Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-globals

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-globals - npm Package Compare versions

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 @@

2

package.json
{
"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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc