From e34058972c994c2288e2df53294dba616359dec5 Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Wed, 14 Aug 2024 23:04:31 +0800 Subject: [PATCH 1/6] fix: should error when invalid syntax at script end --- packages/language-core/lib/codegen/script/index.ts | 10 +++++++++- .../language-core/lib/codegen/script/scriptSetup.ts | 8 ++++++++ packages/tsc/tests/index.spec.ts | 1 + test-workspace/tsc/should-error-#3632/main.vue | 3 +++ test-workspace/tsc/should-error-#3632/tsconfig.json | 4 ++++ 5 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 test-workspace/tsc/should-error-#3632/main.vue create mode 100644 test-workspace/tsc/should-error-#3632/tsconfig.json diff --git a/packages/language-core/lib/codegen/script/index.ts b/packages/language-core/lib/codegen/script/index.ts index ec48ad0a81..dbd85b991d 100644 --- a/packages/language-core/lib/codegen/script/index.ts +++ b/packages/language-core/lib/codegen/script/index.ts @@ -114,7 +114,15 @@ export function* generateScript(options: ScriptCodegenOptions): Generator(t: T) { return t })(`; diff --git a/packages/tsc/tests/index.spec.ts b/packages/tsc/tests/index.spec.ts index 7d39072d75..136f7fea4c 100644 --- a/packages/tsc/tests/index.spec.ts +++ b/packages/tsc/tests/index.spec.ts @@ -9,6 +9,7 @@ const shouldErrorDirs = [ 'should-error', 'should-error-2', 'should-error-3', + 'should-error-#3632', 'should-error-#4569', ]; diff --git a/test-workspace/tsc/should-error-#3632/main.vue b/test-workspace/tsc/should-error-#3632/main.vue new file mode 100644 index 0000000000..5dd8b35a6a --- /dev/null +++ b/test-workspace/tsc/should-error-#3632/main.vue @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/test-workspace/tsc/should-error-#3632/tsconfig.json b/test-workspace/tsc/should-error-#3632/tsconfig.json new file mode 100644 index 0000000000..a1e651d6e8 --- /dev/null +++ b/test-workspace/tsc/should-error-#3632/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.json", + "include": [ "**/*" ] +} From 3dcebe6cae19a01034ecd56fb1bf6519129b2c18 Mon Sep 17 00:00:00 2001 From: Johnson Chu Date: Mon, 26 Aug 2024 07:45:12 +0800 Subject: [PATCH 2/6] Update test --- packages/tsc/tests/typecheck.spec.ts | 2 ++ .../{should-error-#3632 => failureFixtures/#3632}/main.vue | 2 +- test-workspace/tsc/failureFixtures/#3632/tsconfig.json | 4 ++++ test-workspace/tsc/should-error-#3632/tsconfig.json | 4 ---- test-workspace/tsc/tsconfig.json | 1 + 5 files changed, 8 insertions(+), 5 deletions(-) rename test-workspace/tsc/{should-error-#3632 => failureFixtures/#3632}/main.vue (79%) create mode 100644 test-workspace/tsc/failureFixtures/#3632/tsconfig.json delete mode 100644 test-workspace/tsc/should-error-#3632/tsconfig.json diff --git a/packages/tsc/tests/typecheck.spec.ts b/packages/tsc/tests/typecheck.spec.ts index a7cc585449..c19d383c45 100644 --- a/packages/tsc/tests/typecheck.spec.ts +++ b/packages/tsc/tests/typecheck.spec.ts @@ -9,6 +9,7 @@ describe(`vue-tsc`, () => { getTscOutput('stable') ).toMatchInlineSnapshot(` [ + "test-workspace/tsc/failureFixtures/#3632/main.vue(2,13): error TS1109: Expression expected.", "test-workspace/tsc/failureFixtures/directives/main.vue(4,6): error TS2339: Property 'notExist' does not exist on type 'CreateComponentPublicInstance>, { exist: typeof exist; }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 12 more ..., {}>'.", "test-workspace/tsc/failureFixtures/directives/main.vue(9,6): error TS2339: Property 'notExist' does not exist on type 'CreateComponentPublicInstance>, { exist: typeof exist; }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 12 more ..., {}>'.", "test-workspace/tsc/failureFixtures/directives/main.vue(12,2): error TS2578: Unused '@ts-expect-error' directive.", @@ -21,6 +22,7 @@ describe(`vue-tsc`, () => { getTscOutput('next') ).toMatchInlineSnapshot(` [ + "test-workspace/tsc/failureFixtures/#3632/main.vue(2,13): error TS1109: Expression expected.", "test-workspace/tsc/failureFixtures/directives/main.vue(4,6): error TS2339: Property 'notExist' does not exist on type 'CreateComponentPublicInstance>, { exist: typeof exist; }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 12 more ..., {}>'.", "test-workspace/tsc/failureFixtures/directives/main.vue(9,6): error TS2339: Property 'notExist' does not exist on type 'CreateComponentPublicInstance>, { exist: typeof exist; }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 12 more ..., {}>'.", "test-workspace/tsc/failureFixtures/directives/main.vue(12,2): error TS2578: Unused '@ts-expect-error' directive.", diff --git a/test-workspace/tsc/should-error-#3632/main.vue b/test-workspace/tsc/failureFixtures/#3632/main.vue similarity index 79% rename from test-workspace/tsc/should-error-#3632/main.vue rename to test-workspace/tsc/failureFixtures/#3632/main.vue index 5dd8b35a6a..791a3030cc 100644 --- a/test-workspace/tsc/should-error-#3632/main.vue +++ b/test-workspace/tsc/failureFixtures/#3632/main.vue @@ -1,3 +1,3 @@ \ No newline at end of file + diff --git a/test-workspace/tsc/failureFixtures/#3632/tsconfig.json b/test-workspace/tsc/failureFixtures/#3632/tsconfig.json new file mode 100644 index 0000000000..52ecbeb3c3 --- /dev/null +++ b/test-workspace/tsc/failureFixtures/#3632/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../../tsconfig.base.json", + "include": [ "**/*" ] +} diff --git a/test-workspace/tsc/should-error-#3632/tsconfig.json b/test-workspace/tsc/should-error-#3632/tsconfig.json deleted file mode 100644 index a1e651d6e8..0000000000 --- a/test-workspace/tsc/should-error-#3632/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "include": [ "**/*" ] -} diff --git a/test-workspace/tsc/tsconfig.json b/test-workspace/tsc/tsconfig.json index 714f41f63f..5fe8b46ccf 100644 --- a/test-workspace/tsc/tsconfig.json +++ b/test-workspace/tsc/tsconfig.json @@ -1,6 +1,7 @@ { "include": [ ], "references": [ + { "path": "./failureFixtures/#3632" }, // { "path": "./failureFixtures/#4569" }, // TODO: not working with --build flag { "path": "./failureFixtures/directives" }, From a1592fb0d0c547f0f14c3e8da972afe2d09447ec Mon Sep 17 00:00:00 2001 From: Johnson Chu Date: Wed, 23 Oct 2024 15:21:00 +0800 Subject: [PATCH 3/6] Update typecheck.spec.ts --- packages/tsc/tests/typecheck.spec.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/tsc/tests/typecheck.spec.ts b/packages/tsc/tests/typecheck.spec.ts index 679513ab49..c84ac2ed19 100644 --- a/packages/tsc/tests/typecheck.spec.ts +++ b/packages/tsc/tests/typecheck.spec.ts @@ -9,6 +9,7 @@ describe(`vue-tsc`, () => { getTscOutput('stable') ).toMatchInlineSnapshot(` [ + "test-workspace/tsc/failureFixtures/#3632/main.vue(2,13): error TS1109: Expression expected.", "test-workspace/tsc/failureFixtures/directives/main.vue(4,6): error TS2339: Property 'notExist' does not exist on type 'CreateComponentPublicInstanceWithMixins, { exist: typeof exist; }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 18 more ..., {}>'.", "test-workspace/tsc/failureFixtures/directives/main.vue(9,6): error TS2339: Property 'notExist' does not exist on type 'CreateComponentPublicInstanceWithMixins, { exist: typeof exist; }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 18 more ..., {}>'.", "test-workspace/tsc/failureFixtures/directives/main.vue(12,2): error TS2578: Unused '@ts-expect-error' directive.", @@ -24,6 +25,7 @@ describe(`vue-tsc`, () => { getTscOutput('next') ).toMatchInlineSnapshot(` [ + "test-workspace/tsc/failureFixtures/#3632/main.vue(2,13): error TS1109: Expression expected.", "test-workspace/tsc/failureFixtures/directives/main.vue(4,6): error TS2339: Property 'notExist' does not exist on type 'CreateComponentPublicInstanceWithMixins, { exist: typeof exist; }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 18 more ..., {}>'.", "test-workspace/tsc/failureFixtures/directives/main.vue(9,6): error TS2339: Property 'notExist' does not exist on type 'CreateComponentPublicInstanceWithMixins, { exist: typeof exist; }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 18 more ..., {}>'.", "test-workspace/tsc/failureFixtures/directives/main.vue(12,2): error TS2578: Unused '@ts-expect-error' directive.", From 10e8c1f04c721cbc96bb70a23cb9fb9a7db921ae Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Wed, 23 Oct 2024 15:47:39 +0800 Subject: [PATCH 4/6] test: update snapshot --- packages/tsc/tests/typecheck.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/tsc/tests/typecheck.spec.ts b/packages/tsc/tests/typecheck.spec.ts index c84ac2ed19..604ae11025 100644 --- a/packages/tsc/tests/typecheck.spec.ts +++ b/packages/tsc/tests/typecheck.spec.ts @@ -9,7 +9,7 @@ describe(`vue-tsc`, () => { getTscOutput('stable') ).toMatchInlineSnapshot(` [ - "test-workspace/tsc/failureFixtures/#3632/main.vue(2,13): error TS1109: Expression expected.", + "test-workspace/tsc/failureFixtures/#3632/main.vue(2,12): error TS1109: Expression expected.", "test-workspace/tsc/failureFixtures/directives/main.vue(4,6): error TS2339: Property 'notExist' does not exist on type 'CreateComponentPublicInstanceWithMixins, { exist: typeof exist; }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 18 more ..., {}>'.", "test-workspace/tsc/failureFixtures/directives/main.vue(9,6): error TS2339: Property 'notExist' does not exist on type 'CreateComponentPublicInstanceWithMixins, { exist: typeof exist; }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 18 more ..., {}>'.", "test-workspace/tsc/failureFixtures/directives/main.vue(12,2): error TS2578: Unused '@ts-expect-error' directive.", @@ -25,7 +25,7 @@ describe(`vue-tsc`, () => { getTscOutput('next') ).toMatchInlineSnapshot(` [ - "test-workspace/tsc/failureFixtures/#3632/main.vue(2,13): error TS1109: Expression expected.", + "test-workspace/tsc/failureFixtures/#3632/main.vue(2,12): error TS1109: Expression expected.", "test-workspace/tsc/failureFixtures/directives/main.vue(4,6): error TS2339: Property 'notExist' does not exist on type 'CreateComponentPublicInstanceWithMixins, { exist: typeof exist; }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 18 more ..., {}>'.", "test-workspace/tsc/failureFixtures/directives/main.vue(9,6): error TS2339: Property 'notExist' does not exist on type 'CreateComponentPublicInstanceWithMixins, { exist: typeof exist; }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 18 more ..., {}>'.", "test-workspace/tsc/failureFixtures/directives/main.vue(12,2): error TS2578: Unused '@ts-expect-error' directive.", From c16eb6077ba59d802e9af26ec4d885ebec25e2ec Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Wed, 23 Oct 2024 15:51:15 +0800 Subject: [PATCH 5/6] test: update snapshot --- packages/tsc/tests/typecheck.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/tsc/tests/typecheck.spec.ts b/packages/tsc/tests/typecheck.spec.ts index 604ae11025..c84ac2ed19 100644 --- a/packages/tsc/tests/typecheck.spec.ts +++ b/packages/tsc/tests/typecheck.spec.ts @@ -9,7 +9,7 @@ describe(`vue-tsc`, () => { getTscOutput('stable') ).toMatchInlineSnapshot(` [ - "test-workspace/tsc/failureFixtures/#3632/main.vue(2,12): error TS1109: Expression expected.", + "test-workspace/tsc/failureFixtures/#3632/main.vue(2,13): error TS1109: Expression expected.", "test-workspace/tsc/failureFixtures/directives/main.vue(4,6): error TS2339: Property 'notExist' does not exist on type 'CreateComponentPublicInstanceWithMixins, { exist: typeof exist; }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 18 more ..., {}>'.", "test-workspace/tsc/failureFixtures/directives/main.vue(9,6): error TS2339: Property 'notExist' does not exist on type 'CreateComponentPublicInstanceWithMixins, { exist: typeof exist; }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 18 more ..., {}>'.", "test-workspace/tsc/failureFixtures/directives/main.vue(12,2): error TS2578: Unused '@ts-expect-error' directive.", @@ -25,7 +25,7 @@ describe(`vue-tsc`, () => { getTscOutput('next') ).toMatchInlineSnapshot(` [ - "test-workspace/tsc/failureFixtures/#3632/main.vue(2,12): error TS1109: Expression expected.", + "test-workspace/tsc/failureFixtures/#3632/main.vue(2,13): error TS1109: Expression expected.", "test-workspace/tsc/failureFixtures/directives/main.vue(4,6): error TS2339: Property 'notExist' does not exist on type 'CreateComponentPublicInstanceWithMixins, { exist: typeof exist; }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 18 more ..., {}>'.", "test-workspace/tsc/failureFixtures/directives/main.vue(9,6): error TS2339: Property 'notExist' does not exist on type 'CreateComponentPublicInstanceWithMixins, { exist: typeof exist; }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 18 more ..., {}>'.", "test-workspace/tsc/failureFixtures/directives/main.vue(12,2): error TS2578: Unused '@ts-expect-error' directive.", From f58f8cc3dfd2c90d20b4870d46b91a73b966dd0e Mon Sep 17 00:00:00 2001 From: Johnson Chu Date: Wed, 23 Oct 2024 18:35:35 +0800 Subject: [PATCH 6/6] handle for both script tags --- .../language-core/lib/codegen/script/index.ts | 21 +++++++++---------- .../lib/codegen/script/scriptSetup.ts | 12 +++-------- packages/tsc/tests/typecheck.spec.ts | 10 +++++++-- .../tsc/failureFixtures/#3632/both.vue | 7 +++++++ .../tsc/failureFixtures/#3632/script.vue | 3 +++ .../#3632/{main.vue => scriptSetup.vue} | 0 6 files changed, 31 insertions(+), 22 deletions(-) create mode 100644 test-workspace/tsc/failureFixtures/#3632/both.vue create mode 100644 test-workspace/tsc/failureFixtures/#3632/script.vue rename test-workspace/tsc/failureFixtures/#3632/{main.vue => scriptSetup.vue} (100%) diff --git a/packages/language-core/lib/codegen/script/index.ts b/packages/language-core/lib/codegen/script/index.ts index 11f0d71342..11da3c59e5 100644 --- a/packages/language-core/lib/codegen/script/index.ts +++ b/packages/language-core/lib/codegen/script/index.ts @@ -6,8 +6,8 @@ import type { Code, Sfc, VueCodeInformation, VueCompilerOptions } from '../../ty import { endOfLine, generateSfcBlockSection, newLine } from '../common'; import { generateGlobalTypes } from '../globalTypes'; import type { TemplateCodegenContext } from '../template/context'; -import { createScriptCodegenContext, ScriptCodegenContext } from './context'; import { generateComponentSelf } from './componentSelf'; +import { createScriptCodegenContext, ScriptCodegenContext } from './context'; import { generateScriptSetup, generateScriptSetupImports } from './scriptSetup'; import { generateSrc } from './src'; import { generateStyleModulesType } from './styleModulesType'; @@ -79,6 +79,7 @@ export function* generateScript(options: ScriptCodegenOptions): Generator { + yield `;`; + yield ['', source, end, codeFeatures.verification]; + yield `/* PartiallyEnd: ${mark} */${newLine}`; +} + function* generateDefineProp( options: ScriptCodegenOptions, scriptSetup: NonNullable diff --git a/packages/language-core/lib/codegen/script/scriptSetup.ts b/packages/language-core/lib/codegen/script/scriptSetup.ts index 2c211790b4..19db16b49a 100644 --- a/packages/language-core/lib/codegen/script/scriptSetup.ts +++ b/packages/language-core/lib/codegen/script/scriptSetup.ts @@ -2,9 +2,9 @@ import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges'; import type { Code, Sfc, TextRange } from '../../types'; import { endOfLine, generateSfcBlockSection, newLine } from '../common'; import { generateComponent, generateEmitsOption } from './component'; -import type { ScriptCodegenContext } from './context'; -import { ScriptCodegenOptions, codeFeatures } from './index'; import { generateComponentSelf } from './componentSelf'; +import type { ScriptCodegenContext } from './context'; +import { ScriptCodegenOptions, codeFeatures, generateScriptSectionPartiallyEnding } from './index'; import { generateTemplate } from './template'; export function* generateScriptSetupImports( @@ -278,13 +278,7 @@ function* generateSetupFunction( yield generateSfcBlockSection(scriptSetup, scriptSetupRanges.importSectionEndOffset, scriptSetup.content.length, codeFeatures.all); } - // #3632 - yield [ - ';', - 'scriptSetup', - scriptSetup.content.length - 1, - codeFeatures.verification, - ]; + yield* generateScriptSectionPartiallyEnding(scriptSetup.name, scriptSetup.content.length, '#3632/scriptSetup.vue'); if (scriptSetupRanges.props.define?.typeArg && scriptSetupRanges.props.withDefaults?.arg) { // fix https://github.com/vuejs/language-tools/issues/1187 diff --git a/packages/tsc/tests/typecheck.spec.ts b/packages/tsc/tests/typecheck.spec.ts index c84ac2ed19..68279f6379 100644 --- a/packages/tsc/tests/typecheck.spec.ts +++ b/packages/tsc/tests/typecheck.spec.ts @@ -9,7 +9,10 @@ describe(`vue-tsc`, () => { getTscOutput('stable') ).toMatchInlineSnapshot(` [ - "test-workspace/tsc/failureFixtures/#3632/main.vue(2,13): error TS1109: Expression expected.", + "test-workspace/tsc/failureFixtures/#3632/both.vue(3,1): error TS1109: Expression expected.", + "test-workspace/tsc/failureFixtures/#3632/both.vue(7,1): error TS1109: Expression expected.", + "test-workspace/tsc/failureFixtures/#3632/script.vue(3,1): error TS1109: Expression expected.", + "test-workspace/tsc/failureFixtures/#3632/scriptSetup.vue(3,1): error TS1109: Expression expected.", "test-workspace/tsc/failureFixtures/directives/main.vue(4,6): error TS2339: Property 'notExist' does not exist on type 'CreateComponentPublicInstanceWithMixins, { exist: typeof exist; }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 18 more ..., {}>'.", "test-workspace/tsc/failureFixtures/directives/main.vue(9,6): error TS2339: Property 'notExist' does not exist on type 'CreateComponentPublicInstanceWithMixins, { exist: typeof exist; }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 18 more ..., {}>'.", "test-workspace/tsc/failureFixtures/directives/main.vue(12,2): error TS2578: Unused '@ts-expect-error' directive.", @@ -25,7 +28,10 @@ describe(`vue-tsc`, () => { getTscOutput('next') ).toMatchInlineSnapshot(` [ - "test-workspace/tsc/failureFixtures/#3632/main.vue(2,13): error TS1109: Expression expected.", + "test-workspace/tsc/failureFixtures/#3632/both.vue(3,1): error TS1109: Expression expected.", + "test-workspace/tsc/failureFixtures/#3632/both.vue(7,1): error TS1109: Expression expected.", + "test-workspace/tsc/failureFixtures/#3632/script.vue(3,1): error TS1109: Expression expected.", + "test-workspace/tsc/failureFixtures/#3632/scriptSetup.vue(3,1): error TS1109: Expression expected.", "test-workspace/tsc/failureFixtures/directives/main.vue(4,6): error TS2339: Property 'notExist' does not exist on type 'CreateComponentPublicInstanceWithMixins, { exist: typeof exist; }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 18 more ..., {}>'.", "test-workspace/tsc/failureFixtures/directives/main.vue(9,6): error TS2339: Property 'notExist' does not exist on type 'CreateComponentPublicInstanceWithMixins, { exist: typeof exist; }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 18 more ..., {}>'.", "test-workspace/tsc/failureFixtures/directives/main.vue(12,2): error TS2578: Unused '@ts-expect-error' directive.", diff --git a/test-workspace/tsc/failureFixtures/#3632/both.vue b/test-workspace/tsc/failureFixtures/#3632/both.vue new file mode 100644 index 0000000000..ddcb6aeffc --- /dev/null +++ b/test-workspace/tsc/failureFixtures/#3632/both.vue @@ -0,0 +1,7 @@ + + + diff --git a/test-workspace/tsc/failureFixtures/#3632/script.vue b/test-workspace/tsc/failureFixtures/#3632/script.vue new file mode 100644 index 0000000000..d32d8fe997 --- /dev/null +++ b/test-workspace/tsc/failureFixtures/#3632/script.vue @@ -0,0 +1,3 @@ + diff --git a/test-workspace/tsc/failureFixtures/#3632/main.vue b/test-workspace/tsc/failureFixtures/#3632/scriptSetup.vue similarity index 100% rename from test-workspace/tsc/failureFixtures/#3632/main.vue rename to test-workspace/tsc/failureFixtures/#3632/scriptSetup.vue