fix: don't error on `{type}` in declaration tags (#18321)

The `\b` in the regex matched on `}`, too, so you would get a very
confusing "invalid declaration tag" error on `{type}`. Match on
whitespace instead (because that's what has to come afterwards)

---------

Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
Co-authored-by: Rich-Harris <hello@rich-harris.dev>
pull/18322/head
Simon H 3 months ago committed by GitHub
parent 5300843e86
commit 980c7e2321
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -12,7 +12,10 @@ import { find_matching_bracket, match_bracket } from '../utils/bracket.js';
const regex_whitespace_with_closing_curly_brace = /\s*}/y;
const regex_supported_declaration = /(?:let|const)\b/y;
const regex_unsupported_declaration = /(?:var|function|class|type|interface|enum)\b/y;
// All except `type` are reserved keywords and cannot be used as variable names.
// For type we check if it's not something like `type .x` / `type ()` / `type % 2` / ...
const regex_unsupported_declaration =
/(?:(?:var|function|class|interface|enum)\b)|(?:type\s+[^?.(`<[&|%^}])/y;
const pointy_bois = { '<': '>' };

@ -0,0 +1,14 @@
[
{
"code": "declaration_tag_invalid_type",
"message": "Declaration tags must be `let` or `const` declarations",
"start": {
"line": 14,
"column": 2
},
"end": {
"line": 14,
"column": 8
}
}
]

@ -0,0 +1,15 @@
{#if true}
<!-- check that these doesn't trigger already -->
{type}
{type }
{type && foo}
{type || bar}
{type % 2}
{type .x}
{type ?.x}
{type ()}
{type [1]}
{type `tag`}
<!-- ... this one should trigger though -->
{type foo = boolean}
{/if}
Loading…
Cancel
Save