Skip to content

Commit 9c9c4a7

Browse files
committed
refactor($parse): remove support for locals in input watchers
1 parent 144d899 commit 9c9c4a7

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/ng/parse.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,7 @@ ASTCompiler.prototype = {
726726
findConstantAndWatchExpressions(ast.body[i].expression, this.$filter);
727727
}
728728
var toWatch = useInputs(ast.body) ? ast.body[ast.body.length - 1].expression.toWatch : [];
729+
self.stage = 'inputs';
729730
forEach(toWatch, function(watch, key) {
730731
var fnKey = 'fn' + key;
731732
self.state[fnKey] = {vars: [], body: [], own: {}};
@@ -736,6 +737,7 @@ ASTCompiler.prototype = {
736737
self.state.inputs.push(fnKey);
737738
watch.watchId = key;
738739
});
740+
self.stage = 'main';
739741
this.state.computing = 'fn';
740742
for (i = 0; i < ast.body.length; ++i) {
741743
if (lastExpression) this.current().body.push(lastExpression, ';');
@@ -744,6 +746,7 @@ ASTCompiler.prototype = {
744746
if (lastExpression) this.return(lastExpression);
745747
var extra = '';
746748
if (ast.body.length === 1 && isAssignable(ast.body[0].expression)) {
749+
self.stage = 'assign';
747750
this.state.computing = 'assign';
748751
var result = this.nextId();
749752
this.recurse({type: AST.AssignmentExpression, left: ast.body[0].expression, right: {type: AST.NGValueParameter}, operator: '='}, result);
@@ -794,7 +797,7 @@ ASTCompiler.prototype = {
794797
isLiteral,
795798
isConstant);
796799
/* jshint +W054 */
797-
this.state = undefined;
800+
this.state = this.stage = undefined;
798801
return fn;
799802
},
800803

@@ -808,7 +811,7 @@ ASTCompiler.prototype = {
808811
var self = this;
809812
forEach(fns, function(name) {
810813
result.push(
811-
'var ' + name + ' = function(s,l){' +
814+
'var ' + name + ' = function(s){' +
812815
self.varsPrefix(name) +
813816
self.body(name) +
814817
'};');
@@ -893,13 +896,13 @@ ASTCompiler.prototype = {
893896
case AST.Identifier:
894897
intoId = intoId || this.nextId();
895898
if (nameId) {
896-
nameId.context = this.assign(this.nextId(), this.getHasOwnProperty('l', ast.name), '?l:s');
899+
nameId.context = self.stage === 'inputs' ? 's' : this.assign(this.nextId(), this.getHasOwnProperty('l', ast.name), '?l:s');
897900
nameId.computed = false;
898901
nameId.name = ast.name;
899902
}
900903
this.if(isDefined(ast.watchId) ? '!i' : true, function() {
901904
ensureSafeMemberName(ast.name);
902-
self.if(self.not(self.getHasOwnProperty('l', ast.name)),
905+
self.if(self.stage === 'inputs' || self.not(self.getHasOwnProperty('l', ast.name)),
903906
function() {
904907
self.if('s', function() {
905908
if (create && create !== 1) {

0 commit comments

Comments
 (0)