@vue/language-core 2.1.8 → 2.2.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 (77) hide show
  1. package/lib/codegen/globalTypes.js +12 -5
  2. package/lib/codegen/localTypes.js +3 -3
  3. package/lib/codegen/script/component.js +42 -42
  4. package/lib/codegen/script/componentSelf.js +14 -13
  5. package/lib/codegen/script/context.js +2 -2
  6. package/lib/codegen/script/index.d.ts +5 -3
  7. package/lib/codegen/script/index.js +24 -37
  8. package/lib/codegen/script/scriptSetup.js +240 -193
  9. package/lib/codegen/script/src.js +6 -6
  10. package/lib/codegen/script/styleModulesType.js +5 -5
  11. package/lib/codegen/script/template.d.ts +1 -1
  12. package/lib/codegen/script/template.js +89 -99
  13. package/lib/codegen/template/context.d.ts +13 -3
  14. package/lib/codegen/template/context.js +21 -12
  15. package/lib/codegen/template/element.d.ts +2 -4
  16. package/lib/codegen/template/element.js +132 -105
  17. package/lib/codegen/template/elementChildren.d.ts +1 -1
  18. package/lib/codegen/template/elementChildren.js +8 -8
  19. package/lib/codegen/template/elementDirectives.d.ts +1 -0
  20. package/lib/codegen/template/elementDirectives.js +28 -22
  21. package/lib/codegen/template/elementEvents.d.ts +2 -2
  22. package/lib/codegen/template/elementEvents.js +32 -65
  23. package/lib/codegen/template/elementProps.d.ts +3 -2
  24. package/lib/codegen/template/elementProps.js +119 -122
  25. package/lib/codegen/template/index.js +52 -60
  26. package/lib/codegen/template/interpolation.d.ts +5 -3
  27. package/lib/codegen/template/interpolation.js +18 -19
  28. package/lib/codegen/template/objectProperty.js +8 -8
  29. package/lib/codegen/template/propertyAccess.js +4 -4
  30. package/lib/codegen/template/slotOutlet.d.ts +1 -1
  31. package/lib/codegen/template/slotOutlet.js +13 -13
  32. package/lib/codegen/template/styleScopedClasses.d.ts +1 -1
  33. package/lib/codegen/template/styleScopedClasses.js +11 -8
  34. package/lib/codegen/template/templateChild.d.ts +1 -1
  35. package/lib/codegen/template/templateChild.js +31 -19
  36. package/lib/codegen/template/vFor.d.ts +1 -1
  37. package/lib/codegen/template/vFor.js +11 -11
  38. package/lib/codegen/template/vIf.d.ts +1 -1
  39. package/lib/codegen/template/vIf.js +6 -6
  40. package/lib/codegen/{template → utils}/camelized.js +2 -2
  41. package/lib/codegen/{common.d.ts → utils/index.d.ts} +1 -2
  42. package/lib/codegen/{common.js → utils/index.js} +4 -15
  43. package/lib/codegen/{template → utils}/stringLiteralKey.js +3 -3
  44. package/lib/codegen/utils/unicode.d.ts +2 -0
  45. package/lib/codegen/utils/unicode.js +25 -0
  46. package/lib/languagePlugin.js +1 -1
  47. package/lib/parsers/scriptRanges.d.ts +7 -2
  48. package/lib/parsers/scriptSetupRanges.d.ts +67 -81
  49. package/lib/parsers/scriptSetupRanges.js +195 -166
  50. package/lib/parsers/vueCompilerOptions.d.ts +2 -0
  51. package/lib/parsers/vueCompilerOptions.js +23 -0
  52. package/lib/plugins/file-html.js +4 -3
  53. package/lib/plugins/file-md.js +1 -1
  54. package/lib/plugins/file-vue.js +4 -4
  55. package/lib/plugins/vue-root-tags.js +2 -2
  56. package/lib/plugins/vue-template-html.js +6 -2
  57. package/lib/plugins/vue-template-inline-css.js +1 -1
  58. package/lib/plugins/vue-template-inline-ts.js +13 -5
  59. package/lib/plugins/vue-tsx.d.ts +101 -72
  60. package/lib/plugins/vue-tsx.js +65 -69
  61. package/lib/types.d.ts +19 -10
  62. package/lib/utils/buildMappings.d.ts +1 -1
  63. package/lib/utils/parseSfc.d.ts +5 -0
  64. package/lib/utils/parseSfc.js +7 -2
  65. package/lib/utils/ts.d.ts +1 -1
  66. package/lib/utils/ts.js +38 -24
  67. package/lib/virtualFile/computedEmbeddedCodes.d.ts +1 -2
  68. package/lib/virtualFile/computedSfc.js +23 -12
  69. package/lib/virtualFile/computedVueSfc.d.ts +1 -1
  70. package/lib/virtualFile/vueFile.d.ts +3 -3
  71. package/package.json +5 -5
  72. package/lib/codegen/types.d.ts +0 -9
  73. package/lib/codegen/types.js +0 -3
  74. package/lib/utils/findDestructuredProps.d.ts +0 -1
  75. package/lib/utils/findDestructuredProps.js +0 -3
  76. /package/lib/codegen/{template → utils}/camelized.d.ts +0 -0
  77. /package/lib/codegen/{template → utils}/stringLiteralKey.d.ts +0 -0
