@vue/language-core 3.2.6 → 3.2.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/index.d.ts +1 -1
- package/index.js +3 -24
- package/lib/codegen/codeFeatures.d.ts +84 -18
- package/lib/codegen/names.d.ts +73 -26
- package/lib/codegen/names.js +75 -27
- package/lib/codegen/script/component.js +19 -58
- package/lib/codegen/script/index.js +12 -12
- package/lib/codegen/script/scriptSetup.js +48 -81
- package/lib/codegen/script/template.js +29 -63
- package/lib/codegen/style/index.d.ts +7 -7
- package/lib/codegen/style/modules.js +4 -37
- package/lib/codegen/style/scopedClasses.js +2 -1
- package/lib/codegen/template/context.d.ts +7 -7
- package/lib/codegen/template/element.js +28 -25
- package/lib/codegen/template/elementDirectives.js +4 -4
- package/lib/codegen/template/elementEvents.js +3 -2
- package/lib/codegen/template/elementProps.js +3 -3
- package/lib/codegen/template/index.d.ts +7 -7
- package/lib/codegen/template/index.js +16 -49
- package/lib/codegen/template/interpolation.js +3 -36
- package/lib/codegen/template/objectProperty.js +2 -1
- package/lib/codegen/template/slotOutlet.js +5 -5
- package/lib/codegen/template/styleScopedClasses.js +3 -2
- package/lib/codegen/template/vFor.js +2 -1
- package/lib/codegen/template/vSlot.js +2 -1
- package/lib/compilerOptions.js +2 -6
- package/lib/parsers/scriptRanges.d.ts +3 -3
- package/lib/plugins/file-md.js +2 -2
- package/lib/plugins/vue-tsx.d.ts +10 -10
- package/lib/plugins/vue-tsx.js +5 -22
- package/lib/types.d.ts +1 -1
- package/lib/utils/shared.js +1 -1
- package/lib/virtualCode/embeddedCodes.js +2 -6
- package/lib/virtualCode/index.js +1 -10
- package/package.json +9 -6
- package/scripts/generate-names.js +41 -0
|
@@ -41,7 +41,7 @@ const muggle_string_1 = require("muggle-string");
|
|
|
41
41
|
const shared_2 = require("../../utils/shared");
|
|
42
42
|
const codeFeatures_1 = require("../codeFeatures");
|
|
43
43
|
const inlayHints_1 = require("../inlayHints");
|
|
44
|
-
const
|
|
44
|
+
const names_1 = require("../names");
|
|
45
45
|
const utils_1 = require("../utils");
|
|
46
46
|
const boundary_1 = require("../utils/boundary");
|
|
47
47
|
const camelized_1 = require("../utils/camelized");
|
|
@@ -114,9 +114,9 @@ function* generateComponent(options, ctx, node) {
|
|
|
114
114
|
yield utils_1.endOfLine;
|
|
115
115
|
}
|
|
116
116
|
else {
|
|
117
|
-
yield `let ${componentVar}!:
|
|
117
|
+
yield `let ${componentVar}!: ${names_1.names.WithComponent}<'${tag}', ${names_1.names.LocalComponents}, ${names_1.names.GlobalComponents}`;
|
|
118
118
|
yield originalNames.has(options.componentName)
|
|
119
|
-
? `, typeof ${names.
|
|
119
|
+
? `, typeof ${names_1.names.export}`
|
|
120
120
|
: `, void`;
|
|
121
121
|
for (const name of originalNames) {
|
|
122
122
|
yield `, '${name}'`;
|
|
@@ -131,18 +131,21 @@ function* generateComponent(options, ctx, node) {
|
|
|
131
131
|
yield `]${utils_1.endOfLine}`;
|
|
132
132
|
if (utils_1.identifierRegex.test((0, shared_1.camelize)(tag))) {
|
|
133
133
|
// navigation support
|
|
134
|
-
yield `/** @ts-ignore @type {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
yield ` | typeof ${names.components}.`;
|
|
142
|
-
yield* (0, camelized_1.generateCamelized)(tag, 'template', endTagOffset, codeFeatures_1.codeFeatures.navigation);
|
|
134
|
+
yield `/** @ts-ignore @type {`;
|
|
135
|
+
for (const offset of [startTagOffset, endTagOffset]) {
|
|
136
|
+
if (offset === undefined) {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
yield ` | typeof ${names_1.names.components}.`;
|
|
140
|
+
yield* (0, camelized_1.generateCamelized)(tag, 'template', offset, codeFeatures_1.codeFeatures.navigation);
|
|
143
141
|
if (tag[0] !== tag[0].toUpperCase()) {
|
|
144
|
-
yield ` | typeof ${names.components}.`;
|
|
145
|
-
yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(tag), 'template',
|
|
142
|
+
yield ` | typeof ${names_1.names.components}.`;
|
|
143
|
+
yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(tag), 'template', offset, codeFeatures_1.codeFeatures.navigation);
|
|
144
|
+
}
|
|
145
|
+
if (tag.includes('-')) {
|
|
146
|
+
yield ` | typeof ${names_1.names.components}[`;
|
|
147
|
+
yield* (0, stringLiteralKey_1.generateStringLiteralKey)(tag, offset, codeFeatures_1.codeFeatures.navigation);
|
|
148
|
+
yield `]`;
|
|
146
149
|
}
|
|
147
150
|
}
|
|
148
151
|
yield `} */${utils_1.newLine}`;
|
|
@@ -163,16 +166,16 @@ function* generateComponentBody(options, ctx, node, tag, tagOffset, props, compo
|
|
|
163
166
|
const failGeneratedExpressions = [];
|
|
164
167
|
const propCodes = [...(0, elementProps_1.generateElementProps)(options, ctx, node, props, options.vueCompilerOptions.checkUnknownProps, failGeneratedExpressions)];
|
|
165
168
|
const functionalVar = ctx.getInternalVariable();
|
|
166
|
-
const
|
|
169
|
+
const vnodeVar = ctx.getInternalVariable();
|
|
167
170
|
const ctxVar = ctx.getInternalVariable();
|
|
168
171
|
const propsVar = ctx.getInternalVariable();
|
|
169
172
|
yield `// @ts-ignore${utils_1.newLine}`;
|
|
170
|
-
yield `const ${functionalVar} = ${options.vueCompilerOptions.checkUnknownProps ?
|
|
173
|
+
yield `const ${functionalVar} = ${options.vueCompilerOptions.checkUnknownProps ? names_1.names.asFunctionalComponent0 : names_1.names.asFunctionalComponent1}(${componentVar}, new ${componentVar}({${utils_1.newLine}`;
|
|
171
174
|
yield (0, muggle_string_1.toString)(propCodes);
|
|
172
175
|
yield `}))${utils_1.endOfLine}`;
|
|
173
176
|
yield `const `;
|
|
174
177
|
const token = yield* (0, boundary_1.startBoundary)('template', node.loc.start.offset, codeFeatures_1.codeFeatures.doNotReportTs6133);
|
|
175
|
-
yield
|
|
178
|
+
yield vnodeVar;
|
|
176
179
|
yield (0, boundary_1.endBoundary)(token, node.loc.end.offset);
|
|
177
180
|
yield ` = ${functionalVar}`;
|
|
178
181
|
if (ctx.currentInfo.generic) {
|
|
@@ -189,7 +192,7 @@ function* generateComponentBody(options, ctx, node, tag, tagOffset, props, compo
|
|
|
189
192
|
yield* propCodes;
|
|
190
193
|
yield `}`;
|
|
191
194
|
yield (0, boundary_1.endBoundary)(token2, tagOffset + tag.length);
|
|
192
|
-
yield `,
|
|
195
|
+
yield `, ...${names_1.names.functionalComponentArgsRest}(${functionalVar}))${utils_1.endOfLine}`;
|
|
193
196
|
yield* generateFailedExpressions(options, ctx, failGeneratedExpressions);
|
|
194
197
|
yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, componentVar, getCtxVar, getPropsVar);
|
|
195
198
|
yield* (0, elementDirectives_1.generateElementDirectives)(options, ctx, node);
|
|
@@ -220,21 +223,21 @@ function* generateComponentBody(options, ctx, node, tag, tagOffset, props, compo
|
|
|
220
223
|
yield* (0, vSlot_1.generateVSlot)(options, ctx, node, slotDir, getCtxVar());
|
|
221
224
|
}
|
|
222
225
|
if (isCtxVarUsed) {
|
|
223
|
-
yield `var ${ctxVar}!:
|
|
226
|
+
yield `var ${ctxVar}!: ${names_1.names.FunctionalComponentCtx}<typeof ${componentVar}, typeof ${vnodeVar}>${utils_1.endOfLine}`;
|
|
224
227
|
}
|
|
225
228
|
if (isPropsVarUsed) {
|
|
226
|
-
yield `var ${propsVar}!:
|
|
229
|
+
yield `var ${propsVar}!: ${names_1.names.FunctionalComponentProps}<typeof ${componentVar}, typeof ${vnodeVar}>${utils_1.endOfLine}`;
|
|
227
230
|
}
|
|
228
231
|
ctx.components.pop();
|
|
229
232
|
}
|
|
230
233
|
function* generateElement(options, ctx, node) {
|
|
231
234
|
const [startTagOffset, endTagOffset] = (0, shared_2.getElementTagOffsets)(node, options.template);
|
|
232
235
|
const failedPropExps = [];
|
|
233
|
-
yield `${options.vueCompilerOptions.checkUnknownProps ?
|
|
236
|
+
yield `${options.vueCompilerOptions.checkUnknownProps ? names_1.names.asFunctionalElement0 : names_1.names.asFunctionalElement1}(${names_1.names.intrinsics}`;
|
|
234
237
|
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, startTagOffset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
|
|
235
238
|
if (endTagOffset !== undefined) {
|
|
236
239
|
yield `, `;
|
|
237
|
-
yield names.intrinsics;
|
|
240
|
+
yield names_1.names.intrinsics;
|
|
238
241
|
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, endTagOffset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
|
|
239
242
|
}
|
|
240
243
|
yield `)(`;
|
|
@@ -248,17 +251,17 @@ function* generateElement(options, ctx, node) {
|
|
|
248
251
|
yield* (0, elementDirectives_1.generateElementDirectives)(options, ctx, node);
|
|
249
252
|
const templateRef = getTemplateRef(node);
|
|
250
253
|
if (templateRef) {
|
|
251
|
-
let typeExp =
|
|
254
|
+
let typeExp = `${names_1.names.Elements}['${node.tag}']`;
|
|
252
255
|
if (ctx.inVFor) {
|
|
253
256
|
typeExp += `[]`;
|
|
254
257
|
}
|
|
255
258
|
ctx.addTemplateRef(templateRef[0], typeExp, templateRef[1]);
|
|
256
259
|
}
|
|
257
260
|
if (ctx.singleRootNodes.has(node)) {
|
|
258
|
-
ctx.singleRootElTypes.add(
|
|
261
|
+
ctx.singleRootElTypes.add(`${names_1.names.Elements}['${node.tag}']`);
|
|
259
262
|
}
|
|
260
263
|
if (hasVBindAttrs(options, ctx, node)) {
|
|
261
|
-
ctx.inheritedAttrVars.add(
|
|
264
|
+
ctx.inheritedAttrVars.add(`${names_1.names.intrinsics}.${node.tag}`);
|
|
262
265
|
}
|
|
263
266
|
yield* generateStyleScopedClassReferences(options, node);
|
|
264
267
|
for (const child of node.children) {
|
|
@@ -38,7 +38,7 @@ exports.generateModifiers = generateModifiers;
|
|
|
38
38
|
const CompilerDOM = __importStar(require("@vue/compiler-dom"));
|
|
39
39
|
const shared_1 = require("@vue/shared");
|
|
40
40
|
const codeFeatures_1 = require("../codeFeatures");
|
|
41
|
-
const
|
|
41
|
+
const names_1 = require("../names");
|
|
42
42
|
const utils_1 = require("../utils");
|
|
43
43
|
const boundary_1 = require("../utils/boundary");
|
|
44
44
|
const camelized_1 = require("../utils/camelized");
|
|
@@ -56,9 +56,9 @@ function* generateElementDirectives(options, ctx, node) {
|
|
|
56
56
|
continue;
|
|
57
57
|
}
|
|
58
58
|
const token = yield* (0, boundary_1.startBoundary)('template', prop.loc.start.offset, codeFeatures_1.codeFeatures.verification);
|
|
59
|
-
yield
|
|
59
|
+
yield `${names_1.names.asFunctionalDirective}(`;
|
|
60
60
|
yield* generateIdentifier(options, ctx, prop);
|
|
61
|
-
yield `, {} as import('${options.vueCompilerOptions.lib}').ObjectDirective)(null!, {
|
|
61
|
+
yield `, {} as import('${options.vueCompilerOptions.lib}').ObjectDirective)(null!, { ...${names_1.names.directiveBindingRestFields}, `;
|
|
62
62
|
yield* generateArg(options, ctx, prop);
|
|
63
63
|
yield* generateModifiers(options, ctx, prop);
|
|
64
64
|
yield* generateValue(options, ctx, prop);
|
|
@@ -71,7 +71,7 @@ function* generateIdentifier(options, ctx, prop) {
|
|
|
71
71
|
const rawName = 'v-' + prop.name;
|
|
72
72
|
const startOffset = prop.loc.start.offset;
|
|
73
73
|
const token = yield* (0, boundary_1.startBoundary)('template', startOffset, codeFeatures_1.codeFeatures.verification);
|
|
74
|
-
yield names.directives;
|
|
74
|
+
yield names_1.names.directives;
|
|
75
75
|
yield `.`;
|
|
76
76
|
yield* (0, camelized_1.generateCamelized)(rawName, 'template', prop.loc.start.offset, {
|
|
77
77
|
...codeFeatures_1.codeFeatures.withoutHighlightAndCompletion,
|
|
@@ -41,6 +41,7 @@ exports.isCompoundExpression = isCompoundExpression;
|
|
|
41
41
|
const CompilerDOM = __importStar(require("@vue/compiler-dom"));
|
|
42
42
|
const shared_1 = require("@vue/shared");
|
|
43
43
|
const codeFeatures_1 = require("../codeFeatures");
|
|
44
|
+
const names_1 = require("../names");
|
|
44
45
|
const utils_1 = require("../utils");
|
|
45
46
|
const boundary_1 = require("../utils/boundary");
|
|
46
47
|
const camelized_1 = require("../utils/camelized");
|
|
@@ -56,7 +57,7 @@ function* generateElementEvents(options, ctx, node, componentOriginalVar, getCtx
|
|
|
56
57
|
&& (!prop.arg || prop.arg.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic))) {
|
|
57
58
|
if (!emitsVar) {
|
|
58
59
|
emitsVar = ctx.getInternalVariable();
|
|
59
|
-
yield `let ${emitsVar}!:
|
|
60
|
+
yield `let ${emitsVar}!: ${names_1.names.ResolveEmits}<typeof ${componentOriginalVar}, typeof ${getCtxVar()}.emit>${utils_1.endOfLine}`;
|
|
60
61
|
}
|
|
61
62
|
let source = prop.arg?.loc.source ?? 'model-value';
|
|
62
63
|
let start = prop.arg?.loc.start.offset;
|
|
@@ -75,7 +76,7 @@ function* generateElementEvents(options, ctx, node, componentOriginalVar, getCtx
|
|
|
75
76
|
const propName = (0, shared_1.camelize)(propPrefix + source);
|
|
76
77
|
const emitName = emitPrefix + source;
|
|
77
78
|
const camelizedEmitName = (0, shared_1.camelize)(emitName);
|
|
78
|
-
yield `const ${ctx.getInternalVariable()}:
|
|
79
|
+
yield `const ${ctx.getInternalVariable()}: ${names_1.names.NormalizeComponentEvent}<typeof ${getPropsVar()}, typeof ${emitsVar}, '${propName}', '${emitName}', '${camelizedEmitName}'> = (${utils_1.newLine}`;
|
|
79
80
|
if (prop.name === 'on') {
|
|
80
81
|
yield `{ `;
|
|
81
82
|
yield* generateEventArg(options, source, start, emitPrefix.slice(0, -1), codeFeatures_1.codeFeatures.navigation);
|
|
@@ -41,7 +41,7 @@ const picomatch_1 = require("picomatch");
|
|
|
41
41
|
const shared_2 = require("../../utils/shared");
|
|
42
42
|
const codeFeatures_1 = require("../codeFeatures");
|
|
43
43
|
const inlayHints_1 = require("../inlayHints");
|
|
44
|
-
const
|
|
44
|
+
const names_1 = require("../names");
|
|
45
45
|
const utils_1 = require("../utils");
|
|
46
46
|
const boundary_1 = require("../utils/boundary");
|
|
47
47
|
const camelized_1 = require("../utils/camelized");
|
|
@@ -136,7 +136,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, fail
|
|
|
136
136
|
if (isComponent && prop.name === 'model' && prop.modifiers.length) {
|
|
137
137
|
const propertyName = prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
138
138
|
? !prop.arg.isStatic
|
|
139
|
-
? `[
|
|
139
|
+
? `[${names_1.names.tryAsConstant}(\`\${${prop.arg.content}}Modifiers\`)]`
|
|
140
140
|
: (0, shared_1.camelize)(propName) + `Modifiers`
|
|
141
141
|
: `modelModifiers`;
|
|
142
142
|
yield* (0, elementDirectives_1.generateModifiers)(options, ctx, prop, propertyName);
|
|
@@ -219,7 +219,7 @@ function* generatePropExp(options, ctx, prop, exp) {
|
|
|
219
219
|
}
|
|
220
220
|
else {
|
|
221
221
|
ctx.recordComponentAccess('template', propVariableName, exp.loc.start.offset);
|
|
222
|
-
yield names.ctx;
|
|
222
|
+
yield names_1.names.ctx;
|
|
223
223
|
yield `.`;
|
|
224
224
|
yield* codes;
|
|
225
225
|
}
|
|
@@ -16,21 +16,21 @@ export { generate as generateTemplate };
|
|
|
16
16
|
declare function generate(options: TemplateCodegenOptions): {
|
|
17
17
|
generatedTypes: Set<string>;
|
|
18
18
|
currentInfo: {
|
|
19
|
-
ignoreError?: boolean
|
|
19
|
+
ignoreError?: boolean;
|
|
20
20
|
expectError?: {
|
|
21
21
|
token: number;
|
|
22
22
|
node: import("@vue/compiler-dom").CommentNode;
|
|
23
|
-
}
|
|
23
|
+
};
|
|
24
24
|
generic?: {
|
|
25
25
|
content: string;
|
|
26
26
|
offset: number;
|
|
27
|
-
}
|
|
27
|
+
};
|
|
28
28
|
};
|
|
29
29
|
resolveCodeFeatures: (features: import("../../types").VueCodeInformation) => import("../../types").VueCodeInformation;
|
|
30
30
|
inVFor: boolean;
|
|
31
31
|
slots: {
|
|
32
32
|
name: string;
|
|
33
|
-
offset?: number
|
|
33
|
+
offset?: number;
|
|
34
34
|
tagRange: [number, number];
|
|
35
35
|
nodeLoc: any;
|
|
36
36
|
propsVar: string;
|
|
@@ -51,7 +51,7 @@ declare function generate(options: TemplateCodegenOptions): {
|
|
|
51
51
|
singleRootElTypes: Set<string>;
|
|
52
52
|
singleRootNodes: Set<import("@vue/compiler-dom").ElementNode | null>;
|
|
53
53
|
addTemplateRef(name: string, typeExp: string, offset: number): void;
|
|
54
|
-
recordComponentAccess(source: string, name: string, offset?: number
|
|
54
|
+
recordComponentAccess(source: string, name: string, offset?: number): void;
|
|
55
55
|
scopes: Set<string>[];
|
|
56
56
|
components: (() => string)[];
|
|
57
57
|
declare(...varNames: string[]): void;
|
|
@@ -60,7 +60,7 @@ declare function generate(options: TemplateCodegenOptions): {
|
|
|
60
60
|
getHoistVariable(originalVar: string): string;
|
|
61
61
|
generateHoistVariables(): Generator<string, void, unknown>;
|
|
62
62
|
generateConditionGuards(): Generator<string, void, unknown>;
|
|
63
|
-
enter(node: import("@vue/compiler-dom").RootNode | import("@vue/compiler-dom").
|
|
64
|
-
exit(): Generator<Code
|
|
63
|
+
enter(node: import("@vue/compiler-dom").RootNode | import("@vue/compiler-dom").TemplateChildNode | import("@vue/compiler-dom").SimpleExpressionNode): boolean;
|
|
64
|
+
exit(): Generator<Code>;
|
|
65
65
|
codes: Code[];
|
|
66
66
|
};
|
|
@@ -1,41 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.generateTemplate = generate;
|
|
37
4
|
const codeFeatures_1 = require("../codeFeatures");
|
|
38
|
-
const
|
|
5
|
+
const names_1 = require("../names");
|
|
39
6
|
const utils_1 = require("../utils");
|
|
40
7
|
const boundary_1 = require("../utils/boundary");
|
|
41
8
|
const context_1 = require("./context");
|
|
@@ -84,24 +51,24 @@ function* generateWorker(options, ctx) {
|
|
|
84
51
|
yield* generateTemplateRefsType(options, ctx);
|
|
85
52
|
yield* generateRootElType(ctx);
|
|
86
53
|
if (ctx.dollarVars.size) {
|
|
87
|
-
yield `var ${names.dollars}!: {${utils_1.newLine}`;
|
|
54
|
+
yield `var ${names_1.names.dollars}!: {${utils_1.newLine}`;
|
|
88
55
|
if (ctx.dollarVars.has('$slots')) {
|
|
89
|
-
const type = ctx.generatedTypes.has(names.Slots) ? names.Slots : `{}`;
|
|
56
|
+
const type = ctx.generatedTypes.has(names_1.names.Slots) ? names_1.names.Slots : `{}`;
|
|
90
57
|
yield `$slots: ${type}${utils_1.endOfLine}`;
|
|
91
58
|
}
|
|
92
59
|
if (ctx.dollarVars.has('$attrs')) {
|
|
93
60
|
yield `$attrs: import('${vueCompilerOptions.lib}').ComponentPublicInstance['$attrs']`;
|
|
94
|
-
if (ctx.generatedTypes.has(names.InheritedAttrs)) {
|
|
95
|
-
yield ` & ${names.InheritedAttrs}`;
|
|
61
|
+
if (ctx.generatedTypes.has(names_1.names.InheritedAttrs)) {
|
|
62
|
+
yield ` & ${names_1.names.InheritedAttrs}`;
|
|
96
63
|
}
|
|
97
64
|
yield utils_1.endOfLine;
|
|
98
65
|
}
|
|
99
66
|
if (ctx.dollarVars.has('$refs')) {
|
|
100
|
-
const type = ctx.generatedTypes.has(names.TemplateRefs) ? names.TemplateRefs : `{}`;
|
|
67
|
+
const type = ctx.generatedTypes.has(names_1.names.TemplateRefs) ? names_1.names.TemplateRefs : `{}`;
|
|
101
68
|
yield `$refs: ${type}${utils_1.endOfLine}`;
|
|
102
69
|
}
|
|
103
70
|
if (ctx.dollarVars.has('$el')) {
|
|
104
|
-
const type = ctx.generatedTypes.has(names.RootEl) ? names.RootEl : `any`;
|
|
71
|
+
const type = ctx.generatedTypes.has(names_1.names.RootEl) ? names_1.names.RootEl : `any`;
|
|
105
72
|
yield `$el: ${type}${utils_1.endOfLine}`;
|
|
106
73
|
}
|
|
107
74
|
yield `} & { [K in keyof import('${vueCompilerOptions.lib}').ComponentPublicInstance]: unknown }${utils_1.endOfLine}`;
|
|
@@ -110,14 +77,14 @@ function* generateWorker(options, ctx) {
|
|
|
110
77
|
}
|
|
111
78
|
function* generateSlotsType(options, ctx) {
|
|
112
79
|
if (options.hasDefineSlots) {
|
|
113
|
-
ctx.generatedTypes.add(names.Slots);
|
|
80
|
+
ctx.generatedTypes.add(names_1.names.Slots);
|
|
114
81
|
return;
|
|
115
82
|
}
|
|
116
83
|
if (!ctx.slots.length && !ctx.dynamicSlots.length) {
|
|
117
84
|
return;
|
|
118
85
|
}
|
|
119
|
-
ctx.generatedTypes.add(names.Slots);
|
|
120
|
-
yield `type ${names.Slots} = {}`;
|
|
86
|
+
ctx.generatedTypes.add(names_1.names.Slots);
|
|
87
|
+
yield `type ${names_1.names.Slots} = {}`;
|
|
121
88
|
for (const { expVar, propsVar } of ctx.dynamicSlots) {
|
|
122
89
|
yield `${utils_1.newLine}& { [K in NonNullable<typeof ${expVar}>]?: (props: typeof ${propsVar}) => any }`;
|
|
123
90
|
}
|
|
@@ -139,16 +106,16 @@ function* generateInheritedAttrsType(ctx) {
|
|
|
139
106
|
if (!ctx.inheritedAttrVars.size) {
|
|
140
107
|
return;
|
|
141
108
|
}
|
|
142
|
-
ctx.generatedTypes.add(names.InheritedAttrs);
|
|
143
|
-
yield `type ${names.InheritedAttrs} = Partial<${[...ctx.inheritedAttrVars].map(name => `typeof ${name}`).join(` & `)}>`;
|
|
109
|
+
ctx.generatedTypes.add(names_1.names.InheritedAttrs);
|
|
110
|
+
yield `type ${names_1.names.InheritedAttrs} = Partial<${[...ctx.inheritedAttrVars].map(name => `typeof ${name}`).join(` & `)}>`;
|
|
144
111
|
yield utils_1.endOfLine;
|
|
145
112
|
}
|
|
146
113
|
function* generateTemplateRefsType(options, ctx) {
|
|
147
114
|
if (!ctx.templateRefs.size) {
|
|
148
115
|
return;
|
|
149
116
|
}
|
|
150
|
-
ctx.generatedTypes.add(names.TemplateRefs);
|
|
151
|
-
yield `type ${names.TemplateRefs} = {}`;
|
|
117
|
+
ctx.generatedTypes.add(names_1.names.TemplateRefs);
|
|
118
|
+
yield `type ${names_1.names.TemplateRefs} = {}`;
|
|
152
119
|
for (const [name, refs] of ctx.templateRefs) {
|
|
153
120
|
yield `${utils_1.newLine}& `;
|
|
154
121
|
if (refs.length >= 2) {
|
|
@@ -173,8 +140,8 @@ function* generateRootElType(ctx) {
|
|
|
173
140
|
if (!ctx.singleRootElTypes.size || ctx.singleRootNodes.has(null)) {
|
|
174
141
|
return;
|
|
175
142
|
}
|
|
176
|
-
ctx.generatedTypes.add(names.RootEl);
|
|
177
|
-
yield `type ${names.RootEl} = `;
|
|
143
|
+
ctx.generatedTypes.add(names_1.names.RootEl);
|
|
144
|
+
yield `type ${names_1.names.RootEl} = `;
|
|
178
145
|
for (const type of ctx.singleRootElTypes) {
|
|
179
146
|
yield `${utils_1.newLine}| ${type}`;
|
|
180
147
|
}
|
|
@@ -1,44 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.generateInterpolation = generateInterpolation;
|
|
37
4
|
const shared_1 = require("@vue/shared");
|
|
38
5
|
const collectBindings_1 = require("../../utils/collectBindings");
|
|
39
6
|
const shared_2 = require("../../utils/shared");
|
|
40
7
|
const codeFeatures_1 = require("../codeFeatures");
|
|
41
|
-
const
|
|
8
|
+
const names_1 = require("../names");
|
|
42
9
|
const utils_1 = require("../utils");
|
|
43
10
|
// https://github.com/vuejs/core/blob/fb0c3ca519f1fccf52049cd6b8db3a67a669afe9/packages/compiler-core/src/transforms/transformExpression.ts#L47
|
|
44
11
|
const isLiteralWhitelisted = /*@__PURE__*/ (0, shared_1.makeMap)('true,false,null,this');
|
|
@@ -95,11 +62,11 @@ function* forEachInterpolationSegment(ts, setupRefs, ctx, block, originalCode, s
|
|
|
95
62
|
else {
|
|
96
63
|
yield ['', offset, 'errorMappingOnly']; // #1205, #1264
|
|
97
64
|
if (ctx.dollarVars.has(name)) {
|
|
98
|
-
yield names.dollars;
|
|
65
|
+
yield names_1.names.dollars;
|
|
99
66
|
}
|
|
100
67
|
else {
|
|
101
68
|
ctx.recordComponentAccess(block.name, name, start - prefix.length + offset);
|
|
102
|
-
yield names.ctx;
|
|
69
|
+
yield names_1.names.ctx;
|
|
103
70
|
}
|
|
104
71
|
yield `.`;
|
|
105
72
|
yield [name, offset, isShorthand ? 'shorthand' : undefined];
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateObjectProperty = generateObjectProperty;
|
|
4
4
|
const shared_1 = require("@vue/shared");
|
|
5
|
+
const names_1 = require("../names");
|
|
5
6
|
const utils_1 = require("../utils");
|
|
6
7
|
const boundary_1 = require("../utils/boundary");
|
|
7
8
|
const camelized_1 = require("../utils/camelized");
|
|
@@ -10,7 +11,7 @@ const interpolation_1 = require("./interpolation");
|
|
|
10
11
|
function* generateObjectProperty(options, ctx, code, offset, features, shouldCamelize = false, shouldBeConstant = false) {
|
|
11
12
|
if (code.startsWith('[') && code.endsWith(']')) {
|
|
12
13
|
if (shouldBeConstant) {
|
|
13
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, features, code.slice(1, -1), offset + 1, `[
|
|
14
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, features, code.slice(1, -1), offset + 1, `[${names_1.names.tryAsConstant}(`, `)]`);
|
|
14
15
|
}
|
|
15
16
|
else {
|
|
16
17
|
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, features, code, offset);
|
|
@@ -38,7 +38,7 @@ const CompilerDOM = __importStar(require("@vue/compiler-dom"));
|
|
|
38
38
|
const shared_1 = require("../../utils/shared");
|
|
39
39
|
const codeFeatures_1 = require("../codeFeatures");
|
|
40
40
|
const inlayHints_1 = require("../inlayHints");
|
|
41
|
-
const
|
|
41
|
+
const names_1 = require("../names");
|
|
42
42
|
const utils_1 = require("../utils");
|
|
43
43
|
const boundary_1 = require("../utils/boundary");
|
|
44
44
|
const elementProps_1 = require("./elementProps");
|
|
@@ -59,7 +59,7 @@ function* generateSlotOutlet(options, ctx, node) {
|
|
|
59
59
|
}
|
|
60
60
|
});
|
|
61
61
|
if (options.hasDefineSlots) {
|
|
62
|
-
yield
|
|
62
|
+
yield `${names_1.names.asFunctionalSlot}(`;
|
|
63
63
|
if (nameProp) {
|
|
64
64
|
let codes;
|
|
65
65
|
if (nameProp.type === CompilerDOM.NodeTypes.ATTRIBUTE && nameProp.value) {
|
|
@@ -78,13 +78,13 @@ function* generateSlotOutlet(options, ctx, node) {
|
|
|
78
78
|
codes = [`['default']`];
|
|
79
79
|
}
|
|
80
80
|
const token = yield* (0, boundary_1.startBoundary)('template', nameProp.loc.start.offset, codeFeatures_1.codeFeatures.verification);
|
|
81
|
-
yield options.slotsAssignName ?? names.slots;
|
|
81
|
+
yield options.slotsAssignName ?? names_1.names.slots;
|
|
82
82
|
yield* codes;
|
|
83
83
|
yield (0, boundary_1.endBoundary)(token, nameProp.loc.end.offset);
|
|
84
84
|
}
|
|
85
85
|
else {
|
|
86
86
|
const token = yield* (0, boundary_1.startBoundary)('template', startTagOffset, codeFeatures_1.codeFeatures.verification);
|
|
87
|
-
yield `${options.slotsAssignName ?? names.slots}[`;
|
|
87
|
+
yield `${options.slotsAssignName ?? names_1.names.slots}[`;
|
|
88
88
|
const token2 = yield* (0, boundary_1.startBoundary)('template', startTagOffset, codeFeatures_1.codeFeatures.verification);
|
|
89
89
|
yield `'default'`;
|
|
90
90
|
yield (0, boundary_1.endBoundary)(token2, startTagEndOffset);
|
|
@@ -120,7 +120,7 @@ function* generateSlotOutlet(options, ctx, node) {
|
|
|
120
120
|
ctx.inlayHints.push((0, inlayHints_1.createVBindShorthandInlayHintInfo)(nameProp.exp.loc, 'name'));
|
|
121
121
|
}
|
|
122
122
|
const expVar = ctx.getInternalVariable();
|
|
123
|
-
yield `var ${expVar} =
|
|
123
|
+
yield `var ${expVar} = ${names_1.names.tryAsConstant}(`;
|
|
124
124
|
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, isShortHand
|
|
125
125
|
? codeFeatures_1.codeFeatures.withoutHighlightAndCompletion
|
|
126
126
|
: codeFeatures_1.codeFeatures.all, nameProp.exp.content, nameProp.exp.loc.start.offset);
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.references = void 0;
|
|
4
4
|
exports.generateStyleScopedClassReference = generateStyleScopedClassReference;
|
|
5
5
|
const codeFeatures_1 = require("../codeFeatures");
|
|
6
|
+
const names_1 = require("../names");
|
|
6
7
|
const utils_1 = require("../utils");
|
|
7
8
|
const boundary_1 = require("../utils/boundary");
|
|
8
9
|
const escaped_1 = require("../utils/escaped");
|
|
@@ -11,7 +12,7 @@ const classNameEscapeRegex = /([\\'])/;
|
|
|
11
12
|
exports.references = new WeakMap();
|
|
12
13
|
function* generateStyleScopedClassReference(block, className, offset, fullStart = offset) {
|
|
13
14
|
if (!className) {
|
|
14
|
-
yield `/** @type {
|
|
15
|
+
yield `/** @type {${names_1.names.StyleScopedClasses}['`;
|
|
15
16
|
yield ['', 'template', offset, codeFeatures_1.codeFeatures.completion];
|
|
16
17
|
yield `']} */${utils_1.endOfLine}`;
|
|
17
18
|
return;
|
|
@@ -25,7 +26,7 @@ function* generateStyleScopedClassReference(block, className, offset, fullStart
|
|
|
25
26
|
else {
|
|
26
27
|
cache[1].push([className, offset]);
|
|
27
28
|
}
|
|
28
|
-
yield `/** @type {
|
|
29
|
+
yield `/** @type {${names_1.names.StyleScopedClasses}[`;
|
|
29
30
|
const token = yield* (0, boundary_1.startBoundary)(block.name, fullStart, codeFeatures_1.codeFeatures.navigation);
|
|
30
31
|
yield `'`;
|
|
31
32
|
yield* (0, escaped_1.generateEscaped)(className, block.name, offset, codeFeatures_1.codeFeatures.navigationAndCompletion, classNameEscapeRegex);
|
|
@@ -38,6 +38,7 @@ exports.parseVForNode = parseVForNode;
|
|
|
38
38
|
const CompilerDOM = __importStar(require("@vue/compiler-dom"));
|
|
39
39
|
const collectBindings_1 = require("../../utils/collectBindings");
|
|
40
40
|
const codeFeatures_1 = require("../codeFeatures");
|
|
41
|
+
const names_1 = require("../names");
|
|
41
42
|
const utils_1 = require("../utils");
|
|
42
43
|
const interpolation_1 = require("./interpolation");
|
|
43
44
|
const templateChild_1 = require("./templateChild");
|
|
@@ -58,7 +59,7 @@ function* generateVFor(options, ctx, node) {
|
|
|
58
59
|
}
|
|
59
60
|
yield `] of `;
|
|
60
61
|
if (source.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
61
|
-
yield
|
|
62
|
+
yield `${names_1.names.vFor}(`;
|
|
62
63
|
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, source.content, source.loc.start.offset, `(`, `)`);
|
|
63
64
|
yield `!)`; // #3102
|
|
64
65
|
}
|
|
@@ -38,6 +38,7 @@ const CompilerDOM = __importStar(require("@vue/compiler-dom"));
|
|
|
38
38
|
const muggle_string_1 = require("muggle-string");
|
|
39
39
|
const collectBindings_1 = require("../../utils/collectBindings");
|
|
40
40
|
const codeFeatures_1 = require("../codeFeatures");
|
|
41
|
+
const names_1 = require("../names");
|
|
41
42
|
const utils_1 = require("../utils");
|
|
42
43
|
const boundary_1 = require("../utils/boundary");
|
|
43
44
|
const interpolation_1 = require("./interpolation");
|
|
@@ -125,7 +126,7 @@ function* generateSlotParameters(options, ctx, ast, exp, slotVar) {
|
|
|
125
126
|
}
|
|
126
127
|
yield `const [`;
|
|
127
128
|
yield* interpolation;
|
|
128
|
-
yield `] =
|
|
129
|
+
yield `] = ${names_1.names.vSlot}(${slotVar}!`;
|
|
129
130
|
if (types.some(t => t)) {
|
|
130
131
|
yield `, `;
|
|
131
132
|
const token = yield* (0, boundary_1.startBoundary)('template', exp.loc.start.offset, codeFeatures_1.codeFeatures.verification);
|
package/lib/compilerOptions.js
CHANGED
|
@@ -79,15 +79,11 @@ function createParsedCommandLine(ts, host, configFileName) {
|
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
81
|
class CompilerOptionsResolver {
|
|
82
|
-
ts;
|
|
83
|
-
readFile;
|
|
84
|
-
options = {};
|
|
85
|
-
target;
|
|
86
|
-
typesRoot;
|
|
87
|
-
plugins = [];
|
|
88
82
|
constructor(ts, readFile) {
|
|
89
83
|
this.ts = ts;
|
|
90
84
|
this.readFile = readFile;
|
|
85
|
+
this.options = {};
|
|
86
|
+
this.plugins = [];
|
|
91
87
|
}
|
|
92
88
|
addConfig(options, rootDir) {
|
|
93
89
|
for (const key in options) {
|
|
@@ -8,13 +8,13 @@ export declare function parseScriptRanges(ts: typeof import('typescript'), sourc
|
|
|
8
8
|
isObjectLiteral: boolean;
|
|
9
9
|
options?: {
|
|
10
10
|
isObjectLiteral: boolean;
|
|
11
|
-
expression: TextRange
|
|
11
|
+
expression: TextRange;
|
|
12
12
|
args: TextRange<ts.ObjectLiteralExpression>;
|
|
13
13
|
components: TextRange<ts.ObjectLiteralExpression> | undefined;
|
|
14
|
-
directives: TextRange
|
|
14
|
+
directives: TextRange | undefined;
|
|
15
15
|
name: TextRange<ts.StringLiteral> | undefined;
|
|
16
16
|
inheritAttrs: string | undefined;
|
|
17
|
-
}
|
|
17
|
+
};
|
|
18
18
|
}) | undefined;
|
|
19
19
|
bindings: TextRange<ts.Node>[];
|
|
20
20
|
components: TextRange<ts.Node>[];
|
package/lib/plugins/file-md.js
CHANGED
|
@@ -33,8 +33,6 @@ const plugin = ({ vueCompilerOptions }) => {
|
|
|
33
33
|
.replace(frontmatterReg, match => ' '.repeat(match.length))
|
|
34
34
|
// code block
|
|
35
35
|
.replace(codeblockReg, (match, quotes) => quotes + ' '.repeat(match.length - quotes.length * 2) + quotes)
|
|
36
|
-
// inline code block
|
|
37
|
-
.replace(inlineCodeblockReg, match => `\`${' '.repeat(match.length - 2)}\``)
|
|
38
36
|
// latex block
|
|
39
37
|
.replace(latexBlockReg, (match, quotes) => quotes + ' '.repeat(match.length - quotes.length * 2) + quotes)
|
|
40
38
|
// # \<script setup>
|
|
@@ -50,6 +48,8 @@ const plugin = ({ vueCompilerOptions }) => {
|
|
|
50
48
|
+ content.slice(match.index + matchText.length);
|
|
51
49
|
}
|
|
52
50
|
content = content
|
|
51
|
+
// inline code block
|
|
52
|
+
.replace(inlineCodeblockReg, match => `\`${' '.repeat(match.length - 2)}\``)
|
|
53
53
|
// angle bracket: <http://foo.com>
|
|
54
54
|
.replace(angleBracketReg, match => ' '.repeat(match.length))
|
|
55
55
|
// [foo](http://foo.com)
|