Skip to content

Commit 5113802

Browse files
committed
[BUGFIX] Use state to store normalized options
1 parent 7872467 commit 5113802

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/index.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const normalizeOptions = require('./utils/normalize-options').normalizeOptions;
66

77
function macros(babel) {
88
let t = babel.types;
9-
let options;
109

1110
function buildIdentifier(value, name) {
1211
let replacement = t.booleanLiteral(value);
@@ -27,9 +26,9 @@ function macros(babel) {
2726
return {
2827
name: 'babel-feature-flags-and-debug-macros',
2928
visitor: {
30-
ImportSpecifier(path) {
29+
ImportSpecifier(path, state) {
3130
let importPath = path.parent.source.value;
32-
let flagsForImport = options.flags[importPath];
31+
let flagsForImport = state.opts.flags[importPath];
3332

3433
if (flagsForImport) {
3534
let flagName = path.node.imported.name;
@@ -58,9 +57,9 @@ function macros(babel) {
5857
},
5958

6059
ImportDeclaration: {
61-
exit(path) {
60+
exit(path, state) {
6261
let importPath = path.node.source.value;
63-
let flagsForImport = options.flags[importPath];
62+
let flagsForImport = state.opts.flags[importPath];
6463

6564
// remove flag source imports when no specifiers are left
6665
if (flagsForImport && path.get('specifiers').length === 0) {
@@ -71,16 +70,16 @@ function macros(babel) {
7170

7271
Program: {
7372
enter(path, state) {
74-
options = normalizeOptions(state.opts);
75-
this.macroBuilder = new Macros(babel, options);
73+
state.opts = normalizeOptions(state.opts);
74+
this.macroBuilder = new Macros(babel, state.opts);
7675

7776
let body = path.get('body');
7877

7978
body.forEach(item => {
8079
if (item.isImportDeclaration()) {
8180
let importPath = item.node.source.value;
8281

83-
let debugToolsImport = options.debugTools.debugToolsImport;
82+
let debugToolsImport = state.opts.debugTools.debugToolsImport;
8483

8584
if (debugToolsImport && debugToolsImport === importPath) {
8685
if (!item.node.specifiers.length) {

0 commit comments

Comments
 (0)