This commit is contained in:
2024-11-28 23:08:17 +01:00
parent 8895fde030
commit 0dda8e760c
16116 changed files with 2866428 additions and 71 deletions

View File

@@ -0,0 +1,3 @@
import type { Segment } from 'muggle-string';
import type { Mapping } from '@volar/language-core';
export declare function buildMappings<T>(chunks: Segment<T>[]): Mapping<T>[];

View File

@@ -0,0 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildMappings = buildMappings;
function buildMappings(chunks) {
let length = 0;
const mappings = [];
for (const segment of chunks) {
if (typeof segment === 'string') {
length += segment.length;
}
else {
mappings.push({
sourceOffsets: [segment[2]],
generatedOffsets: [length],
lengths: [segment[0].length],
data: segment[3],
});
length += segment[0].length;
}
}
return mappings;
}
//# sourceMappingURL=buildMappings.js.map

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=findDestructuredProps.js.map

View File

@@ -0,0 +1,4 @@
export declare function parseCssClassNames(css: string): Generator<{
offset: number;
text: string;
}, void, unknown>;

View File

@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseCssClassNames = parseCssClassNames;
const parseCssVars_1 = require("./parseCssVars");
const cssClassNameReg = /(?=(\.[a-z_][-\w]*)[\s.,+~>:#)[{])/gi;
const fragmentReg = /(?<={)[^{]*(?=(?<!\\);)/g;
function* parseCssClassNames(css) {
css = (0, parseCssVars_1.fillBlank)(css, parseCssVars_1.commentReg, fragmentReg);
const matches = css.matchAll(cssClassNameReg);
for (const match of matches) {
const matchText = match[1];
if (matchText) {
yield { offset: match.index, text: matchText };
}
}
}
//# sourceMappingURL=parseCssClassNames.js.map

View File

@@ -0,0 +1,6 @@
export declare const commentReg: RegExp;
export declare function parseCssVars(css: string): Generator<{
offset: number;
text: string;
}, void, unknown>;
export declare function fillBlank(css: string, ...regs: RegExp[]): string;

View File

@@ -0,0 +1,26 @@
"use strict";
// https://github.com/vuejs/core/blob/main/packages/compiler-sfc/src/cssVars.ts#L47-L61
Object.defineProperty(exports, "__esModule", { value: true });
exports.commentReg = void 0;
exports.parseCssVars = parseCssVars;
exports.fillBlank = fillBlank;
const vBindCssVarReg = /\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([a-z_]\w*))\s*\)/gi;
exports.commentReg = /(?<=\/\*)[\s\S]*?(?=\*\/)|(?<=\/\/)[\s\S]*?(?=\n)/g;
function* parseCssVars(css) {
css = fillBlank(css, exports.commentReg);
const matchs = css.matchAll(vBindCssVarReg);
for (const match of matchs) {
const matchText = match.slice(1).find(t => t);
if (matchText) {
const offset = match.index + css.slice(match.index).indexOf(matchText);
yield { offset, text: matchText };
}
}
}
function fillBlank(css, ...regs) {
for (const reg of regs) {
css = css.replace(reg, match => ' '.repeat(match.length));
}
return css;
}
//# sourceMappingURL=parseCssVars.js.map

View File

@@ -0,0 +1,2 @@
import type { SFCParseResult } from '@vue/compiler-sfc';
export declare function parse(source: string): SFCParseResult;

123
node_modules/@vue/language-core/lib/utils/parseSfc.js generated vendored Normal file
View File

@@ -0,0 +1,123 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parse = parse;
const compiler = require("@vue/compiler-dom");
function parse(source) {
const errors = [];
const ast = compiler.parse(source, {
// there are no components at SFC parsing level
isNativeTag: () => true,
// preserve all whitespaces
isPreTag: () => true,
parseMode: 'sfc',
onError: e => {
errors.push(e);
},
comments: true,
});
const descriptor = {
filename: 'anonymous.vue',
source,
template: null,
script: null,
scriptSetup: null,
styles: [],
customBlocks: [],
cssVars: [],
slotted: false,
shouldForceReload: () => false,
};
ast.children.forEach(node => {
if (node.type !== compiler.NodeTypes.ELEMENT) {
return;
}
switch (node.tag) {
case 'template':
descriptor.template = createBlock(node, source);
break;
case 'script':
const scriptBlock = createBlock(node, source);
const isSetup = !!scriptBlock.attrs.setup;
if (isSetup && !descriptor.scriptSetup) {
descriptor.scriptSetup = scriptBlock;
break;
}
if (!isSetup && !descriptor.script) {
descriptor.script = scriptBlock;
break;
}
break;
case 'style':
const styleBlock = createBlock(node, source);
descriptor.styles.push(styleBlock);
break;
default:
descriptor.customBlocks.push(createBlock(node, source));
break;
}
});
return {
descriptor,
errors,
};
}
function createBlock(node, source) {
const type = node.tag;
let { start, end } = node.loc;
let content = '';
if (node.children.length) {
start = node.children[0].loc.start;
end = node.children[node.children.length - 1].loc.end;
content = source.slice(start.offset, end.offset);
}
else {
const offset = node.loc.source.indexOf(`</`);
if (offset > -1) {
start = {
line: start.line,
column: start.column + offset,
offset: start.offset + offset
};
}
end = Object.assign({}, start);
}
const loc = {
source: content,
start,
end
};
const attrs = {};
const block = {
type,
content,
loc,
attrs
};
node.props.forEach(p => {
if (p.type === compiler.NodeTypes.ATTRIBUTE) {
attrs[p.name] = p.value ? p.value.content || true : true;
if (p.name === 'lang') {
block.lang = p.value && p.value.content;
}
else if (p.name === 'src') {
block.src = p.value && p.value.content;
}
else if (type === 'style') {
if (p.name === 'scoped') {
block.scoped = true;
}
else if (p.name === 'module') {
block.module = {
name: p.value?.content ?? '$style',
offset: p.value?.content ? p.value?.loc.start.offset - node.loc.start.offset : undefined
};
}
}
else if (type === 'script' && p.name === 'setup') {
block.setup = attrs.setup;
}
}
});
return block;
}
//# sourceMappingURL=parseSfc.js.map

View File

@@ -0,0 +1,3 @@
export declare function getSlotsPropertyName(vueVersion: number): "$scopedSlots" | "$slots";
export { hyphenate as hyphenateTag } from '@vue/shared';
export declare function hyphenateAttr(str: string): string;

20
node_modules/@vue/language-core/lib/utils/shared.js generated vendored Normal file
View File

@@ -0,0 +1,20 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.hyphenateTag = void 0;
exports.getSlotsPropertyName = getSlotsPropertyName;
exports.hyphenateAttr = hyphenateAttr;
const shared_1 = require("@vue/shared");
function getSlotsPropertyName(vueVersion) {
return vueVersion < 3 ? '$scopedSlots' : '$slots';
}
var shared_2 = require("@vue/shared");
Object.defineProperty(exports, "hyphenateTag", { enumerable: true, get: function () { return shared_2.hyphenate; } });
function hyphenateAttr(str) {
let hyphencase = (0, shared_1.hyphenate)(str);
// fix https://github.com/vuejs/core/issues/8811
if (str.length && str[0] !== str[0].toLowerCase()) {
hyphencase = '-' + hyphencase;
}
return hyphencase;
}
//# sourceMappingURL=shared.js.map

14
node_modules/@vue/language-core/lib/utils/ts.d.ts generated vendored Normal file
View File

@@ -0,0 +1,14 @@
import type * as ts from 'typescript';
import type { VueCompilerOptions } from '../types';
export type ParsedCommandLine = ts.ParsedCommandLine & {
vueOptions: VueCompilerOptions;
};
export declare function createParsedCommandLineByJson(ts: typeof import('typescript'), parseConfigHost: ts.ParseConfigHost & {
writeFile?(path: string, data: string): void;
}, rootDir: string, json: any, configFileName?: string, skipGlobalTypesSetup?: boolean): ParsedCommandLine;
export declare function createParsedCommandLine(ts: typeof import('typescript'), parseConfigHost: ts.ParseConfigHost, tsConfigPath: string, skipGlobalTypesSetup?: boolean): ParsedCommandLine;
export declare function resolveVueCompilerOptions(vueOptions: Partial<VueCompilerOptions>): VueCompilerOptions;
export declare function setupGlobalTypes(rootDir: string, vueOptions: VueCompilerOptions, host: {
fileExists(path: string): boolean;
writeFile?(path: string, data: string): void;
}): VueCompilerOptions['__setupedGlobalTypes'];

243
node_modules/@vue/language-core/lib/utils/ts.js generated vendored Normal file
View File

@@ -0,0 +1,243 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createParsedCommandLineByJson = createParsedCommandLineByJson;
exports.createParsedCommandLine = createParsedCommandLine;
exports.resolveVueCompilerOptions = resolveVueCompilerOptions;
exports.setupGlobalTypes = setupGlobalTypes;
const shared_1 = require("@vue/shared");
const path_browserify_1 = require("path-browserify");
const languagePlugin_1 = require("../languagePlugin");
const globalTypes_1 = require("../codegen/globalTypes");
function createParsedCommandLineByJson(ts, parseConfigHost, rootDir, json, configFileName = rootDir + '/jsconfig.json', skipGlobalTypesSetup = false) {
const proxyHost = proxyParseConfigHostForExtendConfigPaths(parseConfigHost);
ts.parseJsonConfigFileContent(json, proxyHost.host, rootDir, {}, configFileName);
let vueOptions = {};
for (const extendPath of proxyHost.extendConfigPaths.reverse()) {
try {
vueOptions = {
...vueOptions,
...getPartialVueCompilerOptions(ts, ts.readJsonConfigFile(extendPath, proxyHost.host.readFile)),
};
}
catch (err) { }
}
const resolvedVueOptions = resolveVueCompilerOptions(vueOptions);
if (skipGlobalTypesSetup) {
resolvedVueOptions.__setupedGlobalTypes = true;
}
else {
resolvedVueOptions.__setupedGlobalTypes = setupGlobalTypes(rootDir, resolvedVueOptions, parseConfigHost);
}
const parsed = ts.parseJsonConfigFileContent(json, proxyHost.host, rootDir, {}, configFileName, undefined, (0, languagePlugin_1.getAllExtensions)(resolvedVueOptions)
.map(extension => ({
extension: extension.slice(1),
isMixedContent: true,
scriptKind: ts.ScriptKind.Deferred,
})));
// fix https://github.com/vuejs/language-tools/issues/1786
// https://github.com/microsoft/TypeScript/issues/30457
// patching ts server broke with outDir + rootDir + composite/incremental
parsed.options.outDir = undefined;
return {
...parsed,
vueOptions: resolvedVueOptions,
};
}
function createParsedCommandLine(ts, parseConfigHost, tsConfigPath, skipGlobalTypesSetup = false) {
try {
const proxyHost = proxyParseConfigHostForExtendConfigPaths(parseConfigHost);
const config = ts.readJsonConfigFile(tsConfigPath, proxyHost.host.readFile);
ts.parseJsonSourceFileConfigFileContent(config, proxyHost.host, path_browserify_1.posix.dirname(tsConfigPath), {}, tsConfigPath);
let vueOptions = {};
for (const extendPath of proxyHost.extendConfigPaths.reverse()) {
try {
vueOptions = {
...vueOptions,
...getPartialVueCompilerOptions(ts, ts.readJsonConfigFile(extendPath, proxyHost.host.readFile)),
};
}
catch (err) { }
}
const resolvedVueOptions = resolveVueCompilerOptions(vueOptions);
if (skipGlobalTypesSetup) {
resolvedVueOptions.__setupedGlobalTypes = true;
}
else {
resolvedVueOptions.__setupedGlobalTypes = setupGlobalTypes(path_browserify_1.posix.dirname(tsConfigPath), resolvedVueOptions, parseConfigHost);
}
const parsed = ts.parseJsonSourceFileConfigFileContent(config, proxyHost.host, path_browserify_1.posix.dirname(tsConfigPath), {}, tsConfigPath, undefined, (0, languagePlugin_1.getAllExtensions)(resolvedVueOptions)
.map(extension => ({
extension: extension.slice(1),
isMixedContent: true,
scriptKind: ts.ScriptKind.Deferred,
})));
// fix https://github.com/vuejs/language-tools/issues/1786
// https://github.com/microsoft/TypeScript/issues/30457
// patching ts server broke with outDir + rootDir + composite/incremental
parsed.options.outDir = undefined;
return {
...parsed,
vueOptions: resolvedVueOptions,
};
}
catch (err) {
// console.warn('Failed to resolve tsconfig path:', tsConfigPath, err);
return {
fileNames: [],
options: {},
vueOptions: resolveVueCompilerOptions({}),
errors: [],
};
}
}
function proxyParseConfigHostForExtendConfigPaths(parseConfigHost) {
const extendConfigPaths = [];
const host = new Proxy(parseConfigHost, {
get(target, key) {
if (key === 'readFile') {
return (fileName) => {
if (!fileName.endsWith('/package.json') && !extendConfigPaths.includes(fileName)) {
extendConfigPaths.push(fileName);
}
return target.readFile(fileName);
};
}
return target[key];
}
});
return {
host,
extendConfigPaths,
};
}
function getPartialVueCompilerOptions(ts, tsConfigSourceFile) {
const folder = path_browserify_1.posix.dirname(tsConfigSourceFile.fileName);
const obj = ts.convertToObject(tsConfigSourceFile, []);
const rawOptions = obj?.vueCompilerOptions ?? {};
const result = {
...rawOptions,
};
const target = rawOptions.target ?? 'auto';
if (target === 'auto') {
const resolvedPath = resolvePath('vue/package.json');
if (resolvedPath) {
const vuePackageJson = require(resolvedPath);
const versionNumbers = vuePackageJson.version.split('.');
result.target = Number(versionNumbers[0] + '.' + versionNumbers[1]);
}
else {
// console.warn('Load vue/package.json failed from', folder);
}
}
else {
result.target = target;
}
if (rawOptions.plugins) {
const plugins = rawOptions.plugins
.map((pluginPath) => {
try {
const resolvedPath = resolvePath(pluginPath);
if (resolvedPath) {
const plugin = require(resolvedPath);
plugin.__moduleName = pluginPath;
return plugin;
}
else {
console.warn('[Vue] Load plugin failed:', pluginPath);
}
}
catch (error) {
console.warn('[Vue] Resolve plugin path failed:', pluginPath, error);
}
return [];
});
result.plugins = plugins;
}
return result;
function resolvePath(scriptPath) {
try {
if (require?.resolve) {
return require.resolve(scriptPath, { paths: [folder] });
}
else {
// console.warn('failed to resolve path:', scriptPath, 'require.resolve is not supported in web');
}
}
catch (error) {
// console.warn(error);
}
}
}
function resolveVueCompilerOptions(vueOptions) {
const target = vueOptions.target ?? 3.3;
const lib = vueOptions.lib ?? 'vue';
return {
...vueOptions,
target,
extensions: vueOptions.extensions ?? ['.vue'],
vitePressExtensions: vueOptions.vitePressExtensions ?? [],
petiteVueExtensions: vueOptions.petiteVueExtensions ?? [],
lib,
jsxSlots: vueOptions.jsxSlots ?? false,
strictTemplates: vueOptions.strictTemplates ?? false,
skipTemplateCodegen: vueOptions.skipTemplateCodegen ?? false,
fallthroughAttributes: vueOptions.fallthroughAttributes ?? false,
dataAttributes: vueOptions.dataAttributes ?? [],
htmlAttributes: vueOptions.htmlAttributes ?? ['aria-*'],
optionsWrapper: vueOptions.optionsWrapper ?? (target >= 2.7
? [`(await import('${lib}')).defineComponent(`, `)`]
: [`(await import('${lib}')).default.extend(`, `)`]),
macros: {
defineProps: ['defineProps'],
defineSlots: ['defineSlots'],
defineEmits: ['defineEmits'],
defineExpose: ['defineExpose'],
defineModel: ['defineModel'],
defineOptions: ['defineOptions'],
withDefaults: ['withDefaults'],
...vueOptions.macros,
},
composibles: {
useCssModule: ['useCssModule'],
useTemplateRef: ['useTemplateRef', 'templateRef'],
...vueOptions.composibles,
},
plugins: vueOptions.plugins ?? [],
// experimental
experimentalDefinePropProposal: vueOptions.experimentalDefinePropProposal ?? false,
experimentalResolveStyleCssClasses: vueOptions.experimentalResolveStyleCssClasses ?? 'scoped',
// 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: Object.fromEntries(Object.entries(vueOptions.experimentalModelPropName ?? {
'': {
input: true
},
value: {
input: { type: 'text' },
textarea: true,
select: true
}
}).map(([k, v]) => [(0, shared_1.camelize)(k), v])),
};
}
function setupGlobalTypes(rootDir, vueOptions, host) {
if (!host.writeFile) {
return;
}
try {
let dir = rootDir;
while (!host.fileExists(path_browserify_1.posix.join(dir, 'node_modules', vueOptions.lib, 'package.json'))) {
const parentDir = path_browserify_1.posix.dirname(dir);
if (dir === parentDir) {
throw 0;
}
dir = parentDir;
}
const globalTypesPath = path_browserify_1.posix.join(dir, 'node_modules', '.vue-global-types', `${vueOptions.lib}_${vueOptions.target}_${vueOptions.strictTemplates}.d.ts`);
const globalTypesContents = `// @ts-nocheck\nexport {};\n` + (0, globalTypes_1.generateGlobalTypes)(vueOptions.lib, vueOptions.target, vueOptions.strictTemplates);
host.writeFile(globalTypesPath, globalTypesContents);
return { absolutePath: globalTypesPath };
}
catch { }
}
//# sourceMappingURL=ts.js.map

