Skip to content

Commit

Permalink
Merge 5c788e6 into a4cd85e
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerturdenpants committed Nov 13, 2019
2 parents a4cd85e + 5c788e6 commit 4b8b1d1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
16 changes: 16 additions & 0 deletions transforms/angle-brackets/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1045,3 +1045,19 @@ test('wallstreet.hbs', () => {
"
`);
});

test('attr-space', () => {
let input = `
<MyComp::Test @color={{"custom-2"}} @visible={{Group.item.isNew}} />
<MyComp::Test @color="custom-2" @visible={{Group.item.isNew}} />
<MyComp @value={{value}} @cont={{this}} @class={{model.some-stuff-here}} />
`;

expect(runTest('attr-space.hbs', input)).toMatchInlineSnapshot(`
"
<MyComp::Test @color={{\\"custom-2\\"}} @visible={{Group.item.isNew}} />
<MyComp::Test @color=\\"custom-2\\" @visible={{Group.item.isNew}} />
<MyComp @value={{value}} @cont={{this}} @class={{model.some-stuff-here}} />
"
`);
});
17 changes: 15 additions & 2 deletions transforms/angle-brackets/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const { builders: b } = recast;
const HTML_ATTRIBUTES = ['class', 'placeholder', 'required'];
const BUILT_IN_COMPONENTS = ['link-to', 'input', 'textarea'];

let inAttr = false;

function isAttribute(key) {
return HTML_ATTRIBUTES.includes(key) || isDataAttribute(key);
}
Expand Down Expand Up @@ -48,7 +50,7 @@ function transformTagName(tagName) {
return char.toUpperCase();
}

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

Expand Down Expand Up @@ -299,7 +301,7 @@ function transformNode(node, fileInfo, config) {
return;
}

const newTagName = transformTagName(tagName);
const newTagName = transformTagName(tagName, inAttr);

let attributes;
let children = node.program ? node.program.body : undefined;
Expand Down Expand Up @@ -327,6 +329,9 @@ function transformNode(node, fileInfo, config) {
);
return;
}
if (inAttr) {
return;
}
attributes = transformNodeAttributes(tagName, node);
}
return b.element(
Expand Down Expand Up @@ -391,5 +396,13 @@ function transformToAngleBracket(_, fileInfo, config) {
return transformNode(node, fileInfo, config);
}
},
AttrNode: {
enter() {
inAttr = true;
},
exit() {
inAttr = false;
},
},
};
}

0 comments on commit 4b8b1d1

Please sign in to comment.