@vue/language-core 3.1.5 → 3.1.7

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 (106) hide show
  1. package/index.d.ts +2 -1
  2. package/index.js +3 -2
  3. package/lib/codegen/codeFeatures.d.ts +5 -9
  4. package/lib/codegen/codeFeatures.js +5 -5
  5. package/lib/codegen/globalTypes.js +12 -18
  6. package/lib/codegen/localTypes.d.ts +1 -1
  7. package/lib/codegen/localTypes.js +6 -6
  8. package/lib/codegen/names.d.ts +30 -0
  9. package/lib/codegen/names.js +34 -0
  10. package/lib/codegen/script/component.js +45 -54
  11. package/lib/codegen/script/context.d.ts +2 -5
  12. package/lib/codegen/script/context.js +1 -7
  13. package/lib/codegen/script/index.d.ts +10 -12
  14. package/lib/codegen/script/index.js +74 -73
  15. package/lib/codegen/script/scriptSetup.d.ts +3 -2
  16. package/lib/codegen/script/scriptSetup.js +209 -283
  17. package/lib/codegen/script/src.js +9 -3
  18. package/lib/codegen/script/template.js +64 -108
  19. package/lib/codegen/style/common.d.ts +3 -0
  20. package/lib/codegen/style/common.js +43 -0
  21. package/lib/codegen/style/index.d.ts +63 -0
  22. package/lib/codegen/style/index.js +38 -0
  23. package/lib/codegen/style/modules.d.ts +3 -2
  24. package/lib/codegen/style/modules.js +12 -11
  25. package/lib/codegen/style/scopedClasses.d.ts +2 -3
  26. package/lib/codegen/style/scopedClasses.js +23 -21
  27. package/lib/codegen/template/context.d.ts +7 -16
  28. package/lib/codegen/template/context.js +81 -93
  29. package/lib/codegen/template/element.js +153 -55
  30. package/lib/codegen/template/elementDirectives.js +32 -12
  31. package/lib/codegen/template/elementEvents.js +27 -28
  32. package/lib/codegen/template/elementProps.d.ts +2 -2
  33. package/lib/codegen/template/elementProps.js +49 -23
  34. package/lib/codegen/template/index.d.ts +8 -19
  35. package/lib/codegen/template/index.js +85 -80
  36. package/lib/codegen/template/interpolation.d.ts +3 -3
  37. package/lib/codegen/template/interpolation.js +90 -136
  38. package/lib/codegen/template/objectProperty.js +8 -4
  39. package/lib/codegen/template/propertyAccess.d.ts +1 -1
  40. package/lib/codegen/template/propertyAccess.js +5 -7
  41. package/lib/codegen/template/slotOutlet.js +25 -8
  42. package/lib/codegen/template/styleScopedClasses.d.ts +3 -6
  43. package/lib/codegen/template/styleScopedClasses.js +23 -149
  44. package/lib/codegen/template/templateChild.d.ts +0 -1
  45. package/lib/codegen/template/templateChild.js +11 -68
  46. package/lib/codegen/template/vFor.js +10 -13
  47. package/lib/codegen/template/vIf.js +5 -3
  48. package/lib/codegen/template/vSlot.js +20 -15
  49. package/lib/codegen/utils/boundary.d.ts +3 -0
  50. package/lib/codegen/utils/boundary.js +13 -0
  51. package/lib/codegen/utils/camelized.js +3 -3
  52. package/lib/codegen/utils/escaped.js +4 -2
  53. package/lib/codegen/utils/index.d.ts +4 -5
  54. package/lib/codegen/utils/index.js +49 -21
  55. package/lib/codegen/utils/merge.d.ts +2 -2
  56. package/lib/codegen/utils/merge.js +9 -9
  57. package/lib/codegen/utils/stringLiteralKey.js +6 -3
  58. package/lib/codegen/utils/transform.d.ts +8 -0
  59. package/lib/codegen/utils/transform.js +27 -0
  60. package/lib/codegen/utils/unicode.js +4 -2
  61. package/lib/compilerOptions.d.ts +5 -2
  62. package/lib/compilerOptions.js +67 -44
  63. package/lib/languagePlugin.d.ts +1 -1
  64. package/lib/languagePlugin.js +5 -6
  65. package/lib/parsers/scriptRanges.d.ts +4 -8
  66. package/lib/parsers/scriptRanges.js +3 -2
  67. package/lib/parsers/scriptSetupRanges.d.ts +2 -6
  68. package/lib/parsers/scriptSetupRanges.js +3 -2
  69. package/lib/parsers/utils.d.ts +4 -6
  70. package/lib/parsers/utils.js +22 -27
  71. package/lib/plugins/vue-template-inline-css.js +2 -6
  72. package/lib/plugins/vue-template-inline-ts.js +12 -14
  73. package/lib/plugins/vue-tsx.d.ts +14 -32
  74. package/lib/plugins/vue-tsx.js +114 -72
  75. package/lib/plugins.js +1 -1
  76. package/lib/types.d.ts +5 -4
  77. package/lib/utils/parseSfc.js +7 -3
  78. package/lib/utils/shared.d.ts +1 -1
  79. package/lib/utils/shared.js +7 -6
  80. package/lib/utils/signals.d.ts +2 -2
  81. package/lib/utils/signals.js +8 -6
  82. package/lib/virtualCode/embeddedCodes.d.ts +12 -0
  83. package/lib/virtualCode/embeddedCodes.js +249 -0
  84. package/lib/{virtualFile/vueFile.d.ts → virtualCode/index.d.ts} +9 -9
  85. package/lib/virtualCode/index.js +81 -0
  86. package/lib/virtualCode/ir.d.ts +4 -0
  87. package/lib/{virtualFile/computedSfc.js → virtualCode/ir.js} +59 -94
  88. package/lib/virtualCode/normalize.d.ts +2 -0
  89. package/lib/virtualCode/normalize.js +170 -0
  90. package/package.json +4 -4
  91. package/lib/codegen/style/classProperty.d.ts +0 -2
  92. package/lib/codegen/style/classProperty.js +0 -18
  93. package/lib/codegen/style/imports.d.ts +0 -2
  94. package/lib/codegen/style/imports.js +0 -27
  95. package/lib/codegen/template/elementChildren.d.ts +0 -5
  96. package/lib/codegen/template/elementChildren.js +0 -12
  97. package/lib/codegen/utils/wrapWith.d.ts +0 -2
  98. package/lib/codegen/utils/wrapWith.js +0 -15
  99. package/lib/virtualFile/computedEmbeddedCodes.d.ts +0 -4
  100. package/lib/virtualFile/computedEmbeddedCodes.js +0 -262
  101. package/lib/virtualFile/computedSfc.d.ts +0 -6
  102. package/lib/virtualFile/computedVueSfc.d.ts +0 -4
  103. package/lib/virtualFile/computedVueSfc.js +0 -41
  104. package/lib/virtualFile/embeddedFile.d.ts +0 -11
  105. package/lib/virtualFile/embeddedFile.js +0 -14
  106. package/lib/virtualFile/vueFile.js +0 -49
