@vue/language-core 2.0.15 → 2.0.17
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/script/component.js +2 -2
- package/lib/codegen/script/globalTypes.js +3 -3
- package/lib/codegen/script/index.d.ts +3 -6
- package/lib/codegen/script/index.js +12 -15
- package/lib/codegen/script/internalComponent.js +1 -1
- package/lib/codegen/script/scriptSetup.js +25 -23
- package/lib/codegen/script/template.d.ts +1 -1
- package/lib/codegen/script/template.js +45 -36
- package/lib/codegen/template/context.d.ts +8 -3
- package/lib/codegen/template/context.js +42 -13
- package/lib/codegen/template/element.js +81 -49
- package/lib/codegen/template/elementChildren.js +2 -1
- package/lib/codegen/template/elementDirectives.js +1 -1
- package/lib/codegen/template/elementEvents.d.ts +2 -2
- package/lib/codegen/template/elementEvents.js +16 -7
- package/lib/codegen/template/elementProps.js +18 -14
- package/lib/codegen/template/index.d.ts +4 -46
- package/lib/codegen/template/index.js +36 -21
- package/lib/codegen/template/interpolation.d.ts +2 -2
- package/lib/codegen/template/interpolation.js +12 -46
- package/lib/codegen/template/slotOutlet.js +29 -30
- package/lib/languageModule.d.ts +1 -1
- package/lib/languageModule.js +4 -4
- package/lib/parsers/scriptRanges.d.ts +1 -0
- package/lib/parsers/scriptRanges.js +7 -0
- package/lib/parsers/scriptSetupRanges.d.ts +4 -0
- package/lib/parsers/scriptSetupRanges.js +24 -0
- package/lib/plugins/vue-template-inline-ts.js +1 -1
- package/lib/plugins/vue-tsx.d.ts +46 -40
- package/lib/plugins/vue-tsx.js +34 -28
- package/lib/plugins.d.ts +1 -1
- package/lib/types.d.ts +1 -15
- package/lib/utils/parseCssClassNames.js +1 -1
- package/lib/utils/ts.js +0 -1
- package/lib/virtualFile/computedFiles.js +34 -33
- package/lib/virtualFile/computedSfc.js +0 -3
- package/package.json +3 -3
|
@@ -29,41 +29,40 @@ function* generateSlotOutlet(options, ctx, node, currentComponent, componentCtxV
|
|
|
29
29
|
yield `)?.(`;
|
|
30
30
|
yield* (0, common_1.wrapWith)(startTagOffset, startTagOffset + node.tag.length, ctx.codeFeatures.verification, `{${common_1.newLine}`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), true), `}`);
|
|
31
31
|
yield `)${common_1.endOfLine}`;
|
|
32
|
-
return;
|
|
33
32
|
}
|
|
34
33
|
else {
|
|
35
34
|
yield `var ${varSlot} = {${common_1.newLine}`;
|
|
36
35
|
yield* (0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), true);
|
|
37
36
|
yield `}${common_1.endOfLine}`;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
37
|
+
if (nameProp?.type === CompilerDOM.NodeTypes.ATTRIBUTE
|
|
38
|
+
&& nameProp.value) {
|
|
39
|
+
ctx.slots.push({
|
|
40
|
+
name: nameProp.value.content,
|
|
41
|
+
loc: nameProp.loc.start.offset + nameProp.loc.source.indexOf(nameProp.value.content, nameProp.name.length),
|
|
42
|
+
tagRange: [startTagOffset, startTagOffset + node.tag.length],
|
|
43
|
+
varName: varSlot,
|
|
44
|
+
nodeLoc: node.loc,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
else if (nameProp?.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
48
|
+
&& nameProp.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
49
|
+
const slotExpVar = ctx.getInternalVariable();
|
|
50
|
+
yield `var ${slotExpVar} = `;
|
|
51
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, nameProp.exp.content, nameProp.exp, nameProp.exp.loc.start.offset, ctx.codeFeatures.all, '(', ')');
|
|
52
|
+
yield ` as const${common_1.endOfLine}`;
|
|
53
|
+
ctx.dynamicSlots.push({
|
|
54
|
+
expVar: slotExpVar,
|
|
55
|
+
varName: varSlot,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
ctx.slots.push({
|
|
60
|
+
name: 'default',
|
|
61
|
+
tagRange: [startTagOffset, startTagOffset + node.tag.length],
|
|
62
|
+
varName: varSlot,
|
|
63
|
+
nodeLoc: node.loc,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
67
66
|
}
|
|
68
67
|
yield* ctx.generateAutoImportCompletion();
|
|
69
68
|
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node, currentComponent, componentCtxVar);
|
package/lib/languageModule.d.ts
CHANGED
|
@@ -6,4 +6,4 @@ export interface _Plugin extends LanguagePlugin<VueVirtualCode> {
|
|
|
6
6
|
getCanonicalFileName: (fileName: string) => string;
|
|
7
7
|
pluginContext: Parameters<VueLanguagePlugin>[0];
|
|
8
8
|
}
|
|
9
|
-
export declare function createVueLanguagePlugin(ts: typeof import('typescript'), getFileName: (
|
|
9
|
+
export declare function createVueLanguagePlugin(ts: typeof import('typescript'), getFileName: (scriptId: string) => string, useCaseSensitiveFileNames: boolean, getProjectVersion: () => string, getScriptFileNames: () => string[] | Set<string>, compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions): _Plugin;
|
package/lib/languageModule.js
CHANGED
|
@@ -76,9 +76,9 @@ function createVueLanguagePlugin(ts, getFileName, useCaseSensitiveFileNames, get
|
|
|
76
76
|
return 'html';
|
|
77
77
|
}
|
|
78
78
|
},
|
|
79
|
-
createVirtualCode(
|
|
79
|
+
createVirtualCode(scriptId, languageId, snapshot) {
|
|
80
80
|
if (languageId === 'vue' || languageId === 'markdown' || languageId === 'html') {
|
|
81
|
-
const fileName = getFileName(
|
|
81
|
+
const fileName = getFileName(scriptId);
|
|
82
82
|
const projectVersion = getProjectVersion();
|
|
83
83
|
if (projectVersion !== canonicalRootFileNamesVersion) {
|
|
84
84
|
canonicalRootFileNames = new Set([...getScriptFileNames()].map(getCanonicalFileName));
|
|
@@ -88,7 +88,7 @@ function createVueLanguagePlugin(ts, getFileName, useCaseSensitiveFileNames, get
|
|
|
88
88
|
pluginContext.globalTypesHolder = fileName;
|
|
89
89
|
}
|
|
90
90
|
const fileRegistry = getFileRegistry(pluginContext.globalTypesHolder === fileName);
|
|
91
|
-
const code = fileRegistry.get(
|
|
91
|
+
const code = fileRegistry.get(scriptId);
|
|
92
92
|
if (code) {
|
|
93
93
|
code.update(snapshot);
|
|
94
94
|
return code;
|
|
@@ -99,7 +99,7 @@ function createVueLanguagePlugin(ts, getFileName, useCaseSensitiveFileNames, get
|
|
|
99
99
|
: languageId === 'markdown'
|
|
100
100
|
? [vitePressSfcPlugin, ...basePlugins]
|
|
101
101
|
: [vueSfcPlugin, ...basePlugins], ts);
|
|
102
|
-
fileRegistry.set(
|
|
102
|
+
fileRegistry.set(scriptId, code);
|
|
103
103
|
return code;
|
|
104
104
|
}
|
|
105
105
|
}
|
|
@@ -11,5 +11,6 @@ export declare function parseScriptRanges(ts: typeof import('typescript'), ast:
|
|
|
11
11
|
componentsOptionNode: ts.ObjectLiteralExpression | undefined;
|
|
12
12
|
nameOption: TextRange | undefined;
|
|
13
13
|
}) | undefined;
|
|
14
|
+
classBlockEnd: number | undefined;
|
|
14
15
|
bindings: TextRange[];
|
|
15
16
|
};
|
|
@@ -4,6 +4,7 @@ exports.parseScriptRanges = void 0;
|
|
|
4
4
|
const scriptSetupRanges_1 = require("./scriptSetupRanges");
|
|
5
5
|
function parseScriptRanges(ts, ast, hasScriptSetup, withNode) {
|
|
6
6
|
let exportDefault;
|
|
7
|
+
let classBlockEnd;
|
|
7
8
|
const bindings = hasScriptSetup ? (0, scriptSetupRanges_1.parseBindingRanges)(ts, ast) : [];
|
|
8
9
|
ts.forEachChild(ast, raw => {
|
|
9
10
|
if (ts.isExportAssignment(raw)) {
|
|
@@ -46,9 +47,15 @@ function parseScriptRanges(ts, ast, hasScriptSetup, withNode) {
|
|
|
46
47
|
};
|
|
47
48
|
}
|
|
48
49
|
}
|
|
50
|
+
if (ts.isClassDeclaration(raw)
|
|
51
|
+
&& raw.modifiers?.some(mod => mod.kind === ts.SyntaxKind.ExportKeyword)
|
|
52
|
+
&& raw.modifiers?.some(mod => mod.kind === ts.SyntaxKind.DefaultKeyword)) {
|
|
53
|
+
classBlockEnd = raw.end - 1;
|
|
54
|
+
}
|
|
49
55
|
});
|
|
50
56
|
return {
|
|
51
57
|
exportDefault,
|
|
58
|
+
classBlockEnd,
|
|
52
59
|
bindings,
|
|
53
60
|
};
|
|
54
61
|
function _getStartEnd(node) {
|
|
@@ -6,6 +6,7 @@ export declare function parseScriptSetupRanges(ts: typeof import('typescript'),
|
|
|
6
6
|
leadingCommentEndOffset: number;
|
|
7
7
|
importSectionEndOffset: number;
|
|
8
8
|
bindings: TextRange[];
|
|
9
|
+
importComponentNames: Set<string>;
|
|
9
10
|
props: {
|
|
10
11
|
name?: string | undefined;
|
|
11
12
|
define?: (TextRange & {
|
|
@@ -49,6 +50,9 @@ export declare function parseScriptSetupRanges(ts: typeof import('typescript'),
|
|
|
49
50
|
required: boolean;
|
|
50
51
|
isModel?: boolean | undefined;
|
|
51
52
|
}[];
|
|
53
|
+
options: {
|
|
54
|
+
name?: string | undefined;
|
|
55
|
+
};
|
|
52
56
|
};
|
|
53
57
|
export declare function parseBindingRanges(ts: typeof import('typescript'), sourceFile: ts.SourceFile): TextRange[];
|
|
54
58
|
export declare function findBindingVars(ts: typeof import('typescript'), left: ts.BindingName, sourceFile: ts.SourceFile): TextRange[];
|
|
@@ -8,12 +8,14 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
8
8
|
const slots = {};
|
|
9
9
|
const emits = {};
|
|
10
10
|
const expose = {};
|
|
11
|
+
const options = {};
|
|
11
12
|
const definePropProposalA = vueCompilerOptions.experimentalDefinePropProposal === 'kevinEdition' || ast.text.trimStart().startsWith('// @experimentalDefinePropProposal=kevinEdition');
|
|
12
13
|
const definePropProposalB = vueCompilerOptions.experimentalDefinePropProposal === 'johnsonEdition' || ast.text.trimStart().startsWith('// @experimentalDefinePropProposal=johnsonEdition');
|
|
13
14
|
const defineProp = [];
|
|
14
15
|
const bindings = parseBindingRanges(ts, ast);
|
|
15
16
|
const text = ast.text;
|
|
16
17
|
const leadingCommentEndOffset = ts.getLeadingCommentRanges(text, 0)?.reverse()[0].end ?? 0;
|
|
18
|
+
const importComponentNames = new Set();
|
|
17
19
|
ts.forEachChild(ast, node => {
|
|
18
20
|
const isTypeExport = (ts.isTypeAliasDeclaration(node) || ts.isInterfaceDeclaration(node)) && node.modifiers?.some(mod => mod.kind === ts.SyntaxKind.ExportKeyword);
|
|
19
21
|
if (!foundNonImportExportNode
|
|
@@ -32,17 +34,27 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
32
34
|
}
|
|
33
35
|
foundNonImportExportNode = true;
|
|
34
36
|
}
|
|
37
|
+
if (ts.isImportDeclaration(node)
|
|
38
|
+
&& node.importClause?.name
|
|
39
|
+
&& !node.importClause.isTypeOnly) {
|
|
40
|
+
const moduleName = getNodeText(ts, node.moduleSpecifier, ast).slice(1, -1);
|
|
41
|
+
if (vueCompilerOptions.extensions.some(ext => moduleName.endsWith(ext))) {
|
|
42
|
+
importComponentNames.add(getNodeText(ts, node.importClause.name, ast));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
35
45
|
});
|
|
36
46
|
ts.forEachChild(ast, child => visitNode(child, [ast]));
|
|
37
47
|
return {
|
|
38
48
|
leadingCommentEndOffset,
|
|
39
49
|
importSectionEndOffset,
|
|
40
50
|
bindings,
|
|
51
|
+
importComponentNames,
|
|
41
52
|
props,
|
|
42
53
|
slots,
|
|
43
54
|
emits,
|
|
44
55
|
expose,
|
|
45
56
|
defineProp,
|
|
57
|
+
options,
|
|
46
58
|
};
|
|
47
59
|
function _getStartEnd(node) {
|
|
48
60
|
return getStartEnd(ts, node, ast);
|
|
@@ -196,6 +208,15 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
196
208
|
props.name = getNodeText(ts, parent.name, ast);
|
|
197
209
|
}
|
|
198
210
|
}
|
|
211
|
+
else if (vueCompilerOptions.macros.defineOptions.includes(callText)) {
|
|
212
|
+
if (node.arguments.length && ts.isObjectLiteralExpression(node.arguments[0])) {
|
|
213
|
+
for (const prop of node.arguments[0].properties) {
|
|
214
|
+
if ((ts.isPropertyAssignment(prop)) && getNodeText(ts, prop.name, ast) === 'name' && ts.isStringLiteral(prop.initializer)) {
|
|
215
|
+
options.name = prop.initializer.text;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
199
220
|
}
|
|
200
221
|
ts.forEachChild(node, child => {
|
|
201
222
|
parents.push(node);
|
|
@@ -237,6 +258,9 @@ function parseBindingRanges(ts, sourceFile) {
|
|
|
237
258
|
if (node.importClause.namedBindings) {
|
|
238
259
|
if (ts.isNamedImports(node.importClause.namedBindings)) {
|
|
239
260
|
for (const element of node.importClause.namedBindings.elements) {
|
|
261
|
+
if (element.isTypeOnly) {
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
240
264
|
bindings.push(_getStartEnd(element.name));
|
|
241
265
|
}
|
|
242
266
|
}
|
|
@@ -74,7 +74,7 @@ const plugin = ctx => {
|
|
|
74
74
|
if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
75
75
|
&& prop.exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY // style='z-index: 2' will compile to {'z-index':'2'}
|
|
76
76
|
) {
|
|
77
|
-
if (prop.name === 'on') {
|
|
77
|
+
if (prop.name === 'on' && prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
78
78
|
const ast = (0, common_1.createTsAst)(ctx.modules.typescript, prop.exp, prop.exp.content);
|
|
79
79
|
addFormatCodes(prop.exp.content, prop.exp.loc.start.offset, (0, elementEvents_1.isCompoundExpression)(ctx.modules.typescript, ast)
|
|
80
80
|
? formatBrackets.event
|
package/lib/plugins/vue-tsx.d.ts
CHANGED
|
@@ -10,12 +10,14 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
10
10
|
componentsOptionNode: import("typescript").ObjectLiteralExpression | undefined;
|
|
11
11
|
nameOption: import("../types").TextRange | undefined;
|
|
12
12
|
}) | undefined;
|
|
13
|
+
classBlockEnd: number | undefined;
|
|
13
14
|
bindings: import("../types").TextRange[];
|
|
14
15
|
} | undefined;
|
|
15
16
|
scriptSetupRanges: () => {
|
|
16
17
|
leadingCommentEndOffset: number;
|
|
17
18
|
importSectionEndOffset: number;
|
|
18
19
|
bindings: import("../types").TextRange[];
|
|
20
|
+
importComponentNames: Set<string>;
|
|
19
21
|
props: {
|
|
20
22
|
name?: string | undefined;
|
|
21
23
|
define?: (import("../types").TextRange & {
|
|
@@ -59,6 +61,9 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
59
61
|
required: boolean;
|
|
60
62
|
isModel?: boolean | undefined;
|
|
61
63
|
}[];
|
|
64
|
+
options: {
|
|
65
|
+
name?: string | undefined;
|
|
66
|
+
};
|
|
62
67
|
} | undefined;
|
|
63
68
|
lang: () => string;
|
|
64
69
|
generatedScript: () => {
|
|
@@ -67,48 +72,49 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
67
72
|
};
|
|
68
73
|
generatedTemplate: () => {
|
|
69
74
|
codes: Code[];
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
accessGlobalVariables: Map<string, Set<number>>;
|
|
94
|
-
hasSlotElements: Set<import("@vue/compiler-dom").ElementNode>;
|
|
95
|
-
blockConditions: string[];
|
|
96
|
-
usedComponentCtxVars: Set<string>;
|
|
97
|
-
scopedClasses: {
|
|
98
|
-
className: string;
|
|
99
|
-
offset: number;
|
|
100
|
-
}[];
|
|
101
|
-
accessGlobalVariable(name: string, offset?: number | undefined): void;
|
|
102
|
-
hasLocalVariable: (name: string) => boolean;
|
|
103
|
-
addLocalVariable: (name: string) => void;
|
|
104
|
-
removeLocalVariable: (name: string) => void;
|
|
105
|
-
getInternalVariable: () => string;
|
|
106
|
-
ignoreError: () => Generator<Code, any, unknown>;
|
|
107
|
-
expectError: (prevNode: import("@vue/compiler-dom").CommentNode) => Generator<Code, any, unknown>;
|
|
108
|
-
resetDirectiveComments: (endStr: string) => Generator<Code, any, unknown>;
|
|
109
|
-
generateAutoImportCompletion: () => Generator<Code, any, unknown>;
|
|
75
|
+
slots: {
|
|
76
|
+
name: string;
|
|
77
|
+
loc?: number | undefined;
|
|
78
|
+
tagRange: [number, number];
|
|
79
|
+
varName: string;
|
|
80
|
+
nodeLoc: any;
|
|
81
|
+
}[];
|
|
82
|
+
dynamicSlots: {
|
|
83
|
+
expVar: string;
|
|
84
|
+
varName: string;
|
|
85
|
+
}[];
|
|
86
|
+
codeFeatures: {
|
|
87
|
+
all: import("../types").VueCodeInformation;
|
|
88
|
+
verification: import("../types").VueCodeInformation;
|
|
89
|
+
completion: import("../types").VueCodeInformation;
|
|
90
|
+
additionalCompletion: import("../types").VueCodeInformation;
|
|
91
|
+
navigation: import("../types").VueCodeInformation;
|
|
92
|
+
navigationWithoutRename: import("../types").VueCodeInformation;
|
|
93
|
+
navigationAndCompletion: import("../types").VueCodeInformation;
|
|
94
|
+
navigationAndAdditionalCompletion: import("../types").VueCodeInformation;
|
|
95
|
+
withoutHighlight: import("../types").VueCodeInformation;
|
|
96
|
+
withoutHighlightAndCompletion: import("../types").VueCodeInformation;
|
|
97
|
+
withoutHighlightAndCompletionAndNavigation: import("../types").VueCodeInformation;
|
|
110
98
|
};
|
|
99
|
+
accessExternalVariables: Map<string, Set<number>>;
|
|
100
|
+
hasSlotElements: Set<import("@vue/compiler-dom").ElementNode>;
|
|
101
|
+
blockConditions: string[];
|
|
102
|
+
usedComponentCtxVars: Set<string>;
|
|
103
|
+
scopedClasses: {
|
|
104
|
+
className: string;
|
|
105
|
+
offset: number;
|
|
106
|
+
}[];
|
|
107
|
+
emptyClassOffsets: number[];
|
|
111
108
|
hasSlot: boolean;
|
|
109
|
+
accessExternalVariable(name: string, offset?: number | undefined): void;
|
|
110
|
+
hasLocalVariable: (name: string) => boolean;
|
|
111
|
+
addLocalVariable: (name: string) => void;
|
|
112
|
+
removeLocalVariable: (name: string) => void;
|
|
113
|
+
getInternalVariable: () => string;
|
|
114
|
+
ignoreError: () => Generator<Code, any, unknown>;
|
|
115
|
+
expectError: (prevNode: import("@vue/compiler-dom").CommentNode) => Generator<Code, any, unknown>;
|
|
116
|
+
resetDirectiveComments: (endStr: string) => Generator<Code, any, unknown>;
|
|
117
|
+
generateAutoImportCompletion: () => Generator<Code, any, unknown>;
|
|
112
118
|
} | undefined;
|
|
113
119
|
}>;
|
|
114
120
|
declare const plugin: VueLanguagePlugin;
|
package/lib/plugins/vue-tsx.js
CHANGED
|
@@ -57,27 +57,6 @@ function createTsx(fileName, _sfc, ctx) {
|
|
|
57
57
|
const scriptSetupRanges = (0, computeds_1.computed)(() => _sfc.scriptSetup
|
|
58
58
|
? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, _sfc.scriptSetup.ast, ctx.vueCompilerOptions)
|
|
59
59
|
: undefined);
|
|
60
|
-
const shouldGenerateScopedClasses = (0, computeds_1.computed)(() => {
|
|
61
|
-
const option = ctx.vueCompilerOptions.experimentalResolveStyleCssClasses;
|
|
62
|
-
return _sfc.styles.some(s => {
|
|
63
|
-
return option === 'always' || (option === 'scoped' && s.scoped);
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
const stylesScopedClasses = (0, computeds_1.computedSet)(() => {
|
|
67
|
-
const classes = new Set();
|
|
68
|
-
if (!shouldGenerateScopedClasses()) {
|
|
69
|
-
return classes;
|
|
70
|
-
}
|
|
71
|
-
for (const style of _sfc.styles) {
|
|
72
|
-
const option = ctx.vueCompilerOptions.experimentalResolveStyleCssClasses;
|
|
73
|
-
if (option === 'always' || (option === 'scoped' && style.scoped)) {
|
|
74
|
-
for (const className of style.classNames) {
|
|
75
|
-
classes.add(className.text.substring(1));
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return classes;
|
|
80
|
-
});
|
|
81
60
|
const generatedTemplate = (0, computeds_1.computed)(() => {
|
|
82
61
|
if (!_sfc.template) {
|
|
83
62
|
return;
|
|
@@ -88,8 +67,8 @@ function createTsx(fileName, _sfc, ctx) {
|
|
|
88
67
|
compilerOptions: ctx.compilerOptions,
|
|
89
68
|
vueCompilerOptions: ctx.vueCompilerOptions,
|
|
90
69
|
template: _sfc.template,
|
|
91
|
-
|
|
92
|
-
|
|
70
|
+
scriptSetupBindingNames: scriptSetupBindingNames(),
|
|
71
|
+
scriptSetupImportComponentNames: scriptSetupImportComponentNames(),
|
|
93
72
|
hasDefineSlots: hasDefineSlots(),
|
|
94
73
|
slotsAssignName: slotsAssignName(),
|
|
95
74
|
propsAssignName: propsAssignName(),
|
|
@@ -106,6 +85,26 @@ function createTsx(fileName, _sfc, ctx) {
|
|
|
106
85
|
};
|
|
107
86
|
});
|
|
108
87
|
const hasDefineSlots = (0, computeds_1.computed)(() => !!scriptSetupRanges()?.slots.define);
|
|
88
|
+
const scriptSetupBindingNames = (0, computeds_1.computed)(oldNames => {
|
|
89
|
+
const newNames = new Set();
|
|
90
|
+
const bindings = scriptSetupRanges()?.bindings;
|
|
91
|
+
if (_sfc.scriptSetup && bindings) {
|
|
92
|
+
for (const binding of bindings) {
|
|
93
|
+
newNames.add(_sfc.scriptSetup?.content.substring(binding.start, binding.end));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (newNames && oldNames && twoSetsEqual(newNames, oldNames)) {
|
|
97
|
+
return oldNames;
|
|
98
|
+
}
|
|
99
|
+
return newNames;
|
|
100
|
+
});
|
|
101
|
+
const scriptSetupImportComponentNames = (0, computeds_1.computed)(oldNames => {
|
|
102
|
+
const newNames = scriptSetupRanges()?.importComponentNames ?? new Set();
|
|
103
|
+
if (newNames && oldNames && twoSetsEqual(newNames, oldNames)) {
|
|
104
|
+
return oldNames;
|
|
105
|
+
}
|
|
106
|
+
return newNames;
|
|
107
|
+
});
|
|
109
108
|
const slotsAssignName = (0, computeds_1.computed)(() => scriptSetupRanges()?.slots.name);
|
|
110
109
|
const propsAssignName = (0, computeds_1.computed)(() => scriptSetupRanges()?.props.name);
|
|
111
110
|
const generatedScript = (0, computeds_1.computed)(() => {
|
|
@@ -121,11 +120,7 @@ function createTsx(fileName, _sfc, ctx) {
|
|
|
121
120
|
lang: lang(),
|
|
122
121
|
scriptRanges: scriptRanges(),
|
|
123
122
|
scriptSetupRanges: scriptSetupRanges(),
|
|
124
|
-
templateCodegen: _template
|
|
125
|
-
tsCodes: _template.codes,
|
|
126
|
-
ctx: _template.ctx,
|
|
127
|
-
hasSlot: _template.hasSlot,
|
|
128
|
-
} : undefined,
|
|
123
|
+
templateCodegen: _template,
|
|
129
124
|
compilerOptions: ctx.compilerOptions,
|
|
130
125
|
vueCompilerOptions: ctx.vueCompilerOptions,
|
|
131
126
|
getGeneratedLength: () => generatedLength,
|
|
@@ -150,4 +145,15 @@ function createTsx(fileName, _sfc, ctx) {
|
|
|
150
145
|
generatedTemplate,
|
|
151
146
|
};
|
|
152
147
|
}
|
|
148
|
+
function twoSetsEqual(a, b) {
|
|
149
|
+
if (a.size !== b.size) {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
for (const file of a) {
|
|
153
|
+
if (!b.has(file)) {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
153
159
|
//# sourceMappingURL=vue-tsx.js.map
|
package/lib/plugins.d.ts
CHANGED
|
@@ -22,5 +22,5 @@ export declare function getBasePlugins(pluginContext: Parameters<VueLanguagePlug
|
|
|
22
22
|
id: string;
|
|
23
23
|
lang: string;
|
|
24
24
|
}[];
|
|
25
|
-
resolveEmbeddedCode?(fileName: string, sfc: import("./types").Sfc, embeddedFile: import("./
|
|
25
|
+
resolveEmbeddedCode?(fileName: string, sfc: import("./types").Sfc, embeddedFile: import("./types").VueEmbeddedCode): void;
|
|
26
26
|
}[];
|
package/lib/types.d.ts
CHANGED
|
@@ -4,13 +4,12 @@ import type * as ts from 'typescript';
|
|
|
4
4
|
import type { VueEmbeddedCode } from './virtualFile/embeddedFile';
|
|
5
5
|
import type { CodeInformation, Segment } from '@volar/language-core';
|
|
6
6
|
export type { SFCParseResult } from '@vue/compiler-sfc';
|
|
7
|
+
export { VueEmbeddedCode };
|
|
7
8
|
export type RawVueCompilerOptions = Partial<Omit<VueCompilerOptions, 'target' | 'plugins'>> & {
|
|
8
9
|
target?: 'auto' | 2 | 2.7 | 3 | 3.3;
|
|
9
10
|
plugins?: string[];
|
|
10
11
|
};
|
|
11
12
|
export interface VueCodeInformation extends CodeInformation {
|
|
12
|
-
__referencesCodeLens?: boolean;
|
|
13
|
-
__displayWithLink?: boolean;
|
|
14
13
|
__hint?: {
|
|
15
14
|
setting: string;
|
|
16
15
|
label: string;
|
|
@@ -47,7 +46,6 @@ export interface VueCompilerOptions {
|
|
|
47
46
|
experimentalDefinePropProposal: 'kevinEdition' | 'johnsonEdition' | false;
|
|
48
47
|
experimentalResolveStyleCssClasses: 'scoped' | 'always' | 'never';
|
|
49
48
|
experimentalModelPropName: Record<string, Record<string, boolean | Record<string, string> | Record<string, string>[]>>;
|
|
50
|
-
experimentalUseElementAccessInTemplate: boolean;
|
|
51
49
|
}
|
|
52
50
|
export declare const pluginVersion = 2;
|
|
53
51
|
export type VueLanguagePlugin = (ctx: {
|
|
@@ -123,18 +121,6 @@ export interface Sfc {
|
|
|
123
121
|
customBlocks: readonly (SfcBlock & {
|
|
124
122
|
type: string;
|
|
125
123
|
})[];
|
|
126
|
-
/**
|
|
127
|
-
* @deprecated use `template.ast` instead
|
|
128
|
-
*/
|
|
129
|
-
templateAst: CompilerDOM.RootNode | undefined;
|
|
130
|
-
/**
|
|
131
|
-
* @deprecated use `script.ast` instead
|
|
132
|
-
*/
|
|
133
|
-
scriptAst: ts.SourceFile | undefined;
|
|
134
|
-
/**
|
|
135
|
-
* @deprecated use `scriptSetup.ast` instead
|
|
136
|
-
*/
|
|
137
|
-
scriptSetupAst: ts.SourceFile | undefined;
|
|
138
124
|
}
|
|
139
125
|
export interface TextRange {
|
|
140
126
|
start: number;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseCssClassNames = void 0;
|
|
4
4
|
const parseCssVars_1 = require("./parseCssVars");
|
|
5
|
-
const cssClassNameReg = /(?=([\.]{1}[a-zA-Z_]+[\w\_\-]*)[\s
|
|
5
|
+
const cssClassNameReg = /(?=([\.]{1}[a-zA-Z_]+[\w\_\-]*)[\s\.\,\+\{\>#\:]{1})/g;
|
|
6
6
|
function* parseCssClassNames(styleContent) {
|
|
7
7
|
styleContent = (0, parseCssVars_1.clearComments)(styleContent);
|
|
8
8
|
const matches = styleContent.matchAll(cssClassNameReg);
|
package/lib/utils/ts.js
CHANGED
|
@@ -210,7 +210,6 @@ function resolveVueCompilerOptions(vueOptions) {
|
|
|
210
210
|
select: true
|
|
211
211
|
}
|
|
212
212
|
},
|
|
213
|
-
experimentalUseElementAccessInTemplate: vueOptions.experimentalUseElementAccessInTemplate ?? false,
|
|
214
213
|
};
|
|
215
214
|
}
|
|
216
215
|
exports.resolveVueCompilerOptions = resolveVueCompilerOptions;
|