Skip to content

Commit b755fd4

Browse files
committed
Bump ember-template-recast: fix valueless attributes
1 parent e86b127 commit b755fd4

2 files changed

Lines changed: 35 additions & 9 deletions

File tree

transforms/angle-brackets/transform.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ function shouldSkipFile(fileInfo, config) {
124124
return false;
125125
}
126126

127-
function transformAttrs(tagName, attrs, config) {
128-
return attrs.map((a) => {
127+
function transformAttrs(tagName, attrs, nodeParams, config) {
128+
const newAttrs = attrs.map((a) => {
129129
let _key = a.key;
130130
let _valueType = a.value.type;
131131
let _value;
@@ -174,6 +174,17 @@ function transformAttrs(tagName, attrs, config) {
174174
}
175175
return b.attr(_key, _value);
176176
});
177+
178+
const newValuelessAttrs = nodeParams
179+
.filter((param) => !!param.parts)
180+
.filter((param) => isAttribute(param.parts[0]))
181+
.map((param) => {
182+
const attr = b.attr(param.parts[0], b.text(''));
183+
attr.isValueless = true;
184+
return attr;
185+
});
186+
187+
return [...newAttrs, ...newValuelessAttrs];
177188
}
178189

179190
function isQueryParam(param) {
@@ -299,7 +310,7 @@ function shouldSkipDataTestParams(params, includeValuelessDataTestAttributes) {
299310
}
300311

301312
function transformNodeAttributes(tagName, node, config) {
302-
let attributes = transformAttrs(tagName, node.hash.pairs, config);
313+
let attributes = transformAttrs(tagName, node.hash.pairs, node.params, config);
303314
return node.params.concat(attributes);
304315
}
305316

@@ -389,7 +400,7 @@ function transformNode(node, fileInfo, config) {
389400
attributes = transformLinkToAttrs(node.params);
390401
}
391402

392-
let namesParams = transformAttrs(tagName, node.hash.pairs, config);
403+
let namesParams = transformAttrs(tagName, node.hash.pairs, node.params, config);
393404
attributes = attributes.concat(namesParams);
394405
} else {
395406
if (nodeHasPositionalParameters(node)) {

transforms/angle-brackets/transform.test.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ test('data-test-attributes', () => {
200200
<XFoo @data-test-selector={{true}} />
201201
<XFoo @data-test-selector={{post.id}} />
202202
<XFoo @label=\\"hi\\" @data-test-selector={{true}} />
203-
<XFoo data-test-foo />
203+
<XFoo data-test-foo />
204204
<XFoo @data-foo={{true}}>
205205
block
206206
</XFoo>
@@ -210,16 +210,16 @@ test('data-test-attributes', () => {
210210
<XFoo @data-test-selector={{post.id}}>
211211
block
212212
</XFoo>
213-
<Common::AccordionComponent data-test-accordion as |accordion|>
213+
<Common::AccordionComponent data-test-accordion as |accordion|>
214214
block
215215
</Common::AccordionComponent>
216-
<LinkTo @route=\\"posts\\" data-test-foo>
216+
<LinkTo @route=\\"posts\\" data-test-foo >
217217
Recent Posts
218218
</LinkTo>
219-
<LinkTo @route={{this.dynamicPath}} @query={{hash direction=\\"desc\\" showArchived=false}} data-test-foo>
219+
<LinkTo @route={{this.dynamicPath}} @query={{hash direction=\\"desc\\" showArchived=false}} data-test-foo >
220220
Recent Posts
221221
</LinkTo>
222-
<LinkTo @route={{this.dynamicPath}} @query={{hash direction=\\"desc\\" showArchived=false}} data-test-foo data-foo>
222+
<LinkTo @route={{this.dynamicPath}} @query={{hash direction=\\"desc\\" showArchived=false}} data-test-foo data-foo >
223223
Recent Posts
224224
</LinkTo>
225225
@@ -243,6 +243,21 @@ test('data-test-attributes', () => {
243243
`);
244244
});
245245

246+
test('data-test-empty-attributes', () => {
247+
let options = {
248+
includeValuelessDataTestAttributes: true,
249+
};
250+
let input = `
251+
{{x-foo data-test-foo }}
252+
`;
253+
254+
expect(runTest('data-test-empty-attributes.hbs', input, options)).toMatchInlineSnapshot(`
255+
"
256+
<XFoo data-test-foo />
257+
"
258+
`);
259+
});
260+
246261
test('deeply-nested-sub', () => {
247262
let input = `
248263
{{#some-component class=(concat foo (some-helper ted (some-dude bar (a b c)))) }}

0 commit comments

Comments
 (0)