@vue/language-core 2.2.10 → 3.0.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +1 -2
- package/index.js +1 -1
- package/lib/codegen/codeFeatures.d.ts +5 -0
- package/lib/codegen/codeFeatures.js +5 -0
- package/lib/codegen/globalTypes.js +44 -31
- package/lib/codegen/localTypes.d.ts +2 -3
- package/lib/codegen/localTypes.js +5 -15
- package/lib/codegen/script/component.js +21 -9
- package/lib/codegen/script/context.d.ts +1 -1
- package/lib/codegen/script/context.js +1 -1
- package/lib/codegen/script/index.d.ts +1 -2
- package/lib/codegen/script/index.js +2 -18
- package/lib/codegen/script/scriptSetup.js +5 -16
- package/lib/codegen/script/src.js +4 -22
- package/lib/codegen/script/template.js +7 -6
- package/lib/codegen/template/context.d.ts +29 -19
- package/lib/codegen/template/context.js +87 -56
- package/lib/codegen/template/element.d.ts +2 -2
- package/lib/codegen/template/element.js +34 -63
- package/lib/codegen/template/elementChildren.d.ts +2 -2
- package/lib/codegen/template/elementChildren.js +4 -6
- package/lib/codegen/template/elementDirectives.js +3 -15
- package/lib/codegen/template/elementEvents.d.ts +4 -3
- package/lib/codegen/template/elementEvents.js +61 -29
- package/lib/codegen/template/elementProps.d.ts +2 -2
- package/lib/codegen/template/elementProps.js +11 -22
- package/lib/codegen/template/index.d.ts +1 -2
- package/lib/codegen/template/index.js +22 -11
- package/lib/codegen/template/interpolation.d.ts +1 -1
- package/lib/codegen/template/interpolation.js +53 -51
- package/lib/codegen/template/slotOutlet.js +2 -3
- package/lib/codegen/template/styleScopedClasses.js +2 -2
- package/lib/codegen/template/templateChild.d.ts +1 -1
- package/lib/codegen/template/templateChild.js +12 -46
- package/lib/codegen/template/vFor.js +5 -10
- package/lib/codegen/template/vIf.js +2 -10
- package/lib/codegen/template/vSlot.d.ts +1 -2
- package/lib/codegen/template/vSlot.js +111 -59
- package/lib/codegen/utils/index.d.ts +2 -3
- package/lib/codegen/utils/index.js +2 -18
- package/lib/languagePlugin.d.ts +1 -1
- package/lib/languagePlugin.js +1 -7
- package/lib/parsers/scriptRanges.d.ts +2 -3
- package/lib/parsers/scriptRanges.js +10 -13
- package/lib/parsers/scriptSetupRanges.d.ts +0 -3
- package/lib/parsers/scriptSetupRanges.js +36 -43
- package/lib/plugins/file-md.js +3 -0
- package/lib/plugins/vue-style-css.d.ts +3 -0
- package/lib/plugins/vue-style-css.js +18 -0
- package/lib/plugins/vue-template-inline-css.js +1 -1
- package/lib/plugins/vue-template-inline-ts.js +5 -2
- package/lib/plugins/vue-tsx.d.ts +27 -18
- package/lib/plugins/vue-tsx.js +32 -24
- package/lib/plugins.d.ts +1 -1
- package/lib/types.d.ts +3 -2
- package/lib/utils/shared.d.ts +4 -1
- package/lib/utils/shared.js +12 -4
- package/lib/utils/signals.d.ts +1 -0
- package/lib/utils/signals.js +11 -0
- package/lib/utils/ts.d.ts +0 -4
- package/lib/utils/ts.js +4 -14
- package/lib/virtualFile/computedSfc.js +6 -6
- package/package.json +6 -8
- package/lib/utils/vue2TemplateCompiler.d.ts +0 -2
- package/lib/utils/vue2TemplateCompiler.js +0 -89
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateElementEvents = generateElementEvents;
|
|
4
4
|
exports.generateEventArg = generateEventArg;
|
|
5
5
|
exports.generateEventExpression = generateEventExpression;
|
|
6
|
+
exports.generateModelEventExpression = generateModelEventExpression;
|
|
6
7
|
exports.isCompoundExpression = isCompoundExpression;
|
|
7
8
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
8
9
|
const shared_1 = require("@vue/shared");
|
|
@@ -10,54 +11,74 @@ const utils_1 = require("../utils");
|
|
|
10
11
|
const camelized_1 = require("../utils/camelized");
|
|
11
12
|
const wrapWith_1 = require("../utils/wrapWith");
|
|
12
13
|
const interpolation_1 = require("./interpolation");
|
|
13
|
-
function* generateElementEvents(options, ctx, node, componentFunctionalVar, componentVNodeVar, componentCtxVar) {
|
|
14
|
-
let
|
|
15
|
-
let eventsVar;
|
|
14
|
+
function* generateElementEvents(options, ctx, node, componentOriginalVar, componentFunctionalVar, componentVNodeVar, componentCtxVar) {
|
|
15
|
+
let emitsVar;
|
|
16
16
|
let propsVar;
|
|
17
17
|
for (const prop of node.props) {
|
|
18
18
|
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
19
|
-
&& prop.name === 'on'
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
&& (prop.name === 'on'
|
|
20
|
+
&& (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic)
|
|
21
|
+
|| options.vueCompilerOptions.strictVModel
|
|
22
|
+
&& prop.name === 'model'
|
|
23
|
+
&& (!prop.arg || prop.arg.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic))) {
|
|
22
24
|
ctx.currentComponent.used = true;
|
|
23
|
-
if (!
|
|
24
|
-
|
|
25
|
-
eventsVar = ctx.getInternalVariable();
|
|
25
|
+
if (!emitsVar) {
|
|
26
|
+
emitsVar = ctx.getInternalVariable();
|
|
26
27
|
propsVar = ctx.getInternalVariable();
|
|
27
|
-
yield `let ${
|
|
28
|
-
yield `let ${eventsVar}!: __VLS_NormalizeEmits<typeof ${emitVar}>${utils_1.endOfLine}`;
|
|
28
|
+
yield `let ${emitsVar}!: __VLS_ResolveEmits<typeof ${componentOriginalVar}, typeof ${componentCtxVar}.emit>${utils_1.endOfLine}`;
|
|
29
29
|
yield `let ${propsVar}!: __VLS_FunctionalComponentProps<typeof ${componentFunctionalVar}, typeof ${componentVNodeVar}>${utils_1.endOfLine}`;
|
|
30
30
|
}
|
|
31
|
-
let source = prop.arg
|
|
32
|
-
let start = prop.arg
|
|
33
|
-
let propPrefix = 'on';
|
|
31
|
+
let source = prop.arg?.loc.source ?? 'model-value';
|
|
32
|
+
let start = prop.arg?.loc.start.offset;
|
|
33
|
+
let propPrefix = 'on-';
|
|
34
34
|
let emitPrefix = '';
|
|
35
|
-
if (
|
|
35
|
+
if (prop.name === 'model') {
|
|
36
|
+
propPrefix = 'onUpdate:';
|
|
37
|
+
emitPrefix = 'update:';
|
|
38
|
+
}
|
|
39
|
+
else if (source.startsWith('vue:')) {
|
|
36
40
|
source = source.slice('vue:'.length);
|
|
37
41
|
start = start + 'vue:'.length;
|
|
38
|
-
propPrefix = 'onVnode';
|
|
42
|
+
propPrefix = 'onVnode-';
|
|
39
43
|
emitPrefix = 'vnode-';
|
|
40
44
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
yield
|
|
45
|
-
|
|
45
|
+
const propName = (0, shared_1.camelize)(propPrefix + source);
|
|
46
|
+
const emitName = emitPrefix + source;
|
|
47
|
+
const camelizedEmitName = (0, shared_1.camelize)(emitName);
|
|
48
|
+
yield `(): __VLS_NormalizeComponentEvent<typeof ${propsVar}, typeof ${emitsVar}, '${propName}', '${emitName}', '${camelizedEmitName}'> => (${utils_1.newLine}`;
|
|
49
|
+
if (prop.name === 'on') {
|
|
50
|
+
yield `{ `;
|
|
51
|
+
yield* generateEventArg(ctx, source, start, emitPrefix.slice(0, -1), ctx.codeFeatures.navigation);
|
|
52
|
+
yield `: {} as any } as typeof ${emitsVar},${utils_1.newLine}`;
|
|
53
|
+
}
|
|
54
|
+
yield `{ `;
|
|
55
|
+
if (prop.name === 'on') {
|
|
56
|
+
yield* generateEventArg(ctx, source, start, propPrefix.slice(0, -1));
|
|
57
|
+
yield `: `;
|
|
58
|
+
yield* generateEventExpression(options, ctx, prop);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
yield `'${propName}': `;
|
|
62
|
+
yield* generateModelEventExpression(options, ctx, prop);
|
|
63
|
+
}
|
|
64
|
+
yield `})${utils_1.endOfLine}`;
|
|
46
65
|
}
|
|
47
66
|
}
|
|
48
67
|
}
|
|
49
|
-
function* generateEventArg(ctx, name, start, directive = 'on'
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
68
|
+
function* generateEventArg(ctx, name, start, directive = 'on', features = {
|
|
69
|
+
...ctx.codeFeatures.withoutHighlightAndCompletion,
|
|
70
|
+
...ctx.codeFeatures.navigationWithoutRename,
|
|
71
|
+
}) {
|
|
72
|
+
if (directive.length) {
|
|
73
|
+
name = (0, shared_1.capitalize)(name);
|
|
74
|
+
}
|
|
54
75
|
if (utils_1.identifierRegex.test((0, shared_1.camelize)(name))) {
|
|
55
76
|
yield ['', 'template', start, features];
|
|
56
77
|
yield directive;
|
|
57
|
-
yield* (0, camelized_1.generateCamelized)(
|
|
78
|
+
yield* (0, camelized_1.generateCamelized)(name, 'template', start, utils_1.combineLastMapping);
|
|
58
79
|
}
|
|
59
80
|
else {
|
|
60
|
-
yield* (0, wrapWith_1.wrapWith)(start, start + name.length, features, `'`, directive, ...(0, camelized_1.generateCamelized)(
|
|
81
|
+
yield* (0, wrapWith_1.wrapWith)(start, start + name.length, features, `'`, directive, ...(0, camelized_1.generateCamelized)(name, 'template', start, utils_1.combineLastMapping), `'`);
|
|
61
82
|
}
|
|
62
83
|
}
|
|
63
84
|
function* generateEventExpression(options, ctx, prop) {
|
|
@@ -95,7 +116,6 @@ function* generateEventExpression(options, ctx, prop) {
|
|
|
95
116
|
if (_isCompoundExpression) {
|
|
96
117
|
ctx.removeLocalVariable('$event');
|
|
97
118
|
yield utils_1.endOfLine;
|
|
98
|
-
yield* ctx.generateAutoImportCompletion();
|
|
99
119
|
yield `}`;
|
|
100
120
|
}
|
|
101
121
|
}
|
|
@@ -103,6 +123,18 @@ function* generateEventExpression(options, ctx, prop) {
|
|
|
103
123
|
yield `() => {}`;
|
|
104
124
|
}
|
|
105
125
|
}
|
|
126
|
+
function* generateModelEventExpression(options, ctx, prop) {
|
|
127
|
+
if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
128
|
+
yield `(...[$event]) => {${utils_1.newLine}`;
|
|
129
|
+
yield* ctx.generateConditionGuards();
|
|
130
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.verification, prop.exp.content, prop.exp.loc.start.offset, prop.exp.loc);
|
|
131
|
+
yield ` = $event${utils_1.endOfLine}`;
|
|
132
|
+
yield `}`;
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
yield `() => {}`;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
106
138
|
function isCompoundExpression(ts, ast) {
|
|
107
139
|
let result = true;
|
|
108
140
|
if (ast.statements.length === 0) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as CompilerDOM from '@vue/compiler-dom';
|
|
2
|
-
import type { Code
|
|
2
|
+
import type { Code } from '../../types';
|
|
3
3
|
import type { TemplateCodegenContext } from './context';
|
|
4
4
|
import type { TemplateCodegenOptions } from './index';
|
|
5
5
|
export interface FailedPropExpression {
|
|
@@ -8,4 +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,
|
|
11
|
+
export declare function generatePropExp(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode, exp: CompilerDOM.SimpleExpressionNode | undefined, enableCodeFeatures?: boolean): Generator<Code>;
|
|
@@ -77,13 +77,13 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
77
77
|
}
|
|
78
78
|
const shouldSpread = propName === 'style' || propName === 'class';
|
|
79
79
|
const shouldCamelize = isComponent && getShouldCamelize(options, prop, propName);
|
|
80
|
-
const codeInfo = getPropsCodeInfo(ctx, strictPropsCheck
|
|
80
|
+
const codeInfo = getPropsCodeInfo(ctx, strictPropsCheck);
|
|
81
81
|
if (shouldSpread) {
|
|
82
82
|
yield `...{ `;
|
|
83
83
|
}
|
|
84
84
|
const codes = [...(0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, ...(prop.arg
|
|
85
85
|
? (0, objectProperty_1.generateObjectProperty)(options, ctx, propName, prop.arg.loc.start.offset, codeInfo, prop.loc.name_2 ??= {}, shouldCamelize)
|
|
86
|
-
: (0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + 'v-model'.length, ctx.codeFeatures.withoutHighlightAndCompletion, propName)), `: `, ...
|
|
86
|
+
: (0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + 'v-model'.length, ctx.codeFeatures.withoutHighlightAndCompletion, propName)), `: `, ...(0, wrapWith_1.wrapWith)(prop.arg?.loc.start.offset ?? prop.loc.start.offset, prop.arg?.loc.end.offset ?? prop.loc.end.offset, ctx.codeFeatures.verification, ...generatePropExp(options, ctx, prop, prop.exp, enableCodeFeatures)))];
|
|
87
87
|
if (enableCodeFeatures) {
|
|
88
88
|
yield* codes;
|
|
89
89
|
}
|
|
@@ -111,16 +111,12 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
else if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE) {
|
|
114
|
-
if (options.vueCompilerOptions.dataAttributes.some(pattern => (0, minimatch_1.minimatch)(prop.name, pattern))
|
|
115
|
-
// Vue 2 Transition doesn't support "persisted" property but `@vue/compiler-dom` always adds it (#3881)
|
|
116
|
-
|| (options.vueCompilerOptions.target < 3
|
|
117
|
-
&& prop.name === 'persisted'
|
|
118
|
-
&& node.tag.toLowerCase() === 'transition')) {
|
|
114
|
+
if (options.vueCompilerOptions.dataAttributes.some(pattern => (0, minimatch_1.minimatch)(prop.name, pattern))) {
|
|
119
115
|
continue;
|
|
120
116
|
}
|
|
121
117
|
const shouldSpread = prop.name === 'style' || prop.name === 'class';
|
|
122
118
|
const shouldCamelize = isComponent && getShouldCamelize(options, prop, prop.name);
|
|
123
|
-
const codeInfo = getPropsCodeInfo(ctx, strictPropsCheck
|
|
119
|
+
const codeInfo = getPropsCodeInfo(ctx, strictPropsCheck);
|
|
124
120
|
if (shouldSpread) {
|
|
125
121
|
yield `...{ `;
|
|
126
122
|
}
|
|
@@ -148,7 +144,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
148
144
|
}
|
|
149
145
|
}
|
|
150
146
|
else {
|
|
151
|
-
const codes = [...(0, wrapWith_1.wrapWith)(prop.exp.loc.start.offset, prop.exp.loc.end.offset, ctx.codeFeatures.verification, `...`, ...generatePropExp(options, ctx, prop, prop.exp,
|
|
147
|
+
const codes = [...(0, wrapWith_1.wrapWith)(prop.exp.loc.start.offset, prop.exp.loc.end.offset, ctx.codeFeatures.verification, `...`, ...generatePropExp(options, ctx, prop, prop.exp, enableCodeFeatures))];
|
|
152
148
|
if (enableCodeFeatures) {
|
|
153
149
|
yield* codes;
|
|
154
150
|
}
|
|
@@ -160,14 +156,11 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
|
|
|
160
156
|
}
|
|
161
157
|
}
|
|
162
158
|
}
|
|
163
|
-
function* generatePropExp(options, ctx, prop, exp,
|
|
159
|
+
function* generatePropExp(options, ctx, prop, exp, enableCodeFeatures = true) {
|
|
164
160
|
const isShorthand = prop.arg?.loc.start.offset === prop.exp?.loc.start.offset;
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
completion: undefined,
|
|
169
|
-
};
|
|
170
|
-
}
|
|
161
|
+
const features = isShorthand
|
|
162
|
+
? ctx.codeFeatures.withoutHighlightAndCompletion
|
|
163
|
+
: ctx.codeFeatures.all;
|
|
171
164
|
if (exp && exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY) { // style='z-index: 2' will compile to {'z-index':'2'}
|
|
172
165
|
if (!isShorthand) { // vue 3.4+
|
|
173
166
|
yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, exp.loc.source, exp.loc.start.offset, exp.loc, `(`, `)`);
|
|
@@ -223,13 +216,9 @@ function getShouldCamelize(options, prop, propName) {
|
|
|
223
216
|
&& (0, shared_2.hyphenateAttr)(propName) === propName
|
|
224
217
|
&& !options.vueCompilerOptions.htmlAttributes.some(pattern => (0, minimatch_1.minimatch)(propName, pattern));
|
|
225
218
|
}
|
|
226
|
-
function getPropsCodeInfo(ctx, strictPropsCheck
|
|
219
|
+
function getPropsCodeInfo(ctx, strictPropsCheck) {
|
|
227
220
|
return ctx.resolveCodeFeatures({
|
|
228
221
|
...codeFeatures_1.codeFeatures.withoutHighlightAndCompletion,
|
|
229
|
-
navigation: {
|
|
230
|
-
resolveRenameNewName: shared_1.camelize,
|
|
231
|
-
resolveRenameEditText: shouldCamelize ? shared_2.hyphenateAttr : undefined,
|
|
232
|
-
},
|
|
233
222
|
verification: strictPropsCheck || {
|
|
234
223
|
shouldReport(_source, code) {
|
|
235
224
|
// https://typescript.tv/errors/#ts2353
|
|
@@ -279,6 +268,6 @@ function getModelPropName(node, vueCompilerOptions) {
|
|
|
279
268
|
}
|
|
280
269
|
}
|
|
281
270
|
}
|
|
282
|
-
return
|
|
271
|
+
return 'modelValue';
|
|
283
272
|
}
|
|
284
273
|
//# sourceMappingURL=elementProps.js.map
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import * as CompilerDOM from '@vue/compiler-dom';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
3
|
import type { Code, Sfc, VueCompilerOptions } from '../../types';
|
|
4
|
-
import { TemplateCodegenContext } from './context';
|
|
4
|
+
import { type TemplateCodegenContext } from './context';
|
|
5
5
|
export interface TemplateCodegenOptions {
|
|
6
6
|
ts: typeof ts;
|
|
7
7
|
compilerOptions: ts.CompilerOptions;
|
|
8
8
|
vueCompilerOptions: VueCompilerOptions;
|
|
9
9
|
template: NonNullable<Sfc['template']>;
|
|
10
|
-
edited: boolean;
|
|
11
10
|
scriptSetupBindingNames: Set<string>;
|
|
12
11
|
scriptSetupImportComponentNames: Set<string>;
|
|
13
12
|
destructuredPropNames: Set<string>;
|
|
@@ -3,7 +3,6 @@ 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 shared_1 = require("../../utils/shared");
|
|
7
6
|
const utils_1 = require("../utils");
|
|
8
7
|
const wrapWith_1 = require("../utils/wrapWith");
|
|
9
8
|
const context_1 = require("./context");
|
|
@@ -18,9 +17,8 @@ function* generateTemplate(options) {
|
|
|
18
17
|
if (options.propsAssignName) {
|
|
19
18
|
ctx.addLocalVariable(options.propsAssignName);
|
|
20
19
|
}
|
|
21
|
-
const slotsPropertyName = (0, shared_1.getSlotsPropertyName)(options.vueCompilerOptions.target);
|
|
22
20
|
if (options.vueCompilerOptions.inferTemplateDollarSlots) {
|
|
23
|
-
ctx.dollarVars.add(
|
|
21
|
+
ctx.dollarVars.add('$slots');
|
|
24
22
|
}
|
|
25
23
|
if (options.vueCompilerOptions.inferTemplateDollarAttrs) {
|
|
26
24
|
ctx.dollarVars.add('$attrs');
|
|
@@ -32,13 +30,12 @@ function* generateTemplate(options) {
|
|
|
32
30
|
ctx.dollarVars.add('$el');
|
|
33
31
|
}
|
|
34
32
|
if (options.template.ast) {
|
|
35
|
-
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, options.template.ast
|
|
33
|
+
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, options.template.ast);
|
|
36
34
|
}
|
|
37
35
|
yield* (0, styleScopedClasses_1.generateStyleScopedClassReferences)(ctx);
|
|
38
|
-
yield* ctx.generateAutoImportCompletion();
|
|
39
36
|
yield* ctx.generateHoistVariables();
|
|
40
37
|
const speicalTypes = [
|
|
41
|
-
[
|
|
38
|
+
['$slots', yield* generateSlots(options, ctx)],
|
|
42
39
|
['$attrs', yield* generateInheritedAttrs(options, ctx)],
|
|
43
40
|
['$refs', yield* generateTemplateRefs(options, ctx)],
|
|
44
41
|
['$el', yield* generateRootEl(ctx)]
|
|
@@ -93,12 +90,26 @@ function* generateInheritedAttrs(options, ctx) {
|
|
|
93
90
|
return `import('${options.vueCompilerOptions.lib}').ComponentPublicInstance['$attrs'] & Partial<__VLS_InheritedAttrs>`;
|
|
94
91
|
}
|
|
95
92
|
function* generateTemplateRefs(options, ctx) {
|
|
96
|
-
yield `type __VLS_TemplateRefs = {
|
|
97
|
-
for (const [name,
|
|
98
|
-
yield
|
|
99
|
-
|
|
93
|
+
yield `type __VLS_TemplateRefs = {}`;
|
|
94
|
+
for (const [name, refs] of ctx.templateRefs) {
|
|
95
|
+
yield `${utils_1.newLine}& `;
|
|
96
|
+
if (refs.length >= 2) {
|
|
97
|
+
yield `(`;
|
|
98
|
+
}
|
|
99
|
+
for (let i = 0; i < refs.length; i++) {
|
|
100
|
+
const { typeExp, offset } = refs[i];
|
|
101
|
+
if (i) {
|
|
102
|
+
yield ` | `;
|
|
103
|
+
}
|
|
104
|
+
yield `{ `;
|
|
105
|
+
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, name, offset, ctx.codeFeatures.navigation);
|
|
106
|
+
yield `: ${typeExp} }`;
|
|
107
|
+
}
|
|
108
|
+
if (refs.length >= 2) {
|
|
109
|
+
yield `)`;
|
|
110
|
+
}
|
|
100
111
|
}
|
|
101
|
-
yield
|
|
112
|
+
yield utils_1.endOfLine;
|
|
102
113
|
return `__VLS_TemplateRefs`;
|
|
103
114
|
}
|
|
104
115
|
function* generateRootEl(ctx) {
|
|
@@ -5,4 +5,4 @@ export declare function generateInterpolation(options: {
|
|
|
5
5
|
ts: typeof ts;
|
|
6
6
|
destructuredPropNames: Set<string> | undefined;
|
|
7
7
|
templateRefNames: Set<string> | undefined;
|
|
8
|
-
}, ctx: TemplateCodegenContext, source: string, data: VueCodeInformation | ((offset: number) => VueCodeInformation) | 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>;
|
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateInterpolation = generateInterpolation;
|
|
4
4
|
const shared_1 = require("@vue/shared");
|
|
5
|
-
const
|
|
5
|
+
const shared_2 = require("../../utils/shared");
|
|
6
6
|
const utils_1 = require("../utils");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
for (let [section, offset, type] of forEachInterpolationSegment(options.ts, options.destructuredPropNames, options.templateRefNames, ctx, code, start
|
|
7
|
+
// https://github.com/vuejs/core/blob/fb0c3ca519f1fccf52049cd6b8db3a67a669afe9/packages/compiler-core/src/transforms/transformExpression.ts#L47
|
|
8
|
+
const isLiteralWhitelisted = /*@__PURE__*/ (0, shared_1.makeMap)('true,false,null,this');
|
|
9
|
+
function* generateInterpolation(options, ctx, source, data, code, start, astHolder = {}, prefix = '', suffix = '') {
|
|
10
|
+
for (let [section, offset, type] of forEachInterpolationSegment(options.ts, options.destructuredPropNames, options.templateRefNames, ctx, code, start, astHolder, prefix, suffix)) {
|
|
11
11
|
if (offset === undefined) {
|
|
12
12
|
yield section;
|
|
13
13
|
}
|
|
14
14
|
else {
|
|
15
15
|
offset -= prefix.length;
|
|
16
16
|
let addSuffix = '';
|
|
17
|
-
const overLength = offset + section.length -
|
|
17
|
+
const overLength = offset + section.length - code.length;
|
|
18
18
|
if (overLength > 0) {
|
|
19
19
|
addSuffix = section.slice(section.length - overLength);
|
|
20
20
|
section = section.slice(0, -overLength);
|
|
@@ -46,58 +46,46 @@ function* generateInterpolation(options, ctx, source, data, _code, start, astHol
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
;
|
|
49
|
-
function* forEachInterpolationSegment(ts, destructuredPropNames, templateRefNames, ctx,
|
|
49
|
+
function* forEachInterpolationSegment(ts, destructuredPropNames, templateRefNames, ctx, originalCode, start, astHolder, prefix, suffix) {
|
|
50
|
+
const code = prefix + originalCode + suffix;
|
|
51
|
+
const offset = start !== undefined ? start - prefix.length : undefined;
|
|
50
52
|
let ctxVars = [];
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
if (offset !== undefined) {
|
|
70
|
-
ctx.accessExternalVariable(text, offset + (0, scriptSetupRanges_1.getStartEnd)(ts, id, ast).start);
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
ctx.accessExternalVariable(text);
|
|
53
|
+
if (utils_1.identifierRegex.test(originalCode) && !shouldIdentifierSkipped(ctx, originalCode, destructuredPropNames)) {
|
|
54
|
+
ctxVars.push({
|
|
55
|
+
text: originalCode,
|
|
56
|
+
offset: prefix.length,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
const ast = (0, utils_1.createTsAst)(ts, astHolder, code);
|
|
61
|
+
const varCb = (id, isShorthand) => {
|
|
62
|
+
const text = (0, shared_2.getNodeText)(ts, id, ast);
|
|
63
|
+
if (!shouldIdentifierSkipped(ctx, text, destructuredPropNames)) {
|
|
64
|
+
ctxVars.push({
|
|
65
|
+
text,
|
|
66
|
+
offset: (0, shared_2.getStartEnd)(ts, id, ast).start,
|
|
67
|
+
isShorthand,
|
|
68
|
+
});
|
|
74
69
|
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
70
|
+
};
|
|
71
|
+
ts.forEachChild(ast, node => walkIdentifiers(ts, node, ast, varCb, ctx));
|
|
72
|
+
}
|
|
78
73
|
ctxVars = ctxVars.sort((a, b) => a.offset - b.offset);
|
|
79
74
|
if (ctxVars.length) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
yield [': ', undefined];
|
|
83
|
-
}
|
|
84
|
-
else if (ctxVars[0].offset > 0) {
|
|
85
|
-
yield [code.slice(0, ctxVars[0].offset), 0, 'startText'];
|
|
86
|
-
}
|
|
87
|
-
for (let i = 0; i < ctxVars.length - 1; i++) {
|
|
75
|
+
for (let i = 0; i < ctxVars.length; i++) {
|
|
76
|
+
const lastVar = ctxVars[i - 1];
|
|
88
77
|
const curVar = ctxVars[i];
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
yield [code.slice(curVar.offset + curVar.text.length, nextVar.offset + nextVar.text.length), curVar.offset + curVar.text.length];
|
|
78
|
+
const lastVarEnd = lastVar ? lastVar.offset + lastVar.text.length : 0;
|
|
79
|
+
if (curVar.isShorthand) {
|
|
80
|
+
yield [code.slice(lastVarEnd, curVar.offset + curVar.text.length), lastVarEnd];
|
|
93
81
|
yield [': ', undefined];
|
|
94
82
|
}
|
|
95
83
|
else {
|
|
96
|
-
yield [code.slice(
|
|
84
|
+
yield [code.slice(lastVarEnd, curVar.offset), lastVarEnd, i ? undefined : 'startText'];
|
|
97
85
|
}
|
|
86
|
+
yield* generateVar(templateRefNames, ctx, code, offset, curVar);
|
|
98
87
|
}
|
|
99
88
|
const lastVar = ctxVars.at(-1);
|
|
100
|
-
yield* generateVar(code, ctx.dollarVars, destructuredPropNames, templateRefNames, lastVar);
|
|
101
89
|
if (lastVar.offset + lastVar.text.length < code.length) {
|
|
102
90
|
yield [code.slice(lastVar.offset + lastVar.text.length), lastVar.offset + lastVar.text.length, 'endText'];
|
|
103
91
|
}
|
|
@@ -106,11 +94,10 @@ function* forEachInterpolationSegment(ts, destructuredPropNames, templateRefName
|
|
|
106
94
|
yield [code, 0];
|
|
107
95
|
}
|
|
108
96
|
}
|
|
109
|
-
function* generateVar(
|
|
97
|
+
function* generateVar(templateRefNames, ctx, code, offset, curVar) {
|
|
110
98
|
// fix https://github.com/vuejs/language-tools/issues/1205
|
|
111
99
|
// fix https://github.com/vuejs/language-tools/issues/1264
|
|
112
100
|
yield ['', curVar.offset, 'errorMappingOnly'];
|
|
113
|
-
const isDestructuredProp = destructuredPropNames?.has(curVar.text) ?? false;
|
|
114
101
|
const isTemplateRef = templateRefNames?.has(curVar.text) ?? false;
|
|
115
102
|
if (isTemplateRef) {
|
|
116
103
|
yield [`__VLS_unref(`, undefined];
|
|
@@ -118,10 +105,16 @@ function* generateVar(code, dollarVars, destructuredPropNames, templateRefNames,
|
|
|
118
105
|
yield [`)`, undefined];
|
|
119
106
|
}
|
|
120
107
|
else {
|
|
121
|
-
if (
|
|
108
|
+
if (offset !== undefined) {
|
|
109
|
+
ctx.accessExternalVariable(curVar.text, offset + curVar.offset);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
ctx.accessExternalVariable(curVar.text);
|
|
113
|
+
}
|
|
114
|
+
if (ctx.dollarVars.has(curVar.text)) {
|
|
122
115
|
yield [`__VLS_dollars.`, undefined];
|
|
123
116
|
}
|
|
124
|
-
else
|
|
117
|
+
else {
|
|
125
118
|
yield [`__VLS_ctx.`, undefined];
|
|
126
119
|
}
|
|
127
120
|
yield [code.slice(curVar.offset, curVar.offset + curVar.text.length), curVar.offset];
|
|
@@ -222,4 +215,13 @@ function walkIdentifiersInTypeReference(ts, node, cb) {
|
|
|
222
215
|
ts.forEachChild(node, node => walkIdentifiersInTypeReference(ts, node, cb));
|
|
223
216
|
}
|
|
224
217
|
}
|
|
218
|
+
function shouldIdentifierSkipped(ctx, text, destructuredPropNames) {
|
|
219
|
+
return ctx.hasLocalVariable(text)
|
|
220
|
+
// https://github.com/vuejs/core/blob/245230e135152900189f13a4281302de45fdcfaa/packages/compiler-core/src/transforms/transformExpression.ts#L342-L352
|
|
221
|
+
|| (0, shared_1.isGloballyAllowed)(text)
|
|
222
|
+
|| isLiteralWhitelisted(text)
|
|
223
|
+
|| text === 'require'
|
|
224
|
+
|| text.startsWith('__VLS_')
|
|
225
|
+
|| destructuredPropNames?.has(text);
|
|
226
|
+
}
|
|
225
227
|
//# sourceMappingURL=interpolation.js.map
|
|
@@ -39,7 +39,7 @@ function* generateSlotOutlet(options, ctx, node) {
|
|
|
39
39
|
&& nameProp.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
40
40
|
codes = [
|
|
41
41
|
`[`,
|
|
42
|
-
...(0, elementProps_1.generatePropExp)(options, ctx, nameProp, nameProp.exp
|
|
42
|
+
...(0, elementProps_1.generatePropExp)(options, ctx, nameProp, nameProp.exp),
|
|
43
43
|
`]`
|
|
44
44
|
];
|
|
45
45
|
}
|
|
@@ -93,7 +93,6 @@ function* generateSlotOutlet(options, ctx, node) {
|
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
yield* ctx.
|
|
97
|
-
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node);
|
|
96
|
+
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node.children);
|
|
98
97
|
}
|
|
99
98
|
//# sourceMappingURL=slotOutlet.js.map
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateStyleScopedClassReferences = generateStyleScopedClassReferences;
|
|
4
4
|
exports.collectStyleScopedClassReferences = collectStyleScopedClassReferences;
|
|
5
5
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
6
|
-
const
|
|
6
|
+
const shared_1 = require("../../utils/shared");
|
|
7
7
|
const utils_1 = require("../utils");
|
|
8
8
|
const escaped_1 = require("../utils/escaped");
|
|
9
9
|
const wrapWith_1 = require("../utils/wrapWith");
|
|
@@ -126,7 +126,7 @@ function collectStyleScopedClassReferences(options, ctx, node) {
|
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
function walkIdentifier(node) {
|
|
129
|
-
const text = (0,
|
|
129
|
+
const text = (0, shared_1.getNodeText)(ts, node, ast);
|
|
130
130
|
ctx.scopedClasses.push({
|
|
131
131
|
source: 'template',
|
|
132
132
|
className: text,
|
|
@@ -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, enterNode?: 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];
|