Skip to content

Commit 14f2425

Browse files
committed
fixup! refactor(compiler): emit instructions for foreign components
1 parent b26fc24 commit 14f2425

5 files changed

Lines changed: 29 additions & 7 deletions

File tree

packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/standalone/GOLDEN_PARTIAL.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,13 +388,27 @@ function frameworkImport(component) {
388388
export class TestCmp {
389389
title = 'Submit';
390390
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: TestCmp, deps: [], target: i0.ɵɵFactoryTarget.Component });
391-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "0.0.0-PLACEHOLDER", type: TestCmp, isStandalone: true, selector: "main", ngImport: i0, template: '<FancyButton class="btn-cls" [label]="title"></FancyButton>', isInline: true });
391+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "0.0.0-PLACEHOLDER", type: TestCmp, isStandalone: true, selector: "main", ngImport: i0, template: `
392+
<FancyButton
393+
class="btn-cls"
394+
unsafe-attr="value"
395+
[label]="title"
396+
[unsafe-input]="title"
397+
/>
398+
`, isInline: true });
392399
}
393400
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: TestCmp, decorators: [{
394401
type: Component,
395402
args: [{
396403
selector: 'main',
397-
template: '<FancyButton class="btn-cls" [label]="title"></FancyButton>',
404+
template: `
405+
<FancyButton
406+
class="btn-cls"
407+
unsafe-attr="value"
408+
[label]="title"
409+
[unsafe-input]="title"
410+
/>
411+
`,
398412
// @ts-ignore: @angular/core does not expose the `foreignImports` property.
399413
foreignImports: [
400414
// @ts-ignore: @angular/core does not expose the `ForeignComponent` type this expects.

packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/standalone/foreign_component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export class TestCmp {
77
vars: 0,
88
template: function TestCmp_Template(rf, ctx) {
99
if (rf & 1) {
10-
i0.ɵɵforeignComponent(0, frameworkImport(FancyButton), { class: "btn-cls", label: ctx.title });
10+
i0.ɵɵforeignComponent(0, frameworkImport(FancyButton), { class: "btn-cls", "unsafe-attr": "value", label: ctx.title, "unsafe-input": ctx.title });
1111
}
1212
},
1313
encapsulation: 2

packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/standalone/foreign_component.local.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export class TestCmp {
77
vars: 0,
88
template: function TestCmp_Template(rf, ctx) {
99
if (rf & 1) {
10-
i0.ɵɵforeignComponent(0, frameworkImport(FancyButton), { class: "btn-cls", label: ctx.title });
10+
i0.ɵɵforeignComponent(0, frameworkImport(FancyButton), { class: "btn-cls", "unsafe-attr": "value", label: ctx.title, "unsafe-input": ctx.title });
1111
}
1212
},
1313
encapsulation: 2

packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/standalone/foreign_component.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ function frameworkImport(component: {}): Function {
99

1010
@Component({
1111
selector: 'main',
12-
template: '<FancyButton class="btn-cls" [label]="title"></FancyButton>',
12+
template: `
13+
<FancyButton
14+
class="btn-cls"
15+
unsafe-attr="value"
16+
[label]="title"
17+
[unsafe-input]="title"
18+
/>
19+
`,
1320
// @ts-ignore: @angular/core does not expose the `foreignImports` property.
1421
foreignImports: [
1522
// @ts-ignore: @angular/core does not expose the `ForeignComponent` type this expects.

packages/compiler/src/template/pipeline/src/ingest.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {splitNsName} from '../../../ml_parser/tags';
1414
import * as o from '../../../output/output_ast';
1515
import {ParseSourceSpan} from '../../../parse_util';
1616
import * as t from '../../../render3/r3_ast';
17+
import {isUnsafeObjectKey} from '../../../render3/util';
1718
import {
1819
DeferBlockDepsEmitMode,
1920
R3ComponentDeferMetadata,
@@ -296,14 +297,14 @@ function ingestElement(unit: ViewCompilationUnit, element: t.Element): void {
296297
propEntries.push({
297298
key: attr.name,
298299
value: o.literal(attr.value),
299-
quoted: false,
300+
quoted: isUnsafeObjectKey(attr.name),
300301
});
301302
}
302303
for (const input of element.inputs) {
303304
propEntries.push({
304305
key: input.name,
305306
value: convertAst(input.value, unit.job, input.sourceSpan),
306-
quoted: false,
307+
quoted: isUnsafeObjectKey(input.name),
307308
});
308309
}
309310
const props = propEntries.length > 0 ? o.literalMap(propEntries) : null;

0 commit comments

Comments
 (0)