@vue/language-core
Advanced tools
Comparing version 2.0.19 to 2.0.20
@@ -43,3 +43,3 @@ "use strict"; | ||
if (options.sfc.scriptSetup && options.scriptSetupRanges) { | ||
yield (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges); | ||
yield* (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges); | ||
if (exportDefault) { | ||
@@ -103,3 +103,3 @@ yield (0, common_1.generateSfcBlockSection)(options.sfc.script, 0, exportDefault.expression.start, exports.codeFeatures.all); | ||
else if (options.sfc.scriptSetup && options.scriptSetupRanges) { | ||
yield (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges); | ||
yield* (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges); | ||
yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges); | ||
@@ -106,0 +106,0 @@ } |
@@ -9,3 +9,4 @@ "use strict"; | ||
if (options.sfc.scriptSetup && options.scriptSetupRanges) { | ||
yield `const __VLS_internalComponent = (await import('${options.vueCompilerOptions.lib}')).defineComponent({${common_1.newLine}`; | ||
yield `let __VLS_defineComponent!: typeof import('${options.vueCompilerOptions.lib}').defineComponent${common_1.endOfLine}`; | ||
yield `const __VLS_internalComponent = __VLS_defineComponent({${common_1.newLine}`; | ||
yield `setup() {${common_1.newLine}`; | ||
@@ -52,3 +53,3 @@ yield `return {${common_1.newLine}`; | ||
else if (options.sfc.script) { | ||
yield `const __VLS_internalComponent = (await import('./${options.fileBaseName}')).default${common_1.endOfLine}`; | ||
yield `let __VLS_internalComponent!: typeof import('./${options.fileBaseName}').default${common_1.endOfLine}`; | ||
} | ||
@@ -55,0 +56,0 @@ else { |
@@ -5,3 +5,3 @@ import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges'; | ||
import { ScriptCodegenOptions } from './index'; | ||
export declare function generateScriptSetupImports(scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Code; | ||
export declare function generateScriptSetupImports(scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>; | ||
export declare function generateScriptSetup(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>; |
@@ -8,5 +8,5 @@ "use strict"; | ||
const template_1 = require("./template"); | ||
function generateScriptSetupImports(scriptSetup, scriptSetupRanges) { | ||
return [ | ||
scriptSetup.content.substring(0, Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset)) + common_1.newLine, | ||
function* generateScriptSetupImports(scriptSetup, scriptSetupRanges) { | ||
yield [ | ||
scriptSetup.content.substring(0, Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset)), | ||
'scriptSetup', | ||
@@ -16,2 +16,3 @@ 0, | ||
]; | ||
yield common_1.newLine; | ||
} | ||
@@ -346,5 +347,5 @@ exports.generateScriptSetupImports = generateScriptSetupImports; | ||
function* generateModelEmits(options, scriptSetup, scriptSetupRanges) { | ||
yield `let __VLS_modelEmitsType!: {}`; | ||
if (scriptSetupRanges.defineProp.length) { | ||
yield ` & ReturnType<typeof import('${options.vueCompilerOptions.lib}').defineEmits<{${common_1.newLine}`; | ||
yield `const __VLS_modelEmitsType = `; | ||
if (scriptSetupRanges.defineProp.filter(p => p.isModel).length) { | ||
yield `(await import('${options.vueCompilerOptions.lib}')).defineEmits<{${common_1.newLine}`; | ||
for (const defineProp of scriptSetupRanges.defineProp) { | ||
@@ -368,6 +369,9 @@ if (!defineProp.isModel) { | ||
} | ||
yield `}>>`; | ||
yield `}>()`; | ||
} | ||
else { | ||
yield `{}`; | ||
} | ||
yield common_1.endOfLine; | ||
} | ||
//# sourceMappingURL=scriptSetup.js.map |
@@ -88,2 +88,3 @@ "use strict"; | ||
else if (!isComponentTag) { | ||
yield `// @ts-ignore${common_1.newLine}`; | ||
yield `const ${var_originalComponent} = ({} as `; | ||
@@ -95,3 +96,3 @@ for (const componentName of possibleOriginalNames) { | ||
} | ||
yield `typeof __VLS_resolvedLocalAndGlobalComponents)`; | ||
yield `typeof __VLS_resolvedLocalAndGlobalComponents)${common_1.newLine}`; | ||
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, getCanonicalComponentName(node.tag), startTagOffset, ctx.codeFeatures.verification); | ||
@@ -140,2 +141,3 @@ yield common_1.endOfLine; | ||
} | ||
yield `// @ts-ignore${common_1.newLine}`; | ||
yield `const ${var_functionalComponent} = __VLS_asFunctionalComponent(${var_originalComponent}, new ${var_originalComponent}({`; | ||
@@ -142,0 +144,0 @@ yield* (0, elementProps_1.generateElementProps)(options, ctx, node, props, false); |
@@ -39,4 +39,4 @@ "use strict"; | ||
if (argument.type === CompilerDOM.NodeTypes.JS_FUNCTION_EXPRESSION | ||
&& argument.returns.type === CompilerDOM.NodeTypes.VNODE_CALL | ||
&& argument.returns.props?.type === CompilerDOM.NodeTypes.JS_OBJECT_EXPRESSION) { | ||
&& argument.returns?.type === CompilerDOM.NodeTypes.VNODE_CALL | ||
&& argument.returns?.props?.type === CompilerDOM.NodeTypes.JS_OBJECT_EXPRESSION) { | ||
if (argument.returns.tag !== CompilerDOM.FRAGMENT) { | ||
@@ -43,0 +43,0 @@ isFragment = false; |
import { type LanguagePlugin } from '@volar/language-core'; | ||
import type * as ts from 'typescript'; | ||
import type { VueCompilerOptions, VueLanguagePlugin } from './types'; | ||
import type { VueCompilerOptions } from './types'; | ||
import { VueVirtualCode } from './virtualFile/vueFile'; | ||
export interface _Plugin extends LanguagePlugin<VueVirtualCode> { | ||
getCanonicalFileName: (fileName: string) => string; | ||
pluginContext: Parameters<VueLanguagePlugin>[0]; | ||
} | ||
export declare function createVueLanguagePlugin(ts: typeof import('typescript'), getFileName: (scriptId: string) => string, useCaseSensitiveFileNames: boolean, getProjectVersion: () => string, getScriptFileNames: () => string[] | Set<string>, compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions): _Plugin; | ||
export declare function createVueLanguagePlugin<T>(ts: typeof import('typescript'), asFileName: (scriptId: T) => string, getProjectVersion: () => string, isRootFile: (fileName: string) => boolean, compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions): LanguagePlugin<T, VueVirtualCode>; |
@@ -41,3 +41,3 @@ "use strict"; | ||
} | ||
function createVueLanguagePlugin(ts, getFileName, useCaseSensitiveFileNames, getProjectVersion, getScriptFileNames, compilerOptions, vueCompilerOptions) { | ||
function createVueLanguagePlugin(ts, asFileName, getProjectVersion, isRootFile, compilerOptions, vueCompilerOptions) { | ||
const pluginContext = { | ||
@@ -61,18 +61,12 @@ modules: { | ||
const petiteVueSfcPlugin = (0, file_html_1.default)(pluginContext); | ||
const getCanonicalFileName = useCaseSensitiveFileNames | ||
? (fileName) => fileName | ||
: (fileName) => fileName.toLowerCase(); | ||
let canonicalRootFileNames = new Set(); | ||
let canonicalRootFileNamesVersion; | ||
return { | ||
getCanonicalFileName, | ||
pluginContext, | ||
getLanguageId(scriptId) { | ||
if (vueCompilerOptions.extensions.some(ext => scriptId.endsWith(ext))) { | ||
if (vueCompilerOptions.extensions.some(ext => asFileName(scriptId).endsWith(ext))) { | ||
return 'vue'; | ||
} | ||
if (vueCompilerOptions.vitePressExtensions.some(ext => scriptId.endsWith(ext))) { | ||
if (vueCompilerOptions.vitePressExtensions.some(ext => asFileName(scriptId).endsWith(ext))) { | ||
return 'markdown'; | ||
} | ||
if (vueCompilerOptions.petiteVueExtensions.some(ext => scriptId.endsWith(ext))) { | ||
if (vueCompilerOptions.petiteVueExtensions.some(ext => asFileName(scriptId).endsWith(ext))) { | ||
return 'html'; | ||
@@ -83,13 +77,11 @@ } | ||
if (languageId === 'vue' || languageId === 'markdown' || languageId === 'html') { | ||
const fileName = getFileName(scriptId); | ||
const projectVersion = getProjectVersion(); | ||
if (projectVersion !== canonicalRootFileNamesVersion) { | ||
canonicalRootFileNames = new Set([...getScriptFileNames()].map(getCanonicalFileName)); | ||
canonicalRootFileNamesVersion = projectVersion; | ||
const fileName = asFileName(scriptId); | ||
if (!pluginContext.globalTypesHolder && getProjectVersion() !== canonicalRootFileNamesVersion) { | ||
canonicalRootFileNamesVersion = getProjectVersion(); | ||
if (isRootFile(fileName)) { | ||
pluginContext.globalTypesHolder = fileName; | ||
} | ||
} | ||
if (!pluginContext.globalTypesHolder && canonicalRootFileNames.has(getCanonicalFileName(fileName))) { | ||
pluginContext.globalTypesHolder = fileName; | ||
} | ||
const fileRegistry = getFileRegistry(pluginContext.globalTypesHolder === fileName); | ||
const code = fileRegistry.get(scriptId); | ||
const code = fileRegistry.get(fileName); | ||
if (code) { | ||
@@ -105,3 +97,3 @@ code.update(snapshot); | ||
: [vueSfcPlugin, ...basePlugins], ts); | ||
fileRegistry.set(scriptId, code); | ||
fileRegistry.set(fileName, code); | ||
return code; | ||
@@ -108,0 +100,0 @@ } |
@@ -62,4 +62,12 @@ "use strict"; | ||
function transformRange(block) { | ||
block.loc.start.offset = file2VueSourceMap.getSourceOffset(block.loc.start.offset)?.[0] ?? -1; | ||
block.loc.end.offset = file2VueSourceMap.getSourceOffset(block.loc.end.offset)?.[0] ?? -1; | ||
block.loc.start.offset = -1; | ||
block.loc.end.offset = -1; | ||
for (const [start] of file2VueSourceMap.getSourceOffsets(block.loc.start.offset)) { | ||
block.loc.start.offset = start; | ||
break; | ||
} | ||
for (const [end] of file2VueSourceMap.getSourceOffsets(block.loc.end.offset)) { | ||
block.loc.end.offset = end; | ||
break; | ||
} | ||
} | ||
@@ -66,0 +74,0 @@ } |
@@ -10,3 +10,2 @@ "use strict"; | ||
format: true, | ||
// autoInserts: true, // TODO: support vue-autoinsert-parentheses | ||
}; | ||
@@ -13,0 +12,0 @@ const formatBrackets = { |
@@ -71,3 +71,3 @@ import type { Mapping } from '@volar/language-core'; | ||
codes: Code[]; | ||
linkedCodeMappings: Mapping<any>[]; | ||
linkedCodeMappings: Mapping<unknown>[]; | ||
}; | ||
@@ -74,0 +74,0 @@ generatedTemplate: () => { |
@@ -152,3 +152,22 @@ "use strict"; | ||
const { code, snapshot } = _file(); | ||
const mappings = (0, language_core_1.buildMappings)(code.content); | ||
const mappings = (0, language_core_1.buildMappings)(code.content.map(segment => { | ||
if (typeof segment === 'string') { | ||
return segment; | ||
} | ||
const source = segment[1]; | ||
if (source === undefined) { | ||
return segment; | ||
} | ||
const block = nameToBlock()[source]; | ||
if (!block) { | ||
// console.warn('Unable to find block: ' + source); | ||
return segment; | ||
} | ||
return [ | ||
segment[0], | ||
undefined, | ||
segment[2] + block.startTagEnd, | ||
segment[3], | ||
]; | ||
})); | ||
const newMappings = []; | ||
@@ -158,12 +177,2 @@ let lastValidMapping; | ||
const mapping = mappings[i]; | ||
if (mapping.source !== undefined) { | ||
const block = nameToBlock()[mapping.source]; | ||
if (block) { | ||
mapping.sourceOffsets = mapping.sourceOffsets.map(offset => offset + block.startTagEnd); | ||
} | ||
else { | ||
// ignore | ||
} | ||
mapping.source = undefined; | ||
} | ||
if (mapping.data.__combineOffsetMapping !== undefined) { | ||
@@ -170,0 +179,0 @@ const offsetMapping = mappings[i - mapping.data.__combineOffsetMapping]; |
{ | ||
"name": "@vue/language-core", | ||
"version": "2.0.19", | ||
"version": "2.0.20", | ||
"license": "MIT", | ||
@@ -15,3 +15,3 @@ "files": [ | ||
"dependencies": { | ||
"@volar/language-core": "~2.2.4", | ||
"@volar/language-core": "~2.3.0-alpha.14", | ||
"@vue/compiler-dom": "^3.4.0", | ||
@@ -38,3 +38,3 @@ "@vue/shared": "^3.4.0", | ||
}, | ||
"gitHead": "a9fae154ad1efc4359866cfd10251d53e4b0faed" | ||
"gitHead": "e1a5d2f136bf60a772c9655f9f5474c7f71a2ff9" | ||
} |
293867
6542
+ Added@volar/language-core@2.3.4(transitive)
+ Added@volar/source-map@2.3.4(transitive)
- Removed@volar/language-core@2.2.5(transitive)
- Removed@volar/source-map@2.2.5(transitive)
- Removedmuggle-string@0.4.1(transitive)