@vue/language-core 3.3.4 → 3.3.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 +1 -0
- package/index.js +1 -0
- package/lib/codegen/codeFeatures.d.ts +24 -84
- package/lib/codegen/codeFeatures.js +46 -4
- package/lib/codegen/names.d.ts +4 -5
- package/lib/codegen/names.js +4 -5
- package/lib/codegen/script/index.js +5 -5
- package/lib/codegen/script/scriptSetup.js +4 -4
- package/lib/codegen/style/common.js +7 -11
- package/lib/codegen/style/index.d.ts +55 -27
- package/lib/codegen/style/index.js +3 -3
- package/lib/codegen/template/context.d.ts +55 -124
- package/lib/codegen/template/context.js +187 -269
- package/lib/codegen/template/element.js +16 -15
- package/lib/codegen/template/elementDirectives.js +11 -11
- package/lib/codegen/template/elementEvents.js +76 -73
- package/lib/codegen/template/elementProps.js +12 -12
- package/lib/codegen/template/index.d.ts +55 -27
- package/lib/codegen/template/index.js +7 -7
- package/lib/codegen/template/interpolation.js +28 -28
- package/lib/codegen/template/objectProperty.js +5 -5
- package/lib/codegen/template/propertyAccess.js +1 -1
- package/lib/codegen/template/slotOutlet.js +8 -10
- package/lib/codegen/template/styleScopedClasses.js +4 -4
- package/lib/codegen/template/vFor.js +3 -3
- package/lib/codegen/template/vIf.js +4 -4
- package/lib/codegen/template/vSlot.js +9 -9
- package/lib/codegen/utils/boundary.d.ts +7 -2
- package/lib/codegen/utils/boundary.js +15 -9
- package/lib/codegen/utils/camelized.js +5 -13
- package/lib/codegen/utils/escaped.js +4 -9
- package/lib/codegen/utils/index.d.ts +1 -1
- package/lib/codegen/utils/index.js +3 -3
- package/lib/codegen/utils/stringLiteralKey.js +3 -3
- package/lib/codegen/utils/unicode.d.ts +1 -1
- package/lib/codegen/utils/unicode.js +4 -4
- package/lib/languagePlugin.js +2 -1
- package/lib/parsers/scriptRanges.d.ts +2 -2
- package/lib/parsers/scriptRanges.js +3 -10
- package/lib/parsers/scriptSetupRanges.d.ts +2 -2
- package/lib/parsers/scriptSetupRanges.js +3 -10
- package/lib/parsers/utils.d.ts +1 -0
- package/lib/parsers/utils.js +10 -0
- package/lib/parsers/vueCompilerOptions.js +2 -2
- package/lib/plugins/file-html.js +4 -4
- package/lib/plugins/file-md.js +15 -15
- package/lib/plugins/file-vue.js +2 -2
- package/lib/plugins/vue-root-tags.js +3 -3
- package/lib/plugins/vue-sfc-customblocks.js +2 -2
- package/lib/plugins/vue-sfc-scripts.js +2 -4
- package/lib/plugins/vue-sfc-styles.js +3 -3
- package/lib/plugins/vue-sfc-template.js +2 -2
- package/lib/plugins/vue-style-css.js +86 -33
- package/lib/plugins/vue-template-html.js +3 -3
- package/lib/plugins/vue-template-inline-css.js +2 -7
- package/lib/plugins/vue-template-inline-ts.js +4 -5
- package/lib/plugins/vue-tsx.d.ts +61 -31
- package/lib/plugins/vue-tsx.js +26 -23
- package/lib/plugins.d.ts +0 -1
- package/lib/plugins.js +0 -15
- package/lib/utils/forEachTemplateNode.js +36 -43
- package/lib/virtualCode/index.js +2 -2
- package/package.json +2 -2
- package/types/template-helpers.d.ts +15 -25
- package/lib/plugins/shared.d.ts +0 -2
- package/lib/plugins/shared.js +0 -12
|
@@ -40,14 +40,15 @@ exports.generateModelEventExpression = generateModelEventExpression;
|
|
|
40
40
|
exports.isCompoundExpression = isCompoundExpression;
|
|
41
41
|
const CompilerDOM = __importStar(require("@vue/compiler-dom"));
|
|
42
42
|
const shared_1 = require("@vue/shared");
|
|
43
|
+
const utils_1 = require("../../parsers/utils");
|
|
43
44
|
const codeFeatures_1 = require("../codeFeatures");
|
|
44
45
|
const names_1 = require("../names");
|
|
45
|
-
const
|
|
46
|
+
const utils_2 = require("../utils");
|
|
46
47
|
const boundary_1 = require("../utils/boundary");
|
|
47
48
|
const camelized_1 = require("../utils/camelized");
|
|
48
49
|
const interpolation_1 = require("./interpolation");
|
|
49
50
|
function* generateElementEvents(options, ctx, node, componentOriginalVar, getCtxVar, getPropsVar) {
|
|
50
|
-
const definitions =
|
|
51
|
+
const definitions = {};
|
|
51
52
|
for (const prop of node.props) {
|
|
52
53
|
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
53
54
|
&& (prop.name === 'on'
|
|
@@ -71,49 +72,51 @@ function* generateElementEvents(options, ctx, node, componentOriginalVar, getCtx
|
|
|
71
72
|
}
|
|
72
73
|
const propName = (0, shared_1.camelize)(propPrefix + source);
|
|
73
74
|
const emitName = emitPrefix + source;
|
|
74
|
-
|
|
75
|
-
prop,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
const key = [
|
|
76
|
+
prop.name,
|
|
77
|
+
propName,
|
|
78
|
+
...prop.modifiers.map(modifier => modifier.content),
|
|
79
|
+
].join('+');
|
|
80
|
+
definitions[key] ??= {
|
|
79
81
|
propPrefix,
|
|
82
|
+
emitPrefix,
|
|
80
83
|
propName,
|
|
81
84
|
emitName,
|
|
85
|
+
items: [],
|
|
86
|
+
};
|
|
87
|
+
definitions[key].items.push({
|
|
88
|
+
prop,
|
|
89
|
+
source,
|
|
90
|
+
offset,
|
|
82
91
|
});
|
|
83
92
|
}
|
|
84
93
|
}
|
|
85
|
-
if (!definitions.length) {
|
|
94
|
+
if (!Object.keys(definitions).length) {
|
|
86
95
|
return;
|
|
87
96
|
}
|
|
88
97
|
const emitsVar = ctx.getInternalVariable();
|
|
89
|
-
yield `let ${emitsVar}!: ${names_1.names.ResolveEmits}<typeof ${componentOriginalVar}, typeof ${getCtxVar()}.emit>${
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
yield
|
|
108
|
-
yield* generateEventExpression(options, ctx, prop);
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
yield `'${propName}': `;
|
|
112
|
-
yield* generateModelEventExpression(options, ctx, prop);
|
|
98
|
+
yield `let ${emitsVar}!: ${names_1.names.ResolveEmits}<typeof ${componentOriginalVar}, typeof ${getCtxVar()}.emit>${utils_2.endOfLine}`;
|
|
99
|
+
for (const { propPrefix, emitPrefix, propName, emitName, items } of Object.values(definitions)) {
|
|
100
|
+
yield `const ${ctx.getInternalVariable()}: ${names_1.names.ResolveEvent}<typeof ${getPropsVar()}, typeof ${emitsVar}, '${propName}', '${emitName}', '${(0, shared_1.camelize)(emitName)}'> = {${utils_2.newLine}`;
|
|
101
|
+
for (const { prop, source, offset } of items) {
|
|
102
|
+
if (prop.name === 'on') {
|
|
103
|
+
yield `/** @type {typeof ${emitsVar}.`;
|
|
104
|
+
yield* generateEventArg(options, source, offset, emitPrefix.slice(0, -1), codeFeatures_1.codeFeatures.navigation);
|
|
105
|
+
yield `} */${utils_2.newLine}`;
|
|
106
|
+
}
|
|
107
|
+
if (prop.name === 'on') {
|
|
108
|
+
yield* generateEventArg(options, source, offset, propPrefix.slice(0, -1));
|
|
109
|
+
yield `: `;
|
|
110
|
+
yield* generateEventExpression(options, ctx, prop);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
yield `'${propName}': `;
|
|
114
|
+
yield* generateModelEventExpression(options, ctx, prop);
|
|
115
|
+
}
|
|
116
|
+
yield `,${utils_2.newLine}`;
|
|
113
117
|
}
|
|
114
|
-
yield
|
|
118
|
+
yield `}${utils_2.endOfLine}`;
|
|
115
119
|
}
|
|
116
|
-
yield `}${utils_1.endOfLine}`;
|
|
117
120
|
}
|
|
118
121
|
function* generateEventArg(options, name, start, directive = 'on', features) {
|
|
119
122
|
features ??= {
|
|
@@ -126,33 +129,36 @@ function* generateEventArg(options, name, start, directive = 'on', features) {
|
|
|
126
129
|
if (directive.length) {
|
|
127
130
|
name = (0, shared_1.capitalize)(name);
|
|
128
131
|
}
|
|
129
|
-
if (
|
|
130
|
-
const
|
|
132
|
+
if (utils_2.identifierRE.test((0, shared_1.camelize)(name))) {
|
|
133
|
+
const boundary = yield* boundary_1.Boundary.start('template', start, features);
|
|
131
134
|
yield directive;
|
|
132
|
-
yield* (0, camelized_1.generateCamelized)(name, 'template', start,
|
|
135
|
+
yield* (0, camelized_1.generateCamelized)(name, 'template', start, boundary.features);
|
|
133
136
|
}
|
|
134
137
|
else {
|
|
135
|
-
const
|
|
138
|
+
const boundary = yield* boundary_1.Boundary.start('template', start, features);
|
|
136
139
|
yield `'`;
|
|
137
140
|
yield directive;
|
|
138
|
-
yield* (0, camelized_1.generateCamelized)(name, 'template', start,
|
|
141
|
+
yield* (0, camelized_1.generateCamelized)(name, 'template', start, boundary.features);
|
|
139
142
|
yield `'`;
|
|
140
|
-
yield
|
|
143
|
+
yield boundary.end(start + name.length);
|
|
141
144
|
}
|
|
142
145
|
}
|
|
143
146
|
function* generateEventExpression(options, ctx, prop) {
|
|
144
147
|
if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
145
|
-
const ast = (0,
|
|
148
|
+
const ast = (0, utils_2.getTypeScriptAST)(options.typescript, options.template, prop.exp.content);
|
|
146
149
|
const isCompound = isCompoundExpression(options.typescript, ast);
|
|
147
150
|
const interpolation = (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, prop.exp.content, prop.exp.loc.start.offset, isCompound ? `` : `(`, isCompound ? `` : `)`);
|
|
148
151
|
if (isCompound) {
|
|
149
|
-
yield `(...[$event]) => {${
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
+
yield `(...[$event]) => {${utils_2.newLine}`;
|
|
153
|
+
const scope = ctx.scope();
|
|
154
|
+
scope.declare('$event');
|
|
152
155
|
yield* ctx.generateConditionGuards();
|
|
156
|
+
if (isSingleExpression(options.typescript, ast)) {
|
|
157
|
+
yield `return `;
|
|
158
|
+
}
|
|
153
159
|
yield* interpolation;
|
|
154
|
-
yield
|
|
155
|
-
yield*
|
|
160
|
+
yield utils_2.endOfLine;
|
|
161
|
+
yield* scope.end();
|
|
156
162
|
yield `}`;
|
|
157
163
|
ctx.inlayHints.push({
|
|
158
164
|
blockName: 'template',
|
|
@@ -177,10 +183,10 @@ function* generateEventExpression(options, ctx, prop) {
|
|
|
177
183
|
}
|
|
178
184
|
function* generateModelEventExpression(options, ctx, prop) {
|
|
179
185
|
if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
180
|
-
yield `(...[$event]) => {${
|
|
186
|
+
yield `(...[$event]) => {${utils_2.newLine}`;
|
|
181
187
|
yield* ctx.generateConditionGuards();
|
|
182
188
|
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.verification, prop.exp.content, prop.exp.loc.start.offset);
|
|
183
|
-
yield ` = $event${
|
|
189
|
+
yield ` = $event${utils_2.endOfLine}`;
|
|
184
190
|
yield `}`;
|
|
185
191
|
}
|
|
186
192
|
else {
|
|
@@ -188,35 +194,32 @@ function* generateModelEventExpression(options, ctx, prop) {
|
|
|
188
194
|
}
|
|
189
195
|
}
|
|
190
196
|
function isCompoundExpression(ts, ast) {
|
|
191
|
-
let result = true;
|
|
192
197
|
if (ast.statements.length === 0) {
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
else if (ts.isFunctionDeclaration(child_1)) {
|
|
208
|
-
result = false;
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
if (ast.statements.length === 1 && ast.text[ast.endOfFileToken.pos - 1] !== ';') {
|
|
201
|
+
const statement = ast.statements[0];
|
|
202
|
+
if (ts.isExpressionStatement(statement)) {
|
|
203
|
+
const node = (0, utils_1.getUnwrappedExpression)(ts, statement.expression);
|
|
204
|
+
if (ts.isArrowFunction(node)
|
|
205
|
+
|| ts.isIdentifier(node)
|
|
206
|
+
|| ts.isElementAccessExpression(node)
|
|
207
|
+
|| ts.isPropertyAccessExpression(node)) {
|
|
208
|
+
return false;
|
|
209
209
|
}
|
|
210
|
-
}
|
|
210
|
+
}
|
|
211
|
+
else if (ts.isFunctionDeclaration(statement)) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
211
214
|
}
|
|
212
|
-
return
|
|
215
|
+
return true;
|
|
213
216
|
}
|
|
214
|
-
function
|
|
215
|
-
if (
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
217
|
+
function isSingleExpression(ts, ast) {
|
|
218
|
+
if (ast.statements.length === 1 && ast.text[ast.endOfFileToken.pos - 1] !== ';') {
|
|
219
|
+
const statement = ast.statements[0];
|
|
220
|
+
if (ts.isExpressionStatement(statement)) {
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
220
223
|
}
|
|
221
224
|
return false;
|
|
222
225
|
}
|
|
@@ -114,21 +114,21 @@ function* generateElementProps(options, ctx, node, props, checkUnknownProps, fai
|
|
|
114
114
|
if (shouldSpread) {
|
|
115
115
|
yield `...{ `;
|
|
116
116
|
}
|
|
117
|
-
const
|
|
117
|
+
const boundary = yield* boundary_1.Boundary.start('template', prop.loc.start.offset, codeFeatures_1.codeFeatures.verification);
|
|
118
118
|
if (prop.arg) {
|
|
119
119
|
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, propName, prop.arg.loc.start.offset, features, shouldCamelize);
|
|
120
120
|
}
|
|
121
121
|
else {
|
|
122
|
-
const
|
|
122
|
+
const boundary2 = yield* boundary_1.Boundary.start('template', prop.loc.start.offset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
|
|
123
123
|
yield propName;
|
|
124
|
-
yield
|
|
124
|
+
yield boundary2.end(prop.loc.start.offset + 'v-model'.length);
|
|
125
125
|
}
|
|
126
126
|
yield `: `;
|
|
127
127
|
const argLoc = prop.arg?.loc ?? prop.loc;
|
|
128
|
-
const
|
|
128
|
+
const boundary3 = yield* boundary_1.Boundary.start('template', argLoc.start.offset, codeFeatures_1.codeFeatures.verification);
|
|
129
129
|
yield* generatePropExp(options, ctx, prop, prop.exp);
|
|
130
|
-
yield
|
|
131
|
-
yield
|
|
130
|
+
yield boundary3.end(argLoc.end.offset);
|
|
131
|
+
yield boundary.end(prop.loc.end.offset);
|
|
132
132
|
if (shouldSpread) {
|
|
133
133
|
yield ` }`;
|
|
134
134
|
}
|
|
@@ -153,7 +153,7 @@ function* generateElementProps(options, ctx, node, props, checkUnknownProps, fai
|
|
|
153
153
|
if (shouldSpread) {
|
|
154
154
|
yield `...{ `;
|
|
155
155
|
}
|
|
156
|
-
const
|
|
156
|
+
const boundary = yield* boundary_1.Boundary.start('template', prop.loc.start.offset, codeFeatures_1.codeFeatures.verification);
|
|
157
157
|
const prefix = options.template.content.slice(prop.loc.start.offset, prop.loc.start.offset + 1);
|
|
158
158
|
if (prefix === '.' || prefix === '#') {
|
|
159
159
|
// Pug shorthand syntax
|
|
@@ -174,7 +174,7 @@ function* generateElementProps(options, ctx, node, props, checkUnknownProps, fai
|
|
|
174
174
|
else {
|
|
175
175
|
yield `true`;
|
|
176
176
|
}
|
|
177
|
-
yield
|
|
177
|
+
yield boundary.end(prop.loc.end.offset);
|
|
178
178
|
if (shouldSpread) {
|
|
179
179
|
yield ` }`;
|
|
180
180
|
}
|
|
@@ -187,10 +187,10 @@ function* generateElementProps(options, ctx, node, props, checkUnknownProps, fai
|
|
|
187
187
|
failedPropExps?.push({ node: prop.exp, prefix: `(`, suffix: `)` });
|
|
188
188
|
}
|
|
189
189
|
else {
|
|
190
|
-
const
|
|
190
|
+
const boundary = yield* boundary_1.Boundary.start('template', prop.exp.loc.start.offset, codeFeatures_1.codeFeatures.verification);
|
|
191
191
|
yield `...`;
|
|
192
192
|
yield* generatePropExp(options, ctx, prop, prop.exp);
|
|
193
|
-
yield
|
|
193
|
+
yield boundary.end(prop.exp.loc.end.offset);
|
|
194
194
|
yield `,${utils_1.newLine}`;
|
|
195
195
|
}
|
|
196
196
|
}
|
|
@@ -205,7 +205,7 @@ function* generatePropExp(options, ctx, prop, exp) {
|
|
|
205
205
|
}
|
|
206
206
|
else {
|
|
207
207
|
const propVariableName = (0, shared_1.camelize)(exp.loc.source);
|
|
208
|
-
if (utils_1.
|
|
208
|
+
if (utils_1.identifierRE.test(propVariableName)) {
|
|
209
209
|
const codes = (0, camelized_1.generateCamelized)(exp.loc.source, 'template', exp.loc.start.offset, {
|
|
210
210
|
...codeFeatures_1.codeFeatures.withoutHighlightAndCompletion,
|
|
211
211
|
__shorthandExpression: 'html',
|
|
@@ -218,7 +218,7 @@ function* generatePropExp(options, ctx, prop, exp) {
|
|
|
218
218
|
yield `.value`;
|
|
219
219
|
}
|
|
220
220
|
else {
|
|
221
|
-
ctx.
|
|
221
|
+
ctx.accessVariable('template', propVariableName, exp.loc.start.offset);
|
|
222
222
|
yield names_1.names.ctx;
|
|
223
223
|
yield `.`;
|
|
224
224
|
yield* codes;
|
|
@@ -14,8 +14,7 @@ export interface TemplateCodegenOptions {
|
|
|
14
14
|
}
|
|
15
15
|
export { generate as generateTemplate };
|
|
16
16
|
declare function generate(options: TemplateCodegenOptions): {
|
|
17
|
-
|
|
18
|
-
currentInfo: {
|
|
17
|
+
getCommentInfo: () => {
|
|
19
18
|
ignoreError?: boolean;
|
|
20
19
|
expectError?: {
|
|
21
20
|
token: number;
|
|
@@ -26,41 +25,70 @@ declare function generate(options: TemplateCodegenOptions): {
|
|
|
26
25
|
offset: number;
|
|
27
26
|
};
|
|
28
27
|
};
|
|
28
|
+
enter: (node: import("@vue/compiler-dom").RootNode | import("@vue/compiler-dom").TemplateChildNode | import("@vue/compiler-dom").SimpleExpressionNode) => boolean;
|
|
29
|
+
exit: () => Generator<Code>;
|
|
29
30
|
resolveCodeFeatures: (features: import("../../types").VueCodeInformation) => import("../../types").VueCodeInformation;
|
|
30
|
-
|
|
31
|
+
getInternalVariable: () => string;
|
|
32
|
+
scopes: {
|
|
33
|
+
add(value: string): /*elided*/ any;
|
|
34
|
+
declare(...variables: string[]): void;
|
|
35
|
+
end(): Generator<Code, any, any>;
|
|
36
|
+
clear(): void;
|
|
37
|
+
delete(value: string): boolean;
|
|
38
|
+
forEach(callbackfn: (value: string, value2: string, set: Set<string>) => void, thisArg?: any): void;
|
|
39
|
+
has(value: string): boolean;
|
|
40
|
+
readonly size: number;
|
|
41
|
+
[Symbol.iterator](): SetIterator<string>;
|
|
42
|
+
entries(): SetIterator<[string, string]>;
|
|
43
|
+
keys(): SetIterator<string>;
|
|
44
|
+
values(): SetIterator<string>;
|
|
45
|
+
readonly [Symbol.toStringTag]: string;
|
|
46
|
+
}[];
|
|
47
|
+
scope: () => {
|
|
48
|
+
add(value: string): any;
|
|
49
|
+
declare(...variables: string[]): void;
|
|
50
|
+
end(): Generator<Code, any, any>;
|
|
51
|
+
clear(): void;
|
|
52
|
+
delete(value: string): boolean;
|
|
53
|
+
forEach(callbackfn: (value: string, value2: string, set: Set<string>) => void, thisArg?: any): void;
|
|
54
|
+
has(value: string): boolean;
|
|
55
|
+
readonly size: number;
|
|
56
|
+
[Symbol.iterator](): SetIterator<string>;
|
|
57
|
+
entries(): SetIterator<[string, string]>;
|
|
58
|
+
keys(): SetIterator<string>;
|
|
59
|
+
values(): SetIterator<string>;
|
|
60
|
+
readonly [Symbol.toStringTag]: string;
|
|
61
|
+
};
|
|
62
|
+
contextAccesses: Map<string, Map<string, Set<number>>>;
|
|
63
|
+
accessVariable: (source: string, name: string, offset?: number) => void;
|
|
64
|
+
generateAutoImport: () => Generator<Code>;
|
|
65
|
+
conditions: string[];
|
|
66
|
+
generateConditionGuards: () => Generator<string, void, unknown>;
|
|
67
|
+
hoistVars: Map<string, string>;
|
|
68
|
+
getHoistVariable: (originalVar: string) => string;
|
|
69
|
+
generateHoistVariables: () => Generator<string, void, unknown>;
|
|
70
|
+
templateRefs: Map<string, {
|
|
71
|
+
typeExp: string;
|
|
72
|
+
offset: number;
|
|
73
|
+
}[]>;
|
|
74
|
+
addTemplateRef: (name: string, typeExp: string, offset: number) => void;
|
|
75
|
+
components: (() => string)[];
|
|
76
|
+
dollarVars: Set<string>;
|
|
77
|
+
inlayHints: import("../inlayHints").InlayHintInfo[];
|
|
78
|
+
generatedTypes: Set<string>;
|
|
79
|
+
inheritedAttrVars: Set<string>;
|
|
80
|
+
singleRootElTypes: Set<string>;
|
|
81
|
+
singleRootNodes: Set<import("@vue/compiler-dom").ElementNode | null>;
|
|
31
82
|
slots: {
|
|
32
83
|
name: string;
|
|
33
84
|
offset?: number;
|
|
34
85
|
tagRange: [number, number];
|
|
35
|
-
nodeLoc: any;
|
|
36
86
|
propsVar: string;
|
|
37
87
|
}[];
|
|
38
88
|
dynamicSlots: {
|
|
39
89
|
expVar: string;
|
|
40
90
|
propsVar: string;
|
|
41
91
|
}[];
|
|
42
|
-
|
|
43
|
-
componentAccessMap: Map<string, Map<string, Set<number>>>;
|
|
44
|
-
blockConditions: string[];
|
|
45
|
-
inlayHints: import("../inlayHints").InlayHintInfo[];
|
|
46
|
-
inheritedAttrVars: Set<string>;
|
|
47
|
-
templateRefs: Map<string, {
|
|
48
|
-
typeExp: string;
|
|
49
|
-
offset: number;
|
|
50
|
-
}[]>;
|
|
51
|
-
singleRootElTypes: Set<string>;
|
|
52
|
-
singleRootNodes: Set<import("@vue/compiler-dom").ElementNode | null>;
|
|
53
|
-
addTemplateRef(name: string, typeExp: string, offset: number): void;
|
|
54
|
-
recordComponentAccess(source: string, name: string, offset?: number): void;
|
|
55
|
-
scopes: Set<string>[];
|
|
56
|
-
components: (() => string)[];
|
|
57
|
-
declare(...varNames: string[]): void;
|
|
58
|
-
startScope(): () => Generator<Code, any, any>;
|
|
59
|
-
getInternalVariable(): string;
|
|
60
|
-
getHoistVariable(originalVar: string): string;
|
|
61
|
-
generateHoistVariables(): Generator<string, void, unknown>;
|
|
62
|
-
generateConditionGuards(): Generator<string, void, unknown>;
|
|
63
|
-
enter(node: import("@vue/compiler-dom").RootNode | import("@vue/compiler-dom").TemplateChildNode | import("@vue/compiler-dom").SimpleExpressionNode): boolean;
|
|
64
|
-
exit(): Generator<Code>;
|
|
92
|
+
inVFor: boolean;
|
|
65
93
|
codes: Code[];
|
|
66
94
|
};
|
|
@@ -21,14 +21,14 @@ function generate(options) {
|
|
|
21
21
|
return { ...ctx, codes };
|
|
22
22
|
}
|
|
23
23
|
function* generateWorker(options, ctx) {
|
|
24
|
-
const
|
|
25
|
-
|
|
24
|
+
const scope = ctx.scope();
|
|
25
|
+
scope.declare(...options.setupConsts);
|
|
26
26
|
const { slotsAssignName, propsAssignName, vueCompilerOptions, template, } = options;
|
|
27
27
|
if (slotsAssignName) {
|
|
28
|
-
|
|
28
|
+
scope.declare(slotsAssignName);
|
|
29
29
|
}
|
|
30
30
|
if (propsAssignName) {
|
|
31
|
-
|
|
31
|
+
scope.declare(propsAssignName);
|
|
32
32
|
}
|
|
33
33
|
if (vueCompilerOptions.inferTemplateDollarSlots) {
|
|
34
34
|
ctx.dollarVars.add('$slots');
|
|
@@ -73,7 +73,7 @@ function* generateWorker(options, ctx) {
|
|
|
73
73
|
}
|
|
74
74
|
yield `} & { [K in keyof import('${vueCompilerOptions.lib}').ComponentPublicInstance]: unknown }${utils_1.endOfLine}`;
|
|
75
75
|
}
|
|
76
|
-
yield*
|
|
76
|
+
yield* scope.end();
|
|
77
77
|
}
|
|
78
78
|
function* generateSlotsType(options, ctx) {
|
|
79
79
|
if (options.hasDefineSlots) {
|
|
@@ -94,9 +94,9 @@ function* generateSlotsType(options, ctx) {
|
|
|
94
94
|
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slot.name, slot.offset, codeFeatures_1.codeFeatures.navigation);
|
|
95
95
|
}
|
|
96
96
|
else {
|
|
97
|
-
const
|
|
97
|
+
const boundary = yield* boundary_1.Boundary.start('template', slot.tagRange[0], codeFeatures_1.codeFeatures.navigation);
|
|
98
98
|
yield `default`;
|
|
99
|
-
yield
|
|
99
|
+
yield boundary.end(slot.tagRange[1]);
|
|
100
100
|
}
|
|
101
101
|
yield `?: (props: typeof ${slot.propsVar}) => any }`;
|
|
102
102
|
}
|
|
@@ -45,12 +45,12 @@ function* generateInterpolation({ typescript, setupRefs }, ctx, block, data, cod
|
|
|
45
45
|
}
|
|
46
46
|
else {
|
|
47
47
|
// #1205, #1264
|
|
48
|
-
const
|
|
48
|
+
const boundary = yield* boundary_1.Boundary.start(block.name, start + offset, codeFeatures_1.codeFeatures.verification);
|
|
49
49
|
if (ctx.dollarVars.has(name)) {
|
|
50
50
|
yield names_1.names.dollars;
|
|
51
51
|
}
|
|
52
52
|
else {
|
|
53
|
-
ctx.
|
|
53
|
+
ctx.accessVariable(block.name, name, start + offset);
|
|
54
54
|
yield names_1.names.ctx;
|
|
55
55
|
}
|
|
56
56
|
yield `.`;
|
|
@@ -62,7 +62,7 @@ function* generateInterpolation({ typescript, setupRefs }, ctx, block, data, cod
|
|
|
62
62
|
? { ...data, __shorthandExpression: 'js' }
|
|
63
63
|
: data,
|
|
64
64
|
];
|
|
65
|
-
yield
|
|
65
|
+
yield boundary.end(start + offset + name.length);
|
|
66
66
|
}
|
|
67
67
|
prevEnd = offset + name.length;
|
|
68
68
|
}
|
|
@@ -79,22 +79,22 @@ function* generateInterpolation({ typescript, setupRefs }, ctx, block, data, cod
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
function* forEachIdentifiers(ts, ctx, block, code, prefix, suffix) {
|
|
82
|
-
if (utils_1.
|
|
82
|
+
if (utils_1.identifierRE.test(code) && !shouldIdentifierSkipped(ctx, code)) {
|
|
83
83
|
yield [code, 0, false];
|
|
84
84
|
return;
|
|
85
85
|
}
|
|
86
|
-
const
|
|
86
|
+
const scope = ctx.scope();
|
|
87
87
|
const ast = (0, utils_1.getTypeScriptAST)(ts, block, prefix + code + suffix);
|
|
88
|
-
for (const [id, isShorthand] of forEachDeclarations(ts, ast, ast, ctx)) {
|
|
88
|
+
for (const [id, isShorthand] of forEachDeclarations(ts, ast, ast, ctx, scope)) {
|
|
89
89
|
const text = (0, shared_2.getNodeText)(ts, id, ast);
|
|
90
90
|
if (shouldIdentifierSkipped(ctx, text)) {
|
|
91
91
|
continue;
|
|
92
92
|
}
|
|
93
93
|
yield [text, (0, shared_2.getStartEnd)(ts, id, ast).start - prefix.length, isShorthand];
|
|
94
94
|
}
|
|
95
|
-
|
|
95
|
+
scope.end();
|
|
96
96
|
}
|
|
97
|
-
function* forEachDeclarations(ts, node, ast, ctx) {
|
|
97
|
+
function* forEachDeclarations(ts, node, ast, ctx, scope) {
|
|
98
98
|
if (ts.isIdentifier(node)) {
|
|
99
99
|
yield [node, false];
|
|
100
100
|
}
|
|
@@ -102,16 +102,16 @@ function* forEachDeclarations(ts, node, ast, ctx) {
|
|
|
102
102
|
yield [node.name, true];
|
|
103
103
|
}
|
|
104
104
|
else if (ts.isPropertyAccessExpression(node)) {
|
|
105
|
-
yield* forEachDeclarations(ts, node.expression, ast, ctx);
|
|
105
|
+
yield* forEachDeclarations(ts, node.expression, ast, ctx, scope);
|
|
106
106
|
}
|
|
107
107
|
else if (ts.isVariableDeclaration(node)) {
|
|
108
|
-
|
|
109
|
-
yield* forEachDeclarationsInBinding(ts, node, ast, ctx);
|
|
108
|
+
scope.declare(...(0, collectBindings_1.collectBindingNames)(ts, node.name, ast));
|
|
109
|
+
yield* forEachDeclarationsInBinding(ts, node, ast, ctx, scope);
|
|
110
110
|
}
|
|
111
111
|
else if (ts.isArrayBindingPattern(node) || ts.isObjectBindingPattern(node)) {
|
|
112
112
|
for (const element of node.elements) {
|
|
113
113
|
if (ts.isBindingElement(element)) {
|
|
114
|
-
yield* forEachDeclarationsInBinding(ts, element, ast, ctx);
|
|
114
|
+
yield* forEachDeclarationsInBinding(ts, element, ast, ctx, scope);
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
}
|
|
@@ -123,18 +123,18 @@ function* forEachDeclarations(ts, node, ast, ctx) {
|
|
|
123
123
|
if (ts.isPropertyAssignment(prop)) {
|
|
124
124
|
// fix https://github.com/vuejs/language-tools/issues/1176
|
|
125
125
|
if (ts.isComputedPropertyName(prop.name)) {
|
|
126
|
-
yield* forEachDeclarations(ts, prop.name.expression, ast, ctx);
|
|
126
|
+
yield* forEachDeclarations(ts, prop.name.expression, ast, ctx, scope);
|
|
127
127
|
}
|
|
128
|
-
yield* forEachDeclarations(ts, prop.initializer, ast, ctx);
|
|
128
|
+
yield* forEachDeclarations(ts, prop.initializer, ast, ctx, scope);
|
|
129
129
|
}
|
|
130
130
|
// fix https://github.com/vuejs/language-tools/issues/1156
|
|
131
131
|
else if (ts.isShorthandPropertyAssignment(prop)) {
|
|
132
|
-
yield* forEachDeclarations(ts, prop, ast, ctx);
|
|
132
|
+
yield* forEachDeclarations(ts, prop, ast, ctx, scope);
|
|
133
133
|
}
|
|
134
134
|
// fix https://github.com/vuejs/language-tools/issues/1148#issuecomment-1094378126
|
|
135
135
|
else if (ts.isSpreadAssignment(prop)) {
|
|
136
136
|
// TODO: cannot report "Spread types may only be created from object types.ts(2698)"
|
|
137
|
-
yield* forEachDeclarations(ts, prop.expression, ast, ctx);
|
|
137
|
+
yield* forEachDeclarations(ts, prop.expression, ast, ctx, scope);
|
|
138
138
|
}
|
|
139
139
|
// fix https://github.com/vuejs/language-tools/issues/4604
|
|
140
140
|
else if (ts.isFunctionLike(prop) && prop.body) {
|
|
@@ -147,39 +147,39 @@ function* forEachDeclarations(ts, node, ast, ctx) {
|
|
|
147
147
|
yield* forEachDeclarationsInTypeNode(ts, node);
|
|
148
148
|
}
|
|
149
149
|
else if (ts.isBlock(node)) {
|
|
150
|
-
const
|
|
150
|
+
const scope = ctx.scope();
|
|
151
151
|
for (const child of (0, utils_1.forEachNode)(ts, node)) {
|
|
152
|
-
yield* forEachDeclarations(ts, child, ast, ctx);
|
|
152
|
+
yield* forEachDeclarations(ts, child, ast, ctx, scope);
|
|
153
153
|
}
|
|
154
|
-
|
|
154
|
+
scope.end();
|
|
155
155
|
}
|
|
156
156
|
else {
|
|
157
157
|
for (const child of (0, utils_1.forEachNode)(ts, node)) {
|
|
158
|
-
yield* forEachDeclarations(ts, child, ast, ctx);
|
|
158
|
+
yield* forEachDeclarations(ts, child, ast, ctx, scope);
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
|
-
function* forEachDeclarationsInBinding(ts, node, ast, ctx) {
|
|
162
|
+
function* forEachDeclarationsInBinding(ts, node, ast, ctx, scope) {
|
|
163
163
|
if ('type' in node && node.type) {
|
|
164
164
|
yield* forEachDeclarationsInTypeNode(ts, node.type);
|
|
165
165
|
}
|
|
166
166
|
if (!ts.isIdentifier(node.name)) {
|
|
167
|
-
yield* forEachDeclarations(ts, node.name, ast, ctx);
|
|
167
|
+
yield* forEachDeclarations(ts, node.name, ast, ctx, scope);
|
|
168
168
|
}
|
|
169
169
|
if (node.initializer) {
|
|
170
|
-
yield* forEachDeclarations(ts, node.initializer, ast, ctx);
|
|
170
|
+
yield* forEachDeclarations(ts, node.initializer, ast, ctx, scope);
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
function* forEachDeclarationsInFunction(ts, node, ast, ctx) {
|
|
174
|
-
const
|
|
174
|
+
const scope = ctx.scope();
|
|
175
175
|
for (const param of node.parameters) {
|
|
176
|
-
|
|
177
|
-
yield* forEachDeclarationsInBinding(ts, param, ast, ctx);
|
|
176
|
+
scope.declare(...(0, collectBindings_1.collectBindingNames)(ts, param.name, ast));
|
|
177
|
+
yield* forEachDeclarationsInBinding(ts, param, ast, ctx, scope);
|
|
178
178
|
}
|
|
179
179
|
if (node.body) {
|
|
180
|
-
yield* forEachDeclarations(ts, node.body, ast, ctx);
|
|
180
|
+
yield* forEachDeclarations(ts, node.body, ast, ctx, scope);
|
|
181
181
|
}
|
|
182
|
-
|
|
182
|
+
scope.end();
|
|
183
183
|
}
|
|
184
184
|
function* forEachDeclarationsInTypeNode(ts, node) {
|
|
185
185
|
if (ts.isTypeQueryNode(node)) {
|
|
@@ -18,19 +18,19 @@ function* generateObjectProperty(options, ctx, code, offset, features, shouldCam
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
else if (shouldCamelize) {
|
|
21
|
-
if (utils_1.
|
|
21
|
+
if (utils_1.identifierRE.test((0, shared_1.camelize)(code))) {
|
|
22
22
|
yield* (0, camelized_1.generateCamelized)(code, 'template', offset, features);
|
|
23
23
|
}
|
|
24
24
|
else {
|
|
25
|
-
const
|
|
25
|
+
const boundary = yield* boundary_1.Boundary.start('template', offset, features);
|
|
26
26
|
yield `'`;
|
|
27
|
-
yield* (0, camelized_1.generateCamelized)(code, 'template', offset,
|
|
27
|
+
yield* (0, camelized_1.generateCamelized)(code, 'template', offset, boundary.features);
|
|
28
28
|
yield `'`;
|
|
29
|
-
yield
|
|
29
|
+
yield boundary.end(offset + code.length);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
else {
|
|
33
|
-
if (utils_1.
|
|
33
|
+
if (utils_1.identifierRE.test(code)) {
|
|
34
34
|
yield [code, 'template', offset, features];
|
|
35
35
|
}
|
|
36
36
|
else {
|
|
@@ -8,7 +8,7 @@ function* generatePropertyAccess(options, ctx, code, offset, features) {
|
|
|
8
8
|
if (code.startsWith('[') && code.endsWith(']')) {
|
|
9
9
|
yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, features, code, offset);
|
|
10
10
|
}
|
|
11
|
-
else if (utils_1.
|
|
11
|
+
else if (utils_1.identifierRE.test(code)) {
|
|
12
12
|
yield `.`;
|
|
13
13
|
yield [code, 'template', offset, features];
|
|
14
14
|
}
|