babel-plugin-transform-amd-to-commonjs
Advanced tools
Comparing version 0.2.1 to 0.2.2
16
build.js
@@ -52,4 +52,5 @@ 'use strict'; | ||
var isDefineCall = name === 'define'; | ||
if (name === 'define' && !t.isProgram(parent)) return; | ||
if (isDefineCall && !t.isProgram(parent)) return; | ||
@@ -68,5 +69,6 @@ var argumentDecoders = { | ||
if (!t.isArrayExpression(dependencyList) && !t.isFunctionExpression(factory)) return; | ||
if (!t.isArrayExpression(dependencyList) && !factory) return; | ||
var injectsModuleOrExports = false; | ||
var isFunctionFactory = t.isFunctionExpression(factory); | ||
var requireExpressions = []; | ||
@@ -86,3 +88,3 @@ | ||
} | ||
var paramName = factory && factory.params[i]; | ||
var paramName = isFunctionFactory && factory.params[i]; | ||
requireExpressions.push(createRequireExpression(el, paramName)); | ||
@@ -92,3 +94,3 @@ }); | ||
if (factory) { | ||
if (isFunctionFactory) { | ||
var factoryArity = factory.params.length; | ||
@@ -111,3 +113,3 @@ var replacementFuncExpr = t.functionExpression(null, [], t.blockStatement(requireExpressions.concat(factory.body.body))); | ||
injectsModuleOrExports = injectsModuleOrExports || !dependencyList && factoryArity > 1; | ||
if (name === 'define' && !injectsModuleOrExports) { | ||
if (isDefineCall && !injectsModuleOrExports) { | ||
path.replaceWith(createModuleExportsAssignmentExpression(factoryReplacement)); | ||
@@ -117,2 +119,6 @@ } else { | ||
} | ||
} else if (factory && isDefineCall) { | ||
var exportExpression = createModuleExportsAssignmentExpression(factory); | ||
var nodes = requireExpressions.concat(exportExpression); | ||
path.replaceWithMultiple(nodes); | ||
} else { | ||
@@ -119,0 +125,0 @@ path.replaceWithMultiple(requireExpressions); |
{ | ||
"name": "babel-plugin-transform-amd-to-commonjs", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "Transforms AMD code to CommonJS", | ||
@@ -5,0 +5,0 @@ "main": "build.js", |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
12497
103
0
5