@vue/language-core 3.2.8 → 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 (67) hide show
  1. package/README.md +1 -0
  2. package/index.d.ts +1 -0
  3. package/index.js +1 -0
  4. package/lib/codegen/names.d.ts +1 -0
  5. package/lib/codegen/names.js +1 -0
  6. package/lib/codegen/script/component.d.ts +2 -2
  7. package/lib/codegen/script/component.js +64 -58
  8. package/lib/codegen/script/index.d.ts +3 -3
  9. package/lib/codegen/script/scriptSetup.d.ts +4 -4
  10. package/lib/codegen/script/template.js +9 -9
  11. package/lib/codegen/style/common.d.ts +2 -2
  12. package/lib/codegen/style/index.d.ts +2 -2
  13. package/lib/codegen/template/element.d.ts +1 -0
  14. package/lib/codegen/template/element.js +46 -24
  15. package/lib/codegen/template/elementProps.d.ts +2 -2
  16. package/lib/codegen/template/elementProps.js +17 -16
  17. package/lib/codegen/template/index.d.ts +2 -2
  18. package/lib/codegen/template/index.js +6 -3
  19. package/lib/codegen/template/interpolation.d.ts +2 -2
  20. package/lib/codegen/template/styleScopedClasses.d.ts +3 -3
  21. package/lib/codegen/template/templateChild.d.ts +1 -1
  22. package/lib/codegen/template/templateChild.js +20 -25
  23. package/lib/codegen/template/vFor.js +1 -19
  24. package/lib/codegen/template/vIf.js +1 -5
  25. package/lib/codegen/utils/index.d.ts +3 -3
  26. package/lib/codegen/utils/merge.d.ts +2 -2
  27. package/lib/codegen/utils/merge.js +9 -9
  28. package/lib/compilerOptions.js +1 -0
  29. package/lib/languagePlugin.js +2 -0
  30. package/lib/plugins/file-md.js +26 -30
  31. package/lib/plugins/vue-root-tags.js +9 -9
  32. package/lib/plugins/vue-sfc-customblocks.js +4 -4
  33. package/lib/plugins/vue-sfc-scripts.js +8 -8
  34. package/lib/plugins/vue-sfc-styles.js +5 -5
  35. package/lib/plugins/vue-sfc-template.js +7 -7
  36. package/lib/plugins/vue-template-html.js +37 -12
  37. package/lib/plugins/vue-template-inline-css.js +6 -6
  38. package/lib/plugins/vue-template-inline-ts.js +12 -16
  39. package/lib/plugins/vue-tsx.d.ts +2 -2
  40. package/lib/plugins/vue-tsx.js +35 -35
  41. package/lib/template/compile.d.ts +2 -0
  42. package/lib/template/compile.js +31 -0
  43. package/lib/template/transforms/transformElement.d.ts +2 -0
  44. package/lib/template/transforms/transformElement.js +95 -0
  45. package/lib/template/transforms/transformText.d.ts +2 -0
  46. package/lib/template/transforms/transformText.js +35 -0
  47. package/lib/template/transforms/vFor.d.ts +1 -0
  48. package/lib/template/transforms/vFor.js +42 -0
  49. package/lib/template/transforms/vIf.d.ts +1 -0
  50. package/lib/template/transforms/vIf.js +92 -0
  51. package/lib/template/utils.d.ts +3 -0
  52. package/lib/template/utils.js +37 -0
  53. package/lib/types.d.ts +55 -48
  54. package/lib/utils/forEachTemplateNode.js +0 -3
  55. package/lib/utils/parseSfc.js +0 -1
  56. package/lib/utils/shared.d.ts +2 -2
  57. package/lib/virtualCode/embeddedCodes.d.ts +2 -2
  58. package/lib/virtualCode/embeddedCodes.js +11 -11
  59. package/lib/virtualCode/index.d.ts +4 -2
  60. package/lib/virtualCode/index.js +4 -0
  61. package/lib/virtualCode/ir.d.ts +2 -2
  62. package/lib/virtualCode/ir.js +0 -39
  63. package/package.json +9 -6
  64. package/types/template-helpers.d.ts +1 -0
  65. package/lib/virtualCode/normalize.d.ts +0 -2
  66. package/lib/virtualCode/normalize.js +0 -205
  67. package/scripts/generate-names.js +0 -41
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. |
package/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export * from './lib/languagePlugin';
4
4
  export * from './lib/parsers/scriptRanges';
5
5
  export * from './lib/parsers/scriptSetupRanges';
6
6
  export * from './lib/plugins';
7
+ export * from './lib/template/compile';
7
8
  export * from './lib/types';
8
9
  export * from './lib/utils/collectBindings';
9
10
  export * from './lib/utils/forEachTemplateNode';
package/index.js CHANGED
@@ -21,6 +21,7 @@ __exportStar(require("./lib/languagePlugin"), exports);
21
21
  __exportStar(require("./lib/parsers/scriptRanges"), exports);
