@vue/language-core 2.1.8 → 2.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/lib/codegen/globalTypes.js +12 -5
- package/lib/codegen/localTypes.js +3 -3
- package/lib/codegen/script/component.js +42 -42
- package/lib/codegen/script/componentSelf.js +14 -13
- package/lib/codegen/script/context.js +2 -2
- package/lib/codegen/script/index.d.ts +5 -3
- package/lib/codegen/script/index.js +24 -37
- package/lib/codegen/script/scriptSetup.js +240 -193
- package/lib/codegen/script/src.js +6 -6
- package/lib/codegen/script/styleModulesType.js +5 -5
- package/lib/codegen/script/template.d.ts +1 -1
- package/lib/codegen/script/template.js +89 -99
- package/lib/codegen/template/context.d.ts +13 -3
- package/lib/codegen/template/context.js +21 -12
- package/lib/codegen/template/element.d.ts +2 -4
- package/lib/codegen/template/element.js +132 -105
- package/lib/codegen/template/elementChildren.d.ts +1 -1
- package/lib/codegen/template/elementChildren.js +8 -8
- package/lib/codegen/template/elementDirectives.d.ts +1 -0
- package/lib/codegen/template/elementDirectives.js +28 -22
- package/lib/codegen/template/elementEvents.d.ts +2 -2
- package/lib/codegen/template/elementEvents.js +32 -65
- package/lib/codegen/template/elementProps.d.ts +3 -2
- package/lib/codegen/template/elementProps.js +119 -122
- package/lib/codegen/template/index.js +52 -60
- package/lib/codegen/template/interpolation.d.ts +5 -3
- package/lib/codegen/template/interpolation.js +18 -19
- package/lib/codegen/template/objectProperty.js +8 -8
- package/lib/codegen/template/propertyAccess.js +4 -4
- package/lib/codegen/template/slotOutlet.d.ts +1 -1
- package/lib/codegen/template/slotOutlet.js +13 -13
- package/lib/codegen/template/styleScopedClasses.d.ts +1 -1
- package/lib/codegen/template/styleScopedClasses.js +11 -8
- package/lib/codegen/template/templateChild.d.ts +1 -1
- package/lib/codegen/template/templateChild.js +31 -19
- package/lib/codegen/template/vFor.d.ts +1 -1
- package/lib/codegen/template/vFor.js +11 -11
- package/lib/codegen/template/vIf.d.ts +1 -1
- package/lib/codegen/template/vIf.js +6 -6
- package/lib/codegen/{template → utils}/camelized.js +2 -2
- package/lib/codegen/{common.d.ts → utils/index.d.ts} +1 -2
- package/lib/codegen/{common.js → utils/index.js} +4 -15
- package/lib/codegen/{template → utils}/stringLiteralKey.js +3 -3
- package/lib/codegen/utils/unicode.d.ts +2 -0
- package/lib/codegen/utils/unicode.js +25 -0
- package/lib/languagePlugin.js +1 -1
- package/lib/parsers/scriptRanges.d.ts +7 -2
- package/lib/parsers/scriptSetupRanges.d.ts +67 -81
- package/lib/parsers/scriptSetupRanges.js +195 -166
- package/lib/parsers/vueCompilerOptions.d.ts +2 -0
- package/lib/parsers/vueCompilerOptions.js +23 -0
- package/lib/plugins/file-html.js +4 -3
- package/lib/plugins/file-md.js +1 -1
- package/lib/plugins/file-vue.js +4 -4
- package/lib/plugins/vue-root-tags.js +2 -2
- package/lib/plugins/vue-template-html.js +6 -2
- package/lib/plugins/vue-template-inline-css.js +1 -1
- package/lib/plugins/vue-template-inline-ts.js +13 -5
- package/lib/plugins/vue-tsx.d.ts +101 -72
- package/lib/plugins/vue-tsx.js +65 -69
- package/lib/types.d.ts +19 -10
- package/lib/utils/buildMappings.d.ts +1 -1
- package/lib/utils/parseSfc.d.ts +5 -0
- package/lib/utils/parseSfc.js +7 -2
- package/lib/utils/ts.d.ts +1 -1
- package/lib/utils/ts.js +38 -24
- package/lib/virtualFile/computedEmbeddedCodes.d.ts +1 -2
- package/lib/virtualFile/computedSfc.js +23 -12
- package/lib/virtualFile/computedVueSfc.d.ts +1 -1
- package/lib/virtualFile/vueFile.d.ts +3 -3
- package/package.json +5 -5
- package/lib/codegen/types.d.ts +0 -9
- package/lib/codegen/types.js +0 -3
- package/lib/utils/findDestructuredProps.d.ts +0 -1
- package/lib/utils/findDestructuredProps.js +0 -3
- /package/lib/codegen/{template → utils}/camelized.d.ts +0 -0
- /package/lib/codegen/{template → utils}/stringLiteralKey.d.ts +0 -0
|
@@ -155,6 +155,10 @@ const plugin = ({ modules }) => {
|
|
|
155
155
|
if (node.isStatic) {
|
|
156
156
|
return false;
|
|
157
157
|
}
|
|
158
|
+
else if (!node.loc.source) {
|
|
159
|
+
// :class="..." -> :class=""
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
158
162
|
else {
|
|
159
163
|
node.content = node.loc.source;
|
|
160
164
|
}
|
|
@@ -168,9 +172,9 @@ const plugin = ({ modules }) => {
|
|
|
168
172
|
delete loc.__endOffset;
|
|
169
173
|
if (withinChangeRange(loc)) {
|
|
170
174
|
loc.source =
|
|
171
|
-
loc.source.
|
|
175
|
+
loc.source.slice(0, change.start - loc.start.offset)
|
|
172
176
|
+ change.newText
|
|
173
|
-
+ loc.source.
|
|
177
|
+
+ loc.source.slice(change.end - loc.start.offset);
|
|
174
178
|
loc.__endOffset = loc.end.offset;
|
|
175
179
|
loc.end.offset += lengthDiff;
|
|
176
180
|
return true;
|
|
@@ -39,7 +39,7 @@ function* generate(templateAst) {
|
|
|
39
39
|
const endCrt = prop.arg.loc.source[prop.arg.loc.source.length - 1]; // " | '
|
|
40
40
|
const start = prop.arg.loc.source.indexOf(endCrt) + 1;
|
|
41
41
|
const end = prop.arg.loc.source.lastIndexOf(endCrt);
|
|
42
|
-
const content = prop.arg.loc.source.
|
|
42
|
+
const content = prop.arg.loc.source.slice(start, end);
|
|
43
43
|
yield `x { `;
|
|
44
44
|
yield [
|
|
45
45
|
content,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const CompilerDOM = require("@vue/compiler-dom");
|
|
4
4
|
const elementEvents_1 = require("../codegen/template/elementEvents");
|
|
5
5
|
const templateChild_1 = require("../codegen/template/templateChild");
|
|
6
6
|
const vFor_1 = require("../codegen/template/vFor");
|
|
7
|
-
const
|
|
7
|
+
const utils_1 = require("../codegen/utils");
|
|
8
8
|
const codeFeatures = {
|
|
9
9
|
format: true,
|
|
10
10
|
};
|
|
@@ -18,6 +18,7 @@ const formatBrackets = {
|
|
|
18
18
|
// fix https://github.com/vuejs/language-tools/issues/2305
|
|
19
19
|
curly: ['0 +', '+ 0;'],
|
|
20
20
|
event: ['() => ', ';'],
|
|
21
|
+
generic: ['<', '>() => {};'],
|
|
21
22
|
};
|
|
22
23
|
const plugin = ctx => {
|
|
23
24
|
const parseds = new WeakMap();
|
|
@@ -58,7 +59,14 @@ const plugin = ctx => {
|
|
|
58
59
|
sfc.template.ast.children.forEach(visit);
|
|
59
60
|
return data;
|
|
60
61
|
function visit(node) {
|
|
61
|
-
if (node.type === CompilerDOM.NodeTypes.
|
|
62
|
+
if (node.type === CompilerDOM.NodeTypes.COMMENT) {
|
|
63
|
+
const match = node.loc.source.match(/^<!--\s*@vue-generic\b\s*\{(?<content>[^}]*)\}/);
|
|
64
|
+
if (match) {
|
|
65
|
+
const { content } = match.groups ?? {};
|
|
66
|
+
addFormatCodes(content, node.loc.start.offset + match[0].indexOf(content), formatBrackets.generic);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else if (node.type === CompilerDOM.NodeTypes.ELEMENT) {
|
|
62
70
|
for (const prop of node.props) {
|
|
63
71
|
if (prop.type !== CompilerDOM.NodeTypes.DIRECTIVE) {
|
|
64
72
|
continue;
|
|
@@ -74,7 +82,7 @@ const plugin = ctx => {
|
|
|
74
82
|
&& prop.exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY // style='z-index: 2' will compile to {'z-index':'2'}
|
|
75
83
|
) {
|
|
76
84
|
if (prop.name === 'on' && prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
77
|
-
const ast = (0,
|
|
85
|
+
const ast = (0, utils_1.createTsAst)(ctx.modules.typescript, prop.exp, prop.exp.content);
|
|
78
86
|
addFormatCodes(prop.exp.content, prop.exp.loc.start.offset, (0, elementEvents_1.isCompoundExpression)(ctx.modules.typescript, ast)
|
|
79
87
|
? formatBrackets.event
|
|
80
88
|
: formatBrackets.normal);
|
|
@@ -105,7 +113,7 @@ const plugin = ctx => {
|
|
|
105
113
|
if (leftExpressionRange && leftExpressionText && source.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
106
114
|
const start = leftExpressionRange.start;
|
|
107
115
|
const end = source.loc.start.offset + source.content.length;
|
|
108
|
-
addFormatCodes(templateContent.
|
|
116
|
+
addFormatCodes(templateContent.slice(start, end), start, formatBrackets.for);
|
|
109
117
|
}
|
|
110
118
|
for (const child of node.children) {
|
|
111
119
|
visit(child);
|
package/lib/plugins/vue-tsx.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Mapping } from '@volar/language-core';
|
|
2
2
|
import type { Code, Sfc, VueLanguagePlugin } from '../types';
|
|
3
3
|
export declare const tsCodegen: WeakMap<Sfc, {
|
|
4
|
-
scriptRanges: import("alien-signals").
|
|
4
|
+
scriptRanges: import("alien-signals").Computed<{
|
|
5
5
|
exportDefault: (import("../types").TextRange & {
|
|
6
6
|
expression: import("../types").TextRange;
|
|
7
7
|
args: import("../types").TextRange;
|
|
@@ -13,88 +13,107 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
13
13
|
inheritAttrsOption: string | undefined;
|
|
14
14
|
}) | undefined;
|
|
15
15
|
classBlockEnd: number | undefined;
|
|
16
|
-
bindings:
|
|
16
|
+
bindings: {
|
|
17
|
+
range: import("../types").TextRange;
|
|
18
|
+
moduleName?: string;
|
|
19
|
+
isDefaultImport?: boolean;
|
|
20
|
+
isNamespace?: boolean;
|
|
21
|
+
}[];
|
|
17
22
|
} | undefined>;
|
|
18
|
-
scriptSetupRanges: import("alien-signals").
|
|
23
|
+
scriptSetupRanges: import("alien-signals").Computed<{
|
|
19
24
|
leadingCommentEndOffset: number;
|
|
20
25
|
importSectionEndOffset: number;
|
|
21
|
-
bindings:
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
bindings: {
|
|
27
|
+
range: import("../types").TextRange;
|
|
28
|
+
moduleName?: string;
|
|
29
|
+
isDefaultImport?: boolean;
|
|
30
|
+
isNamespace?: boolean;
|
|
31
|
+
}[];
|
|
32
|
+
defineProp: {
|
|
33
|
+
localName?: import("../types").TextRange;
|
|
34
|
+
name?: import("../types").TextRange;
|
|
35
|
+
type?: import("../types").TextRange;
|
|
36
|
+
modifierType?: import("../types").TextRange;
|
|
37
|
+
runtimeType?: import("../types").TextRange;
|
|
38
|
+
defaultValue?: import("../types").TextRange;
|
|
39
|
+
required?: boolean;
|
|
40
|
+
isModel?: boolean;
|
|
41
|
+
}[];
|
|
42
|
+
defineProps: ({
|
|
43
|
+
callExp: import("../types").TextRange;
|
|
44
|
+
exp: import("../types").TextRange;
|
|
45
|
+
arg?: import("../types").TextRange;
|
|
46
|
+
typeArg?: import("../types").TextRange;
|
|
47
|
+
} & {
|
|
24
48
|
name?: string;
|
|
25
49
|
destructured?: Set<string>;
|
|
26
50
|
destructuredRest?: string;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
isObjectBindingPattern?: boolean;
|
|
41
|
-
define?: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
|
|
42
|
-
exp: import("../types").TextRange;
|
|
43
|
-
arg?: import("../types").TextRange;
|
|
44
|
-
typeArg?: import("../types").TextRange;
|
|
45
|
-
}>;
|
|
46
|
-
};
|
|
47
|
-
emits: {
|
|
51
|
+
statement: import("../types").TextRange;
|
|
52
|
+
}) | undefined;
|
|
53
|
+
withDefaults: {
|
|
54
|
+
callExp: import("../types").TextRange;
|
|
55
|
+
exp: import("../types").TextRange;
|
|
56
|
+
arg?: import("../types").TextRange | undefined;
|
|
57
|
+
} | undefined;
|
|
58
|
+
defineEmits: ({
|
|
59
|
+
callExp: import("../types").TextRange;
|
|
60
|
+
exp: import("../types").TextRange;
|
|
61
|
+
arg?: import("../types").TextRange;
|
|
62
|
+
typeArg?: import("../types").TextRange;
|
|
63
|
+
} & {
|
|
48
64
|
name?: string;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
expose: {
|
|
65
|
+
hasUnionTypeArg?: boolean;
|
|
66
|
+
statement: import("../types").TextRange;
|
|
67
|
+
}) | undefined;
|
|
68
|
+
defineSlots: ({
|
|
69
|
+
callExp: import("../types").TextRange;
|
|
70
|
+
exp: import("../types").TextRange;
|
|
71
|
+
arg?: import("../types").TextRange;
|
|
72
|
+
typeArg?: import("../types").TextRange;
|
|
73
|
+
} & {
|
|
59
74
|
name?: string;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
75
|
+
isObjectBindingPattern?: boolean;
|
|
76
|
+
statement: import("../types").TextRange;
|
|
77
|
+
}) | undefined;
|
|
78
|
+
defineExpose: {
|
|
79
|
+
callExp: import("../types").TextRange;
|
|
80
|
+
exp: import("../types").TextRange;
|
|
81
|
+
arg?: import("../types").TextRange;
|
|
82
|
+
typeArg?: import("../types").TextRange;
|
|
83
|
+
} | undefined;
|
|
84
|
+
defineOptions: {
|
|
67
85
|
name?: string;
|
|
68
86
|
inheritAttrs?: string;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}>;
|
|
87
|
+
} | undefined;
|
|
88
|
+
useAttrs: {
|
|
89
|
+
callExp: import("../types").TextRange;
|
|
90
|
+
exp: import("../types").TextRange;
|
|
91
|
+
arg?: import("../types").TextRange;
|
|
92
|
+
typeArg?: import("../types").TextRange;
|
|
76
93
|
}[];
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
runtimeType: import("../types").TextRange | undefined;
|
|
83
|
-
defaultValue: import("../types").TextRange | undefined;
|
|
84
|
-
required: boolean;
|
|
85
|
-
isModel?: boolean;
|
|
94
|
+
useCssModule: {
|
|
95
|
+
callExp: import("../types").TextRange;
|
|
96
|
+
exp: import("../types").TextRange;
|
|
97
|
+
arg?: import("../types").TextRange;
|
|
98
|
+
typeArg?: import("../types").TextRange;
|
|
86
99
|
}[];
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
typeArg?: import("../types").TextRange;
|
|
93
|
-
}>;
|
|
100
|
+
useSlots: {
|
|
101
|
+
callExp: import("../types").TextRange;
|
|
102
|
+
exp: import("../types").TextRange;
|
|
103
|
+
arg?: import("../types").TextRange;
|
|
104
|
+
typeArg?: import("../types").TextRange;
|
|
94
105
|
}[];
|
|
106
|
+
useTemplateRef: ({
|
|
107
|
+
callExp: import("../types").TextRange;
|
|
108
|
+
exp: import("../types").TextRange;
|
|
109
|
+
arg?: import("../types").TextRange;
|
|
110
|
+
typeArg?: import("../types").TextRange;
|
|
111
|
+
} & {
|
|
112
|
+
name?: string;
|
|
113
|
+
})[];
|
|
95
114
|
} | undefined>;
|
|
96
|
-
lang: import("alien-signals").
|
|
97
|
-
generatedScript: import("alien-signals").
|
|
115
|
+
lang: import("alien-signals").Computed<string>;
|
|
116
|
+
generatedScript: import("alien-signals").Computed<{
|
|
98
117
|
codes: Code[];
|
|
99
118
|
linkedCodeMappings: Mapping<unknown>[];
|
|
100
119
|
generatedTemplate: boolean;
|
|
@@ -115,7 +134,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
115
134
|
};
|
|
116
135
|
inlayHints: import("../codegen/inlayHints").InlayHintInfo[];
|
|
117
136
|
}>;
|
|
118
|
-
generatedTemplate: import("alien-signals").
|
|
137
|
+
generatedTemplate: import("alien-signals").Computed<{
|
|
119
138
|
codes: Code[];
|
|
120
139
|
slots: {
|
|
121
140
|
name: string;
|
|
@@ -137,14 +156,18 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
137
156
|
navigationWithoutRename: import("../types").VueCodeInformation;
|
|
138
157
|
navigationAndCompletion: import("../types").VueCodeInformation;
|
|
139
158
|
navigationAndAdditionalCompletion: import("../types").VueCodeInformation;
|
|
159
|
+
withoutNavigation: import("../types").VueCodeInformation;
|
|
140
160
|
withoutHighlight: import("../types").VueCodeInformation;
|
|
141
161
|
withoutHighlightAndCompletion: import("../types").VueCodeInformation;
|
|
142
162
|
withoutHighlightAndCompletionAndNavigation: import("../types").VueCodeInformation;
|
|
143
163
|
};
|
|
144
164
|
accessExternalVariables: Map<string, Set<number>>;
|
|
165
|
+
lastGenericComment: {
|
|
166
|
+
content: string;
|
|
167
|
+
offset: number;
|
|
168
|
+
} | undefined;
|
|
145
169
|
hasSlotElements: Set<import("@vue/compiler-dom").ElementNode>;
|
|
146
170
|
blockConditions: string[];
|
|
147
|
-
usedComponentCtxVars: Set<string>;
|
|
148
171
|
scopedClasses: {
|
|
149
172
|
source: string;
|
|
150
173
|
className: string;
|
|
@@ -153,8 +176,14 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
153
176
|
emptyClassOffsets: number[];
|
|
154
177
|
inlayHints: import("../codegen/inlayHints").InlayHintInfo[];
|
|
155
178
|
hasSlot: boolean;
|
|
156
|
-
|
|
179
|
+
bindingAttrLocs: import("@vue/compiler-dom").SourceLocation[];
|
|
180
|
+
inheritedAttrVars: Set<string>;
|
|
157
181
|
templateRefs: Map<string, [varName: string, offset: number]>;
|
|
182
|
+
currentComponent: {
|
|
183
|
+
node: import("@vue/compiler-dom").ElementNode;
|
|
184
|
+
ctxVar: string;
|
|
185
|
+
used: boolean;
|
|
186
|
+
} | undefined;
|
|
158
187
|
singleRootElType: string | undefined;
|
|
159
188
|
singleRootNode: import("@vue/compiler-dom").ElementNode | undefined;
|
|
160
189
|
accessExternalVariable(name: string, offset?: number): void;
|
package/lib/plugins/vue-tsx.js
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.tsCodegen = void 0;
|
|
4
4
|
const alien_signals_1 = require("alien-signals");
|
|
5
|
-
const path_browserify_1 = require("path-browserify");
|
|
6
5
|
const script_1 = require("../codegen/script");
|
|
7
6
|
const template_1 = require("../codegen/template");
|
|
8
7
|
const scriptRanges_1 = require("../parsers/scriptRanges");
|
|
9
8
|
const scriptSetupRanges_1 = require("../parsers/scriptSetupRanges");
|
|
9
|
+
const vueCompilerOptions_1 = require("../parsers/vueCompilerOptions");
|
|
10
|
+
const ts_1 = require("../utils/ts");
|
|
10
11
|
exports.tsCodegen = new WeakMap();
|
|
11
12
|
const fileEditTimes = new Map();
|
|
12
13
|
const plugin = ctx => {
|
|
@@ -30,8 +31,7 @@ const plugin = ctx => {
|
|
|
30
31
|
if (/script_(js|jsx|ts|tsx)/.test(embeddedFile.id)) {
|
|
31
32
|
const tsx = _tsx.generatedScript.get();
|
|
32
33
|
if (tsx) {
|
|
33
|
-
|
|
34
|
-
embeddedFile.content = content;
|
|
34
|
+
embeddedFile.content = [...tsx.codes];
|
|
35
35
|
embeddedFile.linkedCodeMappings = [...tsx.linkedCodeMappings];
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -58,23 +58,75 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
|
|
|
58
58
|
: _sfc.script && _sfc.script.lang !== 'js' ? _sfc.script.lang
|
|
59
59
|
: 'js';
|
|
60
60
|
});
|
|
61
|
+
const vueCompilerOptions = (0, alien_signals_1.computed)(() => {
|
|
62
|
+
const options = (0, vueCompilerOptions_1.parseVueCompilerOptions)(_sfc.comments);
|
|
63
|
+
return options
|
|
64
|
+
? (0, ts_1.resolveVueCompilerOptions)(options, ctx.vueCompilerOptions)
|
|
65
|
+
: ctx.vueCompilerOptions;
|
|
66
|
+
});
|
|
61
67
|
const scriptRanges = (0, alien_signals_1.computed)(() => _sfc.script
|
|
62
68
|
? (0, scriptRanges_1.parseScriptRanges)(ts, _sfc.script.ast, !!_sfc.scriptSetup, false)
|
|
63
69
|
: undefined);
|
|
64
70
|
const scriptSetupRanges = (0, alien_signals_1.computed)(() => _sfc.scriptSetup
|
|
65
|
-
? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, _sfc.scriptSetup.ast,
|
|
71
|
+
? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, _sfc.scriptSetup.ast, vueCompilerOptions.get())
|
|
66
72
|
: undefined);
|
|
73
|
+
const scriptSetupBindingNames = alien_signals_1.unstable.computedSet((0, alien_signals_1.computed)(() => {
|
|
74
|
+
const newNames = new Set();
|
|
75
|
+
const bindings = scriptSetupRanges.get()?.bindings;
|
|
76
|
+
if (_sfc.scriptSetup && bindings) {
|
|
77
|
+
for (const { range } of bindings) {
|
|
78
|
+
newNames.add(_sfc.scriptSetup.content.slice(range.start, range.end));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return newNames;
|
|
82
|
+
}));
|
|
83
|
+
const scriptSetupImportComponentNames = alien_signals_1.unstable.computedSet((0, alien_signals_1.computed)(() => {
|
|
84
|
+
const newNames = new Set();
|
|
85
|
+
const bindings = scriptSetupRanges.get()?.bindings;
|
|
86
|
+
if (_sfc.scriptSetup && bindings) {
|
|
87
|
+
for (const { range, moduleName, isDefaultImport, isNamespace } of bindings) {
|
|
88
|
+
if (moduleName
|
|
89
|
+
&& isDefaultImport
|
|
90
|
+
&& !isNamespace
|
|
91
|
+
&& ctx.vueCompilerOptions.extensions.some(ext => moduleName.endsWith(ext))) {
|
|
92
|
+
newNames.add(_sfc.scriptSetup.content.slice(range.start, range.end));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return newNames;
|
|
97
|
+
}));
|
|
98
|
+
const destructuredPropNames = alien_signals_1.unstable.computedSet((0, alien_signals_1.computed)(() => {
|
|
99
|
+
const newNames = new Set(scriptSetupRanges.get()?.defineProps?.destructured);
|
|
100
|
+
const rest = scriptSetupRanges.get()?.defineProps?.destructuredRest;
|
|
101
|
+
if (rest) {
|
|
102
|
+
newNames.add(rest);
|
|
103
|
+
}
|
|
104
|
+
return newNames;
|
|
105
|
+
}));
|
|
106
|
+
const templateRefNames = alien_signals_1.unstable.computedSet((0, alien_signals_1.computed)(() => {
|
|
107
|
+
const newNames = new Set(scriptSetupRanges.get()?.useTemplateRef
|
|
108
|
+
.map(({ name }) => name)
|
|
109
|
+
.filter(name => name !== undefined));
|
|
110
|
+
return newNames;
|
|
111
|
+
}));
|
|
112
|
+
const hasDefineSlots = (0, alien_signals_1.computed)(() => !!scriptSetupRanges.get()?.defineSlots);
|
|
113
|
+
const slotsAssignName = (0, alien_signals_1.computed)(() => scriptSetupRanges.get()?.defineSlots?.name);
|
|
114
|
+
const propsAssignName = (0, alien_signals_1.computed)(() => scriptSetupRanges.get()?.defineProps?.name);
|
|
115
|
+
const inheritAttrs = (0, alien_signals_1.computed)(() => {
|
|
116
|
+
const value = scriptSetupRanges.get()?.defineOptions?.inheritAttrs ?? scriptRanges.get()?.exportDefault?.inheritAttrsOption;
|
|
117
|
+
return value !== 'false';
|
|
118
|
+
});
|
|
67
119
|
const generatedTemplate = (0, alien_signals_1.computed)(() => {
|
|
68
|
-
if (
|
|
120
|
+
if (vueCompilerOptions.get().skipTemplateCodegen || !_sfc.template) {
|
|
69
121
|
return;
|
|
70
122
|
}
|
|
71
123
|
const codes = [];
|
|
72
124
|
const codegen = (0, template_1.generateTemplate)({
|
|
73
125
|
ts,
|
|
74
126
|
compilerOptions: ctx.compilerOptions,
|
|
75
|
-
vueCompilerOptions:
|
|
127
|
+
vueCompilerOptions: vueCompilerOptions.get(),
|
|
76
128
|
template: _sfc.template,
|
|
77
|
-
edited:
|
|
129
|
+
edited: vueCompilerOptions.get().__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
|
|
78
130
|
scriptSetupBindingNames: scriptSetupBindingNames.get(),
|
|
79
131
|
scriptSetupImportComponentNames: scriptSetupImportComponentNames.get(),
|
|
80
132
|
destructuredPropNames: destructuredPropNames.get(),
|
|
@@ -95,68 +147,23 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
|
|
|
95
147
|
codes: codes,
|
|
96
148
|
};
|
|
97
149
|
});
|
|
98
|
-
const scriptSetupBindingNames = (0, alien_signals_1.computed)(oldNames => {
|
|
99
|
-
const newNames = new Set();
|
|
100
|
-
const bindings = scriptSetupRanges.get()?.bindings;
|
|
101
|
-
if (_sfc.scriptSetup && bindings) {
|
|
102
|
-
for (const binding of bindings) {
|
|
103
|
-
newNames.add(_sfc.scriptSetup?.content.substring(binding.start, binding.end));
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
if (newNames && oldNames && twoSetsEqual(newNames, oldNames)) {
|
|
107
|
-
return oldNames;
|
|
108
|
-
}
|
|
109
|
-
return newNames;
|
|
110
|
-
});
|
|
111
|
-
const scriptSetupImportComponentNames = (0, alien_signals_1.computed)(oldNames => {
|
|
112
|
-
const newNames = scriptSetupRanges.get()?.importComponentNames ?? new Set();
|
|
113
|
-
if (oldNames && twoSetsEqual(newNames, oldNames)) {
|
|
114
|
-
return oldNames;
|
|
115
|
-
}
|
|
116
|
-
return newNames;
|
|
117
|
-
});
|
|
118
|
-
const destructuredPropNames = (0, alien_signals_1.computed)(oldNames => {
|
|
119
|
-
const newNames = scriptSetupRanges.get()?.props.destructured ?? new Set();
|
|
120
|
-
const rest = scriptSetupRanges.get()?.props.destructuredRest;
|
|
121
|
-
if (rest) {
|
|
122
|
-
newNames.add(rest);
|
|
123
|
-
}
|
|
124
|
-
if (oldNames && twoSetsEqual(newNames, oldNames)) {
|
|
125
|
-
return oldNames;
|
|
126
|
-
}
|
|
127
|
-
return newNames;
|
|
128
|
-
});
|
|
129
|
-
const templateRefNames = (0, alien_signals_1.computed)(oldNames => {
|
|
130
|
-
const newNames = new Set(scriptSetupRanges.get()?.templateRefs
|
|
131
|
-
.map(({ name }) => name)
|
|
132
|
-
.filter(name => name !== undefined));
|
|
133
|
-
if (oldNames && twoSetsEqual(newNames, oldNames)) {
|
|
134
|
-
return oldNames;
|
|
135
|
-
}
|
|
136
|
-
return newNames;
|
|
137
|
-
});
|
|
138
|
-
const hasDefineSlots = (0, alien_signals_1.computed)(() => !!scriptSetupRanges.get()?.slots.define);
|
|
139
|
-
const slotsAssignName = (0, alien_signals_1.computed)(() => scriptSetupRanges.get()?.slots.name);
|
|
140
|
-
const propsAssignName = (0, alien_signals_1.computed)(() => scriptSetupRanges.get()?.props.name);
|
|
141
|
-
const inheritAttrs = (0, alien_signals_1.computed)(() => {
|
|
142
|
-
const value = scriptSetupRanges.get()?.options.inheritAttrs ?? scriptRanges.get()?.exportDefault?.inheritAttrsOption;
|
|
143
|
-
return value !== 'false';
|
|
144
|
-
});
|
|
145
150
|
const generatedScript = (0, alien_signals_1.computed)(() => {
|
|
146
151
|
const codes = [];
|
|
147
152
|
const linkedCodeMappings = [];
|
|
148
153
|
let generatedLength = 0;
|
|
149
154
|
const codegen = (0, script_1.generateScript)({
|
|
150
155
|
ts,
|
|
151
|
-
|
|
156
|
+
compilerOptions: ctx.compilerOptions,
|
|
157
|
+
vueCompilerOptions: vueCompilerOptions.get(),
|
|
152
158
|
sfc: _sfc,
|
|
159
|
+
edited: vueCompilerOptions.get().__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
|
|
160
|
+
fileName,
|
|
153
161
|
lang: lang.get(),
|
|
154
162
|
scriptRanges: scriptRanges.get(),
|
|
155
163
|
scriptSetupRanges: scriptSetupRanges.get(),
|
|
156
164
|
templateCodegen: generatedTemplate.get(),
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
edited: ctx.vueCompilerOptions.__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
|
|
165
|
+
destructuredPropNames: destructuredPropNames.get(),
|
|
166
|
+
templateRefNames: templateRefNames.get(),
|
|
160
167
|
getGeneratedLength: () => generatedLength,
|
|
161
168
|
linkedCodeMappings,
|
|
162
169
|
appendGlobalTypes,
|
|
@@ -185,15 +192,4 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
|
|
|
185
192
|
generatedTemplate,
|
|
186
193
|
};
|
|
187
194
|
}
|
|
188
|
-
function twoSetsEqual(a, b) {
|
|
189
|
-
if (a.size !== b.size) {
|
|
190
|
-
return false;
|
|
191
|
-
}
|
|
192
|
-
for (const file of a) {
|
|
193
|
-
if (!b.has(file)) {
|
|
194
|
-
return false;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
return true;
|
|
198
|
-
}
|
|
199
195
|
//# sourceMappingURL=vue-tsx.js.map
|
package/lib/types.d.ts
CHANGED
|
@@ -37,8 +37,10 @@ export interface VueCompilerOptions {
|
|
|
37
37
|
defineOptions: string[];
|
|
38
38
|
withDefaults: string[];
|
|
39
39
|
};
|
|
40
|
-
|
|
40
|
+
composables: {
|
|
41
|
+
useAttrs: string[];
|
|
41
42
|
useCssModule: string[];
|
|
43
|
+
useSlots: string[];
|
|
42
44
|
useTemplateRef: string[];
|
|
43
45
|
};
|
|
44
46
|
plugins: VueLanguagePlugin[];
|
|
@@ -81,8 +83,8 @@ export type VueLanguagePluginReturn = {
|
|
|
81
83
|
};
|
|
82
84
|
export type VueLanguagePlugin = (ctx: {
|
|
83
85
|
modules: {
|
|
84
|
-
typescript: typeof
|
|
85
|
-
'@vue/compiler-dom': typeof
|
|
86
|
+
typescript: typeof ts;
|
|
87
|
+
'@vue/compiler-dom': typeof CompilerDOM;
|
|
86
88
|
};
|
|
87
89
|
compilerOptions: ts.CompilerOptions;
|
|
88
90
|
vueCompilerOptions: VueCompilerOptions;
|
|
@@ -97,14 +99,9 @@ export interface SfcBlock {
|
|
|
97
99
|
content: string;
|
|
98
100
|
attrs: Record<string, string | true>;
|
|
99
101
|
}
|
|
100
|
-
export interface SFCStyleOverride {
|
|
101
|
-
module?: {
|
|
102
|
-
name: string;
|
|
103
|
-
offset?: number;
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
102
|
export interface Sfc {
|
|
107
103
|
content: string;
|
|
104
|
+
comments: string[];
|
|
108
105
|
template: SfcBlock & {
|
|
109
106
|
ast: CompilerDOM.RootNode | undefined;
|
|
110
107
|
errors: CompilerDOM.CompilerError[];
|
|
@@ -120,8 +117,12 @@ export interface Sfc {
|
|
|
120
117
|
genericOffset: number;
|
|
121
118
|
ast: ts.SourceFile;
|
|
122
119
|
} | undefined;
|
|
123
|
-
styles: readonly (SfcBlock &
|
|
120
|
+
styles: readonly (SfcBlock & {
|
|
124
121
|
scoped: boolean;
|
|
122
|
+
module?: {
|
|
123
|
+
name: string;
|
|
124
|
+
offset?: number;
|
|
125
|
+
};
|
|
125
126
|
cssVars: {
|
|
126
127
|
text: string;
|
|
127
128
|
offset: number;
|
|
@@ -135,6 +136,14 @@ export interface Sfc {
|
|
|
135
136
|
type: string;
|
|
136
137
|
})[];
|
|
137
138
|
}
|
|
139
|
+
declare module '@vue/compiler-sfc' {
|
|
140
|
+
interface SFCStyleBlock {
|
|
141
|
+
__module?: {
|
|
142
|
+
name: string;
|
|
143
|
+
offset?: number;
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
}
|
|
138
147
|
export interface TextRange {
|
|
139
148
|
start: number;
|
|
140
149
|
end: number;
|
package/lib/utils/parseSfc.d.ts
CHANGED
package/lib/utils/parseSfc.js
CHANGED
|
@@ -18,6 +18,7 @@ function parse(source) {
|
|
|
18
18
|
const descriptor = {
|
|
19
19
|
filename: 'anonymous.vue',
|
|
20
20
|
source,
|
|
21
|
+
comments: [],
|
|
21
22
|
template: null,
|
|
22
23
|
script: null,
|
|
23
24
|
scriptSetup: null,
|
|
@@ -28,7 +29,11 @@ function parse(source) {
|
|
|
28
29
|
shouldForceReload: () => false,
|
|
29
30
|
};
|
|
30
31
|
ast.children.forEach(node => {
|
|
31
|
-
if (node.type
|
|
32
|
+
if (node.type === compiler.NodeTypes.COMMENT) {
|
|
33
|
+
descriptor.comments.push(node.content);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
else if (node.type !== compiler.NodeTypes.ELEMENT) {
|
|
32
37
|
return;
|
|
33
38
|
}
|
|
34
39
|
switch (node.tag) {
|
|
@@ -107,7 +112,7 @@ function createBlock(node, source) {
|
|
|
107
112
|
block.scoped = true;
|
|
108
113
|
}
|
|
109
114
|
else if (p.name === 'module') {
|
|
110
|
-
block.
|
|
115
|
+
block.__module = {
|
|
111
116
|
name: p.value?.content ?? '$style',
|
|
112
117
|
offset: p.value?.content ? p.value?.loc.start.offset - node.loc.start.offset : undefined
|
|
113
118
|
};
|
package/lib/utils/ts.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export declare function createParsedCommandLineByJson(ts: typeof import('typescr
|
|
|
7
7
|
writeFile?(path: string, data: string): void;
|
|
8
8
|
}, rootDir: string, json: any, configFileName?: string, skipGlobalTypesSetup?: boolean): ParsedCommandLine;
|
|
9
9
|
export declare function createParsedCommandLine(ts: typeof import('typescript'), parseConfigHost: ts.ParseConfigHost, tsConfigPath: string, skipGlobalTypesSetup?: boolean): ParsedCommandLine;
|
|
10
|
-
export declare function resolveVueCompilerOptions(
|
|
10
|
+
export declare function resolveVueCompilerOptions(options: Partial<VueCompilerOptions>, defaults?: VueCompilerOptions): VueCompilerOptions;
|
|
11
11
|
export declare function setupGlobalTypes(rootDir: string, vueOptions: VueCompilerOptions, host: {
|
|
12
12
|
fileExists(path: string): boolean;
|
|
13
13
|
writeFile?(path: string, data: string): void;
|