From 1f021226c5df92e0685cce806918b8953e521a2a Mon Sep 17 00:00:00 2001 From: Ming07 Date: Mon, 2 Jan 2023 10:23:35 +0800 Subject: [PATCH] [fix] named slots breaks svelte-ignore comments (#8105) * [fix] Named slots breaks svelte-ignore comments Fixes #8075 * test: add tests * refactor * refactor test Co-authored-by: mojinming Co-authored-by: Yuichiro Yamashita --- src/compiler/compile/nodes/InlineComponent.ts | 2 ++ .../samples/slot-warning-ignore/input.svelte | 8 ++++++++ .../samples/slot-warning-ignore/warnings.json | 1 + .../validator/samples/slot-warning/input.svelte | 7 +++++++ .../samples/slot-warning/warnings.json | 17 +++++++++++++++++ .../samples/slot-warning2/input.svelte | 8 ++++++++ .../samples/slot-warning2/warnings.json | 17 +++++++++++++++++ 7 files changed, 60 insertions(+) create mode 100644 test/validator/samples/slot-warning-ignore/input.svelte create mode 100644 test/validator/samples/slot-warning-ignore/warnings.json create mode 100644 test/validator/samples/slot-warning/input.svelte create mode 100644 test/validator/samples/slot-warning/warnings.json create mode 100644 test/validator/samples/slot-warning2/input.svelte create mode 100644 test/validator/samples/slot-warning2/warnings.json diff --git a/src/compiler/compile/nodes/InlineComponent.ts b/src/compiler/compile/nodes/InlineComponent.ts index 26cfeb7ef9..e9ac86a55c 100644 --- a/src/compiler/compile/nodes/InlineComponent.ts +++ b/src/compiler/compile/nodes/InlineComponent.ts @@ -143,6 +143,8 @@ export default class InlineComponent extends Node { children.push(slot_template); info.children.splice(i, 1); + } else if (child.type === 'Comment' && children.length > 0) { + children[children.length - 1].children.unshift(child); } } diff --git a/test/validator/samples/slot-warning-ignore/input.svelte b/test/validator/samples/slot-warning-ignore/input.svelte new file mode 100644 index 0000000000..003b5bde63 --- /dev/null +++ b/test/validator/samples/slot-warning-ignore/input.svelte @@ -0,0 +1,8 @@ + + + + +
hi!
+
diff --git a/test/validator/samples/slot-warning-ignore/warnings.json b/test/validator/samples/slot-warning-ignore/warnings.json new file mode 100644 index 0000000000..fe51488c70 --- /dev/null +++ b/test/validator/samples/slot-warning-ignore/warnings.json @@ -0,0 +1 @@ +[] diff --git a/test/validator/samples/slot-warning/input.svelte b/test/validator/samples/slot-warning/input.svelte new file mode 100644 index 0000000000..3d60236edc --- /dev/null +++ b/test/validator/samples/slot-warning/input.svelte @@ -0,0 +1,7 @@ + + + +
hi!
+
diff --git a/test/validator/samples/slot-warning/warnings.json b/test/validator/samples/slot-warning/warnings.json new file mode 100644 index 0000000000..14691b4231 --- /dev/null +++ b/test/validator/samples/slot-warning/warnings.json @@ -0,0 +1,17 @@ +[ + { + "code": "a11y-click-events-have-key-events", + "message": "A11y: visible, non-interactive elements with an on:click event must be accompanied by an on:keydown, on:keyup, or on:keypress event.", + "start": { + "character": 78, + "column": 1, + "line": 6 + }, + "end": { + "character": 112, + "column": 35, + "line": 6 + }, + "pos": 78 + } +] diff --git a/test/validator/samples/slot-warning2/input.svelte b/test/validator/samples/slot-warning2/input.svelte new file mode 100644 index 0000000000..ab3c52d35d --- /dev/null +++ b/test/validator/samples/slot-warning2/input.svelte @@ -0,0 +1,8 @@ + + + + +
hi!
+
diff --git a/test/validator/samples/slot-warning2/warnings.json b/test/validator/samples/slot-warning2/warnings.json new file mode 100644 index 0000000000..5554c3f764 --- /dev/null +++ b/test/validator/samples/slot-warning2/warnings.json @@ -0,0 +1,17 @@ +[ + { + "code": "a11y-click-events-have-key-events", + "message": "A11y: visible, non-interactive elements with an on:click event must be accompanied by an on:keydown, on:keyup, or on:keypress event.", + "start": { + "character": 120, + "column": 1, + "line": 7 + }, + "end": { + "character": 154, + "column": 35, + "line": 7 + }, + "pos": 120 + } +]