Browse Source

method call is assumed to mutate method owner (#13)

contingency-plan
Rich-Harris 10 years ago
parent
commit
d46d67f1c7
  1. 5
      src/Statement.js
  2. 3
      test/function/method-call-mutates-this/_config.js
  3. 15
      test/function/method-call-mutates-this/foo.js
  4. 3
      test/function/method-call-mutates-this/main.js

5
src/Statement.js

@ -188,6 +188,11 @@ export default class Statement {
else if ( node.type === 'CallExpression' ) {
node.arguments.forEach( arg => addNode( arg, false ) );
// `foo.bar()` is assumed to mutate foo
if ( node.callee.type === 'MemberExpression' ) {
addNode( node.callee );
}
}
}

3
test/function/method-call-mutates-this/_config.js

@ -0,0 +1,3 @@
module.exports = {
description: 'method calls are assumed to mutate the owner'
};

15
test/function/method-call-mutates-this/foo.js

@ -0,0 +1,15 @@
var obj = {
set: function ( key, value ) {
this[ key ] = value;
},
get: function ( key ) {
return this[ key ];
}
};
obj.set( 'answer', 42 );
export default function ( key ) {
return obj.get( key );
}

3
test/function/method-call-mutates-this/main.js

@ -0,0 +1,3 @@
import foo from './foo';
assert.equal( foo( 'answer' ), 42 );
Loading…
Cancel
Save