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

babel-plugin-system-import-transformer

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-system-import-transformer - npm Package Compare versions

Comparing version 3.1.0 to 4.0.0

.eslintignore

8

dist/babelArgumentProvider.js
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
value: true
});
exports.setBabelArgument = setBabelArgument;
var types = exports.types = undefined;
exports.types = void 0;
var types;
exports.types = types;
function setBabelArgument(babelArg) {
exports.types = types = babelArg.types;
exports.types = types = babelArg.types;
}

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -8,3 +8,3 @@ Object.defineProperty(exports, "__esModule", {

var _babelArgumentProvider = require('./babelArgumentProvider');
var _babelArgumentProvider = require("./babelArgumentProvider");

@@ -11,0 +11,0 @@ function getGlobalObjectExpression() {

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,10 +6,25 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = void 0;
exports.default = function (babel) {
var _helperPluginUtils = require("@babel/helper-plugin-utils");
var _pluginSyntaxDynamicImport = _interopRequireDefault(require("@babel/plugin-syntax-dynamic-import"));
var _babelArgumentProvider = require("./babelArgumentProvider");
var _SystemImportExpressionTransformer = _interopRequireDefault(require("./SystemImportExpressionTransformer"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var PATTERN_SYSTEM_IMPORT = 'System.import';
var TYPE_IMPORT = 'Import';
var _default = (0, _helperPluginUtils.declare)(function (api) {
api.assertVersion(7);
return {
inherits: _babelPluginSyntaxDynamicImport2.default,
inherits: _pluginSyntaxDynamicImport.default,
visitor: {
CallExpression: function CallExpression(path, state) {
var callee = path.get('callee');
if (!callee) {

@@ -22,8 +37,10 @@ return;

if (syntax["system-import"] !== false && callee.matchesPattern(PATTERN_SYSTEM_IMPORT) || syntax.import !== false && callee.type === TYPE_IMPORT) {
if (syntax['system-import'] !== false && callee.matchesPattern(PATTERN_SYSTEM_IMPORT) || syntax.import !== false && callee.type === TYPE_IMPORT) {
var params = path.get('arguments');
if (params.length) {
(0, _babelArgumentProvider.setBabelArgument)(babel);
var transformer = new _SystemImportExpressionTransformer2.default(state, params);
(0, _babelArgumentProvider.setBabelArgument)(api);
var transformer = new _SystemImportExpressionTransformer.default(state, params);
var transformedExpression = transformer.createTransformedExpression();
if (transformedExpression) {

@@ -37,17 +54,4 @@ path.replaceWith(transformedExpression);

};
};
});
var _babelPluginSyntaxDynamicImport = require('babel-plugin-syntax-dynamic-import');
var _babelPluginSyntaxDynamicImport2 = _interopRequireDefault(_babelPluginSyntaxDynamicImport);
var _babelArgumentProvider = require('./babelArgumentProvider');
var _SystemImportExpressionTransformer = require('./SystemImportExpressionTransformer');
var _SystemImportExpressionTransformer2 = _interopRequireDefault(_SystemImportExpressionTransformer);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var PATTERN_SYSTEM_IMPORT = 'System.import';
var TYPE_IMPORT = 'Import';
exports.default = _default;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -8,9 +8,9 @@ Object.defineProperty(exports, "__esModule", {

var _babelArgumentProvider = require('./babelArgumentProvider');
var _path = _interopRequireDefault(require("path"));
var _path = require('path');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _path2 = _interopRequireDefault(_path);
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

@@ -28,4 +28,6 @@ function isRelativeImport(importPath) {

var filename = file.opts.filename;
var filePath = filename.replace(/[^\/]+$/, '');
var result = _path2.default.join(filePath, relativeImportPath);
var filePath = filename.replace(/[^/]+$/, '');
var result = _path.default.join(filePath, relativeImportPath);
return result;

@@ -36,7 +38,10 @@ }

// There should be a better way than cloning
var importedModuleFile = _babelArgumentProvider.types.clone(crntFile);
importedModuleFile.opts = _babelArgumentProvider.types.cloneDeep(crntFile.opts);
importedModuleFile.opts.filename = importedModuleFile.opts.filenameRelative = importedModulePath + '.js';
var importedModuleFile = _objectSpread({}, crntFile, {
opts: _objectSpread({}, crntFile.opts, {
filename: crntFile.opts.filenameRelative = importedModulePath + '.js'
}),
getModuleName: crntFile.getModuleName
}); // importedModuleFile.opts.moduleIds = true;\
// importedModuleFile.opts.moduleIds = true;\
return importedModuleFile;

@@ -48,8 +53,7 @@ }

var importedModulePath = isNodeModuleImport(importPath) ? importPath : getImportPath(file, importPath);
var importedModuleFile = getImportedModuleFile(file, importedModulePath); // Use the getModuleName()
// so that the getModuleId configuration option is called
var importedModuleFile = getImportedModuleFile(file, importedModulePath);
// Use the getModuleName()
// so that the getModuleId configuration option is called
var result = importedModuleFile.opts.moduleIds ? importedModuleFile.getModuleName() : importPath;
return result;
}

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -9,6 +9,7 @@ Object.defineProperty(exports, "__esModule", {

var _babelArgumentProvider = require('./babelArgumentProvider');
var _babelArgumentProvider = require("./babelArgumentProvider");
function createResolveExpressionStatement(parameter) {
var result = _babelArgumentProvider.types.expressionStatement(_babelArgumentProvider.types.callExpression(_babelArgumentProvider.types.identifier('resolve'), [parameter]));
return result;

@@ -19,3 +20,4 @@ }

var result = _babelArgumentProvider.types.callExpression(_babelArgumentProvider.types.memberExpression(_babelArgumentProvider.types.identifier('Promise'), _babelArgumentProvider.types.identifier('resolve')), [parameter]);
return result;
}

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,16 +6,21 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = void 0;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _babelArgumentProvider = require("./babelArgumentProvider");
var _babelArgumentProvider = require('./babelArgumentProvider');
var _moduleImportHelper = require("./moduleImportHelper");
var _moduleImportHelper = require('./moduleImportHelper');
var _promiseUtils = require("./promiseUtils");
var _promiseUtils = require('./promiseUtils');
var _utils = require("./utils");
var _utils = require('./utils');
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var SystemImportExpressionTransformer = function () {
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
var SystemImportExpressionTransformer =
/*#__PURE__*/
function () {
function SystemImportExpressionTransformer(state, params) {

@@ -29,3 +34,2 @@ _classCallCheck(this, SystemImportExpressionTransformer);

var param = params[0];
this.importedModuleExpression = param.node;

@@ -41,3 +45,3 @@ this.moduleNameExpression = this.importedModuleExpression;

_createClass(SystemImportExpressionTransformer, [{
key: 'getGlobalIdentifier',
key: "getGlobalIdentifier",
value: function getGlobalIdentifier() {

@@ -47,2 +51,3 @@ if (this.globalIdentifier) {

}
this.globalIdentifier = new _utils.UtilsHelper(this.file).getGlobalIdentifier();

@@ -52,47 +57,50 @@ return this.globalIdentifier;

}, {
key: 'getAmdTest',
key: "getAmdTest",
value: function getAmdTest() {
var globalIdentifier = this.getGlobalIdentifier();
// typeof global.define === 'function' && global.define.amd
var globalIdentifier = this.getGlobalIdentifier(); // typeof global.define === 'function' && global.define.amd
var amdTest = _babelArgumentProvider.types.logicalExpression('&&', _babelArgumentProvider.types.binaryExpression('===', _babelArgumentProvider.types.unaryExpression('typeof', _babelArgumentProvider.types.memberExpression(globalIdentifier, _babelArgumentProvider.types.identifier('define'))), _babelArgumentProvider.types.stringLiteral('function')), _babelArgumentProvider.types.memberExpression(_babelArgumentProvider.types.memberExpression(globalIdentifier, _babelArgumentProvider.types.identifier('define')), _babelArgumentProvider.types.identifier('amd')));
return amdTest;
}
}, {
key: 'getAmdRequirePromise',
key: "getAmdRequirePromise",
value: function getAmdRequirePromise(module) {
var globalIdentifier = this.getGlobalIdentifier();
// global.require(['localforageSerializer'], resolve, reject);
var globalIdentifier = this.getGlobalIdentifier(); // global.require(['localforageSerializer'], resolve, reject);
var amdRequire = _babelArgumentProvider.types.expressionStatement(_babelArgumentProvider.types.callExpression(_babelArgumentProvider.types.memberExpression(globalIdentifier, _babelArgumentProvider.types.identifier('require')), [_babelArgumentProvider.types.arrayExpression([module]), _babelArgumentProvider.types.identifier('resolve'), _babelArgumentProvider.types.identifier('reject')]));
var newPromiseExpression = _babelArgumentProvider.types.newExpression(_babelArgumentProvider.types.identifier('Promise'), [_babelArgumentProvider.types.functionExpression(null, [_babelArgumentProvider.types.identifier('resolve'), _babelArgumentProvider.types.identifier('reject')], _babelArgumentProvider.types.blockStatement([amdRequire]))]);
return newPromiseExpression;
}
}, {
key: 'getCommonJSTest',
key: "getCommonJSTest",
value: function getCommonJSTest() {
// typeof module !== 'undefined' && module.exports && typeof require !== 'undefined'
var commonJSTest = _babelArgumentProvider.types.logicalExpression('&&', _babelArgumentProvider.types.binaryExpression('!==', _babelArgumentProvider.types.unaryExpression('typeof', _babelArgumentProvider.types.identifier('module')), _babelArgumentProvider.types.stringLiteral('undefined')), _babelArgumentProvider.types.logicalExpression('&&', _babelArgumentProvider.types.memberExpression(_babelArgumentProvider.types.identifier('module'), _babelArgumentProvider.types.identifier('exports')), _babelArgumentProvider.types.binaryExpression('!==', _babelArgumentProvider.types.unaryExpression('typeof', _babelArgumentProvider.types.identifier('require')), _babelArgumentProvider.types.stringLiteral('undefined'))));
return commonJSTest;
}
}, {
key: 'getComponentTest',
key: "getComponentTest",
value: function getComponentTest() {
var globalIdentifier = this.getGlobalIdentifier();
// typeof module !== 'undefined' && module.component && global.require && global.require.loader === 'component'
var globalIdentifier = this.getGlobalIdentifier(); // typeof module !== 'undefined' && module.component && global.require && global.require.loader === 'component'
var componentTest = _babelArgumentProvider.types.logicalExpression('&&', _babelArgumentProvider.types.binaryExpression('!==', _babelArgumentProvider.types.unaryExpression('typeof', _babelArgumentProvider.types.identifier('module')), _babelArgumentProvider.types.stringLiteral('undefined')), _babelArgumentProvider.types.logicalExpression('&&', _babelArgumentProvider.types.memberExpression(_babelArgumentProvider.types.identifier('module'), _babelArgumentProvider.types.identifier('component')), _babelArgumentProvider.types.logicalExpression('&&', _babelArgumentProvider.types.memberExpression(globalIdentifier, _babelArgumentProvider.types.identifier('require')), _babelArgumentProvider.types.binaryExpression('===', _babelArgumentProvider.types.memberExpression(_babelArgumentProvider.types.memberExpression(globalIdentifier, _babelArgumentProvider.types.identifier('require')), _babelArgumentProvider.types.identifier('loader')), _babelArgumentProvider.types.stringLiteral('component')))));
return componentTest;
}
}, {
key: 'getCommonJSRequire',
key: "getCommonJSRequire",
value: function getCommonJSRequire(module) {
// resolve(require('./../utils/serializer'));
var commonJSRequireExpression = _babelArgumentProvider.types.callExpression(_babelArgumentProvider.types.identifier('require'),
// [module] // why this isn't working???
var commonJSRequireExpression = _babelArgumentProvider.types.callExpression(_babelArgumentProvider.types.identifier('require'), // [module] // why this isn't working???
// [module, t.identifier('undefined')] // had to add extra undefined parameter or parenthesis !?!?!?
[_babelArgumentProvider.types.parenthesizedExpression(module)]);
return commonJSRequireExpression;
}
}, {
key: 'getCommonJSRequirePromise',
key: "getCommonJSRequirePromise",
value: function getCommonJSRequirePromise(module) {

@@ -102,6 +110,7 @@ if (this.pluginOptions.commonJS && this.pluginOptions.commonJS.useRequireEnsure) {

}
return this.getCommonJSPlainRequirePromise(module);
}
}, {
key: 'getCommonJSPlainRequirePromise',
key: "getCommonJSPlainRequirePromise",
value: function getCommonJSPlainRequirePromise(module) {

@@ -113,3 +122,3 @@ var commonJSRequireExpression = this.getCommonJSRequire(module);

}, {
key: 'getCommonJSRequireEnsurePromise',
key: "getCommonJSRequireEnsurePromise",
value: function getCommonJSRequireEnsurePromise(module) {

@@ -120,16 +129,17 @@ // require.ensure([], function(require) { resolve(require(module)); });

var newPromiseExpression = _babelArgumentProvider.types.newExpression(_babelArgumentProvider.types.identifier('Promise'), [_babelArgumentProvider.types.functionExpression(null, [_babelArgumentProvider.types.identifier('resolve')], _babelArgumentProvider.types.blockStatement([requireEnsure]))]);
return newPromiseExpression;
}
}, {
key: 'getGlobalRequire',
key: "getGlobalRequire",
value: function getGlobalRequire(module) {
var globalIdentifier = this.getGlobalIdentifier();
var globalIdentifier = this.getGlobalIdentifier(); // resolve(global.localforageSerializer);
// resolve(global.localforageSerializer);
var globalMemberExpression = _babelArgumentProvider.types.memberExpression(globalIdentifier, module, true // computed
);
return globalMemberExpression;
}
}, {
key: 'getGlobalRequirePromise',
key: "getGlobalRequirePromise",
value: function getGlobalRequirePromise(module) {

@@ -141,5 +151,6 @@ var globalMemberExpression = this.getGlobalRequire(module);

}, {
key: 'createTransformedExpression',
key: "createTransformedExpression",
value: function createTransformedExpression() {
var moduleImportExpression;
if (this.moduleType === 'amd') {

@@ -156,5 +167,7 @@ moduleImportExpression = this.getAmdRequirePromise(this.moduleNameExpression);

var componentTest = this.getComponentTest();
var commonJSOrComponentTest = _babelArgumentProvider.types.logicalExpression('||', commonJSTest, componentTest);
var umdRequire = _babelArgumentProvider.types.conditionalExpression(amdTest, this.getAmdRequirePromise(this.moduleNameExpression), _babelArgumentProvider.types.conditionalExpression(commonJSOrComponentTest, this.getCommonJSRequirePromise(this.importedModuleExpression), this.getGlobalRequirePromise(this.moduleNameExpression)));
moduleImportExpression = umdRequire;

@@ -161,0 +174,0 @@ }

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,13 +6,17 @@ Object.defineProperty(exports, "__esModule", {

});
exports.UtilsHelper = undefined;
exports.UtilsHelper = void 0;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _babelArgumentProvider = require("./babelArgumentProvider");
var _babelArgumentProvider = require('./babelArgumentProvider');
var _globalObjectHelper = require("./globalObjectHelper");
var _globalObjectHelper = require('./globalObjectHelper');
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var UtilsHelper = exports.UtilsHelper = function () {
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
var UtilsHelper =
/*#__PURE__*/
function () {
function UtilsHelper(file) {

@@ -25,3 +29,3 @@ _classCallCheck(this, UtilsHelper);

_createClass(UtilsHelper, [{
key: 'getGlobalIdentifier',
key: "getGlobalIdentifier",
value: function getGlobalIdentifier() {

@@ -35,5 +39,6 @@ var name = 'system-import-transformer-global-identifier';

}, {
key: 'getOrCreateHelper',
key: "getOrCreateHelper",
value: function getOrCreateHelper(name, ref) {
var declar = this.file.declarations[name];
if (declar) {

@@ -44,3 +49,3 @@ return declar;

var uid = this.file.declarations[name] = this.file.scope.generateUidIdentifier(name);
this.file.usedHelpers[name] = true;
this.file.hub.addHelper(name);

@@ -55,5 +60,5 @@ if (typeof ref === 'function') {

ref.id = uid;
ref.type = "FunctionDeclaration";
ref.type = 'FunctionDeclaration';
this.file.attachAuxiliaryComment(ref);
this.file.path.unshiftContainer("body", ref);
this.file.path.unshiftContainer('body', ref);
} else {

@@ -73,2 +78,4 @@ ref._compact = true;

return UtilsHelper;
}();
}();
exports.UtilsHelper = UtilsHelper;
{
"name": "babel-plugin-system-import-transformer",
"version": "3.1.0",
"version": "4.0.0",
"description": "Babel plugin that replaces System.import with the equivalent UMD pattern",
"main": "dist/index.js",
"scripts": {
"test": "npm run-script build && node test",
"clean": "rimraf build",
"build": "npm run clean && ./node_modules/.bin/babel src --out-dir dist",
"eslint": "eslint src test",
"eslint-fix": "eslint src test --fix",
"prettify": "prettier --config .prettierrc --write \"src/**/*.js\" \"test/**/*.js\"",
"catch-unprettified": "npm run prettify -- --check",
"lint": "npm run catch-unprettified && npm run eslint",
"test": "npm run build && npm run lint && node test",
"watch": "node test --watch",
"build": "./node_modules/.bin/babel src --out-dir dist",
"prepublish": "./node_modules/.bin/babel src --out-dir dist"
"prepack": "npm run build"
},

@@ -31,16 +37,28 @@ "author": "Thodoris Greasidis",

"devDependencies": {
"babel-cli": "^6.14.0",
"babel-core": "^6.14.0",
"babel-plugin-transform-runtime": "^6.15.0",
"babel-preset-es2015": "^6.14.0",
"babel-register": "^6.14.0",
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/register": "^7.0.0",
"babel-eslint": "^10.0.1",
"chalk": "^1.1.3",
"clear": "0.0.1",
"diff": "^2.2.3",
"js-beautify": "^1.6.2",
"eslint": "^5.13.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-node": "^8.0.1",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"husky": "^1.3.1",
"lint-staged": "^8.1.3",
"prettier": "~1.16.4",
"rimraf": "^2.6.3",
"watch": "^0.18.0"
},
"dependencies": {
"babel-plugin-syntax-dynamic-import": "^6.18.0"
"@babel/core": "^7.0.0",
"@babel/helper-plugin-utils": "^7.0.0",
"@babel/plugin-syntax-dynamic-import": "^7.0.0"
}
}

@@ -41,6 +41,7 @@ # babel-plugin-system-import-transformer

- Babel v6.14.x
- Babel v7.x.x
**Notes:**
- for babel < v6.14 please use the [v2.x.x releases](https://github.com/thgreasi/babel-plugin-system-import-transformer/tree/v2.x.x-stable).
- for babel ^6.14.0 please use the [v3.x.x releases](https://github.com/thgreasi/babel-plugin-system-import-transformer/tree/v3.x.x-stable).
- for babel <6.14 please use the [v2.x.x releases](https://github.com/thgreasi/babel-plugin-system-import-transformer/tree/v2.x.x-stable).
- for babel v5 please use the [v1.x.x releases](https://github.com/thgreasi/babel-plugin-system-import-transformer/tree/v1.x.x-stable).

@@ -47,0 +48,0 @@

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