fix(ivy): correctly resolve Array property access (#24664)

PR Close #24664
This commit is contained in:
George Kalpakas 2018-06-25 22:34:46 +03:00 committed by Miško Hevery
parent dcabb05102
commit 3d20c50156
2 changed files with 4 additions and 1 deletions

View File

@ -460,7 +460,7 @@ class StaticInterpreter {
}
} else if (Array.isArray(lhs)) {
if (rhs === 'length') {
return rhs.length;
return lhs.length;
}
if (typeof rhs !== 'number' || !Number.isInteger(rhs)) {
return DYNAMIC_VALUE;

View File

@ -112,6 +112,9 @@ describe('ngtsc metadata', () => {
it('array access works',
() => { expect(evaluate(`const a = [1, 2, 3];`, 'a[1] + a[0]')).toEqual(3); });
it('array `length` property access works',
() => { expect(evaluate(`const a = [1, 2, 3];`, 'a[\'length\'] + 1')).toEqual(4); });
it('negation works', () => {
expect(evaluate(`const x = 3;`, '!x')).toEqual(false);
expect(evaluate(`const x = 3;`, '!!x')).toEqual(true);