Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

$eval assignment expression and locals #4664

Closed
caiotoon opened this issue Oct 26, 2013 · 2 comments
Closed

$eval assignment expression and locals #4664

caiotoon opened this issue Oct 26, 2013 · 2 comments

Comments

@caiotoon
Copy link
Contributor

We can't use a local variable in the left side of an assignment without enclosing it in parenthesis to ensure it to be resolved first.

I tried to raise a discussion here in order to understand whether it's a bug or not but had not much success.

Basically, this test case won't succeed:

it('should allow passing object as locals to the left part of an assignment expression', inject(function($rootScope) {
  var ob = {};
  $rootScope.scopedValue = 1;
  $rootScope.$eval('a.value = scopedValue', {a: ob});
  expect(ob.value).toBe(1);
  expect($rootScope.a).toBeUndefined();
}));

While changing the expression to (a).value = scopedValue the test will succeed. Assembled a Plnkr here to illustrate it.

As I said before, I'm not sure if this is a bug or a limitation. If it's the later, then I think I could change the documentation to exemplify it. So, is this a bug or a expected limitation?

@IgorMinar
Copy link
Contributor

looks like a legit bug to me. it still repro's in 1.2.7 (http://plnkr.co/edit/2etyqSnPdzxvWEwrusqY?p=preview)

at first glance, I suspect that the problem is that we don't consider locals when doing assignment. the fix should be relatively straightforward.

check out this lines and notice how we don't consider locals during assignment but we do consider them in the getter:

angular.js/src/ng/parse.js

Lines 314 to 321 in e0ce9ed

var getter = getterFn(ident, this.options, this.text);
token.fn = extend(function(self, locals) {
return (getter(self, locals));
}, {
assign: function(self, value) {
return setter(self, ident, value, parser.text, parser.options);
}
});

would you like to send a PR (please include test)

PS: sorry for the delay and thanks for being patient

@btford btford removed the gh: issue label Aug 20, 2014
jbedard added a commit to jbedard/angular.js that referenced this issue Dec 4, 2014
jbedard added a commit to jbedard/angular.js that referenced this issue Dec 4, 2014
jbedard added a commit to jbedard/angular.js that referenced this issue Dec 5, 2014
jbedard added a commit to jbedard/angular.js that referenced this issue Dec 6, 2014
jbedard added a commit to jbedard/angular.js that referenced this issue Dec 6, 2014
@petebacondarwin petebacondarwin modified the milestones: Backlog, 1.4.x Dec 15, 2014
jbedard added a commit to jbedard/angular.js that referenced this issue Dec 15, 2014
@lgalfaso
Copy link
Contributor

This was fixed as part of #10592

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants