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
This commit is contained in:
Tim Blasi 2015-10-29 11:24:02 -07:00 committed by Timothy Blasi
parent 860e88c5be
commit 45b33c5a90
2 changed files with 6 additions and 3 deletions

View File

@ -69,7 +69,7 @@ export class ChangeDetectionCompiler {
// and have the same API for calling them! // and have the same API for calling them!
if (IS_DART) { if (IS_DART) {
codegen = new Codegen(PREGEN_PROTO_CHANGE_DETECTOR_MODULE); codegen = new Codegen(PREGEN_PROTO_CHANGE_DETECTOR_MODULE);
var className = definition.id; var className = `_${definition.id}`;
var typeRef = (index === 0 && componentType.isHost) ? var typeRef = (index === 0 && componentType.isHost) ?
'dynamic' : 'dynamic' :
`${moduleRef(componentType.moduleUrl)}${componentType.name}`; `${moduleRef(componentType.moduleUrl)}${componentType.name}`;

View File

@ -46,8 +46,11 @@ function escapeString(input: string, re: RegExp): string {
} }
export function codeGenExportVariable(name: string, isConst: boolean = false): string { export function codeGenExportVariable(name: string, isConst: boolean = false): string {
var declaration = IS_DART && isConst ? `const ${name}` : `var ${name}`; if (IS_DART) {
return IS_DART ? `${declaration} = ` : `${declaration} = exports['${name}'] = `; return isConst ? `const ${name} = ` : `final ${name} = `;
} else {
return `var ${name} = exports['${name}'] = `;
}
} }
export function codeGenConcatArray(expression: string): string { export function codeGenConcatArray(expression: string): string {