@vue/compiler-sfc 3.3.0-alpha.11 → 3.3.0-alpha.13

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.
@@ -15876,6 +15876,7 @@ function resolveTypeElements(ctx, node, scope) {
15876
15876
  );
15877
15877
  }
15878
15878
  function innerResolveTypeElements(ctx, node, scope) {
15879
+ var _a, _b;
15879
15880
  switch (node.type) {
15880
15881
  case "TSTypeLiteral":
15881
15882
  return typeElementsToMap(ctx, node.members, scope);
@@ -15904,22 +15905,65 @@ function innerResolveTypeElements(ctx, node, scope) {
15904
15905
  }
15905
15906
  case "TSExpressionWithTypeArguments":
15906
15907
  case "TSTypeReference": {
15908
+ const typeName = getReferenceName(node);
15909
+ if (typeName === "ExtractPropTypes" && node.typeParameters && ((_a = scope.imports[typeName]) == null ? void 0 : _a.source) === "vue") {
15910
+ return resolveExtractPropTypes(
15911
+ resolveTypeElements(ctx, node.typeParameters.params[0], scope),
15912
+ scope
15913
+ );
15914
+ }
15907
15915
  const resolved = resolveTypeReference(ctx, node, scope);
15908
15916
  if (resolved) {
15909
15917
  return resolveTypeElements(ctx, resolved, resolved._ownerScope);
15910
15918
  } else {
15911
- const typeName = getReferenceName(node);
15912
- if (typeof typeName === "string" && // @ts-ignore
15913
- SupportedBuiltinsSet.has(typeName)) {
15914
- return resolveBuiltin(ctx, node, typeName, scope);
15919
+ if (typeof typeName === "string") {
15920
+ if (
15921
+ // @ts-ignore
15922
+ SupportedBuiltinsSet.has(typeName)
15923
+ ) {
15924
+ return resolveBuiltin(ctx, node, typeName, scope);
15925
+ } else if (typeName === "ReturnType" && node.typeParameters) {
15926
+ const ret = resolveReturnType(
15927
+ ctx,
15928
+ node.typeParameters.params[0],
15929
+ scope
15930
+ );
15931
+ if (ret) {
15932
+ return resolveTypeElements(ctx, ret, scope);
15933
+ }
15934
+ }
15915
15935
  }
15916
15936
  return ctx.error(
15917
- `Unresolvable type reference or unsupported built-in utlility type`,
15937
+ `Unresolvable type reference or unsupported built-in utility type`,
15918
15938
  node,
15919
15939
  scope
15920
15940
  );
15921
15941
  }
15922
15942
  }
15943
+ case "TSImportType": {
15944
+ if (getId(node.argument) === "vue" && ((_b = node.qualifier) == null ? void 0 : _b.type) === "Identifier" && node.qualifier.name === "ExtractPropTypes" && node.typeParameters) {
15945
+ return resolveExtractPropTypes(
15946
+ resolveTypeElements(ctx, node.typeParameters.params[0], scope),
15947
+ scope
15948
+ );
15949
+ }
15950
+ const sourceScope = importSourceToScope(
15951
+ ctx,
15952
+ node.argument,
15953
+ scope,
15954
+ node.argument.value
15955
+ );
15956
+ const resolved = resolveTypeReference(ctx, node, sourceScope);
15957
+ if (resolved) {
15958
+ return resolveTypeElements(ctx, resolved, resolved._ownerScope);
15959
+ }
15960
+ }
15961
+ case "TSTypeQuery": {
15962
+ const resolved = resolveTypeReference(ctx, node, scope);
15963
+ if (resolved) {
15964
+ return resolveTypeElements(ctx, resolved, resolved._ownerScope);
15965
+ }
15966
+ }
15923
15967
  }
15924
15968
  return ctx.error(`Unresolvable type: ${node.type}`, node, scope);
15925
15969
  }
@@ -15965,7 +16009,8 @@ function mergeElements(maps, type) {
15965
16009
  // @ts-ignore
15966
16010
  types: [baseProps[key], props[key]]
15967
16011
  },
15968
- baseProps[key]._ownerScope
16012
+ baseProps[key]._ownerScope,
16013
+ baseProps[key].optional || props[key].optional
15969
16014
  );
15970
16015
  }
15971
16016
  }
