From ab2a93cad3975bd23f170907f73ca851624a9cea Mon Sep 17 00:00:00 2001 From: "Andrey Mikhaylov (lolmaus)" Date: Wed, 14 Feb 2024 18:14:48 +0300 Subject: [PATCH] Remove glimmer components from tests as telemetry helpers do not report glimmer components --- .eslintrc.js | 2 +- README.md | 10 +++--- .../input/app/templates/application.hbs | 35 +++++-------------- .../app/templates/components/file-less.hbs | 1 - .../output/app/templates/application.hbs | 21 +---------- .../app/templates/components/file-less.hbs | 1 - .../angle-brackets/telemetry/invokable.js | 5 --- transforms/angle-brackets/transform.js | 5 +++ transforms/angle-brackets/transform.test.js | 12 +++---- 9 files changed, 24 insertions(+), 68 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 3bc604e7d..c9a0cdd47 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,7 +1,7 @@ module.exports = { root: true, parserOptions: { - ecmaVersion: 2017, + ecmaVersion: 'latest', }, env: { node: true, diff --git a/README.md b/README.md index 508417c47..b1f42e7fb 100644 --- a/README.md +++ b/README.md @@ -193,9 +193,9 @@ If you would like to only convert certain component invocations to use the angle ### Making helper invocations unambiguous -In order to make helper invocations unambiguous, use this: +You may want to convert invocations like `{{concat "foo" "bar"}}` into `{{(concat "foo" "bar")}}`, which may be useful as a temporary step when upgrading to strict-mode Embroider. -**config/anglebrackets-codemod-config.json** +In your **config/anglebrackets-codemod-config.json**, add this: ```js { @@ -203,11 +203,9 @@ In order to make helper invocations unambiguous, use this: } ``` -This will result in invocations like `{{concat "foo" "bar"}}` to be converted into `{{(concat "foo" "bar")}}`, which may be useful in strict-mode Embroider. - -Note that it does not work in non-Embroider Ember, as of January 2024. +Note that unambiguous helpers do not work in non-Embroider Ember, as of January 2024. -Note that ambiguous invocations, that cannot be statically distinguished between a helper, a property and a component, will not be modified. +Note that ambiguous invocations that cannot be statically distinguished between a helper, a property and a component — will not be modified. ## Debugging Workflow diff --git a/test/fixtures/with-telemetry/input/app/templates/application.hbs b/test/fixtures/with-telemetry/input/app/templates/application.hbs index c0dba4462..332dd51e4 100644 --- a/test/fixtures/with-telemetry/input/app/templates/application.hbs +++ b/test/fixtures/with-telemetry/input/app/templates/application.hbs @@ -3,38 +3,19 @@

Components

- + {{#bs-nav type="pills" stacked=true as |nav|}} {{#each this.model as |comp|}} - - + {{#nav.item}} + {{#nav.link-to route=comp.demoRoute}} {{comp.title}} - - + {{/nav.link-to}} + {{/nav.item}} {{/each}} - + {{/bs-nav}}
- {{utils/bee-bop}} {{-wat-wat}} - {{utils/-wat-wat}} - {{#if this.isDetailPage}} -

- {{currentComponent.title}} -

-

- {{currentComponent.description}} -

- {{api-reference component=this.currentComponent}} - {{/if}} - {{outlet}} - - {{#bs-button id="openModal" onClick=(action "addModal")}}Open{{/bs-button}} - - {{#if hasModal}} - {{#bs-modal-simple open=modal onHidden=(action "removeModal") title="Dynamic Dialog"}} - Hi there - {{/bs-modal-simple}} - {{/if}} - + {{outlet}} + {{file-less foo=true}}
diff --git a/test/fixtures/with-telemetry/input/app/templates/components/file-less.hbs b/test/fixtures/with-telemetry/input/app/templates/components/file-less.hbs index b9c03c0c8..6c801e1d9 100644 --- a/test/fixtures/with-telemetry/input/app/templates/components/file-less.hbs +++ b/test/fixtures/with-telemetry/input/app/templates/components/file-less.hbs @@ -1,2 +1 @@
this template has no js
-{{#bs-button type="primary"}}Primary{{/bs-button}} diff --git a/test/fixtures/with-telemetry/output/app/templates/application.hbs b/test/fixtures/with-telemetry/output/app/templates/application.hbs index 552feedef..87bcba4c9 100644 --- a/test/fixtures/with-telemetry/output/app/templates/application.hbs +++ b/test/fixtures/with-telemetry/output/app/templates/application.hbs @@ -14,27 +14,8 @@
- {{-wat-wat}} - - {{#if this.isDetailPage}} -

- {{currentComponent.title}} -

-

- {{currentComponent.description}} -

- - {{/if}} - {{outlet}} - - Open - - {{#if hasModal}} - - Hi there - - {{/if}} + {{outlet}}
diff --git a/test/fixtures/with-telemetry/output/app/templates/components/file-less.hbs b/test/fixtures/with-telemetry/output/app/templates/components/file-less.hbs index 4c50d5d9c..6c801e1d9 100644 --- a/test/fixtures/with-telemetry/output/app/templates/components/file-less.hbs +++ b/test/fixtures/with-telemetry/output/app/templates/components/file-less.hbs @@ -1,2 +1 @@
this template has no js
-Primary diff --git a/transforms/angle-brackets/telemetry/invokable.js b/transforms/angle-brackets/telemetry/invokable.js index 663abd021..62a3f8545 100644 --- a/transforms/angle-brackets/telemetry/invokable.js +++ b/transforms/angle-brackets/telemetry/invokable.js @@ -16,11 +16,6 @@ function invokableName(name, type) { invokePath = '/components/'; } - console.log({ - name, - invokePath, - result: name.substring(name.lastIndexOf(invokePath) + invokePath.length, name.length), - }); return name.substring(name.lastIndexOf(invokePath) + invokePath.length, name.length); } diff --git a/transforms/angle-brackets/transform.js b/transforms/angle-brackets/transform.js index 18fbca425..8d94df81f 100755 --- a/transforms/angle-brackets/transform.js +++ b/transforms/angle-brackets/transform.js @@ -349,6 +349,11 @@ function isKnownHelper(fullName, config, invokableData) { if (isComponent) { return false; } + + let mergedHelpers = [...KNOWN_HELPERS, ...(helpers || [])]; + let isHelper = mergedHelpers.includes(name) || config.helpers.includes(name); + let strName = `${name}`; // coerce boolean and number to string + return isHelper && !strName.includes('.'); } else { let mergedHelpers = [...KNOWN_HELPERS, ...(helpers || [])]; let isHelper = mergedHelpers.includes(name) || config.helpers.includes(name); diff --git a/transforms/angle-brackets/transform.test.js b/transforms/angle-brackets/transform.test.js index af03ac45c..eec96619c 100644 --- a/transforms/angle-brackets/transform.test.js +++ b/transforms/angle-brackets/transform.test.js @@ -1382,24 +1382,22 @@ test('unknown helper with args', () => { " {{api-reference someArg}} - + {{api-reference}} " `); }); test('unambiguousHelpers: true', () => { let input = ` - {{concat}} - {{unknown}} - {{t "some.string" param="string" another=1}} + {{helper-1}} + {{nested/helper "some.string" param="string" another=1}} `; expect(runTest('unambiguousHelpers: true', input, { unambiguousHelpers: true })) .toMatchInlineSnapshot(` " - {{(concat)}} - {{unknown}} - {{(t \\"some.string\\" param=\\"string\\" another=1)}} + {{(helper-1)}} + {{(nested/helper \\"some.string\\" param=\\"string\\" another=1)}} " `); });