@vue/language-core 3.2.9 → 3.3.0

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 (42) hide show
  1. package/README.md +1 -0
  2. package/lib/codegen/names.d.ts +1 -0
  3. package/lib/codegen/names.js +1 -0
  4. package/lib/codegen/script/component.d.ts +2 -2
  5. package/lib/codegen/script/component.js +64 -58
  6. package/lib/codegen/script/index.d.ts +3 -3
  7. package/lib/codegen/script/scriptSetup.d.ts +4 -4
  8. package/lib/codegen/script/template.js +9 -9
  9. package/lib/codegen/style/common.d.ts +2 -2
  10. package/lib/codegen/style/index.d.ts +2 -2
  11. package/lib/codegen/template/element.js +29 -24
  12. package/lib/codegen/template/elementProps.d.ts +2 -2
  13. package/lib/codegen/template/elementProps.js +11 -10
  14. package/lib/codegen/template/index.d.ts +2 -2
  15. package/lib/codegen/template/index.js +6 -3
  16. package/lib/codegen/template/interpolation.d.ts +2 -2
  17. package/lib/codegen/template/styleScopedClasses.d.ts +3 -3
  18. package/lib/codegen/template/templateChild.d.ts +1 -1
  19. package/lib/codegen/template/templateChild.js +8 -4
  20. package/lib/codegen/utils/index.d.ts +3 -3
  21. package/lib/codegen/utils/merge.d.ts +2 -2
  22. package/lib/codegen/utils/merge.js +9 -9
  23. package/lib/compilerOptions.js +1 -0
  24. package/lib/plugins/vue-root-tags.js +9 -9
  25. package/lib/plugins/vue-sfc-customblocks.js +4 -4
  26. package/lib/plugins/vue-sfc-scripts.js +8 -8
  27. package/lib/plugins/vue-sfc-styles.js +5 -5
  28. package/lib/plugins/vue-sfc-template.js +7 -7
  29. package/lib/plugins/vue-template-inline-css.js +6 -6
  30. package/lib/plugins/vue-template-inline-ts.js +12 -12
  31. package/lib/plugins/vue-tsx.d.ts +2 -2
  32. package/lib/plugins/vue-tsx.js +35 -35
  33. package/lib/types.d.ts +54 -48
  34. package/lib/utils/parseSfc.js +0 -1
  35. package/lib/utils/shared.d.ts +2 -2
  36. package/lib/virtualCode/embeddedCodes.d.ts +2 -2
  37. package/lib/virtualCode/embeddedCodes.js +11 -11
  38. package/lib/virtualCode/index.d.ts +4 -2
  39. package/lib/virtualCode/index.js +4 -0
  40. package/lib/virtualCode/ir.d.ts +2 -2
  41. package/package.json +2 -2
  42. package/types/template-helpers.d.ts +1 -0
