babel-plugin-dynamic-import-node
Advanced tools
Comparing version 2.3.2 to 2.3.3
## Unreleased | ||
## v2.3.3 | ||
- [Fix] Generate webpack-compatible output with static string arg (#84) | ||
- [Fix] Handle visiting the same path gracefully (#71) | ||
## v2.3.2 | ||
@@ -4,0 +8,0 @@ - [Fix] avoid using reserved param name in babel 7 templates |
@@ -30,12 +30,35 @@ 'use strict'; | ||
var buildImport = template('Promise.resolve(SOURCE).then(s => INTEROP(require(s)))'); | ||
var buildImportNoInterop = template('Promise.resolve(SOURCE).then(s => require(s))'); | ||
var builders = { | ||
'static': { | ||
interop: template('Promise.resolve().then(() => INTEROP(require(SOURCE)))'), | ||
noInterop: template('Promise.resolve().then(() => require(SOURCE))') | ||
}, | ||
dynamic: { | ||
interop: template('Promise.resolve(SOURCE).then(s => INTEROP(require(s)))'), | ||
noInterop: template('Promise.resolve(SOURCE).then(s => require(s))') | ||
} | ||
}; | ||
var visited = typeof WeakSet === 'function' && new WeakSet(); | ||
var isString = function isString(node) { | ||
return t.isStringLiteral(node) || t.isTemplateLiteral(node) && node.expressions.length === 0; | ||
}; | ||
return function (context, path) { | ||
if (visited) { | ||
if (visited.has(path)) { | ||
return; | ||
} | ||
visited.add(path); | ||
} | ||
var SOURCE = getImportSource(t, path.parent); | ||
var newImport = context.opts.noInterop ? buildImportNoInterop({ SOURCE: SOURCE }) : buildImport({ SOURCE: SOURCE, INTEROP: context.addHelper('interopRequireWildcard') }); | ||
var builder = isString(SOURCE) ? builders['static'] : builders.dynamic; | ||
var newImport = context.opts.noInterop ? builder.noInterop({ SOURCE: SOURCE }) : builder.interop({ SOURCE: SOURCE, INTEROP: context.addHelper('interopRequireWildcard') }); | ||
path.parentPath.replaceWith(newImport); | ||
}; | ||
} |
{ | ||
"name": "babel-plugin-dynamic-import-node", | ||
"version": "2.3.2", | ||
"version": "2.3.3", | ||
"description": "Babel plugin to transpile import() to a deferred require(), for node", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
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
12364
81