diff --git a/packages/language-core/lib/codegen/script/component.ts b/packages/language-core/lib/codegen/script/component.ts index 4a9a091439..aec34c5fa3 100644 --- a/packages/language-core/lib/codegen/script/component.ts +++ b/packages/language-core/lib/codegen/script/component.ts @@ -37,10 +37,18 @@ export function* generateComponent( } yield* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, !!emitOptionCodes.length, true); } - if (options.vueCompilerOptions.target >= 3.5 && options.templateCodegen?.templateRefs.size) { + if ( + options.vueCompilerOptions.target >= 3.5 + && options.vueCompilerOptions.inferComponentDollarRefs + && options.templateCodegen?.templateRefs.size + ) { yield `__typeRefs: {} as __VLS_TemplateRefs,${newLine}`; } - if (options.vueCompilerOptions.target >= 3.5 && options.templateCodegen?.singleRootElType) { + if ( + options.vueCompilerOptions.target >= 3.5 + && options.vueCompilerOptions.inferComponentDollarEl + && options.templateCodegen?.singleRootElType + ) { yield `__typeEl: {} as __VLS_RootEl,${newLine}`; } if (options.sfc.script && options.scriptRanges?.exportDefault?.args) { diff --git a/packages/language-core/lib/codegen/script/scriptSetup.ts b/packages/language-core/lib/codegen/script/scriptSetup.ts index 9bf052af3f..18a1211168 100644 --- a/packages/language-core/lib/codegen/script/scriptSetup.ts +++ b/packages/language-core/lib/codegen/script/scriptSetup.ts @@ -171,16 +171,18 @@ function* generateSetupFunction( ]); } } - for (const { callExp } of scriptSetupRanges.useAttrs) { - setupCodeModifies.push([ - [`(`], - callExp.start, - callExp.start - ], [ - [` as typeof __VLS_special.$attrs)`], - callExp.end, - callExp.end - ]); + if (options.vueCompilerOptions.inferTemplateDollarAttrs) { + for (const { callExp } of scriptSetupRanges.useAttrs) { + setupCodeModifies.push([ + [`(`], + callExp.start, + callExp.start + ], [ + [` as typeof __VLS_dollars.$attrs)`], + callExp.end, + callExp.end + ]); + } } for (const { callExp, exp, arg } of scriptSetupRanges.useCssModule) { setupCodeModifies.push([ @@ -210,16 +212,18 @@ function* generateSetupFunction( ]); } } - for (const { callExp } of scriptSetupRanges.useSlots) { - setupCodeModifies.push([ - [`(`], - callExp.start, - callExp.start - ], [ - [` as typeof __VLS_special.$slots)`], - callExp.end, - callExp.end - ]); + if (options.vueCompilerOptions.inferTemplateDollarSlots) { + for (const { callExp } of scriptSetupRanges.useSlots) { + setupCodeModifies.push([ + [`(`], + callExp.start, + callExp.start + ], [ + [` as typeof __VLS_dollars.$slots)`], + callExp.end, + callExp.end + ]); + } } const isTs = options.lang !== 'js' && options.lang !== 'jsx'; for (const { callExp, exp, arg } of scriptSetupRanges.useTemplateRef) { diff --git a/packages/language-core/lib/codegen/template/context.ts b/packages/language-core/lib/codegen/template/context.ts index cc3d5bffd9..4c5cd6a363 100644 --- a/packages/language-core/lib/codegen/template/context.ts +++ b/packages/language-core/lib/codegen/template/context.ts @@ -45,7 +45,7 @@ export function createTemplateCodegenContext(options: Pick(); const localVars = new Map(); - const specialVars = new Set(); + const dollarVars = new Set(); const accessExternalVariables = new Map>(); const slots: { name: string; @@ -83,7 +83,7 @@ export function createTemplateCodegenContext(options: Pick, + dollarVars: Set, destructuredPropNames: Set | undefined, templateRefNames: Set | undefined, curVar: CtxVar @@ -175,8 +175,8 @@ function* generateVar( yield [`)`, undefined]; } else { - if (specialVars.has(curVar.text)) { - yield [`__VLS_special.`, undefined]; + if (dollarVars.has(curVar.text)) { + yield [`__VLS_dollars.`, undefined]; } else if (!isDestructuredProp) { yield [`__VLS_ctx.`, undefined]; diff --git a/packages/language-core/lib/plugins/file-md.ts b/packages/language-core/lib/plugins/file-md.ts index b3705ce88a..b0afb41ab4 100644 --- a/packages/language-core/lib/plugins/file-md.ts +++ b/packages/language-core/lib/plugins/file-md.ts @@ -7,6 +7,7 @@ import { parse } from '../utils/parseSfc'; const codeblockReg = /(`{3,})[\s\S]+?\1/g; const inlineCodeblockReg = /`[^\n`]+?`/g; +const latexBlockReg = /(\${2,})[\s\S]+?\1/g; const scriptSetupReg = /\\\<[\s\S]+?\>\n?/g; const sfcBlockReg = /\<(script|style)\b[\s\S]*?\>([\s\S]*?)\<\/\1\>/g; const angleBracketReg = /\<\S*\:\S*\>/g; @@ -39,6 +40,8 @@ const plugin: VueLanguagePlugin = ({ vueCompilerOptions }) => { .replace(codeblockReg, (match, quotes) => quotes + ' '.repeat(match.length - quotes.length * 2) + quotes) // inline code block .replace(inlineCodeblockReg, match => `\`${' '.repeat(match.length - 2)}\``) + // latex block + .replace(latexBlockReg, (match, quotes) => quotes + ' '.repeat(match.length - quotes.length * 2) + quotes) // # \ diff --git a/test-workspace/tsc/passedFixtures/vue3/rootEl/child.vue b/test-workspace/tsc/passedFixtures/vue3/rootEl/child.vue index ba23fc8016..883c5d4f41 100644 --- a/test-workspace/tsc/passedFixtures/vue3/rootEl/child.vue +++ b/test-workspace/tsc/passedFixtures/vue3/rootEl/child.vue @@ -1,3 +1,6 @@ + + +