Skip to content

Commit

Permalink
fix($parse): correctly assign expressions who's path is undefined and…
Browse files Browse the repository at this point in the history
… that use brackets notation

Closes angular#8039
  • Loading branch information
rodyhaddad committed Jul 8, 2014
1 parent 36831ec commit 69bd9ba
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
40 changes: 40 additions & 0 deletions scripts/merge-pr-locally.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env node

var rewire = require('rewire'),
shell = rewire('shelljs'),
program = require('commander');

program
.version('0.0.0')
.option('-p, --pr', 'PR number')
.option('-n, --not-tests', 'Ignore local tests')
.parse(process.argv);

if (!program.pr) {
console.log('PR number required and not provided')
program.help();
process.exit(1);
}

var PR_NUMBER = program.pr,
ORIGINAL_BRANCH= shell.exec('git rev-parse --abbrev-ref HEAD');

var stashed = false;
if (shell.exec('git status -s --untracked-files=no', {silent: true}).output) {
shell.exec('git stash');
stashed = true;
}

shell.exec('git fetch upstreamm pull/' + PR_NUMBER + '/head:pr/' + PR_NUMBER);
shell.exec('git checkout pr/' + PR_NUMBER);


shell.exec('git fetch upstream master');

if (shell.exec('grunt ci-checks tests').code === 0) {

}

if (stashed) {
shell.exec('git stash pop');
}
5 changes: 4 additions & 1 deletion src/ng/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,9 @@ Parser.prototype = {
return getter(self || object(scope, locals));
}, {
assign: function(scope, value, locals) {
return setter(object(scope, locals), field, value, parser.text);
var o = object(scope, locals);
if (!o) object.assign(scope, o = {});
return setter(o, field, value, parser.text);
}
});
},
Expand All @@ -708,6 +710,7 @@ Parser.prototype = {
var key = indexFn(self, locals);
// prevent overwriting of Function.constructor which would break ensureSafeObject check
var safe = ensureSafeObject(obj(self, locals), parser.text);
if (!safe) obj.assign(self, safe = {});
return safe[key] = value;
}
});
Expand Down
18 changes: 17 additions & 1 deletion test/ng/parseSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1069,14 +1069,30 @@ describe('parser', function() {
});


describe('assignable', function() {
ddescribe('assignable', function() {
it('should expose assignment function', inject(function($parse) {
var fn = $parse('a');
expect(fn.assign).toBeTruthy();
var scope = {};
fn.assign(scope, 123);
expect(scope).toEqual({a:123});
}));

it('should expose working assignment function for expressions ending with brackets', inject(function($parse) {
var fn = $parse('a.b["c"]');
expect(fn.assign).toBeTruthy();
var scope = {};
fn.assign(scope, 123);
expect(scope.a.b.c).toEqual(123);
}));

iit('should expose working assignment function for expressions with brackets in the middle', inject(function($parse) {
var fn = $parse('a["b"].c');
expect(fn.assign).toBeTruthy();
var scope = {};
fn.assign(scope, 123);
expect(scope.a.b.c).toEqual(123);
}));
});


Expand Down

0 comments on commit 69bd9ba

Please sign in to comment.