diff --git a/packages/compiler-cli/src/ngtsc/metadata/src/resolver.ts b/packages/compiler-cli/src/ngtsc/metadata/src/resolver.ts index e84c84b52e..9740d4e222 100644 --- a/packages/compiler-cli/src/ngtsc/metadata/src/resolver.ts +++ b/packages/compiler-cli/src/ngtsc/metadata/src/resolver.ts @@ -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; diff --git a/packages/compiler-cli/src/ngtsc/metadata/test/resolver_spec.ts b/packages/compiler-cli/src/ngtsc/metadata/test/resolver_spec.ts index 5498f4aa57..7a41ad3595 100644 --- a/packages/compiler-cli/src/ngtsc/metadata/test/resolver_spec.ts +++ b/packages/compiler-cli/src/ngtsc/metadata/test/resolver_spec.ts @@ -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);