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

babel-plugin-namespace-amd-define

Package Overview
Dependencies
Maintainers
1
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-namespace-amd-define - npm Package Compare versions

Comparing version 2.13.2 to 2.13.3-alpha.6

LICENSE.md

183

lib/index.js

@@ -1,95 +0,90 @@

'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function () {
var extraNamespaceCount = void 0;
var firstDefineNamespaced = void 0;
var namespaceVisitor = {
Identifier: function Identifier(path) {
if (path.node.name === 'define') {
if (path.parent.type === 'MemberExpression' && path.parent.property === path.node) {
return;
}
if (path.parent.type === 'ObjectProperty' && path.parent.key === path.node) {
return;
}
var scope = void 0;
// Find if 'define' is defined in any scope
for (scope = path.scope; scope != null; scope = scope.parent) {
if (scope.bindings.define || scope.globals.define) {
break;
}
}
if (scope == null || scope.parent == null && !scope.bindings.define) {
// If 'define' is not defined in any scope namespace or
// defined in the root scope as global...
if (!firstDefineNamespaced) {
// ...and it's its first appearance, namespace it
var namespace = this.opts.namespace || 'Liferay.Loader';
path.node.name = namespace + '.define';
firstDefineNamespaced = true;
} else {
// ...and appeared before, record a new extra appearance
extraNamespaceCount++;
}
}
}
}
};
return {
visitor: {
Program: {
exit: function exit(path, state) {
// We must traverse the AST again because the third party
// transform-es2015-modules-amd emits its define() call after
// Program exit :-(
firstDefineNamespaced = false;
extraNamespaceCount = 0;
path.traverse(namespaceVisitor, { opts: state.opts });
if (extraNamespaceCount > 0) {
var _babelIpc$get = babelIpc.get(state, function () {
return {
log: new _pluginLogger2.default()
};
}),
log = _babelIpc$get.log;
if (firstDefineNamespaced) {
log.info('namespace-amd-define', 'Namespaced first AMD define in file');
}
if (extraNamespaceCount) {
log.warn('namespace-amd-define', 'Found', extraNamespaceCount, 'define() calls inside the module definition', 'which have been ignored as they should never', 'be executed during runtime');
}
}
}
}
}
};
"use strict";
/**
* © 2017 Liferay, Inc. <https://liferay.com>
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var _babelIpc = require('liferay-npm-build-tools-common/lib/babel-ipc');
var babelIpc = _interopRequireWildcard(_babelIpc);
var _pluginLogger = require('liferay-npm-build-tools-common/lib/plugin-logger');
var _pluginLogger2 = _interopRequireDefault(_pluginLogger);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
//# sourceMappingURL=index.js.map
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const babelIpc = __importStar(require("liferay-npm-build-tools-common/lib/babel-ipc"));
const plugin_logger_1 = __importDefault(require("liferay-npm-build-tools-common/lib/plugin-logger"));
/**
* Valid babel plugin options are:
* namespace: 'Liferay.Loader'
* @return {object} a babel visitor
*/
function default_1() {
let extraNamespaceCount;
let firstDefineNamespaced;
const namespaceVisitor = {
Identifier(path) {
if (path.node.name === 'define') {
if (path.parent.type === 'MemberExpression' &&
path.parent.property === path.node) {
return;
}
if (path.parent.type === 'ObjectProperty' &&
path.parent.key === path.node) {
return;
}
let scope;
// Find if 'define' is defined in any scope
for (scope = path.scope; scope != null; scope = scope.parent) {
if (scope.bindings.define || scope.globals.define) {
break;
}
}
if (scope == null ||
(scope.parent == null && !scope.bindings.define)) {
// If 'define' is not defined in any scope namespace or
// defined in the root scope as global...
if (!firstDefineNamespaced) {
// ...and it's its first appearance, namespace it
const namespace = this.opts.namespace || 'Liferay.Loader';
path.node.name = `${namespace}.define`;
firstDefineNamespaced = true;
}
else {
// ...and appeared before, record a new extra appearance
extraNamespaceCount++;
}
}
}
},
};
return {
visitor: {
Program: {
exit(path, state) {
// We must traverse the AST again because the third party
// transform-es2015-modules-amd emits its define() call after
// Program exit :-(
firstDefineNamespaced = false;
extraNamespaceCount = 0;
path.traverse(namespaceVisitor, { opts: state.opts });
if (extraNamespaceCount > 0) {
const { log } = babelIpc.get(state, () => ({
log: new plugin_logger_1.default(),
}));
if (firstDefineNamespaced) {
log.info('namespace-amd-define', 'Namespaced first AMD define in file');
}
if (extraNamespaceCount) {
log.warn('namespace-amd-define', 'Found', extraNamespaceCount, 'define() calls inside the module definition', 'which have been ignored as they should never', 'be executed during runtime');
}
}
},
},
},
};
}
exports.default = default_1;
{
"name": "babel-plugin-namespace-amd-define",
"version": "2.13.2",
"version": "2.13.3-alpha.6+ae09044",
"description": "A Babel plugin to namespace (prefix) AMD define() calls.",
"main": "lib/index.js",
"scripts": {
"build": "babel --source-maps -D -d lib src --ignore '**/__tests__/**'",
"prepublish": "npm run build"
"copyfiles": "node ../../scripts/copyfiles.js",
"build": "tsc && yarn copyfiles",
"prepublish": "yarn build"
},
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-preset-es2015": "^6.24.1"
"dependencies": {
"liferay-npm-build-tools-common": "2.13.3-alpha.6+ae09044"
},
"dependencies": {
"liferay-npm-build-tools-common": "2.13.2"
}
"gitHead": "ae09044beb216743cb2f1e2273aa6e055716ce64"
}
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