From 941ce714f9bce7a33726b3c8592ef19b971f5772 Mon Sep 17 00:00:00 2001 From: Jose David Rodriguez Velasco Date: Sun, 10 Apr 2022 13:02:00 -0400 Subject: [PATCH] fix: test due rebase --- .../fixtures/regression/slot-name-with-dash/expected.js | 7 ++++++- .../fixtures/slots/definition-sibiling-slot/expected.js | 9 +++++++-- .../fixtures/slots/definition-sibling-static/expected.js | 2 +- .../src/__tests__/fixtures/slots/definition/expected.js | 2 +- .../src/__tests__/fixtures/slots/mixed-1/expected.js | 9 +++++++-- .../src/__tests__/fixtures/slots/usage-named/expected.js | 7 ++++++- packages/@lwc/template-compiler/src/codegen/codegen.ts | 8 ++++++-- packages/@lwc/template-compiler/src/codegen/index.ts | 2 +- 8 files changed, 35 insertions(+), 11 deletions(-) diff --git a/packages/@lwc/template-compiler/src/__tests__/fixtures/regression/slot-name-with-dash/expected.js b/packages/@lwc/template-compiler/src/__tests__/fixtures/regression/slot-name-with-dash/expected.js index 7169d08c9b..769ec28320 100644 --- a/packages/@lwc/template-compiler/src/__tests__/fixtures/regression/slot-name-with-dash/expected.js +++ b/packages/@lwc/template-compiler/src/__tests__/fixtures/regression/slot-name-with-dash/expected.js @@ -13,7 +13,12 @@ function tmpl($api, $cmp, $slotset, $ctx) { api_slot( "secret-slot", stc0, - [api_static_fragment($fragment1 || ($fragment1 = $hoisted1()), 2)], + [ + api_static_fragment( + $fragment1 || ($fragment1 = $hoisted1()), + "@secret-slot:2" + ), + ], $slotset ), ]; diff --git a/packages/@lwc/template-compiler/src/__tests__/fixtures/slots/definition-sibiling-slot/expected.js b/packages/@lwc/template-compiler/src/__tests__/fixtures/slots/definition-sibiling-slot/expected.js index 0e58bb37cd..7129756a96 100644 --- a/packages/@lwc/template-compiler/src/__tests__/fixtures/slots/definition-sibiling-slot/expected.js +++ b/packages/@lwc/template-compiler/src/__tests__/fixtures/slots/definition-sibiling-slot/expected.js @@ -27,13 +27,18 @@ function tmpl($api, $cmp, $slotset, $ctx) { api_slot( "other", stc1, - [api_static_fragment($fragment1 || ($fragment1 = $hoisted1()), 3)], + [ + api_static_fragment( + $fragment1 || ($fragment1 = $hoisted1()), + "@other:3" + ), + ], $slotset ), api_slot( "", stc2, - [api_static_fragment($fragment2 || ($fragment2 = $hoisted2()), 6)], + [api_static_fragment($fragment2 || ($fragment2 = $hoisted2()), "@:6")], $slotset ), ]), diff --git a/packages/@lwc/template-compiler/src/__tests__/fixtures/slots/definition-sibling-static/expected.js b/packages/@lwc/template-compiler/src/__tests__/fixtures/slots/definition-sibling-static/expected.js index 6316ff2a30..9aa7a1675f 100644 --- a/packages/@lwc/template-compiler/src/__tests__/fixtures/slots/definition-sibling-static/expected.js +++ b/packages/@lwc/template-compiler/src/__tests__/fixtures/slots/definition-sibling-static/expected.js @@ -22,7 +22,7 @@ function tmpl($api, $cmp, $slotset, $ctx) { api_slot( "", stc1, - [api_static_fragment($fragment2 || ($fragment2 = $hoisted2()), 5)], + [api_static_fragment($fragment2 || ($fragment2 = $hoisted2()), "@:5")], $slotset ), ]), diff --git a/packages/@lwc/template-compiler/src/__tests__/fixtures/slots/definition/expected.js b/packages/@lwc/template-compiler/src/__tests__/fixtures/slots/definition/expected.js index fa10fe0acb..e5ca4a78e8 100644 --- a/packages/@lwc/template-compiler/src/__tests__/fixtures/slots/definition/expected.js +++ b/packages/@lwc/template-compiler/src/__tests__/fixtures/slots/definition/expected.js @@ -19,7 +19,7 @@ function tmpl($api, $cmp, $slotset, $ctx) { api_slot( "", stc1, - [api_static_fragment($fragment1 || ($fragment1 = $hoisted1()), 3)], + [api_static_fragment($fragment1 || ($fragment1 = $hoisted1()), "@:3")], $slotset ), ]), diff --git a/packages/@lwc/template-compiler/src/__tests__/fixtures/slots/mixed-1/expected.js b/packages/@lwc/template-compiler/src/__tests__/fixtures/slots/mixed-1/expected.js index 5e315ac235..b0abdf2751 100644 --- a/packages/@lwc/template-compiler/src/__tests__/fixtures/slots/mixed-1/expected.js +++ b/packages/@lwc/template-compiler/src/__tests__/fixtures/slots/mixed-1/expected.js @@ -43,13 +43,18 @@ function tmpl($api, $cmp, $slotset, $ctx) { api_slot( "", stc2, - [api_static_fragment($fragment4 || ($fragment4 = $hoisted4()), 10)], + [api_static_fragment($fragment4 || ($fragment4 = $hoisted4()), "@:10")], $slotset ), api_slot( "footer", stc3, - [api_static_fragment($fragment5 || ($fragment5 = $hoisted5()), 13)], + [ + api_static_fragment( + $fragment5 || ($fragment5 = $hoisted5()), + "@footer:13" + ), + ], $slotset ), ]), diff --git a/packages/@lwc/template-compiler/src/__tests__/fixtures/slots/usage-named/expected.js b/packages/@lwc/template-compiler/src/__tests__/fixtures/slots/usage-named/expected.js index 254f27de6c..3f2e309ced 100644 --- a/packages/@lwc/template-compiler/src/__tests__/fixtures/slots/usage-named/expected.js +++ b/packages/@lwc/template-compiler/src/__tests__/fixtures/slots/usage-named/expected.js @@ -22,7 +22,12 @@ function tmpl($api, $cmp, $slotset, $ctx) { api_slot( "test", stc1, - [api_static_fragment($fragment1 || ($fragment1 = $hoisted1()), 3)], + [ + api_static_fragment( + $fragment1 || ($fragment1 = $hoisted1()), + "@test:3" + ), + ], $slotset ), ]), diff --git a/packages/@lwc/template-compiler/src/codegen/codegen.ts b/packages/@lwc/template-compiler/src/codegen/codegen.ts index 642a3ff8e3..3c7d25b6c6 100644 --- a/packages/@lwc/template-compiler/src/codegen/codegen.ts +++ b/packages/@lwc/template-compiler/src/codegen/codegen.ts @@ -501,7 +501,11 @@ export default class CodeGen { return expression as t.Expression; } - genHoistedElement(element: Element): t.Expression { + genHoistedElement(element: Element, slotParentName?: string): t.Expression { + const key = + slotParentName !== undefined + ? `@${slotParentName}:${this.generateKey()}` + : this.generateKey(); const html = serializeStaticElement(element); this.usedLwcApis.add(PARSE_FRAGMENT_METHOD_NAME); @@ -537,7 +541,7 @@ export default class CodeGen { t.callExpression(t.identifier(`$hoisted${idx}`), []) ) ), - t.literal(this.generateKey()), + t.literal(key), ]); } } diff --git a/packages/@lwc/template-compiler/src/codegen/index.ts b/packages/@lwc/template-compiler/src/codegen/index.ts index d58c89f82c..b85636f56c 100644 --- a/packages/@lwc/template-compiler/src/codegen/index.ts +++ b/packages/@lwc/template-compiler/src/codegen/index.ts @@ -95,7 +95,7 @@ function transform(codeGen: CodeGen): t.Expression { res = codeGen.getSlot(element.slotName, databag, defaultSlot); } else { res = codeGen.staticNodes.has(element) - ? codeGen.genHoistedElement(element) + ? codeGen.genHoistedElement(element, slotParentName) : codeGen.genElement(name, databag, children); }