Skip to content

Commit bfbb306

Browse files
devversionthePunderWoman
authored andcommitted
fix(compiler-cli): do not error due to multiple components named equally (#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
1 parent 19fae76 commit bfbb306

File tree

9 files changed

+197
-125
lines changed

9 files changed

+197
-125
lines changed

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_control_flow/GOLDEN_PARTIAL.js

+60
Original file line numberDiff line numberDiff line change
@@ -2026,3 +2026,63 @@ export declare class MyApp {
20262026
static ɵcmp: i0.ɵɵComponentDeclaration<MyApp, "ng-component", never, {}, {}, never, never, false, never>;
20272027
}
20282028

2029+
/****************************************************************************************************
2030+
* PARTIAL FILE: conditional_same_component_names.js
2031+
****************************************************************************************************/
2032+
import { Component } from '@angular/core';
2033+
import * as i0 from "@angular/core";
2034+
function it(_desc, fn) { }
2035+
it('case 1', () => {
2036+
class TestComponent {
2037+
}
2038+
TestComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: TestComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2039+
TestComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "0.0.0-PLACEHOLDER", type: TestComponent, selector: "ng-component", ngImport: i0, template: `
2040+
@if (true) {
2041+
First
2042+
} @else {
2043+
Second
2044+
}
2045+
`, isInline: true });
2046+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: TestComponent, decorators: [{
2047+
type: Component,
2048+
args: [{
2049+
template: `
2050+
@if (true) {
2051+
First
2052+
} @else {
2053+
Second
2054+
}
2055+
`,
2056+
}]
2057+
}] });
2058+
});
2059+
it('case 2', () => {
2060+
class TestComponent {
2061+
}
2062+
TestComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: TestComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2063+
TestComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "0.0.0-PLACEHOLDER", type: TestComponent, selector: "ng-component", ngImport: i0, template: `
2064+
@if (true) {
2065+
First
2066+
} @else {
2067+
Second
2068+
}
2069+
`, isInline: true });
2070+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: TestComponent, decorators: [{
2071+
type: Component,
2072+
args: [{
2073+
template: `
2074+
@if (true) {
2075+
First
2076+
} @else {
2077+
Second
2078+
}
2079+
`,
2080+
}]
2081+
}] });
2082+
});
2083+
2084+
/****************************************************************************************************
2085+
* PARTIAL FILE: conditional_same_component_names.d.ts
2086+
****************************************************************************************************/
2087+
export {};
2088+

0 commit comments

Comments
 (0)