22
22
  __exportStar(require("./lib/parsers/scriptSetupRanges"), exports);
23
23
  __exportStar(require("./lib/plugins"), exports);
24
+ __exportStar(require("./lib/template/compile"), exports);
24
25
  __exportStar(require("./lib/types"), exports);
25
26
  __exportStar(require("./lib/utils/collectBindings"), exports);
26
27
  __exportStar(require("./lib/utils/forEachTemplateNode"), exports);
@@ -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
  }
@@ -4,3 +4,4 @@ import type { TemplateCodegenContext } from './context';
4
4
  import type { TemplateCodegenOptions } from './index';
5
5
  export declare function generateComponent(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode): Generator<Code>;
6
6
  export declare function generateElement(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode): Generator<Code>;
7
+ export declare function generateFragment(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode): Generator<Code>;
@@ -35,6 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.generateComponent = generateComponent;
37
37
  exports.generateElement = generateElement;
38
+ exports.generateFragment = generateFragment;
38
39
  const CompilerDOM = __importStar(require("@vue/compiler-dom"));
39
40
  const shared_1 = require("@vue/shared");
40
41
  const muggle_string_1 = require("muggle-string");
@@ -155,23 +156,21 @@ function* generateComponent(options, ctx, node) {
155
156
  }
156
157
  }
157
158
  }
158
- yield* generateComponentBody(options, ctx, node, tag, startTagOffset, props, componentVar);
159
- }
160
- function* generateComponentBody(options, ctx, node, tag, tagOffset, props, componentVar) {
161
159
  let isCtxVarUsed = false;
162
160
  let isPropsVarUsed = false;
163
161
  const getCtxVar = () => (isCtxVarUsed = true, ctxVar);
164
162
  const getPropsVar = () => (isPropsVarUsed = true, propsVar);
165
163
  ctx.components.push(getCtxVar);
166
- const failGeneratedExpressions = [];
167
- const propCodes = [...(0, elementProps_1.generateElementProps)(options, ctx, node, props, options.vueCompilerOptions.checkUnknownProps, failGeneratedExpressions)];
168
164
  const functionalVar = ctx.getInternalVariable();
169
165
  const vnodeVar = ctx.getInternalVariable();
170
166
  const ctxVar = ctx.getInternalVariable();
171
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);
172
171
  yield `// @ts-ignore${utils_1.newLine}`;
173
172
  yield `const ${functionalVar} = ${options.vueCompilerOptions.checkUnknownProps ? names_1.names.asFunctionalComponent0 : names_1.names.asFunctionalComponent1}(${componentVar}, new ${componentVar}({${utils_1.newLine}`;
174
- yield (0, muggle_string_1.toString)(propCodes);
173
+ yield propsStr;
175
174
  yield `}))${utils_1.endOfLine}`;
176
175
  yield `const `;
177
176
  const token = yield* (0, boundary_1.startBoundary)('template', node.loc.start.offset, codeFeatures_1.codeFeatures.doNotReportTs6133);
@@ -186,39 +185,46 @@ function* generateComponentBody(options, ctx, node, tag, tagOffset, props, compo
186
185
  yield `>`;
187
186
  yield (0, boundary_1.endBoundary)(token, offset + content.length);
188
187
  }
188
+ const shouldInheritAttrs = hasVBindAttrs(options, ctx, node);
189
189
  yield `(`;
190
- const token2 = yield* (0, boundary_1.startBoundary)('template', tagOffset, codeFeatures_1.codeFeatures.verification);
191
- 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;
192
196
  yield* propCodes;
193
197
  yield `}`;
194
- yield (0, boundary_1.endBoundary)(token2, tagOffset + tag.length);
198
+ yield (0, boundary_1.endBoundary)(token2, startTagOffset + tag.length);
195
199
  yield `, ...${names_1.names.functionalComponentArgsRest}(${functionalVar}))${utils_1.endOfLine}`;
196
- yield* generateFailedExpressions(options, ctx, failGeneratedExpressions);
200
+ yield* generateFailedExpressions(options, ctx, failedPropExps);
197
201
  yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, componentVar, getCtxVar, getPropsVar);
198
202
  yield* (0, elementDirectives_1.generateElementDirectives)(options, ctx, node);
199
203
  const templateRef = getTemplateRef(node);
200
- const isRootNode = ctx.singleRootNodes.has(node)
204
+ const isSingleRoot = ctx.singleRootNodes.has(node)
201
205
  && !options.vueCompilerOptions.fallthroughComponentNames.includes((0, shared_2.hyphenateTag)(tag));
