@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.
Files changed (66) hide show
  1. package/index.d.ts +1 -0
  2. package/index.js +1 -0
  3. package/lib/codegen/codeFeatures.d.ts +24 -84
  4. package/lib/codegen/codeFeatures.js +46 -4
  5. package/lib/codegen/names.d.ts +4 -5
  6. package/lib/codegen/names.js +4 -5
  7. package/lib/codegen/script/index.js +5 -5
  8. package/lib/codegen/script/scriptSetup.js +4 -4
  9. package/lib/codegen/style/common.js +7 -11
  10. package/lib/codegen/style/index.d.ts +55 -27
  11. package/lib/codegen/style/index.js +3 -3
  12. package/lib/codegen/template/context.d.ts +55 -124
  13. package/lib/codegen/template/context.js +187 -269
  14. package/lib/codegen/template/element.js +16 -15
  15. package/lib/codegen/template/elementDirectives.js +11 -11
  16. package/lib/codegen/template/elementEvents.js +76 -73
  17. package/lib/codegen/template/elementProps.js +12 -12
  18. package/lib/codegen/template/index.d.ts +55 -27
  19. package/lib/codegen/template/index.js +7 -7
  20. package/lib/codegen/template/interpolation.js +28 -28
  21. package/lib/codegen/template/objectProperty.js +5 -5
  22. package/lib/codegen/template/propertyAccess.js +1 -1
  23. package/lib/codegen/template/slotOutlet.js +8 -10
  24. package/lib/codegen/template/styleScopedClasses.js +4 -4
  25. package/lib/codegen/template/vFor.js +3 -3
  26. package/lib/codegen/template/vIf.js +4 -4
  27. package/lib/codegen/template/vSlot.js +9 -9
  28. package/lib/codegen/utils/boundary.d.ts +7 -2
  29. package/lib/codegen/utils/boundary.js +15 -9
  30. package/lib/codegen/utils/camelized.js +5 -13
  31. package/lib/codegen/utils/escaped.js +4 -9
  32. package/lib/codegen/utils/index.d.ts +1 -1
  33. package/lib/codegen/utils/index.js +3 -3
  34. package/lib/codegen/utils/stringLiteralKey.js +3 -3
  35. package/lib/codegen/utils/unicode.d.ts +1 -1
  36. package/lib/codegen/utils/unicode.js +4 -4
  37. package/lib/languagePlugin.js +2 -1
  38. package/lib/parsers/scriptRanges.d.ts +2 -2
  39. package/lib/parsers/scriptRanges.js +3 -10
  40. package/lib/parsers/scriptSetupRanges.d.ts +2 -2
  41. package/lib/parsers/scriptSetupRanges.js +3 -10
  42. package/lib/parsers/utils.d.ts +1 -0
  43. package/lib/parsers/utils.js +10 -0
  44. package/lib/parsers/vueCompilerOptions.js +2 -2
  45. package/lib/plugins/file-html.js +4 -4
  46. package/lib/plugins/file-md.js +15 -15
  47. package/lib/plugins/file-vue.js +2 -2
  48. package/lib/plugins/vue-root-tags.js +3 -3
  49. package/lib/plugins/vue-sfc-customblocks.js +2 -2
  50. package/lib/plugins/vue-sfc-scripts.js +2 -4
  51. package/lib/plugins/vue-sfc-styles.js +3 -3
  52. package/lib/plugins/vue-sfc-template.js +2 -2
  53. package/lib/plugins/vue-style-css.js +86 -33
  54. package/lib/plugins/vue-template-html.js +3 -3
  55. package/lib/plugins/vue-template-inline-css.js +2 -7
  56. package/lib/plugins/vue-template-inline-ts.js +4 -5
  57. package/lib/plugins/vue-tsx.d.ts +61 -31
  58. package/lib/plugins/vue-tsx.js +26 -23
  59. package/lib/plugins.d.ts +0 -1
  60. package/lib/plugins.js +0 -15
  61. package/lib/utils/forEachTemplateNode.js +36 -43
  62. package/lib/virtualCode/index.js +2 -2
  63. package/package.json +2 -2
  64. package/types/template-helpers.d.ts +15 -25
  65. package/lib/plugins/shared.d.ts +0 -2
  66. 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 utils_1 = require("../utils");
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
- definitions.push({
75
- prop,
76
- source,
77
- offset,
78
- emitPrefix,
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>${utils_1.endOfLine}`;
90
- yield `const ${ctx.getInternalVariable()}: `;
91
- for (let i = 0; i < definitions.length; i++) {
92
- const { propName, emitName } = definitions[i];
93
- if (i > 0) {
94
- yield ` & `;
95
- }
96
- yield `${names_1.names.NormalizeComponentEvent}<typeof ${getPropsVar()}, typeof ${emitsVar}, '${propName}', '${emitName}', '${(0, shared_1.camelize)(emitName)}'>`;
97
- }
98
- yield ` = {${utils_1.newLine}`;
99
- for (const { prop, source, offset, emitPrefix, propPrefix, propName } of definitions) {
100
- if (prop.name === 'on') {
101
- yield `...{ `;
102
- yield* generateEventArg(options, source, offset, emitPrefix.slice(0, -1), codeFeatures_1.codeFeatures.navigation);
103
- yield `: {} as any } as typeof ${emitsVar},${utils_1.newLine}`;
104
- }
105
- if (prop.name === 'on') {
106
- yield* generateEventArg(options, source, offset, propPrefix.slice(0, -1));
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 `,${utils_1.newLine}`;
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 (utils_1.identifierRegex.test((0, shared_1.camelize)(name))) {
130
- const token = yield* (0, boundary_1.startBoundary)('template', start, features);
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, { __combineToken: token });
135
+ yield* (0, camelized_1.generateCamelized)(name, 'template', start, boundary.features);
133
136
  }
134
137
  else {
135
- const token = yield* (0, boundary_1.startBoundary)('template', start, features);
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, { __combineToken: token });
141
+ yield* (0, camelized_1.generateCamelized)(name, 'template', start, boundary.features);
139
142
  yield `'`;
140
- yield (0, boundary_1.endBoundary)(token, start + name.length);
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, utils_1.getTypeScriptAST)(options.typescript, options.template, prop.exp.content);
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]) => {${utils_1.newLine}`;
150
- const endScope = ctx.startScope();
151
- ctx.declare('$event');
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 utils_1.endOfLine;
155
- yield* endScope();
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]) => {${utils_1.newLine}`;
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${utils_1.endOfLine}`;
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
- result = false;
194
- }
195
- else if (ast.statements.length === 1) {
196
- ts.forEachChild(ast, child_1 => {
197
- if (ts.isExpressionStatement(child_1)) {
198
- ts.forEachChild(child_1, child_2 => {
199
- if (ts.isArrowFunction(child_2)) {
200
- result = false;
201
- }
202
- else if (isPropertyAccessOrId(ts, child_2)) {
203
- result = false;
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 result;
215
+ return true;
213
216
  }
214
- function isPropertyAccessOrId(ts, node) {
215
- if (ts.isIdentifier(node)) {
216
- return true;
217
- }
218
- if (ts.isPropertyAccessExpression(node)) {
219
- return isPropertyAccessOrId(ts, node.expression);
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 token = yield* (0, boundary_1.startBoundary)('template', prop.loc.start.offset, codeFeatures_1.codeFeatures.verification);
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 token2 = yield* (0, boundary_1.startBoundary)('template', prop.loc.start.offset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
122
+ const boundary2 = yield* boundary_1.Boundary.start('template', prop.loc.start.offset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
123
123
  yield propName;
124
- yield (0, boundary_1.endBoundary)(token2, prop.loc.start.offset + 'v-model'.length);
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 token3 = yield* (0, boundary_1.startBoundary)('template', argLoc.start.offset, codeFeatures_1.codeFeatures.verification);
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 (0, boundary_1.endBoundary)(token3, argLoc.end.offset);
131
- yield (0, boundary_1.endBoundary)(token, prop.loc.end.offset);
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 token = yield* (0, boundary_1.startBoundary)('template', prop.loc.start.offset, codeFeatures_1.codeFeatures.verification);
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 (0, boundary_1.endBoundary)(token, prop.loc.end.offset);
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 token = yield* (0, boundary_1.startBoundary)('template', prop.exp.loc.start.offset, codeFeatures_1.codeFeatures.verification);
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 (0, boundary_1.endBoundary)(token, prop.exp.loc.end.offset);
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.identifierRegex.test(propVariableName)) {
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.recordComponentAccess('template', propVariableName, exp.loc.start.offset);
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
- generatedTypes: Set<string>;
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
- inVFor: boolean;
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
- dollarVars: Set<string>;
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 endScope = ctx.startScope();
25
- ctx.declare(...options.setupConsts);
24
+ const scope = ctx.scope();
25
+ scope.declare(...options.setupConsts);
26
26
  const { slotsAssignName, propsAssignName, vueCompilerOptions, template, } = options;
27
27
  if (slotsAssignName) {
28
- ctx.declare(slotsAssignName);
28
+ scope.declare(slotsAssignName);
29
29
  }
30
30
  if (propsAssignName) {
31
- ctx.declare(propsAssignName);
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* endScope();
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 token = yield* (0, boundary_1.startBoundary)('template', slot.tagRange[0], codeFeatures_1.codeFeatures.navigation);
97
+ const boundary = yield* boundary_1.Boundary.start('template', slot.tagRange[0], codeFeatures_1.codeFeatures.navigation);
98
98
  yield `default`;
99
- yield (0, boundary_1.endBoundary)(token, slot.tagRange[1]);
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 token = yield* (0, boundary_1.startBoundary)(block.name, start + offset, codeFeatures_1.codeFeatures.verification);
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.recordComponentAccess(block.name, name, start + offset);
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 (0, boundary_1.endBoundary)(token, start + offset + name.length);
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.identifierRegex.test(code) && !shouldIdentifierSkipped(ctx, code)) {
82
+ if (utils_1.identifierRE.test(code) && !shouldIdentifierSkipped(ctx, code)) {
83
83
  yield [code, 0, false];
84
84
  return;
85
85
  }
86
- const endScope = ctx.startScope();
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
- endScope();
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
- ctx.declare(...(0, collectBindings_1.collectBindingNames)(ts, node.name, ast));
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 endScope = ctx.startScope();
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
- endScope();
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 endScope = ctx.startScope();
174
+ const scope = ctx.scope();
175
175
  for (const param of node.parameters) {
176
- ctx.declare(...(0, collectBindings_1.collectBindingNames)(ts, param.name, ast));
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
- endScope();
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.identifierRegex.test((0, shared_1.camelize)(code))) {
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 token = yield* (0, boundary_1.startBoundary)('template', offset, features);
25
+ const boundary = yield* boundary_1.Boundary.start('template', offset, features);
26
26
  yield `'`;
27
- yield* (0, camelized_1.generateCamelized)(code, 'template', offset, { __combineToken: token });
27
+ yield* (0, camelized_1.generateCamelized)(code, 'template', offset, boundary.features);
28
28
  yield `'`;
29
- yield (0, boundary_1.endBoundary)(token, offset + code.length);
29
+ yield boundary.end(offset + code.length);
30
30
  }
31
31
  }
32
32
  else {
33
- if (utils_1.identifierRegex.test(code)) {
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.identifierRegex.test(code)) {
11
+ else if (utils_1.identifierRE.test(code)) {
12
12
  yield `.`;
13
13
  yield [code, 'template', offset, features];
14
14
  }