package/README.md CHANGED
@@ -111,6 +111,7 @@ Configure Vue compiler behavior through the `vueCompilerOptions` field in `tscon
111
111
  | `lib` | `string` | `'vue'` | Vue package name, used for generating import statements. |
112
112
  | `skipTemplateCodegen` | `boolean` | `false` | Skip virtual code generation for templates. |
113
113
  | `fallthroughAttributes` | `boolean` | `false` | Enable type inference for fallthrough attributes. |
114
+ | `checkRequiredFallthroughAttributes` | `boolean` | `false` | Check required fallthrough attributes. |
114
115
  | `jsxSlots` | `boolean` | `false` | Use JSX-style slots types. |
115
116
  | `dataAttributes` | `string[]` | `[]` | Allowed data-* attribute patterns. |
116
117
  | `htmlAttributes` | `string[]` | `['aria-*']` | Allowed HTML attribute patterns. |
@@ -43,6 +43,7 @@ declare const raw: {
43
43
  asFunctionalSlot: string;
44
44
  directiveBindingRestFields: string;
45
45
  functionalComponentArgsRest: string;
46
+ omit: string;
46
47
  tryAsConstant: string;
47
48
  vFor: string;
48
49
  vSlot: string;
@@ -47,6 +47,7 @@ const raw = {
47
47
  asFunctionalSlot: '',
48
48
  directiveBindingRestFields: '',
49
49
  functionalComponentArgsRest: '',
50
+ omit: '',
50
51
  tryAsConstant: '',
51
52
  vFor: '',
52
53
  vSlot: '',
@@ -1,5 +1,5 @@
1
1
  import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
2
- import type { Code, Sfc } from '../../types';
2
+ import type { Code, IRScriptSetup } from '../../types';
3
3
  import type { ScriptCodegenContext } from './context';
4
4
  import type { ScriptCodegenOptions } from './index';
5
- export declare function generateComponent(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
5
+ export declare function generateComponent(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: IRScriptSetup, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
@@ -26,83 +26,89 @@ function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
26
26
  yield `})`;
27
27
  }
28
28
  function* generateEmitsOption(options, scriptSetupRanges) {
29
- const optionCodes = [];
30
- const typeOptionCodes = [];
29
+ const typeCodes = options.vueCompilerOptions.target >= 3.5 && !scriptSetupRanges.defineEmits?.hasUnionTypeArg
30
+ ? [...generateTypeEmitsOption(scriptSetupRanges)]
31
+ : [];
32
+ const runtimeCodes = !typeCodes.length
33
+ ? [...generateRuntimeEmitsOption(scriptSetupRanges)]
34
+ : [];
35
+ if (typeCodes.length) {
36
+ yield `__typeEmits: {} as `;
37
+ yield* (0, merge_1.generateIntersectMerge)(...typeCodes);
38
+ yield `,${utils_1.newLine}`;
39
+ }
40
+ else if (runtimeCodes.length) {
41
+ yield `emits: `;
42
+ yield* (0, merge_1.generateSpreadMerge)(...runtimeCodes);
43
+ yield `,${utils_1.newLine}`;
44
+ }
45
+ }
46
+ function* generateTypeEmitsOption(scriptSetupRanges) {
47
+ if (scriptSetupRanges.defineModel.length) {
48
+ yield names_1.names.ModelEmit;
49
+ }
50
+ if (scriptSetupRanges.defineEmits?.typeArg) {
51
+ yield names_1.names.Emit;
52
+ }
53
+ }
54
+ function* generateRuntimeEmitsOption(scriptSetupRanges) {
31
55
  if (scriptSetupRanges.defineModel.length) {
32
- optionCodes.push([`{} as ${names_1.names.NormalizeEmits}<typeof ${names_1.names.modelEmit}>`]);
33
- typeOptionCodes.push([names_1.names.ModelEmit]);
56
+ yield `{} as ${names_1.names.NormalizeEmits}<typeof ${names_1.names.modelEmit}>`;
34
57
  }
35
58
  if (scriptSetupRanges.defineEmits) {
36
- const { name, typeArg, hasUnionTypeArg } = scriptSetupRanges.defineEmits;
37
- optionCodes.push([`{} as ${names_1.names.NormalizeEmits}<typeof ${name ?? names_1.names.emit}>`]);
38
- if (typeArg && !hasUnionTypeArg) {
39
- typeOptionCodes.push([names_1.names.Emit]);
40
- }
41
- else {
42
- typeOptionCodes.length = 0;
43
- }
59
+ yield `{} as ${names_1.names.NormalizeEmits}<typeof ${scriptSetupRanges.defineEmits.name ?? names_1.names.emit}>`;
44
60
  }
45
- if (options.vueCompilerOptions.target >= 3.5 && typeOptionCodes.length) {
46
- yield `__typeEmits: {} as `;
47
- yield* (0, merge_1.generateIntersectMerge)(typeOptionCodes);
61
+ }
62
+ function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasEmitsOption) {
63
+ const typeCodes = options.vueCompilerOptions.target >= 3.5 && !scriptSetupRanges.defineProps?.arg
64
+ ? [...generateTypePropsOption(options, ctx, hasEmitsOption)]
65
+ : [];
66
+ const runtimeCodes = scriptSetupRanges.withDefaults || !typeCodes.length
67
+ ? [...generateRuntimePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasEmitsOption)]
68
+ : [];
69
+ if (typeCodes.length) {
70
+ if (options.vueCompilerOptions.target >= 3.6 && scriptSetupRanges.withDefaults?.arg) {
71
+ yield `__defaults: ${names_1.names.defaults},${utils_1.newLine}`;
72
+ }
73
+ yield `__typeProps: `;
74
+ yield* (0, merge_1.generateSpreadMerge)(...typeCodes);
48
75
  yield `,${utils_1.newLine}`;
49
76
  }
50
- else if (optionCodes.length) {
51
- yield `emits: `;
52
- yield* (0, merge_1.generateSpreadMerge)(optionCodes);
77
+ if (runtimeCodes.length) {
78
+ yield `props: `;
79
+ yield* (0, merge_1.generateSpreadMerge)(...runtimeCodes);
53
80
  yield `,${utils_1.newLine}`;
54
81
  }
55
82
  }
56
- function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasEmitsOption) {
57
- const optionGenerates = [];
58
- const typeOptionGenerates = [];
83
+ function* generateTypePropsOption(options, ctx, hasEmitsOption) {
59
84
  if (options.templateAndStyleTypes.has(names_1.names.InheritedAttrs)) {
60
85
  const attrsType = hasEmitsOption
61
86
  ? `Omit<${names_1.names.InheritedAttrs}, keyof ${names_1.names.EmitProps}>`
62
87
  : names_1.names.InheritedAttrs;
63
- optionGenerates.push(function* () {
64
- const propsType = `${names_1.names.PickNotAny}<${ctx.localTypes.OmitIndexSignature}<${attrsType}>, {}>`;
65
- const optionType = `${ctx.localTypes.TypePropsToOption}<${propsType}>`;
66
- yield `{} as ${optionType}`;
67
- });
68
- typeOptionGenerates.push(function* () {
69
- yield `{} as ${attrsType}`;
70
- });
88
+ yield `{} as ${attrsType}`;
71
89
  }
72
90
  if (ctx.generatedTypes.has(names_1.names.PublicProps)) {
73
- if (options.vueCompilerOptions.target < 3.6) {
74
- optionGenerates.push(function* () {
75
- let propsType = `${ctx.localTypes.TypePropsToOption}<${names_1.names.PublicProps}>`;
76
- if (scriptSetupRanges.withDefaults?.arg) {
77
- propsType = `${ctx.localTypes.WithDefaults}<${propsType}, typeof ${names_1.names.defaults}>`;
78
- }
79
- yield `{} as ${propsType}`;
80
- });
91
+ yield `{} as ${names_1.names.PublicProps}`;
92
+ }
93
+ }
94
+ function* generateRuntimePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasEmitsOption) {
95
+ if (options.templateAndStyleTypes.has(names_1.names.InheritedAttrs)) {
96
+ const attrsType = hasEmitsOption
97
+ ? `Omit<${names_1.names.InheritedAttrs}, keyof ${names_1.names.EmitProps}>`
98
+ : names_1.names.InheritedAttrs;
99
+ const propsType = `${ctx.localTypes.TypePropsToOption}<${names_1.names.PickNotAny}<${ctx.localTypes.OmitIndexSignature}<${attrsType}>, {}>>`;
100
+ yield `{} as ${propsType}`;
101
+ }
102
+ if (ctx.generatedTypes.has(names_1.names.PublicProps) && options.vueCompilerOptions.target < 3.6) {
103
+ let propsType = `${ctx.localTypes.TypePropsToOption}<${names_1.names.PublicProps}>`;
104
+ if (scriptSetupRanges.withDefaults?.arg) {
105
+ propsType = `${ctx.localTypes.WithDefaults}<${propsType}, typeof ${names_1.names.defaults}>`;
81
106
  }
82
- typeOptionGenerates.push(function* () {
83
- yield `{} as ${names_1.names.PublicProps}`;
84
- });
107
+ yield `{} as ${propsType}`;
85
108
  }
86
109
  if (scriptSetupRanges.defineProps?.arg) {
87
110
  const { arg } = scriptSetupRanges.defineProps;
88
- optionGenerates.push(() => (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.navigation));
89
- typeOptionGenerates.length = 0;
90
- }
91
- const useTypeOption = options.vueCompilerOptions.target >= 3.5 && typeOptionGenerates.length;
92
- const useOption = (!useTypeOption || scriptSetupRanges.withDefaults) && optionGenerates.length;
93
- if (useTypeOption) {
94
- if (options.vueCompilerOptions.target >= 3.6
95
- && scriptSetupRanges.withDefaults?.arg) {
96
- yield `__defaults: ${names_1.names.defaults},${utils_1.newLine}`;
97
- }
98
- yield `__typeProps: `;
99
- yield* (0, merge_1.generateSpreadMerge)(typeOptionGenerates.map(g => g()));
100
- yield `,${utils_1.newLine}`;
101
- }
102
- if (useOption) {
103
- yield `props: `;
104
- yield* (0, merge_1.generateSpreadMerge)(optionGenerates.map(g => g()));
105
- yield `,${utils_1.newLine}`;
111
+ yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.navigation);
106
112
  }
107
113
  }
108
114
  //# sourceMappingURL=component.js.map
@@ -1,10 +1,10 @@
1
1
  import type { ScriptRanges } from '../../parsers/scriptRanges';
2
2
  import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
3
- import type { Code, Sfc, VueCompilerOptions } from '../../types';
3
+ import type { Code, IRScript, IRScriptSetup, VueCompilerOptions } from '../../types';
4
4
  export interface ScriptCodegenOptions {
5
5
  vueCompilerOptions: VueCompilerOptions;
6
- script: Sfc['script'];
7
- scriptSetup: Sfc['scriptSetup'];
6
+ script: IRScript | undefined;
7
+ scriptSetup: IRScriptSetup | undefined;
8
8
  fileName: string;
9
9
  scriptRanges: ScriptRanges | undefined;
10
10
  scriptSetupRanges: ScriptSetupRanges | undefined;
@@ -1,7 +1,7 @@
1
1
  import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
2
- import type { Code, Sfc } from '../../types';
2
+ import type { Code, IRScriptSetup } from '../../types';
3
3
  import type { ScriptCodegenContext } from './context';
4
4
  import type { ScriptCodegenOptions } from './index';
5
- export declare function generateScriptSetupImports(scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
6
- export declare function generateGeneric(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges, generic: NonNullable<NonNullable<Sfc['scriptSetup']>['generic']>, body: Iterable<Code>): Generator<Code>;
7
- export declare function generateSetupFunction(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges, body: Iterable<Code>, output?: Iterable<Code>): Generator<Code>;
5
+ export declare function generateScriptSetupImports(scriptSetup: IRScriptSetup, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
6
+ export declare function generateGeneric(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: IRScriptSetup, scriptSetupRanges: ScriptSetupRanges, generic: NonNullable<IRScriptSetup['generic']>, body: Iterable<Code>): Generator<Code>;
7
+ export declare function generateSetupFunction(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: IRScriptSetup, scriptSetupRanges: ScriptSetupRanges, body: Iterable<Code>, output?: Iterable<Code>): Generator<Code>;
@@ -19,16 +19,16 @@ function* generateTemplateCtx({ vueCompilerOptions, templateAndStyleTypes, scrip
19
19
  const emitTypes = [];
20
20
  const propTypes = [];
21
21
  if (vueCompilerOptions.petiteVueExtensions.some(ext => fileName.endsWith(ext))) {
22
- exps.push([`globalThis`]);
22
+ exps.push(`globalThis`);
23
23
  }
24
24
  if (selfType) {
25
- exps.push([`{} as InstanceType<${names_1.names.PickNotAny}<typeof ${selfType}, new () => {}>>`]);
25
+ exps.push(`{} as InstanceType<${names_1.names.PickNotAny}<typeof ${selfType}, new () => {}>>`);
26
26
  }
27
27
  else {
28
- exps.push([`{} as import('${vueCompilerOptions.lib}').ComponentPublicInstance`]);
28
+ exps.push(`{} as import('${vueCompilerOptions.lib}').ComponentPublicInstance`);
29
29
  }
30
30
  if (templateAndStyleTypes.has(names_1.names.StyleModules)) {
31
- exps.push([`{} as ${names_1.names.StyleModules}`]);
31
+ exps.push(`{} as ${names_1.names.StyleModules}`);
32
32
  }
33
33
  if (scriptSetupRanges?.defineEmits) {
34
34
  emitTypes.push(`typeof ${scriptSetupRanges.defineEmits.name ?? names_1.names.emit}`);
@@ -38,7 +38,7 @@ function* generateTemplateCtx({ vueCompilerOptions, templateAndStyleTypes, scrip
38
38
  }
39
39
  if (emitTypes.length) {
40
40
  yield `type ${names_1.names.EmitProps} = ${names_1.names.EmitsToProps}<${names_1.names.NormalizeEmits}<${emitTypes.join(` & `)}>>${utils_1.endOfLine}`;
41
- exps.push([`{} as { $emit: ${emitTypes.join(` & `)} }`]);
41
+ exps.push(`{} as { $emit: ${emitTypes.join(` & `)} }`);
42
42
  }
43
43
  if (scriptSetupRanges?.defineProps) {
44
44
  propTypes.push(`typeof ${scriptSetupRanges.defineProps.name ?? names_1.names.props}`);
@@ -50,14 +50,14 @@ function* generateTemplateCtx({ vueCompilerOptions, templateAndStyleTypes, scrip
50
50
  propTypes.push(names_1.names.EmitProps);
51
51
  }
52
52
  if (propTypes.length) {
53
- exps.push([`{} as { $props: ${propTypes.join(` & `)} }`]);
54
- exps.push([`{} as ${propTypes.join(` & `)}`]);
53
+ exps.push(`{} as { $props: ${propTypes.join(` & `)} }`);
54
+ exps.push(`{} as ${propTypes.join(` & `)}`);
55
55
  }
56
56
  if (ctx.generatedTypes.has(names_1.names.SetupExposed)) {
57
- exps.push([`{} as ${names_1.names.SetupExposed}`]);
57
+ exps.push(`{} as ${names_1.names.SetupExposed}`);
58
58
  }
59
59
  yield `const ${names_1.names.ctx} = `;
60
- yield* (0, merge_1.generateSpreadMerge)(exps);
60
+ yield* (0, merge_1.generateSpreadMerge)(...exps);
61
61
  yield utils_1.endOfLine;
62
62
  }
63
63
  function* generateTemplateComponents({ vueCompilerOptions, script, scriptRanges }, ctx) {
@@ -1,3 +1,3 @@
1
- import type { Code, Sfc } from '../../types';
1
+ import type { Code, IRStyle } from '../../types';
2
2
  export declare function generateClassProperty(source: string, classNameWithDot: string, offset: number, propertyType: string): Generator<Code>;
3
- export declare function generateStyleImports(style: Sfc['styles'][number]): Generator<Code>;
3
+ export declare function generateStyleImports(style: IRStyle): Generator<Code>;
@@ -1,8 +1,8 @@
1
- import type { Code, Sfc, VueCompilerOptions } from '../../types';
1
+ import type { Code, IRStyle, VueCompilerOptions } from '../../types';
2
2
  export interface StyleCodegenOptions {
3
3
  typescript: typeof import('typescript');
4
4
  vueCompilerOptions: VueCompilerOptions;
5
- styles: Sfc['styles'];
5
+ styles: readonly IRStyle[];
6
6
  setupRefs: Set<string>;
7
7
  setupConsts: Set<string>;
8
8
  }
@@ -156,23 +156,21 @@ function* generateComponent(options, ctx, node) {
156
156
  }
157
157
  }
158
158
  }
159
- yield* generateComponentBody(options, ctx, node, tag, startTagOffset, props, componentVar);
160
- }
161
- function* generateComponentBody(options, ctx, node, tag, tagOffset, props, componentVar) {
162
159
  let isCtxVarUsed = false;
163
160
  let isPropsVarUsed = false;
164
161
  const getCtxVar = () => (isCtxVarUsed = true, ctxVar);
165
162
  const getPropsVar = () => (isPropsVarUsed = true, propsVar);
166
163
  ctx.components.push(getCtxVar);
167
- const failGeneratedExpressions = [];
168
- const propCodes = [...(0, elementProps_1.generateElementProps)(options, ctx, node, props, options.vueCompilerOptions.checkUnknownProps, failGeneratedExpressions)];
169
164
  const functionalVar = ctx.getInternalVariable();
170
165
  const vnodeVar = ctx.getInternalVariable();
171
166
  const ctxVar = ctx.getInternalVariable();
172
167
  const propsVar = ctx.getInternalVariable();
168
+ const failedPropExps = [];
169
+ const propCodes = [...(0, elementProps_1.generateElementProps)(options, ctx, node, props, options.vueCompilerOptions.checkUnknownProps, failedPropExps)];
170
+ const propsStr = (0, muggle_string_1.toString)(propCodes);
173
171
  yield `// @ts-ignore${utils_1.newLine}`;