202
- if (templateRef || isRootNode) {
206
+ if (templateRef || isSingleRoot) {
203
207
  const componentInstanceVar = ctx.getInternalVariable();
204
- yield `var ${componentInstanceVar} = {} as (Parameters<NonNullable<typeof ${getCtxVar()}['expose']>>[0] | null)`;
205
- if (ctx.inVFor) {
206
- yield `[]`;
207
- }
208
+ yield `var ${componentInstanceVar}!: Parameters<NonNullable<typeof ${getCtxVar()}['expose']>>[0]`;
208
209
  yield utils_1.endOfLine;
209
210
  if (templateRef) {
210
- const typeExp = `typeof ${ctx.getHoistVariable(componentInstanceVar)}`;
211
+ let typeExp = `typeof ${ctx.getHoistVariable(componentInstanceVar)} | null`;
212
+ if (ctx.inVFor) {
213
+ typeExp = `(${typeExp})[]`;
214
+ }
211
215
  ctx.addTemplateRef(templateRef[0], typeExp, templateRef[1]);
212
216
  }
213
- if (isRootNode) {
217
+ if (isSingleRoot) {
214
218
  ctx.singleRootElTypes.add(`NonNullable<typeof ${componentInstanceVar}>['$el']`);
215
219
  }
216
220
  }
217
- if (hasVBindAttrs(options, ctx, node)) {
218
- 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);
219
225
  }
220
226
  yield* generateStyleScopedClassReferences(options, node);
221
- const slotDir = node.props.find(p => p.type === CompilerDOM.NodeTypes.DIRECTIVE && p.name === 'slot');
227
+ const slotDir = node.props.find(CompilerDOM.isVSlot);
222
228
  if (slotDir || node.children.length) {
223
229
  yield* (0, vSlot_1.generateVSlot)(options, ctx, node, slotDir, getCtxVar());
224
230
  }
@@ -268,6 +274,22 @@ function* generateElement(options, ctx, node) {
268
274
  yield* (0, templateChild_1.generateTemplateChild)(options, ctx, child);
269
275
  }
270
276
  }
277
+ function* generateFragment(options, ctx, node) {
278
+ const [startTagOffset] = (0, shared_2.getElementTagOffsets)(node, options.template);
279
+ // special case for <template v-for="..." :key="..." />
280
+ if (node.props.length) {
281
+ yield `__VLS_asFunctionalElement(__VLS_intrinsics.template)(`;
282
+ const token = yield* (0, boundary_1.startBoundary)('template', startTagOffset, codeFeatures_1.codeFeatures.verification);
283
+ yield `{${utils_1.newLine}`;
284
+ yield* (0, elementProps_1.generateElementProps)(options, ctx, node, node.props, options.vueCompilerOptions.checkUnknownProps);
285
+ yield `}`;
286
+ yield (0, boundary_1.endBoundary)(token, startTagOffset + node.tag.length);
287
+ yield `)${utils_1.endOfLine}`;
288
+ }
289
+ for (const child of node.children) {
290
+ yield* (0, templateChild_1.generateTemplateChild)(options, ctx, child);
291
+ }
292
+ }
271
293
  function* generateStyleScopedClassReferences({ template, typescript: ts }, node) {
272
294
  for (const prop of node.props) {
273
295
  if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE
@@ -354,9 +376,9 @@ function* forEachClassName(content) {
354
376
  offset += className.length + 1;
355
377
  }
356
378
  }
357
- function* generateFailedExpressions(options, ctx, failGeneratedExpressions) {
358
- for (const failedExp of failGeneratedExpressions) {
359
- 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);
360
382
  yield utils_1.endOfLine;
361
383
  }
362
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
  }
@@ -109,8 +109,8 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, fail
109
109
  propName = propName.slice(1);
110
110
  }
111
111
  const shouldSpread = propName === 'style' || propName === 'class';
112
- const shouldCamelize = isComponent && getShouldCamelize(options, prop, propName);
113
- const features = getPropsCodeFeatures(strictPropsCheck);
112
+ const shouldCamelize = getShouldCamelize(options, node, prop, propName);
113
+ const features = getPropsCodeFeatures(checkUnknownProps);
114
114
  if (shouldSpread) {
115
115
  yield `...{ `;
116
116
  }
@@ -148,8 +148,8 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, fail
148
148
  continue;
149
149
  }
150
150
  const shouldSpread = prop.name === 'style' || prop.name === 'class';
151
- const shouldCamelize = isComponent && getShouldCamelize(options, prop, prop.name);
152
- const features = getPropsCodeFeatures(strictPropsCheck);
151
+ const shouldCamelize = getShouldCamelize(options, node, prop, prop.name);
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);
@@ -234,19 +234,20 @@ function* generateAttrValue(node, features) {
234
234
  yield* (0, unicode_1.generateUnicode)(content, offset, features);
235
235
  yield quote;
236
236
  }
237
- function getShouldCamelize(options, prop, propName) {
238
- return (prop.type !== CompilerDOM.NodeTypes.DIRECTIVE
239
- || !prop.arg
240
- || (prop.arg.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic))
237
+ function getShouldCamelize(options, node, prop, propName) {
238
+ return (node.tagType === CompilerDOM.ElementTypes.COMPONENT
239
+ || node.tagType === CompilerDOM.ElementTypes.SLOT) && (prop.type !== CompilerDOM.NodeTypes.DIRECTIVE
240
+ || prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic)
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): 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];