perf(ivy): speed up ngcc ivy switch processing (#25534)

Only parse the AST for ngcc ivy switch constants
if the marker is not found in the module text.

PR Close #25534
This commit is contained in:
Pete Bacon Darwin 2018-08-28 09:25:55 +01:00 committed by Misko Hevery
parent e964319fe9
commit 20b9c61d4c
1 changed files with 5 additions and 2 deletions

View File

@ -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) :
[];
}
/**