@vue/language-core 3.0.0-alpha.0 → 3.0.0-alpha.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/lib/codegen/globalTypes.js +2 -4
- package/lib/codegen/script/component.js +21 -9
- package/lib/codegen/script/index.js +1 -1
- package/lib/codegen/script/scriptSetup.js +1 -10
- package/lib/codegen/script/styleModulesType.d.ts +4 -0
- package/lib/codegen/script/styleModulesType.js +34 -0
- package/lib/codegen/template/context.d.ts +25 -17
- package/lib/codegen/template/context.js +87 -53
- package/lib/codegen/template/element.d.ts +2 -2
- package/lib/codegen/template/element.js +10 -24
- package/lib/codegen/template/elementChildren.d.ts +1 -1
- package/lib/codegen/template/elementChildren.js +4 -6
- package/lib/codegen/template/elementDirectives.js +1 -3
- package/lib/codegen/template/elementEvents.js +0 -1
- package/lib/codegen/template/elementProps.js +1 -1
- package/lib/codegen/template/index.js +20 -7
- package/lib/codegen/template/interpolation.d.ts +1 -1
- package/lib/codegen/template/interpolation.js +52 -52
- package/lib/codegen/template/slotOutlet.js +1 -2
- package/lib/codegen/template/templateChild.d.ts +1 -1
- package/lib/codegen/template/templateChild.js +12 -46
- package/lib/codegen/template/vFor.js +5 -10
- package/lib/codegen/template/vIf.js +2 -10
- package/lib/codegen/template/vSlot.d.ts +1 -2
- package/lib/codegen/template/vSlot.js +84 -62
- package/lib/codegen/utils/objectProperty.d.ts +3 -0
- package/lib/codegen/utils/objectProperty.js +41 -0
- package/lib/parsers/scriptSetupRanges.js +8 -6
- package/lib/plugins/vue-tsx.d.ts +24 -16
- package/lib/plugins/vue-tsx.js +31 -19
- package/lib/types.d.ts +1 -1
- package/lib/utils/forEachElementNode.d.ts +1 -0
- package/lib/utils/forEachElementNode.js +3 -0
- package/package.json +2 -2
|
@@ -114,10 +114,8 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
|
|
|
114
114
|
key: keyof T,
|
|
115
115
|
index: number,
|
|
116
116
|
][];
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
// @ts-ignore
|
|
120
|
-
function __VLS_getSlotParam<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>[0];
|
|
117
|
+
function __VLS_getSlotParameters<S, D extends S>(slot: S, decl?: D):
|
|
118
|
+
__VLS_PickNotAny<NonNullable<D>, (...args: any) => any> extends (...args: infer P) => any ? P : any[];
|
|
121
119
|
function __VLS_asFunctionalDirective<T>(dir: T): T extends import('${lib}').ObjectDirective
|
|
122
120
|
? NonNullable<T['created' | 'beforeMount' | 'mounted' | 'beforeUpdate' | 'updated' | 'beforeUnmount' | 'unmounted']>
|
|
123
121
|
: T extends (...args: any) => any
|
|
@@ -111,15 +111,23 @@ function* generateEmitsOption(options, scriptSetupRanges) {
|
|
|
111
111
|
function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasEmitsOption, inheritAttrs) {
|
|
112
112
|
const codes = [];
|
|
113
113
|
if (ctx.generatedPropsType) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
114
|
+
if (options.vueCompilerOptions.target >= 3.6) {
|
|
115
|
+
codes.push({
|
|
116
|
+
optionExp: '{}',
|
|
117
|
+
typeOptionExp: `{} as __VLS_PublicProps`,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
codes.push({
|
|
122
|
+
optionExp: [
|
|
123
|
+
`{} as `,
|
|
124
|
+
scriptSetupRanges.withDefaults?.arg ? `${ctx.localTypes.WithDefaults}<` : '',
|
|
125
|
+
`${ctx.localTypes.TypePropsToOption}<__VLS_PublicProps>`,
|
|
126
|
+
scriptSetupRanges.withDefaults?.arg ? `, typeof __VLS_withDefaultsArg>` : '',
|
|
127
|
+
].join(''),
|
|
128
|
+
typeOptionExp: `{} as __VLS_PublicProps`,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
123
131
|
}
|
|
124
132
|
if (scriptSetupRanges.defineProps?.arg) {
|
|
125
133
|
const { arg } = scriptSetupRanges.defineProps;
|
|
@@ -146,6 +154,10 @@ function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasE
|
|
|
146
154
|
const useTypeOption = options.vueCompilerOptions.target >= 3.5 && codes.every(code => code.typeOptionExp);
|
|
147
155
|
const useOption = !useTypeOption || scriptSetupRanges.withDefaults;
|
|
148
156
|
if (useTypeOption) {
|
|
157
|
+
if (options.vueCompilerOptions.target >= 3.6
|
|
158
|
+
&& scriptSetupRanges.withDefaults?.arg) {
|
|
159
|
+
yield `__defaults: __VLS_withDefaultsArg,${utils_1.newLine}`;
|
|
160
|
+
}
|
|
149
161
|
if (codes.length === 1) {
|
|
150
162
|
yield `__typeProps: `;
|
|
151
163
|
yield codes[0].typeOptionExp;
|
|
@@ -78,15 +78,6 @@ function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
78
78
|
}
|
|
79
79
|
function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, syntax) {
|
|
80
80
|
let setupCodeModifies = [];
|
|
81
|
-
for (const { comments } of scriptSetupRanges.defineProp) {
|
|
82
|
-
if (comments) {
|
|
83
|
-
setupCodeModifies.push([
|
|
84
|
-
[``],
|
|
85
|
-
comments.start,
|
|
86
|
-
comments.end,
|
|
87
|
-
]);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
81
|
if (scriptSetupRanges.defineProps) {
|
|
91
82
|
const { name, statement, callExp, typeArg } = scriptSetupRanges.defineProps;
|
|
92
83
|
setupCodeModifies.push(...generateDefineWithType(scriptSetup, statement, scriptSetupRanges.withDefaults?.callExp ?? callExp, typeArg, name, `__VLS_props`, `__VLS_Props`));
|
|
@@ -405,7 +396,7 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
405
396
|
for (const defineProp of scriptSetupRanges.defineProp) {
|
|
406
397
|
const [propName, localName] = getPropAndLocalName(scriptSetup, defineProp);
|
|
407
398
|
if (defineProp.comments) {
|
|
408
|
-
yield
|
|
399
|
+
yield scriptSetup.content.slice(defineProp.comments.start, defineProp.comments.end);
|
|
409
400
|
yield utils_1.newLine;
|
|
410
401
|
}
|
|
411
402
|
if (defineProp.isModel && !defineProp.name) {
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Code } from '../../types';
|
|
2
|
+
import type { ScriptCodegenContext } from './context';
|
|
3
|
+
import type { ScriptCodegenOptions } from './index';
|
|
4
|
+
export declare function generateStyleModulesType(options: ScriptCodegenOptions, ctx: ScriptCodegenContext): Generator<Code>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateStyleModulesType = generateStyleModulesType;
|
|
4
|
+
const codeFeatures_1 = require("../codeFeatures");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
const template_1 = require("./template");
|
|
7
|
+
function* generateStyleModulesType(options, ctx) {
|
|
8
|
+
const styles = options.sfc.styles.map((style, i) => [style, i]).filter(([style]) => style.module);
|
|
9
|
+
if (!styles.length && !options.scriptSetupRanges?.useCssModule.length) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
yield `type __VLS_StyleModules = {${utils_1.newLine}`;
|
|
13
|
+
for (const [style, i] of styles) {
|
|
14
|
+
const { name, offset } = style.module;
|
|
15
|
+
if (offset) {
|
|
16
|
+
yield [
|
|
17
|
+
name,
|
|
18
|
+
'main',
|
|
19
|
+
offset + 1,
|
|
20
|
+
codeFeatures_1.codeFeatures.all
|
|
21
|
+
];
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
yield name;
|
|
25
|
+
}
|
|
26
|
+
yield `: Record<string, string> & ${ctx.localTypes.PrettifyLocal}<{}`;
|
|
27
|
+
for (const className of style.classNames) {
|
|
28
|
+
yield* (0, template_1.generateCssClassProperty)(i, className.text, className.offset, 'string', false);
|
|
29
|
+
}
|
|
30
|
+
yield `>${utils_1.endOfLine}`;
|
|
31
|
+
}
|
|
32
|
+
yield `}${utils_1.endOfLine}`;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=styleModulesType.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as CompilerDOM from '@vue/compiler-dom';
|
|
2
2
|
import type { Code, VueCodeInformation } from '../../types';
|
|
3
3
|
import { InlayHintInfo } from '../inlayHints';
|
|
4
4
|
import type { TemplateCodegenOptions } from './index';
|
|
@@ -101,6 +101,17 @@ export type TemplateCodegenContext = ReturnType<typeof createTemplateCodegenCont
|
|
|
101
101
|
* and additionally how we use that to determine whether to propagate diagnostics back upward.
|
|
102
102
|
*/
|
|
103
103
|
export declare function createTemplateCodegenContext(options: Pick<TemplateCodegenOptions, 'scriptSetupBindingNames'>): {
|
|
104
|
+
readonly currentInfo: {
|
|
105
|
+
ignoreError?: boolean;
|
|
106
|
+
expectError?: {
|
|
107
|
+
token: number;
|
|
108
|
+
node: CompilerDOM.CommentNode;
|
|
109
|
+
};
|
|
110
|
+
generic?: {
|
|
111
|
+
content: string;
|
|
112
|
+
offset: number;
|
|
113
|
+
};
|
|
114
|
+
};
|
|
104
115
|
codeFeatures: {
|
|
105
116
|
all: VueCodeInformation;
|
|
106
117
|
none: VueCodeInformation;
|
|
@@ -120,6 +131,7 @@ export declare function createTemplateCodegenContext(options: Pick<TemplateCodeg
|
|
|
120
131
|
withoutHighlightAndCompletionAndNavigation: VueCodeInformation;
|
|
121
132
|
};
|
|
122
133
|
resolveCodeFeatures: (features: VueCodeInformation) => VueCodeInformation;
|
|
134
|
+
inVFor: boolean;
|
|
123
135
|
slots: {
|
|
124
136
|
name: string;
|
|
125
137
|
offset?: number;
|
|
@@ -133,10 +145,6 @@ export declare function createTemplateCodegenContext(options: Pick<TemplateCodeg
|
|
|
133
145
|
}[];
|
|
134
146
|
dollarVars: Set<string>;
|
|
135
147
|
accessExternalVariables: Map<string, Set<number>>;
|
|
136
|
-
lastGenericComment: {
|
|
137
|
-
content: string;
|
|
138
|
-
offset: number;
|
|
139
|
-
} | undefined;
|
|
140
148
|
blockConditions: string[];
|
|
141
149
|
scopedClasses: {
|
|
142
150
|
source: string;
|
|
@@ -150,23 +158,23 @@ export declare function createTemplateCodegenContext(options: Pick<TemplateCodeg
|
|
|
150
158
|
templateRefs: Map<string, {
|
|
151
159
|
typeExp: string;
|
|
152
160
|
offset: number;
|
|
153
|
-
}>;
|
|
161
|
+
}[]>;
|
|
154
162
|
currentComponent: {
|
|
155
163
|
ctxVar: string;
|
|
156
164
|
used: boolean;
|
|
157
165
|
} | undefined;
|
|
158
166
|
singleRootElTypes: string[];
|
|
159
167
|
singleRootNodes: Set<CompilerDOM.ElementNode | null>;
|
|
168
|
+
addTemplateRef(name: string, typeExp: string, offset: number): void;
|
|
160
169
|
accessExternalVariable(name: string, offset?: number): void;
|
|
161
|
-
hasLocalVariable
|
|
162
|
-
addLocalVariable
|
|
163
|
-
removeLocalVariable
|
|
164
|
-
getInternalVariable
|
|
165
|
-
getHoistVariable
|
|
166
|
-
generateHoistVariables
|
|
167
|
-
generateConditionGuards
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
generateAutoImportCompletion: () => Generator<Code>;
|
|
170
|
+
hasLocalVariable(name: string): boolean;
|
|
171
|
+
addLocalVariable(name: string): void;
|
|
172
|
+
removeLocalVariable(name: string): void;
|
|
173
|
+
getInternalVariable(): string;
|
|
174
|
+
getHoistVariable(originalVar: string): string;
|
|
175
|
+
generateHoistVariables(): Generator<string, void, unknown>;
|
|
176
|
+
generateConditionGuards(): Generator<string, void, unknown>;
|
|
177
|
+
generateAutoImportCompletion(): Generator<Code>;
|
|
178
|
+
enter(node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode): boolean;
|
|
179
|
+
exit(): Generator<Code>;
|
|
172
180
|
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createTemplateCodegenContext = createTemplateCodegenContext;
|
|
4
|
+
const CompilerDOM = require("@vue/compiler-dom");
|
|
4
5
|
const codeFeatures_1 = require("../codeFeatures");
|
|
5
6
|
const utils_1 = require("../utils");
|
|
6
7
|
const wrapWith_1 = require("../utils/wrapWith");
|
|
8
|
+
const commentDirectiveRegex = /^<!--\s*@vue-(?<name>[-\w]+)\b(?<content>[\s\S]*)-->$/;
|
|
7
9
|
/**
|
|
8
10
|
* Creates and returns a Context object used for generating type-checkable TS code
|
|
9
11
|
* from the template section of a .vue file.
|
|
@@ -102,13 +104,11 @@ const wrapWith_1 = require("../utils/wrapWith");
|
|
|
102
104
|
* and additionally how we use that to determine whether to propagate diagnostics back upward.
|
|
103
105
|
*/
|
|
104
106
|
function createTemplateCodegenContext(options) {
|
|
105
|
-
let ignoredError = false;
|
|
106
|
-
let expectErrorToken;
|
|
107
|
-
let lastGenericComment;
|
|
108
107
|
let variableId = 0;
|
|
109
108
|
function resolveCodeFeatures(features) {
|
|
110
|
-
if (features.verification) {
|
|
111
|
-
|
|
109
|
+
if (features.verification && stack.length) {
|
|
110
|
+
const data = stack[stack.length - 1];
|
|
111
|
+
if (data.ignoreError) {
|
|
112
112
|
// We are currently in a region of code covered by a @vue-ignore directive, so don't
|
|
113
113
|
// even bother performing any type-checking: set verification to false.
|
|
114
114
|
return {
|
|
@@ -116,17 +116,16 @@ function createTemplateCodegenContext(options) {
|
|
|
116
116
|
verification: false,
|
|
117
117
|
};
|
|
118
118
|
}
|
|
119
|
-
if (
|
|
119
|
+
if (data.expectError !== undefined) {
|
|
120
120
|
// We are currently in a region of code covered by a @vue-expect-error directive. We need to
|
|
121
121
|
// keep track of the number of errors encountered within this region so that we can know whether
|
|
122
122
|
// we will need to propagate an "unused ts-expect-error" diagnostic back to the original
|
|
123
123
|
// .vue file or not.
|
|
124
|
-
const token = expectErrorToken;
|
|
125
124
|
return {
|
|
126
125
|
...features,
|
|
127
126
|
verification: {
|
|
128
127
|
shouldReport: () => {
|
|
129
|
-
token
|
|
128
|
+
data.expectError.token++;
|
|
130
129
|
return false;
|
|
131
130
|
},
|
|
132
131
|
},
|
|
@@ -148,7 +147,12 @@ function createTemplateCodegenContext(options) {
|
|
|
148
147
|
const bindingAttrLocs = [];
|
|
149
148
|
const inheritedAttrVars = new Set();
|
|
150
149
|
const templateRefs = new Map();
|
|
150
|
+
const stack = [];
|
|
151
|
+
const commentBuffer = [];
|
|
151
152
|
return {
|
|
153
|
+
get currentInfo() {
|
|
154
|
+
return stack[stack.length - 1];
|
|
155
|
+
},
|
|
152
156
|
codeFeatures: new Proxy(codeFeatures_1.codeFeatures, {
|
|
153
157
|
get(target, key) {
|
|
154
158
|
const data = target[key];
|
|
@@ -156,11 +160,11 @@ function createTemplateCodegenContext(options) {
|
|
|
156
160
|
},
|
|
157
161
|
}),
|
|
158
162
|
resolveCodeFeatures,
|
|
163
|
+
inVFor: false,
|
|
159
164
|
slots,
|
|
160
165
|
dynamicSlots,
|
|
161
166
|
dollarVars,
|
|
162
167
|
accessExternalVariables,
|
|
163
|
-
lastGenericComment,
|
|
164
168
|
blockConditions,
|
|
165
169
|
scopedClasses,
|
|
166
170
|
emptyClassOffsets,
|
|
@@ -171,6 +175,13 @@ function createTemplateCodegenContext(options) {
|
|
|
171
175
|
currentComponent: undefined,
|
|
172
176
|
singleRootElTypes: [],
|
|
173
177
|
singleRootNodes: new Set(),
|
|
178
|
+
addTemplateRef(name, typeExp, offset) {
|
|
179
|
+
let refs = templateRefs.get(name);
|
|
180
|
+
if (!refs) {
|
|
181
|
+
templateRefs.set(name, refs = []);
|
|
182
|
+
}
|
|
183
|
+
refs.push({ typeExp, offset });
|
|
184
|
+
},
|
|
174
185
|
accessExternalVariable(name, offset) {
|
|
175
186
|
let arr = accessExternalVariables.get(name);
|
|
176
187
|
if (!arr) {
|
|
@@ -180,26 +191,26 @@ function createTemplateCodegenContext(options) {
|
|
|
180
191
|
arr.add(offset);
|
|
181
192
|
}
|
|
182
193
|
},
|
|
183
|
-
hasLocalVariable
|
|
194
|
+
hasLocalVariable(name) {
|
|
184
195
|
return !!localVars.get(name);
|
|
185
196
|
},
|
|
186
|
-
addLocalVariable
|
|
197
|
+
addLocalVariable(name) {
|
|
187
198
|
localVars.set(name, (localVars.get(name) ?? 0) + 1);
|
|
188
199
|
},
|
|
189
|
-
removeLocalVariable
|
|
200
|
+
removeLocalVariable(name) {
|
|
190
201
|
localVars.set(name, localVars.get(name) - 1);
|
|
191
202
|
},
|
|
192
|
-
getInternalVariable
|
|
203
|
+
getInternalVariable() {
|
|
193
204
|
return `__VLS_${variableId++}`;
|
|
194
205
|
},
|
|
195
|
-
getHoistVariable
|
|
206
|
+
getHoistVariable(originalVar) {
|
|
196
207
|
let name = hoistVars.get(originalVar);
|
|
197
208
|
if (name === undefined) {
|
|
198
209
|
hoistVars.set(originalVar, name = `__VLS_${variableId++}`);
|
|
199
210
|
}
|
|
200
211
|
return name;
|
|
201
212
|
},
|
|
202
|
-
generateHoistVariables
|
|
213
|
+
*generateHoistVariables() {
|
|
203
214
|
// trick to avoid TS 4081 (#5186)
|
|
204
215
|
if (hoistVars.size) {
|
|
205
216
|
yield `// @ts-ignore${utils_1.newLine}`;
|
|
@@ -210,47 +221,12 @@ function createTemplateCodegenContext(options) {
|
|
|
210
221
|
yield utils_1.endOfLine;
|
|
211
222
|
}
|
|
212
223
|
},
|
|
213
|
-
generateConditionGuards
|
|
224
|
+
*generateConditionGuards() {
|
|
214
225
|
for (const condition of blockConditions) {
|
|
215
226
|
yield `if (!${condition}) return${utils_1.endOfLine}`;
|
|
216
227
|
}
|
|
217
228
|
},
|
|
218
|
-
|
|
219
|
-
if (!ignoredError) {
|
|
220
|
-
ignoredError = true;
|
|
221
|
-
yield `// @vue-ignore start${utils_1.newLine}`;
|
|
222
|
-
}
|
|
223
|
-
},
|
|
224
|
-
expectError: function* (prevNode) {
|
|
225
|
-
if (!expectErrorToken) {
|
|
226
|
-
expectErrorToken = {
|
|
227
|
-
errors: 0,
|
|
228
|
-
node: prevNode,
|
|
229
|
-
};
|
|
230
|
-
yield `// @vue-expect-error start${utils_1.newLine}`;
|
|
231
|
-
}
|
|
232
|
-
},
|
|
233
|
-
resetDirectiveComments: function* (endStr) {
|
|
234
|
-
if (expectErrorToken) {
|
|
235
|
-
const token = expectErrorToken;
|
|
236
|
-
yield* (0, wrapWith_1.wrapWith)(expectErrorToken.node.loc.start.offset, expectErrorToken.node.loc.end.offset, {
|
|
237
|
-
verification: {
|
|
238
|
-
// If no errors/warnings/diagnostics were reported within the region of code covered
|
|
239
|
-
// by the @vue-expect-error directive, then we should allow any `unused @ts-expect-error`
|
|
240
|
-
// diagnostics to be reported upward.
|
|
241
|
-
shouldReport: () => token.errors === 0,
|
|
242
|
-
},
|
|
243
|
-
}, `// @ts-expect-error __VLS_TS_EXPECT_ERROR`);
|
|
244
|
-
yield `${utils_1.newLine}${utils_1.endOfLine}`;
|
|
245
|
-
expectErrorToken = undefined;
|
|
246
|
-
yield `// @vue-expect-error ${endStr}${utils_1.newLine}`;
|
|
247
|
-
}
|
|
248
|
-
if (ignoredError) {
|
|
249
|
-
ignoredError = false;
|
|
250
|
-
yield `// @vue-ignore ${endStr}${utils_1.newLine}`;
|
|
251
|
-
}
|
|
252
|
-
},
|
|
253
|
-
generateAutoImportCompletion: function* () {
|
|
229
|
+
*generateAutoImportCompletion() {
|
|
254
230
|
const all = [...accessExternalVariables.entries()];
|
|
255
231
|
if (!all.some(([_, offsets]) => offsets.size)) {
|
|
256
232
|
return;
|
|
@@ -284,7 +260,65 @@ function createTemplateCodegenContext(options) {
|
|
|
284
260
|
offsets.clear();
|
|
285
261
|
}
|
|
286
262
|
yield `]${utils_1.endOfLine}`;
|
|
287
|
-
}
|
|
263
|
+
},
|
|
264
|
+
enter(node) {
|
|
265
|
+
if (node.type === CompilerDOM.NodeTypes.COMMENT) {
|
|
266
|
+
commentBuffer.push(node);
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
const data = {};
|
|
270
|
+
const comments = [...commentBuffer];
|
|
271
|
+
commentBuffer.length = 0;
|
|
272
|
+
for (const comment of comments) {
|
|
273
|
+
const match = comment.loc.source.match(commentDirectiveRegex);
|
|
274
|
+
if (match) {
|
|
275
|
+
const { name, content } = match.groups;
|
|
276
|
+
switch (name) {
|
|
277
|
+
case 'skip': {
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
case 'ignore': {
|
|
281
|
+
data.ignoreError = true;
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
case 'expect-error': {
|
|
285
|
+
data.expectError = {
|
|
286
|
+
token: 0,
|
|
287
|
+
node: comment,
|
|
288
|
+
};
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
case 'generic': {
|
|
292
|
+
const text = content.trim();
|
|
293
|
+
if (text.startsWith('{') && text.endsWith('}')) {
|
|
294
|
+
data.generic = {
|
|
295
|
+
content: text.slice(1, -1),
|
|
296
|
+
offset: comment.loc.start.offset + comment.loc.source.indexOf('{') + 1,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
stack.push(data);
|
|
305
|
+
return true;
|
|
306
|
+
},
|
|
307
|
+
*exit() {
|
|
308
|
+
const data = stack.pop();
|
|
309
|
+
commentBuffer.length = 0;
|
|
310
|
+
if (data.expectError !== undefined) {
|
|
311
|
+
yield* (0, wrapWith_1.wrapWith)(data.expectError.node.loc.start.offset, data.expectError.node.loc.end.offset, {
|
|
312
|
+
verification: {
|
|
313
|
+
// If no errors/warnings/diagnostics were reported within the region of code covered
|
|
314
|
+
// by the @vue-expect-error directive, then we should allow any `unused @ts-expect-error`
|
|
315
|
+
// diagnostics to be reported upward.
|
|
316
|
+
shouldReport: () => data.expectError.token === 0,
|
|
317
|
+
},
|
|
318
|
+
}, `// @ts-expect-error`);
|
|
319
|
+
yield `${utils_1.newLine}${utils_1.endOfLine}`;
|
|
320
|
+
}
|
|
321
|
+
},
|
|
288
322
|
};
|
|
289
323
|
}
|
|
290
324
|
//# sourceMappingURL=context.js.map
|
|
@@ -2,5 +2,5 @@ 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 generateComponent(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode
|
|
6
|
-
export declare function generateElement(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode
|
|
5
|
+
export declare function generateComponent(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode): Generator<Code>;
|
|
6
|
+
export declare function generateElement(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode): Generator<Code>;
|
|
@@ -19,7 +19,7 @@ const propertyAccess_1 = require("./propertyAccess");
|
|
|
19
19
|
const styleScopedClasses_1 = require("./styleScopedClasses");
|
|
20
20
|
const vSlot_1 = require("./vSlot");
|
|
21
21
|
const colonReg = /:/g;
|
|
22
|
-
function* generateComponent(options, ctx, node
|
|
22
|
+
function* generateComponent(options, ctx, node) {
|
|
23
23
|
const tagOffsets = [node.loc.start.offset + options.template.content.slice(node.loc.start.offset).indexOf(node.tag)];
|
|
24
24
|
if (!node.isSelfClosing && options.template.lang === 'html') {
|
|
25
25
|
const endTagOffset = node.loc.start.offset + node.loc.source.lastIndexOf(node.tag);
|
|
@@ -168,15 +168,12 @@ function* generateComponent(options, ctx, node, isVForChild) {
|
|
|
168
168
|
const componentInstanceVar = ctx.getInternalVariable();
|
|
169
169
|
ctx.currentComponent.used = true;
|
|
170
170
|
yield `var ${componentInstanceVar} = {} as (Parameters<NonNullable<typeof ${componentCtxVar}['expose']>>[0] | null)`;
|
|
171
|
-
if (
|
|
171
|
+
if (ctx.inVFor) {
|
|
172
172
|
yield `[]`;
|
|
173
173
|
}
|
|
174
174
|
yield `${utils_1.endOfLine}`;
|
|
175
175
|
if (refName && offset) {
|
|
176
|
-
ctx.
|
|
177
|
-
typeExp: `typeof ${ctx.getHoistVariable(componentInstanceVar)}`,
|
|
178
|
-
offset
|
|
179
|
-
});
|
|
176
|
+
ctx.addTemplateRef(refName, `typeof ${ctx.getHoistVariable(componentInstanceVar)}`, offset);
|
|
180
177
|
}
|
|
181
178
|
if (isRootNode) {
|
|
182
179
|
ctx.singleRootElTypes.push(`NonNullable<typeof ${componentInstanceVar}>['$el']`);
|
|
@@ -189,19 +186,12 @@ function* generateComponent(options, ctx, node, isVForChild) {
|
|
|
189
186
|
}
|
|
190
187
|
(0, styleScopedClasses_1.collectStyleScopedClassReferences)(options, ctx, node);
|
|
191
188
|
const slotDir = node.props.find(p => p.type === CompilerDOM.NodeTypes.DIRECTIVE && p.name === 'slot');
|
|
192
|
-
|
|
193
|
-
yield* (0, vSlot_1.generateVSlot)(options, ctx, node, slotDir);
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
// #932: reference for default slot
|
|
197
|
-
yield* (0, vSlot_1.generateImplicitDefaultSlot)(ctx, node);
|
|
198
|
-
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node);
|
|
199
|
-
}
|
|
189
|
+
yield* (0, vSlot_1.generateVSlot)(options, ctx, node, slotDir);
|
|
200
190
|
if (ctx.currentComponent.used) {
|
|
201
191
|
yield `var ${componentCtxVar}!: __VLS_PickFunctionalComponentCtx<typeof ${componentOriginalVar}, typeof ${componentVNodeVar}>${utils_1.endOfLine}`;
|
|
202
192
|
}
|
|
203
193
|
}
|
|
204
|
-
function* generateElement(options, ctx, node
|
|
194
|
+
function* generateElement(options, ctx, node) {
|
|
205
195
|
const startTagOffset = node.loc.start.offset + options.template.content.slice(node.loc.start.offset).indexOf(node.tag);
|
|
206
196
|
const endTagOffset = !node.isSelfClosing && options.template.lang === 'html'
|
|
207
197
|
? node.loc.start.offset + node.loc.source.lastIndexOf(node.tag)
|
|
@@ -221,13 +211,10 @@ function* generateElement(options, ctx, node, isVForChild) {
|
|
|
221
211
|
const [refName, offset] = yield* generateElementReference(options, ctx, node);
|
|
222
212
|
if (refName && offset) {
|
|
223
213
|
let typeExp = `__VLS_NativeElements['${node.tag}']`;
|
|
224
|
-
if (
|
|
214
|
+
if (ctx.inVFor) {
|
|
225
215
|
typeExp += `[]`;
|
|
226
216
|
}
|
|
227
|
-
ctx.
|
|
228
|
-
typeExp,
|
|
229
|
-
offset
|
|
230
|
-
});
|
|
217
|
+
ctx.addTemplateRef(refName, typeExp, offset);
|
|
231
218
|
}
|
|
232
219
|
if (ctx.singleRootNodes.has(node)) {
|
|
233
220
|
ctx.singleRootElTypes.push(`__VLS_NativeElements['${node.tag}']`);
|
|
@@ -236,7 +223,7 @@ function* generateElement(options, ctx, node, isVForChild) {
|
|
|
236
223
|
ctx.inheritedAttrVars.add(`__VLS_elements.${node.tag}`);
|
|
237
224
|
}
|
|
238
225
|
(0, styleScopedClasses_1.collectStyleScopedClassReferences)(options, ctx, node);
|
|
239
|
-
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node);
|
|
226
|
+
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node.children);
|
|
240
227
|
}
|
|
241
228
|
function* generateFailedPropExps(options, ctx, failedPropExps) {
|
|
242
229
|
for (const failedExp of failedPropExps) {
|
|
@@ -271,8 +258,8 @@ function* generateCanonicalComponentName(tagText, offset, features) {
|
|
|
271
258
|
}
|
|
272
259
|
}
|
|
273
260
|
function* generateComponentGeneric(ctx) {
|
|
274
|
-
if (ctx.
|
|
275
|
-
const { content, offset } = ctx.
|
|
261
|
+
if (ctx.currentInfo.generic) {
|
|
262
|
+
const { content, offset } = ctx.currentInfo.generic;
|
|
276
263
|
yield* (0, wrapWith_1.wrapWith)(offset, offset + content.length, ctx.codeFeatures.verification, `<`, [
|
|
277
264
|
content,
|
|
278
265
|
'template',
|
|
@@ -280,7 +267,6 @@ function* generateComponentGeneric(ctx) {
|
|
|
280
267
|
ctx.codeFeatures.all
|
|
281
268
|
], `>`);
|
|
282
269
|
}
|
|
283
|
-
ctx.lastGenericComment = undefined;
|
|
284
270
|
}
|
|
285
271
|
function* generateElementReference(options, ctx, node) {
|
|
286
272
|
for (const prop of node.props) {
|
|
@@ -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,
|
|
5
|
+
export declare function generateElementChildren(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, children: (CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode)[], enterNode?: boolean): Generator<Code>;
|
|
@@ -2,12 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateElementChildren = generateElementChildren;
|
|
4
4
|
const templateChild_1 = require("./templateChild");
|
|
5
|
-
function* generateElementChildren(options, ctx,
|
|
6
|
-
yield* ctx.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, prev);
|
|
10
|
-
prev = childNode;
|
|
5
|
+
function* generateElementChildren(options, ctx, children, enterNode = true) {
|
|
6
|
+
yield* ctx.generateAutoImportCompletion();
|
|
7
|
+
for (const childNode of children) {
|
|
8
|
+
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, enterNode);
|
|
11
9
|
}
|
|
12
10
|
yield* ctx.generateAutoImportCompletion();
|
|
13
11
|
}
|
|
@@ -39,9 +39,7 @@ function* generateElementDirectives(options, ctx, node) {
|
|
|
39
39
|
function* generateIdentifier(options, ctx, prop) {
|
|
40
40
|
const rawName = 'v-' + prop.name;
|
|
41
41
|
yield* (0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + rawName.length, ctx.codeFeatures.verification, `__VLS_directives.`, ...(0, camelized_1.generateCamelized)(rawName, 'template', prop.loc.start.offset, ctx.resolveCodeFeatures({
|
|
42
|
-
...codeFeatures_1.codeFeatures.
|
|
43
|
-
// fix https://github.com/vuejs/language-tools/issues/1905
|
|
44
|
-
...codeFeatures_1.codeFeatures.additionalCompletion,
|
|
42
|
+
...codeFeatures_1.codeFeatures.withoutHighlightAndCompletion,
|
|
45
43
|
verification: options.vueCompilerOptions.checkUnknownDirectives && !builtInDirectives.has(prop.name),
|
|
46
44
|
})));
|
|
47
45
|
}
|
|
@@ -83,7 +83,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
83
83
|
}
|
|
84
84
|
const codes = [...(0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, ...(prop.arg
|
|
85
85
|
? (0, objectProperty_1.generateObjectProperty)(options, ctx, propName, prop.arg.loc.start.offset, codeInfo, prop.loc.name_2 ??= {}, shouldCamelize)
|
|
86
|
-
: (0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + 'v-model'.length, ctx.codeFeatures.withoutHighlightAndCompletion, propName)), `: `, ...generatePropExp(options, ctx, prop, prop.exp, ctx.codeFeatures.all, enableCodeFeatures))];
|
|
86
|
+
: (0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + 'v-model'.length, ctx.codeFeatures.withoutHighlightAndCompletion, propName)), `: `, ...(0, wrapWith_1.wrapWith)(prop.arg?.loc.start.offset ?? prop.loc.start.offset, prop.arg?.loc.end.offset ?? prop.loc.end.offset, ctx.codeFeatures.verification, ...generatePropExp(options, ctx, prop, prop.exp, ctx.codeFeatures.all, enableCodeFeatures)))];
|
|
87
87
|
if (enableCodeFeatures) {
|
|
88
88
|
yield* codes;
|
|
89
89
|
}
|
|
@@ -32,10 +32,9 @@ function* generateTemplate(options) {
|
|
|
32
32
|
ctx.dollarVars.add('$el');
|
|
33
33
|
}
|
|
34
34
|
if (options.template.ast) {
|
|
35
|
-
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, options.template.ast
|
|
35
|
+
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, options.template.ast);
|
|
36
36
|
}
|
|
37
37
|
yield* (0, styleScopedClasses_1.generateStyleScopedClassReferences)(ctx);
|
|
38
|
-
yield* ctx.generateAutoImportCompletion();
|
|
39
38
|
yield* ctx.generateHoistVariables();
|
|
40
39
|
const speicalTypes = [
|
|
41
40
|
[slotsPropertyName, yield* generateSlots(options, ctx)],
|
|
@@ -93,12 +92,26 @@ function* generateInheritedAttrs(options, ctx) {
|
|
|
93
92
|
return `import('${options.vueCompilerOptions.lib}').ComponentPublicInstance['$attrs'] & Partial<__VLS_InheritedAttrs>`;
|
|
94
93
|
}
|
|
95
94
|
function* generateTemplateRefs(options, ctx) {
|
|
96
|
-
yield `type __VLS_TemplateRefs = {
|
|
97
|
-
for (const [name,
|
|
98
|
-
yield
|
|
99
|
-
|
|
95
|
+
yield `type __VLS_TemplateRefs = {}`;
|
|
96
|
+
for (const [name, refs] of ctx.templateRefs) {
|
|
97
|
+
yield `${utils_1.newLine}& `;
|
|
98
|
+
if (refs.length >= 2) {
|
|
99
|
+
yield `(`;
|
|
100
|
+
}
|
|
101
|
+
for (let i = 0; i < refs.length; i++) {
|
|
102
|
+
const { typeExp, offset } = refs[i];
|
|
103
|
+
if (i) {
|
|
104
|
+
yield ` | `;
|
|
105
|
+
}
|
|
106
|
+
yield `{ `;
|
|
107
|
+
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, name, offset, ctx.codeFeatures.navigation);
|
|
108
|
+
yield `: ${typeExp} }`;
|
|
109
|
+
}
|
|
110
|
+
if (refs.length >= 2) {
|
|
111
|
+
yield `)`;
|
|
112
|
+
}
|
|
100
113
|
}
|
|
101
|
-
yield
|
|
114
|
+
yield utils_1.endOfLine;
|
|
102
115
|
return `__VLS_TemplateRefs`;
|
|
103
116
|
}
|
|
104
117
|
function* generateRootEl(ctx) {
|