@vue/language-core 2.1.6 → 2.1.10
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/common.d.ts +2 -2
- package/lib/codegen/common.js +8 -10
- package/lib/codegen/globalTypes.js +10 -7
- package/lib/codegen/{types.d.ts → inlayHints.d.ts} +2 -0
- package/lib/codegen/inlayHints.js +17 -0
- package/lib/codegen/script/component.d.ts +1 -1
- package/lib/codegen/script/component.js +8 -5
- package/lib/codegen/script/componentSelf.js +3 -2
- package/lib/codegen/script/context.d.ts +1 -1
- package/lib/codegen/script/index.d.ts +2 -1
- package/lib/codegen/script/index.js +28 -10
- package/lib/codegen/script/scriptSetup.js +107 -112
- package/lib/codegen/script/styleModulesType.js +4 -6
- package/lib/codegen/script/template.d.ts +1 -1
- package/lib/codegen/script/template.js +13 -14
- package/lib/codegen/template/context.d.ts +3 -2
- package/lib/codegen/template/context.js +1 -0
- package/lib/codegen/template/element.d.ts +1 -1
- package/lib/codegen/template/element.js +31 -11
- package/lib/codegen/template/elementDirectives.js +63 -31
- package/lib/codegen/template/elementProps.js +7 -17
- package/lib/codegen/template/index.d.ts +1 -0
- package/lib/codegen/template/index.js +63 -53
- package/lib/codegen/template/interpolation.d.ts +1 -1
- package/lib/codegen/template/interpolation.js +34 -28
- package/lib/codegen/template/slotOutlet.js +5 -0
- package/lib/codegen/template/templateChild.d.ts +1 -1
- package/lib/codegen/template/templateChild.js +6 -2
- package/lib/codegen/template/vFor.js +1 -1
- package/lib/parsers/scriptSetupRanges.d.ts +17 -5
- package/lib/parsers/scriptSetupRanges.js +43 -27
- package/lib/plugins/vue-tsx.d.ts +30 -17
- package/lib/plugins/vue-tsx.js +44 -33
- package/lib/types.d.ts +3 -1
- package/lib/utils/parseCssClassNames.d.ts +1 -1
- package/lib/utils/parseCssClassNames.js +5 -4
- package/lib/utils/parseCssVars.d.ts +3 -2
- package/lib/utils/parseCssVars.js +12 -11
- package/lib/utils/ts.d.ts +1 -1
- package/lib/utils/ts.js +3 -5
- package/lib/virtualFile/computedEmbeddedCodes.d.ts +2 -1
- package/lib/virtualFile/computedEmbeddedCodes.js +11 -11
- package/lib/virtualFile/computedSfc.d.ts +2 -1
- package/lib/virtualFile/computedSfc.js +77 -76
- package/lib/virtualFile/computedVueSfc.d.ts +2 -1
- package/lib/virtualFile/computedVueSfc.js +8 -8
- package/lib/virtualFile/vueFile.d.ts +6 -7
- package/lib/virtualFile/vueFile.js +13 -12
- package/package.json +9 -8
- package/lib/codegen/types.js +0 -3
|
@@ -8,8 +8,7 @@ const common_1 = require("../common");
|
|
|
8
8
|
function* generateInterpolation(options, ctx, _code, astHolder, start, data, prefix, suffix) {
|
|
9
9
|
const code = prefix + _code + suffix;
|
|
10
10
|
const ast = (0, common_1.createTsAst)(options.ts, astHolder, code);
|
|
11
|
-
|
|
12
|
-
for (let [section, offset, onlyError] of forEachInterpolationSegment(options.ts, options.templateRefNames, ctx, code, start !== undefined ? start - prefix.length : undefined, ast)) {
|
|
11
|
+
for (let [section, offset, type] of forEachInterpolationSegment(options.ts, options.destructuredPropNames, options.templateRefNames, ctx, code, start !== undefined ? start - prefix.length : undefined, ast)) {
|
|
13
12
|
if (offset === undefined) {
|
|
14
13
|
yield section;
|
|
15
14
|
}
|
|
@@ -26,29 +25,28 @@ function* generateInterpolation(options, ctx, _code, astHolder, start, data, pre
|
|
|
26
25
|
section = section.substring(-offset);
|
|
27
26
|
offset = 0;
|
|
28
27
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
28
|
+
const shouldSkip = section.length === 0 && (type === 'startText' || type === 'endText');
|
|
29
|
+
if (!shouldSkip) {
|
|
30
|
+
if (start !== undefined
|
|
31
|
+
&& data) {
|
|
32
|
+
yield [
|
|
33
|
+
section,
|
|
34
|
+
'template',
|
|
35
|
+
start + offset,
|
|
36
|
+
type === 'errorMappingOnly'
|
|
37
|
+
? ctx.codeFeatures.verification
|
|
38
|
+
: typeof data === 'function' ? data(start + offset) : data,
|
|
39
|
+
];
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
yield section;
|
|
43
|
+
}
|
|
41
44
|
}
|
|
42
45
|
yield addSuffix;
|
|
43
46
|
}
|
|
44
47
|
}
|
|
45
|
-
if (start !== undefined) {
|
|
46
|
-
for (const v of vars) {
|
|
47
|
-
v.offset = start + v.offset - prefix.length;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
48
|
}
|
|
51
|
-
function* forEachInterpolationSegment(ts, templateRefNames, ctx, code, offset, ast) {
|
|
49
|
+
function* forEachInterpolationSegment(ts, destructuredPropNames, templateRefNames, ctx, code, offset, ast) {
|
|
52
50
|
let ctxVars = [];
|
|
53
51
|
const varCb = (id, isShorthand) => {
|
|
54
52
|
const text = (0, scriptSetupRanges_1.getNodeText)(ts, id, ast);
|
|
@@ -65,6 +63,9 @@ function* forEachInterpolationSegment(ts, templateRefNames, ctx, code, offset, a
|
|
|
65
63
|
isShorthand: isShorthand,
|
|
66
64
|
offset: (0, scriptSetupRanges_1.getStartEnd)(ts, id, ast).start,
|
|
67
65
|
});
|
|
66
|
+
if (destructuredPropNames?.has(text)) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
68
69
|
if (offset !== undefined) {
|
|
69
70
|
ctx.accessExternalVariable(text, offset + (0, scriptSetupRanges_1.getStartEnd)(ts, id, ast).start);
|
|
70
71
|
}
|
|
@@ -80,13 +81,13 @@ function* forEachInterpolationSegment(ts, templateRefNames, ctx, code, offset, a
|
|
|
80
81
|
yield [code.substring(0, ctxVars[0].offset + ctxVars[0].text.length), 0];
|
|
81
82
|
yield [': ', undefined];
|
|
82
83
|
}
|
|
83
|
-
else {
|
|
84
|
-
yield [code.substring(0, ctxVars[0].offset), 0];
|
|
84
|
+
else if (ctxVars[0].offset > 0) {
|
|
85
|
+
yield [code.substring(0, ctxVars[0].offset), 0, 'startText'];
|
|
85
86
|
}
|
|
86
87
|
for (let i = 0; i < ctxVars.length - 1; i++) {
|
|
87
88
|
const curVar = ctxVars[i];
|
|
88
89
|
const nextVar = ctxVars[i + 1];
|
|
89
|
-
yield* generateVar(code, templateRefNames, curVar, nextVar);
|
|
90
|
+
yield* generateVar(code, destructuredPropNames, templateRefNames, curVar, nextVar);
|
|
90
91
|
if (nextVar.isShorthand) {
|
|
91
92
|
yield [code.substring(curVar.offset + curVar.text.length, nextVar.offset + nextVar.text.length), curVar.offset + curVar.text.length];
|
|
92
93
|
yield [': ', undefined];
|
|
@@ -96,17 +97,20 @@ function* forEachInterpolationSegment(ts, templateRefNames, ctx, code, offset, a
|
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
99
|
const lastVar = ctxVars.at(-1);
|
|
99
|
-
yield* generateVar(code, templateRefNames, lastVar);
|
|
100
|
-
|
|
100
|
+
yield* generateVar(code, destructuredPropNames, templateRefNames, lastVar);
|
|
101
|
+
if (lastVar.offset + lastVar.text.length < code.length) {
|
|
102
|
+
yield [code.substring(lastVar.offset + lastVar.text.length), lastVar.offset + lastVar.text.length, 'endText'];
|
|
103
|
+
}
|
|
101
104
|
}
|
|
102
105
|
else {
|
|
103
106
|
yield [code, 0];
|
|
104
107
|
}
|
|
105
108
|
}
|
|
106
|
-
function* generateVar(code, templateRefNames, curVar, nextVar = curVar) {
|
|
109
|
+
function* generateVar(code, destructuredPropNames, templateRefNames, curVar, nextVar = curVar) {
|
|
107
110
|
// fix https://github.com/vuejs/language-tools/issues/1205
|
|
108
111
|
// fix https://github.com/vuejs/language-tools/issues/1264
|
|
109
|
-
yield ['', nextVar.offset,
|
|
112
|
+
yield ['', nextVar.offset, 'errorMappingOnly'];
|
|
113
|
+
const isDestructuredProp = destructuredPropNames?.has(curVar.text) ?? false;
|
|
110
114
|
const isTemplateRef = templateRefNames?.has(curVar.text) ?? false;
|
|
111
115
|
if (isTemplateRef) {
|
|
112
116
|
yield [`__VLS_unref(`, undefined];
|
|
@@ -114,7 +118,9 @@ function* generateVar(code, templateRefNames, curVar, nextVar = curVar) {
|
|
|
114
118
|
yield [`)`, undefined];
|
|
115
119
|
}
|
|
116
120
|
else {
|
|
117
|
-
|
|
121
|
+
if (!isDestructuredProp) {
|
|
122
|
+
yield [`__VLS_ctx.`, undefined];
|
|
123
|
+
}
|
|
118
124
|
yield [code.substring(curVar.offset, curVar.offset + curVar.text.length), curVar.offset];
|
|
119
125
|
}
|
|
120
126
|
}
|
|
@@ -6,6 +6,7 @@ const common_1 = require("../common");
|
|
|
6
6
|
const elementChildren_1 = require("./elementChildren");
|
|
7
7
|
const elementProps_1 = require("./elementProps");
|
|
8
8
|
const interpolation_1 = require("./interpolation");
|
|
9
|
+
const inlayHints_1 = require("../inlayHints");
|
|
9
10
|
function* generateSlotOutlet(options, ctx, node, currentComponent, componentCtxVar) {
|
|
10
11
|
const startTagOffset = node.loc.start.offset + options.template.content.substring(node.loc.start.offset).indexOf(node.tag);
|
|
11
12
|
const varSlot = ctx.getInternalVariable();
|
|
@@ -46,6 +47,10 @@ function* generateSlotOutlet(options, ctx, node, currentComponent, componentCtxV
|
|
|
46
47
|
}
|
|
47
48
|
else if (nameProp?.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
48
49
|
&& nameProp.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
50
|
+
const isShortHand = nameProp.arg?.loc.start.offset === nameProp.exp.loc.start.offset;
|
|
51
|
+
if (isShortHand) {
|
|
52
|
+
ctx.inlayHints.push((0, inlayHints_1.createVBindShorthandInlayHintInfo)(nameProp.exp.loc, 'name'));
|
|
53
|
+
}
|
|
49
54
|
const slotExpVar = ctx.getInternalVariable();
|
|
50
55
|
yield `var ${slotExpVar} = `;
|
|
51
56
|
yield* (0, interpolation_1.generateInterpolation)(options, ctx, nameProp.exp.content, nameProp.exp, nameProp.exp.loc.start.offset, ctx.codeFeatures.all, '(', ')');
|
|
@@ -2,6 +2,6 @@ import * as CompilerDOM from '@vue/compiler-dom';
|
|
|
2
2
|
import type { Code } from '../../types';
|
|
3
3
|
import type { TemplateCodegenContext } from './context';
|
|
4
4
|
import type { TemplateCodegenOptions } from './index';
|
|
5
|
-
export declare function generateTemplateChild(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode, currentComponent: CompilerDOM.ElementNode | undefined, prevNode: CompilerDOM.TemplateChildNode | undefined, componentCtxVar: string | undefined): Generator<Code>;
|
|
5
|
+
export declare function generateTemplateChild(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode, currentComponent: CompilerDOM.ElementNode | undefined, prevNode: CompilerDOM.TemplateChildNode | undefined, componentCtxVar: string | undefined, isVForChild?: boolean): Generator<Code>;
|
|
6
6
|
export declare function getVForNode(node: CompilerDOM.ElementNode): CompilerDOM.ForNode | undefined;
|
|
7
7
|
export declare function parseInterpolationNode(node: CompilerDOM.InterpolationNode, template: string): readonly [string, number];
|
|
@@ -25,7 +25,7 @@ const transformContext = {
|
|
|
25
25
|
},
|
|
26
26
|
expressionPlugins: ['typescript'],
|
|
27
27
|
};
|
|
28
|
-
function* generateTemplateChild(options, ctx, node, currentComponent, prevNode, componentCtxVar) {
|
|
28
|
+
function* generateTemplateChild(options, ctx, node, currentComponent, prevNode, componentCtxVar, isVForChild = false) {
|
|
29
29
|
if (prevNode?.type === CompilerDOM.NodeTypes.COMMENT) {
|
|
30
30
|
const commentText = prevNode.content.trim().split(' ')[0];
|
|
31
31
|
if (commentText.match(/^@vue-skip\b[\s\S]*/)) {
|
|
@@ -40,6 +40,10 @@ function* generateTemplateChild(options, ctx, node, currentComponent, prevNode,
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
const shouldInheritRootNodeAttrs = options.inheritAttrs;
|
|
43
|
+
const cur = node;
|
|
44
|
+
if (cur.codegenNode?.type === CompilerDOM.NodeTypes.JS_CACHE_EXPRESSION) {
|
|
45
|
+
cur.codegenNode = cur.codegenNode.value;
|
|
46
|
+
}
|
|
43
47
|
if (node.type === CompilerDOM.NodeTypes.ROOT) {
|
|
44
48
|
let prev;
|
|
45
49
|
if (shouldInheritRootNodeAttrs && node.children.length === 1 && node.children[0].type === CompilerDOM.NodeTypes.ELEMENT) {
|
|
@@ -66,7 +70,7 @@ function* generateTemplateChild(options, ctx, node, currentComponent, prevNode,
|
|
|
66
70
|
}
|
|
67
71
|
else if (node.tagType === CompilerDOM.ElementTypes.ELEMENT
|
|
68
72
|
|| node.tagType === CompilerDOM.ElementTypes.TEMPLATE) {
|
|
69
|
-
yield* (0, element_1.generateElement)(options, ctx, node, currentComponent, componentCtxVar);
|
|
73
|
+
yield* (0, element_1.generateElement)(options, ctx, node, currentComponent, componentCtxVar, isVForChild);
|
|
70
74
|
}
|
|
71
75
|
else {
|
|
72
76
|
yield* (0, element_1.generateComponent)(options, ctx, node, currentComponent);
|
|
@@ -57,7 +57,7 @@ function* generateVFor(options, ctx, node, currentComponent, componentCtxVar) {
|
|
|
57
57
|
}
|
|
58
58
|
let prev;
|
|
59
59
|
for (const childNode of node.children) {
|
|
60
|
-
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, currentComponent, prev, componentCtxVar);
|
|
60
|
+
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, currentComponent, prev, componentCtxVar, true);
|
|
61
61
|
prev = childNode;
|
|
62
62
|
}
|
|
63
63
|
for (const varName of forBlockVars) {
|
|
@@ -9,8 +9,10 @@ export declare function parseScriptSetupRanges(ts: typeof import('typescript'),
|
|
|
9
9
|
importComponentNames: Set<string>;
|
|
10
10
|
props: {
|
|
11
11
|
name?: string;
|
|
12
|
-
destructured?: string
|
|
12
|
+
destructured?: Set<string>;
|
|
13
|
+
destructuredRest?: string;
|
|
13
14
|
define?: ReturnType<(node: ts.CallExpression) => TextRange & {
|
|
15
|
+
exp: TextRange;
|
|
14
16
|
arg?: TextRange;
|
|
15
17
|
typeArg?: TextRange;
|
|
16
18
|
}> & {
|
|
@@ -24,22 +26,28 @@ export declare function parseScriptSetupRanges(ts: typeof import('typescript'),
|
|
|
24
26
|
name?: string;
|
|
25
27
|
isObjectBindingPattern?: boolean;
|
|
26
28
|
define?: ReturnType<(node: ts.CallExpression) => TextRange & {
|
|
29
|
+
exp: TextRange;
|
|
27
30
|
arg?: TextRange;
|
|
28
31
|
typeArg?: TextRange;
|
|
29
|
-
}
|
|
32
|
+
}> & {
|
|
33
|
+
statement: TextRange;
|
|
34
|
+
};
|
|
30
35
|
};
|
|
31
36
|
emits: {
|
|
32
37
|
name?: string;
|
|
33
38
|
define?: ReturnType<(node: ts.CallExpression) => TextRange & {
|
|
39
|
+
exp: TextRange;
|
|
34
40
|
arg?: TextRange;
|
|
35
41
|
typeArg?: TextRange;
|
|
36
42
|
}> & {
|
|
43
|
+
statement: TextRange;
|
|
37
44
|
hasUnionTypeArg?: boolean;
|
|
38
45
|
};
|
|
39
46
|
};
|
|
40
47
|
expose: {
|
|
41
48
|
name?: string;
|
|
42
49
|
define?: ReturnType<(node: ts.CallExpression) => TextRange & {
|
|
50
|
+
exp: TextRange;
|
|
43
51
|
arg?: TextRange;
|
|
44
52
|
typeArg?: TextRange;
|
|
45
53
|
}>;
|
|
@@ -49,8 +57,11 @@ export declare function parseScriptSetupRanges(ts: typeof import('typescript'),
|
|
|
49
57
|
inheritAttrs?: string;
|
|
50
58
|
};
|
|
51
59
|
cssModules: {
|
|
52
|
-
|
|
53
|
-
|
|
60
|
+
define: ReturnType<(node: ts.CallExpression) => TextRange & {
|
|
61
|
+
exp: TextRange;
|
|
62
|
+
arg?: TextRange;
|
|
63
|
+
typeArg?: TextRange;
|
|
64
|
+
}>;
|
|
54
65
|
}[];
|
|
55
66
|
defineProp: {
|
|
56
67
|
localName: TextRange | undefined;
|
|
@@ -64,7 +75,8 @@ export declare function parseScriptSetupRanges(ts: typeof import('typescript'),
|
|
|
64
75
|
}[];
|
|
65
76
|
templateRefs: {
|
|
66
77
|
name?: string;
|
|
67
|
-
define
|
|
78
|
+
define: ReturnType<(node: ts.CallExpression) => TextRange & {
|
|
79
|
+
exp: TextRange;
|
|
68
80
|
arg?: TextRange;
|
|
69
81
|
typeArg?: TextRange;
|
|
70
82
|
}>;
|
|
@@ -76,6 +76,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
76
76
|
function parseDefineFunction(node) {
|
|
77
77
|
return {
|
|
78
78
|
..._getStartEnd(node),
|
|
79
|
+
exp: _getStartEnd(node.expression),
|
|
79
80
|
arg: node.arguments.length ? _getStartEnd(node.arguments[0]) : undefined,
|
|
80
81
|
typeArg: node.typeArguments?.length ? _getStartEnd(node.typeArguments[0]) : undefined,
|
|
81
82
|
};
|
|
@@ -206,7 +207,10 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
206
207
|
});
|
|
207
208
|
}
|
|
208
209
|
else if (vueCompilerOptions.macros.defineSlots.includes(callText)) {
|
|
209
|
-
slots.define =
|
|
210
|
+
slots.define = {
|
|
211
|
+
...parseDefineFunction(node),
|
|
212
|
+
statement: getStatementRange(ts, parents, node, ast)
|
|
213
|
+
};
|
|
210
214
|
if (ts.isVariableDeclaration(parent)) {
|
|
211
215
|
if (ts.isIdentifier(parent.name)) {
|
|
212
216
|
slots.name = getNodeText(ts, parent.name, ast);
|
|
@@ -217,7 +221,10 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
217
221
|
}
|
|
218
222
|
}
|
|
219
223
|
else if (vueCompilerOptions.macros.defineEmits.includes(callText)) {
|
|
220
|
-
emits.define =
|
|
224
|
+
emits.define = {
|
|
225
|
+
...parseDefineFunction(node),
|
|
226
|
+
statement: getStatementRange(ts, parents, node, ast)
|
|
227
|
+
};
|
|
221
228
|
if (ts.isVariableDeclaration(parent)) {
|
|
222
229
|
emits.name = getNodeText(ts, parent.name, ast);
|
|
223
230
|
}
|
|
@@ -236,30 +243,25 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
236
243
|
else if (vueCompilerOptions.macros.defineProps.includes(callText)) {
|
|
237
244
|
if (ts.isVariableDeclaration(parent)) {
|
|
238
245
|
if (ts.isObjectBindingPattern(parent.name)) {
|
|
239
|
-
props.destructured =
|
|
246
|
+
props.destructured = new Set();
|
|
247
|
+
const identifiers = (0, common_1.collectIdentifiers)(ts, parent.name, []);
|
|
248
|
+
for (const [id, isRest] of identifiers) {
|
|
249
|
+
const name = getNodeText(ts, id, ast);
|
|
250
|
+
if (isRest) {
|
|
251
|
+
props.destructuredRest = name;
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
props.destructured.add(name);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
240
257
|
}
|
|
241
258
|
else {
|
|
242
259
|
props.name = getNodeText(ts, parent.name, ast);
|
|
243
260
|
}
|
|
244
261
|
}
|
|
245
|
-
let statementRange;
|
|
246
|
-
for (let i = parents.length - 1; i >= 0; i--) {
|
|
247
|
-
if (ts.isStatement(parents[i])) {
|
|
248
|
-
const statement = parents[i];
|
|
249
|
-
ts.forEachChild(statement, child => {
|
|
250
|
-
const range = _getStartEnd(child);
|
|
251
|
-
statementRange ??= range;
|
|
252
|
-
statementRange.end = range.end;
|
|
253
|
-
});
|
|
254
|
-
break;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
if (!statementRange) {
|
|
258
|
-
statementRange = _getStartEnd(node);
|
|
259
|
-
}
|
|
260
262
|
props.define = {
|
|
261
263
|
...parseDefineFunction(node),
|
|
262
|
-
statement:
|
|
264
|
+
statement: getStatementRange(ts, parents, node, ast),
|
|
263
265
|
};
|
|
264
266
|
if (node.arguments.length) {
|
|
265
267
|
props.define.arg = _getStartEnd(node.arguments[0]);
|
|
@@ -298,7 +300,6 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
298
300
|
}
|
|
299
301
|
else if (vueCompilerOptions.composibles.useTemplateRef.includes(callText) && node.arguments.length && !node.typeArguments?.length) {
|
|
300
302
|
const define = parseDefineFunction(node);
|
|
301
|
-
define.arg = _getStartEnd(node.arguments[0]);
|
|
302
303
|
let name;
|
|
303
304
|
if (ts.isVariableDeclaration(parent)) {
|
|
304
305
|
name = getNodeText(ts, parent.name, ast);
|
|
@@ -309,13 +310,10 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
309
310
|
});
|
|
310
311
|
}
|
|
311
312
|
else if (vueCompilerOptions.composibles.useCssModule.includes(callText)) {
|
|
312
|
-
const
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
module.arg = _getStartEnd(node.arguments[0]);
|
|
317
|
-
}
|
|
318
|
-
cssModules.push(module);
|
|
313
|
+
const define = parseDefineFunction(node);
|
|
314
|
+
cssModules.push({
|
|
315
|
+
define
|
|
316
|
+
});
|
|
319
317
|
}
|
|
320
318
|
}
|
|
321
319
|
ts.forEachChild(node, child => {
|
|
@@ -420,4 +418,22 @@ function getNodeText(ts, node, sourceFile) {
|
|
|
420
418
|
const { start, end } = getStartEnd(ts, node, sourceFile);
|
|
421
419
|
return sourceFile.text.substring(start, end);
|
|
422
420
|
}
|
|
421
|
+
function getStatementRange(ts, parents, node, sourceFile) {
|
|
422
|
+
let statementRange;
|
|
423
|
+
for (let i = parents.length - 1; i >= 0; i--) {
|
|
424
|
+
if (ts.isStatement(parents[i])) {
|
|
425
|
+
const statement = parents[i];
|
|
426
|
+
ts.forEachChild(statement, child => {
|
|
427
|
+
const range = getStartEnd(ts, child, sourceFile);
|
|
428
|
+
statementRange ??= range;
|
|
429
|
+
statementRange.end = range.end;
|
|
430
|
+
});
|
|
431
|
+
break;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
if (!statementRange) {
|
|
435
|
+
statementRange = getStartEnd(ts, node, sourceFile);
|
|
436
|
+
}
|
|
437
|
+
return statementRange;
|
|
438
|
+
}
|
|
423
439
|
//# sourceMappingURL=scriptSetupRanges.js.map
|
package/lib/plugins/vue-tsx.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Mapping } from '@volar/language-core';
|
|
2
2
|
import type { Code, Sfc, VueLanguagePlugin } from '../types';
|
|
3
3
|
export declare const tsCodegen: WeakMap<Sfc, {
|
|
4
|
-
scriptRanges: ()
|
|
4
|
+
scriptRanges: import("alien-signals").ISignal<{
|
|
5
5
|
exportDefault: (import("../types").TextRange & {
|
|
6
6
|
expression: import("../types").TextRange;
|
|
7
7
|
args: import("../types").TextRange;
|
|
@@ -14,16 +14,18 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
14
14
|
}) | undefined;
|
|
15
15
|
classBlockEnd: number | undefined;
|
|
16
16
|
bindings: import("../types").TextRange[];
|
|
17
|
-
} | undefined
|
|
18
|
-
scriptSetupRanges: ()
|
|
17
|
+
} | undefined>;
|
|
18
|
+
scriptSetupRanges: import("alien-signals").ISignal<{
|
|
19
19
|
leadingCommentEndOffset: number;
|
|
20
20
|
importSectionEndOffset: number;
|
|
21
21
|
bindings: import("../types").TextRange[];
|
|
22
22
|
importComponentNames: Set<string>;
|
|
23
23
|
props: {
|
|
24
24
|
name?: string;
|
|
25
|
-
destructured?: string
|
|
25
|
+
destructured?: Set<string>;
|
|
26
|
+
destructuredRest?: string;
|
|
26
27
|
define?: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
|
|
28
|
+
exp: import("../types").TextRange;
|
|
27
29
|
arg?: import("../types").TextRange;
|
|
28
30
|
typeArg?: import("../types").TextRange;
|
|
29
31
|
}> & {
|
|
@@ -37,22 +39,28 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
37
39
|
name?: string;
|
|
38
40
|
isObjectBindingPattern?: boolean;
|
|
39
41
|
define?: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
|
|
42
|
+
exp: import("../types").TextRange;
|
|
40
43
|
arg?: import("../types").TextRange;
|
|
41
44
|
typeArg?: import("../types").TextRange;
|
|
42
|
-
}
|
|
45
|
+
}> & {
|
|
46
|
+
statement: import("../types").TextRange;
|
|
47
|
+
};
|
|
43
48
|
};
|
|
44
49
|
emits: {
|
|
45
50
|
name?: string;
|
|
46
51
|
define?: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
|
|
52
|
+
exp: import("../types").TextRange;
|
|
47
53
|
arg?: import("../types").TextRange;
|
|
48
54
|
typeArg?: import("../types").TextRange;
|
|
49
55
|
}> & {
|
|
56
|
+
statement: import("../types").TextRange;
|
|
50
57
|
hasUnionTypeArg?: boolean;
|
|
51
58
|
};
|
|
52
59
|
};
|
|
53
60
|
expose: {
|
|
54
61
|
name?: string;
|
|
55
62
|
define?: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
|
|
63
|
+
exp: import("../types").TextRange;
|
|
56
64
|
arg?: import("../types").TextRange;
|
|
57
65
|
typeArg?: import("../types").TextRange;
|
|
58
66
|
}>;
|
|
@@ -62,8 +70,11 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
62
70
|
inheritAttrs?: string;
|
|
63
71
|
};
|
|
64
72
|
cssModules: {
|
|
65
|
-
|
|
66
|
-
|
|
73
|
+
define: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
|
|
74
|
+
exp: import("../types").TextRange;
|
|
75
|
+
arg?: import("../types").TextRange;
|
|
76
|
+
typeArg?: import("../types").TextRange;
|
|
77
|
+
}>;
|
|
67
78
|
}[];
|
|
68
79
|
defineProp: {
|
|
69
80
|
localName: import("../types").TextRange | undefined;
|
|
@@ -77,14 +88,15 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
77
88
|
}[];
|
|
78
89
|
templateRefs: {
|
|
79
90
|
name?: string;
|
|
80
|
-
define
|
|
91
|
+
define: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
|
|
92
|
+
exp: import("../types").TextRange;
|
|
81
93
|
arg?: import("../types").TextRange;
|
|
82
94
|
typeArg?: import("../types").TextRange;
|
|
83
95
|
}>;
|
|
84
96
|
}[];
|
|
85
|
-
} | undefined
|
|
86
|
-
lang: ()
|
|
87
|
-
generatedScript: ()
|
|
97
|
+
} | undefined>;
|
|
98
|
+
lang: import("alien-signals").ISignal<string>;
|
|
99
|
+
generatedScript: import("alien-signals").ISignal<{
|
|
88
100
|
codes: Code[];
|
|
89
101
|
linkedCodeMappings: Mapping<unknown>[];
|
|
90
102
|
generatedTemplate: boolean;
|
|
@@ -103,9 +115,9 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
103
115
|
readonly TypePropsToOption: string;
|
|
104
116
|
readonly OmitIndexSignature: string;
|
|
105
117
|
};
|
|
106
|
-
inlayHints: import("../codegen/
|
|
107
|
-
}
|
|
108
|
-
generatedTemplate: ()
|
|
118
|
+
inlayHints: import("../codegen/inlayHints").InlayHintInfo[];
|
|
119
|
+
}>;
|
|
120
|
+
generatedTemplate: import("alien-signals").ISignal<{
|
|
109
121
|
codes: Code[];
|
|
110
122
|
slots: {
|
|
111
123
|
name: string;
|
|
@@ -141,10 +153,11 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
141
153
|
offset: number;
|
|
142
154
|
}[];
|
|
143
155
|
emptyClassOffsets: number[];
|
|
144
|
-
inlayHints: import("../codegen/
|
|
156
|
+
inlayHints: import("../codegen/inlayHints").InlayHintInfo[];
|
|
145
157
|
hasSlot: boolean;
|
|
146
158
|
inheritedAttrVars: Set<unknown>;
|
|
147
|
-
templateRefs: Map<string, [string, number]>;
|
|
159
|
+
templateRefs: Map<string, [varName: string, offset: number]>;
|
|
160
|
+
singleRootElType: string | undefined;
|
|
148
161
|
singleRootNode: import("@vue/compiler-dom").ElementNode | undefined;
|
|
149
162
|
accessExternalVariable(name: string, offset?: number): void;
|
|
150
163
|
hasLocalVariable: (name: string) => boolean;
|
|
@@ -155,7 +168,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
155
168
|
expectError: (prevNode: import("@vue/compiler-dom").CommentNode) => Generator<Code>;
|
|
156
169
|
resetDirectiveComments: (endStr: string) => Generator<Code>;
|
|
157
170
|
generateAutoImportCompletion: () => Generator<Code>;
|
|
158
|
-
} | undefined
|
|
171
|
+
} | undefined>;
|
|
159
172
|
}>;
|
|
160
173
|
declare const plugin: VueLanguagePlugin;
|
|
161
174
|
export default plugin;
|
package/lib/plugins/vue-tsx.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.tsCodegen = void 0;
|
|
4
|
-
const
|
|
5
|
-
const path_browserify_1 = require("path-browserify");
|
|
4
|
+
const alien_signals_1 = require("alien-signals");
|
|
6
5
|
const script_1 = require("../codegen/script");
|
|
7
6
|
const template_1 = require("../codegen/template");
|
|
8
7
|
const scriptRanges_1 = require("../parsers/scriptRanges");
|
|
@@ -20,15 +19,15 @@ const plugin = ctx => {
|
|
|
20
19
|
getEmbeddedCodes(fileName, sfc) {
|
|
21
20
|
const tsx = useTsx(fileName, sfc);
|
|
22
21
|
const files = [];
|
|
23
|
-
if (['js', 'ts', 'jsx', 'tsx'].includes(tsx.lang())) {
|
|
24
|
-
files.push({ id: 'script_' + tsx.lang(), lang: tsx.lang() });
|
|
22
|
+
if (['js', 'ts', 'jsx', 'tsx'].includes(tsx.lang.get())) {
|
|
23
|
+
files.push({ id: 'script_' + tsx.lang.get(), lang: tsx.lang.get() });
|
|
25
24
|
}
|
|
26
25
|
return files;
|
|
27
26
|
},
|
|
28
27
|
resolveEmbeddedCode(fileName, sfc, embeddedFile) {
|
|
29
28
|
const _tsx = useTsx(fileName, sfc);
|
|
30
29
|
if (/script_(js|jsx|ts|tsx)/.test(embeddedFile.id)) {
|
|
31
|
-
const tsx = _tsx.generatedScript();
|
|
30
|
+
const tsx = _tsx.generatedScript.get();
|
|
32
31
|
if (tsx) {
|
|
33
32
|
const content = [...tsx.codes];
|
|
34
33
|
embeddedFile.content = content;
|
|
@@ -52,19 +51,19 @@ const plugin = ctx => {
|
|
|
52
51
|
exports.default = plugin;
|
|
53
52
|
function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
|
|
54
53
|
const ts = ctx.modules.typescript;
|
|
55
|
-
const lang = (0,
|
|
54
|
+
const lang = (0, alien_signals_1.computed)(() => {
|
|
56
55
|
return !_sfc.script && !_sfc.scriptSetup ? 'ts'
|
|
57
56
|
: _sfc.scriptSetup && _sfc.scriptSetup.lang !== 'js' ? _sfc.scriptSetup.lang
|
|
58
57
|
: _sfc.script && _sfc.script.lang !== 'js' ? _sfc.script.lang
|
|
59
58
|
: 'js';
|
|
60
59
|
});
|
|
61
|
-
const scriptRanges = (0,
|
|
60
|
+
const scriptRanges = (0, alien_signals_1.computed)(() => _sfc.script
|
|
62
61
|
? (0, scriptRanges_1.parseScriptRanges)(ts, _sfc.script.ast, !!_sfc.scriptSetup, false)
|
|
63
62
|
: undefined);
|
|
64
|
-
const scriptSetupRanges = (0,
|
|
63
|
+
const scriptSetupRanges = (0, alien_signals_1.computed)(() => _sfc.scriptSetup
|
|
65
64
|
? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, _sfc.scriptSetup.ast, ctx.vueCompilerOptions)
|
|
66
65
|
: undefined);
|
|
67
|
-
const generatedTemplate = (0,
|
|
66
|
+
const generatedTemplate = (0, alien_signals_1.computed)(() => {
|
|
68
67
|
if (ctx.vueCompilerOptions.skipTemplateCodegen || !_sfc.template) {
|
|
69
68
|
return;
|
|
70
69
|
}
|
|
@@ -75,13 +74,14 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
|
|
|
75
74
|
vueCompilerOptions: ctx.vueCompilerOptions,
|
|
76
75
|
template: _sfc.template,
|
|
77
76
|
edited: ctx.vueCompilerOptions.__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
|
|
78
|
-
scriptSetupBindingNames: scriptSetupBindingNames(),
|
|
79
|
-
scriptSetupImportComponentNames: scriptSetupImportComponentNames(),
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
77
|
+
scriptSetupBindingNames: scriptSetupBindingNames.get(),
|
|
78
|
+
scriptSetupImportComponentNames: scriptSetupImportComponentNames.get(),
|
|
79
|
+
destructuredPropNames: destructuredPropNames.get(),
|
|
80
|
+
templateRefNames: templateRefNames.get(),
|
|
81
|
+
hasDefineSlots: hasDefineSlots.get(),
|
|
82
|
+
slotsAssignName: slotsAssignName.get(),
|
|
83
|
+
propsAssignName: propsAssignName.get(),
|
|
84
|
+
inheritAttrs: inheritAttrs.get(),
|
|
85
85
|
});
|
|
86
86
|
let current = codegen.next();
|
|
87
87
|
while (!current.done) {
|
|
@@ -94,9 +94,9 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
|
|
|
94
94
|
codes: codes,
|
|
95
95
|
};
|
|
96
96
|
});
|
|
97
|
-
const scriptSetupBindingNames = (0,
|
|
97
|
+
const scriptSetupBindingNames = (0, alien_signals_1.computed)(oldNames => {
|
|
98
98
|
const newNames = new Set();
|
|
99
|
-
const bindings = scriptSetupRanges()?.bindings;
|
|
99
|
+
const bindings = scriptSetupRanges.get()?.bindings;
|
|
100
100
|
if (_sfc.scriptSetup && bindings) {
|
|
101
101
|
for (const binding of bindings) {
|
|
102
102
|
newNames.add(_sfc.scriptSetup?.content.substring(binding.start, binding.end));
|
|
@@ -107,15 +107,26 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
|
|
|
107
107
|
}
|
|
108
108
|
return newNames;
|
|
109
109
|
});
|
|
110
|
-
const scriptSetupImportComponentNames = (0,
|
|
111
|
-
const newNames = scriptSetupRanges()?.importComponentNames ?? new Set();
|
|
110
|
+
const scriptSetupImportComponentNames = (0, alien_signals_1.computed)(oldNames => {
|
|
111
|
+
const newNames = scriptSetupRanges.get()?.importComponentNames ?? new Set();
|
|
112
112
|
if (oldNames && twoSetsEqual(newNames, oldNames)) {
|
|
113
113
|
return oldNames;
|
|
114
114
|
}
|
|
115
115
|
return newNames;
|
|
116
116
|
});
|
|
117
|
-
const
|
|
118
|
-
const newNames = new Set(
|
|
117
|
+
const destructuredPropNames = (0, alien_signals_1.computed)(oldNames => {
|
|
118
|
+
const newNames = scriptSetupRanges.get()?.props.destructured ?? new Set();
|
|
119
|
+
const rest = scriptSetupRanges.get()?.props.destructuredRest;
|
|
120
|
+
if (rest) {
|
|
121
|
+
newNames.add(rest);
|
|
122
|
+
}
|
|
123
|
+
if (oldNames && twoSetsEqual(newNames, oldNames)) {
|
|
124
|
+
return oldNames;
|
|
125
|
+
}
|
|
126
|
+
return newNames;
|
|
127
|
+
});
|
|
128
|
+
const templateRefNames = (0, alien_signals_1.computed)(oldNames => {
|
|
129
|
+
const newNames = new Set(scriptSetupRanges.get()?.templateRefs
|
|
119
130
|
.map(({ name }) => name)
|
|
120
131
|
.filter(name => name !== undefined));
|
|
121
132
|
if (oldNames && twoSetsEqual(newNames, oldNames)) {
|
|
@@ -123,25 +134,25 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
|
|
|
123
134
|
}
|
|
124
135
|
return newNames;
|
|
125
136
|
});
|
|
126
|
-
const hasDefineSlots = (0,
|
|
127
|
-
const slotsAssignName = (0,
|
|
128
|
-
const propsAssignName = (0,
|
|
129
|
-
const inheritAttrs = (0,
|
|
130
|
-
const value = scriptSetupRanges()?.options.inheritAttrs ?? scriptRanges()?.exportDefault?.inheritAttrsOption;
|
|
137
|
+
const hasDefineSlots = (0, alien_signals_1.computed)(() => !!scriptSetupRanges.get()?.slots.define);
|
|
138
|
+
const slotsAssignName = (0, alien_signals_1.computed)(() => scriptSetupRanges.get()?.slots.name);
|
|
139
|
+
const propsAssignName = (0, alien_signals_1.computed)(() => scriptSetupRanges.get()?.props.name);
|
|
140
|
+
const inheritAttrs = (0, alien_signals_1.computed)(() => {
|
|
141
|
+
const value = scriptSetupRanges.get()?.options.inheritAttrs ?? scriptRanges.get()?.exportDefault?.inheritAttrsOption;
|
|
131
142
|
return value !== 'false';
|
|
132
143
|
});
|
|
133
|
-
const generatedScript = (0,
|
|
144
|
+
const generatedScript = (0, alien_signals_1.computed)(() => {
|
|
134
145
|
const codes = [];
|
|
135
146
|
const linkedCodeMappings = [];
|
|
136
147
|
let generatedLength = 0;
|
|
137
148
|
const codegen = (0, script_1.generateScript)({
|
|
138
149
|
ts,
|
|
139
|
-
|
|
150
|
+
fileName,
|
|
140
151
|
sfc: _sfc,
|
|
141
|
-
lang: lang(),
|
|
142
|
-
scriptRanges: scriptRanges(),
|
|
143
|
-
scriptSetupRanges: scriptSetupRanges(),
|
|
144
|
-
templateCodegen: generatedTemplate(),
|
|
152
|
+
lang: lang.get(),
|
|
153
|
+
scriptRanges: scriptRanges.get(),
|
|
154
|
+
scriptSetupRanges: scriptSetupRanges.get(),
|
|
155
|
+
templateCodegen: generatedTemplate.get(),
|
|
145
156
|
compilerOptions: ctx.compilerOptions,
|
|
146
157
|
vueCompilerOptions: ctx.vueCompilerOptions,
|
|
147
158
|
edited: ctx.vueCompilerOptions.__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
|