Skip to content

Commit 4688357

Browse files
committed
fix(language-core): limit the range of parseDiagnostics checks
close #5823
1 parent 101787d commit 4688357

File tree

5 files changed

+17
-2
lines changed

5 files changed

+17
-2
lines changed

packages/language-core/lib/codegen/utils/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ export function* generateSfcBlockSection(
4545

4646
// #3632
4747
if ('parseDiagnostics' in block.ast) {
48-
const emptyEndLength = text.length - text.trimEnd().length;
48+
const textEnd = text.trimEnd().length;
4949
for (const diag of block.ast.parseDiagnostics as ts.DiagnosticWithLocation[]) {
50-
if (diag.start >= end - emptyEndLength) {
50+
const diagStart = diag.start;
51+
const diagEnd = diag.start + diag.length;
52+
if (diagStart >= textEnd && diagEnd <= end) {
5153
yield `;`;
5254
yield ['', block.name, end, codeFeatures.verification];
5355
yield newLine;

packages/tsc/tests/typecheck.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ describe(`vue-tsc`, () => {
1515
"test-workspace/tsc/failureFixtures/#4569/main.vue(1,41): error TS4025: Exported variable '__VLS_export' has or is using private name 'Props'.",
1616
"test-workspace/tsc/failureFixtures/#5071/withScript.vue(1,19): error TS1005: ';' expected.",
1717
"test-workspace/tsc/failureFixtures/#5071/withoutScript.vue(2,26): error TS1005: ';' expected.",
18+
"test-workspace/tsc/failureFixtures/#5823/main.vue(6,13): error TS1109: Expression expected.",
1819
"test-workspace/tsc/failureFixtures/directives/main.vue(14,6): error TS2339: Property 'notExist' does not exist on type '{ exist: {}; Comp: () => void; $: ComponentInternalInstance; $data: {}; $props: {}; $attrs: Data; $refs: Data; $slots: Readonly<InternalSlots>; ... 8 more ...; $watch<T extends string | ((...args: any) => any)>(source: T, cb: T extends (...args: any) => infer R ? (args_0: R, args_1: R, args_2: OnCleanup) => any : (a...'.",
1920
"test-workspace/tsc/failureFixtures/directives/main.vue(17,2): error TS2578: Unused '@ts-expect-error' directive.",
2021
"test-workspace/tsc/failureFixtures/directives/main.vue(20,2): error TS2578: Unused '@ts-expect-error' directive.",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script lang="ts" generic="T" setup>
2+
const { info } = defineProps<{
3+
info?: T;
4+
}>();
5+
6+
const foo = ;
7+
</script>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "../../../tsconfig.base.json",
3+
"include": ["**/*"]
4+
}

test-workspace/tsc/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{ "path": "./failureFixtures/#3632" },
55
{ "path": "./failureFixtures/#4569" },
66
{ "path": "./failureFixtures/#5071" },
7+
{ "path": "./failureFixtures/#5823" },
78
{ "path": "./failureFixtures/directives" },
89

910
{ "path": "./passedFixtures/#1886" },

0 commit comments

Comments
 (0)