Comparing version 0.6.3 to 0.6.4
@@ -187,2 +187,11 @@ const {walk} = require("estree-walker"); | ||
function analyzeThisExpression() { | ||
if (context.scope) { | ||
const fnNode = context.scope.findFunction(); | ||
if (fnNode) { | ||
fnNode.containThis = true; | ||
} | ||
} | ||
} | ||
function analyze() { | ||
@@ -238,2 +247,4 @@ walk(context.ast, { | ||
analyzeNestedExports(node); | ||
} else if (node.type === "ThisExpression") { | ||
analyzeThisExpression(); | ||
} | ||
@@ -240,0 +251,0 @@ if (!context.nested && !context.topLevel.isTop()) { |
@@ -96,2 +96,3 @@ function createExportWriter(context) { | ||
context.hasDefaultComment(node) || | ||
node.exported.object.properties.some(p => p.value && p.value.containThis) || | ||
context.isExportPreferDefault() | ||
@@ -98,0 +99,0 @@ ) |
@@ -33,4 +33,5 @@ const {attachScopes} = require("rollup-pluginutils"); | ||
const rootScope = attachScopes(ast, "scope"); | ||
rootScope._node = ast; | ||
let scope = rootScope; | ||
return {enter, leave, has, isRootVar}; | ||
return {enter, leave, has, isRootVar, findFunction}; | ||
@@ -40,2 +41,3 @@ function enter(node) { | ||
scope = node.scope; | ||
scope._node = node; | ||
} | ||
@@ -59,2 +61,14 @@ } | ||
} | ||
function findFunction() { | ||
// exclude arrow functions | ||
let node = scope._node; | ||
while (node) { | ||
if (node.type === "FunctionExpression" || node.type === "FunctionDeclaration") { | ||
return node; | ||
} | ||
node = node.scope.parent && node.scope.parent._node; | ||
} | ||
return null; | ||
} | ||
} | ||
@@ -61,0 +75,0 @@ |
{ | ||
"name": "cjs-es", | ||
"version": "0.6.3", | ||
"version": "0.6.4", | ||
"description": "Transform CommonJS module into ES module.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -316,2 +316,6 @@ cjs-es | ||
* 0.6.4 (Jun 6, 2019) | ||
- Fix: export default if the object literal has function properties and the function contains `this`. | ||
* 0.6.3 (Jun 6, 2019) | ||
@@ -318,0 +322,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
50665
1236
434