@volar/vue-language-core
Advanced tools
Comparing version 1.2.2-alpha.0 to 1.2.2-alpha.1
@@ -11,3 +11,2 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, cssVars, cssModuleClasses, cssScopedClasses, htmlGen, compilerOptions, vueCompilerOptions, codeGen = [], mirrorBehaviorMappings = []) { | ||
var _a, _b; | ||
// monkey fix for https://github.com/johnsoncodehk/volar/pull/2113 | ||
@@ -48,3 +47,3 @@ const sfc = { | ||
const bypassDefineComponent = lang === 'js' || lang === 'jsx'; | ||
const vueVersion = (_a = vueCompilerOptions.target) !== null && _a !== void 0 ? _a : 3; | ||
const vueVersion = vueCompilerOptions.target ?? 3; | ||
const vueLibName = (0, shared_2.getVueLibraryName)(vueVersion); | ||
@@ -57,3 +56,3 @@ const usedTypes = { | ||
}; | ||
const generateFunctionType = !!vueCompilerOptions.experimentalRfc436 && !!((_b = sfc.scriptSetup) === null || _b === void 0 ? void 0 : _b.generic); | ||
const generateFunctionType = !!vueCompilerOptions.experimentalRfc436 && !!sfc.scriptSetup?.generic; | ||
writeScriptSrc(); | ||
@@ -138,4 +137,3 @@ writeScriptSetupImportsSegment(); | ||
function writeScriptSrc() { | ||
var _a; | ||
if (!((_a = sfc.script) === null || _a === void 0 ? void 0 : _a.src)) | ||
if (!sfc.script?.src) | ||
return; | ||
@@ -156,6 +154,7 @@ let src = sfc.script.src; | ||
[sfc.script.srcOffset - 1, sfc.script.srcOffset + sfc.script.src.length + 1], | ||
Object.assign(Object.assign({}, language_core_1.FileRangeCapabilities.full), { rename: src === sfc.script.src ? true : { | ||
{ | ||
...language_core_1.FileRangeCapabilities.full, | ||
rename: src === sfc.script.src ? true : { | ||
normalize: undefined, | ||
apply(newName) { | ||
var _a, _b, _c, _d, _e, _f; | ||
if (newName.endsWith('.jsx') | ||
@@ -165,9 +164,9 @@ || newName.endsWith('.js')) { | ||
} | ||
if ((_b = (_a = sfc.script) === null || _a === void 0 ? void 0 : _a.src) === null || _b === void 0 ? void 0 : _b.endsWith('.d.ts')) { | ||
if (sfc.script?.src?.endsWith('.d.ts')) { | ||
newName = newName + '.d.ts'; | ||
} | ||
else if ((_d = (_c = sfc.script) === null || _c === void 0 ? void 0 : _c.src) === null || _d === void 0 ? void 0 : _d.endsWith('.ts')) { | ||
else if (sfc.script?.src?.endsWith('.ts')) { | ||
newName = newName + '.ts'; | ||
} | ||
else if ((_f = (_e = sfc.script) === null || _e === void 0 ? void 0 : _e.src) === null || _f === void 0 ? void 0 : _f.endsWith('.tsx')) { | ||
else if (sfc.script?.src?.endsWith('.tsx')) { | ||
newName = newName + '.tsx'; | ||
@@ -177,3 +176,4 @@ } | ||
}, | ||
} }), | ||
}, | ||
}, | ||
]); | ||
@@ -186,3 +186,3 @@ codeGen.push(`;\n`); | ||
return; | ||
if (!!sfc.scriptSetup && (scriptRanges === null || scriptRanges === void 0 ? void 0 : scriptRanges.exportDefault)) { | ||
if (!!sfc.scriptSetup && scriptRanges?.exportDefault) { | ||
// fix https://github.com/johnsoncodehk/volar/issues/1127 | ||
@@ -199,6 +199,6 @@ codeGen.push([ | ||
let isExportRawObject = false; | ||
if (scriptRanges === null || scriptRanges === void 0 ? void 0 : scriptRanges.exportDefault) { | ||
if (scriptRanges?.exportDefault) { | ||
isExportRawObject = sfc.script.content.substring(scriptRanges.exportDefault.expression.start, scriptRanges.exportDefault.expression.end).startsWith('{'); | ||
} | ||
if (isExportRawObject && vueCompilerOptions.optionsWrapper.length && (scriptRanges === null || scriptRanges === void 0 ? void 0 : scriptRanges.exportDefault)) { | ||
if (isExportRawObject && vueCompilerOptions.optionsWrapper.length && scriptRanges?.exportDefault) { | ||
addVirtualCode('script', 0, scriptRanges.exportDefault.expression.start); | ||
@@ -218,3 +218,3 @@ codeGen.push(vueCompilerOptions.optionsWrapper[0]); | ||
return; | ||
if (!!sfc.scriptSetup && (scriptRanges === null || scriptRanges === void 0 ? void 0 : scriptRanges.exportDefault)) { | ||
if (!!sfc.scriptSetup && scriptRanges?.exportDefault) { | ||
addVirtualCode('script', scriptRanges.exportDefault.end, sfc.script.content.length); | ||
@@ -261,5 +261,4 @@ } | ||
function writeScriptSetupAndTemplate() { | ||
var _a; | ||
if (sfc.scriptSetup && scriptSetupRanges) { | ||
if (!(scriptRanges === null || scriptRanges === void 0 ? void 0 : scriptRanges.exportDefault)) { | ||
if (!scriptRanges?.exportDefault) { | ||
// fix https://github.com/johnsoncodehk/volar/issues/1127 | ||
@@ -306,3 +305,3 @@ codeGen.push([ | ||
} | ||
if ((scriptRanges === null || scriptRanges === void 0 ? void 0 : scriptRanges.exportDefault) && scriptRanges.exportDefault.expression.start !== scriptRanges.exportDefault.args.start) { | ||
if (scriptRanges?.exportDefault && scriptRanges.exportDefault.expression.start !== scriptRanges.exportDefault.args.start) { | ||
// use defineComponent() from user space code if it exist | ||
@@ -399,3 +398,3 @@ codeGen.push(`const __VLS_publicComponent = `); | ||
codeGen.push(`},\n`); | ||
if ((_a = scriptRanges === null || scriptRanges === void 0 ? void 0 : scriptRanges.exportDefault) === null || _a === void 0 ? void 0 : _a.args) { | ||
if (scriptRanges?.exportDefault?.args) { | ||
addVirtualCode('script', scriptRanges.exportDefault.args.start + 1, scriptRanges.exportDefault.args.end - 1); | ||
@@ -422,3 +421,3 @@ } | ||
codeGen.push(`,\n`); | ||
if (htmlGen === null || htmlGen === void 0 ? void 0 : htmlGen.hasSlot) { | ||
if (htmlGen?.hasSlot) { | ||
codeGen.push(`children: ReturnType<typeof __VLS_template>,\n`); | ||
@@ -432,3 +431,3 @@ } | ||
else { | ||
if (!vueCompilerOptions.skipTemplateCodegen && (htmlGen === null || htmlGen === void 0 ? void 0 : htmlGen.hasSlot)) { | ||
if (!vueCompilerOptions.skipTemplateCodegen && htmlGen?.hasSlot) { | ||
usedTypes.WithTemplateSlots = true; | ||
@@ -447,3 +446,3 @@ codeGen.push(`return {} as __VLS_WithTemplateSlots<typeof __VLS_publicComponent, ReturnType<typeof __VLS_template>>;\n`); | ||
} | ||
if ((scriptRanges === null || scriptRanges === void 0 ? void 0 : scriptRanges.exportDefault) && scriptRanges.exportDefault.expression.end !== scriptRanges.exportDefault.end) { | ||
if (scriptRanges?.exportDefault && scriptRanges.exportDefault.expression.end !== scriptRanges.exportDefault.end) { | ||
addVirtualCode('script', scriptRanges.exportDefault.expression.end, scriptRanges.exportDefault.end); | ||
@@ -554,6 +553,5 @@ } | ||
function writeExportOptions() { | ||
var _a; | ||
codeGen.push(`\n`); | ||
codeGen.push(`const __VLS_componentsOption = `); | ||
if (sfc.script && ((_a = scriptRanges === null || scriptRanges === void 0 ? void 0 : scriptRanges.exportDefault) === null || _a === void 0 ? void 0 : _a.componentsOption)) { | ||
if (sfc.script && scriptRanges?.exportDefault?.componentsOption) { | ||
const componentsOption = scriptRanges.exportDefault.componentsOption; | ||
@@ -576,5 +574,4 @@ codeGen.push([ | ||
function writeConstNameOption() { | ||
var _a; | ||
codeGen.push(`\n`); | ||
if (sfc.script && ((_a = scriptRanges === null || scriptRanges === void 0 ? void 0 : scriptRanges.exportDefault) === null || _a === void 0 ? void 0 : _a.nameOption)) { | ||
if (sfc.script && scriptRanges?.exportDefault?.nameOption) { | ||
const nameOption = scriptRanges.exportDefault.nameOption; | ||
@@ -593,3 +590,2 @@ codeGen.push(`const __VLS_name = `); | ||
function writeTemplateContext() { | ||
var _a; | ||
const useGlobalThisTypeInCtx = fileName.endsWith('.html'); | ||
@@ -614,3 +610,3 @@ codeGen.push(`let __VLS_ctx!: ${useGlobalThisTypeInCtx ? 'typeof globalThis &' : ''}`); | ||
codeGen.push(`let __VLS_otherComponents!: typeof __VLS_localComponents & import('./__VLS_types.js').GlobalComponents;\n`); | ||
codeGen.push(`let __VLS_own!: import('./__VLS_types.js').SelfComponent<typeof __VLS_name, typeof __VLS_internalComponent & typeof __VLS_publicComponent & (new () => { ${(0, shared_2.getSlotsPropertyName)((_a = vueCompilerOptions.target) !== null && _a !== void 0 ? _a : 3)}: typeof __VLS_slots })>;\n`); | ||
codeGen.push(`let __VLS_own!: import('./__VLS_types.js').SelfComponent<typeof __VLS_name, typeof __VLS_internalComponent & typeof __VLS_publicComponent & (new () => { ${(0, shared_2.getSlotsPropertyName)(vueCompilerOptions.target ?? 3)}: typeof __VLS_slots })>;\n`); | ||
codeGen.push(`let __VLS_components!: typeof __VLS_otherComponents & Omit<typeof __VLS_own, keyof typeof __VLS_otherComponents>;\n`); | ||
@@ -706,6 +702,6 @@ /* Style Scoped */ | ||
if (scriptSetupRanges) { | ||
bindingNames = bindingNames.concat(scriptSetupRanges.bindings.map(range => { var _a, _b; return (_b = (_a = sfc.scriptSetup) === null || _a === void 0 ? void 0 : _a.content.substring(range.start, range.end)) !== null && _b !== void 0 ? _b : ''; })); | ||
bindingNames = bindingNames.concat(scriptSetupRanges.bindings.map(range => sfc.scriptSetup?.content.substring(range.start, range.end) ?? '')); | ||
} | ||
if (scriptRanges) { | ||
bindingNames = bindingNames.concat(scriptRanges.bindings.map(range => { var _a, _b; return (_b = (_a = sfc.script) === null || _a === void 0 ? void 0 : _a.content.substring(range.start, range.end)) !== null && _b !== void 0 ? _b : ''; })); | ||
bindingNames = bindingNames.concat(scriptRanges.bindings.map(range => sfc.script?.content.substring(range.start, range.end) ?? '')); | ||
} | ||
@@ -712,0 +708,0 @@ // fix import components unused report |
@@ -8,3 +8,2 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
function createLanguageModules(ts, compilerOptions, vueCompilerOptions) { | ||
var _a, _b; | ||
patchResolveModuleNames(ts, vueCompilerOptions); | ||
@@ -15,8 +14,7 @@ const vueLanguagePlugin = (0, plugins_1.getDefaultVueLanguagePlugins)(ts, compilerOptions, vueCompilerOptions); | ||
createFile(fileName, snapshot, languageId) { | ||
if (vueCompilerOptions.extensions.some(ext => fileName.endsWith(ext))) { | ||
if (languageId === 'vue' | ||
|| (!languageId | ||
&& vueCompilerOptions.extensions.some(ext => fileName.endsWith(ext)))) { | ||
return new sourceFile_1.VueFile(fileName, snapshot, ts, vueLanguagePlugin); | ||
} | ||
else if (languageId === 'vue') { | ||
return new sourceFile_1.VueFile(fileName, snapshot, ts, vueLanguagePlugin); | ||
} | ||
}, | ||
@@ -74,3 +72,3 @@ updateFile(sourceFile, snapshot) { | ||
languageModule, | ||
...(_b = (_a = vueCompilerOptions.experimentalAdditionalLanguageModules) === null || _a === void 0 ? void 0 : _a.map(module => require(module))) !== null && _b !== void 0 ? _b : [], | ||
...vueCompilerOptions.experimentalAdditionalLanguageModules?.map(module => require(module)) ?? [], | ||
]; | ||
@@ -77,0 +75,0 @@ function getSharedTypesFiles(fileNames) { |
@@ -36,3 +36,11 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
}); | ||
exportDefault = Object.assign(Object.assign({}, _getStartEnd(raw)), { expression: _getStartEnd(node.expression), args: _getStartEnd(obj), argsNode: withNode ? obj : undefined, componentsOption: componentsOptionNode ? _getStartEnd(componentsOptionNode) : undefined, componentsOptionNode: withNode ? componentsOptionNode : undefined, nameOption: nameOptionNode ? _getStartEnd(nameOptionNode) : undefined }); | ||
exportDefault = { | ||
..._getStartEnd(raw), | ||
expression: _getStartEnd(node.expression), | ||
args: _getStartEnd(obj), | ||
argsNode: withNode ? obj : undefined, | ||
componentsOption: componentsOptionNode ? _getStartEnd(componentsOptionNode) : undefined, | ||
componentsOptionNode: withNode ? componentsOptionNode : undefined, | ||
nameOption: nameOptionNode ? _getStartEnd(nameOptionNode) : undefined, | ||
}; | ||
} | ||
@@ -39,0 +47,0 @@ } |
@@ -20,4 +20,3 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
ast.forEachChild(node => { | ||
var _a; | ||
const isTypeExport = (ts.isTypeAliasDeclaration(node) || ts.isInterfaceDeclaration(node)) && ((_a = node.modifiers) === null || _a === void 0 ? void 0 : _a.some(mod => mod.kind === ts.SyntaxKind.ExportKeyword)); | ||
const isTypeExport = (ts.isTypeAliasDeclaration(node) || ts.isInterfaceDeclaration(node)) && node.modifiers?.some(mod => mod.kind === ts.SyntaxKind.ExportKeyword); | ||
if (!foundNonImportExportNode | ||
@@ -57,3 +56,2 @@ && !ts.isImportDeclaration(node) | ||
function visitNode(node, parent) { | ||
var _a; | ||
if (ts.isCallExpression(node) | ||
@@ -83,3 +81,3 @@ && ts.isIdentifier(node.expression)) { | ||
} | ||
if ((_a = node.typeArguments) === null || _a === void 0 ? void 0 : _a.length) { | ||
if (node.typeArguments?.length) { | ||
const typeArg = node.typeArguments[0]; | ||
@@ -86,0 +84,0 @@ if (vueCompilerOptions.macros.defineProps.includes(callText)) { |
@@ -38,5 +38,4 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
.sort((a, b) => { | ||
var _a, _b; | ||
const aOrder = (_a = a.order) !== null && _a !== void 0 ? _a : 0; | ||
const bOrder = (_b = b.order) !== null && _b !== void 0 ? _b : 0; | ||
const aOrder = a.order ?? 0; | ||
const bOrder = b.order ?? 0; | ||
return aOrder - bOrder; | ||
@@ -43,0 +42,0 @@ }); |
@@ -5,3 +5,2 @@ const plugin = () => { | ||
parseSFC(fileName, content) { | ||
var _a; | ||
if (fileName.endsWith('.html')) { | ||
@@ -30,3 +29,3 @@ let sfc = { | ||
const attrs = match[2]; | ||
const lang = (_a = attrs.match(langReg)) === null || _a === void 0 ? void 0 : _a[2]; | ||
const lang = attrs.match(langReg)?.[2]; | ||
const content = match[3]; | ||
@@ -33,0 +32,0 @@ const contentStart = match.index + matchText.indexOf(content); |
@@ -52,5 +52,4 @@ const source_map_1 = require("@volar/source-map"); | ||
function transformRange(block) { | ||
var _a, _b, _c, _d; | ||
block.loc.start.offset = (_b = (_a = file2VueSourceMap.toSourceOffset(block.loc.start.offset)) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : -1; | ||
block.loc.end.offset = (_d = (_c = file2VueSourceMap.toSourceOffset(block.loc.end.offset)) === null || _c === void 0 ? void 0 : _c[0]) !== null && _d !== void 0 ? _d : -1; | ||
block.loc.start.offset = file2VueSourceMap.toSourceOffset(block.loc.start.offset)?.[0] ?? -1; | ||
block.loc.end.offset = file2VueSourceMap.toSourceOffset(block.loc.end.offset)?.[0] ?? -1; | ||
} | ||
@@ -57,0 +56,0 @@ } |
@@ -21,3 +21,8 @@ const language_core_1 = require("@volar/language-core"); | ||
embeddedFile.kind = language_core_1.FileKind.TextFile; | ||
embeddedFile.capabilities = Object.assign(Object.assign({}, language_core_1.FileCapabilities.full), { diagnostic: false, codeAction: false, inlayHint: false }); | ||
embeddedFile.capabilities = { | ||
...language_core_1.FileCapabilities.full, | ||
diagnostic: false, | ||
codeAction: false, | ||
inlayHint: false, | ||
}; | ||
embeddedFile.content.push([ | ||
@@ -24,0 +29,0 @@ script.content, |
@@ -29,3 +29,2 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
resolveEmbeddedFile(fileName, sfc, embeddedFile) { | ||
var _a, _b; | ||
const _tsx = useTsx(fileName, sfc); | ||
@@ -35,3 +34,8 @@ const suffix = embeddedFile.fileName.replace(fileName, ''); | ||
embeddedFile.kind = language_core_1.FileKind.TypeScriptHostFile; | ||
embeddedFile.capabilities = Object.assign(Object.assign({}, language_core_1.FileCapabilities.full), { foldingRange: false, documentFormatting: false, documentSymbol: false }); | ||
embeddedFile.capabilities = { | ||
...language_core_1.FileCapabilities.full, | ||
foldingRange: false, | ||
documentFormatting: false, | ||
documentSymbol: false, | ||
}; | ||
const tsx = _tsx.tsxGen.value; | ||
@@ -45,5 +49,11 @@ if (tsx) { | ||
else if (suffix.match(/^\.template_format\.ts$/)) { | ||
embeddedFile.parentFileName = fileName + '.template.' + ((_a = sfc.template) === null || _a === void 0 ? void 0 : _a.lang); | ||
embeddedFile.parentFileName = fileName + '.template.' + sfc.template?.lang; | ||
embeddedFile.kind = language_core_1.FileKind.TextFile; | ||
embeddedFile.capabilities = Object.assign(Object.assign({}, language_core_1.FileCapabilities.full), { diagnostic: false, foldingRange: false, codeAction: false, inlayHint: false }); | ||
embeddedFile.capabilities = { | ||
...language_core_1.FileCapabilities.full, | ||
diagnostic: false, | ||
foldingRange: false, | ||
codeAction: false, | ||
inlayHint: false, | ||
}; | ||
if (_tsx.htmlGen.value) { | ||
@@ -67,3 +77,3 @@ embeddedFile.content = [..._tsx.htmlGen.value.formatCodeGen]; | ||
else if (suffix.match(/^\.template_style\.css$/)) { | ||
embeddedFile.parentFileName = fileName + '.template.' + ((_b = sfc.template) === null || _b === void 0 ? void 0 : _b.lang); | ||
embeddedFile.parentFileName = fileName + '.template.' + sfc.template?.lang; | ||
if (_tsx.htmlGen.value) { | ||
@@ -110,7 +120,6 @@ embeddedFile.content = [..._tsx.htmlGen.value.cssCodeGen]; | ||
const htmlGen = (0, reactivity_1.computed)(() => { | ||
var _a, _b, _c, _d; | ||
const templateAst = _sfc.templateAst; | ||
if (!templateAst) | ||
return; | ||
return templateGen.generate(ts, compilerOptions, vueCompilerOptions, (_b = (_a = _sfc.template) === null || _a === void 0 ? void 0 : _a.content) !== null && _b !== void 0 ? _b : '', (_d = (_c = _sfc.template) === null || _c === void 0 ? void 0 : _c.lang) !== null && _d !== void 0 ? _d : 'html', templateAst, !!_sfc.scriptSetup, Object.values(cssScopedClasses.value).map(style => style.classNames).flat()); | ||
return templateGen.generate(ts, compilerOptions, vueCompilerOptions, _sfc.template?.content ?? '', _sfc.template?.lang ?? 'html', templateAst, !!_sfc.scriptSetup, Object.values(cssScopedClasses.value).map(style => style.classNames).flat()); | ||
}); | ||
@@ -117,0 +126,0 @@ const tsxGen = (0, reactivity_1.computed)(() => (0, script_1.generate)(ts, fileName, _sfc, lang.value, scriptRanges.value, scriptSetupRanges.value, cssVars.value, cssModuleClasses.value, cssScopedClasses.value, htmlGen.value, compilerOptions, vueCompilerOptions)); |
@@ -23,4 +23,3 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
get mainScriptName() { | ||
var _a, _b; | ||
return (_b = (_a = this._allEmbeddedFiles.value.find(e => e.file.fileName.replace(this.fileName, '').match(/^\.(js|ts)x?$/))) === null || _a === void 0 ? void 0 : _a.file.fileName) !== null && _b !== void 0 ? _b : ''; | ||
return this._allEmbeddedFiles.value.find(e => e.file.fileName.replace(this.fileName, '').match(/^\.(js|ts)x?$/))?.file.fileName ?? ''; | ||
} | ||
@@ -40,20 +39,28 @@ get embeddedFiles() { | ||
// refs | ||
this.sfc = (0, reactivity_1.reactive)(Object.assign({ template: null, script: null, scriptSetup: null, styles: [], customBlocks: [], templateAst: (0, reactivity_1.computed)(() => { | ||
var _a; | ||
return (_a = this._compiledSfcTemplate.value) === null || _a === void 0 ? void 0 : _a.ast; | ||
}), scriptAst: (0, reactivity_1.computed)(() => { | ||
this.sfc = (0, reactivity_1.reactive)({ | ||
template: null, | ||
script: null, | ||
scriptSetup: null, | ||
styles: [], | ||
customBlocks: [], | ||
templateAst: (0, reactivity_1.computed)(() => { | ||
return this._compiledSfcTemplate.value?.ast; | ||
}), | ||
scriptAst: (0, reactivity_1.computed)(() => { | ||
if (this.sfc.script) { | ||
return this.ts.createSourceFile(this.fileName + '.' + this.sfc.script.lang, this.sfc.script.content, this.ts.ScriptTarget.Latest); | ||
} | ||
}), scriptSetupAst: (0, reactivity_1.computed)(() => { | ||
}), | ||
scriptSetupAst: (0, reactivity_1.computed)(() => { | ||
if (this.sfc.scriptSetup) { | ||
return this.ts.createSourceFile(this.fileName + '.' + this.sfc.scriptSetup.lang, this.sfc.scriptSetup.content, this.ts.ScriptTarget.Latest); | ||
} | ||
}) }, { | ||
// backward compatible | ||
getTemplateAst: () => { | ||
var _a; | ||
return (_a = this.compiledSFCTemplate) === null || _a === void 0 ? void 0 : _a.ast; | ||
}), | ||
...{ | ||
// backward compatible | ||
getTemplateAst: () => { | ||
return this.compiledSFCTemplate?.ast; | ||
}, | ||
}, | ||
})) /* avoid Sfc unwrap in .d.ts by reactive */; | ||
}) /* avoid Sfc unwrap in .d.ts by reactive */; | ||
// computed | ||
@@ -80,8 +87,7 @@ this._sfcBlocks = (0, reactivity_1.computed)(() => { | ||
this._compiledSfcTemplate = (0, reactivity_1.computed)(() => { | ||
var _a, _b, _c, _d, _e; | ||
if (((_a = this.compiledSFCTemplateCache) === null || _a === void 0 ? void 0 : _a.template) === ((_b = this.sfc.template) === null || _b === void 0 ? void 0 : _b.content)) { | ||
if (this.compiledSFCTemplateCache?.template === this.sfc.template?.content) { | ||
return { | ||
errors: [], | ||
warnings: [], | ||
ast: (_c = this.compiledSFCTemplateCache) === null || _c === void 0 ? void 0 : _c.result.ast, | ||
ast: this.compiledSFCTemplateCache?.result.ast, | ||
}; | ||
@@ -91,3 +97,3 @@ } | ||
// incremental update | ||
if ((_d = this.compiledSFCTemplateCache) === null || _d === void 0 ? void 0 : _d.plugin.updateSFCTemplate) { | ||
if (this.compiledSFCTemplateCache?.plugin.updateSFCTemplate) { | ||
const change = this.snapshot.getChangeRange(this.compiledSFCTemplateCache.snapshot); | ||
@@ -131,3 +137,3 @@ if (change) { | ||
try { | ||
result = (_e = plugin.compileSFCTemplate) === null || _e === void 0 ? void 0 : _e.call(plugin, this.sfc.template.lang, this.sfc.template.content, options); | ||
result = plugin.compileSFCTemplate?.(this.sfc.template.lang, this.sfc.template.content, options); | ||
} | ||
@@ -153,3 +159,3 @@ catch (e) { | ||
warnings, | ||
ast: result === null || result === void 0 ? void 0 : result.ast, | ||
ast: result?.ast, | ||
}; | ||
@@ -240,4 +246,8 @@ } | ||
for (const { file, snapshot, mappings } of remain) { | ||
embeddedFiles.push(Object.assign(Object.assign({}, file), { snapshot, | ||
mappings, embeddedFiles: [] })); | ||
embeddedFiles.push({ | ||
...file, | ||
snapshot, | ||
mappings, | ||
embeddedFiles: [], | ||
}); | ||
console.error('Unable to resolve embedded: ' + file.parentFileName + ' -> ' + file.fileName); | ||
@@ -250,4 +260,8 @@ } | ||
if (!file.parentFileName) { | ||
embeddedFiles.push(Object.assign(Object.assign({}, file), { snapshot, | ||
mappings, embeddedFiles: [] })); | ||
embeddedFiles.push({ | ||
...file, | ||
snapshot, | ||
mappings, | ||
embeddedFiles: [], | ||
}); | ||
remain.splice(i, 1); | ||
@@ -258,4 +272,8 @@ } | ||
if (parent) { | ||
parent.embeddedFiles.push(Object.assign(Object.assign({}, file), { snapshot, | ||
mappings, embeddedFiles: [] })); | ||
parent.embeddedFiles.push({ | ||
...file, | ||
snapshot, | ||
mappings, | ||
embeddedFiles: [], | ||
}); | ||
remain.splice(i, 1); | ||
@@ -321,5 +339,4 @@ } | ||
parseSfc() { | ||
var _a, _b; | ||
// incremental update | ||
if ((_a = this.parsedSfcCache) === null || _a === void 0 ? void 0 : _a.plugin.updateSFC) { | ||
if (this.parsedSfcCache?.plugin.updateSFC) { | ||
const change = this.snapshot.getChangeRange(this.parsedSfcCache.snapshot); | ||
@@ -340,3 +357,3 @@ if (change) { | ||
for (const plugin of this.plugins) { | ||
const sfc = (_b = plugin.parseSFC) === null || _b === void 0 ? void 0 : _b.call(plugin, this.fileName, this.snapshot.getText(0, this.snapshot.getLength())); | ||
const sfc = plugin.parseSFC?.(this.fileName, this.snapshot.getText(0, this.snapshot.getLength())); | ||
if (sfc) { | ||
@@ -355,3 +372,2 @@ if (!sfc.errors.length) { | ||
updateTemplate(block) { | ||
var _a; | ||
const newData = block ? { | ||
@@ -364,3 +380,3 @@ name: 'template', | ||
content: block.content, | ||
lang: (_a = block.lang) !== null && _a !== void 0 ? _a : 'html', | ||
lang: block.lang ?? 'html', | ||
} : null; | ||
@@ -375,3 +391,2 @@ if (this.sfc.template && newData) { | ||
updateScript(block) { | ||
var _a; | ||
const newData = block ? { | ||
@@ -384,3 +399,3 @@ name: 'script', | ||
content: block.content, | ||
lang: (_a = block.lang) !== null && _a !== void 0 ? _a : 'js', | ||
lang: block.lang ?? 'js', | ||
src: block.src, | ||
@@ -397,3 +412,2 @@ srcOffset: block.src ? this.snapshot.getText(0, block.loc.start.offset).lastIndexOf(block.src) - block.loc.start.offset : -1, | ||
updateScriptSetup(block) { | ||
var _a; | ||
const newData = block ? { | ||
@@ -406,3 +420,3 @@ name: 'scriptSetup', | ||
content: block.content, | ||
lang: (_a = block.lang) !== null && _a !== void 0 ? _a : 'js', | ||
lang: block.lang ?? 'js', | ||
generic: typeof block.attrs.generic === 'string' ? block.attrs.generic : undefined, | ||
@@ -419,3 +433,2 @@ genericOffset: typeof block.attrs.generic === 'string' ? this.snapshot.getText(0, block.loc.start.offset).lastIndexOf(block.attrs.generic) - block.loc.start.offset : -1, | ||
updateStyles(blocks) { | ||
var _a; | ||
for (let i = 0; i < blocks.length; i++) { | ||
@@ -430,3 +443,3 @@ const block = blocks[i]; | ||
content: block.content, | ||
lang: (_a = block.lang) !== null && _a !== void 0 ? _a : 'css', | ||
lang: block.lang ?? 'css', | ||
module: typeof block.module === 'string' ? block.module : block.module ? '$style' : undefined, | ||
@@ -447,3 +460,2 @@ scoped: !!block.scoped, | ||
updateCustomBlocks(blocks) { | ||
var _a; | ||
for (let i = 0; i < blocks.length; i++) { | ||
@@ -458,3 +470,3 @@ const block = blocks[i]; | ||
content: block.content, | ||
lang: (_a = block.lang) !== null && _a !== void 0 ? _a : 'txt', | ||
lang: block.lang ?? 'txt', | ||
type: block.type, | ||
@@ -461,0 +473,0 @@ }; |
@@ -5,3 +5,2 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
function* parseCssVars(styleContent) { | ||
var _a, _b; | ||
styleContent = clearComments(styleContent); | ||
@@ -12,3 +11,3 @@ const reg = /\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([^'"][^)]*))\s*\)/g; | ||
if (match.index !== undefined) { | ||
const matchText = (_b = (_a = match[1]) !== null && _a !== void 0 ? _a : match[2]) !== null && _b !== void 0 ? _b : match[3]; | ||
const matchText = match[1] ?? match[2] ?? match[3]; | ||
if (matchText !== undefined) { | ||
@@ -15,0 +14,0 @@ const offset = match.index + styleContent.slice(match.index).indexOf(matchText); |
@@ -91,3 +91,2 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
function walkIdentifiers(ts, node, cb, localVars) { | ||
var _a, _b; | ||
const blockVars = []; | ||
@@ -106,3 +105,3 @@ if (ts.isIdentifier(node)) { | ||
for (const varName of blockVars) | ||
localVars[varName] = ((_a = localVars[varName]) !== null && _a !== void 0 ? _a : 0) + 1; | ||
localVars[varName] = (localVars[varName] ?? 0) + 1; | ||
if (node.initializer) | ||
@@ -120,3 +119,3 @@ walkIdentifiers(ts, node.initializer, cb, localVars); | ||
for (const varName of functionArgs) | ||
localVars[varName] = ((_b = localVars[varName]) !== null && _b !== void 0 ? _b : 0) + 1; | ||
localVars[varName] = (localVars[varName] ?? 0) + 1; | ||
walkIdentifiers(ts, node.body, cb, localVars); | ||
@@ -123,0 +122,0 @@ for (const varName of functionArgs) |
@@ -32,3 +32,2 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
function createParsedCommandLineBase(ts, parseConfigHost, content, tsConfigPath, extraFileExtensions, extendsSet) { | ||
var _a, _b, _c; | ||
extendsSet.add(tsConfigPath); | ||
@@ -44,3 +43,6 @@ const folder = path.dirname(tsConfigPath); | ||
if (!extendsSet.has(extendsPath)) { | ||
extendsVueOptions = Object.assign(Object.assign({}, extendsVueOptions), createParsedCommandLine(ts, parseConfigHost, extendsPath, extraFileExtensions, extendsSet).vueOptions); | ||
extendsVueOptions = { | ||
...extendsVueOptions, | ||
...createParsedCommandLine(ts, parseConfigHost, extendsPath, extraFileExtensions, extendsSet).vueOptions, | ||
}; | ||
} | ||
@@ -52,3 +54,3 @@ } | ||
} | ||
if ((_a = content.raw.vueCompilerOptions) === null || _a === void 0 ? void 0 : _a.plugins) { | ||
if (content.raw.vueCompilerOptions?.plugins) { | ||
const pluginPaths = content.raw.vueCompilerOptions.plugins; | ||
@@ -70,9 +72,19 @@ const plugins = pluginPaths | ||
} | ||
const vueOptions = Object.assign(Object.assign({}, extendsVueOptions), content.raw.vueCompilerOptions); | ||
vueOptions.hooks = (_b = vueOptions.hooks) === null || _b === void 0 ? void 0 : _b.map(resolvePath).filter((hook) => !!hook); | ||
vueOptions.experimentalAdditionalLanguageModules = (_c = vueOptions.experimentalAdditionalLanguageModules) === null || _c === void 0 ? void 0 : _c.map(resolvePath).filter((module) => !!module); | ||
return Object.assign(Object.assign({}, content), { vueOptions }); | ||
const vueOptions = { | ||
...extendsVueOptions, | ||
...content.raw.vueCompilerOptions, | ||
}; | ||
vueOptions.hooks = vueOptions.hooks | ||
?.map(resolvePath) | ||
.filter((hook) => !!hook); | ||
vueOptions.experimentalAdditionalLanguageModules = vueOptions.experimentalAdditionalLanguageModules | ||
?.map(resolvePath) | ||
.filter((module) => !!module); | ||
return { | ||
...content, | ||
vueOptions, | ||
}; | ||
function resolvePath(scriptPath) { | ||
try { | ||
if (require === null || require === void 0 ? void 0 : require.resolve) { | ||
if (require?.resolve) { | ||
scriptPath = require.resolve(scriptPath, { paths: [folder] }); | ||
@@ -112,5 +124,11 @@ } | ||
function resolveVueCompilerOptions(vueOptions) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t; | ||
const target = (_a = vueOptions.target) !== null && _a !== void 0 ? _a : 3; | ||
return Object.assign(Object.assign({}, vueOptions), { target, extensions: (_b = vueOptions.extensions) !== null && _b !== void 0 ? _b : ['.vue'], jsxTemplates: (_c = vueOptions.jsxTemplates) !== null && _c !== void 0 ? _c : false, strictTemplates: (_d = vueOptions.strictTemplates) !== null && _d !== void 0 ? _d : false, skipTemplateCodegen: (_e = vueOptions.skipTemplateCodegen) !== null && _e !== void 0 ? _e : false, nativeTags: (_f = vueOptions.nativeTags) !== null && _f !== void 0 ? _f : [...new Set([ | ||
const target = vueOptions.target ?? 3; | ||
return { | ||
...vueOptions, | ||
target, | ||
extensions: vueOptions.extensions ?? ['.vue'], | ||
jsxTemplates: vueOptions.jsxTemplates ?? false, | ||
strictTemplates: vueOptions.strictTemplates ?? false, | ||
skipTemplateCodegen: vueOptions.skipTemplateCodegen ?? false, | ||
nativeTags: vueOptions.nativeTags ?? [...new Set([ | ||
...HTML_TAGS.split(','), | ||
@@ -122,5 +140,9 @@ ...SVG_TAGS.split(','), | ||
'component', | ||
])], dataAttributes: (_g = vueOptions.dataAttributes) !== null && _g !== void 0 ? _g : [], htmlAttributes: (_h = vueOptions.htmlAttributes) !== null && _h !== void 0 ? _h : ['aria-*'], optionsWrapper: (_j = vueOptions.optionsWrapper) !== null && _j !== void 0 ? _j : (target >= 2.7 | ||
])], | ||
dataAttributes: vueOptions.dataAttributes ?? [], | ||
htmlAttributes: vueOptions.htmlAttributes ?? ['aria-*'], | ||
optionsWrapper: vueOptions.optionsWrapper ?? (target >= 2.7 | ||
? [`(await import('vue')).defineComponent(`, `)`] | ||
: [`(await import('vue')).default.extend(`, `)`]), macros: (_k = vueOptions.macros) !== null && _k !== void 0 ? _k : { | ||
: [`(await import('vue')).default.extend(`, `)`]), | ||
macros: vueOptions.macros ?? { | ||
defineProps: ['defineProps'], | ||
@@ -130,8 +152,13 @@ defineEmits: ['defineEmits'], | ||
withDefaults: ['withDefaults'], | ||
}, narrowingTypesInInlineHandlers: (_l = vueOptions.narrowingTypesInInlineHandlers) !== null && _l !== void 0 ? _l : false, plugins: (_m = vueOptions.plugins) !== null && _m !== void 0 ? _m : [], hooks: (_o = vueOptions.hooks) !== null && _o !== void 0 ? _o : [], | ||
}, | ||
narrowingTypesInInlineHandlers: vueOptions.narrowingTypesInInlineHandlers ?? false, | ||
plugins: vueOptions.plugins ?? [], | ||
hooks: vueOptions.hooks ?? [], | ||
// experimental | ||
experimentalAdditionalLanguageModules: (_p = vueOptions.experimentalAdditionalLanguageModules) !== null && _p !== void 0 ? _p : [], experimentalResolveStyleCssClasses: (_q = vueOptions.experimentalResolveStyleCssClasses) !== null && _q !== void 0 ? _q : 'scoped', experimentalRfc436: (_r = vueOptions.experimentalRfc436) !== null && _r !== void 0 ? _r : false, | ||
experimentalAdditionalLanguageModules: vueOptions.experimentalAdditionalLanguageModules ?? [], | ||
experimentalResolveStyleCssClasses: vueOptions.experimentalResolveStyleCssClasses ?? 'scoped', | ||
experimentalRfc436: vueOptions.experimentalRfc436 ?? false, | ||
// https://github.com/vuejs/vue-next/blob/master/packages/compiler-dom/src/transforms/vModel.ts#L49-L51 | ||
// https://vuejs.org/guide/essentials/forms.html#form-input-bindings | ||
experimentalModelPropName: (_s = vueOptions.experimentalModelPropName) !== null && _s !== void 0 ? _s : { | ||
experimentalModelPropName: vueOptions.experimentalModelPropName ?? { | ||
'': { | ||
@@ -145,5 +172,7 @@ input: true | ||
} | ||
}, experimentalUseElementAccessInTemplate: (_t = vueOptions.experimentalUseElementAccessInTemplate) !== null && _t !== void 0 ? _t : false }); | ||
}, | ||
experimentalUseElementAccessInTemplate: vueOptions.experimentalUseElementAccessInTemplate ?? false, | ||
}; | ||
} | ||
exports.resolveVueCompilerOptions = resolveVueCompilerOptions; | ||
//# sourceMappingURL=ts.js.map |
@@ -21,3 +21,2 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
function compile(template, options = {}) { | ||
var _a, _b; | ||
const onError = options.onError; | ||
@@ -40,3 +39,3 @@ const onWarn = options.onWarn; | ||
for (const error of vue2Result.errors) { | ||
onError === null || onError === void 0 ? void 0 : onError({ | ||
onError?.({ | ||
code: 'vue-template-compiler', | ||
@@ -48,3 +47,3 @@ name: '', | ||
start: { column: -1, line: -1, offset: error.start }, | ||
end: { column: -1, line: -1, offset: (_a = error.end) !== null && _a !== void 0 ? _a : error.start }, | ||
end: { column: -1, line: -1, offset: error.end ?? error.start }, | ||
}, | ||
@@ -54,3 +53,3 @@ }); | ||
for (const error of vue2Result.tips) { | ||
onWarn === null || onWarn === void 0 ? void 0 : onWarn({ | ||
onWarn?.({ | ||
code: 'vue-template-compiler', | ||
@@ -62,3 +61,3 @@ name: '', | ||
start: { column: -1, line: -1, offset: error.start }, | ||
end: { column: -1, line: -1, offset: (_b = error.end) !== null && _b !== void 0 ? _b : error.start }, | ||
end: { column: -1, line: -1, offset: error.end ?? error.start }, | ||
}, | ||
@@ -65,0 +64,0 @@ }); |
{ | ||
"name": "@volar/vue-language-core", | ||
"version": "1.2.2-alpha.0", | ||
"version": "1.2.2-alpha.1", | ||
"main": "out/index.js", | ||
@@ -16,4 +16,4 @@ "license": "MIT", | ||
"dependencies": { | ||
"@volar/language-core": "1.3.0-alpha.3", | ||
"@volar/source-map": "1.3.0-alpha.3", | ||
"@volar/language-core": "1.4.0-alpha.1", | ||
"@volar/source-map": "1.4.0-alpha.1", | ||
"@vue/compiler-dom": "^3.2.47", | ||
@@ -30,3 +30,3 @@ "@vue/compiler-sfc": "^3.2.47", | ||
}, | ||
"gitHead": "e2bcd4ec1690f402ca8b57c21faa1a053b0f0af6" | ||
"gitHead": "ec74b353fe44dc521a0e4048a8f4e18bd99a546f" | ||
} |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
4876
4
219716
+ Added@volar/language-core@1.4.0-alpha.1(transitive)
+ Added@volar/source-map@1.4.0-alpha.1(transitive)
- Removed@volar/language-core@1.3.0-alpha.3(transitive)
- Removed@volar/source-map@1.3.0-alpha.3(transitive)