babel-plugin-transform-define
Advanced tools
Comparing version 2.0.0 to 2.0.1
# Changelog | ||
## 2.0.1 | ||
* *Bug*: Support ES module identifiers [#69](https://github.com/FormidableLabs/babel-plugin-transform-define/pull/69), [#70](https://github.com/FormidableLabs/babel-plugin-transform-define/pull/70) (*[@jdlm-stripe][]*) | ||
## 2.0.0 (2019-10-23) | ||
@@ -81,1 +85,3 @@ | ||
Initial Release | ||
[@jdlm-stripe]: https://github.com/jdlm-stripe |
@@ -66,2 +66,24 @@ "use strict"; | ||
/** | ||
* Checks if the given identifier is an ES module import | ||
* @param {babelNode} identifierNodePath The node to check | ||
* @return {boolean} Indicates if the provided node is an import specifier or references one | ||
*/ | ||
const isImportIdentifier = (identifierNodePath) => { | ||
const name = get(identifierNodePath, ["node", "name"]); | ||
const containerType = get(identifierNodePath, ["container", "type"]); | ||
if (containerType === "ImportDefaultSpecifier" || containerType === "ImportSpecifier") { | ||
return true; | ||
} | ||
// Check if the identifier references a module import of the same name | ||
const binding = identifierNodePath.scope.getBinding(name); | ||
if (binding && binding.kind === "module") { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
const memberExpressionComparator = (nodePath, value) => nodePath.matchesPattern(value); | ||
@@ -83,2 +105,8 @@ const identifierComparator = (nodePath, value) => nodePath.node.name === value; | ||
Identifier(nodePath, state) { | ||
// Don't transform import idenifiers. This is meant to mimic webpack's | ||
// DefinePlugin behavior. | ||
if (isImportIdentifier(nodePath)) { | ||
return; | ||
} | ||
processNode(state.opts, nodePath, t.valueToNode, identifierComparator); | ||
@@ -85,0 +113,0 @@ }, |
{ | ||
"name": "babel-plugin-transform-define", | ||
"description": "Babel plugin that replaces member expressions and typeof statements with strings", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"contributors": [ | ||
@@ -6,0 +6,0 @@ "Eric Baer <me@ericbaer.com> (https://github.com/baer)", |
@@ -10,4 +10,4 @@ <h1 align="center">babel-plugin-transform-define</h1> | ||
</a> | ||
<a href='http://travis-ci.org/FormidableLabs/babel-plugin-transform-define'> | ||
<img src='https://secure.travis-ci.org/FormidableLabs/babel-plugin-transform-define.svg?branch=master' /> | ||
<a href='http://travis-ci.com/FormidableLabs/babel-plugin-transform-define'> | ||
<img src='https://travis-ci.com/FormidableLabs/babel-plugin-transform-define.svg?branch=master' /> | ||
</a> | ||
@@ -14,0 +14,0 @@ </p> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12107
115