@@ -5,10 +5,11 @@ exports.generateModifiers = generateModifiers;
5
5
  const CompilerDOM = require("@vue/compiler-dom");
6
6
  const shared_1 = require("@vue/shared");
7
7
  const codeFeatures_1 = require("../codeFeatures");
8
+ const names = require("../names");
8
9
  const utils_1 = require("../utils");
10
+ const boundary_1 = require("../utils/boundary");
9
11
  const camelized_1 = require("../utils/camelized");
10
12
  const stringLiteralKey_1 = require("../utils/stringLiteralKey");
11
- const wrapWith_1 = require("../utils/wrapWith");
12
13
  const elementProps_1 = require("./elementProps");
13
14
  const interpolation_1 = require("./interpolation");
14
15
  const objectProperty_1 = require("./objectProperty");
@@ -29,19 +30,32 @@ function* generateElementDirectives(options, ctx, node) {
29
30
  || prop.name === 'bind') {
30
31
  continue;
31
32
  }
32
- if (!builtInDirectives.has(prop.name)) {
33
- ctx.accessExternalVariable((0, shared_1.camelize)('v-' + prop.name), prop.loc.start.offset);
34
- }
35
- yield* (0, wrapWith_1.wrapWith)('template', 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!)`);
33
+ const token = yield* (0, boundary_1.startBoundary)('template', prop.loc.start.offset, codeFeatures_1.codeFeatures.verification);
34
+ yield `__VLS_asFunctionalDirective(`;
35
+ yield* generateIdentifier(options, ctx, prop);
36
+ yield `)(null!, { ...__VLS_directiveBindingRestFields, `;
37
+ yield* generateArg(options, ctx, prop);
38
+ yield* generateModifiers(options, ctx, prop);
39
+ yield* generateValue(options, ctx, prop);
40
+ yield ` }, null!, null!)`;
41
+ yield (0, boundary_1.endBoundary)(token, prop.loc.end.offset);
36
42
  yield utils_1.endOfLine;
37
43
  }
38
44
  }
39
- function* generateIdentifier(options, prop) {
45
+ function* generateIdentifier(options, ctx, prop) {
40
46
  const rawName = 'v-' + prop.name;
41
- yield* (0, wrapWith_1.wrapWith)('template', prop.loc.start.offset, prop.loc.start.offset + rawName.length, codeFeatures_1.codeFeatures.verification, `__VLS_directives.`, ...(0, camelized_1.generateCamelized)(rawName, 'template', prop.loc.start.offset, {
47
+ const startOffset = prop.loc.start.offset;
48
+ const token = yield* (0, boundary_1.startBoundary)('template', startOffset, codeFeatures_1.codeFeatures.verification);
49
+ yield names.directives;
50
+ yield `.`;
51
+ yield* (0, camelized_1.generateCamelized)(rawName, 'template', prop.loc.start.offset, {
42
52
  ...codeFeatures_1.codeFeatures.withoutHighlightAndCompletion,
43
53
  verification: options.vueCompilerOptions.checkUnknownDirectives && !builtInDirectives.has(prop.name),
44
- }));
54
+ });
55
+ if (!builtInDirectives.has(prop.name)) {
56
+ ctx.recordComponentAccess('template', (0, shared_1.camelize)(rawName), prop.loc.start.offset);
57
+ }
58
+ yield (0, boundary_1.endBoundary)(token, startOffset + rawName.length);
45
59
  }
46
60
  function* generateArg(options, ctx, prop) {
47
61
  const { arg } = prop;
@@ -49,13 +63,15 @@ function* generateArg(options, ctx, prop) {
49
63
  return;
50
64
  }
51
65
  const startOffset = arg.loc.start.offset + arg.loc.source.indexOf(arg.content);
52
- yield* (0, wrapWith_1.wrapWith)('template', startOffset, startOffset + arg.content.length, codeFeatures_1.codeFeatures.verification, `arg`);
66
+ const token = yield* (0, boundary_1.startBoundary)('template', startOffset, codeFeatures_1.codeFeatures.verification);
67
+ yield `arg`;
68
+ yield (0, boundary_1.endBoundary)(token, startOffset + arg.content.length);
53
69
  yield `: `;
54
70
  if (arg.isStatic) {
55
71
  yield* (0, stringLiteralKey_1.generateStringLiteralKey)(arg.content, startOffset, codeFeatures_1.codeFeatures.all);
56
72
  }
57
73
  else {
58
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', codeFeatures_1.codeFeatures.all, arg.content, startOffset, `(`, `)`);
74
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, arg.content, startOffset, `(`, `)`);
59
75
  }
60
76
  yield `, `;
61
77
  }
@@ -66,7 +82,9 @@ function* generateModifiers(options, ctx, prop, propertyName = 'modifiers') {
66
82
  }
67
83
  const startOffset = modifiers[0].loc.start.offset - 1;
68
84
  const endOffset = modifiers.at(-1).loc.end.offset;
69
- yield* (0, wrapWith_1.wrapWith)('template', startOffset, endOffset, codeFeatures_1.codeFeatures.verification, propertyName);
85
+ const token = yield* (0, boundary_1.startBoundary)('template', startOffset, codeFeatures_1.codeFeatures.verification);
86
+ yield propertyName;
87
+ yield (0, boundary_1.endBoundary)(token, endOffset);
70
88
  yield `: { `;
71
89
  for (const mod of modifiers) {
72
90
  yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, mod.content, mod.loc.start.offset, codeFeatures_1.codeFeatures.withoutHighlight);
@@ -79,7 +97,9 @@ function* generateValue(options, ctx, prop) {
79
97
  if (exp?.type !== CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
80
98
  return;
81
99
  }
82
- yield* (0, wrapWith_1.wrapWith)('template', exp.loc.start.offset, exp.loc.end.offset, codeFeatures_1.codeFeatures.verification, `value`);
100
+ const token = yield* (0, boundary_1.startBoundary)('template', exp.loc.start.offset, codeFeatures_1.codeFeatures.verification);
101
+ yield `value`;
102
+ yield (0, boundary_1.endBoundary)(token, exp.loc.end.offset);
83
103
  yield `: `;
84
104
  yield* (0, elementProps_1.generatePropExp)(options, ctx, prop, exp);
85
105
  }
@@ -9,8 +9,8 @@ const CompilerDOM = require("@vue/compiler-dom");
9
9
  const shared_1 = require("@vue/shared");
10
10
  const codeFeatures_1 = require("../codeFeatures");
11
11
  const utils_1 = require("../utils");
12
+ const boundary_1 = require("../utils/boundary");
12
13
  const camelized_1 = require("../utils/camelized");
13
- const wrapWith_1 = require("../utils/wrapWith");
14
14
  const interpolation_1 = require("./interpolation");
15
15
  function* generateElementEvents(options, ctx, node, componentOriginalVar) {
16
16
  let emitsVar;
@@ -74,46 +74,45 @@ function* generateEventArg(options, name, start, directive = 'on', features) {
74
74
  name = (0, shared_1.capitalize)(name);
75
75
  }
76
76
  if (utils_1.identifierRegex.test((0, shared_1.camelize)(name))) {
77
- yield ['', 'template', start, features];
77
+ const token = yield* (0, boundary_1.startBoundary)('template', start, features);
78
78
  yield directive;
79
- yield* (0, camelized_1.generateCamelized)(name, 'template', start, utils_1.combineLastMapping);
79
+ yield* (0, camelized_1.generateCamelized)(name, 'template', start, { __combineToken: token });
80
80
  }
81
81
  else {
82
- yield* (0, wrapWith_1.wrapWith)('template', start, start + name.length, features, `'`, directive, ...(0, camelized_1.generateCamelized)(name, 'template', start, utils_1.combineLastMapping), `'`);
82
+ const token = yield* (0, boundary_1.startBoundary)('template', start, features);
83
+ yield `'`;
84
+ yield directive;
85
+ yield* (0, camelized_1.generateCamelized)(name, 'template', start, { __combineToken: token });
86
+ yield `'`;
87
+ yield (0, boundary_1.endBoundary)(token, start + name.length);
83
88
  }
