From 29457cc25650f9c80c33ef91171ee5a0effe572b Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Tue, 28 Aug 2018 09:25:55 +0100 Subject: [PATCH] perf(ivy): speed up ngcc ivy switch processing Only parse the AST for ngcc ivy switch constants if the marker is not found in the module text. --- packages/compiler-cli/src/ngcc/src/host/fesm2015_host.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/compiler-cli/src/ngcc/src/host/fesm2015_host.ts b/packages/compiler-cli/src/ngcc/src/host/fesm2015_host.ts index 0f145b09e4453..f2b2ebccf7d4c 100644 --- a/packages/compiler-cli/src/ngcc/src/host/fesm2015_host.ts +++ b/packages/compiler-cli/src/ngcc/src/host/fesm2015_host.ts @@ -12,7 +12,7 @@ import {ClassMember, ClassMemberKind, CtorParameter, Decorator} from '../../../n import {TypeScriptReflectionHost, reflectObjectLiteral} from '../../../ngtsc/metadata'; import {findAll, getNameText} from '../utils'; -import {NgccReflectionHost, SwitchableVariableDeclaration, isSwitchableVariableDeclaration} from './ngcc_host'; +import {NgccReflectionHost, PRE_NGCC_MARKER, SwitchableVariableDeclaration, isSwitchableVariableDeclaration} from './ngcc_host'; export const DECORATORS = 'decorators' as ts.__String; export const PROP_DECORATORS = 'propDecorators' as ts.__String; @@ -205,7 +205,10 @@ export class Fesm2015ReflectionHost extends TypeScriptReflectionHost implements * @returns An array of variable declarations that match. */ getSwitchableDeclarations(module: ts.Node): SwitchableVariableDeclaration[] { - return findAll(module, isSwitchableVariableDeclaration); + // Don't bother to walk the AST if the marker is not found in the text + return module.getText().indexOf(PRE_NGCC_MARKER) >= 0 ? + findAll(module, isSwitchableVariableDeclaration) : + []; } /**