@vue/language-core 3.2.7 → 3.2.8
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 +2 -23
- package/lib/codegen/names.d.ts +73 -26
- package/lib/codegen/names.js +75 -27
- package/lib/codegen/script/component.js +19 -58
- package/lib/codegen/script/index.js +12 -12
- package/lib/codegen/script/scriptSetup.js +48 -81
- package/lib/codegen/script/template.js +29 -63
- package/lib/codegen/style/modules.js +4 -37
- package/lib/codegen/style/scopedClasses.js +2 -1
- package/lib/codegen/template/element.js +28 -25
- package/lib/codegen/template/elementDirectives.js +4 -4
- package/lib/codegen/template/elementEvents.js +3 -2
- package/lib/codegen/template/elementProps.js +3 -3
- package/lib/codegen/template/index.js +16 -49
- package/lib/codegen/template/interpolation.js +3 -36
- package/lib/codegen/template/objectProperty.js +2 -1
- package/lib/codegen/template/slotOutlet.js +5 -5
- package/lib/codegen/template/styleScopedClasses.js +3 -2
- package/lib/codegen/template/vFor.js +2 -1
- package/lib/codegen/template/vSlot.js +2 -1
- package/lib/plugins/file-md.js +2 -2
- package/lib/plugins/vue-tsx.js +5 -22
- package/package.json +5 -2
- package/scripts/generate-names.js +41 -0
package/index.d.ts
CHANGED
|
@@ -10,6 +10,6 @@ export * from './lib/utils/forEachTemplateNode';
|
|
|
10
10
|
export * from './lib/utils/parseSfc';
|
|
11
11
|
export * from './lib/utils/shared';
|
|
12
12
|
export * from './lib/virtualCode';
|
|
13
|
-
export
|
|
13
|
+
export { names } from './lib/codegen/names';
|
|
14
14
|
export { tsCodegen } from './lib/plugins/vue-tsx';
|
|
15
15
|
export * from '@volar/language-core';
|
package/index.js
CHANGED
|
@@ -10,31 +10,9 @@ 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
|
-
});
|
|
18
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
15
|
};
|
|
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
|
-
})();
|
|
38
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
17
|
exports.tsCodegen = exports.names = void 0;
|
|
40
18
|
__exportStar(require("./lib/codegen/template"), exports);
|
|
@@ -49,7 +27,8 @@ __exportStar(require("./lib/utils/forEachTemplateNode"), exports);
|
|
|
49
27
|
__exportStar(require("./lib/utils/parseSfc"), exports);
|
|
50
28
|
__exportStar(require("./lib/utils/shared"), exports);
|
|
51
29
|
__exportStar(require("./lib/virtualCode"), exports);
|
|
52
|
-
|
|
30
|
+
var names_1 = require("./lib/codegen/names");
|
|
31
|
+
Object.defineProperty(exports, "names", { enumerable: true, get: function () { return names_1.names; } });
|
|
53
32
|
var vue_tsx_1 = require("./lib/plugins/vue-tsx");
|
|
54
33
|
Object.defineProperty(exports, "tsCodegen", { enumerable: true, get: function () { return vue_tsx_1.tsCodegen; } });
|
|
55
34
|
__exportStar(require("@volar/language-core"), exports);
|
package/lib/codegen/names.d.ts
CHANGED
|
@@ -1,26 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
1
|
+
declare const raw: {
|
|
2
|
+
base: string;
|
|
3
|
+
export: string;
|
|
4
|
+
components: string;
|
|
5
|
+
componentsOption: string;
|
|
6
|
+
ctx: string;
|
|
7
|
+
defaultModels: string;
|
|
8
|
+
defaults: string;
|
|
9
|
+
directives: string;
|
|
10
|
+
directivesOption: string;
|
|
11
|
+
dollars: string;
|
|
12
|
+
emit: string;
|
|
13
|
+
exposed: string;
|
|
14
|
+
intrinsics: string;
|
|
15
|
+
modelEmit: string;
|
|
16
|
+
props: string;
|
|
17
|
+
propsOption: string;
|
|
18
|
+
self: string;
|
|
19
|
+
setup: string;
|
|
20
|
+
slots: string;
|
|
21
|
+
src: string;
|
|
22
|
+
Emit: string;
|
|
23
|
+
EmitProps: string;
|
|
24
|
+
GlobalComponents: string;
|
|
25
|
+
InheritedAttrs: string;
|
|
26
|
+
LocalComponents: string;
|
|
27
|
+
LocalDirectives: string;
|
|
28
|
+
ModelEmit: string;
|
|
29
|
+
ModelProps: string;
|
|
30
|
+
Props: string;
|
|
31
|
+
PublicProps: string;
|
|
32
|
+
RootEl: string;
|
|
33
|
+
SetupExposed: string;
|
|
34
|
+
Slots: string;
|
|
35
|
+
StyleModules: string;
|
|
36
|
+
StyleScopedClasses: string;
|
|
37
|
+
TemplateRefs: string;
|
|
38
|
+
asFunctionalComponent0: string;
|
|
39
|
+
asFunctionalComponent1: string;
|
|
40
|
+
asFunctionalDirective: string;
|
|
41
|
+
asFunctionalElement0: string;
|
|
42
|
+
asFunctionalElement1: string;
|
|
43
|
+
asFunctionalSlot: string;
|
|
44
|
+
directiveBindingRestFields: string;
|
|
45
|
+
functionalComponentArgsRest: string;
|
|
46
|
+
tryAsConstant: string;
|
|
47
|
+
vFor: string;
|
|
48
|
+
vSlot: string;
|
|
49
|
+
ConstructorOverloads: string;
|
|
50
|
+
Elements: string;
|
|
51
|
+
EmitsToProps: string;
|
|
52
|
+
FunctionalComponent0: string;
|
|
53
|
+
FunctionalComponent1: string;
|
|
54
|
+
FunctionalComponentCtx: string;
|
|
55
|
+
FunctionalComponentProps: string;
|
|
56
|
+
IsAny: string;
|
|
57
|
+
IsFunction: string;
|
|
58
|
+
NormalizeComponentEvent: string;
|
|
59
|
+
NormalizeEmits: string;
|
|
60
|
+
OverloadUnion: string;
|
|
61
|
+
OverloadUnionInner: string;
|
|
62
|
+
PickNotAny: string;
|
|
63
|
+
PrettifyGlobal: string;
|
|
64
|
+
ResolveDirectives: string;
|
|
65
|
+
ResolveEmits: string;
|
|
66
|
+
ShortEmits: string;
|
|
67
|
+
ShortEmitsToObject: string;
|
|
68
|
+
SpreadMerge: string;
|
|
69
|
+
UnionToIntersection: string;
|
|
70
|
+
WithComponent: string;
|
|
71
|
+
};
|
|
72
|
+
export declare const names: typeof raw;
|
|
73
|
+
export {};
|
package/lib/codegen/names.js
CHANGED
|
@@ -1,30 +1,78 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
3
|
+
exports.names = void 0;
|
|
4
|
+
const raw = {
|
|
5
|
+
base: '',
|
|
6
|
+
export: '',
|
|
7
|
+
components: '',
|
|
8
|
+
componentsOption: '',
|
|
9
|
+
ctx: '',
|
|
10
|
+
defaultModels: '',
|
|
11
|
+
defaults: '',
|
|
12
|
+
directives: '',
|
|
13
|
+
directivesOption: '',
|
|
14
|
+
dollars: '',
|
|
15
|
+
emit: '',
|
|
16
|
+
exposed: '',
|
|
17
|
+
intrinsics: '',
|
|
18
|
+
modelEmit: '',
|
|
19
|
+
props: '',
|
|
20
|
+
propsOption: '',
|
|
21
|
+
self: '',
|
|
22
|
+
setup: '',
|
|
23
|
+
slots: '',
|
|
24
|
+
src: '',
|
|
25
|
+
Emit: '',
|
|
26
|
+
EmitProps: '',
|
|
27
|
+
GlobalComponents: '',
|
|
28
|
+
InheritedAttrs: '',
|
|
29
|
+
LocalComponents: '',
|
|
30
|
+
LocalDirectives: '',
|
|
31
|
+
ModelEmit: '',
|
|
32
|
+
ModelProps: '',
|
|
33
|
+
Props: '',
|
|
34
|
+
PublicProps: '',
|
|
35
|
+
RootEl: '',
|
|
36
|
+
SetupExposed: '',
|
|
37
|
+
Slots: '',
|
|
38
|
+
StyleModules: '',
|
|
39
|
+
StyleScopedClasses: '',
|
|
40
|
+
TemplateRefs: '',
|
|
41
|
+
// #region template helpers
|
|
42
|
+
asFunctionalComponent0: '',
|
|
43
|
+
asFunctionalComponent1: '',
|
|
44
|
+
asFunctionalDirective: '',
|
|
45
|
+
asFunctionalElement0: '',
|
|
46
|
+
asFunctionalElement1: '',
|
|
47
|
+
asFunctionalSlot: '',
|
|
48
|
+
directiveBindingRestFields: '',
|
|
49
|
+
functionalComponentArgsRest: '',
|
|
50
|
+
tryAsConstant: '',
|
|
51
|
+
vFor: '',
|
|
52
|
+
vSlot: '',
|
|
53
|
+
ConstructorOverloads: '',
|
|
54
|
+
Elements: '',
|
|
55
|
+
EmitsToProps: '',
|
|
56
|
+
FunctionalComponent0: '',
|
|
57
|
+
FunctionalComponent1: '',
|
|
58
|
+
FunctionalComponentCtx: '',
|
|
59
|
+
FunctionalComponentProps: '',
|
|
60
|
+
IsAny: '',
|
|
61
|
+
IsFunction: '',
|
|
62
|
+
NormalizeComponentEvent: '',
|
|
63
|
+
NormalizeEmits: '',
|
|
64
|
+
OverloadUnion: '',
|
|
65
|
+
OverloadUnionInner: '',
|
|
66
|
+
PickNotAny: '',
|
|
67
|
+
PrettifyGlobal: '',
|
|
68
|
+
ResolveDirectives: '',
|
|
69
|
+
ResolveEmits: '',
|
|
70
|
+
ShortEmits: '',
|
|
71
|
+
ShortEmitsToObject: '',
|
|
72
|
+
SpreadMerge: '',
|
|
73
|
+
UnionToIntersection: '',
|
|
74
|
+
WithComponent: '',
|
|
75
|
+
// #endregion
|
|
76
|
+
};
|
|
77
|
+
exports.names = Object.fromEntries(Object.keys(raw).map(key => [key, `__VLS_${key}`]));
|
|
30
78
|
//# sourceMappingURL=names.js.map
|
|
@@ -1,66 +1,27 @@
|
|
|
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
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.generateComponent = generateComponent;
|
|
37
4
|
const codeFeatures_1 = require("../codeFeatures");
|
|
38
|
-
const
|
|
5
|
+
const names_1 = require("../names");
|
|
39
6
|
const utils_1 = require("../utils");
|
|
40
7
|
const merge_1 = require("../utils/merge");
|
|
41
8
|
function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
42
9
|
yield `(await import('${options.vueCompilerOptions.lib}')).defineComponent({${utils_1.newLine}`;
|
|
43
|
-
const returns = [];
|
|
44
10
|
if (scriptSetupRanges.defineExpose) {
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
if (returns.length) {
|
|
48
|
-
yield `setup: () => (`;
|
|
49
|
-
yield* (0, merge_1.generateSpreadMerge)(returns);
|
|
50
|
-
yield `),${utils_1.newLine}`;
|
|
11
|
+
yield `setup: () => ${names_1.names.exposed},${utils_1.newLine}`;
|
|
51
12
|
}
|
|
52
13
|
const emitOptionCodes = [...generateEmitsOption(options, scriptSetupRanges)];
|
|
53
14
|
yield* emitOptionCodes;
|
|
54
15
|
yield* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, !!emitOptionCodes.length);
|
|
55
16
|
if (options.vueCompilerOptions.target >= 3.5
|
|
56
17
|
&& options.vueCompilerOptions.inferComponentDollarRefs
|
|
57
|
-
&& options.templateAndStyleTypes.has(names.TemplateRefs)) {
|
|
58
|
-
yield `__typeRefs: {} as ${names.TemplateRefs},${utils_1.newLine}`;
|
|
18
|
+
&& options.templateAndStyleTypes.has(names_1.names.TemplateRefs)) {
|
|
19
|
+
yield `__typeRefs: {} as ${names_1.names.TemplateRefs},${utils_1.newLine}`;
|
|
59
20
|
}
|
|
60
21
|
if (options.vueCompilerOptions.target >= 3.5
|
|
61
22
|
&& options.vueCompilerOptions.inferComponentDollarEl
|
|
62
|
-
&& options.templateAndStyleTypes.has(names.RootEl)) {
|
|
63
|
-
yield `__typeEl: {} as ${names.RootEl},${utils_1.newLine}`;
|
|
23
|
+
&& options.templateAndStyleTypes.has(names_1.names.RootEl)) {
|
|
24
|
+
yield `__typeEl: {} as ${names_1.names.RootEl},${utils_1.newLine}`;
|
|
64
25
|
}
|
|
65
26
|
yield `})`;
|
|
66
27
|
}
|
|
@@ -68,14 +29,14 @@ function* generateEmitsOption(options, scriptSetupRanges) {
|
|
|
68
29
|
const optionCodes = [];
|
|
69
30
|
const typeOptionCodes = [];
|
|
70
31
|
if (scriptSetupRanges.defineModel.length) {
|
|
71
|
-
optionCodes.push([`{} as
|
|
72
|
-
typeOptionCodes.push([names.ModelEmit]);
|
|
32
|
+
optionCodes.push([`{} as ${names_1.names.NormalizeEmits}<typeof ${names_1.names.modelEmit}>`]);
|
|
33
|
+
typeOptionCodes.push([names_1.names.ModelEmit]);
|
|
73
34
|
}
|
|
74
35
|
if (scriptSetupRanges.defineEmits) {
|
|
75
36
|
const { name, typeArg, hasUnionTypeArg } = scriptSetupRanges.defineEmits;
|
|
76
|
-
optionCodes.push([`{} as
|
|
37
|
+
optionCodes.push([`{} as ${names_1.names.NormalizeEmits}<typeof ${name ?? names_1.names.emit}>`]);
|
|
77
38
|
if (typeArg && !hasUnionTypeArg) {
|
|
78
|
-
typeOptionCodes.push([names.Emit]);
|
|
39
|
+
typeOptionCodes.push([names_1.names.Emit]);
|
|
79
40
|
}
|
|
80
41
|
else {
|
|
81
42
|
typeOptionCodes.length = 0;
|
|
@@ -95,12 +56,12 @@ function* generateEmitsOption(options, scriptSetupRanges) {
|
|
|
95
56
|
function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasEmitsOption) {
|
|
96
57
|
const optionGenerates = [];
|
|
97
58
|
const typeOptionGenerates = [];
|
|
98
|
-
if (options.templateAndStyleTypes.has(names.InheritedAttrs)) {
|
|
59
|
+
if (options.templateAndStyleTypes.has(names_1.names.InheritedAttrs)) {
|
|
99
60
|
const attrsType = hasEmitsOption
|
|
100
|
-
? `Omit<${names.InheritedAttrs}, keyof ${names.EmitProps}>`
|
|
101
|
-
: names.InheritedAttrs;
|
|
61
|
+
? `Omit<${names_1.names.InheritedAttrs}, keyof ${names_1.names.EmitProps}>`
|
|
62
|
+
: names_1.names.InheritedAttrs;
|
|
102
63
|
optionGenerates.push(function* () {
|
|
103
|
-
const propsType =
|
|
64
|
+
const propsType = `${names_1.names.PickNotAny}<${ctx.localTypes.OmitIndexSignature}<${attrsType}>, {}>`;
|
|
104
65
|
const optionType = `${ctx.localTypes.TypePropsToOption}<${propsType}>`;
|
|
105
66
|
yield `{} as ${optionType}`;
|
|
106
67
|
});
|
|
@@ -108,18 +69,18 @@ function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasE
|
|
|
108
69
|
yield `{} as ${attrsType}`;
|
|
109
70
|
});
|
|
110
71
|
}
|
|
111
|
-
if (ctx.generatedTypes.has(names.PublicProps)) {
|
|
72
|
+
if (ctx.generatedTypes.has(names_1.names.PublicProps)) {
|
|
112
73
|
if (options.vueCompilerOptions.target < 3.6) {
|
|
113
74
|
optionGenerates.push(function* () {
|
|
114
|
-
let propsType = `${ctx.localTypes.TypePropsToOption}<${names.PublicProps}>`;
|
|
75
|
+
let propsType = `${ctx.localTypes.TypePropsToOption}<${names_1.names.PublicProps}>`;
|
|
115
76
|
if (scriptSetupRanges.withDefaults?.arg) {
|
|
116
|
-
propsType = `${ctx.localTypes.WithDefaults}<${propsType}, typeof ${names.defaults}>`;
|
|
77
|
+
propsType = `${ctx.localTypes.WithDefaults}<${propsType}, typeof ${names_1.names.defaults}>`;
|
|
117
78
|
}
|
|
118
79
|
yield `{} as ${propsType}`;
|
|
119
80
|
});
|
|
120
81
|
}
|
|
121
82
|
typeOptionGenerates.push(function* () {
|
|
122
|
-
yield `{} as ${names.PublicProps}`;
|
|
83
|
+
yield `{} as ${names_1.names.PublicProps}`;
|
|
123
84
|
});
|
|
124
85
|
}
|
|
125
86
|
if (scriptSetupRanges.defineProps?.arg) {
|
|
@@ -132,7 +93,7 @@ function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasE
|
|
|
132
93
|
if (useTypeOption) {
|
|
133
94
|
if (options.vueCompilerOptions.target >= 3.6
|
|
134
95
|
&& scriptSetupRanges.withDefaults?.arg) {
|
|
135
|
-
yield `__defaults: ${names.defaults},${utils_1.newLine}`;
|
|
96
|
+
yield `__defaults: ${names_1.names.defaults},${utils_1.newLine}`;
|
|
136
97
|
}
|
|
137
98
|
yield `__typeProps: `;
|
|
138
99
|
yield* (0, merge_1.generateSpreadMerge)(typeOptionGenerates.map(g => g()));
|
|
@@ -36,13 +36,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.generateScript = generate;
|
|
37
37
|
const path = __importStar(require("path-browserify"));
|
|
38
38
|
const codeFeatures_1 = require("../codeFeatures");
|
|
39
|
-
const
|
|
39
|
+
const names_1 = require("../names");
|
|
40
40
|
const utils_1 = require("../utils");
|
|
41
41
|
const boundary_1 = require("../utils/boundary");
|
|
42
42
|
const context_1 = require("./context");
|
|
43
43
|
const scriptSetup_1 = require("./scriptSetup");
|
|
44
44
|
const template_1 = require("./template");
|
|
45
|
-
const exportExpression = `{} as typeof ${names.
|
|
45
|
+
const exportExpression = `{} as typeof ${names_1.names.export}`;
|
|
46
46
|
function generate(options) {
|
|
47
47
|
const ctx = (0, context_1.createScriptCodegenContext)(options);
|
|
48
48
|
const codeGenerator = generateWorker(options, ctx);
|
|
@@ -60,7 +60,7 @@ function* generateWorker(options, ctx) {
|
|
|
60
60
|
else if (src.endsWith('.tsx')) {
|
|
61
61
|
src = src.slice(0, -'.tsx'.length) + '.jsx';
|
|
62
62
|
}
|
|
63
|
-
yield `import
|
|
63
|
+
yield `import ${names_1.names.src} from `;
|
|
64
64
|
const token = yield* (0, boundary_1.startBoundary)('main', script.src.offset, {
|
|
65
65
|
...codeFeatures_1.codeFeatures.all,
|
|
66
66
|
...src !== script.src.text ? codeFeatures_1.codeFeatures.navigationWithoutRename : {},
|
|
@@ -71,8 +71,8 @@ function* generateWorker(options, ctx) {
|
|
|
71
71
|
yield `'`;
|
|
72
72
|
yield (0, boundary_1.endBoundary)(token, script.src.offset + script.src.text.length);
|
|
73
73
|
yield utils_1.endOfLine;
|
|
74
|
-
yield `export default
|
|
75
|
-
yield* (0, template_1.generateTemplate)(options, ctx,
|
|
74
|
+
yield `export default ${names_1.names.src}${utils_1.endOfLine}`;
|
|
75
|
+
yield* (0, template_1.generateTemplate)(options, ctx, names_1.names.src);
|
|
76
76
|
}
|
|
77
77
|
// <script> + <script setup>
|
|
78
78
|
else if (script && scriptRanges && scriptSetup && scriptSetupRanges) {
|
|
@@ -81,14 +81,14 @@ function* generateWorker(options, ctx) {
|
|
|
81
81
|
let selfType;
|
|
82
82
|
const { exportDefault } = scriptRanges;
|
|
83
83
|
if (exportDefault) {
|
|
84
|
-
yield* generateScriptWithExportDefault(ctx, script, scriptRanges, exportDefault, vueCompilerOptions, selfType =
|
|
84
|
+
yield* generateScriptWithExportDefault(ctx, script, scriptRanges, exportDefault, vueCompilerOptions, selfType = names_1.names.self);
|
|
85
85
|
}
|
|
86
86
|
else {
|
|
87
87
|
yield* (0, utils_1.generateSfcBlockSection)(script, 0, script.content.length, codeFeatures_1.codeFeatures.all);
|
|
88
88
|
yield `export default ${exportExpression}${utils_1.endOfLine}`;
|
|
89
89
|
}
|
|
90
90
|
// <script setup>
|
|
91
|
-
yield* generateExportDeclareEqual(scriptSetup, names.
|
|
91
|
+
yield* generateExportDeclareEqual(scriptSetup, names_1.names.export);
|
|
92
92
|
if (scriptSetup.generic) {
|
|
93
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)));
|
|
94
94
|
}
|
|
@@ -102,12 +102,12 @@ function* generateWorker(options, ctx) {
|
|
|
102
102
|
else if (scriptSetup && scriptSetupRanges) {
|
|
103
103
|
yield* (0, scriptSetup_1.generateScriptSetupImports)(scriptSetup, scriptSetupRanges);
|
|
104
104
|
if (scriptSetup.generic) {
|
|
105
|
-
yield* generateExportDeclareEqual(scriptSetup, names.
|
|
105
|
+
yield* generateExportDeclareEqual(scriptSetup, names_1.names.export);
|
|
106
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)));
|
|
107
107
|
}
|
|
108
108
|
else {
|
|
109
109
|
// no script block, generate script setup code at root
|
|
110
|
-
yield* (0, scriptSetup_1.generateSetupFunction)(options, ctx, scriptSetup, scriptSetupRanges, (0, template_1.generateTemplate)(options, ctx), generateExportDeclareEqual(scriptSetup, names.
|
|
110
|
+
yield* (0, scriptSetup_1.generateSetupFunction)(options, ctx, scriptSetup, scriptSetupRanges, (0, template_1.generateTemplate)(options, ctx), generateExportDeclareEqual(scriptSetup, names_1.names.export));
|
|
111
111
|
}
|
|
112
112
|
yield `export default ${exportExpression}${utils_1.endOfLine}`;
|
|
113
113
|
}
|
|
@@ -115,13 +115,13 @@ function* generateWorker(options, ctx) {
|
|
|
115
115
|
else if (script && scriptRanges) {
|
|
116
116
|
const { exportDefault } = scriptRanges;
|
|
117
117
|
if (exportDefault) {
|
|
118
|
-
yield* generateScriptWithExportDefault(ctx, script, scriptRanges, exportDefault, vueCompilerOptions, names.
|
|
118
|
+
yield* generateScriptWithExportDefault(ctx, script, scriptRanges, exportDefault, vueCompilerOptions, names_1.names.export, (0, template_1.generateTemplate)(options, ctx, names_1.names.export));
|
|
119
119
|
}
|
|
120
120
|
else {
|
|
121
121
|
yield* (0, utils_1.generateSfcBlockSection)(script, 0, script.content.length, codeFeatures_1.codeFeatures.all);
|
|
122
|
-
yield* generateExportDeclareEqual(script, names.
|
|
122
|
+
yield* generateExportDeclareEqual(script, names_1.names.export);
|
|
123
123
|
yield `(await import('${vueCompilerOptions.lib}')).defineComponent({})${utils_1.endOfLine}`;
|
|
124
|
-
yield* (0, template_1.generateTemplate)(options, ctx, names.
|
|
124
|
+
yield* (0, template_1.generateTemplate)(options, ctx, names_1.names.export);
|
|
125
125
|
yield `export default ${exportExpression}${utils_1.endOfLine}`;
|
|
126
126
|
}
|
|
127
127
|
}
|