@vue/language-core 3.0.3 → 3.0.5

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 (47) hide show
  1. package/index.d.ts +1 -1
  2. package/index.js +1 -1
  3. package/lib/codegen/codeFeatures.d.ts +20 -17
  4. package/lib/codegen/codeFeatures.js +23 -13
  5. package/lib/codegen/globalTypes.d.ts +2 -2
  6. package/lib/codegen/globalTypes.js +27 -24
  7. package/lib/codegen/script/context.d.ts +0 -6
  8. package/lib/codegen/script/index.d.ts +2 -1
  9. package/lib/codegen/script/index.js +16 -4
  10. package/lib/codegen/script/scriptSetup.js +4 -5
  11. package/lib/codegen/template/context.d.ts +0 -19
  12. package/lib/codegen/template/context.js +0 -6
  13. package/lib/codegen/template/element.js +23 -21
  14. package/lib/codegen/template/elementDirectives.js +10 -10
  15. package/lib/codegen/template/elementEvents.d.ts +1 -1
  16. package/lib/codegen/template/elementEvents.js +23 -20
  17. package/lib/codegen/template/elementProps.js +17 -24
  18. package/lib/codegen/template/index.d.ts +3 -2
  19. package/lib/codegen/template/index.js +21 -8
  20. package/lib/codegen/template/interpolation.js +5 -3
  21. package/lib/codegen/template/slotOutlet.js +6 -5
  22. package/lib/codegen/template/styleScopedClasses.js +3 -2
  23. package/lib/codegen/template/templateChild.js +2 -1
  24. package/lib/codegen/template/vFor.js +6 -4
  25. package/lib/codegen/template/vIf.js +2 -1
  26. package/lib/codegen/template/vSlot.js +11 -9
  27. package/lib/codegen/tenp.d.ts +1 -0
  28. package/lib/codegen/tenp.js +3 -0
  29. package/lib/codegen/utils/index.d.ts +0 -10
  30. package/lib/codegen/utils/index.js +0 -27
  31. package/lib/parsers/scriptSetupRanges.d.ts +0 -1
  32. package/lib/parsers/scriptSetupRanges.js +4 -40
  33. package/lib/parsers/utils.d.ts +12 -0
  34. package/lib/parsers/utils.js +95 -0
  35. package/lib/plugins/file-css.d.ts +3 -0
  36. package/lib/plugins/file-css.js +57 -0
  37. package/lib/plugins/file-vue.js +16 -1
  38. package/lib/plugins/vue-root-tags.js +2 -9
  39. package/lib/plugins/vue-style-css.d.ts +3 -0
  40. package/lib/plugins/vue-style-css.js +62 -0
  41. package/lib/plugins/vue-tsx.d.ts +2 -20
  42. package/lib/plugins/vue-tsx.js +18 -20
  43. package/lib/types.d.ts +1 -1
  44. package/lib/utils/collectBindings.d.ts +12 -0
  45. package/lib/utils/collectBindings.js +29 -0
  46. package/lib/utils/ts.js +20 -18
  47. package/package.json +4 -4
@@ -7,6 +7,7 @@ exports.generateModelEventExpression = generateModelEventExpression;
7
7
  exports.isCompoundExpression = isCompoundExpression;
8
8
  const CompilerDOM = require("@vue/compiler-dom");
9
9
  const shared_1 = require("@vue/shared");
10
+ const codeFeatures_1 = require("../codeFeatures");
10
11
  const utils_1 = require("../utils");
11
12
  const camelized_1 = require("../utils/camelized");
12
13
  const wrapWith_1 = require("../utils/wrapWith");
@@ -48,12 +49,12 @@ function* generateElementEvents(options, ctx, node, componentOriginalVar, compon
48
49
  yield `const ${ctx.getInternalVariable()}: __VLS_NormalizeComponentEvent<typeof ${propsVar}, typeof ${emitsVar}, '${propName}', '${emitName}', '${camelizedEmitName}'> = (${utils_1.newLine}`;
49
50
  if (prop.name === 'on') {
50
51
  yield `{ `;
51
- yield* generateEventArg(ctx, source, start, emitPrefix.slice(0, -1), ctx.codeFeatures.navigation);
52
+ yield* generateEventArg(options, source, start, emitPrefix.slice(0, -1), codeFeatures_1.codeFeatures.navigation);
52
53
  yield `: {} as any } as typeof ${emitsVar},${utils_1.newLine}`;
53
54
  }
54
55
  yield `{ `;
55
56
  if (prop.name === 'on') {
56
- yield* generateEventArg(ctx, source, start, propPrefix.slice(0, -1));
57
+ yield* generateEventArg(options, source, start, propPrefix.slice(0, -1));
57
58
  yield `: `;
58
59
  yield* generateEventExpression(options, ctx, prop);
59
60
  }
@@ -65,10 +66,14 @@ function* generateElementEvents(options, ctx, node, componentOriginalVar, compon
65
66
  }
66
67
  }
