Skip to content

Commit

Permalink
fix(compiler-cli): do not error due to multiple components named equa…
Browse files Browse the repository at this point in the history
…lly (#54273)

Currently, when two components are named `TestComponent`, and both would
use e.g. control flow. Templates would be generated by the compiler and
those would conflict at runtime because the names for the template
functions are not ensured to be unique.

This seems like a more general problem that could be tackled in the
future in the template pipeline by always using the `ConstantPool`, but
for now, we should be good already, given us ensuring the `baseName`'s are
always unique.

PR Close #54273
  • Loading branch information
devversion authored and thePunderWoman committed Feb 6, 2024
1 parent 4297005 commit bc4a6a9
Show file tree
Hide file tree
Showing 9 changed files with 197 additions and 125 deletions.
Expand Up @@ -2026,3 +2026,63 @@ export declare class MyApp {
static ɵcmp: i0.ɵɵComponentDeclaration<MyApp, "ng-component", never, {}, {}, never, never, false, never>;
}

/****************************************************************************************************
* PARTIAL FILE: conditional_same_component_names.js
****************************************************************************************************/
import { Component } from '@angular/core';
import * as i0 from "@angular/core";
function it(_desc, fn) { }
it('case 1', () => {
class TestComponent {
}
TestComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: TestComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
TestComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "0.0.0-PLACEHOLDER", type: TestComponent, selector: "ng-component", ngImport: i0, template: `
@if (true) {
First
} @else {
Second
}
`, isInline: true });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: TestComponent, decorators: [{
type: Component,
args: [{
template: `
@if (true) {
First
} @else {
Second
}
`,
}]
}] });
});
it('case 2', () => {
class TestComponent {
}
TestComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: TestComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
TestComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "0.0.0-PLACEHOLDER", type: TestComponent, selector: "ng-component", ngImport: i0, template: `
@if (true) {
First
} @else {
Second
}
`, isInline: true });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: TestComponent, decorators: [{
type: Component,
args: [{
template: `
@if (true) {
First
} @else {
Second
}
`,
}]
}] });
});

/****************************************************************************************************
* PARTIAL FILE: conditional_same_component_names.d.ts
****************************************************************************************************/
export {};

0 comments on commit bc4a6a9

Please sign in to comment.