ember-codemods / ember-angle-brackets-codemod

Codemod to convert curly braces syntax to angle brackets syntax
MIT License
60 stars 31 forks source link

Fails with `{{link-to params=...}}` #185

Open gorner opened 4 years ago

gorner commented 4 years ago
Error: Transformation errored on file app/templates/components/folder/component-name.hbs. Reason TypeError: Cannot read property 'type' of undefined. Please report this in https://github.com/ember-codemods/ember-angle-brackets-codemod/issues

Stack trace:
TypeError: Cannot read property 'type' of undefined
    at transformLinkToAttrs (/Users/gorner/.npm/_npx/12814/lib/node_modules/ember-angle-brackets-codemod/transforms/angle-brackets/transform.js:229:32)
    at transformNode (/Users/gorner/.npm/_npx/12814/lib/node_modules/ember-angle-brackets-codemod/transforms/angle-brackets/transform.js:363:22)
    at BlockStatement (/Users/gorner/.npm/_npx/12814/lib/node_modules/ember-angle-brackets-codemod/transforms/angle-brackets/transform.js:409:16)
    at visitNode (../../../../../packages/@glimmer/syntax/lib/traversal/traverse.ts:97:14)
    at visitArray (../../../../../packages/@glimmer/syntax/lib/traversal/traverse.ts:187:18)
    at visitKey (../../../../../packages/@glimmer/syntax/lib/traversal/traverse.ts:168:5)
    at visitNode (../../../../../packages/@glimmer/syntax/lib/traversal/traverse.ts:117:7)
    at visitKey (../../../../../packages/@glimmer/syntax/lib/traversal/traverse.ts:170:18)
    at visitNode (../../../../../packages/@glimmer/syntax/lib/traversal/traverse.ts:117:7)
    at visitArray (../../../../../packages/@glimmer/syntax/lib/traversal/traverse.ts:187:18)
    at module.exports (/Users/gorner/.npm/_npx/12814/lib/node_modules/ember-angle-brackets-codemod/transforms/angle-brackets/index.js:33:11)

This error is occurring with two templates, with the only thing in common (and different from every other template) being the use of the (private) params option in link-to, as in {{#link-to params=someObject ...}}. I suspect that's the reason for the error, but still felt like I should report it even if it's a wontfix scenario.

tylerturdenpants commented 4 years ago

Hi @gorner

Can you provide a failing test?

gorner commented 4 years ago

Pushed a branch with a failing test to: https://github.com/gorner/ember-angle-brackets-codemod/tree/bug/link-to-params

Note that I am not certain that @params works (or is intended to work) with the angle-bracket version.

Additional context: We mostly use this in our app for a set of items with associated links, some of which may just be query param settings on the current route, some of which may be to a different route. e.g.:

buttons: [{
  // ...
  linkParams: [{ isQueryParams: true, values: { someBoolean: true } }] // set ?someBoolean=true on current route
},
{
  linkParams: ['some.route.name', this.model.id] // different route
}]
{{#each buttons as |btn|}}
  {{#link-to params=btn.linkParams ...}} ... {{/link-to}}
{{/each}}
backspace commented 4 years ago

This just happened to me too, thanks for opening the issue, @gorner. The file in question was this one.

backspace commented 4 years ago

@params does still work, incidentally! 🥳