@babel/plugin-transform-modules-commonjs
Advanced tools
Comparing version 7.0.0-beta.35 to 7.0.0-beta.36
@@ -12,3 +12,5 @@ "use strict"; | ||
var _templateObject = _taggedTemplateLiteralLoose(["\n (function(){\n throw new Error(\"The CommonJS '\" + \"", "\" + \"' variable is not available in ES6 modules.\");\n })()\n "], ["\n (function(){\n throw new Error(\"The CommonJS '\" + \"", "\" + \"' variable is not available in ES6 modules.\");\n })()\n "]); | ||
var _templateObject = _taggedTemplateLiteralLoose(["\n (function(){\n throw new Error(\"The CommonJS '\" + \"", "\" + \"' variable is not available in ES6 modules.\");\n })()\n "], ["\n (function(){\n throw new Error(\"The CommonJS '\" + \"", "\" + \"' variable is not available in ES6 modules.\");\n })()\n "]), | ||
_templateObject2 = _taggedTemplateLiteralLoose(["\n function ", "() {\n const data = ", ";\n ", " = function(){ return data; };\n return data;\n }\n "], ["\n function ", "() {\n const data = ", ";\n ", " = function(){ return data; };\n return data;\n }\n "]), | ||
_templateObject3 = _taggedTemplateLiteralLoose(["\n var ", " = ", ";\n "], ["\n var ", " = ", ";\n "]); | ||
@@ -25,5 +27,13 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
noInterop = options.noInterop, | ||
_options$lazy = options.lazy, | ||
lazy = _options$lazy === void 0 ? false : _options$lazy, | ||
_options$allowCommonJ = options.allowCommonJSExports, | ||
allowCommonJSExports = _options$allowCommonJ === void 0 ? true : _options$allowCommonJ; | ||
if (typeof lazy !== "boolean" && typeof lazy !== "function" && (!Array.isArray(lazy) || !lazy.every(function (item) { | ||
return typeof item === "string"; | ||
}))) { | ||
throw new Error(".lazy must be a boolean, array of strings, or a function"); | ||
} | ||
var getAssertion = function getAssertion(localName) { | ||
@@ -107,3 +117,4 @@ return _core.template.expression.ast(_templateObject, localName); | ||
allowTopLevelThis: allowTopLevelThis, | ||
noInterop: noInterop | ||
noInterop: noInterop, | ||
lazy: lazy | ||
}), | ||
@@ -134,5 +145,12 @@ meta = _rewriteModuleStateme.meta, | ||
if ((0, _helperModuleTransforms.isSideEffectImport)(_metadata)) { | ||
if (_metadata.lazy) throw new Error("Assertion failure"); | ||
header = _core.types.expressionStatement(loadExpr); | ||
} else { | ||
header = _core.types.variableDeclaration("var", [_core.types.variableDeclarator(_core.types.identifier(_metadata.name), (0, _helperModuleTransforms.wrapInterop)(path, loadExpr, _metadata.interop) || loadExpr)]); | ||
var init = (0, _helperModuleTransforms.wrapInterop)(path, loadExpr, _metadata.interop) || loadExpr; | ||
if (_metadata.lazy) { | ||
header = _core.template.ast(_templateObject2, _metadata.name, init, _metadata.name); | ||
} else { | ||
header = _core.template.ast(_templateObject3, _metadata.name, init); | ||
} | ||
} | ||
@@ -139,0 +157,0 @@ |
{ | ||
"name": "@babel/plugin-transform-modules-commonjs", | ||
"version": "7.0.0-beta.35", | ||
"version": "7.0.0-beta.36", | ||
"description": "This plugin transforms ES2015 modules to CommonJS", | ||
@@ -9,4 +9,4 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-modules-commonjs", | ||
"dependencies": { | ||
"@babel/helper-module-transforms": "7.0.0-beta.35", | ||
"@babel/helper-simple-access": "7.0.0-beta.35" | ||
"@babel/helper-module-transforms": "7.0.0-beta.36", | ||
"@babel/helper-simple-access": "7.0.0-beta.36" | ||
}, | ||
@@ -17,9 +17,9 @@ "keywords": [ | ||
"peerDependencies": { | ||
"@babel/core": "7.0.0-beta.35" | ||
"@babel/core": "7.0.0-beta.36" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "7.0.0-beta.35", | ||
"@babel/helper-plugin-test-runner": "7.0.0-beta.35", | ||
"@babel/plugin-syntax-object-rest-spread": "7.0.0-beta.35" | ||
"@babel/core": "7.0.0-beta.36", | ||
"@babel/helper-plugin-test-runner": "7.0.0-beta.36", | ||
"@babel/plugin-syntax-object-rest-spread": "7.0.0-beta.36" | ||
} | ||
} |
@@ -71,6 +71,3 @@ # @babel/plugin-transform-modules-commonjs | ||
As per the spec, `import` and `export` are only allowed to be used at the top | ||
level. When in loose mode these are allowed to be used anywhere. | ||
And by default, when using exports with babel a non-enumerable `__esModule` property | ||
By default, when using exports with babel a non-enumerable `__esModule` property | ||
is exported. | ||
@@ -134,1 +131,35 @@ | ||
helper (shown in inline form above). | ||
### `lazy` | ||
`boolean`, `Array<string>`, or `(string) => boolean`, defaults to `false` | ||
Changes Babel's compiled `import` statements to be lazily evaluated when their | ||
imported bindings are used for the first time. | ||
This can improve initial load time of your module because evaluating | ||
dependencies up front is sometimes entirely un-necessary. This is especially | ||
the case when implementing a library module. | ||
The value of `lazy` has a few possible effects: | ||
* `false` - No lazy initialization of any imported module. | ||
* `true` - Do not lazy-initialize local `./foo` imports, but lazy-init `foo` dependencies. | ||
Local paths are much more likely to have circular dependencies, which may break if loaded lazily, | ||
so they are not lazy by default, whereas dependencies between independent modules are rarely cyclical. | ||
* `Array<string>` - Lazy-initialize all imports with source matching one of the given strings. | ||
* `(string) => boolean` - Pass a callback that will be called to decide if a given source string should be lazy-loaded. | ||
The two cases where imports can never be lazy are: | ||
* `import "foo";` | ||
Side-effect imports are automatically non-lazy since their very existence means | ||
that there is no binding to later kick off initialization. | ||
* `export * from "foo"` | ||
Re-exporting all names requires up-front execution because otherwise there is no | ||
way to know what names need to be exported. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11739
136
164
+ Added@babel/code-frame@7.0.0-beta.36(transitive)
+ Added@babel/core@7.0.0-beta.36(transitive)
+ Added@babel/generator@7.0.0-beta.36(transitive)
+ Added@babel/helper-function-name@7.0.0-beta.36(transitive)
+ Added@babel/helper-get-function-arity@7.0.0-beta.36(transitive)
+ Added@babel/helper-module-imports@7.0.0-beta.36(transitive)
+ Added@babel/helper-module-transforms@7.0.0-beta.36(transitive)
+ Added@babel/helper-simple-access@7.0.0-beta.36(transitive)
+ Added@babel/helpers@7.0.0-beta.36(transitive)
+ Added@babel/template@7.0.0-beta.36(transitive)
+ Added@babel/traverse@7.0.0-beta.36(transitive)
+ Added@babel/types@7.0.0-beta.36(transitive)
+ Addedbabylon@7.0.0-beta.36(transitive)
+ Addedglobals@11.12.0(transitive)
- Removed@babel/code-frame@7.0.0-beta.35(transitive)
- Removed@babel/core@7.0.0-beta.35(transitive)
- Removed@babel/generator@7.0.0-beta.35(transitive)
- Removed@babel/helper-function-name@7.0.0-beta.35(transitive)
- Removed@babel/helper-get-function-arity@7.0.0-beta.35(transitive)
- Removed@babel/helper-module-imports@7.0.0-beta.35(transitive)
- Removed@babel/helper-module-transforms@7.0.0-beta.35(transitive)
- Removed@babel/helper-simple-access@7.0.0-beta.35(transitive)
- Removed@babel/helpers@7.0.0-beta.35(transitive)
- Removed@babel/template@7.0.0-beta.35(transitive)
- Removed@babel/traverse@7.0.0-beta.35(transitive)
- Removed@babel/types@7.0.0-beta.35(transitive)
- Removedbabylon@7.0.0-beta.35(transitive)
- Removedglobals@10.4.0(transitive)