@vue/language-core 2.1.10 → 2.2.2
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 +0 -1
- package/index.js +1 -2
- package/lib/codeFeatures.d.ts +1 -0
- package/lib/codeFeatures.js +3 -0
- package/lib/codegen/codeFeatures.d.ts +83 -0
- package/lib/codegen/codeFeatures.js +71 -0
- package/lib/codegen/globalTypes.d.ts +3 -1
- package/lib/codegen/globalTypes.js +39 -14
- package/lib/codegen/localTypes.d.ts +1 -1
- package/lib/codegen/localTypes.js +7 -7
- package/lib/codegen/script/binding.d.ts +4 -0
- package/lib/codegen/script/binding.js +41 -0
- package/lib/codegen/script/component.d.ts +1 -1
- package/lib/codegen/script/component.js +44 -44
- package/lib/codegen/script/componentSelf.d.ts +1 -1
- package/lib/codegen/script/componentSelf.js +14 -14
- package/lib/codegen/script/context.d.ts +1 -1
- package/lib/codegen/script/context.js +2 -2
- package/lib/codegen/script/index.d.ts +6 -11
- package/lib/codegen/script/index.js +21 -63
- package/lib/codegen/script/scriptSetup.d.ts +1 -1
- package/lib/codegen/script/scriptSetup.js +236 -205
- package/lib/codegen/script/src.js +8 -8
- package/lib/codegen/script/styleModulesType.d.ts +1 -1
- package/lib/codegen/script/styleModulesType.js +7 -7
- package/lib/codegen/script/template.d.ts +2 -2
- package/lib/codegen/script/template.js +81 -114
- package/lib/codegen/template/context.d.ts +29 -15
- package/lib/codegen/template/context.js +51 -96
- package/lib/codegen/template/element.d.ts +2 -4
- package/lib/codegen/template/element.js +124 -317
- package/lib/codegen/template/elementChildren.d.ts +1 -1
- package/lib/codegen/template/elementChildren.js +10 -11
- package/lib/codegen/template/elementDirectives.d.ts +1 -0
- package/lib/codegen/template/elementDirectives.js +43 -30
- package/lib/codegen/template/elementEvents.d.ts +2 -2
- package/lib/codegen/template/elementEvents.js +32 -65
- package/lib/codegen/template/elementProps.d.ts +5 -3
- package/lib/codegen/template/elementProps.js +116 -123
- package/lib/codegen/template/index.d.ts +1 -0
- package/lib/codegen/template/index.js +67 -69
- package/lib/codegen/template/interpolation.d.ts +5 -3
- package/lib/codegen/template/interpolation.js +30 -27
- package/lib/codegen/template/objectProperty.js +8 -8
- package/lib/codegen/template/propertyAccess.js +4 -4
- package/lib/codegen/template/slotOutlet.d.ts +1 -1
- package/lib/codegen/template/slotOutlet.js +47 -25
- package/lib/codegen/template/styleScopedClasses.d.ts +4 -1
- package/lib/codegen/template/styleScopedClasses.js +152 -8
- package/lib/codegen/template/templateChild.d.ts +1 -1
- package/lib/codegen/template/templateChild.js +39 -20
- package/lib/codegen/template/vFor.d.ts +1 -1
- package/lib/codegen/template/vFor.js +11 -11
- package/lib/codegen/template/vIf.d.ts +1 -1
- package/lib/codegen/template/vIf.js +6 -6
- package/lib/codegen/template/vSlot.d.ts +5 -0
- package/lib/codegen/template/vSlot.js +80 -0
- package/lib/codegen/utils/camelized.d.ts +2 -0
- package/lib/codegen/utils/camelized.js +31 -0
- package/lib/codegen/utils/index.d.ts +21 -0
- package/lib/codegen/utils/index.js +79 -0
- package/lib/codegen/utils/src.d.ts +2 -0
- package/lib/codegen/utils/src.js +19 -0
- package/lib/codegen/{template → utils}/stringLiteralKey.js +3 -3
- package/lib/codegen/utils/unicode.d.ts +2 -0
- package/lib/codegen/utils/unicode.js +25 -0
- package/lib/languagePlugin.js +1 -1
- package/lib/parsers/scriptRanges.d.ts +7 -2
- package/lib/parsers/scriptSetupRanges.d.ts +69 -83
- package/lib/parsers/scriptSetupRanges.js +194 -171
- package/lib/parsers/vueCompilerOptions.d.ts +2 -0
- package/lib/parsers/vueCompilerOptions.js +23 -0
- package/lib/plugins/file-html.js +4 -3
- package/lib/plugins/file-md.js +1 -1
- package/lib/plugins/file-vue.js +4 -4
- package/lib/plugins/vue-root-tags.js +2 -2
- package/lib/plugins/vue-style-class-names.d.ts +5 -0
- package/lib/plugins/vue-style-class-names.js +32 -0
- package/lib/plugins/vue-style-reference-link.d.ts +1 -0
- package/lib/plugins/vue-style-reference-link.js +3 -0
- package/lib/plugins/vue-style-reference-links.d.ts +3 -0
- package/lib/plugins/vue-style-reference-links.js +26 -0
- package/lib/plugins/vue-template-html.js +6 -2
- package/lib/plugins/vue-template-inline-css.js +1 -1
- package/lib/plugins/vue-template-inline-ts.js +66 -17
- package/lib/plugins/vue-tsx.d.ts +126 -92
- package/lib/plugins/vue-tsx.js +114 -97
- package/lib/plugins/vue-vine.d.ts +3 -0
- package/lib/plugins/vue-vine.js +35 -0
- package/lib/types.d.ts +25 -12
- package/lib/utils/buildMappings.d.ts +1 -1
- package/lib/utils/parseCssImports.d.ts +4 -0
- package/lib/utils/parseCssImports.js +19 -0
- package/lib/utils/parseSfc.d.ts +5 -0
- package/lib/utils/parseSfc.js +11 -5
- package/lib/utils/signals.d.ts +2 -0
- package/lib/utils/signals.js +54 -0
- package/lib/utils/ts.d.ts +14 -2
- package/lib/utils/ts.js +134 -91
- package/lib/virtualFile/computedEmbeddedCodes.d.ts +1 -2
- package/lib/virtualFile/computedEmbeddedCodes.js +11 -11
- package/lib/virtualFile/computedSfc.d.ts +1 -2
- package/lib/virtualFile/computedSfc.js +87 -79
- package/lib/virtualFile/computedVueSfc.d.ts +1 -2
- package/lib/virtualFile/computedVueSfc.js +7 -7
- package/lib/virtualFile/vueFile.d.ts +5 -5
- package/lib/virtualFile/vueFile.js +6 -6
- package/package.json +6 -6
- /package/lib/codegen/{template → utils}/stringLiteralKey.d.ts +0 -0
|
@@ -4,12 +4,13 @@ exports.generateTemplateChild = generateTemplateChild;
|
|
|
4
4
|
exports.getVForNode = getVForNode;
|
|
5
5
|
exports.parseInterpolationNode = parseInterpolationNode;
|
|
6
6
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
7
|
-
const
|
|
7
|
+
const utils_1 = require("../utils");
|
|
8
8
|
const element_1 = require("./element");
|
|
9
9
|
const interpolation_1 = require("./interpolation");
|
|
10
10
|
const slotOutlet_1 = require("./slotOutlet");
|
|
11
11
|
const vFor_1 = require("./vFor");
|
|
12
12
|
const vIf_1 = require("./vIf");
|
|
13
|
+
const vSlot_1 = require("./vSlot");
|
|
13
14
|
// @ts-ignore
|
|
14
15
|
const transformContext = {
|
|
15
16
|
onError: () => { },
|
|
@@ -25,19 +26,29 @@ const transformContext = {
|
|
|
25
26
|
},
|
|
26
27
|
expressionPlugins: ['typescript'],
|
|
27
28
|
};
|
|
28
|
-
function* generateTemplateChild(options, ctx, node,
|
|
29
|
+
function* generateTemplateChild(options, ctx, node, prevNode, isVForChild = false) {
|
|
29
30
|
if (prevNode?.type === CompilerDOM.NodeTypes.COMMENT) {
|
|
30
31
|
const commentText = prevNode.content.trim().split(' ')[0];
|
|
31
|
-
if (
|
|
32
|
-
yield `// @vue-skip${
|
|
32
|
+
if (/^@vue-skip\b[\s\S]*/.test(commentText)) {
|
|
33
|
+
yield `// @vue-skip${utils_1.newLine}`;
|
|
33
34
|
return;
|
|
34
35
|
}
|
|
35
|
-
else if (
|
|
36
|
+
else if (/^@vue-ignore\b[\s\S]*/.test(commentText)) {
|
|
36
37
|
yield* ctx.ignoreError();
|
|
37
38
|
}
|
|
38
|
-
else if (
|
|
39
|
+
else if (/^@vue-expect-error\b[\s\S]*/.test(commentText)) {
|
|
39
40
|
yield* ctx.expectError(prevNode);
|
|
40
41
|
}
|
|
42
|
+
else {
|
|
43
|
+
const match = prevNode.loc.source.match(/^<!--\s*@vue-generic\b\s*\{(?<content>[^}]*)\}/);
|
|
44
|
+
if (match) {
|
|
45
|
+
const { content } = match.groups ?? {};
|
|
46
|
+
ctx.lastGenericComment = {
|
|
47
|
+
content,
|
|
48
|
+
offset: prevNode.loc.start.offset + match[0].indexOf(content)
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
41
52
|
}
|
|
42
53
|
const shouldInheritRootNodeAttrs = options.inheritAttrs;
|
|
43
54
|
const cur = node;
|
|
@@ -50,7 +61,7 @@ function* generateTemplateChild(options, ctx, node, currentComponent, prevNode,
|
|
|
50
61
|
ctx.singleRootNode = node.children[0];
|
|
51
62
|
}
|
|
52
63
|
for (const childNode of node.children) {
|
|
53
|
-
yield* generateTemplateChild(options, ctx, childNode,
|
|
64
|
+
yield* generateTemplateChild(options, ctx, childNode, prev);
|
|
54
65
|
prev = childNode;
|
|
55
66
|
}
|
|
56
67
|
yield* ctx.resetDirectiveComments('end of root');
|
|
@@ -59,49 +70,57 @@ function* generateTemplateChild(options, ctx, node, currentComponent, prevNode,
|
|
|
59
70
|
const vForNode = getVForNode(node);
|
|
60
71
|
const vIfNode = getVIfNode(node);
|
|
61
72
|
if (vForNode) {
|
|
62
|
-
yield* (0, vFor_1.generateVFor)(options, ctx, vForNode
|
|
73
|
+
yield* (0, vFor_1.generateVFor)(options, ctx, vForNode);
|
|
63
74
|
}
|
|
64
75
|
else if (vIfNode) {
|
|
65
|
-
yield* (0, vIf_1.generateVIf)(options, ctx, vIfNode
|
|
76
|
+
yield* (0, vIf_1.generateVIf)(options, ctx, vIfNode);
|
|
77
|
+
}
|
|
78
|
+
else if (node.tagType === CompilerDOM.ElementTypes.SLOT) {
|
|
79
|
+
yield* (0, slotOutlet_1.generateSlotOutlet)(options, ctx, node);
|
|
66
80
|
}
|
|
67
81
|
else {
|
|
68
|
-
|
|
69
|
-
|
|
82
|
+
const slotDir = node.props.find(p => p.type === CompilerDOM.NodeTypes.DIRECTIVE && p.name === 'slot');
|
|
83
|
+
if (node.tagType === CompilerDOM.ElementTypes.TEMPLATE
|
|
84
|
+
&& ctx.currentComponent
|
|
85
|
+
&& slotDir) {
|
|
86
|
+
yield* (0, vSlot_1.generateVSlot)(options, ctx, node, slotDir);
|
|
70
87
|
}
|
|
71
88
|
else if (node.tagType === CompilerDOM.ElementTypes.ELEMENT
|
|
72
89
|
|| node.tagType === CompilerDOM.ElementTypes.TEMPLATE) {
|
|
73
|
-
yield* (0, element_1.generateElement)(options, ctx, node,
|
|
90
|
+
yield* (0, element_1.generateElement)(options, ctx, node, isVForChild);
|
|
74
91
|
}
|
|
75
92
|
else {
|
|
76
|
-
|
|
93
|
+
const { currentComponent } = ctx;
|
|
94
|
+
yield* (0, element_1.generateComponent)(options, ctx, node);
|
|
95
|
+
ctx.currentComponent = currentComponent;
|
|
77
96
|
}
|
|
78
97
|
}
|
|
79
98
|
}
|
|
80
99
|
else if (node.type === CompilerDOM.NodeTypes.TEXT_CALL) {
|
|
81
100
|
// {{ var }}
|
|
82
|
-
yield* generateTemplateChild(options, ctx, node.content,
|
|
101
|
+
yield* generateTemplateChild(options, ctx, node.content, undefined);
|
|
83
102
|
}
|
|
84
103
|
else if (node.type === CompilerDOM.NodeTypes.COMPOUND_EXPRESSION) {
|
|
85
104
|
// {{ ... }} {{ ... }}
|
|
86
105
|
for (const childNode of node.children) {
|
|
87
106
|
if (typeof childNode === 'object') {
|
|
88
|
-
yield* generateTemplateChild(options, ctx, childNode,
|
|
107
|
+
yield* generateTemplateChild(options, ctx, childNode, undefined);
|
|
89
108
|
}
|
|
90
109
|
}
|
|
91
110
|
}
|
|
92
111
|
else if (node.type === CompilerDOM.NodeTypes.INTERPOLATION) {
|
|
93
112
|
// {{ ... }}
|
|
94
113
|
const [content, start] = parseInterpolationNode(node, options.template.content);
|
|
95
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx,
|
|
114
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, content, start, node.content.loc, `(`, `)${utils_1.endOfLine}`);
|
|
96
115
|
yield* ctx.resetDirectiveComments('end of INTERPOLATION');
|
|
97
116
|
}
|
|
98
117
|
else if (node.type === CompilerDOM.NodeTypes.IF) {
|
|
99
118
|
// v-if / v-else-if / v-else
|
|
100
|
-
yield* (0, vIf_1.generateVIf)(options, ctx, node
|
|
119
|
+
yield* (0, vIf_1.generateVIf)(options, ctx, node);
|
|
101
120
|
}
|
|
102
121
|
else if (node.type === CompilerDOM.NodeTypes.FOR) {
|
|
103
122
|
// v-for
|
|
104
|
-
yield* (0, vFor_1.generateVFor)(options, ctx, node
|
|
123
|
+
yield* (0, vFor_1.generateVFor)(options, ctx, node);
|
|
105
124
|
}
|
|
106
125
|
else if (node.type === CompilerDOM.NodeTypes.TEXT) {
|
|
107
126
|
// not needed progress
|
|
@@ -152,11 +171,11 @@ function parseInterpolationNode(node, template) {
|
|
|
152
171
|
let leftCharacter;
|
|
153
172
|
let rightCharacter;
|
|
154
173
|
// fix https://github.com/vuejs/language-tools/issues/1787
|
|
155
|
-
while ((leftCharacter = template.
|
|
174
|
+
while ((leftCharacter = template.slice(start - 1, start)).trim() === '' && leftCharacter.length) {
|
|
156
175
|
start--;
|
|
157
176
|
content = leftCharacter + content;
|
|
158
177
|
}
|
|
159
|
-
while ((rightCharacter = template.
|
|
178
|
+
while ((rightCharacter = template.slice(start + content.length, start + content.length + 1)).trim() === '' && rightCharacter.length) {
|
|
160
179
|
content = content + rightCharacter;
|
|
161
180
|
}
|
|
162
181
|
return [
|
|
@@ -2,7 +2,7 @@ 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 generateVFor(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ForNode
|
|
5
|
+
export declare function generateVFor(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ForNode): Generator<Code>;
|
|
6
6
|
export declare function parseVForNode(node: CompilerDOM.ForNode): {
|
|
7
7
|
leftExpressionRange: {
|
|
8
8
|
start: number;
|
|
@@ -3,17 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateVFor = generateVFor;
|
|
4
4
|
exports.parseVForNode = parseVForNode;
|
|
5
5
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
6
|
-
const
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
7
|
const interpolation_1 = require("./interpolation");
|
|
8
8
|
const templateChild_1 = require("./templateChild");
|
|
9
|
-
function* generateVFor(options, ctx, node
|
|
9
|
+
function* generateVFor(options, ctx, node) {
|
|
10
10
|
const { source } = node.parseResult;
|
|
11
11
|
const { leftExpressionRange, leftExpressionText } = parseVForNode(node);
|
|
12
12
|
const forBlockVars = [];
|
|
13
13
|
yield `for (const [`;
|
|
14
14
|
if (leftExpressionRange && leftExpressionText) {
|
|
15
|
-
const collectAst = (0,
|
|
16
|
-
(0,
|
|
15
|
+
const collectAst = (0, utils_1.createTsAst)(options.ts, node.parseResult, `const [${leftExpressionText}]`);
|
|
16
|
+
(0, utils_1.collectVars)(options.ts, collectAst, collectAst, forBlockVars);
|
|
17
17
|
yield [
|
|
18
18
|
leftExpressionText,
|
|
19
19
|
'template',
|
|
@@ -24,13 +24,13 @@ function* generateVFor(options, ctx, node, currentComponent, componentCtxVar) {
|
|
|
24
24
|
yield `] of `;
|
|
25
25
|
if (source.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
26
26
|
yield `__VLS_getVForSourceType(`;
|
|
27
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx,
|
|
27
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, source.content, source.loc.start.offset, source.loc, '(', ')');
|
|
28
28
|
yield `!)`; // #3102
|
|
29
29
|
}
|
|
30
30
|
else {
|
|
31
31
|
yield `{} as any`;
|
|
32
32
|
}
|
|
33
|
-
yield `) {${
|
|
33
|
+
yield `) {${utils_1.newLine}`;
|
|
34
34
|
for (const varName of forBlockVars) {
|
|
35
35
|
ctx.addLocalVariable(varName);
|
|
36
36
|
}
|
|
@@ -46,8 +46,8 @@ function* generateVFor(options, ctx, node, currentComponent, componentCtxVar) {
|
|
|
46
46
|
for (const prop of argument.returns.props.properties) {
|
|
47
47
|
if (prop.value.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
48
48
|
&& !prop.value.isStatic) {
|
|
49
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx,
|
|
50
|
-
yield
|
|
49
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, prop.value.content, prop.value.loc.start.offset, prop.value.loc, '(', ')');
|
|
50
|
+
yield utils_1.endOfLine;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
}
|
|
@@ -57,14 +57,14 @@ function* generateVFor(options, ctx, node, currentComponent, componentCtxVar) {
|
|
|
57
57
|
}
|
|
58
58
|
let prev;
|
|
59
59
|
for (const childNode of node.children) {
|
|
60
|
-
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode,
|
|
60
|
+
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, prev, true);
|
|
61
61
|
prev = childNode;
|
|
62
62
|
}
|
|
63
63
|
for (const varName of forBlockVars) {
|
|
64
64
|
ctx.removeLocalVariable(varName);
|
|
65
65
|
}
|
|
66
66
|
yield* ctx.generateAutoImportCompletion();
|
|
67
|
-
yield `}${
|
|
67
|
+
yield `}${utils_1.newLine}`;
|
|
68
68
|
}
|
|
69
69
|
function parseVForNode(node) {
|
|
70
70
|
const { value, key, index } = node.parseResult;
|
|
@@ -75,7 +75,7 @@ function parseVForNode(node) {
|
|
|
75
75
|
}
|
|
76
76
|
: undefined;
|
|
77
77
|
const leftExpressionText = leftExpressionRange
|
|
78
|
-
? node.loc.source.
|
|
78
|
+
? node.loc.source.slice(leftExpressionRange.start - node.loc.start.offset, leftExpressionRange.end - node.loc.start.offset)
|
|
79
79
|
: undefined;
|
|
80
80
|
return {
|
|
81
81
|
leftExpressionRange,
|
|
@@ -2,4 +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 generateVIf(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.IfNode
|
|
5
|
+
export declare function generateVIf(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.IfNode): Generator<Code>;
|
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateVIf = generateVIf;
|
|
4
4
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
5
5
|
const muggle_string_1 = require("muggle-string");
|
|
6
|
-
const
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
7
|
const interpolation_1 = require("./interpolation");
|
|
8
8
|
const templateChild_1 = require("./templateChild");
|
|
9
|
-
function* generateVIf(options, ctx, node
|
|
9
|
+
function* generateVIf(options, ctx, node) {
|
|
10
10
|
let originalBlockConditionsLength = ctx.blockConditions.length;
|
|
11
11
|
for (let i = 0; i < node.branches.length; i++) {
|
|
12
12
|
const branch = node.branches[i];
|
|
@@ -22,7 +22,7 @@ function* generateVIf(options, ctx, node, currentComponent, componentCtxVar) {
|
|
|
22
22
|
let addedBlockCondition = false;
|
|
23
23
|
if (branch.condition?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
24
24
|
const codes = [
|
|
25
|
-
...(0, interpolation_1.generateInterpolation)(options, ctx,
|
|
25
|
+
...(0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, branch.condition.content, branch.condition.loc.start.offset, branch.condition.loc, '(', ')'),
|
|
26
26
|
];
|
|
27
27
|
for (const code of codes) {
|
|
28
28
|
yield code;
|
|
@@ -31,17 +31,17 @@ function* generateVIf(options, ctx, node, currentComponent, componentCtxVar) {
|
|
|
31
31
|
addedBlockCondition = true;
|
|
32
32
|
yield ` `;
|
|
33
33
|
}
|
|
34
|
-
yield `{${
|
|
34
|
+
yield `{${utils_1.newLine}`;
|
|
35
35
|
if (isFragment(node)) {
|
|
36
36
|
yield* ctx.resetDirectiveComments('end of v-if start');
|
|
37
37
|
}
|
|
38
38
|
let prev;
|
|
39
39
|
for (const childNode of branch.children) {
|
|
40
|
-
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode,
|
|
40
|
+
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, prev);
|
|
41
41
|
prev = childNode;
|
|
42
42
|
}
|
|
43
43
|
yield* ctx.generateAutoImportCompletion();
|
|
44
|
-
yield `}${
|
|
44
|
+
yield `}${utils_1.newLine}`;
|
|
45
45
|
if (addedBlockCondition) {
|
|
46
46
|
ctx.blockConditions[ctx.blockConditions.length - 1] = `!(${ctx.blockConditions[ctx.blockConditions.length - 1]})`;
|
|
47
47
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as CompilerDOM from '@vue/compiler-dom';
|
|
2
|
+
import type { Code } from '../../types';
|
|
3
|
+
import type { TemplateCodegenContext } from './context';
|
|
4
|
+
import type { TemplateCodegenOptions } from './index';
|
|
5
|
+
export declare function generateVSlot(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, slotDir: CompilerDOM.DirectiveNode): Generator<Code>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateVSlot = generateVSlot;
|
|
4
|
+
const CompilerDOM = require("@vue/compiler-dom");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
const objectProperty_1 = require("./objectProperty");
|
|
7
|
+
const templateChild_1 = require("./templateChild");
|
|
8
|
+
function* generateVSlot(options, ctx, node, slotDir) {
|
|
9
|
+
if (!ctx.currentComponent) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
ctx.currentComponent.used = true;
|
|
13
|
+
const slotBlockVars = [];
|
|
14
|
+
yield `{${utils_1.newLine}`;
|
|
15
|
+
yield `const { `;
|
|
16
|
+
if (slotDir.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && slotDir.arg.content) {
|
|
17
|
+
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);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
yield* (0, utils_1.wrapWith)(slotDir.loc.start.offset, slotDir.loc.start.offset + (slotDir.rawName?.length ?? 0), ctx.codeFeatures.withoutHighlightAndCompletion, `default`);
|
|
21
|
+
}
|
|
22
|
+
yield `: __VLS_thisSlot } = ${ctx.currentComponent.ctxVar}.slots!${utils_1.endOfLine}`;
|
|
23
|
+
if (slotDir.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
24
|
+
const slotAst = (0, utils_1.createTsAst)(options.ts, slotDir, `(${slotDir.exp.content}) => {}`);
|
|
25
|
+
(0, utils_1.collectVars)(options.ts, slotAst, slotAst, slotBlockVars);
|
|
26
|
+
if (!slotDir.exp.content.includes(':')) {
|
|
27
|
+
yield `const [`;
|
|
28
|
+
yield [
|
|
29
|
+
slotDir.exp.content,
|
|
30
|
+
'template',
|
|
31
|
+
slotDir.exp.loc.start.offset,
|
|
32
|
+
ctx.codeFeatures.all,
|
|
33
|
+
];
|
|
34
|
+
yield `] = __VLS_getSlotParams(__VLS_thisSlot)${utils_1.endOfLine}`;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
yield `const `;
|
|
38
|
+
yield [
|
|
39
|
+
slotDir.exp.content,
|
|
40
|
+
'template',
|
|
41
|
+
slotDir.exp.loc.start.offset,
|
|
42
|
+
ctx.codeFeatures.all,
|
|
43
|
+
];
|
|
44
|
+
yield ` = __VLS_getSlotParam(__VLS_thisSlot)${utils_1.endOfLine}`;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
for (const varName of slotBlockVars) {
|
|
48
|
+
ctx.addLocalVariable(varName);
|
|
49
|
+
}
|
|
50
|
+
yield* ctx.resetDirectiveComments('end of slot children start');
|
|
51
|
+
let prev;
|
|
52
|
+
for (const childNode of node.children) {
|
|
53
|
+
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, prev);
|
|
54
|
+
prev = childNode;
|
|
55
|
+
}
|
|
56
|
+
for (const varName of slotBlockVars) {
|
|
57
|
+
ctx.removeLocalVariable(varName);
|
|
58
|
+
}
|
|
59
|
+
let isStatic = true;
|
|
60
|
+
if (slotDir.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
61
|
+
isStatic = slotDir.arg.isStatic;
|
|
62
|
+
}
|
|
63
|
+
if (isStatic && !slotDir.arg) {
|
|
64
|
+
yield `${ctx.currentComponent.ctxVar}.slots!['`;
|
|
65
|
+
yield [
|
|
66
|
+
'',
|
|
67
|
+
'template',
|
|
68
|
+
slotDir.loc.start.offset + (slotDir.loc.source.startsWith('#')
|
|
69
|
+
? '#'.length
|
|
70
|
+
: slotDir.loc.source.startsWith('v-slot:')
|
|
71
|
+
? 'v-slot:'.length
|
|
72
|
+
: 0),
|
|
73
|
+
ctx.codeFeatures.completion,
|
|
74
|
+
];
|
|
75
|
+
yield `'/* empty slot name completion */]${utils_1.endOfLine}`;
|
|
76
|
+
}
|
|
77
|
+
yield* ctx.generateAutoImportCompletion();
|
|
78
|
+
yield `}${utils_1.newLine}`;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=vSlot.js.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateCamelized = generateCamelized;
|
|
4
|
+
const shared_1 = require("@vue/shared");
|
|
5
|
+
const index_1 = require("./index");
|
|
6
|
+
function* generateCamelized(code, offset, info) {
|
|
7
|
+
const parts = code.split('-');
|
|
8
|
+
for (let i = 0; i < parts.length; i++) {
|
|
9
|
+
const part = parts[i];
|
|
10
|
+
if (part !== '') {
|
|
11
|
+
if (i === 0) {
|
|
12
|
+
yield [
|
|
13
|
+
part,
|
|
14
|
+
'template',
|
|
15
|
+
offset,
|
|
16
|
+
info,
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
yield [
|
|
21
|
+
(0, shared_1.capitalize)(part),
|
|
22
|
+
'template',
|
|
23
|
+
offset,
|
|
24
|
+
index_1.combineLastMapping,
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
offset += part.length + 1;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=camelized.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as CompilerDOM from '@vue/compiler-dom';
|
|
2
|
+
import type * as ts from 'typescript';
|
|
3
|
+
import type { Code, SfcBlock, VueCodeInformation } from '../../types';
|
|
4
|
+
export declare const newLine = "\n";
|
|
5
|
+
export declare const endOfLine = ";\n";
|
|
6
|
+
export declare const combineLastMapping: VueCodeInformation;
|
|
7
|
+
export declare const variableNameRegex: RegExp;
|
|
8
|
+
export declare function wrapWith(startOffset: number, endOffset: number, features: VueCodeInformation, ...wrapCodes: Code[]): Generator<Code>;
|
|
9
|
+
export declare function collectVars(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile, results?: string[]): string[];
|
|
10
|
+
export declare function collectIdentifiers(ts: typeof import('typescript'), node: ts.Node, results?: {
|
|
11
|
+
id: ts.Identifier;
|
|
12
|
+
isRest: boolean;
|
|
13
|
+
initializer: ts.Expression | undefined;
|
|
14
|
+
}[], isRest?: boolean, initializer?: ts.Expression | undefined): {
|
|
15
|
+
id: ts.Identifier;
|
|
16
|
+
isRest: boolean;
|
|
17
|
+
initializer: ts.Expression | undefined;
|
|
18
|
+
}[];
|
|
19
|
+
export declare function normalizeAttributeValue(node: CompilerDOM.TextNode): [string, number];
|
|
20
|
+
export declare function createTsAst(ts: typeof import('typescript'), astHolder: any, text: string): ts.SourceFile;
|
|
21
|
+
export declare function generateSfcBlockSection(block: SfcBlock, start: number, end: number, features: VueCodeInformation): Code;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.variableNameRegex = exports.combineLastMapping = exports.endOfLine = exports.newLine = void 0;
|
|
4
|
+
exports.wrapWith = wrapWith;
|
|
5
|
+
exports.collectVars = collectVars;
|
|
6
|
+
exports.collectIdentifiers = collectIdentifiers;
|
|
7
|
+
exports.normalizeAttributeValue = normalizeAttributeValue;
|
|
8
|
+
exports.createTsAst = createTsAst;
|
|
9
|
+
exports.generateSfcBlockSection = generateSfcBlockSection;
|
|
10
|
+
const scriptSetupRanges_1 = require("../../parsers/scriptSetupRanges");
|
|
11
|
+
exports.newLine = `\n`;
|
|
12
|
+
exports.endOfLine = `;${exports.newLine}`;
|
|
13
|
+
exports.combineLastMapping = { __combineLastMapping: true };
|
|
14
|
+
exports.variableNameRegex = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
|
|
15
|
+
function* wrapWith(startOffset, endOffset, features, ...wrapCodes) {
|
|
16
|
+
yield ['', 'template', startOffset, features];
|
|
17
|
+
let offset = 1;
|
|
18
|
+
for (const wrapCode of wrapCodes) {
|
|
19
|
+
if (typeof wrapCode !== 'string') {
|
|
20
|
+
offset++;
|
|
21
|
+
}
|
|
22
|
+
yield wrapCode;
|
|
23
|
+
}
|
|
24
|
+
yield ['', 'template', endOffset, { __combineOffsetMapping: offset }];
|
|
25
|
+
}
|
|
26
|
+
function collectVars(ts, node, ast, results = []) {
|
|
27
|
+
const identifiers = collectIdentifiers(ts, node, []);
|
|
28
|
+
for (const { id } of identifiers) {
|
|
29
|
+
results.push((0, scriptSetupRanges_1.getNodeText)(ts, id, ast));
|
|
30
|
+
}
|
|
31
|
+
return results;
|
|
32
|
+
}
|
|
33
|
+
function collectIdentifiers(ts, node, results = [], isRest = false, initializer = undefined) {
|
|
34
|
+
if (ts.isIdentifier(node)) {
|
|
35
|
+
results.push({ id: node, isRest, initializer });
|
|
36
|
+
}
|
|
37
|
+
else if (ts.isObjectBindingPattern(node)) {
|
|
38
|
+
for (const el of node.elements) {
|
|
39
|
+
collectIdentifiers(ts, el.name, results, !!el.dotDotDotToken, el.initializer);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else if (ts.isArrayBindingPattern(node)) {
|
|
43
|
+
for (const el of node.elements) {
|
|
44
|
+
if (ts.isBindingElement(el)) {
|
|
45
|
+
collectIdentifiers(ts, el.name, results, !!el.dotDotDotToken);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
ts.forEachChild(node, node => collectIdentifiers(ts, node, results, false));
|
|
51
|
+
}
|
|
52
|
+
return results;
|
|
53
|
+
}
|
|
54
|
+
function normalizeAttributeValue(node) {
|
|
55
|
+
let offset = node.loc.start.offset;
|
|
56
|
+
let content = node.loc.source;
|
|
57
|
+
if ((content.startsWith(`'`) && content.endsWith(`'`))
|
|
58
|
+
|| (content.startsWith(`"`) && content.endsWith(`"`))) {
|
|
59
|
+
offset++;
|
|
60
|
+
content = content.slice(1, -1);
|
|
61
|
+
}
|
|
62
|
+
return [content, offset];
|
|
63
|
+
}
|
|
64
|
+
function createTsAst(ts, astHolder, text) {
|
|
65
|
+
if (astHolder.__volar_ast_text !== text) {
|
|
66
|
+
astHolder.__volar_ast_text = text;
|
|
67
|
+
astHolder.__volar_ast = ts.createSourceFile('/a.ts', text, 99);
|
|
68
|
+
}
|
|
69
|
+
return astHolder.__volar_ast;
|
|
70
|
+
}
|
|
71
|
+
function generateSfcBlockSection(block, start, end, features) {
|
|
72
|
+
return [
|
|
73
|
+
block.content.slice(start, end),
|
|
74
|
+
block.name,
|
|
75
|
+
start,
|
|
76
|
+
features,
|
|
77
|
+
];
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateSfcBlockSrc = generateSfcBlockSrc;
|
|
4
|
+
function* generateSfcBlockSrc(src, text, features) {
|
|
5
|
+
const { offset, quotes } = src;
|
|
6
|
+
if (!quotes) {
|
|
7
|
+
yield [``, 'main', offset, { verification: true }];
|
|
8
|
+
}
|
|
9
|
+
yield [
|
|
10
|
+
quotes ? text : `'${text}'`,
|
|
11
|
+
'main',
|
|
12
|
+
quotes ? offset : offset - 1,
|
|
13
|
+
features
|
|
14
|
+
];
|
|
15
|
+
if (!quotes) {
|
|
16
|
+
yield [``, 'main', offset + text.length, { __combineOffsetMapping: 2 }];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=src.js.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateStringLiteralKey = generateStringLiteralKey;
|
|
4
|
-
const
|
|
4
|
+
const index_1 = require("./index");
|
|
5
5
|
function* generateStringLiteralKey(code, offset, info) {
|
|
6
6
|
if (offset === undefined || !info) {
|
|
7
|
-
yield `
|
|
7
|
+
yield `'${code}'`;
|
|
8
8
|
}
|
|
9
9
|
else {
|
|
10
|
-
yield* (0,
|
|
10
|
+
yield* (0, index_1.wrapWith)(offset, offset + code.length, info, `'`, [code, 'template', offset, index_1.combineLastMapping], `'`);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
//# sourceMappingURL=stringLiteralKey.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateUnicode = generateUnicode;
|
|
4
|
+
const index_1 = require("./index");
|
|
5
|
+
function* generateUnicode(code, offset, info) {
|
|
6
|
+
if (needToUnicode(code)) {
|
|
7
|
+
yield* (0, index_1.wrapWith)(offset, offset + code.length, info, toUnicode(code));
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
yield [code, 'template', offset, info];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function needToUnicode(str) {
|
|
14
|
+
return str.includes('\\') || str.includes('\n');
|
|
15
|
+
}
|
|
16
|
+
function toUnicode(str) {
|
|
17
|
+
return str.split('').map(value => {
|
|
18
|
+
const temp = value.charCodeAt(0).toString(16).padStart(4, '0');
|
|
19
|
+
if (temp.length > 2) {
|
|
20
|
+
return '\\u' + temp;
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
23
|
+
}).join('');
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=unicode.js.map
|
package/lib/languagePlugin.js
CHANGED
|
@@ -90,7 +90,7 @@ function createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFile
|
|
|
90
90
|
getServiceScript(root) {
|
|
91
91
|
for (const code of (0, language_core_1.forEachEmbeddedCode)(root)) {
|
|
92
92
|
if (/script_(js|jsx|ts|tsx)/.test(code.id)) {
|
|
93
|
-
const lang = code.id.
|
|
93
|
+
const lang = code.id.slice('script_'.length);
|
|
94
94
|
return {
|
|
95
95
|
code,
|
|
96
96
|
extension: '.' + lang,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { TextRange } from '../types';
|
|
2
1
|
import type * as ts from 'typescript';
|
|
2
|
+
import type { TextRange } from '../types';
|
|
3
3
|
export interface ScriptRanges extends ReturnType<typeof parseScriptRanges> {
|
|
4
4
|
}
|
|
5
5
|
export declare function parseScriptRanges(ts: typeof import('typescript'), ast: ts.SourceFile, hasScriptSetup: boolean, withNode: boolean): {
|
|
@@ -14,5 +14,10 @@ export declare function parseScriptRanges(ts: typeof import('typescript'), ast:
|
|
|
14
14
|
inheritAttrsOption: string | undefined;
|
|
15
15
|
}) | undefined;
|
|
16
16
|
classBlockEnd: number | undefined;
|
|
17
|
-
bindings:
|
|
17
|
+
bindings: {
|
|
18
|
+
range: TextRange;
|
|
19
|
+
moduleName?: string;
|
|
20
|
+
isDefaultImport?: boolean;
|
|
21
|
+
isNamespace?: boolean;
|
|
22
|
+
}[];
|
|
18
23
|
};
|