@vue/language-core 2.1.6-patch.1 → 2.1.8
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/globalTypes.js +9 -4
- package/lib/codegen/inlayHints.d.ts +11 -0
- package/lib/codegen/inlayHints.js +17 -0
- package/lib/codegen/script/component.d.ts +1 -1
- package/lib/codegen/script/component.js +5 -5
- package/lib/codegen/script/componentSelf.js +1 -1
- package/lib/codegen/script/context.d.ts +1 -1
- package/lib/codegen/script/index.d.ts +1 -0
- package/lib/codegen/script/index.js +23 -10
- package/lib/codegen/script/scriptSetup.js +103 -112
- package/lib/codegen/script/styleModulesType.js +3 -5
- package/lib/codegen/script/template.d.ts +1 -1
- package/lib/codegen/script/template.js +4 -9
- package/lib/codegen/template/context.d.ts +1 -1
- package/lib/codegen/template/element.d.ts +1 -1
- package/lib/codegen/template/element.js +19 -8
- package/lib/codegen/template/elementDirectives.js +63 -31
- package/lib/codegen/template/elementProps.js +6 -16
- package/lib/codegen/template/interpolation.js +0 -6
- package/lib/codegen/template/slotOutlet.js +5 -0
- package/lib/codegen/template/templateChild.d.ts +1 -1
- package/lib/codegen/template/templateChild.js +2 -2
- package/lib/codegen/template/vFor.js +1 -1
- package/lib/parsers/scriptSetupRanges.d.ts +12 -3
- package/lib/parsers/scriptSetupRanges.js +28 -25
- package/lib/plugins/vue-tsx.d.ts +23 -14
- package/lib/plugins/vue-tsx.js +35 -35
- 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 +10 -8
|
@@ -17,6 +17,7 @@ const interpolation_1 = require("./interpolation");
|
|
|
17
17
|
const propertyAccess_1 = require("./propertyAccess");
|
|
18
18
|
const templateChild_1 = require("./templateChild");
|
|
19
19
|
const objectProperty_1 = require("./objectProperty");
|
|
20
|
+
const inlayHints_1 = require("../inlayHints");
|
|
20
21
|
const scriptSetupRanges_1 = require("../../parsers/scriptSetupRanges");
|
|
21
22
|
const colonReg = /:/g;
|
|
22
23
|
function* generateComponent(options, ctx, node, currentComponent) {
|
|
@@ -39,9 +40,15 @@ function* generateComponent(options, ctx, node, currentComponent) {
|
|
|
39
40
|
let dynamicTagInfo;
|
|
40
41
|
if (isComponentTag) {
|
|
41
42
|
for (const prop of node.props) {
|
|
42
|
-
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
43
|
+
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
44
|
+
&& prop.name === 'bind'
|
|
45
|
+
&& prop.arg?.loc.source === 'is'
|
|
46
|
+
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
47
|
+
if (prop.arg.loc.end.offset === prop.exp.loc.end.offset) {
|
|
48
|
+
ctx.inlayHints.push((0, inlayHints_1.createVBindShorthandInlayHintInfo)(prop.exp.loc, 'is'));
|
|
49
|
+
}
|
|
43
50
|
dynamicTagInfo = {
|
|
44
|
-
|
|
51
|
+
tag: prop.exp.content,
|
|
45
52
|
offsets: [prop.exp.loc.start.offset, undefined],
|
|
46
53
|
astHolder: prop.exp.loc,
|
|
47
54
|
};
|
|
@@ -53,9 +60,9 @@ function* generateComponent(options, ctx, node, currentComponent) {
|
|
|
53
60
|
else if (node.tag.includes('.')) {
|
|
54
61
|
// namespace tag
|
|
55
62
|
dynamicTagInfo = {
|
|
56
|
-
|
|
57
|
-
astHolder: node.loc,
|
|
63
|
+
tag: node.tag,
|
|
58
64
|
offsets: [startTagOffset, endTagOffset],
|
|
65
|
+
astHolder: node.loc,
|
|
59
66
|
};
|
|
60
67
|
}
|
|
61
68
|
if (matchImportName) {
|
|
@@ -86,10 +93,10 @@ function* generateComponent(options, ctx, node, currentComponent) {
|
|
|
86
93
|
}
|
|
87
94
|
else if (dynamicTagInfo) {
|
|
88
95
|
yield `const ${var_originalComponent} = (`;
|
|
89
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, dynamicTagInfo.
|
|
96
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, dynamicTagInfo.tag, dynamicTagInfo.astHolder, dynamicTagInfo.offsets[0], ctx.codeFeatures.all, '(', ')');
|
|
90
97
|
if (dynamicTagInfo.offsets[1] !== undefined) {
|
|
91
98
|
yield `,`;
|
|
92
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, dynamicTagInfo.
|
|
99
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, dynamicTagInfo.tag, dynamicTagInfo.astHolder, dynamicTagInfo.offsets[1], {
|
|
93
100
|
...ctx.codeFeatures.all,
|
|
94
101
|
completion: false,
|
|
95
102
|
}, '(', ')');
|
|
@@ -193,7 +200,7 @@ function* generateComponent(options, ctx, node, currentComponent) {
|
|
|
193
200
|
yield `var ${var_defineComponentCtx}!: __VLS_PickFunctionalComponentCtx<typeof ${var_originalComponent}, typeof ${var_componentInstance}>${common_1.endOfLine}`;
|
|
194
201
|
}
|
|
195
202
|
}
|
|
196
|
-
function* generateElement(options, ctx, node, currentComponent, componentCtxVar) {
|
|
203
|
+
function* generateElement(options, ctx, node, currentComponent, componentCtxVar, isVForChild) {
|
|
197
204
|
const startTagOffset = node.loc.start.offset + options.template.content.substring(node.loc.start.offset).indexOf(node.tag);
|
|
198
205
|
const endTagOffset = !node.isSelfClosing && options.template.lang === 'html'
|
|
199
206
|
? node.loc.start.offset + node.loc.source.lastIndexOf(node.tag)
|
|
@@ -214,7 +221,11 @@ function* generateElement(options, ctx, node, currentComponent, componentCtxVar)
|
|
|
214
221
|
}
|
|
215
222
|
const [refName, offset] = yield* generateVScope(options, ctx, node, node.props);
|
|
216
223
|
if (refName) {
|
|
217
|
-
|
|
224
|
+
let refValue = `__VLS_nativeElements['${node.tag}']`;
|
|
225
|
+
if (isVForChild) {
|
|
226
|
+
refValue = `[${refValue}]`;
|
|
227
|
+
}
|
|
228
|
+
ctx.templateRefs.set(refName, [refValue, offset]);
|
|
218
229
|
}
|
|
219
230
|
if (ctx.singleRootNode === node) {
|
|
220
231
|
ctx.singleRootElType = `typeof __VLS_nativeElements['${node.tag}']`;
|
|
@@ -7,42 +7,74 @@ const shared_2 = require("../../utils/shared");
|
|
|
7
7
|
const common_1 = require("../common");
|
|
8
8
|
const camelized_1 = require("./camelized");
|
|
9
9
|
const interpolation_1 = require("./interpolation");
|
|
10
|
+
const objectProperty_1 = require("./objectProperty");
|
|
11
|
+
const stringLiteralKey_1 = require("./stringLiteralKey");
|
|
10
12
|
function* generateElementDirectives(options, ctx, node) {
|
|
11
13
|
for (const prop of node.props) {
|
|
12
|
-
if (prop.type
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && !prop.arg.isStatic) {
|
|
21
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, prop.arg.content, prop.arg.loc, prop.arg.loc.start.offset + prop.arg.loc.source.indexOf(prop.arg.content), ctx.codeFeatures.all, '(', ')');
|
|
22
|
-
yield common_1.endOfLine;
|
|
23
|
-
}
|
|
24
|
-
yield* (0, common_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, `__VLS_directiveAsFunction(__VLS_directives.`, ...(0, camelized_1.generateCamelized)('v-' + prop.name, prop.loc.start.offset, {
|
|
25
|
-
...ctx.codeFeatures.all,
|
|
26
|
-
verification: false,
|
|
27
|
-
completion: {
|
|
28
|
-
// fix https://github.com/vuejs/language-tools/issues/1905
|
|
29
|
-
isAdditional: true,
|
|
30
|
-
},
|
|
31
|
-
navigation: {
|
|
32
|
-
resolveRenameNewName: shared_1.camelize,
|
|
33
|
-
resolveRenameEditText: getPropRenameApply(prop.name),
|
|
34
|
-
},
|
|
35
|
-
}), `)(null!, { ...__VLS_directiveBindingRestFields, `, ...(prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
36
|
-
? [
|
|
37
|
-
...(0, common_1.wrapWith)(prop.exp.loc.start.offset, prop.exp.loc.end.offset, ctx.codeFeatures.verification, 'value'),
|
|
38
|
-
': ',
|
|
39
|
-
...(0, common_1.wrapWith)(prop.exp.loc.start.offset, prop.exp.loc.end.offset, ctx.codeFeatures.verification, ...(0, interpolation_1.generateInterpolation)(options, ctx, prop.exp.content, prop.exp.loc, prop.exp.loc.start.offset, ctx.codeFeatures.all, '(', ')'))
|
|
40
|
-
]
|
|
41
|
-
: [`undefined`]), `}, null!, null!)`);
|
|
42
|
-
yield common_1.endOfLine;
|
|
14
|
+
if (prop.type !== CompilerDOM.NodeTypes.DIRECTIVE
|
|
15
|
+
|| prop.name === 'slot'
|
|
16
|
+
|| prop.name === 'on'
|
|
17
|
+
|| prop.name === 'model'
|
|
18
|
+
|| prop.name === 'bind'
|
|
19
|
+
|| prop.name === 'scope'
|
|
20
|
+
|| prop.name === 'data') {
|
|
21
|
+
continue;
|
|
43
22
|
}
|
|
23
|
+
ctx.accessExternalVariable((0, shared_1.camelize)('v-' + prop.name), prop.loc.start.offset);
|
|
24
|
+
yield* (0, common_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, `__VLS_asFunctionalDirective(`, ...generateIdentifier(ctx, prop), `)(null!, { ...__VLS_directiveBindingRestFields, `, ...generateArg(options, ctx, prop), ...generateModifiers(options, ctx, prop), ...generateValue(options, ctx, prop), `}, null!, null!)`);
|
|
25
|
+
yield common_1.endOfLine;
|
|
44
26
|
}
|
|
45
27
|
}
|
|
28
|
+
function* generateIdentifier(ctx, prop) {
|
|
29
|
+
const rawName = 'v-' + prop.name;
|
|
30
|
+
yield* (0, common_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + rawName.length, ctx.codeFeatures.verification, `__VLS_directives.`, ...(0, camelized_1.generateCamelized)(rawName, prop.loc.start.offset, {
|
|
31
|
+
...ctx.codeFeatures.all,
|
|
32
|
+
verification: false,
|
|
33
|
+
completion: {
|
|
34
|
+
// fix https://github.com/vuejs/language-tools/issues/1905
|
|
35
|
+
isAdditional: true,
|
|
36
|
+
},
|
|
37
|
+
navigation: {
|
|
38
|
+
resolveRenameNewName: shared_1.camelize,
|
|
39
|
+
resolveRenameEditText: getPropRenameApply(prop.name),
|
|
40
|
+
},
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
function* generateArg(options, ctx, prop) {
|
|
44
|
+
const { arg } = prop;
|
|
45
|
+
if (arg?.type !== CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const startOffset = arg.loc.start.offset + arg.loc.source.indexOf(arg.content);
|
|
49
|
+
yield* (0, common_1.wrapWith)(startOffset, startOffset + arg.content.length, ctx.codeFeatures.verification, 'arg');
|
|
50
|
+
yield ': ';
|
|
51
|
+
if (arg.isStatic) {
|
|
52
|
+
yield* (0, stringLiteralKey_1.generateStringLiteralKey)(arg.content, startOffset, ctx.codeFeatures.withoutHighlight);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, arg.content, arg.loc, startOffset, ctx.codeFeatures.all, '(', ')');
|
|
56
|
+
}
|
|
57
|
+
yield ', ';
|
|
58
|
+
}
|
|
59
|
+
function* generateModifiers(options, ctx, prop) {
|
|
60
|
+
if (options.vueCompilerOptions.target < 3.5) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
yield 'modifiers: { ';
|
|
64
|
+
for (const mod of prop.modifiers) {
|
|
65
|
+
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, mod.content, mod.loc.start.offset, ctx.codeFeatures.withoutHighlight);
|
|
66
|
+
yield ': true, ';
|
|
67
|
+
}
|
|
68
|
+
yield '}, ';
|
|
69
|
+
}
|
|
70
|
+
function* generateValue(options, ctx, prop) {
|
|
71
|
+
if (prop.exp?.type !== CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
yield* (0, common_1.wrapWith)(prop.exp.loc.start.offset, prop.exp.loc.end.offset, ctx.codeFeatures.verification, 'value');
|
|
75
|
+
yield ': ';
|
|
76
|
+
yield* (0, common_1.wrapWith)(prop.exp.loc.start.offset, prop.exp.loc.end.offset, ctx.codeFeatures.verification, ...(0, interpolation_1.generateInterpolation)(options, ctx, prop.exp.content, prop.exp.loc, prop.exp.loc.start.offset, ctx.codeFeatures.all, '(', ')'));
|
|
77
|
+
}
|
|
46
78
|
function getPropRenameApply(oldName) {
|
|
47
79
|
return oldName === (0, shared_2.hyphenateAttr)(oldName) ? shared_2.hyphenateAttr : undefined;
|
|
48
80
|
}
|
|
@@ -11,16 +11,16 @@ const camelized_1 = require("./camelized");
|
|
|
11
11
|
const elementEvents_1 = require("./elementEvents");
|
|
12
12
|
const interpolation_1 = require("./interpolation");
|
|
13
13
|
const objectProperty_1 = require("./objectProperty");
|
|
14
|
+
const inlayHints_1 = require("../inlayHints");
|
|
14
15
|
function* generateElementProps(options, ctx, node, props, enableCodeFeatures, propsFailedExps) {
|
|
15
|
-
const
|
|
16
|
-
const canCamelize = node.tagType === CompilerDOM.ElementTypes.COMPONENT;
|
|
16
|
+
const isComponent = node.tagType === CompilerDOM.ElementTypes.COMPONENT;
|
|
17
17
|
for (const prop of props) {
|
|
18
18
|
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
19
19
|
&& prop.name === 'on') {
|
|
20
20
|
if (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
21
21
|
&& !prop.arg.loc.source.startsWith('[')
|
|
22
22
|
&& !prop.arg.loc.source.endsWith(']')) {
|
|
23
|
-
if (
|
|
23
|
+
if (!isComponent) {
|
|
24
24
|
yield `...{ `;
|
|
25
25
|
yield* (0, elementEvents_1.generateEventArg)(ctx, prop.arg, true);
|
|
26
26
|
yield `: `;
|
|
@@ -69,7 +69,7 @@ function* generateElementProps(options, ctx, node, props, enableCodeFeatures, pr
|
|
|
69
69
|
propName = propName.substring(1);
|
|
70
70
|
}
|
|
71
71
|
const shouldSpread = propName === 'style' || propName === 'class';
|
|
72
|
-
const shouldCamelize =
|
|
72
|
+
const shouldCamelize = isComponent
|
|
73
73
|
&& (!prop.arg || (prop.arg.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic)) // isStatic
|
|
74
74
|
&& (0, shared_2.hyphenateAttr)(propName) === propName
|
|
75
75
|
&& !options.vueCompilerOptions.htmlAttributes.some(pattern => (0, minimatch_1.minimatch)(propName, pattern));
|
|
@@ -120,7 +120,7 @@ function* generateElementProps(options, ctx, node, props, enableCodeFeatures, pr
|
|
|
120
120
|
continue;
|
|
121
121
|
}
|
|
122
122
|
const shouldSpread = prop.name === 'style' || prop.name === 'class';
|
|
123
|
-
const shouldCamelize =
|
|
123
|
+
const shouldCamelize = isComponent
|
|
124
124
|
&& (0, shared_2.hyphenateAttr)(prop.name) === prop.name
|
|
125
125
|
&& !options.vueCompilerOptions.htmlAttributes.some(pattern => (0, minimatch_1.minimatch)(prop.name, pattern));
|
|
126
126
|
if (shouldSpread) {
|
|
@@ -205,17 +205,7 @@ function* generatePropExp(options, ctx, prop, exp, features, isShorthand, enable
|
|
|
205
205
|
}
|
|
206
206
|
yield* (0, camelized_1.generateCamelized)(exp.loc.source, exp.loc.start.offset, features);
|
|
207
207
|
if (enableCodeFeatures) {
|
|
208
|
-
ctx.inlayHints.push(
|
|
209
|
-
blockName: 'template',
|
|
210
|
-
offset: prop.loc.end.offset,
|
|
211
|
-
setting: 'vue.inlayHints.vBindShorthand',
|
|
212
|
-
label: `="${propVariableName}"`,
|
|
213
|
-
tooltip: [
|
|
214
|
-
`This is a shorthand for \`${prop.loc.source}="${propVariableName}"\`.`,
|
|
215
|
-
'To hide this hint, set `vue.inlayHints.vBindShorthand` to `false` in IDE settings.',
|
|
216
|
-
'[More info](https://github.com/vuejs/core/pull/9451)',
|
|
217
|
-
].join('\n\n'),
|
|
218
|
-
});
|
|
208
|
+
ctx.inlayHints.push((0, inlayHints_1.createVBindShorthandInlayHintInfo)(prop.loc, propVariableName));
|
|
219
209
|
}
|
|
220
210
|
}
|
|
221
211
|
}
|
|
@@ -8,7 +8,6 @@ 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
|
-
const vars = [];
|
|
12
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;
|
|
@@ -46,11 +45,6 @@ function* generateInterpolation(options, ctx, _code, astHolder, start, data, pre
|
|
|
46
45
|
yield addSuffix;
|
|
47
46
|
}
|
|
48
47
|
}
|
|
49
|
-
if (start !== undefined) {
|
|
50
|
-
for (const v of vars) {
|
|
51
|
-
v.offset = start + v.offset - prefix.length;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
48
|
}
|
|
55
49
|
function* forEachInterpolationSegment(ts, destructuredPropNames, templateRefNames, ctx, code, offset, ast) {
|
|
56
50
|
let ctxVars = [];
|
|
@@ -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]*/)) {
|
|
@@ -70,7 +70,7 @@ function* generateTemplateChild(options, ctx, node, currentComponent, prevNode,
|
|
|
70
70
|
}
|
|
71
71
|
else if (node.tagType === CompilerDOM.ElementTypes.ELEMENT
|
|
72
72
|
|| node.tagType === CompilerDOM.ElementTypes.TEMPLATE) {
|
|
73
|
-
yield* (0, element_1.generateElement)(options, ctx, node, currentComponent, componentCtxVar);
|
|
73
|
+
yield* (0, element_1.generateElement)(options, ctx, node, currentComponent, componentCtxVar, isVForChild);
|
|
74
74
|
}
|
|
75
75
|
else {
|
|
76
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) {
|
|
@@ -12,6 +12,7 @@ export declare function parseScriptSetupRanges(ts: typeof import('typescript'),
|
|
|
12
12
|
destructured?: Set<string>;
|
|
13
13
|
destructuredRest?: string;
|
|
14
14
|
define?: ReturnType<(node: ts.CallExpression) => TextRange & {
|
|
15
|
+
exp: TextRange;
|
|
15
16
|
arg?: TextRange;
|
|
16
17
|
typeArg?: TextRange;
|
|
17
18
|
}> & {
|
|
@@ -25,6 +26,7 @@ export declare function parseScriptSetupRanges(ts: typeof import('typescript'),
|
|
|
25
26
|
name?: string;
|
|
26
27
|
isObjectBindingPattern?: boolean;
|
|
27
28
|
define?: ReturnType<(node: ts.CallExpression) => TextRange & {
|
|
29
|
+
exp: TextRange;
|
|
28
30
|
arg?: TextRange;
|
|
29
31
|
typeArg?: TextRange;
|
|
30
32
|
}>;
|
|
@@ -32,15 +34,18 @@ export declare function parseScriptSetupRanges(ts: typeof import('typescript'),
|
|
|
32
34
|
emits: {
|
|
33
35
|
name?: string;
|
|
34
36
|
define?: ReturnType<(node: ts.CallExpression) => TextRange & {
|
|
37
|
+
exp: TextRange;
|
|
35
38
|
arg?: TextRange;
|
|
36
39
|
typeArg?: TextRange;
|
|
37
40
|
}> & {
|
|
41
|
+
statement: TextRange;
|
|
38
42
|
hasUnionTypeArg?: boolean;
|
|
39
43
|
};
|
|
40
44
|
};
|
|
41
45
|
expose: {
|
|
42
46
|
name?: string;
|
|
43
47
|
define?: ReturnType<(node: ts.CallExpression) => TextRange & {
|
|
48
|
+
exp: TextRange;
|
|
44
49
|
arg?: TextRange;
|
|
45
50
|
typeArg?: TextRange;
|
|
46
51
|
}>;
|
|
@@ -50,8 +55,11 @@ export declare function parseScriptSetupRanges(ts: typeof import('typescript'),
|
|
|
50
55
|
inheritAttrs?: string;
|
|
51
56
|
};
|
|
52
57
|
cssModules: {
|
|
53
|
-
|
|
54
|
-
|
|
58
|
+
define: ReturnType<(node: ts.CallExpression) => TextRange & {
|
|
59
|
+
exp: TextRange;
|
|
60
|
+
arg?: TextRange;
|
|
61
|
+
typeArg?: TextRange;
|
|
62
|
+
}>;
|
|
55
63
|
}[];
|
|
56
64
|
defineProp: {
|
|
57
65
|
localName: TextRange | undefined;
|
|
@@ -65,7 +73,8 @@ export declare function parseScriptSetupRanges(ts: typeof import('typescript'),
|
|
|
65
73
|
}[];
|
|
66
74
|
templateRefs: {
|
|
67
75
|
name?: string;
|
|
68
|
-
define
|
|
76
|
+
define: ReturnType<(node: ts.CallExpression) => TextRange & {
|
|
77
|
+
exp: TextRange;
|
|
69
78
|
arg?: TextRange;
|
|
70
79
|
typeArg?: TextRange;
|
|
71
80
|
}>;
|
|
@@ -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
|
};
|
|
@@ -217,7 +218,10 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
217
218
|
}
|
|
218
219
|
}
|
|
219
220
|
else if (vueCompilerOptions.macros.defineEmits.includes(callText)) {
|
|
220
|
-
emits.define =
|
|
221
|
+
emits.define = {
|
|
222
|
+
...parseDefineFunction(node),
|
|
223
|
+
statement: getStatementRange(ts, parents, node, ast)
|
|
224
|
+
};
|
|
221
225
|
if (ts.isVariableDeclaration(parent)) {
|
|
222
226
|
emits.name = getNodeText(ts, parent.name, ast);
|
|
223
227
|
}
|
|
@@ -252,24 +256,9 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
252
256
|
props.name = getNodeText(ts, parent.name, ast);
|
|
253
257
|
}
|
|
254
258
|
}
|
|
255
|
-
let statementRange;
|
|
256
|
-
for (let i = parents.length - 1; i >= 0; i--) {
|
|
257
|
-
if (ts.isStatement(parents[i])) {
|
|
258
|
-
const statement = parents[i];
|
|
259
|
-
ts.forEachChild(statement, child => {
|
|
260
|
-
const range = _getStartEnd(child);
|
|
261
|
-
statementRange ??= range;
|
|
262
|
-
statementRange.end = range.end;
|
|
263
|
-
});
|
|
264
|
-
break;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
if (!statementRange) {
|
|
268
|
-
statementRange = _getStartEnd(node);
|
|
269
|
-
}
|
|
270
259
|
props.define = {
|
|
271
260
|
...parseDefineFunction(node),
|
|
272
|
-
statement:
|
|
261
|
+
statement: getStatementRange(ts, parents, node, ast),
|
|
273
262
|
};
|
|
274
263
|
if (node.arguments.length) {
|
|
275
264
|
props.define.arg = _getStartEnd(node.arguments[0]);
|
|
@@ -308,7 +297,6 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
308
297
|
}
|
|
309
298
|
else if (vueCompilerOptions.composibles.useTemplateRef.includes(callText) && node.arguments.length && !node.typeArguments?.length) {
|
|
310
299
|
const define = parseDefineFunction(node);
|
|
311
|
-
define.arg = _getStartEnd(node.arguments[0]);
|
|
312
300
|
let name;
|
|
313
301
|
if (ts.isVariableDeclaration(parent)) {
|
|
314
302
|
name = getNodeText(ts, parent.name, ast);
|
|
@@ -319,13 +307,10 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
319
307
|
});
|
|
320
308
|
}
|
|
321
309
|
else if (vueCompilerOptions.composibles.useCssModule.includes(callText)) {
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
module.arg = _getStartEnd(node.arguments[0]);
|
|
327
|
-
}
|
|
328
|
-
cssModules.push(module);
|
|
310
|
+
const define = parseDefineFunction(node);
|
|
311
|
+
cssModules.push({
|
|
312
|
+
define
|
|
313
|
+
});
|
|
329
314
|
}
|
|
330
315
|
}
|
|
331
316
|
ts.forEachChild(node, child => {
|
|
@@ -430,4 +415,22 @@ function getNodeText(ts, node, sourceFile) {
|
|
|
430
415
|
const { start, end } = getStartEnd(ts, node, sourceFile);
|
|
431
416
|
return sourceFile.text.substring(start, end);
|
|
432
417
|
}
|
|
418
|
+
function getStatementRange(ts, parents, node, sourceFile) {
|
|
419
|
+
let statementRange;
|
|
420
|
+
for (let i = parents.length - 1; i >= 0; i--) {
|
|
421
|
+
if (ts.isStatement(parents[i])) {
|
|
422
|
+
const statement = parents[i];
|
|
423
|
+
ts.forEachChild(statement, child => {
|
|
424
|
+
const range = getStartEnd(ts, child, sourceFile);
|
|
425
|
+
statementRange ??= range;
|
|
426
|
+
statementRange.end = range.end;
|
|
427
|
+
});
|
|
428
|
+
break;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
if (!statementRange) {
|
|
432
|
+
statementRange = getStartEnd(ts, node, sourceFile);
|
|
433
|
+
}
|
|
434
|
+
return statementRange;
|
|
435
|
+
}
|
|
433
436
|
//# 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,8 +14,8 @@ 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[];
|
|
@@ -25,6 +25,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
25
25
|
destructured?: Set<string>;
|
|
26
26
|
destructuredRest?: string;
|
|
27
27
|
define?: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
|
|
28
|
+
exp: import("../types").TextRange;
|
|
28
29
|
arg?: import("../types").TextRange;
|
|
29
30
|
typeArg?: import("../types").TextRange;
|
|
30
31
|
}> & {
|
|
@@ -38,6 +39,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
38
39
|
name?: string;
|
|
39
40
|
isObjectBindingPattern?: boolean;
|
|
40
41
|
define?: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
|
|
42
|
+
exp: import("../types").TextRange;
|
|
41
43
|
arg?: import("../types").TextRange;
|
|
42
44
|
typeArg?: import("../types").TextRange;
|
|
43
45
|
}>;
|
|
@@ -45,15 +47,18 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
45
47
|
emits: {
|
|
46
48
|
name?: string;
|
|
47
49
|
define?: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
|
|
50
|
+
exp: import("../types").TextRange;
|
|
48
51
|
arg?: import("../types").TextRange;
|
|
49
52
|
typeArg?: import("../types").TextRange;
|
|
50
53
|
}> & {
|
|
54
|
+
statement: import("../types").TextRange;
|
|
51
55
|
hasUnionTypeArg?: boolean;
|
|
52
56
|
};
|
|
53
57
|
};
|
|
54
58
|
expose: {
|
|
55
59
|
name?: string;
|
|
56
60
|
define?: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
|
|
61
|
+
exp: import("../types").TextRange;
|
|
57
62
|
arg?: import("../types").TextRange;
|
|
58
63
|
typeArg?: import("../types").TextRange;
|
|
59
64
|
}>;
|
|
@@ -63,8 +68,11 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
63
68
|
inheritAttrs?: string;
|
|
64
69
|
};
|
|
65
70
|
cssModules: {
|
|
66
|
-
|
|
67
|
-
|
|
71
|
+
define: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
|
|
72
|
+
exp: import("../types").TextRange;
|
|
73
|
+
arg?: import("../types").TextRange;
|
|
74
|
+
typeArg?: import("../types").TextRange;
|
|
75
|
+
}>;
|
|
68
76
|
}[];
|
|
69
77
|
defineProp: {
|
|
70
78
|
localName: import("../types").TextRange | undefined;
|
|
@@ -78,14 +86,15 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
78
86
|
}[];
|
|
79
87
|
templateRefs: {
|
|
80
88
|
name?: string;
|
|
81
|
-
define
|
|
89
|
+
define: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
|
|
90
|
+
exp: import("../types").TextRange;
|
|
82
91
|
arg?: import("../types").TextRange;
|
|
83
92
|
typeArg?: import("../types").TextRange;
|
|
84
93
|
}>;
|
|
85
94
|
}[];
|
|
86
|
-
} | undefined
|
|
87
|
-
lang: ()
|
|
88
|
-
generatedScript: ()
|
|
95
|
+
} | undefined>;
|
|
96
|
+
lang: import("alien-signals").ISignal<string>;
|
|
97
|
+
generatedScript: import("alien-signals").ISignal<{
|
|
89
98
|
codes: Code[];
|
|
90
99
|
linkedCodeMappings: Mapping<unknown>[];
|
|
91
100
|
generatedTemplate: boolean;
|
|
@@ -104,9 +113,9 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
104
113
|
readonly TypePropsToOption: string;
|
|
105
114
|
readonly OmitIndexSignature: string;
|
|
106
115
|
};
|
|
107
|
-
inlayHints: import("../codegen/
|
|
108
|
-
}
|
|
109
|
-
generatedTemplate: ()
|
|
116
|
+
inlayHints: import("../codegen/inlayHints").InlayHintInfo[];
|
|
117
|
+
}>;
|
|
118
|
+
generatedTemplate: import("alien-signals").ISignal<{
|
|
110
119
|
codes: Code[];
|
|
111
120
|
slots: {
|
|
112
121
|
name: string;
|
|
@@ -142,7 +151,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
142
151
|
offset: number;
|
|
143
152
|
}[];
|
|
144
153
|
emptyClassOffsets: number[];
|
|
145
|
-
inlayHints: import("../codegen/
|
|
154
|
+
inlayHints: import("../codegen/inlayHints").InlayHintInfo[];
|
|
146
155
|
hasSlot: boolean;
|
|
147
156
|
inheritedAttrVars: Set<unknown>;
|
|
148
157
|
templateRefs: Map<string, [varName: string, offset: number]>;
|
|
@@ -157,7 +166,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
157
166
|
expectError: (prevNode: import("@vue/compiler-dom").CommentNode) => Generator<Code>;
|
|
158
167
|
resetDirectiveComments: (endStr: string) => Generator<Code>;
|
|
159
168
|
generateAutoImportCompletion: () => Generator<Code>;
|
|
160
|
-
} | undefined
|
|
169
|
+
} | undefined>;
|
|
161
170
|
}>;
|
|
162
171
|
declare const plugin: VueLanguagePlugin;
|
|
163
172
|
export default plugin;
|