rollup-plugin-cjs-es
Advanced tools
Comparing version 0.2.0 to 0.2.1
50
index.js
@@ -64,12 +64,19 @@ const path = require("path"); | ||
if (options.splitCode) { | ||
const result = wrapImport({ | ||
code, | ||
parse, | ||
shouldSplitCode: importee => { | ||
if (typeof options.splitCode === "function") { | ||
return options.splitCode(id, importee); | ||
let result; | ||
try { | ||
result = wrapImport({ | ||
code, | ||
parse, | ||
shouldSplitCode: importee => { | ||
if (typeof options.splitCode === "function") { | ||
return options.splitCode(id, importee); | ||
} | ||
return false; | ||
} | ||
return false; | ||
} | ||
}); | ||
}); | ||
} catch (err) { | ||
const pos = err.node ? err.node.start : null; | ||
this.error(err, pos); | ||
return; | ||
} | ||
if (result.isTouched) { | ||
@@ -82,11 +89,18 @@ code = result.code; | ||
} | ||
const result = cjsEs({ | ||
code, | ||
parse, | ||
sourceMap: options.sourceMap, | ||
importStyle: requireId => getExportType(requireId, id), | ||
exportStyle: () => getExportType(id), | ||
hoist: options.hoist, | ||
dynamicImport: options.dynamicImport | ||
}); | ||
let result; | ||
try { | ||
result = cjsEs({ | ||
code, | ||
parse, | ||
sourceMap: options.sourceMap, | ||
importStyle: requireId => getExportType(requireId, id), | ||
exportStyle: () => getExportType(id), | ||
hoist: options.hoist, | ||
dynamicImport: options.dynamicImport | ||
}); | ||
} catch (err) { | ||
const pos = err.node ? err.node.start : null; | ||
this.error(err, pos); | ||
return; | ||
} | ||
if (result.isTouched) { | ||
@@ -93,0 +107,0 @@ code = result.code; |
@@ -54,7 +54,19 @@ const {walk} = require("estree-walker"); | ||
const scope = createScopeAnalyzer(ast); | ||
walk(ast, {enter(node) { | ||
if (node.type === "CallExpression") { | ||
isTouched = transformWrapImport({node, s, code, shouldSplitCode, scope}) || isTouched; | ||
let currentNode; | ||
function doWalk() { | ||
walk(ast, {enter(node) { | ||
currentNode = node; | ||
if (node.type === "CallExpression") { | ||
isTouched = transformWrapImport({node, s, code, shouldSplitCode, scope}) || isTouched; | ||
} | ||
}}); | ||
} | ||
try { | ||
doWalk(); | ||
} catch (err) { | ||
if (!err.node) { | ||
err.node = currentNode; | ||
} | ||
}}); | ||
throw err; | ||
} | ||
return { | ||
@@ -61,0 +73,0 @@ code: isTouched ? s.toString() : code, |
{ | ||
"name": "rollup-plugin-cjs-es", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Convert CommonJS module into ES module", | ||
@@ -30,3 +30,3 @@ "keywords": [ | ||
"dependencies": { | ||
"cjs-es": "^0.3.1", | ||
"cjs-es": "^0.3.2", | ||
"estree-walker": "^0.5.1", | ||
@@ -33,0 +33,0 @@ "magic-string": "^0.24.0", |
@@ -337,2 +337,7 @@ rollup-plugin-cjs-es | ||
* 0.2.1 (Apr 28, 2018) | ||
- Update cjs-es to 0.3.2. | ||
- Add: include pos while reporting errors. | ||
* 0.2.0 (Apr 28, 2018) | ||
@@ -339,0 +344,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
17083
235
350
Updatedcjs-es@^0.3.2