@vue/language-core 3.0.7-alpha.0 → 3.0.7
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/componentSelf.js +1 -1
- package/lib/codegen/script/index.js +2 -6
- package/lib/codegen/script/scriptSetup.js +2 -2
- package/lib/codegen/template/element.js +3 -3
- package/lib/codegen/template/elementProps.js +4 -5
- package/lib/codegen/template/index.js +2 -3
- package/lib/codegen/template/slotOutlet.js +2 -3
- package/lib/codegen/template/styleScopedClasses.js +1 -2
- package/lib/codegen/template/vFor.js +1 -1
- package/lib/codegen/template/vSlot.js +1 -1
- package/lib/codegen/tenp.d.ts +1 -0
- package/lib/codegen/tenp.js +3 -0
- package/lib/compilerOptions.js +2 -5
- package/lib/parsers/scriptRanges.js +1 -1
- package/lib/parsers/scriptSetupRanges.js +2 -2
- package/lib/parsers/utils.d.ts +12 -0
- package/lib/parsers/utils.js +95 -0
- package/lib/plugins/file-css.d.ts +3 -0
- package/lib/plugins/file-css.js +57 -0
- package/lib/plugins/vue-template-inline-ts.js +2 -3
- package/lib/plugins/vue-tsx.js +1 -3
- package/lib/utils/parseCssClassNames.d.ts +4 -0
- package/lib/utils/parseCssClassNames.js +17 -0
- package/lib/utils/parseCssImports.d.ts +4 -0
- package/lib/utils/parseCssImports.js +19 -0
- package/lib/utils/parseCssVars.d.ts +6 -0
- package/lib/utils/parseCssVars.js +26 -0
- package/lib/utils/shared.d.ts +1 -1
- package/lib/utils/ts.d.ts +24 -0
- package/lib/utils/vue2TemplateCompiler.js +2 -2
- package/lib/virtualFile/computedSfc.js +4 -4
- package/package.json +2 -2
|
@@ -32,7 +32,7 @@ function* generateComponentSelf(options, ctx, templateCodegenCtx) {
|
|
|
32
32
|
yield `${varName},${utils_1.newLine}`;
|
|
33
33
|
}
|
|
34
34
|
yield `}),${utils_1.newLine}`;
|
|
35
|
-
if (
|
|
35
|
+
if (!ctx.bypassDefineComponent) {
|
|
36
36
|
const emitOptionCodes = [...(0, component_1.generateEmitsOption)(options, options.scriptSetupRanges)];
|
|
37
37
|
yield* emitOptionCodes;
|
|
38
38
|
yield* (0, component_1.generatePropsOption)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges, !!emitOptionCodes.length, false);
|
|
@@ -47,9 +47,7 @@ function* generateScript(options, ctx) {
|
|
|
47
47
|
blockName: options.sfc.script.name,
|
|
48
48
|
offset: exportDefault.expression.start,
|
|
49
49
|
setting: 'vue.inlayHints.optionsWrapper',
|
|
50
|
-
label: options.vueCompilerOptions.optionsWrapper
|
|
51
|
-
? options.vueCompilerOptions.optionsWrapper[0]
|
|
52
|
-
: '[Missing optionsWrapper[0]]',
|
|
50
|
+
label: options.vueCompilerOptions.optionsWrapper[0],
|
|
53
51
|
tooltip: [
|
|
54
52
|
'This is virtual code that is automatically wrapped for type support, it does not affect your runtime behavior, you can customize it via `vueCompilerOptions.optionsWrapper` option in tsconfig / jsconfig.',
|
|
55
53
|
'To hide it, you can set `"vue.inlayHints.optionsWrapper": false` in IDE settings.',
|
|
@@ -58,9 +56,7 @@ function* generateScript(options, ctx) {
|
|
|
58
56
|
blockName: options.sfc.script.name,
|
|
59
57
|
offset: exportDefault.expression.end,
|
|
60
58
|
setting: 'vue.inlayHints.optionsWrapper',
|
|
61
|
-
label: options.vueCompilerOptions.optionsWrapper
|
|
62
|
-
? options.vueCompilerOptions.optionsWrapper[1]
|
|
63
|
-
: '[Missing optionsWrapper[1]]',
|
|
59
|
+
label: options.vueCompilerOptions.optionsWrapper[1],
|
|
64
60
|
});
|
|
65
61
|
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, exportDefault.expression.start, codeFeatures_1.codeFeatures.all);
|
|
66
62
|
yield options.vueCompilerOptions.optionsWrapper[0];
|
|
@@ -97,7 +97,7 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
97
97
|
[
|
|
98
98
|
`let __VLS_exposed!: `,
|
|
99
99
|
(0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.start, typeArg.end, codeFeatures_1.codeFeatures.all),
|
|
100
|
-
|
|
100
|
+
utils_1.endOfLine,
|
|
101
101
|
],
|
|
102
102
|
callExp.start,
|
|
103
103
|
callExp.start,
|
|
@@ -112,7 +112,7 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
112
112
|
[
|
|
113
113
|
`const __VLS_exposed = `,
|
|
114
114
|
(0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.all),
|
|
115
|
-
|
|
115
|
+
utils_1.endOfLine,
|
|
116
116
|
],
|
|
117
117
|
callExp.start,
|
|
118
118
|
callExp.start,
|
|
@@ -110,7 +110,7 @@ function* generateComponent(options, ctx, node) {
|
|
|
110
110
|
? codeFeatures_1.codeFeatures.verification
|
|
111
111
|
: codeFeatures_1.codeFeatures.doNotReportTs2339AndTs2551,
|
|
112
112
|
});
|
|
113
|
-
yield
|
|
113
|
+
yield utils_1.endOfLine;
|
|
114
114
|
const camelizedTag = (0, shared_1.camelize)(node.tag);
|
|
115
115
|
if (utils_1.identifierRegex.test(camelizedTag)) {
|
|
116
116
|
// navigation support
|
|
@@ -131,7 +131,7 @@ function* generateComponent(options, ctx, node) {
|
|
|
131
131
|
onlyImport: true,
|
|
132
132
|
},
|
|
133
133
|
});
|
|
134
|
-
yield
|
|
134
|
+
yield utils_1.endOfLine;
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
yield `// @ts-ignore${utils_1.newLine}`;
|
|
@@ -159,7 +159,7 @@ function* generateComponent(options, ctx, node) {
|
|
|
159
159
|
if (ctx.inVFor) {
|
|
160
160
|
yield `[]`;
|
|
161
161
|
}
|
|
162
|
-
yield
|
|
162
|
+
yield utils_1.endOfLine;
|
|
163
163
|
if (refName && offset) {
|
|
164
164
|
ctx.addTemplateRef(refName, `typeof ${ctx.getHoistVariable(componentInstanceVar)}`, offset);
|
|
165
165
|
}
|
|
@@ -138,8 +138,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
138
138
|
}
|
|
139
139
|
yield `,${utils_1.newLine}`;
|
|
140
140
|
}
|
|
141
|
-
else if (prop.
|
|
142
|
-
&& prop.name === 'bind'
|
|
141
|
+
else if (prop.name === 'bind'
|
|
143
142
|
&& !prop.arg
|
|
144
143
|
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
145
144
|
if (prop.exp.loc.source === '$attrs') {
|
|
@@ -172,8 +171,8 @@ function* generatePropExp(options, ctx, prop, exp, enableCodeFeatures = true) {
|
|
|
172
171
|
else {
|
|
173
172
|
const propVariableName = (0, shared_1.camelize)(exp.loc.source);
|
|
174
173
|
if (utils_1.identifierRegex.test(propVariableName)) {
|
|
175
|
-
const isDestructuredProp = options.destructuredPropNames
|
|
176
|
-
const isTemplateRef = options.templateRefNames
|
|
174
|
+
const isDestructuredProp = options.destructuredPropNames.has(propVariableName);
|
|
175
|
+
const isTemplateRef = options.templateRefNames.has(propVariableName);
|
|
177
176
|
const codes = (0, camelized_1.generateCamelized)(exp.loc.source, 'template', exp.loc.start.offset, features);
|
|
178
177
|
if (ctx.hasLocalVariable(propVariableName) || isDestructuredProp) {
|
|
179
178
|
yield* codes;
|
|
@@ -216,7 +215,7 @@ function* generateAttrValue(attrNode, features) {
|
|
|
216
215
|
function getShouldCamelize(options, prop, propName) {
|
|
217
216
|
return (prop.type !== CompilerDOM.NodeTypes.DIRECTIVE
|
|
218
217
|
|| !prop.arg
|
|
219
|
-
|| (prop.arg
|
|
218
|
+
|| (prop.arg.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic))
|
|
220
219
|
&& (0, shared_2.hyphenateAttr)(propName) === propName
|
|
221
220
|
&& !options.vueCompilerOptions.htmlAttributes.some(pattern => (0, picomatch_1.isMatch)(propName, pattern));
|
|
222
221
|
}
|
|
@@ -79,7 +79,7 @@ function* generateSlots(options, ctx) {
|
|
|
79
79
|
}
|
|
80
80
|
yield `?: (props: typeof ${slot.propsVar}) => any }`;
|
|
81
81
|
}
|
|
82
|
-
yield
|
|
82
|
+
yield utils_1.endOfLine;
|
|
83
83
|
}
|
|
84
84
|
return `__VLS_Slots`;
|
|
85
85
|
}
|
|
@@ -160,8 +160,7 @@ function* forEachElementNode(node) {
|
|
|
160
160
|
}
|
|
161
161
|
else if (node.type === CompilerDOM.NodeTypes.IF) {
|
|
162
162
|
// v-if / v-else-if / v-else
|
|
163
|
-
for (
|
|
164
|
-
const branch = node.branches[i];
|
|
163
|
+
for (const branch of node.branches) {
|
|
165
164
|
for (const childNode of branch.children) {
|
|
166
165
|
yield* forEachElementNode(childNode);
|
|
167
166
|
}
|
|
@@ -19,8 +19,7 @@ function* generateSlotOutlet(options, ctx, node) {
|
|
|
19
19
|
if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE) {
|
|
20
20
|
return prop.name === 'name';
|
|
21
21
|
}
|
|
22
|
-
if (prop.
|
|
23
|
-
&& prop.name === 'bind'
|
|
22
|
+
if (prop.name === 'bind'
|
|
24
23
|
&& prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
25
24
|
return prop.arg.content === 'name';
|
|
26
25
|
}
|
|
@@ -48,7 +47,7 @@ function* generateSlotOutlet(options, ctx, node) {
|
|
|
48
47
|
else {
|
|
49
48
|
codes = [`['default']`];
|
|
50
49
|
}
|
|
51
|
-
yield* (0, wrapWith_1.wrapWith)(nameProp.loc.start.offset, nameProp.loc.end.offset, codeFeatures_1.codeFeatures.verification,
|
|
50
|
+
yield* (0, wrapWith_1.wrapWith)(nameProp.loc.start.offset, nameProp.loc.end.offset, codeFeatures_1.codeFeatures.verification, options.slotsAssignName ?? '__VLS_slots', ...codes);
|
|
52
51
|
}
|
|
53
52
|
else {
|
|
54
53
|
yield* (0, wrapWith_1.wrapWith)(startTagOffset, startTagEndOffset, codeFeatures_1.codeFeatures.verification, `${options.slotsAssignName ?? '__VLS_slots'}[`, ...(0, wrapWith_1.wrapWith)(startTagOffset, startTagEndOffset, codeFeatures_1.codeFeatures.verification, `'default'`), `]`);
|
|
@@ -47,10 +47,9 @@ function collectStyleScopedClassReferences(options, ctx, node) {
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
else {
|
|
50
|
-
let isWrapped = false;
|
|
51
50
|
const [content, startOffset] = (0, utils_1.normalizeAttributeValue)(prop.value);
|
|
52
51
|
if (content) {
|
|
53
|
-
const classes = collectClasses(content, startOffset
|
|
52
|
+
const classes = collectClasses(content, startOffset);
|
|
54
53
|
ctx.scopedClasses.push(...classes);
|
|
55
54
|
}
|
|
56
55
|
else {
|
|
@@ -40,7 +40,7 @@ function* generateVFor(options, ctx, node) {
|
|
|
40
40
|
for (const argument of node.codegenNode?.children.arguments ?? []) {
|
|
41
41
|
if (argument.type === CompilerDOM.NodeTypes.JS_FUNCTION_EXPRESSION
|
|
42
42
|
&& argument.returns?.type === CompilerDOM.NodeTypes.VNODE_CALL
|
|
43
|
-
&& argument.returns
|
|
43
|
+
&& argument.returns.props?.type === CompilerDOM.NodeTypes.JS_OBJECT_EXPRESSION) {
|
|
44
44
|
if (argument.returns.tag !== CompilerDOM.FRAGMENT) {
|
|
45
45
|
isFragment = false;
|
|
46
46
|
continue;
|
|
@@ -73,7 +73,7 @@ function* generateVSlot(options, ctx, node, slotDir) {
|
|
|
73
73
|
function* generateSlotParameters(options, ctx, ast, exp, slotVar) {
|
|
74
74
|
const { ts } = options;
|
|
75
75
|
const statement = ast.statements[0];
|
|
76
|
-
if (!ts.isExpressionStatement(statement) || !ts.isArrowFunction(statement.expression)) {
|
|
76
|
+
if (!statement || !ts.isExpressionStatement(statement) || !ts.isArrowFunction(statement.expression)) {
|
|
77
77
|
return;
|
|
78
78
|
}
|
|
79
79
|
const { expression } = statement;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/compilerOptions.js
CHANGED
|
@@ -277,13 +277,10 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
|
|
|
277
277
|
};
|
|
278
278
|
}
|
|
279
279
|
function writeGlobalTypes(vueOptions, writeFile) {
|
|
280
|
-
const originalFn = vueOptions.globalTypesPath;
|
|
281
|
-
if (!originalFn) {
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
280
|
const writed = new Set();
|
|
281
|
+
const { globalTypesPath } = vueOptions;
|
|
285
282
|
vueOptions.globalTypesPath = (fileName) => {
|
|
286
|
-
const result =
|
|
283
|
+
const result = globalTypesPath(fileName);
|
|
287
284
|
if (result && !writed.has(result)) {
|
|
288
285
|
writed.add(result);
|
|
289
286
|
writeFile(result, (0, globalTypes_1.generateGlobalTypes)(vueOptions));
|
|
@@ -60,7 +60,7 @@ function parseScriptRanges(ts, ast, hasScriptSetup) {
|
|
|
60
60
|
}
|
|
61
61
|
if (ts.isClassDeclaration(raw)
|
|
62
62
|
&& raw.modifiers?.some(mod => mod.kind === ts.SyntaxKind.ExportKeyword)
|
|
63
|
-
&& raw.modifiers
|
|
63
|
+
&& raw.modifiers.some(mod => mod.kind === ts.SyntaxKind.DefaultKeyword)) {
|
|
64
64
|
classBlockEnd = raw.end - 1;
|
|
65
65
|
}
|
|
66
66
|
});
|
|
@@ -335,8 +335,8 @@ function parseBindingRanges(ts, ast) {
|
|
|
335
335
|
function getStatementRange(ts, parents, node, ast) {
|
|
336
336
|
let statementRange;
|
|
337
337
|
for (let i = parents.length - 1; i >= 0; i--) {
|
|
338
|
-
|
|
339
|
-
|
|
338
|
+
const statement = parents[i];
|
|
339
|
+
if (ts.isStatement(statement)) {
|
|
340
340
|
ts.forEachChild(statement, child => {
|
|
341
341
|
const range = (0, shared_1.getStartEnd)(ts, child, ast);
|
|
342
342
|
statementRange ??= range;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type * as ts from 'typescript';
|
|
2
|
+
import type { TextRange } from '../types';
|
|
3
|
+
export declare function parseBindingRanges(ts: typeof import('typescript'), ast: ts.SourceFile): {
|
|
4
|
+
range: TextRange;
|
|
5
|
+
moduleName?: string;
|
|
6
|
+
isDefaultImport?: boolean;
|
|
7
|
+
isNamespace?: boolean;
|
|
8
|
+
}[];
|
|
9
|
+
export declare function getClosestMultiLineCommentRange(ts: typeof import('typescript'), node: ts.Node, parents: ts.Node[], ast: ts.SourceFile): {
|
|
10
|
+
start: number;
|
|
11
|
+
end: number;
|
|
12
|
+
} | undefined;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseBindingRanges = parseBindingRanges;
|
|
4
|
+
exports.getClosestMultiLineCommentRange = getClosestMultiLineCommentRange;
|
|
5
|
+
const collectBindings_1 = require("../utils/collectBindings");
|
|
6
|
+
const shared_1 = require("../utils/shared");
|
|
7
|
+
function parseBindingRanges(ts, ast) {
|
|
8
|
+
const bindings = [];
|
|
9
|
+
ts.forEachChild(ast, node => {
|
|
10
|
+
if (ts.isVariableStatement(node)) {
|
|
11
|
+
for (const decl of node.declarationList.declarations) {
|
|
12
|
+
const ranges = (0, collectBindings_1.collectBindingRanges)(ts, decl.name, ast);
|
|
13
|
+
bindings.push(...ranges.map(range => ({ range })));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
else if (ts.isFunctionDeclaration(node)) {
|
|
17
|
+
if (node.name && ts.isIdentifier(node.name)) {
|
|
18
|
+
bindings.push({
|
|
19
|
+
range: _getStartEnd(node.name),
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
else if (ts.isClassDeclaration(node)) {
|
|
24
|
+
if (node.name) {
|
|
25
|
+
bindings.push({
|
|
26
|
+
range: _getStartEnd(node.name),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else if (ts.isEnumDeclaration(node)) {
|
|
31
|
+
bindings.push({
|
|
32
|
+
range: _getStartEnd(node.name),
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
if (ts.isImportDeclaration(node)) {
|
|
36
|
+
const moduleName = _getNodeText(node.moduleSpecifier).slice(1, -1);
|
|
37
|
+
if (node.importClause && !node.importClause.isTypeOnly) {
|
|
38
|
+
const { name, namedBindings } = node.importClause;
|
|
39
|
+
if (name) {
|
|
40
|
+
bindings.push({
|
|
41
|
+
range: _getStartEnd(name),
|
|
42
|
+
moduleName,
|
|
43
|
+
isDefaultImport: true,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
if (namedBindings) {
|
|
47
|
+
if (ts.isNamedImports(namedBindings)) {
|
|
48
|
+
for (const element of namedBindings.elements) {
|
|
49
|
+
if (element.isTypeOnly) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
bindings.push({
|
|
53
|
+
range: _getStartEnd(element.name),
|
|
54
|
+
moduleName,
|
|
55
|
+
isDefaultImport: element.propertyName?.text === 'default',
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
bindings.push({
|
|
61
|
+
range: _getStartEnd(namedBindings.name),
|
|
62
|
+
moduleName,
|
|
63
|
+
isNamespace: true,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
return bindings;
|
|
71
|
+
function _getStartEnd(node) {
|
|
72
|
+
return (0, shared_1.getStartEnd)(ts, node, ast);
|
|
73
|
+
}
|
|
74
|
+
function _getNodeText(node) {
|
|
75
|
+
return (0, shared_1.getNodeText)(ts, node, ast);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function getClosestMultiLineCommentRange(ts, node, parents, ast) {
|
|
79
|
+
for (let i = parents.length - 1; i >= 0; i--) {
|
|
80
|
+
if (ts.isStatement(node)) {
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
node = parents[i];
|
|
84
|
+
}
|
|
85
|
+
const comment = ts.getLeadingCommentRanges(ast.text, node.pos)
|
|
86
|
+
?.reverse()
|
|
87
|
+
.find(range => range.kind === 3);
|
|
88
|
+
if (comment) {
|
|
89
|
+
return {
|
|
90
|
+
start: comment.pos,
|
|
91
|
+
end: comment.end,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const parseSfc_1 = require("../utils/parseSfc");
|
|
4
|
+
const plugin = ({ vueCompilerOptions }) => {
|
|
5
|
+
return {
|
|
6
|
+
version: 2.1,
|
|
7
|
+
getLanguageId(fileName) {
|
|
8
|
+
if (vueCompilerOptions.extensions.some(ext => fileName.endsWith(ext))) {
|
|
9
|
+
return 'vue';
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
isValidFile(_fileName, languageId) {
|
|
13
|
+
return languageId === 'vue';
|
|
14
|
+
},
|
|
15
|
+
parseSFC2(_fileName, languageId, content) {
|
|
16
|
+
if (languageId !== 'vue') {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
return (0, parseSfc_1.parse)(content);
|
|
20
|
+
},
|
|
21
|
+
updateSFC(sfc, change) {
|
|
22
|
+
const blocks = [
|
|
23
|
+
sfc.descriptor.template,
|
|
24
|
+
sfc.descriptor.script,
|
|
25
|
+
sfc.descriptor.scriptSetup,
|
|
26
|
+
...sfc.descriptor.styles,
|
|
27
|
+
...sfc.descriptor.customBlocks,
|
|
28
|
+
].filter(block => !!block);
|
|
29
|
+
const hitBlock = blocks.find(block => change.start >= block.loc.start.offset && change.end <= block.loc.end.offset);
|
|
30
|
+
if (!hitBlock) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const oldContent = hitBlock.content;
|
|
34
|
+
const newContent = hitBlock.content = hitBlock.content.slice(0, change.start - hitBlock.loc.start.offset)
|
|
35
|
+
+ change.newText
|
|
36
|
+
+ hitBlock.content.slice(change.end - hitBlock.loc.start.offset);
|
|
37
|
+
// #3449
|
|
38
|
+
const endTagRegex = new RegExp(`</\\s*${hitBlock.type}\\s*>`);
|
|
39
|
+
const insertedEndTag = endTagRegex.test(oldContent) !== endTagRegex.test(newContent);
|
|
40
|
+
if (insertedEndTag) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const lengthDiff = change.newText.length - (change.end - change.start);
|
|
44
|
+
for (const block of blocks) {
|
|
45
|
+
if (block.loc.start.offset > change.end) {
|
|
46
|
+
block.loc.start.offset += lengthDiff;
|
|
47
|
+
}
|
|
48
|
+
if (block.loc.end.offset >= change.end) {
|
|
49
|
+
block.loc.end.offset += lengthDiff;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return sfc;
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
exports.default = plugin;
|
|
57
|
+
//# sourceMappingURL=file-css.js.map
|
|
@@ -59,7 +59,7 @@ const plugin = ctx => {
|
|
|
59
59
|
return data;
|
|
60
60
|
}
|
|
61
61
|
const templateContent = sfc.template.content;
|
|
62
|
-
const inlineTsAsts =
|
|
62
|
+
const inlineTsAsts = computedSfc_1.templateInlineTsAsts.get(sfc.template.ast);
|
|
63
63
|
let i = 0;
|
|
64
64
|
sfc.template.ast.children.forEach(visit);
|
|
65
65
|
return data;
|
|
@@ -120,8 +120,7 @@ const plugin = ctx => {
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
else if (node.type === CompilerDOM.NodeTypes.IF) {
|
|
123
|
-
for (
|
|
124
|
-
const branch = node.branches[i];
|
|
123
|
+
for (const branch of node.branches) {
|
|
125
124
|
if (branch.condition?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
126
125
|
addFormatCodes(branch.condition.loc.source, branch.condition.loc.start.offset, formatBrackets.if);
|
|
127
126
|
}
|
package/lib/plugins/vue-tsx.js
CHANGED
|
@@ -31,9 +31,7 @@ const plugin = ctx => {
|
|
|
31
31
|
if (/script_(js|jsx|ts|tsx)/.test(embeddedFile.id)) {
|
|
32
32
|
const codegen = useCodegen(fileName, sfc);
|
|
33
33
|
const tsx = codegen.getGeneratedScript();
|
|
34
|
-
|
|
35
|
-
embeddedFile.content = [...tsx.codes];
|
|
36
|
-
}
|
|
34
|
+
embeddedFile.content = [...tsx.codes];
|
|
37
35
|
}
|
|
38
36
|
},
|
|
39
37
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseCssClassNames = parseCssClassNames;
|
|
4
|
+
const parseCssVars_1 = require("./parseCssVars");
|
|
5
|
+
const cssClassNameReg = /(?=(\.[a-z_][-\w]*)[\s.,+~>:#)[{])/gi;
|
|
6
|
+
const fragmentReg = /(?<={)[^{]*(?=(?<!\\);)/g;
|
|
7
|
+
function* parseCssClassNames(css) {
|
|
8
|
+
css = (0, parseCssVars_1.fillBlank)(css, parseCssVars_1.commentReg, fragmentReg);
|
|
9
|
+
const matches = css.matchAll(cssClassNameReg);
|
|
10
|
+
for (const match of matches) {
|
|
11
|
+
const matchText = match[1];
|
|
12
|
+
if (matchText) {
|
|
13
|
+
yield { offset: match.index, text: matchText };
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=parseCssClassNames.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseCssImports = parseCssImports;
|
|
4
|
+
const cssImportReg = /(?<=@import\s+url\()(["']?).*?\1(?=\))|(?<=@import\b\s*)(["']).*?\2/g;
|
|
5
|
+
function* parseCssImports(css) {
|
|
6
|
+
const matches = css.matchAll(cssImportReg);
|
|
7
|
+
for (const match of matches) {
|
|
8
|
+
let text = match[0];
|
|
9
|
+
let offset = match.index;
|
|
10
|
+
if (text.startsWith("'") || text.startsWith('"')) {
|
|
11
|
+
text = text.slice(1, -1);
|
|
12
|
+
offset += 1;
|
|
13
|
+
}
|
|
14
|
+
if (text) {
|
|
15
|
+
yield { text, offset };
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=parseCssImports.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// https://github.com/vuejs/core/blob/main/packages/compiler-sfc/src/cssVars.ts#L47-L61
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.commentReg = void 0;
|
|
5
|
+
exports.parseCssVars = parseCssVars;
|
|
6
|
+
exports.fillBlank = fillBlank;
|
|
7
|
+
const vBindCssVarReg = /\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([a-z_]\w*))\s*\)/gi;
|
|
8
|
+
exports.commentReg = /(?<=\/\*)[\s\S]*?(?=\*\/)|(?<=\/\/)[\s\S]*?(?=\n)/g;
|
|
9
|
+
function* parseCssVars(css) {
|
|
10
|
+
css = fillBlank(css, exports.commentReg);
|
|
11
|
+
const matchs = css.matchAll(vBindCssVarReg);
|
|
12
|
+
for (const match of matchs) {
|
|
13
|
+
const matchText = match.slice(1).find(t => t);
|
|
14
|
+
if (matchText) {
|
|
15
|
+
const offset = match.index + css.slice(match.index).indexOf(matchText);
|
|
16
|
+
yield { offset, text: matchText };
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function fillBlank(css, ...regs) {
|
|
21
|
+
for (const reg of regs) {
|
|
22
|
+
css = css.replace(reg, match => ' '.repeat(match.length));
|
|
23
|
+
}
|
|
24
|
+
return css;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=parseCssVars.js.map
|
package/lib/utils/shared.d.ts
CHANGED
|
@@ -4,6 +4,6 @@ import type { Sfc, TextRange } from '../types';
|
|
|
4
4
|
export { hyphenate as hyphenateTag } from '@vue/shared';
|
|
5
5
|
export declare function hyphenateAttr(str: string): string;
|
|
6
6
|
export declare function getSlotsPropertyName(vueVersion: number): "$scopedSlots" | "$slots";
|
|
7
|
-
export declare function getElementTagOffsets(node: CompilerDOM.ElementNode, template: NonNullable<Sfc['template']>): number[];
|
|
7
|
+
export declare function getElementTagOffsets(node: CompilerDOM.ElementNode, template: NonNullable<Sfc['template']>): [number] | [number, number];
|
|
8
8
|
export declare function getStartEnd(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): TextRange;
|
|
9
9
|
export declare function getNodeText(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type * as ts from 'typescript';
|
|
2
|
+
import type { RawVueCompilerOptions, VueCompilerOptions, VueLanguagePlugin } from '../types';
|
|
3
|
+
interface ParseConfigHost extends Omit<ts.ParseConfigHost, 'readDirectory'> {
|
|
4
|
+
}
|
|
5
|
+
export interface ParsedCommandLine extends Omit<ts.ParsedCommandLine, 'fileNames'> {
|
|
6
|
+
vueOptions: VueCompilerOptions;
|
|
7
|
+
}
|
|
8
|
+
export declare function createParsedCommandLineByJson(ts: typeof import('typescript'), host: ParseConfigHost, rootDir: string, json: any, configFileName?: string): ParsedCommandLine;
|
|
9
|
+
export declare function createParsedCommandLine(ts: typeof import('typescript'), host: ParseConfigHost, configFileName: string): ParsedCommandLine;
|
|
10
|
+
export declare class CompilerOptionsResolver {
|
|
11
|
+
fileExists?: ((path: string) => boolean) | undefined;
|
|
12
|
+
configRoots: Set<string>;
|
|
13
|
+
options: Omit<RawVueCompilerOptions, 'target' | 'globalTypesPath' | 'plugins'>;
|
|
14
|
+
target: number | undefined;
|
|
15
|
+
globalTypesPath: string | undefined;
|
|
16
|
+
plugins: VueLanguagePlugin[];
|
|
17
|
+
constructor(fileExists?: ((path: string) => boolean) | undefined);
|
|
18
|
+
addConfig(options: RawVueCompilerOptions, rootDir: string): void;
|
|
19
|
+
build(defaults?: VueCompilerOptions): VueCompilerOptions;
|
|
20
|
+
private findNodeModulesRoot;
|
|
21
|
+
}
|
|
22
|
+
export declare function getDefaultCompilerOptions(target?: number, lib?: string, strictTemplates?: boolean): VueCompilerOptions;
|
|
23
|
+
export declare function writeGlobalTypes(vueOptions: VueCompilerOptions, writeFile: (fileName: string, data: string) => void): void;
|
|
24
|
+
export {};
|
|
@@ -31,7 +31,7 @@ const compile = (template, options = {}) => {
|
|
|
31
31
|
loc: {
|
|
32
32
|
source: '',
|
|
33
33
|
start: { column: -1, line: -1, offset: error.start },
|
|
34
|
-
end: { column: -1, line: -1, offset: error.end
|
|
34
|
+
end: { column: -1, line: -1, offset: error.end },
|
|
35
35
|
},
|
|
36
36
|
});
|
|
37
37
|
}
|
|
@@ -43,7 +43,7 @@ const compile = (template, options = {}) => {
|
|
|
43
43
|
loc: {
|
|
44
44
|
source: '',
|
|
45
45
|
start: { column: -1, line: -1, offset: error.start },
|
|
46
|
-
end: { column: -1, line: -1, offset: error.end
|
|
46
|
+
end: { column: -1, line: -1, offset: error.end },
|
|
47
47
|
},
|
|
48
48
|
});
|
|
49
49
|
}
|
|
@@ -18,7 +18,7 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
|
|
|
18
18
|
const getComments = (0, alien_signals_1.computed)(oldValue => {
|
|
19
19
|
const newValue = getParseResult()?.descriptor.comments ?? [];
|
|
20
20
|
if (oldValue?.length === newValue.length
|
|
21
|
-
&& oldValue
|
|
21
|
+
&& oldValue.every((v, i) => v === newValue[i])) {
|
|
22
22
|
return oldValue;
|
|
23
23
|
}
|
|
24
24
|
return newValue;
|
|
@@ -27,13 +27,13 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
|
|
|
27
27
|
const compiledAst = computedTemplateAst(base);
|
|
28
28
|
return mergeObject(base, {
|
|
29
29
|
get ast() {
|
|
30
|
-
return compiledAst()
|
|
30
|
+
return compiledAst().ast;
|
|
31
31
|
},
|
|
32
32
|
get errors() {
|
|
33
|
-
return compiledAst()
|
|
33
|
+
return compiledAst().errors;
|
|
34
34
|
},
|
|
35
35
|
get warnings() {
|
|
36
|
-
return compiledAst()
|
|
36
|
+
return compiledAst().warnings;
|
|
37
37
|
},
|
|
38
38
|
});
|
|
39
39
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/language-core",
|
|
3
|
-
"version": "3.0.7
|
|
3
|
+
"version": "3.0.7",
|
|
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": "6022b75534487f8a031dfc61a7879f900b64d414"
|
|
41
41
|
}
|