@vue/language-core 3.0.0-alpha.0 → 3.0.0-alpha.4
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 +47 -29
- package/lib/codegen/script/component.js +21 -9
- package/lib/codegen/script/index.js +1 -1
- package/lib/codegen/script/scriptSetup.js +1 -10
- package/lib/codegen/script/src.js +4 -3
- package/lib/codegen/script/styleModulesType.d.ts +4 -0
- package/lib/codegen/script/styleModulesType.js +34 -0
- package/lib/codegen/script/template.js +3 -5
- package/lib/codegen/template/context.d.ts +26 -17
- package/lib/codegen/template/context.js +87 -53
- package/lib/codegen/template/element.d.ts +2 -2
- package/lib/codegen/template/element.js +19 -27
- package/lib/codegen/template/elementChildren.d.ts +1 -1
- package/lib/codegen/template/elementChildren.js +4 -6
- package/lib/codegen/template/elementDirectives.js +1 -3
- package/lib/codegen/template/elementEvents.d.ts +1 -1
- package/lib/codegen/template/elementEvents.js +13 -10
- package/lib/codegen/template/elementProps.js +1 -1
- package/lib/codegen/template/index.js +20 -7
- package/lib/codegen/template/interpolation.d.ts +1 -1
- package/lib/codegen/template/interpolation.js +52 -52
- package/lib/codegen/template/slotOutlet.js +1 -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 +1 -2
- package/lib/codegen/utils/index.js +0 -16
- package/lib/parsers/scriptSetupRanges.js +8 -6
- package/lib/plugins/vue-template-inline-css.js +1 -1
- package/lib/plugins/vue-template-inline-ts.js +2 -2
- package/lib/plugins/vue-tsx.d.ts +25 -16
- package/lib/plugins/vue-tsx.js +31 -19
- package/lib/types.d.ts +2 -1
- package/lib/utils/forEachElementNode.d.ts +1 -0
- package/lib/utils/forEachElementNode.js +3 -0
- package/lib/utils/ts.js +1 -0
- package/package.json +2 -2
|
@@ -19,7 +19,7 @@ const propertyAccess_1 = require("./propertyAccess");
|
|
|
19
19
|
const styleScopedClasses_1 = require("./styleScopedClasses");
|
|
20
20
|
const vSlot_1 = require("./vSlot");
|
|
21
21
|
const colonReg = /:/g;
|
|
22
|
-
function* generateComponent(options, ctx, node
|
|
22
|
+
function* generateComponent(options, ctx, node) {
|
|
23
23
|
const tagOffsets = [node.loc.start.offset + options.template.content.slice(node.loc.start.offset).indexOf(node.tag)];
|
|
24
24
|
if (!node.isSelfClosing && options.template.lang === 'html') {
|
|
25
25
|
const endTagOffset = node.loc.start.offset + node.loc.source.lastIndexOf(node.tag);
|
|
@@ -35,9 +35,11 @@ function* generateComponent(options, ctx, node, isVForChild) {
|
|
|
35
35
|
const componentVNodeVar = ctx.getInternalVariable();
|
|
36
36
|
const componentCtxVar = ctx.getInternalVariable();
|
|
37
37
|
const isComponentTag = node.tag.toLowerCase() === 'component';
|
|
38
|
+
ctx.currentComponent?.childTypes.push(`typeof ${componentVNodeVar}`);
|
|
38
39
|
ctx.currentComponent = {
|
|
39
40
|
ctxVar: componentCtxVar,
|
|
40
|
-
|
|
41
|
+
childTypes: [],
|
|
42
|
+
used: false,
|
|
41
43
|
};
|
|
42
44
|
let props = node.props;
|
|
43
45
|
let dynamicTagInfo;
|
|
@@ -159,7 +161,7 @@ function* generateComponent(options, ctx, node, isVForChild) {
|
|
|
159
161
|
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), `}`);
|
|
160
162
|
yield `, ...__VLS_functionalComponentArgsRest(${componentFunctionalVar}))${utils_1.endOfLine}`;
|
|
161
163
|
yield* generateFailedPropExps(options, ctx, failedPropExps);
|
|
162
|
-
yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, componentFunctionalVar, componentVNodeVar, componentCtxVar);
|
|
164
|
+
yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, componentOriginalVar, componentFunctionalVar, componentVNodeVar, componentCtxVar);
|
|
163
165
|
yield* (0, elementDirectives_1.generateElementDirectives)(options, ctx, node);
|
|
164
166
|
const [refName, offset] = yield* generateElementReference(options, ctx, node);
|
|
165
167
|
const tag = (0, shared_2.hyphenateTag)(node.tag);
|
|
@@ -168,15 +170,12 @@ function* generateComponent(options, ctx, node, isVForChild) {
|
|
|
168
170
|
const componentInstanceVar = ctx.getInternalVariable();
|
|
169
171
|
ctx.currentComponent.used = true;
|
|
170
172
|
yield `var ${componentInstanceVar} = {} as (Parameters<NonNullable<typeof ${componentCtxVar}['expose']>>[0] | null)`;
|
|
171
|
-
if (
|
|
173
|
+
if (ctx.inVFor) {
|
|
172
174
|
yield `[]`;
|
|
173
175
|
}
|
|
174
176
|
yield `${utils_1.endOfLine}`;
|
|
175
177
|
if (refName && offset) {
|
|
176
|
-
ctx.
|
|
177
|
-
typeExp: `typeof ${ctx.getHoistVariable(componentInstanceVar)}`,
|
|
178
|
-
offset
|
|
179
|
-
});
|
|
178
|
+
ctx.addTemplateRef(refName, `typeof ${ctx.getHoistVariable(componentInstanceVar)}`, offset);
|
|
180
179
|
}
|
|
181
180
|
if (isRootNode) {
|
|
182
181
|
ctx.singleRootElTypes.push(`NonNullable<typeof ${componentInstanceVar}>['$el']`);
|
|
@@ -189,24 +188,18 @@ function* generateComponent(options, ctx, node, isVForChild) {
|
|
|
189
188
|
}
|
|
190
189
|
(0, styleScopedClasses_1.collectStyleScopedClassReferences)(options, ctx, node);
|
|
191
190
|
const slotDir = node.props.find(p => p.type === CompilerDOM.NodeTypes.DIRECTIVE && p.name === 'slot');
|
|
192
|
-
|
|
193
|
-
yield* (0, vSlot_1.generateVSlot)(options, ctx, node, slotDir);
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
// #932: reference for default slot
|
|
197
|
-
yield* (0, vSlot_1.generateImplicitDefaultSlot)(ctx, node);
|
|
198
|
-
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node);
|
|
199
|
-
}
|
|
191
|
+
yield* (0, vSlot_1.generateVSlot)(options, ctx, node, slotDir);
|
|
200
192
|
if (ctx.currentComponent.used) {
|
|
201
|
-
yield `var ${componentCtxVar}!:
|
|
193
|
+
yield `var ${componentCtxVar}!: __VLS_FunctionalComponentCtx<typeof ${componentOriginalVar}, typeof ${componentVNodeVar}>${utils_1.endOfLine}`;
|
|
202
194
|
}
|
|
203
195
|
}
|
|
204
|
-
function* generateElement(options, ctx, node
|
|
196
|
+
function* generateElement(options, ctx, node) {
|
|
205
197
|
const startTagOffset = node.loc.start.offset + options.template.content.slice(node.loc.start.offset).indexOf(node.tag);
|
|
206
198
|
const endTagOffset = !node.isSelfClosing && options.template.lang === 'html'
|
|
207
199
|
? node.loc.start.offset + node.loc.source.lastIndexOf(node.tag)
|
|
208
200
|
: undefined;
|
|
209
201
|
const failedPropExps = [];
|
|
202
|
+
ctx.currentComponent?.childTypes.push(`__VLS_NativeElements['${node.tag}']`);
|
|
210
203
|
yield `__VLS_asFunctionalElement(__VLS_elements`;
|
|
211
204
|
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, startTagOffset, ctx.codeFeatures.withoutHighlightAndCompletion);
|
|
212
205
|
if (endTagOffset !== undefined) {
|
|
@@ -221,13 +214,10 @@ function* generateElement(options, ctx, node, isVForChild) {
|
|
|
221
214
|
const [refName, offset] = yield* generateElementReference(options, ctx, node);
|
|
222
215
|
if (refName && offset) {
|
|
223
216
|
let typeExp = `__VLS_NativeElements['${node.tag}']`;
|
|
224
|
-
if (
|
|
217
|
+
if (ctx.inVFor) {
|
|
225
218
|
typeExp += `[]`;
|
|
226
219
|
}
|
|
227
|
-
ctx.
|
|
228
|
-
typeExp,
|
|
229
|
-
offset
|
|
230
|
-
});
|
|
220
|
+
ctx.addTemplateRef(refName, typeExp, offset);
|
|
231
221
|
}
|
|
232
222
|
if (ctx.singleRootNodes.has(node)) {
|
|
233
223
|
ctx.singleRootElTypes.push(`__VLS_NativeElements['${node.tag}']`);
|
|
@@ -236,7 +226,10 @@ function* generateElement(options, ctx, node, isVForChild) {
|
|
|
236
226
|
ctx.inheritedAttrVars.add(`__VLS_elements.${node.tag}`);
|
|
237
227
|
}
|
|
238
228
|
(0, styleScopedClasses_1.collectStyleScopedClassReferences)(options, ctx, node);
|
|
239
|
-
|
|
229
|
+
const { currentComponent } = ctx;
|
|
230
|
+
ctx.currentComponent = undefined;
|
|
231
|
+
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node.children);
|
|
232
|
+
ctx.currentComponent = currentComponent;
|
|
240
233
|
}
|
|
241
234
|
function* generateFailedPropExps(options, ctx, failedPropExps) {
|
|
242
235
|
for (const failedExp of failedPropExps) {
|
|
@@ -271,8 +264,8 @@ function* generateCanonicalComponentName(tagText, offset, features) {
|
|
|
271
264
|
}
|
|
272
265
|
}
|
|
273
266
|
function* generateComponentGeneric(ctx) {
|
|
274
|
-
if (ctx.
|
|
275
|
-
const { content, offset } = ctx.
|
|
267
|
+
if (ctx.currentInfo.generic) {
|
|
268
|
+
const { content, offset } = ctx.currentInfo.generic;
|
|
276
269
|
yield* (0, wrapWith_1.wrapWith)(offset, offset + content.length, ctx.codeFeatures.verification, `<`, [
|
|
277
270
|
content,
|
|
278
271
|
'template',
|
|
@@ -280,7 +273,6 @@ function* generateComponentGeneric(ctx) {
|
|
|
280
273
|
ctx.codeFeatures.all
|
|
281
274
|
], `>`);
|
|
282
275
|
}
|
|
283
|
-
ctx.lastGenericComment = undefined;
|
|
284
276
|
}
|
|
285
277
|
function* generateElementReference(options, ctx, node) {
|
|
286
278
|
for (const prop of node.props) {
|
|
@@ -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
|
}
|
|
@@ -39,9 +39,7 @@ function* generateElementDirectives(options, ctx, node) {
|
|
|
39
39
|
function* generateIdentifier(options, ctx, prop) {
|
|
40
40
|
const rawName = 'v-' + prop.name;
|
|
41
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({
|
|
42
|
-
...codeFeatures_1.codeFeatures.
|
|
43
|
-
// fix https://github.com/vuejs/language-tools/issues/1905
|
|
44
|
-
...codeFeatures_1.codeFeatures.additionalCompletion,
|
|
42
|
+
...codeFeatures_1.codeFeatures.withoutHighlightAndCompletion,
|
|
45
43
|
verification: options.vueCompilerOptions.checkUnknownDirectives && !builtInDirectives.has(prop.name),
|
|
46
44
|
})));
|
|
47
45
|
}
|
|
@@ -3,7 +3,7 @@ import type * as ts from 'typescript';
|
|
|
3
3
|
import type { Code } 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>;
|
|
6
|
+
export declare function generateElementEvents(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, componentOriginalVar: string, 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
9
|
export declare function generateModelEventExpression(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode): Generator<Code>;
|
|
@@ -11,9 +11,9 @@ const utils_1 = require("../utils");
|
|
|
11
11
|
const camelized_1 = require("../utils/camelized");
|
|
12
12
|
const wrapWith_1 = require("../utils/wrapWith");
|
|
13
13
|
const interpolation_1 = require("./interpolation");
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
let
|
|
14
|
+
const objectProperty_1 = require("./objectProperty");
|
|
15
|
+
function* generateElementEvents(options, ctx, node, componentOriginalVar, componentFunctionalVar, componentVNodeVar, componentCtxVar) {
|
|
16
|
+
let emitsVar;
|
|
17
17
|
let propsVar;
|
|
18
18
|
for (const prop of node.props) {
|
|
19
19
|
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
@@ -23,12 +23,10 @@ function* generateElementEvents(options, ctx, node, componentFunctionalVar, comp
|
|
|
23
23
|
&& prop.name === 'model'
|
|
24
24
|
&& (!prop.arg || prop.arg.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic))) {
|
|
25
25
|
ctx.currentComponent.used = true;
|
|
26
|
-
if (!
|
|
27
|
-
|
|
28
|
-
eventsVar = ctx.getInternalVariable();
|
|
26
|
+
if (!emitsVar) {
|
|
27
|
+
emitsVar = ctx.getInternalVariable();
|
|
29
28
|
propsVar = ctx.getInternalVariable();
|
|
30
|
-
yield `let ${
|
|
31
|
-
yield `let ${eventsVar}!: __VLS_NormalizeEmits<typeof ${emitVar}>${utils_1.endOfLine}`;
|
|
29
|
+
yield `let ${emitsVar}!: __VLS_ResolveEmits<typeof ${componentOriginalVar}, typeof ${componentCtxVar}.emit>${utils_1.endOfLine}`;
|
|
32
30
|
yield `let ${propsVar}!: __VLS_FunctionalComponentProps<typeof ${componentFunctionalVar}, typeof ${componentVNodeVar}>${utils_1.endOfLine}`;
|
|
33
31
|
}
|
|
34
32
|
let source = prop.arg?.loc.source ?? 'model-value';
|
|
@@ -45,7 +43,13 @@ function* generateElementEvents(options, ctx, node, componentFunctionalVar, comp
|
|
|
45
43
|
propPrefix = 'onVnode-';
|
|
46
44
|
emitPrefix = 'vnode-';
|
|
47
45
|
}
|
|
48
|
-
yield `(): __VLS_NormalizeComponentEvent<typeof ${propsVar}, typeof ${
|
|
46
|
+
yield `(): __VLS_NormalizeComponentEvent<typeof ${propsVar}, typeof ${emitsVar}, '${(0, shared_1.camelize)(propPrefix + source)}', '${emitPrefix + source}', '${(0, shared_1.camelize)(emitPrefix + source)}'> => (${utils_1.newLine}`;
|
|
47
|
+
if (prop.name === 'on') {
|
|
48
|
+
yield `{ `;
|
|
49
|
+
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, emitPrefix + source, start, ctx.codeFeatures.navigation, undefined, true);
|
|
50
|
+
yield `: {} as any } as typeof ${emitsVar},${utils_1.newLine}`;
|
|
51
|
+
}
|
|
52
|
+
yield `{ `;
|
|
49
53
|
if (prop.name === 'on') {
|
|
50
54
|
yield* generateEventArg(ctx, source, start, propPrefix.slice(0, -1));
|
|
51
55
|
yield `: `;
|
|
@@ -108,7 +112,6 @@ function* generateEventExpression(options, ctx, prop) {
|
|
|
108
112
|
if (_isCompoundExpression) {
|
|
109
113
|
ctx.removeLocalVariable('$event');
|
|
110
114
|
yield utils_1.endOfLine;
|
|
111
|
-
yield* ctx.generateAutoImportCompletion();
|
|
112
115
|
yield `}`;
|
|
113
116
|
}
|
|
114
117
|
}
|
|
@@ -83,7 +83,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
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
|
}
|
|
@@ -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)],
|
|
@@ -93,12 +92,26 @@ function* generateInheritedAttrs(options, ctx) {
|
|
|
93
92
|
return `import('${options.vueCompilerOptions.lib}').ComponentPublicInstance['$attrs'] & Partial<__VLS_InheritedAttrs>`;
|
|
94
93
|
}
|
|
95
94
|
function* generateTemplateRefs(options, ctx) {
|
|
96
|
-
yield `type __VLS_TemplateRefs = {
|
|
97
|
-
for (const [name,
|
|
98
|
-
yield
|
|
99
|
-
|
|
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
|
+
}
|
|
100
113
|
}
|
|
101
|
-
yield
|
|
114
|
+
yield utils_1.endOfLine;
|
|
102
115
|
return `__VLS_TemplateRefs`;
|
|
103
116
|
}
|
|
104
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>;
|
|
@@ -4,17 +4,17 @@ exports.generateInterpolation = generateInterpolation;
|
|
|
4
4
|
const shared_1 = require("@vue/shared");
|
|
5
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, shared_2.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
|
|
@@ -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,
|
|
5
|
+
export declare function generateTemplateChild(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode, enterNode?: 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];
|
|
@@ -7,12 +7,12 @@ const CompilerDOM = require("@vue/compiler-dom");
|
|
|
7
7
|
const shared_1 = require("../../utils/shared");
|
|
8
8
|
const utils_1 = require("../utils");
|
|
9
9
|
const element_1 = require("./element");
|
|
10
|
+
const elementChildren_1 = require("./elementChildren");
|
|
10
11
|
const interpolation_1 = require("./interpolation");
|
|
11
12
|
const slotOutlet_1 = require("./slotOutlet");
|
|
12
13
|
const vFor_1 = require("./vFor");
|
|
13
14
|
const vIf_1 = require("./vIf");
|
|
14
15
|
const vSlot_1 = require("./vSlot");
|
|
15
|
-
const commentDirectiveRegex = /^<!--\s*@vue-(?<name>[-\w]+)\b(?<content>[\s\S]*)-->$/;
|
|
16
16
|
// @ts-ignore
|
|
17
17
|
const transformContext = {
|
|
18
18
|
onError: () => { },
|
|
@@ -28,36 +28,9 @@ const transformContext = {
|
|
|
28
28
|
},
|
|
29
29
|
expressionPlugins: ['typescript'],
|
|
30
30
|
};
|
|
31
|
-
function* generateTemplateChild(options, ctx, node,
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
if (match) {
|
|
35
|
-
const { name, content } = match.groups;
|
|
36
|
-
switch (name) {
|
|
37
|
-
case 'skip': {
|
|
38
|
-
yield `// @vue-skip${utils_1.newLine}`;
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
case 'ignore': {
|
|
42
|
-
yield* ctx.ignoreError();
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
|
-
case 'expect-error': {
|
|
46
|
-
yield* ctx.expectError(prevNode);
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
case 'generic': {
|
|
50
|
-
const text = content.trim();
|
|
51
|
-
if (text.startsWith('{') && text.endsWith('}')) {
|
|
52
|
-
ctx.lastGenericComment = {
|
|
53
|
-
content: text.slice(1, -1),
|
|
54
|
-
offset: prevNode.loc.start.offset + prevNode.loc.source.indexOf('{') + 1,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
31
|
+
function* generateTemplateChild(options, ctx, node, enterNode = true) {
|
|
32
|
+
if (enterNode && !ctx.enter(node)) {
|
|
33
|
+
return;
|
|
61
34
|
}
|
|
62
35
|
const cur = node;
|
|
63
36
|
if (cur.codegenNode?.type === CompilerDOM.NodeTypes.JS_CACHE_EXPRESSION) {
|
|
@@ -67,12 +40,7 @@ function* generateTemplateChild(options, ctx, node, prevNode, isVForChild = fals
|
|
|
67
40
|
for (const item of collectSingleRootNodes(options, node.children)) {
|
|
68
41
|
ctx.singleRootNodes.add(item);
|
|
69
42
|
}
|
|
70
|
-
|
|
71
|
-
for (const childNode of node.children) {
|
|
72
|
-
yield* generateTemplateChild(options, ctx, childNode, prev);
|
|
73
|
-
prev = childNode;
|
|
74
|
-
}
|
|
75
|
-
yield* ctx.resetDirectiveComments('end of root');
|
|
43
|
+
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node.children);
|
|
76
44
|
}
|
|
77
45
|
else if (node.type === CompilerDOM.NodeTypes.ELEMENT) {
|
|
78
46
|
const vForNode = getVForNode(node);
|
|
@@ -95,32 +63,27 @@ function* generateTemplateChild(options, ctx, node, prevNode, isVForChild = fals
|
|
|
95
63
|
}
|
|
96
64
|
else if (node.tagType === CompilerDOM.ElementTypes.ELEMENT
|
|
97
65
|
|| node.tagType === CompilerDOM.ElementTypes.TEMPLATE) {
|
|
98
|
-
yield* (0, element_1.generateElement)(options, ctx, node
|
|
66
|
+
yield* (0, element_1.generateElement)(options, ctx, node);
|
|
99
67
|
}
|
|
100
68
|
else {
|
|
101
69
|
const { currentComponent } = ctx;
|
|
102
|
-
yield* (0, element_1.generateComponent)(options, ctx, node
|
|
70
|
+
yield* (0, element_1.generateComponent)(options, ctx, node);
|
|
103
71
|
ctx.currentComponent = currentComponent;
|
|
104
72
|
}
|
|
105
73
|
}
|
|
106
74
|
}
|
|
107
75
|
else if (node.type === CompilerDOM.NodeTypes.TEXT_CALL) {
|
|
108
76
|
// {{ var }}
|
|
109
|
-
yield* generateTemplateChild(options, ctx, node.content,
|
|
77
|
+
yield* generateTemplateChild(options, ctx, node.content, false);
|
|
110
78
|
}
|
|
111
79
|
else if (node.type === CompilerDOM.NodeTypes.COMPOUND_EXPRESSION) {
|
|
112
80
|
// {{ ... }} {{ ... }}
|
|
113
|
-
|
|
114
|
-
if (typeof childNode === 'object') {
|
|
115
|
-
yield* generateTemplateChild(options, ctx, childNode, undefined);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
81
|
+
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node.children.filter(child => typeof child === 'object'), false);
|
|
118
82
|
}
|
|
119
83
|
else if (node.type === CompilerDOM.NodeTypes.INTERPOLATION) {
|
|
120
84
|
// {{ ... }}
|
|
121
85
|
const [content, start] = parseInterpolationNode(node, options.template.content);
|
|
122
86
|
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, content, start, node.content.loc, `(`, `)${utils_1.endOfLine}`);
|
|
123
|
-
yield* ctx.resetDirectiveComments('end of INTERPOLATION');
|
|
124
87
|
}
|
|
125
88
|
else if (node.type === CompilerDOM.NodeTypes.IF) {
|
|
126
89
|
// v-if / v-else-if / v-else
|
|
@@ -133,6 +96,9 @@ function* generateTemplateChild(options, ctx, node, prevNode, isVForChild = fals
|
|
|
133
96
|
else if (node.type === CompilerDOM.NodeTypes.TEXT) {
|
|
134
97
|
// not needed progress
|
|
135
98
|
}
|
|
99
|
+
if (enterNode) {
|
|
100
|
+
yield* ctx.exit();
|
|
101
|
+
}
|
|
136
102
|
}
|
|
137
103
|
function* collectSingleRootNodes(options, children) {
|
|
138
104
|
if (children.length !== 1) {
|
|
@@ -4,8 +4,8 @@ exports.generateVFor = generateVFor;
|
|
|
4
4
|
exports.parseVForNode = parseVForNode;
|
|
5
5
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
6
6
|
const utils_1 = require("../utils");
|
|
7
|
+
const elementChildren_1 = require("./elementChildren");
|
|
7
8
|
const interpolation_1 = require("./interpolation");
|
|
8
|
-
const templateChild_1 = require("./templateChild");
|
|
9
9
|
function* generateVFor(options, ctx, node) {
|
|
10
10
|
const { source } = node.parseResult;
|
|
11
11
|
const { leftExpressionRange, leftExpressionText } = parseVForNode(node);
|
|
@@ -52,18 +52,13 @@ function* generateVFor(options, ctx, node) {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
for (const childNode of node.children) {
|
|
60
|
-
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, prev, true);
|
|
61
|
-
prev = childNode;
|
|
62
|
-
}
|
|
55
|
+
const { inVFor } = ctx;
|
|
56
|
+
ctx.inVFor = true;
|
|
57
|
+
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node.children, isFragment);
|
|
58
|
+
ctx.inVFor = inVFor;
|
|
63
59
|
for (const varName of forBlockVars) {
|
|
64
60
|
ctx.removeLocalVariable(varName);
|
|
65
61
|
}
|
|
66
|
-
yield* ctx.generateAutoImportCompletion();
|
|
67
62
|
yield `}${utils_1.newLine}`;
|
|
68
63
|
}
|
|
69
64
|
function parseVForNode(node) {
|
|
@@ -4,8 +4,8 @@ exports.generateVIf = generateVIf;
|
|
|
4
4
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
5
5
|
const muggle_string_1 = require("muggle-string");
|
|
6
6
|
const utils_1 = require("../utils");
|
|
7
|
+
const elementChildren_1 = require("./elementChildren");
|
|
7
8
|
const interpolation_1 = require("./interpolation");
|
|
8
|
-
const templateChild_1 = require("./templateChild");
|
|
9
9
|
function* generateVIf(options, ctx, node) {
|
|
10
10
|
const originalBlockConditionsLength = ctx.blockConditions.length;
|
|
11
11
|
for (let i = 0; i < node.branches.length; i++) {
|
|
@@ -28,15 +28,7 @@ function* generateVIf(options, ctx, node) {
|
|
|
28
28
|
yield ` `;
|
|
29
29
|
}
|
|
30
30
|
yield `{${utils_1.newLine}`;
|
|
31
|
-
|
|
32
|
-
yield* ctx.resetDirectiveComments('end of v-if start');
|
|
33
|
-
}
|
|
34
|
-
let prev;
|
|
35
|
-
for (const childNode of branch.children) {
|
|
36
|
-
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, prev);
|
|
37
|
-
prev = childNode;
|
|
38
|
-
}
|
|
39
|
-
yield* ctx.generateAutoImportCompletion();
|
|
31
|
+
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, branch.children, isFragment(node));
|
|
40
32
|
yield `}${utils_1.newLine}`;
|
|
41
33
|
if (addedBlockCondition) {
|
|
42
34
|
ctx.blockConditions[ctx.blockConditions.length - 1] = `!${ctx.blockConditions[ctx.blockConditions.length - 1]}`;
|