174
172
  yield `const ${functionalVar} = ${options.vueCompilerOptions.checkUnknownProps ? names_1.names.asFunctionalComponent0 : names_1.names.asFunctionalComponent1}(${componentVar}, new ${componentVar}({${utils_1.newLine}`;
175
- yield (0, muggle_string_1.toString)(propCodes);
173
+ yield propsStr;
176
174
  yield `}))${utils_1.endOfLine}`;
177
175
  yield `const `;
178
176
  const token = yield* (0, boundary_1.startBoundary)('template', node.loc.start.offset, codeFeatures_1.codeFeatures.doNotReportTs6133);
@@ -187,39 +185,46 @@ function* generateComponentBody(options, ctx, node, tag, tagOffset, props, compo
187
185
  yield `>`;
188
186
  yield (0, boundary_1.endBoundary)(token, offset + content.length);
189
187
  }
188
+ const shouldInheritAttrs = hasVBindAttrs(options, ctx, node);
190
189
  yield `(`;
191
- const token2 = yield* (0, boundary_1.startBoundary)('template', tagOffset, codeFeatures_1.codeFeatures.verification);
192
- yield `{${utils_1.newLine}`;
190
+ const token2 = yield* (0, boundary_1.startBoundary)('template', startTagOffset, shouldInheritAttrs && options.vueCompilerOptions.checkRequiredFallthroughAttributes
191
+ ? {}
192
+ : codeFeatures_1.codeFeatures.verification);
193
+ yield `{`;
194
+ yield [``, 'template', node.loc.start.offset, { __propsCompletion: true }];
195
+ yield utils_1.newLine;
193
196
  yield* propCodes;
