@vue/language-core
Advanced tools
Comparing version 1.8.19 to 1.8.20
@@ -9,3 +9,4 @@ import { FileRangeCapabilities, MirrorBehaviorCapabilities } from '@volar/language-core'; | ||
import { Sfc } from '../types'; | ||
export declare function generate(ts: typeof import('typescript/lib/tsserverlibrary'), fileName: string, _sfc: Sfc, lang: string, scriptRanges: ScriptRanges | undefined, scriptSetupRanges: ScriptSetupRanges | undefined, htmlGen: ReturnType<typeof templateGen['generate']> | undefined, compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions, codegenStack: boolean): { | ||
export declare function generate(ts: typeof import('typescript/lib/tsserverlibrary'), fileName: string, script: Sfc['script'], scriptSetup: Sfc['scriptSetup'], styles: Sfc['styles'], // TODO: computed it | ||
lang: string, scriptRanges: ScriptRanges | undefined, scriptSetupRanges: ScriptSetupRanges | undefined, htmlGen: ReturnType<typeof templateGen['generate']> | undefined, compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions, codegenStack: boolean): { | ||
codes: SourceMaps.Segment<FileRangeCapabilities>[]; | ||
@@ -12,0 +13,0 @@ codeStacks: SourceMaps.StackNode[]; |
@@ -33,12 +33,9 @@ "use strict"; | ||
const transform_1 = require("../utils/transform"); | ||
function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htmlGen, compilerOptions, vueCompilerOptions, codegenStack) { | ||
function generate(ts, fileName, script, scriptSetup, styles, // TODO: computed it | ||
lang, scriptRanges, scriptSetupRanges, htmlGen, compilerOptions, vueCompilerOptions, codegenStack) { | ||
const [codes, codeStacks] = codegenStack ? muggle.track([]) : [[], []]; | ||
const mirrorBehaviorMappings = []; | ||
//#region monkey fix: https://github.com/vuejs/language-tools/pull/2113 | ||
const sfc = { | ||
script: _sfc.script, | ||
scriptSetup: _sfc.scriptSetup, | ||
}; | ||
if (!sfc.script && !sfc.scriptSetup) { | ||
sfc.scriptSetup = { | ||
if (!script && !scriptSetup) { | ||
scriptSetup = { | ||
content: '', | ||
@@ -54,2 +51,3 @@ lang: 'ts', | ||
attrs: {}, | ||
ast: ts.createSourceFile('', '', ts.ScriptTarget.Latest, false, ts.ScriptKind.TS), | ||
}; | ||
@@ -69,4 +67,4 @@ scriptSetupRanges = { | ||
const bindingNames = new Set([ | ||
...scriptRanges?.bindings.map(range => sfc.script.content.substring(range.start, range.end)) ?? [], | ||
...scriptSetupRanges?.bindings.map(range => sfc.scriptSetup.content.substring(range.start, range.end)) ?? [], | ||
...scriptRanges?.bindings.map(range => script.content.substring(range.start, range.end)) ?? [], | ||
...scriptSetupRanges?.bindings.map(range => scriptSetup.content.substring(range.start, range.end)) ?? [], | ||
]); | ||
@@ -91,3 +89,3 @@ const bypassDefineComponent = lang === 'js' || lang === 'jsx'; | ||
} | ||
if (sfc.scriptSetup) { | ||
if (scriptSetup) { | ||
// for code action edits | ||
@@ -97,3 +95,3 @@ codes.push([ | ||
'scriptSetup', | ||
sfc.scriptSetup.content.length, | ||
scriptSetup.content.length, | ||
{}, | ||
@@ -126,3 +124,3 @@ ]); | ||
if (usedHelperTypes.WithTemplateSlots) { | ||
codes.push(`type __VLS_WithTemplateSlots<T, S> = T & { new(): {\n`, `$slots: S;\n`); | ||
codes.push(`type __VLS_WithTemplateSlots<T, S> = T & { new(): {\n`, `${(0, shared_1.getSlotsPropertyName)(vueCompilerOptions.target)}: S;\n`); | ||
if (vueCompilerOptions.jsxSlots) { | ||
@@ -139,5 +137,5 @@ usedHelperTypes.PropsChildren = true; | ||
function generateSrc() { | ||
if (!sfc.script?.src) | ||
if (!script?.src) | ||
return; | ||
let src = sfc.script.src; | ||
let src = script.src; | ||
if (src.endsWith('.d.ts')) | ||
@@ -155,6 +153,6 @@ src = src.substring(0, src.length - '.d.ts'.length); | ||
'script', | ||
[sfc.script.srcOffset - 1, sfc.script.srcOffset + sfc.script.src.length + 1], | ||
[script.srcOffset - 1, script.srcOffset + script.src.length + 1], | ||
{ | ||
...language_core_1.FileRangeCapabilities.full, | ||
rename: src === sfc.script.src ? true : { | ||
rename: src === script.src ? true : { | ||
normalize: undefined, | ||
@@ -166,9 +164,9 @@ apply(newName) { | ||
} | ||
if (sfc.script?.src?.endsWith('.d.ts')) { | ||
if (script?.src?.endsWith('.d.ts')) { | ||
newName = newName + '.d.ts'; | ||
} | ||
else if (sfc.script?.src?.endsWith('.ts')) { | ||
else if (script?.src?.endsWith('.ts')) { | ||
newName = newName + '.ts'; | ||
} | ||
else if (sfc.script?.src?.endsWith('.tsx')) { | ||
else if (script?.src?.endsWith('.tsx')) { | ||
newName = newName + '.tsx'; | ||
@@ -185,5 +183,5 @@ } | ||
function generateScriptContentBeforeExportDefault() { | ||
if (!sfc.script) | ||
if (!script) | ||
return; | ||
if (!!sfc.scriptSetup && scriptRanges?.exportDefault) { | ||
if (!!scriptSetup && scriptRanges?.exportDefault) { | ||
addVirtualCode('script', 0, scriptRanges.exportDefault.expression.start); | ||
@@ -194,3 +192,3 @@ } | ||
if (scriptRanges?.exportDefault) { | ||
isExportRawObject = sfc.script.content.substring(scriptRanges.exportDefault.expression.start, scriptRanges.exportDefault.expression.end).startsWith('{'); | ||
isExportRawObject = script.content.substring(scriptRanges.exportDefault.expression.start, scriptRanges.exportDefault.expression.end).startsWith('{'); | ||
} | ||
@@ -221,6 +219,6 @@ if (isExportRawObject && vueCompilerOptions.optionsWrapper.length === 2 && scriptRanges?.exportDefault) { | ||
codes.push(vueCompilerOptions.optionsWrapper[1]); | ||
addVirtualCode('script', scriptRanges.exportDefault.expression.end, sfc.script.content.length); | ||
addVirtualCode('script', scriptRanges.exportDefault.expression.end, script.content.length); | ||
} | ||
else { | ||
addVirtualCode('script', 0, sfc.script.content.length); | ||
addVirtualCode('script', 0, script.content.length); | ||
} | ||
@@ -230,10 +228,10 @@ } | ||
function generateScriptContentAfterExportDefault() { | ||
if (!sfc.script) | ||
if (!script) | ||
return; | ||
if (!!sfc.scriptSetup && scriptRanges?.exportDefault) { | ||
addVirtualCode('script', scriptRanges.exportDefault.end, sfc.script.content.length); | ||
if (!!scriptSetup && scriptRanges?.exportDefault) { | ||
addVirtualCode('script', scriptRanges.exportDefault.end, script.content.length); | ||
} | ||
} | ||
function generateScriptSetupImports() { | ||
if (!sfc.scriptSetup) | ||
if (!scriptSetup) | ||
return; | ||
@@ -243,3 +241,3 @@ if (!scriptSetupRanges) | ||
codes.push([ | ||
sfc.scriptSetup.content.substring(0, Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset)) + '\n', | ||
scriptSetup.content.substring(0, Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset)) + '\n', | ||
'scriptSetup', | ||
@@ -251,3 +249,3 @@ 0, | ||
function generateExportDefaultEndMapping() { | ||
if (!sfc.scriptSetup) { | ||
if (!scriptSetup) { | ||
return; | ||
@@ -259,3 +257,3 @@ } | ||
'scriptSetup', | ||
sfc.scriptSetup.content.length, | ||
scriptSetup.content.length, | ||
{ diagnostic: true }, | ||
@@ -266,3 +264,3 @@ ]); | ||
function generateScriptSetupAndTemplate() { | ||
if (!sfc.scriptSetup || !scriptSetupRanges) { | ||
if (!scriptSetup || !scriptSetupRanges) { | ||
return; | ||
@@ -272,3 +270,3 @@ } | ||
let scriptSetupGeneratedOffset; | ||
if (sfc.scriptSetup.generic) { | ||
if (scriptSetup.generic) { | ||
if (!scriptRanges?.exportDefault) { | ||
@@ -279,8 +277,8 @@ codes.push('export default '); | ||
codes.push([ | ||
sfc.scriptSetup.generic, | ||
sfc.scriptSetup.name, | ||
sfc.scriptSetup.genericOffset, | ||
scriptSetup.generic, | ||
scriptSetup.name, | ||
scriptSetup.genericOffset, | ||
language_core_1.FileRangeCapabilities.full, | ||
]); | ||
if (!sfc.scriptSetup.generic.endsWith(',')) { | ||
if (!scriptSetup.generic.endsWith(',')) { | ||
codes.push(`,`); | ||
@@ -312,3 +310,3 @@ } | ||
if (defineProp.name) { | ||
codes.push(sfc.scriptSetup.content.substring(defineProp.name.start, defineProp.name.end)); | ||
codes.push(scriptSetup.content.substring(defineProp.name.start, defineProp.name.end)); | ||
} | ||
@@ -319,3 +317,3 @@ else { | ||
codes.push(`: `); | ||
codes.push(sfc.scriptSetup.content.substring(defineProp.defaultValue.start, defineProp.defaultValue.end)); | ||
codes.push(scriptSetup.content.substring(defineProp.defaultValue.start, defineProp.defaultValue.end)); | ||
codes.push(`,\n`); | ||
@@ -336,3 +334,3 @@ } | ||
if (defineProp.name) { | ||
propName = sfc.scriptSetup.content.substring(defineProp.name.start, defineProp.name.end); | ||
propName = scriptSetup.content.substring(defineProp.name.start, defineProp.name.end); | ||
const propMirrorStart = muggle.getLength(codes); | ||
@@ -343,3 +341,3 @@ definePropMirrors[propName] = [propMirrorStart, propMirrorStart + propName.length]; | ||
if (defineProp.type) { | ||
codes.push(sfc.scriptSetup.content.substring(defineProp.type.start, defineProp.type.end)); | ||
codes.push(scriptSetup.content.substring(defineProp.type.start, defineProp.type.end)); | ||
} | ||
@@ -373,3 +371,3 @@ else if (defineProp.defaultValue) { | ||
codes.push('return {} as {\n'); | ||
codes.push(`props: __VLS_Prettify<Omit<typeof __VLS_fnPropsDefineComponent & typeof __VLS_fnPropsTypeOnly, keyof typeof __VLS_defaultProps>> & typeof __VLS_fnPropsSlots & typeof __VLS_defaultProps,\n`); | ||
codes.push(`props: __VLS_Prettify<__VLS_OmitKeepDiscriminatedUnion<typeof __VLS_fnPropsDefineComponent & typeof __VLS_fnPropsTypeOnly, keyof typeof __VLS_defaultProps>> & typeof __VLS_fnPropsSlots & typeof __VLS_defaultProps,\n`); | ||
codes.push(`expose(exposed: import('${vueCompilerOptions.lib}').ShallowUnwrapRef<${scriptSetupRanges.expose.define ? 'typeof __VLS_exposed' : '{}'}>): void,\n`); | ||
@@ -383,3 +381,3 @@ codes.push('attrs: any,\n'); | ||
} | ||
else if (!sfc.script) { | ||
else if (!script) { | ||
// no script block, generate script setup code at root | ||
@@ -402,3 +400,3 @@ scriptSetupGeneratedOffset = generateSetupFunction(false, 'export', definePropMirrors); | ||
} | ||
const propName = sfc.scriptSetup.content.substring(defineProp.name.start, defineProp.name.end); | ||
const propName = scriptSetup.content.substring(defineProp.name.start, defineProp.name.end); | ||
const propMirror = definePropMirrors[propName]; | ||
@@ -419,7 +417,7 @@ if (propMirror) { | ||
function generateSetupFunction(functional, mode, definePropMirrors) { | ||
if (!scriptSetupRanges || !sfc.scriptSetup) { | ||
if (!scriptSetupRanges || !scriptSetup) { | ||
return; | ||
} | ||
const definePropProposalA = sfc.scriptSetup.content.trimStart().startsWith('// @experimentalDefinePropProposal=kevinEdition') || vueCompilerOptions.experimentalDefinePropProposal === 'kevinEdition'; | ||
const definePropProposalB = sfc.scriptSetup.content.trimStart().startsWith('// @experimentalDefinePropProposal=johnsonEdition') || vueCompilerOptions.experimentalDefinePropProposal === 'johnsonEdition'; | ||
const definePropProposalA = scriptSetup.content.trimStart().startsWith('// @experimentalDefinePropProposal=kevinEdition') || vueCompilerOptions.experimentalDefinePropProposal === 'kevinEdition'; | ||
const definePropProposalB = scriptSetup.content.trimStart().startsWith('// @experimentalDefinePropProposal=johnsonEdition') || vueCompilerOptions.experimentalDefinePropProposal === 'johnsonEdition'; | ||
if (vueCompilerOptions.target >= 3.3) { | ||
@@ -522,3 +520,3 @@ codes.push('const { '); | ||
else if (defineProp.name) { | ||
propName = sfc.scriptSetup.content.substring(defineProp.name.start, defineProp.name.end); | ||
propName = scriptSetup.content.substring(defineProp.name.start, defineProp.name.end); | ||
const start = muggle.getLength(codes); | ||
@@ -537,3 +535,3 @@ definePropMirrors[propName] = [start, start + propName.length]; | ||
else if (defineProp.type) { | ||
type = sfc.scriptSetup.content.substring(defineProp.type.start, defineProp.type.end); | ||
type = scriptSetup.content.substring(defineProp.type.start, defineProp.type.end); | ||
} | ||
@@ -594,13 +592,16 @@ if (defineProp.required) { | ||
if (scriptSetupRanges && !bypassDefineComponent) { | ||
if (scriptSetupRanges.props.define?.arg || scriptSetupRanges.props.define?.typeArg || (!functional && scriptSetupRanges.defineProp.length)) { | ||
codes.push(`props: {\n`); | ||
if (scriptSetupRanges.props.define?.arg) { | ||
codes.push('...'); | ||
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.props.define.arg.start, scriptSetupRanges.props.define.arg.end); | ||
codes.push(',\n'); | ||
} | ||
if (scriptSetupRanges.props.define?.typeArg) { | ||
const ranges = scriptSetupRanges; | ||
const propsCodegens = []; | ||
if (ranges.props.define?.arg) { | ||
const arg = ranges.props.define.arg; | ||
propsCodegens.push(() => { | ||
addExtraReferenceVirtualCode('scriptSetup', arg.start, arg.end); | ||
}); | ||
} | ||
if (ranges.props.define?.typeArg) { | ||
const typeArg = ranges.props.define.typeArg; | ||
propsCodegens.push(() => { | ||
usedHelperTypes.DefinePropsToOptions = true; | ||
codes.push('...{} as '); | ||
if (scriptSetupRanges.props.withDefaults?.arg) { | ||
codes.push(`{} as `); | ||
if (ranges.props.withDefaults?.arg) { | ||
usedHelperTypes.MergePropDefaults = true; | ||
@@ -614,18 +615,34 @@ codes.push(`__VLS_WithDefaults<`); | ||
else { | ||
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.props.define.typeArg.start, scriptSetupRanges.props.define.typeArg.end); | ||
addExtraReferenceVirtualCode('scriptSetup', typeArg.start, typeArg.end); | ||
} | ||
codes.push(`>`); | ||
if (scriptSetupRanges.props.withDefaults?.arg) { | ||
if (ranges.props.withDefaults?.arg) { | ||
codes.push(`, typeof __VLS_withDefaultsArg`); | ||
codes.push(`>`); | ||
} | ||
}); | ||
} | ||
if (!functional && ranges.defineProp.length) { | ||
propsCodegens.push(() => { | ||
codes.push(`__VLS_propsOption_defineProp`); | ||
}); | ||
} | ||
if (propsCodegens.length === 1) { | ||
codes.push(`props: `); | ||
for (const generate of propsCodegens) { | ||
generate(); | ||
} | ||
codes.push(`,\n`); | ||
} | ||
else if (propsCodegens.length >= 2) { | ||
codes.push(`props: {\n`); | ||
for (const generate of propsCodegens) { | ||
codes.push('...'); | ||
generate(); | ||
codes.push(',\n'); | ||
} | ||
if (!functional && scriptSetupRanges.defineProp.length) { | ||
codes.push(`...__VLS_propsOption_defineProp,\n`); | ||
} | ||
codes.push(`},\n`); | ||
} | ||
if (scriptSetupRanges.emits.define) { | ||
codes.push(`emits: ({} as __VLS_NormalizeEmits<typeof `, scriptSetupRanges.emits.name ?? '__VLS_emit', `>),\n`); | ||
if (ranges.emits.define) { | ||
codes.push(`emits: ({} as __VLS_NormalizeEmits<typeof `, ranges.emits.name ?? '__VLS_emit', `>),\n`); | ||
} | ||
@@ -671,3 +688,3 @@ } | ||
function generateComponentForTemplateUsage(functional, cssIds) { | ||
if (sfc.scriptSetup && scriptSetupRanges) { | ||
if (scriptSetup && scriptSetupRanges) { | ||
codes.push(`const __VLS_internalComponent = (await import('${vueCompilerOptions.lib}')).defineComponent({\n`); | ||
@@ -681,5 +698,5 @@ generateComponentOptions(functional); | ||
for (const [content, bindings] of [ | ||
[sfc.scriptSetup.content, scriptSetupRanges.bindings], | ||
scriptRanges && sfc.script | ||
? [sfc.script.content, scriptRanges.bindings] | ||
[scriptSetup.content, scriptSetupRanges.bindings], | ||
scriptRanges && script | ||
? [script.content, scriptRanges.bindings] | ||
: ['', []], | ||
@@ -714,3 +731,3 @@ ]) { | ||
} | ||
else if (sfc.script) { | ||
else if (script) { | ||
codes.push(`let __VLS_internalComponent!: typeof import('./${path_1.posix.basename(fileName)}')['default'];\n`); | ||
@@ -725,6 +742,6 @@ } | ||
codes.push(`const __VLS_componentsOption = `); | ||
if (sfc.script && scriptRanges?.exportDefault?.componentsOption) { | ||
if (script && scriptRanges?.exportDefault?.componentsOption) { | ||
const componentsOption = scriptRanges.exportDefault.componentsOption; | ||
codes.push([ | ||
sfc.script.content.substring(componentsOption.start, componentsOption.end), | ||
script.content.substring(componentsOption.start, componentsOption.end), | ||
'script', | ||
@@ -745,9 +762,9 @@ componentsOption.start, | ||
codes.push(`\n`); | ||
if (sfc.script && scriptRanges?.exportDefault?.nameOption) { | ||
if (script && scriptRanges?.exportDefault?.nameOption) { | ||
const nameOption = scriptRanges.exportDefault.nameOption; | ||
codes.push(`const __VLS_name = `); | ||
codes.push(`${sfc.script.content.substring(nameOption.start, nameOption.end)} as const`); | ||
codes.push(`${script.content.substring(nameOption.start, nameOption.end)} as const`); | ||
codes.push(`;\n`); | ||
} | ||
else if (sfc.scriptSetup) { | ||
else if (scriptSetup) { | ||
codes.push(`let __VLS_name!: '${path_1.posix.basename(fileName.substring(0, fileName.lastIndexOf('.')))}';\n`); | ||
@@ -764,11 +781,11 @@ } | ||
/* CSS Module */ | ||
for (let i = 0; i < _sfc.styles.length; i++) { | ||
const style = _sfc.styles[i]; | ||
if (!style.module) | ||
continue; | ||
codes.push(`${style.module}: Record<string, string> & __VLS_Prettify<{}`); | ||
for (const className of style.classNames) { | ||
generateCssClassProperty(i, className.text.substring(1), { start: className.offset, end: className.offset + className.text.length }, 'string', false, true); | ||
for (let i = 0; i < styles.length; i++) { | ||
const style = styles[i]; | ||
if (style.module) { | ||
codes.push(`${style.module}: Record<string, string> & __VLS_Prettify<{}`); | ||
for (const className of style.classNames) { | ||
generateCssClassProperty(i, className.text.substring(1), { start: className.offset, end: className.offset + className.text.length }, 'string', false, true); | ||
} | ||
codes.push('>;\n'); | ||
} | ||
codes.push('>;\n'); | ||
} | ||
@@ -785,8 +802,9 @@ codes.push(`};\n`); | ||
codes.push('type __VLS_StyleScopedClasses = {}'); | ||
for (let i = 0; i < _sfc.styles.length; i++) { | ||
const style = _sfc.styles[i]; | ||
if (!style.scoped && vueCompilerOptions.experimentalResolveStyleCssClasses !== 'always') | ||
continue; | ||
for (const className of style.classNames) { | ||
generateCssClassProperty(i, className.text.substring(1), { start: className.offset, end: className.offset + className.text.length }, 'boolean', true, !style.module); | ||
for (let i = 0; i < styles.length; i++) { | ||
const style = styles[i]; | ||
const option = vueCompilerOptions.experimentalResolveStyleCssClasses; | ||
if ((option === 'always' || option === 'scoped') && style.scoped) { | ||
for (const className of style.classNames) { | ||
generateCssClassProperty(i, className.text.substring(1), { start: className.offset, end: className.offset + className.text.length }, 'boolean', true, !style.module); | ||
} | ||
} | ||
@@ -854,3 +872,3 @@ } | ||
const identifiers = new Set(); | ||
for (const style of _sfc.styles) { | ||
for (const style of styles) { | ||
for (const cssBind of style.cssVars) { | ||
@@ -901,3 +919,3 @@ (0, transform_1.walkInterpolationFragment)(ts, cssBind.text, ts.createSourceFile('/a.txt', cssBind.text, ts.ScriptTarget.ESNext), (frag, fragOffset, onlyForErrorMapping) => { | ||
codes.push([ | ||
sfc[vueTag].content.substring(start, end), | ||
(vueTag === 'script' ? script : scriptSetup).content.substring(start, end), | ||
vueTag, | ||
@@ -912,3 +930,3 @@ start, | ||
codes.push([ | ||
sfc[vueTag].content.substring(start, end), | ||
(vueTag === 'script' ? script : scriptSetup).content.substring(start, end), | ||
vueTag, | ||
@@ -915,0 +933,0 @@ start, |
@@ -8,3 +8,3 @@ import { FileRangeCapabilities } from '@volar/language-core'; | ||
type Code = Segment<FileRangeCapabilities>; | ||
export declare function generate(ts: typeof import('typescript/lib/tsserverlibrary'), compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions, sourceTemplate: string, sourceLang: string, sfc: Sfc, hasScriptSetupSlots: boolean, slotsAssignName: string | undefined, propsAssignName: string | undefined, codegenStack: boolean): { | ||
export declare function generate(ts: typeof import('typescript/lib/tsserverlibrary'), compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions, template: NonNullable<Sfc['template']>, shouldGenerateScopedClasses: boolean, stylesScopedClasses: Set<string>, hasScriptSetupSlots: boolean, slotsAssignName: string | undefined, propsAssignName: string | undefined, codegenStack: boolean): { | ||
codes: Code[]; | ||
@@ -11,0 +11,0 @@ codeStacks: muggle.StackNode[]; |
@@ -5,3 +5,3 @@ export * from './generators/template'; | ||
export * from './plugins'; | ||
export * from './sourceFile'; | ||
export * from './virtualFile/vueFile'; | ||
export * from './types'; | ||
@@ -8,0 +8,0 @@ export * from './utils/ts'; |
@@ -34,3 +34,3 @@ "use strict"; | ||
__exportStar(require("./plugins"), exports); | ||
__exportStar(require("./sourceFile"), exports); | ||
__exportStar(require("./virtualFile/vueFile"), exports); | ||
__exportStar(require("./types"), exports); | ||
@@ -37,0 +37,0 @@ __exportStar(require("./utils/ts"), exports); |
import type { Language } from '@volar/language-core'; | ||
import { VueFile } from './sourceFile'; | ||
import { VueFile } from './virtualFile/vueFile'; | ||
import { VueCompilerOptions } from './types'; | ||
@@ -4,0 +4,0 @@ import type * as ts from 'typescript/lib/tsserverlibrary'; |
@@ -29,3 +29,3 @@ "use strict"; | ||
const plugins_1 = require("./plugins"); | ||
const sourceFile_1 = require("./sourceFile"); | ||
const vueFile_1 = require("./virtualFile/vueFile"); | ||
const sharedTypes = __importStar(require("./utils/globalTypes")); | ||
@@ -77,3 +77,3 @@ const ts_1 = require("./utils/ts"); | ||
} | ||
const vueFile = new sourceFile_1.VueFile(fileName, snapshot, vueCompilerOptions, plugins, ts, codegenStack); | ||
const vueFile = new vueFile_1.VueFile(fileName, snapshot, vueCompilerOptions, plugins, ts, codegenStack); | ||
fileRegistry.set(fileName, vueFile); | ||
@@ -80,0 +80,0 @@ return vueFile; |
@@ -23,4 +23,4 @@ import type * as ts from 'typescript/lib/tsserverlibrary'; | ||
getEmbeddedFileNames?(fileName: string, sfc: import("./types").Sfc): string[]; | ||
resolveEmbeddedFile?(fileName: string, sfc: import("./types").Sfc, embeddedFile: import("./sourceFile").VueEmbeddedFile): void; | ||
resolveEmbeddedFile?(fileName: string, sfc: import("./types").Sfc, embeddedFile: import("./virtualFile/embeddedFile").VueEmbeddedFile): void; | ||
}[]; | ||
//# sourceMappingURL=plugins.d.ts.map |
import { Sfc, VueLanguagePlugin } from '../types'; | ||
import * as muggle from 'muggle-string'; | ||
export declare const tsCodegen: WeakMap<Sfc, { | ||
scriptRanges: import("@vue/reactivity").ComputedRef<{ | ||
scriptRanges: () => { | ||
exportDefault: (import("../types").TextRange & { | ||
@@ -14,4 +14,4 @@ expression: import("../types").TextRange; | ||
bindings: import("../types").TextRange[]; | ||
} | undefined>; | ||
scriptSetupRanges: import("@vue/reactivity").ComputedRef<{ | ||
} | undefined; | ||
scriptSetupRanges: () => { | ||
leadingCommentEndOffset: number; | ||
@@ -53,10 +53,10 @@ importSectionEndOffset: number; | ||
}[]; | ||
} | undefined>; | ||
lang: import("@vue/reactivity").ComputedRef<string>; | ||
generatedScript: import("@vue/reactivity").ComputedRef<{ | ||
} | undefined; | ||
lang: () => string; | ||
generatedScript: () => { | ||
codes: muggle.Segment<import("@volar/language-core").FileRangeCapabilities>[]; | ||
codeStacks: muggle.StackNode[]; | ||
mirrorBehaviorMappings: import("@volar/source-map").Mapping<[import("@volar/language-core").MirrorBehaviorCapabilities, import("@volar/language-core").MirrorBehaviorCapabilities]>[]; | ||
}>; | ||
generatedTemplate: import("@vue/reactivity").ComputedRef<{ | ||
}; | ||
generatedTemplate: () => { | ||
codes: (string | [string, string | undefined, number | [number, number], import("@volar/language-core").FileRangeCapabilities])[]; | ||
@@ -71,3 +71,3 @@ codeStacks: muggle.StackNode[]; | ||
hasSlot: boolean; | ||
} | undefined>; | ||
} | undefined; | ||
}>; | ||
@@ -74,0 +74,0 @@ declare const plugin: VueLanguagePlugin; |
@@ -27,3 +27,3 @@ "use strict"; | ||
exports.tsCodegen = void 0; | ||
const reactivity_1 = require("@vue/reactivity"); | ||
const computeds_1 = require("computeds"); | ||
const script_1 = require("../generators/script"); | ||
@@ -48,4 +48,4 @@ const template_1 = require("../generators/template"); | ||
const fileNames = []; | ||
if (['js', 'ts', 'jsx', 'tsx'].includes(tsx.lang.value)) { | ||
fileNames.push(fileName + '.' + tsx.lang.value); | ||
if (['js', 'ts', 'jsx', 'tsx'].includes(tsx.lang())) { | ||
fileNames.push(fileName + '.' + tsx.lang()); | ||
} | ||
@@ -61,3 +61,3 @@ if (sfc.template) { | ||
const suffix = embeddedFile.fileName.replace(fileName, ''); | ||
if (suffix === '.' + _tsx.lang.value) { | ||
if (suffix === '.' + _tsx.lang()) { | ||
embeddedFile.kind = language_core_1.FileKind.TypeScriptHostFile; | ||
@@ -70,3 +70,3 @@ embeddedFile.capabilities = { | ||
}; | ||
const tsx = _tsx.generatedScript.value; | ||
const tsx = _tsx.generatedScript(); | ||
if (tsx) { | ||
@@ -89,4 +89,7 @@ const [content, contentStacks] = ctx.codegenStack ? muggle.track([...tsx.codes], [...tsx.codeStacks]) : [[...tsx.codes], [...tsx.codeStacks]]; | ||
}; | ||
if (_tsx.generatedTemplate.value) { | ||
const [content, contentStacks] = ctx.codegenStack ? muggle.track([..._tsx.generatedTemplate.value.formatCodes], [..._tsx.generatedTemplate.value.formatCodeStacks]) : [[..._tsx.generatedTemplate.value.formatCodes], [..._tsx.generatedTemplate.value.formatCodeStacks]]; | ||
const template = _tsx.generatedTemplate(); | ||
if (template) { | ||
const [content, contentStacks] = ctx.codegenStack | ||
? muggle.track([...template.formatCodes], [...template.formatCodeStacks]) | ||
: [[...template.formatCodes], [...template.formatCodeStacks]]; | ||
embeddedFile.content = content; | ||
@@ -111,4 +114,7 @@ embeddedFile.contentStacks = contentStacks; | ||
embeddedFile.parentFileName = fileName + '.template.' + sfc.template?.lang; | ||
if (_tsx.generatedTemplate.value) { | ||
const [content, contentStacks] = ctx.codegenStack ? muggle.track([..._tsx.generatedTemplate.value.cssCodes], [..._tsx.generatedTemplate.value.cssCodeStacks]) : [[..._tsx.generatedTemplate.value.cssCodes], [..._tsx.generatedTemplate.value.cssCodeStacks]]; | ||
const template = _tsx.generatedTemplate(); | ||
if (template) { | ||
const [content, contentStacks] = ctx.codegenStack | ||
? muggle.track([...template.cssCodes], [...template.cssCodeStacks]) | ||
: [[...template.cssCodes], [...template.cssCodeStacks]]; | ||
embeddedFile.content = content; | ||
@@ -132,3 +138,3 @@ embeddedFile.contentStacks = contentStacks; | ||
const ts = modules.typescript; | ||
const lang = (0, reactivity_1.computed)(() => { | ||
const lang = (0, computeds_1.computed)(() => { | ||
return !_sfc.script && !_sfc.scriptSetup ? 'ts' | ||
@@ -139,24 +145,38 @@ : _sfc.scriptSetup && _sfc.scriptSetup.lang !== 'js' ? _sfc.scriptSetup.lang | ||
}); | ||
const scriptRanges = (0, reactivity_1.computed)(() => _sfc.scriptAst | ||
? (0, scriptRanges_1.parseScriptRanges)(ts, _sfc.scriptAst, !!_sfc.scriptSetup, false) | ||
const scriptRanges = (0, computeds_1.computed)(() => _sfc.script | ||
? (0, scriptRanges_1.parseScriptRanges)(ts, _sfc.script.ast, !!_sfc.scriptSetup, false) | ||
: undefined); | ||
const scriptSetupRanges = (0, reactivity_1.computed)(() => _sfc.scriptSetupAst | ||
? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, _sfc.scriptSetupAst, vueCompilerOptions) | ||
const scriptSetupRanges = (0, computeds_1.computed)(() => _sfc.scriptSetup | ||
? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, _sfc.scriptSetup.ast, vueCompilerOptions) | ||
: undefined); | ||
const generatedTemplate = (0, reactivity_1.computed)(() => { | ||
if (!_sfc.templateAst) | ||
const shouldGenerateScopedClasses = (0, computeds_1.computed)(() => { | ||
const option = vueCompilerOptions.experimentalResolveStyleCssClasses; | ||
return _sfc.styles.some(s => { | ||
return option === 'always' || (option === 'scoped' && s.scoped); | ||
}); | ||
}); | ||
const stylesScopedClasses = (0, computeds_1.computedSet)(() => { | ||
const classes = new Set(); | ||
if (!shouldGenerateScopedClasses()) { | ||
return classes; | ||
} | ||
for (const style of _sfc.styles) { | ||
const option = vueCompilerOptions.experimentalResolveStyleCssClasses; | ||
if ((option === 'always' || option === 'scoped') && style.scoped) { | ||
for (const className of style.classNames) { | ||
classes.add(className.text.substring(1)); | ||
} | ||
} | ||
} | ||
return classes; | ||
}); | ||
const generatedTemplate = (0, computeds_1.computed)(() => { | ||
if (!_sfc.template) | ||
return; | ||
return (0, template_1.generate)(ts, compilerOptions, vueCompilerOptions, _sfc.template?.content ?? '', _sfc.template?.lang ?? 'html', _sfc, hasScriptSetupSlots.value, slotsAssignName.value, propsAssignName.value, codegenStack); | ||
return (0, template_1.generate)(ts, compilerOptions, vueCompilerOptions, _sfc.template, shouldGenerateScopedClasses(), stylesScopedClasses(), hasScriptSetupSlots(), slotsAssignName(), propsAssignName(), codegenStack); | ||
}); | ||
//#region remove when https://github.com/vuejs/core/pull/5912 merged | ||
const hasScriptSetupSlots = (0, reactivity_1.shallowRef)(false); | ||
const slotsAssignName = (0, reactivity_1.shallowRef)(); | ||
const propsAssignName = (0, reactivity_1.shallowRef)(); | ||
//#endregion | ||
const generatedScript = (0, reactivity_1.computed)(() => { | ||
hasScriptSetupSlots.value = !!scriptSetupRanges.value?.slots.define; | ||
slotsAssignName.value = scriptSetupRanges.value?.slots.name; | ||
propsAssignName.value = scriptSetupRanges.value?.props.name; | ||
return (0, script_1.generate)(ts, fileName, _sfc, lang.value, scriptRanges.value, scriptSetupRanges.value, generatedTemplate.value, compilerOptions, vueCompilerOptions, codegenStack); | ||
}); | ||
const hasScriptSetupSlots = (0, computeds_1.computed)(() => !!scriptSetupRanges()?.slots.define); | ||
const slotsAssignName = (0, computeds_1.computed)(() => scriptSetupRanges()?.slots.name); | ||
const propsAssignName = (0, computeds_1.computed)(() => scriptSetupRanges()?.props.name); | ||
const generatedScript = (0, computeds_1.computed)(() => (0, script_1.generate)(ts, fileName, _sfc.script, _sfc.scriptSetup, _sfc.styles, lang(), scriptRanges(), scriptSetupRanges(), generatedTemplate(), compilerOptions, vueCompilerOptions, codegenStack)); | ||
return { | ||
@@ -163,0 +183,0 @@ scriptRanges, |
import type * as CompilerDOM from '@vue/compiler-dom'; | ||
import type { SFCParseResult } from '@vue/compiler-sfc'; | ||
import type * as ts from 'typescript/lib/tsserverlibrary'; | ||
import type { VueEmbeddedFile } from './sourceFile'; | ||
import type { VueEmbeddedFile } from './virtualFile/embeddedFile'; | ||
export type { SFCParseResult } from '@vue/compiler-sfc'; | ||
@@ -78,12 +78,18 @@ export type RawVueCompilerOptions = Partial<Omit<VueCompilerOptions, 'target' | 'plugins'>> & { | ||
export interface Sfc { | ||
template: SfcBlock | null; | ||
template: SfcBlock & { | ||
ast: CompilerDOM.RootNode | undefined; | ||
errors: CompilerDOM.CompilerError[]; | ||
warnings: CompilerDOM.CompilerError[]; | ||
} | undefined; | ||
script: (SfcBlock & { | ||
src: string | undefined; | ||
srcOffset: number; | ||
}) | null; | ||
ast: ts.SourceFile; | ||
}) | undefined; | ||
scriptSetup: SfcBlock & { | ||
generic: string | undefined; | ||
genericOffset: number; | ||
} | null; | ||
styles: (SfcBlock & { | ||
ast: ts.SourceFile; | ||
} | undefined; | ||
styles: readonly (SfcBlock & { | ||
module: string | undefined; | ||
@@ -100,7 +106,16 @@ scoped: boolean; | ||
})[]; | ||
customBlocks: (SfcBlock & { | ||
customBlocks: readonly (SfcBlock & { | ||
type: string; | ||
})[]; | ||
/** | ||
* @deprecated use `template.ast` instead | ||
*/ | ||
templateAst: CompilerDOM.RootNode | undefined; | ||
/** | ||
* @deprecated use `script.ast` instead | ||
*/ | ||
scriptAst: ts.SourceFile | undefined; | ||
/** | ||
* @deprecated use `scriptSetup.ast` instead | ||
*/ | ||
scriptSetupAst: ts.SourceFile | undefined; | ||
@@ -107,0 +122,0 @@ } |
@@ -18,2 +18,7 @@ "use strict"; | ||
type __VLS_OmitKeepDiscriminatedUnion<T, K extends keyof any> = | ||
T extends any | ||
? Pick<T, Exclude<keyof T, K>> | ||
: never; | ||
type __VLS_GlobalComponents = | ||
@@ -31,2 +36,4 @@ __VLS_PickNotAny<import('vue').GlobalComponents, {}> | ||
declare const __VLS_intrinsicElements: __VLS_IntrinsicElements; | ||
// v-for | ||
@@ -33,0 +40,0 @@ declare function __VLS_getVForSourceType(source: number): [number, number, number][]; |
@@ -8,3 +8,3 @@ import type * as ts from 'typescript/lib/tsserverlibrary'; | ||
}[]; | ||
export declare function colletVars(ts: typeof import('typescript/lib/tsserverlibrary'), node: ts.Node, result: string[]): void; | ||
export declare function collectVars(ts: typeof import('typescript/lib/tsserverlibrary'), node: ts.Node, result: string[]): void; | ||
//# sourceMappingURL=transform.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.colletVars = exports.walkInterpolationFragment = void 0; | ||
exports.collectVars = exports.walkInterpolationFragment = void 0; | ||
const shared_1 = require("@vue/shared"); | ||
@@ -102,3 +102,3 @@ function walkInterpolationFragment(ts, code, ast, cb, localVars, identifiers, vueOptions) { | ||
else if (ts.isVariableDeclaration(node)) { | ||
colletVars(ts, node.name, blockVars); | ||
collectVars(ts, node.name, blockVars); | ||
for (const varName of blockVars) { | ||
@@ -113,3 +113,3 @@ localVars.set(varName, (localVars.get(varName) ?? 0) + 1); | ||
for (const param of node.parameters) { | ||
colletVars(ts, param.name, functionArgs); | ||
collectVars(ts, param.name, functionArgs); | ||
if (param.type) { | ||
@@ -176,3 +176,3 @@ walkIdentifiers(ts, param.type, cb, localVars, blockVars, false); | ||
} | ||
function colletVars(ts, node, result) { | ||
function collectVars(ts, node, result) { | ||
if (ts.isIdentifier(node)) { | ||
@@ -183,3 +183,3 @@ result.push(node.text); | ||
for (const el of node.elements) { | ||
colletVars(ts, el.name, result); | ||
collectVars(ts, el.name, result); | ||
} | ||
@@ -190,3 +190,3 @@ } | ||
if (ts.isBindingElement(el)) { | ||
colletVars(ts, el.name, result); | ||
collectVars(ts, el.name, result); | ||
} | ||
@@ -196,6 +196,6 @@ } | ||
else { | ||
node.forEachChild(node => colletVars(ts, node, result)); | ||
node.forEachChild(node => collectVars(ts, node, result)); | ||
} | ||
} | ||
exports.colletVars = colletVars; | ||
exports.collectVars = collectVars; | ||
//# sourceMappingURL=transform.js.map |
{ | ||
"name": "@vue/language-core", | ||
"version": "1.8.19", | ||
"version": "1.8.20", | ||
"main": "out/index.js", | ||
@@ -19,4 +19,4 @@ "license": "MIT", | ||
"@vue/compiler-dom": "^3.3.0", | ||
"@vue/reactivity": "^3.3.0", | ||
"@vue/shared": "^3.3.0", | ||
"computeds": "^0.0.1", | ||
"minimatch": "^9.0.3", | ||
@@ -38,3 +38,3 @@ "muggle-string": "^0.3.1", | ||
}, | ||
"gitHead": "2e17f3c9cfa827c71e1ed07331730b3ee2596b76" | ||
"gitHead": "c5f0a7f2bec182880504e250fb3c8615a21ebd1e" | ||
} |
Sorry, the diff of this file is too big to display
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
261151
64
5659
+ Addedcomputeds@^0.0.1
+ Addedcomputeds@0.0.1(transitive)
- Removed@vue/reactivity@^3.3.0
- Removed@vue/reactivity@3.5.12(transitive)