@vue/language-core
Advanced tools
@@ -46,2 +46,3 @@ declare const raw: { | ||
| functionalComponentArgsRest: string; | ||
| omit: string; | ||
| tryAsConstant: string; | ||
@@ -48,0 +49,0 @@ vFor: string; |
@@ -50,2 +50,3 @@ "use strict"; | ||
| functionalComponentArgsRest: '', | ||
| omit: '', | ||
| tryAsConstant: '', | ||
@@ -52,0 +53,0 @@ vFor: '', |
| import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges'; | ||
| import type { Code, Sfc } from '../../types'; | ||
| import type { Code, IRScriptSetup } from '../../types'; | ||
| import type { ScriptCodegenContext } from './context'; | ||
| import type { ScriptCodegenOptions } from './index'; | ||
| export declare function generateComponent(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>; | ||
| export declare function generateComponent(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: IRScriptSetup, scriptSetupRanges: ScriptSetupRanges): Generator<Code>; |
@@ -29,32 +29,57 @@ "use strict"; | ||
| function* generateEmitsOption(options, scriptSetupRanges) { | ||
| const optionCodes = []; | ||
| const typeOptionCodes = []; | ||
| const typeCodes = options.vueCompilerOptions.target >= 3.5 && !scriptSetupRanges.defineEmits?.hasUnionTypeArg | ||
| ? [...generateTypeEmitsOption(scriptSetupRanges)] | ||
| : []; | ||
| const runtimeCodes = !typeCodes.length | ||
| ? [...generateRuntimeEmitsOption(scriptSetupRanges)] | ||
| : []; | ||
| if (typeCodes.length) { | ||
| yield `__typeEmits: {} as `; | ||
| yield* (0, merge_1.generateIntersectMerge)(...typeCodes); | ||
| yield `,${utils_1.newLine}`; | ||
| } | ||
| else if (runtimeCodes.length) { | ||
| yield `emits: `; | ||
| yield* (0, merge_1.generateSpreadMerge)(...runtimeCodes); | ||
| yield `,${utils_1.newLine}`; | ||
| } | ||
| } | ||
| function* generateTypeEmitsOption(scriptSetupRanges) { | ||
| if (scriptSetupRanges.defineModel.length) { | ||
| optionCodes.push([`{} as ${names_1.names.NormalizeEmits}<typeof ${names_1.names.modelEmit}>`]); | ||
| typeOptionCodes.push([names_1.names.ModelEmit]); | ||
| yield names_1.names.ModelEmit; | ||
| } | ||
| if (scriptSetupRanges.defineEmits?.typeArg) { | ||
| yield names_1.names.Emit; | ||
| } | ||
| } | ||
| function* generateRuntimeEmitsOption(scriptSetupRanges) { | ||
| if (scriptSetupRanges.defineModel.length) { | ||
| yield `{} as ${names_1.names.NormalizeEmits}<typeof ${names_1.names.modelEmit}>`; | ||
| } | ||
| if (scriptSetupRanges.defineEmits) { | ||
| const { name, typeArg, hasUnionTypeArg } = scriptSetupRanges.defineEmits; | ||
| optionCodes.push([`{} as ${names_1.names.NormalizeEmits}<typeof ${name ?? names_1.names.emit}>`]); | ||
| if (typeArg && !hasUnionTypeArg) { | ||
| typeOptionCodes.push([names_1.names.Emit]); | ||
| yield `{} as ${names_1.names.NormalizeEmits}<typeof ${scriptSetupRanges.defineEmits.name ?? names_1.names.emit}>`; | ||
| } | ||
| } | ||
| function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasEmitsOption) { | ||
| const typeCodes = options.vueCompilerOptions.target >= 3.5 && !scriptSetupRanges.defineProps?.arg | ||
| ? [...generateTypePropsOption(options, ctx, hasEmitsOption)] | ||
| : []; | ||
| const runtimeCodes = scriptSetupRanges.withDefaults || !typeCodes.length | ||
| ? [...generateRuntimePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasEmitsOption)] | ||
| : []; | ||
| if (typeCodes.length) { | ||
| if (options.vueCompilerOptions.target >= 3.6 && scriptSetupRanges.withDefaults?.arg) { | ||
| yield `__defaults: ${names_1.names.defaults},${utils_1.newLine}`; | ||
| } | ||
| else { | ||
| typeOptionCodes.length = 0; | ||
| } | ||
| } | ||
| if (options.vueCompilerOptions.target >= 3.5 && typeOptionCodes.length) { | ||
| yield `__typeEmits: {} as `; | ||
| yield* (0, merge_1.generateIntersectMerge)(typeOptionCodes); | ||
| yield `__typeProps: `; | ||
| yield* (0, merge_1.generateSpreadMerge)(...typeCodes); | ||
| yield `,${utils_1.newLine}`; | ||
| } | ||
| else if (optionCodes.length) { | ||
| yield `emits: `; | ||
| yield* (0, merge_1.generateSpreadMerge)(optionCodes); | ||
| if (runtimeCodes.length) { | ||
| yield `props: `; | ||
| yield* (0, merge_1.generateSpreadMerge)(...runtimeCodes); | ||
| yield `,${utils_1.newLine}`; | ||
| } | ||
| } | ||
| function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasEmitsOption) { | ||
| const optionGenerates = []; | ||
| const typeOptionGenerates = []; | ||
| function* generateTypePropsOption(options, ctx, hasEmitsOption) { | ||
| if (options.templateAndStyleTypes.has(names_1.names.InheritedAttrs)) { | ||
@@ -64,47 +89,28 @@ const attrsType = hasEmitsOption | ||
| : names_1.names.InheritedAttrs; | ||
| optionGenerates.push(function* () { | ||
| const propsType = `${names_1.names.PickNotAny}<${ctx.localTypes.OmitIndexSignature}<${attrsType}>, {}>`; | ||
| const optionType = `${ctx.localTypes.TypePropsToOption}<${propsType}>`; | ||
| yield `{} as ${optionType}`; | ||
| }); | ||
| typeOptionGenerates.push(function* () { | ||
| yield `{} as ${attrsType}`; | ||
| }); | ||
| yield `{} as ${attrsType}`; | ||
| } | ||
| if (ctx.generatedTypes.has(names_1.names.PublicProps)) { | ||
| if (options.vueCompilerOptions.target < 3.6) { | ||
| optionGenerates.push(function* () { | ||
| let propsType = `${ctx.localTypes.TypePropsToOption}<${names_1.names.PublicProps}>`; | ||
| if (scriptSetupRanges.withDefaults?.arg) { | ||
| propsType = `${ctx.localTypes.WithDefaults}<${propsType}, typeof ${names_1.names.defaults}>`; | ||
| } | ||
| yield `{} as ${propsType}`; | ||
| }); | ||
| yield `{} as ${names_1.names.PublicProps}`; | ||
| } | ||
| } | ||
| function* generateRuntimePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasEmitsOption) { | ||
| if (options.templateAndStyleTypes.has(names_1.names.InheritedAttrs)) { | ||
| const attrsType = hasEmitsOption | ||
| ? `Omit<${names_1.names.InheritedAttrs}, keyof ${names_1.names.EmitProps}>` | ||
| : names_1.names.InheritedAttrs; | ||
| const propsType = `${ctx.localTypes.TypePropsToOption}<${names_1.names.PickNotAny}<${ctx.localTypes.OmitIndexSignature}<${attrsType}>, {}>>`; | ||
| yield `{} as ${propsType}`; | ||
| } | ||
| if (ctx.generatedTypes.has(names_1.names.PublicProps) && options.vueCompilerOptions.target < 3.6) { | ||
| let propsType = `${ctx.localTypes.TypePropsToOption}<${names_1.names.PublicProps}>`; | ||
| if (scriptSetupRanges.withDefaults?.arg) { | ||
| propsType = `${ctx.localTypes.WithDefaults}<${propsType}, typeof ${names_1.names.defaults}>`; | ||
| } | ||
| typeOptionGenerates.push(function* () { | ||
| yield `{} as ${names_1.names.PublicProps}`; | ||
| }); | ||
| yield `{} as ${propsType}`; | ||
| } | ||
| if (scriptSetupRanges.defineProps?.arg) { | ||
| const { arg } = scriptSetupRanges.defineProps; | ||
| optionGenerates.push(() => (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.navigation)); | ||
| typeOptionGenerates.length = 0; | ||
| yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.navigation); | ||
| } | ||
| const useTypeOption = options.vueCompilerOptions.target >= 3.5 && typeOptionGenerates.length; | ||
| const useOption = (!useTypeOption || scriptSetupRanges.withDefaults) && optionGenerates.length; | ||
| if (useTypeOption) { | ||
| if (options.vueCompilerOptions.target >= 3.6 | ||
| && scriptSetupRanges.withDefaults?.arg) { | ||
| yield `__defaults: ${names_1.names.defaults},${utils_1.newLine}`; | ||
| } | ||
| yield `__typeProps: `; | ||
| yield* (0, merge_1.generateSpreadMerge)(typeOptionGenerates.map(g => g())); | ||
| yield `,${utils_1.newLine}`; | ||
| } | ||
| if (useOption) { | ||
| yield `props: `; | ||
| yield* (0, merge_1.generateSpreadMerge)(optionGenerates.map(g => g())); | ||
| yield `,${utils_1.newLine}`; | ||
| } | ||
| } | ||
| //# sourceMappingURL=component.js.map |
| import type { ScriptRanges } from '../../parsers/scriptRanges'; | ||
| import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges'; | ||
| import type { Code, Sfc, VueCompilerOptions } from '../../types'; | ||
| import type { Code, IRScript, IRScriptSetup, VueCompilerOptions } from '../../types'; | ||
| export interface ScriptCodegenOptions { | ||
| vueCompilerOptions: VueCompilerOptions; | ||
| script: Sfc['script']; | ||
| scriptSetup: Sfc['scriptSetup']; | ||
| script: IRScript | undefined; | ||
| scriptSetup: IRScriptSetup | undefined; | ||
| fileName: string; | ||
@@ -9,0 +9,0 @@ scriptRanges: ScriptRanges | undefined; |
| import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges'; | ||
| import type { Code, Sfc } from '../../types'; | ||
| import type { Code, IRScriptSetup } from '../../types'; | ||
| import type { ScriptCodegenContext } from './context'; | ||
| import type { ScriptCodegenOptions } from './index'; | ||
| export declare function generateScriptSetupImports(scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>; | ||
| export declare function generateGeneric(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges, generic: NonNullable<NonNullable<Sfc['scriptSetup']>['generic']>, body: Iterable<Code>): Generator<Code>; | ||
| export declare function generateSetupFunction(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges, body: Iterable<Code>, output?: Iterable<Code>): Generator<Code>; | ||
| export declare function generateScriptSetupImports(scriptSetup: IRScriptSetup, scriptSetupRanges: ScriptSetupRanges): Generator<Code>; | ||
| export declare function generateGeneric(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: IRScriptSetup, scriptSetupRanges: ScriptSetupRanges, generic: NonNullable<IRScriptSetup['generic']>, body: Iterable<Code>): Generator<Code>; | ||
| export declare function generateSetupFunction(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: IRScriptSetup, scriptSetupRanges: ScriptSetupRanges, body: Iterable<Code>, output?: Iterable<Code>): Generator<Code>; |
@@ -22,12 +22,12 @@ "use strict"; | ||
| if (vueCompilerOptions.petiteVueExtensions.some(ext => fileName.endsWith(ext))) { | ||
| exps.push([`globalThis`]); | ||
| exps.push(`globalThis`); | ||
| } | ||
| if (selfType) { | ||
| exps.push([`{} as InstanceType<${names_1.names.PickNotAny}<typeof ${selfType}, new () => {}>>`]); | ||
| exps.push(`{} as InstanceType<${names_1.names.PickNotAny}<typeof ${selfType}, new () => {}>>`); | ||
| } | ||
| else { | ||
| exps.push([`{} as import('${vueCompilerOptions.lib}').ComponentPublicInstance`]); | ||
| exps.push(`{} as import('${vueCompilerOptions.lib}').ComponentPublicInstance`); | ||
| } | ||
| if (templateAndStyleTypes.has(names_1.names.StyleModules)) { | ||
| exps.push([`{} as ${names_1.names.StyleModules}`]); | ||
| exps.push(`{} as ${names_1.names.StyleModules}`); | ||
| } | ||
@@ -42,3 +42,3 @@ if (scriptSetupRanges?.defineEmits) { | ||
| yield `type ${names_1.names.EmitProps} = ${names_1.names.EmitsToProps}<${names_1.names.NormalizeEmits}<${emitTypes.join(` & `)}>>${utils_1.endOfLine}`; | ||
| exps.push([`{} as { $emit: ${emitTypes.join(` & `)} }`]); | ||
| exps.push(`{} as { $emit: ${emitTypes.join(` & `)} }`); | ||
| } | ||
@@ -55,10 +55,10 @@ if (scriptSetupRanges?.defineProps) { | ||
| if (propTypes.length) { | ||
| exps.push([`{} as { $props: ${propTypes.join(` & `)} }`]); | ||
| exps.push([`{} as ${propTypes.join(` & `)}`]); | ||
| exps.push(`{} as { $props: ${propTypes.join(` & `)} }`); | ||
| exps.push(`{} as ${propTypes.join(` & `)}`); | ||
| } | ||
| if (ctx.generatedTypes.has(names_1.names.SetupExposed)) { | ||
| exps.push([`{} as ${names_1.names.SetupExposed}`]); | ||
| exps.push(`{} as ${names_1.names.SetupExposed}`); | ||
| } | ||
| yield `const ${names_1.names.ctx} = `; | ||
| yield* (0, merge_1.generateSpreadMerge)(exps); | ||
| yield* (0, merge_1.generateSpreadMerge)(...exps); | ||
| yield utils_1.endOfLine; | ||
@@ -65,0 +65,0 @@ } |
@@ -1,3 +0,3 @@ | ||
| import type { Code, Sfc } from '../../types'; | ||
| import type { Code, IRStyle } from '../../types'; | ||
| export declare function generateClassProperty(source: string, classNameWithDot: string, offset: number, propertyType: string): Generator<Code>; | ||
| export declare function generateStyleImports(style: Sfc['styles'][number]): Generator<Code>; | ||
| export declare function generateStyleImports(style: IRStyle): Generator<Code>; |
@@ -1,6 +0,6 @@ | ||
| import type { Code, Sfc, VueCompilerOptions } from '../../types'; | ||
| import type { Code, IRStyle, VueCompilerOptions } from '../../types'; | ||
| export interface StyleCodegenOptions { | ||
| typescript: typeof import('typescript'); | ||
| vueCompilerOptions: VueCompilerOptions; | ||
| styles: Sfc['styles']; | ||
| styles: readonly IRStyle[]; | ||
| setupRefs: Set<string>; | ||
@@ -7,0 +7,0 @@ setupConsts: Set<string>; |
@@ -159,5 +159,2 @@ "use strict"; | ||
| } | ||
| yield* generateComponentBody(options, ctx, node, tag, startTagOffset, props, componentVar); | ||
| } | ||
| function* generateComponentBody(options, ctx, node, tag, tagOffset, props, componentVar) { | ||
| let isCtxVarUsed = false; | ||
@@ -168,4 +165,2 @@ let isPropsVarUsed = false; | ||
| ctx.components.push(getCtxVar); | ||
| const failGeneratedExpressions = []; | ||
| const propCodes = [...(0, elementProps_1.generateElementProps)(options, ctx, node, props, options.vueCompilerOptions.checkUnknownProps, failGeneratedExpressions)]; | ||
| const functionalVar = ctx.getInternalVariable(); | ||
@@ -175,5 +170,8 @@ const vnodeVar = ctx.getInternalVariable(); | ||
| const propsVar = ctx.getInternalVariable(); | ||
| const failedPropExps = []; | ||
| const propCodes = [...(0, elementProps_1.generateElementProps)(options, ctx, node, props, options.vueCompilerOptions.checkUnknownProps, failedPropExps)]; | ||
| const propsStr = (0, muggle_string_1.toString)(propCodes); | ||
| yield `// @ts-ignore${utils_1.newLine}`; | ||
| yield `const ${functionalVar} = ${options.vueCompilerOptions.checkUnknownProps ? names_1.names.asFunctionalComponent0 : names_1.names.asFunctionalComponent1}(${componentVar}, new ${componentVar}({${utils_1.newLine}`; | ||
| yield (0, muggle_string_1.toString)(propCodes); | ||
| yield propsStr; | ||
| yield `}))${utils_1.endOfLine}`; | ||
@@ -193,35 +191,42 @@ yield `const `; | ||
| } | ||
| const shouldInheritAttrs = hasVBindAttrs(options, ctx, node); | ||
| yield `(`; | ||
| const token2 = yield* (0, boundary_1.startBoundary)('template', tagOffset, codeFeatures_1.codeFeatures.verification); | ||
| yield `{${utils_1.newLine}`; | ||
| const token2 = yield* (0, boundary_1.startBoundary)('template', startTagOffset, shouldInheritAttrs && options.vueCompilerOptions.checkRequiredFallthroughAttributes | ||
| ? {} | ||
| : codeFeatures_1.codeFeatures.verification); | ||
| yield `{`; | ||
| yield [``, 'template', node.loc.start.offset, { __propsCompletion: true }]; | ||
| yield utils_1.newLine; | ||
| yield* propCodes; | ||
| yield `}`; | ||
| yield (0, boundary_1.endBoundary)(token2, tagOffset + tag.length); | ||
| yield (0, boundary_1.endBoundary)(token2, startTagOffset + tag.length); | ||
| yield `, ...${names_1.names.functionalComponentArgsRest}(${functionalVar}))${utils_1.endOfLine}`; | ||
| yield* generateFailedExpressions(options, ctx, failGeneratedExpressions); | ||
| yield* generateFailedExpressions(options, ctx, failedPropExps); | ||
| yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, componentVar, getCtxVar, getPropsVar); | ||
| yield* (0, elementDirectives_1.generateElementDirectives)(options, ctx, node); | ||
| const templateRef = getTemplateRef(node); | ||
| const isRootNode = ctx.singleRootNodes.has(node) | ||
| const isSingleRoot = ctx.singleRootNodes.has(node) | ||
| && !options.vueCompilerOptions.fallthroughComponentNames.includes((0, shared_2.hyphenateTag)(tag)); | ||
| if (templateRef || isRootNode) { | ||
| if (templateRef || isSingleRoot) { | ||
| const componentInstanceVar = ctx.getInternalVariable(); | ||
| yield `var ${componentInstanceVar} = {} as (Parameters<NonNullable<typeof ${getCtxVar()}['expose']>>[0] | null)`; | ||
| if (ctx.inVFor) { | ||
| yield `[]`; | ||
| } | ||
| yield `var ${componentInstanceVar}!: Parameters<NonNullable<typeof ${getCtxVar()}['expose']>>[0]`; | ||
| yield utils_1.endOfLine; | ||
| if (templateRef) { | ||
| const typeExp = `typeof ${ctx.getHoistVariable(componentInstanceVar)}`; | ||
| let typeExp = `typeof ${ctx.getHoistVariable(componentInstanceVar)} | null`; | ||
| if (ctx.inVFor) { | ||
| typeExp = `(${typeExp})[]`; | ||
| } | ||
| ctx.addTemplateRef(templateRef[0], typeExp, templateRef[1]); | ||
| } | ||
| if (isRootNode) { | ||
| if (isSingleRoot) { | ||
| ctx.singleRootElTypes.add(`NonNullable<typeof ${componentInstanceVar}>['$el']`); | ||
| } | ||
| } | ||
| if (hasVBindAttrs(options, ctx, node)) { | ||
| ctx.inheritedAttrVars.add(getPropsVar()); | ||
| if (shouldInheritAttrs) { | ||
| const restsVar = ctx.getInternalVariable(); | ||
| yield `var ${restsVar} = ${names_1.names.omit}(${getPropsVar()}, {\n${propsStr}})${utils_1.endOfLine}`; | ||
| ctx.inheritedAttrVars.add(restsVar); | ||
| } | ||
| yield* generateStyleScopedClassReferences(options, node); | ||
| const slotDir = node.props.find(p => p.type === CompilerDOM.NodeTypes.DIRECTIVE && p.name === 'slot'); | ||
| const slotDir = node.props.find(CompilerDOM.isVSlot); | ||
| if (slotDir || node.children.length) { | ||
@@ -378,5 +383,5 @@ yield* (0, vSlot_1.generateVSlot)(options, ctx, node, slotDir, getCtxVar()); | ||
| } | ||
| function* generateFailedExpressions(options, ctx, failGeneratedExpressions) { | ||
| for (const failedExp of failGeneratedExpressions) { | ||
| yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, failedExp.node.loc.source, failedExp.node.loc.start.offset, failedExp.prefix, failedExp.suffix); | ||
| function* generateFailedExpressions(options, ctx, failedPropExps) { | ||
| for (const { node, prefix, suffix } of failedPropExps) { | ||
| yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, node.loc.source, node.loc.start.offset, prefix, suffix); | ||
| yield utils_1.endOfLine; | ||
@@ -383,0 +388,0 @@ } |
@@ -5,3 +5,3 @@ import * as CompilerDOM from '@vue/compiler-dom'; | ||
| import type { TemplateCodegenOptions } from './index'; | ||
| export interface FailGeneratedExpression { | ||
| export interface FailedPropExpressions { | ||
| node: CompilerDOM.SimpleExpressionNode; | ||
@@ -11,3 +11,3 @@ prefix: string; | ||
| } | ||
| export declare function generateElementProps(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, props: CompilerDOM.ElementNode['props'], strictPropsCheck: boolean, failGeneratedExpressions?: FailGeneratedExpression[]): Generator<Code>; | ||
| export declare function generateElementProps(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, props: CompilerDOM.ElementNode['props'], checkUnknownProps: boolean, failedPropExps?: FailedPropExpressions[]): Generator<Code>; | ||
| export declare function generatePropExp(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode, exp: CompilerDOM.SimpleExpressionNode | undefined): Generator<Code>; |
@@ -53,3 +53,3 @@ "use strict"; | ||
| const objectProperty_1 = require("./objectProperty"); | ||
| function* generateElementProps(options, ctx, node, props, strictPropsCheck, failGeneratedExpressions) { | ||
| function* generateElementProps(options, ctx, node, props, checkUnknownProps, failedPropExps) { | ||
| const isComponent = node.tagType === CompilerDOM.ElementTypes.COMPONENT; | ||
@@ -78,8 +78,8 @@ for (const prop of props) { | ||
| && prop.arg.loc.source.endsWith(']')) { | ||
| failGeneratedExpressions?.push({ node: prop.arg, prefix: `(`, suffix: `)` }); | ||
| failGeneratedExpressions?.push({ node: prop.exp, prefix: `() => {`, suffix: `}` }); | ||
| failedPropExps?.push({ node: prop.arg, prefix: `(`, suffix: `)` }); | ||
| failedPropExps?.push({ node: prop.exp, prefix: `() => {`, suffix: `}` }); | ||
| } | ||
| else if (!prop.arg | ||
| && prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) { | ||
| failGeneratedExpressions?.push({ node: prop.exp, prefix: `(`, suffix: `)` }); | ||
| failedPropExps?.push({ node: prop.exp, prefix: `(`, suffix: `)` }); | ||
| } | ||
@@ -105,3 +105,3 @@ } | ||
| if (prop.exp && prop.exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY) { | ||
| failGeneratedExpressions?.push({ node: prop.exp, prefix: `(`, suffix: `)` }); | ||
| failedPropExps?.push({ node: prop.exp, prefix: `(`, suffix: `)` }); | ||
| } | ||
@@ -116,3 +116,3 @@ continue; | ||
| const shouldCamelize = getShouldCamelize(options, node, prop, propName); | ||
| const features = getPropsCodeFeatures(strictPropsCheck); | ||
| const features = getPropsCodeFeatures(checkUnknownProps); | ||
| if (shouldSpread) { | ||
@@ -156,3 +156,3 @@ yield `...{ `; | ||
| const shouldCamelize = getShouldCamelize(options, node, prop, prop.name); | ||
| const features = getPropsCodeFeatures(strictPropsCheck); | ||
| const features = getPropsCodeFeatures(checkUnknownProps); | ||
| if (shouldSpread) { | ||
@@ -192,3 +192,3 @@ yield `...{ `; | ||
| if (prop.exp.loc.source === '$attrs') { | ||
| failGeneratedExpressions?.push({ node: prop.exp, prefix: `(`, suffix: `)` }); | ||
| failedPropExps?.push({ node: prop.exp, prefix: `(`, suffix: `)` }); | ||
| } | ||
@@ -250,8 +250,9 @@ else { | ||
| } | ||
| function getPropsCodeFeatures(strictPropsCheck) { | ||
| function getPropsCodeFeatures(checkUnknownProps) { | ||
| return { | ||
| ...codeFeatures_1.codeFeatures.withoutHighlightAndCompletion, | ||
| ...strictPropsCheck | ||
| ...checkUnknownProps | ||
| ? codeFeatures_1.codeFeatures.verification | ||
| : codeFeatures_1.codeFeatures.doNotReportTs2353AndTs2561, | ||
| __propsCompletion: true, | ||
| }; | ||
@@ -258,0 +259,0 @@ } |
| import type * as ts from 'typescript'; | ||
| import type { Code, Sfc, VueCompilerOptions } from '../../types'; | ||
| import type { Code, IRTemplate, VueCompilerOptions } from '../../types'; | ||
| export interface TemplateCodegenOptions { | ||
| typescript: typeof ts; | ||
| vueCompilerOptions: VueCompilerOptions; | ||
| template: NonNullable<Sfc['template']>; | ||
| template: IRTemplate; | ||
| setupRefs: Set<string>; | ||
@@ -8,0 +8,0 @@ setupConsts: Set<string>; |
@@ -50,3 +50,3 @@ "use strict"; | ||
| yield* generateSlotsType(options, ctx); | ||
| yield* generateInheritedAttrsType(ctx); | ||
| yield* generateInheritedAttrsType(options, ctx); | ||
| yield* generateTemplateRefsType(options, ctx); | ||
@@ -106,3 +106,3 @@ yield* generateRootElType(ctx); | ||
| } | ||
| function* generateInheritedAttrsType(ctx) { | ||
| function* generateInheritedAttrsType(options, ctx) { | ||
| if (!ctx.inheritedAttrVars.size) { | ||
@@ -112,3 +112,6 @@ return; | ||
| ctx.generatedTypes.add(names_1.names.InheritedAttrs); | ||
| yield `type ${names_1.names.InheritedAttrs} = Partial<${[...ctx.inheritedAttrVars].map(name => `typeof ${name}`).join(` & `)}>`; | ||
| const type = [...ctx.inheritedAttrVars].map(name => `typeof ${name}`).join(` & `); | ||
| yield `type ${names_1.names.InheritedAttrs} = ${options.vueCompilerOptions.checkRequiredFallthroughAttributes | ||
| ? type | ||
| : `Partial<${type}>`}`; | ||
| yield utils_1.endOfLine; | ||
@@ -115,0 +118,0 @@ } |
@@ -1,2 +0,2 @@ | ||
| import type { Code, SfcBlock, VueCodeInformation } from '../../types'; | ||
| import type { Code, IRBlock, VueCodeInformation } from '../../types'; | ||
| import type { TemplateCodegenContext } from './context'; | ||
@@ -6,2 +6,2 @@ export declare function generateInterpolation({ typescript, setupRefs }: { | ||
| setupRefs: Set<string>; | ||
| }, ctx: TemplateCodegenContext, block: SfcBlock, data: VueCodeInformation, code: string, start: number, prefix?: string, suffix?: string): Generator<Code>; | ||
| }, ctx: TemplateCodegenContext, block: IRBlock, data: VueCodeInformation, code: string, start: number, prefix?: string, suffix?: string): Generator<Code>; |
@@ -1,3 +0,3 @@ | ||
| import type { Code, SfcBlock } from '../../types'; | ||
| export declare const references: WeakMap<SfcBlock, [version: string, [className: string, offset: number][]]>; | ||
| export declare function generateStyleScopedClassReference(block: SfcBlock, className: string, offset: number, fullStart?: number): Generator<Code>; | ||
| import type { Code, IRBlock } from '../../types'; | ||
| export declare const references: WeakMap<IRBlock, [version: string, [className: string, offset: number][]]>; | ||
| export declare function generateStyleScopedClassReference(block: IRBlock, className: string, offset: number, fullStart?: number): Generator<Code>; |
@@ -5,3 +5,3 @@ import * as CompilerDOM from '@vue/compiler-dom'; | ||
| import type { TemplateCodegenOptions } from './index'; | ||
| export declare function generateTemplateChild(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode, enterNode?: boolean, isVForChild?: boolean): Generator<Code>; | ||
| export declare function generateTemplateChild(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode, enterNode?: boolean, treatTemplateAsFragment?: boolean): Generator<Code>; | ||
| export declare function parseInterpolationNode(node: CompilerDOM.InterpolationNode, template: string): readonly [string, number]; |
@@ -48,3 +48,3 @@ "use strict"; | ||
| const vSlot_1 = require("./vSlot"); | ||
| function* generateTemplateChild(options, ctx, node, enterNode = true, isVForChild = false) { | ||
| function* generateTemplateChild(options, ctx, node, enterNode = true, treatTemplateAsFragment = false) { | ||
| if (enterNode && !ctx.enter(node)) { | ||
@@ -70,3 +70,3 @@ return; | ||
| } | ||
| else if (node.tagType === CompilerDOM.ElementTypes.TEMPLATE && isVForChild) { | ||
| else if (node.tagType === CompilerDOM.ElementTypes.TEMPLATE && treatTemplateAsFragment) { | ||
| yield* (0, element_1.generateFragment)(options, ctx, node); | ||
@@ -108,3 +108,3 @@ } | ||
| } | ||
| function* collectSingleRootNodes(options, children) { | ||
| function* collectSingleRootNodes(options, children, treatTemplateAsFragment = false) { | ||
| // Exclude the effect of comments on the root node | ||
@@ -122,3 +122,3 @@ children = children.filter(node => node.type !== CompilerDOM.NodeTypes.COMMENT); | ||
| for (const branch of child.branches) { | ||
| yield* collectSingleRootNodes(options, branch.children); | ||
| yield* collectSingleRootNodes(options, branch.children, true); | ||
| } | ||
@@ -130,2 +130,6 @@ return; | ||
| } | ||
| if (child.tagType === CompilerDOM.ElementTypes.TEMPLATE && treatTemplateAsFragment) { | ||
| yield* collectSingleRootNodes(options, child.children); | ||
| return; | ||
| } | ||
| yield child; | ||
@@ -132,0 +136,0 @@ const tag = (0, shared_1.hyphenateTag)(child.tag); |
| import type * as ts from 'typescript'; | ||
| import type { Code, Sfc, SfcBlock, VueCodeInformation } from '../../types'; | ||
| import type { Code, IRBlock, IRScript, IRScriptSetup, VueCodeInformation } from '../../types'; | ||
| export declare const newLine = "\n"; | ||
| export declare const endOfLine = ";\n"; | ||
| export declare const identifierRegex: RegExp; | ||
| export declare function getTypeScriptAST(ts: typeof import('typescript'), block: SfcBlock, text: string): ts.SourceFile; | ||
| export declare function generateSfcBlockSection(block: NonNullable<Sfc['script' | 'scriptSetup']>, start: number, end: number, features: VueCodeInformation): Generator<Code>; | ||
| export declare function getTypeScriptAST(ts: typeof import('typescript'), block: IRBlock, text: string): ts.SourceFile; | ||
| export declare function generateSfcBlockSection(block: IRScript | IRScriptSetup, start: number, end: number, features: VueCodeInformation): Generator<Code>; | ||
| export declare function forEachNode(ts: typeof import('typescript'), node: ts.Node): Generator<ts.Node>; |
| import type { Code } from '../../types'; | ||
| export declare function generateIntersectMerge(generates: Iterable<Code>[]): Generator<Code>; | ||
| export declare function generateSpreadMerge(generates: Iterable<Code>[]): Generator<Code>; | ||
| export declare function generateIntersectMerge(...codes: Code[]): Generator<Code>; | ||
| export declare function generateSpreadMerge(...codes: Code[]): Generator<Code>; |
@@ -6,18 +6,18 @@ "use strict"; | ||
| const index_1 = require("./index"); | ||
| function* generateIntersectMerge(generates) { | ||
| yield* generates[0]; | ||
| for (let i = 1; i < generates.length; i++) { | ||
| function* generateIntersectMerge(...codes) { | ||
| yield codes[0]; | ||
| for (let i = 1; i < codes.length; i++) { | ||
| yield ` & `; | ||
| yield* generates[i]; | ||
| yield codes[i]; | ||
| } | ||
| } | ||
| function* generateSpreadMerge(generates) { | ||
| if (generates.length === 1) { | ||
| yield* generates[0]; | ||
| function* generateSpreadMerge(...codes) { | ||
| if (codes.length <= 1) { | ||
| yield* codes; | ||
| } | ||
| else { | ||
| yield `{${index_1.newLine}`; | ||
| for (const generate of generates) { | ||
| for (const code of codes) { | ||
| yield `...`; | ||
| yield* generate; | ||
| yield code; | ||
| yield `,${index_1.newLine}`; | ||
@@ -24,0 +24,0 @@ } |
@@ -214,2 +214,3 @@ "use strict"; | ||
| fallthroughAttributes: false, | ||
| checkRequiredFallthroughAttributes: false, | ||
| resolveStyleImports: false, | ||
@@ -216,0 +217,0 @@ resolveStyleClassNames: 'scoped', |
@@ -14,11 +14,11 @@ "use strict"; | ||
| }, | ||
| resolveEmbeddedCode(_fileName, sfc, embeddedFile) { | ||
| resolveEmbeddedCode(_fileName, ir, embeddedFile) { | ||
| if (embeddedFile.id === 'root_tags') { | ||
| embeddedFile.content.push([sfc.content, undefined, 0, shared_1.allCodeFeatures]); | ||
| embeddedFile.content.push([ir.content, undefined, 0, shared_1.allCodeFeatures]); | ||
| for (const block of [ | ||
| sfc.template, | ||
| sfc.script, | ||
| sfc.scriptSetup, | ||
| ...sfc.styles, | ||
| ...sfc.customBlocks, | ||
| ir.template, | ||
| ir.script, | ||
| ir.scriptSetup, | ||
| ...ir.styles, | ||
| ...ir.customBlocks, | ||
| ]) { | ||
@@ -30,3 +30,3 @@ if (!block) { | ||
| // fix folding range end position failed to mapping | ||
| (0, muggle_string_1.replaceSourceRange)(embeddedFile.content, undefined, block.startTagEnd, block.endTagStart, sfc.content.slice(block.startTagEnd, block.startTagEnd + offset), [ | ||
| (0, muggle_string_1.replaceSourceRange)(embeddedFile.content, undefined, block.startTagEnd, block.endTagStart, ir.content.slice(block.startTagEnd, block.startTagEnd + offset), [ | ||
| '', | ||
@@ -36,3 +36,3 @@ undefined, | ||
| { structure: true }, | ||
| ], sfc.content.slice(block.startTagEnd + offset, block.endTagStart)); | ||
| ], ir.content.slice(block.startTagEnd + offset, block.endTagStart)); | ||
| } | ||
@@ -39,0 +39,0 @@ } |
@@ -7,4 +7,4 @@ "use strict"; | ||
| version: 2.2, | ||
| getEmbeddedCodes(_fileName, sfc) { | ||
| return sfc.customBlocks.map((customBlock, i) => ({ | ||
| getEmbeddedCodes(_fileName, ir) { | ||
| return ir.customBlocks.map((customBlock, i) => ({ | ||
| id: 'custom_block_' + i, | ||
@@ -14,6 +14,6 @@ lang: customBlock.lang, | ||
| }, | ||
| resolveEmbeddedCode(_fileName, sfc, embeddedFile) { | ||
| resolveEmbeddedCode(_fileName, ir, embeddedFile) { | ||
| if (embeddedFile.id.startsWith('custom_block_')) { | ||
| const index = parseInt(embeddedFile.id.slice('custom_block_'.length)); | ||
| const customBlock = sfc.customBlocks[index]; | ||
| const customBlock = ir.customBlocks[index]; | ||
| embeddedFile.content.push([ | ||
@@ -20,0 +20,0 @@ customBlock.content, |
@@ -6,17 +6,17 @@ "use strict"; | ||
| version: 2.2, | ||
| getEmbeddedCodes(_fileName, sfc) { | ||
| getEmbeddedCodes(_fileName, ir) { | ||
| const names = []; | ||
| if (sfc.script) { | ||
| names.push({ id: 'script_raw', lang: sfc.script.lang }); | ||
| if (ir.script) { | ||
| names.push({ id: 'script_raw', lang: ir.script.lang }); | ||
| } | ||
| if (sfc.scriptSetup) { | ||
| names.push({ id: 'scriptsetup_raw', lang: sfc.scriptSetup.lang }); | ||
| if (ir.scriptSetup) { | ||
| names.push({ id: 'scriptsetup_raw', lang: ir.scriptSetup.lang }); | ||
| } | ||
| return names; | ||
| }, | ||
| resolveEmbeddedCode(_fileName, sfc, embeddedFile) { | ||
| resolveEmbeddedCode(_fileName, ir, embeddedFile) { | ||
| const script = embeddedFile.id === 'script_raw' | ||
| ? sfc.script | ||
| ? ir.script | ||
| : embeddedFile.id === 'scriptsetup_raw' | ||
| ? sfc.scriptSetup | ||
| ? ir.scriptSetup | ||
| : undefined; | ||
@@ -23,0 +23,0 @@ if (script) { |
@@ -7,6 +7,6 @@ "use strict"; | ||
| version: 2.2, | ||
| getEmbeddedCodes(_fileName, sfc) { | ||
| getEmbeddedCodes(_fileName, ir) { | ||
| const result = []; | ||
| for (let i = 0; i < sfc.styles.length; i++) { | ||
| const style = sfc.styles[i]; | ||
| for (let i = 0; i < ir.styles.length; i++) { | ||
| const style = ir.styles[i]; | ||
| if (style) { | ||
@@ -27,6 +27,6 @@ result.push({ | ||
| }, | ||
| resolveEmbeddedCode(_fileName, sfc, embeddedFile) { | ||
| resolveEmbeddedCode(_fileName, ir, embeddedFile) { | ||
| if (embeddedFile.id.startsWith('style_')) { | ||
| const index = parseInt(embeddedFile.id.split('_')[1]); | ||
| const style = sfc.styles[index]; | ||
| const style = ir.styles[index]; | ||
| if (embeddedFile.id.endsWith('_inline_ts')) { | ||
@@ -33,0 +33,0 @@ embeddedFile.parentCodeId = 'style_' + index; |
@@ -7,7 +7,7 @@ "use strict"; | ||
| version: 2.2, | ||
| getEmbeddedCodes(_fileName, sfc) { | ||
| if (sfc.template?.lang === 'html') { | ||
| getEmbeddedCodes(_fileName, ir) { | ||
| if (ir.template?.lang === 'html') { | ||
| return [{ | ||
| id: 'template', | ||
| lang: sfc.template.lang, | ||
| lang: ir.template.lang, | ||
| }]; | ||
@@ -17,7 +17,7 @@ } | ||
| }, | ||
| resolveEmbeddedCode(_fileName, sfc, embeddedFile) { | ||
| if (embeddedFile.id === 'template' && sfc.template?.lang === 'html') { | ||
| resolveEmbeddedCode(_fileName, ir, embeddedFile) { | ||
| if (embeddedFile.id === 'template' && ir.template?.lang === 'html') { | ||
| embeddedFile.content.push([ | ||
| sfc.template.content, | ||
| sfc.template.name, | ||
| ir.template.content, | ||
| ir.template.name, | ||
| 0, | ||
@@ -24,0 +24,0 @@ shared_1.allCodeFeatures, |
@@ -48,4 +48,4 @@ "use strict"; | ||
| version: 2.2, | ||
| getEmbeddedCodes(_fileName, sfc) { | ||
| if (!sfc.template?.ast) { | ||
| getEmbeddedCodes(_fileName, ir) { | ||
| if (!ir.template?.ast) { | ||
| return []; | ||
@@ -55,8 +55,8 @@ } | ||
| }, | ||
| resolveEmbeddedCode(_fileName, sfc, embeddedFile) { | ||
| if (embeddedFile.id !== 'template_inline_css' || !sfc.template?.ast) { | ||
| resolveEmbeddedCode(_fileName, ir, embeddedFile) { | ||
| if (embeddedFile.id !== 'template_inline_css' || !ir.template?.ast) { | ||
| return; | ||
| } | ||
| embeddedFile.parentCodeId = sfc.template.lang === 'md' ? 'root_tags' : 'template'; | ||
| embeddedFile.content.push(...generate(sfc.template.ast)); | ||
| embeddedFile.parentCodeId = ir.template.lang === 'md' ? 'root_tags' : 'template'; | ||
| embeddedFile.content.push(...generate(ir.template.ast)); | ||
| }, | ||
@@ -63,0 +63,0 @@ }; |
@@ -60,8 +60,8 @@ "use strict"; | ||
| version: 2.2, | ||
| getEmbeddedCodes(_fileName, sfc) { | ||
| if (!sfc.template?.ast) { | ||
| getEmbeddedCodes(_fileName, ir) { | ||
| if (!ir.template?.ast) { | ||
| return []; | ||
| } | ||
| const parsed = parse(sfc); | ||
| parseds.set(sfc, parsed); | ||
| const parsed = parse(ir); | ||
| parseds.set(ir, parsed); | ||
| const result = []; | ||
@@ -73,3 +73,3 @@ for (const [id] of parsed) { | ||
| }, | ||
| resolveEmbeddedCode(_fileName, sfc, embeddedFile) { | ||
| resolveEmbeddedCode(_fileName, ir, embeddedFile) { | ||
| if (!embeddedFile.id.startsWith('template_inline_ts_')) { | ||
@@ -79,4 +79,4 @@ return; | ||
| // access template content to watch change | ||
| void sfc.template?.content; | ||
| const parsed = parseds.get(sfc); | ||
| void ir.template?.content; | ||
| const parsed = parseds.get(ir); | ||
| if (parsed) { | ||
@@ -86,3 +86,3 @@ const codes = parsed.get(embeddedFile.id); | ||
| embeddedFile.content.push(...codes); | ||
| embeddedFile.parentCodeId = sfc.template?.lang === 'md' ? 'root_tags' : 'template'; | ||
| embeddedFile.parentCodeId = ir.template?.lang === 'md' ? 'root_tags' : 'template'; | ||
| } | ||
@@ -92,10 +92,10 @@ } | ||
| }; | ||
| function parse(sfc) { | ||
| function parse(ir) { | ||
| const result = new Map(); | ||
| if (!sfc.template?.ast) { | ||
| if (!ir.template?.ast) { | ||
| return result; | ||
| } | ||
| const template = sfc.template; | ||
| const template = ir.template; | ||
| let i = 0; | ||
| sfc.template.ast.children.forEach(visit); | ||
| ir.template.ast.children.forEach(visit); | ||
| return result; | ||
@@ -102,0 +102,0 @@ function visit(node) { |
@@ -1,3 +0,3 @@ | ||
| import type { Sfc, VueLanguagePlugin } from '../types'; | ||
| export declare const tsCodegen: WeakMap<Sfc, { | ||
| import type { IR, VueLanguagePlugin } from '../types'; | ||
| export declare const tsCodegen: WeakMap<IR, { | ||
| getScriptRanges: () => { | ||
@@ -4,0 +4,0 @@ exportDefault: (import("../types").TextRange<import("typescript").Node> & { |
+35
-35
@@ -53,11 +53,11 @@ "use strict"; | ||
| version: 2.2, | ||
| getEmbeddedCodes(_fileName, sfc) { | ||
| const lang = computeLang(sfc); | ||
| getEmbeddedCodes(_fileName, ir) { | ||
| const lang = computeLang(ir); | ||
| return [{ lang, id: 'script_' + lang }]; | ||
| }, | ||
| resolveEmbeddedCode(fileName, sfc, embeddedFile) { | ||
| resolveEmbeddedCode(fileName, ir, embeddedFile) { | ||
| if (/script_(js|jsx|ts|tsx)/.test(embeddedFile.id)) { | ||
| let codegen = exports.tsCodegen.get(sfc); | ||
| let codegen = exports.tsCodegen.get(ir); | ||
| if (!codegen) { | ||
| exports.tsCodegen.set(sfc, codegen = useCodegen(ts, vueCompilerOptions, fileName, sfc)); | ||
| exports.tsCodegen.set(ir, codegen = useCodegen(ts, vueCompilerOptions, fileName, ir)); | ||
| } | ||
@@ -69,10 +69,10 @@ const generatedScript = codegen.getGeneratedScript(); | ||
| }; | ||
| function computeLang(sfc) { | ||
| let lang = sfc.scriptSetup?.lang ?? sfc.script?.lang; | ||
| if (sfc.script && sfc.scriptSetup) { | ||
| if (sfc.scriptSetup.lang !== 'js') { | ||
| lang = sfc.scriptSetup.lang; | ||
| function computeLang(ir) { | ||
| let lang = ir.scriptSetup?.lang ?? ir.script?.lang; | ||
| if (ir.script && ir.scriptSetup) { | ||
| if (ir.scriptSetup.lang !== 'js') { | ||
| lang = ir.scriptSetup.lang; | ||
| } | ||
| else { | ||
| lang = sfc.script.lang; | ||
| lang = ir.script.lang; | ||
| } | ||
@@ -87,5 +87,5 @@ } | ||
| exports.default = plugin; | ||
| function useCodegen(ts, vueCompilerOptions, fileName, sfc) { | ||
| function useCodegen(ts, vueCompilerOptions, fileName, ir) { | ||
| const getResolvedOptions = (0, alien_signals_1.computed)(() => { | ||
| const options = (0, vueCompilerOptions_1.parseVueCompilerOptions)(sfc.comments); | ||
| const options = (0, vueCompilerOptions_1.parseVueCompilerOptions)(ir.comments); | ||
| if (options) { | ||
@@ -98,7 +98,7 @@ const resolver = new compilerOptions_1.CompilerOptionsResolver(ts, () => undefined /* does not support resolving target="auto" */); | ||
| }); | ||
| const getScriptRanges = (0, alien_signals_1.computed)(() => sfc.script && validLangs.has(sfc.script.lang) | ||
| ? (0, scriptRanges_1.parseScriptRanges)(ts, sfc.script.ast, getResolvedOptions()) | ||
| const getScriptRanges = (0, alien_signals_1.computed)(() => ir.script && validLangs.has(ir.script.lang) | ||
| ? (0, scriptRanges_1.parseScriptRanges)(ts, ir.script.ast, getResolvedOptions()) | ||
| : undefined); | ||
| const getScriptSetupRanges = (0, alien_signals_1.computed)(() => sfc.scriptSetup && validLangs.has(sfc.scriptSetup.lang) | ||
| ? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, sfc.scriptSetup.ast, getResolvedOptions()) | ||
| const getScriptSetupRanges = (0, alien_signals_1.computed)(() => ir.scriptSetup && validLangs.has(ir.scriptSetup.lang) | ||
| ? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, ir.scriptSetup.ast, getResolvedOptions()) | ||
| : undefined); | ||
@@ -108,10 +108,10 @@ const getImportedComponents = (0, signals_1.computedSet)(() => { | ||
| const scriptSetupRanges = getScriptSetupRanges(); | ||
| if (sfc.scriptSetup && scriptSetupRanges) { | ||
| if (ir.scriptSetup && scriptSetupRanges) { | ||
| for (const range of scriptSetupRanges.components) { | ||
| names.add(sfc.scriptSetup.content.slice(range.start, range.end)); | ||
| names.add(ir.scriptSetup.content.slice(range.start, range.end)); | ||
| } | ||
| const scriptRange = getScriptRanges(); | ||
| if (sfc.script && scriptRange) { | ||
| if (ir.script && scriptRange) { | ||
| for (const range of scriptRange.components) { | ||
| names.add(sfc.script.content.slice(range.start, range.end)); | ||
| names.add(ir.script.content.slice(range.start, range.end)); | ||
| } | ||
@@ -150,8 +150,8 @@ } | ||
| const componentOptions = getScriptRanges()?.exportDefault?.options; | ||
| if (sfc.script && componentOptions?.name) { | ||
| name = sfc.script.content.slice(componentOptions.name.start + 1, componentOptions.name.end - 1); | ||
| if (ir.script && componentOptions?.name) { | ||
| name = ir.script.content.slice(componentOptions.name.start + 1, componentOptions.name.end - 1); | ||
| } | ||
| else { | ||
| const { defineOptions } = getScriptSetupRanges() ?? {}; | ||
| if (sfc.scriptSetup && defineOptions?.name) { | ||
| if (ir.scriptSetup && defineOptions?.name) { | ||
| name = defineOptions.name; | ||
@@ -167,3 +167,3 @@ } | ||
| const getGeneratedTemplate = (0, alien_signals_1.computed)(() => { | ||
| if (getResolvedOptions().skipTemplateCodegen || !sfc.template) { | ||
| if (getResolvedOptions().skipTemplateCodegen || !ir.template) { | ||
| return; | ||
@@ -174,3 +174,3 @@ } | ||
| vueCompilerOptions: getResolvedOptions(), | ||
| template: sfc.template, | ||
| template: ir.template, | ||
| componentName: getComponentName(), | ||
@@ -186,3 +186,3 @@ setupConsts: getSetupConsts(), | ||
| const getGeneratedStyle = (0, alien_signals_1.computed)(() => { | ||
| if (!sfc.styles.length) { | ||
| if (!ir.styles.length) { | ||
| return; | ||
@@ -193,3 +193,3 @@ } | ||
| vueCompilerOptions: getResolvedOptions(), | ||
| styles: sfc.styles, | ||
| styles: ir.styles, | ||
| setupConsts: getSetupConsts(), | ||
@@ -202,13 +202,13 @@ setupRefs: getSetupRefs(), | ||
| const scriptSetupRanges = getScriptSetupRanges(); | ||
| if (!sfc.scriptSetup || !scriptSetupRanges) { | ||
| if (!ir.scriptSetup || !scriptSetupRanges) { | ||
| return allVars; | ||
| } | ||
| for (const range of scriptSetupRanges.bindings) { | ||
| const name = sfc.scriptSetup.content.slice(range.start, range.end); | ||
| const name = ir.scriptSetup.content.slice(range.start, range.end); | ||
| allVars.add(name); | ||
| } | ||
| const scriptRanges = getScriptRanges(); | ||
| if (sfc.script && scriptRanges) { | ||
| if (ir.script && scriptRanges) { | ||
| for (const range of scriptRanges.bindings) { | ||
| const name = sfc.script.content.slice(range.start, range.end); | ||
| const name = ir.script.content.slice(range.start, range.end); | ||
| allVars.add(name); | ||
@@ -223,3 +223,3 @@ } | ||
| ...getGeneratedStyle()?.componentAccessMap.keys() ?? [], | ||
| ...sfc.template?.ast?.components.flatMap(name => [(0, shared_1.camelize)(name), (0, shared_1.capitalize)((0, shared_1.camelize)(name))]) ?? [], | ||
| ...ir.template?.ast?.components.flatMap(name => [(0, shared_1.camelize)(name), (0, shared_1.capitalize)((0, shared_1.camelize)(name))]) ?? [], | ||
| ].filter(name => allVars.has(name))); | ||
@@ -231,4 +231,4 @@ }); | ||
| fileName, | ||
| script: sfc.script, | ||
| scriptSetup: sfc.scriptSetup, | ||
| script: ir.script, | ||
| scriptSetup: ir.scriptSetup, | ||
| exposed: getSetupExposed(), | ||
@@ -235,0 +235,0 @@ scriptRanges: getScriptRanges(), |
+54
-48
@@ -19,2 +19,3 @@ import type { CodeInformation } from '@volar/language-core'; | ||
| __importCompletion?: boolean; | ||
| __propsCompletion?: boolean; | ||
| __shorthandExpression?: 'html' | 'js'; | ||
@@ -47,2 +48,3 @@ __combineToken?: symbol; | ||
| fallthroughAttributes: boolean; | ||
| checkRequiredFallthroughAttributes: boolean; | ||
| resolveStyleImports: boolean; | ||
@@ -90,3 +92,3 @@ resolveStyleClassNames: boolean | 'scoped'; | ||
| compileSFCTemplate?(lang: string, template: string, options: CompilerDOM.CompilerOptions): CompilerDOM.CodegenResult | undefined; | ||
| compileSFCStyle?(lang: string, style: string): Pick<Sfc['styles'][number], 'imports' | 'bindings' | 'classNames'> | undefined; | ||
| compileSFCStyle?(lang: string, style: string): Pick<IRStyle, 'imports' | 'bindings' | 'classNames'> | undefined; | ||
| updateSFCTemplate?(oldResult: CompilerDOM.CodegenResult, textChange: { | ||
@@ -97,7 +99,7 @@ start: number; | ||
| }): CompilerDOM.CodegenResult | undefined; | ||
| getEmbeddedCodes?(fileName: string, sfc: Sfc): { | ||
| getEmbeddedCodes?(fileName: string, ir: IR): { | ||
| id: string; | ||
| lang: string; | ||
| }[]; | ||
| resolveEmbeddedCode?(fileName: string, sfc: Sfc, embeddedFile: VueEmbeddedCode): void; | ||
| resolveEmbeddedCode?(fileName: string, ir: IR, embeddedFile: VueEmbeddedCode): void; | ||
| } | ||
@@ -114,3 +116,16 @@ export type VueLanguagePlugin<T extends Record<string, any> = {}> = (ctx: { | ||
| }) => VueLanguagePluginReturn | VueLanguagePluginReturn[]; | ||
| export interface SfcBlock { | ||
| export interface IR { | ||
| content: string; | ||
| comments: string[]; | ||
| template: IRTemplate | undefined; | ||
| script: IRScript | undefined; | ||
| scriptSetup: IRScriptSetup | undefined; | ||
| styles: readonly IRStyle[]; | ||
| customBlocks: readonly IRCustomBlock[]; | ||
| } | ||
| export type IRAttr = true | { | ||
| text: string; | ||
| offset: number; | ||
| }; | ||
| export interface IRBlock { | ||
| name: string; | ||
@@ -125,53 +140,44 @@ start: number; | ||
| } | ||
| export type SfcBlockAttr = true | { | ||
| text: string; | ||
| offset: number; | ||
| quotes: boolean; | ||
| }; | ||
| export interface Sfc { | ||
| content: string; | ||
| comments: string[]; | ||
| template: (SfcBlock & { | ||
| ast: CompilerDOM.RootNode | undefined; | ||
| errors: CompilerDOM.CompilerError[]; | ||
| warnings: CompilerDOM.CompilerError[]; | ||
| }) | undefined; | ||
| script: (SfcBlock & { | ||
| src: SfcBlockAttr | undefined; | ||
| ast: ts.SourceFile; | ||
| }) | undefined; | ||
| scriptSetup: (SfcBlock & { | ||
| generic: SfcBlockAttr | undefined; | ||
| ast: ts.SourceFile; | ||
| }) | undefined; | ||
| styles: readonly (SfcBlock & { | ||
| src: SfcBlockAttr | undefined; | ||
| module: SfcBlockAttr | undefined; | ||
| scoped: boolean; | ||
| imports: { | ||
| text: string; | ||
| offset: number; | ||
| }[]; | ||
| bindings: { | ||
| text: string; | ||
| offset: number; | ||
| }[]; | ||
| classNames: { | ||
| text: string; | ||
| offset: number; | ||
| }[]; | ||
| })[]; | ||
| customBlocks: readonly (SfcBlock & { | ||
| type: string; | ||
| })[]; | ||
| export interface IRTemplate extends IRBlock { | ||
| ast: CompilerDOM.RootNode | undefined; | ||
| errors: CompilerDOM.CompilerError[]; | ||
| warnings: CompilerDOM.CompilerError[]; | ||
| } | ||
| export interface IRScript extends IRBlock { | ||
| src: IRAttr | undefined; | ||
| ast: ts.SourceFile; | ||
| } | ||
| export interface IRScriptSetup extends IRBlock { | ||
| generic: IRAttr | undefined; | ||
| ast: ts.SourceFile; | ||
| } | ||
| export interface IRStyle extends IRBlock { | ||
| src: IRAttr | undefined; | ||
| module: IRAttr | undefined; | ||
| scoped: boolean; | ||
| imports: { | ||
| text: string; | ||
| offset: number; | ||
| }[]; | ||
| bindings: { | ||
| text: string; | ||
| offset: number; | ||
| }[]; | ||
| classNames: { | ||
| text: string; | ||
| offset: number; | ||
| }[]; | ||
| } | ||
| export interface IRCustomBlock extends IRBlock { | ||
| type: string; | ||
| } | ||
| declare module '@vue/compiler-sfc' { | ||
| interface SFCBlock { | ||
| __src?: SfcBlockAttr; | ||
| __src?: IRAttr; | ||
| } | ||
| interface SFCScriptBlock { | ||
| __generic?: SfcBlockAttr; | ||
| __generic?: IRAttr; | ||
| } | ||
| interface SFCStyleBlock { | ||
| __module?: SfcBlockAttr; | ||
| __module?: IRAttr; | ||
| } | ||
@@ -178,0 +184,0 @@ } |
@@ -182,5 +182,4 @@ "use strict"; | ||
| offset: offset - node.loc.start.offset, | ||
| quotes: offset > p.value.loc.start.offset, | ||
| }; | ||
| } | ||
| //# sourceMappingURL=parseSfc.js.map |
| import type * as CompilerDOM from '@vue/compiler-dom'; | ||
| import type * as ts from 'typescript'; | ||
| import type { Sfc, TextRange } from '../types'; | ||
| import type { IRTemplate, TextRange } from '../types'; | ||
| export { hyphenate as hyphenateTag } from '@vue/shared'; | ||
| export declare function hyphenateAttr(str: string): string; | ||
| export declare function normalizeAttributeValue(node: CompilerDOM.TextNode): readonly [string, number]; | ||
| export declare function getElementTagOffsets(node: CompilerDOM.ElementNode, template: NonNullable<Sfc['template']>): [number] | [number, number]; | ||
| export declare function getElementTagOffsets(node: CompilerDOM.ElementNode, template: IRTemplate): [number] | [number, number]; | ||
| export declare function getStartEnd<T extends ts.Node>(ts: typeof import('typescript'), node: T, ast: ts.SourceFile): TextRange<T>; | ||
| export declare function getNodeText(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): string; |
| import type { Mapping, VirtualCode } from '@volar/language-core'; | ||
| import type { Code, Sfc, VueLanguagePluginReturn } from '../types'; | ||
| import type { Code, IR, VueLanguagePluginReturn } from '../types'; | ||
| export declare class VueEmbeddedCode { | ||
@@ -12,2 +12,2 @@ id: string; | ||
| } | ||
| export declare function useEmbeddedCodes(plugins: VueLanguagePluginReturn[], fileName: string, sfc: Sfc): () => VirtualCode[]; | ||
| export declare function useEmbeddedCodes(plugins: VueLanguagePluginReturn[], fileName: string, ir: IR): () => VirtualCode[]; |
@@ -18,18 +18,18 @@ "use strict"; | ||
| exports.VueEmbeddedCode = VueEmbeddedCode; | ||
| function useEmbeddedCodes(plugins, fileName, sfc) { | ||
| function useEmbeddedCodes(plugins, fileName, ir) { | ||
| const getNameToBlockMap = (0, alien_signals_1.computed)(() => { | ||
| const blocks = {}; | ||
| if (sfc.template) { | ||
| blocks[sfc.template.name] = sfc.template; | ||
| if (ir.template) { | ||
| blocks[ir.template.name] = ir.template; | ||
| } | ||
| if (sfc.script) { | ||
| blocks[sfc.script.name] = sfc.script; | ||
| if (ir.script) { | ||
| blocks[ir.script.name] = ir.script; | ||
| } | ||
| if (sfc.scriptSetup) { | ||
| blocks[sfc.scriptSetup.name] = sfc.scriptSetup; | ||
| if (ir.scriptSetup) { | ||
| blocks[ir.scriptSetup.name] = ir.scriptSetup; | ||
| } | ||
| for (const block of sfc.styles) { | ||
| for (const block of ir.styles) { | ||
| blocks[block.name] = block; | ||
| } | ||
| for (const block of sfc.customBlocks) { | ||
| for (const block of ir.customBlocks) { | ||
| blocks[block.name] = block; | ||
@@ -79,3 +79,3 @@ } | ||
| } | ||
| const newCodeList = plugin.getEmbeddedCodes(fileName, sfc); | ||
| const newCodeList = plugin.getEmbeddedCodes(fileName, ir); | ||
| const map = new Map(); | ||
@@ -115,3 +115,3 @@ for (const { id, lang } of newCodeList) { | ||
| try { | ||
| plugin.resolveEmbeddedCode(fileName, sfc, code); | ||
| plugin.resolveEmbeddedCode(fileName, ir, code); | ||
| } | ||
@@ -118,0 +118,0 @@ catch (e) { |
| import type { CodeMapping, VirtualCode } from '@volar/language-core'; | ||
| import type { SFCParseResult } from '@vue/compiler-sfc'; | ||
| import type * as ts from 'typescript'; | ||
| import type { Sfc, VueCompilerOptions, VueLanguagePluginReturn } from '../types'; | ||
| import type { IR, VueCompilerOptions, VueLanguagePluginReturn } from '../types'; | ||
| export declare class VueVirtualCode implements VirtualCode { | ||
@@ -18,3 +18,5 @@ fileName: string; | ||
| get vueSfc(): SFCParseResult | undefined; | ||
| get sfc(): Sfc; | ||
| get ir(): IR; | ||
| /** @deprecated use `ir` instead */ | ||
| get sfc(): IR; | ||
| get embeddedCodes(): VirtualCode[]; | ||
@@ -21,0 +23,0 @@ get mappings(): CodeMapping[]; |
@@ -15,2 +15,6 @@ "use strict"; | ||
| } | ||
| get ir() { | ||
| return this._ir; | ||
| } | ||
| /** @deprecated use `ir` instead */ | ||
| get sfc() { | ||
@@ -17,0 +21,0 @@ return this._ir; |
| import type { SFCParseResult } from '@vue/compiler-sfc'; | ||
| import type * as ts from 'typescript'; | ||
| import type { Sfc, VueLanguagePluginReturn } from '../types'; | ||
| export declare function useIR(ts: typeof import('typescript'), plugins: VueLanguagePluginReturn[], fileName: string, getSnapshot: () => ts.IScriptSnapshot, getParseSfcResult: () => SFCParseResult | undefined): Sfc; | ||
| import type { IR, VueLanguagePluginReturn } from '../types'; | ||
| export declare function useIR(ts: typeof import('typescript'), plugins: VueLanguagePluginReturn[], fileName: string, getSnapshot: () => ts.IScriptSnapshot, getParseSfcResult: () => SFCParseResult | undefined): IR; |
+2
-2
| { | ||
| "name": "@vue/language-core", | ||
| "version": "3.2.9", | ||
| "version": "3.3.0", | ||
| "license": "MIT", | ||
@@ -37,3 +37,3 @@ "files": [ | ||
| }, | ||
| "gitHead": "9c1fd47ffe25e86394232dfc76453a5f76cb4fe0" | ||
| "gitHead": "1088dce8ae6b937f7525fae4982e3b3ea99d3c64" | ||
| } |
+1
-0
@@ -114,2 +114,3 @@ # @vue/language-core | ||
| | `fallthroughAttributes` | `boolean` | `false` | Enable type inference for fallthrough attributes. | | ||
| | `checkRequiredFallthroughAttributes` | `boolean` | `false` | Check required fallthrough attributes. | | ||
| | `jsxSlots` | `boolean` | `false` | Use JSX-style slots types. | | ||
@@ -116,0 +117,0 @@ | `dataAttributes` | `string[]` | `[]` | Allowed data-* attribute patterns. | |
@@ -146,2 +146,3 @@ declare global { | ||
| function __VLS_asFunctionalSlot<S>(slot: S): S extends () => infer R ? (props: {}) => R : NonNullable<S>; | ||
| function __VLS_omit<T, K>(target: T, props: K): Omit<T, keyof K>; | ||
| function __VLS_tryAsConstant<const T>(t: T): T; | ||
@@ -148,0 +149,0 @@ } |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
391771
0.26%8984
0.37%162
0.62%2
-33.33%