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

Commit

Permalink
Avoid plugin local state tracking imports previously created
Browse files Browse the repository at this point in the history
Creating `allAddedImports` in plugin scope "bleeds" across repeated
transpilations. This babel plugin function is invoked once for each
configuration of babel plugins, **not** once per transpilation attempt.

This moves `allAddedImports` onto `state` so that it is reset between
transpilation attempts.
  • Loading branch information
rwjblue committed Mar 12, 2021
1 parent 1a4c7e3 commit 8a5738c
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,9 @@ module.exports = function (babel) {
}
}

let allAddedImports = Object.create(null);

function processModuleApiPolyfill(state) {
for (let module in allAddedImports) {
let addedImports = allAddedImports[module];
for (let module in state.allAddedImports) {
let addedImports = state.allAddedImports[module];

for (let addedImport in addedImports) {
let { path } = addedImports[addedImport];
Expand Down Expand Up @@ -187,8 +185,11 @@ module.exports = function (babel) {
let useEmberModule = Boolean(options.useEmberModule);
let moduleOverrides = options.moduleOverrides;

state.allAddedImports = Object.create(null);

state.ensureImport = (exportName, moduleName) => {
let addedImports = (allAddedImports[moduleName] = allAddedImports[moduleName] || {});
let addedImports = (state.allAddedImports[moduleName] =
state.allAddedImports[moduleName] || {});

if (addedImports[exportName]) return addedImports[exportName].id;

Expand Down

0 comments on commit 8a5738c

Please sign in to comment.