@vue/language-core 1.8.6 → 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 +5 -4
- package/out/index.d.ts +1 -0
- package/out/index.js +3 -1
- package/out/languageModule.d.ts +4 -1
- package/out/languageModule.js +48 -27
- 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/transform.js +1 -1
- package/package.json +4 -4
package/out/generators/script.js
CHANGED
|
@@ -271,9 +271,9 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
271
271
|
}
|
|
272
272
|
codes.push(`>`);
|
|
273
273
|
codes.push('(\n');
|
|
274
|
-
codes.push(`__VLS_props: typeof __VLS_setup['props']`, `& import('${vueCompilerOptions.lib}').VNodeProps`, `& import('${vueCompilerOptions.lib}').AllowedComponentProps`, `& import('${vueCompilerOptions.lib}').ComponentCustomProps,\n`);
|
|
275
|
-
codes.push(`__VLS_ctx?: Pick<typeof __VLS_setup
|
|
276
|
-
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');
|
|
277
277
|
scriptSetupGeneratedOffset = generateSetupFunction(true, 'none', definePropMirrors);
|
|
278
278
|
//#region exposed
|
|
279
279
|
codes.push(`const __VLS_exposed = `);
|
|
@@ -340,6 +340,7 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
340
340
|
usedHelperTypes.PropsChildren = true;
|
|
341
341
|
codes.push(` & __VLS_PropsChildren<`);
|
|
342
342
|
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.slotsTypeArg.start, scriptSetupRanges.slotsTypeArg.end);
|
|
343
|
+
codes.push('>');
|
|
343
344
|
}
|
|
344
345
|
codes.push(`;\n`);
|
|
345
346
|
//#endregion
|
|
@@ -367,7 +368,7 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
|
|
|
367
368
|
codes.push('emit: typeof __VLS_emit');
|
|
368
369
|
codes.push('};\n');
|
|
369
370
|
codes.push('})(),\n');
|
|
370
|
-
codes.push(`) => ({} as import('${vueCompilerOptions.lib}').VNode & { __ctx?: typeof __VLS_setup }))`);
|
|
371
|
+
codes.push(`) => ({} as import('${vueCompilerOptions.lib}').VNode & { __ctx?: Awaited<typeof __VLS_setup> }))`);
|
|
371
372
|
}
|
|
372
373
|
else if (!sfc.script) {
|
|
373
374
|
// no script block, generate script setup code at root
|
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,15 +1,39 @@
|
|
|
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
|
|
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 ?? []);
|
|
13
37
|
const allowLanguageIds = new Set(['vue']);
|
|
14
38
|
if (vueCompilerOptions.extensions.includes('.md')) {
|
|
15
39
|
allowLanguageIds.add('markdown');
|
|
@@ -17,11 +41,18 @@ function createLanguage(compilerOptions = {}, _vueCompilerOptions = {}, ts = req
|
|
|
17
41
|
if (vueCompilerOptions.extensions.includes('.html')) {
|
|
18
42
|
allowLanguageIds.add('html');
|
|
19
43
|
}
|
|
20
|
-
|
|
44
|
+
return {
|
|
21
45
|
createVirtualFile(fileName, snapshot, languageId) {
|
|
22
46
|
if ((languageId && allowLanguageIds.has(languageId))
|
|
23
47
|
|| (!languageId && vueCompilerOptions.extensions.some(ext => fileName.endsWith(ext)))) {
|
|
24
|
-
|
|
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;
|
|
25
56
|
}
|
|
26
57
|
},
|
|
27
58
|
updateVirtualFile(sourceFile, snapshot) {
|
|
@@ -32,6 +63,12 @@ function createLanguage(compilerOptions = {}, _vueCompilerOptions = {}, ts = req
|
|
|
32
63
|
const sharedTypesFileName = path_1.posix.join(host.rootPath, sharedTypes.baseName);
|
|
33
64
|
return {
|
|
34
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
|
+
},
|
|
35
72
|
getScriptFileNames() {
|
|
36
73
|
return [
|
|
37
74
|
sharedTypesFileName,
|
|
@@ -47,32 +84,16 @@ function createLanguage(compilerOptions = {}, _vueCompilerOptions = {}, ts = req
|
|
|
47
84
|
};
|
|
48
85
|
},
|
|
49
86
|
};
|
|
50
|
-
return languageModule;
|
|
51
87
|
}
|
|
52
|
-
exports.
|
|
88
|
+
exports.createVueLanguage = createVueLanguage;
|
|
89
|
+
/**
|
|
90
|
+
* @deprecated planed to remove in 2.0, please use getOrCreateVueLanguage instead of
|
|
91
|
+
*/
|
|
53
92
|
function createLanguages(compilerOptions = {}, vueCompilerOptions = {}, ts = require('typescript'), codegenStack = false) {
|
|
54
93
|
return [
|
|
55
|
-
|
|
94
|
+
createVueLanguage(ts, compilerOptions, vueCompilerOptions, codegenStack),
|
|
56
95
|
...vueCompilerOptions.experimentalAdditionalLanguageModules?.map(module => require(module)) ?? [],
|
|
57
96
|
];
|
|
58
97
|
}
|
|
59
98
|
exports.createLanguages = createLanguages;
|
|
60
|
-
function patchResolveModuleNames(ts, vueCompilerOptions) {
|
|
61
|
-
try {
|
|
62
|
-
// from https://github.com/vuejs/language-tools/pull/1543
|
|
63
|
-
if (!(ts.__vuePatchResolveModuleNames)) {
|
|
64
|
-
ts.__vuePatchResolveModuleNames = true;
|
|
65
|
-
const resolveModuleNames = ts.resolveModuleName;
|
|
66
|
-
ts.resolveModuleName = (...args) => {
|
|
67
|
-
if (args[6] === ts.ModuleKind.ESNext && vueCompilerOptions.extensions.some(ext => args[0].endsWith(ext))) {
|
|
68
|
-
args[6] = ts.ModuleKind.CommonJS;
|
|
69
|
-
}
|
|
70
|
-
return resolveModuleNames(...args);
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
catch (e) {
|
|
75
|
-
// console.warn('[volar] patchResolveModuleNames failed', e);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
99
|
//# sourceMappingURL=languageModule.js.map
|
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/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
|
}
|