From 94536ca2adfb017d4a74a51fade39d0a0282203a Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Sun, 18 Sep 2016 08:31:51 -0400 Subject: [PATCH] strawman fix for #953 --- src/ast/nodes/shared/isUsedByBundle.js | 17 +++-------------- .../function/mutate-aliased-property/_config.js | 3 +++ test/function/mutate-aliased-property/main.js | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 test/function/mutate-aliased-property/_config.js create mode 100644 test/function/mutate-aliased-property/main.js diff --git a/src/ast/nodes/shared/isUsedByBundle.js b/src/ast/nodes/shared/isUsedByBundle.js index 07e315f..b7209b5 100644 --- a/src/ast/nodes/shared/isUsedByBundle.js +++ b/src/ast/nodes/shared/isUsedByBundle.js @@ -3,22 +3,11 @@ import { UNKNOWN } from '../../values.js'; export default function isUsedByBundle ( scope, node ) { while ( node.type === 'ParenthesizedExpression' ) node = node.expression; - // const expression = node; - while ( node.type === 'MemberExpression' ) node = node.object; - - const declaration = scope.findDeclaration( node.name ); - - if ( declaration.isParam ) { - return true; - - // TODO if we mutate a parameter, assume the worst - // return node !== expression; - } - - if ( declaration.activated ) return true; + // TODO do we need to distinguish between assignments and mutations somehow? + if ( node.type === 'MemberExpression' ) node = node.object; const values = new Set(); - declaration.gatherPossibleValues( values ); + node.gatherPossibleValues( values ); for ( const value of values ) { if ( value === UNKNOWN ) { return true; diff --git a/test/function/mutate-aliased-property/_config.js b/test/function/mutate-aliased-property/_config.js new file mode 100644 index 0000000..700dff7 --- /dev/null +++ b/test/function/mutate-aliased-property/_config.js @@ -0,0 +1,3 @@ +module.exports = { + // solo: true +}; diff --git a/test/function/mutate-aliased-property/main.js b/test/function/mutate-aliased-property/main.js new file mode 100644 index 0000000..dfd5000 --- /dev/null +++ b/test/function/mutate-aliased-property/main.js @@ -0,0 +1,14 @@ +var Foo = (function() { + function Foo() {} + Foo.prototype.toString = function() { return 'foo'; }; + return Foo; +}()); + +var Bar = (function() { + function Bar() {} + Bar.prototype = Foo.prototype; + Bar.prototype.toString = function() { return 'bar'; }; + return Bar; +}()); + +assert.equal( new Foo().toString(), 'bar' );