@vue/language-core 1.7.11 → 1.7.12

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.
@@ -58,6 +58,7 @@ const transformContext = {
58
58
  expressionPlugins: ['typescript'],
59
59
  };
60
60
  function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourceLang, sfc, hasScriptSetupSlots, codegenStack) {
61
+ const nativeTags = new Set(vueCompilerOptions.nativeTags);
61
62
  const [codes, codeStacks] = codegenStack ? muggle.track([]) : [[], []];
62
63
  const [formatCodes, formatCodeStacks] = codegenStack ? muggle.track([]) : [[], []];
63
64
  const [cssCodes, cssCodeStacks] = codegenStack ? muggle.track([]) : [[], []];
@@ -144,25 +145,24 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
144
145
  }
145
146
  function generateComponentVars() {
146
147
  const data = {};
147
- codes.push(`let __VLS_templateComponents!: __VLS_IntrinsicElements\n`);
148
+ codes.push(`let __VLS_templateComponents!: {}\n`);
148
149
  for (const tagName in tagNames) {
150
+ if (nativeTags.has(tagName))
151
+ continue;
149
152
  const isNamespacedTag = tagName.indexOf('.') >= 0;
150
153
  if (isNamespacedTag)
151
154
  continue;
152
- const varName = validTsVar.test(tagName) ? tagName : (0, shared_1.capitalize)((0, shared_1.camelize)(tagName.replace(/:/g, '-')));
153
- codes.push(`& __VLS_WithComponent<'${varName}', typeof __VLS_components, `,
155
+ const validName = validTsVar.test(tagName) ? tagName : (0, shared_1.capitalize)((0, shared_1.camelize)(tagName.replace(/:/g, '-')));
156
+ codes.push(`& __VLS_WithComponent<'${validName}', typeof __VLS_components, `,
154
157
  // order is important: https://github.com/vuejs/language-tools/issues/2010
155
158
  `"${(0, shared_1.capitalize)((0, shared_1.camelize)(tagName))}", `, `"${(0, shared_1.camelize)(tagName)}", `, `"${tagName}"`, '>\n');
156
- data[tagName] = varName;
159
+ data[tagName] = validName;
157
160
  }
158
161
  codes.push(`;\n`);
159
162
  for (const tagName in tagNames) {
160
- const varName = data[tagName];
161
- if (!varName)
162
- continue;
163
163
  const tagOffsets = tagNames[tagName];
164
164
  const tagRanges = tagOffsets.map(offset => [offset, offset + tagName.length]);
165
- const names = new Set([
165
+ const names = new Set(nativeTags.has(tagName) ? [tagName] : [
166
166
  // order is important: https://github.com/vuejs/language-tools/issues/2010
167
167
  (0, shared_1.capitalize)((0, shared_1.camelize)(tagName)),
168
168
  (0, shared_1.camelize)(tagName),
@@ -170,7 +170,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
170
170
  ]);
171
171
  for (const name of names) {
172
172
  for (const tagRange of tagRanges) {
173
- codes.push(name === tagName ? '__VLS_templateComponents' : '__VLS_components', ...createPropertyAccessCode([
173
+ codes.push(nativeTags.has(tagName) ? '({} as __VLS_IntrinsicElements)' : '__VLS_components', ...createPropertyAccessCode([
174
174
  name,
175
175
  'template',
176
176
  tagRange,
@@ -185,23 +185,26 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
185
185
  }
186
186
  }
187
187
  codes.push('\n');
188
- codes.push('// @ts-ignore\n', // #2304
189
- '[');
190
- for (const tagRange of tagRanges) {
191
- codes.push([
192
- varName,
193
- 'template',
194
- tagRange,
195
- {
196
- completion: {
197
- additional: true,
198
- autoImportOnly: true,
188
+ const validName = data[tagName];
189
+ if (validName) {
190
+ codes.push('// @ts-ignore\n', // #2304
191
+ '[');
192
+ for (const tagRange of tagRanges) {
193
+ codes.push([
194
+ validName,
195
+ 'template',
196
+ tagRange,
197
+ {
198
+ completion: {
199
+ additional: true,
200
+ autoImportOnly: true,
201
+ },
199
202
  },
200
- },
201
- ]);
202
- codes.push(',');
203
+ ]);
204
+ codes.push(',');
205
+ }
206
+ codes.push(`];\n`);
203
207
  }
204
- codes.push(`];\n`);
205
208
  }
206
209
  return data;
207
210
  }
@@ -474,7 +477,16 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
474
477
  }
475
478
  }
476
479
  }
477
- if (isNamespacedTag) {
480
+ const isIntrinsicElement = nativeTags.has(tag) && tagOffsets.length;
481
+ if (isIntrinsicElement) {
482
+ codes.push('const ', var_originalComponent, ` = ({} as __VLS_IntrinsicElements)[`, ...createStringLiteralKeyCode([
483
+ tag,
484
+ 'template',
485
+ tagOffsets[0],
486
+ capabilitiesPresets.diagnosticOnly,
487
+ ]), '];\n');
488
+ }
489
+ else if (isNamespacedTag) {
478
490
  codes.push(`const ${var_originalComponent} = `, ...createInterpolationCode(tag, node.loc, startTagOffset, capabilitiesPresets.all, '', ''), ';\n');
479
491
  }
480
492
  else if (dynamicTagExp) {
@@ -486,7 +498,14 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
486
498
  else {
487
499
  codes.push(`const ${var_originalComponent} = {} as any;\n`);
488
500
  }
489
- codes.push(`const ${var_functionalComponent} = __VLS_asFunctionalComponent(`, `${var_originalComponent}, `, `new ${var_originalComponent}({`, ...createPropsCode(node, props, 'extraReferences'), '}));\n');
501
+ codes.push(`const ${var_functionalComponent} = __VLS_asFunctionalComponent(`, `${var_originalComponent}, `);
502
+ if (isIntrinsicElement) {
503
+ codes.push('{}');
504
+ }
505
+ else {
506
+ codes.push(`new ${var_originalComponent}({`, ...createPropsCode(node, props, 'extraReferences'), '})');
507
+ }
508
+ codes.push(');\n');
490
509
  for (const offset of tagOffsets) {
491
510
  if (isNamespacedTag) {
492
511
  continue;
@@ -495,7 +514,10 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
495
514
  continue;
496
515
  }
497
516
  else {
498
- if (componentVars[tag]) {
517
+ if (isIntrinsicElement) {
518
+ codes.push(`({} as __VLS_IntrinsicElements).`);
519
+ }
520
+ else {
499
521
  codes.push(`__VLS_templateComponents.`);
500
522
  }
501
523
  codes.push([
@@ -661,9 +683,11 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
661
683
  {
662
684
  ...capabilitiesPresets.attrReference,
663
685
  rename: {
686
+ // @click-outside -> onClickOutside
664
687
  normalize(newName) {
665
688
  return (0, shared_1.camelize)('on-' + newName);
666
689
  },
690
+ // onClickOutside -> @click-outside
667
691
  apply(newName) {
668
692
  const hName = (0, shared_1.hyphenate)(newName);
669
693
  if ((0, shared_1.hyphenate)(newName).startsWith('on-')) {
@@ -805,14 +829,12 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
805
829
  }
806
830
  continue;
807
831
  }
808
- const isStatic = !prop.arg || (prop.arg.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */ && prop.arg.isStatic);
809
- const propName = isStatic
832
+ let camelized = false;
833
+ if ((!prop.arg || (prop.arg.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */ && prop.arg.isStatic)) // isStatic
810
834
  && (0, shared_1.hyphenate)(attrNameText) === attrNameText
811
- && !vueCompilerOptions.htmlAttributes.some(pattern => (0, minimatch_1.minimatch)(attrNameText, pattern))
812
- ? (0, shared_1.camelize)(attrNameText)
813
- : attrNameText;
814
- if (vueCompilerOptions.strictTemplates) {
815
- attrNameText = propName;
835
+ && !vueCompilerOptions.htmlAttributes.some(pattern => (0, minimatch_1.minimatch)(attrNameText, pattern))) {
836
+ attrNameText = (0, shared_1.camelize)(attrNameText);
837
+ camelized = true;
816
838
  }
817
839
  // camelize name
818
840
  codes.push([
@@ -831,28 +853,28 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
831
853
  }
832
854
  else if (prop.exp?.constType === 3 /* CompilerDOM.ConstantTypes.CAN_STRINGIFY */) {
833
855
  codes.push(...createObjectPropertyCode([
834
- propName,
856
+ attrNameText,
835
857
  'template',
836
858
  [prop.arg.loc.start.offset, prop.arg.loc.start.offset + attrNameText.length],
837
859
  {
838
860
  ...caps_attr,
839
861
  rename: {
840
862
  normalize: shared_1.camelize,
841
- apply: getRenameApply(attrNameText),
863
+ apply: camelized ? shared_1.hyphenate : noEditApply,
842
864
  },
843
865
  },
844
866
  ], prop.loc.name_2 ?? (prop.loc.name_2 = {})));
845
867
  }
846
868
  else {
847
869
  codes.push(...createObjectPropertyCode([
848
- propName,
870
+ attrNameText,
849
871
  'template',
850
872
  [prop.arg.loc.start.offset, prop.arg.loc.end.offset],
851
873
  {
852
874
  ...caps_attr,
853
875
  rename: {
854
876
  normalize: shared_1.camelize,
855
- apply: getRenameApply(attrNameText),
877
+ apply: camelized ? shared_1.hyphenate : noEditApply,
856
878
  },
857
879
  },
858
880
  ], prop.loc.name_2 ?? (prop.loc.name_2 = {})));
@@ -875,30 +897,6 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
875
897
  caps_diagnosticOnly,
876
898
  ]);
877
899
  codes.push(', ');
878
- // original name
879
- if (prop.arg && attrNameText !== propName) {
880
- codes.push(...createObjectPropertyCode([
881
- attrNameText,
882
- 'template',
883
- [prop.arg.loc.start.offset, prop.arg.loc.end.offset],
884
- {
885
- ...caps_attr,
886
- rename: {
887
- normalize: shared_1.camelize,
888
- apply: getRenameApply(attrNameText),
889
- },
890
- },
891
- ], prop.loc.name_1 ?? (prop.loc.name_1 = {})));
892
- codes.push(': (');
893
- if (prop.exp) {
894
- codes.push(...createInterpolationCode(prop.exp.loc.source, prop.exp.loc, undefined, undefined, '(', ')'));
895
- }
896
- else {
897
- codes.push('undefined');
898
- }
899
- codes.push(')');
900
- codes.push(', ');
901
- }
902
900
  }
903
901
  else if (prop.type === 6 /* CompilerDOM.NodeTypes.ATTRIBUTE */) {
904
902
  let attrNameText = prop.name;
package/out/types.d.ts CHANGED
@@ -14,6 +14,7 @@ export interface VueCompilerOptions {
14
14
  jsxSlots: boolean;
15
15
  strictTemplates: boolean;
16
16
  skipTemplateCodegen: boolean;
17
+ nativeTags: string[];
17
18
  dataAttributes: string[];
18
19
  htmlAttributes: string[];
19
20
  optionsWrapper: [string, string] | [];
@@ -11,21 +11,17 @@ type __VLS_IntrinsicElements = __VLS_PickNotAny<import('vue/jsx-runtime').JSX.In
11
11
  type __VLS_Element = __VLS_PickNotAny<import('vue/jsx-runtime').JSX.Element, JSX.Element>;
12
12
 
13
13
  type __VLS_IsAny<T> = boolean extends (T extends never ? true : false) ? true : false;
14
- type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
14
+ type __VLS_PickNotAny<A, B> = __VLS_IsAny<A & {}> extends true ? B : A; // & {} for https://github.com/microsoft/TypeScript/issues/54630
15
15
 
16
16
  type __VLS_Prettify<T> = {
17
17
  [K in keyof T]: T[K];
18
18
  } & {};
19
19
 
20
20
  type __VLS_GlobalComponents =
21
- // @ts-ignore
22
21
  __VLS_PickNotAny<import('vue').GlobalComponents, {}>
23
- // @ts-ignore
24
22
  & __VLS_PickNotAny<import('@vue/runtime-core').GlobalComponents, {}>
25
- // @ts-ignore
26
23
  & __VLS_PickNotAny<import('@vue/runtime-dom').GlobalComponents, {}>
27
24
  & Pick<typeof import('${vueCompilerOptions.lib}'),
28
- // @ts-ignore
29
25
  'Transition'
30
26
  | 'TransitionGroup'
31
27
  | 'KeepAlive'
package/out/utils/ts.js CHANGED
@@ -153,6 +153,27 @@ function getPartialVueCompilerOptions(ts, tsConfigSourceFile) {
153
153
  }
154
154
  }
155
155
  }
156
+ // https://developer.mozilla.org/en-US/docs/Web/HTML/Element
157
+ const HTML_TAGS = 'html,body,base,head,link,meta,style,title,address,article,aside,footer,' +
158
+ 'header,hgroup,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,' +
159
+ 'figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,' +
160
+ 'data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,' +
161
+ 'time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,' +
162
+ 'canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,' +
163
+ 'th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,' +
164
+ 'option,output,progress,select,textarea,details,dialog,menu,' +
165
+ 'summary,template,blockquote,iframe,tfoot';
166
+ // https://developer.mozilla.org/en-US/docs/Web/SVG/Element
167
+ const SVG_TAGS = 'svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,' +
168
+ 'defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer,' +
169
+ 'feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,' +
170
+ 'feDistanceLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,' +
171
+ 'feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,' +
172
+ 'fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,' +
173
+ 'foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,' +
174
+ 'mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,' +
175
+ 'polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,' +
176
+ 'text,textPath,title,tspan,unknown,use,view';
156
177
  function resolveVueCompilerOptions(vueOptions) {
157
178
  const target = vueOptions.target ?? 3.3;
158
179
  const lib = vueOptions.lib || (target < 2.7 ? '@vue/runtime-dom' : 'vue');
@@ -164,6 +185,14 @@ function resolveVueCompilerOptions(vueOptions) {
164
185
  jsxSlots: vueOptions.jsxSlots ?? false,
165
186
  strictTemplates: vueOptions.strictTemplates ?? false,
166
187
  skipTemplateCodegen: vueOptions.skipTemplateCodegen ?? false,
188
+ nativeTags: vueOptions.nativeTags ?? [...new Set([
189
+ ...HTML_TAGS.split(','),
190
+ ...SVG_TAGS.split(','),
191
+ // fix https://github.com/johnsoncodehk/volar/issues/1340
192
+ 'hgroup',
193
+ 'slot',
194
+ 'component',
195
+ ])],
167
196
  dataAttributes: vueOptions.dataAttributes ?? [],
168
197
  htmlAttributes: vueOptions.htmlAttributes ?? ['aria-*'],
169
198
  optionsWrapper: vueOptions.optionsWrapper ?? (target >= 2.7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-core",
3
- "version": "1.7.11",
3
+ "version": "1.7.12",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -34,5 +34,5 @@
34
34
  "optional": true
35
35
  }
36
36
  },
37
- "gitHead": "8ed51477115bf67f73eb74653b2770e5d9d586f0"
37
+ "gitHead": "9e712c2d603c690cd03502f5ec1a99bd80b800ac"
38
38
  }