@vue/language-core 2.1.10 → 2.2.2

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 (109) hide show
  1. package/index.d.ts +0 -1
  2. package/index.js +1 -2
  3. package/lib/codeFeatures.d.ts +1 -0
  4. package/lib/codeFeatures.js +3 -0
  5. package/lib/codegen/codeFeatures.d.ts +83 -0
  6. package/lib/codegen/codeFeatures.js +71 -0
  7. package/lib/codegen/globalTypes.d.ts +3 -1
  8. package/lib/codegen/globalTypes.js +39 -14
  9. package/lib/codegen/localTypes.d.ts +1 -1
  10. package/lib/codegen/localTypes.js +7 -7
  11. package/lib/codegen/script/binding.d.ts +4 -0
  12. package/lib/codegen/script/binding.js +41 -0
  13. package/lib/codegen/script/component.d.ts +1 -1
  14. package/lib/codegen/script/component.js +44 -44
  15. package/lib/codegen/script/componentSelf.d.ts +1 -1
  16. package/lib/codegen/script/componentSelf.js +14 -14
  17. package/lib/codegen/script/context.d.ts +1 -1
  18. package/lib/codegen/script/context.js +2 -2
  19. package/lib/codegen/script/index.d.ts +6 -11
  20. package/lib/codegen/script/index.js +21 -63
  21. package/lib/codegen/script/scriptSetup.d.ts +1 -1
  22. package/lib/codegen/script/scriptSetup.js +236 -205
  23. package/lib/codegen/script/src.js +8 -8
  24. package/lib/codegen/script/styleModulesType.d.ts +1 -1
  25. package/lib/codegen/script/styleModulesType.js +7 -7
  26. package/lib/codegen/script/template.d.ts +2 -2
  27. package/lib/codegen/script/template.js +81 -114
  28. package/lib/codegen/template/context.d.ts +29 -15
  29. package/lib/codegen/template/context.js +51 -96
  30. package/lib/codegen/template/element.d.ts +2 -4
  31. package/lib/codegen/template/element.js +124 -317
  32. package/lib/codegen/template/elementChildren.d.ts +1 -1
  33. package/lib/codegen/template/elementChildren.js +10 -11
  34. package/lib/codegen/template/elementDirectives.d.ts +1 -0
  35. package/lib/codegen/template/elementDirectives.js +43 -30
  36. package/lib/codegen/template/elementEvents.d.ts +2 -2
  37. package/lib/codegen/template/elementEvents.js +32 -65
  38. package/lib/codegen/template/elementProps.d.ts +5 -3
  39. package/lib/codegen/template/elementProps.js +116 -123
  40. package/lib/codegen/template/index.d.ts +1 -0
  41. package/lib/codegen/template/index.js +67 -69
  42. package/lib/codegen/template/interpolation.d.ts +5 -3
  43. package/lib/codegen/template/interpolation.js +30 -27
  44. package/lib/codegen/template/objectProperty.js +8 -8
  45. package/lib/codegen/template/propertyAccess.js +4 -4
  46. package/lib/codegen/template/slotOutlet.d.ts +1 -1
  47. package/lib/codegen/template/slotOutlet.js +47 -25
  48. package/lib/codegen/template/styleScopedClasses.d.ts +4 -1
  49. package/lib/codegen/template/styleScopedClasses.js +152 -8
  50. package/lib/codegen/template/templateChild.d.ts +1 -1
  51. package/lib/codegen/template/templateChild.js +39 -20
  52. package/lib/codegen/template/vFor.d.ts +1 -1
  53. package/lib/codegen/template/vFor.js +11 -11
  54. package/lib/codegen/template/vIf.d.ts +1 -1
  55. package/lib/codegen/template/vIf.js +6 -6
  56. package/lib/codegen/template/vSlot.d.ts +5 -0
  57. package/lib/codegen/template/vSlot.js +80 -0
  58. package/lib/codegen/utils/camelized.d.ts +2 -0
  59. package/lib/codegen/utils/camelized.js +31 -0
  60. package/lib/codegen/utils/index.d.ts +21 -0
  61. package/lib/codegen/utils/index.js +79 -0
  62. package/lib/codegen/utils/src.d.ts +2 -0
  63. package/lib/codegen/utils/src.js +19 -0
  64. package/lib/codegen/{template → utils}/stringLiteralKey.js +3 -3
  65. package/lib/codegen/utils/unicode.d.ts +2 -0
  66. package/lib/codegen/utils/unicode.js +25 -0
  67. package/lib/languagePlugin.js +1 -1
  68. package/lib/parsers/scriptRanges.d.ts +7 -2
  69. package/lib/parsers/scriptSetupRanges.d.ts +69 -83
  70. package/lib/parsers/scriptSetupRanges.js +194 -171
  71. package/lib/parsers/vueCompilerOptions.d.ts +2 -0
  72. package/lib/parsers/vueCompilerOptions.js +23 -0
  73. package/lib/plugins/file-html.js +4 -3
  74. package/lib/plugins/file-md.js +1 -1
  75. package/lib/plugins/file-vue.js +4 -4
  76. package/lib/plugins/vue-root-tags.js +2 -2
  77. package/lib/plugins/vue-style-class-names.d.ts +5 -0
  78. package/lib/plugins/vue-style-class-names.js +32 -0
  79. package/lib/plugins/vue-style-reference-link.d.ts +1 -0
  80. package/lib/plugins/vue-style-reference-link.js +3 -0
  81. package/lib/plugins/vue-style-reference-links.d.ts +3 -0
  82. package/lib/plugins/vue-style-reference-links.js +26 -0
  83. package/lib/plugins/vue-template-html.js +6 -2
  84. package/lib/plugins/vue-template-inline-css.js +1 -1
  85. package/lib/plugins/vue-template-inline-ts.js +66 -17
  86. package/lib/plugins/vue-tsx.d.ts +126 -92
  87. package/lib/plugins/vue-tsx.js +114 -97
  88. package/lib/plugins/vue-vine.d.ts +3 -0
  89. package/lib/plugins/vue-vine.js +35 -0
  90. package/lib/types.d.ts +25 -12
  91. package/lib/utils/buildMappings.d.ts +1 -1
  92. package/lib/utils/parseCssImports.d.ts +4 -0
  93. package/lib/utils/parseCssImports.js +19 -0
  94. package/lib/utils/parseSfc.d.ts +5 -0
  95. package/lib/utils/parseSfc.js +11 -5
  96. package/lib/utils/signals.d.ts +2 -0
  97. package/lib/utils/signals.js +54 -0
  98. package/lib/utils/ts.d.ts +14 -2
  99. package/lib/utils/ts.js +134 -91
  100. package/lib/virtualFile/computedEmbeddedCodes.d.ts +1 -2
  101. package/lib/virtualFile/computedEmbeddedCodes.js +11 -11
  102. package/lib/virtualFile/computedSfc.d.ts +1 -2
  103. package/lib/virtualFile/computedSfc.js +87 -79
  104. package/lib/virtualFile/computedVueSfc.d.ts +1 -2
  105. package/lib/virtualFile/computedVueSfc.js +7 -7
  106. package/lib/virtualFile/vueFile.d.ts +5 -5
  107. package/lib/virtualFile/vueFile.js +6 -6
  108. package/package.json +6 -6
  109. /package/lib/codegen/{template → utils}/stringLiteralKey.d.ts +0 -0
