@volar/vue-language-core
Advanced tools
Comparing version 1.3.11 to 1.3.12
@@ -11,2 +11,3 @@ "use strict"; | ||
const localTypes_1 = require("../utils/localTypes"); | ||
const muggle = require("muggle-string"); | ||
function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, cssVars, cssModuleClasses, cssScopedClasses, htmlGen, compilerOptions, vueCompilerOptions, codes = [], mirrorBehaviorMappings = []) { | ||
@@ -38,3 +39,2 @@ //#region monkey fix: https://github.com/johnsoncodehk/volar/pull/2113 | ||
importSectionEndOffset: 0, | ||
notOnTopTypeExports: [], | ||
defineProps: undefined, | ||
@@ -45,4 +45,4 @@ propsAssignName: undefined, | ||
slotsTypeArg: undefined, | ||
typeBindings: [], | ||
withDefaultsArg: undefined, | ||
defineProp: [], | ||
}; | ||
@@ -58,2 +58,3 @@ } | ||
WithTemplateSlots: false, | ||
ToTemplateSlots: false, | ||
}; | ||
@@ -141,2 +142,5 @@ if (vueCompilerOptions.jsxTemplates && vueCompilerOptions.target >= 3.3) { | ||
} | ||
if (usedHelperTypes.ToTemplateSlots) { | ||
codes.push(`type __VLS_ToTemplateSlots<T> = { [K in keyof T]: NonNullable<T[K]> extends (...args: any[]) => any ? T[K] : (props: T[K]) => any };\n`); | ||
} | ||
if (usedPrettify) { | ||
@@ -238,2 +242,25 @@ codes.push(`type __VLS_Prettify<T> = { [K in keyof T]: T[K]; } & {};\n`); | ||
} | ||
function generateExportDefault() { | ||
// fix https://github.com/johnsoncodehk/volar/issues/1127 | ||
codes.push([ | ||
'', | ||
'scriptSetup', | ||
0, | ||
{ diagnostic: true }, | ||
]); | ||
codes.push('export default '); | ||
} | ||
function generateExportDefaultEndMapping() { | ||
if (!sfc.scriptSetup) { | ||
return; | ||
} | ||
// fix https://github.com/johnsoncodehk/volar/issues/1127 | ||
codes.push([ | ||
'', | ||
'scriptSetup', | ||
sfc.scriptSetup.content.length, | ||
{ diagnostic: true }, | ||
]); | ||
codes.push(`\n`); | ||
} | ||
function generateScriptSetupAndTemplate() { | ||
@@ -243,13 +270,8 @@ if (!sfc.scriptSetup || !scriptSetupRanges) { | ||
} | ||
if (!scriptRanges?.exportDefault) { | ||
// fix https://github.com/johnsoncodehk/volar/issues/1127 | ||
codes.push([ | ||
'', | ||
'scriptSetup', | ||
0, | ||
{ diagnostic: true }, | ||
]); | ||
codes.push('export default '); | ||
} | ||
const definePropMirrors = {}; | ||
let scriptSetupGeneratedOffset; | ||
if (sfc.scriptSetup.generic) { | ||
if (!scriptRanges?.exportDefault) { | ||
generateExportDefault(); | ||
} | ||
codes.push(`(<`); | ||
@@ -267,55 +289,123 @@ codes.push([ | ||
codes.push('(\n'); | ||
if (scriptSetupRanges.propsRuntimeArg && scriptSetupRanges.defineProps) { | ||
codes.push(`__VLS_props = (() => {\n`); | ||
codes.push(`const __VLS_return = (await import('vue')).`); | ||
addVirtualCode('scriptSetup', scriptSetupRanges.defineProps.start, scriptSetupRanges.defineProps.end); | ||
codes.push(`__VLS_props: typeof __VLS_setup['props'] & import('vue').VNodeProps,\n`); | ||
codes.push(`__VLS_ctx: Pick<typeof __VLS_setup, 'expose' | 'attrs' | 'emit' | 'slots'>,\n`); | ||
codes.push('__VLS_setup = (() => {\n'); | ||
scriptSetupGeneratedOffset = generateSetupFunction(true, 'none', definePropMirrors); | ||
//#region exposed | ||
codes.push(`const __VLS_exposed = `); | ||
if (scriptSetupRanges.exposeRuntimeArg) { | ||
addVirtualCode('scriptSetup', scriptSetupRanges.exposeRuntimeArg.start, scriptSetupRanges.exposeRuntimeArg.end); | ||
} | ||
else { | ||
codes.push(`{}`); | ||
} | ||
codes.push(';\n'); | ||
//#endregion | ||
//#region props | ||
if ((scriptSetupRanges.propsRuntimeArg && scriptSetupRanges.defineProps) | ||
|| scriptSetupRanges.defineProp.length) { | ||
if (scriptSetupRanges.propsRuntimeArg && scriptSetupRanges.defineProps) { | ||
codes.push(`const __VLS_props = `); | ||
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.defineProps.start, scriptSetupRanges.defineProps.end); | ||
codes.push(`;\n`); | ||
} | ||
else if (scriptSetupRanges.defineProp.length) { | ||
codes.push(`const __VLS_defaults = {\n`); | ||
for (const defineProp of scriptSetupRanges.defineProp) { | ||
if (defineProp.defaultValue) { | ||
if (defineProp.name) { | ||
codes.push(sfc.scriptSetup.content.substring(defineProp.name.start, defineProp.name.end)); | ||
} | ||
else { | ||
codes.push('modelValue'); | ||
} | ||
codes.push(`: `); | ||
codes.push(sfc.scriptSetup.content.substring(defineProp.defaultValue.start, defineProp.defaultValue.end)); | ||
codes.push(`,\n`); | ||
} | ||
} | ||
codes.push(`};\n`); | ||
codes.push(`let __VLS_props!: {\n`); | ||
for (const defineProp of scriptSetupRanges.defineProp) { | ||
let propName = 'modelValue'; | ||
if (defineProp.name) { | ||
propName = sfc.scriptSetup.content.substring(defineProp.name.start, defineProp.name.end); | ||
const propMirrorStart = muggle.getLength(codes); | ||
definePropMirrors[propName] = [propMirrorStart, propMirrorStart + propName.length]; | ||
} | ||
codes.push(`${propName}${defineProp.required ? '' : '?'}: `); | ||
if (defineProp.type) { | ||
codes.push(sfc.scriptSetup.content.substring(defineProp.type.start, defineProp.type.end)); | ||
} | ||
else if (defineProp.defaultValue) { | ||
codes.push(`typeof __VLS_defaults['`); | ||
codes.push(propName); | ||
codes.push(`']`); | ||
} | ||
else { | ||
codes.push(`any`); | ||
} | ||
codes.push(',\n'); | ||
} | ||
codes.push(`};\n`); | ||
} | ||
if (scriptSetupRanges.slotsTypeArg) { | ||
usedHelperTypes.ToTemplateSlots = true; | ||
codes.push(` & { [K in keyof JSX.ElementChildrenAttribute]: __VLS_ToTemplateSlots<`); | ||
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.slotsTypeArg.start, scriptSetupRanges.slotsTypeArg.end); | ||
codes.push(`>; }`); | ||
} | ||
codes.push(`;\n`); | ||
codes.push(`return {} as typeof __VLS_return & import('vue').VNodeProps;\n`); | ||
codes.push(`})()`); | ||
} | ||
else { | ||
codes.push(`__VLS_props: import('vue').VNodeProps`); | ||
codes.push(`const __VLS_props: {}`); | ||
if (scriptSetupRanges.slotsTypeArg) { | ||
codes.push(` & { [K in keyof JSX.ElementChildrenAttribute]: `); | ||
addVirtualCode('scriptSetup', scriptSetupRanges.slotsTypeArg.start, scriptSetupRanges.slotsTypeArg.end); | ||
codes.push(`; }`); | ||
usedHelperTypes.ToTemplateSlots = true; | ||
codes.push(` & { [K in keyof JSX.ElementChildrenAttribute]: __VLS_ToTemplateSlots<`); | ||
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.slotsTypeArg.start, scriptSetupRanges.slotsTypeArg.end); | ||
codes.push(`>; }`); | ||
} | ||
if (scriptSetupRanges.propsTypeArg) { | ||
codes.push(' & '); | ||
addVirtualCode('scriptSetup', scriptSetupRanges.propsTypeArg.start, scriptSetupRanges.propsTypeArg.end); | ||
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.propsTypeArg.start, scriptSetupRanges.propsTypeArg.end); | ||
} | ||
codes.push(`;\n`); | ||
} | ||
codes.push(',\n'); | ||
codes.push('__VLS_ctx = (() => {\n'); | ||
generateSetupFunction(true); | ||
codes.push('return {\n'); | ||
codes.push('attrs: {} as any,\n'); | ||
codes.push('slots: {} as typeof __VLS_setup extends () => Promise<{ slots: infer T }> ? T : never,\n'); | ||
//#region emit | ||
codes.push('emit: '); | ||
//#endregion | ||
//#region emits | ||
codes.push(`const __VLS_emit = `); | ||
if (scriptSetupRanges.emitsTypeArg) { | ||
codes.push('{} as '); | ||
addVirtualCode('scriptSetup', scriptSetupRanges.emitsTypeArg.start, scriptSetupRanges.emitsTypeArg.end); | ||
codes.push(',\n'); | ||
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.emitsTypeArg.start, scriptSetupRanges.emitsTypeArg.end); | ||
codes.push(';\n'); | ||
} | ||
else if (scriptSetupRanges.emitsRuntimeArg) { | ||
codes.push(`(await import('vue')).defineEmits(`); | ||
addVirtualCode('scriptSetup', scriptSetupRanges.emitsRuntimeArg.start, scriptSetupRanges.emitsRuntimeArg.end); | ||
codes.push('),\n'); | ||
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.emitsRuntimeArg.start, scriptSetupRanges.emitsRuntimeArg.end); | ||
codes.push(');\n'); | ||
} | ||
else { | ||
codes.push('{} as any,\n'); | ||
codes.push('{} as any;\n'); | ||
} | ||
//#endregion | ||
//#region expose | ||
codes.push('expose(__VLS_exposed: typeof __VLS_setup extends () => Promise<{ exposed: infer T }> ? T : never) { },\n'); | ||
//#endregion | ||
codes.push('return {} as {\n'); | ||
codes.push(`props: typeof __VLS_props,\n`); | ||
codes.push('expose(exposed: typeof __VLS_exposed): void,\n'); | ||
codes.push('attrs: any,\n'); | ||
codes.push('slots: ReturnType<typeof __VLS_template>,\n'); | ||
codes.push('emit: typeof __VLS_emit'); | ||
codes.push('};\n'); | ||
codes.push('})(),\n'); | ||
codes.push(') => ({} as JSX.Element & { __ctx?: typeof __VLS_ctx, __props?: typeof __VLS_props }))'); | ||
codes.push(') => ({} as any))'); | ||
} | ||
else if (!sfc.script) { | ||
// no script block, generate script setup code at root | ||
scriptSetupGeneratedOffset = generateSetupFunction(false, 'export', definePropMirrors); | ||
} | ||
else { | ||
if (!scriptRanges?.exportDefault) { | ||
generateExportDefault(); | ||
} | ||
codes.push('(() => {\n'); | ||
generateSetupFunction(false); | ||
codes.push(`return {} as typeof __VLS_setup extends () => Promise<infer T> ? T : never;\n`); | ||
scriptSetupGeneratedOffset = generateSetupFunction(false, 'return', definePropMirrors); | ||
codes.push(`})()`); | ||
@@ -326,30 +416,48 @@ } | ||
} | ||
codes.push(`;`); | ||
// fix https://github.com/johnsoncodehk/volar/issues/1127 | ||
codes.push([ | ||
'', | ||
'scriptSetup', | ||
sfc.scriptSetup.content.length, | ||
{ diagnostic: true }, | ||
]); | ||
codes.push(`\n`); | ||
generateExportDefaultEndMapping(); | ||
if (scriptSetupGeneratedOffset !== undefined) { | ||
for (const defineProp of scriptSetupRanges.defineProp) { | ||
if (!defineProp.name) { | ||
continue; | ||
} | ||
const propName = sfc.scriptSetup.content.substring(defineProp.name.start, defineProp.name.end); | ||
const propMirror = definePropMirrors[propName]; | ||
if (propMirror) { | ||
mirrorBehaviorMappings.push({ | ||
sourceRange: [defineProp.name.start + scriptSetupGeneratedOffset, defineProp.name.end + scriptSetupGeneratedOffset], | ||
generatedRange: propMirror, | ||
data: [ | ||
language_core_1.MirrorBehaviorCapabilities.full, | ||
language_core_1.MirrorBehaviorCapabilities.full, | ||
], | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
function generateSetupFunction(functional) { | ||
function generateSetupFunction(functional, mode, definePropMirrors) { | ||
if (!scriptSetupRanges || !sfc.scriptSetup) { | ||
return; | ||
} | ||
codes.push('const __VLS_setup = async () => {\n'); | ||
if (sfc.scriptSetup.generic && scriptSetupRanges.propsRuntimeArg && scriptSetupRanges.defineProps) { | ||
addVirtualCode('scriptSetup', scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.defineProps.start); | ||
codes.push('__VLS_props'); | ||
addVirtualCode('scriptSetup', scriptSetupRanges.defineProps.end); | ||
const definePropProposalA = sfc.scriptSetup.content.trimStart().startsWith('// @experimentalDefinePropProposal=kevinEdition') || vueCompilerOptions.experimentalDefinePropProposal === 'kevinEdition'; | ||
const definePropProposalB = sfc.scriptSetup.content.trimStart().startsWith('// @experimentalDefinePropProposal=johnsonEdition') || vueCompilerOptions.experimentalDefinePropProposal === 'johnsonEdition'; | ||
if (vueCompilerOptions.target >= 3.3) { | ||
codes.push(`const { defineProps, defineEmits, defineSlots, defineModel, defineOptions, withDefaults } = await import('vue');\n`); | ||
} | ||
else if (sfc.scriptSetup.generic && scriptSetupRanges.propsTypeArg) { | ||
addVirtualCode('scriptSetup', scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.propsTypeArg.start); | ||
codes.push('typeof __VLS_props'); | ||
addVirtualCode('scriptSetup', scriptSetupRanges.propsTypeArg.end); | ||
if (definePropProposalA) { | ||
codes.push(` | ||
declare function defineProp<T>(name: string, options: { required: true } & Record<string, unknown>): import('vue').ComputedRef<T>; | ||
declare function defineProp<T>(name: string, options: { default: any } & Record<string, unknown>): import('vue').ComputedRef<T>; | ||
declare function defineProp<T>(name?: string, options?: any): import('vue').ComputedRef<T | undefined>; | ||
`.trim() + '\n'); | ||
} | ||
else { | ||
addVirtualCode('scriptSetup', scriptSetupRanges.importSectionEndOffset); | ||
if (definePropProposalB) { | ||
codes.push(` | ||
declare function defineProp<T>(value: T | (() => T), required?: boolean, rest?: any): import('vue').ComputedRef<T>; | ||
declare function defineProp<T>(value: T | (() => T) | undefined, required: true, rest?: any): import('vue').ComputedRef<T>; | ||
declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?: any): import('vue').ComputedRef<T | undefined>; | ||
`.trim() + '\n'); | ||
} | ||
const scriptSetupGeneratedOffset = muggle.getLength(codes) - scriptSetupRanges.importSectionEndOffset; | ||
addVirtualCode('scriptSetup', scriptSetupRanges.importSectionEndOffset); | ||
if (scriptSetupRanges.propsTypeArg && scriptSetupRanges.withDefaultsArg) { | ||
@@ -370,2 +478,28 @@ // fix https://github.com/johnsoncodehk/volar/issues/1187 | ||
} | ||
if (scriptSetupRanges.defineProp.length) { | ||
codes.push(`props: {} as {\n`); | ||
for (const defineProp of scriptSetupRanges.defineProp) { | ||
let propName = 'modelValue'; | ||
if (defineProp.name) { | ||
propName = sfc.scriptSetup.content.substring(defineProp.name.start, defineProp.name.end); | ||
const start = muggle.getLength(codes); | ||
definePropMirrors[propName] = [start, start + propName.length]; | ||
} | ||
codes.push(`${propName}: `); | ||
let type = 'any'; | ||
if (!defineProp.nameIsString) { | ||
type = `NonNullable<typeof ${propName}['value']>`; | ||
} | ||
else if (defineProp.type) { | ||
type = sfc.scriptSetup.content.substring(defineProp.type.start, defineProp.type.end); | ||
} | ||
if (defineProp.required) { | ||
codes.push(`{ required: true, type: import('vue').PropType<${type}> },\n`); | ||
} | ||
else { | ||
codes.push(`import('vue').PropType<${type}>,\n`); | ||
} | ||
} | ||
codes.push(`},\n`); | ||
} | ||
if (!bypassDefineComponent) { | ||
@@ -454,25 +588,21 @@ if (scriptSetupRanges.propsRuntimeArg || scriptSetupRanges.propsTypeArg) { | ||
generateTemplate(); | ||
if (functional) { | ||
codes.push('return {\n'); | ||
codes.push('slots: __VLS_template(),\n'); | ||
codes.push('exposed: '); | ||
if (scriptSetupRanges.exposeRuntimeArg) { | ||
addVirtualCode('scriptSetup', scriptSetupRanges.exposeRuntimeArg.start, scriptSetupRanges.exposeRuntimeArg.end); | ||
} | ||
else { | ||
codes.push(`{}`); | ||
} | ||
codes.push(',\n'); | ||
codes.push('};\n'); | ||
if (mode === 'return') { | ||
codes.push(`return `); | ||
} | ||
else { | ||
if (!vueCompilerOptions.skipTemplateCodegen && htmlGen?.hasSlot) { | ||
else if (mode === 'export') { | ||
generateExportDefault(); | ||
} | ||
if (mode === 'return' || mode === 'export') { | ||
if (!vueCompilerOptions.skipTemplateCodegen && (htmlGen?.hasSlot || scriptSetupRanges?.slotsTypeArg)) { | ||
usedHelperTypes.WithTemplateSlots = true; | ||
codes.push(`return {} as __VLS_WithTemplateSlots<typeof __VLS_publicComponent, ReturnType<typeof __VLS_template>>;\n`); | ||
codes.push(`{} as __VLS_WithTemplateSlots<typeof __VLS_publicComponent, ReturnType<typeof __VLS_template>>;`); | ||
} | ||
else { | ||
codes.push(`return {} as typeof __VLS_publicComponent;\n`); | ||
codes.push(`{} as typeof __VLS_publicComponent;`); | ||
} | ||
} | ||
codes.push(`};\n`); | ||
if (mode === 'export') { | ||
generateExportDefaultEndMapping(); | ||
} | ||
return scriptSetupGeneratedOffset; | ||
} | ||
@@ -485,3 +615,4 @@ function generateTemplate() { | ||
if (scriptSetupRanges?.slotsTypeArg && sfc.scriptSetup) { | ||
codes.push(`var __VLS_slots!: `); | ||
usedHelperTypes.ToTemplateSlots = true; | ||
codes.push(`var __VLS_slots!: __VLS_ToTemplateSlots<`); | ||
codes.push([ | ||
@@ -493,3 +624,3 @@ sfc.scriptSetup.content.substring(scriptSetupRanges.slotsTypeArg.start, scriptSetupRanges.slotsTypeArg.end), | ||
]); | ||
codes.push(';\n'); | ||
codes.push('>;\n'); | ||
} | ||
@@ -654,5 +785,6 @@ ; | ||
if (scriptSetupRanges?.slotsTypeArg && sfc.scriptSetup) { | ||
codes.push(`let __VLS_slots!: `); | ||
usedHelperTypes.ToTemplateSlots = true; | ||
codes.push(`let __VLS_slots!: __VLS_ToTemplateSlots<`); | ||
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.slotsTypeArg.start, scriptSetupRanges.slotsTypeArg.end); | ||
codes.push(`;\n`); | ||
codes.push(`>;\n`); | ||
} | ||
@@ -659,0 +791,0 @@ else { |
@@ -7,5 +7,3 @@ import type * as ts from 'typescript/lib/tsserverlibrary'; | ||
importSectionEndOffset: number; | ||
notOnTopTypeExports: TextRange[]; | ||
bindings: TextRange[]; | ||
typeBindings: TextRange[]; | ||
withDefaultsArg: TextRange | undefined; | ||
@@ -22,2 +20,9 @@ defineProps: TextRange | undefined; | ||
exposeRuntimeArg: TextRange | undefined; | ||
defineProp: { | ||
name: TextRange | undefined; | ||
nameIsString: boolean; | ||
type: TextRange | undefined; | ||
defaultValue: TextRange | undefined; | ||
required: boolean; | ||
}[]; | ||
}; | ||
@@ -24,0 +29,0 @@ export declare function parseBindingRanges(ts: typeof import('typescript/lib/tsserverlibrary'), sourceFile: ts.SourceFile, isType: boolean): TextRange[]; |
@@ -6,3 +6,2 @@ "use strict"; | ||
let foundNonImportExportNode = false; | ||
let notOnTopTypeExports = []; | ||
let importSectionEndOffset = 0; | ||
@@ -20,4 +19,6 @@ let withDefaultsArg; | ||
let emitsTypeNums = -1; | ||
const definePropProposalA = vueCompilerOptions.experimentalDefinePropProposal === 'kevinEdition' || ast.getFullText().trimStart().startsWith('// @experimentalDefinePropProposal=kevinEdition'); | ||
const definePropProposalB = vueCompilerOptions.experimentalDefinePropProposal === 'johnsonEdition' || ast.getFullText().trimStart().startsWith('// @experimentalDefinePropProposal=johnsonEdition'); | ||
const defineProp = []; | ||
const bindings = parseBindingRanges(ts, ast, false); | ||
const typeBindings = parseBindingRanges(ts, ast, true); | ||
ast.forEachChild(node => { | ||
@@ -34,5 +35,2 @@ const isTypeExport = (ts.isTypeAliasDeclaration(node) || ts.isInterfaceDeclaration(node)) && node.modifiers?.some(mod => mod.kind === ts.SyntaxKind.ExportKeyword); | ||
} | ||
else if (isTypeExport && foundNonImportExportNode) { | ||
notOnTopTypeExports.push(_getStartEnd(node)); | ||
} | ||
}); | ||
@@ -42,5 +40,3 @@ ast.forEachChild(child => visitNode(child, ast)); | ||
importSectionEndOffset, | ||
notOnTopTypeExports, | ||
bindings, | ||
typeBindings, | ||
withDefaultsArg, | ||
@@ -57,2 +53,3 @@ defineProps, | ||
exposeRuntimeArg, | ||
defineProp, | ||
}; | ||
@@ -66,2 +63,77 @@ function _getStartEnd(node) { | ||
const callText = node.expression.getText(ast); | ||
if (callText === 'defineModel') { | ||
let name; | ||
let options; | ||
if (node.arguments.length >= 2) { | ||
name = _getStartEnd(node.arguments[0]); | ||
options = node.arguments[1]; | ||
} | ||
else if (node.arguments.length >= 1) { | ||
if (ts.isStringLiteral(node.arguments[0])) { | ||
name = _getStartEnd(node.arguments[0]); | ||
} | ||
else { | ||
options = node.arguments[0]; | ||
} | ||
} | ||
let required = false; | ||
if (options && ts.isObjectLiteralExpression(options)) { | ||
for (const property of options.properties) { | ||
if (ts.isPropertyAssignment(property) && ts.isIdentifier(property.name) && property.name.getText(ast) === 'required' && property.initializer.kind === ts.SyntaxKind.TrueKeyword) { | ||
required = true; | ||
break; | ||
} | ||
} | ||
} | ||
defineProp.push({ | ||
name, | ||
nameIsString: true, | ||
type: node.typeArguments?.length ? _getStartEnd(node.typeArguments[0]) : undefined, | ||
defaultValue: undefined, | ||
required, | ||
}); | ||
} | ||
else if (callText === 'defineProp') { | ||
if (definePropProposalA) { | ||
let required = false; | ||
if (node.arguments.length >= 2) { | ||
const secondArg = node.arguments[1]; | ||
if (ts.isObjectLiteralExpression(secondArg)) { | ||
for (const property of secondArg.properties) { | ||
if (ts.isPropertyAssignment(property) && ts.isIdentifier(property.name) && property.name.getText(ast) === 'required' && property.initializer.kind === ts.SyntaxKind.TrueKeyword) { | ||
required = true; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
if (node.arguments.length >= 1) { | ||
defineProp.push({ | ||
name: _getStartEnd(node.arguments[0]), | ||
nameIsString: true, | ||
type: node.typeArguments?.length ? _getStartEnd(node.typeArguments[0]) : undefined, | ||
defaultValue: undefined, | ||
required, | ||
}); | ||
} | ||
else if (ts.isVariableDeclaration(parent)) { | ||
defineProp.push({ | ||
name: _getStartEnd(parent.name), | ||
nameIsString: false, | ||
type: node.typeArguments?.length ? _getStartEnd(node.typeArguments[0]) : undefined, | ||
defaultValue: undefined, | ||
required, | ||
}); | ||
} | ||
} | ||
else if (definePropProposalB && ts.isVariableDeclaration(parent)) { | ||
defineProp.push({ | ||
name: _getStartEnd(parent.name), | ||
nameIsString: false, | ||
defaultValue: node.arguments.length >= 1 ? _getStartEnd(node.arguments[0]) : undefined, | ||
type: node.typeArguments?.length ? _getStartEnd(node.typeArguments[0]) : undefined, | ||
required: node.arguments.length >= 2 && node.arguments[1].kind === ts.SyntaxKind.TrueKeyword, | ||
}); | ||
} | ||
} | ||
if (vueCompilerOptions.macros.defineProps.includes(callText) | ||
@@ -68,0 +140,0 @@ || vueCompilerOptions.macros.defineSlots.includes(callText) |
@@ -33,2 +33,3 @@ import * as embedded from '@volar/language-core'; | ||
hooks: string[]; | ||
experimentalDefinePropProposal: 'kevinEdition' | 'johnsonEdition' | false; | ||
experimentalResolveStyleCssClasses: 'scoped' | 'always' | 'never'; | ||
@@ -35,0 +36,0 @@ experimentalModelPropName: Record<string, Record<string, boolean | Record<string, string> | Record<string, string>[]>>; |
import { VueCompilerOptions } from '../types'; | ||
export declare const typesFileName = "__VLS_types.ts"; | ||
export declare const typesFileName = "__VLS_types.d.ts"; | ||
export declare function getTypesCode(vueVersion: number, vueCompilerOptions: VueCompilerOptions): string; | ||
export declare function genConstructorOverloads(name?: string, nums?: number): string; |
@@ -5,3 +5,3 @@ "use strict"; | ||
const shared_1 = require("./shared"); | ||
exports.typesFileName = '__VLS_types.ts'; | ||
exports.typesFileName = '__VLS_types.d.ts'; | ||
function getTypesCode(vueVersion, vueCompilerOptions) { | ||
@@ -88,3 +88,3 @@ const libName = (0, shared_1.getVueLibraryName)(vueVersion); | ||
? (props: Props, ctx?: { attrs?: any, expose?: any, slots?: Slots, emit?: Emit }) => JSX.Element & { __ctx?: typeof ctx, __props?: typeof props } | ||
: (_: T) => { __ctx?: { attrs?: undefined, expose?: undefined, slots?: undefined, emit?: undefined }, __props?: T }; // IntrinsicElement | ||
: (_: T, ctx?: any) => { __ctx?: { attrs?: undefined, expose?: undefined, slots?: undefined, emit?: undefined }, __props?: T }; // IntrinsicElement | ||
export declare function pickEvent<Emit, K, E>(emit: Emit, emitKey: K, event: E): FillingEventArg< | ||
@@ -91,0 +91,0 @@ PickNotAny< |
@@ -190,2 +190,3 @@ "use strict"; | ||
// experimental | ||
experimentalDefinePropProposal: vueOptions.experimentalDefinePropProposal ?? false, | ||
experimentalAdditionalLanguageModules: vueOptions.experimentalAdditionalLanguageModules ?? [], | ||
@@ -192,0 +193,0 @@ experimentalResolveStyleCssClasses: vueOptions.experimentalResolveStyleCssClasses ?? 'scoped', |
{ | ||
"name": "@volar/vue-language-core", | ||
"version": "1.3.11", | ||
"version": "1.3.12", | ||
"main": "out/index.js", | ||
@@ -29,3 +29,3 @@ "license": "MIT", | ||
}, | ||
"gitHead": "53656272d5a3c17842318760ad00278689b07005" | ||
"gitHead": "03f8745d7428faee5c89d17e65d4cb76961efb2b" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
234288
5214