@vue/language-core 2.0.14 → 2.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/codegen/script/component.d.ts +1 -1
- package/lib/codegen/script/component.js +12 -4
- package/lib/codegen/script/globalTypes.js +1 -1
- package/lib/codegen/script/internalComponent.js +1 -1
- package/lib/codegen/script/scriptSetup.js +52 -19
- package/lib/codegen/script/template.js +5 -2
- package/lib/codegen/template/context.js +0 -1
- package/lib/codegen/template/element.d.ts +2 -1
- package/lib/codegen/template/element.js +101 -48
- package/lib/codegen/template/elementChildren.d.ts +2 -2
- package/lib/codegen/template/elementChildren.js +9 -3
- package/lib/codegen/template/elementEvents.d.ts +2 -0
- package/lib/codegen/template/elementEvents.js +47 -31
- package/lib/codegen/template/elementProps.js +33 -8
- package/lib/codegen/template/index.d.ts +10 -10
- package/lib/codegen/template/index.js +12 -99
- package/lib/codegen/template/slotOutlet.d.ts +1 -1
- package/lib/codegen/template/slotOutlet.js +31 -32
- package/lib/codegen/template/templateChild.d.ts +1 -1
- package/lib/codegen/template/templateChild.js +14 -10
- package/lib/codegen/template/vFor.d.ts +1 -1
- package/lib/codegen/template/vFor.js +2 -2
- package/lib/codegen/template/vIf.d.ts +1 -1
- package/lib/codegen/template/vIf.js +2 -2
- package/lib/languageModule.d.ts +1 -2
- package/lib/languageModule.js +30 -12
- package/lib/parsers/scriptSetupRanges.d.ts +1 -0
- package/lib/parsers/scriptSetupRanges.js +6 -1
- package/lib/plugins/file-html.js +63 -66
- package/lib/plugins/file-md.js +47 -50
- package/lib/plugins/vue-tsx.d.ts +1 -0
- package/lib/plugins.d.ts +3 -2
- package/lib/plugins.js +18 -9
- package/lib/types.d.ts +3 -0
- package/lib/utils/ts.js +20 -3
- package/lib/virtualFile/computedFiles.d.ts +1 -0
- package/lib/virtualFile/computedFiles.js +51 -34
- package/package.json +3 -3
package/lib/plugins/file-html.js
CHANGED
|
@@ -6,74 +6,71 @@ const plugin = () => {
|
|
|
6
6
|
return {
|
|
7
7
|
version: 2,
|
|
8
8
|
parseSFC(fileName, content) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
// ignore `<script src="...">`
|
|
47
|
-
else if (tag === 'script' && attrs.indexOf('src=') === -1) {
|
|
48
|
-
let type = attrs.indexOf('type=') >= 0 ? 'scriptSetup' : 'script';
|
|
49
|
-
sfc.descriptor[type] = {
|
|
50
|
-
attrs: {},
|
|
51
|
-
content,
|
|
52
|
-
loc: {
|
|
53
|
-
start: { column: -1, line: -1, offset: contentStart },
|
|
54
|
-
end: { column: -1, line: -1, offset: contentStart + content.length },
|
|
55
|
-
source: content,
|
|
56
|
-
},
|
|
57
|
-
type: 'script',
|
|
58
|
-
lang,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
templateContent = templateContent.substring(0, match.index) + ' '.repeat(matchText.length) + templateContent.substring(match.index + matchText.length);
|
|
9
|
+
let sfc = {
|
|
10
|
+
descriptor: {
|
|
11
|
+
filename: fileName,
|
|
12
|
+
source: content,
|
|
13
|
+
template: null,
|
|
14
|
+
script: null,
|
|
15
|
+
scriptSetup: null,
|
|
16
|
+
styles: [],
|
|
17
|
+
customBlocks: [],
|
|
18
|
+
cssVars: [],
|
|
19
|
+
shouldForceReload: () => false,
|
|
20
|
+
slotted: false,
|
|
21
|
+
},
|
|
22
|
+
errors: [],
|
|
23
|
+
};
|
|
24
|
+
let templateContent = content;
|
|
25
|
+
for (const match of content.matchAll(sfcBlockReg)) {
|
|
26
|
+
const matchText = match[0];
|
|
27
|
+
const tag = match[1];
|
|
28
|
+
const attrs = match[2];
|
|
29
|
+
const lang = attrs.match(langReg)?.[2];
|
|
30
|
+
const content = match[3];
|
|
31
|
+
const contentStart = match.index + matchText.indexOf(content);
|
|
32
|
+
if (tag === 'style') {
|
|
33
|
+
sfc.descriptor.styles.push({
|
|
34
|
+
attrs: {},
|
|
35
|
+
content,
|
|
36
|
+
loc: {
|
|
37
|
+
start: { column: -1, line: -1, offset: contentStart },
|
|
38
|
+
end: { column: -1, line: -1, offset: contentStart + content.length },
|
|
39
|
+
source: content,
|
|
40
|
+
},
|
|
41
|
+
type: 'style',
|
|
42
|
+
lang,
|
|
43
|
+
});
|
|
62
44
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
45
|
+
// ignore `<script src="...">`
|
|
46
|
+
else if (tag === 'script' && attrs.indexOf('src=') === -1) {
|
|
47
|
+
let type = attrs.indexOf('type=') >= 0 ? 'scriptSetup' : 'script';
|
|
48
|
+
sfc.descriptor[type] = {
|
|
49
|
+
attrs: {},
|
|
50
|
+
content,
|
|
51
|
+
loc: {
|
|
52
|
+
start: { column: -1, line: -1, offset: contentStart },
|
|
53
|
+
end: { column: -1, line: -1, offset: contentStart + content.length },
|
|
54
|
+
source: content,
|
|
55
|
+
},
|
|
56
|
+
type: 'script',
|
|
57
|
+
lang,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
templateContent = templateContent.substring(0, match.index) + ' '.repeat(matchText.length) + templateContent.substring(match.index + matchText.length);
|
|
75
61
|
}
|
|
76
|
-
|
|
62
|
+
sfc.descriptor.template = {
|
|
63
|
+
attrs: {},
|
|
64
|
+
content: templateContent,
|
|
65
|
+
loc: {
|
|
66
|
+
start: { column: -1, line: -1, offset: 0 },
|
|
67
|
+
end: { column: -1, line: -1, offset: templateContent.length },
|
|
68
|
+
source: templateContent,
|
|
69
|
+
},
|
|
70
|
+
type: 'template',
|
|
71
|
+
ast: {},
|
|
72
|
+
};
|
|
73
|
+
return sfc;
|
|
77
74
|
}
|
|
78
75
|
};
|
|
79
76
|
};
|
package/lib/plugins/file-md.js
CHANGED
|
@@ -12,58 +12,55 @@ const codeSnippetImportReg = /^\s*<<<\s*.+/gm;
|
|
|
12
12
|
const plugin = () => {
|
|
13
13
|
return {
|
|
14
14
|
version: 2,
|
|
15
|
-
parseSFC(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
content = content.substring(0, match.index) + ' '.repeat(matchText.length) + content.substring(match.index + matchText.length);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
content = content
|
|
36
|
-
// angle bracket: <http://foo.com>
|
|
37
|
-
.replace(angleBracketReg, match => ' '.repeat(match.length))
|
|
38
|
-
// [foo](http://foo.com)
|
|
39
|
-
.replace(linkReg, match => ' '.repeat(match.length));
|
|
40
|
-
codes.push('<template>\n');
|
|
41
|
-
codes.push([content, undefined, 0]);
|
|
42
|
-
codes.push('\n</template>');
|
|
43
|
-
const file2VueSourceMap = new language_core_1.SourceMap((0, language_core_1.buildMappings)(codes));
|
|
44
|
-
const sfc = (0, parseSfc_1.parse)((0, language_core_1.toString)(codes));
|
|
45
|
-
if (sfc.descriptor.template) {
|
|
46
|
-
transformRange(sfc.descriptor.template);
|
|
47
|
-
}
|
|
48
|
-
if (sfc.descriptor.script) {
|
|
49
|
-
transformRange(sfc.descriptor.script);
|
|
50
|
-
}
|
|
51
|
-
if (sfc.descriptor.scriptSetup) {
|
|
52
|
-
transformRange(sfc.descriptor.scriptSetup);
|
|
53
|
-
}
|
|
54
|
-
for (const style of sfc.descriptor.styles) {
|
|
55
|
-
transformRange(style);
|
|
56
|
-
}
|
|
57
|
-
for (const customBlock of sfc.descriptor.customBlocks) {
|
|
58
|
-
transformRange(customBlock);
|
|
59
|
-
}
|
|
60
|
-
return sfc;
|
|
61
|
-
function transformRange(block) {
|
|
62
|
-
block.loc.start.offset = file2VueSourceMap.getSourceOffset(block.loc.start.offset)?.[0] ?? -1;
|
|
63
|
-
block.loc.end.offset = file2VueSourceMap.getSourceOffset(block.loc.end.offset)?.[0] ?? -1;
|
|
15
|
+
parseSFC(_fileName, content) {
|
|
16
|
+
content = content
|
|
17
|
+
// code block
|
|
18
|
+
.replace(codeblockReg, (match, quotes) => quotes + ' '.repeat(match.length - quotes.length * 2) + quotes)
|
|
19
|
+
// inline code block
|
|
20
|
+
.replace(inlineCodeblockReg, match => `\`${' '.repeat(match.length - 2)}\``)
|
|
21
|
+
// # \<script setup>
|
|
22
|
+
.replace(scriptSetupReg, match => ' '.repeat(match.length))
|
|
23
|
+
// <<< https://vitepress.dev/guide/markdown#import-code-snippets
|
|
24
|
+
.replace(codeSnippetImportReg, match => ' '.repeat(match.length));
|
|
25
|
+
const codes = [];
|
|
26
|
+
for (const match of content.matchAll(sfcBlockReg)) {
|
|
27
|
+
if (match.index !== undefined) {
|
|
28
|
+
const matchText = match[0];
|
|
29
|
+
codes.push([matchText, undefined, match.index]);
|
|
30
|
+
codes.push('\n\n');
|
|
31
|
+
content = content.substring(0, match.index) + ' '.repeat(matchText.length) + content.substring(match.index + matchText.length);
|
|
64
32
|
}
|
|
65
33
|
}
|
|
66
|
-
|
|
34
|
+
content = content
|
|
35
|
+
// angle bracket: <http://foo.com>
|
|
36
|
+
.replace(angleBracketReg, match => ' '.repeat(match.length))
|
|
37
|
+
// [foo](http://foo.com)
|
|
38
|
+
.replace(linkReg, match => ' '.repeat(match.length));
|
|
39
|
+
codes.push('<template>\n');
|
|
40
|
+
codes.push([content, undefined, 0]);
|
|
41
|
+
codes.push('\n</template>');
|
|
42
|
+
const file2VueSourceMap = new language_core_1.SourceMap((0, language_core_1.buildMappings)(codes));
|
|
43
|
+
const sfc = (0, parseSfc_1.parse)((0, language_core_1.toString)(codes));
|
|
44
|
+
if (sfc.descriptor.template) {
|
|
45
|
+
transformRange(sfc.descriptor.template);
|
|
46
|
+
}
|
|
47
|
+
if (sfc.descriptor.script) {
|
|
48
|
+
transformRange(sfc.descriptor.script);
|
|
49
|
+
}
|
|
50
|
+
if (sfc.descriptor.scriptSetup) {
|
|
51
|
+
transformRange(sfc.descriptor.scriptSetup);
|
|
52
|
+
}
|
|
53
|
+
for (const style of sfc.descriptor.styles) {
|
|
54
|
+
transformRange(style);
|
|
55
|
+
}
|
|
56
|
+
for (const customBlock of sfc.descriptor.customBlocks) {
|
|
57
|
+
transformRange(customBlock);
|
|
58
|
+
}
|
|
59
|
+
return sfc;
|
|
60
|
+
function transformRange(block) {
|
|
61
|
+
block.loc.start.offset = file2VueSourceMap.getSourceOffset(block.loc.start.offset)?.[0] ?? -1;
|
|
62
|
+
block.loc.end.offset = file2VueSourceMap.getSourceOffset(block.loc.end.offset)?.[0] ?? -1;
|
|
63
|
+
}
|
|
67
64
|
}
|
|
68
65
|
};
|
|
69
66
|
};
|
package/lib/plugins/vue-tsx.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
30
30
|
};
|
|
31
31
|
slots: {
|
|
32
32
|
name?: string | undefined;
|
|
33
|
+
isObjectBindingPattern?: boolean | undefined;
|
|
33
34
|
define?: (import("../types").TextRange & {
|
|
34
35
|
arg?: import("../types").TextRange | undefined;
|
|
35
36
|
typeArg?: import("../types").TextRange | undefined;
|
package/lib/plugins.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type VueLanguagePlugin } from './types';
|
|
2
|
-
export
|
|
2
|
+
export * from './plugins/shared';
|
|
3
|
+
export declare function getBasePlugins(pluginContext: Parameters<VueLanguagePlugin>[0]): {
|
|
3
4
|
version: 2;
|
|
4
5
|
name?: string | undefined;
|
|
5
6
|
order?: number | undefined;
|
|
@@ -21,5 +22,5 @@ export declare function getDefaultVueLanguagePlugins(pluginContext: Parameters<V
|
|
|
21
22
|
id: string;
|
|
22
23
|
lang: string;
|
|
23
24
|
}[];
|
|
24
|
-
resolveEmbeddedCode?(fileName: string, sfc: import("./types").Sfc, embeddedFile: import("./
|
|
25
|
+
resolveEmbeddedCode?(fileName: string, sfc: import("./types").Sfc, embeddedFile: import("./types").VueEmbeddedCode): void;
|
|
25
26
|
}[];
|
package/lib/plugins.js
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const file_html_1 = require("./plugins/file-html");
|
|
5
|
-
const file_md_1 = require("./plugins/file-md");
|
|
6
|
-
const file_vue_1 = require("./plugins/file-vue");
|
|
17
|
+
exports.getBasePlugins = void 0;
|
|
7
18
|
const vue_sfc_customblocks_1 = require("./plugins/vue-sfc-customblocks");
|
|
8
19
|
const vue_sfc_scripts_1 = require("./plugins/vue-sfc-scripts");
|
|
9
20
|
const vue_sfc_styles_1 = require("./plugins/vue-sfc-styles");
|
|
@@ -13,11 +24,9 @@ const vue_template_inline_css_1 = require("./plugins/vue-template-inline-css");
|
|
|
13
24
|
const vue_template_inline_ts_1 = require("./plugins/vue-template-inline-ts");
|
|
14
25
|
const vue_tsx_1 = require("./plugins/vue-tsx");
|
|
15
26
|
const types_1 = require("./types");
|
|
16
|
-
|
|
27
|
+
__exportStar(require("./plugins/shared"), exports);
|
|
28
|
+
function getBasePlugins(pluginContext) {
|
|
17
29
|
const plugins = [
|
|
18
|
-
file_md_1.default, // .md for VitePress
|
|
19
|
-
file_html_1.default, // .html for PetiteVue
|
|
20
|
-
file_vue_1.default, // .vue and others for Vue
|
|
21
30
|
vue_template_html_1.default,
|
|
22
31
|
vue_template_inline_css_1.default,
|
|
23
32
|
vue_template_inline_ts_1.default,
|
|
@@ -53,5 +62,5 @@ function getDefaultVueLanguagePlugins(pluginContext) {
|
|
|
53
62
|
return valid;
|
|
54
63
|
});
|
|
55
64
|
}
|
|
56
|
-
exports.
|
|
65
|
+
exports.getBasePlugins = getBasePlugins;
|
|
57
66
|
//# sourceMappingURL=plugins.js.map
|
package/lib/types.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type * as ts from 'typescript';
|
|
|
4
4
|
import type { VueEmbeddedCode } from './virtualFile/embeddedFile';
|
|
5
5
|
import type { CodeInformation, Segment } from '@volar/language-core';
|
|
6
6
|
export type { SFCParseResult } from '@vue/compiler-sfc';
|
|
7
|
+
export { VueEmbeddedCode };
|
|
7
8
|
export type RawVueCompilerOptions = Partial<Omit<VueCompilerOptions, 'target' | 'plugins'>> & {
|
|
8
9
|
target?: 'auto' | 2 | 2.7 | 3 | 3.3;
|
|
9
10
|
plugins?: string[];
|
|
@@ -26,6 +27,8 @@ export interface VueCompilerOptions {
|
|
|
26
27
|
target: number;
|
|
27
28
|
lib: string;
|
|
28
29
|
extensions: string[];
|
|
30
|
+
vitePressExtensions: string[];
|
|
31
|
+
petiteVueExtensions: string[];
|
|
29
32
|
jsxSlots: boolean;
|
|
30
33
|
strictTemplates: boolean;
|
|
31
34
|
skipTemplateCodegen: boolean;
|
package/lib/utils/ts.js
CHANGED
|
@@ -16,7 +16,11 @@ function createParsedCommandLineByJson(ts, parseConfigHost, rootDir, json, confi
|
|
|
16
16
|
catch (err) { }
|
|
17
17
|
}
|
|
18
18
|
const resolvedVueOptions = resolveVueCompilerOptions(vueOptions);
|
|
19
|
-
const parsed = ts.parseJsonConfigFileContent(json, proxyHost.host, rootDir, {}, configFileName, undefined,
|
|
19
|
+
const parsed = ts.parseJsonConfigFileContent(json, proxyHost.host, rootDir, {}, configFileName, undefined, [
|
|
20
|
+
...resolvedVueOptions.extensions,
|
|
21
|
+
...resolvedVueOptions.vitePressExtensions,
|
|
22
|
+
...resolvedVueOptions.petiteVueExtensions,
|
|
23
|
+
].map(extension => ({
|
|
20
24
|
extension: extension.slice(1),
|
|
21
25
|
isMixedContent: true,
|
|
22
26
|
scriptKind: ts.ScriptKind.Deferred,
|
|
@@ -47,7 +51,11 @@ function createParsedCommandLine(ts, parseConfigHost, tsConfigPath) {
|
|
|
47
51
|
catch (err) { }
|
|
48
52
|
}
|
|
49
53
|
const resolvedVueOptions = resolveVueCompilerOptions(vueOptions);
|
|
50
|
-
const parsed = ts.parseJsonSourceFileConfigFileContent(config, proxyHost.host, path.dirname(tsConfigPath), {}, tsConfigPath, undefined,
|
|
54
|
+
const parsed = ts.parseJsonSourceFileConfigFileContent(config, proxyHost.host, path.dirname(tsConfigPath), {}, tsConfigPath, undefined, [
|
|
55
|
+
...resolvedVueOptions.extensions,
|
|
56
|
+
...resolvedVueOptions.vitePressExtensions,
|
|
57
|
+
...resolvedVueOptions.petiteVueExtensions,
|
|
58
|
+
].map(extension => ({
|
|
51
59
|
extension: extension.slice(1),
|
|
52
60
|
isMixedContent: true,
|
|
53
61
|
scriptKind: ts.ScriptKind.Deferred,
|
|
@@ -121,7 +129,14 @@ function getPartialVueCompilerOptions(ts, tsConfigSourceFile) {
|
|
|
121
129
|
const resolvedPath = resolvePath(pluginPath);
|
|
122
130
|
if (resolvedPath) {
|
|
123
131
|
const plugin = require(resolvedPath);
|
|
124
|
-
plugin
|
|
132
|
+
if (Array.isArray(plugin)) {
|
|
133
|
+
for (let i = 0; i < plugin.length; i++) {
|
|
134
|
+
plugin[i].__moduleName = `${pluginPath} (${i})`;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
plugin.__moduleName = pluginPath;
|
|
139
|
+
}
|
|
125
140
|
return plugin;
|
|
126
141
|
}
|
|
127
142
|
else {
|
|
@@ -158,6 +173,8 @@ function resolveVueCompilerOptions(vueOptions) {
|
|
|
158
173
|
...vueOptions,
|
|
159
174
|
target,
|
|
160
175
|
extensions: vueOptions.extensions ?? ['.vue'],
|
|
176
|
+
vitePressExtensions: vueOptions.vitePressExtensions ?? [],
|
|
177
|
+
petiteVueExtensions: vueOptions.petiteVueExtensions ?? [],
|
|
161
178
|
lib,
|
|
162
179
|
jsxSlots: vueOptions.jsxSlots ?? false,
|
|
163
180
|
strictTemplates: vueOptions.strictTemplates ?? false,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { VirtualCode } from '@volar/language-core';
|
|
2
2
|
import type { Sfc, VueLanguagePlugin } from '../types';
|
|
3
3
|
export declare function computedFiles(plugins: ReturnType<VueLanguagePlugin>[], fileName: string, sfc: Sfc): () => VirtualCode[];
|
|
4
|
+
export declare function resolveCommonLanguageId(lang: string): string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.computedFiles = void 0;
|
|
3
|
+
exports.resolveCommonLanguageId = exports.computedFiles = void 0;
|
|
4
4
|
const language_core_1 = require("@volar/language-core");
|
|
5
5
|
const computeds_1 = require("computeds");
|
|
6
6
|
const embeddedFile_1 = require("./embeddedFile");
|
|
@@ -24,7 +24,7 @@ function computedFiles(plugins, fileName, sfc) {
|
|
|
24
24
|
}
|
|
25
25
|
return blocks;
|
|
26
26
|
});
|
|
27
|
-
const pluginsResult = plugins.map(plugin =>
|
|
27
|
+
const pluginsResult = plugins.map(plugin => computedPluginEmbeddedCodes(plugins, plugin, fileName, sfc, nameToBlock));
|
|
28
28
|
const flatResult = (0, computeds_1.computed)(() => pluginsResult.map(r => r()).flat());
|
|
29
29
|
const structuredResult = (0, computeds_1.computed)(() => {
|
|
30
30
|
const embeddedCodes = [];
|
|
@@ -36,18 +36,18 @@ function computedFiles(plugins, fileName, sfc) {
|
|
|
36
36
|
break;
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
for (const {
|
|
40
|
-
console.error('Unable to resolve embedded: ' +
|
|
39
|
+
for (const { code } of remain) {
|
|
40
|
+
console.error('Unable to resolve embedded: ' + code.parentCodeId + ' -> ' + code.id);
|
|
41
41
|
}
|
|
42
42
|
return embeddedCodes;
|
|
43
43
|
function consumeRemain() {
|
|
44
44
|
for (let i = remain.length - 1; i >= 0; i--) {
|
|
45
|
-
const {
|
|
46
|
-
if (!
|
|
45
|
+
const { code, snapshot, mappings } = remain[i];
|
|
46
|
+
if (!code.parentCodeId) {
|
|
47
47
|
embeddedCodes.push({
|
|
48
|
-
id:
|
|
49
|
-
languageId:
|
|
50
|
-
linkedCodeMappings:
|
|
48
|
+
id: code.id,
|
|
49
|
+
languageId: resolveCommonLanguageId(code.lang),
|
|
50
|
+
linkedCodeMappings: code.linkedCodeMappings,
|
|
51
51
|
snapshot,
|
|
52
52
|
mappings,
|
|
53
53
|
embeddedCodes: [],
|
|
@@ -55,13 +55,13 @@ function computedFiles(plugins, fileName, sfc) {
|
|
|
55
55
|
remain.splice(i, 1);
|
|
56
56
|
}
|
|
57
57
|
else {
|
|
58
|
-
const parent = findParentStructure(
|
|
58
|
+
const parent = findParentStructure(code.parentCodeId, embeddedCodes);
|
|
59
59
|
if (parent) {
|
|
60
60
|
parent.embeddedCodes ??= [];
|
|
61
61
|
parent.embeddedCodes.push({
|
|
62
|
-
id:
|
|
63
|
-
languageId:
|
|
64
|
-
linkedCodeMappings:
|
|
62
|
+
id: code.id,
|
|
63
|
+
languageId: resolveCommonLanguageId(code.lang),
|
|
64
|
+
linkedCodeMappings: code.linkedCodeMappings,
|
|
65
65
|
snapshot,
|
|
66
66
|
mappings,
|
|
67
67
|
embeddedCodes: [],
|
|
@@ -86,36 +86,37 @@ function computedFiles(plugins, fileName, sfc) {
|
|
|
86
86
|
return structuredResult;
|
|
87
87
|
}
|
|
88
88
|
exports.computedFiles = computedFiles;
|
|
89
|
-
function
|
|
90
|
-
const
|
|
91
|
-
const
|
|
89
|
+
function computedPluginEmbeddedCodes(plugins, plugin, fileName, sfc, nameToBlock) {
|
|
90
|
+
const computeds = new Map();
|
|
91
|
+
const getComputedKey = (code) => code.id + '__' + code.lang;
|
|
92
|
+
const codes = (0, computeds_1.computed)(() => {
|
|
92
93
|
try {
|
|
93
94
|
if (!plugin.getEmbeddedCodes) {
|
|
94
|
-
return
|
|
95
|
+
return [...computeds.values()];
|
|
95
96
|
}
|
|
96
|
-
const
|
|
97
|
-
for (const oldId of
|
|
98
|
-
if (!
|
|
99
|
-
delete
|
|
97
|
+
const embeddedCodeInfos = plugin.getEmbeddedCodes(fileName, sfc);
|
|
98
|
+
for (const oldId of computeds.keys()) {
|
|
99
|
+
if (!embeddedCodeInfos.some(code => getComputedKey(code) === oldId)) {
|
|
100
|
+
computeds.delete(oldId);
|
|
100
101
|
}
|
|
101
102
|
}
|
|
102
|
-
for (const
|
|
103
|
-
if (!
|
|
104
|
-
|
|
103
|
+
for (const codeInfo of embeddedCodeInfos) {
|
|
104
|
+
if (!computeds.has(getComputedKey(codeInfo))) {
|
|
105
|
+
computeds.set(getComputedKey(codeInfo), (0, computeds_1.computed)(() => {
|
|
105
106
|
const content = [];
|
|
106
|
-
const
|
|
107
|
+
const code = new embeddedFile_1.VueEmbeddedCode(codeInfo.id, codeInfo.lang, content);
|
|
107
108
|
for (const plugin of plugins) {
|
|
108
109
|
if (!plugin.resolveEmbeddedCode) {
|
|
109
110
|
continue;
|
|
110
111
|
}
|
|
111
112
|
try {
|
|
112
|
-
plugin.resolveEmbeddedCode(fileName, sfc,
|
|
113
|
+
plugin.resolveEmbeddedCode(fileName, sfc, code);
|
|
113
114
|
}
|
|
114
115
|
catch (e) {
|
|
115
116
|
console.error(e);
|
|
116
117
|
}
|
|
117
118
|
}
|
|
118
|
-
const newText = (0, language_core_1.toString)(
|
|
119
|
+
const newText = (0, language_core_1.toString)(code.content);
|
|
119
120
|
const changeRanges = new Map();
|
|
120
121
|
const snapshot = {
|
|
121
122
|
getText: (start, end) => newText.slice(start, end),
|
|
@@ -133,22 +134,22 @@ function computedPluginFiles(plugins, plugin, fileName, sfc, nameToBlock) {
|
|
|
133
134
|
},
|
|
134
135
|
};
|
|
135
136
|
return {
|
|
136
|
-
|
|
137
|
+
code,
|
|
137
138
|
snapshot,
|
|
138
139
|
};
|
|
139
|
-
});
|
|
140
|
+
}));
|
|
140
141
|
}
|
|
141
142
|
}
|
|
142
143
|
}
|
|
143
144
|
catch (e) {
|
|
144
145
|
console.error(e);
|
|
145
146
|
}
|
|
146
|
-
return
|
|
147
|
+
return [...computeds.values()];
|
|
147
148
|
});
|
|
148
149
|
return (0, computeds_1.computed)(() => {
|
|
149
|
-
return
|
|
150
|
-
const {
|
|
151
|
-
const mappings = (0, language_core_1.buildMappings)(
|
|
150
|
+
return codes().map(_file => {
|
|
151
|
+
const { code, snapshot } = _file();
|
|
152
|
+
const mappings = (0, language_core_1.buildMappings)(code.content);
|
|
152
153
|
const newMappings = [];
|
|
153
154
|
let lastValidMapping;
|
|
154
155
|
for (let i = 0; i < mappings.length; i++) {
|
|
@@ -185,7 +186,7 @@ function computedPluginFiles(plugins, plugin, fileName, sfc, nameToBlock) {
|
|
|
185
186
|
newMappings.push(mapping);
|
|
186
187
|
}
|
|
187
188
|
return {
|
|
188
|
-
|
|
189
|
+
code,
|
|
189
190
|
snapshot,
|
|
190
191
|
mappings: newMappings,
|
|
191
192
|
};
|
|
@@ -215,4 +216,20 @@ function fullDiffTextChangeRange(oldText, newText) {
|
|
|
215
216
|
}
|
|
216
217
|
}
|
|
217
218
|
}
|
|
219
|
+
function resolveCommonLanguageId(lang) {
|
|
220
|
+
switch (lang) {
|
|
221
|
+
case 'js': return 'javascript';
|
|
222
|
+
case 'cjs': return 'javascript';
|
|
223
|
+
case 'mjs': return 'javascript';
|
|
224
|
+
case 'ts': return 'typescript';
|
|
225
|
+
case 'cts': return 'typescript';
|
|
226
|
+
case 'mts': return 'typescript';
|
|
227
|
+
case 'jsx': return 'javascriptreact';
|
|
228
|
+
case 'tsx': return 'typescriptreact';
|
|
229
|
+
case 'pug': return 'jade';
|
|
230
|
+
case 'md': return 'markdown';
|
|
231
|
+
}
|
|
232
|
+
return lang;
|
|
233
|
+
}
|
|
234
|
+
exports.resolveCommonLanguageId = resolveCommonLanguageId;
|
|
218
235
|
//# sourceMappingURL=computedFiles.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/language-core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.16",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"directory": "packages/language-core"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@volar/language-core": "2.2.0
|
|
15
|
+
"@volar/language-core": "~2.2.0",
|
|
16
16
|
"@vue/compiler-dom": "^3.4.0",
|
|
17
17
|
"@vue/shared": "^3.4.0",
|
|
18
18
|
"computeds": "^0.0.1",
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"optional": true
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "95b78c38cbf75481ebb59e11956b592346f01d92"
|
|
38
38
|
}
|