fix(tsc-wrapped): report errors for invalid ast forms (#17994)

Fixes: #17993
This commit is contained in:
Chuck Jazdzewski 2017-07-13 15:55:59 -06:00 committed by Igor Minar
parent 4f1e4ffa4e
commit ce0f4f0d7c
2 changed files with 25 additions and 0 deletions

View File

@ -388,6 +388,9 @@ export class Evaluator {
if (isFoldableError(expression)) {
return recordEntry(expression, node);
}
if (!elementAccessExpression.argumentExpression) {
return recordEntry(errorSymbol('Expression form not supported', node), node);
}
const index = this.evaluateNode(elementAccessExpression.argumentExpression);
if (isFoldableError(expression)) {
return recordEntry(expression, node);

View File

@ -864,6 +864,28 @@ describe('Collector', () => {
const metadata = collector.getMetadata(source);
expect(metadata).toBeUndefined();
});
it('should be able to collect an invalid access expression', () => {
const source = createSource(`
import {Component} from '@angular/core';
const value = [];
@Component({
provider: [{provide: 'some token', useValue: value[]}]
})
export class MyComponent {}
`);
const metadata = collector.getMetadata(source);
expect(metadata.metadata.MyComponent).toEqual({
__symbolic: 'class',
decorators: [{
__symbolic: 'error',
message: 'Expression form not supported',
line: 5,
character: 55
}]
});
});
});
function override(fileName: string, content: string) {