194
197
  yield `}`;
195
- yield (0, boundary_1.endBoundary)(token2, tagOffset + tag.length);
198
+ yield (0, boundary_1.endBoundary)(token2, startTagOffset + tag.length);
196
199
  yield `, ...${names_1.names.functionalComponentArgsRest}(${functionalVar}))${utils_1.endOfLine}`;
197
- yield* generateFailedExpressions(options, ctx, failGeneratedExpressions);
200
+ yield* generateFailedExpressions(options, ctx, failedPropExps);
198
201
  yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, componentVar, getCtxVar, getPropsVar);
199
202
  yield* (0, elementDirectives_1.generateElementDirectives)(options, ctx, node);
200
203
  const templateRef = getTemplateRef(node);
201
- const isRootNode = ctx.singleRootNodes.has(node)
204
+ const isSingleRoot = ctx.singleRootNodes.has(node)
202
205
  && !options.vueCompilerOptions.fallthroughComponentNames.includes((0, shared_2.hyphenateTag)(tag));
203
- if (templateRef || isRootNode) {
206
+ if (templateRef || isSingleRoot) {
204
207
  const componentInstanceVar = ctx.getInternalVariable();
205
- yield `var ${componentInstanceVar} = {} as (Parameters<NonNullable<typeof ${getCtxVar()}['expose']>>[0] | null)`;
206
- if (ctx.inVFor) {
207
- yield `[]`;
208
- }
208
+ yield `var ${componentInstanceVar}!: Parameters<NonNullable<typeof ${getCtxVar()}['expose']>>[0]`;
209
209
  yield utils_1.endOfLine;
210
210
  if (templateRef) {
211
- const typeExp = `typeof ${ctx.getHoistVariable(componentInstanceVar)}`;
211
+ let typeExp = `typeof ${ctx.getHoistVariable(componentInstanceVar)} | null`;
212
+ if (ctx.inVFor) {
213
+ typeExp = `(${typeExp})[]`;
214
+ }
212
215
  ctx.addTemplateRef(templateRef[0], typeExp, templateRef[1]);
213
216
  }
214
- if (isRootNode) {
217
+ if (isSingleRoot) {
215
218
  ctx.singleRootElTypes.add(`NonNullable<typeof ${componentInstanceVar}>['$el']`);
216
219
  }
217
220
  }
218
- if (hasVBindAttrs(options, ctx, node)) {
219
- ctx.inheritedAttrVars.add(getPropsVar());
221
+ if (shouldInheritAttrs) {
222
+ const restsVar = ctx.getInternalVariable();
223
+ yield `var ${restsVar} = ${names_1.names.omit}(${getPropsVar()}, {\n${propsStr}})${utils_1.endOfLine}`;
224
+ ctx.inheritedAttrVars.add(restsVar);
220
225
  }
221
226
  yield* generateStyleScopedClassReferences(options, node);
222
- const slotDir = node.props.find(p => p.type === CompilerDOM.NodeTypes.DIRECTIVE && p.name === 'slot');
227
+ const slotDir = node.props.find(CompilerDOM.isVSlot);
223
228
  if (slotDir || node.children.length) {
224
229
  yield* (0, vSlot_1.generateVSlot)(options, ctx, node, slotDir, getCtxVar());
225
230
  }
@@ -371,9 +376,9 @@ function* forEachClassName(content) {
371
376
  offset += className.length + 1;
372
377
  }
373
378
  }
374
- function* generateFailedExpressions(options, ctx, failGeneratedExpressions) {
375
- for (const failedExp of failGeneratedExpressions) {
376
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, failedExp.node.loc.source, failedExp.node.loc.start.offset, failedExp.prefix, failedExp.suffix);
379
+ function* generateFailedExpressions(options, ctx, failedPropExps) {
380
+ for (const { node, prefix, suffix } of failedPropExps) {
381
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, node.loc.source, node.loc.start.offset, prefix, suffix);
377
382
  yield utils_1.endOfLine;
378
383
  }
379
384
  }
@@ -2,10 +2,10 @@ import * as CompilerDOM from '@vue/compiler-dom';
2
2
  import type { Code } from '../../types';
3
3
  import type { TemplateCodegenContext } from './context';
4
4
  import type { TemplateCodegenOptions } from './index';
5
- export interface FailGeneratedExpression {
5
+ export interface FailedPropExpressions {
6
6
  node: CompilerDOM.SimpleExpressionNode;
7
7
  prefix: string;
8
8
  suffix: string;
9
9
  }
10
- export declare function generateElementProps(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, props: CompilerDOM.ElementNode['props'], strictPropsCheck: boolean, failGeneratedExpressions?: FailGeneratedExpression[]): Generator<Code>;
10
+ export declare function generateElementProps(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, props: CompilerDOM.ElementNode['props'], checkUnknownProps: boolean, failedPropExps?: FailedPropExpressions[]): Generator<Code>;
11
11
  export declare function generatePropExp(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode, exp: CompilerDOM.SimpleExpressionNode | undefined): Generator<Code>;
@@ -50,7 +50,7 @@ const elementDirectives_1 = require("./elementDirectives");
50
50
  const elementEvents_1 = require("./elementEvents");
51
51
  const interpolation_1 = require("./interpolation");
52
52
  const objectProperty_1 = require("./objectProperty");
53
- function* generateElementProps(options, ctx, node, props, strictPropsCheck, failGeneratedExpressions) {
53
+ function* generateElementProps(options, ctx, node, props, checkUnknownProps, failedPropExps) {
54
54
  const isComponent = node.tagType === CompilerDOM.ElementTypes.COMPONENT;
55
55
  for (const prop of props) {
56
56
  if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
@@ -74,12 +74,12 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, fail
74
74
  && prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
75
75
  && prop.arg.loc.source.startsWith('[')
76
76
  && prop.arg.loc.source.endsWith(']')) {
77
- failGeneratedExpressions?.push({ node: prop.arg, prefix: `(`, suffix: `)` });
78
- failGeneratedExpressions?.push({ node: prop.exp, prefix: `() => {`, suffix: `}` });
77
+ failedPropExps?.push({ node: prop.arg, prefix: `(`, suffix: `)` });
78
+ failedPropExps?.push({ node: prop.exp, prefix: `() => {`, suffix: `}` });
79
79
  }
80
80
  else if (!prop.arg
81
81
  && prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
82
- failGeneratedExpressions?.push({ node: prop.exp, prefix: `(`, suffix: `)` });
82
+ failedPropExps?.push({ node: prop.exp, prefix: `(`, suffix: `)` });
83
83
  }
84
84
  }
85
85
  }
@@ -100,7 +100,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, fail
100
100
  if (propName === undefined
101
101
  || options.vueCompilerOptions.dataAttributes.some(pattern => (0, picomatch_1.isMatch)(propName, pattern))) {
102
102
  if (prop.exp && prop.exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY) {
103
- failGeneratedExpressions?.push({ node: prop.exp, prefix: `(`, suffix: `)` });
103
+ failedPropExps?.push({ node: prop.exp, prefix: `(`, suffix: `)` });
104
104
  }
105
105
  continue;
106
106
  }
@@ -110,7 +110,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, fail
110
110
  }
111
111
  const shouldSpread = propName === 'style' || propName === 'class';
112
112
  const shouldCamelize = getShouldCamelize(options, node, prop, propName);
113
- const features = getPropsCodeFeatures(strictPropsCheck);
113
+ const features = getPropsCodeFeatures(checkUnknownProps);
114
114
  if (shouldSpread) {
115
115
  yield `...{ `;
116
116
  }
@@ -149,7 +149,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, fail
149
149
  }
150
150
  const shouldSpread = prop.name === 'style' || prop.name === 'class';
151
151
  const shouldCamelize = getShouldCamelize(options, node, prop, prop.name);
152
- const features = getPropsCodeFeatures(strictPropsCheck);
152
+ const features = getPropsCodeFeatures(checkUnknownProps);
153
153
  if (shouldSpread) {
154
154
  yield `...{ `;
155
155
  }
@@ -184,7 +184,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, fail
184
184
  && !prop.arg
185
185
  && prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
186
186
  if (prop.exp.loc.source === '$attrs') {
187
- failGeneratedExpressions?.push({ node: prop.exp, prefix: `(`, suffix: `)` });
187
+ failedPropExps?.push({ node: prop.exp, prefix: `(`, suffix: `)` });
188
188
  }
189
189
  else {
190
190
  const token = yield* (0, boundary_1.startBoundary)('template', prop.exp.loc.start.offset, codeFeatures_1.codeFeatures.verification);
@@ -241,12 +241,13 @@ function getShouldCamelize(options, node, prop, propName) {
241
241
  && (0, shared_2.hyphenateAttr)(propName) === propName
242
242
  && !options.vueCompilerOptions.htmlAttributes.some(pattern => (0, picomatch_1.isMatch)(propName, pattern));
243
243
  }
244
- function getPropsCodeFeatures(strictPropsCheck) {
244
+ function getPropsCodeFeatures(checkUnknownProps) {
245
245
  return {
246
246
  ...codeFeatures_1.codeFeatures.withoutHighlightAndCompletion,
247
- ...strictPropsCheck
247
+ ...checkUnknownProps
248
248
  ? codeFeatures_1.codeFeatures.verification
249
249
  : codeFeatures_1.codeFeatures.doNotReportTs2353AndTs2561,
250
+ __propsCompletion: true,
250
251
  };
251
252
  }
252
253
  function getModelPropName(node, vueCompilerOptions) {
@@ -1,9 +1,9 @@
1
1
  import type * as ts from 'typescript';
2
- import type { Code, Sfc, VueCompilerOptions } from '../../types';
2
+ import type { Code, IRTemplate, VueCompilerOptions } from '../../types';
3
3
  export interface TemplateCodegenOptions {
4
4
  typescript: typeof ts;
5
5
  vueCompilerOptions: VueCompilerOptions;
6
- template: NonNullable<Sfc['template']>;
6
+ template: IRTemplate;
7
7
  setupRefs: Set<string>;
8
8
  setupConsts: Set<string>;
9
9
  hasDefineSlots?: boolean;
@@ -47,7 +47,7 @@ function* generateWorker(options, ctx) {
47
47
  }
48
48
  yield* ctx.generateHoistVariables();
49
49
  yield* generateSlotsType(options, ctx);
50
- yield* generateInheritedAttrsType(ctx);
50
+ yield* generateInheritedAttrsType(options, ctx);
51
51
  yield* generateTemplateRefsType(options, ctx);
52
52
  yield* generateRootElType(ctx);
53
53
  if (ctx.dollarVars.size) {
@@ -102,12 +102,15 @@ function* generateSlotsType(options, ctx) {
102
102
  }
103
103
  yield utils_1.endOfLine;
104
104
  }
105
- function* generateInheritedAttrsType(ctx) {
105
+ function* generateInheritedAttrsType(options, ctx) {
106
106
  if (!ctx.inheritedAttrVars.size) {
107
107
  return;
108
108
  }
109
109
  ctx.generatedTypes.add(names_1.names.InheritedAttrs);
110
- yield `type ${names_1.names.InheritedAttrs} = Partial<${[...ctx.inheritedAttrVars].map(name => `typeof ${name}`).join(` & `)}>`;
110
+ const type = [...ctx.inheritedAttrVars].map(name => `typeof ${name}`).join(` & `);
111
+ yield `type ${names_1.names.InheritedAttrs} = ${options.vueCompilerOptions.checkRequiredFallthroughAttributes
112
+ ? type
113
+ : `Partial<${type}>`}`;
111
114
  yield utils_1.endOfLine;
112
115
  }
113
116
  function* generateTemplateRefsType(options, ctx) {
@@ -1,6 +1,6 @@
1
- import type { Code, SfcBlock, VueCodeInformation } from '../../types';
1
+ import type { Code, IRBlock, VueCodeInformation } from '../../types';
2
2
  import type { TemplateCodegenContext } from './context';
3
3
  export declare function generateInterpolation({ typescript, setupRefs }: {
4
4
  typescript: typeof import('typescript');
5
5
  setupRefs: Set<string>;
6
- }, ctx: TemplateCodegenContext, block: SfcBlock, data: VueCodeInformation, code: string, start: number, prefix?: string, suffix?: string): Generator<Code>;
6
+ }, ctx: TemplateCodegenContext, block: IRBlock, data: VueCodeInformation, code: string, start: number, prefix?: string, suffix?: string): Generator<Code>;
@@ -1,3 +1,3 @@
1
- import type { Code, SfcBlock } from '../../types';
2
- export declare const references: WeakMap<SfcBlock, [version: string, [className: string, offset: number][]]>;
3
- export declare function generateStyleScopedClassReference(block: SfcBlock, className: string, offset: number, fullStart?: number): Generator<Code>;
1
+ import type { Code, IRBlock } from '../../types';
2
+ export declare const references: WeakMap<IRBlock, [version: string, [className: string, offset: number][]]>;
3
+ export declare function generateStyleScopedClassReference(block: IRBlock, className: string, offset: number, fullStart?: number): Generator<Code>;
@@ -2,5 +2,5 @@ import * as CompilerDOM from '@vue/compiler-dom';
2
2
  import type { Code } from '../../types';
3
3
  import type { TemplateCodegenContext } from './context';
4
4
  import type { TemplateCodegenOptions } from './index';
5
- export declare function generateTemplateChild(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode, enterNode?: boolean, isVForChild?: boolean): Generator<Code>;
5
+ export declare function generateTemplateChild(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode, enterNode?: boolean, treatTemplateAsFragment?: boolean): Generator<Code>;
6
6
  export declare function parseInterpolationNode(node: CompilerDOM.InterpolationNode, template: string): readonly [string, number];
@@ -45,7 +45,7 @@ const slotOutlet_1 = require("./slotOutlet");
45
45
  const vFor_1 = require("./vFor");
46
46
  const vIf_1 = require("./vIf");
47
47
  const vSlot_1 = require("./vSlot");
48
- function* generateTemplateChild(options, ctx, node, enterNode = true, isVForChild = false) {
48
+ function* generateTemplateChild(options, ctx, node, enterNode = true, treatTemplateAsFragment = false) {
49
49
  if (enterNode && !ctx.enter(node)) {
50
50
  return;
51
51
  }
@@ -66,7 +66,7 @@ function* generateTemplateChild(options, ctx, node, enterNode = true, isVForChil
66
66
  if (node.tagType === CompilerDOM.ElementTypes.TEMPLATE && ctx.components.length && slotDir) {
67
67
  yield* (0, vSlot_1.generateVSlot)(options, ctx, node, slotDir, ctx.components.at(-1)());
68
68
  }
69
- else if (node.tagType === CompilerDOM.ElementTypes.TEMPLATE && isVForChild) {
69
+ else if (node.tagType === CompilerDOM.ElementTypes.TEMPLATE && treatTemplateAsFragment) {
70
70
  yield* (0, element_1.generateFragment)(options, ctx, node);
71
71
  }
72
72
  else if (node.tagType === CompilerDOM.ElementTypes.COMPONENT) {
@@ -103,7 +103,7 @@ function* generateTemplateChild(options, ctx, node, enterNode = true, isVForChil
103
103
  yield* ctx.exit();
104
104
  }
105
105
  }
106
- function* collectSingleRootNodes(options, children) {
106
+ function* collectSingleRootNodes(options, children, treatTemplateAsFragment = false) {
107
107
  // Exclude the effect of comments on the root node
108
108
  children = children.filter(node => node.type !== CompilerDOM.NodeTypes.COMMENT);
109
109
  if (children.length !== 1) {
@@ -116,13 +116,17 @@ function* collectSingleRootNodes(options, children) {
116
116
  const child = children[0];
117
117
  if (child.type === CompilerDOM.NodeTypes.IF) {
118
118
  for (const branch of child.branches) {
119
- yield* collectSingleRootNodes(options, branch.children);
119
+ yield* collectSingleRootNodes(options, branch.children, true);
120
120
  }
121
121
  return;
122
122
  }
123
123
  else if (child.type !== CompilerDOM.NodeTypes.ELEMENT) {
124
124
  return;
125
125
  }
126
+ if (child.tagType === CompilerDOM.ElementTypes.TEMPLATE && treatTemplateAsFragment) {
127
+ yield* collectSingleRootNodes(options, child.children);
128
+ return;
129
+ }
126
130
  yield child;
127
131
  const tag = (0, shared_1.hyphenateTag)(child.tag);
128
132
  if (options.vueCompilerOptions.fallthroughComponentNames.includes(tag)) {
@@ -1,8 +1,8 @@
1
1
  import type * as ts from 'typescript';
2
- import type { Code, Sfc, SfcBlock, VueCodeInformation } from '../../types';
2
+ import type { Code, IRBlock, IRScript, IRScriptSetup, VueCodeInformation } from '../../types';
3
3
  export declare const newLine = "\n";
4
4
  export declare const endOfLine = ";\n";
5
5
  export declare const identifierRegex: RegExp;
6
- export declare function getTypeScriptAST(ts: typeof import('typescript'), block: SfcBlock, text: string): ts.SourceFile;
7
- export declare function generateSfcBlockSection(block: NonNullable<Sfc['script' | 'scriptSetup']>, start: number, end: number, features: VueCodeInformation): Generator<Code>;
6
+ export declare function getTypeScriptAST(ts: typeof import('typescript'), block: IRBlock, text: string): ts.SourceFile;
7
+ export declare function generateSfcBlockSection(block: IRScript | IRScriptSetup, start: number, end: number, features: VueCodeInformation): Generator<Code>;
8
8
  export declare function forEachNode(ts: typeof import('typescript'), node: ts.Node): Generator<ts.Node>;
@@ -1,3 +1,3 @@
1
1
  import type { Code } from '../../types';
2
- export declare function generateIntersectMerge(generates: Iterable<Code>[]): Generator<Code>;
3
- export declare function generateSpreadMerge(generates: Iterable<Code>[]): Generator<Code>;
2
+ export declare function generateIntersectMerge(...codes: Code[]): Generator<Code>;
3
+ export declare function generateSpreadMerge(...codes: Code[]): Generator<Code>;