@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/lib/parsers/utils.js
CHANGED
|
@@ -35,6 +35,9 @@ function parseBindingRanges(ts, ast, componentExtsensions) {
|
|
|
35
35
|
if (componentExtsensions.some(ext => moduleName.endsWith(ext))) {
|
|
36
36
|
components.push(_getStartEnd(name));
|
|
37
37
|
}
|
|
38
|
+
else {
|
|
39
|
+
bindings.push(_getStartEnd(name));
|
|
40
|
+
}
|
|
38
41
|
}
|
|
39
42
|
if (namedBindings) {
|
|
40
43
|
if (ts.isNamedImports(namedBindings)) {
|
|
@@ -82,6 +85,7 @@ function getClosestMultiLineCommentRange(ts, node, parents, ast) {
|
|
|
82
85
|
.find(range => range.kind === 3);
|
|
83
86
|
if (comment) {
|
|
84
87
|
return {
|
|
88
|
+
node,
|
|
85
89
|
start: comment.pos,
|
|
86
90
|
end: comment.end,
|
|
87
91
|
};
|
|
@@ -6,7 +6,7 @@ const plugin = ({ modules }) => {
|
|
|
6
6
|
compileSFCScript(lang, script) {
|
|
7
7
|
if (lang === 'js' || lang === 'ts' || lang === 'jsx' || lang === 'tsx') {
|
|
8
8
|
const ts = modules.typescript;
|
|
9
|
-
return ts.createSourceFile('
|
|
9
|
+
return ts.createSourceFile('.' + lang, script, 99);
|
|
10
10
|
}
|
|
11
11
|
},
|
|
12
12
|
};
|
|
@@ -1,6 +1,39 @@
|
|
|
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
|
-
const CompilerDOM = require("@vue/compiler-dom");
|
|
36
|
+
const CompilerDOM = __importStar(require("@vue/compiler-dom"));
|
|
4
37
|
const forEachTemplateNode_1 = require("../utils/forEachTemplateNode");
|
|
5
38
|
const shared_1 = require("../utils/shared");
|
|
6
39
|
const shared_2 = require("./shared");
|
|
@@ -1,6 +1,39 @@
|
|
|
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
|
-
const CompilerDOM = require("@vue/compiler-dom");
|
|
36
|
+
const CompilerDOM = __importStar(require("@vue/compiler-dom"));
|
|
4
37
|
const elementEvents_1 = require("../codegen/template/elementEvents");
|
|
5
38
|
const templateChild_1 = require("../codegen/template/templateChild");
|
|
6
39
|
const vFor_1 = require("../codegen/template/vFor");
|
package/lib/plugins/vue-tsx.d.ts
CHANGED
|
@@ -1,117 +1,40 @@
|
|
|
1
1
|
import type { Sfc, VueLanguagePlugin } from '../types';
|
|
2
2
|
export declare const tsCodegen: WeakMap<Sfc, {
|
|
3
3
|
getScriptRanges: () => {
|
|
4
|
-
exportDefault: (import("../types").TextRange & {
|
|
5
|
-
expression: import("../types").TextRange
|
|
4
|
+
exportDefault: (import("../types").TextRange<import("typescript").Node> & {
|
|
5
|
+
expression: import("../types").TextRange<import("typescript").Expression>;
|
|
6
|
+
isObjectLiteral: boolean;
|
|
7
|
+
options?: {
|
|
8
|
+
isObjectLiteral: boolean;
|
|
9
|
+
expression: import("../types").TextRange<import("typescript").Node>;
|
|
10
|
+
args: import("../types").TextRange<import("typescript").ObjectLiteralExpression>;
|
|
11
|
+
components: import("../types").TextRange<import("typescript").ObjectLiteralExpression> | undefined;
|
|
12
|
+
directives: import("../types").TextRange<import("typescript").Node> | undefined;
|
|
13
|
+
name: import("../types").TextRange<import("typescript").StringLiteral> | undefined;
|
|
14
|
+
inheritAttrs: string | undefined;
|
|
15
|
+
} | undefined;
|
|
6
16
|
}) | undefined;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
args: import("../types").TextRange;
|
|
10
|
-
argsNode: import("typescript").ObjectLiteralExpression;
|
|
11
|
-
components: import("../types").TextRange | undefined;
|
|
12
|
-
componentsNode: import("typescript").ObjectLiteralExpression | undefined;
|
|
13
|
-
directives: import("../types").TextRange | undefined;
|
|
14
|
-
name: import("../types").TextRange | undefined;
|
|
15
|
-
inheritAttrs: string | undefined;
|
|
16
|
-
} | undefined;
|
|
17
|
-
bindings: import("../types").TextRange[];
|
|
18
|
-
components: import("../types").TextRange[];
|
|
17
|
+
bindings: import("../types").TextRange<import("typescript").Node>[];
|
|
18
|
+
components: import("../types").TextRange<import("typescript").Node>[];
|
|
19
19
|
} | undefined;
|
|
20
20
|
getScriptSetupRanges: () => {
|
|
21
21
|
leadingCommentEndOffset: number;
|
|
22
22
|
importSectionEndOffset: number;
|
|
23
|
-
bindings: import("../types").TextRange[];
|
|
24
|
-
components: import("../types").TextRange[];
|
|
25
|
-
defineModel:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
defineProps: ({
|
|
37
|
-
callExp: import("../types").TextRange;
|
|
38
|
-
exp: import("../types").TextRange;
|
|
39
|
-
arg?: import("../types").TextRange;
|
|
40
|
-
typeArg?: import("../types").TextRange;
|
|
41
|
-
} & {
|
|
42
|
-
name?: string;
|
|
43
|
-
destructured?: Map<string, import("typescript").Expression | undefined>;
|
|
44
|
-
destructuredRest?: string;
|
|
45
|
-
statement: import("../types").TextRange;
|
|
46
|
-
argNode?: import("typescript").Expression;
|
|
47
|
-
}) | undefined;
|
|
48
|
-
withDefaults: (Omit<{
|
|
49
|
-
callExp: import("../types").TextRange;
|
|
50
|
-
exp: import("../types").TextRange;
|
|
51
|
-
arg?: import("../types").TextRange;
|
|
52
|
-
typeArg?: import("../types").TextRange;
|
|
53
|
-
}, "typeArg"> & {
|
|
54
|
-
argNode?: import("typescript").Expression;
|
|
55
|
-
}) | undefined;
|
|
56
|
-
defineEmits: ({
|
|
57
|
-
callExp: import("../types").TextRange;
|
|
58
|
-
exp: import("../types").TextRange;
|
|
59
|
-
arg?: import("../types").TextRange;
|
|
60
|
-
typeArg?: import("../types").TextRange;
|
|
61
|
-
} & {
|
|
62
|
-
name?: string;
|
|
63
|
-
hasUnionTypeArg?: boolean;
|
|
64
|
-
statement: import("../types").TextRange;
|
|
65
|
-
}) | undefined;
|
|
66
|
-
defineSlots: ({
|
|
67
|
-
callExp: import("../types").TextRange;
|
|
68
|
-
exp: import("../types").TextRange;
|
|
69
|
-
arg?: import("../types").TextRange;
|
|
70
|
-
typeArg?: import("../types").TextRange;
|
|
71
|
-
} & {
|
|
72
|
-
name?: string;
|
|
73
|
-
statement: import("../types").TextRange;
|
|
74
|
-
}) | undefined;
|
|
75
|
-
defineExpose: {
|
|
76
|
-
callExp: import("../types").TextRange;
|
|
77
|
-
exp: import("../types").TextRange;
|
|
78
|
-
arg?: import("../types").TextRange;
|
|
79
|
-
typeArg?: import("../types").TextRange;
|
|
80
|
-
} | undefined;
|
|
81
|
-
defineOptions: {
|
|
82
|
-
name?: string;
|
|
83
|
-
inheritAttrs?: string;
|
|
84
|
-
} | undefined;
|
|
85
|
-
useAttrs: {
|
|
86
|
-
callExp: import("../types").TextRange;
|
|
87
|
-
exp: import("../types").TextRange;
|
|
88
|
-
arg?: import("../types").TextRange;
|
|
89
|
-
typeArg?: import("../types").TextRange;
|
|
90
|
-
}[];
|
|
91
|
-
useCssModule: {
|
|
92
|
-
callExp: import("../types").TextRange;
|
|
93
|
-
exp: import("../types").TextRange;
|
|
94
|
-
arg?: import("../types").TextRange;
|
|
95
|
-
typeArg?: import("../types").TextRange;
|
|
96
|
-
}[];
|
|
97
|
-
useSlots: {
|
|
98
|
-
callExp: import("../types").TextRange;
|
|
99
|
-
exp: import("../types").TextRange;
|
|
100
|
-
arg?: import("../types").TextRange;
|
|
101
|
-
typeArg?: import("../types").TextRange;
|
|
102
|
-
}[];
|
|
103
|
-
useTemplateRef: ({
|
|
104
|
-
callExp: import("../types").TextRange;
|
|
105
|
-
exp: import("../types").TextRange;
|
|
106
|
-
arg?: import("../types").TextRange;
|
|
107
|
-
typeArg?: import("../types").TextRange;
|
|
108
|
-
} & {
|
|
109
|
-
name?: string;
|
|
110
|
-
})[];
|
|
23
|
+
bindings: import("../types").TextRange<import("typescript").Node>[];
|
|
24
|
+
components: import("../types").TextRange<import("typescript").Node>[];
|
|
25
|
+
defineModel: import("../parsers/scriptSetupRanges").DefineModel[];
|
|
26
|
+
defineProps: import("../parsers/scriptSetupRanges").DefineProps | undefined;
|
|
27
|
+
withDefaults: import("../parsers/scriptSetupRanges").CallExpressionRange | undefined;
|
|
28
|
+
defineEmits: import("../parsers/scriptSetupRanges").DefineEmits | undefined;
|
|
29
|
+
defineSlots: import("../parsers/scriptSetupRanges").DefineSlots | undefined;
|
|
30
|
+
defineExpose: import("../parsers/scriptSetupRanges").CallExpressionRange | undefined;
|
|
31
|
+
defineOptions: import("../parsers/scriptSetupRanges").DefineOptions | undefined;
|
|
32
|
+
useAttrs: import("../parsers/scriptSetupRanges").CallExpressionRange[];
|
|
33
|
+
useCssModule: import("../parsers/scriptSetupRanges").CallExpressionRange[];
|
|
34
|
+
useSlots: import("../parsers/scriptSetupRanges").CallExpressionRange[];
|
|
35
|
+
useTemplateRef: import("../parsers/scriptSetupRanges").UseTemplateRef[];
|
|
111
36
|
} | undefined;
|
|
112
|
-
getSetupSlotsAssignName: () => string | undefined;
|
|
113
37
|
getGeneratedScript: () => {
|
|
114
|
-
codes: import("../types").Code[];
|
|
115
38
|
generatedTypes: Set<string>;
|
|
116
39
|
localTypes: {
|
|
117
40
|
generate: () => Generator<string, void, unknown>;
|
|
@@ -123,26 +46,26 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
123
46
|
readonly OmitIndexSignature: string;
|
|
124
47
|
};
|
|
125
48
|
inlayHints: import("../codegen/inlayHints").InlayHintInfo[];
|
|
49
|
+
codes: import("../types").Code[];
|
|
126
50
|
};
|
|
127
51
|
getGeneratedTemplate: () => {
|
|
128
|
-
codes: import("../types").Code[];
|
|
129
52
|
generatedTypes: Set<string>;
|
|
130
53
|
currentInfo: {
|
|
131
|
-
ignoreError?: boolean;
|
|
54
|
+
ignoreError?: boolean | undefined;
|
|
132
55
|
expectError?: {
|
|
133
56
|
token: number;
|
|
134
57
|
node: import("@vue/compiler-dom").CommentNode;
|
|
135
|
-
};
|
|
58
|
+
} | undefined;
|
|
136
59
|
generic?: {
|
|
137
60
|
content: string;
|
|
138
61
|
offset: number;
|
|
139
|
-
};
|
|
62
|
+
} | undefined;
|
|
140
63
|
};
|
|
141
64
|
resolveCodeFeatures: (features: import("../types").VueCodeInformation) => import("../types").VueCodeInformation;
|
|
142
65
|
inVFor: boolean;
|
|
143
66
|
slots: {
|
|
144
67
|
name: string;
|
|
145
|
-
offset?: number;
|
|
68
|
+
offset?: number | undefined;
|
|
146
69
|
tagRange: [number, number];
|
|
147
70
|
nodeLoc: any;
|
|
148
71
|
propsVar: string;
|
|
@@ -160,25 +83,23 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
160
83
|
typeExp: string;
|
|
161
84
|
offset: number;
|
|
162
85
|
}[]>;
|
|
163
|
-
currentComponent: {
|
|
164
|
-
get ctxVar(): string;
|
|
165
|
-
get propsVar(): string;
|
|
166
|
-
} | undefined;
|
|
167
86
|
singleRootElTypes: Set<string>;
|
|
168
87
|
singleRootNodes: Set<import("@vue/compiler-dom").ElementNode | null>;
|
|
169
88
|
addTemplateRef(name: string, typeExp: string, offset: number): void;
|
|
170
|
-
recordComponentAccess(source: string, name: string, offset?: number): void;
|
|
89
|
+
recordComponentAccess(source: string, name: string, offset?: number | undefined): void;
|
|
171
90
|
scopes: Set<string>[];
|
|
91
|
+
components: (() => string)[];
|
|
172
92
|
declare(...varNames: string[]): void;
|
|
173
93
|
startScope(): () => Generator<import("../types").Code, any, any>;
|
|
174
94
|
getInternalVariable(): string;
|
|
175
95
|
getHoistVariable(originalVar: string): string;
|
|
176
96
|
generateHoistVariables(): Generator<string, void, unknown>;
|
|
177
97
|
generateConditionGuards(): Generator<string, void, unknown>;
|
|
178
|
-
enter(node: import("@vue/compiler-dom").RootNode | import("@vue/compiler-dom").
|
|
179
|
-
exit(): Generator<import("../types").Code>;
|
|
98
|
+
enter(node: import("@vue/compiler-dom").RootNode | import("@vue/compiler-dom").SimpleExpressionNode | import("@vue/compiler-dom").TemplateChildNode): boolean;
|
|
99
|
+
exit(): Generator<import("../types").Code, any, any>;
|
|
100
|
+
codes: import("../types").Code[];
|
|
180
101
|
} | undefined;
|
|
181
|
-
|
|
102
|
+
getImportedComponents: () => Set<string>;
|
|
182
103
|
getSetupExposed: () => Set<string>;
|
|
183
104
|
}>;
|
|
184
105
|
declare const plugin: VueLanguagePlugin;
|
package/lib/plugins/vue-tsx.js
CHANGED
|
@@ -1,9 +1,42 @@
|
|
|
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.tsCodegen = void 0;
|
|
4
37
|
const shared_1 = require("@vue/shared");
|
|
5
38
|
const alien_signals_1 = require("alien-signals");
|
|
6
|
-
const path = require("path-browserify");
|
|
39
|
+
const path = __importStar(require("path-browserify"));
|
|
7
40
|
const script_1 = require("../codegen/script");
|
|
8
41
|
const style_1 = require("../codegen/style");
|
|
9
42
|
const template_1 = require("../codegen/template");
|
|
@@ -14,7 +47,7 @@ const vueCompilerOptions_1 = require("../parsers/vueCompilerOptions");
|
|
|
14
47
|
const signals_1 = require("../utils/signals");
|
|
15
48
|
exports.tsCodegen = new WeakMap();
|
|
16
49
|
const validLangs = new Set(['js', 'jsx', 'ts', 'tsx']);
|
|
17
|
-
const plugin =
|
|
50
|
+
const plugin = ({ modules: { typescript: ts }, vueCompilerOptions, }) => {
|
|
18
51
|
return {
|
|
19
52
|
version: 2.2,
|
|
20
53
|
getEmbeddedCodes(_fileName, sfc) {
|
|
@@ -25,7 +58,7 @@ const plugin = ctx => {
|
|
|
25
58
|
if (/script_(js|jsx|ts|tsx)/.test(embeddedFile.id)) {
|
|
26
59
|
let codegen = exports.tsCodegen.get(sfc);
|
|
27
60
|
if (!codegen) {
|
|
28
|
-
exports.tsCodegen.set(sfc, codegen = useCodegen(fileName, sfc
|
|
61
|
+
exports.tsCodegen.set(sfc, codegen = useCodegen(ts, vueCompilerOptions, fileName, sfc));
|
|
29
62
|
}
|
|
30
63
|
const generatedScript = codegen.getGeneratedScript();
|
|
31
64
|
embeddedFile.content = [...generatedScript.codes];
|
|
@@ -49,16 +82,15 @@ const plugin = ctx => {
|
|
|
49
82
|
}
|
|
50
83
|
};
|
|
51
84
|
exports.default = plugin;
|
|
52
|
-
function useCodegen(fileName, sfc
|
|
53
|
-
const ts = ctx.modules.typescript;
|
|
85
|
+
function useCodegen(ts, vueCompilerOptions, fileName, sfc) {
|
|
54
86
|
const getResolvedOptions = (0, alien_signals_1.computed)(() => {
|
|
55
87
|
const options = (0, vueCompilerOptions_1.parseVueCompilerOptions)(sfc.comments);
|
|
56
88
|
if (options) {
|
|
57
|
-
const resolver = new compilerOptions_1.CompilerOptionsResolver();
|
|
89
|
+
const resolver = new compilerOptions_1.CompilerOptionsResolver(ts, () => undefined /* does not support resolving target="auto" */);
|
|
58
90
|
resolver.addConfig(options, path.dirname(fileName));
|
|
59
|
-
return resolver.build(
|
|
91
|
+
return resolver.build(vueCompilerOptions);
|
|
60
92
|
}
|
|
61
|
-
return
|
|
93
|
+
return vueCompilerOptions;
|
|
62
94
|
});
|
|
63
95
|
const getScriptRanges = (0, alien_signals_1.computed)(() => sfc.script && validLangs.has(sfc.script.lang)
|
|
64
96
|
? (0, scriptRanges_1.parseScriptRanges)(ts, sfc.script.ast, getResolvedOptions())
|
|
@@ -66,7 +98,7 @@ function useCodegen(fileName, sfc, ctx) {
|
|
|
66
98
|
const getScriptSetupRanges = (0, alien_signals_1.computed)(() => sfc.scriptSetup && validLangs.has(sfc.scriptSetup.lang)
|
|
67
99
|
? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, sfc.scriptSetup.ast, getResolvedOptions())
|
|
68
100
|
: undefined);
|
|
69
|
-
const
|
|
101
|
+
const getImportedComponents = (0, signals_1.computedSet)(() => {
|
|
70
102
|
const names = new Set();
|
|
71
103
|
const scriptSetupRanges = getScriptSetupRanges();
|
|
72
104
|
if (sfc.scriptSetup && scriptSetupRanges) {
|
|
@@ -86,7 +118,7 @@ function useCodegen(fileName, sfc, ctx) {
|
|
|
86
118
|
const scriptSetupRanges = getScriptSetupRanges();
|
|
87
119
|
const names = new Set([
|
|
88
120
|
...scriptSetupRanges?.defineProps?.destructured?.keys() ?? [],
|
|
89
|
-
...
|
|
121
|
+
...getImportedComponents(),
|
|
90
122
|
]);
|
|
91
123
|
const rest = scriptSetupRanges?.defineProps?.destructuredRest;
|
|
92
124
|
if (rest) {
|
|
@@ -95,22 +127,21 @@ function useCodegen(fileName, sfc, ctx) {
|
|
|
95
127
|
return names;
|
|
96
128
|
});
|
|
97
129
|
const getSetupRefs = (0, signals_1.computedSet)(() => {
|
|
98
|
-
|
|
130
|
+
return new Set(getScriptSetupRanges()?.useTemplateRef
|
|
99
131
|
.map(({ name }) => name)
|
|
100
132
|
.filter(name => name !== undefined));
|
|
101
|
-
return newNames;
|
|
102
133
|
});
|
|
103
134
|
const hasDefineSlots = (0, alien_signals_1.computed)(() => !!getScriptSetupRanges()?.defineSlots);
|
|
104
135
|
const getSetupPropsAssignName = (0, alien_signals_1.computed)(() => getScriptSetupRanges()?.defineProps?.name);
|
|
105
136
|
const getSetupSlotsAssignName = (0, alien_signals_1.computed)(() => getScriptSetupRanges()?.defineSlots?.name);
|
|
106
|
-
const
|
|
137
|
+
const getInheritAttrs = (0, alien_signals_1.computed)(() => {
|
|
107
138
|
const value = getScriptSetupRanges()?.defineOptions?.inheritAttrs
|
|
108
|
-
?? getScriptRanges()?.
|
|
139
|
+
?? getScriptRanges()?.exportDefault?.options?.inheritAttrs;
|
|
109
140
|
return value !== 'false';
|
|
110
141
|
});
|
|
111
|
-
const
|
|
142
|
+
const getComponentName = (0, alien_signals_1.computed)(() => {
|
|
112
143
|
let name;
|
|
113
|
-
const
|
|
144
|
+
const componentOptions = getScriptRanges()?.exportDefault?.options;
|
|
114
145
|
if (sfc.script && componentOptions?.name) {
|
|
115
146
|
name = sfc.script.content.slice(componentOptions.name.start + 1, componentOptions.name.end - 1);
|
|
116
147
|
}
|
|
@@ -131,16 +162,16 @@ function useCodegen(fileName, sfc, ctx) {
|
|
|
131
162
|
return;
|
|
132
163
|
}
|
|
133
164
|
return (0, template_1.generateTemplate)({
|
|
134
|
-
ts,
|
|
165
|
+
typescript: ts,
|
|
135
166
|
vueCompilerOptions: getResolvedOptions(),
|
|
136
167
|
template: sfc.template,
|
|
168
|
+
componentName: getComponentName(),
|
|
137
169
|
setupConsts: getSetupConsts(),
|
|
138
170
|
setupRefs: getSetupRefs(),
|
|
139
171
|
hasDefineSlots: hasDefineSlots(),
|
|
140
172
|
propsAssignName: getSetupPropsAssignName(),
|
|
141
173
|
slotsAssignName: getSetupSlotsAssignName(),
|
|
142
|
-
inheritAttrs:
|
|
143
|
-
selfComponentName: getComponentSelfName(),
|
|
174
|
+
inheritAttrs: getInheritAttrs(),
|
|
144
175
|
});
|
|
145
176
|
});
|
|
146
177
|
const getGeneratedStyle = (0, alien_signals_1.computed)(() => {
|
|
@@ -148,18 +179,13 @@ function useCodegen(fileName, sfc, ctx) {
|
|
|
148
179
|
return;
|
|
149
180
|
}
|
|
150
181
|
return (0, style_1.generateStyle)({
|
|
151
|
-
ts,
|
|
182
|
+
typescript: ts,
|
|
152
183
|
vueCompilerOptions: getResolvedOptions(),
|
|
153
184
|
styles: sfc.styles,
|
|
154
185
|
setupConsts: getSetupConsts(),
|
|
155
186
|
setupRefs: getSetupRefs(),
|
|
156
187
|
});
|
|
157
188
|
});
|
|
158
|
-
const getTemplateStartTagOffset = (0, alien_signals_1.computed)(() => {
|
|
159
|
-
if (sfc.template) {
|
|
160
|
-
return sfc.template.start - sfc.template.startTagEnd;
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
189
|
const getSetupExposed = (0, signals_1.computedSet)(() => {
|
|
164
190
|
const allVars = new Set();
|
|
165
191
|
const scriptSetupRanges = getScriptSetupRanges();
|
|
@@ -205,26 +231,29 @@ function useCodegen(fileName, sfc, ctx) {
|
|
|
205
231
|
});
|
|
206
232
|
const getGeneratedScript = (0, alien_signals_1.computed)(() => {
|
|
207
233
|
return (0, script_1.generateScript)({
|
|
208
|
-
ts,
|
|
209
234
|
vueCompilerOptions: getResolvedOptions(),
|
|
235
|
+
fileName,
|
|
210
236
|
script: sfc.script,
|
|
211
237
|
scriptSetup: sfc.scriptSetup,
|
|
212
|
-
|
|
213
|
-
fileName,
|
|
238
|
+
exposed: getSetupExposed(),
|
|
214
239
|
scriptRanges: getScriptRanges(),
|
|
215
240
|
scriptSetupRanges: getScriptSetupRanges(),
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
241
|
+
templateAndStyleTypes: new Set([
|
|
242
|
+
...getGeneratedTemplate()?.generatedTypes ?? [],
|
|
243
|
+
...getGeneratedStyle()?.generatedTypes ?? [],
|
|
244
|
+
]),
|
|
245
|
+
templateAndStyleCodes: [
|
|
246
|
+
...getGeneratedStyle()?.codes ?? [],
|
|
247
|
+
...getGeneratedTemplate()?.codes ?? [],
|
|
248
|
+
],
|
|
219
249
|
});
|
|
220
250
|
});
|
|
221
251
|
return {
|
|
222
252
|
getScriptRanges,
|
|
223
253
|
getScriptSetupRanges,
|
|
224
|
-
getSetupSlotsAssignName,
|
|
225
254
|
getGeneratedScript,
|
|
226
255
|
getGeneratedTemplate,
|
|
227
|
-
|
|
256
|
+
getImportedComponents,
|
|
228
257
|
getSetupExposed,
|
|
229
258
|
};
|
|
230
259
|
}
|
package/lib/plugins.js
CHANGED
|
@@ -13,22 +13,25 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
13
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
16
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
20
|
exports.createPlugins = createPlugins;
|
|
18
|
-
const file_html_1 = require("./plugins/file-html");
|
|
19
|
-
const file_md_1 = require("./plugins/file-md");
|
|
20
|
-
const file_vue_1 = require("./plugins/file-vue");
|
|
21
|
-
const vue_root_tags_1 = require("./plugins/vue-root-tags");
|
|
22
|
-
const vue_script_js_1 = require("./plugins/vue-script-js");
|
|
23
|
-
const vue_sfc_customblocks_1 = require("./plugins/vue-sfc-customblocks");
|
|
24
|
-
const vue_sfc_scripts_1 = require("./plugins/vue-sfc-scripts");
|
|
25
|
-
const vue_sfc_styles_1 = require("./plugins/vue-sfc-styles");
|
|
26
|
-
const vue_sfc_template_1 = require("./plugins/vue-sfc-template");
|
|
27
|
-
const vue_style_css_1 = require("./plugins/vue-style-css");
|
|
28
|
-
const vue_template_html_1 = require("./plugins/vue-template-html");
|
|
29
|
-
const vue_template_inline_css_1 = require("./plugins/vue-template-inline-css");
|
|
30
|
-
const vue_template_inline_ts_1 = require("./plugins/vue-template-inline-ts");
|
|
31
|
-
const vue_tsx_1 = require("./plugins/vue-tsx");
|
|
21
|
+
const file_html_1 = __importDefault(require("./plugins/file-html"));
|
|
22
|
+
const file_md_1 = __importDefault(require("./plugins/file-md"));
|
|
23
|
+
const file_vue_1 = __importDefault(require("./plugins/file-vue"));
|
|
24
|
+
const vue_root_tags_1 = __importDefault(require("./plugins/vue-root-tags"));
|
|
25
|
+
const vue_script_js_1 = __importDefault(require("./plugins/vue-script-js"));
|
|
26
|
+
const vue_sfc_customblocks_1 = __importDefault(require("./plugins/vue-sfc-customblocks"));
|
|
27
|
+
const vue_sfc_scripts_1 = __importDefault(require("./plugins/vue-sfc-scripts"));
|
|
28
|
+
const vue_sfc_styles_1 = __importDefault(require("./plugins/vue-sfc-styles"));
|
|
29
|
+
const vue_sfc_template_1 = __importDefault(require("./plugins/vue-sfc-template"));
|
|
30
|
+
const vue_style_css_1 = __importDefault(require("./plugins/vue-style-css"));
|
|
31
|
+
const vue_template_html_1 = __importDefault(require("./plugins/vue-template-html"));
|
|
32
|
+
const vue_template_inline_css_1 = __importDefault(require("./plugins/vue-template-inline-css"));
|
|
33
|
+
const vue_template_inline_ts_1 = __importDefault(require("./plugins/vue-template-inline-ts"));
|
|
34
|
+
const vue_tsx_1 = __importDefault(require("./plugins/vue-tsx"));
|
|
32
35
|
const types_1 = require("./types");
|
|
33
36
|
__exportStar(require("./plugins/shared"), exports);
|
|
34
37
|
function createPlugins(pluginContext) {
|
package/lib/types.d.ts
CHANGED
|
@@ -6,10 +6,9 @@ import type * as ts from 'typescript';
|
|
|
6
6
|
import type { VueEmbeddedCode } from './virtualCode/embeddedCodes';
|
|
7
7
|
export type { SFCParseResult } from '@vue/compiler-sfc';
|
|
8
8
|
export { VueEmbeddedCode };
|
|
9
|
-
export type RawVueCompilerOptions = Partial<Omit<VueCompilerOptions, 'target' | '
|
|
9
|
+
export type RawVueCompilerOptions = Partial<Omit<VueCompilerOptions, 'target' | 'plugins'>> & {
|
|
10
10
|
strictTemplates?: boolean;
|
|
11
11
|
target?: 'auto' | 3 | 3.3 | 3.5 | 3.6 | 99 | number;
|
|
12
|
-
globalTypesPath?: string;
|
|
13
12
|
plugins?: string[];
|
|
14
13
|
};
|
|
15
14
|
export interface VueCodeInformation extends CodeInformation {
|
|
@@ -21,7 +20,7 @@ export type Code = Segment<VueCodeInformation>;
|
|
|
21
20
|
export interface VueCompilerOptions {
|
|
22
21
|
target: number;
|
|
23
22
|
lib: string;
|
|
24
|
-
|
|
23
|
+
typesRoot: string;
|
|
25
24
|
extensions: string[];
|
|
26
25
|
vitePressExtensions: string[];
|
|
27
26
|
petiteVueExtensions: string[];
|
|
@@ -120,19 +119,19 @@ export type SfcBlockAttr = true | {
|
|
|
120
119
|
export interface Sfc {
|
|
121
120
|
content: string;
|
|
122
121
|
comments: string[];
|
|
123
|
-
template: SfcBlock & {
|
|
122
|
+
template: (SfcBlock & {
|
|
124
123
|
ast: CompilerDOM.RootNode | undefined;
|
|
125
124
|
errors: CompilerDOM.CompilerError[];
|
|
126
125
|
warnings: CompilerDOM.CompilerError[];
|
|
127
|
-
} | undefined;
|
|
126
|
+
}) | undefined;
|
|
128
127
|
script: (SfcBlock & {
|
|
129
128
|
src: SfcBlockAttr | undefined;
|
|
130
129
|
ast: ts.SourceFile;
|
|
131
130
|
}) | undefined;
|
|
132
|
-
scriptSetup: SfcBlock & {
|
|
131
|
+
scriptSetup: (SfcBlock & {
|
|
133
132
|
generic: SfcBlockAttr | undefined;
|
|
134
133
|
ast: ts.SourceFile;
|
|
135
|
-
} | undefined;
|
|
134
|
+
}) | undefined;
|
|
136
135
|
styles: readonly (SfcBlock & {
|
|
137
136
|
src: SfcBlockAttr | undefined;
|
|
138
137
|
module: SfcBlockAttr | undefined;
|
|
@@ -165,7 +164,8 @@ declare module '@vue/compiler-sfc' {
|
|
|
165
164
|
__module?: SfcBlockAttr;
|
|
166
165
|
}
|
|
167
166
|
}
|
|
168
|
-
export interface TextRange {
|
|
167
|
+
export interface TextRange<Node extends ts.Node = ts.Node> {
|
|
168
|
+
node: Node;
|
|
169
169
|
start: number;
|
|
170
170
|
end: number;
|
|
171
171
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type * as ts from 'typescript';
|
|
2
2
|
export declare function collectBindingNames(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): string[];
|
|
3
|
-
export declare function collectBindingRanges(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): import("../types").TextRange[];
|
|
3
|
+
export declare function collectBindingRanges(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): import("../types").TextRange<ts.Identifier>[];
|
|
4
4
|
export declare function collectBindingIdentifiers(ts: typeof import('typescript'), node: ts.Node, results?: {
|
|
5
5
|
id: ts.Identifier;
|
|
6
6
|
isRest: boolean;
|