@vue/language-core 2.2.8 → 3.0.0-alpha.2
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/globalTypes.js +3 -9
- package/lib/codegen/script/component.js +21 -9
- package/lib/codegen/script/index.d.ts +0 -1
- package/lib/codegen/script/index.js +1 -4
- package/lib/codegen/script/scriptSetup.js +1 -10
- package/lib/codegen/script/src.js +1 -20
- package/lib/codegen/script/styleModulesType.d.ts +1 -1
- package/lib/codegen/script/styleModulesType.js +2 -2
- package/lib/codegen/script/template.js +4 -1
- package/lib/codegen/template/context.d.ts +26 -17
- package/lib/codegen/template/context.js +89 -53
- package/lib/codegen/template/element.d.ts +2 -2
- package/lib/codegen/template/element.js +24 -57
- package/lib/codegen/template/elementChildren.d.ts +1 -1
- package/lib/codegen/template/elementChildren.js +4 -6
- package/lib/codegen/template/elementDirectives.js +1 -11
- package/lib/codegen/template/elementEvents.d.ts +1 -0
- package/lib/codegen/template/elementEvents.js +39 -17
- package/lib/codegen/template/elementProps.js +4 -8
- package/lib/codegen/template/index.d.ts +0 -1
- package/lib/codegen/template/index.js +22 -10
- package/lib/codegen/template/interpolation.d.ts +1 -1
- package/lib/codegen/template/interpolation.js +53 -53
- package/lib/codegen/template/slotOutlet.js +1 -2
- 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 +84 -62
- package/lib/codegen/utils/index.js +2 -2
- package/lib/parsers/scriptRanges.js +7 -3
- package/lib/parsers/scriptSetupRanges.d.ts +0 -3
- package/lib/parsers/scriptSetupRanges.js +18 -28
- package/lib/plugins/vue-tsx.d.ts +24 -15
- package/lib/plugins/vue-tsx.js +31 -23
- package/lib/types.d.ts +2 -2
- package/lib/utils/forEachElementNode.d.ts +1 -0
- package/lib/utils/forEachElementNode.js +3 -0
- package/lib/utils/shared.d.ts +5 -1
- package/lib/utils/shared.js +16 -4
- package/lib/utils/ts.d.ts +0 -4
- package/lib/utils/ts.js +1 -10
- package/package.json +2 -2
|
@@ -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);
|
|
@@ -82,13 +83,7 @@ function* generateComponent(options, ctx, node, isVForChild) {
|
|
|
82
83
|
}
|
|
83
84
|
else {
|
|
84
85
|
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
|
-
});
|
|
86
|
+
yield* (0, camelized_1.generateCamelized)(shouldCapitalize ? (0, shared_1.capitalize)(node.tag) : node.tag, 'template', tagOffset, ctx.codeFeatures.withoutHighlightAndCompletion);
|
|
92
87
|
}
|
|
93
88
|
yield `, `;
|
|
94
89
|
}
|
|
@@ -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 {
|
|
@@ -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,21 @@ 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
191
|
yield `var ${componentCtxVar}!: __VLS_PickFunctionalComponentCtx<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
|
-
yield `__VLS_asFunctionalElement(
|
|
200
|
+
yield `__VLS_asFunctionalElement(__VLS_elements`;
|
|
224
201
|
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, startTagOffset, ctx.codeFeatures.withoutHighlightAndCompletion);
|
|
225
202
|
if (endTagOffset !== undefined) {
|
|
226
|
-
yield `,
|
|
203
|
+
yield `, __VLS_elements`;
|
|
227
204
|
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, endTagOffset, ctx.codeFeatures.withoutHighlightAndCompletion);
|
|
228
205
|
}
|
|
229
206
|
yield `)(`;
|
|
@@ -234,22 +211,19 @@ function* generateElement(options, ctx, node, isVForChild) {
|
|
|
234
211
|
const [refName, offset] = yield* generateElementReference(options, ctx, node);
|
|
235
212
|
if (refName && offset) {
|
|
236
213
|
let typeExp = `__VLS_NativeElements['${node.tag}']`;
|
|
237
|
-
if (
|
|
214
|
+
if (ctx.inVFor) {
|
|
238
215
|
typeExp += `[]`;
|
|
239
216
|
}
|
|
240
|
-
ctx.
|
|
241
|
-
typeExp,
|
|
242
|
-
offset
|
|
243
|
-
});
|
|
217
|
+
ctx.addTemplateRef(refName, typeExp, offset);
|
|
244
218
|
}
|
|
245
219
|
if (ctx.singleRootNodes.has(node)) {
|
|
246
220
|
ctx.singleRootElTypes.push(`__VLS_NativeElements['${node.tag}']`);
|
|
247
221
|
}
|
|
248
222
|
if (hasVBindAttrs(options, ctx, node)) {
|
|
249
|
-
ctx.inheritedAttrVars.add(`
|
|
223
|
+
ctx.inheritedAttrVars.add(`__VLS_elements.${node.tag}`);
|
|
250
224
|
}
|
|
251
225
|
(0, styleScopedClasses_1.collectStyleScopedClassReferences)(options, ctx, node);
|
|
252
|
-
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node);
|
|
226
|
+
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node.children);
|
|
253
227
|
}
|
|
254
228
|
function* generateFailedPropExps(options, ctx, failedPropExps) {
|
|
255
229
|
for (const failedExp of failedPropExps) {
|
|
@@ -284,8 +258,8 @@ function* generateCanonicalComponentName(tagText, offset, features) {
|
|
|
284
258
|
}
|
|
285
259
|
}
|
|
286
260
|
function* generateComponentGeneric(ctx) {
|
|
287
|
-
if (ctx.
|
|
288
|
-
const { content, offset } = ctx.
|
|
261
|
+
if (ctx.currentInfo.generic) {
|
|
262
|
+
const { content, offset } = ctx.currentInfo.generic;
|
|
289
263
|
yield* (0, wrapWith_1.wrapWith)(offset, offset + content.length, ctx.codeFeatures.verification, `<`, [
|
|
290
264
|
content,
|
|
291
265
|
'template',
|
|
@@ -293,7 +267,6 @@ function* generateComponentGeneric(ctx) {
|
|
|
293
267
|
ctx.codeFeatures.all
|
|
294
268
|
], `>`);
|
|
295
269
|
}
|
|
296
|
-
ctx.lastGenericComment = undefined;
|
|
297
270
|
}
|
|
298
271
|
function* generateElementReference(options, ctx, node) {
|
|
299
272
|
for (const prop of node.props) {
|
|
@@ -319,10 +292,4 @@ function hasVBindAttrs(options, ctx, node) {
|
|
|
319
292
|
&& prop.name === 'bind'
|
|
320
293
|
&& prop.exp?.loc.source === '$attrs'));
|
|
321
294
|
}
|
|
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
295
|
//# sourceMappingURL=element.js.map
|
|
@@ -2,4 +2,4 @@ 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 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");
|
|
@@ -40,14 +39,8 @@ function* generateElementDirectives(options, ctx, node) {
|
|
|
40
39
|
function* generateIdentifier(options, ctx, prop) {
|
|
41
40
|
const rawName = 'v-' + prop.name;
|
|
42
41
|
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,
|
|
42
|
+
...codeFeatures_1.codeFeatures.withoutHighlightAndCompletion,
|
|
46
43
|
verification: options.vueCompilerOptions.checkUnknownDirectives && !builtInDirectives.has(prop.name),
|
|
47
|
-
navigation: {
|
|
48
|
-
resolveRenameNewName: shared_1.camelize,
|
|
49
|
-
resolveRenameEditText: getPropRenameApply(prop.name),
|
|
50
|
-
},
|
|
51
44
|
})));
|
|
52
45
|
}
|
|
53
46
|
function* generateArg(options, ctx, prop) {
|
|
@@ -90,7 +83,4 @@ function* generateValue(options, ctx, prop) {
|
|
|
90
83
|
yield `: `;
|
|
91
84
|
yield* (0, elementProps_1.generatePropExp)(options, ctx, prop, exp, ctx.codeFeatures.all);
|
|
92
85
|
}
|
|
93
|
-
function getPropRenameApply(oldName) {
|
|
94
|
-
return oldName === (0, shared_2.hyphenateAttr)(oldName) ? shared_2.hyphenateAttr : undefined;
|
|
95
|
-
}
|
|
96
86
|
//# sourceMappingURL=elementDirectives.js.map
|
|
@@ -6,4 +6,5 @@ import type { TemplateCodegenOptions } from './index';
|
|
|
6
6
|
export declare function generateElementEvents(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, componentFunctionalVar: string, componentVNodeVar: string, componentCtxVar: string): Generator<Code>;
|
|
7
7
|
export declare function generateEventArg(ctx: TemplateCodegenContext, name: string, start: number, directive?: string): 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;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateElementEvents = generateElementEvents;
|
|
4
4
|
exports.generateEventArg = generateEventArg;
|
|
5
5
|
exports.generateEventExpression = generateEventExpression;
|
|
6
|
+
exports.generateModelEventExpression = generateModelEventExpression;
|
|
6
7
|
exports.isCompoundExpression = isCompoundExpression;
|
|
7
8
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
8
9
|
const shared_1 = require("@vue/shared");
|
|
@@ -16,9 +17,11 @@ function* generateElementEvents(options, ctx, node, componentFunctionalVar, comp
|
|
|
16
17
|
let propsVar;
|
|
17
18
|
for (const prop of node.props) {
|
|
18
19
|
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
19
|
-
&& prop.name === 'on'
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
&& (prop.name === 'on'
|
|
21
|
+
&& (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic)
|
|
22
|
+
|| options.vueCompilerOptions.strictVModel
|
|
23
|
+
&& prop.name === 'model'
|
|
24
|
+
&& (!prop.arg || prop.arg.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic))) {
|
|
22
25
|
ctx.currentComponent.used = true;
|
|
23
26
|
if (!emitVar) {
|
|
24
27
|
emitVar = ctx.getInternalVariable();
|
|
@@ -28,21 +31,31 @@ function* generateElementEvents(options, ctx, node, componentFunctionalVar, comp
|
|
|
28
31
|
yield `let ${eventsVar}!: __VLS_NormalizeEmits<typeof ${emitVar}>${utils_1.endOfLine}`;
|
|
29
32
|
yield `let ${propsVar}!: __VLS_FunctionalComponentProps<typeof ${componentFunctionalVar}, typeof ${componentVNodeVar}>${utils_1.endOfLine}`;
|
|
30
33
|
}
|
|
31
|
-
let source = prop.arg
|
|
32
|
-
let start = prop.arg
|
|
33
|
-
let propPrefix = 'on';
|
|
34
|
+
let source = prop.arg?.loc.source ?? 'model-value';
|
|
35
|
+
let start = prop.arg?.loc.start.offset;
|
|
36
|
+
let propPrefix = 'on-';
|
|
34
37
|
let emitPrefix = '';
|
|
35
|
-
if (
|
|
38
|
+
if (prop.name === 'model') {
|
|
39
|
+
propPrefix = 'onUpdate:';
|
|
40
|
+
emitPrefix = 'update:';
|
|
41
|
+
}
|
|
42
|
+
else if (source.startsWith('vue:')) {
|
|
36
43
|
source = source.slice('vue:'.length);
|
|
37
44
|
start = start + 'vue:'.length;
|
|
38
|
-
propPrefix = 'onVnode';
|
|
45
|
+
propPrefix = 'onVnode-';
|
|
39
46
|
emitPrefix = 'vnode-';
|
|
40
47
|
}
|
|
41
|
-
yield `
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
yield `(): __VLS_NormalizeComponentEvent<typeof ${propsVar}, typeof ${eventsVar}, '${(0, shared_1.camelize)(propPrefix + source)}', '${emitPrefix + source}', '${(0, shared_1.camelize)(emitPrefix + source)}'> => ({${utils_1.newLine}`;
|
|
49
|
+
if (prop.name === 'on') {
|
|
50
|
+
yield* generateEventArg(ctx, source, start, propPrefix.slice(0, -1));
|
|
51
|
+
yield `: `;
|
|
52
|
+
yield* generateEventExpression(options, ctx, prop);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
yield `'${(0, shared_1.camelize)(propPrefix + source)}': `;
|
|
56
|
+
yield* generateModelEventExpression(options, ctx, prop);
|
|
57
|
+
}
|
|
58
|
+
yield `})${utils_1.endOfLine}`;
|
|
46
59
|
}
|
|
47
60
|
}
|
|
48
61
|
}
|
|
@@ -70,11 +83,9 @@ function* generateEventExpression(options, ctx, prop) {
|
|
|
70
83
|
if (_isCompoundExpression) {
|
|
71
84
|
yield `(...[$event]) => {${utils_1.newLine}`;
|
|
72
85
|
ctx.addLocalVariable('$event');
|
|
86
|
+
yield* ctx.generateConditionGuards();
|
|
73
87
|
prefix = ``;
|
|
74
88
|
suffix = ``;
|
|
75
|
-
for (const blockCondition of ctx.blockConditions) {
|
|
76
|
-
prefix += `if (!${blockCondition}) return${utils_1.endOfLine}`;
|
|
77
|
-
}
|
|
78
89
|
}
|
|
79
90
|
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', offset => {
|
|
80
91
|
if (_isCompoundExpression && isFirstMapping) {
|
|
@@ -97,7 +108,6 @@ function* generateEventExpression(options, ctx, prop) {
|
|
|
97
108
|
if (_isCompoundExpression) {
|
|
98
109
|
ctx.removeLocalVariable('$event');
|
|
99
110
|
yield utils_1.endOfLine;
|
|
100
|
-
yield* ctx.generateAutoImportCompletion();
|
|
101
111
|
yield `}`;
|
|
102
112
|
}
|
|
103
113
|
}
|
|
@@ -105,6 +115,18 @@ function* generateEventExpression(options, ctx, prop) {
|
|
|
105
115
|
yield `() => {}`;
|
|
106
116
|
}
|
|
107
117
|
}
|
|
118
|
+
function* generateModelEventExpression(options, ctx, prop) {
|
|
119
|
+
if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
120
|
+
yield `(...[$event]) => {${utils_1.newLine}`;
|
|
121
|
+
yield* ctx.generateConditionGuards();
|
|
122
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.verification, prop.exp.content, prop.exp.loc.start.offset, prop.exp.loc);
|
|
123
|
+
yield ` = $event${utils_1.endOfLine}`;
|
|
124
|
+
yield `}`;
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
yield `() => {}`;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
108
130
|
function isCompoundExpression(ts, ast) {
|
|
109
131
|
let result = true;
|
|
110
132
|
if (ast.statements.length === 0) {
|
|
@@ -77,13 +77,13 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
77
77
|
}
|
|
78
78
|
const shouldSpread = propName === 'style' || propName === 'class';
|
|
79
79
|
const shouldCamelize = isComponent && getShouldCamelize(options, prop, propName);
|
|
80
|
-
const codeInfo = getPropsCodeInfo(ctx, strictPropsCheck
|
|
80
|
+
const codeInfo = getPropsCodeInfo(ctx, strictPropsCheck);
|
|
81
81
|
if (shouldSpread) {
|
|
82
82
|
yield `...{ `;
|
|
83
83
|
}
|
|
84
84
|
const codes = [...(0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, ...(prop.arg
|
|
85
85
|
? (0, objectProperty_1.generateObjectProperty)(options, ctx, propName, prop.arg.loc.start.offset, codeInfo, prop.loc.name_2 ??= {}, shouldCamelize)
|
|
86
|
-
: (0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + 'v-model'.length, ctx.codeFeatures.withoutHighlightAndCompletion, propName)), `: `, ...generatePropExp(options, ctx, prop, prop.exp, ctx.codeFeatures.all, enableCodeFeatures))];
|
|
86
|
+
: (0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + 'v-model'.length, ctx.codeFeatures.withoutHighlightAndCompletion, propName)), `: `, ...(0, wrapWith_1.wrapWith)(prop.arg?.loc.start.offset ?? prop.loc.start.offset, prop.arg?.loc.end.offset ?? prop.loc.end.offset, ctx.codeFeatures.verification, ...generatePropExp(options, ctx, prop, prop.exp, ctx.codeFeatures.all, enableCodeFeatures)))];
|
|
87
87
|
if (enableCodeFeatures) {
|
|
88
88
|
yield* codes;
|
|
89
89
|
}
|
|
@@ -120,7 +120,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
120
120
|
}
|
|
121
121
|
const shouldSpread = prop.name === 'style' || prop.name === 'class';
|
|
122
122
|
const shouldCamelize = isComponent && getShouldCamelize(options, prop, prop.name);
|
|
123
|
-
const codeInfo = getPropsCodeInfo(ctx, strictPropsCheck
|
|
123
|
+
const codeInfo = getPropsCodeInfo(ctx, strictPropsCheck);
|
|
124
124
|
if (shouldSpread) {
|
|
125
125
|
yield `...{ `;
|
|
126
126
|
}
|
|
@@ -223,13 +223,9 @@ function getShouldCamelize(options, prop, propName) {
|
|
|
223
223
|
&& (0, shared_2.hyphenateAttr)(propName) === propName
|
|
224
224
|
&& !options.vueCompilerOptions.htmlAttributes.some(pattern => (0, minimatch_1.minimatch)(propName, pattern));
|
|
225
225
|
}
|
|
226
|
-
function getPropsCodeInfo(ctx, strictPropsCheck
|
|
226
|
+
function getPropsCodeInfo(ctx, strictPropsCheck) {
|
|
227
227
|
return ctx.resolveCodeFeatures({
|
|
228
228
|
...codeFeatures_1.codeFeatures.withoutHighlightAndCompletion,
|
|
229
|
-
navigation: {
|
|
230
|
-
resolveRenameNewName: shared_1.camelize,
|
|
231
|
-
resolveRenameEditText: shouldCamelize ? shared_2.hyphenateAttr : undefined,
|
|
232
|
-
},
|
|
233
229
|
verification: strictPropsCheck || {
|
|
234
230
|
shouldReport(_source, code) {
|
|
235
231
|
// https://typescript.tv/errors/#ts2353
|
|
@@ -7,7 +7,6 @@ export interface TemplateCodegenOptions {
|
|
|
7
7
|
compilerOptions: ts.CompilerOptions;
|
|
8
8
|
vueCompilerOptions: VueCompilerOptions;
|
|
9
9
|
template: NonNullable<Sfc['template']>;
|
|
10
|
-
edited: boolean;
|
|
11
10
|
scriptSetupBindingNames: Set<string>;
|
|
12
11
|
scriptSetupImportComponentNames: Set<string>;
|
|
13
12
|
destructuredPropNames: Set<string>;
|
|
@@ -32,10 +32,9 @@ function* generateTemplate(options) {
|
|
|
32
32
|
ctx.dollarVars.add('$el');
|
|
33
33
|
}
|
|
34
34
|
if (options.template.ast) {
|
|
35
|
-
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, options.template.ast
|
|
35
|
+
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, options.template.ast);
|
|
36
36
|
}
|
|
37
37
|
yield* (0, styleScopedClasses_1.generateStyleScopedClassReferences)(ctx);
|
|
38
|
-
yield* ctx.generateAutoImportCompletion();
|
|
39
38
|
yield* ctx.generateHoistVariables();
|
|
40
39
|
const speicalTypes = [
|
|
41
40
|
[slotsPropertyName, yield* generateSlots(options, ctx)],
|
|
@@ -52,8 +51,7 @@ function* generateTemplate(options) {
|
|
|
52
51
|
}
|
|
53
52
|
function* generateSlots(options, ctx) {
|
|
54
53
|
if (!options.hasDefineSlots) {
|
|
55
|
-
|
|
56
|
-
yield `type __VLS_Slots = __VLS_PrettifyGlobal<__VLS_OmitStringIndex<typeof __VLS_ctx.${name}>`;
|
|
54
|
+
yield `type __VLS_Slots = {}`;
|
|
57
55
|
for (const { expVar, propsVar } of ctx.dynamicSlots) {
|
|
58
56
|
yield `${utils_1.newLine}& { [K in NonNullable<typeof ${expVar}>]?: (props: typeof ${propsVar}) => any }`;
|
|
59
57
|
}
|
|
@@ -67,7 +65,7 @@ function* generateSlots(options, ctx) {
|
|
|
67
65
|
}
|
|
68
66
|
yield `?: (props: typeof ${slot.propsVar}) => any }`;
|
|
69
67
|
}
|
|
70
|
-
yield
|
|
68
|
+
yield `${utils_1.endOfLine}`;
|
|
71
69
|
}
|
|
72
70
|
return `__VLS_Slots`;
|
|
73
71
|
}
|
|
@@ -94,12 +92,26 @@ function* generateInheritedAttrs(options, ctx) {
|
|
|
94
92
|
return `import('${options.vueCompilerOptions.lib}').ComponentPublicInstance['$attrs'] & Partial<__VLS_InheritedAttrs>`;
|
|
95
93
|
}
|
|
96
94
|
function* generateTemplateRefs(options, ctx) {
|
|
97
|
-
yield `type __VLS_TemplateRefs = {
|
|
98
|
-
for (const [name,
|
|
99
|
-
yield
|
|
100
|
-
|
|
95
|
+
yield `type __VLS_TemplateRefs = {}`;
|
|
96
|
+
for (const [name, refs] of ctx.templateRefs) {
|
|
97
|
+
yield `${utils_1.newLine}& `;
|
|
98
|
+
if (refs.length >= 2) {
|
|
99
|
+
yield `(`;
|
|
100
|
+
}
|
|
101
|
+
for (let i = 0; i < refs.length; i++) {
|
|
102
|
+
const { typeExp, offset } = refs[i];
|
|
103
|
+
if (i) {
|
|
104
|
+
yield ` | `;
|
|
105
|
+
}
|
|
106
|
+
yield `{ `;
|
|
107
|
+
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, name, offset, ctx.codeFeatures.navigation);
|
|
108
|
+
yield `: ${typeExp} }`;
|
|
109
|
+
}
|
|
110
|
+
if (refs.length >= 2) {
|
|
111
|
+
yield `)`;
|
|
112
|
+
}
|
|
101
113
|
}
|
|
102
|
-
yield
|
|
114
|
+
yield utils_1.endOfLine;
|
|
103
115
|
return `__VLS_TemplateRefs`;
|
|
104
116
|
}
|
|
105
117
|
function* generateRootEl(ctx) {
|
|
@@ -5,4 +5,4 @@ export declare function generateInterpolation(options: {
|
|
|
5
5
|
ts: typeof ts;
|
|
6
6
|
destructuredPropNames: Set<string> | undefined;
|
|
7
7
|
templateRefNames: Set<string> | undefined;
|
|
8
|
-
}, ctx: TemplateCodegenContext, source: string, data: VueCodeInformation | ((offset: number) => VueCodeInformation) | undefined,
|
|
8
|
+
}, ctx: TemplateCodegenContext, source: string, data: VueCodeInformation | ((offset: number) => VueCodeInformation) | undefined, code: string, start: number | undefined, astHolder?: any, prefix?: string, suffix?: string): Generator<Code>;
|
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateInterpolation = generateInterpolation;
|
|
4
4
|
const shared_1 = require("@vue/shared");
|
|
5
|
-
const
|
|
5
|
+
const shared_2 = require("../../utils/shared");
|
|
6
6
|
const utils_1 = require("../utils");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
for (let [section, offset, type] of forEachInterpolationSegment(options.ts, options.destructuredPropNames, options.templateRefNames, ctx, code, start
|
|
7
|
+
// https://github.com/vuejs/core/blob/fb0c3ca519f1fccf52049cd6b8db3a67a669afe9/packages/compiler-core/src/transforms/transformExpression.ts#L47
|
|
8
|
+
const isLiteralWhitelisted = /*@__PURE__*/ (0, shared_1.makeMap)('true,false,null,this');
|
|
9
|
+
function* generateInterpolation(options, ctx, source, data, code, start, astHolder = {}, prefix = '', suffix = '') {
|
|
10
|
+
for (let [section, offset, type] of forEachInterpolationSegment(options.ts, options.destructuredPropNames, options.templateRefNames, ctx, code, start, astHolder, prefix, suffix)) {
|
|
11
11
|
if (offset === undefined) {
|
|
12
12
|
yield section;
|
|
13
13
|
}
|
|
14
14
|
else {
|
|
15
15
|
offset -= prefix.length;
|
|
16
16
|
let addSuffix = '';
|
|
17
|
-
const overLength = offset + section.length -
|
|
17
|
+
const overLength = offset + section.length - code.length;
|
|
18
18
|
if (overLength > 0) {
|
|
19
19
|
addSuffix = section.slice(section.length - overLength);
|
|
20
20
|
section = section.slice(0, -overLength);
|
|
@@ -46,58 +46,46 @@ function* generateInterpolation(options, ctx, source, data, _code, start, astHol
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
;
|
|
49
|
-
function* forEachInterpolationSegment(ts, destructuredPropNames, templateRefNames, ctx,
|
|
49
|
+
function* forEachInterpolationSegment(ts, destructuredPropNames, templateRefNames, ctx, originalCode, start, astHolder, prefix, suffix) {
|
|
50
|
+
const code = prefix + originalCode + suffix;
|
|
51
|
+
const offset = start !== undefined ? start - prefix.length : undefined;
|
|
50
52
|
let ctxVars = [];
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
if (offset !== undefined) {
|
|
70
|
-
ctx.accessExternalVariable(text, offset + (0, scriptSetupRanges_1.getStartEnd)(ts, id, ast).start);
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
ctx.accessExternalVariable(text);
|
|
53
|
+
if (utils_1.identifierRegex.test(originalCode) && !shouldIdentifierSkipped(ctx, originalCode, destructuredPropNames)) {
|
|
54
|
+
ctxVars.push({
|
|
55
|
+
text: originalCode,
|
|
56
|
+
offset: prefix.length,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
const ast = (0, utils_1.createTsAst)(ts, astHolder, code);
|
|
61
|
+
const varCb = (id, isShorthand) => {
|
|
62
|
+
const text = (0, shared_2.getNodeText)(ts, id, ast);
|
|
63
|
+
if (!shouldIdentifierSkipped(ctx, text, destructuredPropNames)) {
|
|
64
|
+
ctxVars.push({
|
|
65
|
+
text,
|
|
66
|
+
offset: (0, shared_2.getStartEnd)(ts, id, ast).start,
|
|
67
|
+
isShorthand,
|
|
68
|
+
});
|
|
74
69
|
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
70
|
+
};
|
|
71
|
+
ts.forEachChild(ast, node => walkIdentifiers(ts, node, ast, varCb, ctx));
|
|
72
|
+
}
|
|
78
73
|
ctxVars = ctxVars.sort((a, b) => a.offset - b.offset);
|
|
79
74
|
if (ctxVars.length) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
yield [': ', undefined];
|
|
83
|
-
}
|
|
84
|
-
else if (ctxVars[0].offset > 0) {
|
|
85
|
-
yield [code.slice(0, ctxVars[0].offset), 0, 'startText'];
|
|
86
|
-
}
|
|
87
|
-
for (let i = 0; i < ctxVars.length - 1; i++) {
|
|
75
|
+
for (let i = 0; i < ctxVars.length; i++) {
|
|
76
|
+
const lastVar = ctxVars[i - 1];
|
|
88
77
|
const curVar = ctxVars[i];
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
yield [code.slice(curVar.offset + curVar.text.length, nextVar.offset + nextVar.text.length), curVar.offset + curVar.text.length];
|
|
78
|
+
const lastVarEnd = lastVar ? lastVar.offset + lastVar.text.length : 0;
|
|
79
|
+
if (curVar.isShorthand) {
|
|
80
|
+
yield [code.slice(lastVarEnd, curVar.offset + curVar.text.length), lastVarEnd];
|
|
93
81
|
yield [': ', undefined];
|
|
94
82
|
}
|
|
95
83
|
else {
|
|
96
|
-
yield [code.slice(
|
|
84
|
+
yield [code.slice(lastVarEnd, curVar.offset), lastVarEnd, i ? undefined : 'startText'];
|
|
97
85
|
}
|
|
86
|
+
yield* generateVar(templateRefNames, ctx, code, offset, curVar);
|
|
98
87
|
}
|
|
99
88
|
const lastVar = ctxVars.at(-1);
|
|
100
|
-
yield* generateVar(code, ctx.dollarVars, destructuredPropNames, templateRefNames, lastVar);
|
|
101
89
|
if (lastVar.offset + lastVar.text.length < code.length) {
|
|
102
90
|
yield [code.slice(lastVar.offset + lastVar.text.length), lastVar.offset + lastVar.text.length, 'endText'];
|
|
103
91
|
}
|
|
@@ -106,11 +94,10 @@ function* forEachInterpolationSegment(ts, destructuredPropNames, templateRefName
|
|
|
106
94
|
yield [code, 0];
|
|
107
95
|
}
|
|
108
96
|
}
|
|
109
|
-
function* generateVar(
|
|
97
|
+
function* generateVar(templateRefNames, ctx, code, offset, curVar) {
|
|
110
98
|
// fix https://github.com/vuejs/language-tools/issues/1205
|
|
111
99
|
// fix https://github.com/vuejs/language-tools/issues/1264
|
|
112
100
|
yield ['', curVar.offset, 'errorMappingOnly'];
|
|
113
|
-
const isDestructuredProp = destructuredPropNames?.has(curVar.text) ?? false;
|
|
114
101
|
const isTemplateRef = templateRefNames?.has(curVar.text) ?? false;
|
|
115
102
|
if (isTemplateRef) {
|
|
116
103
|
yield [`__VLS_unref(`, undefined];
|
|
@@ -118,12 +105,16 @@ function* generateVar(code, dollarVars, destructuredPropNames, templateRefNames,
|
|
|
118
105
|
yield [`)`, undefined];
|
|
119
106
|
}
|
|
120
107
|
else {
|
|
121
|
-
if (
|
|
122
|
-
|
|
108
|
+
if (offset !== undefined) {
|
|
109
|
+
ctx.accessExternalVariable(curVar.text, offset + curVar.offset);
|
|
123
110
|
}
|
|
124
|
-
else
|
|
125
|
-
|
|
111
|
+
else {
|
|
112
|
+
ctx.accessExternalVariable(curVar.text);
|
|
113
|
+
}
|
|
114
|
+
if (ctx.dollarVars.has(curVar.text)) {
|
|
115
|
+
yield [`__VLS_dollars.`, undefined];
|
|
126
116
|
}
|
|
117
|
+
yield [`__VLS_ctx.`, undefined];
|
|
127
118
|
yield [code.slice(curVar.offset, curVar.offset + curVar.text.length), curVar.offset];
|
|
128
119
|
}
|
|
129
120
|
}
|
|
@@ -222,4 +213,13 @@ function walkIdentifiersInTypeReference(ts, node, cb) {
|
|
|
222
213
|
ts.forEachChild(node, node => walkIdentifiersInTypeReference(ts, node, cb));
|
|
223
214
|
}
|
|
224
215
|
}
|
|
216
|
+
function shouldIdentifierSkipped(ctx, text, destructuredPropNames) {
|
|
217
|
+
return ctx.hasLocalVariable(text)
|
|
218
|
+
// https://github.com/vuejs/core/blob/245230e135152900189f13a4281302de45fdcfaa/packages/compiler-core/src/transforms/transformExpression.ts#L342-L352
|
|
219
|
+
|| (0, shared_1.isGloballyAllowed)(text)
|
|
220
|
+
|| isLiteralWhitelisted(text)
|
|
221
|
+
|| text === 'require'
|
|
222
|
+
|| text.startsWith('__VLS_')
|
|
223
|
+
|| destructuredPropNames?.has(text);
|
|
224
|
+
}
|
|
225
225
|
//# sourceMappingURL=interpolation.js.map
|
|
@@ -93,7 +93,6 @@ function* generateSlotOutlet(options, ctx, node) {
|
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
yield* ctx.
|
|
97
|
-
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node);
|
|
96
|
+
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node.children);
|
|
98
97
|
}
|
|
99
98
|
//# sourceMappingURL=slotOutlet.js.map
|