@@ -15975,11 +16020,12 @@ function mergeElements(maps, type) {
15975
16020
  }
15976
16021
  return res;
15977
16022
  }
15978
- function createProperty(key, typeAnnotation, scope) {
16023
+ function createProperty(key, typeAnnotation, scope, optional) {
15979
16024
  return {
15980
16025
  type: "TSPropertySignature",
15981
16026
  key,
15982
16027
  kind: "get",
16028
+ optional,
15983
16029
  typeAnnotation: {
15984
16030
  type: "TSTypeAnnotation",
15985
16031
  typeAnnotation
@@ -16011,7 +16057,8 @@ function resolveMappedType(ctx, node, scope) {
16011
16057
  name: key
16012
16058
  },
16013
16059
  node.typeAnnotation,
16014
- scope
16060
+ scope,
16061
+ !!node.optional
16015
16062
  );
16016
16063
  }
16017
16064
  return res;
@@ -16194,47 +16241,49 @@ function innerResolveTypeReference(ctx, scope, name, node, onlyExported) {
16194
16241
  if (scope.imports[name]) {
16195
16242
  return resolveTypeFromImport(ctx, node, name, scope);
16196
16243
  } else {
16197
- const types = onlyExported ? scope.exportedTypes : scope.types;
16198
- if (types[name]) {
16199
- return types[name];
16244
+ const lookupSource = node.type === "TSTypeQuery" ? onlyExported ? scope.exportedDeclares : scope.declares : onlyExported ? scope.exportedTypes : scope.types;
16245
+ if (lookupSource[name]) {
16246
+ return lookupSource[name];
16200
16247
  } else {
16201
16248
  const globalScopes = resolveGlobalScope(ctx);
16202
16249
  if (globalScopes) {
16203
16250
  for (const s of globalScopes) {
16204
- if (s.types[name]) {
16251
+ const src = node.type === "TSTypeQuery" ? s.declares : s.types;
16252
+ if (src[name]) {
16205
16253
  (ctx.deps || (ctx.deps = /* @__PURE__ */ new Set())).add(s.filename);
16206
- return s.types[name];
16254
+ return src[name];
16207
16255
  }
16208
16256
  }
16209
16257
  }
16210
16258
  }
16211
16259
  }
16212
16260
  } else {
16213
- const ns = innerResolveTypeReference(
16214
- ctx,
16215
- scope,
16216
- name[0],
16217
- node,
16218
- onlyExported
16219
- );
16220
- if (ns && ns.type === "TSModuleDeclaration") {
16221
- const childScope = moduleDeclToScope(ns, scope);
16222
- return innerResolveTypeReference(
16223
- ctx,
16224
- childScope,
16225
- name.length > 2 ? name.slice(1) : name[name.length - 1],
16226
- node,
16227
- !ns.declare
16228
- );
16261
+ let ns = innerResolveTypeReference(ctx, scope, name[0], node, onlyExported);
16262
+ if (ns) {
16263
+ if (ns.type !== "TSModuleDeclaration") {
16264
+ ns = ns._ns;
16265
+ }
16266
+ if (ns) {
16267
+ const childScope = moduleDeclToScope(ctx, ns, ns._ownerScope || scope);
16268
+ return innerResolveTypeReference(
16269
+ ctx,
16270
+ childScope,
16271
+ name.length > 2 ? name.slice(1) : name[name.length - 1],
16272
+ node,
16273
+ !ns.declare
16274
+ );
16275
+ }
16229
16276
  }
16230
16277
  }
16231
16278
  }
16232
16279
  function getReferenceName(node) {
16233
- const ref = node.type === "TSTypeReference" ? node.typeName : node.expression;
16234
- if (ref.type === "Identifier") {
16280
+ const ref = node.type === "TSTypeReference" ? node.typeName : node.type === "TSExpressionWithTypeArguments" ? node.expression : node.type === "TSImportType" ? node.qualifier : node.exprName;
16281
+ if ((ref == null ? void 0 : ref.type) === "Identifier") {
16235
16282
  return ref.name;
16236
- } else {
16283
+ } else if ((ref == null ? void 0 : ref.type) === "TSQualifiedName") {
16237
16284
  return qualifiedNameToPath(ref);
16285
+ } else {
16286
+ return "default";
16238
16287
  }
16239
16288
  }
16240
16289
  function qualifiedNameToPath(node) {
@@ -16251,7 +16300,7 @@ function resolveGlobalScope(ctx) {
16251
16300
  throw new Error("[vue/compiler-sfc] globalTypeFiles requires fs access.");
16252
16301
  }
16253
16302
  return ctx.options.globalTypeFiles.map(
16254
- (file) => fileToScope(normalizePath(file), fs, ctx.options.babelParserPlugins, true)
16303
+ (file) => fileToScope(ctx, normalizePath(file), true)
16255
16304
  );
16256
16305
  }
16257
16306
  }
@@ -16260,46 +16309,39 @@ function registerTS(_ts) {
16260
16309
  ts = _ts;
16261
16310
  }
16262
16311
  function resolveTypeFromImport(ctx, node, name, scope) {
16312
+ const { source, imported } = scope.imports[name];
16313
+ const sourceScope = importSourceToScope(ctx, node, scope, source);
16314
+ return resolveTypeReference(ctx, node, sourceScope, imported, true);
16315
+ }
16316
+ function importSourceToScope(ctx, node, scope, source) {
16263
16317
  const fs = ctx.options.fs || (ts == null ? void 0 : ts.sys);
16264
16318
  if (!fs) {
16265
16319
  ctx.error(
16266
16320
  `No fs option provided to \`compileScript\` in non-Node environment. File system access is required for resolving imported types.`,
16267
- node
16321
+ node,
16322
+ scope
16268
16323
  );
16269
16324
  }
16270
- const containingFile = scope.filename;
16271
- const { source, imported } = scope.imports[name];
16272
16325
  let resolved;
16273
16326
  if (source.startsWith(".")) {
16274
- const filename = path$2.join(containingFile, "..", source);
16327
+ const filename = path$2.join(scope.filename, "..", source);
16275
16328
  resolved = resolveExt(filename, fs);
16276
16329
  } else {
16277
16330
  if (!ts) {
16278
16331
  ctx.error(
16279
- `Failed to resolve type ${imported} from module ${JSON.stringify(
16280
- source
16281
- )}. typescript is required as a peer dep for vue in order to support resolving types from module imports.`,
16332
+ `Failed to resolve import source ${JSON.stringify(source)}. typescript is required as a peer dep for vue in order to support resolving types from module imports.`,
16282
16333
  node,
16283
16334
  scope
16284
16335
  );
16285
16336
  }
16286
- resolved = resolveWithTS(containingFile, source, fs);
16337
+ resolved = resolveWithTS(scope.filename, source, fs);
16287
16338
  }
16288
16339
  if (resolved) {
16289
- resolved = normalizePath(resolved);
16290
16340
  (ctx.deps || (ctx.deps = /* @__PURE__ */ new Set())).add(resolved);
16291
- return resolveTypeReference(
16292
- ctx,
16293
- node,
16294
- fileToScope(resolved, fs, ctx.options.babelParserPlugins),
16295
- imported,
16296
- true
16297
- );
16341
+ return fileToScope(ctx, normalizePath(resolved));
16298
16342
  } else {
16299
- ctx.error(
16300
- `Failed to resolve import source ${JSON.stringify(
16301
- source
16302
- )} for type ${name}`,
16343
+ return ctx.error(
16344
+ `Failed to resolve import source ${JSON.stringify(source)}.`,
16303
16345
  node,
16304
16346
  scope
16305
16347
  );
@@ -16349,25 +16391,29 @@ function resolveWithTS(containingFile, source, fs) {
16349
16391
  }
16350
16392
  const fileToScopeCache = createCache();
16351
16393
  function invalidateTypeCache(filename) {
16394
+ filename = normalizePath(filename);
16352
16395
  fileToScopeCache.delete(filename);
16353
16396
  tsConfigCache.delete(filename);
16354
16397
  }
16355
- function fileToScope(filename, fs, parserPlugins, asGlobal = false) {
16398
+ function fileToScope(ctx, filename, asGlobal = false) {
16356
16399
  const cached = fileToScopeCache.get(filename);
16357
16400
  if (cached) {
16358
16401
  return cached;
16359
16402
  }
16403
+ const fs = ctx.options.fs || (ts == null ? void 0 : ts.sys);
16360
16404
  const source = fs.readFile(filename) || "";
16361
- const body = parseFile(filename, source, parserPlugins);
16405
+ const body = parseFile(filename, source, ctx.options.babelParserPlugins);
16362
16406
  const scope = {
16363
16407
  filename,
16364
16408
  source,
16365
16409
  offset: 0,
16366
16410
  imports: recordImports(body),
16367
16411
  types: /* @__PURE__ */ Object.create(null),
16368
- exportedTypes: /* @__PURE__ */ Object.create(null)
16412
+ exportedTypes: /* @__PURE__ */ Object.create(null),
16413
+ declares: /* @__PURE__ */ Object.create(null),
16414
+ exportedDeclares: /* @__PURE__ */ Object.create(null)
16369
16415
  };
16370
- recordTypes(body, scope, asGlobal);
16416
+ recordTypes(ctx, body, scope, asGlobal);
16371
16417
  fileToScopeCache.set(filename, scope);
16372
16418
  return scope;
16373
16419
  }
@@ -16412,48 +16458,60 @@ function ctxToScope(ctx) {
16412
16458
  offset: "startOffset" in ctx ? ctx.startOffset : 0,
16413
16459
  imports: "userImports" in ctx ? Object.create(ctx.userImports) : recordImports(body),
16414
16460
  types: /* @__PURE__ */ Object.create(null),
16415
- exportedTypes: /* @__PURE__ */ Object.create(null)
16461
+ exportedTypes: /* @__PURE__ */ Object.create(null),
16462
+ declares: /* @__PURE__ */ Object.create(null),
16463
+ exportedDeclares: /* @__PURE__ */ Object.create(null)
16416
16464
  };
16417
- recordTypes(body, scope);
16465
+ recordTypes(ctx, body, scope);
16418
16466
  return ctx.scope = scope;
16419
16467
  }
16420
- function moduleDeclToScope(node, parentScope) {
16468
+ function moduleDeclToScope(ctx, node, parentScope) {
16421
16469
  if (node._resolvedChildScope) {
16422
16470
  return node._resolvedChildScope;
16423
16471
  }
16424
16472
  const scope = {
16425
16473
  ...parentScope,
16474
+ imports: Object.create(parentScope.imports),
16426
16475
  types: Object.create(parentScope.types),
16427
- imports: Object.create(parentScope.imports)
16476
+ declares: Object.create(parentScope.declares),
16477
+ exportedTypes: /* @__PURE__ */ Object.create(null),
16478
+ exportedDeclares: /* @__PURE__ */ Object.create(null)
16428
16479
  };
16429
- recordTypes(node.body.body, scope);
16480
+ if (node.body.type === "TSModuleDeclaration") {
16481
+ const decl = node.body;
16482
+ decl._ownerScope = scope;
16483
+ const id = getId(decl.id);
16484
+ scope.types[id] = scope.exportedTypes[id] = decl;
16485
+ } else {
16486
+ recordTypes(ctx, node.body.body, scope);
16487
+ }
16430
16488
  return node._resolvedChildScope = scope;
16431
16489
  }
16432
16490
  const importExportRE = /^Import|^Export/;
16433
- function recordTypes(body, scope, asGlobal = false) {
16434
- const { types, exportedTypes, imports } = scope;
16491
+ function recordTypes(ctx, body, scope, asGlobal = false) {
16492
+ const { types, declares, exportedTypes, exportedDeclares, imports } = scope;
16435
16493
  const isAmbient = asGlobal ? !body.some((s) => importExportRE.test(s.type)) : false;
16436
16494
  for (const stmt of body) {
16437
16495
  if (asGlobal) {
16438
16496
  if (isAmbient) {
16439
16497
  if (stmt.declare) {
16440
- recordType(stmt, types);
16498
+ recordType(stmt, types, declares);
16441
16499
  }
16442
16500
  } else if (stmt.type === "TSModuleDeclaration" && stmt.global) {
16443
16501
  for (const s of stmt.body.body) {
16444
- recordType(s, types);
16502
+ recordType(s, types, declares);
16445
16503
  }
16446
16504
  }
16447
16505
  } else {
16448
- recordType(stmt, types);
16506
+ recordType(stmt, types, declares);
16449
16507
  }
16450
16508
  }
16451
16509
  if (!asGlobal) {
16452
16510
  for (const stmt of body) {
16453
16511
  if (stmt.type === "ExportNamedDeclaration") {
16454
16512
  if (stmt.declaration) {
16455
- recordType(stmt.declaration, types);
16456
- recordType(stmt.declaration, exportedTypes);
16513
+ recordType(stmt.declaration, types, declares);
16514
+ recordType(stmt.declaration, exportedTypes, exportedDeclares);
16457
16515
  } else {
16458
16516
  for (const spec of stmt.specifiers) {
16459
16517
  if (spec.type === "ExportSpecifier") {
@@ -16478,31 +16536,76 @@ function recordTypes(body, scope, asGlobal = false) {
16478
16536
  }
16479
16537
  }
16480
16538
  }
16539
+ } else if (stmt.type === "ExportAllDeclaration") {
16540
+ const sourceScope = importSourceToScope(
16541
+ ctx,
16542
+ stmt.source,
16543
+ scope,
16544
+ stmt.source.value
16545
+ );
16546
+ Object.assign(scope.exportedTypes, sourceScope.exportedTypes);
16481
16547
  }
16482
16548
  }
16483
16549
  }
16484
16550
  for (const key of Object.keys(types)) {
16485
- types[key]._ownerScope = scope;
16551
+ const node = types[key];
16552
+ node._ownerScope = scope;
16553
+ if (node._ns)
16554
+ node._ns._ownerScope = scope;
16555
+ }
16556
+ for (const key of Object.keys(declares)) {
16557
+ declares[key]._ownerScope = scope;
16486
16558
  }
16487
16559
  }
16488
- function recordType(node, types) {
16560
+ function recordType(node, types, declares) {
16489
16561
  switch (node.type) {
16490
16562
  case "TSInterfaceDeclaration":
16491
16563
  case "TSEnumDeclaration":
16492
- case "TSModuleDeclaration":
16493
- case "ClassDeclaration": {
16494
- const id = node.id.type === "Identifier" ? node.id.name : node.id.value;
16495
- types[id] = node;
16564
+ case "TSModuleDeclaration": {
16565
+ const id = getId(node.id);
16566
+ let existing = types[id];
16567
+ if (existing) {
16568
+ if (node.type === "TSModuleDeclaration") {
16569
+ if (existing.type === "TSModuleDeclaration") {
16570
+ mergeNamespaces(existing, node);
16571
+ } else {
16572
+ attachNamespace(existing, node);
16573
+ }
16574
+ break;
16575
+ }
16576
+ if (existing.type === "TSModuleDeclaration") {
16577
+ types[id] = node;
16578
+ attachNamespace(node, existing);
16579
+ break;
16580
+ }
16581
+ if (existing.type !== node.type) {
16582
+ break;
16583
+ }
16584
+ if (node.type === "TSInterfaceDeclaration") {
16585
+ existing.body.body.push(...node.body.body);
16586
+ } else {
16587
+ existing.members.push(...node.members);
16588
+ }
16589
+ } else {
16590
+ types[id] = node;
16591
+ }
16496
16592
  break;
16497
16593
  }
16594
+ case "ClassDeclaration":
16595
+ types[getId(node.id)] = node;
16596
+ break;
16498
16597
  case "TSTypeAliasDeclaration":
16499
16598
  types[node.id.name] = node.typeAnnotation;
16500
16599
  break;
16600
+ case "TSDeclareFunction":
16601
+ if (node.id)
16602
+ declares[node.id.name] = node;
16603
+ break;
16501
16604
  case "VariableDeclaration": {
16502
16605
  if (node.declare) {
16503
16606
  for (const decl of node.declarations) {
16504
16607
  if (decl.id.type === "Identifier" && decl.id.typeAnnotation) {
16505
- types[decl.id.name] = decl.id.typeAnnotation.typeAnnotation;
16608
+ declares[decl.id.name] = decl.id.typeAnnotation.typeAnnotation;
16506
16609
  }
16507
16610
  }
16508
16611
  }
@@ -16510,6 +16613,38 @@ function recordType(node, types) {
16510
16613
  }
16511
16614
  }
16512
16615
  }
16616
+ function mergeNamespaces(to, from) {
16617
+ const toBody = to.body;
16618
+ const fromBody = from.body;
16619
+ if (toBody.type === "TSModuleDeclaration") {
16620
+ if (fromBody.type === "TSModuleDeclaration") {
16621
+ mergeNamespaces(toBody, fromBody);
16622
+ } else {
16623
+ fromBody.body.push({
16624
+ type: "ExportNamedDeclaration",
16625
+ declaration: toBody,
16626
+ exportKind: "type",
16627
+ specifiers: []
16628
+ });
16629
+ }
16630
+ } else if (fromBody.type === "TSModuleDeclaration") {
16631
+ toBody.body.push({
16632
+ type: "ExportNamedDeclaration",
16633
+ declaration: fromBody,
16634
+ exportKind: "type",
16635
+ specifiers: []
16636
+ });
16637
+ } else {
16638
+ toBody.body.push(...fromBody.body);
16639
+ }
16640
+ }
16641
+ function attachNamespace(to, ns) {
16642
+ if (!to._ns) {
16643
+ to._ns = ns;
16644
+ } else {
16645
+ mergeNamespaces(to._ns, ns);
16646
+ }
16647
+ }
16513
16648
  function recordImports(body) {
16514
16649
  const imports = /* @__PURE__ */ Object.create(null);
16515
16650
  for (const s of body) {
@@ -16575,12 +16710,12 @@ function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx)
16575
16710
  default:
16576
16711
  return [UNKNOWN_TYPE];
16577
16712
  }
16578
- case "TSTypeReference":
16713
+ case "TSTypeReference": {
16714
+ const resolved = resolveTypeReference(ctx, node, scope);
16715
+ if (resolved) {
16716
+ return inferRuntimeType(ctx, resolved, resolved._ownerScope);
16717
+ }
16579
16718
  if (node.typeName.type === "Identifier") {
16580
- const resolved = resolveTypeReference(ctx, node, scope);
16581
- if (resolved) {
16582
- return inferRuntimeType(ctx, resolved, resolved._ownerScope);
16583
- }
16584
16719
  switch (node.typeName.name) {
16585
16720
  case "Array":
16586
16721
  case "Function":
@@ -16630,7 +16765,8 @@ function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx)
16630
16765
  break;
16631
16766
  }
16632
16767
  }
16633
- return [UNKNOWN_TYPE];
16768
+ break;
16769
+ }
16634
16770
  case "TSParenthesizedType":
16635
16771
  return inferRuntimeType(ctx, node.typeAnnotation, scope);
16636
16772
  case "TSUnionType":
@@ -16649,14 +16785,39 @@ function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx)
16649
16785
  const types = resolveIndexType(ctx, node, scope);
16650
16786
  return flattenTypes(ctx, types, scope);
16651
16787
  } catch (e) {
16652
- return [UNKNOWN_TYPE];
16788
+ break;
16653
16789
  }
16654
16790
  }
16655
16791
  case "ClassDeclaration":
16656
16792
  return ["Object"];
16657
- default:
16658
- return [UNKNOWN_TYPE];
16793
+ case "TSImportType": {
16794
+ try {
16795
+ const sourceScope = importSourceToScope(
16796
+ ctx,
16797
+ node.argument,
16798
+ scope,
16799
+ node.argument.value
16800
+ );
16801
+ const resolved = resolveTypeReference(ctx, node, sourceScope);
16802
+ if (resolved) {
16803
+ return inferRuntimeType(ctx, resolved, resolved._ownerScope);
16804
+ }
16805
+ } catch (e) {
16806
+ }
16807
+ break;
16808
+ }
16809
+ case "TSTypeQuery": {
16810
+ const id = node.exprName;
16811
+ if (id.type === "Identifier") {
16812
+ const matched = scope.declares[id.name];
16813
+ if (matched) {
16814
+ return inferRuntimeType(ctx, matched, matched._ownerScope);
16815
+ }
16816
+ }
16817
+ break;
16818
+ }
16659
16819
  }
16820
+ return [UNKNOWN_TYPE];
16660
16821
  }
16661
16822
  function flattenTypes(ctx, types, scope) {
16662
16823
  if (types.length === 1) {
@@ -16686,6 +16847,91 @@ function inferEnumType(node) {
16686
16847
  }
16687
16848
  return types.size ? [...types] : ["Number"];
16688
16849
  }
16850
+ function resolveExtractPropTypes({ props }, scope) {
16851
+ const res = { props: {} };
16852
+ for (const key in props) {
16853
+ const raw = props[key];
16854
+ res.props[key] = reverseInferType(
16855
+ raw.key,
16856
+ raw.typeAnnotation.typeAnnotation,
16857
+ scope
16858
+ );
16859
+ }
16860
+ return res;
16861
+ }
16862
+ function reverseInferType(key, node, scope, optional = true, checkObjectSyntax = true) {
16863
+ if (checkObjectSyntax && node.type === "TSTypeLiteral") {
16864
+ const typeType = findStaticPropertyType(node, "type");
16865
+ if (typeType) {
16866
+ const requiredType = findStaticPropertyType(node, "required");
16867
+ const optional2 = requiredType && requiredType.type === "TSLiteralType" && requiredType.literal.type === "BooleanLiteral" ? !requiredType.literal.value : true;
16868
+ return reverseInferType(key, typeType, scope, optional2, false);
16869
+ }
16870
+ } else if (node.type === "TSTypeReference" && node.typeName.type === "Identifier") {
16871
+ if (node.typeName.name.endsWith("Constructor")) {
16872
+ return createProperty(
16873
+ key,
16874
+ ctorToType(node.typeName.name),
16875
+ scope,
16876
+ optional
16877
+ );
16878
+ } else if (node.typeName.name === "PropType" && node.typeParameters) {
16879
+ return createProperty(key, node.typeParameters.params[0], scope, optional);
16880
+ }
16881
+ }
16882
+ if ((node.type === "TSTypeReference" || node.type === "TSImportType") && node.typeParameters) {
16883
+ for (const t of node.typeParameters.params) {
16884
+ const inferred = reverseInferType(key, t, scope, optional);
16885
+ if (inferred)
16886
+ return inferred;
16887
+ }
16888
+ }
16889
+ return createProperty(key, { type: `TSNullKeyword` }, scope, optional);
16890
+ }
16891
+ function ctorToType(ctorType) {
16892
+ const ctor = ctorType.slice(0, -11);
16893
+ switch (ctor) {
16894
+ case "String":
16895
+ case "Number":
16896
+ case "Boolean":
16897
+ return { type: `TS${ctor}Keyword` };
16898
+ case "Array":
16899
+ case "Function":
16900
+ case "Object":
16901
+ case "Set":
16902
+ case "Map":
16903
+ case "WeakSet":
16904
+ case "WeakMap":
16905
+ case "Date":
16906
+ case "Promise":
16907
+ return {
16908
+ type: "TSTypeReference",
16909
+ typeName: { type: "Identifier", name: ctor }
16910
+ };
16911
+ }
16912
+ return { type: `TSNullKeyword` };
16913
+ }
16914
+ function findStaticPropertyType(node, key) {
16915
+ const prop = node.members.find(
16916
+ (m) => m.type === "TSPropertySignature" && !m.computed && getId(m.key) === key && m.typeAnnotation
16917
+ );
16918
+ return prop && prop.typeAnnotation.typeAnnotation;
16919
+ }
16920
+ function resolveReturnType(ctx, arg, scope) {
16921
+ var _a;
16922
+ let resolved = arg;
16923
+ if (arg.type === "TSTypeReference" || arg.type === "TSTypeQuery" || arg.type === "TSImportType") {
16924
+ resolved = resolveTypeReference(ctx, arg, scope);
16925
+ }
16926
+ if (!resolved)
16927
+ return;
16928
+ if (resolved.type === "TSFunctionType") {
16929
+ return (_a = resolved.typeAnnotation) == null ? void 0 : _a.typeAnnotation;
16930
+ }
16931
+ if (resolved.type === "TSDeclareFunction") {
16932
+ return resolved.returnType;
16933
+ }
16934
+ }
16689
16935
 
16690
16936
  const DEFINE_MODEL = "defineModel";
16691
16937
  function processDefineModel(ctx, node, declId) {
@@ -18193,7 +18439,7 @@ function isStaticNode(node) {
18193
18439
  }
18194
18440
  }
18195
18441
 
18196
- const version = "3.3.0-alpha.11";
18442
+ const version = "3.3.0-alpha.13";
18197
18443
  const walk = estreeWalker.walk;
18198
18444
 
18199
18445
  exports.babelParse = parser$2.parse;