ember-template-lint / ember-template-recast

Non-destructive template transformer.
MIT License
40 stars 38 forks source link

`builder.element(tagName)` throws an error in 6.x #734

Open runspired opened 2 years ago

runspired commented 2 years ago

Error:

TypeError: Cannot destructure property 'attrs' of 'options' as it is undefined.
    at Object.buildElement [as element] (/Users/runspired/github/private/fnb/frontend/node_modules/@glimmer/syntax/dist/commonjs/es2017/lib/v1/public-builders.js:158:5)

Example Working in 5.x

Transform:

module.exports = function(env) {
  const b = env.syntax.builders;

  return {
    ElementNode(node) {
      return b.element("span");
    }
  }
}

Code to modify:

<Input />
runspired commented 2 years ago

utilizing npx ember-template-recast@{version} I worked back to this affects all versions of 6.x. I'm not sure why the default for npx ember-template-recast was 5.x until this week (the particular transform this threw for was working fine via this execution only 2 weeks ago).

The global node on my machine is v17.4.0, the project node is v14.17.6

dcyriller commented 2 years ago

I ran into this error while upgrading @glimmer/syntax a while ago here in template-recast: https://github.com/ember-template-lint/ember-template-recast/pull/627/files#diff-3a4f3cd1ddd47fc9011205425ed890cfab4f79a21f7cbda7ad8055cb0ef82ff2R11

If we want to fix this, we should do it in @glimmer/syntax. As far as I remember it is a very light fix there (a missing ?).

As a work around, you can provide an empty object as a second argument.

runspired commented 2 years ago

@dcyriller confirm, it came into glimmer/syntax in this PR https://github.com/glimmerjs/glimmer-vm/commit/8e11b91167d55995c7400135460a0d4c8b2a4164

we'd just need to have options = {} as the default here: https://github.com/glimmerjs/glimmer-vm/blob/a397f489047d89c4b2b6f4bfc4415e780c054b99/packages/%40glimmer/syntax/lib/v1/public-builders.ts#L205