@vue/language-core 3.1.3 → 3.1.5
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 -0
- package/index.js +1 -0
- package/lib/codegen/globalTypes.js +4 -3
- package/lib/codegen/script/component.js +1 -1
- package/lib/codegen/script/index.js +17 -10
- package/lib/codegen/script/scriptSetup.js +2 -2
- package/lib/codegen/script/src.js +1 -1
- package/lib/codegen/style/classProperty.js +1 -1
- package/lib/codegen/style/imports.js +1 -1
- package/lib/codegen/template/context.d.ts +3 -3
- package/lib/codegen/template/context.js +8 -4
- package/lib/codegen/template/element.js +30 -17
- package/lib/codegen/template/elementDirectives.js +5 -5
- package/lib/codegen/template/elementEvents.d.ts +1 -1
- package/lib/codegen/template/elementEvents.js +4 -8
- package/lib/codegen/template/elementProps.d.ts +2 -2
- package/lib/codegen/template/elementProps.js +38 -83
- package/lib/codegen/template/index.d.ts +7 -9
- package/lib/codegen/template/index.js +2 -37
- package/lib/codegen/template/interpolation.js +38 -39
- package/lib/codegen/template/objectProperty.js +1 -1
- package/lib/codegen/template/slotOutlet.js +5 -10
- package/lib/codegen/template/styleScopedClasses.js +8 -8
- package/lib/codegen/template/templateChild.js +5 -12
- package/lib/codegen/template/vIf.js +5 -7
- package/lib/codegen/template/vSlot.js +3 -4
- package/lib/codegen/utils/index.d.ts +0 -2
- package/lib/codegen/utils/index.js +0 -11
- package/lib/codegen/utils/stringLiteralKey.js +1 -1
- package/lib/codegen/utils/unicode.js +1 -1
- package/lib/codegen/utils/wrapWith.d.ts +1 -2
- package/lib/codegen/utils/wrapWith.js +1 -10
- package/lib/compilerOptions.d.ts +2 -5
- package/lib/compilerOptions.js +43 -66
- package/lib/languagePlugin.js +16 -23
- package/lib/plugins/vue-template-html.js +12 -9
- package/lib/plugins/vue-template-inline-css.js +10 -16
- package/lib/plugins/vue-tsx.d.ts +3 -3
- package/lib/plugins/vue-tsx.js +0 -1
- package/lib/utils/forEachTemplateNode.d.ts +3 -0
- package/lib/utils/forEachTemplateNode.js +68 -0
- package/lib/utils/parseSfc.js +5 -10
- package/lib/utils/shared.d.ts +1 -0
- package/lib/utils/shared.js +8 -0
- package/lib/virtualFile/computedSfc.d.ts +1 -1
- package/lib/virtualFile/computedSfc.js +6 -2
- package/package.json +2 -2
package/lib/languagePlugin.js
CHANGED
|
@@ -7,32 +7,21 @@ const language_core_1 = require("@volar/language-core");
|
|
|
7
7
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
8
8
|
const plugins_1 = require("./plugins");
|
|
9
9
|
const vueFile_1 = require("./virtualFile/vueFile");
|
|
10
|
-
const fileRegistries =
|
|
11
|
-
function getVueFileRegistry(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
fileRegistry = new Map();
|
|
17
|
-
fileRegistries.push({
|
|
18
|
-
key: key,
|
|
19
|
-
plugins: plugins,
|
|
20
|
-
files: fileRegistry,
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
return fileRegistry;
|
|
24
|
-
}
|
|
25
|
-
function getFileRegistryKey(compilerOptions, vueCompilerOptions, plugins) {
|
|
26
|
-
const values = [
|
|
10
|
+
const fileRegistries = {};
|
|
11
|
+
function getVueFileRegistry(compilerOptions, vueCompilerOptions, plugins) {
|
|
12
|
+
const key = JSON.stringify([
|
|
13
|
+
...plugins.map(plugin => plugin.name)
|
|
14
|
+
.filter(name => typeof name === 'string')
|
|
15
|
+
.sort(),
|
|
27
16
|
...Object.keys(vueCompilerOptions)
|
|
28
|
-
.sort()
|
|
29
17
|
.filter(key => key !== 'plugins')
|
|
18
|
+
.sort()
|
|
30
19
|
.map(key => [key, vueCompilerOptions[key]]),
|
|
31
|
-
[...new Set(plugins.
|
|
20
|
+
...[...new Set(plugins.flatMap(plugin => plugin.requiredCompilerOptions ?? []))]
|
|
32
21
|
.sort()
|
|
33
22
|
.map(key => [key, compilerOptions[key]]),
|
|
34
|
-
];
|
|
35
|
-
return
|
|
23
|
+
]);
|
|
24
|
+
return fileRegistries[key] ??= new Map();
|
|
36
25
|
}
|
|
37
26
|
function createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFileName) {
|
|
38
27
|
const pluginContext = {
|
|
@@ -44,7 +33,7 @@ function createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFile
|
|
|
44
33
|
vueCompilerOptions,
|
|
45
34
|
};
|
|
46
35
|
const plugins = (0, plugins_1.createPlugins)(pluginContext);
|
|
47
|
-
const fileRegistry = getVueFileRegistry(
|
|
36
|
+
const fileRegistry = getVueFileRegistry(compilerOptions, vueCompilerOptions, plugins);
|
|
48
37
|
return {
|
|
49
38
|
getLanguageId(scriptId) {
|
|
50
39
|
const fileName = asFileName(scriptId);
|
|
@@ -70,10 +59,14 @@ function createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFile
|
|
|
70
59
|
}
|
|
71
60
|
}
|
|
72
61
|
},
|
|
73
|
-
updateVirtualCode(
|
|
62
|
+
updateVirtualCode(_scriptId, code, snapshot) {
|
|
74
63
|
code.update(snapshot);
|
|
75
64
|
return code;
|
|
76
65
|
},
|
|
66
|
+
disposeVirtualCode(scriptId) {
|
|
67
|
+
const fileName = asFileName(scriptId);
|
|
68
|
+
fileRegistry.delete(fileName);
|
|
69
|
+
},
|
|
77
70
|
typescript: {
|
|
78
71
|
extraFileExtensions: getAllExtensions(vueCompilerOptions)
|
|
79
72
|
.map(ext => ({
|
|
@@ -2,38 +2,41 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const shouldAddSuffix = /(?<=<[^>/]+)$/;
|
|
4
4
|
const plugin = ({ modules }) => {
|
|
5
|
+
const CompilerDOM = modules['@vue/compiler-dom'];
|
|
5
6
|
return {
|
|
6
7
|
version: 2.2,
|
|
7
8
|
compileSFCTemplate(lang, template, options) {
|
|
8
9
|
if (lang === 'html' || lang === 'md') {
|
|
9
|
-
const compiler = modules['@vue/compiler-dom'];
|
|
10
10
|
let addedSuffix = false;
|
|
11
11
|
// #4583
|
|
12
12
|
if (shouldAddSuffix.test(template)) {
|
|
13
13
|
template += '>';
|
|
14
14
|
addedSuffix = true;
|
|
15
15
|
}
|
|
16
|
-
const
|
|
16
|
+
const ast = CompilerDOM.parse(template, {
|
|
17
17
|
...options,
|
|
18
18
|
comments: true,
|
|
19
19
|
});
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
CompilerDOM.transform(ast, options);
|
|
21
|
+
return {
|
|
22
|
+
ast,
|
|
23
|
+
code: '',
|
|
24
|
+
preamble: '',
|
|
25
|
+
__addedSuffix: addedSuffix,
|
|
26
|
+
};
|
|
23
27
|
}
|
|
24
28
|
},
|
|
25
29
|
updateSFCTemplate(oldResult, change) {
|
|
26
|
-
|
|
30
|
+
const newSource = oldResult.ast.source.slice(0, change.start)
|
|
27
31
|
+ change.newText
|
|
28
|
-
+ oldResult.
|
|
32
|
+
+ oldResult.ast.source.slice(change.end);
|
|
29
33
|
// @ts-expect-error
|
|
30
34
|
if (oldResult.__addedSuffix) {
|
|
31
|
-
const originalTemplate =
|
|
35
|
+
const originalTemplate = newSource.slice(0, -1); // remove added '>'
|
|
32
36
|
if (!shouldAddSuffix.test(originalTemplate)) {
|
|
33
37
|
return undefined;
|
|
34
38
|
}
|
|
35
39
|
}
|
|
36
|
-
const CompilerDOM = modules['@vue/compiler-dom'];
|
|
37
40
|
const lengthDiff = change.newText.length - (change.end - change.start);
|
|
38
41
|
let hitNodes = [];
|
|
39
42
|
if (tryUpdateNode(oldResult.ast) && hitNodes.length) {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
4
|
-
const
|
|
5
|
-
const shared_1 = require("
|
|
4
|
+
const forEachTemplateNode_1 = require("../utils/forEachTemplateNode");
|
|
5
|
+
const shared_1 = require("../utils/shared");
|
|
6
|
+
const shared_2 = require("./shared");
|
|
6
7
|
const codeFeatures = {
|
|
7
|
-
...
|
|
8
|
+
...shared_2.allCodeFeatures,
|
|
8
9
|
format: false,
|
|
9
10
|
structure: false,
|
|
10
11
|
};
|
|
@@ -28,23 +29,16 @@ const plugin = () => {
|
|
|
28
29
|
};
|
|
29
30
|
exports.default = plugin;
|
|
30
31
|
function* generate(templateAst) {
|
|
31
|
-
for (const node of (0,
|
|
32
|
+
for (const node of (0, forEachTemplateNode_1.forEachElementNode)(templateAst)) {
|
|
32
33
|
for (const prop of node.props) {
|
|
33
|
-
if (prop.type === CompilerDOM.NodeTypes.
|
|
34
|
-
&& prop.name === '
|
|
35
|
-
&& prop.
|
|
36
|
-
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
37
|
-
&& prop.arg.content === 'style'
|
|
38
|
-
&& prop.exp.constType === CompilerDOM.ConstantTypes.CAN_STRINGIFY) {
|
|
39
|
-
const endCrt = prop.arg.loc.source[prop.arg.loc.source.length - 1]; // " | '
|
|
40
|
-
const start = prop.arg.loc.source.indexOf(endCrt) + 1;
|
|
41
|
-
const end = prop.arg.loc.source.lastIndexOf(endCrt);
|
|
42
|
-
const content = prop.arg.loc.source.slice(start, end);
|
|
34
|
+
if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE
|
|
35
|
+
&& prop.name === 'style'
|
|
36
|
+
&& prop.value) {
|
|
43
37
|
yield `x { `;
|
|
44
38
|
yield [
|
|
45
|
-
content,
|
|
39
|
+
prop.value.content,
|
|
46
40
|
'template',
|
|
47
|
-
prop.
|
|
41
|
+
(0, shared_1.getAttributeValueOffset)(prop.value),
|
|
48
42
|
codeFeatures,
|
|
49
43
|
];
|
|
50
44
|
yield ` }\n`;
|
package/lib/plugins/vue-tsx.d.ts
CHANGED
|
@@ -180,10 +180,10 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
180
180
|
offset: number;
|
|
181
181
|
}[]>;
|
|
182
182
|
currentComponent: {
|
|
183
|
-
ctxVar: string;
|
|
184
|
-
|
|
183
|
+
get ctxVar(): string;
|
|
184
|
+
get propsVar(): string;
|
|
185
185
|
} | undefined;
|
|
186
|
-
singleRootElTypes: string
|
|
186
|
+
singleRootElTypes: Set<string>;
|
|
187
187
|
singleRootNodes: Set<import("@vue/compiler-dom").ElementNode | null>;
|
|
188
188
|
addTemplateRef(name: string, typeExp: string, offset: number): void;
|
|
189
189
|
accessExternalVariable(name: string, offset?: number): void;
|
package/lib/plugins/vue-tsx.js
CHANGED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import * as CompilerDOM from '@vue/compiler-dom';
|
|
2
|
+
export declare function forEachElementNode(node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode): Generator<CompilerDOM.ElementNode>;
|
|
3
|
+
export declare function forEachInterpolationNode(node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode): Generator<CompilerDOM.InterpolationNode>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.forEachElementNode = forEachElementNode;
|
|
4
|
+
exports.forEachInterpolationNode = forEachInterpolationNode;
|
|
5
|
+
const CompilerDOM = require("@vue/compiler-dom");
|
|
6
|
+
function* forEachElementNode(node) {
|
|
7
|
+
if (node.type === CompilerDOM.NodeTypes.ROOT) {
|
|
8
|
+
for (const child of node.children) {
|
|
9
|
+
yield* forEachElementNode(child);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
else if (node.type === CompilerDOM.NodeTypes.ELEMENT) {
|
|
13
|
+
yield node;
|
|
14
|
+
for (const child of node.children) {
|
|
15
|
+
yield* forEachElementNode(child);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
else if (node.type === CompilerDOM.NodeTypes.IF) {
|
|
19
|
+
for (const branch of node.branches) {
|
|
20
|
+
for (const childNode of branch.children) {
|
|
21
|
+
yield* forEachElementNode(childNode);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
else if (node.type === CompilerDOM.NodeTypes.FOR) {
|
|
26
|
+
for (const child of node.children) {
|
|
27
|
+
yield* forEachElementNode(child);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function* forEachInterpolationNode(node) {
|
|
32
|
+
if (node.type === CompilerDOM.NodeTypes.ROOT) {
|
|
33
|
+
for (const child of node.children) {
|
|
34
|
+
yield* forEachInterpolationNode(child);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else if (node.type === CompilerDOM.NodeTypes.ELEMENT) {
|
|
38
|
+
for (const child of node.children) {
|
|
39
|
+
yield* forEachInterpolationNode(child);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else if (node.type === CompilerDOM.NodeTypes.TEXT_CALL) {
|
|
43
|
+
yield* forEachInterpolationNode(node.content);
|
|
44
|
+
}
|
|
45
|
+
else if (node.type === CompilerDOM.NodeTypes.COMPOUND_EXPRESSION) {
|
|
46
|
+
for (const child of node.children) {
|
|
47
|
+
if (typeof child === 'object') {
|
|
48
|
+
yield* forEachInterpolationNode(child);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else if (node.type === CompilerDOM.NodeTypes.INTERPOLATION) {
|
|
53
|
+
yield node;
|
|
54
|
+
}
|
|
55
|
+
else if (node.type === CompilerDOM.NodeTypes.IF) {
|
|
56
|
+
for (const branch of node.branches) {
|
|
57
|
+
for (const childNode of branch.children) {
|
|
58
|
+
yield* forEachInterpolationNode(childNode);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else if (node.type === CompilerDOM.NodeTypes.FOR) {
|
|
63
|
+
for (const child of node.children) {
|
|
64
|
+
yield* forEachInterpolationNode(child);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=forEachTemplateNode.js.map
|
package/lib/utils/parseSfc.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parse = parse;
|
|
4
4
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
5
|
+
const shared_1 = require("./shared");
|
|
5
6
|
function parse(source) {
|
|
6
7
|
const errors = [];
|
|
7
8
|
const ast = CompilerDOM.parse(source, {
|
|
@@ -137,17 +138,11 @@ function parseAttr(p, node) {
|
|
|
137
138
|
if (!p.value) {
|
|
138
139
|
return true;
|
|
139
140
|
}
|
|
140
|
-
const
|
|
141
|
-
const source = p.value.loc.source;
|
|
142
|
-
let offset = p.value.loc.start.offset - node.loc.start.offset;
|
|
143
|
-
const quotes = source.startsWith('"') || source.startsWith("'");
|
|
144
|
-
if (quotes) {
|
|
145
|
-
offset++;
|
|
146
|
-
}
|
|
141
|
+
const offset = (0, shared_1.getAttributeValueOffset)(p.value);
|
|
147
142
|
return {
|
|
148
|
-
text,
|
|
149
|
-
offset,
|
|
150
|
-
quotes,
|
|
143
|
+
text: p.value.content,
|
|
144
|
+
offset: offset - node.loc.start.offset,
|
|
145
|
+
quotes: offset > p.value.loc.start.offset,
|
|
151
146
|
};
|
|
152
147
|
}
|
|
153
148
|
//# sourceMappingURL=parseSfc.js.map
|
package/lib/utils/shared.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type * as ts from 'typescript';
|
|
|
3
3
|
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
|
+
export declare function getAttributeValueOffset(node: CompilerDOM.TextNode): number;
|
|
6
7
|
export declare function getElementTagOffsets(node: CompilerDOM.ElementNode, template: NonNullable<Sfc['template']>): [number] | [number, number];
|
|
7
8
|
export declare function getStartEnd(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): TextRange;
|
|
8
9
|
export declare function getNodeText(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): string;
|
package/lib/utils/shared.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.hyphenateTag = void 0;
|
|
4
4
|
exports.hyphenateAttr = hyphenateAttr;
|
|
5
|
+
exports.getAttributeValueOffset = getAttributeValueOffset;
|
|
5
6
|
exports.getElementTagOffsets = getElementTagOffsets;
|
|
6
7
|
exports.getStartEnd = getStartEnd;
|
|
7
8
|
exports.getNodeText = getNodeText;
|
|
@@ -16,6 +17,13 @@ function hyphenateAttr(str) {
|
|
|
16
17
|
}
|
|
17
18
|
return hyphencase;
|
|
18
19
|
}
|
|
20
|
+
function getAttributeValueOffset(node) {
|
|
21
|
+
let offset = node.loc.start.offset;
|
|
22
|
+
if (node.loc.source.startsWith('"') || node.loc.source.startsWith("'")) {
|
|
23
|
+
offset++;
|
|
24
|
+
}
|
|
25
|
+
return offset;
|
|
26
|
+
}
|
|
19
27
|
function getElementTagOffsets(node, template) {
|
|
20
28
|
const tagOffsets = [
|
|
21
29
|
template.content.indexOf(node.tag, node.loc.start.offset),
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.templateInlineTsAsts = void 0;
|
|
4
4
|
exports.computedSfc = computedSfc;
|
|
5
|
+
const CompilerDOM = require("@vue/compiler-dom");
|
|
5
6
|
const alien_signals_1 = require("alien-signals");
|
|
6
7
|
const signals_1 = require("../utils/signals");
|
|
7
8
|
exports.templateInlineTsAsts = new WeakMap();
|
|
@@ -225,10 +226,13 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
|
|
|
225
226
|
}
|
|
226
227
|
const errors = [];
|
|
227
228
|
const warnings = [];
|
|
229
|
+
const [nodeTransforms, directiveTransforms] = CompilerDOM.getBaseTransformPreset();
|
|
228
230
|
let options = {
|
|
229
|
-
onError:
|
|
230
|
-
onWarn:
|
|
231
|
+
onError: err => errors.push(err),
|
|
232
|
+
onWarn: err => warnings.push(err),
|
|
231
233
|
expressionPlugins: ['typescript'],
|
|
234
|
+
nodeTransforms,
|
|
235
|
+
directiveTransforms,
|
|
232
236
|
};
|
|
233
237
|
for (const plugin of plugins) {
|
|
234
238
|
if (plugin.resolveTemplateCompilerOptions) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/language-core",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.5",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"optional": true
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "d124a88fbf169e793c39ae4248da2092098de92d"
|
|
40
40
|
}
|