From 91bffa9c53fe813d36b86200ea34c29a5fed73bb Mon Sep 17 00:00:00 2001 From: Olivier Combe Date: Thu, 15 Nov 2018 16:00:55 +0100 Subject: [PATCH] fix(ivy): set encapsulation metadata (#27115) PR Close #27115 --- .../test/compliance/r3_view_compiler_styling_spec.ts | 8 +++++++- packages/compiler/src/render3/view/compiler.ts | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/compiler-cli/test/compliance/r3_view_compiler_styling_spec.ts b/packages/compiler-cli/test/compliance/r3_view_compiler_styling_spec.ts index b9a8603001..df66bc6240 100644 --- a/packages/compiler-cli/test/compliance/r3_view_compiler_styling_spec.ts +++ b/packages/compiler-cli/test/compliance/r3_view_compiler_styling_spec.ts @@ -94,7 +94,13 @@ describe('compiler compliance: styling', () => { } }; - const template = 'div.cool { color: blue; }", ":host.nice p { color: gold; }'; + const template = ` + MyComponent.ngComponentDef = $r3$.ɵdefineComponent({ + … + styles: ["div.cool { color: blue; }", ":host.nice p { color: gold; }"], + encapsulation: 1 + }) + `; const result = compile(files, angularFiles); expectEmit(result.source, template, 'Incorrect template'); }); diff --git a/packages/compiler/src/render3/view/compiler.ts b/packages/compiler/src/render3/view/compiler.ts index 4890db09c3..ea8c32d01c 100644 --- a/packages/compiler/src/render3/view/compiler.ts +++ b/packages/compiler/src/render3/view/compiler.ts @@ -269,6 +269,11 @@ export function compileComponentFromMetadata( definitionMap.set('styles', o.literalArr(strings)); } + // Only set view encapsulation if it's not the default value + if (meta.encapsulation !== null && meta.encapsulation !== core.ViewEncapsulation.Emulated) { + definitionMap.set('encapsulation', o.literal(meta.encapsulation)); + } + // e.g. `animations: [trigger('123', [])]` if (meta.animations !== null) { definitionMap.set(