@vue/language-core 2.0.13 → 2.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/lib/codegen/common.d.ts +11 -0
- package/lib/codegen/common.js +70 -0
- package/lib/codegen/script/component.d.ts +9 -0
- package/lib/codegen/script/component.js +109 -0
- package/lib/codegen/script/context.d.ts +25 -0
- package/lib/codegen/script/context.js +124 -0
- package/lib/{generators → codegen/script}/globalTypes.d.ts +1 -1
- package/lib/codegen/script/globalTypes.js +135 -0
- package/lib/codegen/script/index.d.ts +33 -0
- package/lib/codegen/script/index.js +127 -0
- package/lib/codegen/script/internalComponent.d.ts +5 -0
- package/lib/codegen/script/internalComponent.js +58 -0
- package/lib/codegen/script/scriptSetup.d.ts +6 -0
- package/lib/codegen/script/scriptSetup.js +371 -0
- package/lib/codegen/script/src.d.ts +2 -0
- package/lib/codegen/script/src.js +52 -0
- package/lib/codegen/script/template.d.ts +5 -0
- package/lib/codegen/script/template.js +196 -0
- package/lib/codegen/template/camelized.d.ts +2 -0
- package/lib/codegen/template/camelized.js +32 -0
- package/lib/codegen/template/context.d.ts +44 -0
- package/lib/codegen/template/context.js +170 -0
- package/lib/codegen/template/element.d.ts +8 -0
- package/lib/codegen/template/element.js +378 -0
- package/lib/codegen/template/elementChildren.d.ts +5 -0
- package/lib/codegen/template/elementChildren.js +26 -0
- package/lib/codegen/template/elementDirectives.d.ts +5 -0
- package/lib/codegen/template/elementDirectives.js +46 -0
- package/lib/codegen/template/elementEvents.d.ts +9 -0
- package/lib/codegen/template/elementEvents.js +157 -0
- package/lib/codegen/template/elementProps.d.ts +5 -0
- package/lib/codegen/template/elementProps.js +275 -0
- package/lib/codegen/template/index.d.ts +60 -0
- package/lib/codegen/template/index.js +130 -0
- package/lib/codegen/template/interpolation.d.ts +6 -0
- package/lib/{utils/transform.js → codegen/template/interpolation.js} +76 -46
- package/lib/codegen/template/objectProperty.d.ts +4 -0
- package/lib/codegen/template/objectProperty.js +31 -0
- package/lib/codegen/template/propertyAccess.d.ts +4 -0
- package/lib/codegen/template/propertyAccess.js +24 -0
- package/lib/codegen/template/slotOutlet.d.ts +5 -0
- package/lib/codegen/template/slotOutlet.js +72 -0
- package/lib/codegen/template/stringLiteralKey.d.ts +2 -0
- package/lib/codegen/template/stringLiteralKey.js +14 -0
- package/lib/codegen/template/templateChild.d.ts +7 -0
- package/lib/codegen/template/templateChild.js +160 -0
- package/lib/codegen/template/vFor.d.ts +12 -0
- package/lib/codegen/template/vFor.js +69 -0
- package/lib/codegen/template/vIf.d.ts +5 -0
- package/lib/codegen/template/vIf.js +53 -0
- package/lib/languageModule.d.ts +3 -4
- package/lib/languageModule.js +31 -14
- package/lib/parsers/scriptSetupRanges.d.ts +1 -0
- package/lib/parsers/scriptSetupRanges.js +6 -1
- package/lib/plugins/file-html.js +63 -66
- package/lib/plugins/file-md.js +47 -50
- package/lib/plugins/shared.d.ts +2 -0
- package/lib/plugins/shared.js +12 -0
- package/lib/plugins/vue-sfc-customblocks.js +2 -2
- package/lib/plugins/vue-sfc-scripts.js +2 -3
- package/lib/plugins/vue-sfc-styles.js +3 -3
- package/lib/plugins/vue-sfc-template.js +2 -2
- package/lib/plugins/vue-template-inline-css.js +34 -2
- package/lib/plugins/vue-template-inline-ts.js +10 -8
- package/lib/plugins/vue-tsx.d.ts +43 -5
- package/lib/plugins/vue-tsx.js +38 -28
- package/lib/plugins.d.ts +2 -1
- package/lib/plugins.js +18 -9
- package/lib/types.d.ts +3 -3
- package/lib/utils/ts.js +20 -32
- package/lib/virtualFile/computedFiles.d.ts +2 -1
- package/lib/virtualFile/computedFiles.js +41 -15
- package/lib/virtualFile/computedMappings.js +3 -3
- package/lib/virtualFile/computedSfc.js +22 -1
- package/lib/virtualFile/embeddedFile.d.ts +2 -3
- package/lib/virtualFile/embeddedFile.js +1 -2
- package/lib/virtualFile/vueFile.d.ts +3 -5
- package/lib/virtualFile/vueFile.js +6 -8
- package/package.json +3 -3
- package/lib/generators/globalTypes.js +0 -135
- package/lib/generators/inlineCss.d.ts +0 -3
- package/lib/generators/inlineCss.js +0 -37
- package/lib/generators/script.d.ts +0 -13
- package/lib/generators/script.js +0 -981
- package/lib/generators/template.d.ts +0 -19
- package/lib/generators/template.js +0 -1578
- package/lib/generators/utils.d.ts +0 -5
- package/lib/generators/utils.js +0 -54
- package/lib/utils/transform.d.ts +0 -8
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -15,7 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.tsCodegen = exports.scriptRanges = void 0;
|
|
18
|
-
__exportStar(require("./lib/
|
|
18
|
+
__exportStar(require("./lib/codegen/template"), exports);
|
|
19
19
|
__exportStar(require("./lib/languageModule"), exports);
|
|
20
20
|
__exportStar(require("./lib/parsers/scriptSetupRanges"), exports);
|
|
21
21
|
__exportStar(require("./lib/plugins"), exports);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type * as ts from 'typescript';
|
|
2
|
+
import type { Code, SfcBlock, VueCodeInformation } from '../types';
|
|
3
|
+
export declare const newLine = "\n";
|
|
4
|
+
export declare const endOfLine = ";\n";
|
|
5
|
+
export declare const combineLastMapping: VueCodeInformation;
|
|
6
|
+
export declare const variableNameRegex: RegExp;
|
|
7
|
+
export declare function conditionWrapWith(condition: boolean, startOffset: number, endOffset: number, features: VueCodeInformation, ...wrapCodes: Code[]): Generator<Code>;
|
|
8
|
+
export declare function wrapWith(startOffset: number, endOffset: number, features: VueCodeInformation, ...wrapCodes: Code[]): Generator<Code>;
|
|
9
|
+
export declare function collectVars(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile, result: string[]): void;
|
|
10
|
+
export declare function createTsAst(ts: typeof import('typescript'), astHolder: any, text: string): ts.SourceFile;
|
|
11
|
+
export declare function generateSfcBlockSection(block: SfcBlock, start: number, end: number, features: VueCodeInformation): Code;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateSfcBlockSection = exports.createTsAst = exports.collectVars = exports.wrapWith = exports.conditionWrapWith = exports.variableNameRegex = exports.combineLastMapping = exports.endOfLine = exports.newLine = void 0;
|
|
4
|
+
const scriptSetupRanges_1 = require("../parsers/scriptSetupRanges");
|
|
5
|
+
exports.newLine = '\n';
|
|
6
|
+
exports.endOfLine = `;${exports.newLine}`;
|
|
7
|
+
exports.combineLastMapping = { __combineLastMapping: true };
|
|
8
|
+
exports.variableNameRegex = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
|
|
9
|
+
function* conditionWrapWith(condition, startOffset, endOffset, features, ...wrapCodes) {
|
|
10
|
+
if (condition) {
|
|
11
|
+
yield* wrapWith(startOffset, endOffset, features, ...wrapCodes);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
for (const wrapCode of wrapCodes) {
|
|
15
|
+
yield wrapCode;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.conditionWrapWith = conditionWrapWith;
|
|
20
|
+
function* wrapWith(startOffset, endOffset, features, ...wrapCodes) {
|
|
21
|
+
yield ['', 'template', startOffset, features];
|
|
22
|
+
let offset = 1;
|
|
23
|
+
for (const wrapCode of wrapCodes) {
|
|
24
|
+
if (typeof wrapCode !== 'string') {
|
|
25
|
+
offset++;
|
|
26
|
+
}
|
|
27
|
+
yield wrapCode;
|
|
28
|
+
}
|
|
29
|
+
yield ['', 'template', endOffset, { __combineOffsetMapping: offset }];
|
|
30
|
+
}
|
|
31
|
+
exports.wrapWith = wrapWith;
|
|
32
|
+
function collectVars(ts, node, ast, result) {
|
|
33
|
+
if (ts.isIdentifier(node)) {
|
|
34
|
+
result.push((0, scriptSetupRanges_1.getNodeText)(ts, node, ast));
|
|
35
|
+
}
|
|
36
|
+
else if (ts.isObjectBindingPattern(node)) {
|
|
37
|
+
for (const el of node.elements) {
|
|
38
|
+
collectVars(ts, el.name, ast, result);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else if (ts.isArrayBindingPattern(node)) {
|
|
42
|
+
for (const el of node.elements) {
|
|
43
|
+
if (ts.isBindingElement(el)) {
|
|
44
|
+
collectVars(ts, el.name, ast, result);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
ts.forEachChild(node, node => collectVars(ts, node, ast, result));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.collectVars = collectVars;
|
|
53
|
+
function createTsAst(ts, astHolder, text) {
|
|
54
|
+
if (astHolder.__volar_ast_text !== text) {
|
|
55
|
+
astHolder.__volar_ast_text = text;
|
|
56
|
+
astHolder.__volar_ast = ts.createSourceFile('/a.ts', text, 99);
|
|
57
|
+
}
|
|
58
|
+
return astHolder.__volar_ast;
|
|
59
|
+
}
|
|
60
|
+
exports.createTsAst = createTsAst;
|
|
61
|
+
function generateSfcBlockSection(block, start, end, features) {
|
|
62
|
+
return [
|
|
63
|
+
block.content.substring(start, end),
|
|
64
|
+
block.name,
|
|
65
|
+
start,
|
|
66
|
+
features,
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
exports.generateSfcBlockSection = generateSfcBlockSection;
|
|
70
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ScriptRanges } from '../../parsers/scriptRanges';
|
|
2
|
+
import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
|
|
3
|
+
import type { Code, Sfc } from '../../types';
|
|
4
|
+
import type { ScriptCodegenContext } from './context';
|
|
5
|
+
import { ScriptCodegenOptions } from './index';
|
|
6
|
+
export declare function generateComponent(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
|
|
7
|
+
export declare function generateComponentSetupReturns(scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
|
|
8
|
+
export declare function generateScriptOptions(script: NonNullable<Sfc['script']>, scriptRanges: ScriptRanges): Generator<Code>;
|
|
9
|
+
export declare function generateScriptSetupOptions(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateScriptSetupOptions = exports.generateScriptOptions = exports.generateComponentSetupReturns = exports.generateComponent = void 0;
|
|
4
|
+
const common_1 = require("../common");
|
|
5
|
+
const index_1 = require("./index");
|
|
6
|
+
function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
7
|
+
if (options.sfc.script && options.scriptRanges?.exportDefault && options.scriptRanges.exportDefault.expression.start !== options.scriptRanges.exportDefault.args.start) {
|
|
8
|
+
// use defineComponent() from user space code if it exist
|
|
9
|
+
yield (0, common_1.generateSfcBlockSection)(options.sfc.script, options.scriptRanges.exportDefault.expression.start, options.scriptRanges.exportDefault.args.start, index_1.codeFeatures.all);
|
|
10
|
+
yield `{${common_1.newLine}`;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
yield `(await import('${options.vueCompilerOptions.lib}')).defineComponent({${common_1.newLine}`;
|
|
14
|
+
}
|
|
15
|
+
yield `setup() {${common_1.newLine}`;
|
|
16
|
+
yield `return {${common_1.newLine}`;
|
|
17
|
+
if (ctx.bypassDefineComponent) {
|
|
18
|
+
yield* generateComponentSetupReturns(scriptSetupRanges);
|
|
19
|
+
}
|
|
20
|
+
if (scriptSetupRanges.expose.define) {
|
|
21
|
+
yield `...__VLS_exposed,${common_1.newLine}`;
|
|
22
|
+
}
|
|
23
|
+
yield `}${common_1.endOfLine}`;
|
|
24
|
+
yield `},${common_1.newLine}`;
|
|
25
|
+
if (!ctx.bypassDefineComponent) {
|
|
26
|
+
yield* generateScriptSetupOptions(options, ctx, scriptSetup, scriptSetupRanges);
|
|
27
|
+
}
|
|
28
|
+
if (options.sfc.script && options.scriptRanges) {
|
|
29
|
+
yield* generateScriptOptions(options.sfc.script, options.scriptRanges);
|
|
30
|
+
}
|
|
31
|
+
yield `})`;
|
|
32
|
+
}
|
|
33
|
+
exports.generateComponent = generateComponent;
|
|
34
|
+
function* generateComponentSetupReturns(scriptSetupRanges) {
|
|
35
|
+
// fill $props
|
|
36
|
+
if (scriptSetupRanges.props.define) {
|
|
37
|
+
// NOTE: defineProps is inaccurate for $props
|
|
38
|
+
yield `$props: __VLS_makeOptional(${scriptSetupRanges.props.name ?? `__VLS_props`}),${common_1.newLine}`;
|
|
39
|
+
yield `...${scriptSetupRanges.props.name ?? `__VLS_props`},${common_1.newLine}`;
|
|
40
|
+
}
|
|
41
|
+
// fill $emit
|
|
42
|
+
if (scriptSetupRanges.emits.define) {
|
|
43
|
+
yield `$emit: ${scriptSetupRanges.emits.name ?? '__VLS_emit'},${common_1.newLine}`;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.generateComponentSetupReturns = generateComponentSetupReturns;
|
|
47
|
+
function* generateScriptOptions(script, scriptRanges) {
|
|
48
|
+
if (scriptRanges.exportDefault?.args) {
|
|
49
|
+
yield (0, common_1.generateSfcBlockSection)(script, scriptRanges.exportDefault.args.start + 1, scriptRanges.exportDefault.args.end - 1, index_1.codeFeatures.all);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.generateScriptOptions = generateScriptOptions;
|
|
53
|
+
function* generateScriptSetupOptions(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
54
|
+
const propsCodegens = [];
|
|
55
|
+
if (ctx.generatedPropsType) {
|
|
56
|
+
propsCodegens.push(function* () {
|
|
57
|
+
yield `{} as `;
|
|
58
|
+
if (scriptSetupRanges.props.withDefaults?.arg) {
|
|
59
|
+
yield `${ctx.helperTypes.WithDefaults.name}<`;
|
|
60
|
+
}
|
|
61
|
+
yield `${ctx.helperTypes.TypePropsToOption.name}<`;
|
|
62
|
+
yield `__VLS_PublicProps>`;
|
|
63
|
+
if (scriptSetupRanges.props.withDefaults?.arg) {
|
|
64
|
+
yield `, typeof __VLS_withDefaultsArg>`;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
if (scriptSetupRanges.props.define?.arg) {
|
|
69
|
+
const { arg } = scriptSetupRanges.props.define;
|
|
70
|
+
propsCodegens.push(function* () {
|
|
71
|
+
yield (0, common_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, index_1.codeFeatures.navigation);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
if (propsCodegens.length === 1) {
|
|
75
|
+
yield `props: `;
|
|
76
|
+
for (const generate of propsCodegens) {
|
|
77
|
+
yield* generate();
|
|
78
|
+
}
|
|
79
|
+
yield `,${common_1.newLine}`;
|
|
80
|
+
}
|
|
81
|
+
else if (propsCodegens.length >= 2) {
|
|
82
|
+
yield `props: {${common_1.newLine}`;
|
|
83
|
+
for (const generate of propsCodegens) {
|
|
84
|
+
yield `...`;
|
|
85
|
+
yield* generate();
|
|
86
|
+
yield `,${common_1.newLine}`;
|
|
87
|
+
}
|
|
88
|
+
yield `},${common_1.newLine}`;
|
|
89
|
+
}
|
|
90
|
+
if (scriptSetupRanges.defineProp.filter(p => p.isModel).length || scriptSetupRanges.emits.define) {
|
|
91
|
+
yield `emits: ({} as __VLS_NormalizeEmits<typeof __VLS_modelEmitsType`;
|
|
92
|
+
if (scriptSetupRanges.emits.define) {
|
|
93
|
+
yield ` & typeof `;
|
|
94
|
+
yield scriptSetupRanges.emits.name ?? '__VLS_emit';
|
|
95
|
+
}
|
|
96
|
+
yield `>),${common_1.newLine}`;
|
|
97
|
+
}
|
|
98
|
+
if (options.vueCompilerOptions.target >= 3.5) {
|
|
99
|
+
// https://github.com/vuejs/core/pull/10801
|
|
100
|
+
if (scriptSetupRanges.props.define?.typeArg) {
|
|
101
|
+
yield `__typeProps: typeof __VLS_typeProps,${common_1.newLine}`;
|
|
102
|
+
}
|
|
103
|
+
if (scriptSetupRanges.emits.define?.typeArg) {
|
|
104
|
+
yield `__typeEmits: typeof ${scriptSetupRanges.emits.name ?? '__VLS_emit'},${common_1.newLine}`;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.generateScriptSetupOptions = generateScriptSetupOptions;
|
|
109
|
+
//# sourceMappingURL=component.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ScriptCodegenOptions } from './index';
|
|
2
|
+
interface HelperType {
|
|
3
|
+
name: string;
|
|
4
|
+
used?: boolean;
|
|
5
|
+
generated?: boolean;
|
|
6
|
+
code: string;
|
|
7
|
+
}
|
|
8
|
+
export type ScriptCodegenContext = ReturnType<typeof createScriptCodegenContext>;
|
|
9
|
+
export declare function createScriptCodegenContext(options: ScriptCodegenOptions): {
|
|
10
|
+
generatedTemplate: boolean;
|
|
11
|
+
generatedPropsType: boolean;
|
|
12
|
+
scriptSetupGeneratedOffset: number | undefined;
|
|
13
|
+
bypassDefineComponent: boolean;
|
|
14
|
+
bindingNames: Set<string>;
|
|
15
|
+
helperTypes: {
|
|
16
|
+
OmitKeepDiscriminatedUnion: HelperType;
|
|
17
|
+
WithDefaults: HelperType;
|
|
18
|
+
Prettify: HelperType;
|
|
19
|
+
WithTemplateSlots: HelperType;
|
|
20
|
+
PropsChildren: HelperType;
|
|
21
|
+
TypePropsToOption: HelperType;
|
|
22
|
+
};
|
|
23
|
+
generateHelperTypes: () => Generator<string, void, unknown>;
|
|
24
|
+
};
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createScriptCodegenContext = void 0;
|
|
4
|
+
const shared_1 = require("../../utils/shared");
|
|
5
|
+
const common_1 = require("../common");
|
|
6
|
+
function createScriptCodegenContext(options) {
|
|
7
|
+
const helperTypes = {
|
|
8
|
+
OmitKeepDiscriminatedUnion: {
|
|
9
|
+
get name() {
|
|
10
|
+
this.used = true;
|
|
11
|
+
return `__VLS_OmitKeepDiscriminatedUnion`;
|
|
12
|
+
},
|
|
13
|
+
get code() {
|
|
14
|
+
return `type __VLS_OmitKeepDiscriminatedUnion<T, K extends keyof any> = T extends any
|
|
15
|
+
? Pick<T, Exclude<keyof T, K>>
|
|
16
|
+
: never;`;
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
WithDefaults: {
|
|
20
|
+
get name() {
|
|
21
|
+
this.used = true;
|
|
22
|
+
return `__VLS_WithDefaults`;
|
|
23
|
+
},
|
|
24
|
+
get code() {
|
|
25
|
+
return `type __VLS_WithDefaults<P, D> = {
|
|
26
|
+
[K in keyof Pick<P, keyof P>]: K extends keyof D
|
|
27
|
+
? ${helperTypes.Prettify.name}<P[K] & { default: D[K]}>
|
|
28
|
+
: P[K]
|
|
29
|
+
};`;
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
Prettify: {
|
|
33
|
+
get name() {
|
|
34
|
+
this.used = true;
|
|
35
|
+
return `__VLS_Prettify`;
|
|
36
|
+
},
|
|
37
|
+
get code() {
|
|
38
|
+
return `type __VLS_Prettify<T> = { [K in keyof T]: T[K]; } & {};`;
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
WithTemplateSlots: {
|
|
42
|
+
get name() {
|
|
43
|
+
this.used = true;
|
|
44
|
+
return `__VLS_WithTemplateSlots`;
|
|
45
|
+
},
|
|
46
|
+
get code() {
|
|
47
|
+
return `type __VLS_WithTemplateSlots<T, S> = T & {
|
|
48
|
+
new(): {
|
|
49
|
+
${(0, shared_1.getSlotsPropertyName)(options.vueCompilerOptions.target)}: S;
|
|
50
|
+
${options.vueCompilerOptions.jsxSlots ? `$props: ${helperTypes.PropsChildren.name}<S>;` : ''}
|
|
51
|
+
}
|
|
52
|
+
};`;
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
PropsChildren: {
|
|
56
|
+
get name() {
|
|
57
|
+
this.used = true;
|
|
58
|
+
return `__VLS_PropsChildren`;
|
|
59
|
+
},
|
|
60
|
+
get code() {
|
|
61
|
+
return `type __VLS_PropsChildren<S> = {
|
|
62
|
+
[K in keyof (
|
|
63
|
+
boolean extends (
|
|
64
|
+
// @ts-ignore
|
|
65
|
+
JSX.ElementChildrenAttribute extends never
|
|
66
|
+
? true
|
|
67
|
+
: false
|
|
68
|
+
)
|
|
69
|
+
? never
|
|
70
|
+
// @ts-ignore
|
|
71
|
+
: JSX.ElementChildrenAttribute
|
|
72
|
+
)]?: S;
|
|
73
|
+
};`;
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
TypePropsToOption: {
|
|
77
|
+
get name() {
|
|
78
|
+
this.used = true;
|
|
79
|
+
return `__VLS_TypePropsToOption`;
|
|
80
|
+
},
|
|
81
|
+
get code() {
|
|
82
|
+
return options.compilerOptions.exactOptionalPropertyTypes ?
|
|
83
|
+
`type __VLS_TypePropsToOption<T> = {
|
|
84
|
+
[K in keyof T]-?: {} extends Pick<T, K>
|
|
85
|
+
? { type: import('${options.vueCompilerOptions.lib}').PropType<T[K]> }
|
|
86
|
+
: { type: import('${options.vueCompilerOptions.lib}').PropType<T[K]>, required: true }
|
|
87
|
+
};` :
|
|
88
|
+
`type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
89
|
+
type __VLS_TypePropsToOption<T> = {
|
|
90
|
+
[K in keyof T]-?: {} extends Pick<T, K>
|
|
91
|
+
? { type: import('${options.vueCompilerOptions.lib}').PropType<__VLS_NonUndefinedable<T[K]>> }
|
|
92
|
+
: { type: import('${options.vueCompilerOptions.lib}').PropType<T[K]>, required: true }
|
|
93
|
+
};`;
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
return {
|
|
98
|
+
generatedTemplate: false,
|
|
99
|
+
generatedPropsType: false,
|
|
100
|
+
scriptSetupGeneratedOffset: undefined,
|
|
101
|
+
bypassDefineComponent: options.lang === 'js' || options.lang === 'jsx',
|
|
102
|
+
bindingNames: new Set([
|
|
103
|
+
...options.scriptRanges?.bindings.map(range => options.sfc.script.content.substring(range.start, range.end)) ?? [],
|
|
104
|
+
...options.scriptSetupRanges?.bindings.map(range => options.sfc.scriptSetup.content.substring(range.start, range.end)) ?? [],
|
|
105
|
+
]),
|
|
106
|
+
helperTypes,
|
|
107
|
+
generateHelperTypes,
|
|
108
|
+
};
|
|
109
|
+
function* generateHelperTypes() {
|
|
110
|
+
let shouldCheck = true;
|
|
111
|
+
while (shouldCheck) {
|
|
112
|
+
shouldCheck = false;
|
|
113
|
+
for (const helperType of Object.values(helperTypes)) {
|
|
114
|
+
if (helperType.used && !helperType.generated) {
|
|
115
|
+
shouldCheck = true;
|
|
116
|
+
helperType.generated = true;
|
|
117
|
+
yield common_1.newLine + helperType.code + common_1.newLine;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.createScriptCodegenContext = createScriptCodegenContext;
|
|
124
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { VueCompilerOptions } from '
|
|
1
|
+
import type { VueCompilerOptions } from '../../types';
|
|
2
2
|
export declare function generateGlobalTypes(vueCompilerOptions: VueCompilerOptions): string;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateGlobalTypes = void 0;
|
|
4
|
+
const shared_1 = require("../../utils/shared");
|
|
5
|
+
function generateGlobalTypes(vueCompilerOptions) {
|
|
6
|
+
const fnPropsType = `(K extends { $props: infer Props } ? Props : any)${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'}`;
|
|
7
|
+
return `
|
|
8
|
+
; export const __VLS_globalTypesStart = {};
|
|
9
|
+
declare global {
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
type __VLS_IntrinsicElements = __VLS_PickNotAny<import('vue/jsx-runtime').JSX.IntrinsicElements, __VLS_PickNotAny<globalThis.JSX.IntrinsicElements, Record<string, any>>>;
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
type __VLS_Element = __VLS_PickNotAny<import('vue/jsx-runtime').JSX.Element, globalThis.JSX.Element>;
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
type __VLS_GlobalComponents = ${[
|
|
16
|
+
`__VLS_PickNotAny<import('vue').GlobalComponents, {}>`,
|
|
17
|
+
`__VLS_PickNotAny<import('@vue/runtime-core').GlobalComponents, {}>`,
|
|
18
|
+
`__VLS_PickNotAny<import('@vue/runtime-dom').GlobalComponents, {}>`,
|
|
19
|
+
`Pick<typeof import('${vueCompilerOptions.lib}'), 'Transition' | 'TransitionGroup' | 'KeepAlive' | 'Suspense' | 'Teleport'>`
|
|
20
|
+
].join(' & ')};
|
|
21
|
+
type __VLS_IsAny<T> = 0 extends 1 & T ? true : false;
|
|
22
|
+
type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
|
|
23
|
+
|
|
24
|
+
const __VLS_intrinsicElements: __VLS_IntrinsicElements;
|
|
25
|
+
|
|
26
|
+
// v-for
|
|
27
|
+
function __VLS_getVForSourceType(source: number): [number, number, number][];
|
|
28
|
+
function __VLS_getVForSourceType(source: string): [string, number, number][];
|
|
29
|
+
function __VLS_getVForSourceType<T extends any[]>(source: T): [
|
|
30
|
+
item: T[number],
|
|
31
|
+
key: number,
|
|
32
|
+
index: number,
|
|
33
|
+
][];
|
|
34
|
+
function __VLS_getVForSourceType<T extends { [Symbol.iterator](): Iterator<any> }>(source: T): [
|
|
35
|
+
item: T extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never,
|
|
36
|
+
key: number,
|
|
37
|
+
index: undefined,
|
|
38
|
+
][];
|
|
39
|
+
// #3845
|
|
40
|
+
function __VLS_getVForSourceType<T extends number | { [Symbol.iterator](): Iterator<any> }>(source: T): [
|
|
41
|
+
item: number | (Exclude<T, number> extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never),
|
|
42
|
+
key: number,
|
|
43
|
+
index: undefined,
|
|
44
|
+
][];
|
|
45
|
+
function __VLS_getVForSourceType<T>(source: T): [
|
|
46
|
+
item: T[keyof T],
|
|
47
|
+
key: keyof T,
|
|
48
|
+
index: number,
|
|
49
|
+
][];
|
|
50
|
+
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
function __VLS_getSlotParams<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>;
|
|
53
|
+
// @ts-ignore
|
|
54
|
+
function __VLS_getSlotParam<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>[0];
|
|
55
|
+
function __VLS_directiveFunction<T>(dir: T):
|
|
56
|
+
T extends import('${vueCompilerOptions.lib}').ObjectDirective<infer E, infer V> | import('${vueCompilerOptions.lib}').FunctionDirective<infer E, infer V> ? (value: V) => void
|
|
57
|
+
: T;
|
|
58
|
+
function __VLS_withScope<T, K>(ctx: T, scope: K): ctx is T & K;
|
|
59
|
+
function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
|
|
60
|
+
|
|
61
|
+
type __VLS_SelfComponent<N, C> = string extends N ? {} : N extends string ? { [P in N]: C } : {};
|
|
62
|
+
type __VLS_WithComponent<N0 extends string, LocalComponents, N1 extends string, N2 extends string, N3 extends string> =
|
|
63
|
+
N1 extends keyof LocalComponents ? N1 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N1] } :
|
|
64
|
+
N2 extends keyof LocalComponents ? N2 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N2] } :
|
|
65
|
+
N3 extends keyof LocalComponents ? N3 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N3] } :
|
|
66
|
+
N1 extends keyof __VLS_GlobalComponents ? N1 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N1] } :
|
|
67
|
+
N2 extends keyof __VLS_GlobalComponents ? N2 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N2] } :
|
|
68
|
+
N3 extends keyof __VLS_GlobalComponents ? N3 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N3] } :
|
|
69
|
+
${vueCompilerOptions.strictTemplates ? '{}' : '{ [K in N0]: unknown }'}
|
|
70
|
+
|
|
71
|
+
type __VLS_FillingEventArg_ParametersLength<E extends (...args: any) => any> = __VLS_IsAny<Parameters<E>> extends true ? -1 : Parameters<E>['length'];
|
|
72
|
+
type __VLS_FillingEventArg<E> = E extends (...args: any) => any ? __VLS_FillingEventArg_ParametersLength<E> extends 0 ? ($event?: undefined) => ReturnType<E> : E : E;
|
|
73
|
+
function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
|
|
74
|
+
T extends new (...args: any) => any
|
|
75
|
+
? (props: ${fnPropsType}, ctx?: any) => __VLS_Element & { __ctx?: {
|
|
76
|
+
attrs?: any,
|
|
77
|
+
slots?: K extends { ${(0, shared_1.getSlotsPropertyName)(vueCompilerOptions.target)}: infer Slots } ? Slots : any,
|
|
78
|
+
emit?: K extends { $emit: infer Emit } ? Emit : any
|
|
79
|
+
} & { props?: ${fnPropsType}; expose?(exposed: K): void; } }
|
|
80
|
+
: T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>
|
|
81
|
+
: T extends (...args: any) => any ? T
|
|
82
|
+
: (_: {}${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'}, ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: {}${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'} } };
|
|
83
|
+
function __VLS_elementAsFunction<T>(tag: T, endTag?: T): (_: T${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'}) => void;
|
|
84
|
+
function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): Parameters<T>['length'] extends 2 ? [any] : [];
|
|
85
|
+
function __VLS_pickEvent<E1, E2>(emitEvent: E1, propEvent: E2): __VLS_FillingEventArg<
|
|
86
|
+
__VLS_PickNotAny<
|
|
87
|
+
__VLS_AsFunctionOrAny<E2>,
|
|
88
|
+
__VLS_AsFunctionOrAny<E1>
|
|
89
|
+
>
|
|
90
|
+
> | undefined;
|
|
91
|
+
function __VLS_pickFunctionalComponentCtx<T, K>(comp: T, compInstance: K): __VLS_PickNotAny<
|
|
92
|
+
'__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: infer Ctx } ? Ctx : never : any
|
|
93
|
+
, T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
|
|
94
|
+
>;
|
|
95
|
+
type __VLS_FunctionalComponentProps<T, K> =
|
|
96
|
+
'__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: { props?: infer P } } ? NonNullable<P> : never
|
|
97
|
+
: T extends (props: infer P, ...args: any) => any ? P :
|
|
98
|
+
{};
|
|
99
|
+
type __VLS_AsFunctionOrAny<F> = unknown extends F ? any : ((...args: any) => any) extends F ? F : any;
|
|
100
|
+
|
|
101
|
+
function __VLS_normalizeSlot<S>(s: S): S extends () => infer R ? (props: {}) => R : S;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* emit
|
|
105
|
+
*/
|
|
106
|
+
// fix https://github.com/vuejs/language-tools/issues/926
|
|
107
|
+
type __VLS_UnionToIntersection<U> = (U extends unknown ? (arg: U) => unknown : never) extends ((arg: infer P) => unknown) ? P : never;
|
|
108
|
+
type __VLS_OverloadUnionInner<T, U = unknown> = U & T extends (...args: infer A) => infer R
|
|
109
|
+
? U extends T
|
|
110
|
+
? never
|
|
111
|
+
: __VLS_OverloadUnionInner<T, Pick<T, keyof T> & U & ((...args: A) => R)> | ((...args: A) => R)
|
|
112
|
+
: never;
|
|
113
|
+
type __VLS_OverloadUnion<T> = Exclude<
|
|
114
|
+
__VLS_OverloadUnionInner<(() => never) & T>,
|
|
115
|
+
T extends () => never ? never : () => never
|
|
116
|
+
>;
|
|
117
|
+
type __VLS_ConstructorOverloads<T> = __VLS_OverloadUnion<T> extends infer F
|
|
118
|
+
? F extends (event: infer E, ...args: infer A) => any
|
|
119
|
+
? { [K in E & string]: (...args: A) => void; }
|
|
120
|
+
: never
|
|
121
|
+
: never;
|
|
122
|
+
type __VLS_NormalizeEmits<T> = __VLS_PrettifyGlobal<
|
|
123
|
+
__VLS_UnionToIntersection<
|
|
124
|
+
__VLS_ConstructorOverloads<T> & {
|
|
125
|
+
[K in keyof T]: T[K] extends any[] ? { (...args: T[K]): void } : never
|
|
126
|
+
}
|
|
127
|
+
>
|
|
128
|
+
>;
|
|
129
|
+
type __VLS_PrettifyGlobal<T> = { [K in keyof T]: T[K]; } & {};
|
|
130
|
+
}
|
|
131
|
+
export const __VLS_globalTypesEnd = {};`;
|
|
132
|
+
}
|
|
133
|
+
exports.generateGlobalTypes = generateGlobalTypes;
|
|
134
|
+
;
|
|
135
|
+
//# sourceMappingURL=globalTypes.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Mapping } from '@volar/language-core';
|
|
2
|
+
import type * as ts from 'typescript';
|
|
3
|
+
import type { ScriptRanges } from '../../parsers/scriptRanges';
|
|
4
|
+
import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
|
|
5
|
+
import type { Code, Sfc, VueCodeInformation, VueCompilerOptions } from '../../types';
|
|
6
|
+
import type { TemplateCodegenContext } from '../template/context';
|
|
7
|
+
export declare const codeFeatures: {
|
|
8
|
+
all: VueCodeInformation;
|
|
9
|
+
none: VueCodeInformation;
|
|
10
|
+
verification: VueCodeInformation;
|
|
11
|
+
navigation: VueCodeInformation;
|
|
12
|
+
referencesCodeLens: VueCodeInformation;
|
|
13
|
+
cssClassNavigation: VueCodeInformation;
|
|
14
|
+
};
|
|
15
|
+
export interface ScriptCodegenOptions {
|
|
16
|
+
fileBaseName: string;
|
|
17
|
+
ts: typeof ts;
|
|
18
|
+
compilerOptions: ts.CompilerOptions;
|
|
19
|
+
vueCompilerOptions: VueCompilerOptions;
|
|
20
|
+
sfc: Sfc;
|
|
21
|
+
lang: string;
|
|
22
|
+
scriptRanges: ScriptRanges | undefined;
|
|
23
|
+
scriptSetupRanges: ScriptSetupRanges | undefined;
|
|
24
|
+
templateCodegen: {
|
|
25
|
+
tsCodes: Code[];
|
|
26
|
+
ctx: TemplateCodegenContext;
|
|
27
|
+
hasSlot: boolean;
|
|
28
|
+
} | undefined;
|
|
29
|
+
globalTypes: boolean;
|
|
30
|
+
getGeneratedLength: () => number;
|
|
31
|
+
linkedCodeMappings: Mapping[];
|
|
32
|
+
}
|
|
33
|
+
export declare function generateScript(options: ScriptCodegenOptions): Generator<Code>;
|