babel-plugin-inline-replace-variables
Advanced tools
Comparing version 1.1.2 to 1.2.0
@@ -20,6 +20,9 @@ 'use strict'; | ||
Identifier: function Identifier(path, state) { | ||
var replacement = state.opts[path.node.name]; | ||
if (path.parent.type === 'MemberExpression') { | ||
return; | ||
} | ||
if (path.isPure()) { | ||
return; | ||
} | ||
var replacement = state.opts[path.node.name]; | ||
if (replacement !== undefined) { | ||
@@ -26,0 +29,0 @@ var type = typeof replacement === 'undefined' ? 'undefined' : _typeof(replacement); |
{ | ||
"name": "babel-plugin-inline-replace-variables", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"description": "babel plugin to inline replace variables", | ||
@@ -12,3 +12,3 @@ "main": "lib/index.js", | ||
"type": "git", | ||
"url": "github.com/wssgcg1213/babel-plugin-inline-replace-variables" | ||
"url": "https://github.com/wssgcg1213/babel-plugin-inline-replace-variables" | ||
}, | ||
@@ -15,0 +15,0 @@ "keywords": [ |
@@ -10,6 +10,9 @@ /** | ||
Identifier(path, state) { | ||
const replacement = state.opts[path.node.name] | ||
if (path.parent.type === 'MemberExpression') { | ||
return; | ||
} | ||
if (path.isPure()) { | ||
return; | ||
} | ||
const replacement = state.opts[path.node.name] | ||
if (replacement !== undefined) { | ||
@@ -16,0 +19,0 @@ const type = typeof replacement |
@@ -61,2 +61,24 @@ /** | ||
}); | ||
}); | ||
describe('non-globals', () => { | ||
describe(`transform`, () => { | ||
it(`__SERVER__ should NOT be replaced to true`, () => { | ||
babel.transform(` | ||
function foo(__SERVER__) { | ||
console.log('this is a normal argument', __SERVER__) | ||
} | ||
`, { | ||
plugins: [[plugin, { | ||
__SERVER__: true, | ||
__VERSION__: "v1.2.3" | ||
}]] | ||
}).code | ||
.should.be.equal(` | ||
function foo(__SERVER__) { | ||
console.log('this is a normal argument', __SERVER__); | ||
}`) | ||
}); | ||
}); | ||
}); |
6328
139