Skip to content

Commit f128933

Browse files
committed
transform: Add hasComponentCSS option
1 parent 78fcf15 commit f128933

3 files changed

Lines changed: 41 additions & 2 deletions

File tree

lib/__tests__/__snapshots__/transform.js.snap

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,30 @@ foo
119119
=========="
120120
`;
121121
122+
exports[`handles \`hasComponentCSS\` option correctly 1`] = `
123+
"==========
124+
125+
export default Component.extend({
126+
classNames: ['foo', 'bar:baz'],
127+
});
128+
129+
~~~~~~~~~~
130+
foo
131+
~~~~~~~~~~
132+
=> tagName: div
133+
~~~~~~~~~~
134+
135+
export default Component.extend({
136+
tagName: \\"\\",
137+
});
138+
139+
~~~~~~~~~~
140+
<div class=\\"{{styleNamespace}} foo bar:baz\\" ...attributes>
141+
foo
142+
</div>
143+
=========="
144+
`;
145+
122146
exports[`handles single \`classNames\` item correctly 1`] = `
123147
"==========
124148

lib/__tests__/transform.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { transform } = require('../transform');
22

3-
function generateSnapshot(source, template) {
4-
let result = transform(source, template);
3+
function generateSnapshot(source, template, options = {}) {
4+
let result = transform(source, template, options);
55

66
return `==========
77
${source}
@@ -190,3 +190,15 @@ test('multi-line template', () => {
190190

191191
expect(generateSnapshot(source, template)).toMatchSnapshot();
192192
});
193+
194+
test('handles `hasComponentCSS` option correctly', () => {
195+
let source = `
196+
export default Component.extend({
197+
classNames: ['foo', 'bar:baz'],
198+
});
199+
`;
200+
201+
let template = `foo`;
202+
203+
expect(generateSnapshot(source, template, { hasComponentCSS: true })).toMatchSnapshot();
204+
});

lib/transform.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ function transform(source, template, options = {}) {
178178

179179
// wrap existing template with root element
180180
let classNodes = [];
181+
if (options.hasComponentCSS) {
182+
classNodes.push(b.mustache('styleNamespace'));
183+
}
181184
for (let className of classNames) {
182185
classNodes.push(b.text(className));
183186
}

0 commit comments

Comments
 (0)