84
89
  }
85
90
  function* generateEventExpression(options, ctx, prop) {
86
91
  if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
87
- let isFirstMapping = true;
88
- const ast = (0, utils_1.createTsAst)(options.ts, ctx.inlineTsAsts, prop.exp.content);
92
+ const ast = (0, utils_1.getTypeScriptAST)(options.ts, options.template, prop.exp.content);
89
93
  const isCompound = isCompoundExpression(options.ts, ast);
90
- const interpolation = (0, interpolation_1.generateInterpolation)(options, ctx, 'template', offset => {
91
- if (isCompound && isFirstMapping) {
92
- isFirstMapping = false;
93
- ctx.inlayHints.push({
94
- blockName: 'template',
95
- offset,
96
- setting: 'vue.inlayHints.inlineHandlerLeading',
97
- label: '$event =>',
98
- paddingRight: true,
99
- tooltip: [
100
- '`$event` is a hidden parameter, you can use it in this callback.',
101
- 'To hide this hint, set `vue.inlayHints.inlineHandlerLeading` to `false` in IDE settings.',
102
- '[More info](https://github.com/vuejs/language-tools/issues/2445#issuecomment-1444771420)',
103
- ].join('\n\n'),
104
- });
105
- }
106
- return codeFeatures_1.codeFeatures.all;
107
- }, prop.exp.content, prop.exp.loc.start.offset, isCompound ? `` : `(`, isCompound ? `` : `)`);
94
+ const interpolation = (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, prop.exp.content, prop.exp.loc.start.offset, isCompound ? `` : `(`, isCompound ? `` : `)`);
108
95
  if (isCompound) {
109
96
  yield `(...[$event]) => {${utils_1.newLine}`;
110
- ctx.addLocalVariable('$event');
97
+ const endScope = ctx.startScope();
98
+ ctx.declare('$event');
111
99
  yield* ctx.generateConditionGuards();
112
100
  yield* interpolation;
113
101
  yield utils_1.endOfLine;
114
- ctx.removeLocalVariable('$event');
115
- yield* ctx.generateAutoImportCompletion();
102
+ yield* endScope();
116
103
  yield `}`;
104
+ ctx.inlayHints.push({
105
+ blockName: 'template',
106
+ offset: prop.exp.loc.start.offset,
107
+ setting: 'vue.inlayHints.inlineHandlerLeading',
108
+ label: '$event =>',
109
+ paddingRight: true,
110
+ tooltip: [
111
+ '`$event` is a hidden parameter, you can use it in this callback.',
112
+ 'To hide this hint, set `vue.inlayHints.inlineHandlerLeading` to `false` in IDE settings.',
113
+ '[More info](https://github.com/vuejs/language-tools/issues/2445#issuecomment-1444771420)',
114
+ ].join('\n\n'),
115
+ });
117
116
  }
118
117
  else {
119
118
  yield* interpolation;
@@ -127,7 +126,7 @@ function* generateModelEventExpression(options, ctx, prop) {
127
126
  if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
128
127
  yield `(...[$event]) => {${utils_1.newLine}`;
129
128
  yield* ctx.generateConditionGuards();
130
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', codeFeatures_1.codeFeatures.verification, prop.exp.content, prop.exp.loc.start.offset);
129
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.verification, prop.exp.content, prop.exp.loc.start.offset);
131
130
  yield ` = $event${utils_1.endOfLine}`;
132
131
  yield `}`;
133
132
  }
@@ -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 FailedPropExpression {
5
+ export interface FailGeneratedExpression {
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, failedPropExps?: FailedPropExpression[]): Generator<Code>;
10
+ export declare function generateElementProps(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, props: CompilerDOM.ElementNode['props'], strictPropsCheck: boolean, failGeneratedExpressions?: FailGeneratedExpression[]): Generator<Code>;
11
11
  export declare function generatePropExp(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode, exp: CompilerDOM.SimpleExpressionNode | undefined): Generator<Code>;
@@ -8,15 +8,16 @@ const picomatch_1 = require("picomatch");
8
8
  const shared_2 = require("../../utils/shared");
9
9
  const codeFeatures_1 = require("../codeFeatures");
10
10
  const inlayHints_1 = require("../inlayHints");
11
+ const names = require("../names");
11
12
  const utils_1 = require("../utils");
13
+ const boundary_1 = require("../utils/boundary");
12
14
  const camelized_1 = require("../utils/camelized");
13
15
  const unicode_1 = require("../utils/unicode");
14
- const wrapWith_1 = require("../utils/wrapWith");
15
16
  const elementDirectives_1 = require("./elementDirectives");
16
17
  const elementEvents_1 = require("./elementEvents");
17
18
  const interpolation_1 = require("./interpolation");
18
19
  const objectProperty_1 = require("./objectProperty");
19
- function* generateElementProps(options, ctx, node, props, strictPropsCheck, failedPropExps) {
20
+ function* generateElementProps(options, ctx, node, props, strictPropsCheck, failGeneratedExpressions) {
20
21
  const isComponent = node.tagType === CompilerDOM.ElementTypes.COMPONENT;
21
22
  for (const prop of props) {
22
23
  if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
@@ -40,12 +41,12 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, fail
40
41
  && prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
41
42
  && prop.arg.loc.source.startsWith('[')
42
43
  && prop.arg.loc.source.endsWith(']')) {
43
- failedPropExps?.push({ node: prop.arg, prefix: `(`, suffix: `)` });
44
- failedPropExps?.push({ node: prop.exp, prefix: `() => {`, suffix: `}` });
44
+ failGeneratedExpressions?.push({ node: prop.arg, prefix: `(`, suffix: `)` });
45
+ failGeneratedExpressions?.push({ node: prop.exp, prefix: `() => {`, suffix: `}` });
45
46
  }
46
47
  else if (!prop.arg
47
48
  && prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
48
- failedPropExps?.push({ node: prop.exp, prefix: `(`, suffix: `)` });
49
+ failGeneratedExpressions?.push({ node: prop.exp, prefix: `(`, suffix: `)` });
49
50
  }
50
51
  }
51
52
  }
@@ -66,7 +67,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, fail
66
67
  if (propName === undefined
67
68
  || options.vueCompilerOptions.dataAttributes.some(pattern => (0, picomatch_1.isMatch)(propName, pattern))) {
68
69
  if (prop.exp && prop.exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY) {
69
- failedPropExps?.push({ node: prop.exp, prefix: `(`, suffix: `)` });
70
+ failGeneratedExpressions?.push({ node: prop.exp, prefix: `(`, suffix: `)` });
70
71
  }
71
72
  continue;
72
73
  }
@@ -80,9 +81,21 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, fail
80
81
  if (shouldSpread) {
81
82
  yield `...{ `;
82
83
  }
83
- yield* (0, wrapWith_1.wrapWith)('template', prop.loc.start.offset, prop.loc.end.offset, codeFeatures_1.codeFeatures.verification, ...(prop.arg
84
- ? (0, objectProperty_1.generateObjectProperty)(options, ctx, propName, prop.arg.loc.start.offset, features, shouldCamelize)
85
- : (0, wrapWith_1.wrapWith)('template', prop.loc.start.offset, prop.loc.start.offset + 'v-model'.length, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion, propName)), `: `, ...(0, wrapWith_1.wrapWith)('template', prop.arg?.loc.start.offset ?? prop.loc.start.offset, prop.arg?.loc.end.offset ?? prop.loc.end.offset, codeFeatures_1.codeFeatures.verification, ...generatePropExp(options, ctx, prop, prop.exp)));
84
+ const token = yield* (0, boundary_1.startBoundary)('template', prop.loc.start.offset, codeFeatures_1.codeFeatures.verification);
85
+ if (prop.arg) {
86
+ yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, propName, prop.arg.loc.start.offset, features, shouldCamelize);
87
+ }
88
+ else {
89
+ const token2 = yield* (0, boundary_1.startBoundary)('template', prop.loc.start.offset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
90
+ yield propName;
91
+ yield (0, boundary_1.endBoundary)(token2, prop.loc.start.offset + 'v-model'.length);
92
+ }
93
+ yield `: `;
94
+ const argLoc = prop.arg?.loc ?? prop.loc;
95
+ const token3 = yield* (0, boundary_1.startBoundary)('template', argLoc.start.offset, codeFeatures_1.codeFeatures.verification);
96
+ yield* generatePropExp(options, ctx, prop, prop.exp);
97
+ yield (0, boundary_1.endBoundary)(token3, argLoc.end.offset);
98
+ yield (0, boundary_1.endBoundary)(token, prop.loc.end.offset);
86
99
  if (shouldSpread) {
87
100
  yield ` }`;
88
101
  }
@@ -107,9 +120,19 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, fail
107
120
  if (shouldSpread) {
108
121
  yield `...{ `;
109
122
  }
110
- yield* (0, wrapWith_1.wrapWith)('template', prop.loc.start.offset, prop.loc.end.offset, codeFeatures_1.codeFeatures.verification, ...(0, objectProperty_1.generateObjectProperty)(options, ctx, prop.name, prop.loc.start.offset, features, shouldCamelize), `: `, ...(prop.value
111
- ? generateAttrValue(prop.value, codeFeatures_1.codeFeatures.withoutNavigation)
112
- : [`true`]));
123
+ const token = yield* (0, boundary_1.startBoundary)('template', prop.loc.start.offset, codeFeatures_1.codeFeatures.verification);
124
+ yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, prop.name, prop.loc.start.offset, features, shouldCamelize);
125
+ yield `: `;
126
+ if (prop.name === 'style') {
127
+ yield `{}`;
128
+ }
129
+ else if (prop.value) {
130
+ yield* generateAttrValue(prop.value, codeFeatures_1.codeFeatures.withoutNavigation);
131
+ }
132
+ else {
133
+ yield `true`;
134
+ }
135
+ yield (0, boundary_1.endBoundary)(token, prop.loc.end.offset);
113
136
  if (shouldSpread) {
114
137
  yield ` }`;
115
138
  }
@@ -119,10 +142,13 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, fail
119
142
  && !prop.arg
120
143
  && prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
121
144
  if (prop.exp.loc.source === '$attrs') {
122
- ctx.bindingAttrLocs.push(prop.exp.loc);
145
+ failGeneratedExpressions?.push({ node: prop.exp, prefix: `(`, suffix: `)` });
123
146
  }
124
147
  else {
125
- yield* (0, wrapWith_1.wrapWith)('template', prop.exp.loc.start.offset, prop.exp.loc.end.offset, codeFeatures_1.codeFeatures.verification, `...`, ...generatePropExp(options, ctx, prop, prop.exp));
148
+ const token = yield* (0, boundary_1.startBoundary)('template', prop.exp.loc.start.offset, codeFeatures_1.codeFeatures.verification);
149
+ yield `...`;
150
+ yield* generatePropExp(options, ctx, prop, prop.exp);
151
+ yield (0, boundary_1.endBoundary)(token, prop.exp.loc.end.offset);
126
152
  yield `,${utils_1.newLine}`;
127
153
  }
128
154
  }
