@vue/language-core 3.1.6 → 3.1.8
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/globalTypes.js +1 -1
- package/lib/codegen/names.d.ts +0 -1
- package/lib/codegen/names.js +1 -2
- package/lib/codegen/script/component.js +1 -14
- package/lib/codegen/script/index.js +59 -53
- package/lib/codegen/script/scriptSetup.js +2 -2
- package/lib/codegen/script/src.d.ts +1 -0
- package/lib/codegen/script/src.js +17 -12
- package/lib/codegen/script/template.d.ts +1 -1
- package/lib/codegen/script/template.js +9 -24
- package/lib/codegen/style/classProperty.d.ts +2 -0
- package/lib/codegen/style/classProperty.js +18 -0
- package/lib/codegen/style/imports.d.ts +2 -0
- package/lib/codegen/style/imports.js +27 -0
- package/lib/codegen/style/index.d.ts +1 -4
- package/lib/codegen/template/context.d.ts +1 -4
- package/lib/codegen/template/context.js +2 -1
- package/lib/codegen/template/element.js +105 -157
- package/lib/codegen/template/elementChildren.d.ts +5 -0
- package/lib/codegen/template/elementChildren.js +12 -0
- package/lib/codegen/template/elementEvents.d.ts +1 -1
- package/lib/codegen/template/elementEvents.js +3 -3
- package/lib/codegen/template/index.d.ts +2 -5
- package/lib/codegen/template/templateChild.js +11 -15
- package/lib/codegen/template/vSlot.d.ts +1 -1
- package/lib/codegen/template/vSlot.js +14 -20
- package/lib/codegen/utils/index.d.ts +2 -2
- package/lib/codegen/utils/index.js +15 -11
- package/lib/codegen/utils/wrapWith.d.ts +2 -0
- package/lib/codegen/utils/wrapWith.js +15 -0
- package/lib/languagePlugin.js +3 -4
- package/lib/parsers/scriptRanges.d.ts +6 -8
- package/lib/parsers/scriptRanges.js +5 -2
- package/lib/parsers/scriptSetupRanges.d.ts +2 -6
- package/lib/parsers/scriptSetupRanges.js +3 -2
- package/lib/parsers/utils.d.ts +4 -6
- package/lib/parsers/utils.js +25 -27
- package/lib/plugins/vue-script-js.js +1 -1
- package/lib/plugins/vue-tsx.d.ts +7 -17
- package/lib/plugins/vue-tsx.js +7 -18
- package/lib/virtualFile/computedEmbeddedCodes.d.ts +4 -0
- package/lib/virtualFile/computedEmbeddedCodes.js +262 -0
- package/lib/virtualFile/computedSfc.d.ts +6 -0
- package/lib/virtualFile/computedSfc.js +340 -0
- package/lib/virtualFile/computedVueSfc.d.ts +4 -0
- package/lib/virtualFile/computedVueSfc.js +41 -0
- package/lib/virtualFile/embeddedFile.d.ts +11 -0
- package/lib/virtualFile/embeddedFile.js +14 -0
- package/lib/virtualFile/vueFile.d.ts +24 -0
- package/lib/virtualFile/vueFile.js +49 -0
- package/package.json +2 -2
package/lib/languagePlugin.js
CHANGED
|
@@ -47,14 +47,14 @@ function createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFile
|
|
|
47
47
|
createVirtualCode(scriptId, languageId, snapshot) {
|
|
48
48
|
const fileName = asFileName(scriptId);
|
|
49
49
|
if (plugins.some(plugin => plugin.isValidFile?.(fileName, languageId))) {
|
|
50
|
-
const code = fileRegistry.get(
|
|
50
|
+
const code = fileRegistry.get(String(scriptId));
|
|
51
51
|
if (code) {
|
|
52
52
|
code.update(snapshot);
|
|
53
53
|
return code;
|
|
54
54
|
}
|
|
55
55
|
else {
|
|
56
56
|
const code = new virtualCode_1.VueVirtualCode(fileName, languageId, snapshot, vueCompilerOptions, plugins, ts);
|
|
57
|
-
fileRegistry.set(
|
|
57
|
+
fileRegistry.set(String(scriptId), code);
|
|
58
58
|
return code;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
@@ -64,8 +64,7 @@ function createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFile
|
|
|
64
64
|
return code;
|
|
65
65
|
},
|
|
66
66
|
disposeVirtualCode(scriptId) {
|
|
67
|
-
|
|
68
|
-
fileRegistry.delete(fileName);
|
|
67
|
+
fileRegistry.delete(String(scriptId));
|
|
69
68
|
},
|
|
70
69
|
typescript: {
|
|
71
70
|
extraFileExtensions: getAllExtensions(vueCompilerOptions)
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import type * as ts from 'typescript';
|
|
2
|
-
import type { TextRange } from '../types';
|
|
2
|
+
import type { TextRange, VueCompilerOptions } from '../types';
|
|
3
3
|
export interface ScriptRanges extends ReturnType<typeof parseScriptRanges> {
|
|
4
4
|
}
|
|
5
|
-
export declare function parseScriptRanges(ts: typeof import('typescript'), ast: ts.SourceFile,
|
|
5
|
+
export declare function parseScriptRanges(ts: typeof import('typescript'), ast: ts.SourceFile, vueCompilerOptions: VueCompilerOptions): {
|
|
6
6
|
exportDefault: (TextRange & {
|
|
7
7
|
expression: TextRange;
|
|
8
|
+
isObjectLiteral: boolean;
|
|
8
9
|
}) | undefined;
|
|
9
10
|
componentOptions: {
|
|
11
|
+
isObjectLiteral: boolean;
|
|
10
12
|
expression: TextRange;
|
|
11
13
|
args: TextRange;
|
|
12
14
|
argsNode: ts.ObjectLiteralExpression;
|
|
@@ -16,10 +18,6 @@ export declare function parseScriptRanges(ts: typeof import('typescript'), ast:
|
|
|
16
18
|
name: TextRange | undefined;
|
|
17
19
|
inheritAttrs: string | undefined;
|
|
18
20
|
} | undefined;
|
|
19
|
-
bindings:
|
|
20
|
-
|
|
21
|
-
moduleName?: string;
|
|
22
|
-
isDefaultImport?: boolean;
|
|
23
|
-
isNamespace?: boolean;
|
|
24
|
-
}[];
|
|
21
|
+
bindings: TextRange[];
|
|
22
|
+
components: TextRange[];
|
|
25
23
|
};
|
|
@@ -3,15 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.parseScriptRanges = parseScriptRanges;
|
|
4
4
|
const shared_1 = require("../utils/shared");
|
|
5
5
|
const utils_1 = require("./utils");
|
|
6
|
-
function parseScriptRanges(ts, ast,
|
|
6
|
+
function parseScriptRanges(ts, ast, vueCompilerOptions) {
|
|
7
7
|
let exportDefault;
|
|
8
8
|
let componentOptions;
|
|
9
|
-
const bindings
|
|
9
|
+
const { bindings, components } = (0, utils_1.parseBindingRanges)(ts, ast, vueCompilerOptions.extensions);
|
|
10
10
|
ts.forEachChild(ast, raw => {
|
|
11
11
|
if (ts.isExportAssignment(raw)) {
|
|
12
12
|
exportDefault = {
|
|
13
13
|
..._getStartEnd(raw),
|
|
14
14
|
expression: _getStartEnd(raw.expression),
|
|
15
|
+
isObjectLiteral: ts.isObjectLiteralExpression(raw.expression),
|
|
15
16
|
};
|
|
16
17
|
const comment = (0, utils_1.getClosestMultiLineCommentRange)(ts, raw, [], ast);
|
|
17
18
|
if (comment) {
|
|
@@ -54,6 +55,7 @@ function parseScriptRanges(ts, ast, hasScriptSetup) {
|
|
|
54
55
|
}
|
|
55
56
|
});
|
|
56
57
|
componentOptions = {
|
|
58
|
+
isObjectLiteral: ts.isObjectLiteralExpression(node.expression),
|
|
57
59
|
expression: _getStartEnd(node.expression),
|
|
58
60
|
args: _getStartEnd(obj),
|
|
59
61
|
argsNode: obj,
|
|
@@ -70,6 +72,7 @@ function parseScriptRanges(ts, ast, hasScriptSetup) {
|
|
|
70
72
|
exportDefault,
|
|
71
73
|
componentOptions,
|
|
72
74
|
bindings,
|
|
75
|
+
components,
|
|
73
76
|
};
|
|
74
77
|
function _getStartEnd(node) {
|
|
75
78
|
return (0, shared_1.getStartEnd)(ts, node, ast);
|
|
@@ -48,12 +48,8 @@ export interface ScriptSetupRanges extends ReturnType<typeof parseScriptSetupRan
|
|
|
48
48
|
export declare function parseScriptSetupRanges(ts: typeof import('typescript'), ast: ts.SourceFile, vueCompilerOptions: VueCompilerOptions): {
|
|
49
49
|
leadingCommentEndOffset: number;
|
|
50
50
|
importSectionEndOffset: number;
|
|
51
|
-
bindings:
|
|
52
|
-
|
|
53
|
-
moduleName?: string;
|
|
54
|
-
isDefaultImport?: boolean;
|
|
55
|
-
isNamespace?: boolean;
|
|
56
|
-
}[];
|
|
51
|
+
bindings: TextRange[];
|
|
52
|
+
components: TextRange[];
|
|
57
53
|
defineModel: DefineModel[];
|
|
58
54
|
defineProps: DefineProps | undefined;
|
|
59
55
|
withDefaults: WithDefaults | undefined;
|
|
@@ -20,7 +20,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
20
20
|
const text = ast.text;
|
|
21
21
|
const leadingCommentRanges = ts.getLeadingCommentRanges(text, 0)?.reverse() ?? [];
|
|
22
22
|
const leadingCommentEndOffset = leadingCommentRanges.find(range => tsCheckReg.test(text.slice(range.pos, range.end)))?.end ?? 0;
|
|
23
|
-
let bindings = (0, utils_1.parseBindingRanges)(ts, ast);
|
|
23
|
+
let { bindings, components } = (0, utils_1.parseBindingRanges)(ts, ast, vueCompilerOptions.extensions);
|
|
24
24
|
let foundNonImportExportNode = false;
|
|
25
25
|
let importSectionEndOffset = 0;
|
|
26
26
|
ts.forEachChild(ast, node => {
|
|
@@ -48,7 +48,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
48
48
|
});
|
|
49
49
|
ts.forEachChild(ast, node => visitNode(node, [ast]));
|
|
50
50
|
const templateRefNames = new Set(useTemplateRef.map(ref => ref.name));
|
|
51
|
-
bindings = bindings.filter(
|
|
51
|
+
bindings = bindings.filter(range => {
|
|
52
52
|
const name = text.slice(range.start, range.end);
|
|
53
53
|
return !templateRefNames.has(name);
|
|
54
54
|
});
|
|
@@ -56,6 +56,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
56
56
|
leadingCommentEndOffset,
|
|
57
57
|
importSectionEndOffset,
|
|
58
58
|
bindings,
|
|
59
|
+
components,
|
|
59
60
|
defineModel,
|
|
60
61
|
defineProps,
|
|
61
62
|
withDefaults,
|
package/lib/parsers/utils.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import type * as ts from 'typescript';
|
|
2
2
|
import type { TextRange } from '../types';
|
|
3
|
-
export declare function parseBindingRanges(ts: typeof import('typescript'), ast: ts.SourceFile): {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
isNamespace?: boolean;
|
|
8
|
-
}[];
|
|
3
|
+
export declare function parseBindingRanges(ts: typeof import('typescript'), ast: ts.SourceFile, componentExtsensions: string[]): {
|
|
4
|
+
bindings: TextRange[];
|
|
5
|
+
components: TextRange[];
|
|
6
|
+
};
|
|
9
7
|
export declare function getClosestMultiLineCommentRange(ts: typeof import('typescript'), node: ts.Node, parents: ts.Node[], ast: ts.SourceFile): {
|
|
10
8
|
start: number;
|
|
11
9
|
end: number;
|
package/lib/parsers/utils.js
CHANGED
|
@@ -4,44 +4,40 @@ exports.parseBindingRanges = parseBindingRanges;
|
|
|
4
4
|
exports.getClosestMultiLineCommentRange = getClosestMultiLineCommentRange;
|
|
5
5
|
const collectBindings_1 = require("../utils/collectBindings");
|
|
6
6
|
const shared_1 = require("../utils/shared");
|
|
7
|
-
function parseBindingRanges(ts, ast) {
|
|
7
|
+
function parseBindingRanges(ts, ast, componentExtsensions) {
|
|
8
8
|
const bindings = [];
|
|
9
|
+
const components = [];
|
|
9
10
|
ts.forEachChild(ast, node => {
|
|
10
11
|
if (ts.isVariableStatement(node)) {
|
|
11
12
|
for (const decl of node.declarationList.declarations) {
|
|
12
13
|
const ranges = (0, collectBindings_1.collectBindingRanges)(ts, decl.name, ast);
|
|
13
|
-
bindings.push(...ranges
|
|
14
|
+
bindings.push(...ranges);
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
17
|
else if (ts.isFunctionDeclaration(node)) {
|
|
17
18
|
if (node.name && ts.isIdentifier(node.name)) {
|
|
18
|
-
bindings.push(
|
|
19
|
-
range: _getStartEnd(node.name),
|
|
20
|
-
});
|
|
19
|
+
bindings.push(_getStartEnd(node.name));
|
|
21
20
|
}
|
|
22
21
|
}
|
|
23
22
|
else if (ts.isClassDeclaration(node)) {
|
|
24
23
|
if (node.name) {
|
|
25
|
-
bindings.push(
|
|
26
|
-
range: _getStartEnd(node.name),
|
|
27
|
-
});
|
|
24
|
+
bindings.push(_getStartEnd(node.name));
|
|
28
25
|
}
|
|
29
26
|
}
|
|
30
27
|
else if (ts.isEnumDeclaration(node)) {
|
|
31
|
-
bindings.push(
|
|
32
|
-
range: _getStartEnd(node.name),
|
|
33
|
-
});
|
|
28
|
+
bindings.push(_getStartEnd(node.name));
|
|
34
29
|
}
|
|
35
30
|
if (ts.isImportDeclaration(node)) {
|
|
36
31
|
const moduleName = _getNodeText(node.moduleSpecifier).slice(1, -1);
|
|
37
32
|
if (node.importClause && !node.importClause.isTypeOnly) {
|
|
38
33
|
const { name, namedBindings } = node.importClause;
|
|
39
34
|
if (name) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
if (componentExtsensions.some(ext => moduleName.endsWith(ext))) {
|
|
36
|
+
components.push(_getStartEnd(name));
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
bindings.push(_getStartEnd(name));
|
|
40
|
+
}
|
|
45
41
|
}
|
|
46
42
|
if (namedBindings) {
|
|
47
43
|
if (ts.isNamedImports(namedBindings)) {
|
|
@@ -49,25 +45,27 @@ function parseBindingRanges(ts, ast) {
|
|
|
49
45
|
if (element.isTypeOnly) {
|
|
50
46
|
continue;
|
|
51
47
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
moduleName
|
|
55
|
-
|
|
56
|
-
}
|
|
48
|
+
if (element.propertyName
|
|
49
|
+
&& _getNodeText(element.propertyName) === 'default'
|
|
50
|
+
&& componentExtsensions.some(ext => moduleName.endsWith(ext))) {
|
|
51
|
+
components.push(_getStartEnd(element.name));
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
bindings.push(_getStartEnd(element.name));
|
|
55
|
+
}
|
|
57
56
|
}
|
|
58
57
|
}
|
|
59
58
|
else {
|
|
60
|
-
bindings.push(
|
|
61
|
-
range: _getStartEnd(namedBindings.name),
|
|
62
|
-
moduleName,
|
|
63
|
-
isNamespace: true,
|
|
64
|
-
});
|
|
59
|
+
bindings.push(_getStartEnd(namedBindings.name));
|
|
65
60
|
}
|
|
66
61
|
}
|
|
67
62
|
}
|
|
68
63
|
}
|
|
69
64
|
});
|
|
70
|
-
return
|
|
65
|
+
return {
|
|
66
|
+
bindings,
|
|
67
|
+
components,
|
|
68
|
+
};
|
|
71
69
|
function _getStartEnd(node) {
|
|
72
70
|
return (0, shared_1.getStartEnd)(ts, node, ast);
|
|
73
71
|
}
|
|
@@ -6,7 +6,7 @@ const plugin = ({ modules }) => {
|
|
|
6
6
|
compileSFCScript(lang, script) {
|
|
7
7
|
if (lang === 'js' || lang === 'ts' || lang === 'jsx' || lang === 'tsx') {
|
|
8
8
|
const ts = modules.typescript;
|
|
9
|
-
return ts.createSourceFile('
|
|
9
|
+
return ts.createSourceFile('.' + lang, script, 99);
|
|
10
10
|
}
|
|
11
11
|
},
|
|
12
12
|
};
|
package/lib/plugins/vue-tsx.d.ts
CHANGED
|
@@ -3,8 +3,10 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
3
3
|
getScriptRanges: () => {
|
|
4
4
|
exportDefault: (import("../types").TextRange & {
|
|
5
5
|
expression: import("../types").TextRange;
|
|
6
|
+
isObjectLiteral: boolean;
|
|
6
7
|
}) | undefined;
|
|
7
8
|
componentOptions: {
|
|
9
|
+
isObjectLiteral: boolean;
|
|
8
10
|
expression: import("../types").TextRange;
|
|
9
11
|
args: import("../types").TextRange;
|
|
10
12
|
argsNode: import("typescript").ObjectLiteralExpression;
|
|
@@ -14,22 +16,14 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
14
16
|
name: import("../types").TextRange | undefined;
|
|
15
17
|
inheritAttrs: string | undefined;
|
|
16
18
|
} | undefined;
|
|
17
|
-
bindings:
|
|
18
|
-
|
|
19
|
-
moduleName?: string;
|
|
20
|
-
isDefaultImport?: boolean;
|
|
21
|
-
isNamespace?: boolean;
|
|
22
|
-
}[];
|
|
19
|
+
bindings: import("../types").TextRange[];
|
|
20
|
+
components: import("../types").TextRange[];
|
|
23
21
|
} | undefined;
|
|
24
22
|
getScriptSetupRanges: () => {
|
|
25
23
|
leadingCommentEndOffset: number;
|
|
26
24
|
importSectionEndOffset: number;
|
|
27
|
-
bindings:
|
|
28
|
-
|
|
29
|
-
moduleName?: string;
|
|
30
|
-
isDefaultImport?: boolean;
|
|
31
|
-
isNamespace?: boolean;
|
|
32
|
-
}[];
|
|
25
|
+
bindings: import("../types").TextRange[];
|
|
26
|
+
components: import("../types").TextRange[];
|
|
33
27
|
defineModel: {
|
|
34
28
|
localName?: import("../types").TextRange;
|
|
35
29
|
name?: import("../types").TextRange;
|
|
@@ -168,15 +162,12 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
168
162
|
typeExp: string;
|
|
169
163
|
offset: number;
|
|
170
164
|
}[]>;
|
|
171
|
-
currentComponent: {
|
|
172
|
-
get ctxVar(): string;
|
|
173
|
-
get propsVar(): string;
|
|
174
|
-
} | undefined;
|
|
175
165
|
singleRootElTypes: Set<string>;
|
|
176
166
|
singleRootNodes: Set<import("@vue/compiler-dom").ElementNode | null>;
|
|
177
167
|
addTemplateRef(name: string, typeExp: string, offset: number): void;
|
|
178
168
|
recordComponentAccess(source: string, name: string, offset?: number): void;
|
|
179
169
|
scopes: Set<string>[];
|
|
170
|
+
components: (() => string)[];
|
|
180
171
|
declare(...varNames: string[]): void;
|
|
181
172
|
startScope(): () => Generator<import("../types").Code, any, any>;
|
|
182
173
|
getInternalVariable(): string;
|
|
@@ -188,7 +179,6 @@ export declare const tsCodegen: WeakMap<Sfc, {
|
|
|
188
179
|
} | undefined;
|
|
189
180
|
getImportComponentNames: () => Set<string>;
|
|
190
181
|
getSetupExposed: () => Set<string>;
|
|
191
|
-
getSetupConsts: () => Set<string>;
|
|
192
182
|
}>;
|
|
193
183
|
declare const plugin: VueLanguagePlugin;
|
|
194
184
|
export default plugin;
|
package/lib/plugins/vue-tsx.js
CHANGED
|
@@ -61,7 +61,7 @@ function useCodegen(fileName, sfc, ctx) {
|
|
|
61
61
|
return ctx.vueCompilerOptions;
|
|
62
62
|
});
|
|
63
63
|
const getScriptRanges = (0, alien_signals_1.computed)(() => sfc.script && validLangs.has(sfc.script.lang)
|
|
64
|
-
? (0, scriptRanges_1.parseScriptRanges)(ts, sfc.script.ast,
|
|
64
|
+
? (0, scriptRanges_1.parseScriptRanges)(ts, sfc.script.ast, getResolvedOptions())
|
|
65
65
|
: undefined);
|
|
66
66
|
const getScriptSetupRanges = (0, alien_signals_1.computed)(() => sfc.scriptSetup && validLangs.has(sfc.scriptSetup.lang)
|
|
67
67
|
? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, sfc.scriptSetup.ast, getResolvedOptions())
|
|
@@ -70,23 +70,13 @@ function useCodegen(fileName, sfc, ctx) {
|
|
|
70
70
|
const names = new Set();
|
|
71
71
|
const scriptSetupRanges = getScriptSetupRanges();
|
|
72
72
|
if (sfc.scriptSetup && scriptSetupRanges) {
|
|
73
|
-
for (const
|
|
74
|
-
|
|
75
|
-
&& isDefaultImport
|
|
76
|
-
&& !isNamespace
|
|
77
|
-
&& ctx.vueCompilerOptions.extensions.some(ext => moduleName.endsWith(ext))) {
|
|
78
|
-
names.add(sfc.scriptSetup.content.slice(range.start, range.end));
|
|
79
|
-
}
|
|
73
|
+
for (const range of scriptSetupRanges.components) {
|
|
74
|
+
names.add(sfc.scriptSetup.content.slice(range.start, range.end));
|
|
80
75
|
}
|
|
81
76
|
const scriptRange = getScriptRanges();
|
|
82
77
|
if (sfc.script && scriptRange) {
|
|
83
|
-
for (const
|
|
84
|
-
|
|
85
|
-
&& isDefaultImport
|
|
86
|
-
&& !isNamespace
|
|
87
|
-
&& ctx.vueCompilerOptions.extensions.some(ext => moduleName.endsWith(ext))) {
|
|
88
|
-
names.add(sfc.script.content.slice(range.start, range.end));
|
|
89
|
-
}
|
|
78
|
+
for (const range of scriptRange.components) {
|
|
79
|
+
names.add(sfc.script.content.slice(range.start, range.end));
|
|
90
80
|
}
|
|
91
81
|
}
|
|
92
82
|
}
|
|
@@ -176,13 +166,13 @@ function useCodegen(fileName, sfc, ctx) {
|
|
|
176
166
|
if (!sfc.scriptSetup || !scriptSetupRanges) {
|
|
177
167
|
return allVars;
|
|
178
168
|
}
|
|
179
|
-
for (const
|
|
169
|
+
for (const range of scriptSetupRanges.bindings) {
|
|
180
170
|
const name = sfc.scriptSetup.content.slice(range.start, range.end);
|
|
181
171
|
allVars.add(name);
|
|
182
172
|
}
|
|
183
173
|
const scriptRanges = getScriptRanges();
|
|
184
174
|
if (sfc.script && scriptRanges) {
|
|
185
|
-
for (const
|
|
175
|
+
for (const range of scriptRanges.bindings) {
|
|
186
176
|
const name = sfc.script.content.slice(range.start, range.end);
|
|
187
177
|
allVars.add(name);
|
|
188
178
|
}
|
|
@@ -236,7 +226,6 @@ function useCodegen(fileName, sfc, ctx) {
|
|
|
236
226
|
getGeneratedTemplate,
|
|
237
227
|
getImportComponentNames,
|
|
238
228
|
getSetupExposed,
|
|
239
|
-
getSetupConsts,
|
|
240
229
|
};
|
|
241
230
|
}
|
|
242
231
|
//# sourceMappingURL=vue-tsx.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { VirtualCode } from '@volar/language-core';
|
|
2
|
+
import type { Sfc, VueLanguagePluginReturn } from '../types';
|
|
3
|
+
export declare function computedEmbeddedCodes(plugins: VueLanguagePluginReturn[], fileName: string, sfc: Sfc): () => VirtualCode[];
|
|
4
|
+
export declare function resolveCommonLanguageId(lang: string): string;
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computedEmbeddedCodes = computedEmbeddedCodes;
|
|
4
|
+
exports.resolveCommonLanguageId = resolveCommonLanguageId;
|
|
5
|
+
const alien_signals_1 = require("alien-signals");
|
|
6
|
+
const muggle_string_1 = require("muggle-string");
|
|
7
|
+
const buildMappings_1 = require("../utils/buildMappings");
|
|
8
|
+
const embeddedFile_1 = require("./embeddedFile");
|
|
9
|
+
function computedEmbeddedCodes(plugins, fileName, sfc) {
|
|
10
|
+
const getNameToBlockMap = (0, alien_signals_1.computed)(() => {
|
|
11
|
+
const blocks = {};
|
|
12
|
+
if (sfc.template) {
|
|
13
|
+
blocks[sfc.template.name] = sfc.template;
|
|
14
|
+
}
|
|
15
|
+
if (sfc.script) {
|
|
16
|
+
blocks[sfc.script.name] = sfc.script;
|
|
17
|
+
}
|
|
18
|
+
if (sfc.scriptSetup) {
|
|
19
|
+
blocks[sfc.scriptSetup.name] = sfc.scriptSetup;
|
|
20
|
+
}
|
|
21
|
+
for (const block of sfc.styles) {
|
|
22
|
+
blocks[block.name] = block;
|
|
23
|
+
}
|
|
24
|
+
for (const block of sfc.customBlocks) {
|
|
25
|
+
blocks[block.name] = block;
|
|
26
|
+
}
|
|
27
|
+
return blocks;
|
|
28
|
+
});
|
|
29
|
+
const getPluginsResult = plugins.map(plugin => computedPluginEmbeddedCodes(plugins, plugin, fileName, sfc, name => getNameToBlockMap()[name]));
|
|
30
|
+
const getFlatResult = (0, alien_signals_1.computed)(() => getPluginsResult.map(r => r()).flat());
|
|
31
|
+
const getStructuredResult = (0, alien_signals_1.computed)(() => {
|
|
32
|
+
const embeddedCodes = [];
|
|
33
|
+
let remain = [...getFlatResult()];
|
|
34
|
+
while (remain.length) {
|
|
35
|
+
const beforeLength = remain.length;
|
|
36
|
+
consumeRemain();
|
|
37
|
+
if (beforeLength === remain.length) {
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
for (const { code } of remain) {
|
|
42
|
+
console.error('Unable to resolve embedded: ' + code.parentCodeId + ' -> ' + code.id);
|
|
43
|
+
}
|
|
44
|
+
return embeddedCodes;
|
|
45
|
+
function consumeRemain() {
|
|
46
|
+
for (let i = remain.length - 1; i >= 0; i--) {
|
|
47
|
+
const { code, snapshot, mappings } = remain[i];
|
|
48
|
+
if (!code.parentCodeId) {
|
|
49
|
+
embeddedCodes.push({
|
|
50
|
+
id: code.id,
|
|
51
|
+
languageId: resolveCommonLanguageId(code.lang),
|
|
52
|
+
linkedCodeMappings: code.linkedCodeMappings,
|
|
53
|
+
snapshot,
|
|
54
|
+
mappings,
|
|
55
|
+
embeddedCodes: [],
|
|
56
|
+
});
|
|
57
|
+
remain.splice(i, 1);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
const parent = findParentStructure(code.parentCodeId, embeddedCodes);
|
|
61
|
+
if (parent) {
|
|
62
|
+
parent.embeddedCodes ??= [];
|
|
63
|
+
parent.embeddedCodes.push({
|
|
64
|
+
id: code.id,
|
|
65
|
+
languageId: resolveCommonLanguageId(code.lang),
|
|
66
|
+
linkedCodeMappings: code.linkedCodeMappings,
|
|
67
|
+
snapshot,
|
|
68
|
+
mappings,
|
|
69
|
+
embeddedCodes: [],
|
|
70
|
+
});
|
|
71
|
+
remain.splice(i, 1);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function findParentStructure(id, current) {
|
|
77
|
+
for (const child of current) {
|
|
78
|
+
if (child.id === id) {
|
|
79
|
+
return child;
|
|
80
|
+
}
|
|
81
|
+
let parent = findParentStructure(id, child.embeddedCodes ?? []);
|
|
82
|
+
if (parent) {
|
|
83
|
+
return parent;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
return getStructuredResult;
|
|
89
|
+
}
|
|
90
|
+
function computedPluginEmbeddedCodes(plugins, plugin, fileName, sfc, getBlockByName) {
|
|
91
|
+
const computeds = new Map();
|
|
92
|
+
const getComputedKey = (code) => code.id + '__' + code.lang;
|
|
93
|
+
const getCodes = (0, alien_signals_1.computed)(() => {
|
|
94
|
+
try {
|
|
95
|
+
if (!plugin.getEmbeddedCodes) {
|
|
96
|
+
return [...computeds.values()];
|
|
97
|
+
}
|
|
98
|
+
const embeddedCodeInfos = plugin.getEmbeddedCodes(fileName, sfc);
|
|
99
|
+
for (const oldId of computeds.keys()) {
|
|
100
|
+
if (!embeddedCodeInfos.some(code => getComputedKey(code) === oldId)) {
|
|
101
|
+
computeds.delete(oldId);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
for (const codeInfo of embeddedCodeInfos) {
|
|
105
|
+
if (!computeds.has(getComputedKey(codeInfo))) {
|
|
106
|
+
computeds.set(getComputedKey(codeInfo), (0, alien_signals_1.computed)(() => {
|
|
107
|
+
const content = [];
|
|
108
|
+
const code = new embeddedFile_1.VueEmbeddedCode(codeInfo.id, codeInfo.lang, content);
|
|
109
|
+
for (const plugin of plugins) {
|
|
110
|
+
if (!plugin.resolveEmbeddedCode) {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
plugin.resolveEmbeddedCode(fileName, sfc, code);
|
|
115
|
+
}
|
|
116
|
+
catch (e) {
|
|
117
|
+
console.error(e);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const newText = (0, muggle_string_1.toString)(code.content);
|
|
121
|
+
const changeRanges = new Map();
|
|
122
|
+
const snapshot = {
|
|
123
|
+
getText: (start, end) => newText.slice(start, end),
|
|
124
|
+
getLength: () => newText.length,
|
|
125
|
+
getChangeRange(oldSnapshot) {
|
|
126
|
+
if (!changeRanges.has(oldSnapshot)) {
|
|
127
|
+
changeRanges.set(oldSnapshot, undefined);
|
|
128
|
+
const oldText = oldSnapshot.getText(0, oldSnapshot.getLength());
|
|
129
|
+
const changeRange = fullDiffTextChangeRange(oldText, newText);
|
|
130
|
+
if (changeRange) {
|
|
131
|
+
changeRanges.set(oldSnapshot, changeRange);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return changeRanges.get(oldSnapshot);
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
return {
|
|
138
|
+
code,
|
|
139
|
+
snapshot,
|
|
140
|
+
};
|
|
141
|
+
}));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
catch (e) {
|
|
146
|
+
console.error(e);
|
|
147
|
+
}
|
|
148
|
+
return [...computeds.values()];
|
|
149
|
+
});
|
|
150
|
+
return (0, alien_signals_1.computed)(() => {
|
|
151
|
+
return getCodes().map(_file => {
|
|
152
|
+
const { code, snapshot } = _file();
|
|
153
|
+
const mappings = (0, buildMappings_1.buildMappings)(code.content.map(segment => {
|
|
154
|
+
if (typeof segment === 'string') {
|
|
155
|
+
return segment;
|
|
156
|
+
}
|
|
157
|
+
const source = segment[1];
|
|
158
|
+
if (source === undefined) {
|
|
159
|
+
return segment;
|
|
160
|
+
}
|
|
161
|
+
const block = getBlockByName(source);
|
|
162
|
+
if (!block) {
|
|
163
|
+
// console.warn('Unable to find block: ' + source);
|
|
164
|
+
return segment;
|
|
165
|
+
}
|
|
166
|
+
return [
|
|
167
|
+
segment[0],
|
|
168
|
+
undefined,
|
|
169
|
+
segment[2] + block.startTagEnd,
|
|
170
|
+
segment[3],
|
|
171
|
+
];
|
|
172
|
+
}));
|
|
173
|
+
const newMappings = [];
|
|
174
|
+
const tokenMappings = new Map();
|
|
175
|
+
for (let i = 0; i < mappings.length; i++) {
|
|
176
|
+
const mapping = mappings[i];
|
|
177
|
+
if (mapping.data.__combineOffset !== undefined) {
|
|
178
|
+
const offsetMapping = mappings[i - mapping.data.__combineOffset];
|
|
179
|
+
if (typeof offsetMapping === 'string' || !offsetMapping) {
|
|
180
|
+
throw new Error('Invalid offset mapping, mappings: ' + mappings.length + ', i: ' + i + ', offset: '
|
|
181
|
+
+ mapping.data.__combineOffset);
|
|
182
|
+
}
|
|
183
|
+
offsetMapping.sourceOffsets.push(...mapping.sourceOffsets);
|
|
184
|
+
offsetMapping.generatedOffsets.push(...mapping.generatedOffsets);
|
|
185
|
+
offsetMapping.lengths.push(...mapping.lengths);
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if (mapping.data.__linkedToken !== undefined) {
|
|
189
|
+
const token = mapping.data.__linkedToken;
|
|
190
|
+
if (tokenMappings.has(token)) {
|
|
191
|
+
const prevMapping = tokenMappings.get(token);
|
|
192
|
+
code.linkedCodeMappings.push({
|
|
193
|
+
sourceOffsets: [prevMapping.generatedOffsets[0]],
|
|
194
|
+
generatedOffsets: [mapping.generatedOffsets[0]],
|
|
195
|
+
lengths: [Number(token.description)],
|
|
196
|
+
data: undefined,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
tokenMappings.set(token, mapping);
|
|
201
|
+
}
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
newMappings.push(mapping);
|
|
205
|
+
}
|
|
206
|
+
return {
|
|
207
|
+
code,
|
|
208
|
+
snapshot,
|
|
209
|
+
mappings: newMappings,
|
|
210
|
+
};
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
function fullDiffTextChangeRange(oldText, newText) {
|
|
215
|
+
for (let start = 0; start < oldText.length && start < newText.length; start++) {
|
|
216
|
+
if (oldText[start] !== newText[start]) {
|
|
217
|
+
let end = oldText.length;
|
|
218
|
+
for (let i = 0; i < oldText.length - start && i < newText.length - start; i++) {
|
|
219
|
+
if (oldText[oldText.length - i - 1] !== newText[newText.length - i - 1]) {
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
end--;
|
|
223
|
+
}
|
|
224
|
+
let length = end - start;
|
|
225
|
+
let newLength = length + (newText.length - oldText.length);
|
|
226
|
+
if (newLength < 0) {
|
|
227
|
+
length -= newLength;
|
|
228
|
+
newLength = 0;
|
|
229
|
+
}
|
|
230
|
+
return {
|
|
231
|
+
span: { start, length },
|
|
232
|
+
newLength,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function resolveCommonLanguageId(lang) {
|
|
238
|
+
switch (lang) {
|
|
239
|
+
case 'js':
|
|
240
|
+
return 'javascript';
|
|
241
|
+
case 'cjs':
|
|
242
|
+
return 'javascript';
|
|
243
|
+
case 'mjs':
|
|
244
|
+
return 'javascript';
|
|
245
|
+
case 'ts':
|
|
246
|
+
return 'typescript';
|
|
247
|
+
case 'cts':
|
|
248
|
+
return 'typescript';
|
|
249
|
+
case 'mts':
|
|
250
|
+
return 'typescript';
|
|
251
|
+
case 'jsx':
|
|
252
|
+
return 'javascriptreact';
|
|
253
|
+
case 'tsx':
|
|
254
|
+
return 'typescriptreact';
|
|
255
|
+
case 'pug':
|
|
256
|
+
return 'jade';
|
|
257
|
+
case 'md':
|
|
258
|
+
return 'markdown';
|
|
259
|
+
}
|
|
260
|
+
return lang;
|
|
261
|
+
}
|
|
262
|
+
//# sourceMappingURL=computedEmbeddedCodes.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as CompilerDOM from '@vue/compiler-dom';
|
|
2
|
+
import type { SFCParseResult } from '@vue/compiler-sfc';
|
|
3
|
+
import type * as ts from 'typescript';
|
|
4
|
+
import type { Sfc, VueLanguagePluginReturn } from '../types';
|
|
5
|
+
export declare const templateInlineTsAsts: WeakMap<CompilerDOM.RootNode, Map<string, ts.SourceFile>>;
|
|
6
|
+
export declare function computedSfc(ts: typeof import('typescript'), plugins: VueLanguagePluginReturn[], fileName: string, getSnapshot: () => ts.IScriptSnapshot, getParseResult: () => SFCParseResult | undefined): Sfc;
|