@vue/language-core 3.0.0 → 3.0.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 -2
- package/lib/codegen/script/component.js +64 -103
- package/lib/codegen/script/index.d.ts +0 -1
- package/lib/codegen/script/index.js +9 -11
- package/lib/codegen/template/element.js +1 -4
- package/lib/codegen/template/elementProps.js +4 -4
- package/lib/codegen/template/index.js +2 -2
- package/lib/codegen/template/interpolation.js +36 -28
- package/lib/codegen/template/vFor.js +1 -1
- package/lib/codegen/template/vSlot.js +4 -28
- package/lib/codegen/utils/index.d.ts +1 -1
- package/lib/codegen/utils/index.js +3 -7
- package/lib/parsers/scriptSetupRanges.js +9 -5
- package/lib/plugins/file-html.js +2 -1
- package/lib/plugins/file-md.js +24 -31
- package/lib/plugins/vue-tsx.js +2 -9
- package/lib/types.d.ts +1 -3
- package/lib/utils/ts.d.ts +6 -7
- package/lib/utils/ts.js +41 -47
- package/package.json +7 -6
|
@@ -14,7 +14,7 @@ function getGlobalTypesFileName({ lib, target, checkUnknownProps, checkUnknownEv
|
|
|
14
14
|
}
|
|
15
15
|
function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvents, checkUnknownComponents, }) {
|
|
16
16
|
const fnPropsType = `(T extends { $props: infer Props } ? Props : {})${checkUnknownProps ? '' : ' & Record<string, unknown>'}`;
|
|
17
|
-
let text =
|
|
17
|
+
let text = `// @ts-nocheck\nexport {};\n`;
|
|
18
18
|
if (target < 3.5) {
|
|
19
19
|
text += `
|
|
20
20
|
; declare module '${lib}' {
|
|
@@ -143,7 +143,7 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
|
|
|
143
143
|
index: number,
|
|
144
144
|
][];
|
|
145
145
|
function __VLS_getSlotParameters<S, D extends S>(slot: S, decl?: D):
|
|
146
|
-
|
|
146
|
+
D extends (...args: infer P) => any ? P : any[];
|
|
147
147
|
function __VLS_asFunctionalDirective<T>(dir: T): T extends import('${lib}').ObjectDirective
|
|
148
148
|
? NonNullable<T['created' | 'beforeMount' | 'mounted' | 'beforeUpdate' | 'updated' | 'beforeUnmount' | 'unmounted']>
|
|
149
149
|
: T extends (...args: any) => any
|
|
@@ -60,135 +60,96 @@ function* generateComponentSetupReturns(scriptSetupRanges) {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
function* generateEmitsOption(options, scriptSetupRanges) {
|
|
63
|
-
const
|
|
63
|
+
const optionCodes = [];
|
|
64
|
+
const typeOptionCodes = [];
|
|
64
65
|
if (scriptSetupRanges.defineModel.length) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
typeOptionType: `__VLS_ModelEmit`,
|
|
68
|
-
});
|
|
66
|
+
optionCodes.push(`{} as __VLS_NormalizeEmits<typeof __VLS_modelEmit>`);
|
|
67
|
+
typeOptionCodes.push(`__VLS_ModelEmit`);
|
|
69
68
|
}
|
|
70
69
|
if (scriptSetupRanges.defineEmits) {
|
|
71
70
|
const { name, typeArg, hasUnionTypeArg } = scriptSetupRanges.defineEmits;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
? `__VLS_Emit`
|
|
76
|
-
: undefined,
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
if (options.vueCompilerOptions.target >= 3.5 && codes.every(code => code.typeOptionType)) {
|
|
80
|
-
if (codes.length === 1) {
|
|
81
|
-
yield `__typeEmits: {} as `;
|
|
82
|
-
yield codes[0].typeOptionType;
|
|
83
|
-
yield `,${utils_1.newLine}`;
|
|
71
|
+
optionCodes.push(`{} as __VLS_NormalizeEmits<typeof ${name ?? '__VLS_emit'}>`);
|
|
72
|
+
if (typeArg && !hasUnionTypeArg) {
|
|
73
|
+
typeOptionCodes.push(`__VLS_Emit`);
|
|
84
74
|
}
|
|
85
|
-
else
|
|
86
|
-
|
|
87
|
-
yield codes[0].typeOptionType;
|
|
88
|
-
for (let i = 1; i < codes.length; i++) {
|
|
89
|
-
yield ` & `;
|
|
90
|
-
yield codes[i].typeOptionType;
|
|
91
|
-
}
|
|
92
|
-
yield `,${utils_1.newLine}`;
|
|
75
|
+
else {
|
|
76
|
+
typeOptionCodes.length = 0;
|
|
93
77
|
}
|
|
94
78
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
else if (codes.length >= 2) {
|
|
102
|
-
yield `emits: {${utils_1.newLine}`;
|
|
103
|
-
for (const code of codes) {
|
|
104
|
-
yield `...`;
|
|
105
|
-
yield code.optionExp;
|
|
106
|
-
yield `,${utils_1.newLine}`;
|
|
107
|
-
}
|
|
108
|
-
yield `},${utils_1.newLine}`;
|
|
109
|
-
}
|
|
79
|
+
if (options.vueCompilerOptions.target >= 3.5 && typeOptionCodes.length) {
|
|
80
|
+
yield* generateIntersectMerge('__typeEmits', typeOptionCodes);
|
|
81
|
+
}
|
|
82
|
+
else if (optionCodes.length) {
|
|
83
|
+
yield* generateSpreadMerge('emits', optionCodes);
|
|
110
84
|
}
|
|
111
85
|
}
|
|
112
86
|
function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasEmitsOption, inheritAttrs) {
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
if (options.vueCompilerOptions.target >= 3.6) {
|
|
116
|
-
codes.push({
|
|
117
|
-
optionExp: '{}',
|
|
118
|
-
typeOptionExp: `{} as __VLS_PublicProps`,
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
codes.push({
|
|
123
|
-
optionExp: [
|
|
124
|
-
`{} as `,
|
|
125
|
-
scriptSetupRanges.withDefaults?.arg ? `${ctx.localTypes.WithDefaults}<` : '',
|
|
126
|
-
`${ctx.localTypes.TypePropsToOption}<__VLS_PublicProps>`,
|
|
127
|
-
scriptSetupRanges.withDefaults?.arg ? `, typeof __VLS_withDefaultsArg>` : '',
|
|
128
|
-
].join(''),
|
|
129
|
-
typeOptionExp: `{} as __VLS_PublicProps`,
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if (scriptSetupRanges.defineProps?.arg) {
|
|
134
|
-
const { arg } = scriptSetupRanges.defineProps;
|
|
135
|
-
codes.push({
|
|
136
|
-
optionExp: (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.navigation),
|
|
137
|
-
typeOptionExp: undefined,
|
|
138
|
-
});
|
|
139
|
-
}
|
|
87
|
+
const getOptionCodes = [];
|
|
88
|
+
const typeOptionCodes = [];
|
|
140
89
|
if (inheritAttrs && options.templateCodegen?.inheritedAttrVars.size) {
|
|
141
90
|
let attrsType = `Partial<__VLS_InheritedAttrs>`;
|
|
142
91
|
if (hasEmitsOption) {
|
|
143
92
|
attrsType = `Omit<${attrsType}, \`on\${string}\`>`;
|
|
144
93
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
? `{} as ${optionType}`
|
|
150
|
-
// workaround for https://github.com/vuejs/core/pull/7419
|
|
151
|
-
: `{} as keyof ${propsType} extends never ? never: ${optionType}`,
|
|
152
|
-
typeOptionExp: `{} as ${attrsType}`,
|
|
94
|
+
getOptionCodes.push(() => {
|
|
95
|
+
const propsType = `__VLS_PickNotAny<${ctx.localTypes.OmitIndexSignature}<${attrsType}>, {}>`;
|
|
96
|
+
const optionType = `${ctx.localTypes.TypePropsToOption}<${propsType}>`;
|
|
97
|
+
return `{} as ${optionType}`;
|
|
153
98
|
});
|
|
99
|
+
typeOptionCodes.push(`{} as ${attrsType}`);
|
|
100
|
+
}
|
|
101
|
+
if (ctx.generatedPropsType) {
|
|
102
|
+
if (options.vueCompilerOptions.target < 3.6) {
|
|
103
|
+
getOptionCodes.push(() => {
|
|
104
|
+
const propsType = `${ctx.localTypes.TypePropsToOption}<__VLS_PublicProps>`;
|
|
105
|
+
return `{} as ` + (scriptSetupRanges.withDefaults?.arg
|
|
106
|
+
? `${ctx.localTypes.WithDefaults}<${propsType}, typeof __VLS_withDefaultsArg>`
|
|
107
|
+
: propsType);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
typeOptionCodes.push(`{} as __VLS_PublicProps`);
|
|
154
111
|
}
|
|
155
|
-
|
|
156
|
-
|
|
112
|
+
if (scriptSetupRanges.defineProps?.arg) {
|
|
113
|
+
const { arg } = scriptSetupRanges.defineProps;
|
|
114
|
+
getOptionCodes.push(() => (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.navigation));
|
|
115
|
+
typeOptionCodes.length = 0;
|
|
116
|
+
}
|
|
117
|
+
const useTypeOption = options.vueCompilerOptions.target >= 3.5 && typeOptionCodes.length;
|
|
118
|
+
const useOption = (!useTypeOption || scriptSetupRanges.withDefaults) && getOptionCodes.length;
|
|
157
119
|
if (useTypeOption) {
|
|
158
120
|
if (options.vueCompilerOptions.target >= 3.6
|
|
159
121
|
&& scriptSetupRanges.withDefaults?.arg) {
|
|
160
122
|
yield `__defaults: __VLS_withDefaultsArg,${utils_1.newLine}`;
|
|
161
123
|
}
|
|
162
|
-
|
|
163
|
-
yield `__typeProps: `;
|
|
164
|
-
yield codes[0].typeOptionExp;
|
|
165
|
-
yield `,${utils_1.newLine}`;
|
|
166
|
-
}
|
|
167
|
-
else if (codes.length >= 2) {
|
|
168
|
-
yield `__typeProps: {${utils_1.newLine}`;
|
|
169
|
-
for (const { typeOptionExp } of codes) {
|
|
170
|
-
yield `...`;
|
|
171
|
-
yield typeOptionExp;
|
|
172
|
-
yield `,${utils_1.newLine}`;
|
|
173
|
-
}
|
|
174
|
-
yield `},${utils_1.newLine}`;
|
|
175
|
-
}
|
|
124
|
+
yield* generateSpreadMerge('__typeProps', typeOptionCodes);
|
|
176
125
|
}
|
|
177
126
|
if (useOption) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
127
|
+
yield* generateSpreadMerge('props', getOptionCodes.map(fn => fn()));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function* generateIntersectMerge(key, codes) {
|
|
131
|
+
yield `${key}: {} as `;
|
|
132
|
+
yield codes[0];
|
|
133
|
+
for (let i = 1; i < codes.length; i++) {
|
|
134
|
+
yield ` & `;
|
|
135
|
+
yield codes[i];
|
|
136
|
+
}
|
|
137
|
+
yield `,${utils_1.newLine}`;
|
|
138
|
+
}
|
|
139
|
+
function* generateSpreadMerge(key, codes) {
|
|
140
|
+
yield `${key}: `;
|
|
141
|
+
if (codes.length === 1) {
|
|
142
|
+
yield codes[0];
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
yield `{${utils_1.newLine}`;
|
|
146
|
+
for (const code of codes) {
|
|
147
|
+
yield `...`;
|
|
148
|
+
yield code;
|
|
181
149
|
yield `,${utils_1.newLine}`;
|
|
182
150
|
}
|
|
183
|
-
|
|
184
|
-
yield `props: {${utils_1.newLine}`;
|
|
185
|
-
for (const { optionExp } of codes) {
|
|
186
|
-
yield `...`;
|
|
187
|
-
yield optionExp;
|
|
188
|
-
yield `,${utils_1.newLine}`;
|
|
189
|
-
}
|
|
190
|
-
yield `},${utils_1.newLine}`;
|
|
191
|
-
}
|
|
151
|
+
yield `}`;
|
|
192
152
|
}
|
|
153
|
+
yield `,${utils_1.newLine}`;
|
|
193
154
|
}
|
|
194
155
|
//# sourceMappingURL=component.js.map
|
|
@@ -18,7 +18,6 @@ export interface ScriptCodegenOptions {
|
|
|
18
18
|
} | undefined;
|
|
19
19
|
destructuredPropNames: Set<string>;
|
|
20
20
|
templateRefNames: Set<string>;
|
|
21
|
-
appendGlobalTypes: boolean;
|
|
22
21
|
}
|
|
23
22
|
export declare function generateScript(options: ScriptCodegenOptions): Generator<Code, ScriptCodegenContext>;
|
|
24
23
|
export declare function generateScriptSectionPartiallyEnding(source: string, end: number, mark: string, delimiter?: string): Generator<Code>;
|
|
@@ -4,7 +4,6 @@ exports.generateScript = generateScript;
|
|
|
4
4
|
exports.generateScriptSectionPartiallyEnding = generateScriptSectionPartiallyEnding;
|
|
5
5
|
const path = require("path-browserify");
|
|
6
6
|
const codeFeatures_1 = require("../codeFeatures");
|
|
7
|
-
const globalTypes_1 = require("../globalTypes");
|
|
8
7
|
const utils_1 = require("../utils");
|
|
9
8
|
const componentSelf_1 = require("./componentSelf");
|
|
10
9
|
const context_1 = require("./context");
|
|
@@ -13,21 +12,23 @@ const src_1 = require("./src");
|
|
|
13
12
|
const template_1 = require("./template");
|
|
14
13
|
function* generateScript(options) {
|
|
15
14
|
const ctx = (0, context_1.createScriptCodegenContext)(options);
|
|
16
|
-
if (options.vueCompilerOptions.
|
|
17
|
-
const
|
|
18
|
-
if (
|
|
19
|
-
let relativePath = path.relative(path.dirname(options.fileName),
|
|
20
|
-
if (relativePath !==
|
|
15
|
+
if (options.vueCompilerOptions.globalTypesPath) {
|
|
16
|
+
const globalTypesPath = options.vueCompilerOptions.globalTypesPath;
|
|
17
|
+
if (path.isAbsolute(globalTypesPath)) {
|
|
18
|
+
let relativePath = path.relative(path.dirname(options.fileName), globalTypesPath);
|
|
19
|
+
if (relativePath !== globalTypesPath
|
|
20
|
+
&& !relativePath.startsWith('./')
|
|
21
|
+
&& !relativePath.startsWith('../')) {
|
|
21
22
|
relativePath = './' + relativePath;
|
|
22
23
|
}
|
|
23
24
|
yield `/// <reference types="${relativePath}" />${utils_1.newLine}`;
|
|
24
25
|
}
|
|
25
26
|
else {
|
|
26
|
-
yield `/// <reference types="
|
|
27
|
+
yield `/// <reference types="${globalTypesPath}" />${utils_1.newLine}`;
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
else {
|
|
30
|
-
yield
|
|
31
|
+
yield `/* placeholder */${utils_1.newLine}`;
|
|
31
32
|
}
|
|
32
33
|
if (options.sfc.script?.src) {
|
|
33
34
|
yield* (0, src_1.generateSrc)(options.sfc.script.src);
|
|
@@ -106,9 +107,6 @@ function* generateScript(options) {
|
|
|
106
107
|
yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
|
|
107
108
|
}
|
|
108
109
|
yield* ctx.localTypes.generate([...ctx.localTypes.getUsedNames()]);
|
|
109
|
-
if (options.appendGlobalTypes) {
|
|
110
|
-
yield (0, globalTypes_1.generateGlobalTypes)(options.vueCompilerOptions);
|
|
111
|
-
}
|
|
112
110
|
if (options.sfc.scriptSetup) {
|
|
113
111
|
yield ['', 'scriptSetup', options.sfc.scriptSetup.content.length, codeFeatures_1.codeFeatures.verification];
|
|
114
112
|
}
|
|
@@ -98,7 +98,7 @@ function* generateComponent(options, ctx, node) {
|
|
|
98
98
|
}
|
|
99
99
|
yield `)${utils_1.endOfLine}`;
|
|
100
100
|
}
|
|
101
|
-
else
|
|
101
|
+
else {
|
|
102
102
|
yield `const ${componentOriginalVar} = ({} as __VLS_WithComponent<'${getCanonicalComponentName(node.tag)}', __VLS_LocalComponents, `;
|
|
103
103
|
if (options.selfComponentName && possibleOriginalNames.includes(options.selfComponentName)) {
|
|
104
104
|
yield `typeof __VLS_self & (new () => { `
|
|
@@ -137,9 +137,6 @@ function* generateComponent(options, ctx, node) {
|
|
|
137
137
|
yield `${utils_1.endOfLine}`;
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
|
-
else {
|
|
141
|
-
yield `const ${componentOriginalVar} = {} as any${utils_1.endOfLine}`;
|
|
142
|
-
}
|
|
143
140
|
yield `// @ts-ignore${utils_1.newLine}`;
|
|
144
141
|
yield `const ${componentFunctionalVar} = __VLS_asFunctionalComponent(${componentOriginalVar}, new ${componentOriginalVar}({${utils_1.newLine}`;
|
|
145
142
|
yield* (0, elementProps_1.generateElementProps)(options, ctx, node, props, options.vueCompilerOptions.checkUnknownProps, false);
|
|
@@ -4,8 +4,8 @@ exports.generateElementProps = generateElementProps;
|
|
|
4
4
|
exports.generatePropExp = generatePropExp;
|
|
5
5
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
6
6
|
const shared_1 = require("@vue/shared");
|
|
7
|
-
const minimatch_1 = require("minimatch");
|
|
8
7
|
const muggle_string_1 = require("muggle-string");
|
|
8
|
+
const picomatch_1 = require("picomatch");
|
|
9
9
|
const shared_2 = require("../../utils/shared");
|
|
10
10
|
const codeFeatures_1 = require("../codeFeatures");
|
|
11
11
|
const inlayHints_1 = require("../inlayHints");
|
|
@@ -65,7 +65,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
65
65
|
propName = getModelPropName(node, options.vueCompilerOptions);
|
|
66
66
|
}
|
|
67
67
|
if (propName === undefined
|
|
68
|
-
|| options.vueCompilerOptions.dataAttributes.some(pattern => (0,
|
|
68
|
+
|| options.vueCompilerOptions.dataAttributes.some(pattern => (0, picomatch_1.isMatch)(propName, pattern))) {
|
|
69
69
|
if (prop.exp && prop.exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY) {
|
|
70
70
|
failedPropExps?.push({ node: prop.exp, prefix: `(`, suffix: `)` });
|
|
71
71
|
}
|
|
@@ -111,7 +111,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
else if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE) {
|
|
114
|
-
if (options.vueCompilerOptions.dataAttributes.some(pattern => (0,
|
|
114
|
+
if (options.vueCompilerOptions.dataAttributes.some(pattern => (0, picomatch_1.isMatch)(prop.name, pattern))
|
|
115
115
|
// Vue 2 Transition doesn't support "persisted" property but `@vue/compiler-dom` always adds it (#3881)
|
|
116
116
|
|| (options.vueCompilerOptions.target < 3
|
|
117
117
|
&& prop.name === 'persisted'
|
|
@@ -218,7 +218,7 @@ function getShouldCamelize(options, prop, propName) {
|
|
|
218
218
|
|| !prop.arg
|
|
219
219
|
|| (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic))
|
|
220
220
|
&& (0, shared_2.hyphenateAttr)(propName) === propName
|
|
221
|
-
&& !options.vueCompilerOptions.htmlAttributes.some(pattern => (0,
|
|
221
|
+
&& !options.vueCompilerOptions.htmlAttributes.some(pattern => (0, picomatch_1.isMatch)(propName, pattern));
|
|
222
222
|
}
|
|
223
223
|
function getPropsCodeInfo(ctx, strictPropsCheck) {
|
|
224
224
|
return ctx.resolveCodeFeatures({
|
|
@@ -58,10 +58,10 @@ function* generateSlots(options, ctx) {
|
|
|
58
58
|
for (const slot of ctx.slots) {
|
|
59
59
|
yield `${utils_1.newLine}& { `;
|
|
60
60
|
if (slot.name && slot.offset !== undefined) {
|
|
61
|
-
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slot.name, slot.offset, ctx.codeFeatures.
|
|
61
|
+
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slot.name, slot.offset, ctx.codeFeatures.navigation);
|
|
62
62
|
}
|
|
63
63
|
else {
|
|
64
|
-
yield* (0, wrapWith_1.wrapWith)(slot.tagRange[0], slot.tagRange[1], ctx.codeFeatures.
|
|
64
|
+
yield* (0, wrapWith_1.wrapWith)(slot.tagRange[0], slot.tagRange[1], ctx.codeFeatures.navigation, `default`);
|
|
65
65
|
}
|
|
66
66
|
yield `?: (props: typeof ${slot.propsVar}) => any }`;
|
|
67
67
|
}
|
|
@@ -70,7 +70,7 @@ function* forEachInterpolationSegment(ts, inlineTsAsts, destructuredPropNames, t
|
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
72
|
};
|
|
73
|
-
ts.forEachChild(ast, node => walkIdentifiers(ts, node, ast, varCb, ctx));
|
|
73
|
+
ts.forEachChild(ast, node => walkIdentifiers(ts, node, ast, varCb, ctx, [], true));
|
|
74
74
|
}
|
|
75
75
|
ctxVars = ctxVars.sort((a, b) => a.offset - b.offset);
|
|
76
76
|
if (ctxVars.length) {
|
|
@@ -122,7 +122,7 @@ function* generateVar(templateRefNames, ctx, code, offset, curVar) {
|
|
|
122
122
|
yield [code.slice(curVar.offset, curVar.offset + curVar.text.length), curVar.offset];
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
-
function walkIdentifiers(ts, node, ast, cb, ctx, blockVars
|
|
125
|
+
function walkIdentifiers(ts, node, ast, cb, ctx, blockVars, isRoot = false) {
|
|
126
126
|
if (ts.isIdentifier(node)) {
|
|
127
127
|
cb(node, false);
|
|
128
128
|
}
|
|
@@ -130,51 +130,55 @@ function walkIdentifiers(ts, node, ast, cb, ctx, blockVars = [], isRoot = true)
|
|
|
130
130
|
cb(node.name, true);
|
|
131
131
|
}
|
|
132
132
|
else if (ts.isPropertyAccessExpression(node)) {
|
|
133
|
-
walkIdentifiers(ts, node.expression, ast, cb, ctx, blockVars
|
|
133
|
+
walkIdentifiers(ts, node.expression, ast, cb, ctx, blockVars);
|
|
134
134
|
}
|
|
135
135
|
else if (ts.isVariableDeclaration(node)) {
|
|
136
|
-
(0, utils_1.
|
|
137
|
-
for (const
|
|
138
|
-
ctx.addLocalVariable(
|
|
136
|
+
const bindingNames = (0, utils_1.collectBindingNames)(ts, node.name, ast);
|
|
137
|
+
for (const name of bindingNames) {
|
|
138
|
+
ctx.addLocalVariable(name);
|
|
139
|
+
blockVars.push(name);
|
|
139
140
|
}
|
|
140
141
|
if (node.initializer) {
|
|
141
|
-
walkIdentifiers(ts, node.initializer, ast, cb, ctx, blockVars
|
|
142
|
+
walkIdentifiers(ts, node.initializer, ast, cb, ctx, blockVars);
|
|
142
143
|
}
|
|
143
144
|
}
|
|
144
145
|
else if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {
|
|
145
|
-
|
|
146
|
+
walkIdentifiersInFunction(ts, node, ast, cb, ctx);
|
|
146
147
|
}
|
|
147
148
|
else if (ts.isObjectLiteralExpression(node)) {
|
|
148
149
|
for (const prop of node.properties) {
|
|
149
150
|
if (ts.isPropertyAssignment(prop)) {
|
|
150
151
|
// fix https://github.com/vuejs/language-tools/issues/1176
|
|
151
152
|
if (ts.isComputedPropertyName(prop.name)) {
|
|
152
|
-
walkIdentifiers(ts, prop.name.expression, ast, cb, ctx, blockVars
|
|
153
|
+
walkIdentifiers(ts, prop.name.expression, ast, cb, ctx, blockVars);
|
|
153
154
|
}
|
|
154
|
-
walkIdentifiers(ts, prop.initializer, ast, cb, ctx, blockVars
|
|
155
|
-
}
|
|
155
|
+
walkIdentifiers(ts, prop.initializer, ast, cb, ctx, blockVars);
|
|
156
|
+
}
|
|
157
|
+
// fix https://github.com/vuejs/language-tools/issues/1156
|
|
156
158
|
else if (ts.isShorthandPropertyAssignment(prop)) {
|
|
157
|
-
walkIdentifiers(ts, prop, ast, cb, ctx, blockVars
|
|
158
|
-
}
|
|
159
|
+
walkIdentifiers(ts, prop, ast, cb, ctx, blockVars);
|
|
160
|
+
}
|
|
161
|
+
// fix https://github.com/vuejs/language-tools/issues/1148#issuecomment-1094378126
|
|
159
162
|
else if (ts.isSpreadAssignment(prop)) {
|
|
160
163
|
// TODO: cannot report "Spread types may only be created from object types.ts(2698)"
|
|
161
|
-
walkIdentifiers(ts, prop.expression, ast, cb, ctx, blockVars
|
|
162
|
-
}
|
|
164
|
+
walkIdentifiers(ts, prop.expression, ast, cb, ctx, blockVars);
|
|
165
|
+
}
|
|
166
|
+
// fix https://github.com/vuejs/language-tools/issues/4604
|
|
163
167
|
else if (ts.isFunctionLike(prop) && prop.body) {
|
|
164
|
-
|
|
168
|
+
walkIdentifiersInFunction(ts, prop, ast, cb, ctx);
|
|
165
169
|
}
|
|
166
170
|
}
|
|
167
171
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
172
|
+
// fix https://github.com/vuejs/language-tools/issues/1422
|
|
173
|
+
else if (ts.isTypeNode(node)) {
|
|
174
|
+
walkIdentifiersInTypeNode(ts, node, cb);
|
|
171
175
|
}
|
|
172
176
|
else {
|
|
173
177
|
const _blockVars = blockVars;
|
|
174
178
|
if (ts.isBlock(node)) {
|
|
175
179
|
blockVars = [];
|
|
176
180
|
}
|
|
177
|
-
ts.forEachChild(node, node => walkIdentifiers(ts, node, ast, cb, ctx, blockVars
|
|
181
|
+
ts.forEachChild(node, node => walkIdentifiers(ts, node, ast, cb, ctx, blockVars));
|
|
178
182
|
if (ts.isBlock(node)) {
|
|
179
183
|
for (const varName of blockVars) {
|
|
180
184
|
ctx.removeLocalVariable(varName);
|
|
@@ -188,30 +192,34 @@ function walkIdentifiers(ts, node, ast, cb, ctx, blockVars = [], isRoot = true)
|
|
|
188
192
|
}
|
|
189
193
|
}
|
|
190
194
|
}
|
|
191
|
-
function
|
|
195
|
+
function walkIdentifiersInFunction(ts, node, ast, cb, ctx) {
|
|
192
196
|
const functionArgs = [];
|
|
193
197
|
for (const param of node.parameters) {
|
|
194
|
-
(0, utils_1.
|
|
198
|
+
functionArgs.push(...(0, utils_1.collectBindingNames)(ts, param.name, ast));
|
|
195
199
|
if (param.type) {
|
|
196
|
-
|
|
200
|
+
walkIdentifiersInTypeNode(ts, param.type, cb);
|
|
197
201
|
}
|
|
198
202
|
}
|
|
199
203
|
for (const varName of functionArgs) {
|
|
200
204
|
ctx.addLocalVariable(varName);
|
|
201
205
|
}
|
|
202
206
|
if (node.body) {
|
|
203
|
-
walkIdentifiers(ts, node.body, ast, cb, ctx);
|
|
207
|
+
walkIdentifiers(ts, node.body, ast, cb, ctx, [], true);
|
|
204
208
|
}
|
|
205
209
|
for (const varName of functionArgs) {
|
|
206
210
|
ctx.removeLocalVariable(varName);
|
|
207
211
|
}
|
|
208
212
|
}
|
|
209
|
-
function
|
|
210
|
-
if (ts.isTypeQueryNode(node)
|
|
211
|
-
|
|
213
|
+
function walkIdentifiersInTypeNode(ts, node, cb) {
|
|
214
|
+
if (ts.isTypeQueryNode(node)) {
|
|
215
|
+
let id = node.exprName;
|
|
216
|
+
while (!ts.isIdentifier(id)) {
|
|
217
|
+
id = id.left;
|
|
218
|
+
}
|
|
219
|
+
cb(id, false);
|
|
212
220
|
}
|
|
213
221
|
else {
|
|
214
|
-
ts.forEachChild(node, node =>
|
|
222
|
+
ts.forEachChild(node, node => walkIdentifiersInTypeNode(ts, node, cb));
|
|
215
223
|
}
|
|
216
224
|
}
|
|
217
225
|
function shouldIdentifierSkipped(ctx, text, destructuredPropNames) {
|
|
@@ -13,7 +13,7 @@ function* generateVFor(options, ctx, node) {
|
|
|
13
13
|
yield `for (const [`;
|
|
14
14
|
if (leftExpressionRange && leftExpressionText) {
|
|
15
15
|
const collectAst = (0, utils_1.createTsAst)(options.ts, ctx.inlineTsAsts, `const [${leftExpressionText}]`);
|
|
16
|
-
(0, utils_1.
|
|
16
|
+
forBlockVars.push(...(0, utils_1.collectBindingNames)(options.ts, collectAst, collectAst));
|
|
17
17
|
yield [
|
|
18
18
|
leftExpressionText,
|
|
19
19
|
'template',
|
|
@@ -29,14 +29,13 @@ function* generateVSlot(options, ctx, node, slotDir) {
|
|
|
29
29
|
}
|
|
30
30
|
else {
|
|
31
31
|
// #932: reference for implicit default slot
|
|
32
|
-
|
|
33
|
-
yield* (0, wrapWith_1.wrapWith)(start, end, ctx.codeFeatures.navigation, `default`);
|
|
32
|
+
yield* (0, wrapWith_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, ctx.codeFeatures.navigation, `default`);
|
|
34
33
|
}
|
|
35
34
|
yield `: ${slotVar} } = ${ctx.currentComponent.ctxVar}.slots!${utils_1.endOfLine}`;
|
|
36
35
|
}
|
|
37
36
|
if (slotDir?.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
38
37
|
const slotAst = (0, utils_1.createTsAst)(options.ts, ctx.inlineTsAsts, `(${slotDir.exp.content}) => {}`);
|
|
39
|
-
(0, utils_1.
|
|
38
|
+
slotBlockVars.push(...(0, utils_1.collectBindingNames)(options.ts, slotAst, slotAst));
|
|
40
39
|
yield* generateSlotParameters(options, ctx, slotAst, slotDir.exp, slotVar);
|
|
41
40
|
}
|
|
42
41
|
for (const varName of slotBlockVars) {
|
|
@@ -47,9 +46,8 @@ function* generateVSlot(options, ctx, node, slotDir) {
|
|
|
47
46
|
ctx.removeLocalVariable(varName);
|
|
48
47
|
}
|
|
49
48
|
if (options.vueCompilerOptions.strictSlotChildren && node.children.length) {
|
|
50
|
-
const { start, end } = getElementInnerLoc(options, node);
|
|
51
49
|
yield `(): __VLS_NormalizeSlotReturns<typeof ${slotVar}> => (`;
|
|
52
|
-
yield* (0, wrapWith_1.wrapWith)(start, end, ctx.codeFeatures.verification, `{} as [`, ...ctx.currentComponent.childTypes.map(name => `${name}, `), `]`);
|
|
50
|
+
yield* (0, wrapWith_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, ctx.codeFeatures.verification, `{} as [`, ...ctx.currentComponent.childTypes.map(name => `${name}, `), `]`);
|
|
53
51
|
yield `)${utils_1.endOfLine}`;
|
|
54
52
|
}
|
|
55
53
|
if (slotDir) {
|
|
@@ -105,7 +103,7 @@ function* generateSlotParameters(options, ctx, ast, exp, slotVar) {
|
|
|
105
103
|
nextStart = end;
|
|
106
104
|
}
|
|
107
105
|
yield chunk(nextStart, expression.equalsGreaterThanToken.pos - 1);
|
|
108
|
-
yield `] = __VLS_getSlotParameters(${slotVar}
|
|
106
|
+
yield `] = __VLS_getSlotParameters(${slotVar}!`;
|
|
109
107
|
if (types.some(t => t)) {
|
|
110
108
|
yield `, `;
|
|
111
109
|
yield* (0, wrapWith_1.wrapWith)(exp.loc.start.offset, exp.loc.end.offset, ctx.codeFeatures.verification, `(`, ...types.flatMap(type => type ? [`_: `, type, `, `] : `_, `), `) => [] as any`);
|
|
@@ -120,26 +118,4 @@ function* generateSlotParameters(options, ctx, ast, exp, slotVar) {
|
|
|
120
118
|
];
|
|
121
119
|
}
|
|
122
120
|
}
|
|
123
|
-
function getElementInnerLoc(options, node) {
|
|
124
|
-
if (node.children.length) {
|
|
125
|
-
let start = node.children[0].loc.start.offset;
|
|
126
|
-
let end = node.children.at(-1).loc.end.offset;
|
|
127
|
-
while (options.template.content[start - 1] !== '>') {
|
|
128
|
-
start--;
|
|
129
|
-
}
|
|
130
|
-
while (options.template.content[end] !== '<' && end < node.loc.end.offset) {
|
|
131
|
-
end++;
|
|
132
|
-
}
|
|
133
|
-
return {
|
|
134
|
-
start,
|
|
135
|
-
end,
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
return {
|
|
140
|
-
start: node.loc.start.offset,
|
|
141
|
-
end: node.loc.end.offset,
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
121
|
//# sourceMappingURL=vSlot.js.map
|
|
@@ -5,7 +5,7 @@ export declare const newLine = "\n";
|
|
|
5
5
|
export declare const endOfLine = ";\n";
|
|
6
6
|
export declare const combineLastMapping: VueCodeInformation;
|
|
7
7
|
export declare const identifierRegex: RegExp;
|
|
8
|
-
export declare function
|
|
8
|
+
export declare function collectBindingNames(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): string[];
|
|
9
9
|
export declare function collectIdentifiers(ts: typeof import('typescript'), node: ts.Node, results?: {
|
|
10
10
|
id: ts.Identifier;
|
|
11
11
|
isRest: boolean;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.identifierRegex = exports.combineLastMapping = exports.endOfLine = exports.newLine = void 0;
|
|
4
|
-
exports.
|
|
4
|
+
exports.collectBindingNames = collectBindingNames;
|
|
5
5
|
exports.collectIdentifiers = collectIdentifiers;
|
|
6
6
|
exports.normalizeAttributeValue = normalizeAttributeValue;
|
|
7
7
|
exports.createTsAst = createTsAst;
|
|
@@ -11,12 +11,8 @@ exports.newLine = `\n`;
|
|
|
11
11
|
exports.endOfLine = `;${exports.newLine}`;
|
|
12
12
|
exports.combineLastMapping = { __combineOffset: 1 };
|
|
13
13
|
exports.identifierRegex = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
for (const { id } of identifiers) {
|
|
17
|
-
results.push((0, shared_1.getNodeText)(ts, id, ast));
|
|
18
|
-
}
|
|
19
|
-
return results;
|
|
14
|
+
function collectBindingNames(ts, node, ast) {
|
|
15
|
+
return collectIdentifiers(ts, node).map(({ id }) => (0, shared_1.getNodeText)(ts, id, ast));
|
|
20
16
|
}
|
|
21
17
|
function collectIdentifiers(ts, node, results = [], isRest = false, initializer = undefined) {
|
|
22
18
|
if (ts.isIdentifier(node)) {
|
|
@@ -147,7 +147,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
147
147
|
};
|
|
148
148
|
if (ts.isVariableDeclaration(parent) && ts.isObjectBindingPattern(parent.name)) {
|
|
149
149
|
defineProps.destructured = new Map();
|
|
150
|
-
const identifiers = (0, utils_1.collectIdentifiers)(ts, parent.name
|
|
150
|
+
const identifiers = (0, utils_1.collectIdentifiers)(ts, parent.name);
|
|
151
151
|
for (const { id, isRest, initializer } of identifiers) {
|
|
152
152
|
const name = _getNodeText(id);
|
|
153
153
|
if (isRest) {
|
|
@@ -343,7 +343,8 @@ function findBindingVars(ts, left, ast) {
|
|
|
343
343
|
function worker(node) {
|
|
344
344
|
if (ts.isIdentifier(node)) {
|
|
345
345
|
vars.push((0, shared_1.getStartEnd)(ts, node, ast));
|
|
346
|
-
}
|
|
346
|
+
}
|
|
347
|
+
// { ? } = ...
|
|
347
348
|
// [ ? ] = ...
|
|
348
349
|
else if (ts.isObjectBindingPattern(node) || ts.isArrayBindingPattern(node)) {
|
|
349
350
|
for (const property of node.elements) {
|
|
@@ -351,13 +352,16 @@ function findBindingVars(ts, left, ast) {
|
|
|
351
352
|
worker(property.name);
|
|
352
353
|
}
|
|
353
354
|
}
|
|
354
|
-
}
|
|
355
|
+
}
|
|
356
|
+
// { foo: ? } = ...
|
|
355
357
|
else if (ts.isPropertyAssignment(node)) {
|
|
356
358
|
worker(node.initializer);
|
|
357
|
-
}
|
|
359
|
+
}
|
|
360
|
+
// { foo } = ...
|
|
358
361
|
else if (ts.isShorthandPropertyAssignment(node)) {
|
|
359
362
|
vars.push((0, shared_1.getStartEnd)(ts, node.name, ast));
|
|
360
|
-
}
|
|
363
|
+
}
|
|
364
|
+
// { ...? } = ...
|
|
361
365
|
// [ ...? ] = ...
|
|
362
366
|
else if (ts.isSpreadAssignment(node) || ts.isSpreadElement(node)) {
|
|
363
367
|
worker(node.expression);
|
package/lib/plugins/file-html.js
CHANGED
|
@@ -53,7 +53,8 @@ const plugin = ({ vueCompilerOptions }) => {
|
|
|
53
53
|
type: 'style',
|
|
54
54
|
lang,
|
|
55
55
|
});
|
|
56
|
-
}
|
|
56
|
+
}
|
|
57
|
+
// ignore `<script src="...">`
|
|
57
58
|
else if (tag === 'script' && !attrs.includes('src=')) {
|
|
58
59
|
let type = attrs.includes('type=') ? 'scriptSetup' : 'script';
|
|
59
60
|
sfc.descriptor[type] = {
|
package/lib/plugins/file-md.js
CHANGED
|
@@ -9,9 +9,9 @@ const codeblockReg = /(`{3,})[\s\S]+?\1/g;
|
|
|
9
9
|
const inlineCodeblockReg = /`[^\n`]+?`/g;
|
|
10
10
|
const latexBlockReg = /(\${2,})[\s\S]+?\1/g;
|
|
11
11
|
const scriptSetupReg = /\\<[\s\S]+?>\n?/g;
|
|
12
|
-
const sfcBlockReg = /<(script|style)\b[\s\S]*?>([\s\S]*?)<\/\1>/g;
|
|
13
12
|
const angleBracketReg = /<\S*:\S*>/g;
|
|
14
13
|
const linkReg = /\[[\s\S]*?\]\([\s\S]*?\)/g;
|
|
14
|
+
const sfcBlockReg = /<(script|style)\b[\s\S]*?>([\s\S]*?)<\/\1>/g;
|
|
15
15
|
const codeSnippetImportReg = /^\s*<<<\s*.+/gm;
|
|
16
16
|
const plugin = ({ vueCompilerOptions }) => {
|
|
17
17
|
return {
|
|
@@ -40,42 +40,35 @@ const plugin = ({ vueCompilerOptions }) => {
|
|
|
40
40
|
// # \<script setup>
|
|
41
41
|
.replace(scriptSetupReg, match => ' '.repeat(match.length))
|
|
42
42
|
// <<< https://vitepress.dev/guide/markdown#import-code-snippets
|
|
43
|
-
.replace(codeSnippetImportReg, match => ' '.repeat(match.length))
|
|
44
|
-
const codes = [];
|
|
45
|
-
for (const match of content.matchAll(sfcBlockReg)) {
|
|
46
|
-
if (match.index !== undefined) {
|
|
47
|
-
const matchText = match[0];
|
|
48
|
-
codes.push([matchText, undefined, match.index]);
|
|
49
|
-
codes.push('\n\n');
|
|
50
|
-
content = content.slice(0, match.index) + ' '.repeat(matchText.length)
|
|
51
|
-
+ content.slice(match.index + matchText.length);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
content = content
|
|
43
|
+
.replace(codeSnippetImportReg, match => ' '.repeat(match.length))
|
|
55
44
|
// angle bracket: <http://foo.com>
|
|
56
45
|
.replace(angleBracketReg, match => ' '.repeat(match.length))
|
|
57
46
|
// [foo](http://foo.com)
|
|
58
47
|
.replace(linkReg, match => ' '.repeat(match.length));
|
|
48
|
+
const codes = [];
|
|
49
|
+
for (const match of content.matchAll(sfcBlockReg)) {
|
|
50
|
+
const matchText = match[0];
|
|
51
|
+
codes.push([matchText, undefined, match.index]);
|
|
52
|
+
codes.push('\n\n');
|
|
53
|
+
content = content.slice(0, match.index) + ' '.repeat(matchText.length)
|
|
54
|
+
+ content.slice(match.index + matchText.length);
|
|
55
|
+
}
|
|
59
56
|
codes.push('<template>\n');
|
|
60
57
|
codes.push([content, undefined, 0]);
|
|
61
58
|
codes.push('\n</template>');
|
|
62
|
-
const
|
|
59
|
+
const mappings = (0, buildMappings_1.buildMappings)(codes);
|
|
60
|
+
const mapper = new language_core_1.SourceMap(mappings);
|
|
63
61
|
const sfc = (0, parseSfc_1.parse)((0, muggle_string_1.toString)(codes));
|
|
64
|
-
|
|
65
|
-
sfc.descriptor.template
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
for (const style of sfc.descriptor.styles) {
|
|
75
|
-
transformRange(style);
|
|
76
|
-
}
|
|
77
|
-
for (const customBlock of sfc.descriptor.customBlocks) {
|
|
78
|
-
transformRange(customBlock);
|
|
62
|
+
for (const block of [
|
|
63
|
+
sfc.descriptor.template,
|
|
64
|
+
sfc.descriptor.script,
|
|
65
|
+
sfc.descriptor.scriptSetup,
|
|
66
|
+
...sfc.descriptor.styles,
|
|
67
|
+
...sfc.descriptor.customBlocks,
|
|
68
|
+
]) {
|
|
69
|
+
if (block) {
|
|
70
|
+
transformRange(block);
|
|
71
|
+
}
|
|
79
72
|
}
|
|
80
73
|
return sfc;
|
|
81
74
|
function transformRange(block) {
|
|
@@ -84,11 +77,11 @@ const plugin = ({ vueCompilerOptions }) => {
|
|
|
84
77
|
const endOffset = end.offset;
|
|
85
78
|
start.offset = -1;
|
|
86
79
|
end.offset = -1;
|
|
87
|
-
for (const [offset] of
|
|
80
|
+
for (const [offset] of mapper.toSourceLocation(startOffset)) {
|
|
88
81
|
start.offset = offset;
|
|
89
82
|
break;
|
|
90
83
|
}
|
|
91
|
-
for (const [offset] of
|
|
84
|
+
for (const [offset] of mapper.toSourceLocation(endOffset)) {
|
|
92
85
|
end.offset = offset;
|
|
93
86
|
break;
|
|
94
87
|
}
|
package/lib/plugins/vue-tsx.js
CHANGED
|
@@ -14,7 +14,6 @@ const ts_1 = require("../utils/ts");
|
|
|
14
14
|
exports.tsCodegen = new WeakMap();
|
|
15
15
|
const validLangs = new Set(['js', 'jsx', 'ts', 'tsx']);
|
|
16
16
|
const plugin = ctx => {
|
|
17
|
-
let appendedGlobalTypes = false;
|
|
18
17
|
return {
|
|
19
18
|
version: 2.1,
|
|
20
19
|
requiredCompilerOptions: [
|
|
@@ -40,18 +39,13 @@ const plugin = ctx => {
|
|
|
40
39
|
};
|
|
41
40
|
function useCodegen(fileName, sfc) {
|
|
42
41
|
if (!exports.tsCodegen.has(sfc)) {
|
|
43
|
-
|
|
44
|
-
if (!ctx.vueCompilerOptions.__setupedGlobalTypes && !appendedGlobalTypes) {
|
|
45
|
-
appendGlobalTypes = true;
|
|
46
|
-
appendedGlobalTypes = true;
|
|
47
|
-
}
|
|
48
|
-
exports.tsCodegen.set(sfc, createTsx(fileName, sfc, ctx, appendGlobalTypes));
|
|
42
|
+
exports.tsCodegen.set(sfc, createTsx(fileName, sfc, ctx));
|
|
49
43
|
}
|
|
50
44
|
return exports.tsCodegen.get(sfc);
|
|
51
45
|
}
|
|
52
46
|
};
|
|
53
47
|
exports.default = plugin;
|
|
54
|
-
function createTsx(fileName, sfc, ctx
|
|
48
|
+
function createTsx(fileName, sfc, ctx) {
|
|
55
49
|
const ts = ctx.modules.typescript;
|
|
56
50
|
const getRawLang = (0, alien_signals_1.computed)(() => {
|
|
57
51
|
if (sfc.script && sfc.scriptSetup) {
|
|
@@ -191,7 +185,6 @@ function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
|
|
|
191
185
|
templateCodegen: getGeneratedTemplate(),
|
|
192
186
|
destructuredPropNames: getSetupDestructuredPropNames(),
|
|
193
187
|
templateRefNames: getSetupTemplateRefNames(),
|
|
194
|
-
appendGlobalTypes,
|
|
195
188
|
});
|
|
196
189
|
let current = codegen.next();
|
|
197
190
|
while (!current.done) {
|
package/lib/types.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export type Code = Segment<VueCodeInformation>;
|
|
|
19
19
|
export interface VueCompilerOptions {
|
|
20
20
|
target: number;
|
|
21
21
|
lib: string;
|
|
22
|
+
globalTypesPath?: string;
|
|
22
23
|
extensions: string[];
|
|
23
24
|
vitePressExtensions: string[];
|
|
24
25
|
petiteVueExtensions: string[];
|
|
@@ -61,9 +62,6 @@ export interface VueCompilerOptions {
|
|
|
61
62
|
};
|
|
62
63
|
plugins: VueLanguagePlugin[];
|
|
63
64
|
experimentalModelPropName: Record<string, Record<string, boolean | Record<string, string> | Record<string, string>[]>>;
|
|
64
|
-
__setupedGlobalTypes?: true | {
|
|
65
|
-
absolutePath: string;
|
|
66
|
-
};
|
|
67
65
|
}
|
|
68
66
|
export declare const validVersions: readonly [2, 2.1];
|
|
69
67
|
export type VueLanguagePluginReturn = {
|
package/lib/utils/ts.d.ts
CHANGED
|
@@ -5,18 +5,17 @@ export type ParsedCommandLine = ts.ParsedCommandLine & {
|
|
|
5
5
|
};
|
|
6
6
|
export declare function createParsedCommandLineByJson(ts: typeof import('typescript'), parseConfigHost: ts.ParseConfigHost & {
|
|
7
7
|
writeFile?(path: string, data: string): void;
|
|
8
|
-
}, rootDir: string, json: any, configFileName?: string
|
|
9
|
-
export declare function createParsedCommandLine(ts: typeof import('typescript'), parseConfigHost: ts.ParseConfigHost, tsConfigPath: string
|
|
8
|
+
}, rootDir: string, json: any, configFileName?: string): ParsedCommandLine;
|
|
9
|
+
export declare function createParsedCommandLine(ts: typeof import('typescript'), parseConfigHost: ts.ParseConfigHost, tsConfigPath: string): ParsedCommandLine;
|
|
10
10
|
export declare class CompilerOptionsResolver {
|
|
11
|
+
fileExists?: ((path: string) => boolean) | undefined;
|
|
12
|
+
configRoots: Set<string>;
|
|
11
13
|
options: Omit<RawVueCompilerOptions, 'target' | 'plugin'>;
|
|
12
|
-
fallbackTarget: number | undefined;
|
|
13
14
|
target: number | undefined;
|
|
15
|
+
globalTypesPath: string | undefined;
|
|
14
16
|
plugins: VueLanguagePlugin[];
|
|
17
|
+
constructor(fileExists?: ((path: string) => boolean) | undefined);
|
|
15
18
|
addConfig(options: RawVueCompilerOptions, rootDir: string): void;
|
|
16
19
|
build(defaults?: VueCompilerOptions): VueCompilerOptions;
|
|
17
20
|
}
|
|
18
21
|
export declare function getDefaultCompilerOptions(target?: number, lib?: string, strictTemplates?: boolean): VueCompilerOptions;
|
|
19
|
-
export declare function setupGlobalTypes(rootDir: string, vueOptions: VueCompilerOptions, host: {
|
|
20
|
-
fileExists(path: string): boolean;
|
|
21
|
-
writeFile?(path: string, data: string): void;
|
|
22
|
-
}): VueCompilerOptions['__setupedGlobalTypes'];
|
package/lib/utils/ts.js
CHANGED
|
@@ -4,16 +4,15 @@ exports.CompilerOptionsResolver = void 0;
|
|
|
4
4
|
exports.createParsedCommandLineByJson = createParsedCommandLineByJson;
|
|
5
5
|
exports.createParsedCommandLine = createParsedCommandLine;
|
|
6
6
|
exports.getDefaultCompilerOptions = getDefaultCompilerOptions;
|
|
7
|
-
exports.setupGlobalTypes = setupGlobalTypes;
|
|
8
7
|
const shared_1 = require("@vue/shared");
|
|
9
8
|
const path_browserify_1 = require("path-browserify");
|
|
10
9
|
const globalTypes_1 = require("../codegen/globalTypes");
|
|
11
10
|
const languagePlugin_1 = require("../languagePlugin");
|
|
12
11
|
const shared_2 = require("./shared");
|
|
13
|
-
function createParsedCommandLineByJson(ts, parseConfigHost, rootDir, json, configFileName = rootDir + '/jsconfig.json'
|
|
12
|
+
function createParsedCommandLineByJson(ts, parseConfigHost, rootDir, json, configFileName = rootDir + '/jsconfig.json') {
|
|
14
13
|
const proxyHost = proxyParseConfigHostForExtendConfigPaths(parseConfigHost);
|
|
15
14
|
ts.parseJsonConfigFileContent(json, proxyHost.host, rootDir, {}, configFileName);
|
|
16
|
-
const resolver = new CompilerOptionsResolver();
|
|
15
|
+
const resolver = new CompilerOptionsResolver(parseConfigHost.fileExists);
|
|
17
16
|
for (const extendPath of proxyHost.extendConfigPaths.reverse()) {
|
|
18
17
|
try {
|
|
19
18
|
const configFile = ts.readJsonConfigFile(extendPath, proxyHost.host.readFile);
|
|
@@ -23,13 +22,9 @@ function createParsedCommandLineByJson(ts, parseConfigHost, rootDir, json, confi
|
|
|
23
22
|
}
|
|
24
23
|
catch { }
|
|
25
24
|
}
|
|
25
|
+
// ensure the rootDir is added to the config roots
|
|
26
|
+
resolver.addConfig({}, rootDir);
|
|
26
27
|
const resolvedVueOptions = resolver.build();
|
|
27
|
-
if (skipGlobalTypesSetup) {
|
|
28
|
-
resolvedVueOptions.__setupedGlobalTypes = true;
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
resolvedVueOptions.__setupedGlobalTypes = setupGlobalTypes(rootDir, resolvedVueOptions, parseConfigHost);
|
|
32
|
-
}
|
|
33
28
|
const parsed = ts.parseJsonConfigFileContent(json, proxyHost.host, rootDir, {}, configFileName, undefined, (0, languagePlugin_1.getAllExtensions)(resolvedVueOptions)
|
|
34
29
|
.map(extension => ({
|
|
35
30
|
extension: extension.slice(1),
|
|
@@ -45,12 +40,13 @@ function createParsedCommandLineByJson(ts, parseConfigHost, rootDir, json, confi
|
|
|
45
40
|
vueOptions: resolvedVueOptions,
|
|
46
41
|
};
|
|
47
42
|
}
|
|
48
|
-
function createParsedCommandLine(ts, parseConfigHost, tsConfigPath
|
|
43
|
+
function createParsedCommandLine(ts, parseConfigHost, tsConfigPath) {
|
|
49
44
|
try {
|
|
45
|
+
const rootDir = path_browserify_1.posix.dirname(tsConfigPath);
|
|
50
46
|
const proxyHost = proxyParseConfigHostForExtendConfigPaths(parseConfigHost);
|
|
51
47
|
const config = ts.readJsonConfigFile(tsConfigPath, proxyHost.host.readFile);
|
|
52
|
-
ts.parseJsonSourceFileConfigFileContent(config, proxyHost.host,
|
|
53
|
-
const resolver = new CompilerOptionsResolver();
|
|
48
|
+
ts.parseJsonSourceFileConfigFileContent(config, proxyHost.host, rootDir, {}, tsConfigPath);
|
|
49
|
+
const resolver = new CompilerOptionsResolver(parseConfigHost.fileExists);
|
|
54
50
|
for (const extendPath of proxyHost.extendConfigPaths.reverse()) {
|
|
55
51
|
try {
|
|
56
52
|
const configFile = ts.readJsonConfigFile(extendPath, proxyHost.host.readFile);
|
|
@@ -61,12 +57,6 @@ function createParsedCommandLine(ts, parseConfigHost, tsConfigPath, skipGlobalTy
|
|
|
61
57
|
catch { }
|
|
62
58
|
}
|
|
63
59
|
const resolvedVueOptions = resolver.build();
|
|
64
|
-
if (skipGlobalTypesSetup) {
|
|
65
|
-
resolvedVueOptions.__setupedGlobalTypes = true;
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
resolvedVueOptions.__setupedGlobalTypes = setupGlobalTypes(path_browserify_1.posix.dirname(tsConfigPath), resolvedVueOptions, parseConfigHost);
|
|
69
|
-
}
|
|
70
60
|
const parsed = ts.parseJsonSourceFileConfigFileContent(config, proxyHost.host, path_browserify_1.posix.dirname(tsConfigPath), {}, tsConfigPath, undefined, (0, languagePlugin_1.getAllExtensions)(resolvedVueOptions)
|
|
71
61
|
.map(extension => ({
|
|
72
62
|
extension: extension.slice(1),
|
|
@@ -113,20 +103,27 @@ function proxyParseConfigHostForExtendConfigPaths(parseConfigHost) {
|
|
|
113
103
|
};
|
|
114
104
|
}
|
|
115
105
|
class CompilerOptionsResolver {
|
|
116
|
-
constructor() {
|
|
106
|
+
constructor(fileExists) {
|
|
107
|
+
this.fileExists = fileExists;
|
|
108
|
+
this.configRoots = new Set();
|
|
117
109
|
this.options = {};
|
|
118
110
|
this.plugins = [];
|
|
119
111
|
}
|
|
120
112
|
addConfig(options, rootDir) {
|
|
113
|
+
this.configRoots.add(rootDir);
|
|
121
114
|
for (const key in options) {
|
|
122
115
|
switch (key) {
|
|
123
116
|
case 'target':
|
|
124
|
-
|
|
125
|
-
if (typeof target === 'string') {
|
|
117
|
+
if (options[key] === 'auto') {
|
|
126
118
|
this.target = findVueVersion(rootDir);
|
|
127
119
|
}
|
|
128
120
|
else {
|
|
129
|
-
this.target =
|
|
121
|
+
this.target = options[key];
|
|
122
|
+
}
|
|
123
|
+
break;
|
|
124
|
+
case 'globalTypesPath':
|
|
125
|
+
if (options[key] !== undefined) {
|
|
126
|
+
this.globalTypesPath = path_browserify_1.posix.join(rootDir, options[key]);
|
|
130
127
|
}
|
|
131
128
|
break;
|
|
132
129
|
case 'plugins':
|
|
@@ -155,14 +152,13 @@ class CompilerOptionsResolver {
|
|
|
155
152
|
break;
|
|
156
153
|
}
|
|
157
154
|
}
|
|
158
|
-
if (
|
|
159
|
-
this.
|
|
155
|
+
if (options.target === undefined) {
|
|
156
|
+
this.target ??= findVueVersion(rootDir);
|
|
160
157
|
}
|
|
161
158
|
}
|
|
162
159
|
build(defaults) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
return {
|
|
160
|
+
defaults ??= getDefaultCompilerOptions(this.target, this.options.lib, this.options.strictTemplates);
|
|
161
|
+
const resolvedOptions = {
|
|
166
162
|
...defaults,
|
|
167
163
|
...this.options,
|
|
168
164
|
plugins: this.plugins,
|
|
@@ -182,6 +178,24 @@ class CompilerOptionsResolver {
|
|
|
182
178
|
// https://vuejs.org/guide/essentials/forms.html#form-input-bindings
|
|
183
179
|
experimentalModelPropName: Object.fromEntries(Object.entries(this.options.experimentalModelPropName ?? defaults.experimentalModelPropName).map(([k, v]) => [(0, shared_1.camelize)(k), v])),
|
|
184
180
|
};
|
|
181
|
+
if (this.fileExists && this.globalTypesPath === undefined) {
|
|
182
|
+
root: for (const rootDir of [...this.configRoots].reverse()) {
|
|
183
|
+
let dir = rootDir;
|
|
184
|
+
while (!this.fileExists(path_browserify_1.posix.join(dir, 'node_modules', resolvedOptions.lib, 'package.json'))) {
|
|
185
|
+
const parentDir = path_browserify_1.posix.dirname(dir);
|
|
186
|
+
if (dir === parentDir) {
|
|
187
|
+
continue root;
|
|
188
|
+
}
|
|
189
|
+
dir = parentDir;
|
|
190
|
+
}
|
|
191
|
+
resolvedOptions.globalTypesPath = path_browserify_1.posix.join(dir, 'node_modules', '.vue-global-types', (0, globalTypes_1.getGlobalTypesFileName)(resolvedOptions));
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
resolvedOptions.globalTypesPath = this.globalTypesPath;
|
|
197
|
+
}
|
|
198
|
+
return resolvedOptions;
|
|
185
199
|
}
|
|
186
200
|
}
|
|
187
201
|
exports.CompilerOptionsResolver = CompilerOptionsResolver;
|
|
@@ -273,24 +287,4 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
|
|
|
273
287
|
},
|
|
274
288
|
};
|
|
275
289
|
}
|
|
276
|
-
function setupGlobalTypes(rootDir, vueOptions, host) {
|
|
277
|
-
if (!host.writeFile) {
|
|
278
|
-
return;
|
|
279
|
-
}
|
|
280
|
-
try {
|
|
281
|
-
let dir = rootDir;
|
|
282
|
-
while (!host.fileExists(path_browserify_1.posix.join(dir, 'node_modules', vueOptions.lib, 'package.json'))) {
|
|
283
|
-
const parentDir = path_browserify_1.posix.dirname(dir);
|
|
284
|
-
if (dir === parentDir) {
|
|
285
|
-
throw 0;
|
|
286
|
-
}
|
|
287
|
-
dir = parentDir;
|
|
288
|
-
}
|
|
289
|
-
const globalTypesPath = path_browserify_1.posix.join(dir, 'node_modules', '.vue-global-types', (0, globalTypes_1.getGlobalTypesFileName)(vueOptions));
|
|
290
|
-
const globalTypesContents = `// @ts-nocheck\nexport {};\n` + (0, globalTypes_1.generateGlobalTypes)(vueOptions);
|
|
291
|
-
host.writeFile(globalTypesPath, globalTypesContents);
|
|
292
|
-
return { absolutePath: globalTypesPath };
|
|
293
|
-
}
|
|
294
|
-
catch { }
|
|
295
|
-
}
|
|
296
290
|
//# sourceMappingURL=ts.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/language-core",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -13,19 +13,20 @@
|
|
|
13
13
|
"directory": "packages/language-core"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@volar/language-core": "2.4.
|
|
16
|
+
"@volar/language-core": "2.4.19",
|
|
17
17
|
"@vue/compiler-dom": "^3.5.0",
|
|
18
18
|
"@vue/compiler-vue2": "^2.7.16",
|
|
19
19
|
"@vue/shared": "^3.5.0",
|
|
20
20
|
"alien-signals": "^2.0.5",
|
|
21
|
-
"minimatch": "^10.0.1",
|
|
22
21
|
"muggle-string": "^0.4.1",
|
|
23
|
-
"path-browserify": "^1.0.1"
|
|
22
|
+
"path-browserify": "^1.0.1",
|
|
23
|
+
"picomatch": "^4.0.2"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/node": "^22.10.4",
|
|
27
27
|
"@types/path-browserify": "^1.0.1",
|
|
28
|
-
"@
|
|
28
|
+
"@types/picomatch": "^4.0.0",
|
|
29
|
+
"@volar/typescript": "2.4.19",
|
|
29
30
|
"@vue/compiler-sfc": "^3.5.0"
|
|
30
31
|
},
|
|
31
32
|
"peerDependencies": {
|
|
@@ -36,5 +37,5 @@
|
|
|
36
37
|
"optional": true
|
|
37
38
|
}
|
|
38
39
|
},
|
|
39
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "7343119e9ca4f6a54f63b57f448f15df4b592a9a"
|
|
40
41
|
}
|