@vue/language-core 3.1.0 → 3.1.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/script/component.js +7 -6
- package/lib/codegen/script/index.js +11 -12
- package/lib/codegen/script/scriptSetup.js +1 -1
- package/lib/codegen/script/template.js +14 -8
- package/lib/codegen/template/element.js +15 -14
- package/lib/codegen/template/templateChild.js +2 -0
- package/lib/codegen/utils/index.d.ts +1 -1
- package/lib/compilerOptions.d.ts +4 -0
- package/lib/compilerOptions.js +9 -2
- package/lib/parsers/scriptRanges.d.ts +9 -6
- package/lib/parsers/scriptRanges.js +16 -11
- package/lib/plugins/file-md.js +8 -7
- package/lib/plugins/vue-tsx.d.ts +9 -6
- package/lib/plugins/vue-tsx.js +4 -4
- package/package.json +2 -2
|
@@ -5,10 +5,11 @@ const codeFeatures_1 = require("../codeFeatures");
|
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
6
|
const merge_1 = require("../utils/merge");
|
|
7
7
|
function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
8
|
-
if (options.sfc.script
|
|
9
|
-
&& options.scriptRanges
|
|
8
|
+
if (options.sfc.script
|
|
9
|
+
&& options.scriptRanges?.componentOptions
|
|
10
|
+
&& options.scriptRanges.componentOptions.expression.start !== options.scriptRanges.componentOptions.args.start) {
|
|
10
11
|
// use defineComponent() from user space code if it exist
|
|
11
|
-
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, options.scriptRanges.
|
|
12
|
+
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, options.scriptRanges.componentOptions.expression.start, options.scriptRanges.componentOptions.args.start, codeFeatures_1.codeFeatures.all);
|
|
12
13
|
yield `{${utils_1.newLine}`;
|
|
13
14
|
}
|
|
14
15
|
else {
|
|
@@ -50,8 +51,8 @@ function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
50
51
|
&& options.templateCodegen?.singleRootElTypes.length) {
|
|
51
52
|
yield `__typeEl: {} as __VLS_RootEl,${utils_1.newLine}`;
|
|
52
53
|
}
|
|
53
|
-
if (options.sfc.script && options.scriptRanges?.
|
|
54
|
-
const { args } = options.scriptRanges.
|
|
54
|
+
if (options.sfc.script && options.scriptRanges?.componentOptions?.args) {
|
|
55
|
+
const { args } = options.scriptRanges.componentOptions;
|
|
55
56
|
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, args.start + 1, args.end - 1, codeFeatures_1.codeFeatures.all);
|
|
56
57
|
}
|
|
57
58
|
yield `})`;
|
|
@@ -90,7 +91,7 @@ function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasE
|
|
|
90
91
|
if (options.templateCodegen?.inheritedAttrVars.size) {
|
|
91
92
|
let attrsType = `__VLS_InheritedAttrs`;
|
|
92
93
|
if (hasEmitsOption) {
|
|
93
|
-
attrsType = `Omit<${attrsType},
|
|
94
|
+
attrsType = `Omit<${attrsType}, keyof __VLS_EmitProps>`;
|
|
94
95
|
}
|
|
95
96
|
getOptionCodes.push(() => {
|
|
96
97
|
const propsType = `__VLS_PickNotAny<${ctx.localTypes.OmitIndexSignature}<${attrsType}>, {}>`;
|
|
@@ -24,7 +24,7 @@ function* generateScript(options, ctx) {
|
|
|
24
24
|
yield* (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges);
|
|
25
25
|
}
|
|
26
26
|
if (options.sfc.script && options.scriptRanges) {
|
|
27
|
-
const { exportDefault } = options.scriptRanges;
|
|
27
|
+
const { exportDefault, componentOptions } = options.scriptRanges;
|
|
28
28
|
if (options.sfc.scriptSetup && options.scriptSetupRanges) {
|
|
29
29
|
if (exportDefault) {
|
|
30
30
|
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, exportDefault.start, codeFeatures_1.codeFeatures.all);
|
|
@@ -36,14 +36,15 @@ function* generateScript(options, ctx) {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
else if (exportDefault) {
|
|
39
|
+
const { expression } = componentOptions ?? exportDefault;
|
|
39
40
|
let wrapLeft;
|
|
40
41
|
let wrapRight;
|
|
41
|
-
if (options.sfc.script.content[
|
|
42
|
+
if (options.sfc.script.content[expression.start] === '{'
|
|
42
43
|
&& options.vueCompilerOptions.optionsWrapper.length) {
|
|
43
44
|
[wrapLeft, wrapRight] = options.vueCompilerOptions.optionsWrapper;
|
|
44
45
|
ctx.inlayHints.push({
|
|
45
46
|
blockName: options.sfc.script.name,
|
|
46
|
-
offset:
|
|
47
|
+
offset: expression.start,
|
|
47
48
|
setting: 'vue.inlayHints.optionsWrapper',
|
|
48
49
|
label: wrapLeft || '[Missing optionsWrapper[0]]',
|
|
49
50
|
tooltip: [
|
|
@@ -52,7 +53,7 @@ function* generateScript(options, ctx) {
|
|
|
52
53
|
].join('\n\n'),
|
|
53
54
|
}, {
|
|
54
55
|
blockName: options.sfc.script.name,
|
|
55
|
-
offset:
|
|
56
|
+
offset: expression.end,
|
|
56
57
|
setting: 'vue.inlayHints.optionsWrapper',
|
|
57
58
|
label: wrapRight || '[Missing optionsWrapper[1]]',
|
|
58
59
|
});
|
|
@@ -62,7 +63,7 @@ function* generateScript(options, ctx) {
|
|
|
62
63
|
if (wrapLeft) {
|
|
63
64
|
yield wrapLeft;
|
|
64
65
|
}
|
|
65
|
-
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script,
|
|
66
|
+
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, expression.start, expression.end, codeFeatures_1.codeFeatures.all);
|
|
66
67
|
if (wrapRight) {
|
|
67
68
|
yield wrapRight;
|
|
68
69
|
}
|
|
@@ -103,12 +104,10 @@ function* generateGlobalTypesReference(options) {
|
|
|
103
104
|
}
|
|
104
105
|
function* generateConstExport(options, block) {
|
|
105
106
|
if (options.sfc.script) {
|
|
106
|
-
yield* (0, utils_1.generatePartiallyEnding)(options.sfc.script.name, options.scriptRanges?.exportDefault
|
|
107
|
-
? options.scriptRanges.exportDefault.start
|
|
108
|
-
: options.sfc.script.content.length, '#3632/script.vue');
|
|
107
|
+
yield* (0, utils_1.generatePartiallyEnding)(options.sfc.script.name, options.scriptRanges?.exportDefault?.start ?? options.sfc.script.content.length, '#3632/script.vue');
|
|
109
108
|
}
|
|
110
109
|
yield `const `;
|
|
111
|
-
yield* (0, wrapWith_1.wrapWith)(0, block.content.length, block.name, codeFeatures_1.codeFeatures.
|
|
110
|
+
yield* (0, wrapWith_1.wrapWith)(0, block.content.length, block.name, codeFeatures_1.codeFeatures.doNotReportTs6133, `__VLS_export`);
|
|
112
111
|
yield ` = `;
|
|
113
112
|
}
|
|
114
113
|
function* generateExportDefault(options) {
|
|
@@ -119,9 +118,9 @@ function* generateExportDefault(options) {
|
|
|
119
118
|
let prefix;
|
|
120
119
|
let suffix;
|
|
121
120
|
if (options.sfc.script && options.scriptRanges?.exportDefault) {
|
|
122
|
-
const { exportDefault } = options.scriptRanges;
|
|
123
|
-
prefix = (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.start, exportDefault.expression.start, codeFeatures_1.codeFeatures.all);
|
|
124
|
-
suffix = (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.end, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
|
|
121
|
+
const { exportDefault, componentOptions } = options.scriptRanges;
|
|
122
|
+
prefix = (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.start, (componentOptions ?? exportDefault).expression.start, codeFeatures_1.codeFeatures.all);
|
|
123
|
+
suffix = (0, utils_1.generateSfcBlockSection)(options.sfc.script, (componentOptions ?? exportDefault).expression.end, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
|
|
125
124
|
}
|
|
126
125
|
else {
|
|
127
126
|
prefix = `export default `;
|
|
@@ -65,7 +65,7 @@ function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
65
65
|
emitTypes.push(`typeof __VLS_modelEmit`);
|
|
66
66
|
}
|
|
67
67
|
yield `return {} as {${utils_1.newLine}`
|
|
68
|
-
+ ` props: ${ctx.localTypes.PrettifyLocal}<${propTypes.join(` & `)}> & ${options.vueCompilerOptions.target >= 3.4
|
|
68
|
+
+ ` props: ${propTypes.length ? `${ctx.localTypes.PrettifyLocal}<${propTypes.join(` & `)}> & ` : ``}${options.vueCompilerOptions.target >= 3.4
|
|
69
69
|
? `import('${options.vueCompilerOptions.lib}').PublicProps`
|
|
70
70
|
: options.vueCompilerOptions.target >= 3
|
|
71
71
|
? `import('${options.vueCompilerOptions.lib}').VNodeProps`
|
|
@@ -21,12 +21,18 @@ function* generateTemplate(options, ctx) {
|
|
|
21
21
|
yield* generateTemplateBody(options, ctx);
|
|
22
22
|
}
|
|
23
23
|
function* generateSelf(options) {
|
|
24
|
-
if (options.sfc.script && options.scriptRanges?.
|
|
24
|
+
if (options.sfc.script && options.scriptRanges?.componentOptions) {
|
|
25
25
|
yield `const __VLS_self = (await import('${options.vueCompilerOptions.lib}')).defineComponent(`;
|
|
26
|
-
const { args } = options.scriptRanges.
|
|
26
|
+
const { args } = options.scriptRanges.componentOptions;
|
|
27
27
|
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, args.start, args.end, codeFeatures_1.codeFeatures.all);
|
|
28
28
|
yield `)${utils_1.endOfLine}`;
|
|
29
29
|
}
|
|
30
|
+
else if (options.sfc.script && options.scriptRanges?.exportDefault) {
|
|
31
|
+
yield `const __VLS_self = `;
|
|
32
|
+
const { expression } = options.scriptRanges.exportDefault;
|
|
33
|
+
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, expression.start, expression.end, codeFeatures_1.codeFeatures.all);
|
|
34
|
+
yield utils_1.endOfLine;
|
|
35
|
+
}
|
|
30
36
|
else if (options.sfc.script?.src) {
|
|
31
37
|
yield `let __VLS_self!: typeof import('./${path.basename(options.fileName)}').default${utils_1.endOfLine}`;
|
|
32
38
|
}
|
|
@@ -92,10 +98,10 @@ function* generateTemplateElements() {
|
|
|
92
98
|
}
|
|
93
99
|
function* generateTemplateComponents(options) {
|
|
94
100
|
const types = [`typeof __VLS_ctx`];
|
|
95
|
-
if (options.sfc.script && options.scriptRanges?.
|
|
96
|
-
const {
|
|
101
|
+
if (options.sfc.script && options.scriptRanges?.componentOptions?.components) {
|
|
102
|
+
const { components } = options.scriptRanges.componentOptions;
|
|
97
103
|
yield `const __VLS_componentsOption = `;
|
|
98
|
-
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script,
|
|
104
|
+
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, components.start, components.end, codeFeatures_1.codeFeatures.navigation);
|
|
99
105
|
yield utils_1.endOfLine;
|
|
100
106
|
types.push(`typeof __VLS_componentsOption`);
|
|
101
107
|
}
|
|
@@ -104,10 +110,10 @@ function* generateTemplateComponents(options) {
|
|
|
104
110
|
}
|
|
105
111
|
function* generateTemplateDirectives(options) {
|
|
106
112
|
const types = [`typeof __VLS_ctx`];
|
|
107
|
-
if (options.sfc.script && options.scriptRanges?.
|
|
108
|
-
const {
|
|
113
|
+
if (options.sfc.script && options.scriptRanges?.componentOptions?.directives) {
|
|
114
|
+
const { directives } = options.scriptRanges.componentOptions;
|
|
109
115
|
yield `const __VLS_directivesOption = `;
|
|
110
|
-
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script,
|
|
116
|
+
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, directives.start, directives.end, codeFeatures_1.codeFeatures.navigation);
|
|
111
117
|
yield utils_1.endOfLine;
|
|
112
118
|
types.push(`__VLS_ResolveDirectives<typeof __VLS_directivesOption>`);
|
|
113
119
|
}
|
|
@@ -146,11 +146,11 @@ function* generateComponent(options, ctx, node) {
|
|
|
146
146
|
yield* generateFailedPropExps(options, ctx, failedPropExps);
|
|
147
147
|
yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, componentOriginalVar, componentFunctionalVar, componentVNodeVar, componentCtxVar);
|
|
148
148
|
yield* (0, elementDirectives_1.generateElementDirectives)(options, ctx, node);
|
|
149
|
-
const
|
|
149
|
+
const reference = yield* generateElementReference(options, ctx, node);
|
|
150
150
|
const tag = (0, shared_2.hyphenateTag)(node.tag);
|
|
151
151
|
const isRootNode = ctx.singleRootNodes.has(node)
|
|
152
152
|
&& !options.vueCompilerOptions.fallthroughComponentNames.includes(tag);
|
|
153
|
-
if (
|
|
153
|
+
if (reference || isRootNode) {
|
|
154
154
|
const componentInstanceVar = ctx.getInternalVariable();
|
|
155
155
|
ctx.currentComponent.used = true;
|
|
156
156
|
yield `var ${componentInstanceVar} = {} as (Parameters<NonNullable<typeof ${componentCtxVar}['expose']>>[0] | null)`;
|
|
@@ -158,8 +158,9 @@ function* generateComponent(options, ctx, node) {
|
|
|
158
158
|
yield `[]`;
|
|
159
159
|
}
|
|
160
160
|
yield utils_1.endOfLine;
|
|
161
|
-
if (
|
|
162
|
-
|
|
161
|
+
if (reference) {
|
|
162
|
+
const typeExp = `typeof ${ctx.getHoistVariable(componentInstanceVar)}`;
|
|
163
|
+
ctx.addTemplateRef(reference.name, typeExp, reference.offset);
|
|
163
164
|
}
|
|
164
165
|
if (isRootNode) {
|
|
165
166
|
ctx.singleRootElTypes.push(`NonNullable<typeof ${componentInstanceVar}>['$el']`);
|
|
@@ -167,7 +168,8 @@ function* generateComponent(options, ctx, node) {
|
|
|
167
168
|
}
|
|
168
169
|
if (hasVBindAttrs(options, ctx, node)) {
|
|
169
170
|
const attrsVar = ctx.getInternalVariable();
|
|
170
|
-
|
|
171
|
+
ctx.currentComponent.used = true;
|
|
172
|
+
yield `var ${attrsVar}!: NonNullable<typeof ${componentCtxVar}['props']>${utils_1.endOfLine}`;
|
|
171
173
|
ctx.inheritedAttrVars.add(attrsVar);
|
|
172
174
|
}
|
|
173
175
|
(0, styleScopedClasses_1.collectStyleScopedClassReferences)(options, ctx, node);
|
|
@@ -191,13 +193,13 @@ function* generateElement(options, ctx, node) {
|
|
|
191
193
|
yield `)${utils_1.endOfLine}`;
|
|
192
194
|
yield* generateFailedPropExps(options, ctx, failedPropExps);
|
|
193
195
|
yield* (0, elementDirectives_1.generateElementDirectives)(options, ctx, node);
|
|
194
|
-
const
|
|
195
|
-
if (
|
|
196
|
+
const reference = yield* generateElementReference(options, ctx, node);
|
|
197
|
+
if (reference) {
|
|
196
198
|
let typeExp = `__VLS_NativeElements['${node.tag}']`;
|
|
197
199
|
if (ctx.inVFor) {
|
|
198
200
|
typeExp += `[]`;
|
|
199
201
|
}
|
|
200
|
-
ctx.addTemplateRef(
|
|
202
|
+
ctx.addTemplateRef(reference.name, typeExp, reference.offset);
|
|
201
203
|
}
|
|
202
204
|
if (ctx.singleRootNodes.has(node)) {
|
|
203
205
|
ctx.singleRootElTypes.push(`__VLS_NativeElements['${node.tag}']`);
|
|
@@ -259,18 +261,17 @@ function* generateElementReference(options, ctx, node) {
|
|
|
259
261
|
if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE
|
|
260
262
|
&& prop.name === 'ref'
|
|
261
263
|
&& prop.value) {
|
|
262
|
-
const [
|
|
264
|
+
const [name, offset] = (0, utils_1.normalizeAttributeValue)(prop.value);
|
|
263
265
|
// navigation support for `const foo = ref()`
|
|
264
266
|
yield `/** @type {typeof __VLS_ctx`;
|
|
265
|
-
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx,
|
|
267
|
+
yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, name, offset, codeFeatures_1.codeFeatures.navigation);
|
|
266
268
|
yield `} */${utils_1.endOfLine}`;
|
|
267
|
-
if (utils_1.identifierRegex.test(
|
|
268
|
-
ctx.accessExternalVariable(
|
|
269
|
+
if (utils_1.identifierRegex.test(name) && !options.templateRefNames.has(name)) {
|
|
270
|
+
ctx.accessExternalVariable(name, offset);
|
|
269
271
|
}
|
|
270
|
-
return
|
|
272
|
+
return { name, offset };
|
|
271
273
|
}
|
|
272
274
|
}
|
|
273
|
-
return [];
|
|
274
275
|
}
|
|
275
276
|
function hasVBindAttrs(options, ctx, node) {
|
|
276
277
|
return options.vueCompilerOptions.fallthroughAttributes && ((options.inheritAttrs && ctx.singleRootNodes.has(node))
|
|
@@ -102,6 +102,8 @@ function* generateTemplateChild(options, ctx, node, enterNode = true) {
|
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
function* collectSingleRootNodes(options, children) {
|
|
105
|
+
// Exclude the effect of comments on the root node
|
|
106
|
+
children = children.filter(node => node.type !== CompilerDOM.NodeTypes.COMMENT);
|
|
105
107
|
if (children.length !== 1) {
|
|
106
108
|
// "null" is used to determine whether the component is not always has a single root
|
|
107
109
|
if (children.length > 1) {
|
|
@@ -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 normalizeAttributeValue(node: CompilerDOM.TextNode): [string, number];
|
|
8
|
+
export declare function normalizeAttributeValue(node: CompilerDOM.TextNode): readonly [string, number];
|
|
9
9
|
export declare function createTsAst(ts: typeof import('typescript'), inlineTsAsts: Map<string, ts.SourceFile> | undefined, text: string): ts.SourceFile;
|
|
10
10
|
export declare function generateSfcBlockSection(block: SfcBlock, start: number, end: number, features: VueCodeInformation): Code;
|
|
11
11
|
export declare function generatePartiallyEnding(source: string, end: number, mark: string, delimiter?: string): Generator<Code>;
|
package/lib/compilerOptions.d.ts
CHANGED
|
@@ -19,5 +19,9 @@ export declare class CompilerOptionsResolver {
|
|
|
19
19
|
private findNodeModulesRoot;
|
|
20
20
|
}
|
|
21
21
|
export declare function getDefaultCompilerOptions(target?: number, lib?: string, strictTemplates?: boolean): VueCompilerOptions;
|
|
22
|
+
export declare function createGlobalTypesWriter(vueOptions: VueCompilerOptions, writeFile: (fileName: string, data: string) => void): (fileName: string) => string | void;
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated use `createGlobalTypesWriter` instead
|
|
25
|
+
*/
|
|
22
26
|
export declare function writeGlobalTypes(vueOptions: VueCompilerOptions, writeFile: (fileName: string, data: string) => void): void;
|
|
23
27
|
export {};
|
package/lib/compilerOptions.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.CompilerOptionsResolver = void 0;
|
|
|
4
4
|
exports.createParsedCommandLineByJson = createParsedCommandLineByJson;
|
|
5
5
|
exports.createParsedCommandLine = createParsedCommandLine;
|
|
6
6
|
exports.getDefaultCompilerOptions = getDefaultCompilerOptions;
|
|
7
|
+
exports.createGlobalTypesWriter = createGlobalTypesWriter;
|
|
7
8
|
exports.writeGlobalTypes = writeGlobalTypes;
|
|
8
9
|
const shared_1 = require("@vue/shared");
|
|
9
10
|
const path_browserify_1 = require("path-browserify");
|
|
@@ -274,10 +275,10 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
|
|
|
274
275
|
},
|
|
275
276
|
};
|
|
276
277
|
}
|
|
277
|
-
function
|
|
278
|
+
function createGlobalTypesWriter(vueOptions, writeFile) {
|
|
278
279
|
const writed = new Set();
|
|
279
280
|
const { globalTypesPath } = vueOptions;
|
|
280
|
-
|
|
281
|
+
return (fileName) => {
|
|
281
282
|
const result = globalTypesPath(fileName);
|
|
282
283
|
if (result && !writed.has(result)) {
|
|
283
284
|
writed.add(result);
|
|
@@ -286,4 +287,10 @@ function writeGlobalTypes(vueOptions, writeFile) {
|
|
|
286
287
|
return result;
|
|
287
288
|
};
|
|
288
289
|
}
|
|
290
|
+
/**
|
|
291
|
+
* @deprecated use `createGlobalTypesWriter` instead
|
|
292
|
+
*/
|
|
293
|
+
function writeGlobalTypes(vueOptions, writeFile) {
|
|
294
|
+
vueOptions.globalTypesPath = createGlobalTypesWriter(vueOptions, writeFile);
|
|
295
|
+
}
|
|
289
296
|
//# sourceMappingURL=compilerOptions.js.map
|
|
@@ -5,14 +5,17 @@ export interface ScriptRanges extends ReturnType<typeof parseScriptRanges> {
|
|
|
5
5
|
export declare function parseScriptRanges(ts: typeof import('typescript'), ast: ts.SourceFile, hasScriptSetup: boolean): {
|
|
6
6
|
exportDefault: (TextRange & {
|
|
7
7
|
expression: TextRange;
|
|
8
|
+
}) | undefined;
|
|
9
|
+
componentOptions: {
|
|
10
|
+
expression: TextRange;
|
|
8
11
|
args: TextRange;
|
|
9
12
|
argsNode: ts.ObjectLiteralExpression;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
13
|
+
components: TextRange | undefined;
|
|
14
|
+
componentsNode: ts.ObjectLiteralExpression | undefined;
|
|
15
|
+
directives: TextRange | undefined;
|
|
16
|
+
name: TextRange | undefined;
|
|
17
|
+
inheritAttrs: string | undefined;
|
|
18
|
+
} | undefined;
|
|
16
19
|
bindings: {
|
|
17
20
|
range: TextRange;
|
|
18
21
|
moduleName?: string;
|
|
@@ -5,9 +5,18 @@ const shared_1 = require("../utils/shared");
|
|
|
5
5
|
const utils_1 = require("./utils");
|
|
6
6
|
function parseScriptRanges(ts, ast, hasScriptSetup) {
|
|
7
7
|
let exportDefault;
|
|
8
|
+
let componentOptions;
|
|
8
9
|
const bindings = hasScriptSetup ? (0, utils_1.parseBindingRanges)(ts, ast) : [];
|
|
9
10
|
ts.forEachChild(ast, raw => {
|
|
10
11
|
if (ts.isExportAssignment(raw)) {
|
|
12
|
+
exportDefault = {
|
|
13
|
+
..._getStartEnd(raw),
|
|
14
|
+
expression: _getStartEnd(raw.expression),
|
|
15
|
+
};
|
|
16
|
+
const comment = (0, utils_1.getClosestMultiLineCommentRange)(ts, raw, [], ast);
|
|
17
|
+
if (comment) {
|
|
18
|
+
exportDefault.start = comment.start;
|
|
19
|
+
}
|
|
11
20
|
let node = raw;
|
|
12
21
|
while (isAsExpression(node.expression) || ts.isParenthesizedExpression(node.expression)) { // fix https://github.com/vuejs/language-tools/issues/1882
|
|
13
22
|
node = node.expression;
|
|
@@ -44,26 +53,22 @@ function parseScriptRanges(ts, ast, hasScriptSetup) {
|
|
|
44
53
|
}
|
|
45
54
|
}
|
|
46
55
|
});
|
|
47
|
-
|
|
48
|
-
..._getStartEnd(raw),
|
|
56
|
+
componentOptions = {
|
|
49
57
|
expression: _getStartEnd(node.expression),
|
|
50
58
|
args: _getStartEnd(obj),
|
|
51
59
|
argsNode: obj,
|
|
52
|
-
|
|
53
|
-
componentsOptionNode,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
inheritAttrsOption,
|
|
60
|
+
components: componentsOptionNode ? _getStartEnd(componentsOptionNode) : undefined,
|
|
61
|
+
componentsNode: componentsOptionNode,
|
|
62
|
+
directives: directivesOptionNode ? _getStartEnd(directivesOptionNode) : undefined,
|
|
63
|
+
name: nameOptionNode ? _getStartEnd(nameOptionNode) : undefined,
|
|
64
|
+
inheritAttrs: inheritAttrsOption,
|
|
57
65
|
};
|
|
58
|
-
const comment = (0, utils_1.getClosestMultiLineCommentRange)(ts, raw, [], ast);
|
|
59
|
-
if (comment) {
|
|
60
|
-
exportDefault.start = comment.start;
|
|
61
|
-
}
|
|
62
66
|
}
|
|
63
67
|
}
|
|
64
68
|
});
|
|
65
69
|
return {
|
|
66
70
|
exportDefault,
|
|
71
|
+
componentOptions,
|
|
67
72
|
bindings,
|
|
68
73
|
};
|
|
69
74
|
function _getStartEnd(node) {
|
package/lib/plugins/file-md.js
CHANGED
|
@@ -9,10 +9,10 @@ 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 codeSnippetImportReg = /^\s*<<<\s*.+/gm;
|
|
13
|
+
const sfcBlockReg = /<(script|style)\b[\s\S]*?>([\s\S]*?)<\/\1>/g;
|
|
12
14
|
const angleBracketReg = /<\S*:\S*>/g;
|
|
13
15
|
const linkReg = /\[[\s\S]*?\]\([\s\S]*?\)/g;
|
|
14
|
-
const sfcBlockReg = /<(script|style)\b[\s\S]*?>([\s\S]*?)<\/\1>/g;
|
|
15
|
-
const codeSnippetImportReg = /^\s*<<<\s*.+/gm;
|
|
16
16
|
const plugin = ({ vueCompilerOptions }) => {
|
|
17
17
|
return {
|
|
18
18
|
version: 2.2,
|
|
@@ -40,11 +40,7 @@ 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
|
-
// angle bracket: <http://foo.com>
|
|
45
|
-
.replace(angleBracketReg, match => ' '.repeat(match.length))
|
|
46
|
-
// [foo](http://foo.com)
|
|
47
|
-
.replace(linkReg, match => ' '.repeat(match.length));
|
|
43
|
+
.replace(codeSnippetImportReg, match => ' '.repeat(match.length));
|
|
48
44
|
const codes = [];
|
|
49
45
|
for (const match of content.matchAll(sfcBlockReg)) {
|
|
50
46
|
const matchText = match[0];
|
|
@@ -53,6 +49,11 @@ const plugin = ({ vueCompilerOptions }) => {
|
|
|
53
49
|
content = content.slice(0, match.index) + ' '.repeat(matchText.length)
|
|
54
50
|
+ content.slice(match.index + matchText.length);
|
|
55
51
|
}
|
|
52
|
+
content = content
|
|
53
|
+
// angle bracket: <http://foo.com>
|
|
54
|
+
.replace(angleBracketReg, match => ' '.repeat(match.length))
|
|
55
|
+
// [foo](http://foo.com)
|
|
56
|
+
.replace(linkReg, match => ' '.repeat(match.length));
|
|
56
57
|
codes.push('<template>\n');
|
|
57
58
|
codes.push([content, undefined, 0]);
|
|
58
59
|
codes.push('\n</template>');
|
package/lib/plugins/vue-tsx.d.ts
CHANGED
|
@@ -4,14 +4,17 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
4
4
|
getScriptRanges: () => {
|
|
5
5
|
exportDefault: (import("../types").TextRange & {
|
|
6
6
|
expression: import("../types").TextRange;
|
|
7
|
+
}) | undefined;
|
|
8
|
+
componentOptions: {
|
|
9
|
+
expression: import("../types").TextRange;
|
|
7
10
|
args: import("../types").TextRange;
|
|
8
11
|
argsNode: import("typescript").ObjectLiteralExpression;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
12
|
+
components: import("../types").TextRange | undefined;
|
|
13
|
+
componentsNode: import("typescript").ObjectLiteralExpression | undefined;
|
|
14
|
+
directives: import("../types").TextRange | undefined;
|
|
15
|
+
name: import("../types").TextRange | undefined;
|
|
16
|
+
inheritAttrs: string | undefined;
|
|
17
|
+
} | undefined;
|
|
15
18
|
bindings: {
|
|
16
19
|
range: import("../types").TextRange;
|
|
17
20
|
moduleName?: string;
|
package/lib/plugins/vue-tsx.js
CHANGED
|
@@ -122,14 +122,14 @@ function createTsx(fileName, sfc, ctx) {
|
|
|
122
122
|
const getSetupSlotsAssignName = (0, alien_signals_1.computed)(() => getScriptSetupRanges()?.defineSlots?.name);
|
|
123
123
|
const getSetupInheritAttrs = (0, alien_signals_1.computed)(() => {
|
|
124
124
|
const value = getScriptSetupRanges()?.defineOptions?.inheritAttrs
|
|
125
|
-
?? getScriptRanges()?.
|
|
125
|
+
?? getScriptRanges()?.componentOptions?.inheritAttrs;
|
|
126
126
|
return value !== 'false';
|
|
127
127
|
});
|
|
128
128
|
const getComponentSelfName = (0, alien_signals_1.computed)(() => {
|
|
129
129
|
let name;
|
|
130
|
-
const {
|
|
131
|
-
if (sfc.script &&
|
|
132
|
-
name = sfc.script.content.slice(
|
|
130
|
+
const { componentOptions } = getScriptRanges() ?? {};
|
|
131
|
+
if (sfc.script && componentOptions?.name) {
|
|
132
|
+
name = sfc.script.content.slice(componentOptions.name.start + 1, componentOptions.name.end - 1);
|
|
133
133
|
}
|
|
134
134
|
else {
|
|
135
135
|
const { defineOptions } = getScriptSetupRanges() ?? {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/language-core",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"optional": true
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "77db3d889305e8c02740f4c14793bff0156ccdb8"
|
|
40
40
|
}
|