Skip to content
This repository has been archived by the owner on Dec 8, 2024. It is now read-only.

Commit

Permalink
Reproduce failures when using shared babel config to transpile multip…
Browse files Browse the repository at this point in the history
…le files

```
    TypeError: /Users/rjackson/src/ember-cli/babel-plugin-htmlbars-inline-precompile/foo-bar.js: C
annot read property 'reference' of undefined

      14 |   for (let ref of refPaths) {
      15 |     let binding = ref.scope.getBinding(ref.node.name);
    > 16 |     binding.reference(ref);
         |             ^
      17 |   }
      18 | };
      19 |

      at reference (src/util.js:16:13)
      at registerRefs (index.js:143:7)
      at PluginPass.replacePath (index.js:383:7)
      at newFn (node_modules/@babel/traverse/lib/visitors.js:175:21)

```

Simply guarding for `ref.scope.getBinding(...)` returning `undefined` is
not "good enough".
  • Loading branch information
rwjblue committed Mar 12, 2021
1 parent 0f77fcc commit 4a0a86a
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions __tests__/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,36 @@ describe('htmlbars-inline-precompile', function () {
`);
});

it('does not error when transpiling multiple modules with a single plugin config', function () {
let transpiled = transform(
"import hbs from 'htmlbars-inline-precompile';\nvar compiled = hbs`hello`;"
);

expect(transpiled).toMatchInlineSnapshot(`
"import { createTemplateFactory as _createTemplateFactory } from \\"@ember/template-factory\\";
var compiled = _createTemplateFactory(
/*
hello
*/
\\"precompiled(hello)\\");"
`);

transpiled = transform(
"import hbs from 'htmlbars-inline-precompile';\nvar compiled = hbs`hello`;"
);

expect(transpiled).toMatchInlineSnapshot(`
"import { createTemplateFactory as _createTemplateFactory } from \\"@ember/template-factory\\";
var compiled = _createTemplateFactory(
/*
hello
*/
\\"precompiled(hello)\\");"
`);
});

it('passes options when used as a call expression', function () {
let source = 'hello';
transform(`import hbs from 'htmlbars-inline-precompile';\nvar compiled = hbs('${source}');`);
Expand Down

0 comments on commit 4a0a86a

Please sign in to comment.