fix(tsc-wrapped): support as and class expressions (#16904)

This commit is contained in:
Chuck Jazdzewski 2017-07-13 16:17:16 -06:00 committed by Igor Minar
parent 1bf7ba87a0
commit 45ffe54ae4
2 changed files with 20 additions and 0 deletions

View File

@ -647,6 +647,11 @@ export class Evaluator {
return result; return result;
}, this.evaluateNode(templateExpression.head)); }, this.evaluateNode(templateExpression.head));
} }
case ts.SyntaxKind.AsExpression:
const asExpression = <ts.AsExpression>node;
return this.evaluateNode(asExpression.expression);
case ts.SyntaxKind.ClassExpression:
return {__symbolic: 'class'};
} }
return recordEntry(errorSymbol('Expression form not supported', node), node); return recordEntry(errorSymbol('Expression form not supported', node), node);
} }

View File

@ -727,6 +727,21 @@ describe('Collector', () => {
}); });
}); });
it('should treat exported class expressions as a class', () => {
const source = ts.createSourceFile(
'', `
export const InjectionToken: {new<T>(desc: string): InjectionToken<T>;} = class extends OpaqueToken {
constructor(desc: string) {
super(desc);
}
toString(): string { return \`InjectionToken ${this._desc}\`; }
} as any;`,
ts.ScriptTarget.Latest, true);
const metadata = collector.getMetadata(source);
expect(metadata.metadata).toEqual({InjectionToken: {__symbolic: 'class'}});
});
describe('in strict mode', () => { describe('in strict mode', () => {
it('should throw if an error symbol is collecting a reference to a non-exported symbol', () => { it('should throw if an error symbol is collecting a reference to a non-exported symbol', () => {
const source = program.getSourceFile('/local-symbol-ref.ts'); const source = program.getSourceFile('/local-symbol-ref.ts');