Skip to content

Commit

Permalink
chore(language-core): only generate __typeProps, __typeEmits for …
Browse files Browse the repository at this point in the history
…Vue 3.5
  • Loading branch information
johnsoncodehk committed Apr 27, 2024
1 parent a27caa1 commit 66bdccc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
17 changes: 10 additions & 7 deletions packages/language-core/lib/codegen/script/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function* generateComponent(
yield `}${endOfLine}`;
yield `},${newLine}`;
if (!ctx.bypassDefineComponent) {
yield* generateScriptSetupOptions(ctx, scriptSetup, scriptSetupRanges);
yield* generateScriptSetupOptions(options, ctx, scriptSetup, scriptSetupRanges);
}
if (options.sfc.script && options.scriptRanges) {
yield* generateScriptOptions(options.sfc.script, options.scriptRanges);
Expand Down Expand Up @@ -62,6 +62,7 @@ export function* generateScriptOptions(
}

export function* generateScriptSetupOptions(
options: ScriptCodegenOptions,
ctx: ScriptCodegenContext,
scriptSetup: NonNullable<Sfc['scriptSetup']>,
scriptSetupRanges: ScriptSetupRanges,
Expand Down Expand Up @@ -113,11 +114,13 @@ export function* generateScriptSetupOptions(
yield `>),${newLine}`;
}

// https://github.com/vuejs/core/pull/10801
if (scriptSetupRanges.props.define?.typeArg) {
yield `__typeProps: typeof __VLS_typeProps,${newLine}`;
}
if (scriptSetupRanges.emits.define) {
yield `__typeEmits: typeof ${scriptSetupRanges.emits.name ?? '__VLS_emit'},${newLine}`;
if (options.vueCompilerOptions.target >= 3.5) {
// https://github.com/vuejs/core/pull/10801
if (scriptSetupRanges.props.define?.typeArg) {
yield `__typeProps: typeof __VLS_typeProps,${newLine}`;
}
if (scriptSetupRanges.emits.define?.typeArg) {
yield `__typeEmits: typeof ${scriptSetupRanges.emits.name ?? '__VLS_emit'},${newLine}`;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function* generateInternalComponent(
yield `}${endOfLine}`; // return {
yield `},${newLine}`; // setup() {
if (options.sfc.scriptSetup && options.scriptSetupRanges && !ctx.bypassDefineComponent) {
yield* generateScriptSetupOptions(ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
yield* generateScriptSetupOptions(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
}
if (options.sfc.script && options.scriptRanges) {
yield* generateScriptOptions(options.sfc.script, options.scriptRanges);
Expand Down
3 changes: 2 additions & 1 deletion packages/language-core/schemas/vue-tsconfig.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
2,
2.7,
3,
3.3
3.3,
3.5
],
"markdownDescription": "Target version of Vue."
},
Expand Down

0 comments on commit 66bdccc

Please sign in to comment.