fix(ivy): use a single constant pool per source file (#25392)

Previously, ngtsc used a new ConstantPool for each decorator
compilation. This could result in collisions between constants in the
top-level scope.

Now, ngtsc uses a single ConstantPool for each source file being
compiled, and merges the constant statements into the file after the
import section.

PR Close #25392
This commit is contained in:
Alex Rickabaugh
2018-06-27 08:41:11 -07:00
committed by Ben Lesh
parent 9c92a6fc7a
commit fba276d3d1
9 changed files with 115 additions and 25 deletions

View File

@ -146,9 +146,8 @@ export class ComponentDecoratorHandler implements DecoratorHandler<R3ComponentMe
};
}
compile(node: ts.ClassDeclaration, analysis: R3ComponentMetadata): CompileResult {
const pool = new ConstantPool();
compile(node: ts.ClassDeclaration, analysis: R3ComponentMetadata, pool: ConstantPool):
CompileResult {
// Check whether this component was registered with an NgModule. If so, it should be compiled
// under that module's compilation scope.
const scope = this.scopeRegistry.lookupCompilationScope(node);
@ -163,7 +162,7 @@ export class ComponentDecoratorHandler implements DecoratorHandler<R3ComponentMe
return {
name: 'ngComponentDef',
initializer: res.expression,
statements: pool.statements,
statements: [],
type: res.type,
};
}