@@ -6,11 +6,10 @@ exports.generateEventExpression = generateEventExpression;
6
6
  exports.isCompoundExpression = isCompoundExpression;
7
7
  const CompilerDOM = require("@vue/compiler-dom");
8
8
  const shared_1 = require("@vue/shared");
9
- const shared_2 = require("../../utils/shared");
10
- const common_1 = require("../common");
11
- const camelized_1 = require("./camelized");
9
+ const utils_1 = require("../utils");
10
+ const camelized_1 = require("../utils/camelized");
12
11
  const interpolation_1 = require("./interpolation");
13
- function* generateElementEvents(options, ctx, node, componentVar, componentInstanceVar, emitVar, eventsVar) {
12
+ function* generateElementEvents(options, ctx, node, componentVar, componentInstanceVar, eventsVar) {
14
13
  let usedComponentEventsVar = false;
15
14
  let propsVar;
16
15
  for (const prop of node.props) {
@@ -22,71 +21,39 @@ function* generateElementEvents(options, ctx, node, componentVar, componentInsta
22
21
  usedComponentEventsVar = true;
23
22
  if (!propsVar) {
24
23
  propsVar = ctx.getInternalVariable();
25
- yield `let ${propsVar}!: __VLS_FunctionalComponentProps<typeof ${componentVar}, typeof ${componentInstanceVar}>${common_1.endOfLine}`;
24
+ yield `let ${propsVar}!: __VLS_FunctionalComponentProps<typeof ${componentVar}, typeof ${componentInstanceVar}>${utils_1.endOfLine}`;
26
25
  }
27
- const originalPropName = (0, shared_1.camelize)('on-' + prop.arg.loc.source);
28
- const originalPropNameObjectKey = common_1.variableNameRegex.test(originalPropName)
29
- ? originalPropName
30
- : `'${originalPropName}'`;
31
- yield `const ${ctx.getInternalVariable()}: `;
32
- if (!options.vueCompilerOptions.strictTemplates) {
33
- yield `Record<string, unknown> & `;
26
+ let source = prop.arg.loc.source;
27
+ let start = prop.arg.loc.start.offset;
28
+ let propPrefix = 'on';
29
+ let emitPrefix = '';
30
+ if (source.startsWith('vue:')) {
31
+ source = source.slice('vue:'.length);
32
+ start = start + 'vue:'.length;
33
+ propPrefix = 'onVnode';
34
+ emitPrefix = 'vnode-';
34
35
  }
35
- yield `(${common_1.newLine}`;
36
- yield `__VLS_IsFunction<typeof ${propsVar}, '${originalPropName}'> extends true${common_1.newLine}`;
37
- yield `? typeof ${propsVar}${common_1.newLine}`;
38
- yield `: __VLS_IsFunction<typeof ${eventsVar}, '${prop.arg.loc.source}'> extends true${common_1.newLine}`;
39
- yield `? {${common_1.newLine}`;
40
- yield `/**__VLS_emit,${emitVar},${prop.arg.loc.source}*/${common_1.newLine}`;
41
- yield `${originalPropNameObjectKey}?: typeof ${eventsVar}['${prop.arg.loc.source}']${common_1.newLine}`;
42
- yield `}${common_1.newLine}`;
43
- if (prop.arg.loc.source !== (0, shared_1.camelize)(prop.arg.loc.source)) {
44
- yield `: __VLS_IsFunction<typeof ${eventsVar}, '${(0, shared_1.camelize)(prop.arg.loc.source)}'> extends true${common_1.newLine}`;
45
- yield `? {${common_1.newLine}`;
46
- yield `/**__VLS_emit,${emitVar},${(0, shared_1.camelize)(prop.arg.loc.source)}*/${common_1.newLine}`;
47
- yield `${originalPropNameObjectKey}?: typeof ${eventsVar}['${(0, shared_1.camelize)(prop.arg.loc.source)}']${common_1.newLine}`;
48
- yield `}${common_1.newLine}`;
49
- }
50
- yield `: typeof ${propsVar}${common_1.newLine}`;
51
- yield `) = {${common_1.newLine}`;
52
- yield* generateEventArg(ctx, prop.arg, true);
36
+ yield `const ${ctx.getInternalVariable()}: __VLS_NormalizeComponentEvent<typeof ${propsVar}, typeof ${eventsVar}, '${(0, shared_1.camelize)(propPrefix + '-' + source)}', '${emitPrefix}${source}', '${(0, shared_1.camelize)(emitPrefix + source)}'> = {${utils_1.newLine}`;
37
+ yield* generateEventArg(ctx, source, start, propPrefix);
53
38
  yield `: `;
54
39
  yield* generateEventExpression(options, ctx, prop);
55
- yield `}${common_1.endOfLine}`;
40
+ yield `}${utils_1.endOfLine}`;
56
41
  }
57
42
  }
58
43
  return usedComponentEventsVar;
59
44
  }
60
- const eventArgFeatures = {
61
- navigation: {
62
- // @click-outside -> onClickOutside
63
- resolveRenameNewName(newName) {
64
- return (0, shared_1.camelize)('on-' + newName);
65
- },
66
- // onClickOutside -> @click-outside
67
- resolveRenameEditText(newName) {
68
- const hName = (0, shared_2.hyphenateAttr)(newName);
69
- if ((0, shared_2.hyphenateAttr)(newName).startsWith('on-')) {
70
- return (0, shared_1.camelize)(hName.slice('on-'.length));
71
- }
72
- return newName;
73
- },
74
- },
75
- };
76
- function* generateEventArg(ctx, arg, enableHover) {
77
- const features = enableHover
78
- ? {
79
- ...ctx.codeFeatures.withoutHighlightAndCompletion,
80
- ...eventArgFeatures,
81
- }
82
- : eventArgFeatures;
83
- if (common_1.variableNameRegex.test((0, shared_1.camelize)(arg.loc.source))) {
84
- yield ['', 'template', arg.loc.start.offset, features];
85
- yield `on`;
86
- yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(arg.loc.source), arg.loc.start.offset, common_1.combineLastMapping);
45
+ function* generateEventArg(ctx, name, start, directive = 'on') {
46
+ const features = {
47
+ ...ctx.codeFeatures.withoutHighlightAndCompletion,
48
+ ...ctx.codeFeatures.navigationWithoutRename,
49
+ };
50
+ if (utils_1.variableNameRegex.test((0, shared_1.camelize)(name))) {
51
+ yield ['', 'template', start, features];
52
+ yield directive;
53
+ yield* (0, camelized_1.generateCamelized)((0, shared_1.capitalize)(name), start, utils_1.combineLastMapping);
87
54
  }
88
55
  else {
89
- yield* (0, common_1.wrapWith)(arg.loc.start.offset, arg.loc.end.offset, features, `'`, ['', 'template', arg.loc.start.offset, common_1.combineLastMapping], 'on', ...(0, camelized_1.generateCamelized)((0, shared_1.capitalize)(arg.loc.source), arg.loc.start.offset, common_1.combineLastMapping), `'`);
56
+ yield* (0, utils_1.wrapWith)(start, start + name.length, features, `'`, ['', 'template', start, utils_1.combineLastMapping], directive, ...(0, camelized_1.generateCamelized)((0, shared_1.capitalize)(name), start, utils_1.combineLastMapping), `'`);
90
57
  }
91
58
  }
92
59
  function* generateEventExpression(options, ctx, prop) {
@@ -94,18 +61,18 @@ function* generateEventExpression(options, ctx, prop) {
94
61
  let prefix = '(';
95
62
  let suffix = ')';
96
63
  let isFirstMapping = true;
97
- const ast = (0, common_1.createTsAst)(options.ts, prop.exp, prop.exp.content);
64
+ const ast = (0, utils_1.createTsAst)(options.ts, prop.exp, prop.exp.content);
98
65
  const _isCompoundExpression = isCompoundExpression(options.ts, ast);
99
66
  if (_isCompoundExpression) {
100
- yield `(...[$event]) => {${common_1.newLine}`;
67
+ yield `(...[$event]) => {${utils_1.newLine}`;
101
68
  ctx.addLocalVariable('$event');
102
69
  prefix = '';
103
70
  suffix = '';
104
71
  for (const blockCondition of ctx.blockConditions) {
105
- prefix += `if (!(${blockCondition})) return${common_1.endOfLine}`;
72
+ prefix += `if (!(${blockCondition})) return${utils_1.endOfLine}`;
106
73
  }
107
74
  }
108
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, prop.exp.content, prop.exp.loc, prop.exp.loc.start.offset, offset => {
75
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', offset => {
109
76
  if (_isCompoundExpression && isFirstMapping) {
110
77
  isFirstMapping = false;
111
78
  ctx.inlayHints.push({
@@ -122,10 +89,10 @@ function* generateEventExpression(options, ctx, prop) {
122
89
  });
123
90
  }
124
91
  return ctx.codeFeatures.all;
125
- }, prefix, suffix);
92
+ }, prop.exp.content, prop.exp.loc.start.offset, prop.exp.loc, prefix, suffix);
126
93
  if (_isCompoundExpression) {
127
94
  ctx.removeLocalVariable('$event');
128
- yield common_1.endOfLine;
95
+ yield utils_1.endOfLine;
129
96
  yield* ctx.generateAutoImportCompletion();
130
97
  yield `}`;
131
98
  }
@@ -2,8 +2,9 @@ import * as CompilerDOM from '@vue/compiler-dom';
2
2
  import type { Code } from '../../types';
3
3
  import type { TemplateCodegenContext } from './context';
4
4
  import type { TemplateCodegenOptions } from './index';
5
- export declare function generateElementProps(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, props: CompilerDOM.ElementNode['props'], enableCodeFeatures: boolean, propsFailedExps?: {
5
+ export interface FailedPropExpression {
6
6
  node: CompilerDOM.SimpleExpressionNode;
7
7
  prefix: string;
8
8
  suffix: string;
9
- }[]): Generator<Code>;
9
+ }
10
+ export declare function generateElementProps(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, props: CompilerDOM.ElementNode['props'], strictPropsCheck: boolean, enableCodeFeatures: boolean, failedPropExps?: FailedPropExpression[]): Generator<Code>;
@@ -6,13 +6,15 @@ const shared_1 = require("@vue/shared");
6
6
  const minimatch_1 = require("minimatch");
7
7
  const muggle_string_1 = require("muggle-string");
8
8
  const shared_2 = require("../../utils/shared");
9
- const common_1 = require("../common");
10
- const camelized_1 = require("./camelized");
9
+ const inlayHints_1 = require("../inlayHints");
10
+ const utils_1 = require("../utils");
11
+ const camelized_1 = require("../utils/camelized");
12
+ const unicode_1 = require("../utils/unicode");
13
+ const elementDirectives_1 = require("./elementDirectives");
11
14
  const elementEvents_1 = require("./elementEvents");
12
15
  const interpolation_1 = require("./interpolation");
13
16
  const objectProperty_1 = require("./objectProperty");
14
- const inlayHints_1 = require("../inlayHints");
15
- function* generateElementProps(options, ctx, node, props, enableCodeFeatures, propsFailedExps) {
17
+ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enableCodeFeatures, failedPropExps) {
16
18
  const isComponent = node.tagType === CompilerDOM.ElementTypes.COMPONENT;
17
19
  for (const prop of props) {
18
20
  if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
@@ -22,25 +24,26 @@ function* generateElementProps(options, ctx, node, props, enableCodeFeatures, pr
22
24
  && !prop.arg.loc.source.endsWith(']')) {
23
25
  if (!isComponent) {
24
26
  yield `...{ `;
25
- yield* (0, elementEvents_1.generateEventArg)(ctx, prop.arg, true);
27
+ yield* (0, elementEvents_1.generateEventArg)(ctx, prop.arg.loc.source, prop.arg.loc.start.offset);
26
28
  yield `: `;
27
29
  yield* (0, elementEvents_1.generateEventExpression)(options, ctx, prop);
28
- yield `}, `;
30
+ yield `},`;
29
31
  }
30
32
  else {
31
- yield `...{ '${(0, shared_1.camelize)('on-' + prop.arg.loc.source)}': {} as any }, `;
33
+ yield `...{ '${(0, shared_1.camelize)('on-' + prop.arg.loc.source)}': {} as any },`;
32
34
  }
35
+ yield utils_1.newLine;
33
36
  }
34
37
  else if (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
35
38
  && prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
36
39
  && prop.arg.loc.source.startsWith('[')
37
40
  && prop.arg.loc.source.endsWith(']')) {
38
- propsFailedExps?.push({ node: prop.arg, prefix: '(', suffix: ')' });
39
- propsFailedExps?.push({ node: prop.exp, prefix: '() => {', suffix: '}' });
41
+ failedPropExps?.push({ node: prop.arg, prefix: '(', suffix: ')' });
42
+ failedPropExps?.push({ node: prop.exp, prefix: '() => {', suffix: '}' });
40
43
  }
41
44
  else if (!prop.arg
42
45
  && prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
43
- propsFailedExps?.push({ node: prop.exp, prefix: '(', suffix: ')' });
46
+ failedPropExps?.push({ node: prop.exp, prefix: '(', suffix: ')' });
44
47
  }
45
48
  }
46
49
  }
@@ -56,132 +59,101 @@ function* generateElementProps(options, ctx, node, props, enableCodeFeatures, pr
56
59
  : prop.arg.loc.source;
57
60
  }
58
61
  else {
59
- propName = getModelValuePropName(node, options.vueCompilerOptions.target, options.vueCompilerOptions);
62
+ propName = getModelPropName(node, options.vueCompilerOptions);
60
63
  }
61
64
  if (propName === undefined
62
65
  || options.vueCompilerOptions.dataAttributes.some(pattern => (0, minimatch_1.minimatch)(propName, pattern))) {
63
66
  if (prop.exp && prop.exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY) {
64
- propsFailedExps?.push({ node: prop.exp, prefix: '(', suffix: ')' });
67
+ failedPropExps?.push({ node: prop.exp, prefix: '(', suffix: ')' });
65
68
  }
66
69
  continue;
67
70
  }
68
- if (prop.modifiers.some(m => m.content === 'prop' || m.content === 'attr')) {
69
- propName = propName.substring(1);
71
+ if (prop.name === 'bind'
72
+ && prop.modifiers.some(m => m.content === 'prop' || m.content === 'attr')) {
73
+ propName = propName.slice(1);
70
74
  }
71
75
  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));
76
+ const shouldCamelize = isComponent && getShouldCamelize(options, prop, propName);
77
+ const codeInfo = getPropsCodeInfo(ctx, strictPropsCheck, shouldCamelize);
76
78
  if (shouldSpread) {
77
79
  yield `...{ `;
78
80
  }
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]);
81
+ const codes = (0, utils_1.wrapWith)(prop.loc.start.offset, prop.loc.end.offset, ctx.codeFeatures.verification, ...(prop.arg
82
+ ? (0, objectProperty_1.generateObjectProperty)(options, ctx, propName, prop.arg.loc.start.offset, codeInfo, prop.loc.name_2 ??= {}, shouldCamelize)
83
+ : (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, prop.arg?.loc.start.offset === prop.exp?.loc.start.offset, enableCodeFeatures), `)`);
84
+ if (enableCodeFeatures) {
85
+ yield* codes;
105
86
  }
106
87
  else {
107
- yield* codes;
88
+ yield (0, muggle_string_1.toString)([...codes]);
108
89
  }
109
90
  if (shouldSpread) {
110
91
  yield ` }`;
111
92
  }
112
- yield `, `;
93
+ yield `,${utils_1.newLine}`;
94
+ if (prop.name === 'model' && prop.modifiers.length) {
95
+ const propertyName = prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
96
+ ? !prop.arg.isStatic
97
+ ? `[__VLS_tryAsConstant(\`$\{${prop.arg.content}\}Modifiers\`)]`
98
+ : (0, shared_1.camelize)(propName) + `Modifiers`
99
+ : `modelModifiers`;
100
+ const codes = (0, elementDirectives_1.generateModifiers)(options, ctx, prop, propertyName);
101
+ if (enableCodeFeatures) {
102
+ yield* codes;
103
+ }
104
+ else {
105
+ yield (0, muggle_string_1.toString)([...codes]);
106
+ }
107
+ yield utils_1.newLine;
108
+ }
113
109
  }
