Skip to content

Commit 68082dd

Browse files
Merge pull request #5 from angular/master
Update upstream
2 parents 52e63cb + 2b0c050 commit 68082dd

File tree

6 files changed

+50
-31
lines changed

6 files changed

+50
-31
lines changed

src/.eslintrc.json

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"arrayRemove": false,
7070
"copy": false,
7171
"shallowCopy": false,
72+
"simpleCompare": false,
7273
"equals": false,
7374
"csp": false,
7475
"concat": false,

src/Angular.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
includes,
6363
arrayRemove,
6464
copy,
65+
simpleCompare,
6566
equals,
6667
csp,
6768
jq,
@@ -1024,6 +1025,10 @@ function copy(source, destination, maxDepth) {
10241025
}
10251026

10261027

1028+
// eslint-disable-next-line no-self-compare
1029+
function simpleCompare(a, b) { return a === b || (a !== a && b !== b); }
1030+
1031+
10271032
/**
10281033
* @ngdoc function
10291034
* @name angular.equals
@@ -1104,7 +1109,7 @@ function equals(o1, o2) {
11041109
}
11051110
} else if (isDate(o1)) {
11061111
if (!isDate(o2)) return false;
1107-
return equals(o1.getTime(), o2.getTime());
1112+
return simpleCompare(o1.getTime(), o2.getTime());
11081113
} else if (isRegExp(o1)) {
11091114
if (!isRegExp(o2)) return false;
11101115
return o1.toString() === o2.toString();

src/ng/compile.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -3434,8 +3434,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
34343434
if (parentGet.literal) {
34353435
compare = equals;
34363436
} else {
3437-
// eslint-disable-next-line no-self-compare
3438-
compare = function simpleCompare(a, b) { return a === b || (a !== a && b !== b); };
3437+
compare = simpleCompare;
34393438
}
34403439
parentSet = parentGet.assign || function() {
34413440
// reset the change, or we will throw this exception on every $digest
@@ -3510,9 +3509,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
35103509
});
35113510

35123511
function recordChanges(key, currentValue, previousValue) {
3513-
if (isFunction(destination.$onChanges) && currentValue !== previousValue &&
3514-
// eslint-disable-next-line no-self-compare
3515-
(currentValue === currentValue || previousValue === previousValue)) {
3512+
if (isFunction(destination.$onChanges) && !simpleCompare(currentValue, previousValue)) {
35163513
// If we have not already scheduled the top level onChangesQueue handler then do so now
35173514
if (!onChangesQueue) {
35183515
scope.$$postDigest(flushOnChangesQueue);

src/ng/directive/ngModel.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -890,8 +890,8 @@ function setupModelWatcher(ctrl) {
890890
// -> scope value did not change since the last digest as
891891
// ng-change executes in apply phase
892892
// 4. view should be changed back to 'a'
893-
ctrl.$$scope.$watch(function ngModelWatch() {
894-
var modelValue = ctrl.$$ngModelGet(ctrl.$$scope);
893+
ctrl.$$scope.$watch(function ngModelWatch(scope) {
894+
var modelValue = ctrl.$$ngModelGet(scope);
895895

896896
// if scope model value and ngModel value are out of sync
897897
// TODO(perf): why not move this to the action fn?

src/ng/parse.js

+15-23
Original file line numberDiff line numberDiff line change
@@ -769,15 +769,13 @@ function isConstant(ast) {
769769
return ast.constant;
770770
}
771771

772-
function ASTCompiler(astBuilder, $filter) {
773-
this.astBuilder = astBuilder;
772+
function ASTCompiler($filter) {
774773
this.$filter = $filter;
775774
}
776775

777776
ASTCompiler.prototype = {
778-
compile: function(expression) {
777+
compile: function(ast) {
779778
var self = this;
780-
var ast = this.astBuilder.ast(expression);
781779
this.state = {
782780
nextId: 0,
783781
filters: {},
@@ -832,8 +830,6 @@ ASTCompiler.prototype = {
832830
ifDefined,
833831
plusFn);
834832
this.state = this.stage = undefined;
835-
fn.literal = isLiteral(ast);
836-
fn.constant = isConstant(ast);
837833
return fn;
838834
},
839835

@@ -1236,15 +1232,13 @@ ASTCompiler.prototype = {
12361232
};
12371233

12381234

1239-
function ASTInterpreter(astBuilder, $filter) {
1240-
this.astBuilder = astBuilder;
1235+
function ASTInterpreter($filter) {
12411236
this.$filter = $filter;
12421237
}
12431238

12441239
ASTInterpreter.prototype = {
1245-
compile: function(expression) {
1240+
compile: function(ast) {
12461241
var self = this;
1247-
var ast = this.astBuilder.ast(expression);
12481242
findConstantAndWatchExpressions(ast, self.$filter);
12491243
var assignable;
12501244
var assign;
@@ -1283,8 +1277,6 @@ ASTInterpreter.prototype = {
12831277
if (inputs) {
12841278
fn.inputs = inputs;
12851279
}
1286-
fn.literal = isLiteral(ast);
1287-
fn.constant = isConstant(ast);
12881280
return fn;
12891281
},
12901282

@@ -1613,20 +1605,21 @@ ASTInterpreter.prototype = {
16131605
/**
16141606
* @constructor
16151607
*/
1616-
var Parser = function Parser(lexer, $filter, options) {
1617-
this.lexer = lexer;
1618-
this.$filter = $filter;
1619-
this.options = options;
1608+
function Parser(lexer, $filter, options) {
16201609
this.ast = new AST(lexer, options);
1621-
this.astCompiler = options.csp ? new ASTInterpreter(this.ast, $filter) :
1622-
new ASTCompiler(this.ast, $filter);
1623-
};
1610+
this.astCompiler = options.csp ? new ASTInterpreter($filter) :
1611+
new ASTCompiler($filter);
1612+
}
16241613

