metro 0.75.1 → 0.76.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 (55) hide show
  1. package/package.json +23 -24
  2. package/src/Assets.js +2 -2
  3. package/src/Assets.js.flow +1 -1
  4. package/src/DeltaBundler/Graph.js +11 -28
  5. package/src/DeltaBundler/Graph.js.flow +7 -0
  6. package/src/DeltaBundler/Serializers/helpers/js.js +2 -7
  7. package/src/DeltaBundler/types.flow.js.flow +1 -7
  8. package/src/HmrServer.js +9 -32
  9. package/src/IncrementalBundler.js +5 -9
  10. package/src/ModuleGraph/worker/collectDependencies.js +53 -89
  11. package/src/ModuleGraph/worker/collectDependencies.js.flow +113 -141
  12. package/src/Server/symbolicate.js +1 -5
  13. package/src/Server.js +10 -53
  14. package/src/commands/dependencies.js +1 -5
  15. package/src/index.flow.js +1 -2
  16. package/src/integration_tests/basic_bundle/TestBigInt.js +0 -3
  17. package/src/integration_tests/basic_bundle/TestBigInt.js.flow +0 -3
  18. package/src/integration_tests/basic_bundle/require-resolveWeak/import-and-resolveWeak.js +28 -0
  19. package/src/integration_tests/basic_bundle/require-resolveWeak/import-and-resolveWeak.js.flow +33 -0
  20. package/src/integration_tests/basic_bundle/require-resolveWeak/multiple.js +20 -0
  21. package/src/integration_tests/basic_bundle/require-resolveWeak/multiple.js.flow +23 -0
  22. package/src/integration_tests/basic_bundle/require-resolveWeak/never-required.js +18 -0
  23. package/src/integration_tests/basic_bundle/require-resolveWeak/never-required.js.flow +21 -0
  24. package/src/integration_tests/basic_bundle/require-resolveWeak/require-and-resolveWeak.js +28 -0
  25. package/src/integration_tests/basic_bundle/require-resolveWeak/require-and-resolveWeak.js.flow +33 -0
  26. package/src/integration_tests/basic_bundle/require-resolveWeak/subdir/counter-module.js +19 -0
  27. package/src/integration_tests/basic_bundle/require-resolveWeak/subdir/counter-module.js.flow +18 -0
  28. package/src/integration_tests/basic_bundle/require-resolveWeak/subdir/throwing-module.js +13 -0
  29. package/src/integration_tests/basic_bundle/require-resolveWeak/subdir/throwing-module.js.flow +11 -0
  30. package/src/integration_tests/basic_bundle/require-resolveWeak/utils.js +1 -0
  31. package/src/integration_tests/basic_bundle/require-resolveWeak/utils.js.flow +14 -0
  32. package/src/lib/CountingSet.js +1 -5
  33. package/src/lib/RamBundleParser.js +0 -1
  34. package/src/lib/RamBundleParser.js.flow +0 -1
  35. package/src/lib/TerminalReporter.js +3 -17
  36. package/src/lib/contextModuleTemplates.js +1 -1
  37. package/src/lib/contextModuleTemplates.js.flow +1 -1
  38. package/src/lib/formatBundlingError.js +0 -3
  39. package/src/lib/formatBundlingError.js.flow +0 -3
  40. package/src/lib/getAppendScripts.js +0 -3
  41. package/src/lib/getAppendScripts.js.flow +0 -3
  42. package/src/lib/getGraphId.js +2 -11
  43. package/src/lib/getPrependedScripts.js +0 -1
  44. package/src/lib/getPrependedScripts.js.flow +0 -1
  45. package/src/lib/transformHelpers.js +14 -22
  46. package/src/lib/transformHelpers.js.flow +5 -8
  47. package/src/node-haste/DependencyGraph/ModuleResolution.js +4 -11
  48. package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +3 -5
  49. package/src/node-haste/DependencyGraph/createHasteMap.js +13 -38
  50. package/src/node-haste/DependencyGraph/createHasteMap.js.flow +2 -1
  51. package/src/node-haste/DependencyGraph.js +6 -17
  52. package/src/node-haste/DependencyGraph.js.flow +1 -5
  53. package/src/node-haste/Module.js +5 -3
  54. package/src/node-haste/Module.js.flow +2 -3
  55. package/src/node-haste/ModuleCache.js +1 -5
@@ -22,19 +22,16 @@ const generate = require('@babel/generator').default;
22
22
  const template = require('@babel/template').default;