114
110
  else if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE) {
115
111
  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)
112
+ // Vue 2 Transition doesn't support "persisted" property but `@vue/compiler-dom` always adds it (#3881)
117
113
  || (options.vueCompilerOptions.target < 3
118
114
  && prop.name === 'persisted'
119
115
  && node.tag.toLowerCase() === 'transition')) {
120
116
  continue;
121
117
  }
122
118
  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));
119
+ const shouldCamelize = isComponent && getShouldCamelize(options, prop, prop.name);
120
+ const codeInfo = getPropsCodeInfo(ctx, strictPropsCheck, true);
126
121
  if (shouldSpread) {
127
122
  yield `...{ `;
128
123
  }
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)
124
+ 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
125
+ ? generateAttrValue(prop.value, ctx.codeFeatures.withoutNavigation)
157
126
  : [`true`]), `)`);
158
- if (!enableCodeFeatures) {
159
- yield (0, muggle_string_1.toString)([...codes]);
127
+ if (enableCodeFeatures) {
128
+ yield* codes;
160
129
  }
161
130
  else {
162
- yield* codes;
131
+ yield (0, muggle_string_1.toString)([...codes]);
163
132
  }
164
133
  if (shouldSpread) {
165
134
  yield ` }`;
166
135
  }
167
- yield `, `;
136
+ yield `,${utils_1.newLine}`;
168
137
  }
