Commit ac419aba authored by Cholgrrr's avatar Cholgrrr
Browse files

.gitignore, settings.json und 14061 weitere dateien aktualisiert...

parent ed14b8b4
# @babel/plugin-transform-for-of
> Compile ES2015 for...of to ES5
See our website [@babel/plugin-transform-for-of](https://babeljs.io/docs/en/next/babel-plugin-transform-for-of.html) for more information.
## Install
Using npm:
```sh
npm install --save-dev @babel/plugin-transform-for-of
```
or using yarn:
```sh
yarn add @babel/plugin-transform-for-of --dev
```
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
function _helperPluginUtils() {
const data = require("@babel/helper-plugin-utils");
_helperPluginUtils = function () {
return data;
};
return data;
}
function _core() {
const data = require("@babel/core");
_core = function () {
return data;
};
return data;
}
var _default = (0, _helperPluginUtils().declare)((api, options) => {
api.assertVersion(7);
const {
loose,
assumeArray
} = options;
if (loose === true && assumeArray === true) {
throw new Error(`The loose and assumeArray options cannot be used together in @babel/plugin-transform-for-of`);
}
if (assumeArray) {
return {
name: "transform-for-of",
visitor: {
ForOfStatement(path) {
const {
scope
} = path;
const {
left,
right,
body
} = path.node;
const i = scope.generateUidIdentifier("i");
let array = scope.maybeGenerateMemoised(right, true);
const inits = [_core().types.variableDeclarator(i, _core().types.numericLiteral(0))];
if (array) {
inits.push(_core().types.variableDeclarator(array, right));
} else {
array = right;
}
const item = _core().types.memberExpression(_core().types.cloneNode(array), _core().types.cloneNode(i), true);
let assignment;
if (_core().types.isVariableDeclaration(left)) {
assignment = left;
assignment.declarations[0].init = item;
} else {
assignment = _core().types.expressionStatement(_core().types.assignmentExpression("=", left, item));
}
const block = _core().types.toBlock(body);
block.body.unshift(assignment);
path.replaceWith(_core().types.forStatement(_core().types.variableDeclaration("let", inits), _core().types.binaryExpression("<", _core().types.cloneNode(i), _core().types.memberExpression(_core().types.cloneNode(array), _core().types.identifier("length"))), _core().types.updateExpression("++", _core().types.cloneNode(i)), block));
}
}
};
}
const pushComputedProps = loose ? pushComputedPropsLoose : pushComputedPropsSpec;
const buildForOfArray = (0, _core().template)(`
for (var KEY = 0, NAME = ARR; KEY < NAME.length; KEY++) BODY;
`);
const buildForOfLoose = (0, _core().template)(`
for (var LOOP_OBJECT = OBJECT,
IS_ARRAY = Array.isArray(LOOP_OBJECT),
INDEX = 0,
LOOP_OBJECT = IS_ARRAY ? LOOP_OBJECT : LOOP_OBJECT[Symbol.iterator]();;) {
INTERMEDIATE;
if (IS_ARRAY) {
if (INDEX >= LOOP_OBJECT.length) break;
ID = LOOP_OBJECT[INDEX++];
} else {
INDEX = LOOP_OBJECT.next();
if (INDEX.done) break;
ID = INDEX.value;
}
}
`);
const buildForOf = (0, _core().template)(`
var ITERATOR_COMPLETION = true;
var ITERATOR_HAD_ERROR_KEY = false;
var ITERATOR_ERROR_KEY = undefined;
try {
for (
var ITERATOR_KEY = OBJECT[Symbol.iterator](), STEP_KEY;
!(ITERATOR_COMPLETION = (STEP_KEY = ITERATOR_KEY.next()).done);
ITERATOR_COMPLETION = true
) {}
} catch (err) {
ITERATOR_HAD_ERROR_KEY = true;
ITERATOR_ERROR_KEY = err;
} finally {
try {
if (!ITERATOR_COMPLETION && ITERATOR_KEY.return != null) {
ITERATOR_KEY.return();
}
} finally {
if (ITERATOR_HAD_ERROR_KEY) {
throw ITERATOR_ERROR_KEY;
}
}
}
`);
function _ForOfStatementArray(path) {
const {
node,
scope
} = path;
const right = scope.generateUidIdentifierBasedOnNode(node.right, "arr");
const iterationKey = scope.generateUidIdentifier("i");
let loop = buildForOfArray({
BODY: node.body,
KEY: iterationKey,
NAME: right,
ARR: node.right
});
_core().types.inherits(loop, node);
_core().types.ensureBlock(loop);
const iterationValue = _core().types.memberExpression(_core().types.cloneNode(right), _core().types.cloneNode(iterationKey), true);
const left = node.left;
if (_core().types.isVariableDeclaration(left)) {
left.declarations[0].init = iterationValue;
loop.body.body.unshift(left);
} else {
loop.body.body.unshift(_core().types.expressionStatement(_core().types.assignmentExpression("=", left, iterationValue)));
}
if (path.parentPath.isLabeledStatement()) {
loop = _core().types.labeledStatement(path.parentPath.node.label, loop);
}
return [loop];
}
function replaceWithArray(path) {
if (path.parentPath.isLabeledStatement()) {
path.parentPath.replaceWithMultiple(_ForOfStatementArray(path));
} else {
path.replaceWithMultiple(_ForOfStatementArray(path));
}
}
return {
name: "transform-for-of",
visitor: {
ForOfStatement(path, state) {
const right = path.get("right");
if (right.isArrayExpression() || right.isGenericType("Array") || _core().types.isArrayTypeAnnotation(right.getTypeAnnotation())) {
replaceWithArray(path);
return;
}
const {
node
} = path;
const build = pushComputedProps(path, state);
const declar = build.declar;
const loop = build.loop;
const block = loop.body;
path.ensureBlock();
if (declar) {
block.body.push(declar);
}
block.body = block.body.concat(node.body.body);
_core().types.inherits(loop, node);
_core().types.inherits(loop.body, node.body);
if (build.replaceParent) {
path.parentPath.replaceWithMultiple(build.node);
path.remove();
} else {
path.replaceWithMultiple(build.node);
}
}
}
};
function pushComputedPropsLoose(path, file) {
const {
node,
scope,
parent
} = path;
const {
left
} = node;
let declar, id, intermediate;
if (_core().types.isIdentifier(left) || _core().types.isPattern(left) || _core().types.isMemberExpression(left)) {
id = left;
intermediate = null;
} else if (_core().types.isVariableDeclaration(left)) {
id = scope.generateUidIdentifier("ref");
declar = _core().types.variableDeclaration(left.kind, [_core().types.variableDeclarator(left.declarations[0].id, _core().types.identifier(id.name))]);
intermediate = _core().types.variableDeclaration("var", [_core().types.variableDeclarator(_core().types.identifier(id.name))]);
} else {
throw file.buildCodeFrameError(left, `Unknown node type ${left.type} in ForStatement`);
}
const iteratorKey = scope.generateUidIdentifier("iterator");
const isArrayKey = scope.generateUidIdentifier("isArray");
const loop = buildForOfLoose({
LOOP_OBJECT: iteratorKey,
IS_ARRAY: isArrayKey,
OBJECT: node.right,
INDEX: scope.generateUidIdentifier("i"),
ID: id,
INTERMEDIATE: intermediate
});
const isLabeledParent = _core().types.isLabeledStatement(parent);
let labeled;
if (isLabeledParent) {
labeled = _core().types.labeledStatement(parent.label, loop);
}
return {
replaceParent: isLabeledParent,
declar: declar,
node: labeled || loop,
loop: loop
};
}
function pushComputedPropsSpec(path, file) {
const {
node,
scope,
parent
} = path;
const left = node.left;
let declar;
const stepKey = scope.generateUid("step");
const stepValue = _core().types.memberExpression(_core().types.identifier(stepKey), _core().types.identifier("value"));
if (_core().types.isIdentifier(left) || _core().types.isPattern(left) || _core().types.isMemberExpression(left)) {
declar = _core().types.expressionStatement(_core().types.assignmentExpression("=", left, stepValue));
} else if (_core().types.isVariableDeclaration(left)) {
declar = _core().types.variableDeclaration(left.kind, [_core().types.variableDeclarator(left.declarations[0].id, stepValue)]);
} else {
throw file.buildCodeFrameError(left, `Unknown node type ${left.type} in ForStatement`);
}
const template = buildForOf({
ITERATOR_HAD_ERROR_KEY: scope.generateUidIdentifier("didIteratorError"),
ITERATOR_COMPLETION: scope.generateUidIdentifier("iteratorNormalCompletion"),
ITERATOR_ERROR_KEY: scope.generateUidIdentifier("iteratorError"),
ITERATOR_KEY: scope.generateUidIdentifier("iterator"),
STEP_KEY: _core().types.identifier(stepKey),
OBJECT: node.right
});
const isLabeledParent = _core().types.isLabeledStatement(parent);
const tryBody = template[3].block.body;
const loop = tryBody[0];
if (isLabeledParent) {
tryBody[0] = _core().types.labeledStatement(parent.label, loop);
}
return {
replaceParent: isLabeledParent,
declar: declar,
loop: loop,
node: template
};
}
});
exports.default = _default;
\ No newline at end of file
{
"name": "@babel/plugin-transform-for-of",
"version": "7.4.4",
"description": "Compile ES2015 for...of to ES5",
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-for-of",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"main": "lib/index.js",
"keywords": [
"babel-plugin"
],
"dependencies": {
"@babel/helper-plugin-utils": "^7.0.0"
},
"peerDependencies": {
"@babel/core": "^7.0.0-0"
},
"devDependencies": {
"@babel/core": "^7.4.4",
"@babel/helper-plugin-test-runner": "^7.0.0"
},
"gitHead": "2c88694388831b1e5b88e4bbed6781eb2be1edba"
}
MIT License
Copyright (c) 2014-present Sebastian McKenzie and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# @babel/plugin-transform-function-name
> Apply ES2015 function.name semantics to all functions
See our website [@babel/plugin-transform-function-name](https://babeljs.io/docs/en/next/babel-plugin-transform-function-name.html) for more information.
## Install
Using npm:
```sh
npm install --save-dev @babel/plugin-transform-function-name
```
or using yarn:
```sh
yarn add @babel/plugin-transform-function-name --dev
```
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _helperPluginUtils = require("@babel/helper-plugin-utils");
var _helperFunctionName = _interopRequireDefault(require("@babel/helper-function-name"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _default = (0, _helperPluginUtils.declare)(api => {
api.assertVersion(7);
return {
name: "transform-function-name",
visitor: {
FunctionExpression: {
exit(path) {
if (path.key !== "value" && !path.parentPath.isObjectProperty()) {
const replacement = (0, _helperFunctionName.default)(path);
if (replacement) path.replaceWith(replacement);
}
}
},
ObjectProperty(path) {
const value = path.get("value");
if (value.isFunction()) {
const newNode = (0, _helperFunctionName.default)(value);
if (newNode) value.replaceWith(newNode);
}
}
}
};
});
exports.default = _default;
\ No newline at end of file
{
"name": "@babel/plugin-transform-function-name",
"version": "7.7.0",
"description": "Apply ES2015 function.name semantics to all functions",
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-function-name",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"main": "lib/index.js",
"keywords": [
"babel-plugin"
],
"dependencies": {
"@babel/helper-function-name": "^7.7.0",
"@babel/helper-plugin-utils": "^7.0.0"
},
"peerDependencies": {
"@babel/core": "^7.0.0-0"
},
"devDependencies": {
"@babel/core": "^7.7.0",
"@babel/helper-plugin-test-runner": "^7.0.0"
},
"gitHead": "97faa83953cb87e332554fa559a4956d202343ea"
}
MIT License
Copyright (c) 2014-2018 Sebastian McKenzie and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# @babel/plugin-transform-literals
> Compile ES2015 unicode string and number literals to ES5
See our website [@babel/plugin-transform-literals](https://babeljs.io/docs/en/next/babel-plugin-transform-literals.html) for more information.
## Install
Using npm:
```sh
npm install --save-dev @babel/plugin-transform-literals
```
or using yarn:
```sh
yarn add @babel/plugin-transform-literals --dev
```
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
function _helperPluginUtils() {
const data = require("@babel/helper-plugin-utils");
_helperPluginUtils = function () {
return data;
};
return data;
}
var _default = (0, _helperPluginUtils().declare)(api => {
api.assertVersion(7);
return {
name: "transform-literals",
visitor: {
NumericLiteral({
node
}) {
if (node.extra && /^0[ob]/i.test(node.extra.raw)) {
node.extra = undefined;
}
},
StringLiteral({
node
}) {
if (node.extra && /\\[u]/gi.test(node.extra.raw)) {
node.extra = undefined;
}
}
}
};
});
exports.default = _default;
\ No newline at end of file
{
"name": "@babel/plugin-transform-literals",
"version": "7.2.0",
"description": "Compile ES2015 unicode string and number literals to ES5",
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-literals",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"main": "lib/index.js",
"keywords": [
"babel-plugin"
],
"dependencies": {
"@babel/helper-plugin-utils": "^7.0.0"
},
"peerDependencies": {
"@babel/core": "^7.0.0-0"
},
"devDependencies": {
"@babel/core": "^7.2.0",
"@babel/helper-plugin-test-runner": "^7.0.0"
}
}
MIT License
Copyright (c) 2014-present Sebastian McKenzie and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# @babel/plugin-transform-modules-amd
> This plugin transforms ES2015 modules to AMD
See our website [@babel/plugin-transform-modules-amd](https://babeljs.io/docs/en/next/babel-plugin-transform-modules-amd.html) for more information.
## Install
Using npm:
```sh
npm install --save-dev @babel/plugin-transform-modules-amd
```
or using yarn:
```sh
yarn add @babel/plugin-transform-modules-amd --dev
```
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
function _helperPluginUtils() {
const data = require("@babel/helper-plugin-utils");
_helperPluginUtils = function () {
return data;
};
return data;
}
function _helperModuleTransforms() {
const data = require("@babel/helper-module-transforms");
_helperModuleTransforms = function () {
return data;
};
return data;
}
function _core() {
const data = require("@babel/core");
_core = function () {
return data;
};
return data;
}
function _utils() {
const data = require("babel-plugin-dynamic-import-node/utils");
_utils = function () {
return data;
};
return data;
}
const buildWrapper = (0, _core().template)(`
define(MODULE_NAME, AMD_ARGUMENTS, function(IMPORT_NAMES) {
})
`);
const buildAnonymousWrapper = (0, _core().template)(`
define(["require"], function(REQUIRE) {
})
`);
function injectWrapper(path, wrapper) {
const {
body,
directives
} = path.node;
path.node.directives = [];
path.node.body = [];
const amdWrapper = path.pushContainer("body", wrapper)[0];
const amdFactory = amdWrapper.get("expression.arguments").filter(arg => arg.isFunctionExpression())[0].get("body");
amdFactory.pushContainer("directives", directives);
amdFactory.pushContainer("body", body);
}
var _default = (0, _helperPluginUtils().declare)((api, options) => {
api.assertVersion(7);
const {
loose,
allowTopLevelThis,
strict,
strictMode,
noInterop
} = options;
return {
name: "transform-modules-amd",
pre() {
this.file.set("@babel/plugin-transform-modules-*", "amd");
},
visitor: {
CallExpression(path, state) {
if (!this.file.has("@babel/plugin-proposal-dynamic-import")) return;
if (!path.get("callee").isImport()) return;
let {
requireId,
resolveId,
rejectId
} = state;
if (!requireId) {
requireId = path.scope.generateUidIdentifier("require");
state.requireId = requireId;
}
if (!resolveId || !rejectId) {
resolveId = path.scope.generateUidIdentifier("resolve");
rejectId = path.scope.generateUidIdentifier("reject");
state.resolveId = resolveId;
state.rejectId = rejectId;
}
let result = _core().types.identifier("imported");
if (!noInterop) result = (0, _helperModuleTransforms().wrapInterop)(path, result, "namespace");
path.replaceWith(_core().template.expression.ast`
new Promise((${resolveId}, ${rejectId}) =>
${requireId}(
[${(0, _utils().getImportSource)(_core().types, path.node)}],
imported => ${resolveId}(${result}),
${rejectId}
)
)`);
},
Program: {
exit(path, {
requireId
}) {
if (!(0, _helperModuleTransforms().isModule)(path)) {
if (requireId) {
injectWrapper(path, buildAnonymousWrapper({
REQUIRE: requireId
}));
}
return;
}
const amdArgs = [];
const importNames = [];
if (requireId) {
amdArgs.push(_core().types.stringLiteral("require"));
importNames.push(requireId);
}
let moduleName = this.getModuleName();
if (moduleName) moduleName = _core().types.stringLiteral(moduleName);
const {
meta,
headers
} = (0, _helperModuleTransforms().rewriteModuleStatementsAndPrepareHeader)(path, {
loose,
strict,
strictMode,
allowTopLevelThis,
noInterop
});
if ((0, _helperModuleTransforms().hasExports)(meta)) {
amdArgs.push(_core().types.stringLiteral("exports"));
importNames.push(_core().types.identifier(meta.exportName));
}
for (const [source, metadata] of meta.source) {
amdArgs.push(_core().types.stringLiteral(source));
importNames.push(_core().types.identifier(metadata.name));
if (!(0, _helperModuleTransforms().isSideEffectImport)(metadata)) {
const interop = (0, _helperModuleTransforms().wrapInterop)(path, _core().types.identifier(metadata.name), metadata.interop);
if (interop) {
const header = _core().types.expressionStatement(_core().types.assignmentExpression("=", _core().types.identifier(metadata.name), interop));
header.loc = metadata.loc;
headers.push(header);
}
}
headers.push(...(0, _helperModuleTransforms().buildNamespaceInitStatements)(meta, metadata, loose));
}
(0, _helperModuleTransforms().ensureStatementsHoisted)(headers);
path.unshiftContainer("body", headers);
injectWrapper(path, buildWrapper({
MODULE_NAME: moduleName,
AMD_ARGUMENTS: _core().types.arrayExpression(amdArgs),
IMPORT_NAMES: importNames
}));
}
}
}
};
});
exports.default = _default;
\ No newline at end of file
{
"name": "@babel/plugin-transform-modules-amd",
"version": "7.5.0",
"description": "This plugin transforms ES2015 modules to AMD",
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-modules-amd",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"main": "lib/index.js",
"dependencies": {
"@babel/helper-module-transforms": "^7.1.0",
"@babel/helper-plugin-utils": "^7.0.0",
"babel-plugin-dynamic-import-node": "^2.3.0"
},
"keywords": [
"babel-plugin"
],
"peerDependencies": {
"@babel/core": "^7.0.0-0"
},
"devDependencies": {
"@babel/core": "^7.5.0",
"@babel/helper-plugin-test-runner": "^7.0.0"
},
"gitHead": "49da9a07c81156e997e60146eb001ea77b7044c4"
}
MIT License
Copyright (c) 2014-present Sebastian McKenzie and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# @babel/plugin-transform-modules-commonjs
> This plugin transforms ES2015 modules to CommonJS
See our website [@babel/plugin-transform-modules-commonjs](https://babeljs.io/docs/en/next/babel-plugin-transform-modules-commonjs.html) for more information.
## Install
Using npm:
```sh
npm install --save-dev @babel/plugin-transform-modules-commonjs
```
or using yarn:
```sh
yarn add @babel/plugin-transform-modules-commonjs --dev
```
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _helperPluginUtils = require("@babel/helper-plugin-utils");
var _helperModuleTransforms = require("@babel/helper-module-transforms");
var _helperSimpleAccess = _interopRequireDefault(require("@babel/helper-simple-access"));
var _core = require("@babel/core");
var _utils = require("babel-plugin-dynamic-import-node/utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _default = (0, _helperPluginUtils.declare)((api, options) => {
api.assertVersion(7);
const transformImportCall = (0, _utils.createDynamicImportTransform)(api);
const {
loose,
strictNamespace = false,
mjsStrictNamespace = true,
allowTopLevelThis,
strict,
strictMode,
noInterop,
lazy = false,
allowCommonJSExports = true
} = options;
if (typeof lazy !== "boolean" && typeof lazy !== "function" && (!Array.isArray(lazy) || !lazy.every(item => typeof item === "string"))) {
throw new Error(`.lazy must be a boolean, array of strings, or a function`);
}
if (typeof strictNamespace !== "boolean") {
throw new Error(`.strictNamespace must be a boolean, or undefined`);
}
if (typeof mjsStrictNamespace !== "boolean") {
throw new Error(`.mjsStrictNamespace must be a boolean, or undefined`);
}
const getAssertion = localName => _core.template.expression.ast`
(function(){
throw new Error(
"The CommonJS '" + "${localName}" + "' variable is not available in ES6 modules." +
"Consider setting setting sourceType:script or sourceType:unambiguous in your " +
"Babel config for this file.");
})()
`;
const moduleExportsVisitor = {
ReferencedIdentifier(path) {
const localName = path.node.name;
if (localName !== "module" && localName !== "exports") return;
const localBinding = path.scope.getBinding(localName);
const rootBinding = this.scope.getBinding(localName);
if (rootBinding !== localBinding || path.parentPath.isObjectProperty({
value: path.node
}) && path.parentPath.parentPath.isObjectPattern() || path.parentPath.isAssignmentExpression({
left: path.node
}) || path.isAssignmentExpression({
left: path.node
})) {
return;
}
path.replaceWith(getAssertion(localName));
},
AssignmentExpression(path) {
const left = path.get("left");
if (left.isIdentifier()) {
const localName = path.node.name;
if (localName !== "module" && localName !== "exports") return;
const localBinding = path.scope.getBinding(localName);
const rootBinding = this.scope.getBinding(localName);
if (rootBinding !== localBinding) return;
const right = path.get("right");
right.replaceWith(_core.types.sequenceExpression([right.node, getAssertion(localName)]));
} else if (left.isPattern()) {
const ids = left.getOuterBindingIdentifiers();
const localName = Object.keys(ids).filter(localName => {
if (localName !== "module" && localName !== "exports") return false;
return this.scope.getBinding(localName) === path.scope.getBinding(localName);
})[0];
if (localName) {
const right = path.get("right");
right.replaceWith(_core.types.sequenceExpression([right.node, getAssertion(localName)]));
}
}
}
};
return {
name: "transform-modules-commonjs",
pre() {
this.file.set("@babel/plugin-transform-modules-*", "commonjs");
},
visitor: {
CallExpression(path) {
if (!this.file.has("@babel/plugin-proposal-dynamic-import")) return;
if (!path.get("callee").isImport()) return;
let {
scope
} = path;
do {
scope.rename("require");
} while (scope = scope.parent);
transformImportCall(this, path.get("callee"));
},
Program: {
exit(path, state) {
if (!(0, _helperModuleTransforms.isModule)(path)) return;
path.scope.rename("exports");
path.scope.rename("module");
path.scope.rename("require");
path.scope.rename("__filename");
path.scope.rename("__dirname");
if (!allowCommonJSExports) {
(0, _helperSimpleAccess.default)(path, new Set(["module", "exports"]));
path.traverse(moduleExportsVisitor, {
scope: path.scope
});
}
let moduleName = this.getModuleName();
if (moduleName) moduleName = _core.types.stringLiteral(moduleName);
const {
meta,
headers
} = (0, _helperModuleTransforms.rewriteModuleStatementsAndPrepareHeader)(path, {
exportName: "exports",
loose,
strict,
strictMode,
allowTopLevelThis,
noInterop,
lazy,
esNamespaceOnly: typeof state.filename === "string" && /\.mjs$/.test(state.filename) ? mjsStrictNamespace : strictNamespace
});
for (const [source, metadata] of meta.source) {
const loadExpr = _core.types.callExpression(_core.types.identifier("require"), [_core.types.stringLiteral(source)]);
let header;
if ((0, _helperModuleTransforms.isSideEffectImport)(metadata)) {
if (metadata.lazy) throw new Error("Assertion failure");
header = _core.types.expressionStatement(loadExpr);
} else {
const init = (0, _helperModuleTransforms.wrapInterop)(path, loadExpr, metadata.interop) || loadExpr;
if (metadata.lazy) {
header = _core.template.ast`
function ${metadata.name}() {
const data = ${init};
${metadata.name} = function(){ return data; };
return data;
}
`;
} else {
header = _core.template.ast`
var ${metadata.name} = ${init};
`;
}
}
header.loc = metadata.loc;
headers.push(header);
headers.push(...(0, _helperModuleTransforms.buildNamespaceInitStatements)(meta, metadata, loose));
}
(0, _helperModuleTransforms.ensureStatementsHoisted)(headers);
path.unshiftContainer("body", headers);
}
}
}
};
});
exports.default = _default;
\ No newline at end of file
{
"name": "@babel/plugin-transform-modules-commonjs",
"version": "7.7.0",
"description": "This plugin transforms ES2015 modules to CommonJS",
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-modules-commonjs",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"main": "lib/index.js",
"dependencies": {
"@babel/helper-module-transforms": "^7.7.0",
"@babel/helper-plugin-utils": "^7.0.0",
"@babel/helper-simple-access": "^7.7.0",
"babel-plugin-dynamic-import-node": "^2.3.0"
},
"keywords": [
"babel-plugin"
],
"peerDependencies": {
"@babel/core": "^7.0.0-0"
},
"devDependencies": {
"@babel/core": "^7.7.0",
"@babel/helper-plugin-test-runner": "^7.0.0",
"@babel/plugin-syntax-object-rest-spread": "^7.2.0"
},
"gitHead": "97faa83953cb87e332554fa559a4956d202343ea"
}
MIT License
Copyright (c) 2014-present Sebastian McKenzie and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment