From 45b33c5a9022064600fbbad70c23504188b84b2a Mon Sep 17 00:00:00 2001 From: Tim Blasi Date: Thu, 29 Oct 2015 11:24:02 -0700 Subject: [PATCH] perf(dart/transform): Restrict visibility/mutability of codegen For exported, generated templates, declare with `final` so `dart2js` knows they will never be reassigned. For non-exported, generated change detector classes, prefix the classname with `_` to mark them as internal. Closes #5009 --- .../angular2/src/core/compiler/change_detector_compiler.ts | 2 +- modules/angular2/src/core/compiler/util.ts | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/angular2/src/core/compiler/change_detector_compiler.ts b/modules/angular2/src/core/compiler/change_detector_compiler.ts index 177105a28d..41c6bf0123 100644 --- a/modules/angular2/src/core/compiler/change_detector_compiler.ts +++ b/modules/angular2/src/core/compiler/change_detector_compiler.ts @@ -69,7 +69,7 @@ export class ChangeDetectionCompiler { // and have the same API for calling them! if (IS_DART) { codegen = new Codegen(PREGEN_PROTO_CHANGE_DETECTOR_MODULE); - var className = definition.id; + var className = `_${definition.id}`; var typeRef = (index === 0 && componentType.isHost) ? 'dynamic' : `${moduleRef(componentType.moduleUrl)}${componentType.name}`; diff --git a/modules/angular2/src/core/compiler/util.ts b/modules/angular2/src/core/compiler/util.ts index 1912b41f28..1ad6c34bbb 100644 --- a/modules/angular2/src/core/compiler/util.ts +++ b/modules/angular2/src/core/compiler/util.ts @@ -46,8 +46,11 @@ function escapeString(input: string, re: RegExp): string { } export function codeGenExportVariable(name: string, isConst: boolean = false): string { - var declaration = IS_DART && isConst ? `const ${name}` : `var ${name}`; - return IS_DART ? `${declaration} = ` : `${declaration} = exports['${name}'] = `; + if (IS_DART) { + return isConst ? `const ${name} = ` : `final ${name} = `; + } else { + return `var ${name} = exports['${name}'] = `; + } } export function codeGenConcatArray(expression: string): string {