@vue/language-core 3.1.4 → 3.1.6
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 +2 -1
- package/index.js +3 -2
- package/lib/codegen/codeFeatures.d.ts +5 -9
- package/lib/codegen/codeFeatures.js +5 -5
- package/lib/codegen/globalTypes.js +15 -20
- package/lib/codegen/localTypes.d.ts +1 -1
- package/lib/codegen/localTypes.js +6 -6
- package/lib/codegen/names.d.ts +30 -0
- package/lib/codegen/names.js +34 -0
- package/lib/codegen/script/component.js +45 -54
- package/lib/codegen/script/context.d.ts +2 -5
- package/lib/codegen/script/context.js +1 -7
- package/lib/codegen/script/index.d.ts +10 -12
- package/lib/codegen/script/index.js +74 -73
- package/lib/codegen/script/scriptSetup.d.ts +3 -2
- package/lib/codegen/script/scriptSetup.js +209 -283
- package/lib/codegen/script/src.js +9 -3
- package/lib/codegen/script/template.js +64 -108
- package/lib/codegen/style/common.d.ts +3 -0
- package/lib/codegen/style/common.js +43 -0
- package/lib/codegen/style/index.d.ts +63 -0
- package/lib/codegen/style/index.js +38 -0
- package/lib/codegen/style/modules.d.ts +3 -2
- package/lib/codegen/style/modules.js +12 -11
- package/lib/codegen/style/scopedClasses.d.ts +2 -3
- package/lib/codegen/style/scopedClasses.js +23 -21
- package/lib/codegen/template/context.d.ts +10 -19
- package/lib/codegen/template/context.js +82 -94
- package/lib/codegen/template/element.js +174 -65
- package/lib/codegen/template/elementDirectives.js +32 -12
- package/lib/codegen/template/elementEvents.d.ts +1 -1
- package/lib/codegen/template/elementEvents.js +30 -35
- package/lib/codegen/template/elementProps.d.ts +3 -3
- package/lib/codegen/template/elementProps.js +64 -83
- package/lib/codegen/template/index.d.ts +11 -22
- package/lib/codegen/template/index.js +85 -80
- package/lib/codegen/template/interpolation.d.ts +3 -3
- package/lib/codegen/template/interpolation.js +108 -155
- package/lib/codegen/template/objectProperty.js +8 -4
- package/lib/codegen/template/propertyAccess.d.ts +1 -1
- package/lib/codegen/template/propertyAccess.js +5 -7
- package/lib/codegen/template/slotOutlet.js +26 -14
- package/lib/codegen/template/styleScopedClasses.d.ts +3 -6
- package/lib/codegen/template/styleScopedClasses.js +23 -149
- package/lib/codegen/template/templateChild.d.ts +0 -1
- package/lib/codegen/template/templateChild.js +11 -68
- package/lib/codegen/template/vFor.js +10 -13
- package/lib/codegen/template/vIf.js +5 -3
- package/lib/codegen/template/vSlot.js +20 -16
- package/lib/codegen/utils/boundary.d.ts +3 -0
- package/lib/codegen/utils/boundary.js +13 -0
- package/lib/codegen/utils/camelized.js +3 -3
- package/lib/codegen/utils/escaped.js +4 -2
- package/lib/codegen/utils/index.d.ts +3 -6
- package/lib/codegen/utils/index.js +41 -26
- package/lib/codegen/utils/merge.d.ts +2 -2
- package/lib/codegen/utils/merge.js +9 -9
- package/lib/codegen/utils/stringLiteralKey.js +6 -3
- package/lib/codegen/utils/transform.d.ts +8 -0
- package/lib/codegen/utils/transform.js +27 -0
- package/lib/codegen/utils/unicode.js +4 -2
- package/lib/compilerOptions.js +4 -4
- package/lib/languagePlugin.d.ts +1 -1
- package/lib/languagePlugin.js +18 -25
- package/lib/plugins/vue-template-html.js +12 -9
- package/lib/plugins/vue-template-inline-css.js +8 -18
- package/lib/plugins/vue-template-inline-ts.js +12 -14
- package/lib/plugins/vue-tsx.d.ts +14 -23
- package/lib/plugins/vue-tsx.js +121 -69
- package/lib/plugins.js +1 -1
- package/lib/types.d.ts +5 -4
- package/lib/utils/parseSfc.js +10 -11
- package/lib/utils/shared.d.ts +1 -0
- package/lib/utils/shared.js +9 -0
- package/lib/utils/signals.d.ts +2 -2
- package/lib/utils/signals.js +8 -6
- package/lib/virtualCode/embeddedCodes.d.ts +12 -0
- package/lib/virtualCode/embeddedCodes.js +249 -0
- package/lib/{virtualFile/vueFile.d.ts → virtualCode/index.d.ts} +9 -9
- package/lib/virtualCode/index.js +81 -0
- package/lib/virtualCode/ir.d.ts +4 -0
- package/lib/{virtualFile/computedSfc.js → virtualCode/ir.js} +65 -96
- package/lib/virtualCode/normalize.d.ts +2 -0
- package/lib/virtualCode/normalize.js +170 -0
- package/package.json +4 -4
- package/lib/codegen/style/classProperty.d.ts +0 -2
- package/lib/codegen/style/classProperty.js +0 -18
- package/lib/codegen/style/imports.d.ts +0 -2
- package/lib/codegen/style/imports.js +0 -27
- package/lib/codegen/template/elementChildren.d.ts +0 -5
- package/lib/codegen/template/elementChildren.js +0 -12
- package/lib/codegen/utils/wrapWith.d.ts +0 -3
- package/lib/codegen/utils/wrapWith.js +0 -24
- package/lib/virtualFile/computedEmbeddedCodes.d.ts +0 -4
- package/lib/virtualFile/computedEmbeddedCodes.js +0 -262
- package/lib/virtualFile/computedSfc.d.ts +0 -6
- package/lib/virtualFile/computedVueSfc.d.ts +0 -4
- package/lib/virtualFile/computedVueSfc.js +0 -41
- package/lib/virtualFile/embeddedFile.d.ts +0 -11
- package/lib/virtualFile/embeddedFile.js +0 -14
- package/lib/virtualFile/vueFile.js +0 -49
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateEscaped = generateEscaped;
|
|
4
4
|
function* generateEscaped(text, source, offset, features, escapeTarget) {
|
|
5
5
|
const parts = text.split(escapeTarget);
|
|
6
|
-
const
|
|
6
|
+
const combineToken = features.__combineToken ?? Symbol();
|
|
7
7
|
let isEscapeTarget = false;
|
|
8
8
|
for (let i = 0; i < parts.length; i++) {
|
|
9
9
|
const part = parts[i];
|
|
@@ -14,7 +14,9 @@ function* generateEscaped(text, source, offset, features, escapeTarget) {
|
|
|
14
14
|
part,
|
|
15
15
|
source,
|
|
16
16
|
offset,
|
|
17
|
-
i === 0
|
|
17
|
+
i === 0
|
|
18
|
+
? { ...features, __combineToken: combineToken }
|
|
19
|
+
: { __combineToken: combineToken },
|
|
18
20
|
];
|
|
19
21
|
offset += part.length;
|
|
20
22
|
isEscapeTarget = !isEscapeTarget;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import type * as CompilerDOM from '@vue/compiler-dom';
|
|
2
1
|
import type * as ts from 'typescript';
|
|
3
2
|
import type { Code, SfcBlock, VueCodeInformation } from '../../types';
|
|
4
3
|
export declare const newLine = "\n";
|
|
5
4
|
export declare const endOfLine = ";\n";
|
|
6
|
-
export declare const combineLastMapping: VueCodeInformation;
|
|
7
5
|
export declare const identifierRegex: RegExp;
|
|
8
|
-
export declare function
|
|
9
|
-
export declare function
|
|
10
|
-
export declare function
|
|
11
|
-
export declare function generatePartiallyEnding(source: string, end: number, mark: string, delimiter?: string): Generator<Code>;
|
|
6
|
+
export declare function getTypeScriptAST(ts: typeof import('typescript'), block: SfcBlock, text: string): ts.SourceFile;
|
|
7
|
+
export declare function generateSfcBlockSection(block: SfcBlock, start: number, end: number, features: VueCodeInformation, partiallyEnd?: boolean): Generator<Code>;
|
|
8
|
+
export declare function forEachNode(ts: typeof import('typescript'), node: ts.Node): Generator<ts.Node>;
|
|
@@ -1,45 +1,60 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.identifierRegex = exports.
|
|
4
|
-
exports.
|
|
5
|
-
exports.createTsAst = createTsAst;
|
|
3
|
+
exports.identifierRegex = exports.endOfLine = exports.newLine = void 0;
|
|
4
|
+
exports.getTypeScriptAST = getTypeScriptAST;
|
|
6
5
|
exports.generateSfcBlockSection = generateSfcBlockSection;
|
|
7
|
-
exports.
|
|
6
|
+
exports.forEachNode = forEachNode;
|
|
8
7
|
const codeFeatures_1 = require("../codeFeatures");
|
|
9
8
|
exports.newLine = `\n`;
|
|
10
9
|
exports.endOfLine = `;${exports.newLine}`;
|
|
11
|
-
exports.combineLastMapping = { __combineOffset: 1 };
|
|
12
10
|
exports.identifierRegex = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|| (content.startsWith(`"`) && content.endsWith(`"`))) {
|
|
18
|
-
offset++;
|
|
19
|
-
content = content.slice(1, -1);
|
|
11
|
+
const cacheMaps = new Map();
|
|
12
|
+
function getTypeScriptAST(ts, block, text) {
|
|
13
|
+
if (!cacheMaps.has(block)) {
|
|
14
|
+
cacheMaps.set(block, [block.content, new Map()]);
|
|
20
15
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
16
|
+
const cacheMap = cacheMaps.get(block);
|
|
17
|
+
if (cacheMap[0] !== block.content) {
|
|
18
|
+
cacheMap[0] = block.content;
|
|
19
|
+
for (const [key, info] of cacheMap[1]) {
|
|
20
|
+
if (info[1]) {
|
|
21
|
+
info[1] = 0;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
cacheMap[1].delete(key);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const cache = cacheMap[1].get(text);
|
|
29
|
+
if (cache) {
|
|
30
|
+
cache[1]++;
|
|
31
|
+
return cache[0];
|
|
28
32
|
}
|
|
29
|
-
ast
|
|
33
|
+
const ast = ts.createSourceFile('/dummy.ts', text, 99);
|
|
34
|
+
cacheMap[1].set(text, [ast, 1]);
|
|
30
35
|
return ast;
|
|
31
36
|
}
|
|
32
|
-
function generateSfcBlockSection(block, start, end, features) {
|
|
33
|
-
|
|
37
|
+
function* generateSfcBlockSection(block, start, end, features, partiallyEnd = false) {
|
|
38
|
+
yield [
|
|
34
39
|
block.content.slice(start, end),
|
|
35
40
|
block.name,
|
|
36
41
|
start,
|
|
37
42
|
features,
|
|
38
43
|
];
|
|
44
|
+
// #3632
|
|
45
|
+
if (partiallyEnd) {
|
|
46
|
+
yield `;`;
|
|
47
|
+
yield ['', block.name, end, codeFeatures_1.codeFeatures.verification];
|
|
48
|
+
yield exports.newLine;
|
|
49
|
+
}
|
|
39
50
|
}
|
|
40
|
-
function*
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
51
|
+
function* forEachNode(ts, node) {
|
|
52
|
+
const children = [];
|
|
53
|
+
ts.forEachChild(node, child => {
|
|
54
|
+
children.push(child);
|
|
55
|
+
});
|
|
56
|
+
for (const child of children) {
|
|
57
|
+
yield child;
|
|
58
|
+
}
|
|
44
59
|
}
|
|
45
60
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Code } from '../../types';
|
|
2
|
-
export declare function generateIntersectMerge(
|
|
3
|
-
export declare function generateSpreadMerge(
|
|
2
|
+
export declare function generateIntersectMerge(generates: Iterable<Code>[]): Generator<Code>;
|
|
3
|
+
export declare function generateSpreadMerge(generates: Iterable<Code>[]): Generator<Code>;
|
|
@@ -3,22 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateIntersectMerge = generateIntersectMerge;
|
|
4
4
|
exports.generateSpreadMerge = generateSpreadMerge;
|
|
5
5
|
const index_1 = require("./index");
|
|
6
|
-
function* generateIntersectMerge(
|
|
7
|
-
yield
|
|
8
|
-
for (let i = 1; i <
|
|
6
|
+
function* generateIntersectMerge(generates) {
|
|
7
|
+
yield* generates[0];
|
|
8
|
+
for (let i = 1; i < generates.length; i++) {
|
|
9
9
|
yield ` & `;
|
|
10
|
-
yield
|
|
10
|
+
yield* generates[i];
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
function* generateSpreadMerge(
|
|
14
|
-
if (
|
|
15
|
-
yield
|
|
13
|
+
function* generateSpreadMerge(generates) {
|
|
14
|
+
if (generates.length === 1) {
|
|
15
|
+
yield* generates[0];
|
|
16
16
|
}
|
|
17
17
|
else {
|
|
18
18
|
yield `{${index_1.newLine}`;
|
|
19
|
-
for (const
|
|
19
|
+
for (const generate of generates) {
|
|
20
20
|
yield `...`;
|
|
21
|
-
yield
|
|
21
|
+
yield* generate;
|
|
22
22
|
yield `,${index_1.newLine}`;
|
|
23
23
|
}
|
|
24
24
|
yield `}`;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateStringLiteralKey = generateStringLiteralKey;
|
|
4
|
-
const
|
|
5
|
-
const wrapWith_1 = require("./wrapWith");
|
|
4
|
+
const boundary_1 = require("./boundary");
|
|
6
5
|
function* generateStringLiteralKey(code, offset, info) {
|
|
7
6
|
if (offset === undefined || !info) {
|
|
8
7
|
yield `'${code}'`;
|
|
9
8
|
}
|
|
10
9
|
else {
|
|
11
|
-
yield* (0,
|
|
10
|
+
const token = yield* (0, boundary_1.startBoundary)('template', offset, info);
|
|
11
|
+
yield `'`;
|
|
12
|
+
yield [code, 'template', offset, { __combineToken: token }];
|
|
13
|
+
yield `'`;
|
|
14
|
+
yield (0, boundary_1.endBoundary)(token, offset + code.length);
|
|
12
15
|
}
|
|
13
16
|
}
|
|
14
17
|
//# sourceMappingURL=stringLiteralKey.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Code } from '../../types';
|
|
2
|
+
export interface CodeTransform {
|
|
3
|
+
range: [start: number, end: number];
|
|
4
|
+
generate(): Iterable<Code>;
|
|
5
|
+
}
|
|
6
|
+
export declare function replace(start: number, end: number, replacement: () => Iterable<Code>): CodeTransform;
|
|
7
|
+
export declare function insert(position: number, insertion: () => Iterable<Code>): CodeTransform;
|
|
8
|
+
export declare function generateCodeWithTransforms(start: number, end: number, transforms: CodeTransform[], section: (start: number, end: number) => Iterable<Code>): Generator<Code>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.replace = replace;
|
|
4
|
+
exports.insert = insert;
|
|
5
|
+
exports.generateCodeWithTransforms = generateCodeWithTransforms;
|
|
6
|
+
function replace(start, end, replacement) {
|
|
7
|
+
return {
|
|
8
|
+
range: [start, end],
|
|
9
|
+
generate: replacement,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function insert(position, insertion) {
|
|
13
|
+
return {
|
|
14
|
+
range: [position, position],
|
|
15
|
+
generate: insertion,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function* generateCodeWithTransforms(start, end, transforms, section) {
|
|
19
|
+
const sortedTransforms = transforms.sort((a, b) => a.range[0] - b.range[0]);
|
|
20
|
+
for (const { range, generate } of sortedTransforms) {
|
|
21
|
+
yield* section(start, range[0]);
|
|
22
|
+
yield* generate();
|
|
23
|
+
start = range[1];
|
|
24
|
+
}
|
|
25
|
+
yield* section(start, end);
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=transform.js.map
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateUnicode = generateUnicode;
|
|
4
|
-
const
|
|
4
|
+
const boundary_1 = require("./boundary");
|
|
5
5
|
function* generateUnicode(code, offset, info) {
|
|
6
6
|
if (needToUnicode(code)) {
|
|
7
|
-
yield* (0,
|
|
7
|
+
const token = yield* (0, boundary_1.startBoundary)('template', offset, info);
|
|
8
|
+
yield toUnicode(code);
|
|
9
|
+
yield (0, boundary_1.endBoundary)(token, offset + code.length);
|
|
8
10
|
}
|
|
9
11
|
else {
|
|
10
12
|
yield [code, 'template', offset, info];
|
package/lib/compilerOptions.js
CHANGED
|
@@ -24,7 +24,8 @@ function createParsedCommandLineByJson(ts, host, rootDir, json, configFileName)
|
|
|
24
24
|
return [];
|
|
25
25
|
},
|
|
26
26
|
};
|
|
27
|
-
const
|
|
27
|
+
const config = ts.readJsonConfigFile(rootDir, () => JSON.stringify(json));
|
|
28
|
+
const parsed = ts.parseJsonSourceFileConfigFileContent(config, proxyHost, rootDir, {}, configFileName);
|
|
28
29
|
const resolver = new CompilerOptionsResolver(host.fileExists);
|
|
29
30
|
for (const extendPath of [...extendedPaths].reverse()) {
|
|
30
31
|
try {
|
|
@@ -35,8 +36,7 @@ function createParsedCommandLineByJson(ts, host, rootDir, json, configFileName)
|
|
|
35
36
|
}
|
|
36
37
|
catch { }
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
-
resolver.addConfig({}, rootDir);
|
|
39
|
+
resolver.addConfig(json?.vueCompilerOptions ?? {}, rootDir);
|
|
40
40
|
return {
|
|
41
41
|
...parsed,
|
|
42
42
|
vueOptions: resolver.build(),
|
|
@@ -151,7 +151,7 @@ class CompilerOptionsResolver {
|
|
|
151
151
|
...defaults.fallthroughComponentNames,
|
|
152
152
|
...this.options.fallthroughComponentNames ?? [],
|
|
153
153
|
].map(shared_2.hyphenateTag),
|
|
154
|
-
// https://github.com/vuejs/
|
|
154
|
+
// https://github.com/vuejs/core/blob/master/packages/compiler-dom/src/transforms/vModel.ts#L49-L51
|
|
155
155
|
// https://vuejs.org/guide/essentials/forms.html#form-input-bindings
|
|
156
156
|
experimentalModelPropName: Object.fromEntries(Object.entries(this.options.experimentalModelPropName ?? defaults.experimentalModelPropName).map(([k, v]) => [(0, shared_1.camelize)(k), v])),
|
|
157
157
|
};
|
package/lib/languagePlugin.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type LanguagePlugin } from '@volar/language-core';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
3
|
import type { VueCompilerOptions } from './types';
|
|
4
|
-
import { VueVirtualCode } from './
|
|
4
|
+
import { VueVirtualCode } from './virtualCode';
|
|
5
5
|
export declare function createVueLanguagePlugin<T>(ts: typeof import('typescript'), compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions, asFileName: (scriptId: T) => string): LanguagePlugin<T, VueVirtualCode>;
|
|
6
6
|
export declare function getAllExtensions(options: VueCompilerOptions): string[];
|
package/lib/languagePlugin.js
CHANGED
|
@@ -6,33 +6,22 @@ exports.getAllExtensions = getAllExtensions;
|
|
|
6
6
|
const language_core_1 = require("@volar/language-core");
|
|
7
7
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
8
8
|
const plugins_1 = require("./plugins");
|
|
9
|
-
const
|
|
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 = [
|
|
9
|
+
const virtualCode_1 = require("./virtualCode");
|
|
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);
|
|
@@ -64,16 +53,20 @@ function createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFile
|
|
|
64
53
|
return code;
|
|
65
54
|
}
|
|
66
55
|
else {
|
|
67
|
-
const code = new
|
|
56
|
+
const code = new virtualCode_1.VueVirtualCode(fileName, languageId, snapshot, vueCompilerOptions, plugins, ts);
|
|
68
57
|
fileRegistry.set(fileName, code);
|
|
69
58
|
return code;
|
|
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) {
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
4
4
|
const forEachTemplateNode_1 = require("../utils/forEachTemplateNode");
|
|
5
|
-
const shared_1 = require("
|
|
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
|
};
|
|
@@ -30,23 +31,12 @@ exports.default = plugin;
|
|
|
30
31
|
function* generate(templateAst) {
|
|
31
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
|
-
|
|
45
|
-
|
|
46
|
-
'template',
|
|
47
|
-
prop.arg.loc.start.offset + start,
|
|
48
|
-
codeFeatures,
|
|
49
|
-
];
|
|
38
|
+
const [content, offset] = (0, shared_1.normalizeAttributeValue)(prop.value);
|
|
39
|
+
yield [content, 'template', offset, codeFeatures];
|
|
50
40
|
yield ` }\n`;
|
|
51
41
|
}
|
|
52
42
|
}
|
|
@@ -5,7 +5,6 @@ const elementEvents_1 = require("../codegen/template/elementEvents");
|
|
|
5
5
|
const templateChild_1 = require("../codegen/template/templateChild");
|
|
6
6
|
const vFor_1 = require("../codegen/template/vFor");
|
|
7
7
|
const utils_1 = require("../codegen/utils");
|
|
8
|
-
const computedSfc_1 = require("../virtualFile/computedSfc");
|
|
9
8
|
const codeFeatures = {
|
|
10
9
|
format: true,
|
|
11
10
|
};
|
|
@@ -21,7 +20,7 @@ const formatBrackets = {
|
|
|
21
20
|
event: ['() => ', ';'],
|
|
22
21
|
generic: ['<', '>() => {};'],
|
|
23
22
|
};
|
|
24
|
-
const plugin =
|
|
23
|
+
const plugin = ({ modules: { typescript: ts } }) => {
|
|
25
24
|
const parseds = new WeakMap();
|
|
26
25
|
return {
|
|
27
26
|
version: 2.2,
|
|
@@ -54,15 +53,14 @@ const plugin = ctx => {
|
|
|
54
53
|
},
|
|
55
54
|
};
|
|
56
55
|
function parse(sfc) {
|
|
57
|
-
const
|
|
56
|
+
const result = new Map();
|
|
58
57
|
if (!sfc.template?.ast) {
|
|
59
|
-
return
|
|
58
|
+
return result;
|
|
60
59
|
}
|
|
61
|
-
const
|
|
62
|
-
const inlineTsAsts = computedSfc_1.templateInlineTsAsts.get(sfc.template.ast);
|
|
60
|
+
const template = sfc.template;
|
|
63
61
|
let i = 0;
|
|
64
62
|
sfc.template.ast.children.forEach(visit);
|
|
65
|
-
return
|
|
63
|
+
return result;
|
|
66
64
|
function visit(node) {
|
|
67
65
|
if (node.type === CompilerDOM.NodeTypes.COMMENT) {
|
|
68
66
|
const match = node.loc.source.match(/^<!--\s*@vue-generic\s*\{(?<content>[\s\S]*)\}\s*-->$/);
|
|
@@ -87,8 +85,8 @@ const plugin = ctx => {
|
|
|
87
85
|
&& prop.exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY // style='z-index: 2' will compile to {'z-index':'2'}
|
|
88
86
|
) {
|
|
89
87
|
if (prop.name === 'on' && prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
90
|
-
const ast = (0, utils_1.
|
|
91
|
-
if ((0, elementEvents_1.isCompoundExpression)(
|
|
88
|
+
const ast = (0, utils_1.getTypeScriptAST)(ts, template, prop.exp.content);
|
|
89
|
+
if ((0, elementEvents_1.isCompoundExpression)(ts, ast)) {
|
|
92
90
|
addFormatCodes(prop.exp.loc.source, prop.exp.loc.start.offset, formatBrackets.event);
|
|
93
91
|
}
|
|
94
92
|
else {
|
|
@@ -135,13 +133,13 @@ const plugin = ctx => {
|
|
|
135
133
|
if (leftExpressionRange && leftExpressionText && source.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
136
134
|
let start = leftExpressionRange.start;
|
|
137
135
|
let end = source.loc.start.offset + source.content.length;
|
|
138
|
-
while (
|
|
136
|
+
while (template.content[start - 1] === ' ' || template.content[start - 1] === '(') {
|
|
139
137
|
start--;
|
|
140
138
|
}
|
|
141
|
-
while (
|
|
139
|
+
while (template.content[end] === ' ' || template.content[end] === ')') {
|
|
142
140
|
end++;
|
|
143
141
|
}
|
|
144
|
-
addFormatCodes(
|
|
142
|
+
addFormatCodes(template.content.slice(start, end), start, formatBrackets.for);
|
|
145
143
|
}
|
|
146
144
|
for (const child of node.children) {
|
|
147
145
|
visit(child);
|
|
@@ -161,7 +159,7 @@ const plugin = ctx => {
|
|
|
161
159
|
}
|
|
162
160
|
else if (node.type === CompilerDOM.NodeTypes.INTERPOLATION) {
|
|
163
161
|
// {{ ... }}
|
|
164
|
-
const [content, start] = (0, templateChild_1.parseInterpolationNode)(node,
|
|
162
|
+
const [content, start] = (0, templateChild_1.parseInterpolationNode)(node, template.content);
|
|
165
163
|
const lines = content.split('\n');
|
|
166
164
|
const firstLineEmpty = lines[0].trim() === '';
|
|
167
165
|
const lastLineEmpty = lines[lines.length - 1].trim() === '';
|
|
@@ -188,7 +186,7 @@ const plugin = ctx => {
|
|
|
188
186
|
}
|
|
189
187
|
function addFormatCodes(code, offset, wrapper) {
|
|
190
188
|
const id = 'template_inline_ts_' + i++;
|
|
191
|
-
|
|
189
|
+
result.set(id, [
|
|
192
190
|
wrapper[0],
|
|
193
191
|
[
|
|
194
192
|
code,
|
package/lib/plugins/vue-tsx.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Sfc, VueLanguagePlugin } from '../types';
|
|
2
2
|
export declare const tsCodegen: WeakMap<Sfc, {
|
|
3
|
-
getLang: () => string;
|
|
4
3
|
getScriptRanges: () => {
|
|
5
4
|
exportDefault: (import("../types").TextRange & {
|
|
6
5
|
expression: import("../types").TextRange;
|
|
@@ -121,14 +120,11 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
121
120
|
getSetupSlotsAssignName: () => string | undefined;
|
|
122
121
|
getGeneratedScript: () => {
|
|
123
122
|
codes: import("../types").Code[];
|
|
124
|
-
|
|
125
|
-
generatedPropsType: boolean;
|
|
126
|
-
bypassDefineComponent: boolean;
|
|
127
|
-
bindingNames: Set<string>;
|
|
123
|
+
generatedTypes: Set<string>;
|
|
128
124
|
localTypes: {
|
|
129
125
|
generate: () => Generator<string, void, unknown>;
|
|
130
126
|
readonly PrettifyLocal: string;
|
|
131
|
-
readonly
|
|
127
|
+
readonly WithDefaults: string;
|
|
132
128
|
readonly WithSlots: string;
|
|
133
129
|
readonly PropsChildren: string;
|
|
134
130
|
readonly TypePropsToOption: string;
|
|
@@ -138,6 +134,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
138
134
|
};
|
|
139
135
|
getGeneratedTemplate: () => {
|
|
140
136
|
codes: import("../types").Code[];
|
|
137
|
+
generatedTypes: Set<string>;
|
|
141
138
|
currentInfo: {
|
|
142
139
|
ignoreError?: boolean;
|
|
143
140
|
expectError?: {
|
|
@@ -150,7 +147,6 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
150
147
|
};
|
|
151
148
|
};
|
|
152
149
|
resolveCodeFeatures: (features: import("../types").VueCodeInformation) => import("../types").VueCodeInformation;
|
|
153
|
-
inlineTsAsts: Map<string, import("typescript").SourceFile> | undefined;
|
|
154
150
|
inVFor: boolean;
|
|
155
151
|
slots: {
|
|
156
152
|
name: string;
|
|
@@ -164,40 +160,35 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
164
160
|
propsVar: string;
|
|
165
161
|
}[];
|
|
166
162
|
dollarVars: Set<string>;
|
|
167
|
-
|
|
163
|
+
componentAccessMap: Map<string, Map<string, Set<number>>>;
|
|
168
164
|
blockConditions: string[];
|
|
169
|
-
scopedClasses: {
|
|
170
|
-
source: string;
|
|
171
|
-
className: string;
|
|
172
|
-
offset: number;
|
|
173
|
-
}[];
|
|
174
|
-
emptyClassOffsets: number[];
|
|
175
165
|
inlayHints: import("../codegen/inlayHints").InlayHintInfo[];
|
|
176
|
-
bindingAttrLocs: import("@vue/compiler-dom").SourceLocation[];
|
|
177
166
|
inheritedAttrVars: Set<string>;
|
|
178
167
|
templateRefs: Map<string, {
|
|
179
168
|
typeExp: string;
|
|
180
169
|
offset: number;
|
|
181
170
|
}[]>;
|
|
182
171
|
currentComponent: {
|
|
183
|
-
ctxVar: string;
|
|
184
|
-
|
|
172
|
+
get ctxVar(): string;
|
|
173
|
+
get propsVar(): string;
|
|
185
174
|
} | undefined;
|
|
186
|
-
singleRootElTypes: string
|
|
175
|
+
singleRootElTypes: Set<string>;
|
|
187
176
|
singleRootNodes: Set<import("@vue/compiler-dom").ElementNode | null>;
|
|
188
177
|
addTemplateRef(name: string, typeExp: string, offset: number): void;
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
178
|
+
recordComponentAccess(source: string, name: string, offset?: number): void;
|
|
179
|
+
scopes: Set<string>[];
|
|
180
|
+
declare(...varNames: string[]): void;
|
|
181
|
+
startScope(): () => Generator<import("../types").Code, any, any>;
|
|
193
182
|
getInternalVariable(): string;
|
|
194
183
|
getHoistVariable(originalVar: string): string;
|
|
195
184
|
generateHoistVariables(): Generator<string, void, unknown>;
|
|
196
185
|
generateConditionGuards(): Generator<string, void, unknown>;
|
|
197
|
-
generateAutoImportCompletion(): Generator<import("../types").Code>;
|
|
198
186
|
enter(node: import("@vue/compiler-dom").RootNode | import("@vue/compiler-dom").TemplateChildNode | import("@vue/compiler-dom").SimpleExpressionNode): boolean;
|
|
199
187
|
exit(): Generator<import("../types").Code>;
|
|
200
188
|
} | undefined;
|
|
189
|
+
getImportComponentNames: () => Set<string>;
|
|
190
|
+
getSetupExposed: () => Set<string>;
|
|
191
|
+
getSetupConsts: () => Set<string>;
|
|
201
192
|
}>;
|
|
202
193
|
declare const plugin: VueLanguagePlugin;
|
|
203
194
|
export default plugin;
|