Skip to content

Commit

Permalink
chore(language-core): virtual code adjust
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Apr 26, 2024
1 parent 572ee13 commit 1940c6d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 1 addition & 2 deletions packages/language-core/lib/codegen/script/component.ts
Expand Up @@ -75,8 +75,7 @@ export function* generateScriptSetupOptions(
yield `${ctx.helperTypes.WithDefaults.name}<`;
}
yield `${ctx.helperTypes.TypePropsToOption.name}<`;
yield `typeof __VLS_componentProps`;
yield `>`;
yield `typeof __VLS_componentProps>`;
if (scriptSetupRanges.props.withDefaults?.arg) {
yield `, typeof __VLS_withDefaultsArg>`;
}
Expand Down
5 changes: 4 additions & 1 deletion packages/language-core/lib/codegen/script/scriptSetup.ts
Expand Up @@ -51,7 +51,10 @@ export function* generateScriptSetup(
+ ` expose(exposed: import('${options.vueCompilerOptions.lib}').ShallowUnwrapRef<${scriptSetupRanges.expose.define ? 'typeof __VLS_exposed' : '{}'}>): void,${newLine}`
+ ` attrs: any,${newLine}`
+ ` slots: ReturnType<typeof __VLS_template>,${newLine}`
+ ` emit: typeof ${scriptSetupRanges.emits.name ?? '__VLS_emit'} & typeof __VLS_modelEmitsType,${newLine}`
+ ` emit: ${scriptSetupRanges.emits.define
? `typeof '${scriptSetupRanges.emits.name ?? '__VLS_emit'} & `
: ''
}typeof __VLS_modelEmitsType,${newLine}`
+ ` }${endOfLine}`;
yield ` })(),${newLine}`; // __VLS_setup = (async () => {
yield `) => ({} as import('${options.vueCompilerOptions.lib}').VNode & { __ctx?: Awaited<typeof __VLS_setup> }))`;
Expand Down
8 changes: 5 additions & 3 deletions packages/language-core/lib/codegen/script/template.ts
Expand Up @@ -128,10 +128,7 @@ function* generateTemplateContext(
}
yield endOfLine;
yield `let __VLS_styleScopedClasses!: __VLS_StyleScopedClasses | keyof __VLS_StyleScopedClasses | (keyof __VLS_StyleScopedClasses)[]${endOfLine}`;

yield `/* CSS variable injection */${newLine}`;
yield* generateCssVars(options, templateCodegenCtx);
yield `/* CSS variable injection end */${newLine}`;

if (options.templateCodegen) {
for (const code of options.templateCodegen.tsCodes) {
Expand Down Expand Up @@ -190,6 +187,10 @@ function* generateCssClassProperty(
}

function* generateCssVars(options: ScriptCodegenOptions, ctx: TemplateCodegenContext): Generator<Code> {
if (!options.sfc.styles.length) {
return;
}
yield `// CSS variable injection ${newLine}`;
for (const style of options.sfc.styles) {
for (const cssBind of style.cssVars) {
for (const [segment, offset, onlyError] of forEachInterpolationSegment(
Expand Down Expand Up @@ -217,6 +218,7 @@ function* generateCssVars(options: ScriptCodegenOptions, ctx: TemplateCodegenCon
yield endOfLine;
}
}
yield `// CSS variable injection end ${newLine}`;
}

export function getTemplateUsageVars(options: ScriptCodegenOptions, ctx: ScriptCodegenContext) {
Expand Down

0 comments on commit 1940c6d

Please sign in to comment.