From 0f40da7acbdf2590faf6703da74405c6f38c5702 Mon Sep 17 00:00:00 2001 From: "Lyu, Wei Da" Date: Mon, 2 Oct 2023 13:25:03 +0800 Subject: [PATCH] fix: enhance precompile blank for parser error workaround --- packages/svelte2tsx/src/utils/htmlxparser.ts | 2 +- .../samples/editing-bracket/expected.error.json | 16 ++++++++++++++++ .../samples/editing-bracket/expectedv2.js | 1 + .../samples/editing-bracket/input.svelte | 1 + .../editing-parentheses/expected.error.json | 16 ++++++++++++++++ .../samples/editing-parentheses/expectedv2.js | 7 +++++++ .../samples/editing-parentheses/input.svelte | 7 +++++++ 7 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 packages/svelte2tsx/test/htmlx2jsx/samples/editing-bracket/expected.error.json create mode 100644 packages/svelte2tsx/test/htmlx2jsx/samples/editing-bracket/expectedv2.js create mode 100644 packages/svelte2tsx/test/htmlx2jsx/samples/editing-bracket/input.svelte create mode 100644 packages/svelte2tsx/test/htmlx2jsx/samples/editing-parentheses/expected.error.json create mode 100644 packages/svelte2tsx/test/htmlx2jsx/samples/editing-parentheses/expectedv2.js create mode 100644 packages/svelte2tsx/test/htmlx2jsx/samples/editing-parentheses/input.svelte diff --git a/packages/svelte2tsx/src/utils/htmlxparser.ts b/packages/svelte2tsx/src/utils/htmlxparser.ts index 7c5c35b97..a2682cfdd 100644 --- a/packages/svelte2tsx/src/utils/htmlxparser.ts +++ b/packages/svelte2tsx/src/utils/htmlxparser.ts @@ -163,7 +163,7 @@ function blankPossiblyErrorOperatorOrPropertyAccess(htmlx: string) { } htmlx = htmlx.substring(0, backwardIndex) + ' ' + htmlx.substring(backwardIndex + 1); - } else if (!/\s/.test(char)) { + } else if (!/\s/.test(char) && char !== ')' && char !== ']') { break; } backwardIndex--; diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/editing-bracket/expected.error.json b/packages/svelte2tsx/test/htmlx2jsx/samples/editing-bracket/expected.error.json new file mode 100644 index 000000000..62c67b476 --- /dev/null +++ b/packages/svelte2tsx/test/htmlx2jsx/samples/editing-bracket/expected.error.json @@ -0,0 +1,16 @@ +{ + "name": "ParseError", + "code": "parse-error", + "start": { + "line": 1, + "column": 26, + "character": 26 + }, + "end": { + "line": 1, + "column": 26, + "character": 26 + }, + "pos": 26, + "frame": "1: {someRecord[anotherRecord.]}\n ^" +} \ No newline at end of file diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/editing-bracket/expectedv2.js b/packages/svelte2tsx/test/htmlx2jsx/samples/editing-bracket/expectedv2.js new file mode 100644 index 000000000..3503b42fa --- /dev/null +++ b/packages/svelte2tsx/test/htmlx2jsx/samples/editing-bracket/expectedv2.js @@ -0,0 +1 @@ +someRecord[anotherRecord.]; \ No newline at end of file diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/editing-bracket/input.svelte b/packages/svelte2tsx/test/htmlx2jsx/samples/editing-bracket/input.svelte new file mode 100644 index 000000000..0b41edb28 --- /dev/null +++ b/packages/svelte2tsx/test/htmlx2jsx/samples/editing-bracket/input.svelte @@ -0,0 +1 @@ +{someRecord[anotherRecord.]} diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/editing-parentheses/expected.error.json b/packages/svelte2tsx/test/htmlx2jsx/samples/editing-parentheses/expected.error.json new file mode 100644 index 000000000..ecd2606b1 --- /dev/null +++ b/packages/svelte2tsx/test/htmlx2jsx/samples/editing-parentheses/expected.error.json @@ -0,0 +1,16 @@ +{ + "name": "ParseError", + "code": "parse-error", + "start": { + "line": 1, + "column": 16, + "character": 16 + }, + "end": { + "line": 1, + "column": 16, + "character": 16 + }, + "pos": 16, + "frame": "1: {console.log(''.)}\n ^\n2: \n3: {#await Promise.resolve(''.)}" +} \ No newline at end of file diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/editing-parentheses/expectedv2.js b/packages/svelte2tsx/test/htmlx2jsx/samples/editing-parentheses/expectedv2.js new file mode 100644 index 000000000..680bddbf2 --- /dev/null +++ b/packages/svelte2tsx/test/htmlx2jsx/samples/editing-parentheses/expectedv2.js @@ -0,0 +1,7 @@ +console.log(''.); + + { + +const $$_value = await (Promise.resolve(''.));{ const value = $$_value; + +}} \ No newline at end of file diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/editing-parentheses/input.svelte b/packages/svelte2tsx/test/htmlx2jsx/samples/editing-parentheses/input.svelte new file mode 100644 index 000000000..e43762f0c --- /dev/null +++ b/packages/svelte2tsx/test/htmlx2jsx/samples/editing-parentheses/input.svelte @@ -0,0 +1,7 @@ +{console.log(''.)} + +{#await Promise.resolve(''.)} + +{:then value} + +{/await} \ No newline at end of file