67
68
  }
68
- function* generateEventArg(ctx, name, start, directive = 'on', features = {
69
- ...ctx.codeFeatures.withoutHighlightAndCompletion,
70
- ...ctx.codeFeatures.navigationWithoutRename,
71
- }) {
69
+ function* generateEventArg(options, name, start, directive = 'on', features) {
70
+ features ??= {
71
+ ...codeFeatures_1.codeFeatures.semanticWithoutHighlight,
72
+ ...codeFeatures_1.codeFeatures.navigationWithoutRename,
73
+ ...options.vueCompilerOptions.checkUnknownEvents
74
+ ? codeFeatures_1.codeFeatures.verification
75
+ : codeFeatures_1.codeFeatures.doNotReportTs2353AndTs2561,
76
+ };
72
77
  if (directive.length) {
73
78
  name = (0, shared_1.capitalize)(name);
74
79
  }
@@ -83,19 +88,10 @@ function* generateEventArg(ctx, name, start, directive = 'on', features = {
83
88
  }
84
89
  function* generateEventExpression(options, ctx, prop) {
85
90
  if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
86
- let prefix = `(`;
87
- let suffix = `)`;
88
91
  let isFirstMapping = true;
89
92
  const ast = (0, utils_1.createTsAst)(options.ts, ctx.inlineTsAsts, prop.exp.content);
90
93
  const isCompound = isCompoundExpression(options.ts, ast);
91
- if (isCompound) {
92
- ctx.addLocalVariable('$event');
93
- yield `(...[$event]) => {${utils_1.newLine}`;
94
- yield* ctx.generateConditionGuards();
95
- prefix = ``;
96
- suffix = ``;
97
- }
98
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', offset => {
94
+ const interpolation = (0, interpolation_1.generateInterpolation)(options, ctx, 'template', offset => {
99
95
  if (isCompound && isFirstMapping) {
100
96
  isFirstMapping = false;
101
97
  ctx.inlayHints.push({
@@ -111,14 +107,21 @@ function* generateEventExpression(options, ctx, prop) {
111
107
  ].join('\n\n'),
112
108
  });
113
109
  }
114
- return ctx.codeFeatures.all;
115
- }, prop.exp.content, prop.exp.loc.start.offset, prefix, suffix);
110
+ return codeFeatures_1.codeFeatures.all;
111
+ }, prop.exp.content, prop.exp.loc.start.offset, isCompound ? `` : `(`, isCompound ? `` : `)`);
116
112
  if (isCompound) {
117
- ctx.removeLocalVariable('$event');
113
+ yield `(...[$event]) => {${utils_1.newLine}`;
114
+ ctx.addLocalVariable('$event');
115
+ yield* ctx.generateConditionGuards();
116
+ yield* interpolation;
118
117
  yield utils_1.endOfLine;
118
+ ctx.removeLocalVariable('$event');
119
119
  yield* ctx.generateAutoImportCompletion();
120
120
  yield `}`;
121
121
  }
122
+ else {
123
+ yield* interpolation;
124
+ }
122
125
  }
123
126
  else {
124
127
  yield `() => {}`;
@@ -128,7 +131,7 @@ function* generateModelEventExpression(options, ctx, prop) {
128
131
  if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
129
132
  yield `(...[$event]) => {${utils_1.newLine}`;
130
133
  yield* ctx.generateConditionGuards();
131
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.verification, prop.exp.content, prop.exp.loc.start.offset);
134
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', codeFeatures_1.codeFeatures.verification, prop.exp.content, prop.exp.loc.start.offset);
132
135
  yield ` = $event${utils_1.endOfLine}`;
133
136
  yield `}`;
134
137
  }
@@ -27,7 +27,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
27
27
  && !prop.arg.loc.source.endsWith(']')) {
28
28
  if (!isComponent) {
29
29
  yield `...{ `;
30
- yield* (0, elementEvents_1.generateEventArg)(ctx, prop.arg.loc.source, prop.arg.loc.start.offset);
30
+ yield* (0, elementEvents_1.generateEventArg)(options, prop.arg.loc.source, prop.arg.loc.start.offset);
31
31
  yield `: `;
32
32
  yield* (0, elementEvents_1.generateEventExpression)(options, ctx, prop);
33
33
  yield `},`;
@@ -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 features = getPropsCodeFeatures(strictPropsCheck);
81
81
  if (shouldSpread) {
82
82
  yield `...{ `;
83
83
  }
84
- const codes = [...(0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, ...(prop.arg
85
- ? (0, objectProperty_1.generateObjectProperty)(options, ctx, propName, prop.arg.loc.start.offset, codeInfo, shouldCamelize)
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)))];
84
+ const codes = [...(0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, codeFeatures_1.codeFeatures.verification, ...(prop.arg
85
+ ? (0, objectProperty_1.generateObjectProperty)(options, ctx, propName, prop.arg.loc.start.offset, features, shouldCamelize)
86
+ : (0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + 'v-model'.length, codeFeatures_1.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, codeFeatures_1.codeFeatures.verification, ...generatePropExp(options, ctx, prop, prop.exp, enableCodeFeatures)))];
87
87
  if (enableCodeFeatures) {
88
88
  yield* codes;
89
89
  }
@@ -120,12 +120,12 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
120
120
  }
121
121
  const shouldSpread = prop.name === 'style' || prop.name === 'class';
122
122
  const shouldCamelize = isComponent && getShouldCamelize(options, prop, prop.name);
123
- const codeInfo = getPropsCodeInfo(ctx, strictPropsCheck);
123
+ const features = getPropsCodeFeatures(strictPropsCheck);
124
124
  if (shouldSpread) {
125
125
  yield `...{ `;
126
126
  }
127
- const codes = [...(0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, ...(0, objectProperty_1.generateObjectProperty)(options, ctx, prop.name, prop.loc.start.offset, codeInfo, shouldCamelize), `: `, ...(prop.value
128
- ? generateAttrValue(prop.value, ctx.codeFeatures.withoutNavigation)
127
+ const codes = [...(0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, codeFeatures_1.codeFeatures.verification, ...(0, objectProperty_1.generateObjectProperty)(options, ctx, prop.name, prop.loc.start.offset, features, shouldCamelize), `: `, ...(prop.value
128
+ ? generateAttrValue(prop.value, codeFeatures_1.codeFeatures.withoutNavigation)
129
129
  : [`true`]))];
130
130
  if (enableCodeFeatures) {
131
131
  yield* codes;
@@ -148,7 +148,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
148
148
  }
149
149
  }
150
150
  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, enableCodeFeatures))];
