fix(ivy): evaluate non existing property access as undefined (#30738)

Closes #30726

PR Close #30738
This commit is contained in:
Matt Lewis 2019-05-29 16:39:27 -04:00 committed by Kara Erickson
parent 4b16d98955
commit f0395836b6
2 changed files with 4 additions and 1 deletions

View File

@ -329,7 +329,7 @@ export class StaticInterpreter {
if (lhs.has(strIndex)) { if (lhs.has(strIndex)) {
return lhs.get(strIndex) !; return lhs.get(strIndex) !;
} else { } else {
throw new Error(`Invalid map access: [${Array.from(lhs.keys())}] dot ${rhs}`); return undefined;
} }
} else if (Array.isArray(lhs)) { } else if (Array.isArray(lhs)) {
if (rhs === 'length') { if (rhs === 'length') {

View File

@ -39,6 +39,9 @@ describe('ngtsc metadata', () => {
it('map access works', it('map access works',
() => { expect(evaluate('const obj = {a: "test"};', 'obj.a')).toEqual('test'); }); () => { expect(evaluate('const obj = {a: "test"};', 'obj.a')).toEqual('test'); });
it('resolves undefined property access',
() => { expect(evaluate('const obj: any = {}', 'obj.bar')).toEqual(undefined); });
it('function calls work', () => { it('function calls work', () => {
expect(evaluate(`function foo(bar) { return bar; }`, 'foo("test")')).toEqual('test'); expect(evaluate(`function foo(bar) { return bar; }`, 'foo("test")')).toEqual('test');
}); });