Skip to content

Commit 69bd9ba

Browse files
committed
fix($parse): correctly assign expressions who's path is undefined and that use brackets notation
Closes angular#8039
1 parent 36831ec commit 69bd9ba

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

scripts/merge-pr-locally.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env node
2+
3+
var rewire = require('rewire'),
4+
shell = rewire('shelljs'),
5+
program = require('commander');
6+
7+
program
8+
.version('0.0.0')
9+
.option('-p, --pr', 'PR number')
10+
.option('-n, --not-tests', 'Ignore local tests')
11+
.parse(process.argv);
12+
13+
if (!program.pr) {
14+
console.log('PR number required and not provided')
15+
program.help();
16+
process.exit(1);
17+
}
18+
19+
var PR_NUMBER = program.pr,
20+
ORIGINAL_BRANCH= shell.exec('git rev-parse --abbrev-ref HEAD');
21+
22+
var stashed = false;
23+
if (shell.exec('git status -s --untracked-files=no', {silent: true}).output) {
24+
shell.exec('git stash');
25+
stashed = true;
26+
}
27+
28+
shell.exec('git fetch upstreamm pull/' + PR_NUMBER + '/head:pr/' + PR_NUMBER);
29+
shell.exec('git checkout pr/' + PR_NUMBER);
30+
31+
32+
shell.exec('git fetch upstream master');
33+
34+
if (shell.exec('grunt ci-checks tests').code === 0) {
35+
36+
}
37+
38+
if (stashed) {
39+
shell.exec('git stash pop');
40+
}

src/ng/parse.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,9 @@ Parser.prototype = {
683683
return getter(self || object(scope, locals));
684684
}, {
685685
assign: function(scope, value, locals) {
686-
return setter(object(scope, locals), field, value, parser.text);
686+
var o = object(scope, locals);
687+
if (!o) object.assign(scope, o = {});
688+
return setter(o, field, value, parser.text);
687689
}
688690
});
689691
},
@@ -708,6 +710,7 @@ Parser.prototype = {
708710
var key = indexFn(self, locals);
709711
// prevent overwriting of Function.constructor which would break ensureSafeObject check
710712
var safe = ensureSafeObject(obj(self, locals), parser.text);
713+
if (!safe) obj.assign(self, safe = {});
711714
return safe[key] = value;
712715
}
713716
});

test/ng/parseSpec.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -1069,14 +1069,30 @@ describe('parser', function() {
10691069
});
10701070

10711071

1072-
describe('assignable', function() {
1072+
ddescribe('assignable', function() {
10731073
it('should expose assignment function', inject(function($parse) {
10741074
var fn = $parse('a');
10751075
expect(fn.assign).toBeTruthy();
10761076
var scope = {};
10771077
fn.assign(scope, 123);
10781078
expect(scope).toEqual({a:123});
10791079
}));
1080+
1081+
it('should expose working assignment function for expressions ending with brackets', inject(function($parse) {
1082+
var fn = $parse('a.b["c"]');
1083+
expect(fn.assign).toBeTruthy();
1084+
var scope = {};
1085+
fn.assign(scope, 123);
1086+
expect(scope.a.b.c).toEqual(123);
1087+
}));
1088+
1089+
iit('should expose working assignment function for expressions with brackets in the middle', inject(function($parse) {
1090+
var fn = $parse('a["b"].c');
1091+
expect(fn.assign).toBeTruthy();
1092+
var scope = {};
1093+
fn.assign(scope, 123);
1094+
expect(scope.a.b.c).toEqual(123);
1095+
}));
10801096
});
10811097

10821098

0 commit comments

Comments
 (0)