@vue/language-core 3.0.5 → 3.0.7-alpha.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 (56) hide show
  1. package/index.d.ts +1 -1
  2. package/index.js +1 -1
  3. package/lib/codegen/codeFeatures.d.ts +0 -5
  4. package/lib/codegen/codeFeatures.js +0 -3
  5. package/lib/codegen/script/component.d.ts +1 -1
  6. package/lib/codegen/script/component.js +10 -14
  7. package/lib/codegen/script/componentSelf.js +19 -23
  8. package/lib/codegen/script/index.d.ts +20 -3
  9. package/lib/codegen/script/index.js +10 -16
  10. package/lib/codegen/script/scriptSetup.js +1 -1
  11. package/lib/codegen/script/template.d.ts +0 -1
  12. package/lib/codegen/script/template.js +6 -43
  13. package/lib/codegen/template/element.js +4 -18
  14. package/lib/codegen/template/elementDirectives.js +3 -1
  15. package/lib/codegen/template/index.d.ts +63 -3
  16. package/lib/codegen/template/index.js +21 -21
  17. package/lib/codegen/template/interpolation.js +19 -5
  18. package/lib/codegen/template/slotOutlet.js +2 -2
  19. package/lib/codegen/template/styleScopedClasses.js +6 -10
  20. package/lib/codegen/template/vSlot.js +15 -25
  21. package/lib/{utils/ts.d.ts → compilerOptions.d.ts} +8 -8
  22. package/lib/compilerOptions.js +294 -0
  23. package/lib/plugins/file-html.js +1 -1
  24. package/lib/plugins/file-md.js +1 -1
  25. package/lib/plugins/file-vue.js +1 -1
  26. package/lib/plugins/vue-root-tags.js +1 -1
  27. package/lib/plugins/vue-script-js.js +1 -1
  28. package/lib/plugins/vue-sfc-customblocks.js +1 -1
  29. package/lib/plugins/vue-sfc-scripts.js +1 -1
  30. package/lib/plugins/vue-sfc-styles.js +5 -5
  31. package/lib/plugins/vue-sfc-template.js +1 -1
  32. package/lib/plugins/vue-template-html.js +1 -1
  33. package/lib/plugins/vue-template-inline-css.js +1 -1
  34. package/lib/plugins/vue-template-inline-ts.js +1 -1
  35. package/lib/plugins/vue-tsx.d.ts +5 -5
  36. package/lib/plugins/vue-tsx.js +7 -26
  37. package/lib/plugins.js +2 -0
  38. package/lib/types.d.ts +3 -2
  39. package/lib/types.js +1 -1
  40. package/lib/utils/shared.d.ts +3 -1
  41. package/lib/utils/shared.js +13 -0
  42. package/lib/utils/ts.js +43 -66
  43. package/lib/virtualFile/computedSfc.js +13 -8
  44. package/package.json +4 -4
  45. package/lib/codegen/tenp.d.ts +0 -1
  46. package/lib/codegen/tenp.js +0 -3
  47. package/lib/parsers/utils.d.ts +0 -12
  48. package/lib/parsers/utils.js +0 -95
  49. package/lib/plugins/file-css.d.ts +0 -3
  50. package/lib/plugins/file-css.js +0 -57
  51. package/lib/utils/parseCssClassNames.d.ts +0 -4
  52. package/lib/utils/parseCssClassNames.js +0 -17
  53. package/lib/utils/parseCssImports.d.ts +0 -4
  54. package/lib/utils/parseCssImports.js +0 -19
  55. package/lib/utils/parseCssVars.d.ts +0 -6
  56. package/lib/utils/parseCssVars.js +0 -26
package/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './lib/codegen/globalTypes';
2
2
  export * from './lib/codegen/template';
3
+ export * from './lib/compilerOptions';
3
4
  export * from './lib/languagePlugin';
4
5
  export * from './lib/parsers/scriptSetupRanges';
5
6
  export * from './lib/plugins';
@@ -7,7 +8,6 @@ export * from './lib/types';
7
8
  export * from './lib/utils/collectBindings';
8
9
  export * from './lib/utils/parseSfc';
9
10
  export * from './lib/utils/shared';
10
- export * from './lib/utils/ts';
11
11
  export * from './lib/virtualFile/vueFile';
12
12
  export { tsCodegen } from './lib/plugins/vue-tsx';
13
13
  export * from '@volar/language-core';
package/index.js CHANGED
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.tsCodegen = void 0;
18
18
  __exportStar(require("./lib/codegen/globalTypes"), exports);
