From 45ffe54ae4b574d1469e60c9546c04fdbda9e8d7 Mon Sep 17 00:00:00 2001 From: Chuck Jazdzewski Date: Thu, 13 Jul 2017 16:17:16 -0600 Subject: [PATCH] fix(tsc-wrapped): support as and class expressions (#16904) --- tools/@angular/tsc-wrapped/src/evaluator.ts | 5 +++++ tools/@angular/tsc-wrapped/test/collector.spec.ts | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/tools/@angular/tsc-wrapped/src/evaluator.ts b/tools/@angular/tsc-wrapped/src/evaluator.ts index ee43f71b59..b8ec384dc0 100644 --- a/tools/@angular/tsc-wrapped/src/evaluator.ts +++ b/tools/@angular/tsc-wrapped/src/evaluator.ts @@ -647,6 +647,11 @@ export class Evaluator { return result; }, this.evaluateNode(templateExpression.head)); } + case ts.SyntaxKind.AsExpression: + const asExpression = node; + return this.evaluateNode(asExpression.expression); + case ts.SyntaxKind.ClassExpression: + return {__symbolic: 'class'}; } return recordEntry(errorSymbol('Expression form not supported', node), node); } diff --git a/tools/@angular/tsc-wrapped/test/collector.spec.ts b/tools/@angular/tsc-wrapped/test/collector.spec.ts index a83edd48c1..bc0a94dddf 100644 --- a/tools/@angular/tsc-wrapped/test/collector.spec.ts +++ b/tools/@angular/tsc-wrapped/test/collector.spec.ts @@ -727,6 +727,21 @@ describe('Collector', () => { }); }); + it('should treat exported class expressions as a class', () => { + const source = ts.createSourceFile( + '', ` + export const InjectionToken: {new(desc: string): InjectionToken;} = 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', () => { it('should throw if an error symbol is collecting a reference to a non-exported symbol', () => { const source = program.getSourceFile('/local-symbol-ref.ts');