Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions transforms/angle-brackets/telemetry/mock-invokables.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,7 @@ module.exports = {
'app/helpers/nested/helper': {
type: 'Helper',
},
'app/components/power-select': {
type: 'Component',
},
};
11 changes: 10 additions & 1 deletion transforms/angle-brackets/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const HTML_ATTRIBUTES = ['class', 'placeholder', 'required'];
const BUILT_IN_COMPONENTS = ['link-to', 'input', 'textarea'];

let inAttr = false;
let havingBlockParams = false;
let currentBlockParams = [];

function isAttribute(key) {
return HTML_ATTRIBUTES.includes(key) || isDataAttribute(key);
Expand Down Expand Up @@ -435,16 +437,23 @@ function transformToAngleBracket(fileInfo, config, invokableData) {
node.loc.source !== '(synthetic)' &&
!shouldIgnoreMustacheStatement(tagName, config, invokableData);
const isNestedComponent = isNestedComponentTagName(tagName);
const isNotBlockParamValue =
!havingBlockParams && !currentBlockParams.includes(node.path.original);

if (
isValidMustache &&
(node.hash.pairs.length > 0 || node.params.length > 0 || isNestedComponent)
(node.hash.pairs.length > 0 || node.params.length > 0 || isNestedComponent) &&
isNotBlockParamValue
) {
return transformNode(node, fileInfo, config);
}
},
BlockStatement(node) {
let tagName = `${node.path.original}`;
havingBlockParams = node.program.blockParams.length > 0;
if (havingBlockParams) {
currentBlockParams = node.program.blockParams;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't work for nested block params

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Turbo87 Can you give me an example?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the corresponding template-lint rule has something like this implemented, or you can have a look at the implicit-this codemod

}
if (
!shouldIgnoreMustacheStatement(node.path.original, config, invokableData) ||
isWallStreet(tagName)
Expand Down
58 changes: 58 additions & 0 deletions transforms/angle-brackets/transform.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1164,3 +1164,61 @@ test('No telemetry', () => {
"
`);
});

test('contextual-component-variable', () => {
let input = `
{{#power-select search=(perform searchThings)
selected=selectedResult
placeholder="Enter the thing..."
loadingMessage="Searching..."
onchange=(perform selectThing) as |fooResult|}}
<span class="select-description">{{fooResult.attributes.thing-desc}}</span>
{{/power-select}}
`;

expect(runTest('contextual-component-variable.hbs', input)).toMatchInlineSnapshot(`
"
<PowerSelect @search={{perform searchThings}} @selected={{selectedResult}} @placeholder=\\"Enter the thing...\\" @loadingMessage=\\"Searching...\\" @onchange={{perform selectThing}} as |fooResult|>
<span class=\\"select-description\\">{{fooResult.attributes.thing-desc}}</span>
</PowerSelect>
"
`);
});

test('nested-block-params', () => {
let input = `
{{#my-component as |foo myAction hash components|}}
{{foo}} {{myAction}}
{{hash.property}} {{hash.foo}}

{{components.foo}}

{{#components.my-component}}

{{/components.my-component}}

{{#components.block as |block|}}
{{block}}
{{/components.block}}
{{/my-component}}
`;

expect(runTest('nested-block-params', input)).toMatchInlineSnapshot(`
"
<MyComponent as |foo myAction hash components|>
{{foo}} {{myAction}}
{{hash.property}} {{hash.foo}}

{{components.foo}}

<components.my-component>

</components.my-component>

<components.block as |block|>
{{block}}
</components.block>
</MyComponent>
"
`);
});