babel-plugin-globals
Advanced tools
Comparing version 2.0.0 to 2.0.1
41
index.js
@@ -51,3 +51,3 @@ 'use strict'; | ||
*/ | ||
function createGlobal(expr, nodes) { | ||
function createGlobal(expr, nodes, opt_namedPartial) { | ||
var exprs = []; | ||
@@ -60,3 +60,3 @@ while (t.isMemberExpression(expr)) { | ||
var currGlobalName = ''; | ||
for (var i = exprs.length - 2; i > 0; i--) { | ||
for (var i = exprs.length - 2; opt_namedPartial ? i >= 0 : i > 0; i--) { | ||
currGlobalName += '.' + exprs[i].property.value; | ||
@@ -114,3 +114,3 @@ if (!createdGlobals[currGlobalName]) { | ||
id = 'this.' + globalName + '.' + moduleName + (name ? '.' + name : ''); | ||
id = 'this.' + globalName + '.' + moduleName + (name && name !== true ? '.' + name : ''); | ||
} | ||
@@ -184,7 +184,36 @@ | ||
/** | ||
* Removes export all declarations. | ||
* Replaces export all declarations with code that copies all named | ||
* exports from the imported file into the named exports of the current | ||
* file. The final generated code will be something like this: | ||
* Object.keys(importedGlobal).forEach(function (key) { | ||
* currGlobal[key] = importedGlobal[key]; | ||
* }); | ||
* @param {!NodePath} nodePath | ||
*/ | ||
ExportAllDeclaration: function(nodePath) { | ||
nodePath.replaceWithMultiple([]); | ||
ExportAllDeclaration: function(nodePath, state) { | ||
var replacements = []; | ||
var expr = getGlobalExpression(state, getFilenameNoExt(state.file.opts.filename), true); | ||
createGlobal(expr, replacements, true); | ||
var originalGlobal = getGlobalExpression(state, nodePath.node.source.value, true); | ||
replacements.push(t.expressionStatement(t.callExpression( | ||
t.memberExpression( | ||
t.callExpression( | ||
t.memberExpression(t.identifier('Object'), t.identifier('keys')), | ||
[originalGlobal] | ||
), | ||
t.identifier('forEach') | ||
), | ||
[t.functionExpression( | ||
null, | ||
[t.identifier('key')], | ||
t.blockStatement( | ||
[t.expressionStatement(t.assignmentExpression( | ||
'=', | ||
t.memberExpression(expr, t.identifier('key'), true), | ||
t.memberExpression(originalGlobal, t.identifier('key'), true) | ||
))] | ||
) | ||
)] | ||
))); | ||
nodePath.replaceWithMultiple(replacements); | ||
}, | ||
@@ -191,0 +220,0 @@ |
{ | ||
"name": "babel-plugin-globals", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "A babel plugin that exposes ES6 modules to global variables.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
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
12281
247