@vue/language-core 3.1.6 → 3.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/codegen/globalTypes.js +1 -1
- package/lib/codegen/names.d.ts +0 -1
- package/lib/codegen/names.js +1 -2
- package/lib/codegen/script/component.js +1 -14
- package/lib/codegen/script/index.js +59 -53
- package/lib/codegen/script/scriptSetup.js +2 -2
- package/lib/codegen/script/src.d.ts +1 -0
- package/lib/codegen/script/src.js +17 -12
- package/lib/codegen/script/template.d.ts +1 -1
- package/lib/codegen/script/template.js +9 -24
- package/lib/codegen/style/classProperty.d.ts +2 -0
- package/lib/codegen/style/classProperty.js +18 -0
- package/lib/codegen/style/imports.d.ts +2 -0
- package/lib/codegen/style/imports.js +27 -0
- package/lib/codegen/style/index.d.ts +1 -4
- package/lib/codegen/template/context.d.ts +1 -4
- package/lib/codegen/template/context.js +2 -1
- package/lib/codegen/template/element.js +105 -157
- package/lib/codegen/template/elementChildren.d.ts +5 -0
- package/lib/codegen/template/elementChildren.js +12 -0
- package/lib/codegen/template/elementEvents.d.ts +1 -1
- package/lib/codegen/template/elementEvents.js +3 -3
- package/lib/codegen/template/index.d.ts +2 -5
- package/lib/codegen/template/templateChild.js +11 -15
- package/lib/codegen/template/vSlot.d.ts +1 -1
- package/lib/codegen/template/vSlot.js +14 -20
- package/lib/codegen/utils/index.d.ts +2 -2
- package/lib/codegen/utils/index.js +15 -11
- package/lib/codegen/utils/wrapWith.d.ts +2 -0
- package/lib/codegen/utils/wrapWith.js +15 -0
- package/lib/languagePlugin.js +3 -4
- package/lib/parsers/scriptRanges.d.ts +6 -8
- package/lib/parsers/scriptRanges.js +5 -2
- package/lib/parsers/scriptSetupRanges.d.ts +2 -6
- package/lib/parsers/scriptSetupRanges.js +3 -2
- package/lib/parsers/utils.d.ts +4 -6
- package/lib/parsers/utils.js +25 -27
- package/lib/plugins/vue-script-js.js +1 -1
- package/lib/plugins/vue-tsx.d.ts +7 -17
- package/lib/plugins/vue-tsx.js +7 -18
- package/lib/virtualFile/computedEmbeddedCodes.d.ts +4 -0
- package/lib/virtualFile/computedEmbeddedCodes.js +262 -0
- package/lib/virtualFile/computedSfc.d.ts +6 -0
- package/lib/virtualFile/computedSfc.js +340 -0
- package/lib/virtualFile/computedVueSfc.d.ts +4 -0
- package/lib/virtualFile/computedVueSfc.js +41 -0
- package/lib/virtualFile/embeddedFile.d.ts +11 -0
- package/lib/virtualFile/embeddedFile.js +14 -0
- package/lib/virtualFile/vueFile.d.ts +24 -0
- package/lib/virtualFile/vueFile.js +49 -0
- package/package.json +2 -2
|
@@ -12,6 +12,7 @@ const names = require("../names");
|
|
|
12
12
|
const utils_1 = require("../utils");
|
|
13
13
|
const boundary_1 = require("../utils/boundary");
|
|
14
14
|
const camelized_1 = require("../utils/camelized");
|
|
15
|
+
const stringLiteralKey_1 = require("../utils/stringLiteralKey");
|
|
15
16
|
const elementDirectives_1 = require("./elementDirectives");
|
|
16
17
|
const elementEvents_1 = require("./elementEvents");
|
|
17
18
|
const elementProps_1 = require("./elementProps");
|
|
@@ -20,33 +21,14 @@ const propertyAccess_1 = require("./propertyAccess");
|
|
|
20
21
|
const styleScopedClasses_1 = require("./styleScopedClasses");
|
|
21
22
|
const templateChild_1 = require("./templateChild");
|
|
22
23
|
const vSlot_1 = require("./vSlot");
|
|
23
|
-
const colonReg = /:/g;
|
|
24
24
|
function* generateComponent(options, ctx, node) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const componentCtxVar = ctx.getInternalVariable();
|
|
33
|
-
const componentPropsVar = ctx.getInternalVariable();
|
|
34
|
-
const isComponentTag = node.tag.toLowerCase() === 'component';
|
|
35
|
-
let isCtxVarUsed = false;
|
|
36
|
-
let isPropsVarUsed = false;
|
|
37
|
-
ctx.currentComponent = {
|
|
38
|
-
get ctxVar() {
|
|
39
|
-
isCtxVarUsed = true;
|
|
40
|
-
return componentCtxVar;
|
|
41
|
-
},
|
|
42
|
-
get propsVar() {
|
|
43
|
-
isPropsVarUsed = true;
|
|
44
|
-
return componentPropsVar;
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
let props = node.props;
|
|
48
|
-
let dynamicTagInfo;
|
|
49
|
-
if (isComponentTag) {
|
|
25
|
+
let { tag, props } = node;
|
|
26
|
+
let [startTagOffset, endTagOffset] = (0, shared_2.getElementTagOffsets)(node, options.template);
|
|
27
|
+
let isExpression = false;
|
|
28
|
+
if (tag.includes('.')) {
|
|
29
|
+
isExpression = true;
|
|
30
|
+
}
|
|
31
|
+
else if (tag === 'component') {
|
|
50
32
|
for (const prop of node.props) {
|
|
51
33
|
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
52
34
|
&& prop.name === 'bind'
|
|
@@ -55,122 +37,123 @@ function* generateComponent(options, ctx, node) {
|
|
|
55
37
|
if (prop.arg.loc.end.offset === prop.exp.loc.end.offset) {
|
|
56
38
|
ctx.inlayHints.push((0, inlayHints_1.createVBindShorthandInlayHintInfo)(prop.exp.loc, 'is'));
|
|
57
39
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
40
|
+
isExpression = true;
|
|
41
|
+
tag = prop.exp.content;
|
|
42
|
+
startTagOffset = prop.exp.loc.start.offset;
|
|
43
|
+
endTagOffset = undefined;
|
|
62
44
|
props = props.filter(p => p !== prop);
|
|
63
45
|
break;
|
|
64
46
|
}
|
|
65
47
|
}
|
|
66
48
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (matchConst) {
|
|
75
|
-
// navigation support
|
|
76
|
-
yield `/** @type {[`;
|
|
77
|
-
for (const tagOffset of tagOffsets) {
|
|
78
|
-
yield `typeof `;
|
|
79
|
-
if (componentOriginalVar === node.tag) {
|
|
80
|
-
yield [
|
|
81
|
-
componentOriginalVar,
|
|
82
|
-
'template',
|
|
83
|
-
tagOffset,
|
|
84
|
-
codeFeatures_1.codeFeatures.withoutHighlightAndCompletion,
|
|
85
|
-
];
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
const shouldCapitalize = matchConst[0].toUpperCase() === matchConst[0];
|
|
89
|
-
yield* (0, camelized_1.generateCamelized)(shouldCapitalize ? (0, shared_1.capitalize)(node.tag) : node.tag, 'template', tagOffset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
|
|
90
|
-
}
|
|
91
|
-
yield `, `;
|
|
92
|
-
}
|
|
93
|
-
yield `]} */${utils_1.endOfLine}`;
|
|
94
|
-
// auto import support
|
|
95
|
-
yield `// @ts-ignore${utils_1.newLine}`; // #2304
|
|
96
|
-
yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(node.tag), 'template', tagOffsets[0], codeFeatures_1.codeFeatures.importCompletionOnly);
|
|
97
|
-
yield utils_1.endOfLine;
|
|
98
|
-
}
|
|
99
|
-
else if (dynamicTagInfo) {
|
|
100
|
-
yield `const ${componentOriginalVar} = (`;
|
|
101
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, dynamicTagInfo.tag, dynamicTagInfo.offsets[0], `(`, `)`);
|
|
102
|
-
if (dynamicTagInfo.offsets[1] !== undefined) {
|
|
103
|
-
yield `,`;
|
|
104
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.withoutCompletion, dynamicTagInfo.tag, dynamicTagInfo.offsets[1], `(`, `)`);
|
|
49
|
+
const componentVar = ctx.getInternalVariable();
|
|
50
|
+
if (isExpression) {
|
|
51
|
+
yield `const ${componentVar} = `;
|
|
52
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, tag, startTagOffset, `(`, `)`);
|
|
53
|
+
if (endTagOffset !== undefined) {
|
|
54
|
+
yield ` || `;
|
|
55
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.withoutCompletion, tag, endTagOffset, `(`, `)`);
|
|
105
56
|
}
|
|
106
|
-
yield
|
|
57
|
+
yield `${utils_1.endOfLine}`;
|
|
107
58
|
}
|
|
108
59
|
else {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
60
|
+
const originalNames = new Set([
|
|
61
|
+
(0, shared_1.capitalize)((0, shared_1.camelize)(tag)),
|
|
62
|
+
(0, shared_1.camelize)(tag),
|
|
63
|
+
tag,
|
|
64
|
+
]);
|
|
65
|
+
const matchedSetupConst = [...originalNames].find(name => options.setupConsts.has(name));
|
|
66
|
+
if (matchedSetupConst) {
|
|
67
|
+
// navigation & auto import support
|
|
68
|
+
yield `const ${componentVar} = `;
|
|
69
|
+
yield* (0, camelized_1.generateCamelized)(matchedSetupConst[0] + tag.slice(1), 'template', startTagOffset, {
|
|
70
|
+
...codeFeatures_1.codeFeatures.withoutHighlightAndCompletion,
|
|
71
|
+
...codeFeatures_1.codeFeatures.importCompletionOnly,
|
|
72
|
+
});
|
|
73
|
+
if (endTagOffset !== undefined) {
|
|
74
|
+
yield ` || `;
|
|
75
|
+
yield* (0, camelized_1.generateCamelized)(matchedSetupConst[0] + tag.slice(1), 'template', endTagOffset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
|
|
76
|
+
}
|
|
77
|
+
yield utils_1.endOfLine;
|
|
112
78
|
}
|
|
113
79
|
else {
|
|
114
|
-
yield `
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
yield
|
|
135
|
-
yield
|
|
80
|
+
yield `let ${componentVar}!: __VLS_WithComponent<'${tag}', __VLS_LocalComponents`;
|
|
81
|
+
yield originalNames.has(options.selfComponentName)
|
|
82
|
+
? `, typeof ${names._export}`
|
|
83
|
+
: `, void`;
|
|
84
|
+
for (const name of originalNames) {
|
|
85
|
+
yield `, '${name}'`;
|
|
86
|
+
}
|
|
87
|
+
yield `>[`;
|
|
88
|
+
yield* (0, stringLiteralKey_1.generateStringLiteralKey)(tag, startTagOffset, {
|
|
89
|
+
...codeFeatures_1.codeFeatures.semanticWithoutHighlight,
|
|
90
|
+
...options.vueCompilerOptions.checkUnknownComponents
|
|
91
|
+
? codeFeatures_1.codeFeatures.verification
|
|
92
|
+
: codeFeatures_1.codeFeatures.doNotReportTs2339AndTs2551,
|
|
93
|
+
});
|
|
94
|
+
yield `]${utils_1.endOfLine}`;
|
|
95
|
+
if (utils_1.identifierRegex.test((0, shared_1.camelize)(tag))) {
|
|
96
|
+
// navigation support
|
|
97
|
+
yield `/** @ts-ignore @type {typeof ${names.components}.`;
|
|
98
|
+
yield* (0, camelized_1.generateCamelized)(tag, 'template', startTagOffset, codeFeatures_1.codeFeatures.navigation);
|
|
99
|
+
if (tag[0] !== tag[0].toUpperCase()) {
|
|
100
|
+
yield ` | typeof ${names.components}.`;
|
|
101
|
+
yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(tag), 'template', startTagOffset, codeFeatures_1.codeFeatures.navigation);
|
|
136
102
|
}
|
|
103
|
+
yield `} */${utils_1.newLine}`;
|
|
104
|
+
// auto import support
|
|
105
|
+
yield* (0, camelized_1.generateCamelized)(tag, 'template', startTagOffset, codeFeatures_1.codeFeatures.importCompletionOnly);
|
|
106
|
+
yield utils_1.endOfLine;
|
|
137
107
|
}
|
|
138
|
-
yield `]} */${utils_1.endOfLine}`;
|
|
139
|
-
// auto import support
|
|
140
|
-
yield `// @ts-ignore${utils_1.newLine}`; // #2304
|
|
141
|
-
yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(node.tag), 'template', tagOffsets[0], codeFeatures_1.codeFeatures.importCompletionOnly);
|
|
142
|
-
yield utils_1.endOfLine;
|
|
143
108
|
}
|
|
144
109
|
}
|
|
110
|
+
yield* generateComponentBody(options, ctx, node, tag, startTagOffset, props, componentVar);
|
|
111
|
+
}
|
|
112
|
+
function* generateComponentBody(options, ctx, node, tag, tagOffset, props, componentVar) {
|
|
113
|
+
let isCtxVarUsed = false;
|
|
114
|
+
let isPropsVarUsed = false;
|
|
115
|
+
const getCtxVar = () => (isCtxVarUsed = true, ctxVar);
|
|
116
|
+
const getPropsVar = () => (isPropsVarUsed = true, propsVar);
|
|
117
|
+
ctx.components.push(getCtxVar);
|
|
118
|
+
const failGeneratedExpressions = [];
|
|
145
119
|
const propCodes = [...(0, elementProps_1.generateElementProps)(options, ctx, node, props, options.vueCompilerOptions.checkUnknownProps, failGeneratedExpressions)];
|
|
120
|
+
const functionalVar = ctx.getInternalVariable();
|
|
121
|
+
const vNodeVar = ctx.getInternalVariable();
|
|
122
|
+
const ctxVar = ctx.getInternalVariable();
|
|
123
|
+
const propsVar = ctx.getInternalVariable();
|
|
146
124
|
yield `// @ts-ignore${utils_1.newLine}`;
|
|
147
|
-
yield `const ${
|
|
125
|
+
yield `const ${functionalVar} = __VLS_asFunctionalComponent(${componentVar}, new ${componentVar}({${utils_1.newLine}`;
|
|
148
126
|
yield* (0, muggle_string_1.toString)(propCodes);
|
|
149
127
|
yield `}))${utils_1.endOfLine}`;
|
|
150
128
|
yield `const `;
|
|
151
129
|
const token = yield* (0, boundary_1.startBoundary)('template', node.loc.start.offset, codeFeatures_1.codeFeatures.doNotReportTs6133);
|
|
152
|
-
yield
|
|
130
|
+
yield vNodeVar;
|
|
153
131
|
yield (0, boundary_1.endBoundary)(token, node.loc.end.offset);
|
|
154
|
-
yield ` = ${
|
|
155
|
-
|
|
132
|
+
yield ` = ${functionalVar}`;
|
|
133
|
+
if (ctx.currentInfo.generic) {
|
|
134
|
+
const { content, offset } = ctx.currentInfo.generic;
|
|
135
|
+
const token = yield* (0, boundary_1.startBoundary)('template', offset, codeFeatures_1.codeFeatures.verification);
|
|
136
|
+
yield `<`;
|
|
137
|
+
yield [content, 'template', offset, codeFeatures_1.codeFeatures.all];
|
|
138
|
+
yield `>`;
|
|
139
|
+
yield (0, boundary_1.endBoundary)(token, offset + content.length);
|
|
140
|
+
}
|
|
156
141
|
yield `(`;
|
|
157
|
-
const token2 = yield* (0, boundary_1.startBoundary)('template',
|
|
142
|
+
const token2 = yield* (0, boundary_1.startBoundary)('template', tagOffset, codeFeatures_1.codeFeatures.verification);
|
|
158
143
|
yield `{${utils_1.newLine}`;
|
|
159
144
|
yield* propCodes;
|
|
160
145
|
yield `}`;
|
|
161
|
-
yield (0, boundary_1.endBoundary)(token2,
|
|
162
|
-
yield `, ...__VLS_functionalComponentArgsRest(${
|
|
146
|
+
yield (0, boundary_1.endBoundary)(token2, tagOffset + tag.length);
|
|
147
|
+
yield `, ...__VLS_functionalComponentArgsRest(${functionalVar}))${utils_1.endOfLine}`;
|
|
163
148
|
yield* generateFailedExpressions(options, ctx, failGeneratedExpressions);
|
|
164
|
-
yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node,
|
|
149
|
+
yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, componentVar, getCtxVar, getPropsVar);
|
|
165
150
|
yield* (0, elementDirectives_1.generateElementDirectives)(options, ctx, node);
|
|
166
151
|
const templateRef = getTemplateRef(node);
|
|
167
|
-
const tag = (0, shared_2.hyphenateTag)(node.tag);
|
|
168
152
|
const isRootNode = ctx.singleRootNodes.has(node)
|
|
169
|
-
&& !options.vueCompilerOptions.fallthroughComponentNames.includes(tag);
|
|
153
|
+
&& !options.vueCompilerOptions.fallthroughComponentNames.includes((0, shared_2.hyphenateTag)(tag));
|
|
170
154
|
if (templateRef || isRootNode) {
|
|
171
155
|
const componentInstanceVar = ctx.getInternalVariable();
|
|
172
|
-
|
|
173
|
-
yield `var ${componentInstanceVar} = {} as (Parameters<NonNullable<typeof ${componentCtxVar}['expose']>>[0] | null)`;
|
|
156
|
+
yield `var ${componentInstanceVar} = {} as (Parameters<NonNullable<typeof ${getCtxVar()}['expose']>>[0] | null)`;
|
|
174
157
|
if (ctx.inVFor) {
|
|
175
158
|
yield `[]`;
|
|
176
159
|
}
|
|
@@ -184,18 +167,20 @@ function* generateComponent(options, ctx, node) {
|
|
|
184
167
|
}
|
|
185
168
|
}
|
|
186
169
|
if (hasVBindAttrs(options, ctx, node)) {
|
|
187
|
-
ctx.inheritedAttrVars.add(
|
|
188
|
-
isPropsVarUsed = true;
|
|
170
|
+
ctx.inheritedAttrVars.add(getPropsVar());
|
|
189
171
|
}
|
|
190
172
|
yield* generateStyleScopedClassReferences(options, node);
|
|
191
173
|
const slotDir = node.props.find(p => p.type === CompilerDOM.NodeTypes.DIRECTIVE && p.name === 'slot');
|
|
192
|
-
|
|
174
|
+
if (slotDir || node.children.length) {
|
|
175
|
+
yield* (0, vSlot_1.generateVSlot)(options, ctx, node, slotDir, getCtxVar());
|
|
176
|
+
}
|
|
193
177
|
if (isCtxVarUsed) {
|
|
194
|
-
yield `var ${
|
|
178
|
+
yield `var ${ctxVar}!: __VLS_FunctionalComponentCtx<typeof ${componentVar}, typeof ${vNodeVar}>${utils_1.endOfLine}`;
|
|
195
179
|
}
|
|
196
180
|
if (isPropsVarUsed) {
|
|
197
|
-
yield `var ${
|
|
181
|
+
yield `var ${propsVar}!: __VLS_FunctionalComponentProps<typeof ${componentVar}, typeof ${vNodeVar}>${utils_1.endOfLine}`;
|
|
198
182
|
}
|
|
183
|
+
ctx.components.pop();
|
|
199
184
|
}
|
|
200
185
|
function* generateElement(options, ctx, node) {
|
|
201
186
|
const [startTagOffset, endTagOffset] = (0, shared_2.getElementTagOffsets)(node, options.template);
|
|
@@ -231,12 +216,9 @@ function* generateElement(options, ctx, node) {
|
|
|
231
216
|
ctx.inheritedAttrVars.add(`__VLS_intrinsics.${node.tag}`);
|
|
232
217
|
}
|
|
233
218
|
yield* generateStyleScopedClassReferences(options, node);
|
|
234
|
-
const { currentComponent } = ctx;
|
|
235
|
-
ctx.currentComponent = undefined;
|
|
236
219
|
for (const child of node.children) {
|
|
237
220
|
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, child);
|
|
238
221
|
}
|
|
239
|
-
ctx.currentComponent = currentComponent;
|
|
240
222
|
}
|
|
241
223
|
function* generateStyleScopedClassReferences({ template, ts }, node) {
|
|
242
224
|
for (const prop of node.props) {
|
|
@@ -304,7 +286,8 @@ function* generateStyleScopedClassReferences({ template, ts }, node) {
|
|
|
304
286
|
if (ts.isPropertyAssignment(property)) {
|
|
305
287
|
const { name } = property;
|
|
306
288
|
if (ts.isIdentifier(name)) {
|
|
307
|
-
|
|
289
|
+
const text = (0, shared_2.getNodeText)(ts, name, ast);
|
|
290
|
+
yield* (0, styleScopedClasses_1.generateStyleScopedClassReference)(template, text, name.end - text.length + startOffset);
|
|
308
291
|
}
|
|
309
292
|
else if (ts.isStringLiteral(name)) {
|
|
310
293
|
literals.push(name);
|
|
@@ -317,7 +300,8 @@ function* generateStyleScopedClassReferences({ template, ts }, node) {
|
|
|
317
300
|
}
|
|
318
301
|
}
|
|
319
302
|
else if (ts.isShorthandPropertyAssignment(property)) {
|
|
320
|
-
|
|
303
|
+
const text = (0, shared_2.getNodeText)(ts, property.name, ast);
|
|
304
|
+
yield* (0, styleScopedClasses_1.generateStyleScopedClassReference)(template, text, property.name.end - text.length + startOffset);
|
|
321
305
|
}
|
|
322
306
|
}
|
|
323
307
|
}
|
|
@@ -337,42 +321,6 @@ function* generateFailedExpressions(options, ctx, failGeneratedExpressions) {
|
|
|
337
321
|
yield utils_1.endOfLine;
|
|
338
322
|
}
|
|
339
323
|
}
|
|
340
|
-
function getCanonicalComponentName(tagText) {
|
|
341
|
-
return utils_1.identifierRegex.test(tagText)
|
|
342
|
-
? tagText
|
|
343
|
-
: (0, shared_1.capitalize)((0, shared_1.camelize)(tagText.replace(colonReg, '-')));
|
|
344
|
-
}
|
|
345
|
-
function getPossibleOriginalComponentNames(tagText, deduplicate) {
|
|
346
|
-
const name1 = (0, shared_1.capitalize)((0, shared_1.camelize)(tagText));
|
|
347
|
-
const name2 = (0, shared_1.camelize)(tagText);
|
|
348
|
-
const name3 = tagText;
|
|
349
|
-
const names = [name1];
|
|
350
|
-
if (!deduplicate || name2 !== name1) {
|
|
351
|
-
names.push(name2);
|
|
352
|
-
}
|
|
353
|
-
if (!deduplicate || name3 !== name2) {
|
|
354
|
-
names.push(name3);
|
|
355
|
-
}
|
|
356
|
-
return names;
|
|
357
|
-
}
|
|
358
|
-
function* generateCanonicalComponentName(tagText, offset, features) {
|
|
359
|
-
if (utils_1.identifierRegex.test(tagText)) {
|
|
360
|
-
yield [tagText, 'template', offset, features];
|
|
361
|
-
}
|
|
362
|
-
else {
|
|
363
|
-
yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(tagText.replace(colonReg, '-')), 'template', offset, features);
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
function* generateComponentGeneric(ctx) {
|
|
367
|
-
if (ctx.currentInfo.generic) {
|
|
368
|
-
const { content, offset } = ctx.currentInfo.generic;
|
|
369
|
-
const token = yield* (0, boundary_1.startBoundary)('template', offset, codeFeatures_1.codeFeatures.verification);
|
|
370
|
-
yield `<`;
|
|
371
|
-
yield [content, 'template', offset, codeFeatures_1.codeFeatures.all];
|
|
372
|
-
yield `>`;
|
|
373
|
-
yield (0, boundary_1.endBoundary)(token, offset + content.length);
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
324
|
function getTemplateRef(node) {
|
|
377
325
|
for (const prop of node.props) {
|
|
378
326
|
if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type * as CompilerDOM from '@vue/compiler-dom';
|
|
2
|
+
import type { Code } from '../../types';
|
|
3
|
+
import type { TemplateCodegenContext } from './context';
|
|
4
|
+
import type { TemplateCodegenOptions } from './index';
|
|
5
|
+
export declare function generateElementChildren(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, children: (CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode)[], enterNode?: boolean): Generator<Code>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateElementChildren = generateElementChildren;
|
|
4
|
+
const templateChild_1 = require("./templateChild");
|
|
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);
|
|
9
|
+
}
|
|
10
|
+
yield* ctx.generateAutoImportCompletion();
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=elementChildren.js.map
|
|
@@ -3,7 +3,7 @@ import type * as ts from 'typescript';
|
|
|
3
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, componentOriginalVar: string): Generator<Code>;
|
|
6
|
+
export declare function generateElementEvents(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, componentOriginalVar: string, getCtxVar: () => string, getPropsVar: () => string): Generator<Code>;
|
|
7
7
|
export declare function generateEventArg(options: TemplateCodegenOptions, 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
9
|
export declare function generateModelEventExpression(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode): Generator<Code>;
|
|
@@ -12,7 +12,7 @@ const utils_1 = require("../utils");
|
|
|
12
12
|
const boundary_1 = require("../utils/boundary");
|
|
13
13
|
const camelized_1 = require("../utils/camelized");
|
|
14
14
|
const interpolation_1 = require("./interpolation");
|
|
15
|
-
function* generateElementEvents(options, ctx, node, componentOriginalVar) {
|
|
15
|
+
function* generateElementEvents(options, ctx, node, componentOriginalVar, getCtxVar, getPropsVar) {
|
|
16
16
|
let emitsVar;
|
|
17
17
|
for (const prop of node.props) {
|
|
18
18
|
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
@@ -23,7 +23,7 @@ function* generateElementEvents(options, ctx, node, componentOriginalVar) {
|
|
|
23
23
|
&& (!prop.arg || prop.arg.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic))) {
|
|
24
24
|
if (!emitsVar) {
|
|
25
25
|
emitsVar = ctx.getInternalVariable();
|
|
26
|
-
yield `let ${emitsVar}!: __VLS_ResolveEmits<typeof ${componentOriginalVar}, typeof ${
|
|
26
|
+
yield `let ${emitsVar}!: __VLS_ResolveEmits<typeof ${componentOriginalVar}, typeof ${getCtxVar()}.emit>${utils_1.endOfLine}`;
|
|
27
27
|
}
|
|
28
28
|
let source = prop.arg?.loc.source ?? 'model-value';
|
|
29
29
|
let start = prop.arg?.loc.start.offset;
|
|
@@ -42,7 +42,7 @@ function* generateElementEvents(options, ctx, node, componentOriginalVar) {
|
|
|
42
42
|
const propName = (0, shared_1.camelize)(propPrefix + source);
|
|
43
43
|
const emitName = emitPrefix + source;
|
|
44
44
|
const camelizedEmitName = (0, shared_1.camelize)(emitName);
|
|
45
|
-
yield `const ${ctx.getInternalVariable()}: __VLS_NormalizeComponentEvent<typeof ${
|
|
45
|
+
yield `const ${ctx.getInternalVariable()}: __VLS_NormalizeComponentEvent<typeof ${getPropsVar()}, typeof ${emitsVar}, '${propName}', '${emitName}', '${camelizedEmitName}'> = (${utils_1.newLine}`;
|
|
46
46
|
if (prop.name === 'on') {
|
|
47
47
|
yield `{ `;
|
|
48
48
|
yield* generateEventArg(options, source, start, emitPrefix.slice(0, -1), codeFeatures_1.codeFeatures.navigation);
|
|
@@ -10,7 +10,7 @@ export interface TemplateCodegenOptions {
|
|
|
10
10
|
propsAssignName?: string;
|
|
11
11
|
slotsAssignName?: string;
|
|
12
12
|
inheritAttrs: boolean;
|
|
13
|
-
selfComponentName
|
|
13
|
+
selfComponentName: string;
|
|
14
14
|
}
|
|
15
15
|
export { generate as generateTemplate };
|
|
16
16
|
declare function generate(options: TemplateCodegenOptions): {
|
|
@@ -49,15 +49,12 @@ declare function generate(options: TemplateCodegenOptions): {
|
|
|
49
49
|
typeExp: string;
|
|
50
50
|
offset: number;
|
|
51
51
|
}[]>;
|
|
52
|
-
currentComponent: {
|
|
53
|
-
get ctxVar(): string;
|
|
54
|
-
get propsVar(): string;
|
|
55
|
-
} | undefined;
|
|
56
52
|
singleRootElTypes: Set<string>;
|
|
57
53
|
singleRootNodes: Set<import("@vue/compiler-dom").ElementNode | null>;
|
|
58
54
|
addTemplateRef(name: string, typeExp: string, offset: number): void;
|
|
59
55
|
recordComponentAccess(source: string, name: string, offset?: number): void;
|
|
60
56
|
scopes: Set<string>[];
|
|
57
|
+
components: (() => string)[];
|
|
61
58
|
declare(...varNames: string[]): void;
|
|
62
59
|
startScope(): () => Generator<Code, any, any>;
|
|
63
60
|
getInternalVariable(): string;
|
|
@@ -29,25 +29,21 @@ function* generateTemplateChild(options, ctx, node, enterNode = true) {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
else if (node.type === CompilerDOM.NodeTypes.ELEMENT) {
|
|
32
|
+
let slotDir;
|
|
32
33
|
if (node.tagType === CompilerDOM.ElementTypes.SLOT) {
|
|
33
34
|
yield* (0, slotOutlet_1.generateSlotOutlet)(options, ctx, node);
|
|
34
35
|
}
|
|
36
|
+
else if (node.tagType === CompilerDOM.ElementTypes.TEMPLATE
|
|
37
|
+
&& ctx.components.length
|
|
38
|
+
&& (slotDir = node.props.find(p => p.type === CompilerDOM.NodeTypes.DIRECTIVE && p.name === 'slot'))) {
|
|
39
|
+
yield* (0, vSlot_1.generateVSlot)(options, ctx, node, slotDir, ctx.components[ctx.components.length - 1]());
|
|
40
|
+
}
|
|
41
|
+
else if (node.tagType === CompilerDOM.ElementTypes.ELEMENT
|
|
42
|
+
|| node.tagType === CompilerDOM.ElementTypes.TEMPLATE) {
|
|
43
|
+
yield* (0, element_1.generateElement)(options, ctx, node);
|
|
44
|
+
}
|
|
35
45
|
else {
|
|
36
|
-
|
|
37
|
-
if (node.tagType === CompilerDOM.ElementTypes.TEMPLATE
|
|
38
|
-
&& ctx.currentComponent
|
|
39
|
-
&& slotDir) {
|
|
40
|
-
yield* (0, vSlot_1.generateVSlot)(options, ctx, node, slotDir);
|
|
41
|
-
}
|
|
42
|
-
else if (node.tagType === CompilerDOM.ElementTypes.ELEMENT
|
|
43
|
-
|| node.tagType === CompilerDOM.ElementTypes.TEMPLATE) {
|
|
44
|
-
yield* (0, element_1.generateElement)(options, ctx, node);
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
const { currentComponent } = ctx;
|
|
48
|
-
yield* (0, element_1.generateComponent)(options, ctx, node);
|
|
49
|
-
ctx.currentComponent = currentComponent;
|
|
50
|
-
}
|
|
46
|
+
yield* (0, element_1.generateComponent)(options, ctx, node);
|
|
51
47
|
}
|
|
52
48
|
}
|
|
53
49
|
else if (node.type === CompilerDOM.NodeTypes.TEXT_CALL) {
|
|
@@ -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 generateVSlot(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, slotDir: CompilerDOM.DirectiveNode | undefined): Generator<Code>;
|
|
5
|
+
export declare function generateVSlot(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, slotDir: CompilerDOM.DirectiveNode | undefined, ctxVar: string): Generator<Code>;
|
|
@@ -10,34 +10,28 @@ const boundary_1 = require("../utils/boundary");
|
|
|
10
10
|
const interpolation_1 = require("./interpolation");
|
|
11
11
|
const objectProperty_1 = require("./objectProperty");
|
|
12
12
|
const templateChild_1 = require("./templateChild");
|
|
13
|
-
function* generateVSlot(options, ctx, node, slotDir) {
|
|
14
|
-
if (!ctx.currentComponent) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
13
|
+
function* generateVSlot(options, ctx, node, slotDir, ctxVar) {
|
|
17
14
|
const slotVar = ctx.getInternalVariable();
|
|
18
15
|
if (slotDir) {
|
|
19
16
|
yield `{${utils_1.newLine}`;
|
|
20
|
-
}
|
|
21
|
-
if (slotDir || node.children.length) {
|
|
22
17
|
yield `const { `;
|
|
23
|
-
if (slotDir) {
|
|
24
|
-
|
|
25
|
-
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slotDir.arg.loc.source, slotDir.arg.loc.start.offset, slotDir.arg.isStatic ? codeFeatures_1.codeFeatures.withoutHighlight : codeFeatures_1.codeFeatures.all, false, true);
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
const token = yield* (0, boundary_1.startBoundary)('template', slotDir.loc.start.offset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
|
|
29
|
-
yield `default`;
|
|
30
|
-
yield (0, boundary_1.endBoundary)(token, slotDir.loc.start.offset + (slotDir.rawName?.length ?? 0));
|
|
31
|
-
}
|
|
18
|
+
if (slotDir.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && slotDir.arg.content) {
|
|
19
|
+
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slotDir.arg.loc.source, slotDir.arg.loc.start.offset, slotDir.arg.isStatic ? codeFeatures_1.codeFeatures.withoutHighlight : codeFeatures_1.codeFeatures.all, false, true);
|
|
32
20
|
}
|
|
33
21
|
else {
|
|
34
|
-
|
|
35
|
-
const token = yield* (0, boundary_1.startBoundary)('template', node.loc.start.offset, codeFeatures_1.codeFeatures.navigation);
|
|
22
|
+
const token = yield* (0, boundary_1.startBoundary)('template', slotDir.loc.start.offset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
|
|
36
23
|
yield `default`;
|
|
37
|
-
yield (0, boundary_1.endBoundary)(token,
|
|
24
|
+
yield (0, boundary_1.endBoundary)(token, slotDir.loc.start.offset + (slotDir.rawName?.length ?? 0));
|
|
38
25
|
}
|
|
39
|
-
yield `: ${slotVar} } = ${ctx.currentComponent.ctxVar}.slots!${utils_1.endOfLine}`;
|
|
40
26
|
}
|
|
27
|
+
else {
|
|
28
|
+
yield `const { `;
|
|
29
|
+
// #932: reference for implicit default slot
|
|
30
|
+
const token = yield* (0, boundary_1.startBoundary)('template', node.loc.start.offset, codeFeatures_1.codeFeatures.navigation);
|
|
31
|
+
yield `default`;
|
|
32
|
+
yield (0, boundary_1.endBoundary)(token, node.loc.end.offset);
|
|
33
|
+
}
|
|
34
|
+
yield `: ${slotVar} } = ${ctxVar}.slots!${utils_1.endOfLine}`;
|
|
41
35
|
const endScope = ctx.startScope();
|
|
42
36
|
if (slotDir?.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
43
37
|
const slotAst = (0, utils_1.getTypeScriptAST)(options.ts, options.template, `(${slotDir.exp.content}) => {}`);
|
|
@@ -54,7 +48,7 @@ function* generateVSlot(options, ctx, node, slotDir) {
|
|
|
54
48
|
isStatic = slotDir.arg.isStatic;
|
|
55
49
|
}
|
|
56
50
|
if (isStatic && !slotDir.arg) {
|
|
57
|
-
yield `${
|
|
51
|
+
yield `${ctxVar}.slots!['`;
|
|
58
52
|
yield [
|
|
59
53
|
'',
|
|
60
54
|
'template',
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type * as ts from 'typescript';
|
|
2
|
-
import type { Code, SfcBlock, VueCodeInformation } from '../../types';
|
|
2
|
+
import type { Code, Sfc, SfcBlock, VueCodeInformation } from '../../types';
|
|
3
3
|
export declare const newLine = "\n";
|
|
4
4
|
export declare const endOfLine = ";\n";
|
|
5
5
|
export declare const identifierRegex: RegExp;
|
|
6
6
|
export declare function getTypeScriptAST(ts: typeof import('typescript'), block: SfcBlock, text: string): ts.SourceFile;
|
|
7
|
-
export declare function generateSfcBlockSection(block:
|
|
7
|
+
export declare function generateSfcBlockSection(block: NonNullable<Sfc['script' | 'scriptSetup']>, start: number, end: number, features: VueCodeInformation): Generator<Code>;
|
|
8
8
|
export declare function forEachNode(ts: typeof import('typescript'), node: ts.Node): Generator<ts.Node>;
|
|
@@ -34,18 +34,22 @@ function getTypeScriptAST(ts, block, text) {
|
|
|
34
34
|
cacheMap[1].set(text, [ast, 1]);
|
|
35
35
|
return ast;
|
|
36
36
|
}
|
|
37
|
-
function* generateSfcBlockSection(block, start, end, features
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
block.name,
|
|
41
|
-
start,
|
|
42
|
-
features,
|
|
43
|
-
];
|
|
37
|
+
function* generateSfcBlockSection(block, start, end, features) {
|
|
38
|
+
const text = block.content.slice(start, end);
|
|
39
|
+
yield [text, block.name, start, features];
|
|
44
40
|
// #3632
|
|
45
|
-
if (
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
if ('parseDiagnostics' in block.ast) {
|
|
42
|
+
const textEnd = text.trimEnd().length;
|
|
43
|
+
for (const diag of block.ast.parseDiagnostics) {
|
|
44
|
+
const diagStart = diag.start;
|
|
45
|
+
const diagEnd = diag.start + diag.length;
|
|
46
|
+
if (diagStart >= textEnd && diagEnd <= end) {
|
|
47
|
+
yield `;`;
|
|
48
|
+
yield ['', block.name, end, codeFeatures_1.codeFeatures.verification];
|
|
49
|
+
yield exports.newLine;
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
49
53
|
}
|
|
50
54
|
}
|
|
51
55
|
function* forEachNode(ts, node) {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.wrapWith = wrapWith;
|
|
4
|
+
function* wrapWith(source, startOffset, endOffset, features, ...codes) {
|
|
5
|
+
yield ['', source, startOffset, features];
|
|
6
|
+
let offset = 1;
|
|
7
|
+
for (const code of codes) {
|
|
8
|
+
if (typeof code !== 'string') {
|
|
9
|
+
offset++;
|
|
10
|
+
}
|
|
11
|
+
yield code;
|
|
12
|
+
}
|
|
13
|
+
yield ['', source, endOffset, { __combineOffset: offset }];
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=wrapWith.js.map
|