Skip to content

Commit 81bbf31

Browse files
author
Robert Jackson
authored
Break out of transform if in attribute space (#192)
Break out of transform if in attribute space
2 parents a4cd85e + 0afc08c commit 81bbf31

2 files changed

Lines changed: 32 additions & 3 deletions

File tree

transforms/angle-brackets/test.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ test('hyphens with nested usage', () => {
10261026
`);
10271027
});
10281028

1029-
test('wallstreet.hbs', () => {
1029+
test('wallstreet', () => {
10301030
let input = `
10311031
{{#foo-bar$baz-bang/foo-bar::bang}}
10321032
<div ...attributes>
@@ -1045,3 +1045,19 @@ test('wallstreet.hbs', () => {
10451045
"
10461046
`);
10471047
});
1048+
1049+
test('attr-space', () => {
1050+
let input = `
1051+
<MyComp::Test @color={{"custom-2"}} @visible={{Group.item.isNew}} />
1052+
<MyComp::Test @color="custom-2" @visible={{Group.item.isNew}} />
1053+
<MyComp @value={{value}} @cont={{this}} @class={{model.some-stuff-here}} />
1054+
`;
1055+
1056+
expect(runTest('attr-space.hbs', input)).toMatchInlineSnapshot(`
1057+
"
1058+
<MyComp::Test @color={{\\"custom-2\\"}} @visible={{Group.item.isNew}} />
1059+
<MyComp::Test @color=\\"custom-2\\" @visible={{Group.item.isNew}} />
1060+
<MyComp @value={{value}} @cont={{this}} @class={{model.some-stuff-here}} />
1061+
"
1062+
`);
1063+
});

transforms/angle-brackets/transform.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const { builders: b } = recast;
1111
const HTML_ATTRIBUTES = ['class', 'placeholder', 'required'];
1212
const BUILT_IN_COMPONENTS = ['link-to', 'input', 'textarea'];
1313

14+
let inAttr = false;
15+
1416
function isAttribute(key) {
1517
return HTML_ATTRIBUTES.includes(key) || isDataAttribute(key);
1618
}
@@ -48,7 +50,7 @@ function transformTagName(tagName) {
4850
return char.toUpperCase();
4951
}
5052

51-
// Remove all occurances of '-'s from the tagName that aren't starting with `-`
53+
// Remove all occurrences of '-'s from the tagName that aren't starting with `-`
5254
return char === '-' ? '' : char.toLowerCase();
5355
});
5456

@@ -299,7 +301,7 @@ function transformNode(node, fileInfo, config) {
299301
return;
300302
}
301303

302-
const newTagName = transformTagName(tagName);
304+
const newTagName = transformTagName(tagName, inAttr);
303305

304306
let attributes;
305307
let children = node.program ? node.program.body : undefined;
@@ -327,6 +329,9 @@ function transformNode(node, fileInfo, config) {
327329
);
328330
return;
329331
}
332+
if (inAttr) {
333+
return;
334+
}
330335
attributes = transformNodeAttributes(tagName, node);
331336
}
332337
return b.element(
@@ -391,5 +396,13 @@ function transformToAngleBracket(_, fileInfo, config) {
391396
return transformNode(node, fileInfo, config);
392397
}
393398
},
399+
AttrNode: {
400+
enter() {
401+
inAttr = true;
402+
},
403+
exit() {
404+
inAttr = false;
405+
},
406+
},
394407
};
395408
}

0 commit comments

Comments
 (0)