From 95635c18c70c81898d66649ec2655b52fb7e52cb Mon Sep 17 00:00:00 2001 From: Chuck Jazdzewski Date: Mon, 17 Jul 2017 10:52:42 -0700 Subject: [PATCH] fix(compiler): ensure jit external id arguments names are unique Fixes: #17558, #17378, #8676 --- packages/compiler/src/output/output_jit.ts | 4 +-- .../compiler/test/output/output_jit_spec.ts | 35 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 packages/compiler/test/output/output_jit_spec.ts diff --git a/packages/compiler/src/output/output_jit.ts b/packages/compiler/src/output/output_jit.ts index 686e149ca6..0135be2096 100644 --- a/packages/compiler/src/output/output_jit.ts +++ b/packages/compiler/src/output/output_jit.ts @@ -43,7 +43,7 @@ export function jitStatements(sourceUrl: string, statements: o.Statement[]): {[k return evalExpression(sourceUrl, ctx, converter.getArgs()); } -class JitEmitterVisitor extends AbstractJsEmitterVisitor { +export class JitEmitterVisitor extends AbstractJsEmitterVisitor { private _evalArgNames: string[] = []; private _evalArgValues: any[] = []; private _evalExportedVars: string[] = []; @@ -69,7 +69,7 @@ class JitEmitterVisitor extends AbstractJsEmitterVisitor { id = this._evalArgValues.length; this._evalArgValues.push(value); const name = identifierName({reference: ast.value.runtime}) || 'val'; - this._evalArgNames.push(`jit_${name}${id}`); + this._evalArgNames.push(`jit_${name}_${id}`); } ctx.print(ast, this._evalArgNames[id]); return null; diff --git a/packages/compiler/test/output/output_jit_spec.ts b/packages/compiler/test/output/output_jit_spec.ts new file mode 100644 index 0000000000..017ddf8cb6 --- /dev/null +++ b/packages/compiler/test/output/output_jit_spec.ts @@ -0,0 +1,35 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import {EmitterVisitorContext} from '@angular/compiler/src/output/abstract_emitter'; +import * as o from '@angular/compiler/src/output/output_ast'; +import {JitEmitterVisitor} from '@angular/compiler/src/output/output_jit'; + +const anotherModuleUrl = 'somePackage/someOtherPath'; + +export function main() { + describe('Output JIT', () => { + describe('regression', () => { + it('should generate unique argument names', () => { + const externalIds = new Array(10).fill(1).map( + (_, index) => + new o.ExternalReference(anotherModuleUrl, `id_${index}_`, {name: `id_${index}_`})); + const externalIds1 = new Array(10).fill(1).map( + (_, index) => new o.ExternalReference( + anotherModuleUrl, `id_${index}_1`, {name: `id_${index}_1`})); + const ctx = EmitterVisitorContext.createRoot(); + const converter = new JitEmitterVisitor(); + converter.visitAllStatements( + [o.literalArr([...externalIds1, ...externalIds].map(id => o.importExpr(id))).toStmt()], + ctx); + const args = converter.getArgs(); + expect(Object.keys(args).length).toBe(20); + }); + }); + }) +} \ No newline at end of file