@vue/language-core 2.2.10 → 3.0.0-alpha.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/index.d.ts +1 -2
- package/index.js +1 -1
- package/lib/codegen/codeFeatures.d.ts +5 -0
- package/lib/codegen/codeFeatures.js +5 -0
- package/lib/codegen/globalTypes.js +44 -31
- package/lib/codegen/localTypes.d.ts +2 -3
- package/lib/codegen/localTypes.js +5 -15
- package/lib/codegen/script/component.js +21 -9
- package/lib/codegen/script/context.d.ts +1 -1
- package/lib/codegen/script/context.js +1 -1
- package/lib/codegen/script/index.d.ts +1 -2
- package/lib/codegen/script/index.js +2 -18
- package/lib/codegen/script/scriptSetup.js +5 -16
- package/lib/codegen/script/src.js +4 -22
- package/lib/codegen/script/template.js +7 -6
- package/lib/codegen/template/context.d.ts +29 -19
- package/lib/codegen/template/context.js +87 -56
- package/lib/codegen/template/element.d.ts +2 -2
- package/lib/codegen/template/element.js +34 -63
- package/lib/codegen/template/elementChildren.d.ts +2 -2
- package/lib/codegen/template/elementChildren.js +4 -6
- package/lib/codegen/template/elementDirectives.js +3 -15
- package/lib/codegen/template/elementEvents.d.ts +4 -3
- package/lib/codegen/template/elementEvents.js +61 -29
- package/lib/codegen/template/elementProps.d.ts +2 -2
- package/lib/codegen/template/elementProps.js +11 -22
- package/lib/codegen/template/index.d.ts +1 -2
- package/lib/codegen/template/index.js +22 -11
- package/lib/codegen/template/interpolation.d.ts +1 -1
- package/lib/codegen/template/interpolation.js +53 -51
- package/lib/codegen/template/slotOutlet.js +2 -3
- package/lib/codegen/template/styleScopedClasses.js +2 -2
- package/lib/codegen/template/templateChild.d.ts +1 -1
- package/lib/codegen/template/templateChild.js +12 -46
- package/lib/codegen/template/vFor.js +5 -10
- package/lib/codegen/template/vIf.js +2 -10
- package/lib/codegen/template/vSlot.d.ts +1 -2
- package/lib/codegen/template/vSlot.js +111 -59
- package/lib/codegen/utils/index.d.ts +2 -3
- package/lib/codegen/utils/index.js +2 -18
- package/lib/languagePlugin.d.ts +1 -1
- package/lib/languagePlugin.js +1 -7
- package/lib/parsers/scriptRanges.d.ts +2 -3
- package/lib/parsers/scriptRanges.js +10 -13
- package/lib/parsers/scriptSetupRanges.d.ts +0 -3
- package/lib/parsers/scriptSetupRanges.js +36 -43
- package/lib/plugins/file-md.js +3 -0
- package/lib/plugins/vue-style-css.d.ts +3 -0
- package/lib/plugins/vue-style-css.js +18 -0
- package/lib/plugins/vue-template-inline-css.js +1 -1
- package/lib/plugins/vue-template-inline-ts.js +5 -2
- package/lib/plugins/vue-tsx.d.ts +27 -18
- package/lib/plugins/vue-tsx.js +32 -24
- package/lib/plugins.d.ts +1 -1
- package/lib/types.d.ts +3 -2
- package/lib/utils/shared.d.ts +4 -1
- package/lib/utils/shared.js +12 -4
- package/lib/utils/signals.d.ts +1 -0
- package/lib/utils/signals.js +11 -0
- package/lib/utils/ts.d.ts +0 -4
- package/lib/utils/ts.js +4 -14
- package/lib/virtualFile/computedSfc.js +6 -6
- package/package.json +6 -8
- package/lib/utils/vue2TemplateCompiler.d.ts +0 -2
- package/lib/utils/vue2TemplateCompiler.js +0 -89
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createTemplateCodegenContext = createTemplateCodegenContext;
|
|
4
|
+
const CompilerDOM = require("@vue/compiler-dom");
|
|
4
5
|
const codeFeatures_1 = require("../codeFeatures");
|
|
5
6
|
const utils_1 = require("../utils");
|
|
6
7
|
const wrapWith_1 = require("../utils/wrapWith");
|
|
8
|
+
const commentDirectiveRegex = /^<!--\s*@vue-(?<name>[-\w]+)\b(?<content>[\s\S]*)-->$/;
|
|
7
9
|
/**
|
|
8
10
|
* Creates and returns a Context object used for generating type-checkable TS code
|
|
9
11
|
* from the template section of a .vue file.
|
|
@@ -102,13 +104,11 @@ const wrapWith_1 = require("../utils/wrapWith");
|
|
|
102
104
|
* and additionally how we use that to determine whether to propagate diagnostics back upward.
|
|
103
105
|
*/
|
|
104
106
|
function createTemplateCodegenContext(options) {
|
|
105
|
-
let ignoredError = false;
|
|
106
|
-
let expectErrorToken;
|
|
107
|
-
let lastGenericComment;
|
|
108
107
|
let variableId = 0;
|
|
109
108
|
function resolveCodeFeatures(features) {
|
|
110
|
-
if (features.verification) {
|
|
111
|
-
|
|
109
|
+
if (features.verification && stack.length) {
|
|
110
|
+
const data = stack[stack.length - 1];
|
|
111
|
+
if (data.ignoreError) {
|
|
112
112
|
// We are currently in a region of code covered by a @vue-ignore directive, so don't
|
|
113
113
|
// even bother performing any type-checking: set verification to false.
|
|
114
114
|
return {
|
|
@@ -116,17 +116,16 @@ function createTemplateCodegenContext(options) {
|
|
|
116
116
|
verification: false,
|
|
117
117
|
};
|
|
118
118
|
}
|
|
119
|
-
if (
|
|
119
|
+
if (data.expectError !== undefined) {
|
|
120
120
|
// We are currently in a region of code covered by a @vue-expect-error directive. We need to
|
|
121
121
|
// keep track of the number of errors encountered within this region so that we can know whether
|
|
122
122
|
// we will need to propagate an "unused ts-expect-error" diagnostic back to the original
|
|
123
123
|
// .vue file or not.
|
|
124
|
-
const token = expectErrorToken;
|
|
125
124
|
return {
|
|
126
125
|
...features,
|
|
127
126
|
verification: {
|
|
128
127
|
shouldReport: () => {
|
|
129
|
-
token
|
|
128
|
+
data.expectError.token++;
|
|
130
129
|
return false;
|
|
131
130
|
},
|
|
132
131
|
},
|
|
@@ -148,7 +147,12 @@ function createTemplateCodegenContext(options) {
|
|
|
148
147
|
const bindingAttrLocs = [];
|
|
149
148
|
const inheritedAttrVars = new Set();
|
|
150
149
|
const templateRefs = new Map();
|
|
150
|
+
const stack = [];
|
|
151
|
+
const commentBuffer = [];
|
|
151
152
|
return {
|
|
153
|
+
get currentInfo() {
|
|
154
|
+
return stack[stack.length - 1];
|
|
155
|
+
},
|
|
152
156
|
codeFeatures: new Proxy(codeFeatures_1.codeFeatures, {
|
|
153
157
|
get(target, key) {
|
|
154
158
|
const data = target[key];
|
|
@@ -156,11 +160,11 @@ function createTemplateCodegenContext(options) {
|
|
|
156
160
|
},
|
|
157
161
|
}),
|
|
158
162
|
resolveCodeFeatures,
|
|
163
|
+
inVFor: false,
|
|
159
164
|
slots,
|
|
160
165
|
dynamicSlots,
|
|
161
166
|
dollarVars,
|
|
162
167
|
accessExternalVariables,
|
|
163
|
-
lastGenericComment,
|
|
164
168
|
blockConditions,
|
|
165
169
|
scopedClasses,
|
|
166
170
|
emptyClassOffsets,
|
|
@@ -171,6 +175,13 @@ function createTemplateCodegenContext(options) {
|
|
|
171
175
|
currentComponent: undefined,
|
|
172
176
|
singleRootElTypes: [],
|
|
173
177
|
singleRootNodes: new Set(),
|
|
178
|
+
addTemplateRef(name, typeExp, offset) {
|
|
179
|
+
let refs = templateRefs.get(name);
|
|
180
|
+
if (!refs) {
|
|
181
|
+
templateRefs.set(name, refs = []);
|
|
182
|
+
}
|
|
183
|
+
refs.push({ typeExp, offset });
|
|
184
|
+
},
|
|
174
185
|
accessExternalVariable(name, offset) {
|
|
175
186
|
let arr = accessExternalVariables.get(name);
|
|
176
187
|
if (!arr) {
|
|
@@ -180,26 +191,26 @@ function createTemplateCodegenContext(options) {
|
|
|
180
191
|
arr.add(offset);
|
|
181
192
|
}
|
|
182
193
|
},
|
|
183
|
-
hasLocalVariable
|
|
194
|
+
hasLocalVariable(name) {
|
|
184
195
|
return !!localVars.get(name);
|
|
185
196
|
},
|
|
186
|
-
addLocalVariable
|
|
197
|
+
addLocalVariable(name) {
|
|
187
198
|
localVars.set(name, (localVars.get(name) ?? 0) + 1);
|
|
188
199
|
},
|
|
189
|
-
removeLocalVariable
|
|
200
|
+
removeLocalVariable(name) {
|
|
190
201
|
localVars.set(name, localVars.get(name) - 1);
|
|
191
202
|
},
|
|
192
|
-
getInternalVariable
|
|
203
|
+
getInternalVariable() {
|
|
193
204
|
return `__VLS_${variableId++}`;
|
|
194
205
|
},
|
|
195
|
-
getHoistVariable
|
|
206
|
+
getHoistVariable(originalVar) {
|
|
196
207
|
let name = hoistVars.get(originalVar);
|
|
197
208
|
if (name === undefined) {
|
|
198
209
|
hoistVars.set(originalVar, name = `__VLS_${variableId++}`);
|
|
199
210
|
}
|
|
200
211
|
return name;
|
|
201
212
|
},
|
|
202
|
-
generateHoistVariables
|
|
213
|
+
*generateHoistVariables() {
|
|
203
214
|
// trick to avoid TS 4081 (#5186)
|
|
204
215
|
if (hoistVars.size) {
|
|
205
216
|
yield `// @ts-ignore${utils_1.newLine}`;
|
|
@@ -210,50 +221,12 @@ function createTemplateCodegenContext(options) {
|
|
|
210
221
|
yield utils_1.endOfLine;
|
|
211
222
|
}
|
|
212
223
|
},
|
|
213
|
-
generateConditionGuards
|
|
224
|
+
*generateConditionGuards() {
|
|
214
225
|
for (const condition of blockConditions) {
|
|
215
226
|
yield `if (!${condition}) return${utils_1.endOfLine}`;
|
|
216
227
|
}
|
|
217
228
|
},
|
|
218
|
-
|
|
219
|
-
if (!ignoredError) {
|
|
220
|
-
ignoredError = true;
|
|
221
|
-
yield `// @vue-ignore start${utils_1.newLine}`;
|
|
222
|
-
}
|
|
223
|
-
},
|
|
224
|
-
expectError: function* (prevNode) {
|
|
225
|
-
if (!expectErrorToken) {
|
|
226
|
-
expectErrorToken = {
|
|
227
|
-
errors: 0,
|
|
228
|
-
node: prevNode,
|
|
229
|
-
};
|
|
230
|
-
yield `// @vue-expect-error start${utils_1.newLine}`;
|
|
231
|
-
}
|
|
232
|
-
},
|
|
233
|
-
resetDirectiveComments: function* (endStr) {
|
|
234
|
-
if (expectErrorToken) {
|
|
235
|
-
const token = expectErrorToken;
|
|
236
|
-
yield* (0, wrapWith_1.wrapWith)(expectErrorToken.node.loc.start.offset, expectErrorToken.node.loc.end.offset, {
|
|
237
|
-
verification: {
|
|
238
|
-
// If no errors/warnings/diagnostics were reported within the region of code covered
|
|
239
|
-
// by the @vue-expect-error directive, then we should allow any `unused @ts-expect-error`
|
|
240
|
-
// diagnostics to be reported upward.
|
|
241
|
-
shouldReport: () => token.errors === 0,
|
|
242
|
-
},
|
|
243
|
-
}, `// @ts-expect-error __VLS_TS_EXPECT_ERROR`);
|
|
244
|
-
yield `${utils_1.newLine}${utils_1.endOfLine}`;
|
|
245
|
-
expectErrorToken = undefined;
|
|
246
|
-
yield `// @vue-expect-error ${endStr}${utils_1.newLine}`;
|
|
247
|
-
}
|
|
248
|
-
if (ignoredError) {
|
|
249
|
-
ignoredError = false;
|
|
250
|
-
yield `// @vue-ignore ${endStr}${utils_1.newLine}`;
|
|
251
|
-
}
|
|
252
|
-
},
|
|
253
|
-
generateAutoImportCompletion: function* () {
|
|
254
|
-
if (!options.edited) {
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
229
|
+
*generateAutoImportCompletion() {
|
|
257
230
|
const all = [...accessExternalVariables.entries()];
|
|
258
231
|
if (!all.some(([_, offsets]) => offsets.size)) {
|
|
259
232
|
return;
|
|
@@ -287,7 +260,65 @@ function createTemplateCodegenContext(options) {
|
|
|
287
260
|
offsets.clear();
|
|
288
261
|
}
|
|
289
262
|
yield `]${utils_1.endOfLine}`;
|
|
290
|
-
}
|
|
263
|
+
},
|
|
264
|
+
enter(node) {
|
|
265
|
+
if (node.type === CompilerDOM.NodeTypes.COMMENT) {
|
|
266
|
+
commentBuffer.push(node);
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
const data = {};
|
|
270
|
+
const comments = [...commentBuffer];
|
|
271
|
+
commentBuffer.length = 0;
|
|
272
|
+
for (const comment of comments) {
|
|
273
|
+
const match = comment.loc.source.match(commentDirectiveRegex);
|
|
274
|
+
if (match) {
|
|
275
|
+
const { name, content } = match.groups;
|
|
276
|
+
switch (name) {
|
|
277
|
+
case 'skip': {
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
case 'ignore': {
|
|
281
|
+
data.ignoreError = true;
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
case 'expect-error': {
|
|
285
|
+
data.expectError = {
|
|
286
|
+
token: 0,
|
|
287
|
+
node: comment,
|
|
288
|
+
};
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
case 'generic': {
|
|
292
|
+
const text = content.trim();
|
|
293
|
+
if (text.startsWith('{') && text.endsWith('}')) {
|
|
294
|
+
data.generic = {
|
|
295
|
+
content: text.slice(1, -1),
|
|
296
|
+
offset: comment.loc.start.offset + comment.loc.source.indexOf('{') + 1,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
stack.push(data);
|
|
305
|
+
return true;
|
|
306
|
+
},
|
|
307
|
+
*exit() {
|
|
308
|
+
const data = stack.pop();
|
|
309
|
+
commentBuffer.length = 0;
|
|
310
|
+
if (data.expectError !== undefined) {
|
|
311
|
+
yield* (0, wrapWith_1.wrapWith)(data.expectError.node.loc.start.offset, data.expectError.node.loc.end.offset, {
|
|
312
|
+
verification: {
|
|
313
|
+
// If no errors/warnings/diagnostics were reported within the region of code covered
|
|
314
|
+
// by the @vue-expect-error directive, then we should allow any `unused @ts-expect-error`
|
|
315
|
+
// diagnostics to be reported upward.
|
|
316
|
+
shouldReport: () => data.expectError.token === 0,
|
|
317
|
+
},
|
|
318
|
+
}, `// @ts-expect-error`);
|
|
319
|
+
yield `${utils_1.newLine}${utils_1.endOfLine}`;
|
|
320
|
+
}
|
|
321
|
+
},
|
|
291
322
|
};
|
|
292
323
|
}
|
|
293
324
|
//# sourceMappingURL=context.js.map
|
|
@@ -2,5 +2,5 @@ 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 generateComponent(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode
|
|
6
|
-
export declare function generateElement(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode
|
|
5
|
+
export declare function generateComponent(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode): Generator<Code>;
|
|
6
|
+
export declare function generateElement(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode): Generator<Code>;
|
|
@@ -5,6 +5,7 @@ exports.generateElement = generateElement;
|
|
|
5
5
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
6
6
|
const shared_1 = require("@vue/shared");
|
|
7
7
|
const shared_2 = require("../../utils/shared");
|
|
8
|
+
const codeFeatures_1 = require("../codeFeatures");
|
|
8
9
|
const inlayHints_1 = require("../inlayHints");
|
|
9
10
|
const utils_1 = require("../utils");
|
|
10
11
|
const camelized_1 = require("../utils/camelized");
|
|
@@ -18,7 +19,7 @@ const propertyAccess_1 = require("./propertyAccess");
|
|
|
18
19
|
const styleScopedClasses_1 = require("./styleScopedClasses");
|
|
19
20
|
const vSlot_1 = require("./vSlot");
|
|
20
21
|
const colonReg = /:/g;
|
|
21
|
-
function* generateComponent(options, ctx, node
|
|
22
|
+
function* generateComponent(options, ctx, node) {
|
|
22
23
|
const tagOffsets = [node.loc.start.offset + options.template.content.slice(node.loc.start.offset).indexOf(node.tag)];
|
|
23
24
|
if (!node.isSelfClosing && options.template.lang === 'html') {
|
|
24
25
|
const endTagOffset = node.loc.start.offset + node.loc.source.lastIndexOf(node.tag);
|
|
@@ -34,9 +35,11 @@ function* generateComponent(options, ctx, node, isVForChild) {
|
|
|
34
35
|
const componentVNodeVar = ctx.getInternalVariable();
|
|
35
36
|
const componentCtxVar = ctx.getInternalVariable();
|
|
36
37
|
const isComponentTag = node.tag.toLowerCase() === 'component';
|
|
38
|
+
ctx.currentComponent?.childTypes.push(`typeof ${componentVNodeVar}`);
|
|
37
39
|
ctx.currentComponent = {
|
|
38
40
|
ctxVar: componentCtxVar,
|
|
39
|
-
|
|
41
|
+
childTypes: [],
|
|
42
|
+
used: false,
|
|
40
43
|
};
|
|
41
44
|
let props = node.props;
|
|
42
45
|
let dynamicTagInfo;
|
|
@@ -82,13 +85,7 @@ function* generateComponent(options, ctx, node, isVForChild) {
|
|
|
82
85
|
}
|
|
83
86
|
else {
|
|
84
87
|
const shouldCapitalize = matchImportName[0].toUpperCase() === matchImportName[0];
|
|
85
|
-
yield* (0, camelized_1.generateCamelized)(shouldCapitalize ? (0, shared_1.capitalize)(node.tag) : node.tag, 'template', tagOffset,
|
|
86
|
-
...ctx.codeFeatures.withoutHighlightAndCompletion,
|
|
87
|
-
navigation: {
|
|
88
|
-
resolveRenameNewName: camelizeComponentName,
|
|
89
|
-
resolveRenameEditText: getTagRenameApply(node.tag),
|
|
90
|
-
},
|
|
91
|
-
});
|
|
88
|
+
yield* (0, camelized_1.generateCamelized)(shouldCapitalize ? (0, shared_1.capitalize)(node.tag) : node.tag, 'template', tagOffset, ctx.codeFeatures.withoutHighlightAndCompletion);
|
|
92
89
|
}
|
|
93
90
|
yield `, `;
|
|
94
91
|
}
|
|
@@ -106,9 +103,7 @@ function* generateComponent(options, ctx, node, isVForChild) {
|
|
|
106
103
|
else if (!isComponentTag) {
|
|
107
104
|
yield `const ${componentOriginalVar} = ({} as __VLS_WithComponent<'${getCanonicalComponentName(node.tag)}', __VLS_LocalComponents, `;
|
|
108
105
|
if (options.selfComponentName && possibleOriginalNames.includes(options.selfComponentName)) {
|
|
109
|
-
yield `typeof __VLS_self & (new () => {
|
|
110
|
-
+ (0, shared_2.getSlotsPropertyName)(options.vueCompilerOptions.target)
|
|
111
|
-
+ `: __VLS_Slots }), `;
|
|
106
|
+
yield `typeof __VLS_self & (new () => { $slots: __VLS_Slots }), `;
|
|
112
107
|
}
|
|
113
108
|
else {
|
|
114
109
|
yield `void, `;
|
|
@@ -125,29 +120,21 @@ function* generateComponent(options, ctx, node, isVForChild) {
|
|
|
125
120
|
yield `/** @type {[`;
|
|
126
121
|
for (const tagOffset of tagOffsets) {
|
|
127
122
|
for (const shouldCapitalize of (node.tag[0] === node.tag[0].toUpperCase() ? [false] : [true, false])) {
|
|
128
|
-
const expectName = shouldCapitalize ? (0, shared_1.capitalize)(camelizedTag) : camelizedTag;
|
|
129
123
|
yield `typeof __VLS_components.`;
|
|
130
|
-
yield* (0, camelized_1.generateCamelized)(shouldCapitalize ? (0, shared_1.capitalize)(node.tag) : node.tag, 'template', tagOffset,
|
|
131
|
-
navigation: {
|
|
132
|
-
resolveRenameNewName: node.tag !== expectName ? camelizeComponentName : undefined,
|
|
133
|
-
resolveRenameEditText: getTagRenameApply(node.tag),
|
|
134
|
-
},
|
|
135
|
-
});
|
|
124
|
+
yield* (0, camelized_1.generateCamelized)(shouldCapitalize ? (0, shared_1.capitalize)(node.tag) : node.tag, 'template', tagOffset, codeFeatures_1.codeFeatures.navigation);
|
|
136
125
|
yield `, `;
|
|
137
126
|
}
|
|
138
127
|
}
|
|
139
128
|
yield `]} */${utils_1.endOfLine}`;
|
|
140
129
|
// auto import support
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
yield `${utils_1.endOfLine}`;
|
|
150
|
-
}
|
|
130
|
+
yield `// @ts-ignore${utils_1.newLine}`; // #2304
|
|
131
|
+
yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(node.tag), 'template', tagOffsets[0], {
|
|
132
|
+
completion: {
|
|
133
|
+
isAdditional: true,
|
|
134
|
+
onlyImport: true,
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
yield `${utils_1.endOfLine}`;
|
|
151
138
|
}
|
|
152
139
|
}
|
|
153
140
|
else {
|
|
@@ -172,7 +159,7 @@ function* generateComponent(options, ctx, node, isVForChild) {
|
|
|
172
159
|
yield* (0, wrapWith_1.wrapWith)(tagOffsets[0], tagOffsets[0] + node.tag.length, ctx.codeFeatures.verification, `{${utils_1.newLine}`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, props, options.vueCompilerOptions.checkUnknownProps, true, failedPropExps), `}`);
|
|
173
160
|
yield `, ...__VLS_functionalComponentArgsRest(${componentFunctionalVar}))${utils_1.endOfLine}`;
|
|
174
161
|
yield* generateFailedPropExps(options, ctx, failedPropExps);
|
|
175
|
-
yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, componentFunctionalVar, componentVNodeVar, componentCtxVar);
|
|
162
|
+
yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, componentOriginalVar, componentFunctionalVar, componentVNodeVar, componentCtxVar);
|
|
176
163
|
yield* (0, elementDirectives_1.generateElementDirectives)(options, ctx, node);
|
|
177
164
|
const [refName, offset] = yield* generateElementReference(options, ctx, node);
|
|
178
165
|
const tag = (0, shared_2.hyphenateTag)(node.tag);
|
|
@@ -181,15 +168,12 @@ function* generateComponent(options, ctx, node, isVForChild) {
|
|
|
181
168
|
const componentInstanceVar = ctx.getInternalVariable();
|
|
182
169
|
ctx.currentComponent.used = true;
|
|
183
170
|
yield `var ${componentInstanceVar} = {} as (Parameters<NonNullable<typeof ${componentCtxVar}['expose']>>[0] | null)`;
|
|
184
|
-
if (
|
|
171
|
+
if (ctx.inVFor) {
|
|
185
172
|
yield `[]`;
|
|
186
173
|
}
|
|
187
174
|
yield `${utils_1.endOfLine}`;
|
|
188
175
|
if (refName && offset) {
|
|
189
|
-
ctx.
|
|
190
|
-
typeExp: `typeof ${ctx.getHoistVariable(componentInstanceVar)}`,
|
|
191
|
-
offset
|
|
192
|
-
});
|
|
176
|
+
ctx.addTemplateRef(refName, `typeof ${ctx.getHoistVariable(componentInstanceVar)}`, offset);
|
|
193
177
|
}
|
|
194
178
|
if (isRootNode) {
|
|
195
179
|
ctx.singleRootElTypes.push(`NonNullable<typeof ${componentInstanceVar}>['$el']`);
|
|
@@ -202,28 +186,22 @@ function* generateComponent(options, ctx, node, isVForChild) {
|
|
|
202
186
|
}
|
|
203
187
|
(0, styleScopedClasses_1.collectStyleScopedClassReferences)(options, ctx, node);
|
|
204
188
|
const slotDir = node.props.find(p => p.type === CompilerDOM.NodeTypes.DIRECTIVE && p.name === 'slot');
|
|
205
|
-
|
|
206
|
-
yield* (0, vSlot_1.generateVSlot)(options, ctx, node, slotDir);
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
// #932: reference for default slot
|
|
210
|
-
yield* (0, vSlot_1.generateImplicitDefaultSlot)(ctx, node);
|
|
211
|
-
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node);
|
|
212
|
-
}
|
|
189
|
+
yield* (0, vSlot_1.generateVSlot)(options, ctx, node, slotDir);
|
|
213
190
|
if (ctx.currentComponent.used) {
|
|
214
|
-
yield `var ${componentCtxVar}!:
|
|
191
|
+
yield `var ${componentCtxVar}!: __VLS_FunctionalComponentCtx<typeof ${componentOriginalVar}, typeof ${componentVNodeVar}>${utils_1.endOfLine}`;
|
|
215
192
|
}
|
|
216
193
|
}
|
|
217
|
-
function* generateElement(options, ctx, node
|
|
194
|
+
function* generateElement(options, ctx, node) {
|
|
218
195
|
const startTagOffset = node.loc.start.offset + options.template.content.slice(node.loc.start.offset).indexOf(node.tag);
|
|
219
196
|
const endTagOffset = !node.isSelfClosing && options.template.lang === 'html'
|
|
220
197
|
? node.loc.start.offset + node.loc.source.lastIndexOf(node.tag)
|
|
221
198
|
: undefined;
|
|
222
199
|
const failedPropExps = [];
|
|
223
|
-
|
|
200
|
+
ctx.currentComponent?.childTypes.push(`__VLS_NativeElements['${node.tag}']`);
|
|
201
|
+
yield `__VLS_asFunctionalElement(__VLS_elements`;
|
|
224
202
|
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, startTagOffset, ctx.codeFeatures.withoutHighlightAndCompletion);
|
|
225
203
|
if (endTagOffset !== undefined) {
|
|
226
|
-
yield `,
|
|
204
|
+
yield `, __VLS_elements`;
|
|
227
205
|
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, endTagOffset, ctx.codeFeatures.withoutHighlightAndCompletion);
|
|
228
206
|
}
|
|
229
207
|
yield `)(`;
|
|
@@ -234,22 +212,22 @@ function* generateElement(options, ctx, node, isVForChild) {
|
|
|
234
212
|
const [refName, offset] = yield* generateElementReference(options, ctx, node);
|
|
235
213
|
if (refName && offset) {
|
|
236
214
|
let typeExp = `__VLS_NativeElements['${node.tag}']`;
|
|
237
|
-
if (
|
|
215
|
+
if (ctx.inVFor) {
|
|
238
216
|
typeExp += `[]`;
|
|
239
217
|
}
|
|
240
|
-
ctx.
|
|
241
|
-
typeExp,
|
|
242
|
-
offset
|
|
243
|
-
});
|
|
218
|
+
ctx.addTemplateRef(refName, typeExp, offset);
|
|
244
219
|
}
|
|
245
220
|
if (ctx.singleRootNodes.has(node)) {
|
|
246
221
|
ctx.singleRootElTypes.push(`__VLS_NativeElements['${node.tag}']`);
|
|
247
222
|
}
|
|
248
223
|
if (hasVBindAttrs(options, ctx, node)) {
|
|
249
|
-
ctx.inheritedAttrVars.add(`
|
|
224
|
+
ctx.inheritedAttrVars.add(`__VLS_elements.${node.tag}`);
|
|
250
225
|
}
|
|
251
226
|
(0, styleScopedClasses_1.collectStyleScopedClassReferences)(options, ctx, node);
|
|
252
|
-
|
|
227
|
+
const { currentComponent } = ctx;
|
|
228
|
+
ctx.currentComponent = undefined;
|
|
229
|
+
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node.children);
|
|
230
|
+
ctx.currentComponent = currentComponent;
|
|
253
231
|
}
|
|
254
232
|
function* generateFailedPropExps(options, ctx, failedPropExps) {
|
|
255
233
|
for (const failedExp of failedPropExps) {
|
|
@@ -284,8 +262,8 @@ function* generateCanonicalComponentName(tagText, offset, features) {
|
|
|
284
262
|
}
|
|
285
263
|
}
|
|
286
264
|
function* generateComponentGeneric(ctx) {
|
|
287
|
-
if (ctx.
|
|
288
|
-
const { content, offset } = ctx.
|
|
265
|
+
if (ctx.currentInfo.generic) {
|
|
266
|
+
const { content, offset } = ctx.currentInfo.generic;
|
|
289
267
|
yield* (0, wrapWith_1.wrapWith)(offset, offset + content.length, ctx.codeFeatures.verification, `<`, [
|
|
290
268
|
content,
|
|
291
269
|
'template',
|
|
@@ -293,7 +271,6 @@ function* generateComponentGeneric(ctx) {
|
|
|
293
271
|
ctx.codeFeatures.all
|
|
294
272
|
], `>`);
|
|
295
273
|
}
|
|
296
|
-
ctx.lastGenericComment = undefined;
|
|
297
274
|
}
|
|
298
275
|
function* generateElementReference(options, ctx, node) {
|
|
299
276
|
for (const prop of node.props) {
|
|
@@ -319,10 +296,4 @@ function hasVBindAttrs(options, ctx, node) {
|
|
|
319
296
|
&& prop.name === 'bind'
|
|
320
297
|
&& prop.exp?.loc.source === '$attrs'));
|
|
321
298
|
}
|
|
322
|
-
function camelizeComponentName(newName) {
|
|
323
|
-
return (0, shared_1.camelize)('-' + newName);
|
|
324
|
-
}
|
|
325
|
-
function getTagRenameApply(oldName) {
|
|
326
|
-
return oldName === (0, shared_2.hyphenateTag)(oldName) ? shared_2.hyphenateTag : undefined;
|
|
327
|
-
}
|
|
328
299
|
//# sourceMappingURL=element.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as CompilerDOM from '@vue/compiler-dom';
|
|
1
|
+
import type * 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 generateElementChildren(options: TemplateCodegenOptions, ctx: TemplateCodegenContext,
|
|
5
|
+
export declare function generateElementChildren(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, children: (CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode)[], enterNode?: boolean): Generator<Code>;
|
|
@@ -2,12 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateElementChildren = generateElementChildren;
|
|
4
4
|
const templateChild_1 = require("./templateChild");
|
|
5
|
-
function* generateElementChildren(options, ctx,
|
|
6
|
-
yield* ctx.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, prev);
|
|
10
|
-
prev = childNode;
|
|
5
|
+
function* generateElementChildren(options, ctx, children, enterNode = true) {
|
|
6
|
+
yield* ctx.generateAutoImportCompletion();
|
|
7
|
+
for (const childNode of children) {
|
|
8
|
+
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, enterNode);
|
|
11
9
|
}
|
|
12
10
|
yield* ctx.generateAutoImportCompletion();
|
|
13
11
|
}
|
|
@@ -4,7 +4,6 @@ exports.generateElementDirectives = generateElementDirectives;
|
|
|
4
4
|
exports.generateModifiers = generateModifiers;
|
|
5
5
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
6
6
|
const shared_1 = require("@vue/shared");
|
|
7
|
-
const shared_2 = require("../../utils/shared");
|
|
8
7
|
const codeFeatures_1 = require("../codeFeatures");
|
|
9
8
|
const utils_1 = require("../utils");
|
|
10
9
|
const camelized_1 = require("../utils/camelized");
|
|
@@ -27,9 +26,7 @@ function* generateElementDirectives(options, ctx, node) {
|
|
|
27
26
|
|| prop.name === 'slot'
|
|
28
27
|
|| prop.name === 'on'
|
|
29
28
|
|| prop.name === 'model'
|
|
30
|
-
|| prop.name === 'bind'
|
|
31
|
-
|| prop.name === 'scope'
|
|
32
|
-
|| prop.name === 'data') {
|
|
29
|
+
|| prop.name === 'bind') {
|
|
33
30
|
continue;
|
|
34
31
|
}
|
|
35
32
|
ctx.accessExternalVariable((0, shared_1.camelize)('v-' + prop.name), prop.loc.start.offset);
|
|
@@ -40,14 +37,8 @@ function* generateElementDirectives(options, ctx, node) {
|
|
|
40
37
|
function* generateIdentifier(options, ctx, prop) {
|
|
41
38
|
const rawName = 'v-' + prop.name;
|
|
42
39
|
yield* (0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + rawName.length, ctx.codeFeatures.verification, `__VLS_directives.`, ...(0, camelized_1.generateCamelized)(rawName, 'template', prop.loc.start.offset, ctx.resolveCodeFeatures({
|
|
43
|
-
...codeFeatures_1.codeFeatures.
|
|
44
|
-
// fix https://github.com/vuejs/language-tools/issues/1905
|
|
45
|
-
...codeFeatures_1.codeFeatures.additionalCompletion,
|
|
40
|
+
...codeFeatures_1.codeFeatures.withoutHighlightAndCompletion,
|
|
46
41
|
verification: options.vueCompilerOptions.checkUnknownDirectives && !builtInDirectives.has(prop.name),
|
|
47
|
-
navigation: {
|
|
48
|
-
resolveRenameNewName: shared_1.camelize,
|
|
49
|
-
resolveRenameEditText: getPropRenameApply(prop.name),
|
|
50
|
-
},
|
|
51
42
|
})));
|
|
52
43
|
}
|
|
53
44
|
function* generateArg(options, ctx, prop) {
|
|
@@ -88,9 +79,6 @@ function* generateValue(options, ctx, prop) {
|
|
|
88
79
|
}
|
|
89
80
|
yield* (0, wrapWith_1.wrapWith)(exp.loc.start.offset, exp.loc.end.offset, ctx.codeFeatures.verification, `value`);
|
|
90
81
|
yield `: `;
|
|
91
|
-
yield* (0, elementProps_1.generatePropExp)(options, ctx, prop, exp
|
|
92
|
-
}
|
|
93
|
-
function getPropRenameApply(oldName) {
|
|
94
|
-
return oldName === (0, shared_2.hyphenateAttr)(oldName) ? shared_2.hyphenateAttr : undefined;
|
|
82
|
+
yield* (0, elementProps_1.generatePropExp)(options, ctx, prop, exp);
|
|
95
83
|
}
|
|
96
84
|
//# sourceMappingURL=elementDirectives.js.map
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import * as CompilerDOM from '@vue/compiler-dom';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
|
-
import type { Code } from '../../types';
|
|
3
|
+
import type { Code, VueCodeInformation } from '../../types';
|
|
4
4
|
import type { TemplateCodegenContext } from './context';
|
|
5
5
|
import type { TemplateCodegenOptions } from './index';
|
|
6
|
-
export declare function generateElementEvents(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, componentFunctionalVar: string, componentVNodeVar: string, componentCtxVar: string): Generator<Code>;
|
|
7
|
-
export declare function generateEventArg(ctx: TemplateCodegenContext, name: string, start: number, directive?: string): Generator<Code>;
|
|
6
|
+
export declare function generateElementEvents(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, componentOriginalVar: string, componentFunctionalVar: string, componentVNodeVar: string, componentCtxVar: string): Generator<Code>;
|
|
7
|
+
export declare function generateEventArg(ctx: TemplateCodegenContext, name: string, start: number, directive?: string, features?: VueCodeInformation): Generator<Code>;
|
|
8
8
|
export declare function generateEventExpression(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode): Generator<Code>;
|
|
9
|
+
export declare function generateModelEventExpression(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode): Generator<Code>;
|
|
9
10
|
export declare function isCompoundExpression(ts: typeof import('typescript'), ast: ts.SourceFile): boolean;
|