@@ -1,18 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateElementProps = generateElementProps;
4
+ exports.generatePropExp = generatePropExp;
4
5
  const CompilerDOM = require("@vue/compiler-dom");
5
6
  const shared_1 = require("@vue/shared");
6
7
  const minimatch_1 = require("minimatch");
7
8
  const muggle_string_1 = require("muggle-string");
8
9
  const shared_2 = require("../../utils/shared");
9
- const common_1 = require("../common");
10
- const camelized_1 = require("./camelized");
10
+ const codeFeatures_1 = require("../codeFeatures");
11
+ const inlayHints_1 = require("../inlayHints");
12
+ const utils_1 = require("../utils");
13
+ const camelized_1 = require("../utils/camelized");
14
+ const unicode_1 = require("../utils/unicode");
15
+ const elementDirectives_1 = require("./elementDirectives");
11
16
  const elementEvents_1 = require("./elementEvents");
12
17
  const interpolation_1 = require("./interpolation");
13
18
  const objectProperty_1 = require("./objectProperty");
14
- const inlayHints_1 = require("../inlayHints");
15
- function* generateElementProps(options, ctx, node, props, enableCodeFeatures, propsFailedExps) {
19
+ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enableCodeFeatures, failedPropExps) {
16
20
  const isComponent = node.tagType === CompilerDOM.ElementTypes.COMPONENT;
17
21
  for (const prop of props) {
18
22
  if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
@@ -22,25 +26,26 @@ function* generateElementProps(options, ctx, node, props, enableCodeFeatures, pr
22
26
  && !prop.arg.loc.source.endsWith(']')) {
23
27
  if (!isComponent) {
24
28
  yield `...{ `;
25
- yield* (0, elementEvents_1.generateEventArg)(ctx, prop.arg, true);
29
+ yield* (0, elementEvents_1.generateEventArg)(ctx, prop.arg.loc.source, prop.arg.loc.start.offset);
26
30
  yield `: `;
27
31
  yield* (0, elementEvents_1.generateEventExpression)(options, ctx, prop);
28
- yield `}, `;
32
+ yield `},`;
29
33
  }
30
34
  else {
31
- yield `...{ '${(0, shared_1.camelize)('on-' + prop.arg.loc.source)}': {} as any }, `;
35
+ yield `...{ '${(0, shared_1.camelize)('on-' + prop.arg.loc.source)}': {} as any },`;
32
36
  }
37
+ yield utils_1.newLine;
33
38
  }
34
39
  else if (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
35
40
  && prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
36
41
  && prop.arg.loc.source.startsWith('[')
37
42
  && prop.arg.loc.source.endsWith(']')) {
38
- propsFailedExps?.push({ node: prop.arg, prefix: '(', suffix: ')' });
39
- propsFailedExps?.push({ node: prop.exp, prefix: '() => {', suffix: '}' });
43
+ failedPropExps?.push({ node: prop.arg, prefix: '(', suffix: ')' });
44
+ failedPropExps?.push({ node: prop.exp, prefix: '() => {', suffix: '}' });
40
45
  }
41
46
  else if (!prop.arg
42
47
  && prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
43
- propsFailedExps?.push({ node: prop.exp, prefix: '(', suffix: ')' });
48
+ failedPropExps?.push({ node: prop.exp, prefix: '(', suffix: ')' });
44
49
  }
45
50
  }
46
51
  }
