@vue/language-core 3.1.7 → 3.2.0
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 +38 -18
- package/lib/codegen/script/index.d.ts +4 -12
- package/lib/codegen/script/index.js +132 -71
- package/lib/codegen/script/scriptSetup.js +52 -14
- package/lib/codegen/script/template.d.ts +1 -1
- package/lib/codegen/script/template.js +73 -50
- package/lib/codegen/style/index.d.ts +10 -13
- package/lib/codegen/style/modules.js +34 -1
- package/lib/codegen/template/context.d.ts +8 -11
- package/lib/codegen/template/context.js +36 -2
- package/lib/codegen/template/element.js +146 -159
- package/lib/codegen/template/elementDirectives.js +36 -3
- package/lib/codegen/template/elementEvents.d.ts +1 -1
- package/lib/codegen/template/elementEvents.js +39 -6
- package/lib/codegen/template/elementProps.js +35 -2
- package/lib/codegen/template/index.d.ts +11 -14
- 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 +45 -16
- package/lib/codegen/template/vFor.js +37 -4
- package/lib/codegen/template/vIf.js +34 -1
- package/lib/codegen/template/vSlot.d.ts +1 -1
- package/lib/codegen/template/vSlot.js +52 -25
- package/lib/codegen/utils/index.js +4 -2
- 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 +27 -15
- package/lib/parsers/scriptRanges.js +66 -62
- 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 +4 -0
- package/lib/plugins/vue-script-js.js +1 -1
- 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 +38 -117
- 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 -2
- package/lib/codegen/script/src.js +0 -38
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
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export declare const ctx = "__VLS_ctx";
|
|
2
|
-
export declare const self = "__VLS_self";
|
|
3
2
|
export declare const dollars = "__VLS_dollars";
|
|
4
3
|
export declare const slots = "__VLS_slots";
|
|
5
4
|
export declare const props = "__VLS_props";
|
|
@@ -9,10 +8,9 @@ export declare const modelEmit = "__VLS_modelEmit";
|
|
|
9
8
|
export declare const emit = "__VLS_emit";
|
|
10
9
|
export declare const exposed = "__VLS_exposed";
|
|
11
10
|
export declare const setup = "__VLS_setup";
|
|
12
|
-
export declare const components = "
|
|
13
|
-
export declare const directives = "
|
|
11
|
+
export declare const components = "__VLS_components";
|
|
12
|
+
export declare const directives = "__VLS_directives";
|
|
14
13
|
export declare const intrinsics = "__VLS_intrinsics";
|
|
15
|
-
export declare const placeholder = "__VLS_placeholder";
|
|
16
14
|
export declare const _export = "__VLS_export";
|
|
17
15
|
export declare const ModelProps = "__VLS_ModelProps";
|
|
18
16
|
export declare const Props = "__VLS_Props";
|
|
@@ -27,4 +25,3 @@ export declare const Emit = "__VLS_Emit";
|
|
|
27
25
|
export declare const SetupExposed = "__VLS_SetupExposed";
|
|
28
26
|
export declare const PublicProps = "__VLS_PublicProps";
|
|
29
27
|
export declare const StyleModules = "__VLS_StyleModules";
|
|
30
|
-
export declare const PROPS_FALLBACK = "__VLS_PROPS_FALLBACK";
|
package/lib/codegen/names.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.StyleModules = exports.PublicProps = exports.SetupExposed = exports.Emit = exports.InternalProps = 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
|
-
exports.self = '__VLS_self';
|
|
6
5
|
exports.dollars = '__VLS_dollars';
|
|
7
6
|
exports.slots = '__VLS_slots';
|
|
8
7
|
exports.props = '__VLS_props';
|
|
@@ -12,10 +11,9 @@ exports.modelEmit = '__VLS_modelEmit';
|
|
|
12
11
|
exports.emit = '__VLS_emit';
|
|
13
12
|
exports.exposed = '__VLS_exposed';
|
|
14
13
|
exports.setup = '__VLS_setup';
|
|
15
|
-
exports.components = '
|
|
16
|
-
exports.directives = '
|
|
14
|
+
exports.components = '__VLS_components';
|
|
15
|
+
exports.directives = '__VLS_directives';
|
|
17
16
|
exports.intrinsics = '__VLS_intrinsics';
|
|
18
|
-
exports.placeholder = '__VLS_placeholder';
|
|
19
17
|
exports._export = '__VLS_export';
|
|
20
18
|
exports.ModelProps = '__VLS_ModelProps';
|
|
21
19
|
exports.Props = '__VLS_Props';
|
|
@@ -30,5 +28,4 @@ exports.Emit = '__VLS_Emit';
|
|
|
30
28
|
exports.SetupExposed = '__VLS_SetupExposed';
|
|
31
29
|
exports.PublicProps = '__VLS_PublicProps';
|
|
32
30
|
exports.StyleModules = '__VLS_StyleModules';
|
|
33
|
-
exports.PROPS_FALLBACK = '__VLS_PROPS_FALLBACK';
|
|
34
31
|
//# sourceMappingURL=names.js.map
|
|
@@ -1,21 +1,45 @@
|
|
|
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) {
|
|
9
|
-
|
|
10
|
-
&& options.scriptRanges?.componentOptions
|
|
11
|
-
&& options.scriptRanges.componentOptions.expression.start !== options.scriptRanges.componentOptions.args.start) {
|
|
12
|
-
// use defineComponent() from user space code if it exist
|
|
13
|
-
yield* (0, utils_1.generateSfcBlockSection)(options.script, options.scriptRanges.componentOptions.expression.start, options.scriptRanges.componentOptions.args.start, codeFeatures_1.codeFeatures.all);
|
|
14
|
-
yield `{${utils_1.newLine}`;
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
yield `(await import('${options.vueCompilerOptions.lib}')).defineComponent({${utils_1.newLine}`;
|
|
18
|
-
}
|
|
42
|
+
yield `(await import('${options.vueCompilerOptions.lib}')).defineComponent({${utils_1.newLine}`;
|
|
19
43
|
const returns = [];
|
|
20
44
|
if (scriptSetupRanges.defineExpose) {
|
|
21
45
|
returns.push([names.exposed]);
|
|
@@ -30,18 +54,14 @@ function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
30
54
|
yield* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, !!emitOptionCodes.length);
|
|
31
55
|
if (options.vueCompilerOptions.target >= 3.5
|
|
32
56
|
&& options.vueCompilerOptions.inferComponentDollarRefs
|
|
33
|
-
&& options.
|
|
57
|
+
&& options.templateAndStyleTypes.has(names.TemplateRefs)) {
|
|
34
58
|
yield `__typeRefs: {} as ${names.TemplateRefs},${utils_1.newLine}`;
|
|
35
59
|
}
|
|
36
60
|
if (options.vueCompilerOptions.target >= 3.5
|
|
37
61
|
&& options.vueCompilerOptions.inferComponentDollarEl
|
|
38
|
-
&& options.
|
|
62
|
+
&& options.templateAndStyleTypes.has(names.RootEl)) {
|
|
39
63
|
yield `__typeEl: {} as ${names.RootEl},${utils_1.newLine}`;
|
|
40
64
|
}
|
|
41
|
-
if (options.script && options.scriptRanges?.componentOptions?.args) {
|
|
42
|
-
const { args } = options.scriptRanges.componentOptions;
|
|
43
|
-
yield* (0, utils_1.generateSfcBlockSection)(options.script, args.start + 1, args.end - 1, codeFeatures_1.codeFeatures.all);
|
|
44
|
-
}
|
|
45
65
|
yield `})`;
|
|
46
66
|
}
|
|
47
67
|
function* generateEmitsOption(options, scriptSetupRanges) {
|
|
@@ -75,7 +95,7 @@ function* generateEmitsOption(options, scriptSetupRanges) {
|
|
|
75
95
|
function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasEmitsOption) {
|
|
76
96
|
const optionGenerates = [];
|
|
77
97
|
const typeOptionGenerates = [];
|
|
78
|
-
if (options.
|
|
98
|
+
if (options.templateAndStyleTypes.has(names.InheritedAttrs)) {
|
|
79
99
|
const attrsType = hasEmitsOption
|
|
80
100
|
? `Omit<${names.InheritedAttrs}, keyof ${names.EmitProps}>`
|
|
81
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,124 +49,153 @@ 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;
|
|
82
|
+
const { exportDefault } = scriptRanges;
|
|
32
83
|
if (exportDefault) {
|
|
33
|
-
|
|
34
|
-
yield* (0, utils_1.generateSfcBlockSection)(script, 0, options.start, codeFeatures_1.codeFeatures.all);
|
|
35
|
-
yield exportExpression;
|
|
36
|
-
yield* (0, utils_1.generateSfcBlockSection)(script, options.end, script.content.length, codeFeatures_1.codeFeatures.all);
|
|
84
|
+
yield* generateScriptWithExportDefault(ctx, script, scriptRanges, exportDefault, vueCompilerOptions, selfType = '__VLS_self');
|
|
37
85
|
}
|
|
38
86
|
else {
|
|
39
87
|
yield* (0, utils_1.generateSfcBlockSection)(script, 0, script.content.length, codeFeatures_1.codeFeatures.all);
|
|
40
88
|
yield `export default ${exportExpression}${utils_1.endOfLine}`;
|
|
41
89
|
}
|
|
42
90
|
// <script setup>
|
|
43
|
-
yield* generateExportDeclareEqual(scriptSetup);
|
|
91
|
+
yield* generateExportDeclareEqual(scriptSetup, names._export);
|
|
44
92
|
if (scriptSetup.generic) {
|
|
45
|
-
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)));
|
|
93
|
+
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, selfType)));
|
|
46
94
|
}
|
|
47
95
|
else {
|
|
48
96
|
yield `await (async () => {${utils_1.newLine}`;
|
|
49
|
-
yield* (0, scriptSetup_1.generateSetupFunction)(options, ctx, scriptSetup, scriptSetupRanges, (0, template_1.generateTemplate)(options, ctx), [`return `]);
|
|
97
|
+
yield* (0, scriptSetup_1.generateSetupFunction)(options, ctx, scriptSetup, scriptSetupRanges, (0, template_1.generateTemplate)(options, ctx, selfType), [`return `]);
|
|
50
98
|
yield `})()${utils_1.endOfLine}`;
|
|
51
99
|
}
|
|
52
100
|
}
|
|
53
101
|
// only <script setup>
|
|
54
102
|
else if (scriptSetup && scriptSetupRanges) {
|
|
103
|
+
yield* (0, scriptSetup_1.generateScriptSetupImports)(scriptSetup, scriptSetupRanges);
|
|
55
104
|
if (scriptSetup.generic) {
|
|
56
|
-
yield* generateExportDeclareEqual(scriptSetup);
|
|
105
|
+
yield* generateExportDeclareEqual(scriptSetup, names._export);
|
|
57
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)));
|
|
58
107
|
}
|
|
59
108
|
else {
|
|
60
109
|
// no script block, generate script setup code at root
|
|
61
|
-
yield* (0, scriptSetup_1.generateSetupFunction)(options, ctx, scriptSetup, scriptSetupRanges, (0, template_1.generateTemplate)(options, ctx), generateExportDeclareEqual(scriptSetup));
|
|
110
|
+
yield* (0, scriptSetup_1.generateSetupFunction)(options, ctx, scriptSetup, scriptSetupRanges, (0, template_1.generateTemplate)(options, ctx), generateExportDeclareEqual(scriptSetup, names._export));
|
|
62
111
|
}
|
|
63
112
|
yield `export default ${exportExpression}${utils_1.endOfLine}`;
|
|
64
113
|
}
|
|
65
114
|
// only <script>
|
|
66
115
|
else if (script && scriptRanges) {
|
|
67
|
-
const { exportDefault
|
|
116
|
+
const { exportDefault } = scriptRanges;
|
|
68
117
|
if (exportDefault) {
|
|
69
|
-
|
|
70
|
-
let wrapLeft;
|
|
71
|
-
let wrapRight;
|
|
72
|
-
if (script.content[expression.start] === '{'
|
|
73
|
-
&& vueCompilerOptions.optionsWrapper.length) {
|
|
74
|
-
[wrapLeft, wrapRight] = vueCompilerOptions.optionsWrapper;
|
|
75
|
-
ctx.inlayHints.push({
|
|
76
|
-
blockName: script.name,
|
|
77
|
-
offset: expression.start,
|
|
78
|
-
setting: 'vue.inlayHints.optionsWrapper',
|
|
79
|
-
label: wrapLeft || '[Missing optionsWrapper[0]]',
|
|
80
|
-
tooltip: [
|
|
81
|
-
'This is virtual code that is automatically wrapped for type support, it does not affect your runtime behavior, you can customize it via `vueCompilerOptions.optionsWrapper` option in tsconfig / jsconfig.',
|
|
82
|
-
'To hide it, you can set `"vue.inlayHints.optionsWrapper": false` in IDE settings.',
|
|
83
|
-
].join('\n\n'),
|
|
84
|
-
}, {
|
|
85
|
-
blockName: script.name,
|
|
86
|
-
offset: expression.end,
|
|
87
|
-
setting: 'vue.inlayHints.optionsWrapper',
|
|
88
|
-
label: wrapRight || '[Missing optionsWrapper[1]]',
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
yield* (0, utils_1.generateSfcBlockSection)(script, 0, exportDefault.start, codeFeatures_1.codeFeatures.all);
|
|
92
|
-
yield* generateExportDeclareEqual(script);
|
|
93
|
-
if (wrapLeft) {
|
|
94
|
-
yield wrapLeft;
|
|
95
|
-
}
|
|
96
|
-
yield* (0, utils_1.generateSfcBlockSection)(script, expression.start, expression.end, codeFeatures_1.codeFeatures.all);
|
|
97
|
-
if (wrapRight) {
|
|
98
|
-
yield wrapRight;
|
|
99
|
-
}
|
|
100
|
-
yield utils_1.endOfLine;
|
|
101
|
-
yield* (0, template_1.generateTemplate)(options, ctx);
|
|
102
|
-
yield* (0, utils_1.generateSfcBlockSection)(script, exportDefault.start, expression.start, codeFeatures_1.codeFeatures.all);
|
|
103
|
-
yield exportExpression;
|
|
104
|
-
yield* (0, utils_1.generateSfcBlockSection)(script, expression.end, script.content.length, codeFeatures_1.codeFeatures.all);
|
|
118
|
+
yield* generateScriptWithExportDefault(ctx, script, scriptRanges, exportDefault, vueCompilerOptions, names._export, (0, template_1.generateTemplate)(options, ctx, names._export));
|
|
105
119
|
}
|
|
106
120
|
else {
|
|
107
121
|
yield* (0, utils_1.generateSfcBlockSection)(script, 0, script.content.length, codeFeatures_1.codeFeatures.all);
|
|
108
|
-
yield* generateExportDeclareEqual(script);
|
|
122
|
+
yield* generateExportDeclareEqual(script, names._export);
|
|
109
123
|
yield `(await import('${vueCompilerOptions.lib}')).defineComponent({})${utils_1.endOfLine}`;
|
|
110
|
-
yield* (0, template_1.generateTemplate)(options, ctx);
|
|
124
|
+
yield* (0, template_1.generateTemplate)(options, ctx, names._export);
|
|
111
125
|
yield `export default ${exportExpression}${utils_1.endOfLine}`;
|
|
112
126
|
}
|
|
113
127
|
}
|
|
114
128
|
yield* ctx.localTypes.generate();
|
|
115
129
|
}
|
|
116
|
-
function*
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
130
|
+
function* generateScriptWithExportDefault(ctx, script, scriptRanges, exportDefault, vueCompilerOptions, varName, templateGenerator) {
|
|
131
|
+
const componentOptions = scriptRanges.exportDefault?.options;
|
|
132
|
+
const { expression, isObjectLiteral } = componentOptions ?? exportDefault;
|
|
133
|
+
let wrapLeft;
|
|
134
|
+
let wrapRight;
|
|
135
|
+
if (isObjectLiteral
|
|
136
|
+
&& vueCompilerOptions.optionsWrapper.length) {
|
|
137
|
+
[wrapLeft, wrapRight] = vueCompilerOptions.optionsWrapper;
|
|
138
|
+
ctx.inlayHints.push({
|
|
139
|
+
blockName: script.name,
|
|
140
|
+
offset: expression.start,
|
|
141
|
+
setting: 'vue.inlayHints.optionsWrapper',
|
|
142
|
+
label: wrapLeft || '[Missing optionsWrapper[0]]',
|
|
143
|
+
tooltip: [
|
|
144
|
+
'This is virtual code that is automatically wrapped for type support, it does not affect your runtime behavior, you can customize it via `vueCompilerOptions.optionsWrapper` option in tsconfig / jsconfig.',
|
|
145
|
+
'To hide it, you can set `"vue.inlayHints.optionsWrapper": false` in IDE settings.',
|
|
146
|
+
].join('\n\n'),
|
|
147
|
+
}, {
|
|
148
|
+
blockName: script.name,
|
|
149
|
+
offset: expression.end,
|
|
150
|
+
setting: 'vue.inlayHints.optionsWrapper',
|
|
151
|
+
label: wrapRight || '[Missing optionsWrapper[1]]',
|
|
152
|
+
});
|
|
120
153
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
154
|
+
yield* (0, utils_1.generateSfcBlockSection)(script, 0, expression.start, codeFeatures_1.codeFeatures.all);
|
|
155
|
+
yield exportExpression;
|
|
156
|
+
yield* (0, utils_1.generateSfcBlockSection)(script, expression.end, exportDefault.end, codeFeatures_1.codeFeatures.all);
|
|
157
|
+
yield utils_1.endOfLine;
|
|
158
|
+
if (templateGenerator) {
|
|
159
|
+
yield* templateGenerator;
|
|
160
|
+
}
|
|
161
|
+
yield* generateExportDeclareEqual(script, varName);
|
|
162
|
+
if (wrapLeft && wrapRight) {
|
|
163
|
+
yield wrapLeft;
|
|
164
|
+
yield* (0, utils_1.generateSfcBlockSection)(script, expression.start, expression.end, codeFeatures_1.codeFeatures.all);
|
|
165
|
+
yield wrapRight;
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
yield* (0, utils_1.generateSfcBlockSection)(script, expression.start, expression.end, codeFeatures_1.codeFeatures.all);
|
|
169
|
+
}
|
|
170
|
+
yield utils_1.endOfLine;
|
|
171
|
+
yield* (0, utils_1.generateSfcBlockSection)(script, exportDefault.end, script.content.length, codeFeatures_1.codeFeatures.all);
|
|
172
|
+
}
|
|
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
|
|
124
178
|
&& !relativePath.startsWith('./')
|
|
125
179
|
&& !relativePath.startsWith('../')) {
|
|
126
180
|
relativePath = './' + relativePath;
|
|
127
181
|
}
|
|
128
|
-
|
|
182
|
+
typesPath = relativePath;
|
|
129
183
|
}
|
|
130
184
|
else {
|
|
131
|
-
|
|
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}`;
|
|
132
193
|
}
|
|
133
194
|
}
|
|
134
|
-
function* generateExportDeclareEqual(block) {
|
|
195
|
+
function* generateExportDeclareEqual(block, name) {
|
|
135
196
|
yield `const `;
|
|
136
197
|
const token = yield* (0, boundary_1.startBoundary)(block.name, 0, codeFeatures_1.codeFeatures.doNotReportTs6133);
|
|
137
|
-
yield
|
|
198
|
+
yield name;
|
|
138
199
|
yield (0, boundary_1.endBoundary)(token, block.content.length);
|
|
139
200
|
yield ` = `;
|
|
140
201
|
}
|