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

babel-plugin-wrap-modules-amd

Package Overview
Dependencies
Maintainers
1
Versions
120
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-wrap-modules-amd - npm Package Compare versions

Comparing version 1.2.2 to 1.2.3

12

lib/__tests__/index.test.js

@@ -16,11 +16,11 @@ 'use strict';

it('correctly wraps modules', function () {
var source = '\n\tconsole.log(\'Say something\');\n\tif (1 == 0) {\n\t\tconsole.log(\'Something broke in the Matrix\');\n\t}\n\tmodule.exports = \'All OK\';\n\t';
var source = '\n\tconsole.log(\'Say something\');\n\tif (1 == 0) {\n\t\tconsole.log(\'Something broke in the Matrix\');\n\t}\n\tmodule.exports = \'All OK\';\n\t';
var _babel$transform = babel.transform(source, {
plugins: [_index2.default]
}),
code = _babel$transform.code;
var _babel$transform = babel.transform(source, {
plugins: [_index2.default]
}),
code = _babel$transform.code;
expect(code).toMatchSnapshot();
expect(code).toMatchSnapshot();
});
//# sourceMappingURL=index.test.js.map
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
value: true
});
exports.default = function (_ref) {
var t = _ref.types;
var t = _ref.types;
var wrapVisitor = {
Identifier: function Identifier(path, _ref2) {
var dependencies = _ref2.dependencies;
var wrapVisitor = {
Identifier: function Identifier(path, _ref2) {
var dependencies = _ref2.dependencies;
var node = path.node;
var node = path.node;
if (node.name === 'require') {
var parent = path.parent;
if (node.name === 'require') {
var parent = path.parent;
if (t.isCallExpression(parent) && parent.callee === node && parent.arguments.length == 1) {
var argument0 = parent.arguments[0];
if (t.isCallExpression(parent) && parent.callee === node && parent.arguments.length == 1) {
var argument0 = parent.arguments[0];
if (t.isLiteral(argument0)) {
var moduleName = argument0.value;
if (t.isLiteral(argument0)) {
var moduleName = argument0.value;
dependencies[moduleName] = moduleName;
}
}
}
}
};
dependencies[moduleName] = moduleName;
}
}
}
}
};
return {
visitor: {
Program: {
enter: function enter(path, state) {
state.dependencies = {};
},
exit: function exit(path, _ref3) {
var opts = _ref3.opts,
dependencies = _ref3.dependencies;
return {
visitor: {
Program: {
enter: function enter(path, state) {
state.dependencies = {};
},
exit: function exit(path, _ref3) {
var opts = _ref3.opts,
dependencies = _ref3.dependencies;
// We must traverse the AST again because some plugins emit
// their require() calls after exiting Program node :-(
path.traverse(wrapVisitor, { opts: opts, dependencies: dependencies });
// We must traverse the AST again because some plugins emit
// their require() calls after exiting Program node :-(
path.traverse(wrapVisitor, { opts: opts, dependencies: dependencies });
var node = path.node;
var body = node.body;
var node = path.node;
var body = node.body;
dependencies = Object.keys(dependencies).map(function (dep) {
return '\'' + dep + '\'';
});
dependencies = Object.keys(dependencies).map(function (dep) {
return '\'' + dep + '\'';
});
var buildDeps = (0, _babelTemplate2.default)('[\n \'module\', \'exports\', \'require\' \n ' + (dependencies.length > 0 ? ',' : '') + ' \n ' + dependencies.join() + '\n ]');
var buildDeps = (0, _babelTemplate2.default)('[\n \'module\', \'exports\', \'require\' \n ' + (dependencies.length > 0 ? ',' : '') + ' \n ' + dependencies.join() + '\n ]');
node.body = [buildDefine({
SOURCE: body,
DEPS: buildDeps()
})];
}
}
}
};
node.body = [buildDefine({
SOURCE: body,
DEPS: buildDeps()
})];
}
}
}
};
};

@@ -74,4 +74,4 @@

/**
* @return {object} a babel visitor
*/
* @return {object} a babel visitor
*/
//# sourceMappingURL=index.js.map
{
"name": "babel-plugin-wrap-modules-amd",
"version": "1.2.2",
"version": "1.2.3",
"description": "A Babel plugin to wrap package modules inside AMD define() calls.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -5,3 +5,3 @@ import * as babel from 'babel-core';

it('correctly wraps modules', () => {
const source = `
const source = `
console.log('Say something');

@@ -14,7 +14,7 @@ if (1 == 0) {

const {code} = babel.transform(source, {
plugins: [plugin],
});
const {code} = babel.transform(source, {
plugins: [plugin],
});
expect(code).toMatchSnapshot();
expect(code).toMatchSnapshot();
});

@@ -10,46 +10,48 @@ import template from 'babel-template';

/**
* @return {object} a babel visitor
*/
* @return {object} a babel visitor
*/
export default function({types: t}) {
const wrapVisitor = {
Identifier(path, {dependencies}) {
const node = path.node;
const wrapVisitor = {
Identifier(path, {dependencies}) {
const node = path.node;
if (node.name === 'require') {
const parent = path.parent;
if (node.name === 'require') {
const parent = path.parent;
if (
t.isCallExpression(parent) &&
parent.callee === node &&
parent.arguments.length == 1
) {
const argument0 = parent.arguments[0];
if (
t.isCallExpression(parent) &&
parent.callee === node &&
parent.arguments.length == 1
) {
const argument0 = parent.arguments[0];
if (t.isLiteral(argument0)) {
const moduleName = argument0.value;
if (t.isLiteral(argument0)) {
const moduleName = argument0.value;
dependencies[moduleName] = moduleName;
}
}
}
},
};
dependencies[moduleName] = moduleName;
}
}
}
},
};
return {
visitor: {
Program: {
enter(path, state) {
state.dependencies = {};
},
exit(path, {opts, dependencies}) {
// We must traverse the AST again because some plugins emit
// their require() calls after exiting Program node :-(
path.traverse(wrapVisitor, {opts, dependencies});
return {
visitor: {
Program: {
enter(path, state) {
state.dependencies = {};
},
exit(path, {opts, dependencies}) {
// We must traverse the AST again because some plugins emit
// their require() calls after exiting Program node :-(
path.traverse(wrapVisitor, {opts, dependencies});
const node = path.node;
const body = node.body;
const node = path.node;
const body = node.body;
dependencies = Object.keys(dependencies).map(dep => `'${dep}'`);
dependencies = Object.keys(dependencies).map(
dep => `'${dep}'`
);
const buildDeps = template(`[
const buildDeps = template(`[
'module', 'exports', 'require'

@@ -60,12 +62,12 @@ ${dependencies.length > 0 ? ',' : ''}

node.body = [
buildDefine({
SOURCE: body,
DEPS: buildDeps(),
}),
];
},
},
},
};
node.body = [
buildDefine({
SOURCE: body,
DEPS: buildDeps(),
}),
];
},
},
},
};
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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