babel-helper-module-transforms
Advanced tools
Comparing version 7.0.0-beta.1 to 7.0.0-beta.2
@@ -5,2 +5,3 @@ "use strict"; | ||
exports.isSideEffectImport = exports.hasExports = undefined; | ||
exports.isModule = isModule; | ||
exports.rewriteModuleStatementsAndPrepareHeader = rewriteModuleStatementsAndPrepareHeader; | ||
@@ -11,2 +12,6 @@ exports.ensureStatementsHoisted = ensureStatementsHoisted; | ||
var _assert = require("assert"); | ||
var _assert2 = _interopRequireDefault(_assert); | ||
var _babelTypes = require("babel-types"); | ||
@@ -36,9 +41,35 @@ | ||
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; } } | ||
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; } } | ||
exports.hasExports = _normalizeAndLoadMetadata.hasExports; | ||
exports.isSideEffectImport = _normalizeAndLoadMetadata.isSideEffectImport; | ||
function isModule(path, requireUnambiguous) { | ||
if (requireUnambiguous === void 0) { | ||
requireUnambiguous = false; | ||
} | ||
var sourceType = path.node.sourceType; | ||
if (sourceType !== "module" && sourceType !== "script") { | ||
throw path.buildCodeFrameError("Unknown sourceType \"" + sourceType + "\", cannot transform."); | ||
} | ||
var filename = path.hub.file.opts.filename; | ||
if (/\.mjs$/.test(filename)) { | ||
requireUnambiguous = false; | ||
} | ||
return path.node.sourceType === "module" && (!requireUnambiguous || isUnambiguousModule(path)); | ||
} | ||
function isUnambiguousModule(path) { | ||
return path.get("body").some(function (p) { | ||
return p.isModuleDeclaration(); | ||
}); | ||
} | ||
function rewriteModuleStatementsAndPrepareHeader(path, _ref) { | ||
@@ -51,2 +82,4 @@ var exportName = _ref.exportName, | ||
noInterop = _ref.noInterop; | ||
(0, _assert2.default)(isModule(path), "Cannot process module statements in a script"); | ||
path.node.sourceType = "script"; | ||
var meta = (0, _normalizeAndLoadMetadata2.default)(path, exportName, { | ||
@@ -53,0 +86,0 @@ noInterop: noInterop |
@@ -107,3 +107,2 @@ "use strict"; | ||
if (spec.isImportDefaultSpecifier()) { | ||
if (data.interop === "none") data.interop = "default"; | ||
var localName = spec.get("local").node.name; | ||
@@ -121,3 +120,2 @@ data.imports.set(localName, "default"); | ||
var _localName = spec.get("local").node.name; | ||
data.interop = "namespace"; | ||
data.importsNamespace.add(_localName); | ||
@@ -139,6 +137,2 @@ | ||
if (importName === "default" && data.interop === "none") { | ||
data.interop = "default"; | ||
} | ||
var _reexport2 = localData.get(_localName2); | ||
@@ -174,6 +168,2 @@ | ||
if (importName === "default" && _data2.interop === "none") { | ||
_data2.interop = "default"; | ||
} | ||
_data2.reexports.set(exportName, importName); | ||
@@ -187,2 +177,64 @@ | ||
}); | ||
for (var _iterator2 = sourceData.values(), _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var _ref6; | ||
if (_isArray2) { | ||
if (_i2 >= _iterator2.length) break; | ||
_ref6 = _iterator2[_i2++]; | ||
} else { | ||
_i2 = _iterator2.next(); | ||
if (_i2.done) break; | ||
_ref6 = _i2.value; | ||
} | ||
var _metadata2 = _ref6; | ||
if (_metadata2.importsNamespace.size > 0) { | ||
_metadata2.interop = "namespace"; | ||
continue; | ||
} | ||
var needsDefault = false; | ||
var needsNamed = false; | ||
for (var _iterator3 = _metadata2.imports.values(), _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { | ||
var _ref7; | ||
if (_isArray3) { | ||
if (_i3 >= _iterator3.length) break; | ||
_ref7 = _iterator3[_i3++]; | ||
} else { | ||
_i3 = _iterator3.next(); | ||
if (_i3.done) break; | ||
_ref7 = _i3.value; | ||
} | ||
var _importName2 = _ref7; | ||
if (_importName2 === "default") needsDefault = true;else needsNamed = true; | ||
} | ||
for (var _iterator4 = _metadata2.reexports.values(), _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) { | ||
var _ref8; | ||
if (_isArray4) { | ||
if (_i4 >= _iterator4.length) break; | ||
_ref8 = _iterator4[_i4++]; | ||
} else { | ||
_i4 = _iterator4.next(); | ||
if (_i4.done) break; | ||
_ref8 = _i4.value; | ||
} | ||
var _importName3 = _ref8; | ||
if (_importName3 === "default") needsDefault = true;else needsNamed = true; | ||
} | ||
if (needsDefault && needsNamed) { | ||
_metadata2.interop = "namespace"; | ||
} else if (needsDefault) { | ||
_metadata2.interop = "default"; | ||
} | ||
} | ||
return { | ||
@@ -189,0 +241,0 @@ local: localData, |
{ | ||
"name": "babel-helper-module-transforms", | ||
"version": "7.0.0-beta.1", | ||
"version": "7.0.0-beta.2", | ||
"description": "Babel helper functions for implementing ES6 module transformations", | ||
@@ -11,6 +11,6 @@ "author": "Logan Smyth <loganfsmyth@gmail.com>", | ||
"dependencies": { | ||
"babel-template": "7.0.0-beta.1", | ||
"babel-types": "7.0.0-beta.1", | ||
"babel-template": "7.0.0-beta.2", | ||
"babel-types": "7.0.0-beta.2", | ||
"lodash": "^4.2.0" | ||
} | ||
} |
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
37335
928
+ Addedbabel-code-frame@7.0.0-beta.2(transitive)
+ Addedbabel-helper-function-name@7.0.0-beta.2(transitive)
+ Addedbabel-helper-get-function-arity@7.0.0-beta.2(transitive)
+ Addedbabel-messages@7.0.0-beta.2(transitive)
+ Addedbabel-template@7.0.0-beta.2(transitive)
+ Addedbabel-traverse@7.0.0-beta.2(transitive)
+ Addedbabel-types@7.0.0-beta.2(transitive)
+ Addedbabylon@7.0.0-beta.25(transitive)
- Removedbabel-code-frame@7.0.0-beta.1(transitive)
- Removedbabel-helper-function-name@7.0.0-beta.1(transitive)
- Removedbabel-helper-get-function-arity@7.0.0-beta.1(transitive)
- Removedbabel-messages@7.0.0-beta.1(transitive)
- Removedbabel-template@7.0.0-beta.1(transitive)
- Removedbabel-traverse@7.0.0-beta.1(transitive)
- Removedbabel-types@7.0.0-beta.1(transitive)
- Removedbabylon@7.0.0-beta.22(transitive)
Updatedbabel-template@7.0.0-beta.2
Updatedbabel-types@7.0.0-beta.2