vue-component-meta 3.0.0-alpha.0 → 3.0.0-alpha.10

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 (2) hide show
  1. package/lib/base.js +41 -14
  2. package/package.json +5 -5
package/lib/base.js CHANGED
@@ -21,7 +21,6 @@ const typescript_1 = require("@volar/typescript");
21
21
  const vue = require("@vue/language-core");
22
22
  const path_browserify_1 = require("path-browserify");
23
23
  const vue_component_type_helpers_1 = require("vue-component-type-helpers");
24
- const vue2_1 = require("vue-component-type-helpers/vue2");
25
24
  __exportStar(require("./types"), exports);
26
25
  const windowsPathReg = /\\/g;
27
26
  function createCheckerByJsonConfigBase(ts, rootDir, json, checkerOptions = {}) {
@@ -189,7 +188,7 @@ interface ComponentMeta<T> {
189
188
  exposed: ComponentExposed<T>;
190
189
  };
191
190
 
192
- ${commandLine.vueOptions.target < 3 ? vue2_1.code : vue_component_type_helpers_1.code}
191
+ ${vue_component_type_helpers_1.code}
193
192
  `.trim();
194
193
  return code;
195
194
  }
@@ -240,7 +239,7 @@ ${commandLine.vueOptions.target < 3 ? vue2_1.code : vue_component_type_helpers_1
240
239
  }
241
240
  function getProps() {
242
241
  const $props = symbolProperties.find(prop => prop.escapedName === 'props');
243
- const propEventRegex = /^(on[A-Z])/;
242
+ const vnodeEventRegex = /^onVnode[A-Z]/;
244
243
  let result = [];
245
244
  if ($props) {
246
245
  const type = typeChecker.getTypeOfSymbolAtLocation($props, symbolNode);
@@ -250,7 +249,7 @@ ${commandLine.vueOptions.target < 3 ? vue2_1.code : vue_component_type_helpers_1
250
249
  const { resolveNestedProperties, } = createSchemaResolvers(typeChecker, symbolNode, checkerOptions, ts, language);
251
250
  return resolveNestedProperties(prop);
252
251
  })
253
- .filter(prop => !propEventRegex.test(prop.name));
252
+ .filter(prop => !vnodeEventRegex.test(prop.name));
254
253
  }
255
254
  // fill global
256
255
  if (componentPath !== globalComponentName) {
@@ -356,7 +355,7 @@ ${commandLine.vueOptions.target < 3 ? vue2_1.code : vue_component_type_helpers_1
356
355
  function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: options, noDeclarations }, ts, language) {
357
356
  const visited = new Set();
358
357
  function shouldIgnore(subtype) {
359
- const name = typeChecker.typeToString(subtype);
358
+ const name = getFullyQualifiedName(subtype);
360
359
  if (name === 'any') {
361
360
  return true;
362
361
  }
@@ -395,7 +394,7 @@ function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: optio
395
394
  text: tag.text !== undefined ? ts.displayPartsToString(tag.text) : undefined,
396
395
  })),
397
396
  required: !(prop.flags & ts.SymbolFlags.Optional),
398
- type: typeChecker.typeToString(subtype),
397
+ type: getFullyQualifiedName(subtype),
399
398
  rawType: rawType ? subtype : undefined,
400
399
  get declarations() {
401
400
  return declarations ??= getDeclarations(prop.declarations ?? []);
@@ -414,7 +413,7 @@ function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: optio
414
413
  let declarations;
415
414
  return {
416
415
  name: prop.getName(),
417
- type: typeChecker.typeToString(subtype),
416
+ type: getFullyQualifiedName(subtype),
418
417
  rawType: rawType ? subtype : undefined,
419
418
  description: ts.displayPartsToString(prop.getDocumentationComment(typeChecker)),
420
419
  get declarations() {
@@ -431,7 +430,7 @@ function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: optio
431
430
  let declarations;
432
431
  return {
433
432
  name: expose.getName(),
434
- type: typeChecker.typeToString(subtype),
433
+ type: getFullyQualifiedName(subtype),
435
434
  rawType: rawType ? subtype : undefined,
436
435
  description: ts.displayPartsToString(expose.getDocumentationComment(typeChecker)),
437
436
  get declarations() {
@@ -443,9 +442,32 @@ function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: optio
443
442
  };
444
443
  }
445
444
  function resolveEventSignature(call) {
446
- const subtype = typeChecker.getTypeOfSymbolAtLocation(call.parameters[1], symbolNode);
447
445
  let schema;
448
446
  let declarations;
447
+ let subtype = undefined;
448
+ let subtypeStr = '[]';
449
+ let getSchema = () => [];
450
+ if (call.parameters.length >= 2) {
451
+ subtype = typeChecker.getTypeOfSymbolAtLocation(call.parameters[1], symbolNode);
452
+ if (call.parameters[1].valueDeclaration?.dotDotDotToken) {
453
+ subtypeStr = getFullyQualifiedName(subtype);
454
+ getSchema = () => typeChecker.getTypeArguments(subtype).map(resolveSchema);
455
+ }
456
+ else {
457
+ subtypeStr = '[';
458
+ for (let i = 1; i < call.parameters.length; i++) {
459
+ subtypeStr += getFullyQualifiedName(typeChecker.getTypeOfSymbolAtLocation(call.parameters[i], symbolNode)) + ', ';
460
+ }
461
+ subtypeStr = subtypeStr.slice(0, -2) + ']';
462
+ getSchema = () => {
463
+ const result = [];
464
+ for (let i = 1; i < call.parameters.length; i++) {
465
+ result.push(resolveSchema(typeChecker.getTypeOfSymbolAtLocation(call.parameters[i], symbolNode)));
466
+ }
467
+ return result;
468
+ };
469
+ }
470
+ }
449
471
  return {
450
472
  name: typeChecker.getTypeOfSymbolAtLocation(call.parameters[0], symbolNode).value,
451
473
  description: ts.displayPartsToString(call.getDocumentationComment(typeChecker)),
@@ -453,14 +475,14 @@ function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: optio
453
475
  name: tag.name,
454
476
  text: tag.text !== undefined ? ts.displayPartsToString(tag.text) : undefined,
455
477
  })),
456
- type: typeChecker.typeToString(subtype),
478
+ type: subtypeStr,
457
479
  rawType: rawType ? subtype : undefined,
458
480
  signature: typeChecker.signatureToString(call),
459
481
  get declarations() {
460
482
  return declarations ??= call.declaration ? getDeclarations([call.declaration]) : [];
461
483
  },
462
484
  get schema() {
463
- return schema ??= typeChecker.getTypeArguments(subtype).map(resolveSchema);
485
+ return schema ??= getSchema();
464
486
  },
465
487
  };
466
488
  }
@@ -479,7 +501,7 @@ function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: optio
479
501
  };
480
502
  }
481
503
  function resolveSchema(subtype) {
482
- const type = typeChecker.typeToString(subtype);
504
+ const type = getFullyQualifiedName(subtype);
483
505
  if (shouldIgnore(subtype)) {
484
506
  return type;
485
507
  }
@@ -494,7 +516,6 @@ function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: optio
494
516
  },
495
517
  };
496
518
  }
497
- // @ts-ignore - typescript internal, isArrayLikeType exists
498
519
  else if (typeChecker.isArrayLikeType(subtype)) {
499
520
  let schema;
500
521
  return {
@@ -521,6 +542,13 @@ function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: optio
521
542
  }
522
543
  return type;
523
544
  }
545
+ function getFullyQualifiedName(type) {
546
+ const str = typeChecker.typeToString(type, undefined, ts.TypeFormatFlags.UseFullyQualifiedType | ts.TypeFormatFlags.NoTruncation);
547
+ if (str.includes('import(')) {
548
+ return str.replace(/import\(.*?\)\./g, '');
549
+ }
550
+ return str;
551
+ }
524
552
  function getDeclarations(declaration) {
525
553
  if (noDeclarations) {
526
554
  return [];
@@ -676,7 +704,6 @@ function readTsComponentDefaultProps(ast, exportName, printer, ts) {
676
704
  return component;
677
705
  }
678
706
  // export default defineComponent({ ... })
679
- // export default Vue.extend({ ... })
680
707
  else if (ts.isCallExpression(component)) {
681
708
  if (component.arguments.length) {
682
709
  const arg = component.arguments[0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-component-meta",
3
- "version": "3.0.0-alpha.0",
3
+ "version": "3.0.0-alpha.10",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -13,10 +13,10 @@
13
13
  "directory": "packages/component-meta"
14
14
  },
15
15
  "dependencies": {
16
- "@volar/typescript": "~2.4.11",
17
- "@vue/language-core": "3.0.0-alpha.0",
16
+ "@volar/typescript": "~2.4.13",
17
+ "@vue/language-core": "3.0.0-alpha.10",
18
18
  "path-browserify": "^1.0.1",
19
- "vue-component-type-helpers": "3.0.0-alpha.0"
19
+ "vue-component-type-helpers": "3.0.0-alpha.10"
20
20
  },
21
21
  "peerDependencies": {
22
22
  "typescript": "*"
@@ -30,5 +30,5 @@
30
30
  "@types/node": "^22.10.4",
31
31
  "@types/path-browserify": "^1.0.1"
32
32
  },
33
- "gitHead": "4b49cbe09097e482def4603b90f6c3b93bb2e913"
33
+ "gitHead": "28308b4f76cc80c7632f39ae7e0944f1889661a2"
34
34
  }