@vue/language-core 3.1.7 → 3.2.0
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 +25 -3
- package/lib/codegen/codeFeatures.d.ts +18 -84
- package/lib/codegen/names.d.ts +2 -5
- package/lib/codegen/names.js +3 -6
- package/lib/codegen/script/component.js +38 -18
- package/lib/codegen/script/index.d.ts +4 -12
- package/lib/codegen/script/index.js +132 -71
- package/lib/codegen/script/scriptSetup.js +52 -14
- package/lib/codegen/script/template.d.ts +1 -1
- package/lib/codegen/script/template.js +73 -50
- package/lib/codegen/style/index.d.ts +10 -13
- package/lib/codegen/style/modules.js +34 -1
- package/lib/codegen/template/context.d.ts +8 -11
- package/lib/codegen/template/context.js +36 -2
- package/lib/codegen/template/element.js +146 -159
- package/lib/codegen/template/elementDirectives.js +36 -3
- package/lib/codegen/template/elementEvents.d.ts +1 -1
- package/lib/codegen/template/elementEvents.js +39 -6
- package/lib/codegen/template/elementProps.js +35 -2
- package/lib/codegen/template/index.d.ts +11 -14
- package/lib/codegen/template/index.js +34 -1
- package/lib/codegen/template/interpolation.d.ts +4 -3
- package/lib/codegen/template/interpolation.js +37 -4
- package/lib/codegen/template/slotOutlet.js +35 -2
- package/lib/codegen/template/templateChild.js +45 -16
- package/lib/codegen/template/vFor.js +37 -4
- package/lib/codegen/template/vIf.js +34 -1
- package/lib/codegen/template/vSlot.d.ts +1 -1
- package/lib/codegen/template/vSlot.js +52 -25
- package/lib/codegen/utils/index.js +4 -2
- package/lib/compilerOptions.d.ts +7 -11
- package/lib/compilerOptions.js +48 -89
- package/lib/languagePlugin.js +34 -1
- package/lib/parsers/scriptRanges.d.ts +27 -15
- package/lib/parsers/scriptRanges.js +66 -62
- package/lib/parsers/scriptSetupRanges.d.ts +19 -24
- package/lib/parsers/scriptSetupRanges.js +13 -15
- package/lib/parsers/utils.d.ts +3 -6
- package/lib/parsers/utils.js +4 -0
- package/lib/plugins/vue-script-js.js +1 -1
- package/lib/plugins/vue-template-inline-css.js +34 -1
- package/lib/plugins/vue-template-inline-ts.js +34 -1
- package/lib/plugins/vue-tsx.d.ts +38 -117
- package/lib/plugins/vue-tsx.js +62 -33
- package/lib/plugins.js +17 -14
- package/lib/types.d.ts +8 -8
- package/lib/utils/collectBindings.d.ts +1 -1
- package/lib/utils/forEachTemplateNode.js +34 -1
- package/lib/utils/parseSfc.js +34 -1
- package/lib/utils/shared.d.ts +1 -1
- package/lib/utils/shared.js +2 -1
- package/lib/virtualCode/embeddedCodes.js +6 -2
- package/lib/virtualCode/index.js +10 -1
- package/lib/virtualCode/ir.js +34 -1
- package/lib/virtualCode/normalize.js +37 -2
- package/package.json +4 -12
- package/types/props-fallback.d.ts +5 -0
- package/types/template-helpers.d.ts +146 -0
- package/types/vue-3.4-shims.d.ts +6 -0
- package/lib/codegen/globalTypes.d.ts +0 -3
- package/lib/codegen/globalTypes.js +0 -163
- package/lib/codegen/script/src.d.ts +0 -2
- package/lib/codegen/script/src.js +0 -38
|
@@ -1,17 +1,51 @@
|
|
|
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
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.generateComponent = generateComponent;
|
|
4
37
|
exports.generateElement = generateElement;
|
|
5
|
-
const CompilerDOM = require("@vue/compiler-dom");
|
|
38
|
+
const CompilerDOM = __importStar(require("@vue/compiler-dom"));
|
|
6
39
|
const shared_1 = require("@vue/shared");
|
|
7
40
|
const muggle_string_1 = require("muggle-string");
|
|
8
41
|
const shared_2 = require("../../utils/shared");
|
|
9
42
|
const codeFeatures_1 = require("../codeFeatures");
|
|
10
43
|
const inlayHints_1 = require("../inlayHints");
|
|
11
|
-
const names = require("../names");
|
|
44
|
+
const names = __importStar(require("../names"));
|
|
12
45
|
const utils_1 = require("../utils");
|
|
13
46
|
const boundary_1 = require("../utils/boundary");
|
|
14
47
|
const camelized_1 = require("../utils/camelized");
|
|
48
|
+
const stringLiteralKey_1 = require("../utils/stringLiteralKey");
|
|
15
49
|
const elementDirectives_1 = require("./elementDirectives");
|
|
16
50
|
const elementEvents_1 = require("./elementEvents");
|
|
17
51
|
const elementProps_1 = require("./elementProps");
|
|
@@ -20,33 +54,14 @@ const propertyAccess_1 = require("./propertyAccess");
|
|
|
20
54
|
const styleScopedClasses_1 = require("./styleScopedClasses");
|
|
21
55
|
const templateChild_1 = require("./templateChild");
|
|
22
56
|
const vSlot_1 = require("./vSlot");
|
|
23
|
-
const colonReg = /:/g;
|
|
24
57
|
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) {
|
|
58
|
+
let { tag, props } = node;
|
|
59
|
+
let [startTagOffset, endTagOffset] = (0, shared_2.getElementTagOffsets)(node, options.template);
|
|
60
|
+
let isExpression = false;
|
|
61
|
+
if (tag.includes('.')) {
|
|
62
|
+
isExpression = true;
|
|
63
|
+
}
|
|
64
|
+
else if (tag === 'component') {
|
|
50
65
|
for (const prop of node.props) {
|
|
51
66
|
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
52
67
|
&& prop.name === 'bind'
|
|
@@ -55,122 +70,131 @@ function* generateComponent(options, ctx, node) {
|
|
|
55
70
|
if (prop.arg.loc.end.offset === prop.exp.loc.end.offset) {
|
|
56
71
|
ctx.inlayHints.push((0, inlayHints_1.createVBindShorthandInlayHintInfo)(prop.exp.loc, 'is'));
|
|
57
72
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
73
|
+
isExpression = true;
|
|
74
|
+
tag = prop.exp.content;
|
|
75
|
+
startTagOffset = prop.exp.loc.start.offset;
|
|
76
|
+
endTagOffset = undefined;
|
|
62
77
|
props = props.filter(p => p !== prop);
|
|
63
78
|
break;
|
|
64
79
|
}
|
|
65
80
|
}
|
|
66
81
|
}
|
|
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], `(`, `)`);
|
|
82
|
+
const componentVar = ctx.getInternalVariable();
|
|
83
|
+
if (isExpression) {
|
|
84
|
+
yield `const ${componentVar} = `;
|
|
85
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, tag, startTagOffset, `(`, `)`);
|
|
86
|
+
if (endTagOffset !== undefined) {
|
|
87
|
+
yield ` || `;
|
|
88
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.withoutCompletion, tag, endTagOffset, `(`, `)`);
|
|
105
89
|
}
|
|
106
|
-
yield
|
|
90
|
+
yield `${utils_1.endOfLine}`;
|
|
107
91
|
}
|
|
108
92
|
else {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
93
|
+
const originalNames = new Set([
|
|
94
|
+
(0, shared_1.capitalize)((0, shared_1.camelize)(tag)),
|
|
95
|
+
(0, shared_1.camelize)(tag),
|
|
96
|
+
tag,
|
|
97
|
+
]);
|
|
98
|
+
const matchedSetupConst = [...originalNames].find(name => options.setupConsts.has(name));
|
|
99
|
+
if (matchedSetupConst) {
|
|
100
|
+
// navigation & auto import support
|
|
101
|
+
yield `const ${componentVar} = `;
|
|
102
|
+
yield* (0, camelized_1.generateCamelized)(matchedSetupConst[0] + tag.slice(1), 'template', startTagOffset, {
|
|
103
|
+
...codeFeatures_1.codeFeatures.withoutHighlightAndCompletion,
|
|
104
|
+
...codeFeatures_1.codeFeatures.importCompletionOnly,
|
|
105
|
+
});
|
|
106
|
+
if (endTagOffset !== undefined) {
|
|
107
|
+
yield ` || `;
|
|
108
|
+
yield* (0, camelized_1.generateCamelized)(matchedSetupConst[0] + tag.slice(1), 'template', endTagOffset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
|
|
109
|
+
}
|
|
110
|
+
yield utils_1.endOfLine;
|
|
112
111
|
}
|
|
113
112
|
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
|
|
113
|
+
yield `let ${componentVar}!: __VLS_WithComponent<'${tag}', __VLS_LocalComponents, __VLS_GlobalComponents`;
|
|
114
|
+
yield originalNames.has(options.componentName)
|
|
115
|
+
? `, typeof ${names._export}`
|
|
116
|
+
: `, void`;
|
|
117
|
+
for (const name of originalNames) {
|
|
118
|
+
yield `, '${name}'`;
|
|
119
|
+
}
|
|
120
|
+
yield `>[`;
|
|
121
|
+
yield* (0, stringLiteralKey_1.generateStringLiteralKey)(tag, startTagOffset, {
|
|
122
|
+
...codeFeatures_1.codeFeatures.semanticWithoutHighlight,
|
|
123
|
+
...options.vueCompilerOptions.checkUnknownComponents
|
|
124
|
+
? codeFeatures_1.codeFeatures.verification
|
|
125
|
+
: codeFeatures_1.codeFeatures.doNotReportTs2339AndTs2551,
|
|
126
|
+
});
|
|
127
|
+
yield `]${utils_1.endOfLine}`;
|
|
128
|
+
if (utils_1.identifierRegex.test((0, shared_1.camelize)(tag))) {
|
|
129
|
+
// navigation support
|
|
130
|
+
yield `/** @ts-ignore @type {typeof ${names.components}.`;
|
|
131
|
+
yield* (0, camelized_1.generateCamelized)(tag, 'template', startTagOffset, codeFeatures_1.codeFeatures.navigation);
|
|
132
|
+
if (tag[0] !== tag[0].toUpperCase()) {
|
|
133
|
+
yield ` | typeof ${names.components}.`;
|
|
134
|
+
yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(tag), 'template', startTagOffset, codeFeatures_1.codeFeatures.navigation);
|
|
135
|
+
}
|
|
136
|
+
if (endTagOffset !== undefined) {
|
|
137
|
+
yield ` | typeof ${names.components}.`;
|
|
138
|
+
yield* (0, camelized_1.generateCamelized)(tag, 'template', endTagOffset, codeFeatures_1.codeFeatures.navigation);
|
|
139
|
+
if (tag[0] !== tag[0].toUpperCase()) {
|
|
140
|
+
yield ` | typeof ${names.components}.`;
|
|
141
|
+
yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(tag), 'template', endTagOffset, codeFeatures_1.codeFeatures.navigation);
|
|
142
|
+
}
|
|
136
143
|
}
|
|
144
|
+
yield `} */${utils_1.newLine}`;
|
|
145
|
+
// auto import support
|
|
146
|
+
yield* (0, camelized_1.generateCamelized)(tag, 'template', startTagOffset, codeFeatures_1.codeFeatures.importCompletionOnly);
|
|
147
|
+
yield utils_1.endOfLine;
|
|
137
148
|
}
|
|
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
149
|
}
|
|
144
150
|
}
|
|
151
|
+
yield* generateComponentBody(options, ctx, node, tag, startTagOffset, props, componentVar);
|
|
152
|
+
}
|
|
153
|
+
function* generateComponentBody(options, ctx, node, tag, tagOffset, props, componentVar) {
|
|
154
|
+
let isCtxVarUsed = false;
|
|
155
|
+
let isPropsVarUsed = false;
|
|
156
|
+
const getCtxVar = () => (isCtxVarUsed = true, ctxVar);
|
|
157
|
+
const getPropsVar = () => (isPropsVarUsed = true, propsVar);
|
|
158
|
+
ctx.components.push(getCtxVar);
|
|
159
|
+
const failGeneratedExpressions = [];
|
|
145
160
|
const propCodes = [...(0, elementProps_1.generateElementProps)(options, ctx, node, props, options.vueCompilerOptions.checkUnknownProps, failGeneratedExpressions)];
|
|
161
|
+
const functionalVar = ctx.getInternalVariable();
|
|
162
|
+
const vNodeVar = ctx.getInternalVariable();
|
|
163
|
+
const ctxVar = ctx.getInternalVariable();
|
|
164
|
+
const propsVar = ctx.getInternalVariable();
|
|
146
165
|
yield `// @ts-ignore${utils_1.newLine}`;
|
|
147
|
-
yield `const ${
|
|
166
|
+
yield `const ${functionalVar} = ${options.vueCompilerOptions.checkUnknownProps ? '__VLS_asFunctionalComponent0' : '__VLS_asFunctionalComponent1'}(${componentVar}, new ${componentVar}({${utils_1.newLine}`;
|
|
148
167
|
yield* (0, muggle_string_1.toString)(propCodes);
|
|
149
168
|
yield `}))${utils_1.endOfLine}`;
|
|
150
169
|
yield `const `;
|
|
151
170
|
const token = yield* (0, boundary_1.startBoundary)('template', node.loc.start.offset, codeFeatures_1.codeFeatures.doNotReportTs6133);
|
|
152
|
-
yield
|
|
171
|
+
yield vNodeVar;
|
|
153
172
|
yield (0, boundary_1.endBoundary)(token, node.loc.end.offset);
|
|
154
|
-
yield ` = ${
|
|
155
|
-
|
|
173
|
+
yield ` = ${functionalVar}`;
|
|
174
|
+
if (ctx.currentInfo.generic) {
|
|
175
|
+
const { content, offset } = ctx.currentInfo.generic;
|
|
176
|
+
const token = yield* (0, boundary_1.startBoundary)('template', offset, codeFeatures_1.codeFeatures.verification);
|
|
177
|
+
yield `<`;
|
|
178
|
+
yield [content, 'template', offset, codeFeatures_1.codeFeatures.all];
|
|
179
|
+
yield `>`;
|
|
180
|
+
yield (0, boundary_1.endBoundary)(token, offset + content.length);
|
|
181
|
+
}
|
|
156
182
|
yield `(`;
|
|
157
|
-
const token2 = yield* (0, boundary_1.startBoundary)('template',
|
|
183
|
+
const token2 = yield* (0, boundary_1.startBoundary)('template', tagOffset, codeFeatures_1.codeFeatures.verification);
|
|
158
184
|
yield `{${utils_1.newLine}`;
|
|
159
185
|
yield* propCodes;
|
|
160
186
|
yield `}`;
|
|
161
|
-
yield (0, boundary_1.endBoundary)(token2,
|
|
162
|
-
yield `, ...__VLS_functionalComponentArgsRest(${
|
|
187
|
+
yield (0, boundary_1.endBoundary)(token2, tagOffset + tag.length);
|
|
188
|
+
yield `, ...__VLS_functionalComponentArgsRest(${functionalVar}))${utils_1.endOfLine}`;
|
|
163
189
|
yield* generateFailedExpressions(options, ctx, failGeneratedExpressions);
|
|
164
|
-
yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node,
|
|
190
|
+
yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, componentVar, getCtxVar, getPropsVar);
|
|
165
191
|
yield* (0, elementDirectives_1.generateElementDirectives)(options, ctx, node);
|
|
166
192
|
const templateRef = getTemplateRef(node);
|
|
167
|
-
const tag = (0, shared_2.hyphenateTag)(node.tag);
|
|
168
193
|
const isRootNode = ctx.singleRootNodes.has(node)
|
|
169
|
-
&& !options.vueCompilerOptions.fallthroughComponentNames.includes(tag);
|
|
194
|
+
&& !options.vueCompilerOptions.fallthroughComponentNames.includes((0, shared_2.hyphenateTag)(tag));
|
|
170
195
|
if (templateRef || isRootNode) {
|
|
171
196
|
const componentInstanceVar = ctx.getInternalVariable();
|
|
172
|
-
|
|
173
|
-
yield `var ${componentInstanceVar} = {} as (Parameters<NonNullable<typeof ${componentCtxVar}['expose']>>[0] | null)`;
|
|
197
|
+
yield `var ${componentInstanceVar} = {} as (Parameters<NonNullable<typeof ${getCtxVar()}['expose']>>[0] | null)`;
|
|
174
198
|
if (ctx.inVFor) {
|
|
175
199
|
yield `[]`;
|
|
176
200
|
}
|
|
@@ -184,23 +208,25 @@ function* generateComponent(options, ctx, node) {
|
|
|
184
208
|
}
|
|
185
209
|
}
|
|
186
210
|
if (hasVBindAttrs(options, ctx, node)) {
|
|
187
|
-
ctx.inheritedAttrVars.add(
|
|
188
|
-
isPropsVarUsed = true;
|
|
211
|
+
ctx.inheritedAttrVars.add(getPropsVar());
|
|
189
212
|
}
|
|
190
213
|
yield* generateStyleScopedClassReferences(options, node);
|
|
191
214
|
const slotDir = node.props.find(p => p.type === CompilerDOM.NodeTypes.DIRECTIVE && p.name === 'slot');
|
|
192
|
-
|
|
215
|
+
if (slotDir || node.children.length) {
|
|
216
|
+
yield* (0, vSlot_1.generateVSlot)(options, ctx, node, slotDir, getCtxVar());
|
|
217
|
+
}
|
|
193
218
|
if (isCtxVarUsed) {
|
|
194
|
-
yield `var ${
|
|
219
|
+
yield `var ${ctxVar}!: __VLS_FunctionalComponentCtx<typeof ${componentVar}, typeof ${vNodeVar}>${utils_1.endOfLine}`;
|
|
195
220
|
}
|
|
196
221
|
if (isPropsVarUsed) {
|
|
197
|
-
yield `var ${
|
|
222
|
+
yield `var ${propsVar}!: __VLS_FunctionalComponentProps<typeof ${componentVar}, typeof ${vNodeVar}>${utils_1.endOfLine}`;
|
|
198
223
|
}
|
|
224
|
+
ctx.components.pop();
|
|
199
225
|
}
|
|
200
226
|
function* generateElement(options, ctx, node) {
|
|
201
227
|
const [startTagOffset, endTagOffset] = (0, shared_2.getElementTagOffsets)(node, options.template);
|
|
202
228
|
const failedPropExps = [];
|
|
203
|
-
yield `
|
|
229
|
+
yield `${options.vueCompilerOptions.checkUnknownProps ? `__VLS_asFunctionalElement0` : `__VLS_asFunctionalElement1`}(${names.intrinsics}`;
|
|
204
230
|
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, startTagOffset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
|
|
205
231
|
if (endTagOffset !== undefined) {
|
|
206
232
|
yield `, `;
|
|
@@ -231,14 +257,11 @@ function* generateElement(options, ctx, node) {
|
|
|
231
257
|
ctx.inheritedAttrVars.add(`__VLS_intrinsics.${node.tag}`);
|
|
232
258
|
}
|
|
233
259
|
yield* generateStyleScopedClassReferences(options, node);
|
|
234
|
-
const { currentComponent } = ctx;
|
|
235
|
-
ctx.currentComponent = undefined;
|
|
236
260
|
for (const child of node.children) {
|
|
237
261
|
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, child);
|
|
238
262
|
}
|
|
239
|
-
ctx.currentComponent = currentComponent;
|
|
240
263
|
}
|
|
241
|
-
function* generateStyleScopedClassReferences({ template, ts }, node) {
|
|
264
|
+
function* generateStyleScopedClassReferences({ template, typescript: ts }, node) {
|
|
242
265
|
for (const prop of node.props) {
|
|
243
266
|
if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE
|
|
244
267
|
&& prop.name === 'class'
|
|
@@ -339,42 +362,6 @@ function* generateFailedExpressions(options, ctx, failGeneratedExpressions) {
|
|
|
339
362
|
yield utils_1.endOfLine;
|
|
340
363
|
}
|
|
341
364
|
}
|
|
342
|
-
function getCanonicalComponentName(tagText) {
|
|
343
|
-
return utils_1.identifierRegex.test(tagText)
|
|
344
|
-
? tagText
|
|
345
|
-
: (0, shared_1.capitalize)((0, shared_1.camelize)(tagText.replace(colonReg, '-')));
|
|
346
|
-
}
|
|
347
|
-
function getPossibleOriginalComponentNames(tagText, deduplicate) {
|
|
348
|
-
const name1 = (0, shared_1.capitalize)((0, shared_1.camelize)(tagText));
|
|
349
|
-
const name2 = (0, shared_1.camelize)(tagText);
|
|
350
|
-
const name3 = tagText;
|
|
351
|
-
const names = [name1];
|
|
352
|
-
if (!deduplicate || name2 !== name1) {
|
|
353
|
-
names.push(name2);
|
|
354
|
-
}
|
|
355
|
-
if (!deduplicate || name3 !== name2) {
|
|
356
|
-
names.push(name3);
|
|
357
|
-
}
|
|
358
|
-
return names;
|
|
359
|
-
}
|
|
360
|
-
function* generateCanonicalComponentName(tagText, offset, features) {
|
|
361
|
-
if (utils_1.identifierRegex.test(tagText)) {
|
|
362
|
-
yield [tagText, 'template', offset, features];
|
|
363
|
-
}
|
|
364
|
-
else {
|
|
365
|
-
yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(tagText.replace(colonReg, '-')), 'template', offset, features);
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
function* generateComponentGeneric(ctx) {
|
|
369
|
-
if (ctx.currentInfo.generic) {
|
|
370
|
-
const { content, offset } = ctx.currentInfo.generic;
|
|
371
|
-
const token = yield* (0, boundary_1.startBoundary)('template', offset, codeFeatures_1.codeFeatures.verification);
|
|
372
|
-
yield `<`;
|
|
373
|
-
yield [content, 'template', offset, codeFeatures_1.codeFeatures.all];
|
|
374
|
-
yield `>`;
|
|
375
|
-
yield (0, boundary_1.endBoundary)(token, offset + content.length);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
365
|
function getTemplateRef(node) {
|
|
379
366
|
for (const prop of node.props) {
|
|
380
367
|
if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE
|
|
@@ -1,11 +1,44 @@
|
|
|
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
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.generateElementDirectives = generateElementDirectives;
|
|
4
37
|
exports.generateModifiers = generateModifiers;
|
|
5
|
-
const CompilerDOM = require("@vue/compiler-dom");
|
|
38
|
+
const CompilerDOM = __importStar(require("@vue/compiler-dom"));
|
|
6
39
|
const shared_1 = require("@vue/shared");
|
|
7
40
|
const codeFeatures_1 = require("../codeFeatures");
|
|
8
|
-
const names = require("../names");
|
|
41
|
+
const names = __importStar(require("../names"));
|
|
9
42
|
const utils_1 = require("../utils");
|
|
10
43
|
const boundary_1 = require("../utils/boundary");
|
|
11
44
|
const camelized_1 = require("../utils/camelized");
|
|
@@ -33,7 +66,7 @@ function* generateElementDirectives(options, ctx, node) {
|
|
|
33
66
|
const token = yield* (0, boundary_1.startBoundary)('template', prop.loc.start.offset, codeFeatures_1.codeFeatures.verification);
|
|
34
67
|
yield `__VLS_asFunctionalDirective(`;
|
|
35
68
|
yield* generateIdentifier(options, ctx, prop);
|
|
36
|
-
yield
|
|
69
|
+
yield `, {} as import('${options.vueCompilerOptions.lib}').ObjectDirective)(null!, { ...__VLS_directiveBindingRestFields, `;
|
|
37
70
|
yield* generateArg(options, ctx, prop);
|
|
38
71
|
yield* generateModifiers(options, ctx, prop);
|
|
39
72
|
yield* generateValue(options, ctx, prop);
|
|
@@ -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>;
|
|
@@ -1,18 +1,51 @@
|
|
|
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
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.generateElementEvents = generateElementEvents;
|
|
4
37
|
exports.generateEventArg = generateEventArg;
|
|
5
38
|
exports.generateEventExpression = generateEventExpression;
|
|
6
39
|
exports.generateModelEventExpression = generateModelEventExpression;
|
|
7
40
|
exports.isCompoundExpression = isCompoundExpression;
|
|
8
|
-
const CompilerDOM = require("@vue/compiler-dom");
|
|
41
|
+
const CompilerDOM = __importStar(require("@vue/compiler-dom"));
|
|
9
42
|
const shared_1 = require("@vue/shared");
|
|
10
43
|
const codeFeatures_1 = require("../codeFeatures");
|
|
11
44
|
const utils_1 = require("../utils");
|
|
12
45
|
const boundary_1 = require("../utils/boundary");
|
|
13
46
|
const camelized_1 = require("../utils/camelized");
|
|
14
47
|
const interpolation_1 = require("./interpolation");
|
|
15
|
-
function* generateElementEvents(options, ctx, node, componentOriginalVar) {
|
|
48
|
+
function* generateElementEvents(options, ctx, node, componentOriginalVar, getCtxVar, getPropsVar) {
|
|
16
49
|
let emitsVar;
|
|
17
50
|
for (const prop of node.props) {
|
|
18
51
|
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
@@ -23,7 +56,7 @@ function* generateElementEvents(options, ctx, node, componentOriginalVar) {
|
|
|
23
56
|
&& (!prop.arg || prop.arg.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic))) {
|
|
24
57
|
if (!emitsVar) {
|
|
25
58
|
emitsVar = ctx.getInternalVariable();
|
|
26
|
-
yield `let ${emitsVar}!: __VLS_ResolveEmits<typeof ${componentOriginalVar}, typeof ${
|
|
59
|
+
yield `let ${emitsVar}!: __VLS_ResolveEmits<typeof ${componentOriginalVar}, typeof ${getCtxVar()}.emit>${utils_1.endOfLine}`;
|
|
27
60
|
}
|
|
28
61
|
let source = prop.arg?.loc.source ?? 'model-value';
|
|
29
62
|
let start = prop.arg?.loc.start.offset;
|
|
@@ -42,7 +75,7 @@ function* generateElementEvents(options, ctx, node, componentOriginalVar) {
|
|
|
42
75
|
const propName = (0, shared_1.camelize)(propPrefix + source);
|
|
43
76
|
const emitName = emitPrefix + source;
|
|
44
77
|
const camelizedEmitName = (0, shared_1.camelize)(emitName);
|
|
45
|
-
yield `const ${ctx.getInternalVariable()}: __VLS_NormalizeComponentEvent<typeof ${
|
|
78
|
+
yield `const ${ctx.getInternalVariable()}: __VLS_NormalizeComponentEvent<typeof ${getPropsVar()}, typeof ${emitsVar}, '${propName}', '${emitName}', '${camelizedEmitName}'> = (${utils_1.newLine}`;
|
|
46
79
|
if (prop.name === 'on') {
|
|
47
80
|
yield `{ `;
|
|
48
81
|
yield* generateEventArg(options, source, start, emitPrefix.slice(0, -1), codeFeatures_1.codeFeatures.navigation);
|
|
@@ -89,8 +122,8 @@ function* generateEventArg(options, name, start, directive = 'on', features) {
|
|
|
89
122
|
}
|
|
90
123
|
function* generateEventExpression(options, ctx, prop) {
|
|
91
124
|
if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
92
|
-
const ast = (0, utils_1.getTypeScriptAST)(options.
|
|
93
|
-
const isCompound = isCompoundExpression(options.
|
|
125
|
+
const ast = (0, utils_1.getTypeScriptAST)(options.typescript, options.template, prop.exp.content);
|
|
126
|
+
const isCompound = isCompoundExpression(options.typescript, ast);
|
|
94
127
|
const interpolation = (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, prop.exp.content, prop.exp.loc.start.offset, isCompound ? `` : `(`, isCompound ? `` : `)`);
|
|
95
128
|
if (isCompound) {
|
|
96
129
|
yield `(...[$event]) => {${utils_1.newLine}`;
|
|
@@ -1,14 +1,47 @@
|
|
|
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
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.generateElementProps = generateElementProps;
|
|
4
37
|
exports.generatePropExp = generatePropExp;
|
|
5
|
-
const CompilerDOM = require("@vue/compiler-dom");
|
|
38
|
+
const CompilerDOM = __importStar(require("@vue/compiler-dom"));
|
|
6
39
|
const shared_1 = require("@vue/shared");
|
|
7
40
|
const picomatch_1 = require("picomatch");
|
|
8
41
|
const shared_2 = require("../../utils/shared");
|
|
9
42
|
const codeFeatures_1 = require("../codeFeatures");
|
|
10
43
|
const inlayHints_1 = require("../inlayHints");
|
|
11
|
-
const names = require("../names");
|
|
44
|
+
const names = __importStar(require("../names"));
|
|
12
45
|
const utils_1 = require("../utils");
|
|
13
46
|
const boundary_1 = require("../utils/boundary");
|
|
14
47
|
const camelized_1 = require("../utils/camelized");
|