From e8f640b7999858d0874b23bd7bb5ca6e9c67939a Mon Sep 17 00:00:00 2001 From: Ravi Jayaramappa Date: Wed, 5 Oct 2022 11:58:55 -0700 Subject: [PATCH] test: update tests after rebase --- .../compiler/error-info/template-transform.ts | 7 +- .../no-directives-in-slots/metadata.json | 4 +- .../scoped-slots/child-named-slot/ast.json | 270 +++++++++++++++++- .../scoped-slots/child-named-slot/config.json | 3 + .../scoped-slots/child-named-slot/expected.js | 30 ++ .../child-named-slot/metadata.json | 36 +-- .../child-slot-bind/metadata.json | 4 +- .../parent-slot-data/metadata.json | 4 +- .../duplicate-slot-default/metadata.json | 8 +- .../duplicate-slot-named/metadata.json | 4 +- .../invalid-on-non-slot-content/metadata.json | 8 +- .../mixed-slot-default/metadata.json | 4 +- .../slot-bind/mixed-slot-named/metadata.json | 4 +- .../slot-bind/non-light-dom/metadata.json | 4 +- .../comment-direct-child/metadata.json | 4 +- .../invalid-on-non-slot-content/metadata.json | 8 +- .../slot-data/text-direct-child/metadata.json | 8 +- .../template-compiler/src/parser/index.ts | 9 +- 18 files changed, 345 insertions(+), 74 deletions(-) create mode 100644 packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/child-named-slot/config.json diff --git a/packages/@lwc/errors/src/compiler/error-info/template-transform.ts b/packages/@lwc/errors/src/compiler/error-info/template-transform.ts index 4073105365..bb172f44ab 100644 --- a/packages/@lwc/errors/src/compiler/error-info/template-transform.ts +++ b/packages/@lwc/errors/src/compiler/error-info/template-transform.ts @@ -395,7 +395,8 @@ export const ParserDiagnostics = { SLOT_TAG_CANNOT_HAVE_DIRECTIVES: { code: 1082, - message: "Slot tag can't be associated with for:each, for:of or if:true/false directives", + message: + "Slot tag can't be associated with for:each, for:of, if:true, if:flase, lwc:if, lwc:else, lwc:elseif template directives.", level: DiagnosticLevel.Error, url: '', }, @@ -723,14 +724,14 @@ export const ParserDiagnostics = { level: DiagnosticLevel.Error, url: '', }, - + INVALID_ELSEIF_BLOCK_DIRECTIVE_WITH_CONDITIONAL: { code: 1163, message: "Invalid usage of 'lwc:elseif' and '{0}' directives on the same element.", level: DiagnosticLevel.Error, url: '', }, - + INVALID_ELSE_BLOCK_DIRECTIVE_WITH_CONDITIONAL: { code: 1164, message: "Invalid usage of 'lwc:else' and '{0}' directives on the same element.", diff --git a/packages/@lwc/template-compiler/src/__tests__/fixtures/directive-lwc-if-else/slots/duplicate-slots-warning/no-directives-in-slots/metadata.json b/packages/@lwc/template-compiler/src/__tests__/fixtures/directive-lwc-if-else/slots/duplicate-slots-warning/no-directives-in-slots/metadata.json index 0da08c0eb6..0732187a10 100644 --- a/packages/@lwc/template-compiler/src/__tests__/fixtures/directive-lwc-if-else/slots/duplicate-slots-warning/no-directives-in-slots/metadata.json +++ b/packages/@lwc/template-compiler/src/__tests__/fixtures/directive-lwc-if-else/slots/duplicate-slots-warning/no-directives-in-slots/metadata.json @@ -2,7 +2,7 @@ "warnings": [ { "code": 1082, - "message": "LWC1082: Slot tag can't be associated with directives", + "message": "LWC1082: Slot tag can't be associated with for:each, for:of or if:true/false directives", "level": 1, "location": { "line": 2, @@ -13,7 +13,7 @@ }, { "code": 1082, - "message": "LWC1082: Slot tag can't be associated with directives", + "message": "LWC1082: Slot tag can't be associated with for:each, for:of or if:true/false directives", "level": 1, "location": { "line": 3, diff --git a/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/child-named-slot/ast.json b/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/child-named-slot/ast.json index 9e26dfeeb6..863c5137a2 100644 --- a/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/child-named-slot/ast.json +++ b/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/child-named-slot/ast.json @@ -1 +1,269 @@ -{} \ No newline at end of file +{ + "root": { + "type": "Root", + "location": { + "startLine": 1, + "startColumn": 1, + "endLine": 5, + "endColumn": 12, + "start": 0, + "end": 214, + "startTag": { + "startLine": 1, + "startColumn": 1, + "endLine": 1, + "endColumn": 35, + "start": 0, + "end": 34 + }, + "endTag": { + "startLine": 5, + "startColumn": 1, + "endLine": 5, + "endColumn": 12, + "start": 203, + "end": 214 + } + }, + "directives": [ + { + "type": "Directive", + "name": "RenderMode", + "value": { + "type": "Literal", + "value": "light" + }, + "location": { + "startLine": 1, + "startColumn": 11, + "endLine": 1, + "endColumn": 34, + "start": 10, + "end": 33 + } + } + ], + "children": [ + { + "type": "Slot", + "name": "slot", + "namespace": "http://www.w3.org/1999/xhtml", + "slotName": "slotname1", + "location": { + "startLine": 2, + "startColumn": 5, + "endLine": 2, + "endColumn": 61, + "start": 39, + "end": 95, + "startTag": { + "startLine": 2, + "startColumn": 5, + "endLine": 2, + "endColumn": 54, + "start": 39, + "end": 88 + }, + "endTag": { + "startLine": 2, + "startColumn": 54, + "endLine": 2, + "endColumn": 61, + "start": 88, + "end": 95 + } + }, + "attributes": [ + { + "type": "Attribute", + "name": "name", + "value": { + "type": "Literal", + "value": "slotname1" + }, + "location": { + "startLine": 2, + "startColumn": 11, + "endLine": 2, + "endColumn": 27, + "start": 45, + "end": 61 + } + } + ], + "properties": [], + "directives": [ + { + "type": "Directive", + "name": "SlotBind", + "value": { + "type": "Identifier", + "start": 1, + "end": 10, + "name": "slot1data", + "location": { + "startLine": 2, + "startColumn": 28, + "endLine": 2, + "endColumn": 53, + "start": 62, + "end": 87 + } + }, + "location": { + "startLine": 2, + "startColumn": 28, + "endLine": 2, + "endColumn": 53, + "start": 62, + "end": 87 + } + } + ], + "listeners": [], + "children": [] + }, + { + "type": "Slot", + "name": "slot", + "namespace": "http://www.w3.org/1999/xhtml", + "slotName": "slotname2", + "location": { + "startLine": 3, + "startColumn": 5, + "endLine": 3, + "endColumn": 61, + "start": 100, + "end": 156, + "startTag": { + "startLine": 3, + "startColumn": 5, + "endLine": 3, + "endColumn": 54, + "start": 100, + "end": 149 + }, + "endTag": { + "startLine": 3, + "startColumn": 54, + "endLine": 3, + "endColumn": 61, + "start": 149, + "end": 156 + } + }, + "attributes": [ + { + "type": "Attribute", + "name": "name", + "value": { + "type": "Literal", + "value": "slotname2" + }, + "location": { + "startLine": 3, + "startColumn": 11, + "endLine": 3, + "endColumn": 27, + "start": 106, + "end": 122 + } + } + ], + "properties": [], + "directives": [ + { + "type": "Directive", + "name": "SlotBind", + "value": { + "type": "Identifier", + "start": 1, + "end": 10, + "name": "slot2data", + "location": { + "startLine": 3, + "startColumn": 28, + "endLine": 3, + "endColumn": 53, + "start": 123, + "end": 148 + } + }, + "location": { + "startLine": 3, + "startColumn": 28, + "endLine": 3, + "endColumn": 53, + "start": 123, + "end": 148 + } + } + ], + "listeners": [], + "children": [] + }, + { + "type": "Slot", + "name": "slot", + "namespace": "http://www.w3.org/1999/xhtml", + "slotName": "", + "location": { + "startLine": 4, + "startColumn": 5, + "endLine": 4, + "endColumn": 46, + "start": 161, + "end": 202, + "startTag": { + "startLine": 4, + "startColumn": 5, + "endLine": 4, + "endColumn": 39, + "start": 161, + "end": 195 + }, + "endTag": { + "startLine": 4, + "startColumn": 39, + "endLine": 4, + "endColumn": 46, + "start": 195, + "end": 202 + } + }, + "attributes": [], + "properties": [], + "directives": [ + { + "type": "Directive", + "name": "SlotBind", + "value": { + "type": "Identifier", + "start": 1, + "end": 12, + "name": "defaultdata", + "location": { + "startLine": 4, + "startColumn": 11, + "endLine": 4, + "endColumn": 38, + "start": 167, + "end": 194 + } + }, + "location": { + "startLine": 4, + "startColumn": 11, + "endLine": 4, + "endColumn": 38, + "start": 167, + "end": 194 + } + } + ], + "listeners": [], + "children": [] + } + ] + } +} \ No newline at end of file diff --git a/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/child-named-slot/config.json b/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/child-named-slot/config.json new file mode 100644 index 0000000000..089a290bd4 --- /dev/null +++ b/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/child-named-slot/config.json @@ -0,0 +1,3 @@ +{ + "enableScopedSlots": true +} diff --git a/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/child-named-slot/expected.js b/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/child-named-slot/expected.js index e69de29bb2..bbbea1ac5e 100644 --- a/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/child-named-slot/expected.js +++ b/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/child-named-slot/expected.js @@ -0,0 +1,30 @@ +import { registerTemplate } from "lwc"; +const stc0 = { + attrs: { + name: "slotname1", + }, + key: 0, +}; +const stc1 = []; +const stc2 = { + attrs: { + name: "slotname2", + }, + key: 1, +}; +const stc3 = { + key: 2, +}; +function tmpl($api, $cmp, $slotset, $ctx) { + const { s: api_slot, f: api_flatten } = $api; + return api_flatten([ + api_slot("slotname1", stc0, stc1, $slotset), + api_slot("slotname2", stc2, stc1, $slotset), + api_slot("", stc3, stc1, $slotset), + ]); + /*LWC compiler vX.X.X*/ +} +export default registerTemplate(tmpl); +tmpl.slots = ["", "slotname1", "slotname2"]; +tmpl.stylesheets = []; +tmpl.renderMode = "light"; diff --git a/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/child-named-slot/metadata.json b/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/child-named-slot/metadata.json index f4304a37a6..51ec5f799c 100644 --- a/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/child-named-slot/metadata.json +++ b/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/child-named-slot/metadata.json @@ -1,37 +1,3 @@ { - "warnings": [ - { - "code": 1159, - "message": "LWC1159: Invalid `lwc:slot-bind` usage. The \"Scoped Slots\" feature must be enabled in order to use this directive.", - "level": 1, - "location": { - "line": 2, - "column": 5, - "start": 39, - "length": 56 - } - }, - { - "code": 1159, - "message": "LWC1159: Invalid `lwc:slot-bind` usage. The \"Scoped Slots\" feature must be enabled in order to use this directive.", - "level": 1, - "location": { - "line": 3, - "column": 5, - "start": 100, - "length": 56 - } - }, - { - "code": 1159, - "message": "LWC1159: Invalid `lwc:slot-bind` usage. The \"Scoped Slots\" feature must be enabled in order to use this directive.", - "level": 1, - "location": { - "line": 4, - "column": 5, - "start": 161, - "length": 41 - } - } - ] + "warnings": [] } \ No newline at end of file diff --git a/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/config-unset/child-slot-bind/metadata.json b/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/config-unset/child-slot-bind/metadata.json index 0013f7463e..1095476df1 100644 --- a/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/config-unset/child-slot-bind/metadata.json +++ b/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/config-unset/child-slot-bind/metadata.json @@ -1,8 +1,8 @@ { "warnings": [ { - "code": 1159, - "message": "LWC1159: Invalid `lwc:slot-bind` usage. The \"Scoped Slots\" feature must be enabled in order to use this directive.", + "code": 1167, + "message": "LWC1167: Invalid `lwc:slot-bind` usage. The \"Scoped Slots\" feature must be enabled in order to use this directive.", "level": 1, "location": { "line": 2, diff --git a/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/config-unset/parent-slot-data/metadata.json b/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/config-unset/parent-slot-data/metadata.json index a2434c0ac2..8df2cc5292 100644 --- a/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/config-unset/parent-slot-data/metadata.json +++ b/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/config-unset/parent-slot-data/metadata.json @@ -1,8 +1,8 @@ { "warnings": [ { - "code": 1159, - "message": "LWC1159: Invalid `lwc:slot-bind` usage. The \"Scoped Slots\" feature must be enabled in order to use this directive.", + "code": 1167, + "message": "LWC1167: Invalid `lwc:slot-bind` usage. The \"Scoped Slots\" feature must be enabled in order to use this directive.", "level": 1, "location": { "line": 3, diff --git a/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/slot-bind/duplicate-slot-default/metadata.json b/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/slot-bind/duplicate-slot-default/metadata.json index 1729b8e89b..56ceea172c 100644 --- a/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/slot-bind/duplicate-slot-default/metadata.json +++ b/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/slot-bind/duplicate-slot-default/metadata.json @@ -1,8 +1,8 @@ { "warnings": [ { - "code": 1164, - "message": "LWC1164: Invalid duplicate scoped slots (default)", + "code": 1172, + "message": "LWC1172: Invalid duplicate scoped slots (default)", "level": 1, "location": { "line": 3, @@ -12,8 +12,8 @@ } }, { - "code": 1164, - "message": "LWC1164: Invalid duplicate scoped slots (default)", + "code": 1172, + "message": "LWC1172: Invalid duplicate scoped slots (default)", "level": 1, "location": { "line": 4, diff --git a/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/slot-bind/duplicate-slot-named/metadata.json b/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/slot-bind/duplicate-slot-named/metadata.json index 29d6685aa0..6a94069b0f 100644 --- a/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/slot-bind/duplicate-slot-named/metadata.json +++ b/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/slot-bind/duplicate-slot-named/metadata.json @@ -1,8 +1,8 @@ { "warnings": [ { - "code": 1164, - "message": "LWC1164: Invalid duplicate scoped slots (name=\"slotname\")", + "code": 1172, + "message": "LWC1172: Invalid duplicate scoped slots (name=\"slotname\")", "level": 1, "location": { "line": 3, diff --git a/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/slot-bind/invalid-on-non-slot-content/metadata.json b/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/slot-bind/invalid-on-non-slot-content/metadata.json index 6ebe3d8fad..750c0e9204 100644 --- a/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/slot-bind/invalid-on-non-slot-content/metadata.json +++ b/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/slot-bind/invalid-on-non-slot-content/metadata.json @@ -1,8 +1,8 @@ { "warnings": [ { - "code": 1163, - "message": "LWC1163: Invalid `lwc:slot-bind` usage on element \"
\". The directive can be used on a `` element only.", + "code": 1171, + "message": "LWC1171: Invalid `lwc:slot-bind` usage on element \"
\". The directive can be used on a `` element only.", "level": 1, "location": { "line": 2, @@ -12,8 +12,8 @@ } }, { - "code": 1163, - "message": "LWC1163: Invalid `lwc:slot-bind` usage on element \"\". The directive can be used on a `` element only.", + "code": 1171, + "message": "LWC1171: Invalid `lwc:slot-bind` usage on element \"\". The directive can be used on a `` element only.", "level": 1, "location": { "line": 3, diff --git a/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/slot-bind/mixed-slot-default/metadata.json b/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/slot-bind/mixed-slot-default/metadata.json index 4bdbcabbb1..717e9166ba 100644 --- a/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/slot-bind/mixed-slot-default/metadata.json +++ b/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/slot-bind/mixed-slot-default/metadata.json @@ -1,8 +1,8 @@ { "warnings": [ { - "code": 1165, - "message": "LWC1165: Mixing slot types disallowed for same (default) slot.", + "code": 1173, + "message": "LWC1173: Mixing slot types disallowed for same (default) slot.", "level": 1, "location": { "line": 3, diff --git a/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/slot-bind/mixed-slot-named/metadata.json b/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/slot-bind/mixed-slot-named/metadata.json index dc74e6f630..0c2e1fb9c1 100644 --- a/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/slot-bind/mixed-slot-named/metadata.json +++ b/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/slot-bind/mixed-slot-named/metadata.json @@ -1,8 +1,8 @@ { "warnings": [ { - "code": 1165, - "message": "LWC1165: Mixing slot types disallowed for same (name=\"slotname\") slot.", + "code": 1173, + "message": "LWC1173: Mixing slot types disallowed for same (name=\"slotname\") slot.", "level": 1, "location": { "line": 3, diff --git a/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/slot-bind/non-light-dom/metadata.json b/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/slot-bind/non-light-dom/metadata.json index 26fa2c8b9d..243b57f894 100644 --- a/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/slot-bind/non-light-dom/metadata.json +++ b/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/slot-bind/non-light-dom/metadata.json @@ -1,8 +1,8 @@ { "warnings": [ { - "code": 1161, - "message": "LWC1161: Invalid `lwc:slot-bind` usage on element. Scoped slots usage is allowed in Light DOM templates only.", + "code": 1169, + "message": "LWC1169: Invalid `lwc:slot-bind` usage on element. Scoped slots usage is allowed in Light DOM templates only.", "level": 1, "location": { "line": 2, diff --git a/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/slot-data/comment-direct-child/metadata.json b/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/slot-data/comment-direct-child/metadata.json index 5ecbb54224..92d5a54b90 100644 --- a/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/slot-data/comment-direct-child/metadata.json +++ b/packages/@lwc/template-compiler/src/__tests__/fixtures/scoped-slots/invalid/slot-data/comment-direct-child/metadata.json @@ -1,8 +1,8 @@ { "warnings": [ { - "code": 1169, - "message": "LWC1169: `