Skip to content

Commit

Permalink
Remove glimmer components from tests as telemetry helpers do not repo…
Browse files Browse the repository at this point in the history
…rt glimmer components
  • Loading branch information
lolmaus committed Feb 14, 2024
1 parent 208d697 commit ab2a93c
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 2017,
ecmaVersion: 'latest',
},
env: {
node: true,
Expand Down
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,21 +193,19 @@ 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
{
"unambiguousHelpers": true
}
```

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

Expand Down
35 changes: 8 additions & 27 deletions test/fixtures/with-telemetry/input/app/templates/application.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,19 @@
<h3 class="sr-only">
Components
</h3>
<BsNav @type="pills" @stacked={{true}} as |nav|>
{{#bs-nav type="pills" stacked=true as |nav|}}
{{#each this.model as |comp|}}
<nav.item>
<nav.link-to @route={{comp.demoRoute}}>
{{#nav.item}}
{{#nav.link-to route=comp.demoRoute}}
{{comp.title}}
</nav.link-to>
</nav.item>
{{/nav.link-to}}
{{/nav.item}}
{{/each}}
</BsNav>
{{/bs-nav}}
</div>
<div class="col-sm-8 col-sm-pull-4 col-md-9 col-md-pull-3">
{{utils/bee-bop}}
{{-wat-wat}}
{{utils/-wat-wat}}
{{#if this.isDetailPage}}
<h1>
{{currentComponent.title}}
</h1>
<p class="lead">
{{currentComponent.description}}
</p>
{{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}}
<FileLess @foo={{true}} />
{{outlet}}
{{file-less foo=true}}
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<div>this template has no js </div>
{{#bs-button type="primary"}}Primary{{/bs-button}}
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,8 @@
</BsNav>
</div>
<div class="col-sm-8 col-sm-pull-4 col-md-9 col-md-pull-3">
<Utils::BeeBop />
{{-wat-wat}}
<Utils::-WatWat />
{{#if this.isDetailPage}}
<h1>
{{currentComponent.title}}
</h1>
<p class="lead">
{{currentComponent.description}}
</p>
<ApiReference @component={{this.currentComponent}} />
{{/if}}
{{outlet}}

<BsButton @id="openModal" @onClick={{action "addModal"}}>Open</BsButton>

{{#if hasModal}}
<BsModalSimple @open={{modal}} @onHidden={{action "removeModal"}} @title="Dynamic Dialog">
Hi there
</BsModalSimple>
{{/if}}
{{outlet}}
<FileLess @foo={{true}} />
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<div>this template has no js </div>
<BsButton @type="primary">Primary</BsButton>
5 changes: 0 additions & 5 deletions transforms/angle-brackets/telemetry/invokable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
5 changes: 5 additions & 0 deletions transforms/angle-brackets/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 5 additions & 7 deletions transforms/angle-brackets/transform.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1382,24 +1382,22 @@ test('unknown helper with args', () => {
"
<ApiReference @component={{this.currentComponent}} />
{{api-reference someArg}}
<ApiReference />
{{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)}}
"
`);
});

0 comments on commit ab2a93c

Please sign in to comment.