@vue/language-core 2.0.19 → 2.0.21
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/index.js +2 -2
- package/lib/codegen/script/internalComponent.js +3 -2
- package/lib/codegen/script/scriptSetup.d.ts +1 -1
- package/lib/codegen/script/scriptSetup.js +11 -7
- package/lib/codegen/template/element.js +3 -1
- package/lib/codegen/template/vFor.js +2 -2
- package/lib/languageModule.d.ts +2 -6
- package/lib/languageModule.js +12 -20
- package/lib/plugins/file-md.js +10 -2
- package/lib/plugins/vue-template-inline-ts.js +0 -1
- package/lib/plugins/vue-tsx.d.ts +1 -1
- package/lib/virtualFile/computedFiles.js +20 -11
- package/package.json +3 -3
|
@@ -40,7 +40,7 @@ function* generateScript(options) {
|
|
|
40
40
|
const isExportRawObject = exportDefault
|
|
41
41
|
&& options.sfc.script.content[exportDefault.expression.start] === '{';
|
|
42
42
|
if (options.sfc.scriptSetup && options.scriptSetupRanges) {
|
|
43
|
-
yield (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges);
|
|
43
|
+
yield* (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges);
|
|
44
44
|
if (exportDefault) {
|
|
45
45
|
yield (0, common_1.generateSfcBlockSection)(options.sfc.script, 0, exportDefault.expression.start, exports.codeFeatures.all);
|
|
46
46
|
yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
|
|
@@ -99,7 +99,7 @@ function* generateScript(options) {
|
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
else if (options.sfc.scriptSetup && options.scriptSetupRanges) {
|
|
102
|
-
yield (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges);
|
|
102
|
+
yield* (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges);
|
|
103
103
|
yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
|
|
104
104
|
}
|
|
105
105
|
yield common_1.endOfLine;
|
|
@@ -6,7 +6,8 @@ const component_1 = require("./component");
|
|
|
6
6
|
const template_1 = require("./template");
|
|
7
7
|
function* generateInternalComponent(options, ctx, templateCodegenCtx) {
|
|
8
8
|
if (options.sfc.scriptSetup && options.scriptSetupRanges) {
|
|
9
|
-
yield `
|
|
9
|
+
yield `let __VLS_defineComponent!: typeof import('${options.vueCompilerOptions.lib}').defineComponent${common_1.endOfLine}`;
|
|
10
|
+
yield `const __VLS_internalComponent = __VLS_defineComponent({${common_1.newLine}`;
|
|
10
11
|
yield `setup() {${common_1.newLine}`;
|
|
11
12
|
yield `return {${common_1.newLine}`;
|
|
12
13
|
if (ctx.bypassDefineComponent) {
|
|
@@ -48,7 +49,7 @@ function* generateInternalComponent(options, ctx, templateCodegenCtx) {
|
|
|
48
49
|
yield `})${common_1.endOfLine}`; // defineComponent {
|
|
49
50
|
}
|
|
50
51
|
else if (options.sfc.script) {
|
|
51
|
-
yield `
|
|
52
|
+
yield `let __VLS_internalComponent!: typeof import('./${options.fileBaseName}').default${common_1.endOfLine}`;
|
|
52
53
|
}
|
|
53
54
|
else {
|
|
54
55
|
yield `const __VLS_internalComponent = (await import('${options.vueCompilerOptions.lib}')).defineComponent({})${common_1.endOfLine}`;
|
|
@@ -2,5 +2,5 @@ import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
|
|
|
2
2
|
import type { Code, Sfc } from '../../types';
|
|
3
3
|
import type { ScriptCodegenContext } from './context';
|
|
4
4
|
import { ScriptCodegenOptions } from './index';
|
|
5
|
-
export declare function generateScriptSetupImports(scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Code
|
|
5
|
+
export declare function generateScriptSetupImports(scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
|
|
6
6
|
export declare function generateScriptSetup(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
|
|
@@ -5,13 +5,14 @@ const common_1 = require("../common");
|
|
|
5
5
|
const component_1 = require("./component");
|
|
6
6
|
const index_1 = require("./index");
|
|
7
7
|
const template_1 = require("./template");
|
|
8
|
-
function generateScriptSetupImports(scriptSetup, scriptSetupRanges) {
|
|
9
|
-
|
|
10
|
-
scriptSetup.content.substring(0, Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset))
|
|
8
|
+
function* generateScriptSetupImports(scriptSetup, scriptSetupRanges) {
|
|
9
|
+
yield [
|
|
10
|
+
scriptSetup.content.substring(0, Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset)),
|
|
11
11
|
'scriptSetup',
|
|
12
12
|
0,
|
|
13
13
|
index_1.codeFeatures.all,
|
|
14
14
|
];
|
|
15
|
+
yield common_1.newLine;
|
|
15
16
|
}
|
|
16
17
|
exports.generateScriptSetupImports = generateScriptSetupImports;
|
|
17
18
|
function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
@@ -341,9 +342,9 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, d
|
|
|
341
342
|
yield common_1.endOfLine;
|
|
342
343
|
}
|
|
343
344
|
function* generateModelEmits(options, scriptSetup, scriptSetupRanges) {
|
|
344
|
-
yield `
|
|
345
|
-
if (scriptSetupRanges.defineProp.length) {
|
|
346
|
-
yield `
|
|
345
|
+
yield `const __VLS_modelEmitsType = `;
|
|
346
|
+
if (scriptSetupRanges.defineProp.filter(p => p.isModel).length) {
|
|
347
|
+
yield `(await import('${options.vueCompilerOptions.lib}')).defineEmits<{${common_1.newLine}`;
|
|
347
348
|
for (const defineProp of scriptSetupRanges.defineProp) {
|
|
348
349
|
if (!defineProp.isModel) {
|
|
349
350
|
continue;
|
|
@@ -362,7 +363,10 @@ function* generateModelEmits(options, scriptSetup, scriptSetupRanges) {
|
|
|
362
363
|
}
|
|
363
364
|
yield `]${common_1.endOfLine}`;
|
|
364
365
|
}
|
|
365
|
-
yield `}
|
|
366
|
+
yield `}>()`;
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
yield `{}`;
|
|
366
370
|
}
|
|
367
371
|
yield common_1.endOfLine;
|
|
368
372
|
}
|
|
@@ -85,13 +85,14 @@ function* generateComponent(options, ctx, node, currentComponent, componentCtxVa
|
|
|
85
85
|
yield common_1.endOfLine;
|
|
86
86
|
}
|
|
87
87
|
else if (!isComponentTag) {
|
|
88
|
+
yield `// @ts-ignore${common_1.newLine}`;
|
|
88
89
|
yield `const ${var_originalComponent} = ({} as `;
|
|
89
90
|
for (const componentName of possibleOriginalNames) {
|
|
90
91
|
yield `'${componentName}' extends keyof typeof __VLS_ctx ? { '${getCanonicalComponentName(node.tag)}': typeof __VLS_ctx`;
|
|
91
92
|
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, componentName);
|
|
92
93
|
yield ` }: `;
|
|
93
94
|
}
|
|
94
|
-
yield `typeof __VLS_resolvedLocalAndGlobalComponents)`;
|
|
95
|
+
yield `typeof __VLS_resolvedLocalAndGlobalComponents)${common_1.newLine}`;
|
|
95
96
|
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, getCanonicalComponentName(node.tag), startTagOffset, ctx.codeFeatures.verification);
|
|
96
97
|
yield common_1.endOfLine;
|
|
97
98
|
// hover support
|
|
@@ -135,6 +136,7 @@ function* generateComponent(options, ctx, node, currentComponent, componentCtxVa
|
|
|
135
136
|
else {
|
|
136
137
|
yield `const ${var_originalComponent} = {} as any${common_1.endOfLine}`;
|
|
137
138
|
}
|
|
139
|
+
yield `// @ts-ignore${common_1.newLine}`;
|
|
138
140
|
yield `const ${var_functionalComponent} = __VLS_asFunctionalComponent(${var_originalComponent}, new ${var_originalComponent}({`;
|
|
139
141
|
yield* (0, elementProps_1.generateElementProps)(options, ctx, node, props, false);
|
|
140
142
|
yield `}))${common_1.endOfLine}`;
|
|
@@ -36,8 +36,8 @@ function* generateVFor(options, ctx, node, currentComponent, componentCtxVar) {
|
|
|
36
36
|
let isFragment = true;
|
|
37
37
|
for (const argument of node.codegenNode?.children.arguments ?? []) {
|
|
38
38
|
if (argument.type === CompilerDOM.NodeTypes.JS_FUNCTION_EXPRESSION
|
|
39
|
-
&& argument.returns
|
|
40
|
-
&& argument.returns
|
|
39
|
+
&& argument.returns?.type === CompilerDOM.NodeTypes.VNODE_CALL
|
|
40
|
+
&& argument.returns?.props?.type === CompilerDOM.NodeTypes.JS_OBJECT_EXPRESSION) {
|
|
41
41
|
if (argument.returns.tag !== CompilerDOM.FRAGMENT) {
|
|
42
42
|
isFragment = false;
|
|
43
43
|
continue;
|
package/lib/languageModule.d.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { type LanguagePlugin } from '@volar/language-core';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
|
-
import type { VueCompilerOptions
|
|
3
|
+
import type { VueCompilerOptions } from './types';
|
|
4
4
|
import { VueVirtualCode } from './virtualFile/vueFile';
|
|
5
|
-
export
|
|
6
|
-
getCanonicalFileName: (fileName: string) => string;
|
|
7
|
-
pluginContext: Parameters<VueLanguagePlugin>[0];
|
|
8
|
-
}
|
|
9
|
-
export declare function createVueLanguagePlugin(ts: typeof import('typescript'), getFileName: (scriptId: string) => string, useCaseSensitiveFileNames: boolean, getProjectVersion: () => string, getScriptFileNames: () => string[] | Set<string>, compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions): _Plugin;
|
|
5
|
+
export declare function createVueLanguagePlugin<T>(ts: typeof import('typescript'), asFileName: (scriptId: T) => string, getProjectVersion: () => string, isRootFile: (fileName: string) => boolean, compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions): LanguagePlugin<T, VueVirtualCode>;
|
package/lib/languageModule.js
CHANGED
|
@@ -38,7 +38,7 @@ function getFileRegistryKey(compilerOptions, vueCompilerOptions, plugins) {
|
|
|
38
38
|
];
|
|
39
39
|
return JSON.stringify(values);
|
|
40
40
|
}
|
|
41
|
-
function createVueLanguagePlugin(ts,
|
|
41
|
+
function createVueLanguagePlugin(ts, asFileName, getProjectVersion, isRootFile, compilerOptions, vueCompilerOptions) {
|
|
42
42
|
const pluginContext = {
|
|
43
43
|
modules: {
|
|
44
44
|
'@vue/compiler-dom': vueCompilerOptions.target < 3
|
|
@@ -57,38 +57,30 @@ function createVueLanguagePlugin(ts, getFileName, useCaseSensitiveFileNames, get
|
|
|
57
57
|
const vueSfcPlugin = (0, file_vue_1.default)(pluginContext);
|
|
58
58
|
const vitePressSfcPlugin = (0, file_md_1.default)(pluginContext);
|
|
59
59
|
const petiteVueSfcPlugin = (0, file_html_1.default)(pluginContext);
|
|
60
|
-
const getCanonicalFileName = useCaseSensitiveFileNames
|
|
61
|
-
? (fileName) => fileName
|
|
62
|
-
: (fileName) => fileName.toLowerCase();
|
|
63
|
-
let canonicalRootFileNames = new Set();
|
|
64
60
|
let canonicalRootFileNamesVersion;
|
|
65
61
|
return {
|
|
66
|
-
getCanonicalFileName,
|
|
67
|
-
pluginContext,
|
|
68
62
|
getLanguageId(scriptId) {
|
|
69
|
-
if (vueCompilerOptions.extensions.some(ext => scriptId.endsWith(ext))) {
|
|
63
|
+
if (vueCompilerOptions.extensions.some(ext => asFileName(scriptId).endsWith(ext))) {
|
|
70
64
|
return 'vue';
|
|
71
65
|
}
|
|
72
|
-
if (vueCompilerOptions.vitePressExtensions.some(ext => scriptId.endsWith(ext))) {
|
|
66
|
+
if (vueCompilerOptions.vitePressExtensions.some(ext => asFileName(scriptId).endsWith(ext))) {
|
|
73
67
|
return 'markdown';
|
|
74
68
|
}
|
|
75
|
-
if (vueCompilerOptions.petiteVueExtensions.some(ext => scriptId.endsWith(ext))) {
|
|
69
|
+
if (vueCompilerOptions.petiteVueExtensions.some(ext => asFileName(scriptId).endsWith(ext))) {
|
|
76
70
|
return 'html';
|
|
77
71
|
}
|
|
78
72
|
},
|
|
79
73
|
createVirtualCode(scriptId, languageId, snapshot) {
|
|
80
74
|
if (languageId === 'vue' || languageId === 'markdown' || languageId === 'html') {
|
|
81
|
-
const fileName =
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (!pluginContext.globalTypesHolder && canonicalRootFileNames.has(getCanonicalFileName(fileName))) {
|
|
88
|
-
pluginContext.globalTypesHolder = fileName;
|
|
75
|
+
const fileName = asFileName(scriptId);
|
|
76
|
+
if (!pluginContext.globalTypesHolder && getProjectVersion() !== canonicalRootFileNamesVersion) {
|
|
77
|
+
canonicalRootFileNamesVersion = getProjectVersion();
|
|
78
|
+
if (isRootFile(fileName)) {
|
|
79
|
+
pluginContext.globalTypesHolder = fileName;
|
|
80
|
+
}
|
|
89
81
|
}
|
|
90
82
|
const fileRegistry = getFileRegistry(pluginContext.globalTypesHolder === fileName);
|
|
91
|
-
const code = fileRegistry.get(
|
|
83
|
+
const code = fileRegistry.get(fileName);
|
|
92
84
|
if (code) {
|
|
93
85
|
code.update(snapshot);
|
|
94
86
|
return code;
|
|
@@ -99,7 +91,7 @@ function createVueLanguagePlugin(ts, getFileName, useCaseSensitiveFileNames, get
|
|
|
99
91
|
: languageId === 'markdown'
|
|
100
92
|
? [vitePressSfcPlugin, ...basePlugins]
|
|
101
93
|
: [vueSfcPlugin, ...basePlugins], ts);
|
|
102
|
-
fileRegistry.set(
|
|
94
|
+
fileRegistry.set(fileName, code);
|
|
103
95
|
return code;
|
|
104
96
|
}
|
|
105
97
|
}
|
package/lib/plugins/file-md.js
CHANGED
|
@@ -59,8 +59,16 @@ const plugin = () => {
|
|
|
59
59
|
}
|
|
60
60
|
return sfc;
|
|
61
61
|
function transformRange(block) {
|
|
62
|
-
block.loc.start.offset =
|
|
63
|
-
block.loc.end.offset =
|
|
62
|
+
block.loc.start.offset = -1;
|
|
63
|
+
block.loc.end.offset = -1;
|
|
64
|
+
for (const [start] of file2VueSourceMap.getSourceOffsets(block.loc.start.offset)) {
|
|
65
|
+
block.loc.start.offset = start;
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
for (const [end] of file2VueSourceMap.getSourceOffsets(block.loc.end.offset)) {
|
|
69
|
+
block.loc.end.offset = end;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
64
72
|
}
|
|
65
73
|
}
|
|
66
74
|
};
|
|
@@ -7,7 +7,6 @@ const vFor_1 = require("../codegen/template/vFor");
|
|
|
7
7
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
8
8
|
const codeFeatures = {
|
|
9
9
|
format: true,
|
|
10
|
-
// autoInserts: true, // TODO: support vue-autoinsert-parentheses
|
|
11
10
|
};
|
|
12
11
|
const formatBrackets = {
|
|
13
12
|
normal: ['`${', '}`;'],
|
package/lib/plugins/vue-tsx.d.ts
CHANGED
|
@@ -149,21 +149,30 @@ function computedPluginEmbeddedCodes(plugins, plugin, fileName, sfc, nameToBlock
|
|
|
149
149
|
return (0, computeds_1.computed)(() => {
|
|
150
150
|
return codes().map(_file => {
|
|
151
151
|
const { code, snapshot } = _file();
|
|
152
|
-
const mappings = (0, language_core_1.buildMappings)(code.content
|
|
152
|
+
const mappings = (0, language_core_1.buildMappings)(code.content.map(segment => {
|
|
153
|
+
if (typeof segment === 'string') {
|
|
154
|
+
return segment;
|
|
155
|
+
}
|
|
156
|
+
const source = segment[1];
|
|
157
|
+
if (source === undefined) {
|
|
158
|
+
return segment;
|
|
159
|
+
}
|
|
160
|
+
const block = nameToBlock()[source];
|
|
161
|
+
if (!block) {
|
|
162
|
+
// console.warn('Unable to find block: ' + source);
|
|
163
|
+
return segment;
|
|
164
|
+
}
|
|
165
|
+
return [
|
|
166
|
+
segment[0],
|
|
167
|
+
undefined,
|
|
168
|
+
segment[2] + block.startTagEnd,
|
|
169
|
+
segment[3],
|
|
170
|
+
];
|
|
171
|
+
}));
|
|
153
172
|
const newMappings = [];
|
|
154
173
|
let lastValidMapping;
|
|
155
174
|
for (let i = 0; i < mappings.length; i++) {
|
|
156
175
|
const mapping = mappings[i];
|
|
157
|
-
if (mapping.source !== undefined) {
|
|
158
|
-
const block = nameToBlock()[mapping.source];
|
|
159
|
-
if (block) {
|
|
160
|
-
mapping.sourceOffsets = mapping.sourceOffsets.map(offset => offset + block.startTagEnd);
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
// ignore
|
|
164
|
-
}
|
|
165
|
-
mapping.source = undefined;
|
|
166
|
-
}
|
|
167
176
|
if (mapping.data.__combineOffsetMapping !== undefined) {
|
|
168
177
|
const offsetMapping = mappings[i - mapping.data.__combineOffsetMapping];
|
|
169
178
|
if (typeof offsetMapping === 'string' || !offsetMapping) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/language-core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.21",
|
|
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.
|
|
15
|
+
"@volar/language-core": "~2.3.0-alpha.15",
|
|
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": "a5af80e3939a39694abd9dd09a5496bc5fbf6e06"
|
|
38
38
|
}
|