@vue/language-core 3.1.4 → 3.1.6
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 +2 -1
- package/index.js +3 -2
- package/lib/codegen/codeFeatures.d.ts +5 -9
- package/lib/codegen/codeFeatures.js +5 -5
- package/lib/codegen/globalTypes.js +15 -20
- package/lib/codegen/localTypes.d.ts +1 -1
- package/lib/codegen/localTypes.js +6 -6
- package/lib/codegen/names.d.ts +30 -0
- package/lib/codegen/names.js +34 -0
- package/lib/codegen/script/component.js +45 -54
- package/lib/codegen/script/context.d.ts +2 -5
- package/lib/codegen/script/context.js +1 -7
- package/lib/codegen/script/index.d.ts +10 -12
- package/lib/codegen/script/index.js +74 -73
- package/lib/codegen/script/scriptSetup.d.ts +3 -2
- package/lib/codegen/script/scriptSetup.js +209 -283
- package/lib/codegen/script/src.js +9 -3
- package/lib/codegen/script/template.js +64 -108
- package/lib/codegen/style/common.d.ts +3 -0
- package/lib/codegen/style/common.js +43 -0
- package/lib/codegen/style/index.d.ts +63 -0
- package/lib/codegen/style/index.js +38 -0
- package/lib/codegen/style/modules.d.ts +3 -2
- package/lib/codegen/style/modules.js +12 -11
- package/lib/codegen/style/scopedClasses.d.ts +2 -3
- package/lib/codegen/style/scopedClasses.js +23 -21
- package/lib/codegen/template/context.d.ts +10 -19
- package/lib/codegen/template/context.js +82 -94
- package/lib/codegen/template/element.js +174 -65
- package/lib/codegen/template/elementDirectives.js +32 -12
- package/lib/codegen/template/elementEvents.d.ts +1 -1
- package/lib/codegen/template/elementEvents.js +30 -35
- package/lib/codegen/template/elementProps.d.ts +3 -3
- package/lib/codegen/template/elementProps.js +64 -83
- package/lib/codegen/template/index.d.ts +11 -22
- package/lib/codegen/template/index.js +85 -80
- package/lib/codegen/template/interpolation.d.ts +3 -3
- package/lib/codegen/template/interpolation.js +108 -155
- package/lib/codegen/template/objectProperty.js +8 -4
- package/lib/codegen/template/propertyAccess.d.ts +1 -1
- package/lib/codegen/template/propertyAccess.js +5 -7
- package/lib/codegen/template/slotOutlet.js +26 -14
- package/lib/codegen/template/styleScopedClasses.d.ts +3 -6
- package/lib/codegen/template/styleScopedClasses.js +23 -149
- package/lib/codegen/template/templateChild.d.ts +0 -1
- package/lib/codegen/template/templateChild.js +11 -68
- package/lib/codegen/template/vFor.js +10 -13
- package/lib/codegen/template/vIf.js +5 -3
- package/lib/codegen/template/vSlot.js +20 -16
- package/lib/codegen/utils/boundary.d.ts +3 -0
- package/lib/codegen/utils/boundary.js +13 -0
- package/lib/codegen/utils/camelized.js +3 -3
- package/lib/codegen/utils/escaped.js +4 -2
- package/lib/codegen/utils/index.d.ts +3 -6
- package/lib/codegen/utils/index.js +41 -26
- package/lib/codegen/utils/merge.d.ts +2 -2
- package/lib/codegen/utils/merge.js +9 -9
- package/lib/codegen/utils/stringLiteralKey.js +6 -3
- package/lib/codegen/utils/transform.d.ts +8 -0
- package/lib/codegen/utils/transform.js +27 -0
- package/lib/codegen/utils/unicode.js +4 -2
- package/lib/compilerOptions.js +4 -4
- package/lib/languagePlugin.d.ts +1 -1
- package/lib/languagePlugin.js +18 -25
- package/lib/plugins/vue-template-html.js +12 -9
- package/lib/plugins/vue-template-inline-css.js +8 -18
- package/lib/plugins/vue-template-inline-ts.js +12 -14
- package/lib/plugins/vue-tsx.d.ts +14 -23
- package/lib/plugins/vue-tsx.js +121 -69
- package/lib/plugins.js +1 -1
- package/lib/types.d.ts +5 -4
- package/lib/utils/parseSfc.js +10 -11
- package/lib/utils/shared.d.ts +1 -0
- package/lib/utils/shared.js +9 -0
- package/lib/utils/signals.d.ts +2 -2
- package/lib/utils/signals.js +8 -6
- package/lib/virtualCode/embeddedCodes.d.ts +12 -0
- package/lib/virtualCode/embeddedCodes.js +249 -0
- package/lib/{virtualFile/vueFile.d.ts → virtualCode/index.d.ts} +9 -9
- package/lib/virtualCode/index.js +81 -0
- package/lib/virtualCode/ir.d.ts +4 -0
- package/lib/{virtualFile/computedSfc.js → virtualCode/ir.js} +65 -96
- package/lib/virtualCode/normalize.d.ts +2 -0
- package/lib/virtualCode/normalize.js +170 -0
- package/package.json +4 -4
- package/lib/codegen/style/classProperty.d.ts +0 -2
- package/lib/codegen/style/classProperty.js +0 -18
- package/lib/codegen/style/imports.d.ts +0 -2
- package/lib/codegen/style/imports.js +0 -27
- package/lib/codegen/template/elementChildren.d.ts +0 -5
- package/lib/codegen/template/elementChildren.js +0 -12
- package/lib/codegen/utils/wrapWith.d.ts +0 -3
- package/lib/codegen/utils/wrapWith.js +0 -24
- package/lib/virtualFile/computedEmbeddedCodes.d.ts +0 -4
- package/lib/virtualFile/computedEmbeddedCodes.js +0 -262
- package/lib/virtualFile/computedSfc.d.ts +0 -6
- package/lib/virtualFile/computedVueSfc.d.ts +0 -4
- package/lib/virtualFile/computedVueSfc.js +0 -41
- package/lib/virtualFile/embeddedFile.d.ts +0 -11
- package/lib/virtualFile/embeddedFile.js +0 -14
- package/lib/virtualFile/vueFile.js +0 -49
|
@@ -5,10 +5,11 @@ exports.generateModifiers = generateModifiers;
|
|
|
5
5
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
6
6
|
const shared_1 = require("@vue/shared");
|
|
7
7
|
const codeFeatures_1 = require("../codeFeatures");
|
|
8
|
+
const names = require("../names");
|
|
8
9
|
const utils_1 = require("../utils");
|
|
10
|
+
const boundary_1 = require("../utils/boundary");
|
|
9
11
|
const camelized_1 = require("../utils/camelized");
|
|
10
12
|
const stringLiteralKey_1 = require("../utils/stringLiteralKey");
|
|
11
|
-
const wrapWith_1 = require("../utils/wrapWith");
|
|
12
13
|
const elementProps_1 = require("./elementProps");
|
|
13
14
|
const interpolation_1 = require("./interpolation");
|
|
14
15
|
const objectProperty_1 = require("./objectProperty");
|
|
@@ -29,19 +30,32 @@ function* generateElementDirectives(options, ctx, node) {
|
|
|
29
30
|
|| prop.name === 'bind') {
|
|
30
31
|
continue;
|
|
31
32
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
yield
|
|
33
|
+
const token = yield* (0, boundary_1.startBoundary)('template', prop.loc.start.offset, codeFeatures_1.codeFeatures.verification);
|
|
34
|
+
yield `__VLS_asFunctionalDirective(`;
|
|
35
|
+
yield* generateIdentifier(options, ctx, prop);
|
|
36
|
+
yield `)(null!, { ...__VLS_directiveBindingRestFields, `;
|
|
37
|
+
yield* generateArg(options, ctx, prop);
|
|
38
|
+
yield* generateModifiers(options, ctx, prop);
|
|
39
|
+
yield* generateValue(options, ctx, prop);
|
|
40
|
+
yield ` }, null!, null!)`;
|
|
41
|
+
yield (0, boundary_1.endBoundary)(token, prop.loc.end.offset);
|
|
36
42
|
yield utils_1.endOfLine;
|
|
37
43
|
}
|
|
38
44
|
}
|
|
39
|
-
function* generateIdentifier(options, prop) {
|
|
45
|
+
function* generateIdentifier(options, ctx, prop) {
|
|
40
46
|
const rawName = 'v-' + prop.name;
|
|
41
|
-
|
|
47
|
+
const startOffset = prop.loc.start.offset;
|
|
48
|
+
const token = yield* (0, boundary_1.startBoundary)('template', startOffset, codeFeatures_1.codeFeatures.verification);
|
|
49
|
+
yield names.directives;
|
|
50
|
+
yield `.`;
|
|
51
|
+
yield* (0, camelized_1.generateCamelized)(rawName, 'template', prop.loc.start.offset, {
|
|
42
52
|
...codeFeatures_1.codeFeatures.withoutHighlightAndCompletion,
|
|
43
53
|
verification: options.vueCompilerOptions.checkUnknownDirectives && !builtInDirectives.has(prop.name),
|
|
44
|
-
})
|
|
54
|
+
});
|
|
55
|
+
if (!builtInDirectives.has(prop.name)) {
|
|
56
|
+
ctx.recordComponentAccess('template', (0, shared_1.camelize)(rawName), prop.loc.start.offset);
|
|
57
|
+
}
|
|
58
|
+
yield (0, boundary_1.endBoundary)(token, startOffset + rawName.length);
|
|
45
59
|
}
|
|
46
60
|
function* generateArg(options, ctx, prop) {
|
|
47
61
|
const { arg } = prop;
|
|
@@ -49,13 +63,15 @@ function* generateArg(options, ctx, prop) {
|
|
|
49
63
|
return;
|
|
50
64
|
}
|
|
51
65
|
const startOffset = arg.loc.start.offset + arg.loc.source.indexOf(arg.content);
|
|
52
|
-
yield* (0,
|
|
66
|
+
const token = yield* (0, boundary_1.startBoundary)('template', startOffset, codeFeatures_1.codeFeatures.verification);
|
|
67
|
+
yield `arg`;
|
|
68
|
+
yield (0, boundary_1.endBoundary)(token, startOffset + arg.content.length);
|
|
53
69
|
yield `: `;
|
|
54
70
|
if (arg.isStatic) {
|
|
55
71
|
yield* (0, stringLiteralKey_1.generateStringLiteralKey)(arg.content, startOffset, codeFeatures_1.codeFeatures.all);
|
|
56
72
|
}
|
|
57
73
|
else {
|
|
58
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx,
|
|
74
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, arg.content, startOffset, `(`, `)`);
|
|
59
75
|
}
|
|
60
76
|
yield `, `;
|
|
61
77
|
}
|
|
@@ -66,7 +82,9 @@ function* generateModifiers(options, ctx, prop, propertyName = 'modifiers') {
|
|
|
66
82
|
}
|
|
67
83
|
const startOffset = modifiers[0].loc.start.offset - 1;
|
|
68
84
|
const endOffset = modifiers.at(-1).loc.end.offset;
|
|
69
|
-
yield* (0,
|
|
85
|
+
const token = yield* (0, boundary_1.startBoundary)('template', startOffset, codeFeatures_1.codeFeatures.verification);
|
|
86
|
+
yield propertyName;
|
|
87
|
+
yield (0, boundary_1.endBoundary)(token, endOffset);
|
|
70
88
|
yield `: { `;
|
|
71
89
|
for (const mod of modifiers) {
|
|
72
90
|
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, mod.content, mod.loc.start.offset, codeFeatures_1.codeFeatures.withoutHighlight);
|
|
@@ -79,7 +97,9 @@ function* generateValue(options, ctx, prop) {
|
|
|
79
97
|
if (exp?.type !== CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
80
98
|
return;
|
|
81
99
|
}
|
|
82
|
-
yield* (0,
|
|
100
|
+
const token = yield* (0, boundary_1.startBoundary)('template', exp.loc.start.offset, codeFeatures_1.codeFeatures.verification);
|
|
101
|
+
yield `value`;
|
|
102
|
+
yield (0, boundary_1.endBoundary)(token, exp.loc.end.offset);
|
|
83
103
|
yield `: `;
|
|
84
104
|
yield* (0, elementProps_1.generatePropExp)(options, ctx, prop, exp);
|
|
85
105
|
}
|
|
@@ -3,7 +3,7 @@ import type * as ts from 'typescript';
|
|
|
3
3
|
import type { Code, VueCodeInformation } from '../../types';
|
|
4
4
|
import type { TemplateCodegenContext } from './context';
|
|
5
5
|
import type { TemplateCodegenOptions } from './index';
|
|
6
|
-
export declare function generateElementEvents(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, componentOriginalVar: string
|
|
6
|
+
export declare function generateElementEvents(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, componentOriginalVar: string): Generator<Code>;
|
|
7
7
|
export declare function generateEventArg(options: TemplateCodegenOptions, name: string, start: number, directive?: string, features?: VueCodeInformation): Generator<Code>;
|
|
8
8
|
export declare function generateEventExpression(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode): Generator<Code>;
|
|
9
9
|
export declare function generateModelEventExpression(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode): Generator<Code>;
|
|
@@ -9,12 +9,11 @@ const CompilerDOM = require("@vue/compiler-dom");
|
|
|
9
9
|
const shared_1 = require("@vue/shared");
|
|
10
10
|
const codeFeatures_1 = require("../codeFeatures");
|
|
11
11
|
const utils_1 = require("../utils");
|
|
12
|
+
const boundary_1 = require("../utils/boundary");
|
|
12
13
|
const camelized_1 = require("../utils/camelized");
|
|
13
|
-
const wrapWith_1 = require("../utils/wrapWith");
|
|
14
14
|
const interpolation_1 = require("./interpolation");
|
|
15
|
-
function* generateElementEvents(options, ctx, node, componentOriginalVar
|
|
15
|
+
function* generateElementEvents(options, ctx, node, componentOriginalVar) {
|
|
16
16
|
let emitsVar;
|
|
17
|
-
let propsVar;
|
|
18
17
|
for (const prop of node.props) {
|
|
19
18
|
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
20
19
|
&& (prop.name === 'on'
|
|
@@ -22,12 +21,9 @@ function* generateElementEvents(options, ctx, node, componentOriginalVar, compon
|
|
|
22
21
|
|| options.vueCompilerOptions.strictVModel
|
|
23
22
|
&& prop.name === 'model'
|
|
24
23
|
&& (!prop.arg || prop.arg.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic))) {
|
|
25
|
-
ctx.currentComponent.used = true;
|
|
26
24
|
if (!emitsVar) {
|
|
27
25
|
emitsVar = ctx.getInternalVariable();
|
|
28
|
-
|
|
29
|
-
yield `let ${emitsVar}!: __VLS_ResolveEmits<typeof ${componentOriginalVar}, typeof ${componentCtxVar}.emit>${utils_1.endOfLine}`;
|
|
30
|
-
yield `let ${propsVar}!: __VLS_FunctionalComponentProps<typeof ${componentFunctionalVar}, typeof ${componentVNodeVar}>${utils_1.endOfLine}`;
|
|
26
|
+
yield `let ${emitsVar}!: __VLS_ResolveEmits<typeof ${componentOriginalVar}, typeof ${ctx.currentComponent.ctxVar}.emit>${utils_1.endOfLine}`;
|
|
31
27
|
}
|
|
32
28
|
let source = prop.arg?.loc.source ?? 'model-value';
|
|
33
29
|
let start = prop.arg?.loc.start.offset;
|
|
@@ -46,7 +42,7 @@ function* generateElementEvents(options, ctx, node, componentOriginalVar, compon
|
|
|
46
42
|
const propName = (0, shared_1.camelize)(propPrefix + source);
|
|
47
43
|
const emitName = emitPrefix + source;
|
|
48
44
|
const camelizedEmitName = (0, shared_1.camelize)(emitName);
|
|
49
|
-
yield `const ${ctx.getInternalVariable()}: __VLS_NormalizeComponentEvent<typeof ${propsVar}, typeof ${emitsVar}, '${propName}', '${emitName}', '${camelizedEmitName}'> = (${utils_1.newLine}`;
|
|
45
|
+
yield `const ${ctx.getInternalVariable()}: __VLS_NormalizeComponentEvent<typeof ${ctx.currentComponent.propsVar}, typeof ${emitsVar}, '${propName}', '${emitName}', '${camelizedEmitName}'> = (${utils_1.newLine}`;
|
|
50
46
|
if (prop.name === 'on') {
|
|
51
47
|
yield `{ `;
|
|
52
48
|
yield* generateEventArg(options, source, start, emitPrefix.slice(0, -1), codeFeatures_1.codeFeatures.navigation);
|
|
@@ -78,46 +74,45 @@ function* generateEventArg(options, name, start, directive = 'on', features) {
|
|
|
78
74
|
name = (0, shared_1.capitalize)(name);
|
|
79
75
|
}
|
|
80
76
|
if (utils_1.identifierRegex.test((0, shared_1.camelize)(name))) {
|
|
81
|
-
yield
|
|
77
|
+
const token = yield* (0, boundary_1.startBoundary)('template', start, features);
|
|
82
78
|
yield directive;
|
|
83
|
-
yield* (0, camelized_1.generateCamelized)(name, 'template', start,
|
|
79
|
+
yield* (0, camelized_1.generateCamelized)(name, 'template', start, { __combineToken: token });
|
|
84
80
|
}
|
|
85
81
|
else {
|
|
86
|
-
|
|
82
|
+
const token = yield* (0, boundary_1.startBoundary)('template', start, features);
|
|
83
|
+
yield `'`;
|
|
84
|
+
yield directive;
|
|
85
|
+
yield* (0, camelized_1.generateCamelized)(name, 'template', start, { __combineToken: token });
|
|
86
|
+
yield `'`;
|
|
87
|
+
yield (0, boundary_1.endBoundary)(token, start + name.length);
|
|
87
88
|
}
|
|
88
89
|
}
|
|
89
90
|
function* generateEventExpression(options, ctx, prop) {
|
|
90
91
|
if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
91
|
-
|
|
92
|
-
const ast = (0, utils_1.createTsAst)(options.ts, ctx.inlineTsAsts, prop.exp.content);
|
|
92
|
+
const ast = (0, utils_1.getTypeScriptAST)(options.ts, options.template, prop.exp.content);
|
|
93
93
|
const isCompound = isCompoundExpression(options.ts, ast);
|
|
94
|
-
const interpolation = (0, interpolation_1.generateInterpolation)(options, ctx,
|
|
95
|
-
if (isCompound && isFirstMapping) {
|
|
96
|
-
isFirstMapping = false;
|
|
97
|
-
ctx.inlayHints.push({
|
|
98
|
-
blockName: 'template',
|
|
99
|
-
offset,
|
|
100
|
-
setting: 'vue.inlayHints.inlineHandlerLeading',
|
|
101
|
-
label: '$event =>',
|
|
102
|
-
paddingRight: true,
|
|
103
|
-
tooltip: [
|
|
104
|
-
'`$event` is a hidden parameter, you can use it in this callback.',
|
|
105
|
-
'To hide this hint, set `vue.inlayHints.inlineHandlerLeading` to `false` in IDE settings.',
|
|
106
|
-
'[More info](https://github.com/vuejs/language-tools/issues/2445#issuecomment-1444771420)',
|
|
107
|
-
].join('\n\n'),
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
return codeFeatures_1.codeFeatures.all;
|
|
111
|
-
}, prop.exp.content, prop.exp.loc.start.offset, isCompound ? `` : `(`, isCompound ? `` : `)`);
|
|
94
|
+
const interpolation = (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, prop.exp.content, prop.exp.loc.start.offset, isCompound ? `` : `(`, isCompound ? `` : `)`);
|
|
112
95
|
if (isCompound) {
|
|
113
96
|
yield `(...[$event]) => {${utils_1.newLine}`;
|
|
114
|
-
ctx.
|
|
97
|
+
const endScope = ctx.startScope();
|
|
98
|
+
ctx.declare('$event');
|
|
115
99
|
yield* ctx.generateConditionGuards();
|
|
116
100
|
yield* interpolation;
|
|
117
101
|
yield utils_1.endOfLine;
|
|
118
|
-
|
|
119
|
-
yield* ctx.generateAutoImportCompletion();
|
|
102
|
+
yield* endScope();
|
|
120
103
|
yield `}`;
|
|
104
|
+
ctx.inlayHints.push({
|
|
105
|
+
blockName: 'template',
|
|
106
|
+
offset: prop.exp.loc.start.offset,
|
|
107
|
+
setting: 'vue.inlayHints.inlineHandlerLeading',
|
|
108
|
+
label: '$event =>',
|
|
109
|
+
paddingRight: true,
|
|
110
|
+
tooltip: [
|
|
111
|
+
'`$event` is a hidden parameter, you can use it in this callback.',
|
|
112
|
+
'To hide this hint, set `vue.inlayHints.inlineHandlerLeading` to `false` in IDE settings.',
|
|
113
|
+
'[More info](https://github.com/vuejs/language-tools/issues/2445#issuecomment-1444771420)',
|
|
114
|
+
].join('\n\n'),
|
|
115
|
+
});
|
|
121
116
|
}
|
|
122
117
|
else {
|
|
123
118
|
yield* interpolation;
|
|
@@ -131,7 +126,7 @@ function* generateModelEventExpression(options, ctx, prop) {
|
|
|
131
126
|
if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
132
127
|
yield `(...[$event]) => {${utils_1.newLine}`;
|
|
133
128
|
yield* ctx.generateConditionGuards();
|
|
134
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx,
|
|
129
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.verification, prop.exp.content, prop.exp.loc.start.offset);
|
|
135
130
|
yield ` = $event${utils_1.endOfLine}`;
|
|
136
131
|
yield `}`;
|
|
137
132
|
}
|
|
@@ -2,10 +2,10 @@ 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 interface
|
|
5
|
+
export interface FailGeneratedExpression {
|
|
6
6
|
node: CompilerDOM.SimpleExpressionNode;
|
|
7
7
|
prefix: string;
|
|
8
8
|
suffix: string;
|
|
9
9
|
}
|
|
10
|
-
export declare function generateElementProps(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, props: CompilerDOM.ElementNode['props'], strictPropsCheck: boolean,
|
|
11
|
-
export declare function generatePropExp(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode, exp: CompilerDOM.SimpleExpressionNode | undefined
|
|
10
|
+
export declare function generateElementProps(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, props: CompilerDOM.ElementNode['props'], strictPropsCheck: boolean, failGeneratedExpressions?: FailGeneratedExpression[]): Generator<Code>;
|
|
11
|
+
export declare function generatePropExp(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode, exp: CompilerDOM.SimpleExpressionNode | undefined): Generator<Code>;
|
|
@@ -4,20 +4,20 @@ exports.generateElementProps = generateElementProps;
|
|
|
4
4
|
exports.generatePropExp = generatePropExp;
|
|
5
5
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
6
6
|
const shared_1 = require("@vue/shared");
|
|
7
|
-
const muggle_string_1 = require("muggle-string");
|
|
8
7
|
const picomatch_1 = require("picomatch");
|
|
9
8
|
const shared_2 = require("../../utils/shared");
|
|
10
9
|
const codeFeatures_1 = require("../codeFeatures");
|
|
11
10
|
const inlayHints_1 = require("../inlayHints");
|
|
11
|
+
const names = require("../names");
|
|
12
12
|
const utils_1 = require("../utils");
|
|
13
|
+
const boundary_1 = require("../utils/boundary");
|
|
13
14
|
const camelized_1 = require("../utils/camelized");
|
|
14
15
|
const unicode_1 = require("../utils/unicode");
|
|
15
|
-
const wrapWith_1 = require("../utils/wrapWith");
|
|
16
16
|
const elementDirectives_1 = require("./elementDirectives");
|
|
17
17
|
const elementEvents_1 = require("./elementEvents");
|
|
18
18
|
const interpolation_1 = require("./interpolation");
|
|
19
19
|
const objectProperty_1 = require("./objectProperty");
|
|
20
|
-
function* generateElementProps(options, ctx, node, props, strictPropsCheck,
|
|
20
|
+
function* generateElementProps(options, ctx, node, props, strictPropsCheck, failGeneratedExpressions) {
|
|
21
21
|
const isComponent = node.tagType === CompilerDOM.ElementTypes.COMPONENT;
|
|
22
22
|
for (const prop of props) {
|
|
23
23
|
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
@@ -41,12 +41,12 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
41
41
|
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
42
42
|
&& prop.arg.loc.source.startsWith('[')
|
|
43
43
|
&& prop.arg.loc.source.endsWith(']')) {
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
failGeneratedExpressions?.push({ node: prop.arg, prefix: `(`, suffix: `)` });
|
|
45
|
+
failGeneratedExpressions?.push({ node: prop.exp, prefix: `() => {`, suffix: `}` });
|
|
46
46
|
}
|
|
47
47
|
else if (!prop.arg
|
|
48
48
|
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
49
|
-
|
|
49
|
+
failGeneratedExpressions?.push({ node: prop.exp, prefix: `(`, suffix: `)` });
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
}
|
|
@@ -67,7 +67,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
67
67
|
if (propName === undefined
|
|
68
68
|
|| options.vueCompilerOptions.dataAttributes.some(pattern => (0, picomatch_1.isMatch)(propName, pattern))) {
|
|
69
69
|
if (prop.exp && prop.exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY) {
|
|
70
|
-
|
|
70
|
+
failGeneratedExpressions?.push({ node: prop.exp, prefix: `(`, suffix: `)` });
|
|
71
71
|
}
|
|
72
72
|
continue;
|
|
73
73
|
}
|
|
@@ -81,15 +81,21 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
81
81
|
if (shouldSpread) {
|
|
82
82
|
yield `...{ `;
|
|
83
83
|
}
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (enableCodeFeatures) {
|
|
88
|
-
yield* codes;
|
|
84
|
+
const token = yield* (0, boundary_1.startBoundary)('template', prop.loc.start.offset, codeFeatures_1.codeFeatures.verification);
|
|
85
|
+
if (prop.arg) {
|
|
86
|
+
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, propName, prop.arg.loc.start.offset, features, shouldCamelize);
|
|
89
87
|
}
|
|
90
88
|
else {
|
|
91
|
-
yield (0,
|
|
92
|
-
|
|
89
|
+
const token2 = yield* (0, boundary_1.startBoundary)('template', prop.loc.start.offset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
|
|
90
|
+
yield propName;
|
|
91
|
+
yield (0, boundary_1.endBoundary)(token2, prop.loc.start.offset + 'v-model'.length);
|
|
92
|
+
}
|
|
93
|
+
yield `: `;
|
|
94
|
+
const argLoc = prop.arg?.loc ?? prop.loc;
|
|
95
|
+
const token3 = yield* (0, boundary_1.startBoundary)('template', argLoc.start.offset, codeFeatures_1.codeFeatures.verification);
|
|
96
|
+
yield* generatePropExp(options, ctx, prop, prop.exp);
|
|
97
|
+
yield (0, boundary_1.endBoundary)(token3, argLoc.end.offset);
|
|
98
|
+
yield (0, boundary_1.endBoundary)(token, prop.loc.end.offset);
|
|
93
99
|
if (shouldSpread) {
|
|
94
100
|
yield ` }`;
|
|
95
101
|
}
|
|
@@ -100,13 +106,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
100
106
|
? `[__VLS_tryAsConstant(\`\${${prop.arg.content}}Modifiers\`)]`
|
|
101
107
|
: (0, shared_1.camelize)(propName) + `Modifiers`
|
|
102
108
|
: `modelModifiers`;
|
|
103
|
-
|
|
104
|
-
if (enableCodeFeatures) {
|
|
105
|
-
yield* codes;
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
yield (0, muggle_string_1.toString)(codes);
|
|
109
|
-
}
|
|
109
|
+
yield* (0, elementDirectives_1.generateModifiers)(options, ctx, prop, propertyName);
|
|
110
110
|
yield utils_1.newLine;
|
|
111
111
|
}
|
|
112
112
|
}
|
|
@@ -120,15 +120,19 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
120
120
|
if (shouldSpread) {
|
|
121
121
|
yield `...{ `;
|
|
122
122
|
}
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
if (
|
|
127
|
-
yield
|
|
123
|
+
const token = yield* (0, boundary_1.startBoundary)('template', prop.loc.start.offset, codeFeatures_1.codeFeatures.verification);
|
|
124
|
+
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, prop.name, prop.loc.start.offset, features, shouldCamelize);
|
|
125
|
+
yield `: `;
|
|
126
|
+
if (prop.name === 'style') {
|
|
127
|
+
yield `{}`;
|
|
128
|
+
}
|
|
129
|
+
else if (prop.value) {
|
|
130
|
+
yield* generateAttrValue(prop.value, codeFeatures_1.codeFeatures.withoutNavigation);
|
|
128
131
|
}
|
|
129
132
|
else {
|
|
130
|
-
yield
|
|
133
|
+
yield `true`;
|
|
131
134
|
}
|
|
135
|
+
yield (0, boundary_1.endBoundary)(token, prop.loc.end.offset);
|
|
132
136
|
if (shouldSpread) {
|
|
133
137
|
yield ` }`;
|
|
134
138
|
}
|
|
@@ -138,74 +142,51 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
138
142
|
&& !prop.arg
|
|
139
143
|
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
140
144
|
if (prop.exp.loc.source === '$attrs') {
|
|
141
|
-
|
|
142
|
-
ctx.bindingAttrLocs.push(prop.exp.loc);
|
|
143
|
-
}
|
|
145
|
+
failGeneratedExpressions?.push({ node: prop.exp, prefix: `(`, suffix: `)` });
|
|
144
146
|
}
|
|
145
147
|
else {
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
else {
|
|
151
|
-
yield (0, muggle_string_1.toString)(codes);
|
|
152
|
-
}
|
|
148
|
+
const token = yield* (0, boundary_1.startBoundary)('template', prop.exp.loc.start.offset, codeFeatures_1.codeFeatures.verification);
|
|
149
|
+
yield `...`;
|
|
150
|
+
yield* generatePropExp(options, ctx, prop, prop.exp);
|
|
151
|
+
yield (0, boundary_1.endBoundary)(token, prop.exp.loc.end.offset);
|
|
153
152
|
yield `,${utils_1.newLine}`;
|
|
154
153
|
}
|
|
155
154
|
}
|
|
156
155
|
}
|
|
157
156
|
}
|
|
158
|
-
function* generatePropExp(options, ctx, prop, exp
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
if (!isShorthand) { // vue 3.4+
|
|
165
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, exp.loc.source, exp.loc.start.offset, `(`, `)`);
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
const propVariableName = (0, shared_1.camelize)(exp.loc.source);
|
|
169
|
-
if (utils_1.identifierRegex.test(propVariableName)) {
|
|
170
|
-
const isDestructuredProp = options.destructuredPropNames.has(propVariableName);
|
|
171
|
-
const isTemplateRef = options.templateRefNames.has(propVariableName);
|
|
172
|
-
const codes = (0, camelized_1.generateCamelized)(exp.loc.source, 'template', exp.loc.start.offset, features);
|
|
173
|
-
if (ctx.hasLocalVariable(propVariableName) || isDestructuredProp) {
|
|
174
|
-
yield* codes;
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
ctx.accessExternalVariable(propVariableName, exp.loc.start.offset);
|
|
178
|
-
if (isTemplateRef) {
|
|
179
|
-
yield `__VLS_unref(`;
|
|
180
|
-
yield* codes;
|
|
181
|
-
yield `)`;
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
yield `__VLS_ctx.`;
|
|
185
|
-
yield* codes;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
if (enableCodeFeatures) {
|
|
189
|
-
ctx.inlayHints.push((0, inlayHints_1.createVBindShorthandInlayHintInfo)(prop.loc, propVariableName));
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
157
|
+
function* generatePropExp(options, ctx, prop, exp) {
|
|
158
|
+
if (!exp) {
|
|
159
|
+
yield `{}`;
|
|
160
|
+
}
|
|
161
|
+
else if (prop.arg?.loc.start.offset !== prop.exp?.loc.start.offset) {
|
|
162
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, exp.loc.source, exp.loc.start.offset, `(`, `)`);
|
|
193
163
|
}
|
|
194
164
|
else {
|
|
195
|
-
|
|
165
|
+
const propVariableName = (0, shared_1.camelize)(exp.loc.source);
|
|
166
|
+
if (utils_1.identifierRegex.test(propVariableName)) {
|
|
167
|
+
const codes = (0, camelized_1.generateCamelized)(exp.loc.source, 'template', exp.loc.start.offset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
|
|
168
|
+
if (ctx.scopes.some(scope => scope.has(propVariableName))) {
|
|
169
|
+
yield* codes;
|
|
170
|
+
}
|
|
171
|
+
else if (options.setupRefs.has(propVariableName)) {
|
|
172
|
+
yield* codes;
|
|
173
|
+
yield `.value`;
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
ctx.recordComponentAccess('template', propVariableName, exp.loc.start.offset);
|
|
177
|
+
yield names.ctx;
|
|
178
|
+
yield `.`;
|
|
179
|
+
yield* codes;
|
|
180
|
+
}
|
|
181
|
+
ctx.inlayHints.push((0, inlayHints_1.createVBindShorthandInlayHintInfo)(prop.loc, propVariableName));
|
|
182
|
+
}
|
|
196
183
|
}
|
|
197
184
|
}
|
|
198
|
-
function* generateAttrValue(
|
|
199
|
-
const quote =
|
|
185
|
+
function* generateAttrValue(node, features) {
|
|
186
|
+
const quote = node.loc.source.startsWith("'") ? "'" : '"';
|
|
187
|
+
const [content, offset] = (0, shared_2.normalizeAttributeValue)(node);
|
|
200
188
|
yield quote;
|
|
201
|
-
|
|
202
|
-
let content = attrNode.loc.source;
|
|
203
|
-
if ((content.startsWith('"') && content.endsWith('"'))
|
|
204
|
-
|| (content.startsWith("'") && content.endsWith("'"))) {
|
|
205
|
-
start++;
|
|
206
|
-
content = content.slice(1, -1);
|
|
207
|
-
}
|
|
208
|
-
yield* (0, unicode_1.generateUnicode)(content, start, features);
|
|
189
|
+
yield* (0, unicode_1.generateUnicode)(content, offset, features);
|
|
209
190
|
yield quote;
|
|
210
191
|
}
|
|
211
192
|
function getShouldCamelize(options, prop, propName) {
|
|
@@ -2,13 +2,10 @@ import type * as ts from 'typescript';
|
|
|
2
2
|
import type { Code, Sfc, VueCompilerOptions } from '../../types';
|
|
3
3
|
export interface TemplateCodegenOptions {
|
|
4
4
|
ts: typeof ts;
|
|
5
|
-
compilerOptions: ts.CompilerOptions;
|
|
6
5
|
vueCompilerOptions: VueCompilerOptions;
|
|
7
6
|
template: NonNullable<Sfc['template']>;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
destructuredPropNames: Set<string>;
|
|
11
|
-
templateRefNames: Set<string>;
|
|
7
|
+
setupRefs: Set<string>;
|
|
8
|
+
setupConsts: Set<string>;
|
|
12
9
|
hasDefineSlots?: boolean;
|
|
13
10
|
propsAssignName?: string;
|
|
14
11
|
slotsAssignName?: string;
|
|
@@ -18,6 +15,7 @@ export interface TemplateCodegenOptions {
|
|
|
18
15
|
export { generate as generateTemplate };
|
|
19
16
|
declare function generate(options: TemplateCodegenOptions): {
|
|
20
17
|
codes: Code[];
|
|
18
|
+
generatedTypes: Set<string>;
|
|
21
19
|
currentInfo: {
|
|
22
20
|
ignoreError?: boolean;
|
|
23
21
|
expectError?: {
|
|
@@ -30,7 +28,6 @@ declare function generate(options: TemplateCodegenOptions): {
|
|
|
30
28
|
};
|
|
31
29
|
};
|
|
32
30
|
resolveCodeFeatures: (features: import("../../types").VueCodeInformation) => import("../../types").VueCodeInformation;
|
|
33
|
-
inlineTsAsts: Map<string, ts.SourceFile> | undefined;
|
|
34
31
|
inVFor: boolean;
|
|
35
32
|
slots: {
|
|
36
33
|
name: string;
|
|
@@ -44,37 +41,29 @@ declare function generate(options: TemplateCodegenOptions): {
|
|
|
44
41
|
propsVar: string;
|
|
45
42
|
}[];
|
|
46
43
|
dollarVars: Set<string>;
|
|
47
|
-
|
|
44
|
+
componentAccessMap: Map<string, Map<string, Set<number>>>;
|
|
48
45
|
blockConditions: string[];
|
|
49
|
-
scopedClasses: {
|
|
50
|
-
source: string;
|
|
51
|
-
className: string;
|
|
52
|
-
offset: number;
|
|
53
|
-
}[];
|
|
54
|
-
emptyClassOffsets: number[];
|
|
55
46
|
inlayHints: import("../inlayHints").InlayHintInfo[];
|
|
56
|
-
bindingAttrLocs: import("@vue/compiler-dom").SourceLocation[];
|
|
57
47
|
inheritedAttrVars: Set<string>;
|
|
58
48
|
templateRefs: Map<string, {
|
|
59
49
|
typeExp: string;
|
|
60
50
|
offset: number;
|
|
61
51
|
}[]>;
|
|
62
52
|
currentComponent: {
|
|
63
|
-
ctxVar: string;
|
|
64
|
-
|
|
53
|
+
get ctxVar(): string;
|
|
54
|
+
get propsVar(): string;
|
|
65
55
|
} | undefined;
|
|
66
|
-
singleRootElTypes: string
|
|
56
|
+
singleRootElTypes: Set<string>;
|
|
67
57
|
singleRootNodes: Set<import("@vue/compiler-dom").ElementNode | null>;
|
|
68
58
|
addTemplateRef(name: string, typeExp: string, offset: number): void;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
59
|
+
recordComponentAccess(source: string, name: string, offset?: number): void;
|
|
60
|
+
scopes: Set<string>[];
|
|
61
|
+
declare(...varNames: string[]): void;
|
|
62
|
+
startScope(): () => Generator<Code, any, any>;
|
|
73
63
|
getInternalVariable(): string;
|
|
74
64
|
getHoistVariable(originalVar: string): string;
|
|
75
65
|
generateHoistVariables(): Generator<string, void, unknown>;
|
|
76
66
|
generateConditionGuards(): Generator<string, void, unknown>;
|
|
77
|
-
generateAutoImportCompletion(): Generator<Code>;
|
|
78
67
|
enter(node: import("@vue/compiler-dom").RootNode | import("@vue/compiler-dom").TemplateChildNode | import("@vue/compiler-dom").SimpleExpressionNode): boolean;
|
|
79
68
|
exit(): Generator<Code>;
|
|
80
69
|
};
|