Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(language-core): should error when invalid syntax at script end #4692

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/language-core/lib/codegen/script/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,15 @@ export function* generateScript(options: ScriptCodegenOptions): Generator<Code,
yield* generateScriptSetup(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
}

yield `;`;
if (options.sfc.script) {
// #3632
yield [
';',
'script',
options.sfc.script.content.length - 1,
codeFeatures.verification,
];
}
if (options.sfc.scriptSetup) {
// #4569
yield [
Expand Down
8 changes: 8 additions & 0 deletions packages/language-core/lib/codegen/script/scriptSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,14 @@ function* generateSetupFunction(
yield generateSfcBlockSection(scriptSetup, scriptSetupRanges.importSectionEndOffset, scriptSetup.content.length, codeFeatures.all);
}

// #3632
yield [
';',
'scriptSetup',
scriptSetup.content.length - 1,
codeFeatures.verification,
];

if (scriptSetupRanges.props.define?.typeArg && scriptSetupRanges.props.withDefaults?.arg) {
// fix https://github.com/vuejs/language-tools/issues/1187
yield `const __VLS_withDefaultsArg = (function <T>(t: T) { return t })(`;
Expand Down
2 changes: 2 additions & 0 deletions packages/tsc/tests/typecheck.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
test(`TypeScript - Stable`, () => {
expect(
getTscOutput('stable')
).toMatchInlineSnapshot(`

Check failure on line 10 in packages/tsc/tests/typecheck.spec.ts

View workflow job for this annotation

GitHub Actions / build (18, windows-latest)

packages/tsc/tests/typecheck.spec.ts > vue-tsc > TypeScript - Stable

Error: Snapshot `vue-tsc > TypeScript - Stable 1` mismatched - Expected + Received [ - "test-workspace/tsc/failureFixtures/#3632/main.vue(2,13): error TS1109: Expression expected.", + "test-workspace/tsc/failureFixtures/#3632/main.vue(2,14): error TS1109: Expression expected.", "test-workspace/tsc/failureFixtures/directives/main.vue(4,6): error TS2339: Property 'notExist' does not exist on type 'CreateComponentPublicInstance<Readonly<ExtractPropTypes<{}>>, { 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<Readonly<ExtractPropTypes<{}>>, { exist: typeof exist; }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 12 more ..., {}>'.", "test-workspace/tsc/failureFixtures/directives/main.vue(12,2): error TS2578: Unused '@ts-expect-error' directive.", ] ❯ packages/tsc/tests/typecheck.spec.ts:10:5
[
"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<Readonly<ExtractPropTypes<{}>>, { 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<Readonly<ExtractPropTypes<{}>>, { exist: typeof exist; }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 12 more ..., {}>'.",
"test-workspace/tsc/failureFixtures/directives/main.vue(12,2): error TS2578: Unused '@ts-expect-error' directive.",
Expand All @@ -19,8 +20,9 @@
test.skipIf(!process.env.GITHUB_ACTIONS)(`TypeScript - Next`, () => {
expect(
getTscOutput('next')
).toMatchInlineSnapshot(`

Check failure on line 23 in packages/tsc/tests/typecheck.spec.ts

View workflow job for this annotation

GitHub Actions / build (18, windows-latest)

packages/tsc/tests/typecheck.spec.ts > vue-tsc > TypeScript - Next

Error: Snapshot `vue-tsc > TypeScript - Next 1` mismatched - Expected + Received @@ -1,7 +1,7 @@ [ - "test-workspace/tsc/failureFixtures/#3632/main.vue(2,13): error TS1109: Expression expected.", + "test-workspace/tsc/failureFixtures/#3632/main.vue(2,14): error TS1109: Expression expected.", "test-workspace/tsc/failureFixtures/directives/main.vue(4,6): error TS2339: Property 'notExist' does not exist on type 'CreateComponentPublicInstance<Readonly<ExtractPropTypes<{}>>, { 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<Readonly<ExtractPropTypes<{}>>, { exist: typeof exist; }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 12 more ..., {}>'.", "test-workspace/tsc/failureFixtures/directives/main.vue(12,2): error TS2578: Unused '@ts-expect-error' directive.", "test-workspace/tsc/passedFixtures/#3373/tsconfig.json(4,3): error TS5102: Option 'importsNotUsedAsValues' has been removed. Please remove it from your configuration. Use 'verbatimModuleSyntax' instead.", ❯ packages/tsc/tests/typecheck.spec.ts:23:5
[
"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<Readonly<ExtractPropTypes<{}>>, { 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<Readonly<ExtractPropTypes<{}>>, { exist: typeof exist; }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 12 more ..., {}>'.",
"test-workspace/tsc/failureFixtures/directives/main.vue(12,2): error TS2578: Unused '@ts-expect-error' directive.",
Expand Down
3 changes: 3 additions & 0 deletions test-workspace/tsc/failureFixtures/#3632/main.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<script lang="ts" setup>
const foo =
</script>
4 changes: 4 additions & 0 deletions test-workspace/tsc/failureFixtures/#3632/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../../tsconfig.base.json",
"include": [ "**/*" ]
}
1 change: 1 addition & 0 deletions test-workspace/tsc/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"include": [ ],
"references": [
{ "path": "./failureFixtures/#3632" },
// { "path": "./failureFixtures/#4569" }, // TODO: not working with --build flag
{ "path": "./failureFixtures/directives" },

Expand Down
Loading