View File

@@ -0,0 +1,2 @@
import * as CompilerDOM from '@vue/compiler-dom';
export declare const compile: typeof CompilerDOM.compile;

View File

@@ -0,0 +1,89 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.compile = void 0;
const CompilerDOM = require("@vue/compiler-dom");
const Vue2TemplateCompiler = require('@vue/compiler-vue2/build');
const compile = (template, options = {}) => {
if (typeof template !== 'string') {
throw new Error(`[@vue/language-core] compile() first argument must be string.`);
}
const onError = options.onError;
const onWarn = options.onWarn;
options.onError = error => {
if (error.code === 33 // :key binding allowed in v-for template child in vue 2
|| error.code === 29 // fix https://github.com/vuejs/language-tools/issues/1638
) {
return;
}
if (onError) {
onError(error);
}
else {
throw error;
}
};
const vue2Result = Vue2TemplateCompiler.compile(template, { outputSourceRange: true });
for (const error of vue2Result.errors) {
onError?.({
code: 'vue-template-compiler',
name: '',
message: error.msg,
loc: {
source: '',
start: { column: -1, line: -1, offset: error.start },
end: { column: -1, line: -1, offset: error.end ?? error.start },
},
});
}
for (const error of vue2Result.tips) {
onWarn?.({
code: 'vue-template-compiler',
name: '',
message: error.msg,
loc: {
source: '',
start: { column: -1, line: -1, offset: error.start },
end: { column: -1, line: -1, offset: error.end ?? error.start },
},
});
}
return baseCompile(template, Object.assign({}, CompilerDOM.parserOptions, options, {
nodeTransforms: [
...CompilerDOM.DOMNodeTransforms,
...(options.nodeTransforms || [])
],
directiveTransforms: Object.assign({}, CompilerDOM.DOMDirectiveTransforms, options.directiveTransforms || {}),
}));
};
exports.compile = compile;
function baseCompile(template, options = {}) {
const onError = options.onError || (error => { throw error; });
const isModuleMode = options.mode === 'module';
const prefixIdentifiers = options.prefixIdentifiers === true || isModuleMode;
if (!prefixIdentifiers && options.cacheHandlers) {
onError(CompilerDOM.createCompilerError(49));
}
if (options.scopeId && !isModuleMode) {
onError(CompilerDOM.createCompilerError(50));
}
const ast = CompilerDOM.baseParse(template, options);
const [nodeTransforms, directiveTransforms] = CompilerDOM.getBaseTransformPreset(prefixIdentifiers);
// v-for > v-if in vue 2
const transformIf = nodeTransforms[1];
const transformFor = nodeTransforms[3];
nodeTransforms[1] = transformFor;
nodeTransforms[3] = transformIf;
CompilerDOM.transform(ast, Object.assign({}, options, {
prefixIdentifiers,
nodeTransforms: [
...nodeTransforms,
...(options.nodeTransforms || []) // user transforms
],
directiveTransforms: Object.assign({}, directiveTransforms, options.directiveTransforms || {} // user transforms
)
}));
return CompilerDOM.generate(ast, Object.assign({}, options, {
prefixIdentifiers
}));
}
//# sourceMappingURL=vue2TemplateCompiler.js.map