19
19
  __exportStar(require("./lib/codegen/template"), exports);
20
+ __exportStar(require("./lib/compilerOptions"), exports);
20
21
  __exportStar(require("./lib/languagePlugin"), exports);
21
22
  __exportStar(require("./lib/parsers/scriptSetupRanges"), exports);
22
23
  __exportStar(require("./lib/plugins"), exports);
@@ -24,7 +25,6 @@ __exportStar(require("./lib/types"), exports);
24
25
  __exportStar(require("./lib/utils/collectBindings"), exports);
25
26
  __exportStar(require("./lib/utils/parseSfc"), exports);
26
27
  __exportStar(require("./lib/utils/shared"), exports);
27
- __exportStar(require("./lib/utils/ts"), exports);
28
28
  __exportStar(require("./lib/virtualFile/vueFile"), exports);
29
29
  var vue_tsx_1 = require("./lib/plugins/vue-tsx");
30
30
  Object.defineProperty(exports, "tsCodegen", { enumerable: true, get: function () { return vue_tsx_1.tsCodegen; } });
@@ -25,11 +25,6 @@ declare const raw: {
25
25
  navigation: {
26
26
  navigation: true;
27
27
  };
28
- navigationWithoutHighlight: {
29
- navigation: {
30
- shouldHighlight: () => false;
31
- };
32
- };
33
28
  navigationWithoutRename: {
34
29
  navigation: {
35
30
  shouldRename: () => false;
@@ -25,9 +25,6 @@ const raw = {
25
25
  navigation: {
26
26
  navigation: true,
27
27
  },
28
- navigationWithoutHighlight: {
29
- navigation: { shouldHighlight: () => false },
30
- },
31
28
  navigationWithoutRename: {
32
29
  navigation: { shouldRename: () => false },
33
30
  },
@@ -3,6 +3,6 @@ import type { Code, Sfc } from '../../types';
3
3
  import type { ScriptCodegenContext } from './context';
4
4
  import type { ScriptCodegenOptions } from './index';
5
5
  export declare function generateComponent(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
6
- export declare function generateComponentSetupReturns(scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
6
+ export declare function generateComponentSetupReturns(scriptSetupRanges: ScriptSetupRanges): Generator<string>;
7
7
  export declare function generateEmitsOption(options: ScriptCodegenOptions, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
8
8
  export declare function generatePropsOption(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges, hasEmitsOption: boolean, inheritAttrs: boolean): Generator<Code>;
@@ -17,23 +17,18 @@ function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
17
17
  else {
18
18
  yield `(await import('${options.vueCompilerOptions.lib}')).defineComponent({${utils_1.newLine}`;
19
19
  }
20
- yield `setup() {${utils_1.newLine}`;
21
20
  const returns = [];
22
21
  if (ctx.bypassDefineComponent) {
23
- yield* `const __VLS_returns = {${utils_1.newLine}`;
24
- yield* generateComponentSetupReturns(scriptSetupRanges);
25
- yield `}${utils_1.endOfLine}`;
26
- returns.push(`typeof __VLS_returns`);
22
+ returns.push(...generateComponentSetupReturns(scriptSetupRanges));
27
23
  }
28
24
  if (scriptSetupRanges.defineExpose) {
29
- returns.push(`typeof __VLS_exposed`);
25
+ returns.push(`__VLS_exposed`);
30
26
  }
31
27
  if (returns.length) {
32
- yield `return {} as `;
33
- yield* (0, merge_1.generateIntersectMerge)(returns);
34
- yield utils_1.endOfLine;
28
+ yield `setup: () => (`;
29
+ yield* (0, merge_1.generateSpreadMerge)(returns);
30
+ yield `),${utils_1.newLine}`;
35
31
  }
36
- yield `},${utils_1.newLine}`;
37
32
  if (!ctx.bypassDefineComponent) {
38
33
  const emitOptionCodes = [...generateEmitsOption(options, scriptSetupRanges)];
39
34
  yield* emitOptionCodes;
@@ -58,13 +53,14 @@ function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
58
53
  function* generateComponentSetupReturns(scriptSetupRanges) {
59
54
  // fill $props
60
55
  if (scriptSetupRanges.defineProps) {
56
+ const name = scriptSetupRanges.defineProps.name ?? `__VLS_props`;
61
57
  // NOTE: defineProps is inaccurate for $props
62
- yield `$props: __VLS_makeOptional(${scriptSetupRanges.defineProps.name ?? `__VLS_props`}),${utils_1.newLine}`;
63
- yield `...${scriptSetupRanges.defineProps.name ?? `__VLS_props`},${utils_1.newLine}`;
58
+ yield name;
59
+ yield `{} as { $props: Partial<typeof ${name}> }`;
64
60
  }
65
61
  // fill $emit
66
62
  if (scriptSetupRanges.defineEmits) {
67
- yield `$emit: ${scriptSetupRanges.defineEmits.name ?? '__VLS_emit'},${utils_1.newLine}`;
63
+ yield `{} as { $emit: typeof ${scriptSetupRanges.defineEmits.name ?? `__VLS_emit`} }`;
68
64
  }
69
65
  }
70
66
  function* generateEmitsOption(options, scriptSetupRanges) {
@@ -99,7 +95,7 @@ function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasE
99
95
  const getOptionCodes = [];
100
96
  const typeOptionCodes = [];
101
97
  if (inheritAttrs && options.templateCodegen?.inheritedAttrVars.size) {
102
- let attrsType = `Partial<__VLS_InheritedAttrs>`;
98
+ let attrsType = `__VLS_InheritedAttrs`;
103
99
  if (hasEmitsOption) {
104
100
  attrsType = `Omit<${attrsType}, \`on\${string}\`>`;
105
101
  }
@@ -1,41 +1,37 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateComponentSelf = generateComponentSelf;
4
+ const shared_1 = require("@vue/shared");
4
5
  const path = require("path-browserify");
5
6
  const codeFeatures_1 = require("../codeFeatures");
6
7
  const utils_1 = require("../utils");
7
8
  const component_1 = require("./component");
8
- const template_1 = require("./template");
9
9
  function* generateComponentSelf(options, ctx, templateCodegenCtx) {
10
10
  if (options.sfc.scriptSetup && options.scriptSetupRanges) {
11
11
  yield `const __VLS_self = (await import('${options.vueCompilerOptions.lib}')).defineComponent({${utils_1.newLine}`;
12
- yield `setup() {${utils_1.newLine}`;
13
- yield `return {${utils_1.newLine}`;
12
+ yield `setup: () => ({${utils_1.newLine}`;
14
13
  if (ctx.bypassDefineComponent) {
15
- yield* (0, component_1.generateComponentSetupReturns)(options.scriptSetupRanges);
14
+ for (const code of (0, component_1.generateComponentSetupReturns)(options.scriptSetupRanges)) {
15
+ yield `...${code},${utils_1.newLine}`;
16
+ }
16
17
  }
17
18
  // bindings
18
- const templateUsageVars = (0, template_1.getTemplateUsageVars)(options, ctx);
19
- for (const [content, bindings] of [
20
- [options.sfc.scriptSetup.content, options.scriptSetupRanges.bindings],
21
- options.sfc.script && options.scriptRanges
22
- ? [options.sfc.script.content, options.scriptRanges.bindings]
23
- : ['', []],
24
- ]) {
25
- for (const { range } of bindings) {
26
- const varName = content.slice(range.start, range.end);
27
- if (!templateUsageVars.has(varName) && !templateCodegenCtx.accessExternalVariables.has(varName)) {
28
- continue;
29
- }
30
- const token = Symbol(varName.length);
31
- yield ['', undefined, 0, { __linkedToken: token }];
32
- yield `${varName}: ${varName} as typeof `;
33
- yield ['', undefined, 0, { __linkedToken: token }];
34
- yield `${varName},${utils_1.newLine}`;
19
+ const templateUsageVars = new Set([
20
+ ...options.sfc.template?.ast?.components.flatMap(c => [(0, shared_1.camelize)(c), (0, shared_1.capitalize)((0, shared_1.camelize)(c))]) ?? [],
21
+ ...options.templateCodegen?.accessExternalVariables.keys() ?? [],
22
+ ...templateCodegenCtx.accessExternalVariables.keys(),
23
+ ]);
24
+ for (const varName of ctx.bindingNames) {
25
+ if (!templateUsageVars.has(varName)) {
26
+ continue;
35
27
  }
28
+ const token = Symbol(varName.length);
29
+ yield ['', undefined, 0, { __linkedToken: token }];
30
+ yield `${varName}: ${varName} as typeof `;
31
+ yield ['', undefined, 0, { __linkedToken: token }];
32
+ yield `${varName},${utils_1.newLine}`;
36
33
  }
37
- yield `}${utils_1.endOfLine}`; // return {
38
- yield `},${utils_1.newLine}`; // setup() {
34
+ yield `}),${utils_1.newLine}`;
39
35
  if (options.sfc.scriptSetup && options.scriptSetupRanges && !ctx.bypassDefineComponent) {
40
36
  const emitOptionCodes = [...(0, component_1.generateEmitsOption)(options, options.scriptSetupRanges)];
41
37
  yield* emitOptionCodes;
@@ -3,8 +3,6 @@ import type { ScriptRanges } from '../../parsers/scriptRanges';
3
3
  import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
4
4
  import type { Code, Sfc, VueCompilerOptions } from '../../types';
5
5
  import type { TemplateCodegenContext } from '../template/context';
6
- import { type ScriptCodegenContext } from './context';
7
- export * from './context';
8
6
  export interface ScriptCodegenOptions {
9
7
  ts: typeof ts;
10
8
  compilerOptions: ts.CompilerOptions;
@@ -20,5 +18,24 @@ export interface ScriptCodegenOptions {
20
18
  destructuredPropNames: Set<string>;
21
19
  templateRefNames: Set<string>;
22
20
  }
23
- export declare function generateScript(options: ScriptCodegenOptions, ctx: ScriptCodegenContext): Generator<Code>;
21
+ export { generate as generateScript };
22
+ declare function generate(options: ScriptCodegenOptions): {
23
+ codes: Code[];
24
+ generatedTemplate: boolean;
25
+ generatedPropsType: boolean;
26
+ bypassDefineComponent: boolean;
27
+ bindingNames: Set<string>;
28
+ localTypes: {
29
+ generate: (names: string[]) => Generator<string, void, unknown>;
30
+ getUsedNames(): Set<string>;
31
+ readonly PrettifyLocal: string;
32
+ readonly OmitKeepDiscriminatedUnion: string;
33
+ readonly WithDefaults: string;
34
+ readonly WithSlots: string;
35
+ readonly PropsChildren: string;
36
+ readonly TypePropsToOption: string;
37
+ readonly OmitIndexSignature: string;
38
+ };
39
+ inlayHints: import("../inlayHints").InlayHintInfo[];
40
+ };
24
41
  export declare function generateScriptSectionPartiallyEnding(source: string, end: number, mark: string, delimiter?: string): Generator<Code>;
@@ -1,29 +1,23 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.generateScript = generateScript;
3
+ exports.generateScript = generate;
18
4
  exports.generateScriptSectionPartiallyEnding = generateScriptSectionPartiallyEnding;
19
5
  const path = require("path-browserify");
20
6
  const codeFeatures_1 = require("../codeFeatures");
21
7
  const utils_1 = require("../utils");
22
8
  const componentSelf_1 = require("./componentSelf");
9
+ const context_1 = require("./context");
23
10
  const scriptSetup_1 = require("./scriptSetup");
24
11
  const src_1 = require("./src");
25
12
  const template_1 = require("./template");
26
- __exportStar(require("./context"), exports);
13
+ function generate(options) {
14
+ const context = (0, context_1.createScriptCodegenContext)(options);
15
+ const codegen = generateScript(options, context);
16
+ return {
17
+ ...context,
18
+ codes: [...codegen],
19
+ };
20
+ }
27
21
  function* generateScript(options, ctx) {
28
22
  yield* generateGlobalTypesPath(options);
29
23
  if (options.sfc.script?.src) {
@@ -54,7 +54,7 @@ function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
54
54
  emitTypes.push(`typeof __VLS_modelEmit`);
55
55
  }
56
56
  yield `return {} as {${utils_1.newLine}`
57
- + ` props: ${ctx.localTypes.PrettifyLocal}<__VLS_OwnProps & __VLS_PublicProps & Partial<__VLS_InheritedAttrs>> & __VLS_BuiltInPublicProps,${utils_1.newLine}`
57
+ + ` props: ${ctx.localTypes.PrettifyLocal}<__VLS_OwnProps & __VLS_PublicProps & __VLS_InheritedAttrs> & __VLS_BuiltInPublicProps,${utils_1.newLine}`
58
58
  + ` expose(exposed: import('${options.vueCompilerOptions.lib}').ShallowUnwrapRef<${scriptSetupRanges.defineExpose ? 'typeof __VLS_exposed' : '{}'}>): void,${utils_1.newLine}`
59
59
  + ` attrs: any,${utils_1.newLine}`
60
60
  + ` slots: __VLS_Slots,${utils_1.newLine}`
@@ -4,4 +4,3 @@ import type { ScriptCodegenContext } from './context';
4
4
  import type { ScriptCodegenOptions } from './index';
5
5
  export declare function generateTemplate(options: ScriptCodegenOptions, ctx: ScriptCodegenContext): Generator<Code, TemplateCodegenContext>;
6
6
  export declare function generateTemplateDirectives(options: ScriptCodegenOptions): Generator<Code>;
7
- export declare function getTemplateUsageVars(options: ScriptCodegenOptions, ctx: ScriptCodegenContext): Set<string>;
@@ -2,8 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateTemplate = generateTemplate;
4
4
  exports.generateTemplateDirectives = generateTemplateDirectives;
5
- exports.getTemplateUsageVars = getTemplateUsageVars;
6
- const shared_1 = require("../../utils/shared");
7
5
  const codeFeatures_1 = require("../codeFeatures");
8
6
  const modules_1 = require("../style/modules");
9
7
  const scopedClasses_1 = require("../style/scopedClasses");
@@ -45,18 +43,11 @@ function* generateTemplateComponents(options) {
45
43
  if (options.sfc.script && options.scriptRanges?.exportDefault?.componentsOption) {
46
44
  const { componentsOption } = options.scriptRanges.exportDefault;
47
45
  yield `const __VLS_componentsOption = `;
48
- yield [
49
- options.sfc.script.content.slice(componentsOption.start, componentsOption.end),
50
- 'script',
51
- componentsOption.start,
52
- codeFeatures_1.codeFeatures.navigation,
53
- ];
46
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, componentsOption.start, componentsOption.end, codeFeatures_1.codeFeatures.navigation);
54
47
  yield utils_1.endOfLine;
55
48
  types.push(`typeof __VLS_componentsOption`);
56
49
  }
57
- yield `type __VLS_LocalComponents =`;
58
- yield* (0, merge_1.generateIntersectMerge)(types);
59
- yield utils_1.endOfLine;
50
+ yield `type __VLS_LocalComponents = ${types.join(` & `)}${utils_1.endOfLine}`;
60
51
  yield `let __VLS_components!: __VLS_LocalComponents & __VLS_GlobalComponents${utils_1.endOfLine}`;
61
52
  }
62
53
  function* generateTemplateDirectives(options) {
@@ -64,18 +55,11 @@ function* generateTemplateDirectives(options) {
64
55
  if (options.sfc.script && options.scriptRanges?.exportDefault?.directivesOption) {
65
56
  const { directivesOption } = options.scriptRanges.exportDefault;
66
57
  yield `const __VLS_directivesOption = `;
67
- yield [
68
- options.sfc.script.content.slice(directivesOption.start, directivesOption.end),
69
- 'script',
70
- directivesOption.start,
71
- codeFeatures_1.codeFeatures.navigation,
72
- ];
58
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, directivesOption.start, directivesOption.end, codeFeatures_1.codeFeatures.navigation);
73
59
  yield utils_1.endOfLine;
74
60
  types.push(`__VLS_ResolveDirectives<typeof __VLS_directivesOption>`);
75
61
  }
76
- yield `type __VLS_LocalDirectives =`;
77
- yield* (0, merge_1.generateIntersectMerge)(types);
78
- yield utils_1.endOfLine;
62
+ yield `type __VLS_LocalDirectives = ${types.join(` & `)}${utils_1.endOfLine}`;
79
63
  yield `let __VLS_directives!: __VLS_LocalDirectives & __VLS_GlobalDirectives${utils_1.endOfLine}`;
80
64
  }
81
65
  function* generateTemplateBody(options, templateCodegenCtx) {
@@ -101,32 +85,11 @@ function* generateCssVars(options, ctx) {
101
85
  }
102
86
  yield `// CSS variable injection ${utils_1.newLine}`;
103
87
  for (const style of options.sfc.styles) {
104
- for (const cssBind of style.cssVars) {
105
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, style.name, codeFeatures_1.codeFeatures.all, cssBind.text, cssBind.offset);
88
+ for (const binding of style.bindings) {
89
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, style.name, codeFeatures_1.codeFeatures.all, binding.text, binding.offset);
106
90
  yield utils_1.endOfLine;
107
91
  }
108
92
  }
109
93
  yield `// CSS variable injection end ${utils_1.newLine}`;
110
94
  }
111
- function getTemplateUsageVars(options, ctx) {
112
- const usageVars = new Set();
113
- const components = new Set(options.sfc.template?.ast?.components);
114
- if (options.templateCodegen) {
115
- // fix import components unused report
116
- for (const varName of ctx.bindingNames) {
117
- if (components.has(varName) || components.has((0, shared_1.hyphenateTag)(varName))) {
118
- usageVars.add(varName);
119
- }
120
- }
121
- for (const component of components) {
122
- if (component.includes('.')) {
123
- usageVars.add(component.split('.')[0]);
124
- }
125
- }
126
- for (const [varName] of options.templateCodegen.accessExternalVariables) {
127
- usageVars.add(varName);
128
- }
129
- }
130
- return usageVars;
131
- }
132
95
  //# sourceMappingURL=template.js.map
@@ -20,13 +20,7 @@ const styleScopedClasses_1 = require("./styleScopedClasses");
20
20
  const vSlot_1 = require("./vSlot");
21
21
  const colonReg = /:/g;
22
22
  function* generateComponent(options, ctx, node) {
23
- const tagOffsets = [node.loc.start.offset + options.template.content.slice(node.loc.start.offset).indexOf(node.tag)];
24
- if (!node.isSelfClosing && options.template.lang === 'html') {
25
- const endTagOffset = node.loc.start.offset + node.loc.source.lastIndexOf(node.tag);
26
- if (endTagOffset > tagOffsets[0]) {
27
- tagOffsets.push(endTagOffset);
28
- }
29
- }
23
+ const tagOffsets = (0, shared_2.getElementTagOffsets)(node, options.template);
30
24
  const failedPropExps = [];
31
25
  const possibleOriginalNames = getPossibleOriginalComponentNames(node.tag, true);
32
26
  const matchImportName = possibleOriginalNames.find(name => options.scriptSetupImportComponentNames.has(name));
@@ -186,21 +180,13 @@ function* generateComponent(options, ctx, node) {
186
180
  }
187
181
  }
188
182
  function* generateElement(options, ctx, node) {
189
- const startTagOffset = node.loc.start.offset
190
- + options.template.content.slice(node.loc.start.offset).indexOf(node.tag);
191
- const endTagOffset = !node.isSelfClosing && options.template.lang === 'html'
192
- ? node.loc.start.offset + node.loc.source.lastIndexOf(node.tag)
193
- : undefined;
183
+ const [startTagOffset, endTagOffset] = (0, shared_2.getElementTagOffsets)(node, options.template);
194
184
  const failedPropExps = [];
195
- const features = {
196
- ...codeFeatures_1.codeFeatures.semanticWithoutHighlight,
197
- ...codeFeatures_1.codeFeatures.navigationWithoutHighlight,
198
- };
199
185
  yield `__VLS_asFunctionalElement(__VLS_elements`;
200
- yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, startTagOffset, features);
186
+ yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, startTagOffset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
201
187
  if (endTagOffset !== undefined) {
202
188
  yield `, __VLS_elements`;
203
- yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, endTagOffset, features);
189
+ yield* (0, propertyAccess_1.generatePropertyAccess)(options, ctx, node.tag, endTagOffset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
204
190
  }
205
191
  yield `)(`;
206
192
  yield* (0, wrapWith_1.wrapWith)(startTagOffset, startTagOffset + node.tag.length, codeFeatures_1.codeFeatures.verification, `{${utils_1.newLine}`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, node.props, options.vueCompilerOptions.checkUnknownProps, true, failedPropExps), `}`);
@@ -29,7 +29,9 @@ function* generateElementDirectives(options, ctx, node) {
29
29
  || prop.name === 'bind') {
30
30
  continue;
31
31
  }
32
- ctx.accessExternalVariable((0, shared_1.camelize)('v-' + prop.name), prop.loc.start.offset);
32
+ if (!builtInDirectives.has(prop.name)) {
33
+ ctx.accessExternalVariable((0, shared_1.camelize)('v-' + prop.name), prop.loc.start.offset);
34
+ }
33
35
  yield* (0, wrapWith_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, codeFeatures_1.codeFeatures.verification, `__VLS_asFunctionalDirective(`, ...generateIdentifier(options, prop), `)(null!, { ...__VLS_directiveBindingRestFields, `, ...generateArg(options, ctx, prop), ...generateModifiers(options, ctx, prop), ...generateValue(options, ctx, prop), ` }, null!, null!)`);
34
36
  yield utils_1.endOfLine;
35
37
  }
@@ -1,8 +1,6 @@
1
1
  import * as CompilerDOM from '@vue/compiler-dom';
2
2
  import type * as ts from 'typescript';
3
3
  import type { Code, Sfc, VueCompilerOptions } from '../../types';
4
- import type { TemplateCodegenContext } from './context';
5
- export * from './context';
6
4
  export interface TemplateCodegenOptions {
7
5
  ts: typeof ts;
8
6
  compilerOptions: ts.CompilerOptions;
@@ -18,5 +16,67 @@ export interface TemplateCodegenOptions {
18
16
  inheritAttrs: boolean;
19
17
  selfComponentName?: string;
20
18
  }
21
- export declare function generateTemplate(options: TemplateCodegenOptions, ctx: TemplateCodegenContext): Generator<Code>;
19
+ export { generate as generateTemplate };
20
+ declare function generate(options: TemplateCodegenOptions): {
21
+ codes: Code[];
22
+ currentInfo: {
23
+ ignoreError?: boolean;
24
+ expectError?: {
25
+ token: number;
26
+ node: CompilerDOM.CommentNode;
27
+ };
28
+ generic?: {
29
+ content: string;
30
+ offset: number;
31
+ };
32
+ };
33
+ resolveCodeFeatures: (features: import("../../types").VueCodeInformation) => import("../../types").VueCodeInformation;
34
+ inlineTsAsts: Map<string, ts.SourceFile> | undefined;
35
+ inVFor: boolean;
36
+ slots: {
37
+ name: string;
38
+ offset?: number;
39
+ tagRange: [number, number];
40
+ nodeLoc: any;
41
+ propsVar: string;
42
+ }[];
43
+ dynamicSlots: {
44
+ expVar: string;
45
+ propsVar: string;
46
+ }[];
47
+ dollarVars: Set<string>;
48
+ accessExternalVariables: Map<string, Set<number>>;
49
+ blockConditions: string[];
50
+ scopedClasses: {
51
+ source: string;
52
+ className: string;
53
+ offset: number;
54
+ }[];
55
+ emptyClassOffsets: number[];
56
+ inlayHints: import("../inlayHints").InlayHintInfo[];
57
+ bindingAttrLocs: CompilerDOM.SourceLocation[];
58
+ inheritedAttrVars: Set<string>;
59
+ templateRefs: Map<string, {
60
+ typeExp: string;
61
+ offset: number;
62
+ }[]>;
63
+ currentComponent: {
64
+ ctxVar: string;
65
+ used: boolean;
66
+ } | undefined;
67
+ singleRootElTypes: string[];
68
+ singleRootNodes: Set<CompilerDOM.ElementNode | null>;
69
+ addTemplateRef(name: string, typeExp: string, offset: number): void;
70
+ accessExternalVariable(name: string, offset?: number): void;
71
+ hasLocalVariable(name: string): boolean;
72
+ addLocalVariable(name: string): void;
73
+ removeLocalVariable(name: string): void;
74
+ getInternalVariable(): string;
75
+ getHoistVariable(originalVar: string): string;
76
+ generateHoistVariables(): Generator<string, void, unknown>;
77
+ generateConditionGuards(): Generator<string, void, unknown>;
78
+ generateAutoImportCompletion(): Generator<Code>;
79
+ enter(node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode): boolean;
80
+ exit(): Generator<Code>;
81
+ };
22
82
  export declare function forEachElementNode(node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode): Generator<CompilerDOM.ElementNode>;
@@ -1,30 +1,31 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.generateTemplate = generateTemplate;
3
+ exports.generateTemplate = generate;
18
4
  exports.forEachElementNode = forEachElementNode;
19
5
  const CompilerDOM = require("@vue/compiler-dom");
20
6
  const shared_1 = require("../../utils/shared");
21
7
  const codeFeatures_1 = require("../codeFeatures");
22
8
  const utils_1 = require("../utils");
23
9
  const wrapWith_1 = require("../utils/wrapWith");
10
+ const context_1 = require("./context");
24
11
  const objectProperty_1 = require("./objectProperty");
25
12
  const styleScopedClasses_1 = require("./styleScopedClasses");
26
13
  const templateChild_1 = require("./templateChild");
27
- __exportStar(require("./context"), exports);
14
+ function generate(options) {
15
+ const context = (0, context_1.createTemplateCodegenContext)(options, options.template.ast);
16
+ const codegen = generateTemplate(options, context);
17
+ const codes = [];
18
+ for (const code of codegen) {
19
+ if (typeof code === 'object') {
20
+ code[3] = context.resolveCodeFeatures(code[3]);
21
+ }
22
+ codes.push(code);
23
+ }
24
+ return {
25
+ ...context,
26
+ codes,
27
+ };
28
+ }
28
29
  function* generateTemplate(options, ctx) {
29
30
  if (options.slotsAssignName) {
30
31
  ctx.addLocalVariable(options.slotsAssignName);
@@ -83,10 +84,9 @@ function* generateSlots(options, ctx) {
83
84
  return `__VLS_Slots`;
84
85
  }
85
86
  function* generateInheritedAttrs(options, ctx) {
86
- yield `type __VLS_InheritedAttrs = {}`;
87
- for (const varName of ctx.inheritedAttrVars) {
88
- yield ` & typeof ${varName}`;
89
- }
87
+ yield `type __VLS_InheritedAttrs = ${ctx.inheritedAttrVars.size
88
+ ? `Partial<${[...ctx.inheritedAttrVars].map(name => `typeof ${name}`).join(` & `)}>`
89
+ : `{}`}`;
90
90
  yield utils_1.endOfLine;
91
91
  if (ctx.bindingAttrLocs.length) {
92
92
  yield `[`;
@@ -102,7 +102,7 @@ function* generateInheritedAttrs(options, ctx) {
102
102
  }
103
103
  yield `]${utils_1.endOfLine}`;
104
104
  }
105
- return `import('${options.vueCompilerOptions.lib}').ComponentPublicInstance['$attrs'] & Partial<__VLS_InheritedAttrs>`;
105
+ return `import('${options.vueCompilerOptions.lib}').ComponentPublicInstance['$attrs'] & __VLS_InheritedAttrs`;
106
106
  }
107
107
  function* generateTemplateRefs(options, ctx) {
108
108
  yield `type __VLS_TemplateRefs = {}`;
@@ -140,8 +140,13 @@ function walkIdentifiers(ts, node, ast, cb, ctx, blockVars, isRoot = false) {
140
140
  ctx.addLocalVariable(name);
141
141
  blockVars.push(name);
142
142
  }
143
- if (node.initializer) {
144
- walkIdentifiers(ts, node.initializer, ast, cb, ctx, blockVars);
143
+ walkIdentifiersInBinding(ts, node, ast, cb, ctx, blockVars);
144
+ }
145
+ else if (ts.isArrayBindingPattern(node) || ts.isObjectBindingPattern(node)) {
146
+ for (const element of node.elements) {
147
+ if (ts.isBindingElement(element)) {
148
+ walkIdentifiersInBinding(ts, element, ast, cb, ctx, blockVars);
149
+ }
145
150
  }
146
151
  }
147
152
  else if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {
@@ -194,13 +199,22 @@ function walkIdentifiers(ts, node, ast, cb, ctx, blockVars, isRoot = false) {
194
199
  }
195
200
  }
196
201
  }
202
+ function walkIdentifiersInBinding(ts, node, ast, cb, ctx, blockVars) {
203
+ if ('type' in node && node.type) {
204
+ walkIdentifiersInTypeNode(ts, node.type, cb);
205
+ }
206
+ if (!ts.isIdentifier(node.name)) {
207
+ walkIdentifiers(ts, node.name, ast, cb, ctx, blockVars);
208
+ }
209
+ if (node.initializer) {
210
+ walkIdentifiers(ts, node.initializer, ast, cb, ctx, blockVars);
211
+ }
212
+ }
197
213
  function walkIdentifiersInFunction(ts, node, ast, cb, ctx) {
198
214
  const functionArgs = [];
199
215
  for (const param of node.parameters) {
200
216
  functionArgs.push(...(0, collectBindings_1.collectBindingNames)(ts, param.name, ast));
201
- if (param.type) {
202
- walkIdentifiersInTypeNode(ts, param.type, cb);
203
- }
217
+ walkIdentifiersInBinding(ts, param, ast, cb, ctx, functionArgs);
204
218
  }
205
219
  for (const varName of functionArgs) {
206
220
  ctx.addLocalVariable(varName);
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateSlotOutlet = generateSlotOutlet;
4
4
  const CompilerDOM = require("@vue/compiler-dom");
5
+ const shared_1 = require("../../utils/shared");
5
6
  const codeFeatures_1 = require("../codeFeatures");
6
7
  const inlayHints_1 = require("../inlayHints");
7
8
  const utils_1 = require("../utils");
@@ -11,8 +12,7 @@ const elementProps_1 = require("./elementProps");
11
12
  const interpolation_1 = require("./interpolation");
12
13
  const propertyAccess_1 = require("./propertyAccess");
13
14
  function* generateSlotOutlet(options, ctx, node) {
14
- const startTagOffset = node.loc.start.offset
15
- + options.template.content.slice(node.loc.start.offset).indexOf(node.tag);
15
+ const [startTagOffset] = (0, shared_1.getElementTagOffsets)(node, options.template);
16
16
  const startTagEndOffset = startTagOffset + node.tag.length;
17
17
  const propsVar = ctx.getInternalVariable();
18
18
  const nameProp = node.props.find(prop => {