23
23
  const traverse = require('@babel/traverse').default;
24
24
  const types = require('@babel/types');
25
- const invariant = require('invariant');
26
25
  const nullthrows = require('nullthrows');
27
26
 
28
27
  const {isImport} = types;
29
28
 
30
29
  type ImportDependencyOptions = $ReadOnly<{
31
30
  asyncType: AsyncDependencyType,
32
- jsResource?: boolean,
33
- splitCondition?: NodePath<>,
34
31
  }>;
35
32
 
36
- export type Dependency<TSplitCondition> = $ReadOnly<{
37
- data: DependencyData<TSplitCondition>,
33
+ export type Dependency = $ReadOnly<{
34
+ data: DependencyData,
38
35
  name: string,
39
36
  }>;
40
37
 
@@ -52,35 +49,31 @@ export type RequireContextParams = $ReadOnly<{
52
49
  mode: ContextMode,
53
50
  }>;
54
51
 
55
- type DependencyData<TSplitCondition> = $ReadOnly<{
52
+ type DependencyData = $ReadOnly<{
56
53
  // A locally unique key for this dependency within the current module.
57
54
  key: string,
58
55
  // If null, then the dependency is synchronous.
59
56
  // (ex. `require('foo')`)
60
57
  asyncType: AsyncDependencyType | null,
61
58
  isOptional?: boolean,
62
- // If left unspecified, then the dependency is unconditionally split.
63
- splitCondition?: TSplitCondition,
64
59
  locs: Array<BabelSourceLocation>,
65
60
  /** Context for requiring a collection of modules. */
66
61
  contextParams?: RequireContextParams,
67
62
  }>;
68
63
 
69
- export type MutableInternalDependency<TSplitCondition> = {
70
- ...DependencyData<TSplitCondition>,
64
+ export type MutableInternalDependency = {
65
+ ...DependencyData,
71
66
  index: number,
72
67
  name: string,
73
68
  };
74
69
 
75
- export type InternalDependency<TSplitCondition> = $ReadOnly<
76
- MutableInternalDependency<TSplitCondition>,
77
- >;
70
+ export type InternalDependency = $ReadOnly<MutableInternalDependency>;
78
71
 
79
- export type State<TSplitCondition> = {
72
+ export type State = {
80
73
  asyncRequireModulePathStringLiteral: ?StringLiteral,
81
74
  dependencyCalls: Set<string>,
82
- dependencyRegistry: ModuleDependencyRegistry<TSplitCondition>,
83
- dependencyTransformer: DependencyTransformer<TSplitCondition>,
75
+ dependencyRegistry: ModuleDependencyRegistry,
76
+ dependencyTransformer: DependencyTransformer,
84
77
  dynamicRequires: DynamicRequiresBehavior,
85
78
  dependencyMapIdentifier: ?Identifier,
86
79
  keepRequireNames: boolean,
@@ -89,61 +82,51 @@ export type State<TSplitCondition> = {
89
82
  unstable_allowRequireContext: boolean,
90
83
  };
91
84
 
92
- export type Options<TSplitCondition = void> = $ReadOnly<{
85
+ export type Options = $ReadOnly<{
93
86
  asyncRequireModulePath: string,
94
87
  dependencyMapName: ?string,
95
88
  dynamicRequires: DynamicRequiresBehavior,
96
89
  inlineableCalls: $ReadOnlyArray<string>,
97
90
  keepRequireNames: boolean,
98
91
  allowOptionalDependencies: AllowOptionalDependencies,
99
- dependencyRegistry?: ModuleDependencyRegistry<TSplitCondition>,
100
- dependencyTransformer?: DependencyTransformer<TSplitCondition>,
92
+ dependencyRegistry?: ModuleDependencyRegistry,
93
+ dependencyTransformer?: DependencyTransformer,
101
94
  /** Enable `require.context` statements which can be used to import multiple files in a directory. */
102
95
  unstable_allowRequireContext: boolean,
103
96
  }>;
104
97
 
105
- export type CollectedDependencies<+TSplitCondition> = $ReadOnly<{
98
+ export type CollectedDependencies = $ReadOnly<{
106
99
  ast: BabelNodeFile,
107
100
  dependencyMapName: string,
108
- dependencies: $ReadOnlyArray<Dependency<TSplitCondition>>,
101
+ dependencies: $ReadOnlyArray<Dependency>,
109
102
  }>;
110
103
 
111
104
  // Registry for the dependency of a module.
112
105
  // Defines when dependencies should be collapsed.
113
106
  // E.g. should a module that's once required optionally and once not
114
107
  // be treated as the same or different dependencies.
115
- export interface ModuleDependencyRegistry<+TSplitCondition> {
116
- registerDependency(
117
- qualifier: ImportQualifier,
118
- ): InternalDependency<TSplitCondition>;
119
- getDependencies(): Array<InternalDependency<TSplitCondition>>;
108
+ export interface ModuleDependencyRegistry {
109
+ registerDependency(qualifier: ImportQualifier): InternalDependency;
110
+ getDependencies(): Array<InternalDependency>;
120
111
  }
121
112
 
122
- export interface DependencyTransformer<-TSplitCondition> {
113
+ export interface DependencyTransformer {
123
114
  transformSyncRequire(
124
115
  path: NodePath<CallExpression>,
125
- dependency: InternalDependency<TSplitCondition>,
126
- state: State<TSplitCondition>,
116
+ dependency: InternalDependency,
117
+ state: State,
127
118
  ): void;
128
119
  transformImportCall(
129
120
  path: NodePath<>,
130
- dependency: InternalDependency<TSplitCondition>,
131
- state: State<TSplitCondition>,
132
- ): void;
133
- transformJSResource(
134
- path: NodePath<>,
135
- dependency: InternalDependency<TSplitCondition>,
136
- state: State<TSplitCondition>,
121
+ dependency: InternalDependency,
122
+ state: State,
137
123
  ): void;
138
124
  transformPrefetch(
139
125
  path: NodePath<>,
140
- dependency: InternalDependency<TSplitCondition>,
141
- state: State<TSplitCondition>,
142
- ): void;
143
- transformIllegalDynamicRequire(
144
- path: NodePath<>,
145
- state: State<TSplitCondition>,
126
+ dependency: InternalDependency,
127
+ state: State,
146
128
  ): void;
129
+ transformIllegalDynamicRequire(path: NodePath<>, state: State): void;
147
130
  }
148
131
 
149
132
  export type DynamicRequiresBehavior = 'throwAtRuntime' | 'reject';
@@ -157,13 +140,13 @@ export type DynamicRequiresBehavior = 'throwAtRuntime' | 'reject';
157
140
  *
158
141
  * The second argument is only provided for debugging purposes.
159
142
  */
160
- function collectDependencies<TSplitCondition = void>(
143
+ function collectDependencies(
161
144
  ast: BabelNodeFile,
162
- options: Options<TSplitCondition>,
163
- ): CollectedDependencies<TSplitCondition> {
145
+ options: Options,
146
+ ): CollectedDependencies {
164
147
  const visited = new WeakSet<BabelNodeCallExpression>();
165
148
 
166
- const state: State<TSplitCondition> = {
149
+ const state: State = {
167
150
  asyncRequireModulePathStringLiteral: null,
168
151
  dependencyCalls: new Set(),
169
152
  dependencyRegistry:
@@ -180,7 +163,7 @@ function collectDependencies<TSplitCondition = void>(
180
163
  const visitor = {
181
164
  CallExpression(
182
165
  path: NodePath<BabelNodeCallExpression>,
183
- state: State<TSplitCondition>,
166
+ state: State,
184
167
  ): void {
185
168
  if (visited.has(path.node)) {
186
169
  return;
@@ -203,29 +186,6 @@ function collectDependencies<TSplitCondition = void>(
203
186
  return;
204
187
  }
205
188
 
206
- if (name === '__jsResource' && !path.scope.getBinding(name)) {
207
- processImportCall(path, state, {
208
- asyncType: 'async',
209
- jsResource: true,
210
- });
211
- return;
212
- }
213
-
214
- if (
215
- name === '__conditionallySplitJSResource' &&
216
- !path.scope.getBinding(name)
217
- ) {
218
- const args = path.get('arguments');
219
- invariant(Array.isArray(args), 'Expected arguments to be an array');
220
-
221
- processImportCall(path, state, {
222
- asyncType: 'async',
223
- jsResource: true,
224
- splitCondition: args[1],
225
- });
226
- return;
227
- }
228
-
229
189
  // Match `require.context`
230
190
  if (
231
191
  // Feature gate, defaults to `false`.
@@ -246,6 +206,24 @@ function collectDependencies<TSplitCondition = void>(
246
206
  return;
247
207
  }
248
208
 
209
+ // Match `require.resolveWeak`
210
+ if (
211
+ callee.type === 'MemberExpression' &&
212
+ // `require`
213
+ callee.object.type === 'Identifier' &&
214
+ callee.object.name === 'require' &&
215
+ // `resolveWeak`
216
+ callee.property.type === 'Identifier' &&
217
+ callee.property.name === 'resolveWeak' &&
218
+ !callee.computed &&
219
+ // Ensure `require` refers to the global and not something else.
220
+ !path.scope.getBinding('require')
221
+ ) {
222
+ processResolveWeakCall(path, state);
223
+ visited.add(path.node);
224
+ return;
225
+ }
226
+
249
227
  if (
250
228
  name != null &&
251
229
  state.dependencyCalls.has(name) &&
@@ -260,7 +238,7 @@ function collectDependencies<TSplitCondition = void>(
260
238
  ExportNamedDeclaration: collectImports,
261
239
  ExportAllDeclaration: collectImports,
262
240
 
263
- Program(path: NodePath<BabelNodeProgram>, state: State<TSplitCondition>) {
241
+ Program(path: NodePath<BabelNodeProgram>, state: State) {
264
242
  state.asyncRequireModulePathStringLiteral = types.stringLiteral(
265
243
  options.asyncRequireModulePath,
266
244
  );
@@ -282,9 +260,7 @@ function collectDependencies<TSplitCondition = void>(
282
260
 
283
261
  const collectedDependencies = state.dependencyRegistry.getDependencies();
284
262
  // Compute the list of dependencies.
285
- const dependencies = new Array<Dependency<TSplitCondition>>(
286
- collectedDependencies.length,
287
- );
263
+ const dependencies = new Array<Dependency>(collectedDependencies.length);
288
264
 
289
265
  for (const {index, name, ...dependencyData} of collectedDependencies) {
290
266
  dependencies[index] = {
@@ -402,9 +378,9 @@ function getContextMode(path: NodePath<>, mode: string): ContextMode {
402
378
  );
403
379
  }
404
380
 
405
- function processRequireContextCall<TSplitCondition>(
381
+ function processRequireContextCall(
406
382
  path: NodePath<CallExpression>,
407
- state: State<TSplitCondition>,
383
+ state: State,
408
384
  ): void {
409
385
  const [directory, contextParams] = getRequireContextArgs(path);
410
386
  const transformer = state.dependencyTransformer;
@@ -426,10 +402,34 @@ function processRequireContextCall<TSplitCondition>(
426
402
  transformer.transformSyncRequire(path, dep, state);
427
403
  }
428
404
 
429
- function collectImports<TSplitCondition>(
430
- path: NodePath<>,
431
- state: State<TSplitCondition>,
405
+ function processResolveWeakCall(
406
+ path: NodePath<CallExpression>,
407
+ state: State,
432
408
  ): void {
409
+ const name = getModuleNameFromCallArgs(path);
410
+
411
+ if (name == null) {
412
+ throw new InvalidRequireCallError(path);
413
+ }
414
+
415
+ const dependency = registerDependency(
416
+ state,
417
+ {
418
+ name,
419
+ asyncType: 'weak',
420
+ optional: isOptionalDependency(name, path, state),
421
+ },
422
+ path,
423
+ );
424
+
425
+ path.replaceWith(
426
+ makeResolveWeakTemplate({
427
+ MODULE_ID: createModuleIDExpression(dependency, state),
428
+ }),
429
+ );
430
+ }
431
+
432
+ function collectImports(path: NodePath<>, state: State): void {
433
433
  if (path.node.source) {
434
434
  registerDependency(
435
435
  state,
@@ -443,9 +443,9 @@ function collectImports<TSplitCondition>(
443
443
  }
444
444
  }
445
445
 
446
- function processImportCall<TSplitCondition>(
446
+ function processImportCall(
447
447
  path: NodePath<CallExpression>,
448
- state: State<TSplitCondition>,
448
+ state: State,
449
449
  options: ImportDependencyOptions,
450
450
  ): void {
451
451
  const name = getModuleNameFromCallArgs(path);
@@ -459,7 +459,6 @@ function processImportCall<TSplitCondition>(
459
459
  {
460
460
  name,
461
461
  asyncType: options.asyncType,
462
- splitCondition: options.splitCondition,
463
462
  optional: isOptionalDependency(name, path, state),
464
463
  },
465
464
  path,
@@ -467,18 +466,16 @@ function processImportCall<TSplitCondition>(
467
466
 
468
467
  const transformer = state.dependencyTransformer;
469
468
 
470
- if (options.jsResource) {
471
- transformer.transformJSResource(path, dep, state);
472
- } else if (options.asyncType === 'async') {
469
+ if (options.asyncType === 'async') {
473
470
  transformer.transformImportCall(path, dep, state);
474
471
  } else {
475
472
  transformer.transformPrefetch(path, dep, state);
476
473
  }
477
474
  }
478
475
 
479
- function processRequireCall<TSplitCondition>(
476
+ function processRequireCall(
480
477
  path: NodePath<CallExpression>,
481
- state: State<TSplitCondition>,
478
+ state: State,
482
479
  ): void {
483
480
  const name = getModuleNameFromCallArgs(path);
484
481
 
@@ -517,16 +514,15 @@ function getNearestLocFromPath(path: NodePath<>): ?BabelSourceLocation {
517
514
  export type ImportQualifier = $ReadOnly<{
518
515
  name: string,
519
516
  asyncType: AsyncDependencyType | null,
520
- splitCondition?: NodePath<>,
521
517
  optional: boolean,
522
518
  contextParams?: RequireContextParams,
523
519
  }>;
524
520
 
525
- function registerDependency<TSplitCondition>(
526
- state: State<TSplitCondition>,
521
+ function registerDependency(
522
+ state: State,
527
523
  qualifier: ImportQualifier,
528
524
  path: NodePath<>,
529
- ): InternalDependency<TSplitCondition> {
525
+ ): InternalDependency {
530
526
  const dependency = state.dependencyRegistry.registerDependency(qualifier);
531
527
  const loc = getNearestLocFromPath(path);
532
528
  if (loc != null) {
@@ -536,10 +532,10 @@ function registerDependency<TSplitCondition>(
536
532
  return dependency;
537
533
  }
538
534
 
539
- function isOptionalDependency<TSplitCondition>(
535
+ function isOptionalDependency(
540
536
  name: string,
541
537
  path: NodePath<>,
542
- state: State<TSplitCondition>,
538
+ state: State,
543
539
  ): boolean {
544
540
  const {allowOptionalDependencies} = state;
545
541
 
@@ -579,10 +575,8 @@ function isOptionalDependency<TSplitCondition>(
579
575
  }
580
576
 
581
577
  function getModuleNameFromCallArgs(path: NodePath<CallExpression>): ?string {
582
- const expectedCount =
583
- path.node.callee.name === '__conditionallySplitJSResource' ? 2 : 1;
584
578
  const args = path.get('arguments');
585
- if (!Array.isArray(args) || args.length !== expectedCount) {
579
+ if (!Array.isArray(args) || args.length !== 1) {
586
580
  throw new InvalidRequireCallError(path);
587
581
  }
588
582
 
@@ -619,7 +613,7 @@ collectDependencies.InvalidRequireCallError = InvalidRequireCallError;
619
613
  * is reached. This makes dynamic require errors catchable by libraries that
620
614
  * want to use them.
621
615
  */
622
- const dynamicRequireErrorTemplate = template.statement(`
616
+ const dynamicRequireErrorTemplate = template.expression(`
623
617
  (function(line) {
624
618
  throw new Error(
625
619
  'Dynamic require defined at line ' + line + '; not supported by Metro',
@@ -631,23 +625,23 @@ const dynamicRequireErrorTemplate = template.statement(`
631
625
  * Produces a Babel template that transforms an "import(...)" call into a
632
626
  * "require(...)" call to the asyncRequire specified.
633
627
  */
634
- const makeAsyncRequireTemplate = template.statement(`
628
+ const makeAsyncRequireTemplate = template.expression(`
635
629
  require(ASYNC_REQUIRE_MODULE_PATH)(MODULE_ID, MODULE_NAME, DEPENDENCY_MAP.paths)
636
630
  `);
637
631
 
638
- const makeAsyncPrefetchTemplate = template.statement(`
632
+ const makeAsyncPrefetchTemplate = template.expression(`
639
633
  require(ASYNC_REQUIRE_MODULE_PATH).prefetch(MODULE_ID, MODULE_NAME, DEPENDENCY_MAP.paths)
640
634
  `);
641
635
 
642
- const makeJSResourceTemplate = template.statement(`
643
- require(ASYNC_REQUIRE_MODULE_PATH).resource(MODULE_ID, MODULE_NAME, DEPENDENCY_MAP.paths)
636
+ const makeResolveWeakTemplate = template.expression(`
637
+ MODULE_ID
644
638
  `);
645
639
 
646
- const DefaultDependencyTransformer: DependencyTransformer<mixed> = {
640
+ const DefaultDependencyTransformer: DependencyTransformer = {
647
641
  transformSyncRequire(
648
642
  path: NodePath<CallExpression>,
649
- dependency: InternalDependency<mixed>,
650
- state: State<mixed>,
643
+ dependency: InternalDependency,
644
+ state: State,
651
645
  ): void {
652
646
  const moduleIDExpression = createModuleIDExpression(dependency, state);
653
647
  path.node.arguments = ([moduleIDExpression]: Array<
@@ -664,8 +658,8 @@ const DefaultDependencyTransformer: DependencyTransformer<mixed> = {
664
658
 
665
659
  transformImportCall(
666
660
  path: NodePath<>,
667
- dependency: InternalDependency<mixed>,
668
- state: State<mixed>,
661
+ dependency: InternalDependency,
662
+ state: State,
669
663
  ): void {
670
664
  path.replaceWith(
671
665
  makeAsyncRequireTemplate({
@@ -679,27 +673,10 @@ const DefaultDependencyTransformer: DependencyTransformer<mixed> = {
679
673
  );
680
674
  },
681
675
 
682
- transformJSResource(
683
- path: NodePath<>,
684
- dependency: InternalDependency<mixed>,
685
- state: State<mixed>,
686
- ): void {
687
- path.replaceWith(
688
- makeJSResourceTemplate({
689
- ASYNC_REQUIRE_MODULE_PATH: nullthrows(
690
- state.asyncRequireModulePathStringLiteral,
691
- ),
692
- MODULE_ID: createModuleIDExpression(dependency, state),
693
- MODULE_NAME: createModuleNameLiteral(dependency),
694
- DEPENDENCY_MAP: nullthrows(state.dependencyMapIdentifier),
695
- }),
696
- );
697
- },
698
-
699
676
  transformPrefetch(
700
677
  path: NodePath<>,
701
- dependency: InternalDependency<mixed>,
702
- state: State<mixed>,
678
+ dependency: InternalDependency,
679
+ state: State,
703
680
  ): void {
704
681
  path.replaceWith(
705
682
  makeAsyncPrefetchTemplate({
@@ -713,7 +690,7 @@ const DefaultDependencyTransformer: DependencyTransformer<mixed> = {
713
690
  );
714
691
  },
715
692
 
716
- transformIllegalDynamicRequire(path: NodePath<>, state: State<mixed>): void {
693
+ transformIllegalDynamicRequire(path: NodePath<>, state: State): void {
717
694
  path.replaceWith(
718
695
  dynamicRequireErrorTemplate({
719
696
  LINE: types.numericLiteral(path.node.loc?.start.line ?? 0),
@@ -723,9 +700,9 @@ const DefaultDependencyTransformer: DependencyTransformer<mixed> = {
723
700
  };
724
701
 
725
702
  function createModuleIDExpression(
726
- dependency: InternalDependency<mixed>,
727
- state: State<mixed>,
728
- ) {
703
+ dependency: InternalDependency,
704
+ state: State,
705
+ ): BabelNodeExpression {
729
706
  return types.memberExpression(
730
707
  nullthrows(state.dependencyMapIdentifier),
731
708
  types.numericLiteral(dependency.index),
@@ -733,7 +710,7 @@ function createModuleIDExpression(
733
710
  );
734
711
  }
735
712
 
736
- function createModuleNameLiteral(dependency: InternalDependency<mixed>) {
713
+ function createModuleNameLiteral(dependency: InternalDependency) {
737
714
  return types.stringLiteral(dependency.name);
738
715
  }
739
716
 
@@ -781,20 +758,15 @@ function getKeyForDependency(qualifier: ImportQualifier): string {
781
758
  return key;
782
759
  }
783
760
 
784
- class DefaultModuleDependencyRegistry<TSplitCondition = void>
785
- implements ModuleDependencyRegistry<TSplitCondition>
786
- {
787
- _dependencies: Map<string, InternalDependency<TSplitCondition>> = new Map();
761
+ class DefaultModuleDependencyRegistry implements ModuleDependencyRegistry {
762
+ _dependencies: Map<string, InternalDependency> = new Map();
788
763
 
789
- registerDependency(
790
- qualifier: ImportQualifier,
791
- ): InternalDependency<TSplitCondition> {
764
+ registerDependency(qualifier: ImportQualifier): InternalDependency {
792
765
  const key = getKeyForDependency(qualifier);
793
- let dependency: ?InternalDependency<TSplitCondition> =
794
- this._dependencies.get(key);
766
+ let dependency: ?InternalDependency = this._dependencies.get(key);
795
767
 
796
768
  if (dependency == null) {
797
- const newDependency: MutableInternalDependency<TSplitCondition> = {
769
+ const newDependency: MutableInternalDependency = {
798
770
  name: qualifier.name,
799
771
  asyncType: qualifier.asyncType,
800
772
  locs: [],
@@ -826,7 +798,7 @@ class DefaultModuleDependencyRegistry<TSplitCondition = void>
826
798
  return dependency;
827
799
  }
828
800
 
829
- getDependencies(): Array<InternalDependency<TSplitCondition>> {
801
+ getDependencies(): Array<InternalDependency> {
830
802
  return Array.from(this._dependencies.values());
831
803
  }
832
804
  }
@@ -106,7 +106,6 @@ async function symbolicate(stack, maps, config) {
106
106
  return null;
107
107
  }
108
108
  function symbolicateFrame(frame) {
109
- var _findFunctionName;
110
109
  const module = findModule(frame);
111
110
  if (!module) {
112
111
  return frame;
@@ -121,10 +120,7 @@ async function symbolicate(stack, maps, config) {
121
120
  return frame;
122
121
  }
123
122
  const methodName =
124
- (_findFunctionName = findFunctionName(originalPos, module)) !== null &&
125
- _findFunctionName !== void 0
126
- ? _findFunctionName
127
- : frame.methodName;
123
+ findFunctionName(originalPos, module) ?? frame.methodName;
128
124
  return {
129
125
  ...frame,
130
126
  methodName,
package/src/Server.js CHANGED
@@ -96,7 +96,6 @@ class Server {
96
96
  return this._createModuleId;
97
97
  }
98
98
  async build(options) {
99
- var _this$_config$server$;
100
99
  const {
101
100
  entryFile,
102
101
  graphOptions,
@@ -140,10 +139,7 @@ class Server {
140
139
  sourceUrl: serializerOptions.sourceUrl,
141
140
  inlineSourceMap: serializerOptions.inlineSourceMap,
142
141
  serverRoot:
143
- (_this$_config$server$ = this._config.server.unstable_serverRoot) !==
144
- null && _this$_config$server$ !== void 0
145
- ? _this$_config$server$
146
- : this._config.projectRoot,
142
+ this._config.server.unstable_serverRoot ?? this._config.projectRoot,
147
143
  };
148
144
  let bundleCode = null;
149
145
  let bundleMap = null;
@@ -180,7 +176,6 @@ class Server {
180
176
  };
181
177
  }
182
178
  async getRamBundleInfo(options) {
183
- var _this$_config$server$2;
184
179
  const {
185
180
  entryFile,
186
181
  graphOptions,
@@ -227,10 +222,7 @@ class Server {
227
222
  sourceUrl: serializerOptions.sourceUrl,
228
223
  inlineSourceMap: serializerOptions.inlineSourceMap,
229
224
  serverRoot:
230
- (_this$_config$server$2 = this._config.server.unstable_serverRoot) !==
231
- null && _this$_config$server$2 !== void 0
232
- ? _this$_config$server$2
233
- : this._config.projectRoot,
225
+ this._config.server.unstable_serverRoot ?? this._config.projectRoot,
234
226
  });
235
227
  }
236
228
  async getAssets(options) {
@@ -386,24 +378,12 @@ class Server {
386
378
  bundlePerfLogger: noopLogger,
387
379
  });
388
380
  } else {
389
- var _this$_config$unstabl, _this$_config$unstabl2, _this$_config;
390
381
  await this._processBundleRequest(req, res, options, {
391
382
  buildNumber,
392
383
  bundlePerfLogger:
393
- (_this$_config$unstabl =
394
- (_this$_config$unstabl2 = (_this$_config = this._config)
395
- .unstable_perfLoggerFactory) === null ||
396
- _this$_config$unstabl2 === void 0
397
- ? void 0
398
- : _this$_config$unstabl2.call(
399
- _this$_config,
400
- "BUNDLING_REQUEST",
401
- {
402
- key: buildNumber,
403
- }
404
- )) !== null && _this$_config$unstabl !== void 0
405
- ? _this$_config$unstabl
406
- : noopLogger,
384
+ this._config.unstable_perfLoggerFactory?.("BUNDLING_REQUEST", {
385
+ key: buildNumber,
386
+ }) ?? noopLogger,
407
387
  });
408
388
  }
409
389
  if (this._serverOptions && this._serverOptions.onBundleBuilt) {
@@ -628,7 +608,6 @@ class Server {
628
608
  }
629
609
  _processBundleRequest = this._createRequestProcessor({
630
610
  createStartEntry(context) {
631
- var _context$req$headers$;
632
611
  return {
633
612
  action_name: "Requesting bundle",
634
613
  bundle_url: context.req.url,
@@ -637,11 +616,7 @@ class Server {
637
616
  build_id: getBuildID(context.buildNumber),
638
617
  bundle_options: context.bundleOptions,
639
618
  bundle_hash: context.graphId,
640
- user_agent:
641
- (_context$req$headers$ = context.req.headers["user-agent"]) !==
642
- null && _context$req$headers$ !== void 0
643
- ? _context$req$headers$
644
- : "unknown",
619
+ user_agent: context.req.headers["user-agent"] ?? "unknown",
645
620
  };
646
621
  },
647
622
  createEndEntry(context) {
@@ -659,7 +634,6 @@ class Server {
659
634
  transformOptions,
660
635
  bundlePerfLogger,
661
636
  }) => {
662
- var _this$_config$server$3;
663
637
  bundlePerfLogger.start();
664
638
  bundlePerfLogger.annotate({
665
639
  string: {
@@ -721,11 +695,7 @@ class Server {
721
695
  sourceUrl: serializerOptions.sourceUrl,
722
696
  inlineSourceMap: serializerOptions.inlineSourceMap,
723
697
  serverRoot:
724
- (_this$_config$server$3 =
725
- this._config.server.unstable_serverRoot) !== null &&
726
- _this$_config$server$3 !== void 0
727
- ? _this$_config$server$3
728
- : this._config.projectRoot,
698
+ this._config.server.unstable_serverRoot ?? this._config.projectRoot,
729
699
  }
730
700
  );
731
701
  bundlePerfLogger.point("serializingBundle_end");
@@ -798,7 +768,6 @@ class Server {
798
768
  serializerOptions,
799
769
  transformOptions,
800
770
  }) => {
801
- var _this$_config$server$4;
802
771
  const revPromise = this._bundler.getRevisionByGraphId(graphId);
803
772
  const { delta, revision } = await (revPromise != null
804
773
  ? this._bundler.updateGraph(await revPromise, false)
@@ -838,11 +807,7 @@ class Server {
838
807
  sourceUrl: serializerOptions.sourceUrl,
839
808
  inlineSourceMap: serializerOptions.inlineSourceMap,
840
809
  serverRoot:
841
- (_this$_config$server$4 =
842
- this._config.server.unstable_serverRoot) !== null &&
843
- _this$_config$server$4 !== void 0
844
- ? _this$_config$server$4
845
- : this._config.projectRoot,
810
+ this._config.server.unstable_serverRoot ?? this._config.projectRoot,
846
811
  })
847
812
  );
848
813
  return {
@@ -1003,10 +968,7 @@ class Server {
1003
968
  ) {
1004
969
  continue;
1005
970
  }
1006
- const fileAbsolute = path.resolve(
1007
- this._config.projectRoot,
1008
- file !== null && file !== void 0 ? file : ""
1009
- );
971
+ const fileAbsolute = path.resolve(this._config.projectRoot, file ?? "");
1010
972
  try {
1011
973
  return {
1012
974
  content: codeFrameColumns(
@@ -1199,12 +1161,7 @@ class Server {
1199
1161
  sourceUrl: null,
1200
1162
  };
1201
1163
  _getServerRootDir() {
1202
- var _this$_config$server$5;
1203
- return (_this$_config$server$5 =
1204
- this._config.server.unstable_serverRoot) !== null &&
1205
- _this$_config$server$5 !== void 0
1206
- ? _this$_config$server$5
1207
- : this._config.projectRoot;
1164
+ return this._config.server.unstable_serverRoot ?? this._config.projectRoot;
1208
1165
  }
1209
1166
  _getEntryPointAbsolutePath(entryFile) {
1210
1167
  return path.resolve(this._getServerRootDir(), entryFile);