@vue/language-core 2.1.8 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/codegen/globalTypes.js +12 -5
- package/lib/codegen/localTypes.js +3 -3
- package/lib/codegen/script/component.js +42 -42
- package/lib/codegen/script/componentSelf.js +14 -13
- package/lib/codegen/script/context.js +2 -2
- package/lib/codegen/script/index.d.ts +5 -3
- package/lib/codegen/script/index.js +24 -37
- package/lib/codegen/script/scriptSetup.js +240 -193
- package/lib/codegen/script/src.js +6 -6
- package/lib/codegen/script/styleModulesType.js +5 -5
- package/lib/codegen/script/template.d.ts +1 -1
- package/lib/codegen/script/template.js +89 -99
- package/lib/codegen/template/context.d.ts +13 -3
- package/lib/codegen/template/context.js +21 -12
- package/lib/codegen/template/element.d.ts +2 -4
- package/lib/codegen/template/element.js +132 -105
- package/lib/codegen/template/elementChildren.d.ts +1 -1
- package/lib/codegen/template/elementChildren.js +8 -8
- package/lib/codegen/template/elementDirectives.d.ts +1 -0
- package/lib/codegen/template/elementDirectives.js +28 -22
- package/lib/codegen/template/elementEvents.d.ts +2 -2
- package/lib/codegen/template/elementEvents.js +32 -65
- package/lib/codegen/template/elementProps.d.ts +3 -2
- package/lib/codegen/template/elementProps.js +119 -122
- package/lib/codegen/template/index.js +52 -60
- package/lib/codegen/template/interpolation.d.ts +5 -3
- package/lib/codegen/template/interpolation.js +18 -19
- 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 +13 -13
- package/lib/codegen/template/styleScopedClasses.d.ts +1 -1
- package/lib/codegen/template/styleScopedClasses.js +11 -8
- package/lib/codegen/template/templateChild.d.ts +1 -1
- package/lib/codegen/template/templateChild.js +31 -19
- 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 → utils}/camelized.js +2 -2
- package/lib/codegen/{common.d.ts → utils/index.d.ts} +1 -2
- package/lib/codegen/{common.js → utils/index.js} +4 -15
- 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 +67 -81
- package/lib/parsers/scriptSetupRanges.js +195 -166
- 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-template-html.js +6 -2
- package/lib/plugins/vue-template-inline-css.js +1 -1
- package/lib/plugins/vue-template-inline-ts.js +13 -5
- package/lib/plugins/vue-tsx.d.ts +101 -72
- package/lib/plugins/vue-tsx.js +65 -69
- package/lib/types.d.ts +19 -10
- package/lib/utils/buildMappings.d.ts +1 -1
- package/lib/utils/parseSfc.d.ts +5 -0
- package/lib/utils/parseSfc.js +7 -2
- package/lib/utils/ts.d.ts +1 -1
- package/lib/utils/ts.js +38 -24
- package/lib/virtualFile/computedEmbeddedCodes.d.ts +1 -2
- package/lib/virtualFile/computedSfc.js +23 -12
- package/lib/virtualFile/computedVueSfc.d.ts +1 -1
- package/lib/virtualFile/vueFile.d.ts +3 -3
- package/package.json +5 -5
- package/lib/codegen/types.d.ts +0 -9
- package/lib/codegen/types.js +0 -3
- package/lib/utils/findDestructuredProps.d.ts +0 -1
- package/lib/utils/findDestructuredProps.js +0 -3
- /package/lib/codegen/{template → utils}/camelized.d.ts +0 -0
- /package/lib/codegen/{template → utils}/stringLiteralKey.d.ts +0 -0
|
@@ -3,13 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateTemplate = generateTemplate;
|
|
4
4
|
exports.forEachElementNode = forEachElementNode;
|
|
5
5
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
6
|
-
const
|
|
6
|
+
const shared_1 = require("../../utils/shared");
|
|
7
|
+
const utils_1 = require("../utils");
|
|
8
|
+
const stringLiteralKey_1 = require("../utils/stringLiteralKey");
|
|
7
9
|
const context_1 = require("./context");
|
|
8
|
-
const element_1 = require("./element");
|
|
9
10
|
const objectProperty_1 = require("./objectProperty");
|
|
10
|
-
const stringLiteralKey_1 = require("./stringLiteralKey");
|
|
11
|
-
const templateChild_1 = require("./templateChild");
|
|
12
11
|
const styleScopedClasses_1 = require("./styleScopedClasses");
|
|
12
|
+
const templateChild_1 = require("./templateChild");
|
|
13
13
|
function* generateTemplate(options) {
|
|
14
14
|
const ctx = (0, context_1.createTemplateCodegenContext)(options);
|
|
15
15
|
if (options.slotsAssignName) {
|
|
@@ -18,89 +18,81 @@ function* generateTemplate(options) {
|
|
|
18
18
|
if (options.propsAssignName) {
|
|
19
19
|
ctx.addLocalVariable(options.propsAssignName);
|
|
20
20
|
}
|
|
21
|
-
ctx.addLocalVariable(
|
|
21
|
+
ctx.addLocalVariable((0, shared_1.getSlotsPropertyName)(options.vueCompilerOptions.target));
|
|
22
|
+
ctx.addLocalVariable('$attrs');
|
|
22
23
|
ctx.addLocalVariable('$refs');
|
|
23
|
-
|
|
24
|
+
ctx.addLocalVariable('$el');
|
|
24
25
|
if (options.template.ast) {
|
|
25
|
-
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, options.template.ast, undefined
|
|
26
|
-
}
|
|
27
|
-
yield* (0, styleScopedClasses_1.generateStyleScopedClasses)(ctx);
|
|
28
|
-
if (!options.hasDefineSlots) {
|
|
29
|
-
yield `var __VLS_slots!:`;
|
|
30
|
-
yield* generateSlotsType(options, ctx);
|
|
31
|
-
yield common_1.endOfLine;
|
|
26
|
+
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, options.template.ast, undefined);
|
|
32
27
|
}
|
|
33
|
-
yield*
|
|
28
|
+
yield* (0, styleScopedClasses_1.generateStyleScopedClassReferences)(ctx);
|
|
29
|
+
yield* generateSlots(options, ctx);
|
|
34
30
|
yield* generateInheritedAttrs(ctx);
|
|
35
31
|
yield* generateRefs(ctx);
|
|
36
32
|
yield* generateRootEl(ctx);
|
|
33
|
+
yield* ctx.generateAutoImportCompletion();
|
|
37
34
|
return ctx;
|
|
38
35
|
}
|
|
39
|
-
function*
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
for (const slot of ctx.slots) {
|
|
46
|
-
ctx.hasSlot = true;
|
|
47
|
-
if (slot.name && slot.loc !== undefined) {
|
|
48
|
-
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slot.name, slot.loc, ctx.codeFeatures.withoutHighlightAndCompletion, slot.nodeLoc);
|
|
36
|
+
function* generateSlots(options, ctx) {
|
|
37
|
+
if (!options.hasDefineSlots) {
|
|
38
|
+
yield `var __VLS_slots!: `;
|
|
39
|
+
for (const { expVar, varName } of ctx.dynamicSlots) {
|
|
40
|
+
ctx.hasSlot = true;
|
|
41
|
+
yield `Partial<Record<NonNullable<typeof ${expVar}>, (_: typeof ${varName}) => any>> &${utils_1.newLine}`;
|
|
49
42
|
}
|
|
50
|
-
|
|
51
|
-
|
|
43
|
+
yield `{${utils_1.newLine}`;
|
|
44
|
+
for (const slot of ctx.slots) {
|
|
45
|
+
ctx.hasSlot = true;
|
|
46
|
+
if (slot.name && slot.loc !== undefined) {
|
|
47
|
+
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slot.name, slot.loc, ctx.codeFeatures.withoutHighlightAndCompletion, slot.nodeLoc);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
yield* (0, utils_1.wrapWith)(slot.tagRange[0], slot.tagRange[1], ctx.codeFeatures.withoutHighlightAndCompletion, `default`);
|
|
51
|
+
}
|
|
52
|
+
yield `?(_: typeof ${slot.varName}): any,${utils_1.newLine}`;
|
|
52
53
|
}
|
|
53
|
-
yield
|
|
54
|
+
yield `}${utils_1.endOfLine}`;
|
|
54
55
|
}
|
|
55
|
-
|
|
56
|
+
const name = (0, shared_1.getSlotsPropertyName)(options.vueCompilerOptions.target);
|
|
57
|
+
yield `var ${name}!: typeof ${options.slotsAssignName ?? '__VLS_slots'}${utils_1.endOfLine}`;
|
|
56
58
|
}
|
|
57
59
|
function* generateInheritedAttrs(ctx) {
|
|
58
|
-
yield '
|
|
60
|
+
yield 'let __VLS_inheritedAttrs!: {}';
|
|
59
61
|
for (const varName of ctx.inheritedAttrVars) {
|
|
60
62
|
yield ` & typeof ${varName}`;
|
|
61
63
|
}
|
|
62
|
-
yield
|
|
64
|
+
yield utils_1.endOfLine;
|
|
65
|
+
yield `var $attrs!: Partial<typeof __VLS_inheritedAttrs> & Record<string, unknown>${utils_1.endOfLine}`;
|
|
66
|
+
if (ctx.bindingAttrLocs.length) {
|
|
67
|
+
yield `[`;
|
|
68
|
+
for (const loc of ctx.bindingAttrLocs) {
|
|
69
|
+
yield [
|
|
70
|
+
loc.source,
|
|
71
|
+
'template',
|
|
72
|
+
loc.start.offset,
|
|
73
|
+
ctx.codeFeatures.all
|
|
74
|
+
];
|
|
75
|
+
yield `,`;
|
|
76
|
+
}
|
|
77
|
+
yield `]${utils_1.endOfLine}`;
|
|
78
|
+
}
|
|
63
79
|
}
|
|
64
80
|
function* generateRefs(ctx) {
|
|
65
|
-
yield `const __VLS_refs = {${
|
|
81
|
+
yield `const __VLS_refs = {${utils_1.newLine}`;
|
|
66
82
|
for (const [name, [varName, offset]] of ctx.templateRefs) {
|
|
67
83
|
yield* (0, stringLiteralKey_1.generateStringLiteralKey)(name, offset, ctx.codeFeatures.navigationAndCompletion);
|
|
68
|
-
yield `: ${varName},${
|
|
84
|
+
yield `: ${varName},${utils_1.newLine}`;
|
|
69
85
|
}
|
|
70
|
-
yield `}${
|
|
71
|
-
yield `var $refs!: typeof __VLS_refs${
|
|
86
|
+
yield `}${utils_1.endOfLine}`;
|
|
87
|
+
yield `var $refs!: typeof __VLS_refs${utils_1.endOfLine}`;
|
|
72
88
|
}
|
|
73
89
|
function* generateRootEl(ctx) {
|
|
74
90
|
if (ctx.singleRootElType) {
|
|
75
|
-
yield `var $el!: ${ctx.singleRootElType}${
|
|
91
|
+
yield `var $el!: ${ctx.singleRootElType}${utils_1.endOfLine}`;
|
|
76
92
|
}
|
|
77
93
|
else {
|
|
78
|
-
yield `var $el!: any${
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
function* generatePreResolveComponents(options) {
|
|
82
|
-
yield `let __VLS_resolvedLocalAndGlobalComponents!: Required<{}`;
|
|
83
|
-
if (options.template.ast) {
|
|
84
|
-
const components = new Set();
|
|
85
|
-
for (const node of forEachElementNode(options.template.ast)) {
|
|
86
|
-
if (node.tagType === CompilerDOM.ElementTypes.COMPONENT
|
|
87
|
-
&& node.tag.toLowerCase() !== 'component'
|
|
88
|
-
&& !node.tag.includes('.') // namespace tag
|
|
89
|
-
) {
|
|
90
|
-
if (components.has(node.tag)) {
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
components.add(node.tag);
|
|
94
|
-
yield common_1.newLine;
|
|
95
|
-
yield ` & __VLS_WithComponent<'${(0, element_1.getCanonicalComponentName)(node.tag)}', typeof __VLS_localComponents, `;
|
|
96
|
-
yield (0, element_1.getPossibleOriginalComponentNames)(node.tag, false)
|
|
97
|
-
.map(name => `"${name}"`)
|
|
98
|
-
.join(', ');
|
|
99
|
-
yield `>`;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
94
|
+
yield `var $el!: any${utils_1.endOfLine}`;
|
|
102
95
|
}
|
|
103
|
-
yield `>${common_1.endOfLine}`;
|
|
104
96
|
}
|
|
105
97
|
function* forEachElementNode(node) {
|
|
106
98
|
if (node.type === CompilerDOM.NodeTypes.ROOT) {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type * as ts from 'typescript';
|
|
2
2
|
import type { Code, VueCodeInformation } from '../../types';
|
|
3
3
|
import type { TemplateCodegenContext } from './context';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
export declare function generateInterpolation(options: {
|
|
5
|
+
ts: typeof ts;
|
|
6
|
+
destructuredPropNames: Set<string> | undefined;
|
|
7
|
+
templateRefNames: Set<string> | undefined;
|
|
8
|
+
}, ctx: TemplateCodegenContext, source: string, data: VueCodeInformation | ((offset: number) => VueCodeInformation) | undefined, _code: string, start: number | undefined, astHolder?: any, prefix?: string, suffix?: string): Generator<Code>;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateInterpolation = generateInterpolation;
|
|
4
|
-
exports.forEachInterpolationSegment = forEachInterpolationSegment;
|
|
5
4
|
const shared_1 = require("@vue/shared");
|
|
6
5
|
const scriptSetupRanges_1 = require("../../parsers/scriptSetupRanges");
|
|
7
|
-
const
|
|
8
|
-
function* generateInterpolation(options, ctx,
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
function* generateInterpolation(options, ctx, source, data, _code, start, astHolder = {}, prefix = '', suffix = '') {
|
|
9
8
|
const code = prefix + _code + suffix;
|
|
10
|
-
const ast = (0,
|
|
9
|
+
const ast = (0, utils_1.createTsAst)(options.ts, astHolder, code);
|
|
11
10
|
for (let [section, offset, type] of forEachInterpolationSegment(options.ts, options.destructuredPropNames, options.templateRefNames, ctx, code, start !== undefined ? start - prefix.length : undefined, ast)) {
|
|
12
11
|
if (offset === undefined) {
|
|
13
12
|
yield section;
|
|
@@ -17,12 +16,12 @@ function* generateInterpolation(options, ctx, _code, astHolder, start, data, pre
|
|
|
17
16
|
let addSuffix = '';
|
|
18
17
|
const overLength = offset + section.length - _code.length;
|
|
19
18
|
if (overLength > 0) {
|
|
20
|
-
addSuffix = section.
|
|
21
|
-
section = section.
|
|
19
|
+
addSuffix = section.slice(section.length - overLength);
|
|
20
|
+
section = section.slice(0, -overLength);
|
|
22
21
|
}
|
|
23
22
|
if (offset < 0) {
|
|
24
|
-
yield section.
|
|
25
|
-
section = section.
|
|
23
|
+
yield section.slice(0, -offset);
|
|
24
|
+
section = section.slice(-offset);
|
|
26
25
|
offset = 0;
|
|
27
26
|
}
|
|
28
27
|
const shouldSkip = section.length === 0 && (type === 'startText' || type === 'endText');
|
|
@@ -31,7 +30,7 @@ function* generateInterpolation(options, ctx, _code, astHolder, start, data, pre
|
|
|
31
30
|
&& data) {
|
|
32
31
|
yield [
|
|
33
32
|
section,
|
|
34
|
-
|
|
33
|
+
source,
|
|
35
34
|
start + offset,
|
|
36
35
|
type === 'errorMappingOnly'
|
|
37
36
|
? ctx.codeFeatures.verification
|
|
@@ -52,7 +51,7 @@ function* forEachInterpolationSegment(ts, destructuredPropNames, templateRefName
|
|
|
52
51
|
const text = (0, scriptSetupRanges_1.getNodeText)(ts, id, ast);
|
|
53
52
|
if (ctx.hasLocalVariable(text) ||
|
|
54
53
|
// https://github.com/vuejs/core/blob/245230e135152900189f13a4281302de45fdcfaa/packages/compiler-core/src/transforms/transformExpression.ts#L342-L352
|
|
55
|
-
(0, shared_1.
|
|
54
|
+
(0, shared_1.isGloballyAllowed)(text) ||
|
|
56
55
|
text === 'require' ||
|
|
57
56
|
text.startsWith('__VLS_')) {
|
|
58
57
|
// localVarOffsets.push(localVar.getStart(ast));
|
|
@@ -78,28 +77,28 @@ function* forEachInterpolationSegment(ts, destructuredPropNames, templateRefName
|
|
|
78
77
|
ctxVars = ctxVars.sort((a, b) => a.offset - b.offset);
|
|
79
78
|
if (ctxVars.length) {
|
|
80
79
|
if (ctxVars[0].isShorthand) {
|
|
81
|
-
yield [code.
|
|
80
|
+
yield [code.slice(0, ctxVars[0].offset + ctxVars[0].text.length), 0];
|
|
82
81
|
yield [': ', undefined];
|
|
83
82
|
}
|
|
84
83
|
else if (ctxVars[0].offset > 0) {
|
|
85
|
-
yield [code.
|
|
84
|
+
yield [code.slice(0, ctxVars[0].offset), 0, 'startText'];
|
|
86
85
|
}
|
|
87
86
|
for (let i = 0; i < ctxVars.length - 1; i++) {
|
|
88
87
|
const curVar = ctxVars[i];
|
|
89
88
|
const nextVar = ctxVars[i + 1];
|
|
90
89
|
yield* generateVar(code, destructuredPropNames, templateRefNames, curVar, nextVar);
|
|
91
90
|
if (nextVar.isShorthand) {
|
|
92
|
-
yield [code.
|
|
91
|
+
yield [code.slice(curVar.offset + curVar.text.length, nextVar.offset + nextVar.text.length), curVar.offset + curVar.text.length];
|
|
93
92
|
yield [': ', undefined];
|
|
94
93
|
}
|
|
95
94
|
else {
|
|
96
|
-
yield [code.
|
|
95
|
+
yield [code.slice(curVar.offset + curVar.text.length, nextVar.offset), curVar.offset + curVar.text.length];
|
|
97
96
|
}
|
|
98
97
|
}
|
|
99
98
|
const lastVar = ctxVars.at(-1);
|
|
100
99
|
yield* generateVar(code, destructuredPropNames, templateRefNames, lastVar);
|
|
101
100
|
if (lastVar.offset + lastVar.text.length < code.length) {
|
|
102
|
-
yield [code.
|
|
101
|
+
yield [code.slice(lastVar.offset + lastVar.text.length), lastVar.offset + lastVar.text.length, 'endText'];
|
|
103
102
|
}
|
|
104
103
|
}
|
|
105
104
|
else {
|
|
@@ -114,14 +113,14 @@ function* generateVar(code, destructuredPropNames, templateRefNames, curVar, nex
|
|
|
114
113
|
const isTemplateRef = templateRefNames?.has(curVar.text) ?? false;
|
|
115
114
|
if (isTemplateRef) {
|
|
116
115
|
yield [`__VLS_unref(`, undefined];
|
|
117
|
-
yield [code.
|
|
116
|
+
yield [code.slice(curVar.offset, curVar.offset + curVar.text.length), curVar.offset];
|
|
118
117
|
yield [`)`, undefined];
|
|
119
118
|
}
|
|
120
119
|
else {
|
|
121
120
|
if (!isDestructuredProp) {
|
|
122
121
|
yield [`__VLS_ctx.`, undefined];
|
|
123
122
|
}
|
|
124
|
-
yield [code.
|
|
123
|
+
yield [code.slice(curVar.offset, curVar.offset + curVar.text.length), curVar.offset];
|
|
125
124
|
}
|
|
126
125
|
}
|
|
127
126
|
function walkIdentifiers(ts, node, ast, cb, ctx, blockVars = [], isRoot = true) {
|
|
@@ -135,7 +134,7 @@ function walkIdentifiers(ts, node, ast, cb, ctx, blockVars = [], isRoot = true)
|
|
|
135
134
|
walkIdentifiers(ts, node.expression, ast, cb, ctx, blockVars, false);
|
|
136
135
|
}
|
|
137
136
|
else if (ts.isVariableDeclaration(node)) {
|
|
138
|
-
(0,
|
|
137
|
+
(0, utils_1.collectVars)(ts, node.name, ast, blockVars);
|
|
139
138
|
for (const varName of blockVars) {
|
|
140
139
|
ctx.addLocalVariable(varName);
|
|
141
140
|
}
|
|
@@ -196,7 +195,7 @@ function walkIdentifiers(ts, node, ast, cb, ctx, blockVars = [], isRoot = true)
|
|
|
196
195
|
function processFunction(ts, node, ast, cb, ctx) {
|
|
197
196
|
const functionArgs = [];
|
|
198
197
|
for (const param of node.parameters) {
|
|
199
|
-
(0,
|
|
198
|
+
(0, utils_1.collectVars)(ts, param.name, ast, functionArgs);
|
|
200
199
|
if (param.type) {
|
|
201
200
|
walkIdentifiers(ts, param.type, ast, cb, ctx);
|
|
202
201
|
}
|
|
@@ -2,29 +2,29 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateObjectProperty = generateObjectProperty;
|
|
4
4
|
const shared_1 = require("@vue/shared");
|
|
5
|
-
const
|
|
6
|
-
const camelized_1 = require("
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
const camelized_1 = require("../utils/camelized");
|
|
7
|
+
const stringLiteralKey_1 = require("../utils/stringLiteralKey");
|
|
7
8
|
const interpolation_1 = require("./interpolation");
|
|
8
|
-
const stringLiteralKey_1 = require("./stringLiteralKey");
|
|
9
9
|
function* generateObjectProperty(options, ctx, code, offset, features, astHolder, shouldCamelize = false, shouldBeConstant = false) {
|
|
10
10
|
if (code.startsWith('[') && code.endsWith(']') && astHolder) {
|
|
11
11
|
if (shouldBeConstant) {
|
|
12
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, code.slice(1, -1),
|
|
12
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, code.slice(1, -1), offset + 1, astHolder, `[__VLS_tryAsConstant(`, `)]`);
|
|
13
13
|
}
|
|
14
14
|
else {
|
|
15
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx,
|
|
15
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, code, offset, astHolder);
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
else if (shouldCamelize) {
|
|
19
|
-
if (
|
|
19
|
+
if (utils_1.variableNameRegex.test((0, shared_1.camelize)(code))) {
|
|
20
20
|
yield* (0, camelized_1.generateCamelized)(code, offset, features);
|
|
21
21
|
}
|
|
22
22
|
else {
|
|
23
|
-
yield* (0,
|
|
23
|
+
yield* (0, utils_1.wrapWith)(offset, offset + code.length, features, `'`, ...(0, camelized_1.generateCamelized)(code, offset, utils_1.combineLastMapping), `'`);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
else {
|
|
27
|
-
if (
|
|
27
|
+
if (utils_1.variableNameRegex.test(code)) {
|
|
28
28
|
yield [code, 'template', offset, features];
|
|
29
29
|
}
|
|
30
30
|
else {
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generatePropertyAccess = generatePropertyAccess;
|
|
4
|
-
const
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
const stringLiteralKey_1 = require("../utils/stringLiteralKey");
|
|
5
6
|
const interpolation_1 = require("./interpolation");
|
|
6
|
-
const stringLiteralKey_1 = require("./stringLiteralKey");
|
|
7
7
|
function* generatePropertyAccess(options, ctx, code, offset, features, astHolder) {
|
|
8
|
-
if (!options.compilerOptions.noPropertyAccessFromIndexSignature &&
|
|
8
|
+
if (!options.compilerOptions.noPropertyAccessFromIndexSignature && utils_1.variableNameRegex.test(code)) {
|
|
9
9
|
yield `.`;
|
|
10
10
|
yield offset !== undefined && features
|
|
11
11
|
? [code, 'template', offset, features]
|
|
12
12
|
: code;
|
|
13
13
|
}
|
|
14
14
|
else if (code.startsWith('[') && code.endsWith(']')) {
|
|
15
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx,
|
|
15
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, code, offset, astHolder);
|
|
16
16
|
}
|
|
17
17
|
else {
|
|
18
18
|
yield `[`;
|
|
@@ -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 generateSlotOutlet(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.SlotOutletNode
|
|
5
|
+
export declare function generateSlotOutlet(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.SlotOutletNode): Generator<Code>;
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateSlotOutlet = generateSlotOutlet;
|
|
4
4
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
5
|
-
const
|
|
5
|
+
const inlayHints_1 = require("../inlayHints");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
6
7
|
const elementChildren_1 = require("./elementChildren");
|
|
7
8
|
const elementProps_1 = require("./elementProps");
|
|
8
9
|
const interpolation_1 = require("./interpolation");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const startTagOffset = node.loc.start.offset + options.template.content.substring(node.loc.start.offset).indexOf(node.tag);
|
|
10
|
+
function* generateSlotOutlet(options, ctx, node) {
|
|
11
|
+
const startTagOffset = node.loc.start.offset + options.template.content.slice(node.loc.start.offset).indexOf(node.tag);
|
|
12
12
|
const varSlot = ctx.getInternalVariable();
|
|
13
13
|
const nameProp = node.props.find(prop => {
|
|
14
14
|
if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE) {
|
|
@@ -22,19 +22,19 @@ function* generateSlotOutlet(options, ctx, node, currentComponent, componentCtxV
|
|
|
22
22
|
});
|
|
23
23
|
if (options.hasDefineSlots) {
|
|
24
24
|
yield `__VLS_normalizeSlot(`;
|
|
25
|
-
yield* (0,
|
|
25
|
+
yield* (0, utils_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, ctx.codeFeatures.verification, `${options.slotsAssignName ?? '__VLS_slots'}[`, ...(0, utils_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, ctx.codeFeatures.verification, nameProp?.type === CompilerDOM.NodeTypes.ATTRIBUTE && nameProp.value
|
|
26
26
|
? `'${nameProp.value.content}'`
|
|
27
27
|
: nameProp?.type === CompilerDOM.NodeTypes.DIRECTIVE && nameProp.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
28
28
|
? nameProp.exp.content
|
|
29
29
|
: `('default' as const)`), `]`);
|
|
30
30
|
yield `)?.(`;
|
|
31
|
-
yield* (0,
|
|
32
|
-
yield `)${
|
|
31
|
+
yield* (0, utils_1.wrapWith)(startTagOffset, startTagOffset + node.tag.length, ctx.codeFeatures.verification, `{${utils_1.newLine}`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), true, true), `}`);
|
|
32
|
+
yield `)${utils_1.endOfLine}`;
|
|
33
33
|
}
|
|
34
34
|
else {
|
|
35
|
-
yield `var ${varSlot} = {${
|
|
36
|
-
yield* (0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), true);
|
|
37
|
-
yield `}${
|
|
35
|
+
yield `var ${varSlot} = {${utils_1.newLine}`;
|
|
36
|
+
yield* (0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), options.vueCompilerOptions.strictTemplates, true);
|
|
37
|
+
yield `}${utils_1.endOfLine}`;
|
|
38
38
|
if (nameProp?.type === CompilerDOM.NodeTypes.ATTRIBUTE
|
|
39
39
|
&& nameProp.value) {
|
|
40
40
|
ctx.slots.push({
|
|
@@ -53,8 +53,8 @@ function* generateSlotOutlet(options, ctx, node, currentComponent, componentCtxV
|
|
|
53
53
|
}
|
|
54
54
|
const slotExpVar = ctx.getInternalVariable();
|
|
55
55
|
yield `var ${slotExpVar} = `;
|
|
56
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx,
|
|
57
|
-
yield ` as const${
|
|
56
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, nameProp.exp.content, nameProp.exp.loc.start.offset, nameProp.exp, '(', ')');
|
|
57
|
+
yield ` as const${utils_1.endOfLine}`;
|
|
58
58
|
ctx.dynamicSlots.push({
|
|
59
59
|
expVar: slotExpVar,
|
|
60
60
|
varName: varSlot,
|
|
@@ -70,6 +70,6 @@ function* generateSlotOutlet(options, ctx, node, currentComponent, componentCtxV
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
yield* ctx.generateAutoImportCompletion();
|
|
73
|
-
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node
|
|
73
|
+
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node);
|
|
74
74
|
}
|
|
75
75
|
//# sourceMappingURL=slotOutlet.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Code } from '../../types';
|
|
2
2
|
import type { TemplateCodegenContext } from './context';
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function generateStyleScopedClassReferences(ctx: TemplateCodegenContext, withDot?: boolean): Generator<Code>;
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
function*
|
|
3
|
+
exports.generateStyleScopedClassReferences = generateStyleScopedClassReferences;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
function* generateStyleScopedClassReferences(ctx, withDot = false) {
|
|
6
|
+
if (!ctx.emptyClassOffsets.length && !ctx.scopedClasses.length) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
yield `[`;
|
|
6
10
|
for (const offset of ctx.emptyClassOffsets) {
|
|
7
|
-
yield `
|
|
11
|
+
yield `'`;
|
|
8
12
|
yield [
|
|
9
13
|
'',
|
|
10
14
|
'template',
|
|
11
15
|
offset,
|
|
12
16
|
ctx.codeFeatures.additionalCompletion,
|
|
13
17
|
];
|
|
14
|
-
yield `'
|
|
18
|
+
yield `', `;
|
|
15
19
|
}
|
|
16
20
|
for (const { source, className, offset } of ctx.scopedClasses) {
|
|
17
|
-
yield `__VLS_styleScopedClasses[`;
|
|
18
21
|
yield [
|
|
19
22
|
'',
|
|
20
23
|
source,
|
|
@@ -31,9 +34,9 @@ function* generateStyleScopedClasses(ctx, withDot = false) {
|
|
|
31
34
|
offset + className.length,
|
|
32
35
|
ctx.codeFeatures.navigationWithoutRename,
|
|
33
36
|
];
|
|
34
|
-
yield
|
|
37
|
+
yield `, `;
|
|
35
38
|
}
|
|
36
|
-
yield
|
|
39
|
+
yield `] as (keyof __VLS_StyleScopedClasses)[]${utils_1.endOfLine}`;
|
|
37
40
|
function* escapeString(source, className, offset, escapeTargets) {
|
|
38
41
|
let count = 0;
|
|
39
42
|
const currentEscapeTargets = [...escapeTargets];
|
|
@@ -2,6 +2,6 @@ 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 generateTemplateChild(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode,
|
|
5
|
+
export declare function generateTemplateChild(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode, prevNode: CompilerDOM.TemplateChildNode | undefined, isVForChild?: boolean): Generator<Code>;
|
|
6
6
|
export declare function getVForNode(node: CompilerDOM.ElementNode): CompilerDOM.ForNode | undefined;
|
|
7
7
|
export declare function parseInterpolationNode(node: CompilerDOM.InterpolationNode, template: string): readonly [string, number];
|
|
@@ -4,7 +4,7 @@ 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");
|
|
@@ -25,19 +25,29 @@ const transformContext = {
|
|
|
25
25
|
},
|
|
26
26
|
expressionPlugins: ['typescript'],
|
|
27
27
|
};
|
|
28
|
-
function* generateTemplateChild(options, ctx, node,
|
|
28
|
+
function* generateTemplateChild(options, ctx, node, prevNode, isVForChild = false) {
|
|
29
29
|
if (prevNode?.type === CompilerDOM.NodeTypes.COMMENT) {
|
|
30
30
|
const commentText = prevNode.content.trim().split(' ')[0];
|
|
31
|
-
if (
|
|
32
|
-
yield `// @vue-skip${
|
|
31
|
+
if (/^@vue-skip\b[\s\S]*/.test(commentText)) {
|
|
32
|
+
yield `// @vue-skip${utils_1.newLine}`;
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
35
|
-
else if (
|
|
35
|
+
else if (/^@vue-ignore\b[\s\S]*/.test(commentText)) {
|
|
36
36
|
yield* ctx.ignoreError();
|
|
37
37
|
}
|
|
38
|
-
else if (
|
|
38
|
+
else if (/^@vue-expect-error\b[\s\S]*/.test(commentText)) {
|
|
39
39
|
yield* ctx.expectError(prevNode);
|
|
40
40
|
}
|
|
41
|
+
else {
|
|
42
|
+
const match = prevNode.loc.source.match(/^<!--\s*@vue-generic\b\s*\{(?<content>[^}]*)\}/);
|
|
43
|
+
if (match) {
|
|
44
|
+
const { content } = match.groups ?? {};
|
|
45
|
+
ctx.lastGenericComment = {
|
|
46
|
+
content,
|
|
47
|
+
offset: prevNode.loc.start.offset + match[0].indexOf(content)
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
41
51
|
}
|
|
42
52
|
const shouldInheritRootNodeAttrs = options.inheritAttrs;
|
|
43
53
|
const cur = node;
|
|
@@ -50,7 +60,7 @@ function* generateTemplateChild(options, ctx, node, currentComponent, prevNode,
|
|
|
50
60
|
ctx.singleRootNode = node.children[0];
|
|
51
61
|
}
|
|
52
62
|
for (const childNode of node.children) {
|
|
53
|
-
yield* generateTemplateChild(options, ctx, childNode,
|
|
63
|
+
yield* generateTemplateChild(options, ctx, childNode, prev);
|
|
54
64
|
prev = childNode;
|
|
55
65
|
}
|
|
56
66
|
yield* ctx.resetDirectiveComments('end of root');
|
|
@@ -59,49 +69,51 @@ function* generateTemplateChild(options, ctx, node, currentComponent, prevNode,
|
|
|
59
69
|
const vForNode = getVForNode(node);
|
|
60
70
|
const vIfNode = getVIfNode(node);
|
|
61
71
|
if (vForNode) {
|
|
62
|
-
yield* (0, vFor_1.generateVFor)(options, ctx, vForNode
|
|
72
|
+
yield* (0, vFor_1.generateVFor)(options, ctx, vForNode);
|
|
63
73
|
}
|
|
64
74
|
else if (vIfNode) {
|
|
65
|
-
yield* (0, vIf_1.generateVIf)(options, ctx, vIfNode
|
|
75
|
+
yield* (0, vIf_1.generateVIf)(options, ctx, vIfNode);
|
|
66
76
|
}
|
|
67
77
|
else {
|
|
68
78
|
if (node.tagType === CompilerDOM.ElementTypes.SLOT) {
|
|
69
|
-
yield* (0, slotOutlet_1.generateSlotOutlet)(options, ctx, node
|
|
79
|
+
yield* (0, slotOutlet_1.generateSlotOutlet)(options, ctx, node);
|
|
70
80
|
}
|
|
71
81
|
else if (node.tagType === CompilerDOM.ElementTypes.ELEMENT
|
|
72
82
|
|| node.tagType === CompilerDOM.ElementTypes.TEMPLATE) {
|
|
73
|
-
yield* (0, element_1.generateElement)(options, ctx, node,
|
|
83
|
+
yield* (0, element_1.generateElement)(options, ctx, node, isVForChild);
|
|
74
84
|
}
|
|
75
85
|
else {
|
|
76
|
-
|
|
86
|
+
const { currentComponent } = ctx;
|
|
87
|
+
yield* (0, element_1.generateComponent)(options, ctx, node);
|
|
88
|
+
ctx.currentComponent = currentComponent;
|
|
77
89
|
}
|
|
78
90
|
}
|
|
79
91
|
}
|
|
80
92
|
else if (node.type === CompilerDOM.NodeTypes.TEXT_CALL) {
|
|
81
93
|
// {{ var }}
|
|
82
|
-
yield* generateTemplateChild(options, ctx, node.content,
|
|
94
|
+
yield* generateTemplateChild(options, ctx, node.content, undefined);
|
|
83
95
|
}
|
|
84
96
|
else if (node.type === CompilerDOM.NodeTypes.COMPOUND_EXPRESSION) {
|
|
85
97
|
// {{ ... }} {{ ... }}
|
|
86
98
|
for (const childNode of node.children) {
|
|
87
99
|
if (typeof childNode === 'object') {
|
|
88
|
-
yield* generateTemplateChild(options, ctx, childNode,
|
|
100
|
+
yield* generateTemplateChild(options, ctx, childNode, undefined);
|
|
89
101
|
}
|
|
90
102
|
}
|
|
91
103
|
}
|
|
92
104
|
else if (node.type === CompilerDOM.NodeTypes.INTERPOLATION) {
|
|
93
105
|
// {{ ... }}
|
|
94
106
|
const [content, start] = parseInterpolationNode(node, options.template.content);
|
|
95
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx,
|
|
107
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, content, start, node.content.loc, `(`, `)${utils_1.endOfLine}`);
|
|
96
108
|
yield* ctx.resetDirectiveComments('end of INTERPOLATION');
|
|
97
109
|
}
|
|
98
110
|
else if (node.type === CompilerDOM.NodeTypes.IF) {
|
|
99
111
|
// v-if / v-else-if / v-else
|
|
100
|
-
yield* (0, vIf_1.generateVIf)(options, ctx, node
|
|
112
|
+
yield* (0, vIf_1.generateVIf)(options, ctx, node);
|
|
101
113
|
}
|
|
102
114
|
else if (node.type === CompilerDOM.NodeTypes.FOR) {
|
|
103
115
|
// v-for
|
|
104
|
-
yield* (0, vFor_1.generateVFor)(options, ctx, node
|
|
116
|
+
yield* (0, vFor_1.generateVFor)(options, ctx, node);
|
|
105
117
|
}
|
|
106
118
|
else if (node.type === CompilerDOM.NodeTypes.TEXT) {
|
|
107
119
|
// not needed progress
|
|
@@ -152,11 +164,11 @@ function parseInterpolationNode(node, template) {
|
|
|
152
164
|
let leftCharacter;
|
|
153
165
|
let rightCharacter;
|
|
154
166
|
// fix https://github.com/vuejs/language-tools/issues/1787
|
|
155
|
-
while ((leftCharacter = template.
|
|
167
|
+
while ((leftCharacter = template.slice(start - 1, start)).trim() === '' && leftCharacter.length) {
|
|
156
168
|
start--;
|
|
157
169
|
content = leftCharacter + content;
|
|
158
170
|
}
|
|
159
|
-
while ((rightCharacter = template.
|
|
171
|
+
while ((rightCharacter = template.slice(start + content.length, start + content.length + 1)).trim() === '' && rightCharacter.length) {
|
|
160
172
|
content = content + rightCharacter;
|
|
161
173
|
}
|
|
162
174
|
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;
|