151
+ const codes = [...(0, wrapWith_1.wrapWith)(prop.exp.loc.start.offset, prop.exp.loc.end.offset, codeFeatures_1.codeFeatures.verification, `...`, ...generatePropExp(options, ctx, prop, prop.exp, enableCodeFeatures))];
152
152
  if (enableCodeFeatures) {
153
153
  yield* codes;
154
154
  }
@@ -163,8 +163,8 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
163
163
  function* generatePropExp(options, ctx, prop, exp, enableCodeFeatures = true) {
164
164
  const isShorthand = prop.arg?.loc.start.offset === prop.exp?.loc.start.offset;
165
165
  const features = isShorthand
166
- ? ctx.codeFeatures.withoutHighlightAndCompletion
167
- : ctx.codeFeatures.all;
166
+ ? codeFeatures_1.codeFeatures.withoutHighlightAndCompletion
167
+ : codeFeatures_1.codeFeatures.all;
168
168
  if (exp && exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY) { // style='z-index: 2' will compile to {'z-index':'2'}
169
169
  if (!isShorthand) { // vue 3.4+
170
170
  yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, exp.loc.source, exp.loc.start.offset, `(`, `)`);
@@ -220,20 +220,13 @@ function getShouldCamelize(options, prop, propName) {
220
220
  && (0, shared_2.hyphenateAttr)(propName) === propName
221
221
  && !options.vueCompilerOptions.htmlAttributes.some(pattern => (0, picomatch_1.isMatch)(propName, pattern));
222
222
  }
223
- function getPropsCodeInfo(ctx, strictPropsCheck) {
224
- return ctx.resolveCodeFeatures({
223
+ function getPropsCodeFeatures(strictPropsCheck) {
224
+ return {
225
225
  ...codeFeatures_1.codeFeatures.withoutHighlightAndCompletion,
226
- verification: strictPropsCheck || {
227
- shouldReport(_source, code) {
228
- // https://typescript.tv/errors/#ts2353
229
- // https://typescript.tv/errors/#ts2561
230
- if (String(code) === '2353' || String(code) === '2561') {
231
- return false;
232
- }
233
- return true;
234
- },
235
- },
236
- });
226
+ ...strictPropsCheck
227
+ ? codeFeatures_1.codeFeatures.verification
228
+ : codeFeatures_1.codeFeatures.doNotReportTs2353AndTs2561,
229
+ };
237
230
  }
238
231
  function getModelPropName(node, vueCompilerOptions) {
239
232
  for (const modelName in vueCompilerOptions.experimentalModelPropName) {
@@ -1,7 +1,8 @@
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 { type TemplateCodegenContext } from './context';
4
+ import type { TemplateCodegenContext } from './context';
5
+ export * from './context';
5
6
  export interface TemplateCodegenOptions {
6
7
  ts: typeof ts;
7
8
  compilerOptions: ts.CompilerOptions;
@@ -17,5 +18,5 @@ export interface TemplateCodegenOptions {
17
18
  inheritAttrs: boolean;
18
19
  selfComponentName?: string;
19
20
  }
20
- export declare function generateTemplate(options: TemplateCodegenOptions): Generator<Code, TemplateCodegenContext>;
21
+ export declare function generateTemplate(options: TemplateCodegenOptions, ctx: TemplateCodegenContext): Generator<Code>;
21
22
  export declare function forEachElementNode(node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode): Generator<CompilerDOM.ElementNode>;
@@ -1,17 +1,31 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
17
  exports.generateTemplate = generateTemplate;
4
18
  exports.forEachElementNode = forEachElementNode;
5
19
  const CompilerDOM = require("@vue/compiler-dom");
6
20
  const shared_1 = require("../../utils/shared");
21
+ const codeFeatures_1 = require("../codeFeatures");
7
22
  const utils_1 = require("../utils");
8
23
  const wrapWith_1 = require("../utils/wrapWith");
9
- const context_1 = require("./context");
10
24
  const objectProperty_1 = require("./objectProperty");
11
25
  const styleScopedClasses_1 = require("./styleScopedClasses");
12
26
  const templateChild_1 = require("./templateChild");
13
- function* generateTemplate(options) {
14
- const ctx = (0, context_1.createTemplateCodegenContext)(options, options.template.ast);
27
+ __exportStar(require("./context"), exports);
28
+ function* generateTemplate(options, ctx) {
15
29
  if (options.slotsAssignName) {
16
30
  ctx.addLocalVariable(options.slotsAssignName);
17
31
  }
@@ -47,7 +61,6 @@ function* generateTemplate(options) {
47
61
  yield `${name}: ${type}${utils_1.endOfLine}`;
48
62
  }
49
63
  yield `} & { [K in keyof import('${options.vueCompilerOptions.lib}').ComponentPublicInstance]: unknown }${utils_1.endOfLine}`;
50
- return ctx;
51
64
  }
52
65
  function* generateSlots(options, ctx) {
53
66
  if (!options.hasDefineSlots) {
@@ -58,10 +71,10 @@ function* generateSlots(options, ctx) {
58
71
  for (const slot of ctx.slots) {
59
72
  yield `${utils_1.newLine}& { `;
60
73
  if (slot.name && slot.offset !== undefined) {
61
- yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slot.name, slot.offset, ctx.codeFeatures.navigation);
74
+ yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slot.name, slot.offset, codeFeatures_1.codeFeatures.navigation);
62
75
  }
63
76
  else {
64
- yield* (0, wrapWith_1.wrapWith)(slot.tagRange[0], slot.tagRange[1], ctx.codeFeatures.navigation, `default`);
77
+ yield* (0, wrapWith_1.wrapWith)(slot.tagRange[0], slot.tagRange[1], codeFeatures_1.codeFeatures.navigation, `default`);
65
78
  }
66
79
  yield `?: (props: typeof ${slot.propsVar}) => any }`;
67
80
  }
@@ -83,7 +96,7 @@ function* generateInheritedAttrs(options, ctx) {
83
96
  loc.source,
84
97
  'template',
85
98
  loc.start.offset,
86
- ctx.codeFeatures.all,
99
+ codeFeatures_1.codeFeatures.all,
87
100
  ];
88
101
  yield `,`;
89
102
  }
@@ -104,7 +117,7 @@ function* generateTemplateRefs(options, ctx) {
104
117
  yield ` | `;
105
118
  }
106
119
  yield `{ `;
107
- yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, name, offset, ctx.codeFeatures.navigation);
120
+ yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, name, offset, codeFeatures_1.codeFeatures.navigation);
108
121
  yield `: ${typeExp} }`;
109
122
  }
110
123
  if (refs.length >= 2) {
@@ -2,7 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateInterpolation = generateInterpolation;
4
4
  const shared_1 = require("@vue/shared");
5
+ const collectBindings_1 = require("../../utils/collectBindings");
5
6
  const shared_2 = require("../../utils/shared");
7
+ const codeFeatures_1 = require("../codeFeatures");
6
8
  const utils_1 = require("../utils");
7
9
  // https://github.com/vuejs/core/blob/fb0c3ca519f1fccf52049cd6b8db3a67a669afe9/packages/compiler-core/src/transforms/transformExpression.ts#L47
8
10
  const isLiteralWhitelisted = /*@__PURE__*/ (0, shared_1.makeMap)('true,false,null,this');
@@ -34,7 +36,7 @@ function* generateInterpolation(options, ctx, source, data, code, start, prefix
34
36
  source,
35
37
  start + offset,
36
38
  type === 'errorMappingOnly'
37
- ? ctx.codeFeatures.verification
39
+ ? codeFeatures_1.codeFeatures.verification
38
40
  : typeof data === 'function'
39
41
  ? data(start + offset)
40
42
  : data,
@@ -133,7 +135,7 @@ function walkIdentifiers(ts, node, ast, cb, ctx, blockVars, isRoot = false) {
133
135
  walkIdentifiers(ts, node.expression, ast, cb, ctx, blockVars);
134
136
  }
135
137
  else if (ts.isVariableDeclaration(node)) {
136
- const bindingNames = (0, utils_1.collectBindingNames)(ts, node.name, ast);
138
+ const bindingNames = (0, collectBindings_1.collectBindingNames)(ts, node.name, ast);
137
139
  for (const name of bindingNames) {
138
140
  ctx.addLocalVariable(name);
139
141
  blockVars.push(name);
@@ -195,7 +197,7 @@ function walkIdentifiers(ts, node, ast, cb, ctx, blockVars, isRoot = false) {
195
197
  function walkIdentifiersInFunction(ts, node, ast, cb, ctx) {
196
198
  const functionArgs = [];
197
199
  for (const param of node.parameters) {
198
- functionArgs.push(...(0, utils_1.collectBindingNames)(ts, param.name, ast));
200
+ functionArgs.push(...(0, collectBindings_1.collectBindingNames)(ts, param.name, ast));
199
201
  if (param.type) {
200
202
  walkIdentifiersInTypeNode(ts, param.type, cb);
201
203
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateSlotOutlet = generateSlotOutlet;
4
4
  const CompilerDOM = require("@vue/compiler-dom");
5
+ const codeFeatures_1 = require("../codeFeatures");
5
6
  const inlayHints_1 = require("../inlayHints");
6
7
  const utils_1 = require("../utils");
7
8
  const wrapWith_1 = require("../utils/wrapWith");
@@ -34,7 +35,7 @@ function* generateSlotOutlet(options, ctx, node) {
34
35
  source = source.slice(1, -1);
35
36
  offset++;
36
37
  }
37
- codes = (0, propertyAccess_1.generatePropertyAccess)(options, ctx, source, offset, ctx.codeFeatures.navigationAndVerification);
38
+ codes = (0, propertyAccess_1.generatePropertyAccess)(options, ctx, source, offset, codeFeatures_1.codeFeatures.navigationAndVerification);
38
39
  }
39
40
  else if (nameProp.type === CompilerDOM.NodeTypes.DIRECTIVE
40
41
  && nameProp.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
@@ -47,13 +48,13 @@ function* generateSlotOutlet(options, ctx, node) {
47
48
  else {
48
49
  codes = [`['default']`];
49
50
  }
50
- yield* (0, wrapWith_1.wrapWith)(nameProp.loc.start.offset, nameProp.loc.end.offset, ctx.codeFeatures.verification, `${options.slotsAssignName ?? '__VLS_slots'}`, ...codes);
51
+ yield* (0, wrapWith_1.wrapWith)(nameProp.loc.start.offset, nameProp.loc.end.offset, codeFeatures_1.codeFeatures.verification, `${options.slotsAssignName ?? '__VLS_slots'}`, ...codes);
51
52
  }
52
53
  else {
53
- yield* (0, wrapWith_1.wrapWith)(startTagOffset, startTagEndOffset, ctx.codeFeatures.verification, `${options.slotsAssignName ?? '__VLS_slots'}[`, ...(0, wrapWith_1.wrapWith)(startTagOffset, startTagEndOffset, ctx.codeFeatures.verification, `'default'`), `]`);
54
+ yield* (0, wrapWith_1.wrapWith)(startTagOffset, startTagEndOffset, codeFeatures_1.codeFeatures.verification, `${options.slotsAssignName ?? '__VLS_slots'}[`, ...(0, wrapWith_1.wrapWith)(startTagOffset, startTagEndOffset, codeFeatures_1.codeFeatures.verification, `'default'`), `]`);
54
55
  }
55
56
  yield `)(`;
56
- yield* (0, wrapWith_1.wrapWith)(startTagOffset, startTagEndOffset, ctx.codeFeatures.verification, `{${utils_1.newLine}`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), true, true), `}`);
57
+ yield* (0, wrapWith_1.wrapWith)(startTagOffset, startTagEndOffset, codeFeatures_1.codeFeatures.verification, `{${utils_1.newLine}`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), true, true), `}`);
57
58
  yield `)${utils_1.endOfLine}`;
58
59
  }
59
60
  else {
@@ -78,7 +79,7 @@ function* generateSlotOutlet(options, ctx, node) {
78
79
  }
79
80
  const expVar = ctx.getInternalVariable();
80
81
  yield `var ${expVar} = __VLS_tryAsConstant(`;
81
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, nameProp.exp.content, nameProp.exp.loc.start.offset);
82
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', codeFeatures_1.codeFeatures.all, nameProp.exp.content, nameProp.exp.loc.start.offset);
82
83
  yield `)${utils_1.endOfLine}`;
83
84
  ctx.dynamicSlots.push({
84
85
  expVar: ctx.getHoistVariable(expVar),
@@ -4,6 +4,7 @@ exports.generateStyleScopedClassReferences = generateStyleScopedClassReferences;
4
4
  exports.collectStyleScopedClassReferences = collectStyleScopedClassReferences;
5
5
  const CompilerDOM = require("@vue/compiler-dom");
6
6
  const shared_1 = require("../../utils/shared");
7
+ const codeFeatures_1 = require("../codeFeatures");
7
8
  const utils_1 = require("../utils");
8
9
  const escaped_1 = require("../utils/escaped");
9
10
  const wrapWith_1 = require("../utils/wrapWith");
@@ -15,13 +16,13 @@ function* generateStyleScopedClassReferences(ctx, withDot = false) {
15
16
  '',
16
17
  'template',
17
18
  offset,
18
- ctx.codeFeatures.additionalCompletion,
19
+ codeFeatures_1.codeFeatures.additionalCompletion,
19
20
  ];
20
21
  yield `']} */${utils_1.endOfLine}`;
21
22
  }
22
23
  for (const { source, className, offset } of ctx.scopedClasses) {
23
24
  yield `/** @type {__VLS_StyleScopedClasses[`;
24
- yield* (0, wrapWith_1.wrapWith)(offset - (withDot ? 1 : 0), offset + className.length, source, ctx.codeFeatures.navigation, `'`, ...(0, escaped_1.generateEscaped)(className, source, offset, ctx.codeFeatures.navigationAndAdditionalCompletion, classNameEscapeRegex), `'`);
25
+ yield* (0, wrapWith_1.wrapWith)(offset - (withDot ? 1 : 0), offset + className.length, source, codeFeatures_1.codeFeatures.navigation, `'`, ...(0, escaped_1.generateEscaped)(className, source, offset, codeFeatures_1.codeFeatures.navigationAndAdditionalCompletion, classNameEscapeRegex), `'`);
25
26
  yield `]} */${utils_1.endOfLine}`;
26
27
  }
27
28
  }
@@ -5,6 +5,7 @@ exports.getVForNode = getVForNode;
5
5
  exports.parseInterpolationNode = parseInterpolationNode;
6
6
  const CompilerDOM = require("@vue/compiler-dom");
7
7
  const shared_1 = require("../../utils/shared");
8
+ const codeFeatures_1 = require("../codeFeatures");
8
9
  const utils_1 = require("../utils");
9
10
  const element_1 = require("./element");
10
11
  const elementChildren_1 = require("./elementChildren");
@@ -83,7 +84,7 @@ function* generateTemplateChild(options, ctx, node, enterNode = true) {
83
84
  else if (node.type === CompilerDOM.NodeTypes.INTERPOLATION) {
84
85
  // {{ ... }}
85
86
  const [content, start] = parseInterpolationNode(node, options.template.content);
86
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, content, start, `(`, `)${utils_1.endOfLine}`);
87
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', codeFeatures_1.codeFeatures.all, content, start, `(`, `)${utils_1.endOfLine}`);
87
88
  }
88
89
  else if (node.type === CompilerDOM.NodeTypes.IF) {
89
90
  // v-if / v-else-if / v-else
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateVFor = generateVFor;
4
4
  exports.parseVForNode = parseVForNode;
5
5
  const CompilerDOM = require("@vue/compiler-dom");
6
+ const collectBindings_1 = require("../../utils/collectBindings");
7
+ const codeFeatures_1 = require("../codeFeatures");
6
8
  const utils_1 = require("../utils");
7
9
  const elementChildren_1 = require("./elementChildren");
8
10
  const interpolation_1 = require("./interpolation");
@@ -13,18 +15,18 @@ function* generateVFor(options, ctx, node) {
13
15
  yield `for (const [`;
14
16
  if (leftExpressionRange && leftExpressionText) {
15
17
  const collectAst = (0, utils_1.createTsAst)(options.ts, ctx.inlineTsAsts, `const [${leftExpressionText}]`);
16
- forBlockVars.push(...(0, utils_1.collectBindingNames)(options.ts, collectAst, collectAst));
18
+ forBlockVars.push(...(0, collectBindings_1.collectBindingNames)(options.ts, collectAst, collectAst));
17
19
  yield [
18
20
  leftExpressionText,
19
21
  'template',
20
22
  leftExpressionRange.start,
21
- ctx.codeFeatures.all,
23
+ codeFeatures_1.codeFeatures.all,
22
24
  ];
23
25
  }
24
26
  yield `] of `;
25
27
  if (source.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
26
28
  yield `__VLS_getVForSourceType(`;
27
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, source.content, source.loc.start.offset, `(`, `)`);
29
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', codeFeatures_1.codeFeatures.all, source.content, source.loc.start.offset, `(`, `)`);
28
30
  yield `!)`; // #3102
29
31
  }
30
32
  else {
@@ -46,7 +48,7 @@ function* generateVFor(options, ctx, node) {
46
48
  for (const prop of argument.returns.props.properties) {
47
49
  if (prop.value.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
48
50
  && !prop.value.isStatic) {
49
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, prop.value.content, prop.value.loc.start.offset, `(`, `)`);
51
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', codeFeatures_1.codeFeatures.all, prop.value.content, prop.value.loc.start.offset, `(`, `)`);
50
52
  yield utils_1.endOfLine;
51
53
  }
52
54
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateVIf = generateVIf;
4
4
  const CompilerDOM = require("@vue/compiler-dom");
5
5
  const muggle_string_1 = require("muggle-string");
6
+ const codeFeatures_1 = require("../codeFeatures");
6
7
  const utils_1 = require("../utils");
7
8
  const elementChildren_1 = require("./elementChildren");
8
9
  const interpolation_1 = require("./interpolation");
@@ -21,7 +22,7 @@ function* generateVIf(options, ctx, node) {
21
22
  }
22
23
  let addedBlockCondition = false;
23
24
  if (branch.condition?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
24
- const codes = [...(0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, branch.condition.content, branch.condition.loc.start.offset, `(`, `)`)];
25
+ const codes = [...(0, interpolation_1.generateInterpolation)(options, ctx, 'template', codeFeatures_1.codeFeatures.all, branch.condition.content, branch.condition.loc.start.offset, `(`, `)`)];
25
26
  yield* codes;
26
27
  ctx.blockConditions.push((0, muggle_string_1.toString)(codes));
27
28
  addedBlockCondition = true;
@@ -2,7 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateVSlot = generateVSlot;
4
4
  const CompilerDOM = require("@vue/compiler-dom");
5
+ const collectBindings_1 = require("../../utils/collectBindings");
5
6
  const shared_1 = require("../../utils/shared");
7
+ const codeFeatures_1 = require("../codeFeatures");
6
8
  const utils_1 = require("../utils");
7
9
  const wrapWith_1 = require("../utils/wrapWith");
8
10
  const elementChildren_1 = require("./elementChildren");
@@ -21,22 +23,22 @@ function* generateVSlot(options, ctx, node, slotDir) {
21
23
  yield `const { `;
22
24
  if (slotDir) {
23
25
  if (slotDir.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && slotDir.arg.content) {
24
- yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slotDir.arg.loc.source, slotDir.arg.loc.start.offset, slotDir.arg.isStatic ? ctx.codeFeatures.withoutHighlight : ctx.codeFeatures.all, false, true);
26
+ yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slotDir.arg.loc.source, slotDir.arg.loc.start.offset, slotDir.arg.isStatic ? codeFeatures_1.codeFeatures.withoutHighlight : codeFeatures_1.codeFeatures.all, false, true);
25
27
  }
26
28
  else {
27
- yield* (0, wrapWith_1.wrapWith)(slotDir.loc.start.offset, slotDir.loc.start.offset + (slotDir.rawName?.length ?? 0), ctx.codeFeatures.withoutHighlightAndCompletion, `default`);
29
+ yield* (0, wrapWith_1.wrapWith)(slotDir.loc.start.offset, slotDir.loc.start.offset + (slotDir.rawName?.length ?? 0), codeFeatures_1.codeFeatures.withoutHighlightAndCompletion, `default`);
28
30
  }
29
31
  }
30
32
  else {
31
33
  // #932: reference for implicit default slot
32
- yield* (0, wrapWith_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, ctx.codeFeatures.navigation, `default`);
34
+ yield* (0, wrapWith_1.wrapWith)(node.loc.start.offset, node.loc.end.offset, codeFeatures_1.codeFeatures.navigation, `default`);
33
35
  }
34
36
  yield `: ${slotVar} } = ${ctx.currentComponent.ctxVar}.slots!${utils_1.endOfLine}`;
35
37
  }
36
38
  if (slotDir?.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
37
39
  const slotAst = (0, utils_1.createTsAst)(options.ts, ctx.inlineTsAsts, `(${slotDir.exp.content}) => {}`);
38
- slotBlockVars.push(...(0, utils_1.collectBindingNames)(options.ts, slotAst, slotAst));
39
- yield* generateSlotParameters(options, ctx, slotAst, slotDir.exp, slotVar);
40
+ slotBlockVars.push(...(0, collectBindings_1.collectBindingNames)(options.ts, slotAst, slotAst));
41
+ yield* generateSlotParameters(options, slotAst, slotDir.exp, slotVar);
40
42
  }
41
43
  for (const varName of slotBlockVars) {
42
44
  ctx.addLocalVariable(varName);
@@ -60,14 +62,14 @@ function* generateVSlot(options, ctx, node, slotDir) {
60
62
  : slotDir.loc.source.startsWith('v-slot:')
61
63
  ? 'v-slot:'.length
62
64
  : 0),
63
- ctx.codeFeatures.completion,
65
+ codeFeatures_1.codeFeatures.completion,
64
66
  ];
65
67
  yield `'/* empty slot name completion */]${utils_1.endOfLine}`;
66
68
  }
67
69
  yield `}${utils_1.newLine}`;
68
70
  }
69
71
  }
70
- function* generateSlotParameters(options, ctx, ast, exp, slotVar) {
72
+ function* generateSlotParameters(options, ast, exp, slotVar) {
71
73
  const { ts } = options;
72
74
  const statement = ast.statements[0];
73
75
  if (!ts.isExpressionStatement(statement) || !ts.isArrowFunction(statement.expression)) {
@@ -101,7 +103,7 @@ function* generateSlotParameters(options, ctx, ast, exp, slotVar) {
101
103
  yield `] = __VLS_getSlotParameters(${slotVar}!`;
102
104
  if (types.some(t => t)) {
103
105
  yield `, `;
104
- yield* (0, wrapWith_1.wrapWith)(exp.loc.start.offset, exp.loc.end.offset, ctx.codeFeatures.verification, `(`, ...types.flatMap(type => type ? [`_: `, type, `, `] : `_, `), `) => [] as any`);
106
+ yield* (0, wrapWith_1.wrapWith)(exp.loc.start.offset, exp.loc.end.offset, codeFeatures_1.codeFeatures.verification, `(`, ...types.flatMap(type => type ? [`_: `, type, `, `] : `_, `), `) => [] as any`);
105
107
  }
106
108
  yield `)${utils_1.endOfLine}`;
107
109
  function chunk(start, end) {
@@ -109,7 +111,7 @@ function* generateSlotParameters(options, ctx, ast, exp, slotVar) {
109
111
  ast.text.slice(start, end),
110
112
  'template',
111
113
  startOffset + start,
112
- ctx.codeFeatures.all,
114
+ codeFeatures_1.codeFeatures.all,
113
115
  ];
114
116
  }
115
117
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=tenp.js.map
@@ -5,16 +5,6 @@ export declare const newLine = "\n";
5
5
  export declare const endOfLine = ";\n";
6
6
  export declare const combineLastMapping: VueCodeInformation;
7
7
  export declare const identifierRegex: RegExp;
8
- export declare function collectBindingNames(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): string[];
9
- export declare function collectIdentifiers(ts: typeof import('typescript'), node: ts.Node, results?: {
10
- id: ts.Identifier;
11
- isRest: boolean;
12
- initializer: ts.Expression | undefined;
13
- }[], isRest?: boolean, initializer?: ts.Expression | undefined): {
14
- id: ts.Identifier;
15
- isRest: boolean;
16
- initializer: ts.Expression | undefined;
17
- }[];
18
8
  export declare function normalizeAttributeValue(node: CompilerDOM.TextNode): [string, number];
19
9
  export declare function createTsAst(ts: typeof import('typescript'), inlineTsAsts: Map<string, ts.SourceFile> | undefined, text: string): ts.SourceFile;
20
10
  export declare function generateSfcBlockSection(block: SfcBlock, start: number, end: number, features: VueCodeInformation): Code;
@@ -1,40 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.identifierRegex = exports.combineLastMapping = exports.endOfLine = exports.newLine = void 0;
4
- exports.collectBindingNames = collectBindingNames;
5
- exports.collectIdentifiers = collectIdentifiers;
6
4
  exports.normalizeAttributeValue = normalizeAttributeValue;
7
5
  exports.createTsAst = createTsAst;
8
6
  exports.generateSfcBlockSection = generateSfcBlockSection;
9
- const shared_1 = require("../../utils/shared");
10
7
  exports.newLine = `\n`;
11
8
  exports.endOfLine = `;${exports.newLine}`;
12
9
  exports.combineLastMapping = { __combineOffset: 1 };
13
10
  exports.identifierRegex = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
14
- function collectBindingNames(ts, node, ast) {
15
- return collectIdentifiers(ts, node).map(({ id }) => (0, shared_1.getNodeText)(ts, id, ast));
16
- }
17
- function collectIdentifiers(ts, node, results = [], isRest = false, initializer = undefined) {
18
- if (ts.isIdentifier(node)) {
19
- results.push({ id: node, isRest, initializer });
20
- }
21
- else if (ts.isObjectBindingPattern(node)) {
22
- for (const el of node.elements) {
23
- collectIdentifiers(ts, el.name, results, !!el.dotDotDotToken, el.initializer);
24
- }
25
- }
26
- else if (ts.isArrayBindingPattern(node)) {
27
- for (const el of node.elements) {
28
- if (ts.isBindingElement(el)) {
29
- collectIdentifiers(ts, el.name, results, !!el.dotDotDotToken);
30
- }
31
- }
32
- }
33
- else {
34
- ts.forEachChild(node, node => collectIdentifiers(ts, node, results, false));
35
- }
36
- return results;
37
- }
38
11
  function normalizeAttributeValue(node) {
39
12
  let offset = node.loc.start.offset;
40
13
  let content = node.loc.source;
@@ -72,5 +72,4 @@ export declare function parseBindingRanges(ts: typeof import('typescript'), ast:
72
72
  isDefaultImport?: boolean;
73
73
  isNamespace?: boolean;
74
74
  }[];
75
- export declare function findBindingVars(ts: typeof import('typescript'), left: ts.BindingName, ast: ts.SourceFile): TextRange[];
76
75
  export {};