@vue/language-core 3.0.0-alpha.0 → 3.0.0-alpha.4
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 +47 -29
- package/lib/codegen/script/component.js +21 -9
- package/lib/codegen/script/index.js +1 -1
- package/lib/codegen/script/scriptSetup.js +1 -10
- package/lib/codegen/script/src.js +4 -3
- package/lib/codegen/script/styleModulesType.d.ts +4 -0
- package/lib/codegen/script/styleModulesType.js +34 -0
- package/lib/codegen/script/template.js +3 -5
- package/lib/codegen/template/context.d.ts +26 -17
- package/lib/codegen/template/context.js +87 -53
- package/lib/codegen/template/element.d.ts +2 -2
- package/lib/codegen/template/element.js +19 -27
- package/lib/codegen/template/elementChildren.d.ts +1 -1
- package/lib/codegen/template/elementChildren.js +4 -6
- package/lib/codegen/template/elementDirectives.js +1 -3
- package/lib/codegen/template/elementEvents.d.ts +1 -1
- package/lib/codegen/template/elementEvents.js +13 -10
- package/lib/codegen/template/elementProps.js +1 -1
- package/lib/codegen/template/index.js +20 -7
- package/lib/codegen/template/interpolation.d.ts +1 -1
- package/lib/codegen/template/interpolation.js +52 -52
- package/lib/codegen/template/slotOutlet.js +1 -2
- package/lib/codegen/template/templateChild.d.ts +1 -1
- package/lib/codegen/template/templateChild.js +12 -46
- package/lib/codegen/template/vFor.js +5 -10
- package/lib/codegen/template/vIf.js +2 -10
- package/lib/codegen/template/vSlot.d.ts +1 -2
- package/lib/codegen/template/vSlot.js +111 -59
- package/lib/codegen/utils/index.d.ts +1 -2
- package/lib/codegen/utils/index.js +0 -16
- package/lib/parsers/scriptSetupRanges.js +8 -6
- package/lib/plugins/vue-template-inline-css.js +1 -1
- package/lib/plugins/vue-template-inline-ts.js +2 -2
- package/lib/plugins/vue-tsx.d.ts +25 -16
- package/lib/plugins/vue-tsx.js +31 -19
- package/lib/types.d.ts +2 -1
- package/lib/utils/forEachElementNode.d.ts +1 -0
- package/lib/utils/forEachElementNode.js +3 -0
- package/lib/utils/ts.js +1 -0
- package/package.json +2 -2
|
@@ -2,5 +2,4 @@ import * as CompilerDOM from '@vue/compiler-dom';
|
|
|
2
2
|
import type { Code } from '../../types';
|
|
3
3
|
import type { TemplateCodegenContext } from './context';
|
|
4
4
|
import type { TemplateCodegenOptions } from './index';
|
|
5
|
-
export declare function generateVSlot(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, slotDir: CompilerDOM.DirectiveNode): Generator<Code>;
|
|
6
|
-
export declare function generateImplicitDefaultSlot(ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode): Generator<Code, void, any>;
|
|
5
|
+
export declare function generateVSlot(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, slotDir: CompilerDOM.DirectiveNode | undefined): Generator<Code>;
|
|
@@ -1,93 +1,145 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateVSlot = generateVSlot;
|
|
4
|
-
exports.generateImplicitDefaultSlot = generateImplicitDefaultSlot;
|
|
5
4
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
5
|
+
const shared_1 = require("../../utils/shared");
|
|
6
6
|
const utils_1 = require("../utils");
|
|
7
7
|
const wrapWith_1 = require("../utils/wrapWith");
|
|
8
|
+
const elementChildren_1 = require("./elementChildren");
|
|
8
9
|
const objectProperty_1 = require("./objectProperty");
|
|
9
|
-
const templateChild_1 = require("./templateChild");
|
|
10
10
|
function* generateVSlot(options, ctx, node, slotDir) {
|
|
11
11
|
if (!ctx.currentComponent) {
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
|
-
ctx.currentComponent.used = true;
|
|
15
14
|
const slotBlockVars = [];
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slotDir.arg.loc.source, slotDir.arg.loc.start.offset, slotDir.arg.isStatic ? ctx.codeFeatures.withoutHighlight : ctx.codeFeatures.all, slotDir.arg.loc, false, true);
|
|
15
|
+
const slotVar = ctx.getInternalVariable();
|
|
16
|
+
if (slotDir) {
|
|
17
|
+
yield `{${utils_1.newLine}`;
|
|
20
18
|
}
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
if (slotDir || node.children.length) {
|
|
20
|
+
ctx.currentComponent.used = true;
|
|
21
|
+
yield `const { `;
|
|
22
|
+
if (slotDir) {
|
|
23
|
+
if (slotDir.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && slotDir.arg.content) {
|
|
24
|
+
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slotDir.arg.loc.source, slotDir.arg.loc.start.offset, slotDir.arg.isStatic ? ctx.codeFeatures.withoutHighlight : ctx.codeFeatures.all, slotDir.arg.loc, false, true);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
yield* (0, wrapWith_1.wrapWith)(slotDir.loc.start.offset, slotDir.loc.start.offset + (slotDir.rawName?.length ?? 0), ctx.codeFeatures.withoutHighlightAndCompletion, `default`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
// #932: reference for implicit default slot
|
|
32
|
+
const { start, end } = getElementInnerLoc(options, node);
|
|
33
|
+
yield* (0, wrapWith_1.wrapWith)(start, end, ctx.codeFeatures.navigation, `default`);
|
|
34
|
+
}
|
|
35
|
+
yield `: ${slotVar} } = ${ctx.currentComponent.ctxVar}.slots!${utils_1.endOfLine}`;
|
|
23
36
|
}
|
|
24
|
-
|
|
25
|
-
if (slotDir.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
37
|
+
if (slotDir?.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
26
38
|
const slotAst = (0, utils_1.createTsAst)(options.ts, slotDir, `(${slotDir.exp.content}) => {}`);
|
|
27
39
|
(0, utils_1.collectVars)(options.ts, slotAst, slotAst, slotBlockVars);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
yield* generateSlotParameters(options, ctx, slotAst, slotDir.exp, slotVar);
|
|
41
|
+
}
|
|
42
|
+
for (const varName of slotBlockVars) {
|
|
43
|
+
ctx.addLocalVariable(varName);
|
|
44
|
+
}
|
|
45
|
+
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node.children);
|
|
46
|
+
for (const varName of slotBlockVars) {
|
|
47
|
+
ctx.removeLocalVariable(varName);
|
|
48
|
+
}
|
|
49
|
+
if (options.vueCompilerOptions.strictSlotChildren && node.children.length) {
|
|
50
|
+
const { start, end } = getElementInnerLoc(options, node);
|
|
51
|
+
yield `(): __VLS_NormalizeSlotReturns<typeof ${slotVar}> => (`;
|
|
52
|
+
yield* (0, wrapWith_1.wrapWith)(start, end, ctx.codeFeatures.verification, `{} as [`, ...ctx.currentComponent.childTypes.map(name => `${name}, `), `]`);
|
|
53
|
+
yield `)${utils_1.endOfLine}`;
|
|
54
|
+
}
|
|
55
|
+
if (slotDir) {
|
|
56
|
+
let isStatic = true;
|
|
57
|
+
if (slotDir.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
58
|
+
isStatic = slotDir.arg.isStatic;
|
|
37
59
|
}
|
|
38
|
-
|
|
39
|
-
yield
|
|
60
|
+
if (isStatic && !slotDir.arg) {
|
|
61
|
+
yield `${ctx.currentComponent.ctxVar}.slots!['`;
|
|
40
62
|
yield [
|
|
41
|
-
|
|
63
|
+
'',
|
|
42
64
|
'template',
|
|
43
|
-
slotDir.
|
|
44
|
-
|
|
65
|
+
slotDir.loc.start.offset + (slotDir.loc.source.startsWith('#')
|
|
66
|
+
? '#'.length
|
|
67
|
+
: slotDir.loc.source.startsWith('v-slot:')
|
|
68
|
+
? 'v-slot:'.length
|
|
69
|
+
: 0),
|
|
70
|
+
ctx.codeFeatures.completion,
|
|
45
71
|
];
|
|
46
|
-
yield `
|
|
72
|
+
yield `'/* empty slot name completion */]${utils_1.endOfLine}`;
|
|
47
73
|
}
|
|
74
|
+
yield `}${utils_1.newLine}`;
|
|
48
75
|
}
|
|
49
|
-
|
|
50
|
-
|
|
76
|
+
}
|
|
77
|
+
function* generateSlotParameters(options, ctx, ast, exp, slotVar) {
|
|
78
|
+
const { ts } = options;
|
|
79
|
+
const statement = ast.statements[0];
|
|
80
|
+
if (!ts.isExpressionStatement(statement) || !ts.isArrowFunction(statement.expression)) {
|
|
81
|
+
return;
|
|
51
82
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
83
|
+
const { expression } = statement;
|
|
84
|
+
const startOffset = exp.loc.start.offset - 1;
|
|
85
|
+
const modifies = [];
|
|
86
|
+
const types = [];
|
|
87
|
+
for (const { name, type } of expression.parameters) {
|
|
88
|
+
if (type) {
|
|
89
|
+
modifies.push([
|
|
90
|
+
[``],
|
|
91
|
+
name.end,
|
|
92
|
+
type.end,
|
|
93
|
+
]);
|
|
94
|
+
types.push(chunk((0, shared_1.getStartEnd)(ts, type, ast).start, type.end));
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
types.push(null);
|
|
98
|
+
}
|
|
57
99
|
}
|
|
58
|
-
|
|
59
|
-
|
|
100
|
+
yield `const [`;
|
|
101
|
+
let nextStart = 1;
|
|
102
|
+
for (const [codes, start, end] of modifies) {
|
|
103
|
+
yield chunk(nextStart, start);
|
|
104
|
+
yield* codes;
|
|
105
|
+
nextStart = end;
|
|
60
106
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
107
|
+
yield chunk(nextStart, expression.equalsGreaterThanToken.pos - 1);
|
|
108
|
+
yield `] = __VLS_getSlotParameters(${slotVar}`;
|
|
109
|
+
if (types.some(t => t)) {
|
|
110
|
+
yield `, `;
|
|
111
|
+
yield* (0, wrapWith_1.wrapWith)(exp.loc.start.offset, exp.loc.end.offset, ctx.codeFeatures.verification, `(`, ...types.flatMap(type => type ? [`_: `, type, `, `] : `_, `), `) => [] as any`);
|
|
64
112
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
113
|
+
yield `)${utils_1.endOfLine}`;
|
|
114
|
+
function chunk(start, end) {
|
|
115
|
+
return [
|
|
116
|
+
ast.text.slice(start, end),
|
|
69
117
|
'template',
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
: slotDir.loc.source.startsWith('v-slot:')
|
|
73
|
-
? 'v-slot:'.length
|
|
74
|
-
: 0),
|
|
75
|
-
ctx.codeFeatures.completion,
|
|
118
|
+
startOffset + start,
|
|
119
|
+
ctx.codeFeatures.all,
|
|
76
120
|
];
|
|
77
|
-
yield `'/* empty slot name completion */]${utils_1.endOfLine}`;
|
|
78
121
|
}
|
|
79
|
-
yield* ctx.generateAutoImportCompletion();
|
|
80
|
-
yield `}${utils_1.newLine}`;
|
|
81
122
|
}
|
|
82
|
-
function
|
|
83
|
-
if (!ctx.currentComponent) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
123
|
+
function getElementInnerLoc(options, node) {
|
|
86
124
|
if (node.children.length) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
125
|
+
let start = node.children[0].loc.start.offset;
|
|
126
|
+
let end = node.children.at(-1).loc.end.offset;
|
|
127
|
+
while (options.template.content[start - 1] !== '>') {
|
|
128
|
+
start--;
|
|
129
|
+
}
|
|
130
|
+
while (options.template.content[end] !== '<') {
|
|
131
|
+
end++;
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
start,
|
|
135
|
+
end,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
return {
|
|
140
|
+
start: node.loc.start.offset,
|
|
141
|
+
end: node.loc.end.offset,
|
|
142
|
+
};
|
|
91
143
|
}
|
|
92
144
|
}
|
|
93
145
|
//# sourceMappingURL=vSlot.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as CompilerDOM from '@vue/compiler-dom';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
|
-
import type { Code, SfcBlock,
|
|
3
|
+
import type { Code, SfcBlock, VueCodeInformation } from '../../types';
|
|
4
4
|
export declare const newLine = "\n";
|
|
5
5
|
export declare const endOfLine = ";\n";
|
|
6
6
|
export declare const combineLastMapping: VueCodeInformation;
|
|
@@ -18,4 +18,3 @@ export declare function collectIdentifiers(ts: typeof import('typescript'), node
|
|
|
18
18
|
export declare function normalizeAttributeValue(node: CompilerDOM.TextNode): [string, number];
|
|
19
19
|
export declare function createTsAst(ts: typeof import('typescript'), astHolder: any, text: string): ts.SourceFile;
|
|
20
20
|
export declare function generateSfcBlockSection(block: SfcBlock, start: number, end: number, features: VueCodeInformation): Code;
|
|
21
|
-
export declare function generateSfcBlockAttrValue(src: SfcBlockAttr & object, text: string, features: VueCodeInformation): Generator<Code>;
|
|
@@ -6,7 +6,6 @@ exports.collectIdentifiers = collectIdentifiers;
|
|
|
6
6
|
exports.normalizeAttributeValue = normalizeAttributeValue;
|
|
7
7
|
exports.createTsAst = createTsAst;
|
|
8
8
|
exports.generateSfcBlockSection = generateSfcBlockSection;
|
|
9
|
-
exports.generateSfcBlockAttrValue = generateSfcBlockAttrValue;
|
|
10
9
|
const shared_1 = require("../../utils/shared");
|
|
11
10
|
exports.newLine = `\n`;
|
|
12
11
|
exports.endOfLine = `;${exports.newLine}`;
|
|
@@ -65,19 +64,4 @@ function generateSfcBlockSection(block, start, end, features) {
|
|
|
65
64
|
features,
|
|
66
65
|
];
|
|
67
66
|
}
|
|
68
|
-
function* generateSfcBlockAttrValue(src, text, features) {
|
|
69
|
-
const { offset, quotes } = src;
|
|
70
|
-
if (!quotes) {
|
|
71
|
-
yield [``, 'main', offset, { verification: true }];
|
|
72
|
-
}
|
|
73
|
-
yield [
|
|
74
|
-
`'${text}'`,
|
|
75
|
-
'main',
|
|
76
|
-
quotes ? offset - 1 : offset,
|
|
77
|
-
features
|
|
78
|
-
];
|
|
79
|
-
if (!quotes) {
|
|
80
|
-
yield [``, 'main', offset + text.length, { __combineOffset: 2 }];
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
67
|
//# sourceMappingURL=index.js.map
|
|
@@ -159,7 +159,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
159
159
|
defaultValue,
|
|
160
160
|
required,
|
|
161
161
|
isModel: isDefineModel,
|
|
162
|
-
comments:
|
|
162
|
+
comments: getClosestMultiLineCommentRange(ts, node, parents, ast),
|
|
163
163
|
argNode: options,
|
|
164
164
|
});
|
|
165
165
|
}
|
|
@@ -410,18 +410,20 @@ function getStatementRange(ts, parents, node, ast) {
|
|
|
410
410
|
}
|
|
411
411
|
return statementRange;
|
|
412
412
|
}
|
|
413
|
-
function
|
|
413
|
+
function getClosestMultiLineCommentRange(ts, node, parents, ast) {
|
|
414
414
|
for (let i = parents.length - 1; i >= 0; i--) {
|
|
415
415
|
if (ts.isStatement(node)) {
|
|
416
416
|
break;
|
|
417
417
|
}
|
|
418
418
|
node = parents[i];
|
|
419
419
|
}
|
|
420
|
-
const
|
|
421
|
-
|
|
420
|
+
const comment = ts.getLeadingCommentRanges(ast.text, node.pos)
|
|
421
|
+
?.reverse()
|
|
422
|
+
.find(range => range.kind === 3);
|
|
423
|
+
if (comment) {
|
|
422
424
|
return {
|
|
423
|
-
start:
|
|
424
|
-
end:
|
|
425
|
+
start: comment.pos,
|
|
426
|
+
end: comment.end,
|
|
425
427
|
};
|
|
426
428
|
}
|
|
427
429
|
}
|
|
@@ -21,7 +21,7 @@ const plugin = () => {
|
|
|
21
21
|
if (embeddedFile.id !== 'template_inline_css' || !sfc.template?.ast) {
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
|
-
embeddedFile.parentCodeId = 'template';
|
|
24
|
+
embeddedFile.parentCodeId = sfc.template.lang === 'md' ? 'root_tags' : 'template';
|
|
25
25
|
embeddedFile.content.push(...generate(sfc.template.ast));
|
|
26
26
|
},
|
|
27
27
|
};
|
|
@@ -38,13 +38,13 @@ const plugin = ctx => {
|
|
|
38
38
|
},
|
|
39
39
|
resolveEmbeddedCode(_fileName, sfc, embeddedFile) {
|
|
40
40
|
// access template content to watch change
|
|
41
|
-
|
|
41
|
+
void sfc.template?.content;
|
|
42
42
|
const parsed = parseds.get(sfc);
|
|
43
43
|
if (parsed) {
|
|
44
44
|
const codes = parsed.get(embeddedFile.id);
|
|
45
45
|
if (codes) {
|
|
46
46
|
embeddedFile.content.push(...codes);
|
|
47
|
-
embeddedFile.parentCodeId = 'template';
|
|
47
|
+
embeddedFile.parentCodeId = sfc.template?.lang === 'md' ? 'root_tags' : 'template';
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
},
|
package/lib/plugins/vue-tsx.d.ts
CHANGED
|
@@ -138,6 +138,17 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
138
138
|
};
|
|
139
139
|
getGeneratedTemplate: () => {
|
|
140
140
|
codes: Code[];
|
|
141
|
+
currentInfo: {
|
|
142
|
+
ignoreError?: boolean;
|
|
143
|
+
expectError?: {
|
|
144
|
+
token: number;
|
|
145
|
+
node: import("@vue/compiler-dom").CommentNode;
|
|
146
|
+
};
|
|
147
|
+
generic?: {
|
|
148
|
+
content: string;
|
|
149
|
+
offset: number;
|
|
150
|
+
};
|
|
151
|
+
};
|
|
141
152
|
codeFeatures: {
|
|
142
153
|
all: import("../types").VueCodeInformation;
|
|
143
154
|
none: import("../types").VueCodeInformation;
|
|
@@ -157,6 +168,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
157
168
|
withoutHighlightAndCompletionAndNavigation: import("../types").VueCodeInformation;
|
|
158
169
|
};
|
|
159
170
|
resolveCodeFeatures: (features: import("../types").VueCodeInformation) => import("../types").VueCodeInformation;
|
|
171
|
+
inVFor: boolean;
|
|
160
172
|
slots: {
|
|
161
173
|
name: string;
|
|
162
174
|
offset?: number;
|
|
@@ -170,10 +182,6 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
170
182
|
}[];
|
|
171
183
|
dollarVars: Set<string>;
|
|
172
184
|
accessExternalVariables: Map<string, Set<number>>;
|
|
173
|
-
lastGenericComment: {
|
|
174
|
-
content: string;
|
|
175
|
-
offset: number;
|
|
176
|
-
} | undefined;
|
|
177
185
|
blockConditions: string[];
|
|
178
186
|
scopedClasses: {
|
|
179
187
|
source: string;
|
|
@@ -187,25 +195,26 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
187
195
|
templateRefs: Map<string, {
|
|
188
196
|
typeExp: string;
|
|
189
197
|
offset: number;
|
|
190
|
-
}>;
|
|
198
|
+
}[]>;
|
|
191
199
|
currentComponent: {
|
|
192
200
|
ctxVar: string;
|
|
201
|
+
childTypes: string[];
|
|
193
202
|
used: boolean;
|
|
194
203
|
} | undefined;
|
|
195
204
|
singleRootElTypes: string[];
|
|
196
205
|
singleRootNodes: Set<import("@vue/compiler-dom").ElementNode | null>;
|
|
206
|
+
addTemplateRef(name: string, typeExp: string, offset: number): void;
|
|
197
207
|
accessExternalVariable(name: string, offset?: number): void;
|
|
198
|
-
hasLocalVariable
|
|
199
|
-
addLocalVariable
|
|
200
|
-
removeLocalVariable
|
|
201
|
-
getInternalVariable
|
|
202
|
-
getHoistVariable
|
|
203
|
-
generateHoistVariables
|
|
204
|
-
generateConditionGuards
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
generateAutoImportCompletion: () => Generator<Code>;
|
|
208
|
+
hasLocalVariable(name: string): boolean;
|
|
209
|
+
addLocalVariable(name: string): void;
|
|
210
|
+
removeLocalVariable(name: string): void;
|
|
211
|
+
getInternalVariable(): string;
|
|
212
|
+
getHoistVariable(originalVar: string): string;
|
|
213
|
+
generateHoistVariables(): Generator<string, void, unknown>;
|
|
214
|
+
generateConditionGuards(): Generator<string, void, unknown>;
|
|
215
|
+
generateAutoImportCompletion(): Generator<Code>;
|
|
216
|
+
enter(node: import("@vue/compiler-dom").RootNode | import("@vue/compiler-dom").TemplateChildNode | import("@vue/compiler-dom").SimpleExpressionNode): boolean;
|
|
217
|
+
exit(): Generator<Code>;
|
|
209
218
|
} | undefined;
|
|
210
219
|
}>;
|
|
211
220
|
declare const plugin: VueLanguagePlugin;
|
package/lib/plugins/vue-tsx.js
CHANGED
|
@@ -12,6 +12,7 @@ const vueCompilerOptions_1 = require("../parsers/vueCompilerOptions");
|
|
|
12
12
|
const signals_1 = require("../utils/signals");
|
|
13
13
|
const ts_1 = require("../utils/ts");
|
|
14
14
|
exports.tsCodegen = new WeakMap();
|
|
15
|
+
const validLangs = new Set(['js', 'jsx', 'ts', 'tsx']);
|
|
15
16
|
const plugin = ctx => {
|
|
16
17
|
let appendedGlobalTypes = false;
|
|
17
18
|
return {
|
|
@@ -22,11 +23,10 @@ const plugin = ctx => {
|
|
|
22
23
|
],
|
|
23
24
|
getEmbeddedCodes(fileName, sfc) {
|
|
24
25
|
const codegen = useCodegen(fileName, sfc);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return files;
|
|
26
|
+
return [{
|
|
27
|
+
id: 'script_' + codegen.getLang(),
|
|
28
|
+
lang: codegen.getLang(),
|
|
29
|
+
}];
|
|
30
30
|
},
|
|
31
31
|
resolveEmbeddedCode(fileName, sfc, embeddedFile) {
|
|
32
32
|
if (/script_(js|jsx|ts|tsx)/.test(embeddedFile.id)) {
|
|
@@ -53,11 +53,23 @@ const plugin = ctx => {
|
|
|
53
53
|
exports.default = plugin;
|
|
54
54
|
function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
|
|
55
55
|
const ts = ctx.modules.typescript;
|
|
56
|
+
const getRawLang = (0, alien_signals_1.computed)(() => {
|
|
57
|
+
if (sfc.script && sfc.scriptSetup) {
|
|
58
|
+
if (sfc.scriptSetup.lang !== 'js') {
|
|
59
|
+
return sfc.scriptSetup.lang;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
return sfc.script.lang;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return sfc.scriptSetup?.lang ?? sfc.script?.lang;
|
|
66
|
+
});
|
|
56
67
|
const getLang = (0, alien_signals_1.computed)(() => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
68
|
+
const rawLang = getRawLang();
|
|
69
|
+
if (rawLang && validLangs.has(rawLang)) {
|
|
70
|
+
return rawLang;
|
|
71
|
+
}
|
|
72
|
+
return 'ts';
|
|
61
73
|
});
|
|
62
74
|
const getResolvedOptions = (0, alien_signals_1.computed)(() => {
|
|
63
75
|
const options = (0, vueCompilerOptions_1.parseVueCompilerOptions)(sfc.comments);
|
|
@@ -68,13 +80,13 @@ function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
|
|
|
68
80
|
}
|
|
69
81
|
return ctx.vueCompilerOptions;
|
|
70
82
|
});
|
|
71
|
-
const getScriptRanges = (0, alien_signals_1.computed)(() => sfc.script
|
|
83
|
+
const getScriptRanges = (0, alien_signals_1.computed)(() => sfc.script && validLangs.has(sfc.script.lang)
|
|
72
84
|
? (0, scriptRanges_1.parseScriptRanges)(ts, sfc.script.ast, !!sfc.scriptSetup, false)
|
|
73
85
|
: undefined);
|
|
74
|
-
const getScriptSetupRanges = (0, alien_signals_1.computed)(() => sfc.scriptSetup
|
|
86
|
+
const getScriptSetupRanges = (0, alien_signals_1.computed)(() => sfc.scriptSetup && validLangs.has(sfc.scriptSetup.lang)
|
|
75
87
|
? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, sfc.scriptSetup.ast, getResolvedOptions())
|
|
76
88
|
: undefined);
|
|
77
|
-
const getSetupBindingNames = (0, signals_1.computedSet)((
|
|
89
|
+
const getSetupBindingNames = (0, signals_1.computedSet)(() => {
|
|
78
90
|
const newNames = new Set();
|
|
79
91
|
const bindings = getScriptSetupRanges()?.bindings;
|
|
80
92
|
if (sfc.scriptSetup && bindings) {
|
|
@@ -83,8 +95,8 @@ function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
|
|
|
83
95
|
}
|
|
84
96
|
}
|
|
85
97
|
return newNames;
|
|
86
|
-
})
|
|
87
|
-
const getSetupImportComponentNames = (0, signals_1.computedSet)((
|
|
98
|
+
});
|
|
99
|
+
const getSetupImportComponentNames = (0, signals_1.computedSet)(() => {
|
|
88
100
|
const newNames = new Set();
|
|
89
101
|
const bindings = getScriptSetupRanges()?.bindings;
|
|
90
102
|
if (sfc.scriptSetup && bindings) {
|
|
@@ -98,21 +110,21 @@ function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
|
|
|
98
110
|
}
|
|
99
111
|
}
|
|
100
112
|
return newNames;
|
|
101
|
-
})
|
|
102
|
-
const getSetupDestructuredPropNames = (0, signals_1.computedSet)((
|
|
113
|
+
});
|
|
114
|
+
const getSetupDestructuredPropNames = (0, signals_1.computedSet)(() => {
|
|
103
115
|
const newNames = new Set(getScriptSetupRanges()?.defineProps?.destructured?.keys());
|
|
104
116
|
const rest = getScriptSetupRanges()?.defineProps?.destructuredRest;
|
|
105
117
|
if (rest) {
|
|
106
118
|
newNames.add(rest);
|
|
107
119
|
}
|
|
108
120
|
return newNames;
|
|
109
|
-
})
|
|
110
|
-
const getSetupTemplateRefNames = (0, signals_1.computedSet)((
|
|
121
|
+
});
|
|
122
|
+
const getSetupTemplateRefNames = (0, signals_1.computedSet)(() => {
|
|
111
123
|
const newNames = new Set(getScriptSetupRanges()?.useTemplateRef
|
|
112
124
|
.map(({ name }) => name)
|
|
113
125
|
.filter(name => name !== undefined));
|
|
114
126
|
return newNames;
|
|
115
|
-
})
|
|
127
|
+
});
|
|
116
128
|
const setupHasDefineSlots = (0, alien_signals_1.computed)(() => !!getScriptSetupRanges()?.defineSlots);
|
|
117
129
|
const getSetupSlotsAssignName = (0, alien_signals_1.computed)(() => getScriptSetupRanges()?.defineSlots?.name);
|
|
118
130
|
const getSetupPropsAssignName = (0, alien_signals_1.computed)(() => getScriptSetupRanges()?.defineProps?.name);
|
package/lib/types.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export type { SFCParseResult } from '@vue/compiler-sfc';
|
|
|
8
8
|
export { VueEmbeddedCode };
|
|
9
9
|
export type RawVueCompilerOptions = Partial<Omit<VueCompilerOptions, 'target' | 'plugins'>> & {
|
|
10
10
|
strictTemplates?: boolean;
|
|
11
|
-
target?: 'auto' | 2 | 2.7 | 3 | 3.3 | 3.5 | 99 | number;
|
|
11
|
+
target?: 'auto' | 2 | 2.7 | 3 | 3.3 | 3.5 | 3.6 | 99 | number;
|
|
12
12
|
plugins?: string[];
|
|
13
13
|
};
|
|
14
14
|
export interface VueCodeInformation extends CodeInformation {
|
|
@@ -23,6 +23,7 @@ export interface VueCompilerOptions {
|
|
|
23
23
|
vitePressExtensions: string[];
|
|
24
24
|
petiteVueExtensions: string[];
|
|
25
25
|
jsxSlots: boolean;
|
|
26
|
+
strictSlotChildren: boolean;
|
|
26
27
|
strictVModel: boolean;
|
|
27
28
|
checkUnknownProps: boolean;
|
|
28
29
|
checkUnknownEvents: boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/lib/utils/ts.js
CHANGED
|
@@ -217,6 +217,7 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
|
|
|
217
217
|
vitePressExtensions: [],
|
|
218
218
|
petiteVueExtensions: [],
|
|
219
219
|
jsxSlots: false,
|
|
220
|
+
strictSlotChildren: strictTemplates,
|
|
220
221
|
strictVModel: strictTemplates,
|
|
221
222
|
checkUnknownProps: strictTemplates,
|
|
222
223
|
checkUnknownEvents: strictTemplates,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/language-core",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"optional": true
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "1769cd6b94ec9e0cc2681b8dbba904f35856ba1c"
|
|
41
41
|
}
|