Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"scripts": {
"coveralls": "cat ./coverage/lcov.info | node node_modules/.bin/coveralls",
"debug:integration": "node --inspect-brk ./test/run-test.js",
"debug:test": "node --inspect-brk ./node_modules/.bin/jest --runInBand --testNamePattern",
Copy link
Collaborator

Choose a reason for hiding this comment

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

this seems unrelated to the PR?!

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, sorry my bad, it was meant to be in a separate PR, will remove it.

"deploy": "npm version patch && git push && git push --tags && npm publish",
"lint": "eslint . --cache",
"test:integration": "node ./test/run-test.js",
Expand Down
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
17 changes: 17 additions & 0 deletions transforms/angle-brackets/transform.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1164,3 +1164,20 @@ 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>"`);
});