@@ -133,23 +159,23 @@ function* generatePropExp(options, ctx, prop, exp) {
133
159
  yield `{}`;
134
160
  }
135
161
  else if (prop.arg?.loc.start.offset !== prop.exp?.loc.start.offset) {
136
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', codeFeatures_1.codeFeatures.all, exp.loc.source, exp.loc.start.offset, `(`, `)`);
162
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, options.template, codeFeatures_1.codeFeatures.all, exp.loc.source, exp.loc.start.offset, `(`, `)`);
137
163
  }
138
164
  else {
139
165
  const propVariableName = (0, shared_1.camelize)(exp.loc.source);
140
166
  if (utils_1.identifierRegex.test(propVariableName)) {
141
167
  const codes = (0, camelized_1.generateCamelized)(exp.loc.source, 'template', exp.loc.start.offset, codeFeatures_1.codeFeatures.withoutHighlightAndCompletion);
142
- if (options.destructuredPropNames.has(propVariableName) || ctx.hasLocalVariable(propVariableName)) {
168
+ if (ctx.scopes.some(scope => scope.has(propVariableName))) {
143
169
  yield* codes;
144
170
  }
145
- else if (options.templateRefNames.has(propVariableName)) {
146
- yield `__VLS_unref(`;
171
+ else if (options.setupRefs.has(propVariableName)) {
147
172
  yield* codes;
148
- yield `)`;
173
+ yield `.value`;
149
174
  }
150
175
  else {
151
- ctx.accessExternalVariable(propVariableName, exp.loc.start.offset);
152
- yield `__VLS_ctx.`;
176
+ ctx.recordComponentAccess('template', propVariableName, exp.loc.start.offset);
177
+ yield names.ctx;
178
+ yield `.`;
153
179
  yield* codes;
154
180
  }
155
181
  ctx.inlayHints.push((0, inlayHints_1.createVBindShorthandInlayHintInfo)(prop.loc, propVariableName));
@@ -158,9 +184,9 @@ function* generatePropExp(options, ctx, prop, exp) {
158
184
  }
159
185
  function* generateAttrValue(node, features) {
160
186
  const quote = node.loc.source.startsWith("'") ? "'" : '"';
161
- const offset = (0, shared_2.getAttributeValueOffset)(node);
187
+ const [content, offset] = (0, shared_2.normalizeAttributeValue)(node);
162
188
  yield quote;
163
- yield* (0, unicode_1.generateUnicode)(node.content, offset, features);
189
+ yield* (0, unicode_1.generateUnicode)(content, offset, features);
164
190
  yield quote;
165
191
  }
166
192
  function getShouldCamelize(options, prop, propName) {
@@ -2,13 +2,10 @@ import type * as ts from 'typescript';
2
2
  import type { Code, Sfc, VueCompilerOptions } from '../../types';
3
3
  export interface TemplateCodegenOptions {
4
4
  ts: typeof ts;
5
- compilerOptions: ts.CompilerOptions;
6
5
  vueCompilerOptions: VueCompilerOptions;
7
6
  template: NonNullable<Sfc['template']>;
8
- scriptSetupBindingNames: Set<string>;
9
- scriptSetupImportComponentNames: Set<string>;
10
- destructuredPropNames: Set<string>;
11
- templateRefNames: Set<string>;
7
+ setupRefs: Set<string>;
8
+ setupConsts: Set<string>;
12
9
  hasDefineSlots?: boolean;
13
10
  propsAssignName?: string;
14
11
  slotsAssignName?: string;
@@ -18,6 +15,7 @@ export interface TemplateCodegenOptions {
18
15
  export { generate as generateTemplate };
19
16
  declare function generate(options: TemplateCodegenOptions): {
20
17
  codes: Code[];
18
+ generatedTypes: Set<string>;
21
19
  currentInfo: {
22
20
  ignoreError?: boolean;
23
21
  expectError?: {
@@ -30,7 +28,6 @@ declare function generate(options: TemplateCodegenOptions): {
30
28
  };
31
29
  };
32
30
  resolveCodeFeatures: (features: import("../../types").VueCodeInformation) => import("../../types").VueCodeInformation;
33
- inlineTsAsts: Map<string, ts.SourceFile> | undefined;
34
31
  inVFor: boolean;
35
32
  slots: {
36
33
  name: string;
@@ -44,16 +41,9 @@ declare function generate(options: TemplateCodegenOptions): {
44
41
  propsVar: string;
45
42
  }[];
46
43
  dollarVars: Set<string>;
47
- accessExternalVariables: Map<string, Set<number>>;
44
+ componentAccessMap: Map<string, Map<string, Set<number>>>;
48
45
  blockConditions: string[];
49
- scopedClasses: {
50
- source: string;
51
- className: string;
52
- offset: number;
53
- }[];
54
- emptyClassOffsets: number[];
55
46
  inlayHints: import("../inlayHints").InlayHintInfo[];
56
- bindingAttrLocs: import("@vue/compiler-dom").SourceLocation[];
57
47
  inheritedAttrVars: Set<string>;
58
48
  templateRefs: Map<string, {
59
49
  typeExp: string;
@@ -66,15 +56,14 @@ declare function generate(options: TemplateCodegenOptions): {
66
56
  singleRootElTypes: Set<string>;
67
57
  singleRootNodes: Set<import("@vue/compiler-dom").ElementNode | null>;
68
58
  addTemplateRef(name: string, typeExp: string, offset: number): void;
69
- accessExternalVariable(name: string, offset?: number): void;
70
- hasLocalVariable(name: string): boolean;
71
- addLocalVariable(name: string): void;
72
- removeLocalVariable(name: string): void;
59
+ recordComponentAccess(source: string, name: string, offset?: number): void;
60
+ scopes: Set<string>[];
61
+ declare(...varNames: string[]): void;
62
+ startScope(): () => Generator<Code, any, any>;
73
63
  getInternalVariable(): string;
74
64
  getHoistVariable(originalVar: string): string;
75
65
  generateHoistVariables(): Generator<string, void, unknown>;
76
66
  generateConditionGuards(): Generator<string, void, unknown>;
77
- generateAutoImportCompletion(): Generator<Code>;
78
67
  enter(node: import("@vue/compiler-dom").RootNode | import("@vue/compiler-dom").TemplateChildNode | import("@vue/compiler-dom").SimpleExpressionNode): boolean;
79
68
  exit(): Generator<Code>;
80
69
  };
@@ -2,108 +2,116 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateTemplate = generate;
4
4
  const codeFeatures_1 = require("../codeFeatures");
5
+ const names = require("../names");
5
6
  const utils_1 = require("../utils");
6
- const wrapWith_1 = require("../utils/wrapWith");
7
+ const boundary_1 = require("../utils/boundary");
7
8
  const context_1 = require("./context");
8
9
  const objectProperty_1 = require("./objectProperty");
9
- const styleScopedClasses_1 = require("./styleScopedClasses");
10
10
  const templateChild_1 = require("./templateChild");
11
11
  function generate(options) {
12
- const context = (0, context_1.createTemplateCodegenContext)(options, options.template.ast);
13
- const codegen = generateTemplate(options, context);
12
+ const ctx = (0, context_1.createTemplateCodegenContext)();
13
+ const codeGenerator = generateWorker(options, ctx);
14
14
  const codes = [];
15
- for (const code of codegen) {
15
+ for (const code of codeGenerator) {
16
16
  if (typeof code === 'object') {
17
- code[3] = context.resolveCodeFeatures(code[3]);
17
+ code[3] = ctx.resolveCodeFeatures(code[3]);
18
18
  }
19
19
  codes.push(code);
20
20
  }
21
- return {
22
- ...context,
23
- codes,
24
- };
21
+ return { ...ctx, codes };
25
22
  }
26
- function* generateTemplate(options, ctx) {
27
- if (options.slotsAssignName) {
28
- ctx.addLocalVariable(options.slotsAssignName);
23
+ function* generateWorker(options, ctx) {
24
+ const endScope = ctx.startScope();
25
+ ctx.declare(...options.setupConsts);
26
+ const { slotsAssignName, propsAssignName, vueCompilerOptions, template, } = options;
27
+ if (slotsAssignName) {
28
+ ctx.declare(slotsAssignName);
29
29
  }
30
- if (options.propsAssignName) {
31
- ctx.addLocalVariable(options.propsAssignName);
30
+ if (propsAssignName) {
31
+ ctx.declare(propsAssignName);
32
32
  }
33
- if (options.vueCompilerOptions.inferTemplateDollarSlots) {
33
+ if (vueCompilerOptions.inferTemplateDollarSlots) {
34
34
  ctx.dollarVars.add('$slots');
35
35
  }
36
- if (options.vueCompilerOptions.inferTemplateDollarAttrs) {
36
+ if (vueCompilerOptions.inferTemplateDollarAttrs) {
37
37
  ctx.dollarVars.add('$attrs');
38
38
  }
39
- if (options.vueCompilerOptions.inferTemplateDollarRefs) {
39
+ if (vueCompilerOptions.inferTemplateDollarRefs) {
40
40
  ctx.dollarVars.add('$refs');
41
41
  }
42
- if (options.vueCompilerOptions.inferTemplateDollarEl) {
42
+ if (vueCompilerOptions.inferTemplateDollarEl) {
43
43
  ctx.dollarVars.add('$el');
44
44
  }
45
- if (options.template.ast) {
46
- yield* (0, templateChild_1.generateTemplateChild)(options, ctx, options.template.ast);
45
+ if (template.ast) {
46
+ yield* (0, templateChild_1.generateTemplateChild)(options, ctx, template.ast);
47
47
  }
48
- yield* (0, styleScopedClasses_1.generateStyleScopedClassReferences)(ctx);
49
48
  yield* ctx.generateHoistVariables();
50
- const dollarTypes = [
51
- ['$slots', yield* generateSlots(options, ctx)],
52
- ['$attrs', yield* generateInheritedAttrs(options, ctx)],
53
- ['$refs', yield* generateTemplateRefs(options, ctx)],
54
- ['$el', yield* generateRootEl(ctx)],
55
- ].filter(([name]) => ctx.dollarVars.has(name));
56
- if (dollarTypes.length) {
57
- yield `var __VLS_dollars!: {${utils_1.newLine}`;
58
- for (const [name, type] of dollarTypes) {
59
- yield `${name}: ${type}${utils_1.endOfLine}`;
49
+ yield* generateSlotsType(options, ctx);
50
+ yield* generateInheritedAttrsType(ctx);
51
+ yield* generateTemplateRefsType(options, ctx);
52
+ yield* generateRootElType(ctx);
53
+ if (ctx.dollarVars.size) {
54
+ yield `var ${names.dollars}!: {${utils_1.newLine}`;
55
+ if (ctx.dollarVars.has('$slots')) {
56
+ const type = ctx.generatedTypes.has(names.Slots) ? names.Slots : `{}`;
57
+ yield `$slots: ${type}${utils_1.endOfLine}`;
60
58
  }
61
- yield `} & { [K in keyof import('${options.vueCompilerOptions.lib}').ComponentPublicInstance]: unknown }${utils_1.endOfLine}`;
59
+ if (ctx.dollarVars.has('$attrs')) {
60
+ yield `$attrs: import('${vueCompilerOptions.lib}').ComponentPublicInstance['$attrs']`;
61
+ if (ctx.generatedTypes.has(names.InheritedAttrs)) {
62
+ yield ` & ${names.InheritedAttrs}`;
63
+ }
64
+ yield utils_1.endOfLine;
65
+ }
66
+ if (ctx.dollarVars.has('$refs')) {
67
+ const type = ctx.generatedTypes.has(names.TemplateRefs) ? names.TemplateRefs : `{}`;
68
+ yield `$refs: ${type}${utils_1.endOfLine}`;
69
+ }
70
+ if (ctx.dollarVars.has('$el')) {
71
+ const type = ctx.generatedTypes.has(names.RootEl) ? names.RootEl : `any`;
72
+ yield `$el: ${type}${utils_1.endOfLine}`;
73
+ }
74
+ yield `} & { [K in keyof import('${vueCompilerOptions.lib}').ComponentPublicInstance]: unknown }${utils_1.endOfLine}`;
62
75
  }
76
+ yield* endScope();
63
77
  }
64
- function* generateSlots(options, ctx) {
65
- if (!options.hasDefineSlots) {
66
- yield `type __VLS_Slots = {}`;
67
- for (const { expVar, propsVar } of ctx.dynamicSlots) {
68
- yield `${utils_1.newLine}& { [K in NonNullable<typeof ${expVar}>]?: (props: typeof ${propsVar}) => any }`;
78
+ function* generateSlotsType(options, ctx) {
79
+ if (options.hasDefineSlots || (!ctx.slots.length && !ctx.dynamicSlots.length)) {
80
+ return;
81
+ }
82
+ ctx.generatedTypes.add(names.Slots);
83
+ yield `type ${names.Slots} = {}`;
84
+ for (const { expVar, propsVar } of ctx.dynamicSlots) {
85
+ yield `${utils_1.newLine}& { [K in NonNullable<typeof ${expVar}>]?: (props: typeof ${propsVar}) => any }`;
86
+ }
87
+ for (const slot of ctx.slots) {
88
+ yield `${utils_1.newLine}& { `;
89
+ if (slot.name && slot.offset !== undefined) {
90
+ yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slot.name, slot.offset, codeFeatures_1.codeFeatures.navigation);
69
91
  }
70
- for (const slot of ctx.slots) {
71
- yield `${utils_1.newLine}& { `;
72
- if (slot.name && slot.offset !== undefined) {
73
- yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slot.name, slot.offset, codeFeatures_1.codeFeatures.navigation);
74
- }
75
- else {
76
- yield* (0, wrapWith_1.wrapWith)('template', slot.tagRange[0], slot.tagRange[1], codeFeatures_1.codeFeatures.navigation, `default`);
77
- }
78
- yield `?: (props: typeof ${slot.propsVar}) => any }`;
92
+ else {
93
+ const token = yield* (0, boundary_1.startBoundary)('template', slot.tagRange[0], codeFeatures_1.codeFeatures.navigation);
94
+ yield `default`;
95
+ yield (0, boundary_1.endBoundary)(token, slot.tagRange[1]);
79
96
  }
80
- yield utils_1.endOfLine;
97
+ yield `?: (props: typeof ${slot.propsVar}) => any }`;
81
98
  }
82
- return `__VLS_Slots`;
83
- }
84
- function* generateInheritedAttrs(options, ctx) {
85
- yield `type __VLS_InheritedAttrs = ${ctx.inheritedAttrVars.size
86
- ? `Partial<${[...ctx.inheritedAttrVars].map(name => `typeof ${name}`).join(` & `)}>`
87
- : `{}`}`;
88
99
  yield utils_1.endOfLine;
89
- if (ctx.bindingAttrLocs.length) {
90
- yield `[`;
91
- for (const loc of ctx.bindingAttrLocs) {
92
- yield `__VLS_dollars.`;
93
- yield [
94
- loc.source,
95
- 'template',
96
- loc.start.offset,
97
- codeFeatures_1.codeFeatures.all,
98
- ];
99
- yield `,`;
100
- }
101
- yield `]${utils_1.endOfLine}`;
100
+ }
101
+ function* generateInheritedAttrsType(ctx) {
102
+ if (!ctx.inheritedAttrVars.size) {
103
+ return;
102
104
  }
103
- return `import('${options.vueCompilerOptions.lib}').ComponentPublicInstance['$attrs'] & __VLS_InheritedAttrs`;
105
+ ctx.generatedTypes.add(names.InheritedAttrs);
106
+ yield `type ${names.InheritedAttrs} = Partial<${[...ctx.inheritedAttrVars].map(name => `typeof ${name}`).join(` & `)}>`;
107
+ yield utils_1.endOfLine;
104
108
  }
105
- function* generateTemplateRefs(options, ctx) {
106
- yield `type __VLS_TemplateRefs = {}`;
109
+ function* generateTemplateRefsType(options, ctx) {
110
+ if (!ctx.templateRefs.size) {
111
+ return;
112
+ }
113
+ ctx.generatedTypes.add(names.TemplateRefs);
114
+ yield `type ${names.TemplateRefs} = {}`;
107
115
  for (const [name, refs] of ctx.templateRefs) {
108
116
  yield `${utils_1.newLine}& `;
109
117
  if (refs.length >= 2) {
@@ -123,19 +131,16 @@ function* generateTemplateRefs(options, ctx) {
123
131
  }
124
132
  }
125
133
  yield utils_1.endOfLine;
126
- return `__VLS_TemplateRefs`;
127
134
  }
128
- function* generateRootEl(ctx) {
129
- yield `type __VLS_RootEl = `;
130
- if (ctx.singleRootElTypes.size && !ctx.singleRootNodes.has(null)) {
131
- for (const type of ctx.singleRootElTypes) {
132
- yield `${utils_1.newLine}| ${type}`;
133
- }
135
+ function* generateRootElType(ctx) {
136
+ if (!ctx.singleRootElTypes.size || ctx.singleRootNodes.has(null)) {
137
+ return;
134
138
  }
135
- else {
136
- yield `any`;
139
+ ctx.generatedTypes.add(names.RootEl);
140
+ yield `type ${names.RootEl} = `;
141
+ for (const type of ctx.singleRootElTypes) {
142
+ yield `${utils_1.newLine}| ${type}`;
137
143
  }
138
144
  yield utils_1.endOfLine;
139
- return `__VLS_RootEl`;
140
145
  }
141
146
  //# sourceMappingURL=index.js.map
@@ -1,5 +1,5 @@
1
- import type { Code, VueCodeInformation } from '../../types';
2
- import type { ScriptCodegenOptions } from '../script';
1
+ import type { Code, SfcBlock, VueCodeInformation } from '../../types';
2
+ import type { StyleCodegenOptions } from '../style';
3
3
  import type { TemplateCodegenContext } from './context';
4
4
  import type { TemplateCodegenOptions } from './index';
5
- export declare function generateInterpolation(options: TemplateCodegenOptions | ScriptCodegenOptions, ctx: TemplateCodegenContext, source: string, data: VueCodeInformation | ((offset: number) => VueCodeInformation) | undefined, code: string, start: number | undefined, prefix?: string, suffix?: string): Generator<Code>;
5
+ export declare function generateInterpolation(options: Pick<TemplateCodegenOptions | StyleCodegenOptions, 'ts' | 'setupRefs'>, ctx: TemplateCodegenContext, block: SfcBlock, data: VueCodeInformation, code: string, start: number, prefix?: string, suffix?: string): Generator<Code>;