Browse Source

strawman fix for #953

gh-953
Rich-Harris 8 years ago
parent
commit
94536ca2ad
  1. 17
      src/ast/nodes/shared/isUsedByBundle.js
  2. 3
      test/function/mutate-aliased-property/_config.js
  3. 14
      test/function/mutate-aliased-property/main.js

17
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;

3
test/function/mutate-aliased-property/_config.js

@ -0,0 +1,3 @@
module.exports = {
// solo: true
};

14
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' );
Loading…
Cancel
Save