From 4d03b5df93db92774dfa59ee746c7dcb8443ec50 Mon Sep 17 00:00:00 2001 From: Rajasegar Chandran Date: Sun, 12 Jan 2020 11:08:01 +0530 Subject: [PATCH 1/4] [BUGFIX] Contextual component variable transformation Fixes #220 --- package.json | 1 + .../angle-brackets/telemetry/mock-invokables.js | 3 +++ transforms/angle-brackets/transform.js | 11 ++++++++++- transforms/angle-brackets/transform.test.js | 17 +++++++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 7210aefdc..92581f382 100644 --- a/package.json +++ b/package.json @@ -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", "deploy": "npm version patch && git push && git push --tags && npm publish", "lint": "eslint . --cache", "test:integration": "node ./test/run-test.js", diff --git a/transforms/angle-brackets/telemetry/mock-invokables.js b/transforms/angle-brackets/telemetry/mock-invokables.js index 9715c6ea1..98b1352d7 100644 --- a/transforms/angle-brackets/telemetry/mock-invokables.js +++ b/transforms/angle-brackets/telemetry/mock-invokables.js @@ -101,4 +101,7 @@ module.exports = { 'app/helpers/nested/helper': { type: 'Helper', }, + 'app/components/power-select': { + type: 'Component', + }, }; diff --git a/transforms/angle-brackets/transform.js b/transforms/angle-brackets/transform.js index 56d7132c3..f271cd44e 100755 --- a/transforms/angle-brackets/transform.js +++ b/transforms/angle-brackets/transform.js @@ -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); @@ -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; + } if ( !shouldIgnoreMustacheStatement(node.path.original, config, invokableData) || isWallStreet(tagName) diff --git a/transforms/angle-brackets/transform.test.js b/transforms/angle-brackets/transform.test.js index 937cd79d5..490bbeb5c 100644 --- a/transforms/angle-brackets/transform.test.js +++ b/transforms/angle-brackets/transform.test.js @@ -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|}} + {{fooResult.attributes.thing-desc}} + {{/power-select}} + `; + + expect(runTest('contextual-component-variable.hbs', input)).toMatchInlineSnapshot(`" + + {{fooResult.attributes.thing-desc}} + "`); +}); From 53b4b271e8f728207a48179afb245873ab553e62 Mon Sep 17 00:00:00 2001 From: Rajasegar Chandran Date: Sun, 12 Jan 2020 13:04:03 +0530 Subject: [PATCH 2/4] [CHORE] Updating snapshot for the new test --- transforms/angle-brackets/transform.test.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/transforms/angle-brackets/transform.test.js b/transforms/angle-brackets/transform.test.js index 490bbeb5c..334f18f0a 100644 --- a/transforms/angle-brackets/transform.test.js +++ b/transforms/angle-brackets/transform.test.js @@ -1176,8 +1176,11 @@ test('contextual-component-variable', () => { {{/power-select}} `; - expect(runTest('contextual-component-variable.hbs', input)).toMatchInlineSnapshot(`" - - {{fooResult.attributes.thing-desc}} - "`); + expect(runTest('contextual-component-variable.hbs', input)).toMatchInlineSnapshot(` + " + + {{fooResult.attributes.thing-desc}} + + " + `); }); From 1e1b6107d9dfe4bab01662381cb4af3ea1d48f7a Mon Sep 17 00:00:00 2001 From: Rajasegar Chandran Date: Sun, 12 Jan 2020 13:08:10 +0530 Subject: [PATCH 3/4] [CHORE] Removing debug:test script from package.json Addressing review comments --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 92581f382..7210aefdc 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,6 @@ "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", "deploy": "npm version patch && git push && git push --tags && npm publish", "lint": "eslint . --cache", "test:integration": "node ./test/run-test.js", From 944e85a82ba4a6d69db961431e0e9f6fe0047f30 Mon Sep 17 00:00:00 2001 From: Rajasegar Chandran Date: Sun, 12 Jan 2020 15:24:43 +0530 Subject: [PATCH 4/4] [CHORE] Add test for nested block params --- transforms/angle-brackets/transform.test.js | 38 +++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/transforms/angle-brackets/transform.test.js b/transforms/angle-brackets/transform.test.js index 334f18f0a..32ae98641 100644 --- a/transforms/angle-brackets/transform.test.js +++ b/transforms/angle-brackets/transform.test.js @@ -1184,3 +1184,41 @@ test('contextual-component-variable', () => { " `); }); + +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(` + " + + {{foo}} {{myAction}} + {{hash.property}} {{hash.foo}} + + {{components.foo}} + + + + + + + {{block}} + + + " + `); +});