@vue/language-core 3.3.5 → 3.3.7
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 -0
- package/index.js +1 -0
- package/lib/codegen/codeFeatures.d.ts +24 -84
- package/lib/codegen/codeFeatures.js +46 -4
- package/lib/codegen/names.d.ts +3 -4
- package/lib/codegen/names.js +3 -4
- package/lib/codegen/script/index.js +5 -5
- package/lib/codegen/script/scriptSetup.js +4 -4
- package/lib/codegen/style/common.js +7 -11
- package/lib/codegen/style/index.d.ts +55 -27
- package/lib/codegen/style/index.js +4 -4
- package/lib/codegen/style/modules.d.ts +1 -1
- package/lib/codegen/style/modules.js +1 -1
- package/lib/codegen/style/scopedClasses.d.ts +2 -1
- package/lib/codegen/style/scopedClasses.js +5 -4
- package/lib/codegen/template/context.d.ts +55 -124
- package/lib/codegen/template/context.js +187 -269
- package/lib/codegen/template/element.js +18 -103
- package/lib/codegen/template/elementDirectives.js +11 -11
- package/lib/codegen/template/elementEvents.js +50 -45
- package/lib/codegen/template/elementProps.js +12 -12
- package/lib/codegen/template/index.d.ts +55 -27
- package/lib/codegen/template/index.js +7 -7
- package/lib/codegen/template/interpolation.js +28 -28
- package/lib/codegen/template/objectProperty.js +5 -5
- package/lib/codegen/template/propertyAccess.js +1 -1
- package/lib/codegen/template/slotOutlet.js +8 -10
- package/lib/codegen/template/styleScopedClasses.d.ts +3 -0
- package/lib/codegen/template/styleScopedClasses.js +126 -4
- package/lib/codegen/template/vFor.js +3 -3
- package/lib/codegen/template/vIf.js +4 -4
- package/lib/codegen/template/vSlot.js +9 -9
- package/lib/codegen/utils/boundary.d.ts +7 -2
- package/lib/codegen/utils/boundary.js +15 -9
- package/lib/codegen/utils/camelized.js +5 -13
- package/lib/codegen/utils/escaped.js +4 -9
- package/lib/codegen/utils/index.d.ts +1 -1
- package/lib/codegen/utils/index.js +3 -3
- package/lib/codegen/utils/stringLiteralKey.js +3 -3
- package/lib/codegen/utils/unicode.d.ts +1 -1
- package/lib/codegen/utils/unicode.js +4 -4
- package/lib/languagePlugin.js +2 -1
- package/lib/parsers/scriptRanges.d.ts +2 -2
- package/lib/parsers/scriptRanges.js +3 -10
- package/lib/parsers/scriptSetupRanges.d.ts +2 -2
- package/lib/parsers/scriptSetupRanges.js +3 -10
- package/lib/parsers/utils.d.ts +1 -0
- package/lib/parsers/utils.js +10 -0
- package/lib/parsers/vueCompilerOptions.js +2 -2
- package/lib/plugins/file-html.js +4 -4
- package/lib/plugins/file-md.js +15 -15
- package/lib/plugins/file-vue.js +2 -2
- package/lib/plugins/vue-root-tags.js +3 -3
- package/lib/plugins/vue-sfc-customblocks.js +2 -2
- package/lib/plugins/vue-sfc-scripts.js +2 -4
- package/lib/plugins/vue-sfc-styles.js +3 -3
- package/lib/plugins/vue-sfc-template.js +2 -2
- package/lib/plugins/vue-style-css.js +86 -33
- package/lib/plugins/vue-template-html.js +3 -3
- package/lib/plugins/vue-template-inline-css.js +2 -7
- package/lib/plugins/vue-template-inline-ts.js +4 -5
- package/lib/plugins/vue-tsx.d.ts +61 -31
- package/lib/plugins/vue-tsx.js +26 -23
- package/lib/plugins.d.ts +0 -1
- package/lib/plugins.js +0 -15
- package/lib/types.d.ts +1 -1
- package/lib/utils/forEachTemplateNode.js +36 -43
- package/lib/virtualCode/index.js +2 -2
- package/package.json +4 -4
- package/types/template-helpers.d.ts +14 -24
- package/lib/plugins/shared.d.ts +0 -2
- package/lib/plugins/shared.js +0 -12
|
@@ -130,7 +130,7 @@ function* generateComponent(options, ctx, node) {
|
|
|
130
130
|
: codeFeatures_1.codeFeatures.doNotReportTs2339AndTs2551,
|
|
131
131
|
});
|
|
132
132
|
yield `]${utils_1.endOfLine}`;
|
|
133
|
-
if (utils_1.
|
|
133
|
+
if (utils_1.identifierRE.test((0, shared_1.camelize)(tag))) {
|
|
134
134
|
// navigation support
|
|
135
135
|
yield `/** @ts-ignore @type {`;
|
|
136
136
|
for (const offset of [startTagOffset, endTagOffset]) {
|
|
@@ -173,21 +173,22 @@ function* generateComponent(options, ctx, node) {
|
|
|
173
173
|
yield propsStr;
|
|
174
174
|
yield `}))${utils_1.endOfLine}`;
|
|
175
175
|
yield `const `;
|
|
176
|
-
const
|
|
176
|
+
const boundary = yield* boundary_1.Boundary.start('template', node.loc.start.offset, codeFeatures_1.codeFeatures.doNotReportTs6133);
|
|
177
177
|
yield vnodeVar;
|
|
178
|
-
yield
|
|
178
|
+
yield boundary.end(node.loc.end.offset);
|
|
179
179
|
yield ` = ${functionalVar}`;
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
const
|
|
180
|
+
const commentInfo = ctx.getCommentInfo();
|
|
181
|
+
if (commentInfo.generic) {
|
|
182
|
+
const { content, offset } = commentInfo.generic;
|
|
183
|
+
const boundary = yield* boundary_1.Boundary.start('template', offset, codeFeatures_1.codeFeatures.verification);
|
|
183
184
|
yield `<`;
|
|
184
185
|
yield [content, 'template', offset, codeFeatures_1.codeFeatures.all];
|
|
185
186
|
yield `>`;
|
|
186
|
-
yield
|
|
187
|
+
yield boundary.end(offset + content.length);
|
|
187
188
|
}
|
|
188
189
|
const shouldInheritAttrs = hasVBindAttrs(options, ctx, node);
|
|
189
190
|
yield `(`;
|
|
190
|
-
const
|
|
191
|
+
const boundary2 = yield* boundary_1.Boundary.start('template', startTagOffset, shouldInheritAttrs && options.vueCompilerOptions.checkRequiredFallthroughAttributes
|
|
191
192
|
? {}
|
|
192
193
|
: codeFeatures_1.codeFeatures.verification);
|
|
193
194
|
yield `{`;
|
|
@@ -195,7 +196,7 @@ function* generateComponent(options, ctx, node) {
|
|
|
195
196
|
yield utils_1.newLine;
|
|
196
197
|
yield* propCodes;
|
|
197
198
|
yield `}`;
|
|
198
|
-
yield
|
|
199
|
+
yield boundary2.end(startTagOffset + tag.length);
|
|
199
200
|
yield `, ...${names_1.names.functionalComponentArgsRest}(${functionalVar}))${utils_1.endOfLine}`;
|
|
200
201
|
yield* generateFailedExpressions(options, ctx, failedPropExps);
|
|
201
202
|
yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, componentVar, getCtxVar, getPropsVar);
|
|
@@ -228,16 +229,16 @@ function* generateComponent(options, ctx, node) {
|
|
|
228
229
|
ctx.inheritedAttrVars.add(getPropsVar());
|
|
229
230
|
}
|
|
230
231
|
}
|
|
231
|
-
yield* generateStyleScopedClassReferences(options, node);
|
|
232
|
+
yield* (0, styleScopedClasses_1.generateStyleScopedClassReferences)(options, node);
|
|
232
233
|
const slotDir = node.props.find(CompilerDOM.isVSlot);
|
|
233
234
|
if (slotDir || node.children.length) {
|
|
234
235
|
yield* (0, vSlot_1.generateVSlot)(options, ctx, node, slotDir, getCtxVar());
|
|
235
236
|
}
|
|
236
237
|
if (isCtxVarUsed) {
|
|
237
|
-
yield `var ${ctxVar}!: ${names_1.names.
|
|
238
|
+
yield `var ${ctxVar}!: ${names_1.names.ExtractComponentContext}<typeof ${componentVar}, typeof ${vnodeVar}>${utils_1.endOfLine}`;
|
|
238
239
|
}
|
|
239
240
|
if (isPropsVarUsed) {
|
|
240
|
-
yield `var ${propsVar}!: ${names_1.names.
|
|
241
|
+
yield `var ${propsVar}!: ${names_1.names.ExtractComponentProps}<typeof ${componentVar}, typeof ${vnodeVar}>${utils_1.endOfLine}`;
|
|
241
242
|
}
|
|
242
243
|
ctx.components.pop();
|
|
243
244
|
}
|
|
@@ -252,11 +253,11 @@ function* generateElement(options, ctx, node) {
|
|
|
252
253
|
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, endTagOffset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
|
|
253
254
|
}
|
|
254
255
|
yield `)(`;
|
|
255
|
-
const
|
|
256
|
+
const boundary = yield* boundary_1.Boundary.start('template', startTagOffset, codeFeatures_1.codeFeatures.verification);
|
|
256
257
|
yield `{${utils_1.newLine}`;
|
|
257
258
|
yield* (0, elementProps_1.generateElementProps)(options, ctx, node, node.props, options.vueCompilerOptions.checkUnknownProps, failedPropExps);
|
|
258
259
|
yield `}`;
|
|
259
|
-
yield
|
|
260
|
+
yield boundary.end(startTagOffset + node.tag.length);
|
|
260
261
|
yield `)${utils_1.endOfLine}`;
|
|
261
262
|
yield* generateFailedExpressions(options, ctx, failedPropExps);
|
|
262
263
|
yield* (0, elementDirectives_1.generateElementDirectives)(options, ctx, node);
|
|
@@ -274,7 +275,7 @@ function* generateElement(options, ctx, node) {
|
|
|
274
275
|
if (hasVBindAttrs(options, ctx, node)) {
|
|
275
276
|
ctx.inheritedAttrVars.add(`${names_1.names.intrinsics}.${node.tag}`);
|
|
276
277
|
}
|
|
277
|
-
yield* generateStyleScopedClassReferences(options, node);
|
|
278
|
+
yield* (0, styleScopedClasses_1.generateStyleScopedClassReferences)(options, node);
|
|
278
279
|
for (const child of node.children) {
|
|
279
280
|
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, child);
|
|
280
281
|
}
|
|
@@ -284,103 +285,17 @@ function* generateFragment(options, ctx, node) {
|
|
|
284
285
|
// special case for <template v-for="..." :key="..." />
|
|
285
286
|
if (node.props.length) {
|
|
286
287
|
yield `__VLS_asFunctionalElement(__VLS_intrinsics.template)(`;
|
|
287
|
-
const
|
|
288
|
+
const boundary = yield* boundary_1.Boundary.start('template', startTagOffset, codeFeatures_1.codeFeatures.verification);
|
|
288
289
|
yield `{${utils_1.newLine}`;
|
|
289
290
|
yield* (0, elementProps_1.generateElementProps)(options, ctx, node, node.props, options.vueCompilerOptions.checkUnknownProps);
|
|
290
291
|
yield `}`;
|
|
291
|
-
yield
|
|
292
|
+
yield boundary.end(startTagOffset + node.tag.length);
|
|
292
293
|
yield `)${utils_1.endOfLine}`;
|
|
293
294
|
}
|
|
294
295
|
for (const child of node.children) {
|
|
295
296
|
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, child);
|
|
296
297
|
}
|
|
297
298
|
}
|
|
298
|
-
function* generateStyleScopedClassReferences({ template, typescript: ts }, node) {
|
|
299
|
-
for (const prop of node.props) {
|
|
300
|
-
if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE
|
|
301
|
-
&& prop.name === 'class'
|
|
302
|
-
&& prop.value) {
|
|
303
|
-
const [text, start] = (0, shared_2.normalizeAttributeValue)(prop.value);
|
|
304
|
-
for (const [className, offset] of forEachClassName(text)) {
|
|
305
|
-
yield* (0, styleScopedClasses_1.generateStyleScopedClassReference)(template, className, start + offset);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
else if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
309
|
-
&& prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
310
|
-
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
311
|
-
&& prop.arg.content === 'class') {
|
|
312
|
-
const content = '(' + prop.exp.content + ')';
|
|
313
|
-
const startOffset = prop.exp.loc.start.offset - 1;
|
|
314
|
-
const ast = (0, utils_1.getTypeScriptAST)(ts, template, content);
|
|
315
|
-
const literals = [];
|
|
316
|
-
for (const node of (0, utils_1.forEachNode)(ts, ast)) {
|
|
317
|
-
if (!ts.isExpressionStatement(node)
|
|
318
|
-
|| !ts.isParenthesizedExpression(node.expression)) {
|
|
319
|
-
continue;
|
|
320
|
-
}
|
|
321
|
-
const { expression } = node.expression;
|
|
322
|
-
if (ts.isStringLiteralLike(expression)) {
|
|
323
|
-
literals.push(expression);
|
|
324
|
-
}
|
|
325
|
-
else if (ts.isArrayLiteralExpression(expression)) {
|
|
326
|
-
yield* walkArrayLiteral(expression);
|
|
327
|
-
}
|
|
328
|
-
else if (ts.isObjectLiteralExpression(expression)) {
|
|
329
|
-
yield* walkObjectLiteral(expression);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
for (const literal of literals) {
|
|
333
|
-
const start = literal.end - literal.text.length - 1 + startOffset;
|
|
334
|
-
for (const [className, offset] of forEachClassName(literal.text)) {
|
|
335
|
-
yield* (0, styleScopedClasses_1.generateStyleScopedClassReference)(template, className, start + offset);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
function* walkArrayLiteral(node) {
|
|
339
|
-
const { elements } = node;
|
|
340
|
-
for (const element of elements) {
|
|
341
|
-
if (ts.isStringLiteralLike(element)) {
|
|
342
|
-
literals.push(element);
|
|
343
|
-
}
|
|
344
|
-
else if (ts.isObjectLiteralExpression(element)) {
|
|
345
|
-
yield* walkObjectLiteral(element);
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
function* walkObjectLiteral(node) {
|
|
350
|
-
const { properties } = node;
|
|
351
|
-
for (const property of properties) {
|
|
352
|
-
if (ts.isPropertyAssignment(property)) {
|
|
353
|
-
const { name } = property;
|
|
354
|
-
if (ts.isIdentifier(name)) {
|
|
355
|
-
const text = (0, shared_2.getNodeText)(ts, name, ast);
|
|
356
|
-
yield* (0, styleScopedClasses_1.generateStyleScopedClassReference)(template, text, name.end - text.length + startOffset);
|
|
357
|
-
}
|
|
358
|
-
else if (ts.isStringLiteral(name)) {
|
|
359
|
-
literals.push(name);
|
|
360
|
-
}
|
|
361
|
-
else if (ts.isComputedPropertyName(name)) {
|
|
362
|
-
const { expression } = name;
|
|
363
|
-
if (ts.isStringLiteralLike(expression)) {
|
|
364
|
-
literals.push(expression);
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
else if (ts.isShorthandPropertyAssignment(property)) {
|
|
369
|
-
const text = (0, shared_2.getNodeText)(ts, property.name, ast);
|
|
370
|
-
yield* (0, styleScopedClasses_1.generateStyleScopedClassReference)(template, text, property.name.end - text.length + startOffset);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
function* forEachClassName(content) {
|
|
378
|
-
let offset = 0;
|
|
379
|
-
for (const className of content.split(' ')) {
|
|
380
|
-
yield [className, offset];
|
|
381
|
-
offset += className.length + 1;
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
299
|
function* generateFailedExpressions(options, ctx, failedPropExps) {
|
|
385
300
|
for (const { node, prefix, suffix } of failedPropExps) {
|
|
386
301
|
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, node.loc.source, node.loc.start.offset, prefix, suffix);
|
|
@@ -55,7 +55,7 @@ function* generateElementDirectives(options, ctx, node) {
|
|
|
55
55
|
|| prop.name === 'bind') {
|
|
56
56
|
continue;
|
|
57
57
|
}
|
|
58
|
-
const
|
|
58
|
+
const boundary = yield* boundary_1.Boundary.start('template', prop.loc.start.offset, codeFeatures_1.codeFeatures.verification);
|
|
59
59
|
yield `${names_1.names.asFunctionalDirective}(`;
|
|
60
60
|
yield* generateIdentifier(options, ctx, prop);
|
|
61
61
|
yield `, {} as import('${options.vueCompilerOptions.lib}').ObjectDirective)(null!, { ...${names_1.names.directiveBindingRestFields}, `;
|
|
@@ -63,14 +63,14 @@ function* generateElementDirectives(options, ctx, node) {
|
|
|
63
63
|
yield* generateModifiers(options, ctx, prop);
|
|
64
64
|
yield* generateValue(options, ctx, prop);
|
|
65
65
|
yield ` }, null!, null!)`;
|
|
66
|
-
yield
|
|
66
|
+
yield boundary.end(prop.loc.end.offset);
|
|
67
67
|
yield utils_1.endOfLine;
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
function* generateIdentifier(options, ctx, prop) {
|
|
71
71
|
const rawName = 'v-' + prop.name;
|
|
72
72
|
const startOffset = prop.loc.start.offset;
|
|
73
|
-
const
|
|
73
|
+
const boundary = yield* boundary_1.Boundary.start('template', startOffset, codeFeatures_1.codeFeatures.verification);
|
|
74
74
|
yield names_1.names.directives;
|
|
75
75
|
yield `.`;
|
|
76
76
|
yield* (0, camelized_1.generateCamelized)(rawName, 'template', prop.loc.start.offset, {
|
|
@@ -78,9 +78,9 @@ function* generateIdentifier(options, ctx, prop) {
|
|
|
78
78
|
verification: options.vueCompilerOptions.checkUnknownDirectives && !(0, shared_1.isBuiltInDirective)(prop.name),
|
|
79
79
|
});
|
|
80
80
|
if (!(0, shared_1.isBuiltInDirective)(prop.name)) {
|
|
81
|
-
ctx.
|
|
81
|
+
ctx.accessVariable('template', (0, shared_1.camelize)(rawName), prop.loc.start.offset);
|
|
82
82
|
}
|
|
83
|
-
yield
|
|
83
|
+
yield boundary.end(startOffset + rawName.length);
|
|
84
84
|
}
|
|
85
85
|
function* generateArg(options, ctx, prop) {
|
|
86
86
|
const { arg } = prop;
|
|
@@ -88,9 +88,9 @@ function* generateArg(options, ctx, prop) {
|
|
|
88
88
|
return;
|
|
89
89
|
}
|
|
90
90
|
const startOffset = arg.loc.start.offset + arg.loc.source.indexOf(arg.content);
|
|
91
|
-
const
|
|
91
|
+
const boundary = yield* boundary_1.Boundary.start('template', startOffset, codeFeatures_1.codeFeatures.verification);
|
|
92
92
|
yield `arg`;
|
|
93
|
-
yield
|
|
93
|
+
yield boundary.end(startOffset + arg.content.length);
|
|
94
94
|
yield `: `;
|
|
95
95
|
if (arg.isStatic) {
|
|
96
96
|
yield* (0, stringLiteralKey_1.generateStringLiteralKey)(arg.content, startOffset, codeFeatures_1.codeFeatures.all);
|
|
@@ -107,9 +107,9 @@ function* generateModifiers(options, ctx, prop, propertyName = 'modifiers') {
|
|
|
107
107
|
}
|
|
108
108
|
const startOffset = modifiers[0].loc.start.offset - 1;
|
|
109
109
|
const endOffset = modifiers.at(-1).loc.end.offset;
|
|
110
|
-
const
|
|
110
|
+
const boundary = yield* boundary_1.Boundary.start('template', startOffset, codeFeatures_1.codeFeatures.verification);
|
|
111
111
|
yield propertyName;
|
|
112
|
-
yield
|
|
112
|
+
yield boundary.end(endOffset);
|
|
113
113
|
yield `: { `;
|
|
114
114
|
for (const mod of modifiers) {
|
|
115
115
|
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, mod.content, mod.loc.start.offset, codeFeatures_1.codeFeatures.withoutHighlight);
|
|
@@ -122,9 +122,9 @@ function* generateValue(options, ctx, prop) {
|
|
|
122
122
|
if (exp?.type !== CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
123
123
|
return;
|
|
124
124
|
}
|
|
125
|
-
const
|
|
125
|
+
const boundary = yield* boundary_1.Boundary.start('template', exp.loc.start.offset, codeFeatures_1.codeFeatures.verification);
|
|
126
126
|
yield `value`;
|
|
127
|
-
yield
|
|
127
|
+
yield boundary.end(exp.loc.end.offset);
|
|
128
128
|
yield `: `;
|
|
129
129
|
yield* (0, elementProps_1.generatePropExp)(options, ctx, prop, exp);
|
|
130
130
|
}
|
|
@@ -40,9 +40,10 @@ exports.generateModelEventExpression = generateModelEventExpression;
|
|
|
40
40
|
exports.isCompoundExpression = isCompoundExpression;
|
|
41
41
|
const CompilerDOM = __importStar(require("@vue/compiler-dom"));
|
|
42
42
|
const shared_1 = require("@vue/shared");
|
|
43
|
+
const utils_1 = require("../../parsers/utils");
|
|
43
44
|
const codeFeatures_1 = require("../codeFeatures");
|
|
44
45
|
const names_1 = require("../names");
|
|
45
|
-
const
|
|
46
|
+
const utils_2 = require("../utils");
|
|
46
47
|
const boundary_1 = require("../utils/boundary");
|
|
47
48
|
const camelized_1 = require("../utils/camelized");
|
|
48
49
|
const interpolation_1 = require("./interpolation");
|
|
@@ -94,14 +95,14 @@ function* generateElementEvents(options, ctx, node, componentOriginalVar, getCtx
|
|
|
94
95
|
return;
|
|
95
96
|
}
|
|
96
97
|
const emitsVar = ctx.getInternalVariable();
|
|
97
|
-
yield `let ${emitsVar}!: ${names_1.names.ResolveEmits}<typeof ${componentOriginalVar}, typeof ${getCtxVar()}.emit>${
|
|
98
|
+
yield `let ${emitsVar}!: ${names_1.names.ResolveEmits}<typeof ${componentOriginalVar}, typeof ${getCtxVar()}.emit>${utils_2.endOfLine}`;
|
|
98
99
|
for (const { propPrefix, emitPrefix, propName, emitName, items } of Object.values(definitions)) {
|
|
99
|
-
yield `const ${ctx.getInternalVariable()}: ${names_1.names.ResolveEvent}<typeof ${getPropsVar()}, typeof ${emitsVar}, '${propName}', '${emitName}', '${(0, shared_1.camelize)(emitName)}'> = {${
|
|
100
|
+
yield `const ${ctx.getInternalVariable()}: ${names_1.names.ResolveEvent}<typeof ${getPropsVar()}, typeof ${emitsVar}, '${propName}', '${emitName}', '${(0, shared_1.camelize)(emitName)}'> = {${utils_2.newLine}`;
|
|
100
101
|
for (const { prop, source, offset } of items) {
|
|
101
102
|
if (prop.name === 'on') {
|
|
102
103
|
yield `/** @type {typeof ${emitsVar}.`;
|
|
103
104
|
yield* generateEventArg(options, source, offset, emitPrefix.slice(0, -1), codeFeatures_1.codeFeatures.navigation);
|
|
104
|
-
yield `} */${
|
|
105
|
+
yield `} */${utils_2.newLine}`;
|
|
105
106
|
}
|
|
106
107
|
if (prop.name === 'on') {
|
|
107
108
|
yield* generateEventArg(options, source, offset, propPrefix.slice(0, -1));
|
|
@@ -112,9 +113,9 @@ function* generateElementEvents(options, ctx, node, componentOriginalVar, getCtx
|
|
|
112
113
|
yield `'${propName}': `;
|
|
113
114
|
yield* generateModelEventExpression(options, ctx, prop);
|
|
114
115
|
}
|
|
115
|
-
yield `,${
|
|
116
|
+
yield `,${utils_2.newLine}`;
|
|
116
117
|
}
|
|
117
|
-
yield `}${
|
|
118
|
+
yield `}${utils_2.endOfLine}`;
|
|
118
119
|
}
|
|
119
120
|
}
|
|
120
121
|
function* generateEventArg(options, name, start, directive = 'on', features) {
|
|
@@ -128,33 +129,40 @@ function* generateEventArg(options, name, start, directive = 'on', features) {
|
|
|
128
129
|
if (directive.length) {
|
|
129
130
|
name = (0, shared_1.capitalize)(name);
|
|
130
131
|
}
|
|
131
|
-
if (
|
|
132
|
-
const
|
|
132
|
+
if (utils_2.identifierRE.test((0, shared_1.camelize)(name))) {
|
|
133
|
+
const boundary = yield* boundary_1.Boundary.start('template', start, features);
|
|
133
134
|
yield directive;
|
|
134
|
-
yield* (0, camelized_1.generateCamelized)(name, 'template', start,
|
|
135
|
+
yield* (0, camelized_1.generateCamelized)(name, 'template', start, boundary.features);
|
|
135
136
|
}
|
|
136
137
|
else {
|
|
137
|
-
const
|
|
138
|
+
const boundary = yield* boundary_1.Boundary.start('template', start, features);
|
|
138
139
|
yield `'`;
|
|
139
140
|
yield directive;
|
|
140
|
-
yield* (0, camelized_1.generateCamelized)(name, 'template', start,
|
|
141
|
+
yield* (0, camelized_1.generateCamelized)(name, 'template', start, boundary.features);
|
|
141
142
|
yield `'`;
|
|
142
|
-
yield
|
|
143
|
+
yield boundary.end(start + name.length);
|
|
143
144
|
}
|
|
144
145
|
}
|
|
145
146
|
function* generateEventExpression(options, ctx, prop) {
|
|
146
147
|
if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
147
|
-
const ast = (0,
|
|
148
|
+
const ast = (0, utils_2.getTypeScriptAST)(options.typescript, options.template, prop.exp.content);
|
|
148
149
|
const isCompound = isCompoundExpression(options.typescript, ast);
|
|
149
150
|
const interpolation = (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, prop.exp.content, prop.exp.loc.start.offset, isCompound ? `` : `(`, isCompound ? `` : `)`);
|
|
150
151
|
if (isCompound) {
|
|
151
|
-
yield `(...[$event]) => {${
|
|
152
|
-
const
|
|
153
|
-
|
|
152
|
+
yield `(...[$event]) => {${utils_2.newLine}`;
|
|
153
|
+
const scope = ctx.scope();
|
|
154
|
+
scope.declare('$event');
|
|
154
155
|
yield* ctx.generateConditionGuards();
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
156
|
+
if (isSingleExpression(options.typescript, ast)) {
|
|
157
|
+
yield `return (`;
|
|
158
|
+
yield* interpolation;
|
|
159
|
+
yield `)`;
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
yield* interpolation;
|
|
163
|
+
}
|
|
164
|
+
yield utils_2.endOfLine;
|
|
165
|
+
yield* scope.end();
|
|
158
166
|
yield `}`;
|
|
159
167
|
ctx.inlayHints.push({
|
|
160
168
|
blockName: 'template',
|
|
@@ -179,10 +187,10 @@ function* generateEventExpression(options, ctx, prop) {
|
|
|
179
187
|
}
|
|
180
188
|
function* generateModelEventExpression(options, ctx, prop) {
|
|
181
189
|
if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
182
|
-
yield `(...[$event]) => {${
|
|
190
|
+
yield `(...[$event]) => {${utils_2.newLine}`;
|
|
183
191
|
yield* ctx.generateConditionGuards();
|
|
184
192
|
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.verification, prop.exp.content, prop.exp.loc.start.offset);
|
|
185
|
-
yield ` = $event${
|
|
193
|
+
yield ` = $event${utils_2.endOfLine}`;
|
|
186
194
|
yield `}`;
|
|
187
195
|
}
|
|
188
196
|
else {
|
|
@@ -190,35 +198,32 @@ function* generateModelEventExpression(options, ctx, prop) {
|
|
|
190
198
|
}
|
|
191
199
|
}
|
|
192
200
|
function isCompoundExpression(ts, ast) {
|
|
193
|
-
let result = true;
|
|
194
201
|
if (ast.statements.length === 0) {
|
|
195
|
-
|
|
202
|
+
return false;
|
|
196
203
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
else if (ts.isFunctionDeclaration(child_1)) {
|
|
210
|
-
result = false;
|
|
204
|
+
if (ast.statements.length === 1 && ast.text[ast.endOfFileToken.pos - 1] !== ';') {
|
|
205
|
+
const statement = ast.statements[0];
|
|
206
|
+
if (ts.isExpressionStatement(statement)) {
|
|
207
|
+
const node = (0, utils_1.getUnwrappedExpression)(ts, statement.expression);
|
|
208
|
+
if (ts.isArrowFunction(node)
|
|
209
|
+
|| ts.isIdentifier(node)
|
|
210
|
+
|| ts.isElementAccessExpression(node)
|
|
211
|
+
|| ts.isPropertyAccessExpression(node)) {
|
|
212
|
+
return false;
|
|
211
213
|
}
|
|
212
|
-
}
|
|
214
|
+
}
|
|
215
|
+
else if (ts.isFunctionDeclaration(statement)) {
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
213
218
|
}
|
|
214
|
-
return
|
|
219
|
+
return true;
|
|
215
220
|
}
|
|
216
|
-
function
|
|
217
|
-
if (
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
221
|
+
function isSingleExpression(ts, ast) {
|
|
222
|
+
if (ast.statements.length === 1 && ast.text[ast.endOfFileToken.pos - 1] !== ';') {
|
|
223
|
+
const statement = ast.statements[0];
|
|
224
|
+
if (ts.isExpressionStatement(statement)) {
|
|
225
|
+
return true;
|
|
226
|
+
}
|
|
222
227
|
}
|
|
223
228
|
return false;
|
|
224
229
|
}
|
|
@@ -114,21 +114,21 @@ function* generateElementProps(options, ctx, node, props, checkUnknownProps, fai
|
|
|
114
114
|
if (shouldSpread) {
|
|
115
115
|
yield `...{ `;
|
|
116
116
|
}
|
|
117
|
-
const
|
|
117
|
+
const boundary = yield* boundary_1.Boundary.start('template', prop.loc.start.offset, codeFeatures_1.codeFeatures.verification);
|
|
118
118
|
if (prop.arg) {
|
|
119
119
|
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, propName, prop.arg.loc.start.offset, features, shouldCamelize);
|
|
120
120
|
}
|
|
121
121
|
else {
|
|
122
|
-
const
|
|
122
|
+
const boundary2 = yield* boundary_1.Boundary.start('template', prop.loc.start.offset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
|
|
123
123
|
yield propName;
|
|
124
|
-
yield
|
|
124
|
+
yield boundary2.end(prop.loc.start.offset + 'v-model'.length);
|
|
125
125
|
}
|
|
126
126
|
yield `: `;
|
|
127
127
|
const argLoc = prop.arg?.loc ?? prop.loc;
|
|
128
|
-
const
|
|
128
|
+
const boundary3 = yield* boundary_1.Boundary.start('template', argLoc.start.offset, codeFeatures_1.codeFeatures.verification);
|
|
129
129
|
yield* generatePropExp(options, ctx, prop, prop.exp);
|
|
130
|
-
yield
|
|
131
|
-
yield
|
|
130
|
+
yield boundary3.end(argLoc.end.offset);
|
|
131
|
+
yield boundary.end(prop.loc.end.offset);
|
|
132
132
|
if (shouldSpread) {
|
|
133
133
|
yield ` }`;
|
|
134
134
|
}
|
|
@@ -153,7 +153,7 @@ function* generateElementProps(options, ctx, node, props, checkUnknownProps, fai
|
|
|
153
153
|
if (shouldSpread) {
|
|
154
154
|
yield `...{ `;
|
|
155
155
|
}
|
|
156
|
-
const
|
|
156
|
+
const boundary = yield* boundary_1.Boundary.start('template', prop.loc.start.offset, codeFeatures_1.codeFeatures.verification);
|
|
157
157
|
const prefix = options.template.content.slice(prop.loc.start.offset, prop.loc.start.offset + 1);
|
|
158
158
|
if (prefix === '.' || prefix === '#') {
|
|
159
159
|
// Pug shorthand syntax
|
|
@@ -174,7 +174,7 @@ function* generateElementProps(options, ctx, node, props, checkUnknownProps, fai
|
|
|
174
174
|
else {
|
|
175
175
|
yield `true`;
|
|
176
176
|
}
|
|
177
|
-
yield
|
|
177
|
+
yield boundary.end(prop.loc.end.offset);
|
|
178
178
|
if (shouldSpread) {
|
|
179
179
|
yield ` }`;
|
|
180
180
|
}
|
|
@@ -187,10 +187,10 @@ function* generateElementProps(options, ctx, node, props, checkUnknownProps, fai
|
|
|
187
187
|
failedPropExps?.push({ node: prop.exp, prefix: `(`, suffix: `)` });
|
|
188
188
|
}
|
|
189
189
|
else {
|
|
190
|
-
const
|
|
190
|
+
const boundary = yield* boundary_1.Boundary.start('template', prop.exp.loc.start.offset, codeFeatures_1.codeFeatures.verification);
|
|
191
191
|
yield `...`;
|
|
192
192
|
yield* generatePropExp(options, ctx, prop, prop.exp);
|
|
193
|
-
yield
|
|
193
|
+
yield boundary.end(prop.exp.loc.end.offset);
|
|
194
194
|
yield `,${utils_1.newLine}`;
|
|
195
195
|
}
|
|
196
196
|
}
|
|
@@ -205,7 +205,7 @@ function* generatePropExp(options, ctx, prop, exp) {
|
|
|
205
205
|
}
|
|
206
206
|
else {
|
|
207
207
|
const propVariableName = (0, shared_1.camelize)(exp.loc.source);
|
|
208
|
-
if (utils_1.
|
|
208
|
+
if (utils_1.identifierRE.test(propVariableName)) {
|
|
209
209
|
const codes = (0, camelized_1.generateCamelized)(exp.loc.source, 'template', exp.loc.start.offset, {
|
|
210
210
|
...codeFeatures_1.codeFeatures.withoutHighlightAndCompletion,
|
|
211
211
|
__shorthandExpression: 'html',
|
|
@@ -218,7 +218,7 @@ function* generatePropExp(options, ctx, prop, exp) {
|
|
|
218
218
|
yield `.value`;
|
|
219
219
|
}
|
|
220
220
|
else {
|
|
221
|
-
ctx.
|
|
221
|
+
ctx.accessVariable('template', propVariableName, exp.loc.start.offset);
|
|
222
222
|
yield names_1.names.ctx;
|
|
223
223
|
yield `.`;
|
|
224
224
|
yield* codes;
|
|
@@ -14,8 +14,7 @@ export interface TemplateCodegenOptions {
|
|
|
14
14
|
}
|
|
15
15
|
export { generate as generateTemplate };
|
|
16
16
|
declare function generate(options: TemplateCodegenOptions): {
|
|
17
|
-
|
|
18
|
-
currentInfo: {
|
|
17
|
+
getCommentInfo: () => {
|
|
19
18
|
ignoreError?: boolean;
|
|
20
19
|
expectError?: {
|
|
21
20
|
token: number;
|
|
@@ -26,41 +25,70 @@ declare function generate(options: TemplateCodegenOptions): {
|
|
|
26
25
|
offset: number;
|
|
27
26
|
};
|
|
28
27
|
};
|
|
28
|
+
enter: (node: import("@vue/compiler-dom").RootNode | import("@vue/compiler-dom").TemplateChildNode | import("@vue/compiler-dom").SimpleExpressionNode) => boolean;
|
|
29
|
+
exit: () => Generator<Code>;
|
|
29
30
|
resolveCodeFeatures: (features: import("../../types").VueCodeInformation) => import("../../types").VueCodeInformation;
|
|
30
|
-
|
|
31
|
+
getInternalVariable: () => string;
|
|
32
|
+
scopes: {
|
|
33
|
+
add(value: string): /*elided*/ any;
|
|
34
|
+
declare(...variables: string[]): void;
|
|
35
|
+
end(): Generator<Code, any, any>;
|
|
36
|
+
clear(): void;
|
|
37
|
+
delete(value: string): boolean;
|
|
38
|
+
forEach(callbackfn: (value: string, value2: string, set: Set<string>) => void, thisArg?: any): void;
|
|
39
|
+
has(value: string): boolean;
|
|
40
|
+
readonly size: number;
|
|
41
|
+
[Symbol.iterator](): SetIterator<string>;
|
|
42
|
+
entries(): SetIterator<[string, string]>;
|
|
43
|
+
keys(): SetIterator<string>;
|
|
44
|
+
values(): SetIterator<string>;
|
|
45
|
+
readonly [Symbol.toStringTag]: string;
|
|
46
|
+
}[];
|
|
47
|
+
scope: () => {
|
|
48
|
+
add(value: string): any;
|
|
49
|
+
declare(...variables: string[]): void;
|
|
50
|
+
end(): Generator<Code, any, any>;
|
|
51
|
+
clear(): void;
|
|
52
|
+
delete(value: string): boolean;
|
|
53
|
+
forEach(callbackfn: (value: string, value2: string, set: Set<string>) => void, thisArg?: any): void;
|
|
54
|
+
has(value: string): boolean;
|
|
55
|
+
readonly size: number;
|
|
56
|
+
[Symbol.iterator](): SetIterator<string>;
|
|
57
|
+
entries(): SetIterator<[string, string]>;
|
|
58
|
+
keys(): SetIterator<string>;
|
|
59
|
+
values(): SetIterator<string>;
|
|
60
|
+
readonly [Symbol.toStringTag]: string;
|
|
61
|
+
};
|
|
62
|
+
contextAccesses: Map<string, Map<string, Set<number>>>;
|
|
63
|
+
accessVariable: (source: string, name: string, offset?: number) => void;
|
|
64
|
+
generateAutoImport: () => Generator<Code>;
|
|
65
|
+
conditions: string[];
|
|
66
|
+
generateConditionGuards: () => Generator<string, void, unknown>;
|
|
67
|
+
hoistVars: Map<string, string>;
|
|
68
|
+
getHoistVariable: (originalVar: string) => string;
|
|
69
|
+
generateHoistVariables: () => Generator<string, void, unknown>;
|
|
70
|
+
templateRefs: Map<string, {
|
|
71
|
+
typeExp: string;
|
|
72
|
+
offset: number;
|
|
73
|
+
}[]>;
|
|
74
|
+
addTemplateRef: (name: string, typeExp: string, offset: number) => void;
|
|
75
|
+
components: (() => string)[];
|
|
76
|
+
dollarVars: Set<string>;
|
|
77
|
+
inlayHints: import("../inlayHints").InlayHintInfo[];
|
|
78
|
+
generatedTypes: Set<string>;
|
|
79
|
+
inheritedAttrVars: Set<string>;
|
|
80
|
+
singleRootElTypes: Set<string>;
|
|
81
|
+
singleRootNodes: Set<import("@vue/compiler-dom").ElementNode | null>;
|
|
31
82
|
slots: {
|
|
32
83
|
name: string;
|
|
33
84
|
offset?: number;
|
|
34
85
|
tagRange: [number, number];
|
|
35
|
-
nodeLoc: any;
|
|
36
86
|
propsVar: string;
|
|
37
87
|
}[];
|
|
38
88
|
dynamicSlots: {
|
|
39
89
|
expVar: string;
|
|
40
90
|
propsVar: string;
|
|
41
91
|
}[];
|
|
42
|
-
|
|
43
|
-
componentAccessMap: Map<string, Map<string, Set<number>>>;
|
|
44
|
-
blockConditions: string[];
|
|
45
|
-
inlayHints: import("../inlayHints").InlayHintInfo[];
|
|
46
|
-
inheritedAttrVars: Set<string>;
|
|
47
|
-
templateRefs: Map<string, {
|
|
48
|
-
typeExp: string;
|
|
49
|
-
offset: number;
|
|
50
|
-
}[]>;
|
|
51
|
-
singleRootElTypes: Set<string>;
|
|
52
|
-
singleRootNodes: Set<import("@vue/compiler-dom").ElementNode | null>;
|
|
53
|
-
addTemplateRef(name: string, typeExp: string, offset: number): void;
|
|
54
|
-
recordComponentAccess(source: string, name: string, offset?: number): void;
|
|
55
|
-
scopes: Set<string>[];
|
|
56
|
-
components: (() => string)[];
|
|
57
|
-
declare(...varNames: string[]): void;
|
|
58
|
-
startScope(): () => Generator<Code, any, any>;
|
|
59
|
-
getInternalVariable(): string;
|
|
60
|
-
getHoistVariable(originalVar: string): string;
|
|
61
|
-
generateHoistVariables(): Generator<string, void, unknown>;
|
|
62
|
-
generateConditionGuards(): Generator<string, void, unknown>;
|
|
63
|
-
enter(node: import("@vue/compiler-dom").RootNode | import("@vue/compiler-dom").TemplateChildNode | import("@vue/compiler-dom").SimpleExpressionNode): boolean;
|
|
64
|
-
exit(): Generator<Code>;
|
|
92
|
+
inVFor: boolean;
|
|
65
93
|
codes: Code[];
|
|
66
94
|
};
|