@vue/language-core 2.2.10 → 3.0.0-alpha.10
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 -2
- package/index.js +1 -1
- package/lib/codegen/codeFeatures.d.ts +5 -0
- package/lib/codegen/codeFeatures.js +5 -0
- package/lib/codegen/globalTypes.js +44 -31
- package/lib/codegen/localTypes.d.ts +2 -3
- package/lib/codegen/localTypes.js +5 -15
- package/lib/codegen/script/component.js +21 -9
- package/lib/codegen/script/context.d.ts +1 -1
- package/lib/codegen/script/context.js +1 -1
- package/lib/codegen/script/index.d.ts +1 -2
- package/lib/codegen/script/index.js +2 -18
- package/lib/codegen/script/scriptSetup.js +5 -16
- package/lib/codegen/script/src.js +4 -22
- package/lib/codegen/script/template.js +7 -6
- package/lib/codegen/template/context.d.ts +29 -19
- package/lib/codegen/template/context.js +87 -56
- package/lib/codegen/template/element.d.ts +2 -2
- package/lib/codegen/template/element.js +34 -63
- package/lib/codegen/template/elementChildren.d.ts +2 -2
- package/lib/codegen/template/elementChildren.js +4 -6
- package/lib/codegen/template/elementDirectives.js +3 -15
- package/lib/codegen/template/elementEvents.d.ts +4 -3
- package/lib/codegen/template/elementEvents.js +61 -29
- package/lib/codegen/template/elementProps.d.ts +2 -2
- package/lib/codegen/template/elementProps.js +11 -22
- package/lib/codegen/template/index.d.ts +1 -2
- package/lib/codegen/template/index.js +22 -11
- package/lib/codegen/template/interpolation.d.ts +1 -1
- package/lib/codegen/template/interpolation.js +53 -51
- package/lib/codegen/template/slotOutlet.js +2 -3
- package/lib/codegen/template/styleScopedClasses.js +2 -2
- package/lib/codegen/template/templateChild.d.ts +1 -1
- package/lib/codegen/template/templateChild.js +12 -46
- package/lib/codegen/template/vFor.js +5 -10
- package/lib/codegen/template/vIf.js +2 -10
- package/lib/codegen/template/vSlot.d.ts +1 -2
- package/lib/codegen/template/vSlot.js +111 -59
- package/lib/codegen/utils/index.d.ts +2 -3
- package/lib/codegen/utils/index.js +2 -18
- package/lib/languagePlugin.d.ts +1 -1
- package/lib/languagePlugin.js +1 -7
- package/lib/parsers/scriptRanges.d.ts +2 -3
- package/lib/parsers/scriptRanges.js +10 -13
- package/lib/parsers/scriptSetupRanges.d.ts +0 -3
- package/lib/parsers/scriptSetupRanges.js +36 -43
- package/lib/plugins/file-md.js +3 -0
- package/lib/plugins/vue-style-css.d.ts +3 -0
- package/lib/plugins/vue-style-css.js +18 -0
- package/lib/plugins/vue-template-inline-css.js +1 -1
- package/lib/plugins/vue-template-inline-ts.js +5 -2
- package/lib/plugins/vue-tsx.d.ts +27 -18
- package/lib/plugins/vue-tsx.js +32 -24
- package/lib/plugins.d.ts +1 -1
- package/lib/types.d.ts +3 -2
- package/lib/utils/shared.d.ts +4 -1
- package/lib/utils/shared.js +12 -4
- package/lib/utils/signals.d.ts +1 -0
- package/lib/utils/signals.js +11 -0
- package/lib/utils/ts.d.ts +0 -4
- package/lib/utils/ts.js +4 -14
- package/lib/virtualFile/computedSfc.js +6 -6
- package/package.json +6 -8
- package/lib/utils/vue2TemplateCompiler.d.ts +0 -2
- package/lib/utils/vue2TemplateCompiler.js +0 -89
|
@@ -7,12 +7,12 @@ const CompilerDOM = require("@vue/compiler-dom");
|
|
|
7
7
|
const shared_1 = require("../../utils/shared");
|
|
8
8
|
const utils_1 = require("../utils");
|
|
9
9
|
const element_1 = require("./element");
|
|
10
|
+
const elementChildren_1 = require("./elementChildren");
|
|
10
11
|
const interpolation_1 = require("./interpolation");
|
|
11
12
|
const slotOutlet_1 = require("./slotOutlet");
|
|
12
13
|
const vFor_1 = require("./vFor");
|
|
13
14
|
const vIf_1 = require("./vIf");
|
|
14
15
|
const vSlot_1 = require("./vSlot");
|
|
15
|
-
const commentDirectiveRegex = /^<!--\s*@vue-(?<name>[-\w]+)\b(?<content>[\s\S]*)-->$/;
|
|
16
16
|
// @ts-ignore
|
|
17
17
|
const transformContext = {
|
|
18
18
|
onError: () => { },
|
|
@@ -28,36 +28,9 @@ const transformContext = {
|
|
|
28
28
|
},
|
|
29
29
|
expressionPlugins: ['typescript'],
|
|
30
30
|
};
|
|
31
|
-
function* generateTemplateChild(options, ctx, node,
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
if (match) {
|
|
35
|
-
const { name, content } = match.groups;
|
|
36
|
-
switch (name) {
|
|
37
|
-
case 'skip': {
|
|
38
|
-
yield `// @vue-skip${utils_1.newLine}`;
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
case 'ignore': {
|
|
42
|
-
yield* ctx.ignoreError();
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
|
-
case 'expect-error': {
|
|
46
|
-
yield* ctx.expectError(prevNode);
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
case 'generic': {
|
|
50
|
-
const text = content.trim();
|
|
51
|
-
if (text.startsWith('{') && text.endsWith('}')) {
|
|
52
|
-
ctx.lastGenericComment = {
|
|
53
|
-
content: text.slice(1, -1),
|
|
54
|
-
offset: prevNode.loc.start.offset + prevNode.loc.source.indexOf('{') + 1,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
31
|
+
function* generateTemplateChild(options, ctx, node, enterNode = true) {
|
|
32
|
+
if (enterNode && !ctx.enter(node)) {
|
|
33
|
+
return;
|
|
61
34
|
}
|
|
62
35
|
const cur = node;
|
|
63
36
|
if (cur.codegenNode?.type === CompilerDOM.NodeTypes.JS_CACHE_EXPRESSION) {
|
|
@@ -67,12 +40,7 @@ function* generateTemplateChild(options, ctx, node, prevNode, isVForChild = fals
|
|
|
67
40
|
for (const item of collectSingleRootNodes(options, node.children)) {
|
|
68
41
|
ctx.singleRootNodes.add(item);
|
|
69
42
|
}
|
|
70
|
-
|
|
71
|
-
for (const childNode of node.children) {
|
|
72
|
-
yield* generateTemplateChild(options, ctx, childNode, prev);
|
|
73
|
-
prev = childNode;
|
|
74
|
-
}
|
|
75
|
-
yield* ctx.resetDirectiveComments('end of root');
|
|
43
|
+
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node.children);
|
|
76
44
|
}
|
|
77
45
|
else if (node.type === CompilerDOM.NodeTypes.ELEMENT) {
|
|
78
46
|
const vForNode = getVForNode(node);
|
|
@@ -95,32 +63,27 @@ function* generateTemplateChild(options, ctx, node, prevNode, isVForChild = fals
|
|
|
95
63
|
}
|
|
96
64
|
else if (node.tagType === CompilerDOM.ElementTypes.ELEMENT
|
|
97
65
|
|| node.tagType === CompilerDOM.ElementTypes.TEMPLATE) {
|
|
98
|
-
yield* (0, element_1.generateElement)(options, ctx, node
|
|
66
|
+
yield* (0, element_1.generateElement)(options, ctx, node);
|
|
99
67
|
}
|
|
100
68
|
else {
|
|
101
69
|
const { currentComponent } = ctx;
|
|
102
|
-
yield* (0, element_1.generateComponent)(options, ctx, node
|
|
70
|
+
yield* (0, element_1.generateComponent)(options, ctx, node);
|
|
103
71
|
ctx.currentComponent = currentComponent;
|
|
104
72
|
}
|
|
105
73
|
}
|
|
106
74
|
}
|
|
107
75
|
else if (node.type === CompilerDOM.NodeTypes.TEXT_CALL) {
|
|
108
76
|
// {{ var }}
|
|
109
|
-
yield* generateTemplateChild(options, ctx, node.content,
|
|
77
|
+
yield* generateTemplateChild(options, ctx, node.content, false);
|
|
110
78
|
}
|
|
111
79
|
else if (node.type === CompilerDOM.NodeTypes.COMPOUND_EXPRESSION) {
|
|
112
80
|
// {{ ... }} {{ ... }}
|
|
113
|
-
|
|
114
|
-
if (typeof childNode === 'object') {
|
|
115
|
-
yield* generateTemplateChild(options, ctx, childNode, undefined);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
81
|
+
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node.children.filter(child => typeof child === 'object'), false);
|
|
118
82
|
}
|
|
119
83
|
else if (node.type === CompilerDOM.NodeTypes.INTERPOLATION) {
|
|
120
84
|
// {{ ... }}
|
|
121
85
|
const [content, start] = parseInterpolationNode(node, options.template.content);
|
|
122
86
|
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, content, start, node.content.loc, `(`, `)${utils_1.endOfLine}`);
|
|
123
|
-
yield* ctx.resetDirectiveComments('end of INTERPOLATION');
|
|
124
87
|
}
|
|
125
88
|
else if (node.type === CompilerDOM.NodeTypes.IF) {
|
|
126
89
|
// v-if / v-else-if / v-else
|
|
@@ -133,6 +96,9 @@ function* generateTemplateChild(options, ctx, node, prevNode, isVForChild = fals
|
|
|
133
96
|
else if (node.type === CompilerDOM.NodeTypes.TEXT) {
|
|
134
97
|
// not needed progress
|
|
135
98
|
}
|
|
99
|
+
if (enterNode) {
|
|
100
|
+
yield* ctx.exit();
|
|
101
|
+
}
|
|
136
102
|
}
|
|
137
103
|
function* collectSingleRootNodes(options, children) {
|
|
138
104
|
if (children.length !== 1) {
|
|
@@ -4,8 +4,8 @@ exports.generateVFor = generateVFor;
|
|
|
4
4
|
exports.parseVForNode = parseVForNode;
|
|
5
5
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
6
6
|
const utils_1 = require("../utils");
|
|
7
|
+
const elementChildren_1 = require("./elementChildren");
|
|
7
8
|
const interpolation_1 = require("./interpolation");
|
|
8
|
-
const templateChild_1 = require("./templateChild");
|
|
9
9
|
function* generateVFor(options, ctx, node) {
|
|
10
10
|
const { source } = node.parseResult;
|
|
11
11
|
const { leftExpressionRange, leftExpressionText } = parseVForNode(node);
|
|
@@ -52,18 +52,13 @@ function* generateVFor(options, ctx, node) {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
for (const childNode of node.children) {
|
|
60
|
-
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, prev, true);
|
|
61
|
-
prev = childNode;
|
|
62
|
-
}
|
|
55
|
+
const { inVFor } = ctx;
|
|
56
|
+
ctx.inVFor = true;
|
|
57
|
+
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node.children, isFragment);
|
|
58
|
+
ctx.inVFor = inVFor;
|
|
63
59
|
for (const varName of forBlockVars) {
|
|
64
60
|
ctx.removeLocalVariable(varName);
|
|
65
61
|
}
|
|
66
|
-
yield* ctx.generateAutoImportCompletion();
|
|
67
62
|
yield `}${utils_1.newLine}`;
|
|
68
63
|
}
|
|
69
64
|
function parseVForNode(node) {
|
|
@@ -4,8 +4,8 @@ exports.generateVIf = generateVIf;
|
|
|
4
4
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
5
5
|
const muggle_string_1 = require("muggle-string");
|
|
6
6
|
const utils_1 = require("../utils");
|
|
7
|
+
const elementChildren_1 = require("./elementChildren");
|
|
7
8
|
const interpolation_1 = require("./interpolation");
|
|
8
|
-
const templateChild_1 = require("./templateChild");
|
|
9
9
|
function* generateVIf(options, ctx, node) {
|
|
10
10
|
const originalBlockConditionsLength = ctx.blockConditions.length;
|
|
11
11
|
for (let i = 0; i < node.branches.length; i++) {
|
|
@@ -28,15 +28,7 @@ function* generateVIf(options, ctx, node) {
|
|
|
28
28
|
yield ` `;
|
|
29
29
|
}
|
|
30
30
|
yield `{${utils_1.newLine}`;
|
|
31
|
-
|
|
32
|
-
yield* ctx.resetDirectiveComments('end of v-if start');
|
|
33
|
-
}
|
|
34
|
-
let prev;
|
|
35
|
-
for (const childNode of branch.children) {
|
|
36
|
-
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, prev);
|
|
37
|
-
prev = childNode;
|
|
38
|
-
}
|
|
39
|
-
yield* ctx.generateAutoImportCompletion();
|
|
31
|
+
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, branch.children, isFragment(node));
|
|
40
32
|
yield `}${utils_1.newLine}`;
|
|
41
33
|
if (addedBlockCondition) {
|
|
42
34
|
ctx.blockConditions[ctx.blockConditions.length - 1] = `!${ctx.blockConditions[ctx.blockConditions.length - 1]}`;
|
|
@@ -2,5 +2,4 @@ import * as CompilerDOM from '@vue/compiler-dom';
|
|
|
2
2
|
import type { Code } from '../../types';
|
|
3
3
|
import type { TemplateCodegenContext } from './context';
|
|
4
4
|
import type { TemplateCodegenOptions } from './index';
|
|
5
|
-
export declare function generateVSlot(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, slotDir: CompilerDOM.DirectiveNode): Generator<Code>;
|
|
6
|
-
export declare function generateImplicitDefaultSlot(ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode): Generator<Code, void, any>;
|
|
5
|
+
export declare function generateVSlot(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, slotDir: CompilerDOM.DirectiveNode | undefined): Generator<Code>;
|
|
@@ -1,93 +1,145 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateVSlot = generateVSlot;
|
|
4
|
-
exports.generateImplicitDefaultSlot = generateImplicitDefaultSlot;
|
|
5
4
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
5
|
+
const shared_1 = require("../../utils/shared");
|
|
6
6
|
const utils_1 = require("../utils");
|
|
7
7
|
const wrapWith_1 = require("../utils/wrapWith");
|
|
8
|
+
const elementChildren_1 = require("./elementChildren");
|
|
8
9
|
const objectProperty_1 = require("./objectProperty");
|
|
9
|
-
const templateChild_1 = require("./templateChild");
|
|
10
10
|
function* generateVSlot(options, ctx, node, slotDir) {
|
|
11
11
|
if (!ctx.currentComponent) {
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
|
-
ctx.currentComponent.used = true;
|
|
15
14
|
const slotBlockVars = [];
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slotDir.arg.loc.source, slotDir.arg.loc.start.offset, slotDir.arg.isStatic ? ctx.codeFeatures.withoutHighlight : ctx.codeFeatures.all, slotDir.arg.loc, false, true);
|
|
15
|
+
const slotVar = ctx.getInternalVariable();
|
|
16
|
+
if (slotDir) {
|
|
17
|
+
yield `{${utils_1.newLine}`;
|
|
20
18
|
}
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
if (slotDir || node.children.length) {
|
|
20
|
+
ctx.currentComponent.used = true;
|
|
21
|
+
yield `const { `;
|
|
22
|
+
if (slotDir) {
|
|
23
|
+
if (slotDir.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && slotDir.arg.content) {
|
|
24
|
+
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slotDir.arg.loc.source, slotDir.arg.loc.start.offset, slotDir.arg.isStatic ? ctx.codeFeatures.withoutHighlight : ctx.codeFeatures.all, slotDir.arg.loc, false, true);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
yield* (0, wrapWith_1.wrapWith)(slotDir.loc.start.offset, slotDir.loc.start.offset + (slotDir.rawName?.length ?? 0), ctx.codeFeatures.withoutHighlightAndCompletion, `default`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
// #932: reference for implicit default slot
|
|
32
|
+
const { start, end } = getElementInnerLoc(options, node);
|
|
33
|
+
yield* (0, wrapWith_1.wrapWith)(start, end, ctx.codeFeatures.navigation, `default`);
|
|
34
|
+
}
|
|
35
|
+
yield `: ${slotVar} } = ${ctx.currentComponent.ctxVar}.slots!${utils_1.endOfLine}`;
|
|
23
36
|
}
|
|
24
|
-
|
|
25
|
-
if (slotDir.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
37
|
+
if (slotDir?.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
26
38
|
const slotAst = (0, utils_1.createTsAst)(options.ts, slotDir, `(${slotDir.exp.content}) => {}`);
|
|
27
39
|
(0, utils_1.collectVars)(options.ts, slotAst, slotAst, slotBlockVars);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
yield* generateSlotParameters(options, ctx, slotAst, slotDir.exp, slotVar);
|
|
41
|
+
}
|
|
42
|
+
for (const varName of slotBlockVars) {
|
|
43
|
+
ctx.addLocalVariable(varName);
|
|
44
|
+
}
|
|
45
|
+
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node.children);
|
|
46
|
+
for (const varName of slotBlockVars) {
|
|
47
|
+
ctx.removeLocalVariable(varName);
|
|
48
|
+
}
|
|
49
|
+
if (options.vueCompilerOptions.strictSlotChildren && node.children.length) {
|
|
50
|
+
const { start, end } = getElementInnerLoc(options, node);
|
|
51
|
+
yield `(): __VLS_NormalizeSlotReturns<typeof ${slotVar}> => (`;
|
|
52
|
+
yield* (0, wrapWith_1.wrapWith)(start, end, ctx.codeFeatures.verification, `{} as [`, ...ctx.currentComponent.childTypes.map(name => `${name}, `), `]`);
|
|
53
|
+
yield `)${utils_1.endOfLine}`;
|
|
54
|
+
}
|
|
55
|
+
if (slotDir) {
|
|
56
|
+
let isStatic = true;
|
|
57
|
+
if (slotDir.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
58
|
+
isStatic = slotDir.arg.isStatic;
|
|
37
59
|
}
|
|
38
|
-
|
|
39
|
-
yield
|
|
60
|
+
if (isStatic && !slotDir.arg) {
|
|
61
|
+
yield `${ctx.currentComponent.ctxVar}.slots!['`;
|
|
40
62
|
yield [
|
|
41
|
-
|
|
63
|
+
'',
|
|
42
64
|
'template',
|
|
43
|
-
slotDir.
|
|
44
|
-
|
|
65
|
+
slotDir.loc.start.offset + (slotDir.loc.source.startsWith('#')
|
|
66
|
+
? '#'.length
|
|
67
|
+
: slotDir.loc.source.startsWith('v-slot:')
|
|
68
|
+
? 'v-slot:'.length
|
|
69
|
+
: 0),
|
|
70
|
+
ctx.codeFeatures.completion,
|
|
45
71
|
];
|
|
46
|
-
yield `
|
|
72
|
+
yield `'/* empty slot name completion */]${utils_1.endOfLine}`;
|
|
47
73
|
}
|
|
74
|
+
yield `}${utils_1.newLine}`;
|
|
48
75
|
}
|
|
49
|
-
|
|
50
|
-
|
|
76
|
+
}
|
|
77
|
+
function* generateSlotParameters(options, ctx, ast, exp, slotVar) {
|
|
78
|
+
const { ts } = options;
|
|
79
|
+
const statement = ast.statements[0];
|
|
80
|
+
if (!ts.isExpressionStatement(statement) || !ts.isArrowFunction(statement.expression)) {
|
|
81
|
+
return;
|
|
51
82
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
83
|
+
const { expression } = statement;
|
|
84
|
+
const startOffset = exp.loc.start.offset - 1;
|
|
85
|
+
const modifies = [];
|
|
86
|
+
const types = [];
|
|
87
|
+
for (const { name, type } of expression.parameters) {
|
|
88
|
+
if (type) {
|
|
89
|
+
modifies.push([
|
|
90
|
+
[``],
|
|
91
|
+
name.end,
|
|
92
|
+
type.end,
|
|
93
|
+
]);
|
|
94
|
+
types.push(chunk((0, shared_1.getStartEnd)(ts, type, ast).start, type.end));
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
types.push(null);
|
|
98
|
+
}
|
|
57
99
|
}
|
|
58
|
-
|
|
59
|
-
|
|
100
|
+
yield `const [`;
|
|
101
|
+
let nextStart = 1;
|
|
102
|
+
for (const [codes, start, end] of modifies) {
|
|
103
|
+
yield chunk(nextStart, start);
|
|
104
|
+
yield* codes;
|
|
105
|
+
nextStart = end;
|
|
60
106
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
107
|
+
yield chunk(nextStart, expression.equalsGreaterThanToken.pos - 1);
|
|
108
|
+
yield `] = __VLS_getSlotParameters(${slotVar}`;
|
|
109
|
+
if (types.some(t => t)) {
|
|
110
|
+
yield `, `;
|
|
111
|
+
yield* (0, wrapWith_1.wrapWith)(exp.loc.start.offset, exp.loc.end.offset, ctx.codeFeatures.verification, `(`, ...types.flatMap(type => type ? [`_: `, type, `, `] : `_, `), `) => [] as any`);
|
|
64
112
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
113
|
+
yield `)${utils_1.endOfLine}`;
|
|
114
|
+
function chunk(start, end) {
|
|
115
|
+
return [
|
|
116
|
+
ast.text.slice(start, end),
|
|
69
117
|
'template',
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
: slotDir.loc.source.startsWith('v-slot:')
|
|
73
|
-
? 'v-slot:'.length
|
|
74
|
-
: 0),
|
|
75
|
-
ctx.codeFeatures.completion,
|
|
118
|
+
startOffset + start,
|
|
119
|
+
ctx.codeFeatures.all,
|
|
76
120
|
];
|
|
77
|
-
yield `'/* empty slot name completion */]${utils_1.endOfLine}`;
|
|
78
121
|
}
|
|
79
|
-
yield* ctx.generateAutoImportCompletion();
|
|
80
|
-
yield `}${utils_1.newLine}`;
|
|
81
122
|
}
|
|
82
|
-
function
|
|
83
|
-
if (!ctx.currentComponent) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
123
|
+
function getElementInnerLoc(options, node) {
|
|
86
124
|
if (node.children.length) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
125
|
+
let start = node.children[0].loc.start.offset;
|
|
126
|
+
let end = node.children.at(-1).loc.end.offset;
|
|
127
|
+
while (options.template.content[start - 1] !== '>') {
|
|
128
|
+
start--;
|
|
129
|
+
}
|
|
130
|
+
while (options.template.content[end] !== '<' && end < node.loc.end.offset) {
|
|
131
|
+
end++;
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
start,
|
|
135
|
+
end,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
return {
|
|
140
|
+
start: node.loc.start.offset,
|
|
141
|
+
end: node.loc.end.offset,
|
|
142
|
+
};
|
|
91
143
|
}
|
|
92
144
|
}
|
|
93
145
|
//# sourceMappingURL=vSlot.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as CompilerDOM from '@vue/compiler-dom';
|
|
1
|
+
import type * as CompilerDOM from '@vue/compiler-dom';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
|
-
import type { Code, SfcBlock,
|
|
3
|
+
import type { Code, SfcBlock, VueCodeInformation } from '../../types';
|
|
4
4
|
export declare const newLine = "\n";
|
|
5
5
|
export declare const endOfLine = ";\n";
|
|
6
6
|
export declare const combineLastMapping: VueCodeInformation;
|
|
@@ -18,4 +18,3 @@ export declare function collectIdentifiers(ts: typeof import('typescript'), node
|
|
|
18
18
|
export declare function normalizeAttributeValue(node: CompilerDOM.TextNode): [string, number];
|
|
19
19
|
export declare function createTsAst(ts: typeof import('typescript'), astHolder: any, text: string): ts.SourceFile;
|
|
20
20
|
export declare function generateSfcBlockSection(block: SfcBlock, start: number, end: number, features: VueCodeInformation): Code;
|
|
21
|
-
export declare function generateSfcBlockAttrValue(src: SfcBlockAttr & object, text: string, features: VueCodeInformation): Generator<Code>;
|
|
@@ -6,8 +6,7 @@ exports.collectIdentifiers = collectIdentifiers;
|
|
|
6
6
|
exports.normalizeAttributeValue = normalizeAttributeValue;
|
|
7
7
|
exports.createTsAst = createTsAst;
|
|
8
8
|
exports.generateSfcBlockSection = generateSfcBlockSection;
|
|
9
|
-
|
|
10
|
-
const scriptSetupRanges_1 = require("../../parsers/scriptSetupRanges");
|
|
9
|
+
const shared_1 = require("../../utils/shared");
|
|
11
10
|
exports.newLine = `\n`;
|
|
12
11
|
exports.endOfLine = `;${exports.newLine}`;
|
|
13
12
|
exports.combineLastMapping = { __combineOffset: 1 };
|
|
@@ -15,7 +14,7 @@ exports.identifierRegex = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
|
|
|
15
14
|
function collectVars(ts, node, ast, results = []) {
|
|
16
15
|
const identifiers = collectIdentifiers(ts, node, []);
|
|
17
16
|
for (const { id } of identifiers) {
|
|
18
|
-
results.push((0,
|
|
17
|
+
results.push((0, shared_1.getNodeText)(ts, id, ast));
|
|
19
18
|
}
|
|
20
19
|
return results;
|
|
21
20
|
}
|
|
@@ -65,19 +64,4 @@ function generateSfcBlockSection(block, start, end, features) {
|
|
|
65
64
|
features,
|
|
66
65
|
];
|
|
67
66
|
}
|
|
68
|
-
function* generateSfcBlockAttrValue(src, text, features) {
|
|
69
|
-
const { offset, quotes } = src;
|
|
70
|
-
if (!quotes) {
|
|
71
|
-
yield [``, 'main', offset, { verification: true }];
|
|
72
|
-
}
|
|
73
|
-
yield [
|
|
74
|
-
`'${text}'`,
|
|
75
|
-
'main',
|
|
76
|
-
quotes ? offset - 1 : offset,
|
|
77
|
-
features
|
|
78
|
-
];
|
|
79
|
-
if (!quotes) {
|
|
80
|
-
yield [``, 'main', offset + text.length, { __combineOffset: 2 }];
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
67
|
//# sourceMappingURL=index.js.map
|
package/lib/languagePlugin.d.ts
CHANGED
package/lib/languagePlugin.js
CHANGED
|
@@ -6,7 +6,6 @@ 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 CompilerVue2 = require("./utils/vue2TemplateCompiler");
|
|
10
9
|
const vueFile_1 = require("./virtualFile/vueFile");
|
|
11
10
|
const fileRegistries = [];
|
|
12
11
|
function getVueFileRegistry(key, plugins) {
|
|
@@ -38,12 +37,7 @@ function getFileRegistryKey(compilerOptions, vueCompilerOptions, plugins) {
|
|
|
38
37
|
function createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFileName) {
|
|
39
38
|
const pluginContext = {
|
|
40
39
|
modules: {
|
|
41
|
-
'@vue/compiler-dom':
|
|
42
|
-
? {
|
|
43
|
-
...CompilerDOM,
|
|
44
|
-
compile: CompilerVue2.compile,
|
|
45
|
-
}
|
|
46
|
-
: CompilerDOM,
|
|
40
|
+
'@vue/compiler-dom': CompilerDOM,
|
|
47
41
|
typescript: ts,
|
|
48
42
|
},
|
|
49
43
|
compilerOptions,
|
|
@@ -2,18 +2,17 @@ import type * as ts from 'typescript';
|
|
|
2
2
|
import type { TextRange } 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, hasScriptSetup: boolean
|
|
5
|
+
export declare function parseScriptRanges(ts: typeof import('typescript'), ast: ts.SourceFile, hasScriptSetup: boolean): {
|
|
6
6
|
exportDefault: (TextRange & {
|
|
7
7
|
expression: TextRange;
|
|
8
8
|
args: TextRange;
|
|
9
|
-
argsNode: ts.ObjectLiteralExpression
|
|
9
|
+
argsNode: ts.ObjectLiteralExpression;
|
|
10
10
|
componentsOption: TextRange | undefined;
|
|
11
11
|
componentsOptionNode: ts.ObjectLiteralExpression | undefined;
|
|
12
12
|
directivesOption: TextRange | undefined;
|
|
13
13
|
nameOption: TextRange | undefined;
|
|
14
14
|
inheritAttrsOption: string | undefined;
|
|
15
15
|
}) | undefined;
|
|
16
|
-
classBlockEnd: number | undefined;
|
|
17
16
|
bindings: {
|
|
18
17
|
range: TextRange;
|
|
19
18
|
moduleName?: string;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseScriptRanges = parseScriptRanges;
|
|
4
|
+
const shared_1 = require("../utils/shared");
|
|
4
5
|
const scriptSetupRanges_1 = require("./scriptSetupRanges");
|
|
5
|
-
function parseScriptRanges(ts, ast, hasScriptSetup
|
|
6
|
+
function parseScriptRanges(ts, ast, hasScriptSetup) {
|
|
6
7
|
let exportDefault;
|
|
7
|
-
let classBlockEnd;
|
|
8
8
|
const bindings = hasScriptSetup ? (0, scriptSetupRanges_1.parseBindingRanges)(ts, ast) : [];
|
|
9
9
|
ts.forEachChild(ast, raw => {
|
|
10
10
|
if (ts.isExportAssignment(raw)) {
|
|
@@ -29,7 +29,7 @@ function parseScriptRanges(ts, ast, hasScriptSetup, withNode) {
|
|
|
29
29
|
let inheritAttrsOption;
|
|
30
30
|
ts.forEachChild(obj, node => {
|
|
31
31
|
if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name)) {
|
|
32
|
-
const name = (
|
|
32
|
+
const name = _getNodeText(node.name);
|
|
33
33
|
if (name === 'components' && ts.isObjectLiteralExpression(node.initializer)) {
|
|
34
34
|
componentsOptionNode = node.initializer;
|
|
35
35
|
}
|
|
@@ -40,7 +40,7 @@ function parseScriptRanges(ts, ast, hasScriptSetup, withNode) {
|
|
|
40
40
|
nameOptionNode = node.initializer;
|
|
41
41
|
}
|
|
42
42
|
else if (name === 'inheritAttrs') {
|
|
43
|
-
inheritAttrsOption = (
|
|
43
|
+
inheritAttrsOption = _getNodeText(node.initializer);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
});
|
|
@@ -48,28 +48,25 @@ function parseScriptRanges(ts, ast, hasScriptSetup, withNode) {
|
|
|
48
48
|
..._getStartEnd(raw),
|
|
49
49
|
expression: _getStartEnd(node.expression),
|
|
50
50
|
args: _getStartEnd(obj),
|
|
51
|
-
argsNode:
|
|
51
|
+
argsNode: obj,
|
|
52
52
|
componentsOption: componentsOptionNode ? _getStartEnd(componentsOptionNode) : undefined,
|
|
53
|
-
componentsOptionNode
|
|
53
|
+
componentsOptionNode,
|
|
54
54
|
directivesOption: directivesOptionNode ? _getStartEnd(directivesOptionNode) : undefined,
|
|
55
55
|
nameOption: nameOptionNode ? _getStartEnd(nameOptionNode) : undefined,
|
|
56
56
|
inheritAttrsOption,
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
-
if (ts.isClassDeclaration(raw)
|
|
61
|
-
&& raw.modifiers?.some(mod => mod.kind === ts.SyntaxKind.ExportKeyword)
|
|
62
|
-
&& raw.modifiers?.some(mod => mod.kind === ts.SyntaxKind.DefaultKeyword)) {
|
|
63
|
-
classBlockEnd = raw.end - 1;
|
|
64
|
-
}
|
|
65
60
|
});
|
|
66
61
|
return {
|
|
67
62
|
exportDefault,
|
|
68
|
-
classBlockEnd,
|
|
69
63
|
bindings,
|
|
70
64
|
};
|
|
71
65
|
function _getStartEnd(node) {
|
|
72
|
-
return (0,
|
|
66
|
+
return (0, shared_1.getStartEnd)(ts, node, ast);
|
|
67
|
+
}
|
|
68
|
+
function _getNodeText(node) {
|
|
69
|
+
return (0, shared_1.getNodeText)(ts, node, ast);
|
|
73
70
|
}
|
|
74
71
|
// isAsExpression is missing in tsc
|
|
75
72
|
function isAsExpression(node) {
|
|
@@ -73,7 +73,4 @@ export declare function parseBindingRanges(ts: typeof import('typescript'), ast:
|
|
|
73
73
|
isDefaultImport?: boolean;
|
|
74
74
|
isNamespace?: boolean;
|
|
75
75
|
}[];
|
|
76
|
-
export declare function findBindingVars(ts: typeof import('typescript'), left: ts.BindingName, ast: ts.SourceFile): TextRange[];
|
|
77
|
-
export declare function getStartEnd(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): TextRange;
|
|
78
|
-
export declare function getNodeText(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): string;
|
|
79
76
|
export {};
|