169
138
  else if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
170
139
  && prop.name === 'bind'
171
140
  && !prop.arg
172
141
  && 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]);
142
+ if (prop.exp.loc.source === '$attrs') {
143
+ if (enableCodeFeatures) {
144
+ ctx.bindingAttrLocs.push(prop.exp.loc);
145
+ }
176
146
  }
177
147
  else {
178
- yield* codes;
148
+ 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, false, enableCodeFeatures));
149
+ if (enableCodeFeatures) {
150
+ yield* codes;
151
+ }
152
+ else {
153
+ yield (0, muggle_string_1.toString)([...codes]);
154
+ }
155
+ yield `,${utils_1.newLine}`;
179
156
  }
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
157
  }
186
158
  }
187
159
  }
@@ -194,16 +166,29 @@ function* generatePropExp(options, ctx, prop, exp, features, isShorthand, enable
194
166
  }
195
167
  if (exp && exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY) { // style='z-index: 2' will compile to {'z-index':'2'}
196
168
  if (!isShorthand) { // vue 3.4+
197
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, exp.loc.source, exp.loc, exp.loc.start.offset, features, '(', ')');
169
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', features, exp.loc.source, exp.loc.start.offset, exp.loc, '(', ')');
198
170
  }
199
171
  else {
200
172
  const propVariableName = (0, shared_1.camelize)(exp.loc.source);
201
- if (common_1.variableNameRegex.test(propVariableName)) {
202
- if (!ctx.hasLocalVariable(propVariableName)) {
173
+ if (utils_1.variableNameRegex.test(propVariableName)) {
174
+ const isDestructuredProp = options.destructuredPropNames?.has(propVariableName) ?? false;
175
+ const isTemplateRef = options.templateRefNames?.has(propVariableName) ?? false;
176
+ const codes = (0, camelized_1.generateCamelized)(exp.loc.source, exp.loc.start.offset, features);
177
+ if (ctx.hasLocalVariable(propVariableName) || isDestructuredProp) {
178
+ yield* codes;
179
+ }
180
+ else {
203
181
  ctx.accessExternalVariable(propVariableName, exp.loc.start.offset);
204
- yield `__VLS_ctx.`;
182
+ if (isTemplateRef) {
183
+ yield `__VLS_unref(`;
184
+ yield* codes;
185
+ yield `)`;
186
+ }
187
+ else {
188
+ yield `__VLS_ctx.`;
189
+ yield* codes;
190
+ }
205
191
  }
206
- yield* (0, camelized_1.generateCamelized)(exp.loc.source, exp.loc.start.offset, features);
207
192
  if (enableCodeFeatures) {
208
193
  ctx.inlayHints.push((0, inlayHints_1.createVBindShorthandInlayHintInfo)(prop.loc, propVariableName));
209
194
  }
@@ -215,45 +200,57 @@ function* generatePropExp(options, ctx, prop, exp, features, isShorthand, enable
215
200
  }
216
201
  }
217
202
  function* generateAttrValue(attrNode, features) {
218
- const char = attrNode.loc.source.startsWith("'") ? "'" : '"';
219
- yield char;
203
+ const quote = attrNode.loc.source.startsWith("'") ? "'" : '"';
204
+ yield quote;
220
205
  let start = attrNode.loc.start.offset;
221
- let end = attrNode.loc.end.offset;
222
206
  let content = attrNode.loc.source;
223
207
  if ((content.startsWith('"') && content.endsWith('"'))
224
208
  || (content.startsWith("'") && content.endsWith("'"))) {
225
209
  start++;
226
- end--;
227
210
  content = content.slice(1, -1);
228
211
  }
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;
212
+ yield* (0, unicode_1.generateUnicode)(content, start, features);
213
+ yield quote;
236
214
  }
237
- function needToUnicode(str) {
238
- return str.includes('\\') || str.includes('\n');
215
+ function getShouldCamelize(options, prop, propName) {
216
+ return (prop.type !== CompilerDOM.NodeTypes.DIRECTIVE
217
+ || !prop.arg
218
+ || (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic))
219
+ && (0, shared_2.hyphenateAttr)(propName) === propName
220
+ && !options.vueCompilerOptions.htmlAttributes.some(pattern => (0, minimatch_1.minimatch)(propName, pattern));
239
221
  }
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('');
222
+ function getPropsCodeInfo(ctx, strictPropsCheck, shouldCamelize) {
223
+ const codeInfo = ctx.codeFeatures.withoutHighlightAndCompletion;
224
+ return {
225
+ ...codeInfo,
226
+ navigation: codeInfo.navigation
227
+ ? {
228
+ resolveRenameNewName: shared_1.camelize,
229
+ resolveRenameEditText: shouldCamelize ? shared_2.hyphenateAttr : undefined,
230
+ }
231
+ : false,
232
+ verification: strictPropsCheck
233
+ ? codeInfo.verification
234
+ : {
235
+ shouldReport(_source, code) {
236
+ if (String(code) === '2353' || String(code) === '2561') {
237
+ return false;
238
+ }
239
+ return typeof codeInfo.verification === 'object'
240
+ ? codeInfo.verification.shouldReport?.(_source, code) ?? true
241
+ : true;
242
+ },
243
+ }
244
+ };
248
245
  }
249
- function getModelValuePropName(node, vueVersion, vueCompilerOptions) {
246
+ function getModelPropName(node, vueCompilerOptions) {
250
247
  for (const modelName in vueCompilerOptions.experimentalModelPropName) {
251
248
  const tags = vueCompilerOptions.experimentalModelPropName[modelName];
252
249
  for (const tag in tags) {
253
250
  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];
251
+ const val = tags[tag];
252
+ if (typeof val === 'object') {
253
+ const arr = Array.isArray(val) ? val : [val];
257
254
  for (const attrs of arr) {
258
255
  let failed = false;
259
256
  for (const attr in attrs) {
@@ -283,6 +280,6 @@ function getModelValuePropName(node, vueVersion, vueCompilerOptions) {
283
280
  }
284
281
  }
285
282
  }
286
- return vueVersion < 3 ? 'value' : 'modelValue';
283
+ return vueCompilerOptions.target < 3 ? 'value' : 'modelValue';
287
284
  }
288
285
  //# sourceMappingURL=elementProps.js.map