@vue/language-core 3.0.0-beta.3 → 3.0.0-beta.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 (45) hide show
  1. package/lib/codegen/globalTypes.js +14 -10
  2. package/lib/codegen/localTypes.js +23 -8
  3. package/lib/codegen/script/component.js +2 -1
  4. package/lib/codegen/script/index.js +14 -1
  5. package/lib/codegen/script/scriptSetup.js +41 -21
  6. package/lib/codegen/template/context.d.ts +2 -1
  7. package/lib/codegen/template/context.js +3 -1
  8. package/lib/codegen/template/element.js +10 -6
  9. package/lib/codegen/template/elementEvents.js +1 -1
  10. package/lib/codegen/template/elementProps.js +6 -2
  11. package/lib/codegen/template/index.js +5 -3
  12. package/lib/codegen/template/interpolation.js +9 -12
  13. package/lib/codegen/template/slotOutlet.js +2 -1
  14. package/lib/codegen/template/styleScopedClasses.js +2 -2
  15. package/lib/codegen/template/templateChild.js +2 -1
  16. package/lib/codegen/template/vFor.js +1 -1
  17. package/lib/codegen/template/vSlot.js +1 -1
  18. package/lib/codegen/utils/escaped.d.ts +1 -1
  19. package/lib/codegen/utils/index.d.ts +1 -1
  20. package/lib/codegen/utils/index.js +1 -2
  21. package/lib/codegen/utils/wrapWith.d.ts +1 -1
  22. package/lib/languagePlugin.js +13 -4
  23. package/lib/parsers/scriptRanges.d.ts +1 -0
  24. package/lib/parsers/scriptRanges.js +7 -0
  25. package/lib/parsers/scriptSetupRanges.js +4 -8
  26. package/lib/parsers/vueCompilerOptions.js +0 -1
  27. package/lib/plugins/file-html.js +3 -3
  28. package/lib/plugins/file-md.js +2 -1
  29. package/lib/plugins/file-vue.js +3 -4
  30. package/lib/plugins/vue-sfc-scripts.js +4 -2
  31. package/lib/plugins/vue-template-html.js +3 -4
  32. package/lib/plugins/vue-template-inline-ts.js +3 -1
  33. package/lib/plugins/vue-tsx.d.ts +2 -0
  34. package/lib/plugins/vue-tsx.js +2 -1
  35. package/lib/types.d.ts +1 -1
  36. package/lib/utils/parseCssImports.js +1 -1
  37. package/lib/utils/shared.d.ts +1 -0
  38. package/lib/utils/shared.js +4 -0
  39. package/lib/utils/ts.js +3 -1
  40. package/lib/utils/vue2TemplateCompiler.d.ts +2 -0
  41. package/lib/utils/vue2TemplateCompiler.js +90 -0
  42. package/lib/virtualFile/computedEmbeddedCodes.js +22 -11
  43. package/lib/virtualFile/computedSfc.d.ts +2 -0
  44. package/lib/virtualFile/computedSfc.js +94 -32
  45. package/package.json +5 -4
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getGlobalTypesFileName = getGlobalTypesFileName;
4
4
  exports.generateGlobalTypes = generateGlobalTypes;
