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

@vue-expect-error does not seem to work in the language-tools tsc tests #4203

Closed
tinco opened this issue Apr 3, 2024 · 8 comments
Closed
Labels
bug Something isn't working good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first

Comments

@tinco
Copy link
Contributor

tinco commented Apr 3, 2024

For example in the file test-workspace/tsc/vue3/v-bind-require-object/main.vue the code is:

<script setup lang="ts">
const foo = 1;
</script>

<template>
	<!-- @vue-expect-error -->
	<div v-bind="foo"></div>
</template>

To expect that foo = 1 makes the tsc fail. The error is succesfully repressed, so that works well. However if you change the code to foo = {}, like so:

<script setup lang="ts">
const foo = {};
</script>

<template>
	<!-- @vue-expect-error -->
	<div v-bind="foo"></div>
</template>

Then I would expect the test suite to fail because of there no longer being an error. Instead neither vscode, nor running:

 pnpm run test packages/tsc

Gives any error.

If I remove the <!-- @vue-expect-error --> then the code properly typechecks with foo = {} and properly fails with foo = 1.

@tinco tinco changed the title @vue-expect-error does not seem to work in the languaget-tools tsc tests @vue-expect-error does not seem to work in the language-tools tsc tests Apr 3, 2024
@so1ve
Copy link
Member

so1ve commented Apr 3, 2024

You should use pnpm run test tsc, since vitest packages/tsc doesn't match any tests.

@tinco
Copy link
Contributor Author

tinco commented Apr 3, 2024

hi! that makes no difference for me, still same result:

image

@tinco
Copy link
Contributor Author

tinco commented Apr 3, 2024

I can't figure out how to debug this, how do you get it to print the generated typescript?

edit: nvm I figured it out, this is the generated typescript:

const foo = {};
let __VLS_modelEmitsType!: {};

const __VLS_componentsOption = {};

let __VLS_name!: 'main';
function __VLS_template() {
let __VLS_ctx!: InstanceType<__VLS_PickNotAny<typeof __VLS_internalComponent, new () => {}>> & {
};
/* Components */
let __VLS_otherComponents!: NonNullable<typeof __VLS_internalComponent extends { components: infer C } ? C : {}> & typeof __VLS_componentsOption;
let __VLS_own!: __VLS_SelfComponent<typeof __VLS_name, typeof __VLS_internalComponent & (new () => { $scopedSlots: typeof __VLS_slots })>;
let __VLS_localComponents!: typeof __VLS_otherComponents & Omit<typeof __VLS_own, keyof typeof __VLS_otherComponents>;
let __VLS_components!: typeof __VLS_localComponents & __VLS_GlobalComponents & typeof __VLS_ctx;
/* Style Scoped */
type __VLS_StyleScopedClasses = {};
let __VLS_styleScopedClasses!: __VLS_StyleScopedClasses | keyof __VLS_StyleScopedClasses | (keyof __VLS_StyleScopedClasses)[];
/* CSS variable injection */
/* CSS variable injection end */
let __VLS_resolvedLocalAndGlobalComponents!: {}
;
__VLS_intrinsicElements.div;__VLS_intrinsicElements.div;
{
const __VLS_0 = __VLS_intrinsicElements["div"];
const __VLS_1 = __VLS_elementAsFunctionalComponent(__VLS_0);
const __VLS_2 = __VLS_1({ ...{ }, ...(__VLS_ctx.foo), }, ...__VLS_functionalComponentArgsRest(__VLS_1));
({} as (props: __VLS_FunctionalComponentProps<typeof __VLS_0, typeof __VLS_2> & Record<string, unknown>) => void)({ ...{ }, ...(__VLS_ctx.foo), });
// @ts-expect-error __VLS_TS_EXPECT_ERROR
;
const __VLS_3 = __VLS_pickFunctionalComponentCtx(__VLS_0, __VLS_2)!;
}
if (typeof __VLS_styleScopedClasses === 'object' && !Array.isArray(__VLS_styleScopedClasses)) {
}
var __VLS_slots!:{
};
// @ts-ignore
[foo,foo,];
return __VLS_slots;
}
const __VLS_internalComponent = (await import('vue')).defineComponent({
setup() {
return {
foo: foo as typeof foo,
};
},
});
export default (await import('vue')).defineComponent({
setup() {
return {
};
},
});

type __VLS_IntrinsicElementsCompletion = __VLS_IntrinsicElements;

Notice how there's an errant semicolon before the line that I suppose does the reading of the variable. My editor does warn it's unused though, so at least the test suite should have picked up, I don't know why it doesn't:

image

Removing the semicolon makes it properly pick up the error on the next line if there is an error, so that's at least messing with things.

@so1ve
Copy link
Member

so1ve commented Apr 4, 2024

Cool! Seemed to be a bug.

@so1ve so1ve added bug Something isn't working good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first labels Apr 4, 2024
@tinco
Copy link
Contributor Author

tinco commented Apr 4, 2024

I'm sorry I'm having a lot of trouble debugging this. In the tsc package it says:

require('../index.js').run();

But if I add console.log to index.ts in that directory it doesn't affect the test output even though if I add console.log's to vue-tsc.js that does print. I don't understand where that index.js is supposed to be, or how it's generated and how I trigger regeneration.

Do you have any pointers to how to debug things in this project?

@tinco
Copy link
Contributor Author

tinco commented Apr 4, 2024

I suppose I missed the build step. Still awkward that I can't figure out where the results of the build step actually go, but I guess that's a mystery for the ages.

I did figure out that this was already broken in v2.0.0. Now I'm struggling to get v1.8.7 to build.

@tinco
Copy link
Contributor Author

tinco commented Apr 4, 2024

Ok I don't know why I struggled with that at first, but pnpm install and then pnpm build worked just fine. I can confirm that things used to work in v1.8.27. So something went wrong during the v2.0.0 upgrade, which I suppose was a big change.

@tinco
Copy link
Contributor Author

tinco commented Apr 4, 2024

Alright, git bisect tells me:

tinco@tinco-aero-dev language-tools % git show tinco@tinco-aero-dev language-tools % git bisect good
72d3c6c4074c2761fe9e760538bccb16ad543539 is the first bad commit
commit 72d3c6c4074c2761fe9e760538bccb16ad543539
Author: Johnson Chu <johnsoncodehk@gmail.com>
Date:   Wed Dec 6 22:03:24 2023 +0800

    refactor(langauge-core): codegen based on Generator (#3778)

 packages/language-core/src/generators/script.ts    |  964 +++++-----
 packages/language-core/src/generators/template.ts  | 1946 +++++++++-----------
 packages/language-core/src/generators/utils.ts     |   19 +-
 packages/language-core/src/plugins/vue-tsx.ts      |  115 +-
 packages/language-core/src/types.ts                |    2 +
 packages/language-core/src/utils/transform.ts      |   72 +-
 packages/language-service/src/helpers.ts           |    4 +-
 .../src/plugins/vue-toggle-v-bind-codeaction.ts    |    6 +-
 8 files changed, 1541 insertions(+), 1587 deletions(-)

But that's a huge commit so I don't think it's much help unfortunately. Maybe @johnsoncodehk has a tip?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first
Projects
None yet
Development

No branches or pull requests

2 participants