@@ -56,136 +61,106 @@ function* generateElementProps(options, ctx, node, props, enableCodeFeatures, pr
56
61
  : prop.arg.loc.source;
57
62
  }
58
63
  else {
59
- propName = getModelValuePropName(node, options.vueCompilerOptions.target, options.vueCompilerOptions);
64
+ propName = getModelPropName(node, options.vueCompilerOptions);
60
65
  }
61
66
  if (propName === undefined
62
67
  || options.vueCompilerOptions.dataAttributes.some(pattern => (0, minimatch_1.minimatch)(propName, pattern))) {
63
68
  if (prop.exp && prop.exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY) {
64
- propsFailedExps?.push({ node: prop.exp, prefix: '(', suffix: ')' });
69
+ failedPropExps?.push({ node: prop.exp, prefix: '(', suffix: ')' });
65
70
  }
66
71
  continue;
67
72
  }
68
- if (prop.modifiers.some(m => m.content === 'prop' || m.content === 'attr')) {
69
- propName = propName.substring(1);
73
+ if (prop.name === 'bind'
74
+ && prop.modifiers.some(m => m.content === 'prop' || m.content === 'attr')) {
75
+ propName = propName.slice(1);
70
76
  }
71
77
  const shouldSpread = propName === 'style' || propName === 'class';
72
- const shouldCamelize = isComponent
73
- && (!prop.arg || (prop.arg.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic)) // isStatic
74
- && (0, shared_2.hyphenateAttr)(propName) === propName
75
- && !options.vueCompilerOptions.htmlAttributes.some(pattern => (0, minimatch_1.minimatch)(propName, pattern));
78
+ const shouldCamelize = isComponent && getShouldCamelize(options, prop, propName);
79
+ const codeInfo = getPropsCodeInfo(ctx, strictPropsCheck, shouldCamelize);
76
80
  if (shouldSpread) {
77
81
  yield `...{ `;
78
82
  }
79
- const codeInfo = ctx.codeFeatures.withoutHighlightAndCompletion;
80
- const codes = (0, common_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, ...(prop.arg
81
- ? (0, objectProperty_1.generateObjectProperty)(options, ctx, propName, prop.arg.loc.start.offset, {
82
- ...codeInfo,
83
- verification: options.vueCompilerOptions.strictTemplates
84
- ? codeInfo.verification
85
- : {
86
- shouldReport(_source, code) {
87
- if (String(code) === '2353' || String(code) === '2561') {
88
- return false;
89
- }
90
- return typeof codeInfo.verification === 'object'
91
- ? codeInfo.verification.shouldReport?.(_source, code) ?? true
92
- : true;
93
- },
94
- },
95
- navigation: codeInfo.navigation
96
- ? {
97
- resolveRenameNewName: shared_1.camelize,
98
- resolveRenameEditText: shouldCamelize ? shared_2.hyphenateAttr : undefined,
99
- }
100
- : false,
101
- }, prop.loc.name_2 ?? (prop.loc.name_2 = {}), shouldCamelize)
102
- : (0, common_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + 'v-model'.length, ctx.codeFeatures.verification, propName)), `: (`, ...generatePropExp(options, ctx, prop, prop.exp, ctx.codeFeatures.all, prop.arg?.loc.start.offset === prop.exp?.loc.start.offset, enableCodeFeatures), `)`);
103
- if (!enableCodeFeatures) {
104
- yield (0, muggle_string_1.toString)([...codes]);
83
+ const codes = (0, utils_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, ...(prop.arg
84
+ ? (0, objectProperty_1.generateObjectProperty)(options, ctx, propName, prop.arg.loc.start.offset, codeInfo, prop.loc.name_2 ??= {}, shouldCamelize)
85
+ : (0, utils_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + 'v-model'.length, ctx.codeFeatures.verification, propName)), `: (`, ...generatePropExp(options, ctx, prop, prop.exp, ctx.codeFeatures.all, enableCodeFeatures), `)`);
86
+ if (enableCodeFeatures) {
87
+ yield* codes;
105
88
  }
106
89
  else {
107
- yield* codes;
90
+ yield (0, muggle_string_1.toString)([...codes]);
108
91
  }
109
92
  if (shouldSpread) {
110
93
  yield ` }`;
111
94
  }
112
- yield `, `;
95
+ yield `,${utils_1.newLine}`;
96
+ if (isComponent && prop.name === 'model' && prop.modifiers.length) {
97
+ const propertyName = prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
98
+ ? !prop.arg.isStatic
99
+ ? `[__VLS_tryAsConstant(\`$\{${prop.arg.content}\}Modifiers\`)]`
100
+ : (0, shared_1.camelize)(propName) + `Modifiers`
101
+ : `modelModifiers`;
102
+ const codes = (0, elementDirectives_1.generateModifiers)(options, ctx, prop, propertyName);
103
+ if (enableCodeFeatures) {
104
+ yield* codes;
105
+ }
106
+ else {
107
+ yield (0, muggle_string_1.toString)([...codes]);
108
+ }
109
+ yield utils_1.newLine;
110
+ }
113
111
  }
114
112
  else if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE) {
115
113
  if (options.vueCompilerOptions.dataAttributes.some(pattern => (0, minimatch_1.minimatch)(prop.name, pattern))
116
- // Vue 2 Transition doesn't support "persisted" property but `@vue/compiler-dom always adds it (#3881)
114
+ // Vue 2 Transition doesn't support "persisted" property but `@vue/compiler-dom` always adds it (#3881)
117
115
  || (options.vueCompilerOptions.target < 3
118
116
  && prop.name === 'persisted'
119
117
  && node.tag.toLowerCase() === 'transition')) {
120
118
  continue;
121
119
  }
122
120
  const shouldSpread = prop.name === 'style' || prop.name === 'class';
123
- const shouldCamelize = isComponent
124
- && (0, shared_2.hyphenateAttr)(prop.name) === prop.name
125
- && !options.vueCompilerOptions.htmlAttributes.some(pattern => (0, minimatch_1.minimatch)(prop.name, pattern));
121
+ const shouldCamelize = isComponent && getShouldCamelize(options, prop, prop.name);
122
+ const codeInfo = getPropsCodeInfo(ctx, strictPropsCheck, true);
126
123
  if (shouldSpread) {
127
124
  yield `...{ `;
128
125
  }
129
- const codeInfo = shouldCamelize
130
- ? {
131
- ...ctx.codeFeatures.withoutHighlightAndCompletion,
132
- navigation: ctx.codeFeatures.withoutHighlightAndCompletion.navigation
133
- ? {
134
- resolveRenameNewName: shared_1.camelize,
135
- resolveRenameEditText: shared_2.hyphenateAttr,
136
- }
137
- : false,
138
- }
139
- : {
140
- ...ctx.codeFeatures.withoutHighlightAndCompletion,
141
- };
142
- if (!options.vueCompilerOptions.strictTemplates) {
143
- const verification = codeInfo.verification;
144
- codeInfo.verification = {
145
- shouldReport(_source, code) {
146
- if (String(code) === '2353' || String(code) === '2561') {
147
- return false;
148
- }
149
- return typeof verification === 'object'
150
- ? verification.shouldReport?.(_source, code) ?? true
151
- : true;
152
- },
153
- };
154
- }
155
- const codes = (0, common_1.conditionWrapWith)(enableCodeFeatures, prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, ...(0, objectProperty_1.generateObjectProperty)(options, ctx, prop.name, prop.loc.start.offset, codeInfo, prop.loc.name_1 ?? (prop.loc.name_1 = {}), shouldCamelize), `: (`, ...(prop.value
156
- ? generateAttrValue(prop.value, ctx.codeFeatures.all)
126
+ const codes = (0, utils_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, ...(0, objectProperty_1.generateObjectProperty)(options, ctx, prop.name, prop.loc.start.offset, codeInfo, prop.loc.name_1 ??= {}, shouldCamelize), `: (`, ...(prop.value
127
+ ? generateAttrValue(prop.value, ctx.codeFeatures.withoutNavigation)
157
128
  : [`true`]), `)`);
158
- if (!enableCodeFeatures) {
159
- yield (0, muggle_string_1.toString)([...codes]);
129
+ if (enableCodeFeatures) {
130
+ yield* codes;
160
131
  }
161
132
  else {
162
- yield* codes;
133
+ yield (0, muggle_string_1.toString)([...codes]);
163
134
  }
164
135
  if (shouldSpread) {
165
136
  yield ` }`;
166
137
  }
167
- yield `, `;
138
+ yield `,${utils_1.newLine}`;
168
139
  }
169
140
  else if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
170
141
  && prop.name === 'bind'
171
142
  && !prop.arg
172
143
  && prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
173
- const codes = (0, common_1.conditionWrapWith)(enableCodeFeatures, prop.exp.loc.start.offset, prop.exp.loc.end.offset, ctx.codeFeatures.verification, `...`, ...(0, interpolation_1.generateInterpolation)(options, ctx, prop.exp.content, prop.exp.loc, prop.exp.loc.start.offset, ctx.codeFeatures.all, '(', ')'));
174
- if (!enableCodeFeatures) {
175
- yield (0, muggle_string_1.toString)([...codes]);
144
+ if (prop.exp.loc.source === '$attrs') {
145
+ if (enableCodeFeatures) {
146
+ ctx.bindingAttrLocs.push(prop.exp.loc);
147
+ }
176
148
  }
177
149
  else {
178
- yield* codes;
150
+ const codes = (0, utils_1.wrapWith)(prop.exp.loc.start.offset, prop.exp.loc.end.offset, ctx.codeFeatures.verification, `...`, ...generatePropExp(options, ctx, prop, prop.exp, ctx.codeFeatures.all, enableCodeFeatures));
151
+ if (enableCodeFeatures) {
152
+ yield* codes;
153
+ }
154
+ else {
155
+ yield (0, muggle_string_1.toString)([...codes]);
156
+ }
157
+ yield `,${utils_1.newLine}`;
179
158
  }
180
- yield `, `;
181
- }
182
- else {
183
- // comment this line to avoid affecting comments in prop expressions
184
- // tsCodeGen.addText("/* " + [prop.type, prop.name, prop.arg?.loc.source, prop.exp?.loc.source, prop.loc.source].join(", ") + " */ ");
185
159
  }
186
160
  }
187
161
  }
188
- function* generatePropExp(options, ctx, prop, exp, features, isShorthand, enableCodeFeatures) {
162
+ function* generatePropExp(options, ctx, prop, exp, features, enableCodeFeatures) {
163
+ const isShorthand = prop.arg?.loc.start.offset === prop.exp?.loc.start.offset;
189
164
  if (isShorthand && features.completion) {
190
165
  features = {
191
166
  ...features,
@@ -194,16 +169,29 @@ function* generatePropExp(options, ctx, prop, exp, features, isShorthand, enable
194
169
  }
195
170
  if (exp && exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY) { // style='z-index: 2' will compile to {'z-index':'2'}
196
171
  if (!isShorthand) { // vue 3.4+
197
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, exp.loc.source, exp.loc, exp.loc.start.offset, features, '(', ')');
172
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, exp.loc.source, exp.loc.start.offset, exp.loc, '(', ')');
198
173
  }
199
174
  else {
200
175
  const propVariableName = (0, shared_1.camelize)(exp.loc.source);
201
- if (common_1.variableNameRegex.test(propVariableName)) {
202
- if (!ctx.hasLocalVariable(propVariableName)) {
176
+ if (utils_1.variableNameRegex.test(propVariableName)) {
177
+ const isDestructuredProp = options.destructuredPropNames?.has(propVariableName) ?? false;
178
+ const isTemplateRef = options.templateRefNames?.has(propVariableName) ?? false;
179
+ const codes = (0, camelized_1.generateCamelized)(exp.loc.source, exp.loc.start.offset, features);
180
+ if (ctx.hasLocalVariable(propVariableName) || isDestructuredProp) {
181
+ yield* codes;
182
+ }
183
+ else {
203
184
  ctx.accessExternalVariable(propVariableName, exp.loc.start.offset);
204
- yield `__VLS_ctx.`;
185
+ if (isTemplateRef) {
186
+ yield `__VLS_unref(`;
187
+ yield* codes;
188
+ yield `)`;
189
+ }
190
+ else {
191
+ yield `__VLS_ctx.`;
192
+ yield* codes;
193
+ }
205
194
  }
206
- yield* (0, camelized_1.generateCamelized)(exp.loc.source, exp.loc.start.offset, features);
207
195
  if (enableCodeFeatures) {
208
196
  ctx.inlayHints.push((0, inlayHints_1.createVBindShorthandInlayHintInfo)(prop.loc, propVariableName));
209
197
  }
@@ -215,45 +203,50 @@ function* generatePropExp(options, ctx, prop, exp, features, isShorthand, enable
215
203
  }
216
204
  }
217
205
  function* generateAttrValue(attrNode, features) {
218
- const char = attrNode.loc.source.startsWith("'") ? "'" : '"';
219
- yield char;
206
+ const quote = attrNode.loc.source.startsWith("'") ? "'" : '"';
207
+ yield quote;
220
208
  let start = attrNode.loc.start.offset;
221
- let end = attrNode.loc.end.offset;
222
209
  let content = attrNode.loc.source;
223
210
  if ((content.startsWith('"') && content.endsWith('"'))
224
211
  || (content.startsWith("'") && content.endsWith("'"))) {
225
212
  start++;
226
- end--;
227
213
  content = content.slice(1, -1);
228
214
  }
229
- if (needToUnicode(content)) {
230
- yield* (0, common_1.wrapWith)(start, end, features, toUnicode(content));
231
- }
232
- else {
233
- yield [content, 'template', start, features];
234
- }
235
- yield char;
215
+ yield* (0, unicode_1.generateUnicode)(content, start, features);
216
+ yield quote;
236
217
  }
237
- function needToUnicode(str) {
238
- return str.includes('\\') || str.includes('\n');
218
+ function getShouldCamelize(options, prop, propName) {
219
+ return (prop.type !== CompilerDOM.NodeTypes.DIRECTIVE
220
+ || !prop.arg
221
+ || (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic))
222
+ && (0, shared_2.hyphenateAttr)(propName) === propName
223
+ && !options.vueCompilerOptions.htmlAttributes.some(pattern => (0, minimatch_1.minimatch)(propName, pattern));
239
224
  }
240
- function toUnicode(str) {
241
- return str.split('').map(value => {
242
- const temp = value.charCodeAt(0).toString(16).padStart(4, '0');
243
- if (temp.length > 2) {
244
- return '\\u' + temp;
245
- }
246
- return value;
247
- }).join('');
225
+ function getPropsCodeInfo(ctx, strictPropsCheck, shouldCamelize) {
226
+ return ctx.resolveCodeFeatures({
227
+ ...codeFeatures_1.codeFeatures.withoutHighlightAndCompletion,
228
+ navigation: {
229
+ resolveRenameNewName: shared_1.camelize,
230
+ resolveRenameEditText: shouldCamelize ? shared_2.hyphenateAttr : undefined,
231
+ },
232
+ verification: strictPropsCheck || {
233
+ shouldReport(_source, code) {
234
+ if (String(code) === '2353' || String(code) === '2561') {
235
+ return false;
236
+ }
237
+ return true;
238
+ },
239
+ },
240
+ });
248
241
  }
249
- function getModelValuePropName(node, vueVersion, vueCompilerOptions) {
242
+ function getModelPropName(node, vueCompilerOptions) {
250
243
  for (const modelName in vueCompilerOptions.experimentalModelPropName) {
251
244
  const tags = vueCompilerOptions.experimentalModelPropName[modelName];
252
245
  for (const tag in tags) {
253
246
  if (node.tag === tag || node.tag === (0, shared_2.hyphenateTag)(tag)) {
254
- const v = tags[tag];
255
- if (typeof v === 'object') {
256
- const arr = Array.isArray(v) ? v : [v];
247
+ const val = tags[tag];
248
+ if (typeof val === 'object') {
249
+ const arr = Array.isArray(val) ? val : [val];
257
250
  for (const attrs of arr) {
258
251
  let failed = false;
259
252
  for (const attr in attrs) {
@@ -283,6 +276,6 @@ function getModelValuePropName(node, vueVersion, vueCompilerOptions) {
283
276
  }
284
277
  }
285
278
  }
286
- return vueVersion < 3 ? 'value' : 'modelValue';
279
+ return vueCompilerOptions.target < 3 ? 'value' : 'modelValue';
287
280
  }
288
281
  //# sourceMappingURL=elementProps.js.map
@@ -16,6 +16,7 @@ export interface TemplateCodegenOptions {
16
16
  slotsAssignName?: string;
17
17
  propsAssignName?: string;
18
18
  inheritAttrs: boolean;
19
+ selfComponentName?: string;
19
20
  }
20
21
  export declare function generateTemplate(options: TemplateCodegenOptions): Generator<Code, TemplateCodegenContext>;
21
22
  export declare function forEachElementNode(node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode): Generator<CompilerDOM.ElementNode>;
@@ -3,13 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateTemplate = generateTemplate;
4
4
  exports.forEachElementNode = forEachElementNode;
5
5
  const CompilerDOM = require("@vue/compiler-dom");
6
- const common_1 = require("../common");
6
+ const shared_1 = require("../../utils/shared");
7
+ const utils_1 = require("../utils");
7
8
  const context_1 = require("./context");
8
- const element_1 = require("./element");
9
9
  const objectProperty_1 = require("./objectProperty");
10
- const stringLiteralKey_1 = require("./stringLiteralKey");
11
- const templateChild_1 = require("./templateChild");
12
10
  const styleScopedClasses_1 = require("./styleScopedClasses");
11
+ const templateChild_1 = require("./templateChild");
13
12
  function* generateTemplate(options) {
14
13
  const ctx = (0, context_1.createTemplateCodegenContext)(options);
15
14
  if (options.slotsAssignName) {
@@ -18,89 +17,88 @@ function* generateTemplate(options) {
18
17
  if (options.propsAssignName) {
19
18
  ctx.addLocalVariable(options.propsAssignName);
20
19
  }
21
- ctx.addLocalVariable('$el');
22
- ctx.addLocalVariable('$refs');
23
- yield* generatePreResolveComponents(options);
20
+ const slotsPropertyName = (0, shared_1.getSlotsPropertyName)(options.vueCompilerOptions.target);
21
+ ctx.specialVars.add(slotsPropertyName);
22
+ ctx.specialVars.add('$attrs');
23
+ ctx.specialVars.add('$refs');
24
+ ctx.specialVars.add('$el');
24
25
  if (options.template.ast) {
25
- yield* (0, templateChild_1.generateTemplateChild)(options, ctx, options.template.ast, undefined, undefined, undefined);
26
+ yield* (0, templateChild_1.generateTemplateChild)(options, ctx, options.template.ast, undefined);
26
27
  }
27
- yield* (0, styleScopedClasses_1.generateStyleScopedClasses)(ctx);
28
- if (!options.hasDefineSlots) {
29
- yield `var __VLS_slots!:`;
30
- yield* generateSlotsType(options, ctx);
31
- yield common_1.endOfLine;
28
+ yield* (0, styleScopedClasses_1.generateStyleScopedClassReferences)(ctx);
29
+ const speicalTypes = [
30
+ [slotsPropertyName, yield* generateSlots(options, ctx)],
31
+ ['$attrs', yield* generateInheritedAttrs(options, ctx)],
32
+ ['$refs', yield* generateTemplateRefs(options, ctx)],
33
+ ['$el', yield* generateRootEl(ctx)]
34
+ ];
35
+ yield `var __VLS_special!: {${utils_1.newLine}`;
36
+ for (const [name, type] of speicalTypes) {
37
+ yield `${name}: ${type}${utils_1.endOfLine}`;
32
38
  }
39
+ yield `} & { [K in keyof typeof __VLS_ctx]: unknown }${utils_1.endOfLine}`;
33
40
  yield* ctx.generateAutoImportCompletion();
34
- yield* generateInheritedAttrs(ctx);
35
- yield* generateRefs(ctx);
36
- yield* generateRootEl(ctx);
37
41
  return ctx;
38
42
  }
39
- function* generateSlotsType(options, ctx) {
40
- for (const { expVar, varName } of ctx.dynamicSlots) {
41
- ctx.hasSlot = true;
42
- yield `Partial<Record<NonNullable<typeof ${expVar}>, (_: typeof ${varName}) => any>> &${common_1.newLine}`;
43
- }
44
- yield `{${common_1.newLine}`;
45
- for (const slot of ctx.slots) {
46
- ctx.hasSlot = true;
47
- if (slot.name && slot.loc !== undefined) {
48
- yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slot.name, slot.loc, ctx.codeFeatures.withoutHighlightAndCompletion, slot.nodeLoc);
43
+ function* generateSlots(options, ctx) {
44
+ if (!options.hasDefineSlots) {
45
+ const name = (0, shared_1.getSlotsPropertyName)(options.vueCompilerOptions.target);
46
+ yield `type __VLS_Slots = __VLS_PrettifyGlobal<__VLS_OmitStringIndex<typeof __VLS_ctx.${name}>`;
47
+ for (const { expVar, propsVar } of ctx.dynamicSlots) {
48
+ ctx.hasSlot = true;
49
+ yield `${utils_1.newLine}& { [K in NonNullable<typeof ${expVar}>]?: (props: typeof ${propsVar}) => any }`;
49
50
  }
50
- else {
51
- yield* (0, common_1.wrapWith)(slot.tagRange[0], slot.tagRange[1], ctx.codeFeatures.withoutHighlightAndCompletion, `default`);
51
+ for (const slot of ctx.slots) {
52
+ yield `${utils_1.newLine}& { `;
53
+ ctx.hasSlot = true;
54
+ if (slot.name && slot.offset !== undefined) {
55
+ yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slot.name, slot.offset, ctx.codeFeatures.withoutHighlightAndCompletion, slot.nodeLoc);
56
+ }
57
+ else {
58
+ yield* (0, utils_1.wrapWith)(slot.tagRange[0], slot.tagRange[1], ctx.codeFeatures.withoutHighlightAndCompletion, `default`);
59
+ }
60
+ yield `?: (props: typeof ${slot.propsVar}) => any }`;
52
61
  }
53
- yield `?(_: typeof ${slot.varName}): any,${common_1.newLine}`;
62
+ yield `>${utils_1.endOfLine}`;
54
63
  }
55
- yield `}`;
64
+ return `__VLS_Slots`;
56
65
  }
57
- function* generateInheritedAttrs(ctx) {
58
- yield 'var __VLS_inheritedAttrs!: {}';
66
+ function* generateInheritedAttrs(options, ctx) {
67
+ yield `type __VLS_InheritedAttrs = {}`;
59
68
  for (const varName of ctx.inheritedAttrVars) {
60
69
  yield ` & typeof ${varName}`;
61
70
  }
62
- yield common_1.endOfLine;
71
+ yield utils_1.endOfLine;
72
+ if (ctx.bindingAttrLocs.length) {
73
+ yield `[`;
74
+ for (const loc of ctx.bindingAttrLocs) {
75
+ yield `__VLS_special.`;
76
+ yield [
77
+ loc.source,
78
+ 'template',
79
+ loc.start.offset,
80
+ ctx.codeFeatures.all
81
+ ];
82
+ yield `,`;
83
+ }
84
+ yield `]${utils_1.endOfLine}`;
85
+ }
86
+ return `import('${options.vueCompilerOptions.lib}').ComponentPublicInstance['$attrs'] & Partial<__VLS_InheritedAttrs>`;
63
87
  }
64
- function* generateRefs(ctx) {
65
- yield `const __VLS_refs = {${common_1.newLine}`;
88
+ function* generateTemplateRefs(options, ctx) {
89
+ yield `type __VLS_TemplateRefs = {${utils_1.newLine}`;
66
90
  for (const [name, [varName, offset]] of ctx.templateRefs) {
67
- yield* (0, stringLiteralKey_1.generateStringLiteralKey)(name, offset, ctx.codeFeatures.navigationAndCompletion);
68
- yield `: ${varName},${common_1.newLine}`;
91
+ yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, name, offset, ctx.codeFeatures.navigationAndCompletion);
92
+ yield `: typeof ${varName},${utils_1.newLine}`;
69
93
  }
70
- yield `}${common_1.endOfLine}`;
71
- yield `var $refs!: typeof __VLS_refs${common_1.endOfLine}`;
94
+ yield `}${utils_1.endOfLine}`;
95
+ return `__VLS_TemplateRefs`;
72
96
  }
73
97
  function* generateRootEl(ctx) {
74
- if (ctx.singleRootElType) {
75
- yield `var $el!: ${ctx.singleRootElType}${common_1.endOfLine}`;
76
- }
77
- else {
78
- yield `var $el!: any${common_1.endOfLine}`;
79
- }
80
- }
81
- function* generatePreResolveComponents(options) {
82
- yield `let __VLS_resolvedLocalAndGlobalComponents!: Required<{}`;
83
- if (options.template.ast) {
84
- const components = new Set();
85
- for (const node of forEachElementNode(options.template.ast)) {
86
- if (node.tagType === CompilerDOM.ElementTypes.COMPONENT
87
- && node.tag.toLowerCase() !== 'component'
88
- && !node.tag.includes('.') // namespace tag
89
- ) {
90
- if (components.has(node.tag)) {
91
- continue;
92
- }
93
- components.add(node.tag);
94
- yield common_1.newLine;
95
- yield ` & __VLS_WithComponent<'${(0, element_1.getCanonicalComponentName)(node.tag)}', typeof __VLS_localComponents, `;
96
- yield (0, element_1.getPossibleOriginalComponentNames)(node.tag, false)
97
- .map(name => `"${name}"`)
98
- .join(', ');
99
- yield `>`;
100
- }
101
- }
102
- }
103
- yield `>${common_1.endOfLine}`;
98
+ yield `type __VLS_RootEl = `;
99
+ yield ctx.singleRootElType ?? `any`;
100
+ yield utils_1.endOfLine;
101
+ return `__VLS_RootEl`;
104
102
  }
105
103
  function* forEachElementNode(node) {
106
104
  if (node.type === CompilerDOM.NodeTypes.ROOT) {
@@ -1,6 +1,8 @@
1
1
  import type * as ts from 'typescript';
2
2
  import type { Code, VueCodeInformation } from '../../types';
3
3
  import type { TemplateCodegenContext } from './context';
4
- import type { TemplateCodegenOptions } from './index';
5
- export declare function generateInterpolation(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, _code: string, astHolder: any, start: number | undefined, data: VueCodeInformation | ((offset: number) => VueCodeInformation) | undefined, prefix: string, suffix: string): Generator<Code>;
6
- export declare function forEachInterpolationSegment(ts: typeof import('typescript'), destructuredPropNames: Set<string> | undefined, templateRefNames: Set<string> | undefined, ctx: TemplateCodegenContext, code: string, offset: number | undefined, ast: ts.SourceFile): Generator<[fragment: string, offset: number | undefined, type?: 'errorMappingOnly' | 'startText' | 'endText']>;
4
+ export declare function generateInterpolation(options: {
5
+ ts: typeof ts;
6
+ destructuredPropNames: Set<string> | undefined;
7
+ templateRefNames: Set<string> | undefined;
8
+ }, ctx: TemplateCodegenContext, source: string, data: VueCodeInformation | ((offset: number) => VueCodeInformation) | undefined, _code: string, start: number | undefined, astHolder?: any, prefix?: string, suffix?: string): Generator<Code>;