Browse Source

handle updates of parameters

rewrite
Rich-Harris 8 years ago
parent
commit
2295153964
  1. 3
      src/ast/nodes/UpdateExpression.js
  2. 3
      test/function/reassign-parameter/_config.js
  3. 7
      test/function/reassign-parameter/main.js

3
src/ast/nodes/UpdateExpression.js

@ -14,8 +14,11 @@ export default class UpdateExpression extends Node {
if ( subject.type === 'Identifier' ) {
const declaration = scope.findDeclaration( subject.name );
declaration.isReassigned = true;
if ( declaration.possibleValues ) {
declaration.possibleValues.add( NUMBER );
}
}
super.bind( scope );
}

3
test/function/reassign-parameter/_config.js

@ -0,0 +1,3 @@
module.exports = {
description: 'parameters can be reassigned/updated'
};

7
test/function/reassign-parameter/main.js

@ -0,0 +1,7 @@
function numbers ( i ) {
var array = new Array( i );
while ( i-- ) array[i] = i + 1;
return array;
}
assert.deepEqual( numbers( 5 ), [ 1, 2, 3, 4, 5 ] );
Loading…
Cancel
Save