@vue/language-core 2.1.10 → 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 +11 -2
- package/lib/codegen/localTypes.js +3 -3
- package/lib/codegen/script/component.js +42 -42
- package/lib/codegen/script/componentSelf.js +13 -13
- package/lib/codegen/script/context.js +2 -2
- package/lib/codegen/script/index.d.ts +5 -3
- package/lib/codegen/script/index.js +19 -37
- package/lib/codegen/script/scriptSetup.js +240 -197
- 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 +86 -98
- 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 -83
- package/lib/parsers/scriptSetupRanges.js +193 -167
- 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 -74
- package/lib/plugins/vue-tsx.js +65 -68
- 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/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,90 +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
|
-
statement: import("../types").TextRange;
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
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
|
+
} & {
|
|
50
64
|
name?: string;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
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
|
+
} & {
|
|
61
74
|
name?: string;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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: {
|
|
69
85
|
name?: string;
|
|
70
86
|
inheritAttrs?: string;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}>;
|
|
87
|
+
} | undefined;
|
|
88
|
+
useAttrs: {
|
|
89
|
+
callExp: import("../types").TextRange;
|
|
90
|
+
exp: import("../types").TextRange;
|
|
91
|
+
arg?: import("../types").TextRange;
|
|
92
|
+
typeArg?: import("../types").TextRange;
|
|
78
93
|
}[];
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
runtimeType: import("../types").TextRange | undefined;
|
|
85
|
-
defaultValue: import("../types").TextRange | undefined;
|
|
86
|
-
required: boolean;
|
|
87
|
-
isModel?: boolean;
|
|
94
|
+
useCssModule: {
|
|
95
|
+
callExp: import("../types").TextRange;
|
|
96
|
+
exp: import("../types").TextRange;
|
|
97
|
+
arg?: import("../types").TextRange;
|
|
98
|
+
typeArg?: import("../types").TextRange;
|
|
88
99
|
}[];
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
typeArg?: import("../types").TextRange;
|
|
95
|
-
}>;
|
|
100
|
+
useSlots: {
|
|
101
|
+
callExp: import("../types").TextRange;
|
|
102
|
+
exp: import("../types").TextRange;
|
|
103
|
+
arg?: import("../types").TextRange;
|
|
104
|
+
typeArg?: import("../types").TextRange;
|
|
96
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
|
+
})[];
|
|
97
114
|
} | undefined>;
|
|
98
|
-
lang: import("alien-signals").
|
|
99
|
-
generatedScript: import("alien-signals").
|
|
115
|
+
lang: import("alien-signals").Computed<string>;
|
|
116
|
+
generatedScript: import("alien-signals").Computed<{
|
|
100
117
|
codes: Code[];
|
|
101
118
|
linkedCodeMappings: Mapping<unknown>[];
|
|
102
119
|
generatedTemplate: boolean;
|
|
@@ -117,7 +134,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
117
134
|
};
|
|
118
135
|
inlayHints: import("../codegen/inlayHints").InlayHintInfo[];
|
|
119
136
|
}>;
|
|
120
|
-
generatedTemplate: import("alien-signals").
|
|
137
|
+
generatedTemplate: import("alien-signals").Computed<{
|
|
121
138
|
codes: Code[];
|
|
122
139
|
slots: {
|
|
123
140
|
name: string;
|
|
@@ -139,14 +156,18 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
139
156
|
navigationWithoutRename: import("../types").VueCodeInformation;
|
|
140
157
|
navigationAndCompletion: import("../types").VueCodeInformation;
|
|
141
158
|
navigationAndAdditionalCompletion: import("../types").VueCodeInformation;
|
|
159
|
+
withoutNavigation: import("../types").VueCodeInformation;
|
|
142
160
|
withoutHighlight: import("../types").VueCodeInformation;
|
|
143
161
|
withoutHighlightAndCompletion: import("../types").VueCodeInformation;
|
|
144
162
|
withoutHighlightAndCompletionAndNavigation: import("../types").VueCodeInformation;
|
|
145
163
|
};
|
|
146
164
|
accessExternalVariables: Map<string, Set<number>>;
|
|
165
|
+
lastGenericComment: {
|
|
166
|
+
content: string;
|
|
167
|
+
offset: number;
|
|
168
|
+
} | undefined;
|
|
147
169
|
hasSlotElements: Set<import("@vue/compiler-dom").ElementNode>;
|
|
148
170
|
blockConditions: string[];
|
|
149
|
-
usedComponentCtxVars: Set<string>;
|
|
150
171
|
scopedClasses: {
|
|
151
172
|
source: string;
|
|
152
173
|
className: string;
|
|
@@ -155,8 +176,14 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
155
176
|
emptyClassOffsets: number[];
|
|
156
177
|
inlayHints: import("../codegen/inlayHints").InlayHintInfo[];
|
|
157
178
|
hasSlot: boolean;
|
|
158
|
-
|
|
179
|
+
bindingAttrLocs: import("@vue/compiler-dom").SourceLocation[];
|
|
180
|
+
inheritedAttrVars: Set<string>;
|
|
159
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;
|
|
160
187
|
singleRootElType: string | undefined;
|
|
161
188
|
singleRootNode: import("@vue/compiler-dom").ElementNode | undefined;
|
|
162
189
|
accessExternalVariable(name: string, offset?: number): void;
|
package/lib/plugins/vue-tsx.js
CHANGED
|
@@ -6,6 +6,8 @@ const script_1 = require("../codegen/script");
|
|
|
6
6
|
const template_1 = require("../codegen/template");
|
|
7
7
|
const scriptRanges_1 = require("../parsers/scriptRanges");
|
|
8
8
|
const scriptSetupRanges_1 = require("../parsers/scriptSetupRanges");
|
|
9
|
+
const vueCompilerOptions_1 = require("../parsers/vueCompilerOptions");
|
|
10
|
+
const ts_1 = require("../utils/ts");
|
|
9
11
|
exports.tsCodegen = new WeakMap();
|
|
10
12
|
const fileEditTimes = new Map();
|
|
11
13
|
const plugin = ctx => {
|
|
@@ -29,8 +31,7 @@ const plugin = ctx => {
|
|
|
29
31
|
if (/script_(js|jsx|ts|tsx)/.test(embeddedFile.id)) {
|
|
30
32
|
const tsx = _tsx.generatedScript.get();
|
|
31
33
|
if (tsx) {
|
|
32
|
-
|
|
33
|
-
embeddedFile.content = content;
|
|
34
|
+
embeddedFile.content = [...tsx.codes];
|
|
34
35
|
embeddedFile.linkedCodeMappings = [...tsx.linkedCodeMappings];
|
|
35
36
|
}
|
|
36
37
|
}
|
|
@@ -57,23 +58,75 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
|
|
|
57
58
|
: _sfc.script && _sfc.script.lang !== 'js' ? _sfc.script.lang
|
|
58
59
|
: 'js';
|
|
59
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
|
+
});
|
|
60
67
|
const scriptRanges = (0, alien_signals_1.computed)(() => _sfc.script
|
|
61
68
|
? (0, scriptRanges_1.parseScriptRanges)(ts, _sfc.script.ast, !!_sfc.scriptSetup, false)
|
|
62
69
|
: undefined);
|
|
63
70
|
const scriptSetupRanges = (0, alien_signals_1.computed)(() => _sfc.scriptSetup
|
|
64
|
-
? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, _sfc.scriptSetup.ast,
|
|
71
|
+
? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, _sfc.scriptSetup.ast, vueCompilerOptions.get())
|
|
65
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
|
+
});
|
|
66
119
|
const generatedTemplate = (0, alien_signals_1.computed)(() => {
|
|
67
|
-
if (
|
|
120
|
+
if (vueCompilerOptions.get().skipTemplateCodegen || !_sfc.template) {
|
|
68
121
|
return;
|
|
69
122
|
}
|
|
70
123
|
const codes = [];
|
|
71
124
|
const codegen = (0, template_1.generateTemplate)({
|
|
72
125
|
ts,
|
|
73
126
|
compilerOptions: ctx.compilerOptions,
|
|
74
|
-
vueCompilerOptions:
|
|
127
|
+
vueCompilerOptions: vueCompilerOptions.get(),
|
|
75
128
|
template: _sfc.template,
|
|
76
|
-
edited:
|
|
129
|
+
edited: vueCompilerOptions.get().__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
|
|
77
130
|
scriptSetupBindingNames: scriptSetupBindingNames.get(),
|
|
78
131
|
scriptSetupImportComponentNames: scriptSetupImportComponentNames.get(),
|
|
79
132
|
destructuredPropNames: destructuredPropNames.get(),
|
|
@@ -94,68 +147,23 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
|
|
|
94
147
|
codes: codes,
|
|
95
148
|
};
|
|
96
149
|
});
|
|
97
|
-
const scriptSetupBindingNames = (0, alien_signals_1.computed)(oldNames => {
|
|
98
|
-
const newNames = new Set();
|
|
99
|
-
const bindings = scriptSetupRanges.get()?.bindings;
|
|
100
|
-
if (_sfc.scriptSetup && bindings) {
|
|
101
|
-
for (const binding of bindings) {
|
|
102
|
-
newNames.add(_sfc.scriptSetup?.content.substring(binding.start, binding.end));
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
if (newNames && oldNames && twoSetsEqual(newNames, oldNames)) {
|
|
106
|
-
return oldNames;
|
|
107
|
-
}
|
|
108
|
-
return newNames;
|
|
109
|
-
});
|
|
110
|
-
const scriptSetupImportComponentNames = (0, alien_signals_1.computed)(oldNames => {
|
|
111
|
-
const newNames = scriptSetupRanges.get()?.importComponentNames ?? new Set();
|
|
112
|
-
if (oldNames && twoSetsEqual(newNames, oldNames)) {
|
|
113
|
-
return oldNames;
|
|
114
|
-
}
|
|
115
|
-
return newNames;
|
|
116
|
-
});
|
|
117
|
-
const destructuredPropNames = (0, alien_signals_1.computed)(oldNames => {
|
|
118
|
-
const newNames = scriptSetupRanges.get()?.props.destructured ?? new Set();
|
|
119
|
-
const rest = scriptSetupRanges.get()?.props.destructuredRest;
|
|
120
|
-
if (rest) {
|
|
121
|
-
newNames.add(rest);
|
|
122
|
-
}
|
|
123
|
-
if (oldNames && twoSetsEqual(newNames, oldNames)) {
|
|
124
|
-
return oldNames;
|
|
125
|
-
}
|
|
126
|
-
return newNames;
|
|
127
|
-
});
|
|
128
|
-
const templateRefNames = (0, alien_signals_1.computed)(oldNames => {
|
|
129
|
-
const newNames = new Set(scriptSetupRanges.get()?.templateRefs
|
|
130
|
-
.map(({ name }) => name)
|
|
131
|
-
.filter(name => name !== undefined));
|
|
132
|
-
if (oldNames && twoSetsEqual(newNames, oldNames)) {
|
|
133
|
-
return oldNames;
|
|
134
|
-
}
|
|
135
|
-
return newNames;
|
|
136
|
-
});
|
|
137
|
-
const hasDefineSlots = (0, alien_signals_1.computed)(() => !!scriptSetupRanges.get()?.slots.define);
|
|
138
|
-
const slotsAssignName = (0, alien_signals_1.computed)(() => scriptSetupRanges.get()?.slots.name);
|
|
139
|
-
const propsAssignName = (0, alien_signals_1.computed)(() => scriptSetupRanges.get()?.props.name);
|
|
140
|
-
const inheritAttrs = (0, alien_signals_1.computed)(() => {
|
|
141
|
-
const value = scriptSetupRanges.get()?.options.inheritAttrs ?? scriptRanges.get()?.exportDefault?.inheritAttrsOption;
|
|
142
|
-
return value !== 'false';
|
|
143
|
-
});
|
|
144
150
|
const generatedScript = (0, alien_signals_1.computed)(() => {
|
|
145
151
|
const codes = [];
|
|
146
152
|
const linkedCodeMappings = [];
|
|
147
153
|
let generatedLength = 0;
|
|
148
154
|
const codegen = (0, script_1.generateScript)({
|
|
149
155
|
ts,
|
|
150
|
-
|
|
156
|
+
compilerOptions: ctx.compilerOptions,
|
|
157
|
+
vueCompilerOptions: vueCompilerOptions.get(),
|
|
151
158
|
sfc: _sfc,
|
|
159
|
+
edited: vueCompilerOptions.get().__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
|
|
160
|
+
fileName,
|
|
152
161
|
lang: lang.get(),
|
|
153
162
|
scriptRanges: scriptRanges.get(),
|
|
154
163
|
scriptSetupRanges: scriptSetupRanges.get(),
|
|
155
164
|
templateCodegen: generatedTemplate.get(),
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
edited: ctx.vueCompilerOptions.__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
|
|
165
|
+
destructuredPropNames: destructuredPropNames.get(),
|
|
166
|
+
templateRefNames: templateRefNames.get(),
|
|
159
167
|
getGeneratedLength: () => generatedLength,
|
|
160
168
|
linkedCodeMappings,
|
|
161
169
|
appendGlobalTypes,
|
|
@@ -184,15 +192,4 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
|
|
|
184
192
|
generatedTemplate,
|
|
185
193
|
};
|
|
186
194
|
}
|
|
187
|
-
function twoSetsEqual(a, b) {
|
|
188
|
-
if (a.size !== b.size) {
|
|
189
|
-
return false;
|
|
190
|
-
}
|
|
191
|
-
for (const file of a) {
|
|
192
|
-
if (!b.has(file)) {
|
|
193
|
-
return false;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
return true;
|
|
197
|
-
}
|
|
198
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;
|