From 0e174fe38ba7699c59bb8f01531e556a9943ae3c Mon Sep 17 00:00:00 2001 From: tanhauhau Date: Wed, 5 Oct 2022 23:04:12 +0800 Subject: [PATCH] include checking for {@html} tags in invalid location --- src/compiler/parse/errors.ts | 4 ++++ src/compiler/parse/state/tag.ts | 5 +++++ .../samples/html-block-in-attribute/errors.json | 9 +++++++++ .../samples/html-block-in-attribute/input.svelte | 1 + .../validator/samples/html-block-in-textarea/errors.json | 9 +++++++++ .../samples/html-block-in-textarea/input.svelte | 3 +++ 6 files changed, 31 insertions(+) create mode 100644 test/validator/samples/html-block-in-attribute/errors.json create mode 100644 test/validator/samples/html-block-in-attribute/input.svelte create mode 100644 test/validator/samples/html-block-in-textarea/errors.json create mode 100644 test/validator/samples/html-block-in-textarea/input.svelte diff --git a/src/compiler/parse/errors.ts b/src/compiler/parse/errors.ts index 33bd1abab7..26f03c0cb1 100644 --- a/src/compiler/parse/errors.ts +++ b/src/compiler/parse/errors.ts @@ -111,6 +111,10 @@ export default { code: 'invalid-logic-block-placement', message: `{#${name}} logic block cannot be ${location}` }), + invalid_tag_placement: (location: string, name: string) => ({ + code: 'invalid-tag-placement', + message: `{@${name}} tag cannot be ${location}` + }), invalid_ref_directive: (name: string) => ({ code: 'invalid-ref-directive', message: `The ref directive is no longer supported — use \`bind:this={${name}}\` instead` diff --git a/src/compiler/parse/state/tag.ts b/src/compiler/parse/state/tag.ts index 754b43952e..4be47f25b0 100644 --- a/src/compiler/parse/state/tag.ts +++ b/src/compiler/parse/state/tag.ts @@ -527,6 +527,11 @@ function read_sequence(parser: Parser, done: () => boolean, location: string): T parser.eat('#'); const name = parser.read_until(/[^a-z]/); parser.error(parser_errors.invalid_logic_block_placement(location, name), index); + } else if (parser.match('@')) { + const index = parser.index - 1; + parser.eat('@'); + const name = parser.read_until(/[^a-z]/); + parser.error(parser_errors.invalid_tag_placement(location, name), index); } flush(parser.index - 1); diff --git a/test/validator/samples/html-block-in-attribute/errors.json b/test/validator/samples/html-block-in-attribute/errors.json new file mode 100644 index 0000000000..7cfe43dc0b --- /dev/null +++ b/test/validator/samples/html-block-in-attribute/errors.json @@ -0,0 +1,9 @@ +[ + { + "code": "invalid-tag-placement", + "message": "{@html} tag cannot be in attribute value", + "start": { "line": 1, "column": 12, "character": 12 }, + "end": { "line": 1, "column": 12, "character": 12 }, + "pos": 12 + } +] diff --git a/test/validator/samples/html-block-in-attribute/input.svelte b/test/validator/samples/html-block-in-attribute/input.svelte new file mode 100644 index 0000000000..46b8ca5b7e --- /dev/null +++ b/test/validator/samples/html-block-in-attribute/input.svelte @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/test/validator/samples/html-block-in-textarea/errors.json b/test/validator/samples/html-block-in-textarea/errors.json new file mode 100644 index 0000000000..756fa5ad3e --- /dev/null +++ b/test/validator/samples/html-block-in-textarea/errors.json @@ -0,0 +1,9 @@ +[ + { + "code": "invalid-tag-placement", + "message": "{@html} tag cannot be inside \ No newline at end of file