Skip to content

Commit 95635c1

Browse files
chuckjazalxhub
authored andcommitted
fix(compiler): ensure jit external id arguments names are unique
Fixes: #17558, #17378, #8676
1 parent e20cfe1 commit 95635c1

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

packages/compiler/src/output/output_jit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function jitStatements(sourceUrl: string, statements: o.Statement[]): {[k
4343
return evalExpression(sourceUrl, ctx, converter.getArgs());
4444
}
4545

46-
class JitEmitterVisitor extends AbstractJsEmitterVisitor {
46+
export class JitEmitterVisitor extends AbstractJsEmitterVisitor {
4747
private _evalArgNames: string[] = [];
4848
private _evalArgValues: any[] = [];
4949
private _evalExportedVars: string[] = [];
@@ -69,7 +69,7 @@ class JitEmitterVisitor extends AbstractJsEmitterVisitor {
6969
id = this._evalArgValues.length;
7070
this._evalArgValues.push(value);
7171
const name = identifierName({reference: ast.value.runtime}) || 'val';
72-
this._evalArgNames.push(`jit_${name}${id}`);
72+
this._evalArgNames.push(`jit_${name}_${id}`);
7373
}
7474
ctx.print(ast, this._evalArgNames[id]);
7575
return null;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {EmitterVisitorContext} from '@angular/compiler/src/output/abstract_emitter';
10+
import * as o from '@angular/compiler/src/output/output_ast';
11+
import {JitEmitterVisitor} from '@angular/compiler/src/output/output_jit';
12+
13+
const anotherModuleUrl = 'somePackage/someOtherPath';
14+
15+
export function main() {
16+
describe('Output JIT', () => {
17+
describe('regression', () => {
18+
it('should generate unique argument names', () => {
19+
const externalIds = new Array(10).fill(1).map(
20+
(_, index) =>
21+
new o.ExternalReference(anotherModuleUrl, `id_${index}_`, {name: `id_${index}_`}));
22+
const externalIds1 = new Array(10).fill(1).map(
23+
(_, index) => new o.ExternalReference(
24+
anotherModuleUrl, `id_${index}_1`, {name: `id_${index}_1`}));
25+
const ctx = EmitterVisitorContext.createRoot();
26+
const converter = new JitEmitterVisitor();
27+
converter.visitAllStatements(
28+
[o.literalArr([...externalIds1, ...externalIds].map(id => o.importExpr(id))).toStmt()],
29+
ctx);
30+
const args = converter.getArgs();
31+
expect(Object.keys(args).length).toBe(20);
32+
});
33+
});
34+
})
35+
}

0 commit comments

Comments
 (0)