5
+ const shared_1 = require("../utils/shared");
5
6
  function getGlobalTypesFileName({ lib, target, checkUnknownProps, checkUnknownEvents, checkUnknownComponents, }) {
6
7
  return [
7
8
  lib,
@@ -28,15 +29,15 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
28
29
  const __VLS_placeholder: any;
29
30
 
30
31
  type __VLS_NativeElements = __VLS_SpreadMerge<SVGElementTagNameMap, HTMLElementTagNameMap>;
31
- type __VLS_IntrinsicElements = ${(target >= 3.3
32
+ type __VLS_IntrinsicElements = ${target >= 3.3
32
33
  ? `import('${lib}/jsx-runtime').JSX.IntrinsicElements;`
33
- : `globalThis.JSX.IntrinsicElements;`)}
34
- type __VLS_Element = ${(target >= 3.3
34
+ : `globalThis.JSX.IntrinsicElements;`}
35
+ type __VLS_Element = ${target >= 3.3
35
36
  ? `import('${lib}/jsx-runtime').JSX.Element;`
36
- : `globalThis.JSX.Element;`)}
37
- type __VLS_GlobalComponents = ${(target >= 3.5
37
+ : `globalThis.JSX.Element;`}
38
+ type __VLS_GlobalComponents = ${target >= 3.5
38
39
  ? `import('${lib}').GlobalComponents;`
39
- : `import('${lib}').GlobalComponents & Pick<typeof import('${lib}'), 'Transition' | 'TransitionGroup' | 'KeepAlive' | 'Suspense' | 'Teleport'>;`)}
40
+ : `import('${lib}').GlobalComponents & Pick<typeof import('${lib}'), 'Transition' | 'TransitionGroup' | 'KeepAlive' | 'Suspense' | 'Teleport'>;`}
40
41
  type __VLS_GlobalDirectives = import('${lib}').GlobalDirectives;
41
42
  type __VLS_IsAny<T> = 0 extends 1 & T ? true : false;
42
43
  type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
@@ -61,7 +62,7 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
61
62
  type __VLS_FunctionalComponent<T> = (props: ${fnPropsType}, ctx?: any) => __VLS_Element & {
62
63
  __ctx?: {
63
64
  attrs?: any,
64
- slots?: T extends { $slots: infer Slots } ? Slots : Record<string, any>,
65
+ slots?: T extends { ${(0, shared_1.getSlotsPropertyName)(target)}: infer Slots } ? Slots : Record<string, any>,
65
66
  emit?: T extends { $emit: infer Emit } ? Emit : {},
66
67
  props?: ${fnPropsType},
67
68
  expose?: (exposed: T) => void,
@@ -117,7 +118,9 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
117
118
  type __VLS_ResolveEmits<
118
119
  Comp,
119
120
  Emits,
120
- TypeEmits = ${target >= 3.6 ? `Comp extends { __typeEmits?: infer T } ? unknown extends T ? {} : import('${lib}').ShortEmitsToObject<T> : {}` : `{}`},
121
+ TypeEmits = ${target >= 3.6
122
+ ? `Comp extends { __typeEmits?: infer T } ? unknown extends T ? {} : import('${lib}').ShortEmitsToObject<T> : {}`
123
+ : `{}`},
121
124
  NormalizedEmits = __VLS_NormalizeEmits<Emits> extends infer E ? string extends keyof E ? {} : E : never,
122
125
  > = __VLS_SpreadMerge<NormalizedEmits, TypeEmits>;
123
126
  type __VLS_ResolveDirectives<T> = {
@@ -149,7 +152,9 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
149
152
  function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
150
153
  function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
151
154
  T extends new (...args: any) => any ? __VLS_FunctionalComponent<K>
152
- : T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>
155
+ : T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>${target === 2.7
156
+ ? `: T extends import('${lib}').AsyncComponent ? (props: {}, ctx?: any) => any`
157
+ : ``}
153
158
  : T extends (...args: any) => any ? T
154
159
  : __VLS_FunctionalComponent<{}>;
155
160
  function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): 2 extends Parameters<T>['length'] ? [any] : [];
@@ -160,5 +165,4 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
160
165
  `;
161
166
  return text;
162
167
  }
163
- ;
164
168
  //# sourceMappingURL=globalTypes.js.map
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getLocalTypesGenerator = getLocalTypesGenerator;
4
+ const shared_1 = require("../utils/shared");
4
5
  const utils_1 = require("./utils");
5
6
  function getLocalTypesGenerator(vueCompilerOptions) {
6
7
  const used = new Set();
@@ -20,7 +21,7 @@ type __VLS_WithDefaults<P, D> = {
20
21
  const WithSlots = defineHelper(`__VLS_WithSlots`, () => `
21
22
  type __VLS_WithSlots<T, S> = T & {
22
23
  new(): {
23
- $slots: S;
24
+ ${(0, shared_1.getSlotsPropertyName)(vueCompilerOptions.target)}: S;
24
25
  ${vueCompilerOptions.jsxSlots ? `$props: ${PropsChildren.name}<S>;` : ''}
25
26
  }
26
27
  };
@@ -63,13 +64,27 @@ type __VLS_TypePropsToOption<T> = {
63
64
  getUsedNames() {
64
65
  return used;
65
66
  },
66
- get PrettifyLocal() { return PrettifyLocal.name; },
67
- get OmitKeepDiscriminatedUnion() { return OmitKeepDiscriminatedUnion.name; },
68
- get WithDefaults() { return WithDefaults.name; },
69
- get WithSlots() { return WithSlots.name; },
70
- get PropsChildren() { return PropsChildren.name; },
71
- get TypePropsToOption() { return TypePropsToOption.name; },
72
- get OmitIndexSignature() { return OmitIndexSignature.name; },
67
+ get PrettifyLocal() {
68
+ return PrettifyLocal.name;
69
+ },
70
+ get OmitKeepDiscriminatedUnion() {
71
+ return OmitKeepDiscriminatedUnion.name;
72
+ },
73
+ get WithDefaults() {
74
+ return WithDefaults.name;
75
+ },
76
+ get WithSlots() {
77
+ return WithSlots.name;
78
+ },
79
+ get PropsChildren() {
80
+ return PropsChildren.name;
81
+ },
82
+ get TypePropsToOption() {
83
+ return TypePropsToOption.name;
84
+ },
85
+ get OmitIndexSignature() {
86
+ return OmitIndexSignature.name;
87
+ },
73
88
  };
74
89
  function* generate(names) {
75
90
  const generated = new Set();
@@ -7,7 +7,8 @@ exports.generatePropsOption = generatePropsOption;
7
7
  const codeFeatures_1 = require("../codeFeatures");
8
8
  const utils_1 = require("../utils");
9
9
  function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
10
- if (options.sfc.script && options.scriptRanges?.exportDefault && options.scriptRanges.exportDefault.expression.start !== options.scriptRanges.exportDefault.args.start) {
10
+ if (options.sfc.script && options.scriptRanges?.exportDefault
11
+ && options.scriptRanges.exportDefault.expression.start !== options.scriptRanges.exportDefault.args.start) {
11
12
  // use defineComponent() from user space code if it exist
12
13
  yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, options.scriptRanges.exportDefault.expression.start, options.scriptRanges.exportDefault.args.start, codeFeatures_1.codeFeatures.all);
13
14
  yield `{${utils_1.newLine}`;
@@ -36,7 +36,7 @@ function* generateScript(options) {
36
36
  yield* (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges);
37
37
  }
38
38
  if (options.sfc.script && options.scriptRanges) {
39
- const { exportDefault } = options.scriptRanges;
39
+ const { exportDefault, classBlockEnd } = options.scriptRanges;
40
40
  const isExportRawObject = exportDefault
41
41
  && options.sfc.script.content[exportDefault.expression.start] === '{';
42
42
  if (options.sfc.scriptSetup && options.scriptSetupRanges) {
@@ -77,6 +77,19 @@ function* generateScript(options) {
77
77
  yield options.vueCompilerOptions.optionsWrapper[1];
78
78
  yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.end, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
79
79
  }
80
+ else if (classBlockEnd !== undefined) {
81
+ if (options.vueCompilerOptions.skipTemplateCodegen) {
82
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
83
+ }
84
+ else {
85
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, classBlockEnd, codeFeatures_1.codeFeatures.all);
86
+ yield `__VLS_template = () => {${utils_1.newLine}`;
87
+ const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx);
88
+ yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
89
+ yield `}${utils_1.endOfLine}`;
90
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, classBlockEnd, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
91
+ }
92
+ }
80
93
  else {
81
94
  yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
82
95
  yield* generateScriptSectionPartiallyEnding(options.sfc.script.name, options.sfc.script.content.length, '#3632/script.vue');
@@ -149,15 +149,17 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
149
149
  callExp.start,
150
150
  callExp.start,
151
151
  ], [
152
- arg ? [
153
- ` as Omit<__VLS_StyleModules, '$style'>[`,
154
- (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.all),
155
- `])`,
156
- ] : [
157
- ` as __VLS_StyleModules[`,
158
- ...(0, wrapWith_1.wrapWith)(exp.start, exp.end, scriptSetup.name, codeFeatures_1.codeFeatures.verification, `'$style'`),
159
- `])`,
160
- ],
152
+ arg
153
+ ? [
154
+ ` as Omit<__VLS_StyleModules, '$style'>[`,
155
+ (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.all),
156
+ `])`,
157
+ ]
158
+ : [
159
+ ` as __VLS_StyleModules[`,
160
+ ...(0, wrapWith_1.wrapWith)(exp.start, exp.end, scriptSetup.name, codeFeatures_1.codeFeatures.verification, `'$style'`),
161
+ `])`,
162
+ ],
161
163
  callExp.end,
162
164
  callExp.end,
163
165
  ]);
@@ -277,11 +279,15 @@ function* generateMacros(options, ctx) {
277
279
  }
278
280
  function* generateDefineWithType(scriptSetup, statement, callExp, typeArg, name, defaultName, typeName) {
279
281
  if (typeArg) {
280
- yield [[
282
+ yield [
283
+ [
281
284
  `type ${typeName} = `,
282
285
  (0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.start, typeArg.end, codeFeatures_1.codeFeatures.all),
283
286
  utils_1.endOfLine,
284
- ], statement.start, statement.start];
287
+ ],
288
+ statement.start,
289
+ statement.start,
290
+ ];
285
291
  yield [[typeName], typeArg.start, typeArg.end];
286
292
  }
287
293
  if (!name) {
@@ -289,25 +295,37 @@ function* generateDefineWithType(scriptSetup, statement, callExp, typeArg, name,
289
295
  yield [[`const ${defaultName} = `], callExp.start, callExp.start];
290
296
  }
291
297
  else if (typeArg) {
292
- yield [[
298
+ yield [
299
+ [
293
300
  `const ${defaultName} = `,
294
301
  (0, utils_1.generateSfcBlockSection)(scriptSetup, callExp.start, typeArg.start, codeFeatures_1.codeFeatures.all),
295
- ], statement.start, typeArg.start];
296
- yield [[
302
+ ],
303
+ statement.start,
304
+ typeArg.start,
305
+ ];
306
+ yield [
307
+ [
297
308
  (0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.end, callExp.end, codeFeatures_1.codeFeatures.all),
298
309
  utils_1.endOfLine,
299
310
  (0, utils_1.generateSfcBlockSection)(scriptSetup, statement.start, callExp.start, codeFeatures_1.codeFeatures.all),
300
311
  defaultName,
301
- ], typeArg.end, callExp.end];
312
+ ],
313
+ typeArg.end,
314
+ callExp.end,
315
+ ];
302
316
  }
303
317
  else {
304
- yield [[
318
+ yield [
319
+ [
305
320
  `const ${defaultName} = `,
306
321
  (0, utils_1.generateSfcBlockSection)(scriptSetup, callExp.start, callExp.end, codeFeatures_1.codeFeatures.all),
307
322
  utils_1.endOfLine,
308
323
  (0, utils_1.generateSfcBlockSection)(scriptSetup, statement.start, callExp.start, codeFeatures_1.codeFeatures.all),
309
324
  defaultName,
310
- ], statement.start, callExp.end];
325
+ ],
326
+ statement.start,
327
+ callExp.end,
328
+ ];
311
329
  }
312
330
  }
313
331
  }
@@ -323,9 +341,11 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges) {
323
341
  yield `})${utils_1.endOfLine}`;
324
342
  yield `type __VLS_BuiltInPublicProps = ${options.vueCompilerOptions.target >= 3.4
325
343
  ? `import('${options.vueCompilerOptions.lib}').PublicProps`
326
- : `import('${options.vueCompilerOptions.lib}').VNodeProps`
327
- + ` & import('${options.vueCompilerOptions.lib}').AllowedComponentProps`
328
- + ` & import('${options.vueCompilerOptions.lib}').ComponentCustomProps`}`;
344
+ : options.vueCompilerOptions.target >= 3
345
+ ? `import('${options.vueCompilerOptions.lib}').VNodeProps`
346
+ + ` & import('${options.vueCompilerOptions.lib}').AllowedComponentProps`
347
+ + ` & import('${options.vueCompilerOptions.lib}').ComponentCustomProps`
348
+ : `globalThis.JSX.IntrinsicAttributes`}`;
329
349
  yield utils_1.endOfLine;
330
350
  yield `type __VLS_OwnProps = `;
331
351
  yield `${ctx.localTypes.OmitKeepDiscriminatedUnion}<InstanceType<typeof __VLS_fnComponent>['$props'], keyof __VLS_BuiltInPublicProps>`;
@@ -415,7 +435,7 @@ function* generateDefineModelType(scriptSetup, propName, localName, defineModel)
415
435
  yield getRangeText(scriptSetup, defineModel.type);
416
436
  }
417
437
  else if (defineModel.runtimeType && localName) {
418
- // Infer from actual prop declaration code
438
+ // Infer from actual prop declaration code
419
439
  yield `typeof ${localName}['value']`;
420
440
  }
421
441
  else if (defineModel.defaultValue && propName) {
@@ -100,7 +100,7 @@ export type TemplateCodegenContext = ReturnType<typeof createTemplateCodegenCont
100
100
  * an error/diagnostic was encountered for a region of code covered by a `@vue-expect-error` directive,
101
101
  * and additionally how we use that to determine whether to propagate diagnostics back upward.
102
102
  */
103
- export declare function createTemplateCodegenContext(options: Pick<TemplateCodegenOptions, 'scriptSetupBindingNames'>): {
103
+ export declare function createTemplateCodegenContext(options: Pick<TemplateCodegenOptions, 'scriptSetupBindingNames'>, templateAst?: CompilerDOM.RootNode): {
104
104
  readonly currentInfo: {
105
105
  ignoreError?: boolean;
106
106
  expectError?: {
@@ -132,6 +132,7 @@ export declare function createTemplateCodegenContext(options: Pick<TemplateCodeg
132
132
  withoutSemantic: VueCodeInformation;
133
133
  };
134
134
  resolveCodeFeatures: (features: VueCodeInformation) => VueCodeInformation;
135
+ inlineTsAsts: Map<string, import("typescript").SourceFile> | undefined;
135
136
  inVFor: boolean;
136
137
  slots: {
137
138
  name: string;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createTemplateCodegenContext = createTemplateCodegenContext;
4
4
  const CompilerDOM = require("@vue/compiler-dom");
5
+ const computedSfc_1 = require("../../virtualFile/computedSfc");
5
6
  const codeFeatures_1 = require("../codeFeatures");
6
7
  const utils_1 = require("../utils");
7
8
  const wrapWith_1 = require("../utils/wrapWith");
@@ -103,7 +104,7 @@ const commentDirectiveRegex = /^<!--\s*@vue-(?<name>[-\w]+)\b(?<content>[\s\S]*)
103
104
  * an error/diagnostic was encountered for a region of code covered by a `@vue-expect-error` directive,
104
105
  * and additionally how we use that to determine whether to propagate diagnostics back upward.
105
106
  */
106
- function createTemplateCodegenContext(options) {
107
+ function createTemplateCodegenContext(options, templateAst) {
107
108
  let variableId = 0;
108
109
  function resolveCodeFeatures(features) {
109
110
  if (features.verification && stack.length) {
@@ -160,6 +161,7 @@ function createTemplateCodegenContext(options) {
160
161
  },
161
162
  }),
162
163
  resolveCodeFeatures,
164
+ inlineTsAsts: templateAst && computedSfc_1.templateInlineTsAsts.get(templateAst),
163
165
  inVFor: false,
164
166
  slots,
165
167
  dynamicSlots,
@@ -101,7 +101,9 @@ function* generateComponent(options, ctx, node) {
101
101
  else if (!isComponentTag) {
102
102
  yield `const ${componentOriginalVar} = ({} as __VLS_WithComponent<'${getCanonicalComponentName(node.tag)}', __VLS_LocalComponents, `;
103
103
  if (options.selfComponentName && possibleOriginalNames.includes(options.selfComponentName)) {
104
- yield `typeof __VLS_self & (new () => { $slots: __VLS_Slots }), `;
104
+ yield `typeof __VLS_self & (new () => { `
105
+ + (0, shared_2.getSlotsPropertyName)(options.vueCompilerOptions.target)
106
+ + `: __VLS_Slots }), `;
105
107
  }
106
108
  else {
107
109
  yield `void, `;
@@ -161,7 +163,8 @@ function* generateComponent(options, ctx, node) {
161
163
  yield* (0, elementDirectives_1.generateElementDirectives)(options, ctx, node);
162
164
  const [refName, offset] = yield* generateElementReference(options, ctx, node);
163
165
  const tag = (0, shared_2.hyphenateTag)(node.tag);
164
- const isRootNode = ctx.singleRootNodes.has(node) && !options.vueCompilerOptions.fallthroughComponentNames.includes(tag);
166
+ const isRootNode = ctx.singleRootNodes.has(node)
167
+ && !options.vueCompilerOptions.fallthroughComponentNames.includes(tag);
165
168
  if (refName || isRootNode) {
166
169
  const componentInstanceVar = ctx.getInternalVariable();
167
170
  ctx.currentComponent.used = true;
@@ -179,7 +182,7 @@ function* generateComponent(options, ctx, node) {
179
182
  }
180
183
  if (hasVBindAttrs(options, ctx, node)) {
181
184
  const attrsVar = ctx.getInternalVariable();
182
- yield `let ${attrsVar}!: Parameters<typeof ${componentFunctionalVar}>[0]${utils_1.endOfLine}`;
185
+ yield `var ${attrsVar}!: Parameters<typeof ${componentFunctionalVar}>[0]${utils_1.endOfLine}`;
183
186
  ctx.inheritedAttrVars.add(attrsVar);
184
187
  }
185
188
  (0, styleScopedClasses_1.collectStyleScopedClassReferences)(options, ctx, node);
@@ -190,7 +193,8 @@ function* generateComponent(options, ctx, node) {
190
193
  }
191
194
  }
192
195
  function* generateElement(options, ctx, node) {
193
- const startTagOffset = node.loc.start.offset + options.template.content.slice(node.loc.start.offset).indexOf(node.tag);
196
+ const startTagOffset = node.loc.start.offset
197
+ + options.template.content.slice(node.loc.start.offset).indexOf(node.tag);
194
198
  const endTagOffset = !node.isSelfClosing && options.template.lang === 'html'
195
199
  ? node.loc.start.offset + node.loc.source.lastIndexOf(node.tag)
196
200
  : undefined;
@@ -289,8 +293,8 @@ function* generateElementReference(options, ctx, node) {
289
293
  return [];
290
294
  }
291
295
  function hasVBindAttrs(options, ctx, node) {
292
- return options.vueCompilerOptions.fallthroughAttributes && ((options.inheritAttrs && ctx.singleRootNodes.has(node)) ||
293
- node.props.some(prop => prop.type === CompilerDOM.NodeTypes.DIRECTIVE
296
+ return options.vueCompilerOptions.fallthroughAttributes && ((options.inheritAttrs && ctx.singleRootNodes.has(node))
297
+ || node.props.some(prop => prop.type === CompilerDOM.NodeTypes.DIRECTIVE
294
298
  && prop.name === 'bind'
295
299
  && prop.exp?.loc.source === '$attrs'));
296
300
  }
@@ -86,7 +86,7 @@ function* generateEventExpression(options, ctx, prop) {
86
86
  let prefix = `(`;
87
87
  let suffix = `)`;
88
88
  let isFirstMapping = true;
89
- const ast = (0, utils_1.createTsAst)(options.ts, options.template.ast, prop.exp.content);
89
+ const ast = (0, utils_1.createTsAst)(options.ts, ctx.inlineTsAsts, prop.exp.content);
90
90
  const isCompound = isCompoundExpression(options.ts, ast);
91
91
  if (isCompound) {
92
92
  ctx.addLocalVariable('$event');
@@ -111,7 +111,11 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
111
111
  }
112
112
  }
113
113
  else if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE) {
114
- if (options.vueCompilerOptions.dataAttributes.some(pattern => (0, minimatch_1.minimatch)(prop.name, pattern))) {
114
+ if (options.vueCompilerOptions.dataAttributes.some(pattern => (0, minimatch_1.minimatch)(prop.name, pattern))
115
+ // Vue 2 Transition doesn't support "persisted" property but `@vue/compiler-dom` always adds it (#3881)
116
+ || (options.vueCompilerOptions.target < 3
117
+ && prop.name === 'persisted'
118
+ && node.tag.toLowerCase() === 'transition')) {
115
119
  continue;
116
120
  }
117
121
  const shouldSpread = prop.name === 'style' || prop.name === 'class';
@@ -268,6 +272,6 @@ function getModelPropName(node, vueCompilerOptions) {
268
272
  }
269
273
  }
270
274
  }
271
- return 'modelValue';
275
+ return vueCompilerOptions.target < 3 ? 'value' : 'modelValue';
272
276
  }
273
277
  //# sourceMappingURL=elementProps.js.map
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateTemplate = generateTemplate;
4
4
  exports.forEachElementNode = forEachElementNode;
5
5
  const CompilerDOM = require("@vue/compiler-dom");
6
+ const shared_1 = require("../../utils/shared");
6
7
  const utils_1 = require("../utils");
7
8
  const wrapWith_1 = require("../utils/wrapWith");
8
9
  const context_1 = require("./context");
@@ -10,15 +11,16 @@ const objectProperty_1 = require("./objectProperty");
10
11
  const styleScopedClasses_1 = require("./styleScopedClasses");
11
12
  const templateChild_1 = require("./templateChild");
12
13
  function* generateTemplate(options) {
13
- const ctx = (0, context_1.createTemplateCodegenContext)(options);
14
+ const ctx = (0, context_1.createTemplateCodegenContext)(options, options.template.ast);
14
15
  if (options.slotsAssignName) {
15
16
  ctx.addLocalVariable(options.slotsAssignName);
16
17
  }
17
18
  if (options.propsAssignName) {
18
19
  ctx.addLocalVariable(options.propsAssignName);
19
20
  }
21
+ const slotsPropertyName = (0, shared_1.getSlotsPropertyName)(options.vueCompilerOptions.target);
20
22
  if (options.vueCompilerOptions.inferTemplateDollarSlots) {
21
- ctx.dollarVars.add('$slots');
23
+ ctx.dollarVars.add(slotsPropertyName);
22
24
  }
23
25
  if (options.vueCompilerOptions.inferTemplateDollarAttrs) {
24
26
  ctx.dollarVars.add('$attrs');
@@ -35,7 +37,7 @@ function* generateTemplate(options) {
35
37
  yield* (0, styleScopedClasses_1.generateStyleScopedClassReferences)(ctx);
36
38
  yield* ctx.generateHoistVariables();
37
39
  const speicalTypes = [
38
- ['$slots', yield* generateSlots(options, ctx)],
40
+ [slotsPropertyName, yield* generateSlots(options, ctx)],
39
41
  ['$attrs', yield* generateInheritedAttrs(options, ctx)],
40
42
  ['$refs', yield* generateTemplateRefs(options, ctx)],
41
43
  ['$el', yield* generateRootEl(ctx)],
@@ -8,8 +8,7 @@ const utils_1 = require("../utils");
8
8
  const isLiteralWhitelisted = /*@__PURE__*/ (0, shared_1.makeMap)('true,false,null,this');
9
9
  function* generateInterpolation(options, ctx, source, data, code, start, prefix = '', suffix = '') {
10
10
  const { ts, destructuredPropNames, templateRefNames, } = options;
11
- const template = 'template' in options ? options.template : options.sfc.template;
12
- for (let [section, offset, type] of forEachInterpolationSegment(ts, template, destructuredPropNames, templateRefNames, ctx, code, start, prefix, suffix)) {
11
+ for (let [section, offset, type] of forEachInterpolationSegment(ts, ctx.inlineTsAsts, destructuredPropNames, templateRefNames, ctx, code, start, prefix, suffix)) {
13
12
  if (offset === undefined) {
14
13
  yield section;
15
14
  }
@@ -36,7 +35,9 @@ function* generateInterpolation(options, ctx, source, data, code, start, prefix
36
35
  start + offset,
37
36
  type === 'errorMappingOnly'
38
37
  ? ctx.codeFeatures.verification
39
- : typeof data === 'function' ? data(start + offset) : data,
38
+ : typeof data === 'function'
39
+ ? data(start + offset)
40
+ : data,
40
41
  ];
41
42
  }
42
43
  else {
@@ -47,8 +48,7 @@ function* generateInterpolation(options, ctx, source, data, code, start, prefix
47
48
  }
48
49
  }
49
50
  }
50
- ;
51
- function* forEachInterpolationSegment(ts, template, destructuredPropNames, templateRefNames, ctx, originalCode, start, prefix, suffix) {
51
+ function* forEachInterpolationSegment(ts, inlineTsAsts, destructuredPropNames, templateRefNames, ctx, originalCode, start, prefix, suffix) {
52
52
  const code = prefix + originalCode + suffix;
53
53
  const offset = start !== undefined ? start - prefix.length : undefined;
54
54
  let ctxVars = [];
@@ -59,7 +59,7 @@ function* forEachInterpolationSegment(ts, template, destructuredPropNames, templ
59
59
  });
60
60
  }
61
61
  else {
62
- const ast = (0, utils_1.createTsAst)(ts, template?.ast, code);
62
+ const ast = (0, utils_1.createTsAst)(ts, inlineTsAsts, code);
63
63
  const varCb = (id, isShorthand) => {
64
64
  const text = (0, shared_2.getNodeText)(ts, id, ast);
65
65
  if (!shouldIdentifierSkipped(ctx, text, destructuredPropNames)) {
@@ -152,17 +152,14 @@ function walkIdentifiers(ts, node, ast, cb, ctx, blockVars = [], isRoot = true)
152
152
  walkIdentifiers(ts, prop.name.expression, ast, cb, ctx, blockVars, false);
153
153
  }
154
154
  walkIdentifiers(ts, prop.initializer, ast, cb, ctx, blockVars, false);
155
- }
156
- // fix https://github.com/vuejs/language-tools/issues/1156
155
+ } // fix https://github.com/vuejs/language-tools/issues/1156
157
156
  else if (ts.isShorthandPropertyAssignment(prop)) {
158
157
  walkIdentifiers(ts, prop, ast, cb, ctx, blockVars, false);
159
- }
160
- // fix https://github.com/vuejs/language-tools/issues/1148#issuecomment-1094378126
158
+ } // fix https://github.com/vuejs/language-tools/issues/1148#issuecomment-1094378126
161
159
  else if (ts.isSpreadAssignment(prop)) {
162
160
  // TODO: cannot report "Spread types may only be created from object types.ts(2698)"
163
161
  walkIdentifiers(ts, prop.expression, ast, cb, ctx, blockVars, false);
164
- }
165
- // fix https://github.com/vuejs/language-tools/issues/4604
162
+ } // fix https://github.com/vuejs/language-tools/issues/4604
166
163
  else if (ts.isFunctionLike(prop) && prop.body) {
167
164
  processFunction(ts, prop, ast, cb, ctx);
168
165
  }
@@ -10,7 +10,8 @@ const elementProps_1 = require("./elementProps");
10
10
  const interpolation_1 = require("./interpolation");
11
11
  const propertyAccess_1 = require("./propertyAccess");
12
12
  function* generateSlotOutlet(options, ctx, node) {
13
- const startTagOffset = node.loc.start.offset + options.template.content.slice(node.loc.start.offset).indexOf(node.tag);
13
+ const startTagOffset = node.loc.start.offset
14
+ + options.template.content.slice(node.loc.start.offset).indexOf(node.tag);
14
15
  const startTagEndOffset = startTagOffset + node.tag.length;
15
16
  const propsVar = ctx.getInternalVariable();
16
17
  const nameProp = node.props.find(prop => {
@@ -67,8 +67,8 @@ function collectStyleScopedClassReferences(options, ctx, node) {
67
67
  const ast = ts.createSourceFile('', content, 99);
68
68
  const literals = [];
69
69
  ts.forEachChild(ast, node => {
70
- if (!ts.isExpressionStatement(node) ||
71
- !isTemplateExpression(node.expression)) {
70
+ if (!ts.isExpressionStatement(node)
71
+ || !isTemplateExpression(node.expression)) {
72
72
  return;
73
73
  }
74
74
  const expression = node.expression.templateSpans[0].expression;
@@ -173,7 +173,8 @@ function parseInterpolationNode(node, template) {
173
173
  start--;
174
174
  content = leftCharacter + content;
175
175
  }
176
- while ((rightCharacter = template.slice(start + content.length, start + content.length + 1)).trim() === '' && rightCharacter.length) {
176
+ while ((rightCharacter = template.slice(start + content.length, start + content.length + 1)).trim() === ''
177
+ && rightCharacter.length) {
177
178
  content = content + rightCharacter;
178
179
  }
179
180
  return [
@@ -12,7 +12,7 @@ function* generateVFor(options, ctx, node) {
12
12
  const forBlockVars = [];
13
13
  yield `for (const [`;
14
14
  if (leftExpressionRange && leftExpressionText) {
15
- const collectAst = (0, utils_1.createTsAst)(options.ts, options.template.ast, `const [${leftExpressionText}]`);
15
+ const collectAst = (0, utils_1.createTsAst)(options.ts, ctx.inlineTsAsts, `const [${leftExpressionText}]`);
16
16
  (0, utils_1.collectVars)(options.ts, collectAst, collectAst, forBlockVars);
17
17
  yield [
18
18
  leftExpressionText,
@@ -35,7 +35,7 @@ function* generateVSlot(options, ctx, node, slotDir) {
35
35
  yield `: ${slotVar} } = ${ctx.currentComponent.ctxVar}.slots!${utils_1.endOfLine}`;
36
36
  }
37
37
  if (slotDir?.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
38
- const slotAst = (0, utils_1.createTsAst)(options.ts, options.template.ast, `(${slotDir.exp.content}) => {}`);
38
+ const slotAst = (0, utils_1.createTsAst)(options.ts, ctx.inlineTsAsts, `(${slotDir.exp.content}) => {}`);
39
39
  (0, utils_1.collectVars)(options.ts, slotAst, slotAst, slotBlockVars);
40
40
  yield* generateSlotParameters(options, ctx, slotAst, slotDir.exp, slotVar);
41
41
  }
@@ -1,2 +1,2 @@
1
- import type { Code, VueCodeInformation } from "../../types";
1
+ import type { Code, VueCodeInformation } from '../../types';
2
2
  export declare function generateEscaped(text: string, source: string, offset: number, features: VueCodeInformation, escapeTarget: RegExp): Generator<Code>;
@@ -16,5 +16,5 @@ export declare function collectIdentifiers(ts: typeof import('typescript'), node
16
16
  initializer: ts.Expression | undefined;
17
17
  }[];
18
18
  export declare function normalizeAttributeValue(node: CompilerDOM.TextNode): [string, number];
19
- export declare function createTsAst(ts: typeof import('typescript'), templateAst: CompilerDOM.RootNode | undefined, text: string): ts.SourceFile;
19
+ export declare function createTsAst(ts: typeof import('typescript'), inlineTsAsts: Map<string, ts.SourceFile> | undefined, text: string): ts.SourceFile;
20
20
  export declare function generateSfcBlockSection(block: SfcBlock, start: number, end: number, features: VueCodeInformation): Code;
@@ -49,8 +49,7 @@ function normalizeAttributeValue(node) {
49
49
  }
50
50
  return [content, offset];
51
51
  }
52
- function createTsAst(ts, templateAst, text) {
53
- const inlineTsAsts = templateAst?.__volar_inlineTsAsts;
52
+ function createTsAst(ts, inlineTsAsts, text) {
54
53
  let ast = inlineTsAsts?.get(text);
55
54
  if (!ast) {
56
55
  ast = ts.createSourceFile('/a.ts', text, 99);
@@ -1,3 +1,3 @@
1
- import type { Code, VueCodeInformation } from "../../types";
1
+ import type { Code, VueCodeInformation } from '../../types';
2
2
  export declare function wrapWith(startOffset: number, endOffset: number, features: VueCodeInformation, ...codes: Code[]): Generator<Code>;
3
3
  export declare function wrapWith(startOffset: number, endOffset: number, source: string, features: VueCodeInformation, ...codes: Code[]): Generator<Code>;
@@ -6,6 +6,7 @@ exports.getAllExtensions = getAllExtensions;
6
6
  const language_core_1 = require("@volar/language-core");
7
7
  const CompilerDOM = require("@vue/compiler-dom");
8
8
  const plugins_1 = require("./plugins");
9
+ const CompilerVue2 = require("./utils/vue2TemplateCompiler");
9
10
  const vueFile_1 = require("./virtualFile/vueFile");
10
11
  const fileRegistries = [];
11
12
  function getVueFileRegistry(key, plugins) {
@@ -37,7 +38,12 @@ function getFileRegistryKey(compilerOptions, vueCompilerOptions, plugins) {
37
38
  function createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFileName) {
38
39
  const pluginContext = {
39
40
  modules: {
40
- '@vue/compiler-dom': CompilerDOM,
41
+ '@vue/compiler-dom': vueCompilerOptions.target < 3
42
+ ? {
43
+ ...CompilerDOM,
44
+ compile: CompilerVue2.compile,
45
+ }
46
+ : CompilerDOM,
41
47
  typescript: ts,
42
48
  },
43
49
  compilerOptions,
@@ -88,9 +94,12 @@ function createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFile
88
94
  return {
89
95
  code,
90
96
  extension: '.' + lang,
91
- scriptKind: lang === 'js' ? ts.ScriptKind.JS
92
- : lang === 'jsx' ? ts.ScriptKind.JSX
93
- : lang === 'tsx' ? ts.ScriptKind.TSX
97
+ scriptKind: lang === 'js'
98
+ ? ts.ScriptKind.JS
99
+ : lang === 'jsx'
100
+ ? ts.ScriptKind.JSX
101
+ : lang === 'tsx'
102
+ ? ts.ScriptKind.TSX
94
103
  : ts.ScriptKind.TS,
95
104
  };
96
105
  }
@@ -13,6 +13,7 @@ export declare function parseScriptRanges(ts: typeof import('typescript'), ast:
13
13
  nameOption: TextRange | undefined;
14
14
  inheritAttrsOption: string | undefined;
15
15
  }) | undefined;
16
+ classBlockEnd: number | undefined;
16
17
  bindings: {
17
18
  range: TextRange;
18
19
  moduleName?: string;