@vue/language-core 2.2.0 → 2.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +0 -1
- package/index.js +1 -2
- package/lib/codegen/codeFeatures.d.ts +83 -0
- package/lib/codegen/codeFeatures.js +71 -0
- package/lib/codegen/globalTypes.d.ts +3 -1
- package/lib/codegen/globalTypes.js +45 -37
- package/lib/codegen/localTypes.d.ts +1 -1
- package/lib/codegen/localTypes.js +4 -4
- package/lib/codegen/script/component.d.ts +1 -1
- package/lib/codegen/script/component.js +15 -11
- package/lib/codegen/script/componentSelf.d.ts +1 -1
- package/lib/codegen/script/componentSelf.js +2 -2
- package/lib/codegen/script/context.d.ts +1 -1
- package/lib/codegen/script/index.d.ts +1 -8
- package/lib/codegen/script/index.js +19 -45
- package/lib/codegen/script/scriptSetup.d.ts +1 -1
- package/lib/codegen/script/scriptSetup.js +78 -79
- package/lib/codegen/script/src.d.ts +2 -2
- package/lib/codegen/script/src.js +37 -38
- package/lib/codegen/script/template.d.ts +2 -3
- package/lib/codegen/script/template.js +12 -79
- package/lib/codegen/style/classProperty.d.ts +2 -0
- package/lib/codegen/style/classProperty.js +31 -0
- package/lib/codegen/style/modules.d.ts +3 -0
- package/lib/codegen/{script/styleModulesType.js → style/modules.js} +15 -15
- package/lib/codegen/style/scopedClasses.d.ts +4 -0
- package/lib/codegen/style/scopedClasses.js +32 -0
- package/lib/codegen/template/context.d.ts +122 -17
- package/lib/codegen/template/context.js +162 -92
- package/lib/codegen/template/element.d.ts +1 -1
- package/lib/codegen/template/element.js +86 -330
- package/lib/codegen/template/elementChildren.js +0 -13
- package/lib/codegen/template/elementDirectives.js +20 -12
- package/lib/codegen/template/elementEvents.d.ts +1 -1
- package/lib/codegen/template/elementEvents.js +15 -11
- package/lib/codegen/template/elementProps.d.ts +2 -1
- package/lib/codegen/template/elementProps.js +31 -33
- package/lib/codegen/template/index.d.ts +1 -0
- package/lib/codegen/template/index.js +53 -33
- package/lib/codegen/template/interpolation.js +13 -9
- package/lib/codegen/template/slotOutlet.js +44 -21
- package/lib/codegen/template/styleScopedClasses.d.ts +3 -0
- package/lib/codegen/template/styleScopedClasses.js +146 -9
- package/lib/codegen/template/templateChild.js +69 -30
- package/lib/codegen/template/vFor.js +2 -2
- package/lib/codegen/template/vIf.js +3 -3
- package/lib/codegen/template/vSlot.d.ts +6 -0
- package/lib/codegen/template/vSlot.js +92 -0
- package/lib/codegen/utils/index.d.ts +13 -2
- package/lib/codegen/utils/index.js +33 -6
- package/lib/parsers/scriptSetupRanges.d.ts +5 -3
- package/lib/parsers/scriptSetupRanges.js +24 -35
- package/lib/parsers/vueCompilerOptions.d.ts +2 -2
- package/lib/plugins/file-md.js +3 -0
- package/lib/plugins/vue-template-inline-ts.js +56 -15
- package/lib/plugins/vue-tsx.d.ts +43 -32
- package/lib/plugins/vue-tsx.js +88 -68
- package/lib/types.d.ts +29 -16
- package/lib/utils/parseSfc.js +41 -16
- package/lib/utils/signals.d.ts +2 -0
- package/lib/utils/signals.js +54 -0
- package/lib/utils/ts.d.ts +14 -2
- package/lib/utils/ts.js +134 -88
- package/lib/virtualFile/computedEmbeddedCodes.d.ts +1 -1
- package/lib/virtualFile/computedEmbeddedCodes.js +14 -24
- package/lib/virtualFile/computedSfc.d.ts +1 -2
- package/lib/virtualFile/computedSfc.js +86 -96
- package/lib/virtualFile/computedVueSfc.d.ts +1 -2
- package/lib/virtualFile/computedVueSfc.js +7 -7
- package/lib/virtualFile/vueFile.d.ts +8 -11
- package/lib/virtualFile/vueFile.js +15 -9
- package/package.json +4 -4
- package/lib/codegen/script/styleModulesType.d.ts +0 -4
|
@@ -3,7 +3,7 @@ import type * as ts from 'typescript';
|
|
|
3
3
|
import type { Code } 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,
|
|
6
|
+
export declare function generateElementEvents(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, componentFunctionalVar: string, componentVNodeVar: string, componentCtxVar: string): Generator<Code>;
|
|
7
7
|
export declare function generateEventArg(ctx: TemplateCodegenContext, name: string, start: number, directive?: string): Generator<Code>;
|
|
8
8
|
export declare function generateEventExpression(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode): Generator<Code>;
|
|
9
9
|
export declare function isCompoundExpression(ts: typeof import('typescript'), ast: ts.SourceFile): boolean;
|
|
@@ -9,8 +9,9 @@ const shared_1 = require("@vue/shared");
|
|
|
9
9
|
const utils_1 = require("../utils");
|
|
10
10
|
const camelized_1 = require("../utils/camelized");
|
|
11
11
|
const interpolation_1 = require("./interpolation");
|
|
12
|
-
function* generateElementEvents(options, ctx, node,
|
|
13
|
-
let
|
|
12
|
+
function* generateElementEvents(options, ctx, node, componentFunctionalVar, componentVNodeVar, componentCtxVar) {
|
|
13
|
+
let emitVar;
|
|
14
|
+
let eventsVar;
|
|
14
15
|
let propsVar;
|
|
15
16
|
for (const prop of node.props) {
|
|
16
17
|
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
@@ -18,10 +19,14 @@ function* generateElementEvents(options, ctx, node, componentVar, componentInsta
|
|
|
18
19
|
&& prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
19
20
|
&& !prop.arg.loc.source.startsWith('[')
|
|
20
21
|
&& !prop.arg.loc.source.endsWith(']')) {
|
|
21
|
-
|
|
22
|
-
if (!
|
|
22
|
+
ctx.currentComponent.used = true;
|
|
23
|
+
if (!emitVar) {
|
|
24
|
+
emitVar = ctx.getInternalVariable();
|
|
25
|
+
eventsVar = ctx.getInternalVariable();
|
|
23
26
|
propsVar = ctx.getInternalVariable();
|
|
24
|
-
yield `let ${
|
|
27
|
+
yield `let ${emitVar}!: typeof ${componentCtxVar}.emit${utils_1.endOfLine}`;
|
|
28
|
+
yield `let ${eventsVar}!: __VLS_NormalizeEmits<typeof ${emitVar}>${utils_1.endOfLine}`;
|
|
29
|
+
yield `let ${propsVar}!: __VLS_FunctionalComponentProps<typeof ${componentFunctionalVar}, typeof ${componentVNodeVar}>${utils_1.endOfLine}`;
|
|
25
30
|
}
|
|
26
31
|
let source = prop.arg.loc.source;
|
|
27
32
|
let start = prop.arg.loc.start.offset;
|
|
@@ -40,7 +45,6 @@ function* generateElementEvents(options, ctx, node, componentVar, componentInsta
|
|
|
40
45
|
yield `}${utils_1.endOfLine}`;
|
|
41
46
|
}
|
|
42
47
|
}
|
|
43
|
-
return usedComponentEventsVar;
|
|
44
48
|
}
|
|
45
49
|
function* generateEventArg(ctx, name, start, directive = 'on') {
|
|
46
50
|
const features = {
|
|
@@ -58,18 +62,18 @@ function* generateEventArg(ctx, name, start, directive = 'on') {
|
|
|
58
62
|
}
|
|
59
63
|
function* generateEventExpression(options, ctx, prop) {
|
|
60
64
|
if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
61
|
-
let prefix =
|
|
62
|
-
let suffix =
|
|
65
|
+
let prefix = `(`;
|
|
66
|
+
let suffix = `)`;
|
|
63
67
|
let isFirstMapping = true;
|
|
64
68
|
const ast = (0, utils_1.createTsAst)(options.ts, prop.exp, prop.exp.content);
|
|
65
69
|
const _isCompoundExpression = isCompoundExpression(options.ts, ast);
|
|
66
70
|
if (_isCompoundExpression) {
|
|
67
71
|
yield `(...[$event]) => {${utils_1.newLine}`;
|
|
68
72
|
ctx.addLocalVariable('$event');
|
|
69
|
-
prefix =
|
|
70
|
-
suffix =
|
|
73
|
+
prefix = ``;
|
|
74
|
+
suffix = ``;
|
|
71
75
|
for (const blockCondition of ctx.blockConditions) {
|
|
72
|
-
prefix += `if (
|
|
76
|
+
prefix += `if (!${blockCondition}) return${utils_1.endOfLine}`;
|
|
73
77
|
}
|
|
74
78
|
}
|
|
75
79
|
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', offset => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as CompilerDOM from '@vue/compiler-dom';
|
|
2
|
-
import type { Code } from '../../types';
|
|
2
|
+
import type { Code, VueCodeInformation } from '../../types';
|
|
3
3
|
import type { TemplateCodegenContext } from './context';
|
|
4
4
|
import type { TemplateCodegenOptions } from './index';
|
|
5
5
|
export interface FailedPropExpression {
|
|
@@ -8,3 +8,4 @@ export interface FailedPropExpression {
|
|
|
8
8
|
suffix: string;
|
|
9
9
|
}
|
|
10
10
|
export declare function generateElementProps(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, props: CompilerDOM.ElementNode['props'], strictPropsCheck: boolean, enableCodeFeatures: boolean, failedPropExps?: FailedPropExpression[]): Generator<Code>;
|
|
11
|
+
export declare function generatePropExp(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode, exp: CompilerDOM.SimpleExpressionNode | undefined, features: VueCodeInformation, enableCodeFeatures?: boolean): Generator<Code>;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateElementProps = generateElementProps;
|
|
4
|
+
exports.generatePropExp = generatePropExp;
|
|
4
5
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
5
6
|
const shared_1 = require("@vue/shared");
|
|
6
7
|
const minimatch_1 = require("minimatch");
|
|
7
8
|
const muggle_string_1 = require("muggle-string");
|
|
8
9
|
const shared_2 = require("../../utils/shared");
|
|
10
|
+
const codeFeatures_1 = require("../codeFeatures");
|
|
9
11
|
const inlayHints_1 = require("../inlayHints");
|
|
10
12
|
const utils_1 = require("../utils");
|
|
11
13
|
const camelized_1 = require("../utils/camelized");
|
|
@@ -38,12 +40,12 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
38
40
|
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
39
41
|
&& prop.arg.loc.source.startsWith('[')
|
|
40
42
|
&& prop.arg.loc.source.endsWith(']')) {
|
|
41
|
-
failedPropExps?.push({ node: prop.arg, prefix:
|
|
42
|
-
failedPropExps?.push({ node: prop.exp, prefix:
|
|
43
|
+
failedPropExps?.push({ node: prop.arg, prefix: `(`, suffix: `)` });
|
|
44
|
+
failedPropExps?.push({ node: prop.exp, prefix: `() => {`, suffix: `}` });
|
|
43
45
|
}
|
|
44
46
|
else if (!prop.arg
|
|
45
47
|
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
46
|
-
failedPropExps?.push({ node: prop.exp, prefix:
|
|
48
|
+
failedPropExps?.push({ node: prop.exp, prefix: `(`, suffix: `)` });
|
|
47
49
|
}
|
|
48
50
|
}
|
|
49
51
|
}
|
|
@@ -64,7 +66,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
64
66
|
if (propName === undefined
|
|
65
67
|
|| options.vueCompilerOptions.dataAttributes.some(pattern => (0, minimatch_1.minimatch)(propName, pattern))) {
|
|
66
68
|
if (prop.exp && prop.exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY) {
|
|
67
|
-
failedPropExps?.push({ node: prop.exp, prefix:
|
|
69
|
+
failedPropExps?.push({ node: prop.exp, prefix: `(`, suffix: `)` });
|
|
68
70
|
}
|
|
69
71
|
continue;
|
|
70
72
|
}
|
|
@@ -80,7 +82,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
80
82
|
}
|
|
81
83
|
const codes = (0, utils_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, ...(prop.arg
|
|
82
84
|
? (0, objectProperty_1.generateObjectProperty)(options, ctx, propName, prop.arg.loc.start.offset, codeInfo, prop.loc.name_2 ??= {}, shouldCamelize)
|
|
83
|
-
: (0, utils_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + 'v-model'.length, ctx.codeFeatures.verification, propName)), `:
|
|
85
|
+
: (0, utils_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + 'v-model'.length, ctx.codeFeatures.verification, propName)), `: `, ...generatePropExp(options, ctx, prop, prop.exp, ctx.codeFeatures.all, enableCodeFeatures));
|
|
84
86
|
if (enableCodeFeatures) {
|
|
85
87
|
yield* codes;
|
|
86
88
|
}
|
|
@@ -91,7 +93,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
91
93
|
yield ` }`;
|
|
92
94
|
}
|
|
93
95
|
yield `,${utils_1.newLine}`;
|
|
94
|
-
if (prop.name === 'model' && prop.modifiers.length) {
|
|
96
|
+
if (isComponent && prop.name === 'model' && prop.modifiers.length) {
|
|
95
97
|
const propertyName = prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
96
98
|
? !prop.arg.isStatic
|
|
97
99
|
? `[__VLS_tryAsConstant(\`$\{${prop.arg.content}\}Modifiers\`)]`
|
|
@@ -121,9 +123,9 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
121
123
|
if (shouldSpread) {
|
|
122
124
|
yield `...{ `;
|
|
123
125
|
}
|
|
124
|
-
const codes = (0, utils_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, ...(0, objectProperty_1.generateObjectProperty)(options, ctx, prop.name, prop.loc.start.offset, codeInfo, prop.loc.name_1 ??= {}, shouldCamelize), `:
|
|
126
|
+
const codes = (0, utils_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, ...(0, objectProperty_1.generateObjectProperty)(options, ctx, prop.name, prop.loc.start.offset, codeInfo, prop.loc.name_1 ??= {}, shouldCamelize), `: `, ...(prop.value
|
|
125
127
|
? generateAttrValue(prop.value, ctx.codeFeatures.withoutNavigation)
|
|
126
|
-
: [`true`])
|
|
128
|
+
: [`true`]));
|
|
127
129
|
if (enableCodeFeatures) {
|
|
128
130
|
yield* codes;
|
|
129
131
|
}
|
|
@@ -145,7 +147,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
145
147
|
}
|
|
146
148
|
}
|
|
147
149
|
else {
|
|
148
|
-
const codes = (0, utils_1.wrapWith)(prop.exp.loc.start.offset, prop.exp.loc.end.offset, ctx.codeFeatures.verification, `...`, ...generatePropExp(options, ctx, prop, prop.exp, ctx.codeFeatures.all,
|
|
150
|
+
const codes = (0, utils_1.wrapWith)(prop.exp.loc.start.offset, prop.exp.loc.end.offset, ctx.codeFeatures.verification, `...`, ...generatePropExp(options, ctx, prop, prop.exp, ctx.codeFeatures.all, enableCodeFeatures));
|
|
149
151
|
if (enableCodeFeatures) {
|
|
150
152
|
yield* codes;
|
|
151
153
|
}
|
|
@@ -157,7 +159,8 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
157
159
|
}
|
|
158
160
|
}
|
|
159
161
|
}
|
|
160
|
-
function* generatePropExp(options, ctx, prop, exp, features,
|
|
162
|
+
function* generatePropExp(options, ctx, prop, exp, features, enableCodeFeatures = true) {
|
|
163
|
+
const isShorthand = prop.arg?.loc.start.offset === prop.exp?.loc.start.offset;
|
|
161
164
|
if (isShorthand && features.completion) {
|
|
162
165
|
features = {
|
|
163
166
|
...features,
|
|
@@ -166,7 +169,7 @@ function* generatePropExp(options, ctx, prop, exp, features, isShorthand, enable
|
|
|
166
169
|
}
|
|
167
170
|
if (exp && exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY) { // style='z-index: 2' will compile to {'z-index':'2'}
|
|
168
171
|
if (!isShorthand) { // vue 3.4+
|
|
169
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, exp.loc.source, exp.loc.start.offset, exp.loc,
|
|
172
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, exp.loc.source, exp.loc.start.offset, exp.loc, `(`, `)`);
|
|
170
173
|
}
|
|
171
174
|
else {
|
|
172
175
|
const propVariableName = (0, shared_1.camelize)(exp.loc.source);
|
|
@@ -220,28 +223,23 @@ function getShouldCamelize(options, prop, propName) {
|
|
|
220
223
|
&& !options.vueCompilerOptions.htmlAttributes.some(pattern => (0, minimatch_1.minimatch)(propName, pattern));
|
|
221
224
|
}
|
|
222
225
|
function getPropsCodeInfo(ctx, strictPropsCheck, shouldCamelize) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
?
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
? codeInfo.verification.shouldReport?.(_source, code) ?? true
|
|
241
|
-
: true;
|
|
242
|
-
},
|
|
243
|
-
}
|
|
244
|
-
};
|
|
226
|
+
return ctx.resolveCodeFeatures({
|
|
227
|
+
...codeFeatures_1.codeFeatures.withoutHighlightAndCompletion,
|
|
228
|
+
navigation: {
|
|
229
|
+
resolveRenameNewName: shared_1.camelize,
|
|
230
|
+
resolveRenameEditText: shouldCamelize ? shared_2.hyphenateAttr : undefined,
|
|
231
|
+
},
|
|
232
|
+
verification: strictPropsCheck || {
|
|
233
|
+
shouldReport(_source, code) {
|
|
234
|
+
// https://typescript.tv/errors/#ts2353
|
|
235
|
+
// https://typescript.tv/errors/#ts2561
|
|
236
|
+
if (String(code) === '2353' || String(code) === '2561') {
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
return true;
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
});
|
|
245
243
|
}
|
|
246
244
|
function getModelPropName(node, vueCompilerOptions) {
|
|
247
245
|
for (const modelName in vueCompilerOptions.experimentalModelPropName) {
|
|
@@ -16,6 +16,7 @@ export interface TemplateCodegenOptions {
|
|
|
16
16
|
slotsAssignName?: string;
|
|
17
17
|
propsAssignName?: string;
|
|
18
18
|
inheritAttrs: boolean;
|
|
19
|
+
selfComponentName?: string;
|
|
19
20
|
}
|
|
20
21
|
export declare function generateTemplate(options: TemplateCodegenOptions): Generator<Code, TemplateCodegenContext>;
|
|
21
22
|
export declare function forEachElementNode(node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode): Generator<CompilerDOM.ElementNode>;
|
|
@@ -5,7 +5,6 @@ exports.forEachElementNode = forEachElementNode;
|
|
|
5
5
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
6
6
|
const shared_1 = require("../../utils/shared");
|
|
7
7
|
const utils_1 = require("../utils");
|
|
8
|
-
const stringLiteralKey_1 = require("../utils/stringLiteralKey");
|
|
9
8
|
const context_1 = require("./context");
|
|
10
9
|
const objectProperty_1 = require("./objectProperty");
|
|
11
10
|
const styleScopedClasses_1 = require("./styleScopedClasses");
|
|
@@ -18,54 +17,69 @@ function* generateTemplate(options) {
|
|
|
18
17
|
if (options.propsAssignName) {
|
|
19
18
|
ctx.addLocalVariable(options.propsAssignName);
|
|
20
19
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
const slotsPropertyName = (0, shared_1.getSlotsPropertyName)(options.vueCompilerOptions.target);
|
|
21
|
+
if (options.vueCompilerOptions.inferTemplateDollarSlots) {
|
|
22
|
+
ctx.dollarVars.add(slotsPropertyName);
|
|
23
|
+
}
|
|
24
|
+
if (options.vueCompilerOptions.inferTemplateDollarAttrs) {
|
|
25
|
+
ctx.dollarVars.add('$attrs');
|
|
26
|
+
}
|
|
27
|
+
if (options.vueCompilerOptions.inferTemplateDollarRefs) {
|
|
28
|
+
ctx.dollarVars.add('$refs');
|
|
29
|
+
}
|
|
30
|
+
if (options.vueCompilerOptions.inferTemplateDollarEl) {
|
|
31
|
+
ctx.dollarVars.add('$el');
|
|
32
|
+
}
|
|
25
33
|
if (options.template.ast) {
|
|
26
34
|
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, options.template.ast, undefined);
|
|
27
35
|
}
|
|
28
36
|
yield* (0, styleScopedClasses_1.generateStyleScopedClassReferences)(ctx);
|
|
29
|
-
yield* generateSlots(options, ctx);
|
|
30
|
-
yield* generateInheritedAttrs(ctx);
|
|
31
|
-
yield* generateRefs(ctx);
|
|
32
|
-
yield* generateRootEl(ctx);
|
|
33
37
|
yield* ctx.generateAutoImportCompletion();
|
|
38
|
+
yield* ctx.generateHoistVariables();
|
|
39
|
+
const speicalTypes = [
|
|
40
|
+
[slotsPropertyName, yield* generateSlots(options, ctx)],
|
|
41
|
+
['$attrs', yield* generateInheritedAttrs(options, ctx)],
|
|
42
|
+
['$refs', yield* generateTemplateRefs(options, ctx)],
|
|
43
|
+
['$el', yield* generateRootEl(ctx)]
|
|
44
|
+
];
|
|
45
|
+
yield `var __VLS_dollars!: {${utils_1.newLine}`;
|
|
46
|
+
for (const [name, type] of speicalTypes) {
|
|
47
|
+
yield `${name}: ${type}${utils_1.endOfLine}`;
|
|
48
|
+
}
|
|
49
|
+
yield `} & { [K in keyof import('${options.vueCompilerOptions.lib}').ComponentPublicInstance]: unknown }${utils_1.endOfLine}`;
|
|
34
50
|
return ctx;
|
|
35
51
|
}
|
|
36
52
|
function* generateSlots(options, ctx) {
|
|
37
53
|
if (!options.hasDefineSlots) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
yield
|
|
54
|
+
const name = (0, shared_1.getSlotsPropertyName)(options.vueCompilerOptions.target);
|
|
55
|
+
yield `type __VLS_Slots = __VLS_PrettifyGlobal<__VLS_OmitStringIndex<typeof __VLS_ctx.${name}>`;
|
|
56
|
+
for (const { expVar, propsVar } of ctx.dynamicSlots) {
|
|
57
|
+
yield `${utils_1.newLine}& { [K in NonNullable<typeof ${expVar}>]?: (props: typeof ${propsVar}) => any }`;
|
|
42
58
|
}
|
|
43
|
-
yield `{${utils_1.newLine}`;
|
|
44
59
|
for (const slot of ctx.slots) {
|
|
45
|
-
|
|
46
|
-
if (slot.name && slot.
|
|
47
|
-
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slot.name, slot.
|
|
60
|
+
yield `${utils_1.newLine}& { `;
|
|
61
|
+
if (slot.name && slot.offset !== undefined) {
|
|
62
|
+
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slot.name, slot.offset, ctx.codeFeatures.withoutHighlightAndCompletion, slot.nodeLoc);
|
|
48
63
|
}
|
|
49
64
|
else {
|
|
50
65
|
yield* (0, utils_1.wrapWith)(slot.tagRange[0], slot.tagRange[1], ctx.codeFeatures.withoutHighlightAndCompletion, `default`);
|
|
51
66
|
}
|
|
52
|
-
yield
|
|
67
|
+
yield `?: (props: typeof ${slot.propsVar}) => any }`;
|
|
53
68
|
}
|
|
54
|
-
yield
|
|
69
|
+
yield `>${utils_1.endOfLine}`;
|
|
55
70
|
}
|
|
56
|
-
|
|
57
|
-
yield `var ${name}!: typeof ${options.slotsAssignName ?? '__VLS_slots'}${utils_1.endOfLine}`;
|
|
71
|
+
return `__VLS_Slots`;
|
|
58
72
|
}
|
|
59
|
-
function* generateInheritedAttrs(ctx) {
|
|
60
|
-
yield
|
|
73
|
+
function* generateInheritedAttrs(options, ctx) {
|
|
74
|
+
yield `type __VLS_InheritedAttrs = {}`;
|
|
61
75
|
for (const varName of ctx.inheritedAttrVars) {
|
|
62
76
|
yield ` & typeof ${varName}`;
|
|
63
77
|
}
|
|
64
78
|
yield utils_1.endOfLine;
|
|
65
|
-
yield `var $attrs!: Partial<typeof __VLS_inheritedAttrs> & Record<string, unknown>${utils_1.endOfLine}`;
|
|
66
79
|
if (ctx.bindingAttrLocs.length) {
|
|
67
80
|
yield `[`;
|
|
68
81
|
for (const loc of ctx.bindingAttrLocs) {
|
|
82
|
+
yield `__VLS_dollars.`;
|
|
69
83
|
yield [
|
|
70
84
|
loc.source,
|
|
71
85
|
'template',
|
|
@@ -76,23 +90,29 @@ function* generateInheritedAttrs(ctx) {
|
|
|
76
90
|
}
|
|
77
91
|
yield `]${utils_1.endOfLine}`;
|
|
78
92
|
}
|
|
93
|
+
return `import('${options.vueCompilerOptions.lib}').ComponentPublicInstance['$attrs'] & Partial<__VLS_InheritedAttrs>`;
|
|
79
94
|
}
|
|
80
|
-
function*
|
|
81
|
-
yield `
|
|
82
|
-
for (const [name,
|
|
83
|
-
yield* (0,
|
|
84
|
-
yield `: ${
|
|
95
|
+
function* generateTemplateRefs(options, ctx) {
|
|
96
|
+
yield `type __VLS_TemplateRefs = {${utils_1.newLine}`;
|
|
97
|
+
for (const [name, { typeExp, offset }] of ctx.templateRefs) {
|
|
98
|
+
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, name, offset, ctx.codeFeatures.navigationAndCompletion);
|
|
99
|
+
yield `: ${typeExp},${utils_1.newLine}`;
|
|
85
100
|
}
|
|
86
101
|
yield `}${utils_1.endOfLine}`;
|
|
87
|
-
|
|
102
|
+
return `__VLS_TemplateRefs`;
|
|
88
103
|
}
|
|
89
104
|
function* generateRootEl(ctx) {
|
|
90
|
-
|
|
91
|
-
|
|
105
|
+
yield `type __VLS_RootEl = `;
|
|
106
|
+
if (ctx.singleRootElTypes.length && !ctx.singleRootNodes.has(null)) {
|
|
107
|
+
for (const type of ctx.singleRootElTypes) {
|
|
108
|
+
yield `${utils_1.newLine}| ${type}`;
|
|
109
|
+
}
|
|
92
110
|
}
|
|
93
111
|
else {
|
|
94
|
-
yield `
|
|
112
|
+
yield `any`;
|
|
95
113
|
}
|
|
114
|
+
yield utils_1.endOfLine;
|
|
115
|
+
return `__VLS_RootEl`;
|
|
96
116
|
}
|
|
97
117
|
function* forEachElementNode(node) {
|
|
98
118
|
if (node.type === CompilerDOM.NodeTypes.ROOT) {
|
|
@@ -45,15 +45,16 @@ function* generateInterpolation(options, ctx, source, data, _code, start, astHol
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
+
;
|
|
48
49
|
function* forEachInterpolationSegment(ts, destructuredPropNames, templateRefNames, ctx, code, offset, ast) {
|
|
49
50
|
let ctxVars = [];
|
|
50
51
|
const varCb = (id, isShorthand) => {
|
|
51
52
|
const text = (0, scriptSetupRanges_1.getNodeText)(ts, id, ast);
|
|
52
|
-
if (ctx.hasLocalVariable(text)
|
|
53
|
+
if (ctx.hasLocalVariable(text)
|
|
53
54
|
// https://github.com/vuejs/core/blob/245230e135152900189f13a4281302de45fdcfaa/packages/compiler-core/src/transforms/transformExpression.ts#L342-L352
|
|
54
|
-
(0, shared_1.isGloballyAllowed)(text)
|
|
55
|
-
text === 'require'
|
|
56
|
-
text.startsWith('__VLS_')) {
|
|
55
|
+
|| (0, shared_1.isGloballyAllowed)(text)
|
|
56
|
+
|| text === 'require'
|
|
57
|
+
|| text.startsWith('__VLS_')) {
|
|
57
58
|
// localVarOffsets.push(localVar.getStart(ast));
|
|
58
59
|
}
|
|
59
60
|
else {
|
|
@@ -86,7 +87,7 @@ function* forEachInterpolationSegment(ts, destructuredPropNames, templateRefName
|
|
|
86
87
|
for (let i = 0; i < ctxVars.length - 1; i++) {
|
|
87
88
|
const curVar = ctxVars[i];
|
|
88
89
|
const nextVar = ctxVars[i + 1];
|
|
89
|
-
yield* generateVar(code, destructuredPropNames, templateRefNames, curVar
|
|
90
|
+
yield* generateVar(code, ctx.dollarVars, destructuredPropNames, templateRefNames, curVar);
|
|
90
91
|
if (nextVar.isShorthand) {
|
|
91
92
|
yield [code.slice(curVar.offset + curVar.text.length, nextVar.offset + nextVar.text.length), curVar.offset + curVar.text.length];
|
|
92
93
|
yield [': ', undefined];
|
|
@@ -96,7 +97,7 @@ function* forEachInterpolationSegment(ts, destructuredPropNames, templateRefName
|
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
99
|
const lastVar = ctxVars.at(-1);
|
|
99
|
-
yield* generateVar(code, destructuredPropNames, templateRefNames, lastVar);
|
|
100
|
+
yield* generateVar(code, ctx.dollarVars, destructuredPropNames, templateRefNames, lastVar);
|
|
100
101
|
if (lastVar.offset + lastVar.text.length < code.length) {
|
|
101
102
|
yield [code.slice(lastVar.offset + lastVar.text.length), lastVar.offset + lastVar.text.length, 'endText'];
|
|
102
103
|
}
|
|
@@ -105,10 +106,10 @@ function* forEachInterpolationSegment(ts, destructuredPropNames, templateRefName
|
|
|
105
106
|
yield [code, 0];
|
|
106
107
|
}
|
|
107
108
|
}
|
|
108
|
-
function* generateVar(code, destructuredPropNames, templateRefNames, curVar
|
|
109
|
+
function* generateVar(code, dollarVars, destructuredPropNames, templateRefNames, curVar) {
|
|
109
110
|
// fix https://github.com/vuejs/language-tools/issues/1205
|
|
110
111
|
// fix https://github.com/vuejs/language-tools/issues/1264
|
|
111
|
-
yield ['',
|
|
112
|
+
yield ['', curVar.offset, 'errorMappingOnly'];
|
|
112
113
|
const isDestructuredProp = destructuredPropNames?.has(curVar.text) ?? false;
|
|
113
114
|
const isTemplateRef = templateRefNames?.has(curVar.text) ?? false;
|
|
114
115
|
if (isTemplateRef) {
|
|
@@ -117,7 +118,10 @@ function* generateVar(code, destructuredPropNames, templateRefNames, curVar, nex
|
|
|
117
118
|
yield [`)`, undefined];
|
|
118
119
|
}
|
|
119
120
|
else {
|
|
120
|
-
if (
|
|
121
|
+
if (dollarVars.has(curVar.text)) {
|
|
122
|
+
yield [`__VLS_dollars.`, undefined];
|
|
123
|
+
}
|
|
124
|
+
else if (!isDestructuredProp) {
|
|
121
125
|
yield [`__VLS_ctx.`, undefined];
|
|
122
126
|
}
|
|
123
127
|
yield [code.slice(curVar.offset, curVar.offset + curVar.text.length), curVar.offset];
|
|
@@ -7,9 +7,11 @@ const utils_1 = require("../utils");
|
|
|
7
7
|
const elementChildren_1 = require("./elementChildren");
|
|
8
8
|
const elementProps_1 = require("./elementProps");
|
|
9
9
|
const interpolation_1 = require("./interpolation");
|
|
10
|
+
const propertyAccess_1 = require("./propertyAccess");
|
|
10
11
|
function* generateSlotOutlet(options, ctx, node) {
|
|
11
12
|
const startTagOffset = node.loc.start.offset + options.template.content.slice(node.loc.start.offset).indexOf(node.tag);
|
|
12
|
-
const
|
|
13
|
+
const startTagEndOffset = startTagOffset + node.tag.length;
|
|
14
|
+
const propsVar = ctx.getInternalVariable();
|
|
13
15
|
const nameProp = node.props.find(prop => {
|
|
14
16
|
if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE) {
|
|
15
17
|
return prop.name === 'name';
|
|
@@ -21,28 +23,49 @@ function* generateSlotOutlet(options, ctx, node) {
|
|
|
21
23
|
}
|
|
22
24
|
});
|
|
23
25
|
if (options.hasDefineSlots) {
|
|
24
|
-
yield `
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
yield `__VLS_asFunctionalSlot(`;
|
|
27
|
+
if (nameProp) {
|
|
28
|
+
let codes;
|
|
29
|
+
if (nameProp.type === CompilerDOM.NodeTypes.ATTRIBUTE && nameProp.value) {
|
|
30
|
+
let { source, start: { offset } } = nameProp.value.loc;
|
|
31
|
+
if (source.startsWith('"') || source.startsWith("'")) {
|
|
32
|
+
source = source.slice(1, -1);
|
|
33
|
+
offset++;
|
|
34
|
+
}
|
|
35
|
+
codes = (0, propertyAccess_1.generatePropertyAccess)(options, ctx, source, offset, ctx.codeFeatures.navigationAndVerification);
|
|
36
|
+
}
|
|
37
|
+
else if (nameProp.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
38
|
+
&& nameProp.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
39
|
+
codes = [
|
|
40
|
+
`[`,
|
|
41
|
+
...(0, elementProps_1.generatePropExp)(options, ctx, nameProp, nameProp.exp, ctx.codeFeatures.all),
|
|
42
|
+
`]`
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
codes = [`['default']`];
|
|
47
|
+
}
|
|
48
|
+
yield* (0, utils_1.wrapWith)(nameProp.loc.start.offset, nameProp.loc.end.offset, ctx.codeFeatures.verification, `${options.slotsAssignName ?? '__VLS_slots'}`, ...codes);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
yield* (0, utils_1.wrapWith)(startTagOffset, startTagEndOffset, ctx.codeFeatures.verification, `${options.slotsAssignName ?? '__VLS_slots'}[`, ...(0, utils_1.wrapWith)(startTagOffset, startTagEndOffset, ctx.codeFeatures.verification, `'default'`), `]`);
|
|
52
|
+
}
|
|
53
|
+
yield `)(`;
|
|
54
|
+
yield* (0, utils_1.wrapWith)(startTagOffset, startTagEndOffset, ctx.codeFeatures.verification, `{${utils_1.newLine}`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), true, true), `}`);
|
|
32
55
|
yield `)${utils_1.endOfLine}`;
|
|
33
56
|
}
|
|
34
57
|
else {
|
|
35
|
-
yield `var ${
|
|
36
|
-
yield* (0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), options.vueCompilerOptions.
|
|
58
|
+
yield `var ${propsVar} = {${utils_1.newLine}`;
|
|
59
|
+
yield* (0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), options.vueCompilerOptions.checkUnknownProps, true);
|
|
37
60
|
yield `}${utils_1.endOfLine}`;
|
|
38
61
|
if (nameProp?.type === CompilerDOM.NodeTypes.ATTRIBUTE
|
|
39
62
|
&& nameProp.value) {
|
|
40
63
|
ctx.slots.push({
|
|
41
64
|
name: nameProp.value.content,
|
|
42
|
-
|
|
65
|
+
offset: nameProp.loc.start.offset + nameProp.loc.source.indexOf(nameProp.value.content, nameProp.name.length),
|
|
43
66
|
tagRange: [startTagOffset, startTagOffset + node.tag.length],
|
|
44
|
-
varName: varSlot,
|
|
45
67
|
nodeLoc: node.loc,
|
|
68
|
+
propsVar: ctx.getHoistVariable(propsVar),
|
|
46
69
|
});
|
|
47
70
|
}
|
|
48
71
|
else if (nameProp?.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
@@ -51,21 +74,21 @@ function* generateSlotOutlet(options, ctx, node) {
|
|
|
51
74
|
if (isShortHand) {
|
|
52
75
|
ctx.inlayHints.push((0, inlayHints_1.createVBindShorthandInlayHintInfo)(nameProp.exp.loc, 'name'));
|
|
53
76
|
}
|
|
54
|
-
const
|
|
55
|
-
yield `var ${
|
|
56
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, nameProp.exp.content, nameProp.exp.loc.start.offset, nameProp.exp
|
|
57
|
-
yield `
|
|
77
|
+
const expVar = ctx.getInternalVariable();
|
|
78
|
+
yield `var ${expVar} = __VLS_tryAsConstant(`;
|
|
79
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, nameProp.exp.content, nameProp.exp.loc.start.offset, nameProp.exp);
|
|
80
|
+
yield `)${utils_1.endOfLine}`;
|
|
58
81
|
ctx.dynamicSlots.push({
|
|
59
|
-
expVar:
|
|
60
|
-
|
|
82
|
+
expVar: ctx.getHoistVariable(expVar),
|
|
83
|
+
propsVar: ctx.getHoistVariable(propsVar),
|
|
61
84
|
});
|
|
62
85
|
}
|
|
63
86
|
else {
|
|
64
87
|
ctx.slots.push({
|
|
65
88
|
name: 'default',
|
|
66
|
-
tagRange: [startTagOffset,
|
|
67
|
-
varName: varSlot,
|
|
89
|
+
tagRange: [startTagOffset, startTagEndOffset],
|
|
68
90
|
nodeLoc: node.loc,
|
|
91
|
+
propsVar: ctx.getHoistVariable(propsVar),
|
|
69
92
|
});
|
|
70
93
|
}
|
|
71
94
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import * as CompilerDOM from '@vue/compiler-dom';
|
|
1
2
|
import type { Code } from '../../types';
|
|
2
3
|
import type { TemplateCodegenContext } from './context';
|
|
4
|
+
import type { TemplateCodegenOptions } from './index';
|
|
3
5
|
export declare function generateStyleScopedClassReferences(ctx: TemplateCodegenContext, withDot?: boolean): Generator<Code>;
|
|
6
|
+
export declare function collectStyleScopedClassReferences(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode): void;
|