Skip to content

Commit 08d0dd2

Browse files
break out if attr space
1 parent 25ecc7e commit 08d0dd2

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

transforms/angle-brackets/test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,3 +1043,17 @@ test('wallstreet.hbs', () => {
10431043
"
10441044
`);
10451045
});
1046+
1047+
test('attr-space', () => {
1048+
let input = `
1049+
<MyComp::Test @color={{"custom-2"}} @visible={{Group.item.isNew}} />
1050+
<MyComp @value={{value}} @cont={{this}} @class={{model.some-stuff-here}} />
1051+
`;
1052+
1053+
expect(runTest('attr-space.hbs', input)).toMatchInlineSnapshot(`
1054+
"
1055+
<MyComp::Test @color={{\\"custom-2\\"}} @visible={{Group.item.isNew}} />
1056+
<MyComp @value={{value}} @cont={{this}} @class={{model.some-stuff-here}} />
1057+
"
1058+
`);
1059+
});

transforms/angle-brackets/transform.js

Lines changed: 12 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
}
@@ -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;
@@ -321,7 +323,7 @@ function transformNode(node, fileInfo, config) {
321323
let namesParams = transformAttrs(tagName, node.hash.pairs);
322324
attributes = attributes.concat(namesParams);
323325
} else {
324-
if (nodeHasPositionalParameters(node)) {
326+
if (nodeHasPositionalParameters(node) || inAttr) {
325327
logger.warn(
326328
`WARNING: {{${node.path.original}}} was not converted as it has positional parameters which can't be automatically converted. Source: ${fileInfo.path}`
327329
);
@@ -391,5 +393,13 @@ function transformToAngleBracket(_, fileInfo, config) {
391393
return transformNode(node, fileInfo, config);
392394
}
393395
},
396+
AttrNode: {
397+
enter() {
398+
inAttr = true;
399+
},
400+
exit() {
401+
inAttr = false;
402+
},
403+
},
394404
};
395405
}

0 commit comments

Comments
 (0)