16251614
Parser.prototype = {
16261615
constructor: Parser,
16271616

16281617
parse: function(text) {
1629-
return this.astCompiler.compile(text);
1618+
var ast = this.ast.ast(text);
1619+
var fn = this.astCompiler.compile(ast);
1620+
fn.literal = isLiteral(ast);
1621+
fn.constant = isConstant(ast);
1622+
return fn;
16301623
}
16311624
};
16321625

@@ -1942,9 +1935,8 @@ function $ParseProvider() {
19421935

19431936
// Propagate $$watchDelegates other then inputsWatchDelegate
19441937
useInputs = !parsedExpression.inputs;
1945-
if (parsedExpression.$$watchDelegate &&
1946-
parsedExpression.$$watchDelegate !== inputsWatchDelegate) {
1947-
fn.$$watchDelegate = parsedExpression.$$watchDelegate;
1938+
if (watchDelegate && watchDelegate !== inputsWatchDelegate) {
1939+
fn.$$watchDelegate = watchDelegate;
19481940
fn.inputs = parsedExpression.inputs;
19491941
} else if (!interceptorFn.$stateful) {
19501942
// If there is an interceptor, but no watchDelegate then treat the interceptor like

test/ng/compileSpec.js

+24
Original file line numberDiff line numberDiff line change
@@ -5944,6 +5944,30 @@ describe('$compile', function() {
59445944
}));
59455945

59465946

5947+
// https://github.com/angular/angular.js/issues/15833
5948+
it('should work with ng-model inputs', function() {
5949+
var componentScope;
5950+
5951+
module(function($compileProvider) {
5952+
$compileProvider.directive('undi', function() {
5953+
return {
5954+
restrict: 'A',
5955+
scope: {
5956+
undi: '<'
5957+
},
5958+
link: function($scope) { componentScope = $scope; }
5959+
};
5960+
});
5961+
});
5962+
5963+
inject(function($compile, $rootScope) {
5964+
element = $compile('<form name="f" undi="[f.i]"><input name="i" ng-model="a"/></form>')($rootScope);
5965+
$rootScope.$apply();
5966+
expect(componentScope.undi).toBeDefined();
5967+
});
5968+
});
5969+
5970+
59475971
it('should not complain when the isolated scope changes', inject(function() {
59485972
compile('<div><span my-component ow-ref="{name: name}">');
59495973

0 commit comments

Comments
 (0)