@vue/language-core 2.2.10 → 3.0.0-alpha.10
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 -2
- package/index.js +1 -1
- package/lib/codegen/codeFeatures.d.ts +5 -0
- package/lib/codegen/codeFeatures.js +5 -0
- package/lib/codegen/globalTypes.js +44 -31
- package/lib/codegen/localTypes.d.ts +2 -3
- package/lib/codegen/localTypes.js +5 -15
- package/lib/codegen/script/component.js +21 -9
- package/lib/codegen/script/context.d.ts +1 -1
- package/lib/codegen/script/context.js +1 -1
- package/lib/codegen/script/index.d.ts +1 -2
- package/lib/codegen/script/index.js +2 -18
- package/lib/codegen/script/scriptSetup.js +5 -16
- package/lib/codegen/script/src.js +4 -22
- package/lib/codegen/script/template.js +7 -6
- package/lib/codegen/template/context.d.ts +29 -19
- package/lib/codegen/template/context.js +87 -56
- package/lib/codegen/template/element.d.ts +2 -2
- package/lib/codegen/template/element.js +34 -63
- package/lib/codegen/template/elementChildren.d.ts +2 -2
- package/lib/codegen/template/elementChildren.js +4 -6
- package/lib/codegen/template/elementDirectives.js +3 -15
- package/lib/codegen/template/elementEvents.d.ts +4 -3
- package/lib/codegen/template/elementEvents.js +61 -29
- package/lib/codegen/template/elementProps.d.ts +2 -2
- package/lib/codegen/template/elementProps.js +11 -22
- package/lib/codegen/template/index.d.ts +1 -2
- package/lib/codegen/template/index.js +22 -11
- package/lib/codegen/template/interpolation.d.ts +1 -1
- package/lib/codegen/template/interpolation.js +53 -51
- package/lib/codegen/template/slotOutlet.js +2 -3
- package/lib/codegen/template/styleScopedClasses.js +2 -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 +2 -3
- package/lib/codegen/utils/index.js +2 -18
- package/lib/languagePlugin.d.ts +1 -1
- package/lib/languagePlugin.js +1 -7
- package/lib/parsers/scriptRanges.d.ts +2 -3
- package/lib/parsers/scriptRanges.js +10 -13
- package/lib/parsers/scriptSetupRanges.d.ts +0 -3
- package/lib/parsers/scriptSetupRanges.js +36 -43
- package/lib/plugins/file-md.js +3 -0
- package/lib/plugins/vue-style-css.d.ts +3 -0
- package/lib/plugins/vue-style-css.js +18 -0
- package/lib/plugins/vue-template-inline-css.js +1 -1
- package/lib/plugins/vue-template-inline-ts.js +5 -2
- package/lib/plugins/vue-tsx.d.ts +27 -18
- package/lib/plugins/vue-tsx.js +32 -24
- package/lib/plugins.d.ts +1 -1
- package/lib/types.d.ts +3 -2
- package/lib/utils/shared.d.ts +4 -1
- package/lib/utils/shared.js +12 -4
- package/lib/utils/signals.d.ts +1 -0
- package/lib/utils/signals.js +11 -0
- package/lib/utils/ts.d.ts +0 -4
- package/lib/utils/ts.js +4 -14
- package/lib/virtualFile/computedSfc.js +6 -6
- package/package.json +6 -8
- package/lib/utils/vue2TemplateCompiler.d.ts +0 -2
- package/lib/utils/vue2TemplateCompiler.js +0 -89
|
@@ -2,10 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseScriptSetupRanges = parseScriptSetupRanges;
|
|
4
4
|
exports.parseBindingRanges = parseBindingRanges;
|
|
5
|
-
exports.findBindingVars = findBindingVars;
|
|
6
|
-
exports.getStartEnd = getStartEnd;
|
|
7
|
-
exports.getNodeText = getNodeText;
|
|
8
5
|
const utils_1 = require("../codegen/utils");
|
|
6
|
+
const shared_1 = require("../utils/shared");
|
|
9
7
|
const tsCheckReg = /^\/\/\s*@ts-(?:no)?check($|\s)/;
|
|
10
8
|
function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
11
9
|
const defineProp = [];
|
|
@@ -28,24 +26,27 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
28
26
|
let foundNonImportExportNode = false;
|
|
29
27
|
let importSectionEndOffset = 0;
|
|
30
28
|
ts.forEachChild(ast, node => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
&& !isTypeExport
|
|
36
|
-
&& !ts.isEmptyStatement(node)
|
|
29
|
+
if (foundNonImportExportNode
|
|
30
|
+
|| ts.isImportDeclaration(node)
|
|
31
|
+
|| ts.isExportDeclaration(node)
|
|
32
|
+
|| ts.isEmptyStatement(node)
|
|
37
33
|
// fix https://github.com/vuejs/language-tools/issues/1223
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
34
|
+
|| ts.isImportEqualsDeclaration(node)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if ((ts.isTypeAliasDeclaration(node) || ts.isInterfaceDeclaration(node))
|
|
38
|
+
&& node.modifiers?.some(mod => mod.kind === ts.SyntaxKind.ExportKeyword)) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const commentRanges = ts.getLeadingCommentRanges(text, node.pos);
|
|
42
|
+
if (commentRanges?.length) {
|
|
43
|
+
const commentRange = commentRanges.sort((a, b) => a.pos - b.pos)[0];
|
|
44
|
+
importSectionEndOffset = commentRange.pos;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
importSectionEndOffset = (0, shared_1.getStartEnd)(ts, node, ast).start;
|
|
48
48
|
}
|
|
49
|
+
foundNonImportExportNode = true;
|
|
49
50
|
});
|
|
50
51
|
ts.forEachChild(ast, node => visitNode(node, [ast]));
|
|
51
52
|
const templateRefNames = new Set(useTemplateRef.map(ref => ref.name));
|
|
@@ -161,7 +162,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
161
162
|
defaultValue,
|
|
162
163
|
required,
|
|
163
164
|
isModel: isDefineModel,
|
|
164
|
-
comments:
|
|
165
|
+
comments: getClosestMultiLineCommentRange(ts, node, parents, ast),
|
|
165
166
|
argNode: options,
|
|
166
167
|
});
|
|
167
168
|
}
|
|
@@ -282,10 +283,10 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
282
283
|
};
|
|
283
284
|
}
|
|
284
285
|
function _getStartEnd(node) {
|
|
285
|
-
return getStartEnd(ts, node, ast);
|
|
286
|
+
return (0, shared_1.getStartEnd)(ts, node, ast);
|
|
286
287
|
}
|
|
287
288
|
function _getNodeText(node) {
|
|
288
|
-
return getNodeText(ts, node, ast);
|
|
289
|
+
return (0, shared_1.getNodeText)(ts, node, ast);
|
|
289
290
|
}
|
|
290
291
|
}
|
|
291
292
|
function parseBindingRanges(ts, ast) {
|
|
@@ -353,10 +354,10 @@ function parseBindingRanges(ts, ast) {
|
|
|
353
354
|
});
|
|
354
355
|
return bindings;
|
|
355
356
|
function _getStartEnd(node) {
|
|
356
|
-
return getStartEnd(ts, node, ast);
|
|
357
|
+
return (0, shared_1.getStartEnd)(ts, node, ast);
|
|
357
358
|
}
|
|
358
359
|
function _getNodeText(node) {
|
|
359
|
-
return getNodeText(ts, node, ast);
|
|
360
|
+
return (0, shared_1.getNodeText)(ts, node, ast);
|
|
360
361
|
}
|
|
361
362
|
function _findBindingVars(left) {
|
|
362
363
|
return findBindingVars(ts, left, ast);
|
|
@@ -368,7 +369,7 @@ function findBindingVars(ts, left, ast) {
|
|
|
368
369
|
return vars;
|
|
369
370
|
function worker(node) {
|
|
370
371
|
if (ts.isIdentifier(node)) {
|
|
371
|
-
vars.push(getStartEnd(ts, node, ast));
|
|
372
|
+
vars.push((0, shared_1.getStartEnd)(ts, node, ast));
|
|
372
373
|
}
|
|
373
374
|
// { ? } = ...
|
|
374
375
|
// [ ? ] = ...
|
|
@@ -385,7 +386,7 @@ function findBindingVars(ts, left, ast) {
|
|
|
385
386
|
}
|
|
386
387
|
// { foo } = ...
|
|
387
388
|
else if (ts.isShorthandPropertyAssignment(node)) {
|
|
388
|
-
vars.push(getStartEnd(ts, node.name, ast));
|
|
389
|
+
vars.push((0, shared_1.getStartEnd)(ts, node.name, ast));
|
|
389
390
|
}
|
|
390
391
|
// { ...? } = ...
|
|
391
392
|
// [ ...? ] = ...
|
|
@@ -394,23 +395,13 @@ function findBindingVars(ts, left, ast) {
|
|
|
394
395
|
}
|
|
395
396
|
}
|
|
396
397
|
}
|
|
397
|
-
function getStartEnd(ts, node, ast) {
|
|
398
|
-
return {
|
|
399
|
-
start: ts.getTokenPosOfNode(node, ast),
|
|
400
|
-
end: node.end,
|
|
401
|
-
};
|
|
402
|
-
}
|
|
403
|
-
function getNodeText(ts, node, ast) {
|
|
404
|
-
const { start, end } = getStartEnd(ts, node, ast);
|
|
405
|
-
return ast.text.slice(start, end);
|
|
406
|
-
}
|
|
407
398
|
function getStatementRange(ts, parents, node, ast) {
|
|
408
399
|
let statementRange;
|
|
409
400
|
for (let i = parents.length - 1; i >= 0; i--) {
|
|
410
401
|
if (ts.isStatement(parents[i])) {
|
|
411
402
|
const statement = parents[i];
|
|
412
403
|
ts.forEachChild(statement, child => {
|
|
413
|
-
const range = getStartEnd(ts, child, ast);
|
|
404
|
+
const range = (0, shared_1.getStartEnd)(ts, child, ast);
|
|
414
405
|
statementRange ??= range;
|
|
415
406
|
statementRange.end = range.end;
|
|
416
407
|
});
|
|
@@ -418,22 +409,24 @@ function getStatementRange(ts, parents, node, ast) {
|
|
|
418
409
|
}
|
|
419
410
|
}
|
|
420
411
|
if (!statementRange) {
|
|
421
|
-
statementRange = getStartEnd(ts, node, ast);
|
|
412
|
+
statementRange = (0, shared_1.getStartEnd)(ts, node, ast);
|
|
422
413
|
}
|
|
423
414
|
return statementRange;
|
|
424
415
|
}
|
|
425
|
-
function
|
|
416
|
+
function getClosestMultiLineCommentRange(ts, node, parents, ast) {
|
|
426
417
|
for (let i = parents.length - 1; i >= 0; i--) {
|
|
427
418
|
if (ts.isStatement(node)) {
|
|
428
419
|
break;
|
|
429
420
|
}
|
|
430
421
|
node = parents[i];
|
|
431
422
|
}
|
|
432
|
-
const
|
|
433
|
-
|
|
423
|
+
const comment = ts.getLeadingCommentRanges(ast.text, node.pos)
|
|
424
|
+
?.reverse()
|
|
425
|
+
.find(range => range.kind === 3);
|
|
426
|
+
if (comment) {
|
|
434
427
|
return {
|
|
435
|
-
start:
|
|
436
|
-
end:
|
|
428
|
+
start: comment.pos,
|
|
429
|
+
end: comment.end,
|
|
437
430
|
};
|
|
438
431
|
}
|
|
439
432
|
}
|
package/lib/plugins/file-md.js
CHANGED
|
@@ -4,6 +4,7 @@ const language_core_1 = require("@volar/language-core");
|
|
|
4
4
|
const muggle_string_1 = require("muggle-string");
|
|
5
5
|
const buildMappings_1 = require("../utils/buildMappings");
|
|
6
6
|
const parseSfc_1 = require("../utils/parseSfc");
|
|
7
|
+
const frontmatterReg = /^---[\s\S]*?\n---(?:\r?\n|$)/;
|
|
7
8
|
const codeblockReg = /(`{3,})[\s\S]+?\1/g;
|
|
8
9
|
const inlineCodeblockReg = /`[^\n`]+?`/g;
|
|
9
10
|
const latexBlockReg = /(\${2,})[\s\S]+?\1/g;
|
|
@@ -28,6 +29,8 @@ const plugin = ({ vueCompilerOptions }) => {
|
|
|
28
29
|
return;
|
|
29
30
|
}
|
|
30
31
|
content = content
|
|
32
|
+
// frontmatter
|
|
33
|
+
.replace(frontmatterReg, match => ' '.repeat(match.length))
|
|
31
34
|
// code block
|
|
32
35
|
.replace(codeblockReg, (match, quotes) => quotes + ' '.repeat(match.length - quotes.length * 2) + quotes)
|
|
33
36
|
// inline code block
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const css = require("css-tree");
|
|
4
|
+
const plugin = () => {
|
|
5
|
+
return {
|
|
6
|
+
version: 2.1,
|
|
7
|
+
compileSFCStyle(lang, style) {
|
|
8
|
+
if (lang === 'css' || lang === 'scss' || lang === 'sass' || lang === 'less') {
|
|
9
|
+
return css.parse(style, {
|
|
10
|
+
filename: 'test.' + lang,
|
|
11
|
+
positions: true,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
exports.default = plugin;
|
|
18
|
+
//# sourceMappingURL=vue-style-css.js.map
|
|
@@ -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
|
};
|
|
@@ -37,14 +37,17 @@ const plugin = ctx => {
|
|
|
37
37
|
return result;
|
|
38
38
|
},
|
|
39
39
|
resolveEmbeddedCode(_fileName, sfc, embeddedFile) {
|
|
40
|
+
if (!embeddedFile.id.startsWith('template_inline_ts_')) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
40
43
|
// access template content to watch change
|
|
41
|
-
|
|
44
|
+
void sfc.template?.content;
|
|
42
45
|
const parsed = parseds.get(sfc);
|
|
43
46
|
if (parsed) {
|
|
44
47
|
const codes = parsed.get(embeddedFile.id);
|
|
45
48
|
if (codes) {
|
|
46
49
|
embeddedFile.content.push(...codes);
|
|
47
|
-
embeddedFile.parentCodeId = 'template';
|
|
50
|
+
embeddedFile.parentCodeId = sfc.template?.lang === 'md' ? 'root_tags' : 'template';
|
|
48
51
|
}
|
|
49
52
|
}
|
|
50
53
|
},
|
package/lib/plugins/vue-tsx.d.ts
CHANGED
|
@@ -4,14 +4,13 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
4
4
|
exportDefault: (import("../types").TextRange & {
|
|
5
5
|
expression: import("../types").TextRange;
|
|
6
6
|
args: import("../types").TextRange;
|
|
7
|
-
argsNode: import("typescript").ObjectLiteralExpression
|
|
7
|
+
argsNode: import("typescript").ObjectLiteralExpression;
|
|
8
8
|
componentsOption: import("../types").TextRange | undefined;
|
|
9
9
|
componentsOptionNode: import("typescript").ObjectLiteralExpression | undefined;
|
|
10
10
|
directivesOption: import("../types").TextRange | undefined;
|
|
11
11
|
nameOption: import("../types").TextRange | undefined;
|
|
12
12
|
inheritAttrsOption: string | undefined;
|
|
13
13
|
}) | undefined;
|
|
14
|
-
classBlockEnd: number | undefined;
|
|
15
14
|
bindings: {
|
|
16
15
|
range: import("../types").TextRange;
|
|
17
16
|
moduleName?: string;
|
|
@@ -138,6 +137,17 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
138
137
|
};
|
|
139
138
|
getGeneratedTemplate: () => {
|
|
140
139
|
codes: Code[];
|
|
140
|
+
currentInfo: {
|
|
141
|
+
ignoreError?: boolean;
|
|
142
|
+
expectError?: {
|
|
143
|
+
token: number;
|
|
144
|
+
node: import("@vue/compiler-dom").CommentNode;
|
|
145
|
+
};
|
|
146
|
+
generic?: {
|
|
147
|
+
content: string;
|
|
148
|
+
offset: number;
|
|
149
|
+
};
|
|
150
|
+
};
|
|
141
151
|
codeFeatures: {
|
|
142
152
|
all: import("../types").VueCodeInformation;
|
|
143
153
|
none: import("../types").VueCodeInformation;
|
|
@@ -155,8 +165,10 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
155
165
|
withoutHighlightAndNavigation: import("../types").VueCodeInformation;
|
|
156
166
|
withoutHighlightAndCompletion: import("../types").VueCodeInformation;
|
|
157
167
|
withoutHighlightAndCompletionAndNavigation: import("../types").VueCodeInformation;
|
|
168
|
+
withoutSemantic: 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,7 +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
|
|
15
|
+
const validLangs = new Set(['js', 'jsx', 'ts', 'tsx']);
|
|
16
16
|
const plugin = ctx => {
|
|
17
17
|
let appendedGlobalTypes = false;
|
|
18
18
|
return {
|
|
@@ -23,11 +23,10 @@ const plugin = ctx => {
|
|
|
23
23
|
],
|
|
24
24
|
getEmbeddedCodes(fileName, sfc) {
|
|
25
25
|
const codegen = useCodegen(fileName, sfc);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return files;
|
|
26
|
+
return [{
|
|
27
|
+
id: 'script_' + codegen.getLang(),
|
|
28
|
+
lang: codegen.getLang(),
|
|
29
|
+
}];
|
|
31
30
|
},
|
|
32
31
|
resolveEmbeddedCode(fileName, sfc, embeddedFile) {
|
|
33
32
|
if (/script_(js|jsx|ts|tsx)/.test(embeddedFile.id)) {
|
|
@@ -54,11 +53,23 @@ const plugin = ctx => {
|
|
|
54
53
|
exports.default = plugin;
|
|
55
54
|
function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
|
|
56
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
|
+
});
|
|
57
67
|
const getLang = (0, alien_signals_1.computed)(() => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
68
|
+
const rawLang = getRawLang();
|
|
69
|
+
if (rawLang && validLangs.has(rawLang)) {
|
|
70
|
+
return rawLang;
|
|
71
|
+
}
|
|
72
|
+
return 'ts';
|
|
62
73
|
});
|
|
63
74
|
const getResolvedOptions = (0, alien_signals_1.computed)(() => {
|
|
64
75
|
const options = (0, vueCompilerOptions_1.parseVueCompilerOptions)(sfc.comments);
|
|
@@ -69,13 +80,13 @@ function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
|
|
|
69
80
|
}
|
|
70
81
|
return ctx.vueCompilerOptions;
|
|
71
82
|
});
|
|
72
|
-
const getScriptRanges = (0, alien_signals_1.computed)(() => sfc.script
|
|
73
|
-
? (0, scriptRanges_1.parseScriptRanges)(ts, sfc.script.ast, !!sfc.scriptSetup
|
|
83
|
+
const getScriptRanges = (0, alien_signals_1.computed)(() => sfc.script && validLangs.has(sfc.script.lang)
|
|
84
|
+
? (0, scriptRanges_1.parseScriptRanges)(ts, sfc.script.ast, !!sfc.scriptSetup)
|
|
74
85
|
: undefined);
|
|
75
|
-
const getScriptSetupRanges = (0, alien_signals_1.computed)(() => sfc.scriptSetup
|
|
86
|
+
const getScriptSetupRanges = (0, alien_signals_1.computed)(() => sfc.scriptSetup && validLangs.has(sfc.scriptSetup.lang)
|
|
76
87
|
? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, sfc.scriptSetup.ast, getResolvedOptions())
|
|
77
88
|
: undefined);
|
|
78
|
-
const getSetupBindingNames = (0, signals_1.computedSet)((
|
|
89
|
+
const getSetupBindingNames = (0, signals_1.computedSet)(() => {
|
|
79
90
|
const newNames = new Set();
|
|
80
91
|
const bindings = getScriptSetupRanges()?.bindings;
|
|
81
92
|
if (sfc.scriptSetup && bindings) {
|
|
@@ -84,8 +95,8 @@ function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
|
|
|
84
95
|
}
|
|
85
96
|
}
|
|
86
97
|
return newNames;
|
|
87
|
-
})
|
|
88
|
-
const getSetupImportComponentNames = (0, signals_1.computedSet)((
|
|
98
|
+
});
|
|
99
|
+
const getSetupImportComponentNames = (0, signals_1.computedSet)(() => {
|
|
89
100
|
const newNames = new Set();
|
|
90
101
|
const bindings = getScriptSetupRanges()?.bindings;
|
|
91
102
|
if (sfc.scriptSetup && bindings) {
|
|
@@ -99,21 +110,21 @@ function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
|
|
|
99
110
|
}
|
|
100
111
|
}
|
|
101
112
|
return newNames;
|
|
102
|
-
})
|
|
103
|
-
const getSetupDestructuredPropNames = (0, signals_1.computedSet)((
|
|
113
|
+
});
|
|
114
|
+
const getSetupDestructuredPropNames = (0, signals_1.computedSet)(() => {
|
|
104
115
|
const newNames = new Set(getScriptSetupRanges()?.defineProps?.destructured?.keys());
|
|
105
116
|
const rest = getScriptSetupRanges()?.defineProps?.destructuredRest;
|
|
106
117
|
if (rest) {
|
|
107
118
|
newNames.add(rest);
|
|
108
119
|
}
|
|
109
120
|
return newNames;
|
|
110
|
-
})
|
|
111
|
-
const getSetupTemplateRefNames = (0, signals_1.computedSet)((
|
|
121
|
+
});
|
|
122
|
+
const getSetupTemplateRefNames = (0, signals_1.computedSet)(() => {
|
|
112
123
|
const newNames = new Set(getScriptSetupRanges()?.useTemplateRef
|
|
113
124
|
.map(({ name }) => name)
|
|
114
125
|
.filter(name => name !== undefined));
|
|
115
126
|
return newNames;
|
|
116
|
-
})
|
|
127
|
+
});
|
|
117
128
|
const setupHasDefineSlots = (0, alien_signals_1.computed)(() => !!getScriptSetupRanges()?.defineSlots);
|
|
118
129
|
const getSetupSlotsAssignName = (0, alien_signals_1.computed)(() => getScriptSetupRanges()?.defineSlots?.name);
|
|
119
130
|
const getSetupPropsAssignName = (0, alien_signals_1.computed)(() => getScriptSetupRanges()?.defineProps?.name);
|
|
@@ -144,7 +155,6 @@ function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
|
|
|
144
155
|
compilerOptions: ctx.compilerOptions,
|
|
145
156
|
vueCompilerOptions: getResolvedOptions(),
|
|
146
157
|
template: sfc.template,
|
|
147
|
-
edited: getResolvedOptions().__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
|
|
148
158
|
scriptSetupBindingNames: getSetupBindingNames(),
|
|
149
159
|
scriptSetupImportComponentNames: getSetupImportComponentNames(),
|
|
150
160
|
destructuredPropNames: getSetupDestructuredPropNames(),
|
|
@@ -173,7 +183,6 @@ function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
|
|
|
173
183
|
compilerOptions: ctx.compilerOptions,
|
|
174
184
|
vueCompilerOptions: getResolvedOptions(),
|
|
175
185
|
sfc: sfc,
|
|
176
|
-
edited: getResolvedOptions().__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
|
|
177
186
|
fileName,
|
|
178
187
|
lang: getLang(),
|
|
179
188
|
scriptRanges: getScriptRanges(),
|
|
@@ -183,7 +192,6 @@ function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
|
|
|
183
192
|
templateRefNames: getSetupTemplateRefNames(),
|
|
184
193
|
appendGlobalTypes,
|
|
185
194
|
});
|
|
186
|
-
fileEditTimes.set(fileName, (fileEditTimes.get(fileName) ?? 0) + 1);
|
|
187
195
|
let current = codegen.next();
|
|
188
196
|
while (!current.done) {
|
|
189
197
|
const code = current.value;
|
package/lib/plugins.d.ts
CHANGED
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' |
|
|
11
|
+
target?: 'auto' | 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,8 @@ export interface VueCompilerOptions {
|
|
|
23
23
|
vitePressExtensions: string[];
|
|
24
24
|
petiteVueExtensions: string[];
|
|
25
25
|
jsxSlots: boolean;
|
|
26
|
+
strictSlotChildren: boolean;
|
|
27
|
+
strictVModel: boolean;
|
|
26
28
|
checkUnknownProps: boolean;
|
|
27
29
|
checkUnknownEvents: boolean;
|
|
28
30
|
checkUnknownDirectives: boolean;
|
|
@@ -61,7 +63,6 @@ export interface VueCompilerOptions {
|
|
|
61
63
|
__setupedGlobalTypes?: true | {
|
|
62
64
|
absolutePath: string;
|
|
63
65
|
};
|
|
64
|
-
__test?: boolean;
|
|
65
66
|
}
|
|
66
67
|
export declare const validVersions: readonly [2, 2.1];
|
|
67
68
|
export type VueLanguagePluginReturn = {
|
package/lib/utils/shared.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import type * as ts from 'typescript';
|
|
2
|
+
import type { TextRange } from '../types';
|
|
2
3
|
export { hyphenate as hyphenateTag } from '@vue/shared';
|
|
3
4
|
export declare function hyphenateAttr(str: string): string;
|
|
5
|
+
export declare function getStartEnd(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): TextRange;
|
|
6
|
+
export declare function getNodeText(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): string;
|
package/lib/utils/shared.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.hyphenateTag = void 0;
|
|
4
|
-
exports.getSlotsPropertyName = getSlotsPropertyName;
|
|
5
4
|
exports.hyphenateAttr = hyphenateAttr;
|
|
5
|
+
exports.getStartEnd = getStartEnd;
|
|
6
|
+
exports.getNodeText = getNodeText;
|
|
6
7
|
const shared_1 = require("@vue/shared");
|
|
7
|
-
function getSlotsPropertyName(vueVersion) {
|
|
8
|
-
return vueVersion < 3 ? '$scopedSlots' : '$slots';
|
|
9
|
-
}
|
|
10
8
|
var shared_2 = require("@vue/shared");
|
|
11
9
|
Object.defineProperty(exports, "hyphenateTag", { enumerable: true, get: function () { return shared_2.hyphenate; } });
|
|
12
10
|
function hyphenateAttr(str) {
|
|
@@ -17,4 +15,14 @@ function hyphenateAttr(str) {
|
|
|
17
15
|
}
|
|
18
16
|
return hyphencase;
|
|
19
17
|
}
|
|
18
|
+
function getStartEnd(ts, node, ast) {
|
|
19
|
+
return {
|
|
20
|
+
start: ts.getTokenPosOfNode(node, ast),
|
|
21
|
+
end: node.end,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function getNodeText(ts, node, ast) {
|
|
25
|
+
const { start, end } = getStartEnd(ts, node, ast);
|
|
26
|
+
return ast.text.slice(start, end);
|
|
27
|
+
}
|
|
20
28
|
//# sourceMappingURL=shared.js.map
|
package/lib/utils/signals.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export declare function computedArray<I, O>(arr: () => I[], getGetter: (item: () => I, index: number) => () => O): readonly Readonly<O>[];
|
|
2
2
|
export declare function computedSet<T>(source: () => Set<T>): () => Set<T>;
|
|
3
|
+
export declare function computedItems<T>(source: () => T[], compareFn: (oldItem: T, newItem: T) => boolean): () => T[];
|
package/lib/utils/signals.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.computedArray = computedArray;
|
|
4
4
|
exports.computedSet = computedSet;
|
|
5
|
+
exports.computedItems = computedItems;
|
|
5
6
|
const alien_signals_1 = require("alien-signals");
|
|
6
7
|
function computedArray(arr, getGetter) {
|
|
7
8
|
const length = (0, alien_signals_1.computed)(() => arr().length);
|
|
@@ -51,4 +52,14 @@ function computedSet(source) {
|
|
|
51
52
|
return newValue;
|
|
52
53
|
});
|
|
53
54
|
}
|
|
55
|
+
function computedItems(source, compareFn) {
|
|
56
|
+
return (0, alien_signals_1.computed)(oldArr => {
|
|
57
|
+
oldArr ??= [];
|
|
58
|
+
const newArr = source();
|
|
59
|
+
if (oldArr.length === newArr.length && oldArr.every((item, index) => compareFn(item, newArr[index]))) {
|
|
60
|
+
return oldArr;
|
|
61
|
+
}
|
|
62
|
+
return newArr;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
54
65
|
//# sourceMappingURL=signals.js.map
|
package/lib/utils/ts.d.ts
CHANGED
|
@@ -16,10 +16,6 @@ export declare class CompilerOptionsResolver {
|
|
|
16
16
|
build(defaults?: VueCompilerOptions): VueCompilerOptions;
|
|
17
17
|
}
|
|
18
18
|
export declare function getDefaultCompilerOptions(target?: number, lib?: string, strictTemplates?: boolean): VueCompilerOptions;
|
|
19
|
-
/**
|
|
20
|
-
* @deprecated use `getDefaultCompilerOptions` instead
|
|
21
|
-
*/
|
|
22
|
-
export declare function resolveVueCompilerOptions(options: Partial<VueCompilerOptions>): VueCompilerOptions;
|
|
23
19
|
export declare function setupGlobalTypes(rootDir: string, vueOptions: VueCompilerOptions, host: {
|
|
24
20
|
fileExists(path: string): boolean;
|
|
25
21
|
writeFile?(path: string, data: string): void;
|
package/lib/utils/ts.js
CHANGED
|
@@ -4,7 +4,6 @@ exports.CompilerOptionsResolver = void 0;
|
|
|
4
4
|
exports.createParsedCommandLineByJson = createParsedCommandLineByJson;
|
|
5
5
|
exports.createParsedCommandLine = createParsedCommandLine;
|
|
6
6
|
exports.getDefaultCompilerOptions = getDefaultCompilerOptions;
|
|
7
|
-
exports.resolveVueCompilerOptions = resolveVueCompilerOptions;
|
|
8
7
|
exports.setupGlobalTypes = setupGlobalTypes;
|
|
9
8
|
const shared_1 = require("@vue/shared");
|
|
10
9
|
const path_browserify_1 = require("path-browserify");
|
|
@@ -132,7 +131,7 @@ class CompilerOptionsResolver {
|
|
|
132
131
|
break;
|
|
133
132
|
case 'plugins':
|
|
134
133
|
this.plugins = (options.plugins ?? [])
|
|
135
|
-
.
|
|
134
|
+
.flatMap((pluginPath) => {
|
|
136
135
|
try {
|
|
137
136
|
const resolvedPath = resolvePath(pluginPath, rootDir);
|
|
138
137
|
if (resolvedPath) {
|
|
@@ -218,6 +217,8 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
|
|
|
218
217
|
vitePressExtensions: [],
|
|
219
218
|
petiteVueExtensions: [],
|
|
220
219
|
jsxSlots: false,
|
|
220
|
+
strictSlotChildren: strictTemplates,
|
|
221
|
+
strictVModel: strictTemplates,
|
|
221
222
|
checkUnknownProps: strictTemplates,
|
|
222
223
|
checkUnknownEvents: strictTemplates,
|
|
223
224
|
checkUnknownDirectives: strictTemplates,
|
|
@@ -238,9 +239,7 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
|
|
|
238
239
|
],
|
|
239
240
|
dataAttributes: [],
|
|
240
241
|
htmlAttributes: ['aria-*'],
|
|
241
|
-
optionsWrapper:
|
|
242
|
-
? [`(await import('${lib}')).defineComponent(`, `)`]
|
|
243
|
-
: [`(await import('${lib}')).default.extend(`, `)`],
|
|
242
|
+
optionsWrapper: [`(await import('${lib}')).defineComponent(`, `)`],
|
|
244
243
|
macros: {
|
|
245
244
|
defineProps: ['defineProps'],
|
|
246
245
|
defineSlots: ['defineSlots'],
|
|
@@ -271,15 +270,6 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
|
|
|
271
270
|
},
|
|
272
271
|
};
|
|
273
272
|
}
|
|
274
|
-
/**
|
|
275
|
-
* @deprecated use `getDefaultCompilerOptions` instead
|
|
276
|
-
*/
|
|
277
|
-
function resolveVueCompilerOptions(options) {
|
|
278
|
-
return {
|
|
279
|
-
...getDefaultCompilerOptions(options.target, options.lib),
|
|
280
|
-
...options,
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
273
|
function setupGlobalTypes(rootDir, vueOptions, host) {
|
|
284
274
|
if (!host.writeFile) {
|
|
285
275
|
return;
|