@vue/language-core 1.8.5 → 1.8.7
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/out/generators/script.js +7 -5
- package/out/generators/template.js +3 -3
- package/out/index.d.ts +1 -0
- package/out/index.js +3 -1
- package/out/languageModule.d.ts +4 -1
- package/out/languageModule.js +57 -30
- package/out/parsers/scriptSetupRanges.d.ts +1 -0
- package/out/parsers/scriptSetupRanges.js +4 -1
- package/out/plugins/vue-tsx.d.ts +56 -1
- package/out/plugins/vue-tsx.js +45 -38
- package/out/plugins.d.ts +1 -0
- package/out/sourceFile.d.ts +1 -0
- package/out/sourceFile.js +6 -1
- package/out/types.d.ts +1 -0
- package/out/utils/globalTypes.js +1 -1
- package/out/utils/transform.js +1 -1
- package/package.json +4 -4
package/out/generators/script.js
CHANGED
|
@@ -37,6 +37,7 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
37
37
|
emitsTypeArg: undefined,
|
|
38
38
|
emitsTypeNums: 0,
|
|
39
39
|
exposeRuntimeArg: undefined,
|
|
40
|
+
leadingCommentEndOffset: 0,
|
|
40
41
|
importSectionEndOffset: 0,
|
|
41
42
|
defineProps: undefined,
|
|
42
43
|
propsAssignName: undefined,
|
|
@@ -229,7 +230,7 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
229
230
|
if (!scriptSetupRanges)
|
|
230
231
|
return;
|
|
231
232
|
codes.push([
|
|
232
|
-
sfc.scriptSetup.content.substring(0, scriptSetupRanges.importSectionEndOffset),
|
|
233
|
+
sfc.scriptSetup.content.substring(0, Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset)),
|
|
233
234
|
'scriptSetup',
|
|
234
235
|
0,
|
|
235
236
|
language_core_1.FileRangeCapabilities.full,
|
|
@@ -270,9 +271,9 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
270
271
|
}
|
|
271
272
|
codes.push(`>`);
|
|
272
273
|
codes.push('(\n');
|
|
273
|
-
codes.push(`__VLS_props: typeof __VLS_setup['props']`, `& import('${vueCompilerOptions.lib}').VNodeProps`, `& import('${vueCompilerOptions.lib}').AllowedComponentProps`, `& import('${vueCompilerOptions.lib}').ComponentCustomProps,\n`);
|
|
274
|
-
codes.push(`__VLS_ctx?: Pick<typeof __VLS_setup
|
|
275
|
-
codes.push('__VLS_setup = (() => {\n');
|
|
274
|
+
codes.push(`__VLS_props: Awaited<typeof __VLS_setup>['props']`, `& import('${vueCompilerOptions.lib}').VNodeProps`, `& import('${vueCompilerOptions.lib}').AllowedComponentProps`, `& import('${vueCompilerOptions.lib}').ComponentCustomProps,\n`);
|
|
275
|
+
codes.push(`__VLS_ctx?: Pick<Awaited<typeof __VLS_setup>, 'attrs' | 'emit' | 'slots'>,\n`);
|
|
276
|
+
codes.push('__VLS_setup = (async () => {\n');
|
|
276
277
|
scriptSetupGeneratedOffset = generateSetupFunction(true, 'none', definePropMirrors);
|
|
277
278
|
//#region exposed
|
|
278
279
|
codes.push(`const __VLS_exposed = `);
|
|
@@ -339,6 +340,7 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
339
340
|
usedHelperTypes.PropsChildren = true;
|
|
340
341
|
codes.push(` & __VLS_PropsChildren<`);
|
|
341
342
|
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.slotsTypeArg.start, scriptSetupRanges.slotsTypeArg.end);
|
|
343
|
+
codes.push('>');
|
|
342
344
|
}
|
|
343
345
|
codes.push(`;\n`);
|
|
344
346
|
//#endregion
|
|
@@ -366,7 +368,7 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
366
368
|
codes.push('emit: typeof __VLS_emit');
|
|
367
369
|
codes.push('};\n');
|
|
368
370
|
codes.push('})(),\n');
|
|
369
|
-
codes.push(`) => ({} as import('${vueCompilerOptions.lib}').VNode & { __ctx?: typeof __VLS_setup }))`);
|
|
371
|
+
codes.push(`) => ({} as import('${vueCompilerOptions.lib}').VNode & { __ctx?: Awaited<typeof __VLS_setup> }))`);
|
|
370
372
|
}
|
|
371
373
|
else if (!sfc.script) {
|
|
372
374
|
// no script block, generate script setup code at root
|
|
@@ -585,7 +585,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
|
|
|
585
585
|
blockConditions.push(condition);
|
|
586
586
|
inScope = true;
|
|
587
587
|
}
|
|
588
|
-
generateDirectives(node
|
|
588
|
+
generateDirectives(node);
|
|
589
589
|
generateElReferences(node); // <el ref="foo" />
|
|
590
590
|
if (sfc.styles.some(s => s.scoped || vueCompilerOptions.experimentalResolveStyleCssClasses === 'always')) {
|
|
591
591
|
generateClassScoped(node);
|
|
@@ -1019,7 +1019,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
|
|
|
1019
1019
|
}
|
|
1020
1020
|
}
|
|
1021
1021
|
}
|
|
1022
|
-
function generateDirectives(node
|
|
1022
|
+
function generateDirectives(node) {
|
|
1023
1023
|
for (const prop of node.props) {
|
|
1024
1024
|
if (prop.type === 7 /* CompilerDOM.NodeTypes.DIRECTIVE */
|
|
1025
1025
|
&& prop.name !== 'slot'
|
|
@@ -1052,7 +1052,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
|
|
|
1052
1052
|
apply: getRenameApply(prop.name),
|
|
1053
1053
|
},
|
|
1054
1054
|
},
|
|
1055
|
-
], ')', '('
|
|
1055
|
+
], ')', '(');
|
|
1056
1056
|
if (prop.exp?.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */) {
|
|
1057
1057
|
codes.push(['', 'template', prop.exp.loc.start.offset, capabilitiesPresets.diagnosticOnly], ...createInterpolationCode(prop.exp.content, prop.exp.loc, prop.exp.loc.start.offset, capabilitiesPresets.all, '(', ')'), ['', 'template', prop.exp.loc.end.offset, capabilitiesPresets.diagnosticOnly]);
|
|
1058
1058
|
formatCodes.push(...createFormatCode(prop.exp.content, prop.exp.loc.start.offset, formatBrackets.normal));
|
package/out/index.d.ts
CHANGED
|
@@ -8,5 +8,6 @@ export * from './utils/ts';
|
|
|
8
8
|
export * from './utils/parseSfc';
|
|
9
9
|
export * as scriptRanges from './parsers/scriptRanges';
|
|
10
10
|
export * as sharedTypes from './utils/globalTypes';
|
|
11
|
+
export { tsCodegen } from './plugins/vue-tsx';
|
|
11
12
|
export * from '@volar/language-core';
|
|
12
13
|
export * from '@volar/source-map';
|
package/out/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.sharedTypes = exports.scriptRanges = void 0;
|
|
17
|
+
exports.tsCodegen = exports.sharedTypes = exports.scriptRanges = void 0;
|
|
18
18
|
__exportStar(require("./generators/template"), exports);
|
|
19
19
|
__exportStar(require("./languageModule"), exports);
|
|
20
20
|
__exportStar(require("./parsers/scriptSetupRanges"), exports);
|
|
@@ -25,6 +25,8 @@ __exportStar(require("./utils/ts"), exports);
|
|
|
25
25
|
__exportStar(require("./utils/parseSfc"), exports);
|
|
26
26
|
exports.scriptRanges = require("./parsers/scriptRanges");
|
|
27
27
|
exports.sharedTypes = require("./utils/globalTypes");
|
|
28
|
+
var vue_tsx_1 = require("./plugins/vue-tsx");
|
|
29
|
+
Object.defineProperty(exports, "tsCodegen", { enumerable: true, get: function () { return vue_tsx_1.tsCodegen; } });
|
|
28
30
|
__exportStar(require("@volar/language-core"), exports);
|
|
29
31
|
__exportStar(require("@volar/source-map"), exports);
|
|
30
32
|
//# sourceMappingURL=index.js.map
|
package/out/languageModule.d.ts
CHANGED
|
@@ -2,5 +2,8 @@ import type { Language } from '@volar/language-core';
|
|
|
2
2
|
import { VueFile } from './sourceFile';
|
|
3
3
|
import { VueCompilerOptions } from './types';
|
|
4
4
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
5
|
-
export declare function
|
|
5
|
+
export declare function createVueLanguage(ts: typeof import('typescript/lib/tsserverlibrary'), compilerOptions?: ts.CompilerOptions, _vueCompilerOptions?: Partial<VueCompilerOptions>, codegenStack?: boolean): Language<VueFile>;
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated planed to remove in 2.0, please use getOrCreateVueLanguage instead of
|
|
8
|
+
*/
|
|
6
9
|
export declare function createLanguages(compilerOptions?: ts.CompilerOptions, vueCompilerOptions?: Partial<VueCompilerOptions>, ts?: typeof import('typescript/lib/tsserverlibrary'), codegenStack?: boolean): Language[];
|
package/out/languageModule.js
CHANGED
|
@@ -1,21 +1,58 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createLanguages = exports.
|
|
3
|
+
exports.createLanguages = exports.createVueLanguage = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const plugins_1 = require("./plugins");
|
|
6
6
|
const sourceFile_1 = require("./sourceFile");
|
|
7
7
|
const sharedTypes = require("./utils/globalTypes");
|
|
8
8
|
const ts_1 = require("./utils/ts");
|
|
9
|
-
|
|
9
|
+
const fileRegistries = [];
|
|
10
|
+
function getVueFileRegistry(key, plugins) {
|
|
11
|
+
let fileRegistry = fileRegistries.find(r => r.key === key
|
|
12
|
+
&& r.plugins.length === plugins.length
|
|
13
|
+
&& r.plugins.every(plugin => plugins.includes(plugin)))?.files;
|
|
14
|
+
if (!fileRegistry) {
|
|
15
|
+
fileRegistry = new Map();
|
|
16
|
+
fileRegistries.push({
|
|
17
|
+
key: key,
|
|
18
|
+
plugins: plugins,
|
|
19
|
+
files: fileRegistry,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return fileRegistry;
|
|
23
|
+
}
|
|
24
|
+
function createVueLanguage(ts, compilerOptions = {}, _vueCompilerOptions = {}, codegenStack = false) {
|
|
10
25
|
const vueCompilerOptions = (0, ts_1.resolveVueCompilerOptions)(_vueCompilerOptions);
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
26
|
+
const plugins = (0, plugins_1.getDefaultVueLanguagePlugins)(ts, compilerOptions, vueCompilerOptions, codegenStack);
|
|
27
|
+
const keys = [
|
|
28
|
+
...Object.keys(vueCompilerOptions)
|
|
29
|
+
.sort()
|
|
30
|
+
.filter(key => key !== 'plugins')
|
|
31
|
+
.map(key => [key, vueCompilerOptions[key]]),
|
|
32
|
+
[...new Set(plugins.map(plugin => plugin.requiredCompilerOptions ?? []).flat())]
|
|
33
|
+
.sort()
|
|
34
|
+
.map(key => [key, compilerOptions[key]]),
|
|
35
|
+
];
|
|
36
|
+
const fileRegistry = getVueFileRegistry(JSON.stringify(keys), _vueCompilerOptions.plugins ?? []);
|
|
37
|
+
const allowLanguageIds = new Set(['vue']);
|
|
38
|
+
if (vueCompilerOptions.extensions.includes('.md')) {
|
|
39
|
+
allowLanguageIds.add('markdown');
|
|
40
|
+
}
|
|
41
|
+
if (vueCompilerOptions.extensions.includes('.html')) {
|
|
42
|
+
allowLanguageIds.add('html');
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
14
45
|
createVirtualFile(fileName, snapshot, languageId) {
|
|
15
|
-
if (languageId
|
|
16
|
-
|| (!languageId
|
|
17
|
-
|
|
18
|
-
|
|
46
|
+
if ((languageId && allowLanguageIds.has(languageId))
|
|
47
|
+
|| (!languageId && vueCompilerOptions.extensions.some(ext => fileName.endsWith(ext)))) {
|
|
48
|
+
if (fileRegistry.has(fileName)) {
|
|
49
|
+
const reusedVueFile = fileRegistry.get(fileName);
|
|
50
|
+
reusedVueFile.update(snapshot);
|
|
51
|
+
return reusedVueFile;
|
|
52
|
+
}
|
|
53
|
+
const vueFile = new sourceFile_1.VueFile(fileName, snapshot, vueCompilerOptions, plugins, ts, codegenStack);
|
|
54
|
+
fileRegistry.set(fileName, vueFile);
|
|
55
|
+
return vueFile;
|
|
19
56
|
}
|
|
20
57
|
},
|
|
21
58
|
updateVirtualFile(sourceFile, snapshot) {
|
|
@@ -26,6 +63,12 @@ function createLanguage(compilerOptions = {}, _vueCompilerOptions = {}, ts = req
|
|
|
26
63
|
const sharedTypesFileName = path_1.posix.join(host.rootPath, sharedTypes.baseName);
|
|
27
64
|
return {
|
|
28
65
|
...host,
|
|
66
|
+
resolveModuleName(moduleName, impliedNodeFormat) {
|
|
67
|
+
if (impliedNodeFormat === ts.ModuleKind.ESNext && vueCompilerOptions.extensions.some(ext => moduleName.endsWith(ext))) {
|
|
68
|
+
return `${moduleName}.js`;
|
|
69
|
+
}
|
|
70
|
+
return host.resolveModuleName?.(moduleName, impliedNodeFormat) ?? moduleName;
|
|
71
|
+
},
|
|
29
72
|
getScriptFileNames() {
|
|
30
73
|
return [
|
|
31
74
|
sharedTypesFileName,
|
|
@@ -41,32 +84,16 @@ function createLanguage(compilerOptions = {}, _vueCompilerOptions = {}, ts = req
|
|
|
41
84
|
};
|
|
42
85
|
},
|
|
43
86
|
};
|
|
44
|
-
return languageModule;
|
|
45
87
|
}
|
|
46
|
-
exports.
|
|
88
|
+
exports.createVueLanguage = createVueLanguage;
|
|
89
|
+
/**
|
|
90
|
+
* @deprecated planed to remove in 2.0, please use getOrCreateVueLanguage instead of
|
|
91
|
+
*/
|
|
47
92
|
function createLanguages(compilerOptions = {}, vueCompilerOptions = {}, ts = require('typescript'), codegenStack = false) {
|
|
48
93
|
return [
|
|
49
|
-
|
|
94
|
+
createVueLanguage(ts, compilerOptions, vueCompilerOptions, codegenStack),
|
|
50
95
|
...vueCompilerOptions.experimentalAdditionalLanguageModules?.map(module => require(module)) ?? [],
|
|
51
96
|
];
|
|
52
97
|
}
|
|
53
98
|
exports.createLanguages = createLanguages;
|
|
54
|
-
function patchResolveModuleNames(ts, vueCompilerOptions) {
|
|
55
|
-
try {
|
|
56
|
-
// from https://github.com/vuejs/language-tools/pull/1543
|
|
57
|
-
if (!(ts.__vuePatchResolveModuleNames)) {
|
|
58
|
-
ts.__vuePatchResolveModuleNames = true;
|
|
59
|
-
const resolveModuleNames = ts.resolveModuleName;
|
|
60
|
-
ts.resolveModuleName = (...args) => {
|
|
61
|
-
if (args[6] === ts.ModuleKind.ESNext && vueCompilerOptions.extensions.some(ext => args[0].endsWith(ext))) {
|
|
62
|
-
args[6] = ts.ModuleKind.CommonJS;
|
|
63
|
-
}
|
|
64
|
-
return resolveModuleNames(...args);
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
catch (e) {
|
|
69
|
-
// console.warn('[volar] patchResolveModuleNames failed', e);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
99
|
//# sourceMappingURL=languageModule.js.map
|
|
@@ -3,6 +3,7 @@ import type { VueCompilerOptions, TextRange } from '../types';
|
|
|
3
3
|
export interface ScriptSetupRanges extends ReturnType<typeof parseScriptSetupRanges> {
|
|
4
4
|
}
|
|
5
5
|
export declare function parseScriptSetupRanges(ts: typeof import('typescript/lib/tsserverlibrary'), ast: ts.SourceFile, vueCompilerOptions: VueCompilerOptions): {
|
|
6
|
+
leadingCommentEndOffset: number;
|
|
6
7
|
importSectionEndOffset: number;
|
|
7
8
|
bindings: TextRange[];
|
|
8
9
|
withDefaultsArg: TextRange | undefined;
|
|
@@ -19,6 +19,8 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
19
19
|
const definePropProposalB = vueCompilerOptions.experimentalDefinePropProposal === 'johnsonEdition' || ast.getFullText().trimStart().startsWith('// @experimentalDefinePropProposal=johnsonEdition');
|
|
20
20
|
const defineProp = [];
|
|
21
21
|
const bindings = parseBindingRanges(ts, ast, false);
|
|
22
|
+
const text = ast.getFullText();
|
|
23
|
+
const leadingCommentEndOffset = ts.getLeadingCommentRanges(text, 0)?.reverse()[0].end ?? 0;
|
|
22
24
|
ast.forEachChild(node => {
|
|
23
25
|
const isTypeExport = (ts.isTypeAliasDeclaration(node) || ts.isInterfaceDeclaration(node)) && node.modifiers?.some(mod => mod.kind === ts.SyntaxKind.ExportKeyword);
|
|
24
26
|
if (!foundNonImportExportNode
|
|
@@ -27,7 +29,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
27
29
|
&& !ts.isEmptyStatement(node)
|
|
28
30
|
// fix https://github.com/vuejs/language-tools/issues/1223
|
|
29
31
|
&& !ts.isImportEqualsDeclaration(node)) {
|
|
30
|
-
const commentRanges = ts.getLeadingCommentRanges(
|
|
32
|
+
const commentRanges = ts.getLeadingCommentRanges(text, node.getFullStart());
|
|
31
33
|
if (commentRanges?.length) {
|
|
32
34
|
const commentRange = commentRanges.sort((a, b) => a.pos - b.pos)[0];
|
|
33
35
|
importSectionEndOffset = commentRange.pos;
|
|
@@ -40,6 +42,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
40
42
|
});
|
|
41
43
|
ast.forEachChild(child => visitNode(child, ast));
|
|
42
44
|
return {
|
|
45
|
+
leadingCommentEndOffset,
|
|
43
46
|
importSectionEndOffset,
|
|
44
47
|
bindings,
|
|
45
48
|
withDefaultsArg,
|
package/out/plugins/vue-tsx.d.ts
CHANGED
|
@@ -1,3 +1,58 @@
|
|
|
1
|
-
import { VueLanguagePlugin } from '../types';
|
|
1
|
+
import { Sfc, VueLanguagePlugin } from '../types';
|
|
2
|
+
import * as muggle from 'muggle-string';
|
|
3
|
+
import * as ts from 'typescript/lib/tsserverlibrary';
|
|
4
|
+
export declare const tsCodegen: WeakMap<Sfc, {
|
|
5
|
+
scriptRanges: import("@vue/reactivity").ComputedRef<{
|
|
6
|
+
exportDefault: (import("../types").TextRange & {
|
|
7
|
+
expression: import("../types").TextRange;
|
|
8
|
+
args: import("../types").TextRange;
|
|
9
|
+
argsNode: ts.ObjectLiteralExpression | undefined;
|
|
10
|
+
componentsOption: import("../types").TextRange | undefined;
|
|
11
|
+
componentsOptionNode: ts.ObjectLiteralExpression | undefined;
|
|
12
|
+
nameOption: import("../types").TextRange | undefined;
|
|
13
|
+
}) | undefined;
|
|
14
|
+
bindings: import("../types").TextRange[];
|
|
15
|
+
} | undefined>;
|
|
16
|
+
scriptSetupRanges: import("@vue/reactivity").ComputedRef<{
|
|
17
|
+
leadingCommentEndOffset: number;
|
|
18
|
+
importSectionEndOffset: number;
|
|
19
|
+
bindings: import("../types").TextRange[];
|
|
20
|
+
withDefaultsArg: import("../types").TextRange | undefined;
|
|
21
|
+
defineProps: import("../types").TextRange | undefined;
|
|
22
|
+
propsAssignName: string | undefined;
|
|
23
|
+
propsRuntimeArg: import("../types").TextRange | undefined;
|
|
24
|
+
propsTypeArg: import("../types").TextRange | undefined;
|
|
25
|
+
slotsTypeArg: import("../types").TextRange | undefined;
|
|
26
|
+
emitsAssignName: string | undefined;
|
|
27
|
+
emitsRuntimeArg: import("../types").TextRange | undefined;
|
|
28
|
+
emitsTypeArg: import("../types").TextRange | undefined;
|
|
29
|
+
emitsTypeNums: number;
|
|
30
|
+
exposeRuntimeArg: import("../types").TextRange | undefined;
|
|
31
|
+
defineProp: {
|
|
32
|
+
name: import("../types").TextRange | undefined;
|
|
33
|
+
nameIsString: boolean;
|
|
34
|
+
type: import("../types").TextRange | undefined;
|
|
35
|
+
defaultValue: import("../types").TextRange | undefined;
|
|
36
|
+
required: boolean;
|
|
37
|
+
}[];
|
|
38
|
+
} | undefined>;
|
|
39
|
+
lang: import("@vue/reactivity").ComputedRef<string>;
|
|
40
|
+
tsxGen: import("@vue/reactivity").ComputedRef<{
|
|
41
|
+
codes: muggle.Segment<import("@volar/language-core").FileRangeCapabilities>[];
|
|
42
|
+
codeStacks: muggle.StackNode[];
|
|
43
|
+
mirrorBehaviorMappings: import("@volar/source-map").Mapping<[import("@volar/language-core").MirrorBehaviorCapabilities, import("@volar/language-core").MirrorBehaviorCapabilities]>[];
|
|
44
|
+
}>;
|
|
45
|
+
htmlGen: import("@vue/reactivity").ComputedRef<{
|
|
46
|
+
codes: (string | [string, string | undefined, number | [number, number], import("@volar/language-core").FileRangeCapabilities])[];
|
|
47
|
+
codeStacks: muggle.StackNode[];
|
|
48
|
+
formatCodes: (string | [string, string | undefined, number | [number, number], import("@volar/language-core").FileRangeCapabilities])[];
|
|
49
|
+
formatCodeStacks: muggle.StackNode[];
|
|
50
|
+
cssCodes: (string | [string, string | undefined, number | [number, number], import("@volar/language-core").FileRangeCapabilities])[];
|
|
51
|
+
cssCodeStacks: muggle.StackNode[];
|
|
52
|
+
tagNames: Record<string, number[]>;
|
|
53
|
+
identifiers: Set<string>;
|
|
54
|
+
hasSlot: boolean;
|
|
55
|
+
} | undefined>;
|
|
56
|
+
}>;
|
|
2
57
|
declare const plugin: VueLanguagePlugin;
|
|
3
58
|
export default plugin;
|
package/out/plugins/vue-tsx.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tsCodegen = void 0;
|
|
3
4
|
const reactivity_1 = require("@vue/reactivity");
|
|
4
5
|
const script_1 = require("../generators/script");
|
|
5
6
|
const templateGen = require("../generators/template");
|
|
@@ -7,13 +8,17 @@ const scriptRanges_1 = require("../parsers/scriptRanges");
|
|
|
7
8
|
const scriptSetupRanges_1 = require("../parsers/scriptSetupRanges");
|
|
8
9
|
const language_core_1 = require("@volar/language-core");
|
|
9
10
|
const muggle = require("muggle-string");
|
|
11
|
+
const ts = require("typescript/lib/tsserverlibrary");
|
|
10
12
|
const templateFormatReg = /^\.template_format\.ts$/;
|
|
11
13
|
const templateStyleCssReg = /^\.template_style\.css$/;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const instances = new WeakMap();
|
|
14
|
+
exports.tsCodegen = new WeakMap();
|
|
15
|
+
const plugin = (ctx) => {
|
|
15
16
|
return {
|
|
16
17
|
version: 1,
|
|
18
|
+
requiredCompilerOptions: [
|
|
19
|
+
'noPropertyAccessFromIndexSignature',
|
|
20
|
+
'exactOptionalPropertyTypes',
|
|
21
|
+
],
|
|
17
22
|
getEmbeddedFileNames(fileName, sfc) {
|
|
18
23
|
const tsx = useTsx(fileName, sfc);
|
|
19
24
|
const fileNames = [];
|
|
@@ -39,7 +44,7 @@ const plugin = ({ modules, vueCompilerOptions, compilerOptions, codegenStack })
|
|
|
39
44
|
};
|
|
40
45
|
const tsx = _tsx.tsxGen.value;
|
|
41
46
|
if (tsx) {
|
|
42
|
-
const [content, contentStacks] = codegenStack ? muggle.track([...tsx.codes], [...tsx.codeStacks]) : [[...tsx.codes], [...tsx.codeStacks]];
|
|
47
|
+
const [content, contentStacks] = ctx.codegenStack ? muggle.track([...tsx.codes], [...tsx.codeStacks]) : [[...tsx.codes], [...tsx.codeStacks]];
|
|
43
48
|
embeddedFile.content = content;
|
|
44
49
|
embeddedFile.contentStacks = contentStacks;
|
|
45
50
|
embeddedFile.mirrorBehaviorMappings = [...tsx.mirrorBehaviorMappings];
|
|
@@ -56,7 +61,7 @@ const plugin = ({ modules, vueCompilerOptions, compilerOptions, codegenStack })
|
|
|
56
61
|
inlayHint: false,
|
|
57
62
|
};
|
|
58
63
|
if (_tsx.htmlGen.value) {
|
|
59
|
-
const [content, contentStacks] = codegenStack ? muggle.track([..._tsx.htmlGen.value.formatCodes], [..._tsx.htmlGen.value.formatCodeStacks]) : [[..._tsx.htmlGen.value.formatCodes], [..._tsx.htmlGen.value.formatCodeStacks]];
|
|
64
|
+
const [content, contentStacks] = ctx.codegenStack ? muggle.track([..._tsx.htmlGen.value.formatCodes], [..._tsx.htmlGen.value.formatCodeStacks]) : [[..._tsx.htmlGen.value.formatCodes], [..._tsx.htmlGen.value.formatCodeStacks]];
|
|
60
65
|
embeddedFile.content = content;
|
|
61
66
|
embeddedFile.contentStacks = contentStacks;
|
|
62
67
|
}
|
|
@@ -77,7 +82,7 @@ const plugin = ({ modules, vueCompilerOptions, compilerOptions, codegenStack })
|
|
|
77
82
|
else if (suffix.match(templateStyleCssReg)) {
|
|
78
83
|
embeddedFile.parentFileName = fileName + '.template.' + sfc.template?.lang;
|
|
79
84
|
if (_tsx.htmlGen.value) {
|
|
80
|
-
const [content, contentStacks] = codegenStack ? muggle.track([..._tsx.htmlGen.value.cssCodes], [..._tsx.htmlGen.value.cssCodeStacks]) : [[..._tsx.htmlGen.value.cssCodes], [..._tsx.htmlGen.value.cssCodeStacks]];
|
|
85
|
+
const [content, contentStacks] = ctx.codegenStack ? muggle.track([..._tsx.htmlGen.value.cssCodes], [..._tsx.htmlGen.value.cssCodeStacks]) : [[..._tsx.htmlGen.value.cssCodes], [..._tsx.htmlGen.value.cssCodeStacks]];
|
|
81
86
|
embeddedFile.content = content;
|
|
82
87
|
embeddedFile.contentStacks = contentStacks;
|
|
83
88
|
}
|
|
@@ -87,40 +92,42 @@ const plugin = ({ modules, vueCompilerOptions, compilerOptions, codegenStack })
|
|
|
87
92
|
},
|
|
88
93
|
};
|
|
89
94
|
function useTsx(fileName, sfc) {
|
|
90
|
-
if (!
|
|
91
|
-
|
|
95
|
+
if (!exports.tsCodegen.has(sfc)) {
|
|
96
|
+
exports.tsCodegen.set(sfc, createTsx(fileName, sfc, ctx));
|
|
92
97
|
}
|
|
93
|
-
return
|
|
94
|
-
}
|
|
95
|
-
function createTsx(fileName, _sfc) {
|
|
96
|
-
const lang = (0, reactivity_1.computed)(() => {
|
|
97
|
-
return !_sfc.script && !_sfc.scriptSetup ? 'ts'
|
|
98
|
-
: _sfc.scriptSetup && _sfc.scriptSetup.lang !== 'js' ? _sfc.scriptSetup.lang
|
|
99
|
-
: _sfc.script && _sfc.script.lang !== 'js' ? _sfc.script.lang
|
|
100
|
-
: 'js';
|
|
101
|
-
});
|
|
102
|
-
const scriptRanges = (0, reactivity_1.computed)(() => _sfc.scriptAst
|
|
103
|
-
? (0, scriptRanges_1.parseScriptRanges)(ts, _sfc.scriptAst, !!_sfc.scriptSetup, false)
|
|
104
|
-
: undefined);
|
|
105
|
-
const scriptSetupRanges = (0, reactivity_1.computed)(() => _sfc.scriptSetupAst
|
|
106
|
-
? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, _sfc.scriptSetupAst, vueCompilerOptions)
|
|
107
|
-
: undefined);
|
|
108
|
-
const htmlGen = (0, reactivity_1.computed)(() => {
|
|
109
|
-
if (!_sfc.templateAst)
|
|
110
|
-
return;
|
|
111
|
-
return templateGen.generate(ts, compilerOptions, vueCompilerOptions, _sfc.template?.content ?? '', _sfc.template?.lang ?? 'html', _sfc, hasScriptSetupSlots.value, codegenStack);
|
|
112
|
-
});
|
|
113
|
-
const hasScriptSetupSlots = (0, reactivity_1.shallowRef)(false); // remove when https://github.com/vuejs/core/pull/5912 merged
|
|
114
|
-
const tsxGen = (0, reactivity_1.computed)(() => {
|
|
115
|
-
hasScriptSetupSlots.value = !!scriptSetupRanges.value?.slotsTypeArg;
|
|
116
|
-
return (0, script_1.generate)(ts, fileName, _sfc, lang.value, scriptRanges.value, scriptSetupRanges.value, htmlGen.value, compilerOptions, vueCompilerOptions, codegenStack);
|
|
117
|
-
});
|
|
118
|
-
return {
|
|
119
|
-
lang,
|
|
120
|
-
tsxGen,
|
|
121
|
-
htmlGen,
|
|
122
|
-
};
|
|
98
|
+
return exports.tsCodegen.get(sfc);
|
|
123
99
|
}
|
|
124
100
|
};
|
|
125
101
|
exports.default = plugin;
|
|
102
|
+
function createTsx(fileName, _sfc, { vueCompilerOptions, compilerOptions, codegenStack }) {
|
|
103
|
+
const lang = (0, reactivity_1.computed)(() => {
|
|
104
|
+
return !_sfc.script && !_sfc.scriptSetup ? 'ts'
|
|
105
|
+
: _sfc.scriptSetup && _sfc.scriptSetup.lang !== 'js' ? _sfc.scriptSetup.lang
|
|
106
|
+
: _sfc.script && _sfc.script.lang !== 'js' ? _sfc.script.lang
|
|
107
|
+
: 'js';
|
|
108
|
+
});
|
|
109
|
+
const scriptRanges = (0, reactivity_1.computed)(() => _sfc.scriptAst
|
|
110
|
+
? (0, scriptRanges_1.parseScriptRanges)(ts, _sfc.scriptAst, !!_sfc.scriptSetup, false)
|
|
111
|
+
: undefined);
|
|
112
|
+
const scriptSetupRanges = (0, reactivity_1.computed)(() => _sfc.scriptSetupAst
|
|
113
|
+
? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, _sfc.scriptSetupAst, vueCompilerOptions)
|
|
114
|
+
: undefined);
|
|
115
|
+
const htmlGen = (0, reactivity_1.computed)(() => {
|
|
116
|
+
if (!_sfc.templateAst)
|
|
117
|
+
return;
|
|
118
|
+
return templateGen.generate(ts, compilerOptions, vueCompilerOptions, _sfc.template?.content ?? '', _sfc.template?.lang ?? 'html', _sfc, hasScriptSetupSlots.value, codegenStack);
|
|
119
|
+
});
|
|
120
|
+
const hasScriptSetupSlots = (0, reactivity_1.shallowRef)(false); // remove when https://github.com/vuejs/core/pull/5912 merged
|
|
121
|
+
const tsxGen = (0, reactivity_1.computed)(() => {
|
|
122
|
+
hasScriptSetupSlots.value = !!scriptSetupRanges.value?.slotsTypeArg;
|
|
123
|
+
return (0, script_1.generate)(ts, fileName, _sfc, lang.value, scriptRanges.value, scriptSetupRanges.value, htmlGen.value, compilerOptions, vueCompilerOptions, codegenStack);
|
|
124
|
+
});
|
|
125
|
+
return {
|
|
126
|
+
scriptRanges,
|
|
127
|
+
scriptSetupRanges,
|
|
128
|
+
lang,
|
|
129
|
+
tsxGen,
|
|
130
|
+
htmlGen,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
126
133
|
//# sourceMappingURL=vue-tsx.js.map
|
package/out/plugins.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare function getDefaultVueLanguagePlugins(ts: typeof import('typescri
|
|
|
5
5
|
version: 1;
|
|
6
6
|
name?: string | undefined;
|
|
7
7
|
order?: number | undefined;
|
|
8
|
+
requiredCompilerOptions?: string[] | undefined;
|
|
8
9
|
parseSFC?(fileName: string, content: string): import("@vue/compiler-sfc").SFCParseResult | undefined;
|
|
9
10
|
updateSFC?(oldResult: import("@vue/compiler-sfc").SFCParseResult, textChange: {
|
|
10
11
|
start: number;
|
package/out/sourceFile.d.ts
CHANGED
|
@@ -67,6 +67,7 @@ export declare class VueFile implements VirtualFile {
|
|
|
67
67
|
_embeddedFiles: ComputedRef<VirtualFile[]>;
|
|
68
68
|
constructor(fileName: string, snapshot: ts.IScriptSnapshot, vueCompilerOptions: VueCompilerOptions, plugins: ReturnType<VueLanguagePlugin>[], ts: typeof import('typescript/lib/tsserverlibrary'), codegenStack: boolean);
|
|
69
69
|
update(newScriptSnapshot: ts.IScriptSnapshot): void;
|
|
70
|
+
onUpdate(): void;
|
|
70
71
|
parseSfc(): SFCParseResult | undefined;
|
|
71
72
|
parseTemplateBlock(block: SFCTemplateBlock): NonNullable<Sfc['template']>;
|
|
72
73
|
parseScriptBlock(block: SFCScriptBlock): NonNullable<Sfc['script']>;
|
package/out/sourceFile.js
CHANGED
|
@@ -331,10 +331,15 @@ class VueFile {
|
|
|
331
331
|
}
|
|
332
332
|
}
|
|
333
333
|
});
|
|
334
|
-
this.
|
|
334
|
+
this.onUpdate();
|
|
335
335
|
}
|
|
336
336
|
update(newScriptSnapshot) {
|
|
337
|
+
if (newScriptSnapshot === this.snapshot)
|
|
338
|
+
return;
|
|
337
339
|
this.snapshot = newScriptSnapshot;
|
|
340
|
+
this.onUpdate();
|
|
341
|
+
}
|
|
342
|
+
onUpdate() {
|
|
338
343
|
const parsedSfc = this.parseSfc();
|
|
339
344
|
updateObj(this.sfc, {
|
|
340
345
|
template: parsedSfc?.descriptor.template ? this.parseTemplateBlock(parsedSfc.descriptor.template) : null,
|
package/out/types.d.ts
CHANGED
|
@@ -45,6 +45,7 @@ export type VueLanguagePlugin = (ctx: {
|
|
|
45
45
|
version: 1;
|
|
46
46
|
name?: string;
|
|
47
47
|
order?: number;
|
|
48
|
+
requiredCompilerOptions?: string[];
|
|
48
49
|
parseSFC?(fileName: string, content: string): SFCParseResult | undefined;
|
|
49
50
|
updateSFC?(oldResult: SFCParseResult, textChange: {
|
|
50
51
|
start: number;
|
package/out/utils/globalTypes.js
CHANGED
|
@@ -51,7 +51,7 @@ declare function __VLS_getVForSourceType<T>(source: T): [
|
|
|
51
51
|
declare function __VLS_getSlotParams<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>;
|
|
52
52
|
declare function __VLS_getSlotParam<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>[0];
|
|
53
53
|
declare function __VLS_directiveFunction<T>(dir: T):
|
|
54
|
-
T extends import('${vueCompilerOptions.lib}').ObjectDirective<infer E, infer V> | import('${vueCompilerOptions.lib}').FunctionDirective<infer E, infer V> ? (
|
|
54
|
+
T extends import('${vueCompilerOptions.lib}').ObjectDirective<infer E, infer V> | import('${vueCompilerOptions.lib}').FunctionDirective<infer E, infer V> ? (value: V) => void
|
|
55
55
|
: T;
|
|
56
56
|
declare function __VLS_withScope<T, K>(ctx: T, scope: K): ctx is T & K;
|
|
57
57
|
declare function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
|
package/out/utils/transform.js
CHANGED
|
@@ -106,7 +106,7 @@ function walkIdentifiers(ts, node, cb, localVars, blockVars = [], isRoot = true)
|
|
|
106
106
|
if (node.initializer)
|
|
107
107
|
walkIdentifiers(ts, node.initializer, cb, localVars, blockVars, false);
|
|
108
108
|
}
|
|
109
|
-
else if (ts.isArrowFunction(node)) {
|
|
109
|
+
else if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {
|
|
110
110
|
const functionArgs = [];
|
|
111
111
|
for (const param of node.parameters) {
|
|
112
112
|
colletVars(ts, param.name, functionArgs);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/language-core",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.7",
|
|
4
4
|
"main": "out/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"directory": "packages/vue-language-core"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@volar/language-core": "~1.
|
|
17
|
-
"@volar/source-map": "~1.
|
|
16
|
+
"@volar/language-core": "~1.10.0",
|
|
17
|
+
"@volar/source-map": "~1.10.0",
|
|
18
18
|
"@vue/compiler-dom": "^3.3.0",
|
|
19
19
|
"@vue/reactivity": "^3.3.0",
|
|
20
20
|
"@vue/shared": "^3.3.0",
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"optional": true
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "2b888901897fc9155bc12eb30ddae41afed5d942"
|
|
38
38
|
}
|