@vue/language-core 2.1.10 → 2.2.2
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 +0 -1
- package/index.js +1 -2
- package/lib/codeFeatures.d.ts +1 -0
- package/lib/codeFeatures.js +3 -0
- package/lib/codegen/codeFeatures.d.ts +83 -0
- package/lib/codegen/codeFeatures.js +71 -0
- package/lib/codegen/globalTypes.d.ts +3 -1
- package/lib/codegen/globalTypes.js +39 -14
- package/lib/codegen/localTypes.d.ts +1 -1
- package/lib/codegen/localTypes.js +7 -7
- package/lib/codegen/script/binding.d.ts +4 -0
- package/lib/codegen/script/binding.js +41 -0
- package/lib/codegen/script/component.d.ts +1 -1
- package/lib/codegen/script/component.js +44 -44
- package/lib/codegen/script/componentSelf.d.ts +1 -1
- package/lib/codegen/script/componentSelf.js +14 -14
- package/lib/codegen/script/context.d.ts +1 -1
- package/lib/codegen/script/context.js +2 -2
- package/lib/codegen/script/index.d.ts +6 -11
- package/lib/codegen/script/index.js +21 -63
- package/lib/codegen/script/scriptSetup.d.ts +1 -1
- package/lib/codegen/script/scriptSetup.js +236 -205
- package/lib/codegen/script/src.js +8 -8
- package/lib/codegen/script/styleModulesType.d.ts +1 -1
- package/lib/codegen/script/styleModulesType.js +7 -7
- package/lib/codegen/script/template.d.ts +2 -2
- package/lib/codegen/script/template.js +81 -114
- package/lib/codegen/template/context.d.ts +29 -15
- package/lib/codegen/template/context.js +51 -96
- package/lib/codegen/template/element.d.ts +2 -4
- package/lib/codegen/template/element.js +124 -317
- package/lib/codegen/template/elementChildren.d.ts +1 -1
- package/lib/codegen/template/elementChildren.js +10 -11
- package/lib/codegen/template/elementDirectives.d.ts +1 -0
- package/lib/codegen/template/elementDirectives.js +43 -30
- package/lib/codegen/template/elementEvents.d.ts +2 -2
- package/lib/codegen/template/elementEvents.js +32 -65
- package/lib/codegen/template/elementProps.d.ts +5 -3
- package/lib/codegen/template/elementProps.js +116 -123
- package/lib/codegen/template/index.d.ts +1 -0
- package/lib/codegen/template/index.js +67 -69
- package/lib/codegen/template/interpolation.d.ts +5 -3
- package/lib/codegen/template/interpolation.js +30 -27
- package/lib/codegen/template/objectProperty.js +8 -8
- package/lib/codegen/template/propertyAccess.js +4 -4
- package/lib/codegen/template/slotOutlet.d.ts +1 -1
- package/lib/codegen/template/slotOutlet.js +47 -25
- package/lib/codegen/template/styleScopedClasses.d.ts +4 -1
- package/lib/codegen/template/styleScopedClasses.js +152 -8
- package/lib/codegen/template/templateChild.d.ts +1 -1
- package/lib/codegen/template/templateChild.js +39 -20
- package/lib/codegen/template/vFor.d.ts +1 -1
- package/lib/codegen/template/vFor.js +11 -11
- package/lib/codegen/template/vIf.d.ts +1 -1
- package/lib/codegen/template/vIf.js +6 -6
- package/lib/codegen/template/vSlot.d.ts +5 -0
- package/lib/codegen/template/vSlot.js +80 -0
- package/lib/codegen/utils/camelized.d.ts +2 -0
- package/lib/codegen/utils/camelized.js +31 -0
- package/lib/codegen/utils/index.d.ts +21 -0
- package/lib/codegen/utils/index.js +79 -0
- package/lib/codegen/utils/src.d.ts +2 -0
- package/lib/codegen/utils/src.js +19 -0
- package/lib/codegen/{template → utils}/stringLiteralKey.js +3 -3
- package/lib/codegen/utils/unicode.d.ts +2 -0
- package/lib/codegen/utils/unicode.js +25 -0
- package/lib/languagePlugin.js +1 -1
- package/lib/parsers/scriptRanges.d.ts +7 -2
- package/lib/parsers/scriptSetupRanges.d.ts +69 -83
- package/lib/parsers/scriptSetupRanges.js +194 -171
- package/lib/parsers/vueCompilerOptions.d.ts +2 -0
- package/lib/parsers/vueCompilerOptions.js +23 -0
- package/lib/plugins/file-html.js +4 -3
- package/lib/plugins/file-md.js +1 -1
- package/lib/plugins/file-vue.js +4 -4
- package/lib/plugins/vue-root-tags.js +2 -2
- package/lib/plugins/vue-style-class-names.d.ts +5 -0
- package/lib/plugins/vue-style-class-names.js +32 -0
- package/lib/plugins/vue-style-reference-link.d.ts +1 -0
- package/lib/plugins/vue-style-reference-link.js +3 -0
- package/lib/plugins/vue-style-reference-links.d.ts +3 -0
- package/lib/plugins/vue-style-reference-links.js +26 -0
- package/lib/plugins/vue-template-html.js +6 -2
- package/lib/plugins/vue-template-inline-css.js +1 -1
- package/lib/plugins/vue-template-inline-ts.js +66 -17
- package/lib/plugins/vue-tsx.d.ts +126 -92
- package/lib/plugins/vue-tsx.js +114 -97
- package/lib/plugins/vue-vine.d.ts +3 -0
- package/lib/plugins/vue-vine.js +35 -0
- package/lib/types.d.ts +25 -12
- package/lib/utils/buildMappings.d.ts +1 -1
- package/lib/utils/parseCssImports.d.ts +4 -0
- package/lib/utils/parseCssImports.js +19 -0
- package/lib/utils/parseSfc.d.ts +5 -0
- package/lib/utils/parseSfc.js +11 -5
- package/lib/utils/signals.d.ts +2 -0
- package/lib/utils/signals.js +54 -0
- package/lib/utils/ts.d.ts +14 -2
- package/lib/utils/ts.js +134 -91
- package/lib/virtualFile/computedEmbeddedCodes.d.ts +1 -2
- package/lib/virtualFile/computedEmbeddedCodes.js +11 -11
- package/lib/virtualFile/computedSfc.d.ts +1 -2
- package/lib/virtualFile/computedSfc.js +87 -79
- package/lib/virtualFile/computedVueSfc.d.ts +1 -2
- package/lib/virtualFile/computedVueSfc.js +7 -7
- package/lib/virtualFile/vueFile.d.ts +5 -5
- package/lib/virtualFile/vueFile.js +6 -6
- package/package.json +6 -6
- /package/lib/codegen/{template → utils}/stringLiteralKey.d.ts +0 -0
|
@@ -2,31 +2,30 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateComponent = generateComponent;
|
|
4
4
|
exports.generateElement = generateElement;
|
|
5
|
-
exports.getCanonicalComponentName = getCanonicalComponentName;
|
|
6
|
-
exports.getPossibleOriginalComponentNames = getPossibleOriginalComponentNames;
|
|
7
5
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
8
6
|
const shared_1 = require("@vue/shared");
|
|
9
7
|
const shared_2 = require("../../utils/shared");
|
|
10
|
-
const
|
|
11
|
-
const
|
|
8
|
+
const inlayHints_1 = require("../inlayHints");
|
|
9
|
+
const utils_1 = require("../utils");
|
|
10
|
+
const camelized_1 = require("../utils/camelized");
|
|
12
11
|
const elementChildren_1 = require("./elementChildren");
|
|
13
12
|
const elementDirectives_1 = require("./elementDirectives");
|
|
14
13
|
const elementEvents_1 = require("./elementEvents");
|
|
15
14
|
const elementProps_1 = require("./elementProps");
|
|
16
15
|
const interpolation_1 = require("./interpolation");
|
|
17
16
|
const propertyAccess_1 = require("./propertyAccess");
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const inlayHints_1 = require("../inlayHints");
|
|
21
|
-
const scriptSetupRanges_1 = require("../../parsers/scriptSetupRanges");
|
|
17
|
+
const styleScopedClasses_1 = require("./styleScopedClasses");
|
|
18
|
+
const vSlot_1 = require("./vSlot");
|
|
22
19
|
const colonReg = /:/g;
|
|
23
|
-
function* generateComponent(options, ctx, node
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
20
|
+
function* generateComponent(options, ctx, node) {
|
|
21
|
+
const tagOffsets = [node.loc.start.offset + options.template.content.slice(node.loc.start.offset).indexOf(node.tag)];
|
|
22
|
+
if (!node.isSelfClosing && options.template.lang === 'html') {
|
|
23
|
+
const endTagOffset = node.loc.start.offset + node.loc.source.lastIndexOf(node.tag);
|
|
24
|
+
if (endTagOffset > tagOffsets[0]) {
|
|
25
|
+
tagOffsets.push(endTagOffset);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const failedPropExps = [];
|
|
30
29
|
const possibleOriginalNames = getPossibleOriginalComponentNames(node.tag, true);
|
|
31
30
|
const matchImportName = possibleOriginalNames.find(name => options.scriptSetupImportComponentNames.has(name));
|
|
32
31
|
const var_originalComponent = matchImportName ?? ctx.getInternalVariable();
|
|
@@ -36,6 +35,10 @@ function* generateComponent(options, ctx, node, currentComponent) {
|
|
|
36
35
|
const var_componentEvents = ctx.getInternalVariable();
|
|
37
36
|
const var_defineComponentCtx = ctx.getInternalVariable();
|
|
38
37
|
const isComponentTag = node.tag.toLowerCase() === 'component';
|
|
38
|
+
ctx.currentComponent = {
|
|
39
|
+
ctxVar: var_defineComponentCtx,
|
|
40
|
+
used: false
|
|
41
|
+
};
|
|
39
42
|
let props = node.props;
|
|
40
43
|
let dynamicTagInfo;
|
|
41
44
|
if (isComponentTag) {
|
|
@@ -49,7 +52,7 @@ function* generateComponent(options, ctx, node, currentComponent) {
|
|
|
49
52
|
}
|
|
50
53
|
dynamicTagInfo = {
|
|
51
54
|
tag: prop.exp.content,
|
|
52
|
-
offsets: [prop.exp.loc.start.offset
|
|
55
|
+
offsets: [prop.exp.loc.start.offset],
|
|
53
56
|
astHolder: prop.exp.loc,
|
|
54
57
|
};
|
|
55
58
|
props = props.filter(p => p !== prop);
|
|
@@ -61,15 +64,16 @@ function* generateComponent(options, ctx, node, currentComponent) {
|
|
|
61
64
|
// namespace tag
|
|
62
65
|
dynamicTagInfo = {
|
|
63
66
|
tag: node.tag,
|
|
64
|
-
offsets:
|
|
67
|
+
offsets: tagOffsets,
|
|
65
68
|
astHolder: node.loc,
|
|
66
69
|
};
|
|
67
70
|
}
|
|
68
71
|
if (matchImportName) {
|
|
69
72
|
// hover, renaming / find references support
|
|
70
|
-
yield `// @ts-ignore${
|
|
71
|
-
yield
|
|
73
|
+
yield `// @ts-ignore${utils_1.newLine}`; // #2304
|
|
74
|
+
yield `/** @type { [`;
|
|
72
75
|
for (const tagOffset of tagOffsets) {
|
|
76
|
+
yield `typeof `;
|
|
73
77
|
if (var_originalComponent === node.tag) {
|
|
74
78
|
yield [
|
|
75
79
|
var_originalComponent,
|
|
@@ -79,7 +83,8 @@ function* generateComponent(options, ctx, node, currentComponent) {
|
|
|
79
83
|
];
|
|
80
84
|
}
|
|
81
85
|
else {
|
|
82
|
-
|
|
86
|
+
const shouldCapitalize = matchImportName[0].toUpperCase() === matchImportName[0];
|
|
87
|
+
yield* (0, camelized_1.generateCamelized)(shouldCapitalize ? (0, shared_1.capitalize)(node.tag) : node.tag, tagOffset, {
|
|
83
88
|
...ctx.codeFeatures.withoutHighlightAndCompletion,
|
|
84
89
|
navigation: {
|
|
85
90
|
resolveRenameNewName: camelizeComponentName,
|
|
@@ -87,32 +92,37 @@ function* generateComponent(options, ctx, node, currentComponent) {
|
|
|
87
92
|
},
|
|
88
93
|
});
|
|
89
94
|
}
|
|
90
|
-
yield
|
|
95
|
+
yield `, `;
|
|
91
96
|
}
|
|
92
|
-
yield `]
|
|
97
|
+
yield `] } */${utils_1.endOfLine}`;
|
|
93
98
|
}
|
|
94
99
|
else if (dynamicTagInfo) {
|
|
95
100
|
yield `const ${var_originalComponent} = (`;
|
|
96
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx,
|
|
101
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, dynamicTagInfo.tag, dynamicTagInfo.offsets[0], dynamicTagInfo.astHolder, '(', ')');
|
|
97
102
|
if (dynamicTagInfo.offsets[1] !== undefined) {
|
|
98
103
|
yield `,`;
|
|
99
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx,
|
|
100
|
-
...ctx.codeFeatures.all,
|
|
101
|
-
completion: false,
|
|
102
|
-
}, '(', ')');
|
|
104
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.withoutCompletion, dynamicTagInfo.tag, dynamicTagInfo.offsets[1], dynamicTagInfo.astHolder, '(', ')');
|
|
103
105
|
}
|
|
104
|
-
yield `)${
|
|
106
|
+
yield `)${utils_1.endOfLine}`;
|
|
105
107
|
}
|
|
106
108
|
else if (!isComponentTag) {
|
|
107
|
-
yield `const ${var_originalComponent} =
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
|
|
109
|
+
yield `const ${var_originalComponent} = ({} as __VLS_WithComponent<'${getCanonicalComponentName(node.tag)}', __VLS_LocalComponents, `;
|
|
110
|
+
if (options.selfComponentName && possibleOriginalNames.includes(options.selfComponentName)) {
|
|
111
|
+
yield `typeof __VLS_self & (new () => { `
|
|
112
|
+
+ (0, shared_2.getSlotsPropertyName)(options.vueCompilerOptions.target)
|
|
113
|
+
+ `: __VLS_Slots }), `;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
yield `void, `;
|
|
117
|
+
}
|
|
118
|
+
yield getPossibleOriginalComponentNames(node.tag, false)
|
|
119
|
+
.map(name => `'${name}'`)
|
|
120
|
+
.join(`, `);
|
|
121
|
+
yield `>).`;
|
|
122
|
+
yield* generateCanonicalComponentName(node.tag, tagOffsets[0], ctx.codeFeatures.withoutHighlightAndCompletionAndNavigation);
|
|
123
|
+
yield `${utils_1.endOfLine}`;
|
|
114
124
|
const camelizedTag = (0, shared_1.camelize)(node.tag);
|
|
115
|
-
if (
|
|
125
|
+
if (utils_1.variableNameRegex.test(camelizedTag)) {
|
|
116
126
|
// renaming / find references support
|
|
117
127
|
yield `/** @type { [`;
|
|
118
128
|
for (const tagOffset of tagOffsets) {
|
|
@@ -128,47 +138,53 @@ function* generateComponent(options, ctx, node, currentComponent) {
|
|
|
128
138
|
yield `, `;
|
|
129
139
|
}
|
|
130
140
|
}
|
|
131
|
-
yield `] } */${
|
|
141
|
+
yield `] } */${utils_1.endOfLine}`;
|
|
132
142
|
// auto import support
|
|
133
143
|
if (options.edited) {
|
|
134
|
-
yield `// @ts-ignore${
|
|
135
|
-
yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(node.tag),
|
|
144
|
+
yield `// @ts-ignore${utils_1.newLine}`; // #2304
|
|
145
|
+
yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(node.tag), tagOffsets[0], {
|
|
136
146
|
completion: {
|
|
137
147
|
isAdditional: true,
|
|
138
148
|
onlyImport: true,
|
|
139
149
|
},
|
|
140
150
|
});
|
|
141
|
-
yield `${
|
|
151
|
+
yield `${utils_1.endOfLine}`;
|
|
142
152
|
}
|
|
143
153
|
}
|
|
144
154
|
}
|
|
145
155
|
else {
|
|
146
|
-
yield `const ${var_originalComponent} = {} as any${
|
|
147
|
-
}
|
|
148
|
-
yield `// @ts-ignore${
|
|
149
|
-
yield `const ${var_functionalComponent} = __VLS_asFunctionalComponent(${var_originalComponent}, new ${var_originalComponent}({`;
|
|
150
|
-
yield* (0, elementProps_1.generateElementProps)(options, ctx, node, props, false);
|
|
151
|
-
yield `}))${
|
|
152
|
-
yield `const
|
|
153
|
-
yield* (0,
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
156
|
+
yield `const ${var_originalComponent} = {} as any${utils_1.endOfLine}`;
|
|
157
|
+
}
|
|
158
|
+
yield `// @ts-ignore${utils_1.newLine}`;
|
|
159
|
+
yield `const ${var_functionalComponent} = __VLS_asFunctionalComponent(${var_originalComponent}, new ${var_originalComponent}({${utils_1.newLine}`;
|
|
160
|
+
yield* (0, elementProps_1.generateElementProps)(options, ctx, node, props, options.vueCompilerOptions.checkUnknownProps, false);
|
|
161
|
+
yield `}))${utils_1.endOfLine}`;
|
|
162
|
+
yield `const `;
|
|
163
|
+
yield* (0, utils_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, ctx.resolveCodeFeatures({
|
|
164
|
+
verification: {
|
|
165
|
+
shouldReport(_source, code) {
|
|
166
|
+
return String(code) !== '6133';
|
|
167
|
+
},
|
|
168
|
+
}
|
|
169
|
+
}), var_componentInstance);
|
|
170
|
+
yield ` = ${var_functionalComponent}`;
|
|
171
|
+
yield* generateComponentGeneric(ctx);
|
|
172
|
+
yield `(`;
|
|
173
|
+
yield* (0, utils_1.wrapWith)(tagOffsets[0], tagOffsets[0] + node.tag.length, ctx.codeFeatures.verification, `{${utils_1.newLine}`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, props, options.vueCompilerOptions.checkUnknownProps, true, failedPropExps), `}`);
|
|
174
|
+
yield `, ...__VLS_functionalComponentArgsRest(${var_functionalComponent}))${utils_1.endOfLine}`;
|
|
175
|
+
yield* generateFailedPropExps(options, ctx, failedPropExps);
|
|
160
176
|
const [refName, offset] = yield* generateVScope(options, ctx, node, props);
|
|
161
177
|
const isRootNode = node === ctx.singleRootNode;
|
|
162
178
|
if (refName || isRootNode) {
|
|
163
179
|
const varName = ctx.getInternalVariable();
|
|
164
|
-
ctx.
|
|
180
|
+
ctx.currentComponent.used = true;
|
|
165
181
|
yield `var ${varName} = {} as (Parameters<NonNullable<typeof ${var_defineComponentCtx}['expose']>>[0] | null)`;
|
|
166
182
|
if (node.codegenNode?.type === CompilerDOM.NodeTypes.VNODE_CALL
|
|
167
183
|
&& node.codegenNode.props?.type === CompilerDOM.NodeTypes.JS_OBJECT_EXPRESSION
|
|
168
184
|
&& node.codegenNode.props.properties.some(({ key }) => key.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && key.content === 'ref_for')) {
|
|
169
185
|
yield `[]`;
|
|
170
186
|
}
|
|
171
|
-
yield `${
|
|
187
|
+
yield `${utils_1.endOfLine}`;
|
|
172
188
|
if (refName) {
|
|
173
189
|
ctx.templateRefs.set(refName, [varName, offset]);
|
|
174
190
|
}
|
|
@@ -176,49 +192,44 @@ function* generateComponent(options, ctx, node, currentComponent) {
|
|
|
176
192
|
ctx.singleRootElType = `NonNullable<typeof ${varName}>['$el']`;
|
|
177
193
|
}
|
|
178
194
|
}
|
|
179
|
-
const usedComponentEventsVar = yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, var_functionalComponent, var_componentInstance,
|
|
195
|
+
const usedComponentEventsVar = yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, var_functionalComponent, var_componentInstance, var_componentEvents);
|
|
180
196
|
if (usedComponentEventsVar) {
|
|
181
|
-
ctx.
|
|
182
|
-
yield `let ${var_componentEmit}!: typeof ${var_defineComponentCtx}.emit${
|
|
183
|
-
yield `let ${var_componentEvents}!: __VLS_NormalizeEmits<typeof ${var_componentEmit}>${
|
|
197
|
+
ctx.currentComponent.used = true;
|
|
198
|
+
yield `let ${var_componentEmit}!: typeof ${var_defineComponentCtx}.emit${utils_1.endOfLine}`;
|
|
199
|
+
yield `let ${var_componentEvents}!: __VLS_NormalizeEmits<typeof ${var_componentEmit}>${utils_1.endOfLine}`;
|
|
184
200
|
}
|
|
185
|
-
if (options
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
ctx.inheritedAttrVars.add(varAttrs);
|
|
190
|
-
yield `var ${varAttrs}!: Parameters<typeof ${var_functionalComponent}>[0];\n`;
|
|
201
|
+
if (hasVBindAttrs(options, ctx, node)) {
|
|
202
|
+
const attrsVar = ctx.getInternalVariable();
|
|
203
|
+
ctx.inheritedAttrVars.add(attrsVar);
|
|
204
|
+
yield `let ${attrsVar}!: Parameters<typeof ${var_functionalComponent}>[0];\n`;
|
|
191
205
|
}
|
|
192
206
|
const slotDir = node.props.find(p => p.type === CompilerDOM.NodeTypes.DIRECTIVE && p.name === 'slot');
|
|
193
207
|
if (slotDir) {
|
|
194
|
-
yield*
|
|
208
|
+
yield* (0, vSlot_1.generateVSlot)(options, ctx, node, slotDir);
|
|
195
209
|
}
|
|
196
210
|
else {
|
|
197
|
-
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node,
|
|
211
|
+
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node, true);
|
|
198
212
|
}
|
|
199
|
-
if (ctx.
|
|
200
|
-
yield `var ${var_defineComponentCtx}!: __VLS_PickFunctionalComponentCtx<typeof ${var_originalComponent}, typeof ${var_componentInstance}>${
|
|
213
|
+
if (ctx.currentComponent.used) {
|
|
214
|
+
yield `var ${var_defineComponentCtx}!: __VLS_PickFunctionalComponentCtx<typeof ${var_originalComponent}, typeof ${var_componentInstance}>${utils_1.endOfLine}`;
|
|
201
215
|
}
|
|
202
216
|
}
|
|
203
|
-
function* generateElement(options, ctx, node,
|
|
204
|
-
const startTagOffset = node.loc.start.offset + options.template.content.
|
|
217
|
+
function* generateElement(options, ctx, node, isVForChild) {
|
|
218
|
+
const startTagOffset = node.loc.start.offset + options.template.content.slice(node.loc.start.offset).indexOf(node.tag);
|
|
205
219
|
const endTagOffset = !node.isSelfClosing && options.template.lang === 'html'
|
|
206
220
|
? node.loc.start.offset + node.loc.source.lastIndexOf(node.tag)
|
|
207
221
|
: undefined;
|
|
208
|
-
const
|
|
209
|
-
yield `
|
|
222
|
+
const failedPropExps = [];
|
|
223
|
+
yield `__VLS_asFunctionalElement(__VLS_intrinsicElements`;
|
|
210
224
|
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, startTagOffset, ctx.codeFeatures.withoutHighlightAndCompletion);
|
|
211
225
|
if (endTagOffset !== undefined) {
|
|
212
226
|
yield `, __VLS_intrinsicElements`;
|
|
213
227
|
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, endTagOffset, ctx.codeFeatures.withoutHighlightAndCompletion);
|
|
214
228
|
}
|
|
215
229
|
yield `)(`;
|
|
216
|
-
yield* (0,
|
|
217
|
-
yield `)${
|
|
218
|
-
|
|
219
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, failedExp.node.loc.source, failedExp.node.loc, failedExp.node.loc.start.offset, ctx.codeFeatures.all, failedExp.prefix, failedExp.suffix);
|
|
220
|
-
yield common_1.endOfLine;
|
|
221
|
-
}
|
|
230
|
+
yield* (0, utils_1.wrapWith)(startTagOffset, startTagOffset + node.tag.length, ctx.codeFeatures.verification, `{${utils_1.newLine}`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, node.props, options.vueCompilerOptions.checkUnknownProps, true, failedPropExps), `}`);
|
|
231
|
+
yield `)${utils_1.endOfLine}`;
|
|
232
|
+
yield* generateFailedPropExps(options, ctx, failedPropExps);
|
|
222
233
|
const [refName, offset] = yield* generateVScope(options, ctx, node, node.props);
|
|
223
234
|
if (refName) {
|
|
224
235
|
let refValue = `__VLS_nativeElements['${node.tag}']`;
|
|
@@ -230,18 +241,16 @@ function* generateElement(options, ctx, node, currentComponent, componentCtxVar,
|
|
|
230
241
|
if (ctx.singleRootNode === node) {
|
|
231
242
|
ctx.singleRootElType = `typeof __VLS_nativeElements['${node.tag}']`;
|
|
232
243
|
}
|
|
233
|
-
|
|
234
|
-
if (slotDir && componentCtxVar) {
|
|
235
|
-
yield* generateComponentSlot(options, ctx, node, slotDir, currentComponent, componentCtxVar);
|
|
236
|
-
}
|
|
237
|
-
else {
|
|
238
|
-
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node, currentComponent, componentCtxVar);
|
|
239
|
-
}
|
|
240
|
-
if (options.vueCompilerOptions.fallthroughAttributes
|
|
241
|
-
&& (node.props.some(prop => prop.type === CompilerDOM.NodeTypes.DIRECTIVE && prop.name === 'bind' && prop.exp?.loc.source === '$attrs')
|
|
242
|
-
|| node === ctx.singleRootNode)) {
|
|
244
|
+
if (hasVBindAttrs(options, ctx, node)) {
|
|
243
245
|
ctx.inheritedAttrVars.add(`__VLS_intrinsicElements.${node.tag}`);
|
|
244
246
|
}
|
|
247
|
+
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node);
|
|
248
|
+
}
|
|
249
|
+
function* generateFailedPropExps(options, ctx, failedPropExps) {
|
|
250
|
+
for (const failedExp of failedPropExps) {
|
|
251
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, failedExp.node.loc.source, failedExp.node.loc.start.offset, failedExp.node.loc, failedExp.prefix, failedExp.suffix);
|
|
252
|
+
yield utils_1.endOfLine;
|
|
253
|
+
}
|
|
245
254
|
}
|
|
246
255
|
function* generateVScope(options, ctx, node, props) {
|
|
247
256
|
const vScope = props.find(prop => prop.type === CompilerDOM.NodeTypes.DIRECTIVE && (prop.name === 'scope' || prop.name === 'data'));
|
|
@@ -257,22 +266,22 @@ function* generateVScope(options, ctx, node, props) {
|
|
|
257
266
|
vScope.exp.loc.start.offset,
|
|
258
267
|
ctx.codeFeatures.all,
|
|
259
268
|
];
|
|
260
|
-
yield
|
|
261
|
-
yield `if (${condition}) {${
|
|
269
|
+
yield utils_1.endOfLine;
|
|
270
|
+
yield `if (${condition}) {${utils_1.newLine}`;
|
|
262
271
|
ctx.blockConditions.push(condition);
|
|
263
272
|
inScope = true;
|
|
264
273
|
}
|
|
265
274
|
yield* (0, elementDirectives_1.generateElementDirectives)(options, ctx, node);
|
|
266
275
|
const [refName, offset] = yield* generateReferencesForElements(options, ctx, node); // <el ref="foo" />
|
|
267
|
-
|
|
276
|
+
(0, styleScopedClasses_1.collectStyleScopedClassReferences)(options, ctx, node);
|
|
268
277
|
if (inScope) {
|
|
269
|
-
yield `}${
|
|
278
|
+
yield `}${utils_1.newLine}`;
|
|
270
279
|
ctx.blockConditions.length = originalConditionsNum;
|
|
271
280
|
}
|
|
272
281
|
return [refName, offset];
|
|
273
282
|
}
|
|
274
283
|
function getCanonicalComponentName(tagText) {
|
|
275
|
-
return
|
|
284
|
+
return utils_1.variableNameRegex.test(tagText)
|
|
276
285
|
? tagText
|
|
277
286
|
: (0, shared_1.capitalize)((0, shared_1.camelize)(tagText.replace(colonReg, '-')));
|
|
278
287
|
}
|
|
@@ -290,101 +299,36 @@ function getPossibleOriginalComponentNames(tagText, deduplicate) {
|
|
|
290
299
|
return names;
|
|
291
300
|
}
|
|
292
301
|
function* generateCanonicalComponentName(tagText, offset, features) {
|
|
293
|
-
if (
|
|
302
|
+
if (utils_1.variableNameRegex.test(tagText)) {
|
|
294
303
|
yield [tagText, 'template', offset, features];
|
|
295
304
|
}
|
|
296
305
|
else {
|
|
297
306
|
yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(tagText.replace(colonReg, '-')), offset, features);
|
|
298
307
|
}
|
|
299
308
|
}
|
|
300
|
-
function*
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
}
|
|
306
|
-
const slotBlockVars = [];
|
|
307
|
-
yield `const {`;
|
|
308
|
-
if (slotDir?.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && slotDir.arg.content) {
|
|
309
|
-
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slotDir.arg.loc.source, slotDir.arg.loc.start.offset, slotDir.arg.isStatic ? ctx.codeFeatures.withoutHighlight : ctx.codeFeatures.all, slotDir.arg.loc, false, true);
|
|
310
|
-
yield ': __VLS_thisSlot';
|
|
311
|
-
}
|
|
312
|
-
else {
|
|
313
|
-
yield `default: `;
|
|
314
|
-
yield* (0, common_1.wrapWith)(slotDir.loc.start.offset, slotDir.loc.start.offset + (slotDir.loc.source.startsWith('#')
|
|
315
|
-
? '#'.length
|
|
316
|
-
: slotDir.loc.source.startsWith('v-slot:')
|
|
317
|
-
? 'v-slot:'.length
|
|
318
|
-
: 0), ctx.codeFeatures.withoutHighlightAndCompletion, `__VLS_thisSlot`);
|
|
319
|
-
}
|
|
320
|
-
yield `} = __VLS_nonNullable(${componentCtxVar}.slots)${common_1.endOfLine}`;
|
|
321
|
-
if (slotDir?.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
322
|
-
const slotAst = (0, common_1.createTsAst)(options.ts, slotDir, `(${slotDir.exp.content}) => {}`);
|
|
323
|
-
(0, common_1.collectVars)(options.ts, slotAst, slotAst, slotBlockVars);
|
|
324
|
-
if (!slotDir.exp.content.includes(':')) {
|
|
325
|
-
yield `const [`;
|
|
326
|
-
yield [
|
|
327
|
-
slotDir.exp.content,
|
|
328
|
-
'template',
|
|
329
|
-
slotDir.exp.loc.start.offset,
|
|
330
|
-
ctx.codeFeatures.all,
|
|
331
|
-
];
|
|
332
|
-
yield `] = __VLS_getSlotParams(__VLS_thisSlot)${common_1.endOfLine}`;
|
|
333
|
-
}
|
|
334
|
-
else {
|
|
335
|
-
yield `const `;
|
|
336
|
-
yield [
|
|
337
|
-
slotDir.exp.content,
|
|
338
|
-
'template',
|
|
339
|
-
slotDir.exp.loc.start.offset,
|
|
340
|
-
ctx.codeFeatures.all,
|
|
341
|
-
];
|
|
342
|
-
yield ` = __VLS_getSlotParam(__VLS_thisSlot)${common_1.endOfLine}`;
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
for (const varName of slotBlockVars) {
|
|
346
|
-
ctx.addLocalVariable(varName);
|
|
347
|
-
}
|
|
348
|
-
yield* ctx.resetDirectiveComments('end of slot children start');
|
|
349
|
-
let prev;
|
|
350
|
-
for (const childNode of node.children) {
|
|
351
|
-
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, currentComponent, prev, componentCtxVar);
|
|
352
|
-
prev = childNode;
|
|
353
|
-
}
|
|
354
|
-
for (const varName of slotBlockVars) {
|
|
355
|
-
ctx.removeLocalVariable(varName);
|
|
356
|
-
}
|
|
357
|
-
let isStatic = true;
|
|
358
|
-
if (slotDir?.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
359
|
-
isStatic = slotDir.arg.isStatic;
|
|
360
|
-
}
|
|
361
|
-
if (isStatic && slotDir && !slotDir.arg) {
|
|
362
|
-
yield `__VLS_nonNullable(${componentCtxVar}.slots)['`;
|
|
363
|
-
yield [
|
|
364
|
-
'',
|
|
309
|
+
function* generateComponentGeneric(ctx) {
|
|
310
|
+
if (ctx.lastGenericComment) {
|
|
311
|
+
const { content, offset } = ctx.lastGenericComment;
|
|
312
|
+
yield* (0, utils_1.wrapWith)(offset, offset + content.length, ctx.codeFeatures.verification, `<`, [
|
|
313
|
+
content,
|
|
365
314
|
'template',
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
: 0),
|
|
370
|
-
ctx.codeFeatures.completion,
|
|
371
|
-
];
|
|
372
|
-
yield `'/* empty slot name completion */]${common_1.newLine}`;
|
|
315
|
+
offset,
|
|
316
|
+
ctx.codeFeatures.all
|
|
317
|
+
], `>`);
|
|
373
318
|
}
|
|
374
|
-
|
|
375
|
-
yield `}${common_1.newLine}`;
|
|
319
|
+
ctx.lastGenericComment = undefined;
|
|
376
320
|
}
|
|
377
321
|
function* generateReferencesForElements(options, ctx, node) {
|
|
378
322
|
for (const prop of node.props) {
|
|
379
323
|
if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE
|
|
380
324
|
&& prop.name === 'ref'
|
|
381
325
|
&& prop.value) {
|
|
382
|
-
const [content, startOffset] = normalizeAttributeValue(prop.value);
|
|
383
|
-
yield `// @ts-ignore navigation for \`const ${content} = ref()\`${
|
|
384
|
-
yield
|
|
326
|
+
const [content, startOffset] = (0, utils_1.normalizeAttributeValue)(prop.value);
|
|
327
|
+
yield `// @ts-ignore navigation for \`const ${content} = ref()\`${utils_1.newLine}`;
|
|
328
|
+
yield `/** @type { typeof __VLS_ctx`;
|
|
385
329
|
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, content, startOffset, ctx.codeFeatures.navigation, prop.value.loc);
|
|
386
|
-
yield
|
|
387
|
-
if (
|
|
330
|
+
yield ` } */${utils_1.endOfLine}`;
|
|
331
|
+
if (utils_1.variableNameRegex.test(content) && !options.templateRefNames.has(content)) {
|
|
388
332
|
ctx.accessExternalVariable(content, startOffset);
|
|
389
333
|
}
|
|
390
334
|
return [content, startOffset];
|
|
@@ -392,111 +336,11 @@ function* generateReferencesForElements(options, ctx, node) {
|
|
|
392
336
|
}
|
|
393
337
|
return [];
|
|
394
338
|
}
|
|
395
|
-
function
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
&& prop.name === '
|
|
399
|
-
&& prop.
|
|
400
|
-
if (options.template.lang === 'pug') {
|
|
401
|
-
const getClassOffset = Reflect.get(prop.value.loc.start, 'getClassOffset');
|
|
402
|
-
const content = prop.value.loc.source.slice(1, -1);
|
|
403
|
-
let startOffset = 1;
|
|
404
|
-
for (const className of content.split(' ')) {
|
|
405
|
-
if (className) {
|
|
406
|
-
ctx.scopedClasses.push({
|
|
407
|
-
source: 'template',
|
|
408
|
-
className,
|
|
409
|
-
offset: getClassOffset(startOffset),
|
|
410
|
-
});
|
|
411
|
-
}
|
|
412
|
-
startOffset += className.length + 1;
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
else {
|
|
416
|
-
let isWrapped = false;
|
|
417
|
-
const [content, startOffset] = normalizeAttributeValue(prop.value);
|
|
418
|
-
if (content) {
|
|
419
|
-
const classes = collectClasses(content, startOffset + (isWrapped ? 1 : 0));
|
|
420
|
-
ctx.scopedClasses.push(...classes);
|
|
421
|
-
}
|
|
422
|
-
else {
|
|
423
|
-
ctx.emptyClassOffsets.push(startOffset);
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
else if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
428
|
-
&& prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
429
|
-
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
430
|
-
&& prop.arg.content === 'class') {
|
|
431
|
-
const content = '`${' + prop.exp.content + '}`';
|
|
432
|
-
const startOffset = prop.exp.loc.start.offset - 3;
|
|
433
|
-
const { ts } = options;
|
|
434
|
-
const ast = ts.createSourceFile('', content, 99);
|
|
435
|
-
const literals = [];
|
|
436
|
-
ts.forEachChild(ast, node => {
|
|
437
|
-
if (!ts.isExpressionStatement(node) ||
|
|
438
|
-
!isTemplateExpression(node.expression)) {
|
|
439
|
-
return;
|
|
440
|
-
}
|
|
441
|
-
const expression = node.expression.templateSpans[0].expression;
|
|
442
|
-
if (ts.isStringLiteralLike(expression)) {
|
|
443
|
-
literals.push(expression);
|
|
444
|
-
}
|
|
445
|
-
if (ts.isArrayLiteralExpression(expression)) {
|
|
446
|
-
walkArrayLiteral(expression);
|
|
447
|
-
}
|
|
448
|
-
if (ts.isObjectLiteralExpression(expression)) {
|
|
449
|
-
walkObjectLiteral(expression);
|
|
450
|
-
}
|
|
451
|
-
});
|
|
452
|
-
for (const literal of literals) {
|
|
453
|
-
const classes = collectClasses(literal.text, literal.end - literal.text.length - 1 + startOffset);
|
|
454
|
-
ctx.scopedClasses.push(...classes);
|
|
455
|
-
}
|
|
456
|
-
function walkArrayLiteral(node) {
|
|
457
|
-
const { elements } = node;
|
|
458
|
-
for (const element of elements) {
|
|
459
|
-
if (ts.isStringLiteralLike(element)) {
|
|
460
|
-
literals.push(element);
|
|
461
|
-
}
|
|
462
|
-
else if (ts.isObjectLiteralExpression(element)) {
|
|
463
|
-
walkObjectLiteral(element);
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
function walkObjectLiteral(node) {
|
|
468
|
-
const { properties } = node;
|
|
469
|
-
for (const property of properties) {
|
|
470
|
-
if (ts.isPropertyAssignment(property)) {
|
|
471
|
-
const { name } = property;
|
|
472
|
-
if (ts.isIdentifier(name)) {
|
|
473
|
-
walkIdentifier(name);
|
|
474
|
-
}
|
|
475
|
-
else if (ts.isStringLiteral(name)) {
|
|
476
|
-
literals.push(name);
|
|
477
|
-
}
|
|
478
|
-
else if (ts.isComputedPropertyName(name)) {
|
|
479
|
-
const { expression } = name;
|
|
480
|
-
if (ts.isStringLiteralLike(expression)) {
|
|
481
|
-
literals.push(expression);
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
else if (ts.isShorthandPropertyAssignment(property)) {
|
|
486
|
-
walkIdentifier(property.name);
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
function walkIdentifier(node) {
|
|
491
|
-
const text = (0, scriptSetupRanges_1.getNodeText)(ts, node, ast);
|
|
492
|
-
ctx.scopedClasses.push({
|
|
493
|
-
source: 'template',
|
|
494
|
-
className: text,
|
|
495
|
-
offset: node.end - text.length + startOffset
|
|
496
|
-
});
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
}
|
|
339
|
+
function hasVBindAttrs(options, ctx, node) {
|
|
340
|
+
return options.vueCompilerOptions.fallthroughAttributes && (node === ctx.singleRootNode ||
|
|
341
|
+
node.props.some(prop => prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
342
|
+
&& prop.name === 'bind'
|
|
343
|
+
&& prop.exp?.loc.source === '$attrs'));
|
|
500
344
|
}
|
|
501
345
|
function camelizeComponentName(newName) {
|
|
502
346
|
return (0, shared_1.camelize)('-' + newName);
|
|
@@ -504,41 +348,4 @@ function camelizeComponentName(newName) {
|
|
|
504
348
|
function getTagRenameApply(oldName) {
|
|
505
349
|
return oldName === (0, shared_2.hyphenateTag)(oldName) ? shared_2.hyphenateTag : undefined;
|
|
506
350
|
}
|
|
507
|
-
function normalizeAttributeValue(node) {
|
|
508
|
-
let offset = node.loc.start.offset;
|
|
509
|
-
let content = node.loc.source;
|
|
510
|
-
if ((content.startsWith(`'`) && content.endsWith(`'`))
|
|
511
|
-
|| (content.startsWith(`"`) && content.endsWith(`"`))) {
|
|
512
|
-
offset++;
|
|
513
|
-
content = content.slice(1, -1);
|
|
514
|
-
}
|
|
515
|
-
return [content, offset];
|
|
516
|
-
}
|
|
517
|
-
function collectClasses(content, startOffset = 0) {
|
|
518
|
-
const classes = [];
|
|
519
|
-
let currentClassName = '';
|
|
520
|
-
let offset = 0;
|
|
521
|
-
for (const char of (content + ' ')) {
|
|
522
|
-
if (char.trim() === '') {
|
|
523
|
-
if (currentClassName !== '') {
|
|
524
|
-
classes.push({
|
|
525
|
-
source: 'template',
|
|
526
|
-
className: currentClassName,
|
|
527
|
-
offset: offset + startOffset
|
|
528
|
-
});
|
|
529
|
-
offset += currentClassName.length;
|
|
530
|
-
currentClassName = '';
|
|
531
|
-
}
|
|
532
|
-
offset += char.length;
|
|
533
|
-
}
|
|
534
|
-
else {
|
|
535
|
-
currentClassName += char;
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
return classes;
|
|
539
|
-
}
|
|
540
|
-
// isTemplateExpression is missing in tsc
|
|
541
|
-
function isTemplateExpression(node) {
|
|
542
|
-
return node.kind === 228;
|
|
543
|
-
}
|
|
544
351
|
//# sourceMappingURL=element.js.map
|
|
@@ -2,4 +2,4 @@ import * as CompilerDOM from '@vue/compiler-dom';
|
|
|
2
2
|
import type { Code } from '../../types';
|
|
3
3
|
import type { TemplateCodegenContext } from './context';
|
|
4
4
|
import type { TemplateCodegenOptions } from './index';
|
|
5
|
-
export declare function generateElementChildren(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode,
|
|
5
|
+
export declare function generateElementChildren(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, isDefaultSlot?: boolean): Generator<Code>;
|