@vue/language-core 3.1.8 → 3.2.1
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 +25 -3
- package/lib/codegen/codeFeatures.d.ts +18 -84
- package/lib/codegen/names.d.ts +2 -5
- package/lib/codegen/names.js +3 -6
- package/lib/codegen/script/component.js +37 -4
- package/lib/codegen/script/index.d.ts +4 -12
- package/lib/codegen/script/index.js +77 -22
- package/lib/codegen/script/scriptSetup.js +52 -14
- package/lib/codegen/script/template.js +71 -34
- package/lib/codegen/style/index.d.ts +9 -9
- package/lib/codegen/style/modules.js +34 -1
- package/lib/codegen/template/context.d.ts +7 -7
- package/lib/codegen/template/context.js +34 -1
- package/lib/codegen/template/element.js +48 -7
- package/lib/codegen/template/elementDirectives.js +36 -3
- package/lib/codegen/template/elementEvents.js +36 -3
- package/lib/codegen/template/elementProps.js +35 -2
- package/lib/codegen/template/index.d.ts +10 -10
- package/lib/codegen/template/index.js +34 -1
- package/lib/codegen/template/interpolation.d.ts +4 -3
- package/lib/codegen/template/interpolation.js +37 -4
- package/lib/codegen/template/slotOutlet.js +35 -2
- package/lib/codegen/template/templateChild.js +34 -1
- package/lib/codegen/template/vFor.js +37 -4
- package/lib/codegen/template/vIf.js +34 -1
- package/lib/codegen/template/vSlot.js +38 -5
- package/lib/compilerOptions.d.ts +7 -11
- package/lib/compilerOptions.js +48 -89
- package/lib/languagePlugin.js +34 -1
- package/lib/parsers/scriptRanges.d.ts +26 -16
- package/lib/parsers/scriptRanges.js +66 -64
- package/lib/parsers/scriptSetupRanges.d.ts +19 -24
- package/lib/parsers/scriptSetupRanges.js +13 -15
- package/lib/parsers/utils.d.ts +3 -6
- package/lib/parsers/utils.js +1 -0
- package/lib/plugins/vue-template-inline-css.js +34 -1
- package/lib/plugins/vue-template-inline-ts.js +34 -1
- package/lib/plugins/vue-tsx.d.ts +36 -114
- package/lib/plugins/vue-tsx.js +62 -33
- package/lib/plugins.js +17 -14
- package/lib/types.d.ts +8 -8
- package/lib/utils/collectBindings.d.ts +1 -1
- package/lib/utils/forEachTemplateNode.js +34 -1
- package/lib/utils/parseSfc.js +34 -1
- package/lib/utils/shared.d.ts +1 -1
- package/lib/utils/shared.js +2 -1
- package/lib/virtualCode/embeddedCodes.js +6 -2
- package/lib/virtualCode/index.js +10 -1
- package/lib/virtualCode/ir.js +34 -1
- package/lib/virtualCode/normalize.js +37 -2
- package/package.json +4 -12
- package/types/props-fallback.d.ts +5 -0
- package/types/template-helpers.d.ts +146 -0
- package/types/vue-3.4-shims.d.ts +6 -0
- package/lib/codegen/globalTypes.d.ts +0 -3
- package/lib/codegen/globalTypes.js +0 -163
- package/lib/codegen/script/src.d.ts +0 -3
- package/lib/codegen/script/src.js +0 -43
- package/lib/codegen/style/classProperty.d.ts +0 -2
- package/lib/codegen/style/classProperty.js +0 -18
- package/lib/codegen/style/imports.d.ts +0 -2
- package/lib/codegen/style/imports.js +0 -27
- package/lib/codegen/template/elementChildren.d.ts +0 -5
- package/lib/codegen/template/elementChildren.js +0 -12
- package/lib/codegen/utils/wrapWith.d.ts +0 -2
- package/lib/codegen/utils/wrapWith.js +0 -15
- package/lib/virtualFile/computedEmbeddedCodes.d.ts +0 -4
- package/lib/virtualFile/computedEmbeddedCodes.js +0 -262
- package/lib/virtualFile/computedSfc.d.ts +0 -6
- package/lib/virtualFile/computedSfc.js +0 -340
- package/lib/virtualFile/computedVueSfc.d.ts +0 -4
- package/lib/virtualFile/computedVueSfc.js +0 -41
- package/lib/virtualFile/embeddedFile.d.ts +0 -11
- package/lib/virtualFile/embeddedFile.js +0 -14
- package/lib/virtualFile/vueFile.d.ts +0 -24
- package/lib/virtualFile/vueFile.js +0 -49
package/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from './lib/codegen/globalTypes';
|
|
2
1
|
export * from './lib/codegen/template';
|
|
3
2
|
export * from './lib/compilerOptions';
|
|
4
3
|
export * from './lib/languagePlugin';
|
|
4
|
+
export * from './lib/parsers/scriptRanges';
|
|
5
5
|
export * from './lib/parsers/scriptSetupRanges';
|
|
6
6
|
export * from './lib/plugins';
|
|
7
7
|
export * from './lib/types';
|
package/index.js
CHANGED
|
@@ -10,15 +10,37 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
13
18
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
19
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
20
|
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
16
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
39
|
exports.tsCodegen = exports.names = void 0;
|
|
18
|
-
__exportStar(require("./lib/codegen/globalTypes"), exports);
|
|
19
40
|
__exportStar(require("./lib/codegen/template"), exports);
|
|
20
41
|
__exportStar(require("./lib/compilerOptions"), exports);
|
|
21
42
|
__exportStar(require("./lib/languagePlugin"), exports);
|
|
43
|
+
__exportStar(require("./lib/parsers/scriptRanges"), exports);
|
|
22
44
|
__exportStar(require("./lib/parsers/scriptSetupRanges"), exports);
|
|
23
45
|
__exportStar(require("./lib/plugins"), exports);
|
|
24
46
|
__exportStar(require("./lib/types"), exports);
|
|
@@ -27,8 +49,8 @@ __exportStar(require("./lib/utils/forEachTemplateNode"), exports);
|
|
|
27
49
|
__exportStar(require("./lib/utils/parseSfc"), exports);
|
|
28
50
|
__exportStar(require("./lib/utils/shared"), exports);
|
|
29
51
|
__exportStar(require("./lib/virtualCode"), exports);
|
|
30
|
-
exports.names = require("./lib/codegen/names");
|
|
31
|
-
|
|
52
|
+
exports.names = __importStar(require("./lib/codegen/names"));
|
|
53
|
+
const vue_tsx_1 = require("./lib/plugins/vue-tsx");
|
|
32
54
|
Object.defineProperty(exports, "tsCodegen", { enumerable: true, get: function () { return vue_tsx_1.tsCodegen; } });
|
|
33
55
|
__exportStar(require("@volar/language-core"), exports);
|
|
34
56
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,86 +1,20 @@
|
|
|
1
1
|
import type { VueCodeInformation } from '../types';
|
|
2
|
-
declare const
|
|
3
|
-
all:
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
semantic: true;
|
|
21
|
-
navigation: true;
|
|
22
|
-
};
|
|
23
|
-
navigation: {
|
|
24
|
-
navigation: true;
|
|
25
|
-
};
|
|
26
|
-
navigationWithoutRename: {
|
|
27
|
-
navigation: {
|
|
28
|
-
shouldRename: () => false;
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
navigationAndCompletion: {
|
|
32
|
-
navigation: true;
|
|
33
|
-
completion: true;
|
|
34
|
-
};
|
|
35
|
-
navigationAndVerification: {
|
|
36
|
-
navigation: true;
|
|
37
|
-
verification: true;
|
|
38
|
-
};
|
|
39
|
-
withoutNavigation: {
|
|
40
|
-
verification: true;
|
|
41
|
-
completion: true;
|
|
42
|
-
semantic: true;
|
|
43
|
-
};
|
|
44
|
-
semanticWithoutHighlight: {
|
|
45
|
-
semantic: {
|
|
46
|
-
shouldHighlight: () => false;
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
withoutHighlight: {
|
|
50
|
-
semantic: {
|
|
51
|
-
shouldHighlight: () => false;
|
|
52
|
-
};
|
|
53
|
-
verification: true;
|
|
54
|
-
navigation: true;
|
|
55
|
-
completion: true;
|
|
56
|
-
};
|
|
57
|
-
withoutHighlightAndCompletion: {
|
|
58
|
-
semantic: {
|
|
59
|
-
shouldHighlight: () => false;
|
|
60
|
-
};
|
|
61
|
-
verification: true;
|
|
62
|
-
navigation: true;
|
|
63
|
-
};
|
|
64
|
-
withoutSemantic: {
|
|
65
|
-
verification: true;
|
|
66
|
-
navigation: true;
|
|
67
|
-
completion: true;
|
|
68
|
-
};
|
|
69
|
-
doNotReportTs2339AndTs2551: {
|
|
70
|
-
verification: {
|
|
71
|
-
shouldReport: (_source: string | undefined, code: string | number | undefined) => boolean;
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
doNotReportTs2353AndTs2561: {
|
|
75
|
-
verification: {
|
|
76
|
-
shouldReport: (_source: string | undefined, code: string | number | undefined) => boolean;
|
|
77
|
-
};
|
|
78
|
-
};
|
|
79
|
-
doNotReportTs6133: {
|
|
80
|
-
verification: {
|
|
81
|
-
shouldReport: (_source: string | undefined, code: string | number | undefined) => boolean;
|
|
82
|
-
};
|
|
83
|
-
};
|
|
2
|
+
export declare const codeFeatures: {
|
|
3
|
+
all: VueCodeInformation;
|
|
4
|
+
importCompletionOnly: VueCodeInformation;
|
|
5
|
+
verification: VueCodeInformation;
|
|
6
|
+
completion: VueCodeInformation;
|
|
7
|
+
withoutCompletion: VueCodeInformation;
|
|
8
|
+
navigation: VueCodeInformation;
|
|
9
|
+
navigationWithoutRename: VueCodeInformation;
|
|
10
|
+
navigationAndCompletion: VueCodeInformation;
|
|
11
|
+
navigationAndVerification: VueCodeInformation;
|
|
12
|
+
withoutNavigation: VueCodeInformation;
|
|
13
|
+
semanticWithoutHighlight: VueCodeInformation;
|
|
14
|
+
withoutHighlight: VueCodeInformation;
|
|
15
|
+
withoutHighlightAndCompletion: VueCodeInformation;
|
|
16
|
+
withoutSemantic: VueCodeInformation;
|
|
17
|
+
doNotReportTs2339AndTs2551: VueCodeInformation;
|
|
18
|
+
doNotReportTs2353AndTs2561: VueCodeInformation;
|
|
19
|
+
doNotReportTs6133: VueCodeInformation;
|
|
84
20
|
};
|
|
85
|
-
export declare const codeFeatures: { [K in keyof typeof raw]: VueCodeInformation; };
|
|
86
|
-
export {};
|
package/lib/codegen/names.d.ts
CHANGED
|
@@ -8,10 +8,9 @@ export declare const modelEmit = "__VLS_modelEmit";
|
|
|
8
8
|
export declare const emit = "__VLS_emit";
|
|
9
9
|
export declare const exposed = "__VLS_exposed";
|
|
10
10
|
export declare const setup = "__VLS_setup";
|
|
11
|
-
export declare const components = "
|
|
12
|
-
export declare const directives = "
|
|
11
|
+
export declare const components = "__VLS_components";
|
|
12
|
+
export declare const directives = "__VLS_directives";
|
|
13
13
|
export declare const intrinsics = "__VLS_intrinsics";
|
|
14
|
-
export declare const placeholder = "__VLS_placeholder";
|
|
15
14
|
export declare const _export = "__VLS_export";
|
|
16
15
|
export declare const ModelProps = "__VLS_ModelProps";
|
|
17
16
|
export declare const Props = "__VLS_Props";
|
|
@@ -21,9 +20,7 @@ export declare const TemplateRefs = "__VLS_TemplateRefs";
|
|
|
21
20
|
export declare const RootEl = "__VLS_RootEl";
|
|
22
21
|
export declare const ModelEmit = "__VLS_ModelEmit";
|
|
23
22
|
export declare const EmitProps = "__VLS_EmitProps";
|
|
24
|
-
export declare const InternalProps = "__VLS_InternalProps";
|
|
25
23
|
export declare const Emit = "__VLS_Emit";
|
|
26
24
|
export declare const SetupExposed = "__VLS_SetupExposed";
|
|
27
25
|
export declare const PublicProps = "__VLS_PublicProps";
|
|
28
26
|
export declare const StyleModules = "__VLS_StyleModules";
|
|
29
|
-
export declare const PROPS_FALLBACK = "__VLS_PROPS_FALLBACK";
|
package/lib/codegen/names.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.StyleModules = exports.PublicProps = exports.SetupExposed = exports.Emit = exports.EmitProps = exports.ModelEmit = exports.RootEl = exports.TemplateRefs = exports.InheritedAttrs = exports.Slots = exports.Props = exports.ModelProps = exports._export = exports.intrinsics = exports.directives = exports.components = exports.setup = exports.exposed = exports.emit = exports.modelEmit = exports.defaultModels = exports.defaults = exports.props = exports.slots = exports.dollars = exports.ctx = void 0;
|
|
4
4
|
exports.ctx = '__VLS_ctx';
|
|
5
5
|
exports.dollars = '__VLS_dollars';
|
|
6
6
|
exports.slots = '__VLS_slots';
|
|
@@ -11,10 +11,9 @@ exports.modelEmit = '__VLS_modelEmit';
|
|
|
11
11
|
exports.emit = '__VLS_emit';
|
|
12
12
|
exports.exposed = '__VLS_exposed';
|
|
13
13
|
exports.setup = '__VLS_setup';
|
|
14
|
-
exports.components = '
|
|
15
|
-
exports.directives = '
|
|
14
|
+
exports.components = '__VLS_components';
|
|
15
|
+
exports.directives = '__VLS_directives';
|
|
16
16
|
exports.intrinsics = '__VLS_intrinsics';
|
|
17
|
-
exports.placeholder = '__VLS_placeholder';
|
|
18
17
|
exports._export = '__VLS_export';
|
|
19
18
|
exports.ModelProps = '__VLS_ModelProps';
|
|
20
19
|
exports.Props = '__VLS_Props';
|
|
@@ -24,10 +23,8 @@ exports.TemplateRefs = '__VLS_TemplateRefs';
|
|
|
24
23
|
exports.RootEl = '__VLS_RootEl';
|
|
25
24
|
exports.ModelEmit = '__VLS_ModelEmit';
|
|
26
25
|
exports.EmitProps = '__VLS_EmitProps';
|
|
27
|
-
exports.InternalProps = '__VLS_InternalProps';
|
|
28
26
|
exports.Emit = '__VLS_Emit';
|
|
29
27
|
exports.SetupExposed = '__VLS_SetupExposed';
|
|
30
28
|
exports.PublicProps = '__VLS_PublicProps';
|
|
31
29
|
exports.StyleModules = '__VLS_StyleModules';
|
|
32
|
-
exports.PROPS_FALLBACK = '__VLS_PROPS_FALLBACK';
|
|
33
30
|
//# sourceMappingURL=names.js.map
|
|
@@ -1,8 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.generateComponent = generateComponent;
|
|
4
37
|
const codeFeatures_1 = require("../codeFeatures");
|
|
5
|
-
const names = require("../names");
|
|
38
|
+
const names = __importStar(require("../names"));
|
|
6
39
|
const utils_1 = require("../utils");
|
|
7
40
|
const merge_1 = require("../utils/merge");
|
|
8
41
|
function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
@@ -21,12 +54,12 @@ function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
21
54
|
yield* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, !!emitOptionCodes.length);
|
|
22
55
|
if (options.vueCompilerOptions.target >= 3.5
|
|
23
56
|
&& options.vueCompilerOptions.inferComponentDollarRefs
|
|
24
|
-
&& options.
|
|
57
|
+
&& options.templateAndStyleTypes.has(names.TemplateRefs)) {
|
|
25
58
|
yield `__typeRefs: {} as ${names.TemplateRefs},${utils_1.newLine}`;
|
|
26
59
|
}
|
|
27
60
|
if (options.vueCompilerOptions.target >= 3.5
|
|
28
61
|
&& options.vueCompilerOptions.inferComponentDollarEl
|
|
29
|
-
&& options.
|
|
62
|
+
&& options.templateAndStyleTypes.has(names.RootEl)) {
|
|
30
63
|
yield `__typeEl: {} as ${names.RootEl},${utils_1.newLine}`;
|
|
31
64
|
}
|
|
32
65
|
yield `})`;
|
|
@@ -62,7 +95,7 @@ function* generateEmitsOption(options, scriptSetupRanges) {
|
|
|
62
95
|
function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasEmitsOption) {
|
|
63
96
|
const optionGenerates = [];
|
|
64
97
|
const typeOptionGenerates = [];
|
|
65
|
-
if (options.
|
|
98
|
+
if (options.templateAndStyleTypes.has(names.InheritedAttrs)) {
|
|
66
99
|
const attrsType = hasEmitsOption
|
|
67
100
|
? `Omit<${names.InheritedAttrs}, keyof ${names.EmitProps}>`
|
|
68
101
|
: names.InheritedAttrs;
|
|
@@ -1,28 +1,19 @@
|
|
|
1
|
-
import type * as ts from 'typescript';
|
|
2
1
|
import type { ScriptRanges } from '../../parsers/scriptRanges';
|
|
3
2
|
import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
|
|
4
3
|
import type { Code, Sfc, VueCompilerOptions } from '../../types';
|
|
5
|
-
import type { TemplateCodegenContext } from '../template/context';
|
|
6
4
|
export interface ScriptCodegenOptions {
|
|
7
|
-
ts: typeof ts;
|
|
8
5
|
vueCompilerOptions: VueCompilerOptions;
|
|
9
6
|
script: Sfc['script'];
|
|
10
7
|
scriptSetup: Sfc['scriptSetup'];
|
|
11
8
|
fileName: string;
|
|
12
9
|
scriptRanges: ScriptRanges | undefined;
|
|
13
10
|
scriptSetupRanges: ScriptSetupRanges | undefined;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
} | undefined;
|
|
18
|
-
styleCodegen: TemplateCodegenContext & {
|
|
19
|
-
codes: Code[];
|
|
20
|
-
} | undefined;
|
|
21
|
-
setupExposed: Set<string>;
|
|
11
|
+
templateAndStyleTypes: Set<string>;
|
|
12
|
+
templateAndStyleCodes: Code[];
|
|
13
|
+
exposed: Set<string>;
|
|
22
14
|
}
|
|
23
15
|
export { generate as generateScript };
|
|
24
16
|
declare function generate(options: ScriptCodegenOptions): {
|
|
25
|
-
codes: Code[];
|
|
26
17
|
generatedTypes: Set<string>;
|
|
27
18
|
localTypes: {
|
|
28
19
|
generate: () => Generator<string, void, unknown>;
|
|
@@ -34,4 +25,5 @@ declare function generate(options: ScriptCodegenOptions): {
|
|
|
34
25
|
readonly OmitIndexSignature: string;
|
|
35
26
|
};
|
|
36
27
|
inlayHints: import("../inlayHints").InlayHintInfo[];
|
|
28
|
+
codes: Code[];
|
|
37
29
|
};
|
|
@@ -1,14 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.generateScript = generate;
|
|
4
|
-
const path = require("path-browserify");
|
|
37
|
+
const path = __importStar(require("path-browserify"));
|
|
5
38
|
const codeFeatures_1 = require("../codeFeatures");
|
|
6
|
-
const names = require("../names");
|
|
39
|
+
const names = __importStar(require("../names"));
|
|
7
40
|
const utils_1 = require("../utils");
|
|
8
41
|
const boundary_1 = require("../utils/boundary");
|
|
9
42
|
const context_1 = require("./context");
|
|
10
43
|
const scriptSetup_1 = require("./scriptSetup");
|
|
11
|
-
const src_1 = require("./src");
|
|
12
44
|
const template_1 = require("./template");
|
|
13
45
|
const exportExpression = `{} as typeof ${names._export}`;
|
|
14
46
|
function generate(options) {
|
|
@@ -17,16 +49,34 @@ function generate(options) {
|
|
|
17
49
|
return { ...ctx, codes: [...codeGenerator] };
|
|
18
50
|
}
|
|
19
51
|
function* generateWorker(options, ctx) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
52
|
+
const { script, scriptRanges, scriptSetup, scriptSetupRanges, vueCompilerOptions, fileName } = options;
|
|
53
|
+
yield* generateGlobalTypesReference(vueCompilerOptions, fileName);
|
|
54
|
+
// <script src="">
|
|
55
|
+
if (typeof script?.src === 'object') {
|
|
56
|
+
let src = script.src.text;
|
|
57
|
+
if (src.endsWith('.ts') && !src.endsWith('.d.ts')) {
|
|
58
|
+
src = src.slice(0, -'.ts'.length) + '.js';
|
|
59
|
+
}
|
|
60
|
+
else if (src.endsWith('.tsx')) {
|
|
61
|
+
src = src.slice(0, -'.tsx'.length) + '.jsx';
|
|
62
|
+
}
|
|
63
|
+
yield `import __VLS_default from `;
|
|
64
|
+
const token = yield* (0, boundary_1.startBoundary)('main', script.src.offset, {
|
|
65
|
+
...codeFeatures_1.codeFeatures.all,
|
|
66
|
+
...src !== script.src.text ? codeFeatures_1.codeFeatures.navigationWithoutRename : {},
|
|
67
|
+
});
|
|
68
|
+
yield `'`;
|
|
69
|
+
yield [src.slice(0, script.src.text.length), 'main', script.src.offset, { __combineToken: token }];
|
|
70
|
+
yield src.slice(script.src.text.length);
|
|
71
|
+
yield `'`;
|
|
72
|
+
yield (0, boundary_1.endBoundary)(token, script.src.offset + script.src.text.length);
|
|
73
|
+
yield utils_1.endOfLine;
|
|
74
|
+
yield `export default __VLS_default;${utils_1.endOfLine}`;
|
|
75
|
+
yield* (0, template_1.generateTemplate)(options, ctx, '__VLS_default');
|
|
27
76
|
}
|
|
28
77
|
// <script> + <script setup>
|
|
29
|
-
if (script && scriptRanges && scriptSetup && scriptSetupRanges) {
|
|
78
|
+
else if (script && scriptRanges && scriptSetup && scriptSetupRanges) {
|
|
79
|
+
yield* (0, scriptSetup_1.generateScriptSetupImports)(scriptSetup, scriptSetupRanges);
|
|
30
80
|
// <script>
|
|
31
81
|
let selfType;
|
|
32
82
|
const { exportDefault } = scriptRanges;
|
|
@@ -50,6 +100,7 @@ function* generateWorker(options, ctx) {
|
|
|
50
100
|
}
|
|
51
101
|
// only <script setup>
|
|
52
102
|
else if (scriptSetup && scriptSetupRanges) {
|
|
103
|
+
yield* (0, scriptSetup_1.generateScriptSetupImports)(scriptSetup, scriptSetupRanges);
|
|
53
104
|
if (scriptSetup.generic) {
|
|
54
105
|
yield* generateExportDeclareEqual(scriptSetup, names._export);
|
|
55
106
|
yield* (0, scriptSetup_1.generateGeneric)(options, ctx, scriptSetup, scriptSetupRanges, scriptSetup.generic, (0, scriptSetup_1.generateSetupFunction)(options, ctx, scriptSetup, scriptSetupRanges, (0, template_1.generateTemplate)(options, ctx)));
|
|
@@ -77,7 +128,7 @@ function* generateWorker(options, ctx) {
|
|
|
77
128
|
yield* ctx.localTypes.generate();
|
|
78
129
|
}
|
|
79
130
|
function* generateScriptWithExportDefault(ctx, script, scriptRanges, exportDefault, vueCompilerOptions, varName, templateGenerator) {
|
|
80
|
-
const
|
|
131
|
+
const componentOptions = scriptRanges.exportDefault?.options;
|
|
81
132
|
const { expression, isObjectLiteral } = componentOptions ?? exportDefault;
|
|
82
133
|
let wrapLeft;
|
|
83
134
|
let wrapRight;
|
|
@@ -119,22 +170,26 @@ function* generateScriptWithExportDefault(ctx, script, scriptRanges, exportDefau
|
|
|
119
170
|
yield utils_1.endOfLine;
|
|
120
171
|
yield* (0, utils_1.generateSfcBlockSection)(script, exportDefault.end, script.content.length, codeFeatures_1.codeFeatures.all);
|
|
121
172
|
}
|
|
122
|
-
function* generateGlobalTypesReference(
|
|
123
|
-
|
|
124
|
-
if (
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
else if (path.isAbsolute(globalTypesPath)) {
|
|
128
|
-
let relativePath = path.relative(path.dirname(options.fileName), globalTypesPath);
|
|
129
|
-
if (relativePath !== globalTypesPath
|
|
173
|
+
function* generateGlobalTypesReference({ typesRoot, lib, target, checkUnknownProps }, fileName) {
|
|
174
|
+
let typesPath;
|
|
175
|
+
if (path.isAbsolute(typesRoot)) {
|
|
176
|
+
let relativePath = path.relative(path.dirname(fileName), typesRoot);
|
|
177
|
+
if (relativePath !== typesRoot
|
|
130
178
|
&& !relativePath.startsWith('./')
|
|
131
179
|
&& !relativePath.startsWith('../')) {
|
|
132
180
|
relativePath = './' + relativePath;
|
|
133
181
|
}
|
|
134
|
-
|
|
182
|
+
typesPath = relativePath;
|
|
135
183
|
}
|
|
136
184
|
else {
|
|
137
|
-
|
|
185
|
+
typesPath = typesRoot;
|
|
186
|
+
}
|
|
187
|
+
yield `/// <reference types=${JSON.stringify(typesPath + '/template-helpers.d.ts')} />${utils_1.newLine}`;
|
|
188
|
+
if (!checkUnknownProps) {
|
|
189
|
+
yield `/// <reference types=${JSON.stringify(typesPath + '/props-fallback.d.ts')} />${utils_1.newLine}`;
|
|
190
|
+
}
|
|
191
|
+
if (lib === 'vue' && target < 3.5) {
|
|
192
|
+
yield `/// <reference types=${JSON.stringify(typesPath + '/vue-3.4-shims.d.ts')} />${utils_1.newLine}`;
|
|
138
193
|
}
|
|
139
194
|
}
|
|
140
195
|
function* generateExportDeclareEqual(block, name) {
|
|
@@ -1,11 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.generateScriptSetupImports = generateScriptSetupImports;
|
|
4
37
|
exports.generateGeneric = generateGeneric;
|
|
5
38
|
exports.generateSetupFunction = generateSetupFunction;
|
|
6
39
|
const shared_1 = require("@vue/shared");
|
|
7
40
|
const codeFeatures_1 = require("../codeFeatures");
|
|
8
|
-
const names = require("../names");
|
|
41
|
+
const names = __importStar(require("../names"));
|
|
9
42
|
const utils_1 = require("../utils");
|
|
10
43
|
const boundary_1 = require("../utils/boundary");
|
|
11
44
|
const camelized_1 = require("../utils/camelized");
|
|
@@ -36,6 +69,7 @@ function* generateGeneric(options, ctx, scriptSetup, scriptSetupRanges, generic,
|
|
|
36
69
|
+ ` ${names.setup} = (async () => {${utils_1.newLine}`;
|
|
37
70
|
yield* body;
|
|
38
71
|
const propTypes = [];
|
|
72
|
+
const emitTypes = [];
|
|
39
73
|
const { vueCompilerOptions } = options;
|
|
40
74
|
if (ctx.generatedTypes.has(names.PublicProps)) {
|
|
41
75
|
propTypes.push(names.PublicProps);
|
|
@@ -49,10 +83,9 @@ function* generateGeneric(options, ctx, scriptSetup, scriptSetupRanges, generic,
|
|
|
49
83
|
if (scriptSetupRanges.defineEmits || scriptSetupRanges.defineModel.length) {
|
|
50
84
|
propTypes.push(names.EmitProps);
|
|
51
85
|
}
|
|
52
|
-
if (options.
|
|
86
|
+
if (options.templateAndStyleTypes.has(names.InheritedAttrs)) {
|
|
53
87
|
propTypes.push(names.InheritedAttrs);
|
|
54
88
|
}
|
|
55
|
-
const emitTypes = [];
|
|
56
89
|
if (scriptSetupRanges.defineEmits) {
|
|
57
90
|
emitTypes.push(`typeof ${scriptSetupRanges.defineEmits.name ?? names.emit}`);
|
|
58
91
|
}
|
|
@@ -60,23 +93,28 @@ function* generateGeneric(options, ctx, scriptSetup, scriptSetupRanges, generic,
|
|
|
60
93
|
emitTypes.push(`typeof ${names.modelEmit}`);
|
|
61
94
|
}
|
|
62
95
|
yield `return {} as {${utils_1.newLine}`;
|
|
63
|
-
yield ` props:
|
|
96
|
+
yield ` props: `;
|
|
97
|
+
yield vueCompilerOptions.target >= 3.4
|
|
64
98
|
? `import('${vueCompilerOptions.lib}').PublicProps`
|
|
65
99
|
: vueCompilerOptions.target >= 3
|
|
66
100
|
? `import('${vueCompilerOptions.lib}').VNodeProps`
|
|
67
101
|
+ ` & import('${vueCompilerOptions.lib}').AllowedComponentProps`
|
|
68
102
|
+ ` & import('${vueCompilerOptions.lib}').ComponentCustomProps`
|
|
69
|
-
: `globalThis.JSX.IntrinsicAttributes
|
|
103
|
+
: `globalThis.JSX.IntrinsicAttributes`;
|
|
104
|
+
if (propTypes.length) {
|
|
105
|
+
yield ` & ${ctx.localTypes.PrettifyLocal}<${propTypes.join(` & `)}>`;
|
|
106
|
+
}
|
|
107
|
+
yield ` & (typeof globalThis extends { __VLS_PROPS_FALLBACK: infer P } ? P : {})${utils_1.endOfLine}`;
|
|
70
108
|
yield ` expose: (exposed: `;
|
|
71
109
|
yield scriptSetupRanges.defineExpose
|
|
72
110
|
? `import('${vueCompilerOptions.lib}').ShallowUnwrapRef<typeof ${names.exposed}>`
|
|
73
111
|
: `{}`;
|
|
74
112
|
if (options.vueCompilerOptions.inferComponentDollarRefs
|
|
75
|
-
&& options.
|
|
113
|
+
&& options.templateAndStyleTypes.has(names.TemplateRefs)) {
|
|
76
114
|
yield ` & { $refs: ${names.TemplateRefs}; }`;
|
|
77
115
|
}
|
|
78
116
|
if (options.vueCompilerOptions.inferComponentDollarEl
|
|
79
|
-
&& options.
|
|
117
|
+
&& options.templateAndStyleTypes.has(names.RootEl)) {
|
|
80
118
|
yield ` & { $el: ${names.RootEl}; }`;
|
|
81
119
|
}
|
|
82
120
|
yield `) => void${utils_1.endOfLine}`;
|
|
@@ -141,7 +179,7 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, bo
|
|
|
141
179
|
transforms.push((0, transform_1.insert)(callExp.start, function* () {
|
|
142
180
|
yield `(`;
|
|
143
181
|
}));
|
|
144
|
-
const type = options.
|
|
182
|
+
const type = options.templateAndStyleTypes.has(names.StyleModules)
|
|
145
183
|
? names.StyleModules
|
|
146
184
|
: `{}`;
|
|
147
185
|
if (arg) {
|
|
@@ -150,7 +188,7 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, bo
|
|
|
150
188
|
yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.withoutSemantic);
|
|
151
189
|
yield `])`;
|
|
152
190
|
}), (0, transform_1.replace)(arg.start, arg.end, function* () {
|
|
153
|
-
yield
|
|
191
|
+
yield `{} as any`;
|
|
154
192
|
}));
|
|
155
193
|
}
|
|
156
194
|
else {
|
|
@@ -176,7 +214,7 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, bo
|
|
|
176
214
|
transforms.push((0, transform_1.insert)(callExp.start, function* () {
|
|
177
215
|
yield `(`;
|
|
178
216
|
}), (0, transform_1.insert)(callExp.end, function* () {
|
|
179
|
-
yield ` as
|
|
217
|
+
yield ` as Readonly<import('${options.vueCompilerOptions.lib}').ShallowRef<`;
|
|
180
218
|
if (arg) {
|
|
181
219
|
yield names.TemplateRefs;
|
|
182
220
|
yield `[`;
|
|
@@ -186,11 +224,11 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, bo
|
|
|
186
224
|
else {
|
|
187
225
|
yield `unknown`;
|
|
188
226
|
}
|
|
189
|
-
yield
|
|
227
|
+
yield ` | null>>)`;
|
|
190
228
|
}));
|
|
191
229
|
if (arg) {
|
|
192
230
|
transforms.push((0, transform_1.replace)(arg.start, arg.end, function* () {
|
|
193
|
-
yield
|
|
231
|
+
yield `{} as any`;
|
|
194
232
|
}));
|
|
195
233
|
}
|
|
196
234
|
}
|
|
@@ -219,7 +257,7 @@ function* generateMacros(options) {
|
|
|
219
257
|
yield `// @ts-ignore${utils_1.newLine}`;
|
|
220
258
|
yield `declare const { `;
|
|
221
259
|
for (const macro of Object.keys(options.vueCompilerOptions.macros)) {
|
|
222
|
-
if (!options.
|
|
260
|
+
if (!options.exposed.has(macro)) {
|
|
223
261
|
yield `${macro}, `;
|
|
224
262
|
}
|
|
225
263
|
}
|
|
@@ -299,7 +337,7 @@ function* generatePublicProps(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
299
337
|
}
|
|
300
338
|
function hasSlotsType(options) {
|
|
301
339
|
return !!(options.scriptSetupRanges?.defineSlots
|
|
302
|
-
|| options.
|
|
340
|
+
|| options.templateAndStyleTypes.has(names.Slots));
|
|
303
341
|
}
|
|
304
342
|
function* generateModels(scriptSetup, scriptSetupRanges) {
|
|
305
343
|
if (!scriptSetupRanges.defineModel.length) {
|