@vue/language-core 2.2.0 → 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/common.d.ts +12 -0
- package/lib/codegen/common.js +79 -0
- package/lib/codegen/globalTypes.d.ts +3 -1
- package/lib/codegen/globalTypes.js +30 -14
- package/lib/codegen/localTypes.d.ts +1 -1
- package/lib/codegen/localTypes.js +4 -4
- 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 +7 -7
- package/lib/codegen/script/componentSelf.d.ts +1 -1
- package/lib/codegen/script/componentSelf.js +2 -2
- package/lib/codegen/script/context.d.ts +1 -1
- package/lib/codegen/script/index.d.ts +1 -8
- package/lib/codegen/script/index.js +15 -39
- package/lib/codegen/script/scriptSetup.d.ts +1 -1
- package/lib/codegen/script/scriptSetup.js +46 -58
- package/lib/codegen/script/src.js +2 -2
- package/lib/codegen/script/styleModulesType.d.ts +1 -1
- package/lib/codegen/script/styleModulesType.js +2 -2
- package/lib/codegen/script/template.d.ts +1 -1
- package/lib/codegen/script/template.js +11 -32
- package/lib/codegen/template/camelized.d.ts +2 -0
- package/lib/codegen/template/camelized.js +31 -0
- package/lib/codegen/template/context.d.ts +17 -13
- package/lib/codegen/template/context.js +35 -89
- package/lib/codegen/template/element.js +32 -252
- package/lib/codegen/template/elementChildren.d.ts +1 -1
- package/lib/codegen/template/elementChildren.js +3 -4
- package/lib/codegen/template/elementDirectives.js +18 -11
- package/lib/codegen/template/elementProps.d.ts +2 -1
- package/lib/codegen/template/elementProps.js +22 -26
- package/lib/codegen/template/index.d.ts +1 -0
- package/lib/codegen/template/index.js +39 -33
- package/lib/codegen/template/interpolation.js +13 -9
- package/lib/codegen/template/slotOutlet.js +39 -17
- package/lib/codegen/template/styleScopedClasses.d.ts +3 -0
- package/lib/codegen/template/styleScopedClasses.js +141 -0
- package/lib/codegen/template/templateChild.js +9 -2
- package/lib/codegen/template/vSlot.d.ts +5 -0
- package/lib/codegen/template/vSlot.js +80 -0
- package/lib/codegen/utils/index.d.ts +11 -1
- package/lib/codegen/utils/index.js +15 -4
- package/lib/codegen/utils/src.d.ts +2 -0
- package/lib/codegen/utils/src.js +19 -0
- package/lib/parsers/scriptSetupRanges.d.ts +5 -3
- package/lib/parsers/scriptSetupRanges.js +8 -11
- package/lib/parsers/vueCompilerOptions.d.ts +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-inline-ts.js +53 -12
- package/lib/plugins/vue-tsx.d.ts +35 -28
- package/lib/plugins/vue-tsx.js +75 -55
- package/lib/plugins/vue-vine.d.ts +3 -0
- package/lib/plugins/vue-vine.js +35 -0
- package/lib/types.d.ts +6 -2
- package/lib/utils/findDestructuredProps.d.ts +1 -0
- package/lib/utils/findDestructuredProps.js +3 -0
- package/lib/utils/parseCssImports.d.ts +4 -0
- package/lib/utils/parseCssImports.js +19 -0
- package/lib/utils/parseSfc.js +4 -3
- 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 +117 -88
- package/lib/virtualFile/computedEmbeddedCodes.d.ts +1 -1
- package/lib/virtualFile/computedEmbeddedCodes.js +11 -11
- package/lib/virtualFile/computedSfc.d.ts +1 -2
- package/lib/virtualFile/computedSfc.js +79 -82
- 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 +4 -4
|
@@ -4,37 +4,42 @@ import { InlayHintInfo } from '../inlayHints';
|
|
|
4
4
|
import type { TemplateCodegenOptions } from './index';
|
|
5
5
|
export type TemplateCodegenContext = ReturnType<typeof createTemplateCodegenContext>;
|
|
6
6
|
export declare function createTemplateCodegenContext(options: Pick<TemplateCodegenOptions, 'scriptSetupBindingNames' | 'edited'>): {
|
|
7
|
-
slots: {
|
|
8
|
-
name: string;
|
|
9
|
-
loc?: number;
|
|
10
|
-
tagRange: [number, number];
|
|
11
|
-
varName: string;
|
|
12
|
-
nodeLoc: any;
|
|
13
|
-
}[];
|
|
14
|
-
dynamicSlots: {
|
|
15
|
-
expVar: string;
|
|
16
|
-
varName: string;
|
|
17
|
-
}[];
|
|
18
7
|
codeFeatures: {
|
|
19
8
|
all: VueCodeInformation;
|
|
9
|
+
none: VueCodeInformation;
|
|
20
10
|
verification: VueCodeInformation;
|
|
21
11
|
completion: VueCodeInformation;
|
|
22
12
|
additionalCompletion: VueCodeInformation;
|
|
13
|
+
withoutCompletion: VueCodeInformation;
|
|
23
14
|
navigation: VueCodeInformation;
|
|
24
15
|
navigationWithoutRename: VueCodeInformation;
|
|
25
16
|
navigationAndCompletion: VueCodeInformation;
|
|
26
17
|
navigationAndAdditionalCompletion: VueCodeInformation;
|
|
18
|
+
navigationAndVerification: VueCodeInformation;
|
|
27
19
|
withoutNavigation: VueCodeInformation;
|
|
28
20
|
withoutHighlight: VueCodeInformation;
|
|
21
|
+
withoutHighlightAndNavigation: VueCodeInformation;
|
|
29
22
|
withoutHighlightAndCompletion: VueCodeInformation;
|
|
30
23
|
withoutHighlightAndCompletionAndNavigation: VueCodeInformation;
|
|
31
24
|
};
|
|
25
|
+
resolveCodeFeatures: (features: VueCodeInformation) => VueCodeInformation;
|
|
26
|
+
slots: {
|
|
27
|
+
name: string;
|
|
28
|
+
offset?: number;
|
|
29
|
+
tagRange: [number, number];
|
|
30
|
+
nodeLoc: any;
|
|
31
|
+
propsVar: string;
|
|
32
|
+
}[];
|
|
33
|
+
dynamicSlots: {
|
|
34
|
+
expVar: string;
|
|
35
|
+
propsVar: string;
|
|
36
|
+
}[];
|
|
37
|
+
specialVars: Set<string>;
|
|
32
38
|
accessExternalVariables: Map<string, Set<number>>;
|
|
33
39
|
lastGenericComment: {
|
|
34
40
|
content: string;
|
|
35
41
|
offset: number;
|
|
36
42
|
} | undefined;
|
|
37
|
-
hasSlotElements: Set<CompilerDOM.ElementNode>;
|
|
38
43
|
blockConditions: string[];
|
|
39
44
|
scopedClasses: {
|
|
40
45
|
source: string;
|
|
@@ -48,7 +53,6 @@ export declare function createTemplateCodegenContext(options: Pick<TemplateCodeg
|
|
|
48
53
|
inheritedAttrVars: Set<string>;
|
|
49
54
|
templateRefs: Map<string, [varName: string, offset: number]>;
|
|
50
55
|
currentComponent: {
|
|
51
|
-
node: CompilerDOM.ElementNode;
|
|
52
56
|
ctxVar: string;
|
|
53
57
|
used: boolean;
|
|
54
58
|
} | undefined;
|
|
@@ -1,101 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createTemplateCodegenContext = createTemplateCodegenContext;
|
|
4
|
+
const codeFeatures_1 = require("../codeFeatures");
|
|
4
5
|
const utils_1 = require("../utils");
|
|
5
|
-
const _codeFeatures = {
|
|
6
|
-
all: {
|
|
7
|
-
verification: true,
|
|
8
|
-
completion: true,
|
|
9
|
-
semantic: true,
|
|
10
|
-
navigation: true,
|
|
11
|
-
},
|
|
12
|
-
verification: {
|
|
13
|
-
verification: true,
|
|
14
|
-
},
|
|
15
|
-
completion: {
|
|
16
|
-
completion: true,
|
|
17
|
-
},
|
|
18
|
-
additionalCompletion: {
|
|
19
|
-
completion: { isAdditional: true },
|
|
20
|
-
},
|
|
21
|
-
navigation: {
|
|
22
|
-
navigation: true,
|
|
23
|
-
},
|
|
24
|
-
navigationWithoutRename: {
|
|
25
|
-
navigation: {
|
|
26
|
-
shouldRename() {
|
|
27
|
-
return false;
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
navigationAndCompletion: {
|
|
32
|
-
navigation: true,
|
|
33
|
-
completion: true,
|
|
34
|
-
},
|
|
35
|
-
navigationAndAdditionalCompletion: {
|
|
36
|
-
navigation: true,
|
|
37
|
-
completion: { isAdditional: true },
|
|
38
|
-
},
|
|
39
|
-
withoutNavigation: {
|
|
40
|
-
verification: true,
|
|
41
|
-
completion: true,
|
|
42
|
-
semantic: true,
|
|
43
|
-
},
|
|
44
|
-
withoutHighlight: {
|
|
45
|
-
semantic: { shouldHighlight: () => false },
|
|
46
|
-
verification: true,
|
|
47
|
-
navigation: true,
|
|
48
|
-
completion: true,
|
|
49
|
-
},
|
|
50
|
-
withoutHighlightAndCompletion: {
|
|
51
|
-
semantic: { shouldHighlight: () => false },
|
|
52
|
-
verification: true,
|
|
53
|
-
navigation: true,
|
|
54
|
-
},
|
|
55
|
-
withoutHighlightAndCompletionAndNavigation: {
|
|
56
|
-
semantic: { shouldHighlight: () => false },
|
|
57
|
-
verification: true,
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
6
|
function createTemplateCodegenContext(options) {
|
|
61
7
|
let ignoredError = false;
|
|
62
8
|
let expectErrorToken;
|
|
63
9
|
let lastGenericComment;
|
|
64
10
|
let variableId = 0;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
verification: false,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
if (expectErrorToken) {
|
|
76
|
-
const token = expectErrorToken;
|
|
77
|
-
if (typeof data.verification !== 'object' || !data.verification.shouldReport) {
|
|
78
|
-
return {
|
|
79
|
-
...data,
|
|
80
|
-
verification: {
|
|
81
|
-
shouldReport: () => {
|
|
82
|
-
token.errors++;
|
|
83
|
-
return false;
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
}
|
|
11
|
+
function resolveCodeFeatures(features) {
|
|
12
|
+
if (features.verification) {
|
|
13
|
+
if (ignoredError) {
|
|
14
|
+
return {
|
|
15
|
+
...features,
|
|
16
|
+
verification: false,
|
|
17
|
+
};
|
|
89
18
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
19
|
+
if (expectErrorToken) {
|
|
20
|
+
const token = expectErrorToken;
|
|
21
|
+
return {
|
|
22
|
+
...features,
|
|
23
|
+
verification: {
|
|
24
|
+
shouldReport: () => {
|
|
25
|
+
token.errors++;
|
|
26
|
+
return false;
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return features;
|
|
33
|
+
}
|
|
93
34
|
const localVars = new Map();
|
|
35
|
+
const specialVars = new Set();
|
|
94
36
|
const accessExternalVariables = new Map();
|
|
95
37
|
const slots = [];
|
|
96
38
|
const dynamicSlots = [];
|
|
97
|
-
const hasSlotElements = new Set();
|
|
98
|
-
;
|
|
99
39
|
const blockConditions = [];
|
|
100
40
|
const scopedClasses = [];
|
|
101
41
|
const emptyClassOffsets = [];
|
|
@@ -104,12 +44,18 @@ function createTemplateCodegenContext(options) {
|
|
|
104
44
|
const inheritedAttrVars = new Set();
|
|
105
45
|
const templateRefs = new Map();
|
|
106
46
|
return {
|
|
47
|
+
codeFeatures: new Proxy(codeFeatures_1.codeFeatures, {
|
|
48
|
+
get(target, key) {
|
|
49
|
+
const data = target[key];
|
|
50
|
+
return resolveCodeFeatures(data);
|
|
51
|
+
},
|
|
52
|
+
}),
|
|
53
|
+
resolveCodeFeatures,
|
|
107
54
|
slots,
|
|
108
55
|
dynamicSlots,
|
|
109
|
-
|
|
56
|
+
specialVars,
|
|
110
57
|
accessExternalVariables,
|
|
111
58
|
lastGenericComment,
|
|
112
|
-
hasSlotElements,
|
|
113
59
|
blockConditions,
|
|
114
60
|
scopedClasses,
|
|
115
61
|
emptyClassOffsets,
|
|
@@ -193,8 +139,8 @@ function createTemplateCodegenContext(options) {
|
|
|
193
139
|
'template',
|
|
194
140
|
offset,
|
|
195
141
|
{
|
|
196
|
-
...codeFeatures.additionalCompletion,
|
|
197
|
-
...codeFeatures.withoutHighlightAndCompletionAndNavigation,
|
|
142
|
+
...codeFeatures_1.codeFeatures.additionalCompletion,
|
|
143
|
+
...codeFeatures_1.codeFeatures.withoutHighlightAndCompletionAndNavigation,
|
|
198
144
|
},
|
|
199
145
|
];
|
|
200
146
|
}
|
|
@@ -203,7 +149,7 @@ function createTemplateCodegenContext(options) {
|
|
|
203
149
|
varName,
|
|
204
150
|
'template',
|
|
205
151
|
offset,
|
|
206
|
-
codeFeatures.additionalCompletion,
|
|
152
|
+
codeFeatures_1.codeFeatures.additionalCompletion,
|
|
207
153
|
];
|
|
208
154
|
}
|
|
209
155
|
yield `,`;
|
|
@@ -4,7 +4,6 @@ exports.generateComponent = generateComponent;
|
|
|
4
4
|
exports.generateElement = generateElement;
|
|
5
5
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
6
6
|
const shared_1 = require("@vue/shared");
|
|
7
|
-
const scriptSetupRanges_1 = require("../../parsers/scriptSetupRanges");
|
|
8
7
|
const shared_2 = require("../../utils/shared");
|
|
9
8
|
const inlayHints_1 = require("../inlayHints");
|
|
10
9
|
const utils_1 = require("../utils");
|
|
@@ -14,9 +13,9 @@ 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
|
-
const objectProperty_1 = require("./objectProperty");
|
|
18
16
|
const propertyAccess_1 = require("./propertyAccess");
|
|
19
|
-
const
|
|
17
|
+
const styleScopedClasses_1 = require("./styleScopedClasses");
|
|
18
|
+
const vSlot_1 = require("./vSlot");
|
|
20
19
|
const colonReg = /:/g;
|
|
21
20
|
function* generateComponent(options, ctx, node) {
|
|
22
21
|
const tagOffsets = [node.loc.start.offset + options.template.content.slice(node.loc.start.offset).indexOf(node.tag)];
|
|
@@ -37,7 +36,6 @@ function* generateComponent(options, ctx, node) {
|
|
|
37
36
|
const var_defineComponentCtx = ctx.getInternalVariable();
|
|
38
37
|
const isComponentTag = node.tag.toLowerCase() === 'component';
|
|
39
38
|
ctx.currentComponent = {
|
|
40
|
-
node,
|
|
41
39
|
ctxVar: var_defineComponentCtx,
|
|
42
40
|
used: false
|
|
43
41
|
};
|
|
@@ -103,15 +101,20 @@ function* generateComponent(options, ctx, node) {
|
|
|
103
101
|
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, dynamicTagInfo.tag, dynamicTagInfo.offsets[0], dynamicTagInfo.astHolder, '(', ')');
|
|
104
102
|
if (dynamicTagInfo.offsets[1] !== undefined) {
|
|
105
103
|
yield `,`;
|
|
106
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template',
|
|
107
|
-
...ctx.codeFeatures.all,
|
|
108
|
-
completion: false,
|
|
109
|
-
}, dynamicTagInfo.tag, dynamicTagInfo.offsets[1], dynamicTagInfo.astHolder, '(', ')');
|
|
104
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.withoutCompletion, dynamicTagInfo.tag, dynamicTagInfo.offsets[1], dynamicTagInfo.astHolder, '(', ')');
|
|
110
105
|
}
|
|
111
106
|
yield `)${utils_1.endOfLine}`;
|
|
112
107
|
}
|
|
113
108
|
else if (!isComponentTag) {
|
|
114
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
|
+
}
|
|
115
118
|
yield getPossibleOriginalComponentNames(node.tag, false)
|
|
116
119
|
.map(name => `'${name}'`)
|
|
117
120
|
.join(`, `);
|
|
@@ -154,20 +157,20 @@ function* generateComponent(options, ctx, node) {
|
|
|
154
157
|
}
|
|
155
158
|
yield `// @ts-ignore${utils_1.newLine}`;
|
|
156
159
|
yield `const ${var_functionalComponent} = __VLS_asFunctionalComponent(${var_originalComponent}, new ${var_originalComponent}({${utils_1.newLine}`;
|
|
157
|
-
yield* (0, elementProps_1.generateElementProps)(options, ctx, node, props, options.vueCompilerOptions.
|
|
160
|
+
yield* (0, elementProps_1.generateElementProps)(options, ctx, node, props, options.vueCompilerOptions.checkUnknownProps, false);
|
|
158
161
|
yield `}))${utils_1.endOfLine}`;
|
|
159
162
|
yield `const `;
|
|
160
|
-
yield* (0, utils_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, {
|
|
163
|
+
yield* (0, utils_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, ctx.resolveCodeFeatures({
|
|
161
164
|
verification: {
|
|
162
165
|
shouldReport(_source, code) {
|
|
163
166
|
return String(code) !== '6133';
|
|
164
167
|
},
|
|
165
168
|
}
|
|
166
|
-
}, var_componentInstance);
|
|
169
|
+
}), var_componentInstance);
|
|
167
170
|
yield ` = ${var_functionalComponent}`;
|
|
168
171
|
yield* generateComponentGeneric(ctx);
|
|
169
172
|
yield `(`;
|
|
170
|
-
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.
|
|
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), `}`);
|
|
171
174
|
yield `, ...__VLS_functionalComponentArgsRest(${var_functionalComponent}))${utils_1.endOfLine}`;
|
|
172
175
|
yield* generateFailedPropExps(options, ctx, failedPropExps);
|
|
173
176
|
const [refName, offset] = yield* generateVScope(options, ctx, node, props);
|
|
@@ -195,19 +198,17 @@ function* generateComponent(options, ctx, node) {
|
|
|
195
198
|
yield `let ${var_componentEmit}!: typeof ${var_defineComponentCtx}.emit${utils_1.endOfLine}`;
|
|
196
199
|
yield `let ${var_componentEvents}!: __VLS_NormalizeEmits<typeof ${var_componentEmit}>${utils_1.endOfLine}`;
|
|
197
200
|
}
|
|
198
|
-
if (options
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
ctx.inheritedAttrVars.add(varAttrs);
|
|
203
|
-
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`;
|
|
204
205
|
}
|
|
205
206
|
const slotDir = node.props.find(p => p.type === CompilerDOM.NodeTypes.DIRECTIVE && p.name === 'slot');
|
|
206
207
|
if (slotDir) {
|
|
207
|
-
yield*
|
|
208
|
+
yield* (0, vSlot_1.generateVSlot)(options, ctx, node, slotDir);
|
|
208
209
|
}
|
|
209
210
|
else {
|
|
210
|
-
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node);
|
|
211
|
+
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node, true);
|
|
211
212
|
}
|
|
212
213
|
if (ctx.currentComponent.used) {
|
|
213
214
|
yield `var ${var_defineComponentCtx}!: __VLS_PickFunctionalComponentCtx<typeof ${var_originalComponent}, typeof ${var_componentInstance}>${utils_1.endOfLine}`;
|
|
@@ -219,14 +220,14 @@ function* generateElement(options, ctx, node, isVForChild) {
|
|
|
219
220
|
? node.loc.start.offset + node.loc.source.lastIndexOf(node.tag)
|
|
220
221
|
: undefined;
|
|
221
222
|
const failedPropExps = [];
|
|
222
|
-
yield `
|
|
223
|
+
yield `__VLS_asFunctionalElement(__VLS_intrinsicElements`;
|
|
223
224
|
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, startTagOffset, ctx.codeFeatures.withoutHighlightAndCompletion);
|
|
224
225
|
if (endTagOffset !== undefined) {
|
|
225
226
|
yield `, __VLS_intrinsicElements`;
|
|
226
227
|
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, endTagOffset, ctx.codeFeatures.withoutHighlightAndCompletion);
|
|
227
228
|
}
|
|
228
229
|
yield `)(`;
|
|
229
|
-
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.
|
|
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), `}`);
|
|
230
231
|
yield `)${utils_1.endOfLine}`;
|
|
231
232
|
yield* generateFailedPropExps(options, ctx, failedPropExps);
|
|
232
233
|
const [refName, offset] = yield* generateVScope(options, ctx, node, node.props);
|
|
@@ -240,18 +241,10 @@ function* generateElement(options, ctx, node, isVForChild) {
|
|
|
240
241
|
if (ctx.singleRootNode === node) {
|
|
241
242
|
ctx.singleRootElType = `typeof __VLS_nativeElements['${node.tag}']`;
|
|
242
243
|
}
|
|
243
|
-
|
|
244
|
-
if (slotDir && ctx.currentComponent) {
|
|
245
|
-
yield* generateComponentSlot(options, ctx, node, slotDir);
|
|
246
|
-
}
|
|
247
|
-
else {
|
|
248
|
-
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node);
|
|
249
|
-
}
|
|
250
|
-
if (options.vueCompilerOptions.fallthroughAttributes
|
|
251
|
-
&& (node.props.some(prop => prop.type === CompilerDOM.NodeTypes.DIRECTIVE && prop.name === 'bind' && prop.exp?.loc.source === '$attrs')
|
|
252
|
-
|| node === ctx.singleRootNode)) {
|
|
244
|
+
if (hasVBindAttrs(options, ctx, node)) {
|
|
253
245
|
ctx.inheritedAttrVars.add(`__VLS_intrinsicElements.${node.tag}`);
|
|
254
246
|
}
|
|
247
|
+
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node);
|
|
255
248
|
}
|
|
256
249
|
function* generateFailedPropExps(options, ctx, failedPropExps) {
|
|
257
250
|
for (const failedExp of failedPropExps) {
|
|
@@ -280,7 +273,7 @@ function* generateVScope(options, ctx, node, props) {
|
|
|
280
273
|
}
|
|
281
274
|
yield* (0, elementDirectives_1.generateElementDirectives)(options, ctx, node);
|
|
282
275
|
const [refName, offset] = yield* generateReferencesForElements(options, ctx, node); // <el ref="foo" />
|
|
283
|
-
|
|
276
|
+
(0, styleScopedClasses_1.collectStyleScopedClassReferences)(options, ctx, node);
|
|
284
277
|
if (inScope) {
|
|
285
278
|
yield `}${utils_1.newLine}`;
|
|
286
279
|
ctx.blockConditions.length = originalConditionsNum;
|
|
@@ -325,83 +318,12 @@ function* generateComponentGeneric(ctx) {
|
|
|
325
318
|
}
|
|
326
319
|
ctx.lastGenericComment = undefined;
|
|
327
320
|
}
|
|
328
|
-
function* generateComponentSlot(options, ctx, node, slotDir) {
|
|
329
|
-
yield `{${utils_1.newLine}`;
|
|
330
|
-
if (ctx.currentComponent) {
|
|
331
|
-
ctx.currentComponent.used = true;
|
|
332
|
-
ctx.hasSlotElements.add(ctx.currentComponent.node);
|
|
333
|
-
}
|
|
334
|
-
const slotBlockVars = [];
|
|
335
|
-
yield `const {`;
|
|
336
|
-
if (slotDir?.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && slotDir.arg.content) {
|
|
337
|
-
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);
|
|
338
|
-
}
|
|
339
|
-
else {
|
|
340
|
-
yield* (0, utils_1.wrapWith)(slotDir.loc.start.offset, slotDir.loc.start.offset + (slotDir.rawName?.length ?? 0), ctx.codeFeatures.withoutHighlightAndCompletion, `default`);
|
|
341
|
-
}
|
|
342
|
-
yield `: __VLS_thisSlot } = ${ctx.currentComponent.ctxVar}.slots!${utils_1.endOfLine}`;
|
|
343
|
-
if (slotDir?.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
344
|
-
const slotAst = (0, utils_1.createTsAst)(options.ts, slotDir, `(${slotDir.exp.content}) => {}`);
|
|
345
|
-
(0, utils_1.collectVars)(options.ts, slotAst, slotAst, slotBlockVars);
|
|
346
|
-
if (!slotDir.exp.content.includes(':')) {
|
|
347
|
-
yield `const [`;
|
|
348
|
-
yield [
|
|
349
|
-
slotDir.exp.content,
|
|
350
|
-
'template',
|
|
351
|
-
slotDir.exp.loc.start.offset,
|
|
352
|
-
ctx.codeFeatures.all,
|
|
353
|
-
];
|
|
354
|
-
yield `] = __VLS_getSlotParams(__VLS_thisSlot)${utils_1.endOfLine}`;
|
|
355
|
-
}
|
|
356
|
-
else {
|
|
357
|
-
yield `const `;
|
|
358
|
-
yield [
|
|
359
|
-
slotDir.exp.content,
|
|
360
|
-
'template',
|
|
361
|
-
slotDir.exp.loc.start.offset,
|
|
362
|
-
ctx.codeFeatures.all,
|
|
363
|
-
];
|
|
364
|
-
yield ` = __VLS_getSlotParam(__VLS_thisSlot)${utils_1.endOfLine}`;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
for (const varName of slotBlockVars) {
|
|
368
|
-
ctx.addLocalVariable(varName);
|
|
369
|
-
}
|
|
370
|
-
yield* ctx.resetDirectiveComments('end of slot children start');
|
|
371
|
-
let prev;
|
|
372
|
-
for (const childNode of node.children) {
|
|
373
|
-
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, prev);
|
|
374
|
-
prev = childNode;
|
|
375
|
-
}
|
|
376
|
-
for (const varName of slotBlockVars) {
|
|
377
|
-
ctx.removeLocalVariable(varName);
|
|
378
|
-
}
|
|
379
|
-
let isStatic = true;
|
|
380
|
-
if (slotDir?.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
381
|
-
isStatic = slotDir.arg.isStatic;
|
|
382
|
-
}
|
|
383
|
-
if (isStatic && slotDir && !slotDir.arg) {
|
|
384
|
-
yield `${ctx.currentComponent.ctxVar}.slots!['`;
|
|
385
|
-
yield [
|
|
386
|
-
'',
|
|
387
|
-
'template',
|
|
388
|
-
slotDir.loc.start.offset + (slotDir.loc.source.startsWith('#')
|
|
389
|
-
? '#'.length : slotDir.loc.source.startsWith('v-slot:')
|
|
390
|
-
? 'v-slot:'.length
|
|
391
|
-
: 0),
|
|
392
|
-
ctx.codeFeatures.completion,
|
|
393
|
-
];
|
|
394
|
-
yield `'/* empty slot name completion */]${utils_1.newLine}`;
|
|
395
|
-
}
|
|
396
|
-
yield* ctx.generateAutoImportCompletion();
|
|
397
|
-
yield `}${utils_1.newLine}`;
|
|
398
|
-
}
|
|
399
321
|
function* generateReferencesForElements(options, ctx, node) {
|
|
400
322
|
for (const prop of node.props) {
|
|
401
323
|
if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE
|
|
402
324
|
&& prop.name === 'ref'
|
|
403
325
|
&& prop.value) {
|
|
404
|
-
const [content, startOffset] = normalizeAttributeValue(prop.value);
|
|
326
|
+
const [content, startOffset] = (0, utils_1.normalizeAttributeValue)(prop.value);
|
|
405
327
|
yield `// @ts-ignore navigation for \`const ${content} = ref()\`${utils_1.newLine}`;
|
|
406
328
|
yield `/** @type { typeof __VLS_ctx`;
|
|
407
329
|
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, content, startOffset, ctx.codeFeatures.navigation, prop.value.loc);
|
|
@@ -414,116 +336,11 @@ function* generateReferencesForElements(options, ctx, node) {
|
|
|
414
336
|
}
|
|
415
337
|
return [];
|
|
416
338
|
}
|
|
417
|
-
function
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
&& prop.name === '
|
|
421
|
-
&& prop.
|
|
422
|
-
if (options.template.lang === 'pug') {
|
|
423
|
-
const getClassOffset = Reflect.get(prop.value.loc.start, 'getClassOffset');
|
|
424
|
-
const content = prop.value.loc.source.slice(1, -1);
|
|
425
|
-
let startOffset = 1;
|
|
426
|
-
for (const className of content.split(' ')) {
|
|
427
|
-
if (className) {
|
|
428
|
-
ctx.scopedClasses.push({
|
|
429
|
-
source: 'template',
|
|
430
|
-
className,
|
|
431
|
-
offset: getClassOffset(startOffset),
|
|
432
|
-
});
|
|
433
|
-
}
|
|
434
|
-
startOffset += className.length + 1;
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
else {
|
|
438
|
-
let isWrapped = false;
|
|
439
|
-
const [content, startOffset] = normalizeAttributeValue(prop.value);
|
|
440
|
-
if (content) {
|
|
441
|
-
const classes = collectClasses(content, startOffset + (isWrapped ? 1 : 0));
|
|
442
|
-
ctx.scopedClasses.push(...classes);
|
|
443
|
-
}
|
|
444
|
-
else {
|
|
445
|
-
ctx.emptyClassOffsets.push(startOffset);
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
else if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
450
|
-
&& prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
451
|
-
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
452
|
-
&& prop.arg.content === 'class') {
|
|
453
|
-
const content = '`${' + prop.exp.content + '}`';
|
|
454
|
-
const startOffset = prop.exp.loc.start.offset - 3;
|
|
455
|
-
const { ts } = options;
|
|
456
|
-
const ast = ts.createSourceFile('', content, 99);
|
|
457
|
-
const literals = [];
|
|
458
|
-
ts.forEachChild(ast, node => {
|
|
459
|
-
if (!ts.isExpressionStatement(node) ||
|
|
460
|
-
!isTemplateExpression(node.expression)) {
|
|
461
|
-
return;
|
|
462
|
-
}
|
|
463
|
-
const expression = node.expression.templateSpans[0].expression;
|
|
464
|
-
if (ts.isStringLiteralLike(expression)) {
|
|
465
|
-
literals.push(expression);
|
|
466
|
-
}
|
|
467
|
-
if (ts.isArrayLiteralExpression(expression)) {
|
|
468
|
-
walkArrayLiteral(expression);
|
|
469
|
-
}
|
|
470
|
-
if (ts.isObjectLiteralExpression(expression)) {
|
|
471
|
-
walkObjectLiteral(expression);
|
|
472
|
-
}
|
|
473
|
-
});
|
|
474
|
-
for (const literal of literals) {
|
|
475
|
-
if (literal.text) {
|
|
476
|
-
const classes = collectClasses(literal.text, literal.end - literal.text.length - 1 + startOffset);
|
|
477
|
-
ctx.scopedClasses.push(...classes);
|
|
478
|
-
}
|
|
479
|
-
else {
|
|
480
|
-
ctx.emptyClassOffsets.push(literal.end - 1 + startOffset);
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
function walkArrayLiteral(node) {
|
|
484
|
-
const { elements } = node;
|
|
485
|
-
for (const element of elements) {
|
|
486
|
-
if (ts.isStringLiteralLike(element)) {
|
|
487
|
-
literals.push(element);
|
|
488
|
-
}
|
|
489
|
-
else if (ts.isObjectLiteralExpression(element)) {
|
|
490
|
-
walkObjectLiteral(element);
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
function walkObjectLiteral(node) {
|
|
495
|
-
const { properties } = node;
|
|
496
|
-
for (const property of properties) {
|
|
497
|
-
if (ts.isPropertyAssignment(property)) {
|
|
498
|
-
const { name } = property;
|
|
499
|
-
if (ts.isIdentifier(name)) {
|
|
500
|
-
walkIdentifier(name);
|
|
501
|
-
}
|
|
502
|
-
else if (ts.isStringLiteral(name)) {
|
|
503
|
-
literals.push(name);
|
|
504
|
-
}
|
|
505
|
-
else if (ts.isComputedPropertyName(name)) {
|
|
506
|
-
const { expression } = name;
|
|
507
|
-
if (ts.isStringLiteralLike(expression)) {
|
|
508
|
-
literals.push(expression);
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
else if (ts.isShorthandPropertyAssignment(property)) {
|
|
513
|
-
walkIdentifier(property.name);
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
function walkIdentifier(node) {
|
|
518
|
-
const text = (0, scriptSetupRanges_1.getNodeText)(ts, node, ast);
|
|
519
|
-
ctx.scopedClasses.push({
|
|
520
|
-
source: 'template',
|
|
521
|
-
className: text,
|
|
522
|
-
offset: node.end - text.length + startOffset
|
|
523
|
-
});
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
}
|
|
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'));
|
|
527
344
|
}
|
|
528
345
|
function camelizeComponentName(newName) {
|
|
529
346
|
return (0, shared_1.camelize)('-' + newName);
|
|
@@ -531,41 +348,4 @@ function camelizeComponentName(newName) {
|
|
|
531
348
|
function getTagRenameApply(oldName) {
|
|
532
349
|
return oldName === (0, shared_2.hyphenateTag)(oldName) ? shared_2.hyphenateTag : undefined;
|
|
533
350
|
}
|
|
534
|
-
function normalizeAttributeValue(node) {
|
|
535
|
-
let offset = node.loc.start.offset;
|
|
536
|
-
let content = node.loc.source;
|
|
537
|
-
if ((content.startsWith(`'`) && content.endsWith(`'`))
|
|
538
|
-
|| (content.startsWith(`"`) && content.endsWith(`"`))) {
|
|
539
|
-
offset++;
|
|
540
|
-
content = content.slice(1, -1);
|
|
541
|
-
}
|
|
542
|
-
return [content, offset];
|
|
543
|
-
}
|
|
544
|
-
function collectClasses(content, startOffset = 0) {
|
|
545
|
-
const classes = [];
|
|
546
|
-
let currentClassName = '';
|
|
547
|
-
let offset = 0;
|
|
548
|
-
for (const char of (content + ' ')) {
|
|
549
|
-
if (char.trim() === '') {
|
|
550
|
-
if (currentClassName !== '') {
|
|
551
|
-
classes.push({
|
|
552
|
-
source: 'template',
|
|
553
|
-
className: currentClassName,
|
|
554
|
-
offset: offset + startOffset
|
|
555
|
-
});
|
|
556
|
-
offset += currentClassName.length;
|
|
557
|
-
currentClassName = '';
|
|
558
|
-
}
|
|
559
|
-
offset += char.length;
|
|
560
|
-
}
|
|
561
|
-
else {
|
|
562
|
-
currentClassName += char;
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
return classes;
|
|
566
|
-
}
|
|
567
|
-
// isTemplateExpression is missing in tsc
|
|
568
|
-
function isTemplateExpression(node) {
|
|
569
|
-
return node.kind === 228;
|
|
570
|
-
}
|
|
571
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): Generator<Code>;
|
|
5
|
+
export declare function generateElementChildren(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, isDefaultSlot?: boolean): Generator<Code>;
|
|
@@ -4,7 +4,7 @@ exports.generateElementChildren = generateElementChildren;
|
|
|
4
4
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
6
|
const templateChild_1 = require("./templateChild");
|
|
7
|
-
function* generateElementChildren(options, ctx, node) {
|
|
7
|
+
function* generateElementChildren(options, ctx, node, isDefaultSlot = false) {
|
|
8
8
|
yield* ctx.resetDirectiveComments('end of element children start');
|
|
9
9
|
let prev;
|
|
10
10
|
for (const childNode of node.children) {
|
|
@@ -14,10 +14,9 @@ function* generateElementChildren(options, ctx, node) {
|
|
|
14
14
|
yield* ctx.generateAutoImportCompletion();
|
|
15
15
|
// fix https://github.com/vuejs/language-tools/issues/932
|
|
16
16
|
if (ctx.currentComponent
|
|
17
|
-
&&
|
|
17
|
+
&& isDefaultSlot
|
|
18
18
|
&& node.children.length
|
|
19
|
-
&& node.tagType
|
|
20
|
-
&& node.tagType !== CompilerDOM.ElementTypes.TEMPLATE) {
|
|
19
|
+
&& node.tagType === CompilerDOM.ElementTypes.COMPONENT) {
|
|
21
20
|
ctx.currentComponent.used = true;
|
|
22
21
|
yield `${ctx.currentComponent.ctxVar}.slots!.`;
|
|
23
22
|
yield* (0, utils_1.wrapWith)(node.children[0].loc.start.offset, node.children[node.children.length - 1].loc.end.offset, ctx.codeFeatures.navigation, `default`);
|