@vue/language-core 2.0.13 → 2.0.15
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 -1
- package/index.js +1 -1
- package/lib/codegen/common.d.ts +11 -0
- package/lib/codegen/common.js +70 -0
- package/lib/codegen/script/component.d.ts +9 -0
- package/lib/codegen/script/component.js +109 -0
- package/lib/codegen/script/context.d.ts +25 -0
- package/lib/codegen/script/context.js +124 -0
- package/lib/{generators → codegen/script}/globalTypes.d.ts +1 -1
- package/lib/codegen/script/globalTypes.js +135 -0
- package/lib/codegen/script/index.d.ts +33 -0
- package/lib/codegen/script/index.js +127 -0
- package/lib/codegen/script/internalComponent.d.ts +5 -0
- package/lib/codegen/script/internalComponent.js +58 -0
- package/lib/codegen/script/scriptSetup.d.ts +6 -0
- package/lib/codegen/script/scriptSetup.js +371 -0
- package/lib/codegen/script/src.d.ts +2 -0
- package/lib/codegen/script/src.js +52 -0
- package/lib/codegen/script/template.d.ts +5 -0
- package/lib/codegen/script/template.js +196 -0
- package/lib/codegen/template/camelized.d.ts +2 -0
- package/lib/codegen/template/camelized.js +32 -0
- package/lib/codegen/template/context.d.ts +44 -0
- package/lib/codegen/template/context.js +170 -0
- package/lib/codegen/template/element.d.ts +8 -0
- package/lib/codegen/template/element.js +378 -0
- package/lib/codegen/template/elementChildren.d.ts +5 -0
- package/lib/codegen/template/elementChildren.js +26 -0
- package/lib/codegen/template/elementDirectives.d.ts +5 -0
- package/lib/codegen/template/elementDirectives.js +46 -0
- package/lib/codegen/template/elementEvents.d.ts +9 -0
- package/lib/codegen/template/elementEvents.js +157 -0
- package/lib/codegen/template/elementProps.d.ts +5 -0
- package/lib/codegen/template/elementProps.js +275 -0
- package/lib/codegen/template/index.d.ts +60 -0
- package/lib/codegen/template/index.js +130 -0
- package/lib/codegen/template/interpolation.d.ts +6 -0
- package/lib/{utils/transform.js → codegen/template/interpolation.js} +76 -46
- package/lib/codegen/template/objectProperty.d.ts +4 -0
- package/lib/codegen/template/objectProperty.js +31 -0
- package/lib/codegen/template/propertyAccess.d.ts +4 -0
- package/lib/codegen/template/propertyAccess.js +24 -0
- package/lib/codegen/template/slotOutlet.d.ts +5 -0
- package/lib/codegen/template/slotOutlet.js +72 -0
- package/lib/codegen/template/stringLiteralKey.d.ts +2 -0
- package/lib/codegen/template/stringLiteralKey.js +14 -0
- package/lib/codegen/template/templateChild.d.ts +7 -0
- package/lib/codegen/template/templateChild.js +160 -0
- package/lib/codegen/template/vFor.d.ts +12 -0
- package/lib/codegen/template/vFor.js +69 -0
- package/lib/codegen/template/vIf.d.ts +5 -0
- package/lib/codegen/template/vIf.js +53 -0
- package/lib/languageModule.d.ts +3 -4
- package/lib/languageModule.js +31 -14
- package/lib/parsers/scriptSetupRanges.d.ts +1 -0
- package/lib/parsers/scriptSetupRanges.js +6 -1
- package/lib/plugins/file-html.js +63 -66
- package/lib/plugins/file-md.js +47 -50
- package/lib/plugins/shared.d.ts +2 -0
- package/lib/plugins/shared.js +12 -0
- package/lib/plugins/vue-sfc-customblocks.js +2 -2
- package/lib/plugins/vue-sfc-scripts.js +2 -3
- package/lib/plugins/vue-sfc-styles.js +3 -3
- package/lib/plugins/vue-sfc-template.js +2 -2
- package/lib/plugins/vue-template-inline-css.js +34 -2
- package/lib/plugins/vue-template-inline-ts.js +10 -8
- package/lib/plugins/vue-tsx.d.ts +43 -5
- package/lib/plugins/vue-tsx.js +38 -28
- package/lib/plugins.d.ts +2 -1
- package/lib/plugins.js +18 -9
- package/lib/types.d.ts +3 -3
- package/lib/utils/ts.js +20 -32
- package/lib/virtualFile/computedFiles.d.ts +2 -1
- package/lib/virtualFile/computedFiles.js +41 -15
- package/lib/virtualFile/computedMappings.js +3 -3
- package/lib/virtualFile/computedSfc.js +22 -1
- package/lib/virtualFile/embeddedFile.d.ts +2 -3
- package/lib/virtualFile/embeddedFile.js +1 -2
- package/lib/virtualFile/vueFile.d.ts +3 -5
- package/lib/virtualFile/vueFile.js +6 -8
- package/package.json +3 -3
- package/lib/generators/globalTypes.js +0 -135
- package/lib/generators/inlineCss.d.ts +0 -3
- package/lib/generators/inlineCss.js +0 -37
- package/lib/generators/script.d.ts +0 -13
- package/lib/generators/script.js +0 -981
- package/lib/generators/template.d.ts +0 -19
- package/lib/generators/template.js +0 -1578
- package/lib/generators/utils.d.ts +0 -5
- package/lib/generators/utils.js +0 -54
- package/lib/utils/transform.d.ts +0 -8
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Code, VueCodeInformation } from '../../types';
|
|
2
|
+
import type { TemplateCodegenContext } from './context';
|
|
3
|
+
import type { TemplateCodegenOptions } from './index';
|
|
4
|
+
export declare function generateObjectProperty(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, code: string, offset: number, features: VueCodeInformation, astHolder?: any, shouldCamelize?: boolean): Generator<Code>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateObjectProperty = void 0;
|
|
4
|
+
const shared_1 = require("@vue/shared");
|
|
5
|
+
const common_1 = require("../common");
|
|
6
|
+
const camelized_1 = require("./camelized");
|
|
7
|
+
const interpolation_1 = require("./interpolation");
|
|
8
|
+
const stringLiteralKey_1 = require("./stringLiteralKey");
|
|
9
|
+
function* generateObjectProperty(options, ctx, code, offset, features, astHolder, shouldCamelize = false) {
|
|
10
|
+
if (code.startsWith('[') && code.endsWith(']') && astHolder) {
|
|
11
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, code, astHolder, offset, features, '', '');
|
|
12
|
+
}
|
|
13
|
+
else if (shouldCamelize) {
|
|
14
|
+
if (common_1.variableNameRegex.test((0, shared_1.camelize)(code))) {
|
|
15
|
+
yield* (0, camelized_1.generateCamelized)(code, offset, features);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
yield* (0, common_1.wrapWith)(offset, offset + code.length, features, `"`, ...(0, camelized_1.generateCamelized)(code, offset, common_1.combineLastMapping), `"`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
if (common_1.variableNameRegex.test(code)) {
|
|
23
|
+
yield [code, 'template', offset, features];
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
yield* (0, stringLiteralKey_1.generateStringLiteralKey)(code, offset, features);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.generateObjectProperty = generateObjectProperty;
|
|
31
|
+
//# sourceMappingURL=objectProperty.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Code, VueCodeInformation } from '../../types';
|
|
2
|
+
import type { TemplateCodegenContext } from './context';
|
|
3
|
+
import type { TemplateCodegenOptions } from './index';
|
|
4
|
+
export declare function generatePropertyAccess(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, code: string, offset?: number, features?: VueCodeInformation, astHolder?: any): Generator<Code>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generatePropertyAccess = void 0;
|
|
4
|
+
const common_1 = require("../common");
|
|
5
|
+
const interpolation_1 = require("./interpolation");
|
|
6
|
+
const stringLiteralKey_1 = require("./stringLiteralKey");
|
|
7
|
+
function* generatePropertyAccess(options, ctx, code, offset, features, astHolder) {
|
|
8
|
+
if (!options.compilerOptions.noPropertyAccessFromIndexSignature && common_1.variableNameRegex.test(code)) {
|
|
9
|
+
yield `.`;
|
|
10
|
+
yield offset !== undefined && features
|
|
11
|
+
? [code, 'template', offset, features]
|
|
12
|
+
: code;
|
|
13
|
+
}
|
|
14
|
+
else if (code.startsWith('[') && code.endsWith(']')) {
|
|
15
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, code, astHolder, offset, features, '', '');
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
yield `[`;
|
|
19
|
+
yield* (0, stringLiteralKey_1.generateStringLiteralKey)(code, offset, features);
|
|
20
|
+
yield `]`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.generatePropertyAccess = generatePropertyAccess;
|
|
24
|
+
//# sourceMappingURL=propertyAccess.js.map
|
|
@@ -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 generateSlotOutlet(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.SlotOutletNode, currentComponent: CompilerDOM.ElementNode | undefined, componentCtxVar: string | undefined): Generator<Code>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateSlotOutlet = void 0;
|
|
4
|
+
const CompilerDOM = require("@vue/compiler-dom");
|
|
5
|
+
const common_1 = require("../common");
|
|
6
|
+
const elementChildren_1 = require("./elementChildren");
|
|
7
|
+
const elementProps_1 = require("./elementProps");
|
|
8
|
+
const interpolation_1 = require("./interpolation");
|
|
9
|
+
function* generateSlotOutlet(options, ctx, node, currentComponent, componentCtxVar) {
|
|
10
|
+
const startTagOffset = node.loc.start.offset + options.template.content.substring(node.loc.start.offset).indexOf(node.tag);
|
|
11
|
+
const varSlot = ctx.getInternalVariable();
|
|
12
|
+
const nameProp = node.props.find(prop => {
|
|
13
|
+
if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE) {
|
|
14
|
+
return prop.name === 'name';
|
|
15
|
+
}
|
|
16
|
+
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
17
|
+
&& prop.name === 'bind'
|
|
18
|
+
&& prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
19
|
+
return prop.arg.content === 'name';
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
if (options.hasDefineSlots) {
|
|
23
|
+
yield `__VLS_normalizeSlot(`;
|
|
24
|
+
yield* (0, common_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, ctx.codeFeatures.verification, `${options.slotsAssignName ?? '__VLS_slots'}[`, ...(0, common_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, ctx.codeFeatures.verification, nameProp?.type === CompilerDOM.NodeTypes.ATTRIBUTE && nameProp.value
|
|
25
|
+
? `'${nameProp.value.content}'`
|
|
26
|
+
: nameProp?.type === CompilerDOM.NodeTypes.DIRECTIVE && nameProp.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
27
|
+
? nameProp.exp.content
|
|
28
|
+
: `('default' as const)`), `]`);
|
|
29
|
+
yield `)?.(`;
|
|
30
|
+
yield* (0, common_1.wrapWith)(startTagOffset, startTagOffset + node.tag.length, ctx.codeFeatures.verification, `{${common_1.newLine}`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), true), `}`);
|
|
31
|
+
yield `)${common_1.endOfLine}`;
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
yield `var ${varSlot} = {${common_1.newLine}`;
|
|
36
|
+
yield* (0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), true);
|
|
37
|
+
yield `}${common_1.endOfLine}`;
|
|
38
|
+
}
|
|
39
|
+
if (nameProp?.type === CompilerDOM.NodeTypes.ATTRIBUTE
|
|
40
|
+
&& nameProp.value) {
|
|
41
|
+
ctx.slots.push({
|
|
42
|
+
name: nameProp.value.content,
|
|
43
|
+
loc: nameProp.loc.start.offset + nameProp.loc.source.indexOf(nameProp.value.content, nameProp.name.length),
|
|
44
|
+
tagRange: [startTagOffset, startTagOffset + node.tag.length],
|
|
45
|
+
varName: varSlot,
|
|
46
|
+
nodeLoc: node.loc,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
else if (nameProp?.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
50
|
+
&& nameProp.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
51
|
+
const slotExpVar = ctx.getInternalVariable();
|
|
52
|
+
yield `var ${slotExpVar} = `;
|
|
53
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, nameProp.exp.content, nameProp.exp, nameProp.exp.loc.start.offset, ctx.codeFeatures.all, '(', ')');
|
|
54
|
+
yield ` as const${common_1.endOfLine}`;
|
|
55
|
+
ctx.dynamicSlots.push({
|
|
56
|
+
expVar: slotExpVar,
|
|
57
|
+
varName: varSlot,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
ctx.slots.push({
|
|
62
|
+
name: 'default',
|
|
63
|
+
tagRange: [startTagOffset, startTagOffset + node.tag.length],
|
|
64
|
+
varName: varSlot,
|
|
65
|
+
nodeLoc: node.loc,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
yield* ctx.generateAutoImportCompletion();
|
|
69
|
+
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node, currentComponent, componentCtxVar);
|
|
70
|
+
}
|
|
71
|
+
exports.generateSlotOutlet = generateSlotOutlet;
|
|
72
|
+
//# sourceMappingURL=slotOutlet.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateStringLiteralKey = void 0;
|
|
4
|
+
const common_1 = require("../common");
|
|
5
|
+
function* generateStringLiteralKey(code, offset, info) {
|
|
6
|
+
if (offset === undefined || !info) {
|
|
7
|
+
yield `"${code}"`;
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
yield* (0, common_1.wrapWith)(offset, offset + code.length, info, `"`, [code, 'template', offset, common_1.combineLastMapping], `"`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.generateStringLiteralKey = generateStringLiteralKey;
|
|
14
|
+
//# sourceMappingURL=stringLiteralKey.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
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 generateTemplateChild(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode, currentComponent: CompilerDOM.ElementNode | undefined, prevNode: CompilerDOM.TemplateChildNode | undefined, componentCtxVar: string | undefined): Generator<Code>;
|
|
6
|
+
export declare function getVForNode(node: CompilerDOM.ElementNode): CompilerDOM.ForNode | undefined;
|
|
7
|
+
export declare function parseInterpolationNode(node: CompilerDOM.InterpolationNode, template: string): readonly [string, number];
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseInterpolationNode = exports.getVForNode = exports.generateTemplateChild = void 0;
|
|
4
|
+
const CompilerDOM = require("@vue/compiler-dom");
|
|
5
|
+
const common_1 = require("../common");
|
|
6
|
+
const element_1 = require("./element");
|
|
7
|
+
const interpolation_1 = require("./interpolation");
|
|
8
|
+
const slotOutlet_1 = require("./slotOutlet");
|
|
9
|
+
const vFor_1 = require("./vFor");
|
|
10
|
+
const vIf_1 = require("./vIf");
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
const transformContext = {
|
|
13
|
+
onError: () => { },
|
|
14
|
+
helperString: str => str.toString(),
|
|
15
|
+
replaceNode: () => { },
|
|
16
|
+
cacheHandlers: false,
|
|
17
|
+
prefixIdentifiers: false,
|
|
18
|
+
scopes: {
|
|
19
|
+
vFor: 0,
|
|
20
|
+
vOnce: 0,
|
|
21
|
+
vPre: 0,
|
|
22
|
+
vSlot: 0,
|
|
23
|
+
},
|
|
24
|
+
expressionPlugins: ['typescript'],
|
|
25
|
+
};
|
|
26
|
+
function* generateTemplateChild(options, ctx, node, currentComponent, prevNode, componentCtxVar) {
|
|
27
|
+
if (prevNode?.type === CompilerDOM.NodeTypes.COMMENT) {
|
|
28
|
+
const commentText = prevNode.content.trim().split(' ')[0];
|
|
29
|
+
if (commentText.match(/^@vue-skip\b[\s\S]*/)) {
|
|
30
|
+
yield `// @vue-skip${common_1.newLine}`;
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
else if (commentText.match(/^@vue-ignore\b[\s\S]*/)) {
|
|
34
|
+
yield* ctx.ignoreError();
|
|
35
|
+
}
|
|
36
|
+
else if (commentText.match(/^@vue-expect-error\b[\s\S]*/)) {
|
|
37
|
+
yield* ctx.expectError(prevNode);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (node.type === CompilerDOM.NodeTypes.ROOT) {
|
|
41
|
+
let prev;
|
|
42
|
+
for (const childNode of node.children) {
|
|
43
|
+
yield* generateTemplateChild(options, ctx, childNode, currentComponent, prev, componentCtxVar);
|
|
44
|
+
prev = childNode;
|
|
45
|
+
}
|
|
46
|
+
yield* ctx.resetDirectiveComments('end of root');
|
|
47
|
+
}
|
|
48
|
+
else if (node.type === CompilerDOM.NodeTypes.ELEMENT) {
|
|
49
|
+
const vForNode = getVForNode(node);
|
|
50
|
+
const vIfNode = getVIfNode(node);
|
|
51
|
+
if (vForNode) {
|
|
52
|
+
yield* (0, vFor_1.generateVFor)(options, ctx, vForNode, currentComponent, componentCtxVar);
|
|
53
|
+
}
|
|
54
|
+
else if (vIfNode) {
|
|
55
|
+
yield* (0, vIf_1.generateVIf)(options, ctx, vIfNode, currentComponent, componentCtxVar);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
if (node.tagType === CompilerDOM.ElementTypes.SLOT) {
|
|
59
|
+
yield* (0, slotOutlet_1.generateSlotOutlet)(options, ctx, node, currentComponent, componentCtxVar);
|
|
60
|
+
}
|
|
61
|
+
else if (node.tagType === CompilerDOM.ElementTypes.ELEMENT
|
|
62
|
+
|| node.tagType === CompilerDOM.ElementTypes.TEMPLATE) {
|
|
63
|
+
yield* (0, element_1.generateElement)(options, ctx, node, currentComponent, componentCtxVar);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
yield* (0, element_1.generateComponent)(options, ctx, node, currentComponent, componentCtxVar);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else if (node.type === CompilerDOM.NodeTypes.TEXT_CALL) {
|
|
71
|
+
// {{ var }}
|
|
72
|
+
yield* generateTemplateChild(options, ctx, node.content, currentComponent, undefined, componentCtxVar);
|
|
73
|
+
}
|
|
74
|
+
else if (node.type === CompilerDOM.NodeTypes.COMPOUND_EXPRESSION) {
|
|
75
|
+
// {{ ... }} {{ ... }}
|
|
76
|
+
for (const childNode of node.children) {
|
|
77
|
+
if (typeof childNode === 'object') {
|
|
78
|
+
yield* generateTemplateChild(options, ctx, childNode, currentComponent, undefined, componentCtxVar);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else if (node.type === CompilerDOM.NodeTypes.INTERPOLATION) {
|
|
83
|
+
// {{ ... }}
|
|
84
|
+
const [content, start] = parseInterpolationNode(node, options.template.content);
|
|
85
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, content, node.content.loc, start, ctx.codeFeatures.all, `(`, `)${common_1.endOfLine}`);
|
|
86
|
+
yield* ctx.resetDirectiveComments('end of INTERPOLATION');
|
|
87
|
+
}
|
|
88
|
+
else if (node.type === CompilerDOM.NodeTypes.IF) {
|
|
89
|
+
// v-if / v-else-if / v-else
|
|
90
|
+
yield* (0, vIf_1.generateVIf)(options, ctx, node, currentComponent, componentCtxVar);
|
|
91
|
+
}
|
|
92
|
+
else if (node.type === CompilerDOM.NodeTypes.FOR) {
|
|
93
|
+
// v-for
|
|
94
|
+
yield* (0, vFor_1.generateVFor)(options, ctx, node, currentComponent, componentCtxVar);
|
|
95
|
+
}
|
|
96
|
+
else if (node.type === CompilerDOM.NodeTypes.TEXT) {
|
|
97
|
+
// not needed progress
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.generateTemplateChild = generateTemplateChild;
|
|
101
|
+
// TODO: track https://github.com/vuejs/vue-next/issues/3498
|
|
102
|
+
function getVForNode(node) {
|
|
103
|
+
const forDirective = node.props.find((prop) => prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
104
|
+
&& prop.name === 'for');
|
|
105
|
+
if (forDirective) {
|
|
106
|
+
let forNode;
|
|
107
|
+
CompilerDOM.processFor(node, forDirective, transformContext, _forNode => {
|
|
108
|
+
forNode = { ..._forNode };
|
|
109
|
+
return undefined;
|
|
110
|
+
});
|
|
111
|
+
if (forNode) {
|
|
112
|
+
forNode.children = [{
|
|
113
|
+
...node,
|
|
114
|
+
props: node.props.filter(prop => prop !== forDirective),
|
|
115
|
+
}];
|
|
116
|
+
return forNode;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.getVForNode = getVForNode;
|
|
121
|
+
function getVIfNode(node) {
|
|
122
|
+
const forDirective = node.props.find((prop) => prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
123
|
+
&& prop.name === 'if');
|
|
124
|
+
if (forDirective) {
|
|
125
|
+
let ifNode;
|
|
126
|
+
CompilerDOM.processIf(node, forDirective, transformContext, _ifNode => {
|
|
127
|
+
ifNode = { ..._ifNode };
|
|
128
|
+
return undefined;
|
|
129
|
+
});
|
|
130
|
+
if (ifNode) {
|
|
131
|
+
for (const branch of ifNode.branches) {
|
|
132
|
+
branch.children = [{
|
|
133
|
+
...node,
|
|
134
|
+
props: node.props.filter(prop => prop !== forDirective),
|
|
135
|
+
}];
|
|
136
|
+
}
|
|
137
|
+
return ifNode;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function parseInterpolationNode(node, template) {
|
|
142
|
+
let content = node.content.loc.source;
|
|
143
|
+
let start = node.content.loc.start.offset;
|
|
144
|
+
let leftCharacter;
|
|
145
|
+
let rightCharacter;
|
|
146
|
+
// fix https://github.com/vuejs/language-tools/issues/1787
|
|
147
|
+
while ((leftCharacter = template.substring(start - 1, start)).trim() === '' && leftCharacter.length) {
|
|
148
|
+
start--;
|
|
149
|
+
content = leftCharacter + content;
|
|
150
|
+
}
|
|
151
|
+
while ((rightCharacter = template.substring(start + content.length, start + content.length + 1)).trim() === '' && rightCharacter.length) {
|
|
152
|
+
content = content + rightCharacter;
|
|
153
|
+
}
|
|
154
|
+
return [
|
|
155
|
+
content,
|
|
156
|
+
start,
|
|
157
|
+
];
|
|
158
|
+
}
|
|
159
|
+
exports.parseInterpolationNode = parseInterpolationNode;
|
|
160
|
+
//# sourceMappingURL=templateChild.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
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 generateVFor(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ForNode, currentComponent: CompilerDOM.ElementNode | undefined, componentCtxVar: string | undefined): Generator<Code>;
|
|
6
|
+
export declare function parseVForNode(node: CompilerDOM.ForNode): {
|
|
7
|
+
leftExpressionRange: {
|
|
8
|
+
start: number;
|
|
9
|
+
end: number;
|
|
10
|
+
} | undefined;
|
|
11
|
+
leftExpressionText: string | undefined;
|
|
12
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseVForNode = exports.generateVFor = void 0;
|
|
4
|
+
const CompilerDOM = require("@vue/compiler-dom");
|
|
5
|
+
const common_1 = require("../common");
|
|
6
|
+
const index_1 = require("./index");
|
|
7
|
+
const interpolation_1 = require("./interpolation");
|
|
8
|
+
const templateChild_1 = require("./templateChild");
|
|
9
|
+
function* generateVFor(options, ctx, node, currentComponent, componentCtxVar) {
|
|
10
|
+
const { source } = node.parseResult;
|
|
11
|
+
const { leftExpressionRange, leftExpressionText } = parseVForNode(node);
|
|
12
|
+
const forBlockVars = [];
|
|
13
|
+
yield `for (const [`;
|
|
14
|
+
if (leftExpressionRange && leftExpressionText) {
|
|
15
|
+
const collectAst = (0, common_1.createTsAst)(options.ts, node.parseResult, `const [${leftExpressionText}]`);
|
|
16
|
+
(0, common_1.collectVars)(options.ts, collectAst, collectAst, forBlockVars);
|
|
17
|
+
yield [
|
|
18
|
+
leftExpressionText,
|
|
19
|
+
'template',
|
|
20
|
+
leftExpressionRange.start,
|
|
21
|
+
ctx.codeFeatures.all,
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
yield `] of `;
|
|
25
|
+
if (source.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
26
|
+
yield `__VLS_getVForSourceType(`;
|
|
27
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, source.content, source.loc, source.loc.start.offset, ctx.codeFeatures.all, '(', ')');
|
|
28
|
+
yield `!)`; // #3102
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
yield `{} as any`;
|
|
32
|
+
}
|
|
33
|
+
yield `) {${common_1.newLine}`;
|
|
34
|
+
if ((0, index_1.isFragment)(node)) {
|
|
35
|
+
yield* ctx.resetDirectiveComments('end of v-for start');
|
|
36
|
+
}
|
|
37
|
+
for (const varName of forBlockVars) {
|
|
38
|
+
ctx.addLocalVariable(varName);
|
|
39
|
+
}
|
|
40
|
+
let prev;
|
|
41
|
+
for (const childNode of node.children) {
|
|
42
|
+
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, currentComponent, prev, componentCtxVar);
|
|
43
|
+
prev = childNode;
|
|
44
|
+
}
|
|
45
|
+
for (const varName of forBlockVars) {
|
|
46
|
+
ctx.removeLocalVariable(varName);
|
|
47
|
+
}
|
|
48
|
+
yield* ctx.generateAutoImportCompletion();
|
|
49
|
+
yield `}${common_1.newLine}`;
|
|
50
|
+
}
|
|
51
|
+
exports.generateVFor = generateVFor;
|
|
52
|
+
function parseVForNode(node) {
|
|
53
|
+
const { value, key, index } = node.parseResult;
|
|
54
|
+
const leftExpressionRange = (value || key || index)
|
|
55
|
+
? {
|
|
56
|
+
start: (value ?? key ?? index).loc.start.offset,
|
|
57
|
+
end: (index ?? key ?? value).loc.end.offset,
|
|
58
|
+
}
|
|
59
|
+
: undefined;
|
|
60
|
+
const leftExpressionText = leftExpressionRange
|
|
61
|
+
? node.loc.source.substring(leftExpressionRange.start - node.loc.start.offset, leftExpressionRange.end - node.loc.start.offset)
|
|
62
|
+
: undefined;
|
|
63
|
+
return {
|
|
64
|
+
leftExpressionRange,
|
|
65
|
+
leftExpressionText,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
exports.parseVForNode = parseVForNode;
|
|
69
|
+
//# sourceMappingURL=vFor.js.map
|
|
@@ -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 generateVIf(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.IfNode, currentComponent: CompilerDOM.ElementNode | undefined, componentCtxVar: string | undefined): Generator<Code>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateVIf = void 0;
|
|
4
|
+
const language_core_1 = require("@volar/language-core");
|
|
5
|
+
const CompilerDOM = require("@vue/compiler-dom");
|
|
6
|
+
const common_1 = require("../common");
|
|
7
|
+
const index_1 = require("./index");
|
|
8
|
+
const interpolation_1 = require("./interpolation");
|
|
9
|
+
const templateChild_1 = require("./templateChild");
|
|
10
|
+
function* generateVIf(options, ctx, node, currentComponent, componentCtxVar) {
|
|
11
|
+
let originalBlockConditionsLength = ctx.blockConditions.length;
|
|
12
|
+
for (let i = 0; i < node.branches.length; i++) {
|
|
13
|
+
const branch = node.branches[i];
|
|
14
|
+
if (i === 0) {
|
|
15
|
+
yield `if `;
|
|
16
|
+
}
|
|
17
|
+
else if (branch.condition) {
|
|
18
|
+
yield `else if `;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
yield `else `;
|
|
22
|
+
}
|
|
23
|
+
let addedBlockCondition = false;
|
|
24
|
+
if (branch.condition?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
25
|
+
const codes = [
|
|
26
|
+
...(0, interpolation_1.generateInterpolation)(options, ctx, branch.condition.content, branch.condition.loc, branch.condition.loc.start.offset, ctx.codeFeatures.all, '(', ')'),
|
|
27
|
+
];
|
|
28
|
+
for (const code of codes) {
|
|
29
|
+
yield code;
|
|
30
|
+
}
|
|
31
|
+
ctx.blockConditions.push((0, language_core_1.toString)(codes));
|
|
32
|
+
addedBlockCondition = true;
|
|
33
|
+
yield ` `;
|
|
34
|
+
}
|
|
35
|
+
yield `{${common_1.newLine}`;
|
|
36
|
+
if ((0, index_1.isFragment)(node)) {
|
|
37
|
+
yield* ctx.resetDirectiveComments('end of v-if start');
|
|
38
|
+
}
|
|
39
|
+
let prev;
|
|
40
|
+
for (const childNode of branch.children) {
|
|
41
|
+
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, currentComponent, prev, componentCtxVar);
|
|
42
|
+
prev = childNode;
|
|
43
|
+
}
|
|
44
|
+
yield* ctx.generateAutoImportCompletion();
|
|
45
|
+
yield `}${common_1.newLine}`;
|
|
46
|
+
if (addedBlockCondition) {
|
|
47
|
+
ctx.blockConditions[ctx.blockConditions.length - 1] = `!(${ctx.blockConditions[ctx.blockConditions.length - 1]})`;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
ctx.blockConditions.length = originalBlockConditionsLength;
|
|
51
|
+
}
|
|
52
|
+
exports.generateVIf = generateVIf;
|
|
53
|
+
//# sourceMappingURL=vIf.js.map
|
package/lib/languageModule.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { type LanguagePlugin } from '@volar/language-core';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
3
|
import type { VueCompilerOptions, VueLanguagePlugin } from './types';
|
|
4
|
-
import {
|
|
5
|
-
interface _Plugin extends LanguagePlugin<
|
|
4
|
+
import { VueVirtualCode } from './virtualFile/vueFile';
|
|
5
|
+
export interface _Plugin extends LanguagePlugin<VueVirtualCode> {
|
|
6
6
|
getCanonicalFileName: (fileName: string) => string;
|
|
7
7
|
pluginContext: Parameters<VueLanguagePlugin>[0];
|
|
8
8
|
}
|
|
9
|
-
export declare function createVueLanguagePlugin(ts: typeof import('typescript'), getFileName: (fileId: string) => string, useCaseSensitiveFileNames: boolean, getProjectVersion: () => string, getScriptFileNames: () => string[] | Set<string>, compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions
|
|
10
|
-
export {};
|
|
9
|
+
export declare function createVueLanguagePlugin(ts: typeof import('typescript'), getFileName: (fileId: string) => string, useCaseSensitiveFileNames: boolean, getProjectVersion: () => string, getScriptFileNames: () => string[] | Set<string>, compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions): _Plugin;
|
package/lib/languageModule.js
CHANGED
|
@@ -6,6 +6,9 @@ const plugins_1 = require("./plugins");
|
|
|
6
6
|
const vueFile_1 = require("./virtualFile/vueFile");
|
|
7
7
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
8
8
|
const CompilerVue2 = require("./utils/vue2TemplateCompiler");
|
|
9
|
+
const file_html_1 = require("./plugins/file-html");
|
|
10
|
+
const file_md_1 = require("./plugins/file-md");
|
|
11
|
+
const file_vue_1 = require("./plugins/file-vue");
|
|
9
12
|
const normalFileRegistries = [];
|
|
10
13
|
const holderFileRegistries = [];
|
|
11
14
|
function getVueFileRegistry(isGlobalTypesHolder, key, plugins) {
|
|
@@ -35,8 +38,7 @@ function getFileRegistryKey(compilerOptions, vueCompilerOptions, plugins) {
|
|
|
35
38
|
];
|
|
36
39
|
return JSON.stringify(values);
|
|
37
40
|
}
|
|
38
|
-
function createVueLanguagePlugin(ts, getFileName, useCaseSensitiveFileNames, getProjectVersion, getScriptFileNames, compilerOptions, vueCompilerOptions
|
|
39
|
-
const allowLanguageIds = new Set(['vue']);
|
|
41
|
+
function createVueLanguagePlugin(ts, getFileName, useCaseSensitiveFileNames, getProjectVersion, getScriptFileNames, compilerOptions, vueCompilerOptions) {
|
|
40
42
|
const pluginContext = {
|
|
41
43
|
modules: {
|
|
42
44
|
'@vue/compiler-dom': vueCompilerOptions.target < 3
|
|
@@ -49,16 +51,12 @@ function createVueLanguagePlugin(ts, getFileName, useCaseSensitiveFileNames, get
|
|
|
49
51
|
},
|
|
50
52
|
compilerOptions,
|
|
51
53
|
vueCompilerOptions,
|
|
52
|
-
codegenStack,
|
|
53
54
|
globalTypesHolder: undefined,
|
|
54
55
|
};
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (vueCompilerOptions.extensions.includes('.html')) {
|
|
60
|
-
allowLanguageIds.add('html');
|
|
61
|
-
}
|
|
56
|
+
const basePlugins = (0, plugins_1.getBasePlugins)(pluginContext);
|
|
57
|
+
const vueSfcPlugin = (0, file_vue_1.default)(pluginContext);
|
|
58
|
+
const vitePressSfcPlugin = (0, file_md_1.default)(pluginContext);
|
|
59
|
+
const petiteVueSfcPlugin = (0, file_html_1.default)(pluginContext);
|
|
62
60
|
const getCanonicalFileName = useCaseSensitiveFileNames
|
|
63
61
|
? (fileName) => fileName
|
|
64
62
|
: (fileName) => fileName.toLowerCase();
|
|
@@ -67,8 +65,19 @@ function createVueLanguagePlugin(ts, getFileName, useCaseSensitiveFileNames, get
|
|
|
67
65
|
return {
|
|
68
66
|
getCanonicalFileName,
|
|
69
67
|
pluginContext,
|
|
68
|
+
getLanguageId(scriptId) {
|
|
69
|
+
if (vueCompilerOptions.extensions.some(ext => scriptId.endsWith(ext))) {
|
|
70
|
+
return 'vue';
|
|
71
|
+
}
|
|
72
|
+
if (vueCompilerOptions.vitePressExtensions.some(ext => scriptId.endsWith(ext))) {
|
|
73
|
+
return 'markdown';
|
|
74
|
+
}
|
|
75
|
+
if (vueCompilerOptions.petiteVueExtensions.some(ext => scriptId.endsWith(ext))) {
|
|
76
|
+
return 'html';
|
|
77
|
+
}
|
|
78
|
+
},
|
|
70
79
|
createVirtualCode(fileId, languageId, snapshot) {
|
|
71
|
-
if (
|
|
80
|
+
if (languageId === 'vue' || languageId === 'markdown' || languageId === 'html') {
|
|
72
81
|
const fileName = getFileName(fileId);
|
|
73
82
|
const projectVersion = getProjectVersion();
|
|
74
83
|
if (projectVersion !== canonicalRootFileNamesVersion) {
|
|
@@ -85,7 +94,11 @@ function createVueLanguagePlugin(ts, getFileName, useCaseSensitiveFileNames, get
|
|
|
85
94
|
return code;
|
|
86
95
|
}
|
|
87
96
|
else {
|
|
88
|
-
const code = new vueFile_1.
|
|
97
|
+
const code = new vueFile_1.VueVirtualCode(fileName, languageId, snapshot, vueCompilerOptions, languageId === 'html'
|
|
98
|
+
? [petiteVueSfcPlugin, ...basePlugins]
|
|
99
|
+
: languageId === 'markdown'
|
|
100
|
+
? [vitePressSfcPlugin, ...basePlugins]
|
|
101
|
+
: [vueSfcPlugin, ...basePlugins], ts);
|
|
89
102
|
fileRegistry.set(fileId, code);
|
|
90
103
|
return code;
|
|
91
104
|
}
|
|
@@ -120,7 +133,11 @@ function createVueLanguagePlugin(ts, getFileName, useCaseSensitiveFileNames, get
|
|
|
120
133
|
// }
|
|
121
134
|
// },
|
|
122
135
|
typescript: {
|
|
123
|
-
extraFileExtensions:
|
|
136
|
+
extraFileExtensions: [
|
|
137
|
+
...vueCompilerOptions.extensions,
|
|
138
|
+
...vueCompilerOptions.vitePressExtensions,
|
|
139
|
+
...vueCompilerOptions.petiteVueExtensions,
|
|
140
|
+
].map(ext => ({
|
|
124
141
|
extension: ext.slice(1),
|
|
125
142
|
isMixedContent: true,
|
|
126
143
|
scriptKind: 7,
|
|
@@ -143,7 +160,7 @@ function createVueLanguagePlugin(ts, getFileName, useCaseSensitiveFileNames, get
|
|
|
143
160
|
},
|
|
144
161
|
};
|
|
145
162
|
function getFileRegistry(isGlobalTypesHolder) {
|
|
146
|
-
return getVueFileRegistry(isGlobalTypesHolder, getFileRegistryKey(compilerOptions, vueCompilerOptions,
|
|
163
|
+
return getVueFileRegistry(isGlobalTypesHolder, getFileRegistryKey(compilerOptions, vueCompilerOptions, basePlugins), vueCompilerOptions.plugins);
|
|
147
164
|
}
|
|
148
165
|
}
|
|
149
166
|
exports.createVueLanguagePlugin = createVueLanguagePlugin;
|
|
@@ -20,6 +20,7 @@ export declare function parseScriptSetupRanges(ts: typeof import('typescript'),
|
|
|
20
20
|
};
|
|
21
21
|
slots: {
|
|
22
22
|
name?: string | undefined;
|
|
23
|
+
isObjectBindingPattern?: boolean | undefined;
|
|
23
24
|
define?: (TextRange & {
|
|
24
25
|
arg?: TextRange | undefined;
|
|
25
26
|
typeArg?: TextRange | undefined;
|
|
@@ -139,7 +139,12 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
|
|
|
139
139
|
else if (vueCompilerOptions.macros.defineSlots.includes(callText)) {
|
|
140
140
|
slots.define = parseDefineFunction(node);
|
|
141
141
|
if (ts.isVariableDeclaration(parent)) {
|
|
142
|
-
|
|
142
|
+
if (ts.isIdentifier(parent.name)) {
|
|
143
|
+
slots.name = getNodeText(ts, parent.name, ast);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
slots.isObjectBindingPattern = ts.isObjectBindingPattern(parent.name);
|
|
147
|
+
}
|
|
143
148
|
}
|
|
144
149
|
}
|
|
145
150
|
else if (vueCompilerOptions.macros.defineEmits.includes(callText)) {
|