common-shakeify
Advanced tools
Comparing version 0.3.0 to 0.3.1
26
index.js
@@ -108,9 +108,21 @@ 'use strict' | ||
if (node.type === 'AssignmentExpression') { | ||
string.overwrite(node.start, node.right.start, | ||
commentify(`${node.left.getSource()} =`) + | ||
// Make sure we can't accidentally continue a previous statement. | ||
// eg in `exports.a = [0]` the `[0]` could continue a previous statement if that | ||
// did not have a semicolon. By putting `void ` in front we force a new statement. | ||
(node.parent.type === 'ExpressionStatement' ? ' void ' : ' ') | ||
) | ||
var prefix = commentify(`${node.left.getSource()} =`) + ' ' | ||
// Make sure we can't accidentally continue a previous statement. | ||
// eg in `exports.a = [0]` the `[0]` could continue a previous statement if that | ||
// did not have a semicolon. By putting `void ` in front we force a new statement. | ||
if (node.parent.type === 'ExpressionStatement') { | ||
prefix += 'void ' | ||
} | ||
// Anonymous function and class expressions are parsed as statements if they | ||
// are the first thing in a statement, which can happen if the `exports.xyz` | ||
// assignment happened inside a SequenceExpression (usually after minification). | ||
// eg: `exports.a=function(){},exports.b=function(){}` | ||
// Here if `exports.a` is removed we need to make sure the `function(){}` is still | ||
// an expression, by prepending `void 0,` to result in: | ||
// `void 0,function(){},exports.b=function(){}` | ||
var isPossiblyAmbiguousExpression = node.right.type === 'FunctionExpression' || node.right.type === 'ClassExpression' | ||
if (isPossiblyAmbiguousExpression && node.parent.type === 'SequenceExpression') { | ||
prefix += 'void 0, ' | ||
} | ||
string.overwrite(node.start, node.right.start, prefix) | ||
return | ||
@@ -117,0 +129,0 @@ } else if (node.type === 'Property') { |
{ | ||
"name": "common-shakeify", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "browserify tree shaking plugin using @indutny common-shake", | ||
@@ -5,0 +5,0 @@ "main": "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
22198
44
419
27