fix(ivy): evaluate non existing property access as undefined (#30738)
Closes #30726 PR Close #30738
This commit is contained in:
parent
4b16d98955
commit
f0395836b6
|
@ -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') {
|
||||||
|
|
|
@ -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');
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue