babel-plugin-react-compiler 19.0.0-beta-63b359f-20241101 → 19.0.0-beta-a7bf2bd-20241110

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.
package/dist/index.js CHANGED
@@ -125654,6 +125654,12 @@ function makeTemporaryIdentifier(id, loc) {
125654
125654
  loc: loc,
125655
125655
  };
125656
125656
  }
125657
+ function forkTemporaryIdentifier(id, source) {
125658
+ return Object.assign(Object.assign({}, source), {
125659
+ mutableRange: {start: makeInstructionId(0), end: makeInstructionId(0)},
125660
+ id: id,
125661
+ });
125662
+ }
125657
125663
  function makeIdentifierName(name) {
125658
125664
  CompilerError.invariant(t__namespace.isValidIdentifier(name), {
125659
125665
  reason: `Expected a valid identifier name`,
@@ -136618,6 +136624,7 @@ const ReactElementSymbolSchema = z.object({
136618
136624
  z.literal('react.element'),
136619
136625
  z.literal('react.transitional.element'),
136620
136626
  ]),
136627
+ globalDevVar: z.string(),
136621
136628
  });
136622
136629
  const ExternalFunctionSchema = z.object({
136623
136630
  source: z.string(),
@@ -136626,8 +136633,8 @@ const ExternalFunctionSchema = z.object({
136626
136633
  const InstrumentationSchema = z
136627
136634
  .object({
136628
136635
  fn: ExternalFunctionSchema,
136629
- gating: ExternalFunctionSchema.nullish(),
136630
- globalGating: z.string().nullish(),
136636
+ gating: ExternalFunctionSchema.nullable(),
136637
+ globalGating: z.string().nullable(),
136631
136638
  })
136632
136639
  .refine(
136633
136640
  opts => opts.gating != null || opts.globalGating != null,
@@ -136648,7 +136655,7 @@ const HookSchema = z.object({
136648
136655
  transitiveMixedData: z.boolean().default(false),
136649
136656
  });
136650
136657
  const EnvironmentConfigSchema = z.object({
136651
- customHooks: z.map(z.string(), HookSchema).optional().default(new Map()),
136658
+ customHooks: z.map(z.string(), HookSchema).default(new Map()),
136652
136659
  moduleTypeProvider: z.nullable(z.function().args(z.string())).default(null),
136653
136660
  customMacros: z.nullable(z.array(MacroSchema)).default(null),
136654
136661
  enableResetCacheOnSourceFileChanges: z.boolean().default(false),
@@ -136657,9 +136664,7 @@ const EnvironmentConfigSchema = z.object({
136657
136664
  enablePreserveExistingManualUseMemo: z.boolean().default(false),
136658
136665
  enableForest: z.boolean().default(false),
136659
136666
  enableUseTypeAnnotations: z.boolean().default(false),
136660
- enablePropagateDepsInHIR: z.boolean().default(false),
136661
- enableOptionalDependencies: z.boolean().default(true),
136662
- inlineJsxTransform: ReactElementSymbolSchema.nullish(),
136667
+ inlineJsxTransform: ReactElementSymbolSchema.nullable().default(null),
136663
136668
  validateHooksUsage: z.boolean().default(true),
136664
136669
  validateRefAccessDuringRender: z.boolean().default(true),
136665
136670
  validateNoSetStateInRender: z.boolean().default(true),
@@ -136670,26 +136675,60 @@ const EnvironmentConfigSchema = z.object({
136670
136675
  validateBlocklistedImports: z.nullable(z.array(z.string())).default(null),
136671
136676
  enableAssumeHooksFollowRulesOfReact: z.boolean().default(true),
136672
136677
  enableTransitivelyFreezeFunctionExpressions: z.boolean().default(true),
136673
- enableEmitFreeze: ExternalFunctionSchema.nullish(),
136674
- enableEmitHookGuards: ExternalFunctionSchema.nullish(),
136678
+ enableEmitFreeze: ExternalFunctionSchema.nullable().default(null),
136679
+ enableEmitHookGuards: ExternalFunctionSchema.nullable().default(null),
136675
136680
  enableInstructionReordering: z.boolean().default(false),
136676
136681
  enableFunctionOutlining: z.boolean().default(true),
136677
136682
  enableJsxOutlining: z.boolean().default(false),
136678
- enableEmitInstrumentForget: InstrumentationSchema.nullish(),
136683
+ enableEmitInstrumentForget: InstrumentationSchema.nullable().default(null),
136679
136684
  assertValidMutableRanges: z.boolean().default(false),
136680
136685
  enableChangeVariableCodegen: z.boolean().default(false),
136681
136686
  enableMemoizationComments: z.boolean().default(false),
136682
136687
  throwUnknownException__testonly: z.boolean().default(false),
136683
- enableSharedRuntime__testonly: z.boolean().default(false),
136684
136688
  enableTreatFunctionDepsAsConditional: z.boolean().default(false),
136685
136689
  disableMemoizationForDebugging: z.boolean().default(false),
136686
- enableChangeDetectionForDebugging: ExternalFunctionSchema.nullish(),
136690
+ enableChangeDetectionForDebugging:
136691
+ ExternalFunctionSchema.nullable().default(null),
136687
136692
  enableCustomTypeDefinitionForReanimated: z.boolean().default(false),
136688
136693
  hookPattern: z.string().nullable().default(null),
136689
- enableTreatRefLikeIdentifiersAsRefs: z.boolean().nullable().default(false),
136690
- lowerContextAccess: ExternalFunctionSchema.nullish(),
136694
+ enableTreatRefLikeIdentifiersAsRefs: z.boolean().default(false),
136695
+ lowerContextAccess: ExternalFunctionSchema.nullable().default(null),
136691
136696
  });
136692
- function parseConfigPragma(pragma) {
136697
+ const testComplexConfigDefaults = {
136698
+ validateNoCapitalizedCalls: [],
136699
+ enableChangeDetectionForDebugging: {
136700
+ source: 'react-compiler-runtime',
136701
+ importSpecifierName: '$structuralCheck',
136702
+ },
136703
+ enableEmitFreeze: {
136704
+ source: 'react-compiler-runtime',
136705
+ importSpecifierName: 'makeReadOnly',
136706
+ },
136707
+ enableEmitInstrumentForget: {
136708
+ fn: {
136709
+ source: 'react-compiler-runtime',
136710
+ importSpecifierName: 'useRenderCounter',
136711
+ },
136712
+ gating: {
136713
+ source: 'react-compiler-runtime',
136714
+ importSpecifierName: 'shouldInstrument',
136715
+ },
136716
+ globalGating: '__DEV__',
136717
+ },
136718
+ enableEmitHookGuards: {
136719
+ source: 'react-compiler-runtime',
136720
+ importSpecifierName: '$dispatcherGuard',
136721
+ },
136722
+ inlineJsxTransform: {
136723
+ elementSymbol: 'react.transitional.element',
136724
+ globalDevVar: 'DEV',
136725
+ },
136726
+ lowerContextAccess: {
136727
+ source: 'react-compiler-runtime',
136728
+ importSpecifierName: 'useContext_withSelector',
136729
+ },
136730
+ };
136731
+ function parseConfigPragmaForTests(pragma) {
136693
136732
  const maybeConfig = {};
136694
136733
  const defaultConfig = EnvironmentConfigSchema.parse({});
136695
136734
  for (const token of pragma.split(' ')) {
@@ -136697,19 +136736,10 @@ function parseConfigPragma(pragma) {
136697
136736
  continue;
136698
136737
  }
136699
136738
  const keyVal = token.slice(1);
136700
- let [key, val] = keyVal.split(':');
136701
- if (key === 'validateNoCapitalizedCalls') {
136702
- maybeConfig[key] = [];
136703
- continue;
136704
- }
136705
- if (
136706
- key === 'enableChangeDetectionForDebugging' &&
136707
- (val === undefined || val === 'true')
136708
- ) {
136709
- maybeConfig[key] = {
136710
- source: 'react-compiler-runtime',
136711
- importSpecifierName: '$structuralCheck',
136712
- };
136739
+ let [key, val = undefined] = keyVal.split(':');
136740
+ const isSet = val === undefined || val === 'true';
136741
+ if (isSet && key in testComplexConfigDefaults) {
136742
+ maybeConfig[key] = testComplexConfigDefaults[key];
136713
136743
  continue;
136714
136744
  }
136715
136745
  if (key === 'customMacros' && val) {
@@ -136723,15 +136753,6 @@ function parseConfigPragma(pragma) {
136723
136753
  props.push({type: 'name', name: elt});
136724
136754
  }
136725
136755
  }
136726
- console.log([
136727
- valSplit[0],
136728
- props
136729
- .map(x => {
136730
- var _a;
136731
- return (_a = x.name) !== null && _a !== void 0 ? _a : '*';
136732
- })
136733
- .join('.'),
136734
- ]);
136735
136756
  maybeConfig[key] = [[valSplit[0], props]];
136736
136757
  }
136737
136758
  continue;
@@ -136740,11 +136761,10 @@ function parseConfigPragma(pragma) {
136740
136761
  continue;
136741
136762
  }
136742
136763
  if (val === undefined || val === 'true') {
136743
- val = true;
136764
+ maybeConfig[key] = true;
136744
136765
  } else {
136745
- val = false;
136766
+ maybeConfig[key] = false;
136746
136767
  }
136747
- maybeConfig[key] = val;
136748
136768
  }
136749
136769
  const config = EnvironmentConfigSchema.safeParse(maybeConfig);
136750
136770
  if (config.success) {
@@ -139834,7 +139854,7 @@ function findContextIdentifiers(func) {
139834
139854
  const currentFn =
139835
139855
  (_a = state.currentFn.at(-1)) !== null && _a !== void 0 ? _a : null;
139836
139856
  if (path.isReferencedIdentifier()) {
139837
- handleIdentifier(currentFn, state.identifiers, path);
139857
+ handleIdentifier$1(currentFn, state.identifiers, path);
139838
139858
  }
139839
139859
  },
139840
139860
  },
@@ -139850,7 +139870,7 @@ function findContextIdentifiers(func) {
139850
139870
  }
139851
139871
  return result;
139852
139872
  }
139853
- function handleIdentifier(currentFn, identifiers, path) {
139873
+ function handleIdentifier$1(currentFn, identifiers, path) {
139854
139874
  const name = path.node.name;
139855
139875
  const binding = path.scope.getBinding(name);
139856
139876
  if (binding == null) {
@@ -141181,6 +141201,313 @@ function instructionMayThrow(instr) {
141181
141201
  }
141182
141202
  }
141183
141203
  }
141204
+ function inlineJsxTransform(fn, inlineJsxTransformConfig) {
141205
+ var _a;
141206
+ const inlinedJsxDeclarations = new Map();
141207
+ for (const [_, currentBlock] of [...fn.body.blocks]) {
141208
+ let fallthroughBlockInstructions = null;
141209
+ const instructionCount = currentBlock.instructions.length;
141210
+ for (let i = 0; i < instructionCount; i++) {
141211
+ const instr = currentBlock.instructions[i];
141212
+ if (currentBlock.kind === 'value') {
141213
+ (_a = fn.env.logger) === null || _a === void 0
141214
+ ? void 0
141215
+ : _a.logEvent(fn.env.filename, {
141216
+ kind: 'CompileDiagnostic',
141217
+ fnLoc: null,
141218
+ detail: {
141219
+ reason: 'JSX Inlining is not supported on value blocks',
141220
+ loc: instr.loc,
141221
+ },
141222
+ });
141223
+ continue;
141224
+ }
141225
+ switch (instr.value.kind) {
141226
+ case 'JsxExpression':
141227
+ case 'JsxFragment': {
141228
+ const currentBlockInstructions = currentBlock.instructions.slice(
141229
+ 0,
141230
+ i
141231
+ );
141232
+ const thenBlockInstructions = currentBlock.instructions.slice(
141233
+ i,
141234
+ i + 1
141235
+ );
141236
+ const elseBlockInstructions = [];
141237
+ fallthroughBlockInstructions !== null &&
141238
+ fallthroughBlockInstructions !== void 0
141239
+ ? fallthroughBlockInstructions
141240
+ : (fallthroughBlockInstructions = currentBlock.instructions.slice(
141241
+ i + 1
141242
+ ));
141243
+ const fallthroughBlockId = fn.env.nextBlockId;
141244
+ const fallthroughBlock = {
141245
+ kind: currentBlock.kind,
141246
+ id: fallthroughBlockId,
141247
+ instructions: fallthroughBlockInstructions,
141248
+ terminal: currentBlock.terminal,
141249
+ preds: new Set(),
141250
+ phis: new Set(),
141251
+ };
141252
+ const varPlace = createTemporaryPlace(fn.env, instr.value.loc);
141253
+ promoteTemporary(varPlace.identifier);
141254
+ const varLValuePlace = createTemporaryPlace(fn.env, instr.value.loc);
141255
+ const thenVarPlace = Object.assign(Object.assign({}, varPlace), {
141256
+ identifier: forkTemporaryIdentifier(
141257
+ fn.env.nextIdentifierId,
141258
+ varPlace.identifier
141259
+ ),
141260
+ });
141261
+ const elseVarPlace = Object.assign(Object.assign({}, varPlace), {
141262
+ identifier: forkTemporaryIdentifier(
141263
+ fn.env.nextIdentifierId,
141264
+ varPlace.identifier
141265
+ ),
141266
+ });
141267
+ const varInstruction = {
141268
+ id: makeInstructionId(0),
141269
+ lvalue: Object.assign({}, varLValuePlace),
141270
+ value: {
141271
+ kind: 'DeclareLocal',
141272
+ lvalue: {
141273
+ place: Object.assign({}, varPlace),
141274
+ kind: InstructionKind.Let,
141275
+ },
141276
+ type: null,
141277
+ loc: instr.value.loc,
141278
+ },
141279
+ loc: instr.loc,
141280
+ };
141281
+ currentBlockInstructions.push(varInstruction);
141282
+ const devGlobalPlace = createTemporaryPlace(fn.env, instr.value.loc);
141283
+ const devGlobalInstruction = {
141284
+ id: makeInstructionId(0),
141285
+ lvalue: Object.assign(Object.assign({}, devGlobalPlace), {
141286
+ effect: exports.Effect.Mutate,
141287
+ }),
141288
+ value: {
141289
+ kind: 'LoadGlobal',
141290
+ binding: {
141291
+ kind: 'Global',
141292
+ name: inlineJsxTransformConfig.globalDevVar,
141293
+ },
141294
+ loc: instr.value.loc,
141295
+ },
141296
+ loc: instr.loc,
141297
+ };
141298
+ currentBlockInstructions.push(devGlobalInstruction);
141299
+ const thenBlockId = fn.env.nextBlockId;
141300
+ const elseBlockId = fn.env.nextBlockId;
141301
+ const ifTerminal = {
141302
+ kind: 'if',
141303
+ test: Object.assign(Object.assign({}, devGlobalPlace), {
141304
+ effect: exports.Effect.Read,
141305
+ }),
141306
+ consequent: thenBlockId,
141307
+ alternate: elseBlockId,
141308
+ fallthrough: fallthroughBlockId,
141309
+ loc: instr.loc,
141310
+ id: makeInstructionId(0),
141311
+ };
141312
+ currentBlock.instructions = currentBlockInstructions;
141313
+ currentBlock.terminal = ifTerminal;
141314
+ const thenBlock = {
141315
+ id: thenBlockId,
141316
+ instructions: thenBlockInstructions,
141317
+ kind: 'block',
141318
+ phis: new Set(),
141319
+ preds: new Set(),
141320
+ terminal: {
141321
+ kind: 'goto',
141322
+ block: fallthroughBlockId,
141323
+ variant: GotoVariant.Break,
141324
+ id: makeInstructionId(0),
141325
+ loc: instr.loc,
141326
+ },
141327
+ };
141328
+ fn.body.blocks.set(thenBlockId, thenBlock);
141329
+ const resassignElsePlace = createTemporaryPlace(
141330
+ fn.env,
141331
+ instr.value.loc
141332
+ );
141333
+ const reassignElseInstruction = {
141334
+ id: makeInstructionId(0),
141335
+ lvalue: Object.assign({}, resassignElsePlace),
141336
+ value: {
141337
+ kind: 'StoreLocal',
141338
+ lvalue: {place: elseVarPlace, kind: InstructionKind.Reassign},
141339
+ value: Object.assign({}, instr.lvalue),
141340
+ type: null,
141341
+ loc: instr.value.loc,
141342
+ },
141343
+ loc: instr.loc,
141344
+ };
141345
+ thenBlockInstructions.push(reassignElseInstruction);
141346
+ const elseBlockTerminal = {
141347
+ kind: 'goto',
141348
+ block: fallthroughBlockId,
141349
+ variant: GotoVariant.Break,
141350
+ id: makeInstructionId(0),
141351
+ loc: instr.loc,
141352
+ };
141353
+ const elseBlock = {
141354
+ id: elseBlockId,
141355
+ instructions: elseBlockInstructions,
141356
+ kind: 'block',
141357
+ phis: new Set(),
141358
+ preds: new Set(),
141359
+ terminal: elseBlockTerminal,
141360
+ };
141361
+ fn.body.blocks.set(elseBlockId, elseBlock);
141362
+ const {
141363
+ refProperty: refProperty,
141364
+ keyProperty: keyProperty,
141365
+ propsProperty: propsProperty,
141366
+ } = createPropsProperties(
141367
+ fn,
141368
+ instr,
141369
+ elseBlockInstructions,
141370
+ instr.value.kind === 'JsxExpression' ? instr.value.props : [],
141371
+ instr.value.children
141372
+ );
141373
+ const reactElementInstructionPlace = createTemporaryPlace(
141374
+ fn.env,
141375
+ instr.value.loc
141376
+ );
141377
+ const reactElementInstruction = {
141378
+ id: makeInstructionId(0),
141379
+ lvalue: Object.assign(
141380
+ Object.assign({}, reactElementInstructionPlace),
141381
+ {effect: exports.Effect.Store}
141382
+ ),
141383
+ value: {
141384
+ kind: 'ObjectExpression',
141385
+ properties: [
141386
+ createSymbolProperty(
141387
+ fn,
141388
+ instr,
141389
+ elseBlockInstructions,
141390
+ '$$typeof',
141391
+ inlineJsxTransformConfig.elementSymbol
141392
+ ),
141393
+ instr.value.kind === 'JsxExpression'
141394
+ ? createTagProperty(
141395
+ fn,
141396
+ instr,
141397
+ elseBlockInstructions,
141398
+ instr.value.tag
141399
+ )
141400
+ : createSymbolProperty(
141401
+ fn,
141402
+ instr,
141403
+ elseBlockInstructions,
141404
+ 'type',
141405
+ 'react.fragment'
141406
+ ),
141407
+ refProperty,
141408
+ keyProperty,
141409
+ propsProperty,
141410
+ ],
141411
+ loc: instr.value.loc,
141412
+ },
141413
+ loc: instr.loc,
141414
+ };
141415
+ elseBlockInstructions.push(reactElementInstruction);
141416
+ const reassignConditionalInstruction = {
141417
+ id: makeInstructionId(0),
141418
+ lvalue: Object.assign(
141419
+ {},
141420
+ createTemporaryPlace(fn.env, instr.value.loc)
141421
+ ),
141422
+ value: {
141423
+ kind: 'StoreLocal',
141424
+ lvalue: {
141425
+ place: Object.assign({}, elseVarPlace),
141426
+ kind: InstructionKind.Reassign,
141427
+ },
141428
+ value: Object.assign({}, reactElementInstruction.lvalue),
141429
+ type: null,
141430
+ loc: instr.value.loc,
141431
+ },
141432
+ loc: instr.loc,
141433
+ };
141434
+ elseBlockInstructions.push(reassignConditionalInstruction);
141435
+ const operands = new Map();
141436
+ operands.set(thenBlockId, Object.assign({}, elseVarPlace));
141437
+ operands.set(elseBlockId, Object.assign({}, thenVarPlace));
141438
+ const phiIdentifier = forkTemporaryIdentifier(
141439
+ fn.env.nextIdentifierId,
141440
+ varPlace.identifier
141441
+ );
141442
+ const phiPlace = Object.assign(
141443
+ Object.assign({}, createTemporaryPlace(fn.env, instr.value.loc)),
141444
+ {identifier: phiIdentifier}
141445
+ );
141446
+ const phis = new Set([
141447
+ {kind: 'Phi', operands: operands, place: phiPlace},
141448
+ ]);
141449
+ fallthroughBlock.phis = phis;
141450
+ fn.body.blocks.set(fallthroughBlockId, fallthroughBlock);
141451
+ inlinedJsxDeclarations.set(instr.lvalue.identifier.declarationId, {
141452
+ identifier: phiIdentifier,
141453
+ blockIdsToIgnore: new Set([thenBlockId, elseBlockId]),
141454
+ });
141455
+ break;
141456
+ }
141457
+ case 'FunctionExpression':
141458
+ case 'ObjectMethod': {
141459
+ inlineJsxTransform(
141460
+ instr.value.loweredFunc.func,
141461
+ inlineJsxTransformConfig
141462
+ );
141463
+ break;
141464
+ }
141465
+ }
141466
+ }
141467
+ }
141468
+ for (const [blockId, block] of fn.body.blocks) {
141469
+ for (const instr of block.instructions) {
141470
+ mapInstructionOperands(instr, place =>
141471
+ handlePlace(place, blockId, inlinedJsxDeclarations)
141472
+ );
141473
+ mapInstructionLValues(instr, lvalue =>
141474
+ handlelValue(lvalue, blockId, inlinedJsxDeclarations)
141475
+ );
141476
+ mapInstructionValueOperands(instr.value, place =>
141477
+ handlePlace(place, blockId, inlinedJsxDeclarations)
141478
+ );
141479
+ }
141480
+ mapTerminalOperands(block.terminal, place =>
141481
+ handlePlace(place, blockId, inlinedJsxDeclarations)
141482
+ );
141483
+ if (block.terminal.kind === 'scope') {
141484
+ const scope = block.terminal.scope;
141485
+ for (const dep of scope.dependencies) {
141486
+ dep.identifier = handleIdentifier(
141487
+ dep.identifier,
141488
+ inlinedJsxDeclarations
141489
+ );
141490
+ }
141491
+ for (const [origId, decl] of [...scope.declarations]) {
141492
+ const newDecl = handleIdentifier(
141493
+ decl.identifier,
141494
+ inlinedJsxDeclarations
141495
+ );
141496
+ if (newDecl.id !== origId) {
141497
+ scope.declarations.delete(origId);
141498
+ scope.declarations.set(decl.identifier.id, {
141499
+ identifier: newDecl,
141500
+ scope: decl.scope,
141501
+ });
141502
+ }
141503
+ }
141504
+ }
141505
+ }
141506
+ reversePostorderBlocks(fn.body);
141507
+ markPredecessors(fn.body);
141508
+ markInstructionIds(fn.body);
141509
+ fixScopeAndIdentifierRanges(fn.body);
141510
+ }
141184
141511
  function createSymbolProperty(
141185
141512
  fn,
141186
141513
  instr,
@@ -141473,152 +141800,65 @@ function createPropsProperties(
141473
141800
  propsProperty: propsProperty,
141474
141801
  };
141475
141802
  }
141476
- function inlineJsxTransform(fn, inlineJsxTransformConfig) {
141477
- for (const [, block] of fn.body.blocks) {
141478
- let nextInstructions = null;
141479
- for (let i = 0; i < block.instructions.length; i++) {
141480
- const instr = block.instructions[i];
141481
- switch (instr.value.kind) {
141482
- case 'JsxExpression': {
141483
- nextInstructions !== null && nextInstructions !== void 0
141484
- ? nextInstructions
141485
- : (nextInstructions = block.instructions.slice(0, i));
141486
- const {
141487
- refProperty: refProperty,
141488
- keyProperty: keyProperty,
141489
- propsProperty: propsProperty,
141490
- } = createPropsProperties(
141491
- fn,
141492
- instr,
141493
- nextInstructions,
141494
- instr.value.props,
141495
- instr.value.children
141496
- );
141497
- const reactElementInstruction = {
141498
- id: makeInstructionId(0),
141499
- lvalue: Object.assign(Object.assign({}, instr.lvalue), {
141500
- effect: exports.Effect.Store,
141501
- }),
141502
- value: {
141503
- kind: 'ObjectExpression',
141504
- properties: [
141505
- createSymbolProperty(
141506
- fn,
141507
- instr,
141508
- nextInstructions,
141509
- '$$typeof',
141510
- inlineJsxTransformConfig.elementSymbol
141511
- ),
141512
- createTagProperty(fn, instr, nextInstructions, instr.value.tag),
141513
- refProperty,
141514
- keyProperty,
141515
- propsProperty,
141516
- ],
141517
- loc: instr.value.loc,
141518
- },
141519
- loc: instr.loc,
141520
- };
141521
- nextInstructions.push(reactElementInstruction);
141522
- break;
141523
- }
141524
- case 'JsxFragment': {
141525
- nextInstructions !== null && nextInstructions !== void 0
141526
- ? nextInstructions
141527
- : (nextInstructions = block.instructions.slice(0, i));
141528
- const {
141529
- refProperty: refProperty,
141530
- keyProperty: keyProperty,
141531
- propsProperty: propsProperty,
141532
- } = createPropsProperties(
141533
- fn,
141534
- instr,
141535
- nextInstructions,
141536
- [],
141537
- instr.value.children
141538
- );
141539
- const reactElementInstruction = {
141540
- id: makeInstructionId(0),
141541
- lvalue: Object.assign(Object.assign({}, instr.lvalue), {
141542
- effect: exports.Effect.Store,
141543
- }),
141544
- value: {
141545
- kind: 'ObjectExpression',
141546
- properties: [
141547
- createSymbolProperty(
141548
- fn,
141549
- instr,
141550
- nextInstructions,
141551
- '$$typeof',
141552
- inlineJsxTransformConfig.elementSymbol
141553
- ),
141554
- createSymbolProperty(
141555
- fn,
141556
- instr,
141557
- nextInstructions,
141558
- 'type',
141559
- 'react.fragment'
141560
- ),
141561
- refProperty,
141562
- keyProperty,
141563
- propsProperty,
141564
- ],
141565
- loc: instr.value.loc,
141566
- },
141567
- loc: instr.loc,
141568
- };
141569
- nextInstructions.push(reactElementInstruction);
141570
- break;
141571
- }
141572
- case 'FunctionExpression':
141573
- case 'ObjectMethod': {
141574
- inlineJsxTransform(
141575
- instr.value.loweredFunc.func,
141576
- inlineJsxTransformConfig
141577
- );
141578
- if (nextInstructions !== null) {
141579
- nextInstructions.push(instr);
141580
- }
141581
- break;
141582
- }
141583
- default: {
141584
- if (nextInstructions !== null) {
141585
- nextInstructions.push(instr);
141586
- }
141587
- }
141588
- }
141589
- }
141590
- if (nextInstructions !== null) {
141591
- block.instructions = nextInstructions;
141592
- }
141593
- }
141594
- reversePostorderBlocks(fn.body);
141595
- markPredecessors(fn.body);
141596
- markInstructionIds(fn.body);
141597
- fixScopeAndIdentifierRanges(fn.body);
141598
- }
141599
- function findScopesToMerge(fn) {
141600
- const objectMethodDecls = new Set();
141601
- const mergeScopesBuilder = new DisjointSet();
141602
- for (const [_, block] of fn.body.blocks) {
141603
- for (const {lvalue: lvalue, value: value} of block.instructions) {
141604
- if (value.kind === 'ObjectMethod') {
141605
- objectMethodDecls.add(lvalue.identifier);
141606
- } else if (value.kind === 'ObjectExpression') {
141607
- for (const operand of eachInstructionValueOperand(value)) {
141608
- if (objectMethodDecls.has(operand.identifier)) {
141609
- const operandScope = operand.identifier.scope;
141610
- const lvalueScope = lvalue.identifier.scope;
141611
- CompilerError.invariant(
141612
- operandScope != null && lvalueScope != null,
141613
- {
141614
- reason:
141615
- 'Internal error: Expected all ObjectExpressions and ObjectMethods to have non-null scope.',
141616
- suggestions: null,
141617
- loc: GeneratedSource,
141618
- }
141619
- );
141620
- mergeScopesBuilder.union([operandScope, lvalueScope]);
141621
- }
141803
+ function handlePlace(place, blockId, inlinedJsxDeclarations) {
141804
+ const inlinedJsxDeclaration = inlinedJsxDeclarations.get(
141805
+ place.identifier.declarationId
141806
+ );
141807
+ if (
141808
+ inlinedJsxDeclaration == null ||
141809
+ inlinedJsxDeclaration.blockIdsToIgnore.has(blockId)
141810
+ ) {
141811
+ return place;
141812
+ }
141813
+ return Object.assign(Object.assign({}, place), {
141814
+ identifier: inlinedJsxDeclaration.identifier,
141815
+ });
141816
+ }
141817
+ function handlelValue(lvalue, blockId, inlinedJsxDeclarations) {
141818
+ const inlinedJsxDeclaration = inlinedJsxDeclarations.get(
141819
+ lvalue.identifier.declarationId
141820
+ );
141821
+ if (
141822
+ inlinedJsxDeclaration == null ||
141823
+ inlinedJsxDeclaration.blockIdsToIgnore.has(blockId)
141824
+ ) {
141825
+ return lvalue;
141826
+ }
141827
+ return Object.assign(Object.assign({}, lvalue), {
141828
+ identifier: inlinedJsxDeclaration.identifier,
141829
+ });
141830
+ }
141831
+ function handleIdentifier(identifier, inlinedJsxDeclarations) {
141832
+ const inlinedJsxDeclaration = inlinedJsxDeclarations.get(
141833
+ identifier.declarationId
141834
+ );
141835
+ return inlinedJsxDeclaration == null
141836
+ ? identifier
141837
+ : inlinedJsxDeclaration.identifier;
141838
+ }
141839
+ function findScopesToMerge(fn) {
141840
+ const objectMethodDecls = new Set();
141841
+ const mergeScopesBuilder = new DisjointSet();
141842
+ for (const [_, block] of fn.body.blocks) {
141843
+ for (const {lvalue: lvalue, value: value} of block.instructions) {
141844
+ if (value.kind === 'ObjectMethod') {
141845
+ objectMethodDecls.add(lvalue.identifier);
141846
+ } else if (value.kind === 'ObjectExpression') {
141847
+ for (const operand of eachInstructionValueOperand(value)) {
141848
+ if (objectMethodDecls.has(operand.identifier)) {
141849
+ const operandScope = operand.identifier.scope;
141850
+ const lvalueScope = lvalue.identifier.scope;
141851
+ CompilerError.invariant(
141852
+ operandScope != null && lvalueScope != null,
141853
+ {
141854
+ reason:
141855
+ 'Internal error: Expected all ObjectExpressions and ObjectMethods to have non-null scope.',
141856
+ suggestions: null,
141857
+ loc: GeneratedSource,
141858
+ }
141859
+ );
141860
+ mergeScopesBuilder.union([operandScope, lvalueScope]);
141861
+ }
141622
141862
  }
141623
141863
  }
141624
141864
  }
@@ -142254,7 +142494,7 @@ var _Context_nextScheduleId,
142254
142494
  _Context_catchHandlers,
142255
142495
  _Context_controlFlowStack;
142256
142496
  function buildReactiveFunction(fn) {
142257
- const cx = new Context$3(fn.body);
142497
+ const cx = new Context$2(fn.body);
142258
142498
  const driver = new Driver(cx);
142259
142499
  const body = driver.traverseBlock(cx.block(fn.body.entry));
142260
142500
  return {
@@ -143302,7 +143542,7 @@ class Driver {
143302
143542
  };
143303
143543
  }
143304
143544
  }
143305
- let Context$3 = class Context {
143545
+ let Context$2 = class Context {
143306
143546
  constructor(ir) {
143307
143547
  _Context_nextScheduleId.set(this, 0);
143308
143548
  this.emitted = new Set();
@@ -143682,7 +143922,7 @@ function expandFbtScopeRange(fbtRange, extendWith) {
143682
143922
  );
143683
143923
  }
143684
143924
  }
143685
- var _Context_nextCacheIndex, _Context_declarations$2;
143925
+ var _Context_nextCacheIndex, _Context_declarations$1;
143686
143926
  const MEMO_CACHE_SENTINEL = 'react.memo_cache_sentinel';
143687
143927
  const EARLY_RETURN_SENTINEL = 'react.early_return_sentinel';
143688
143928
  function codegenFunction(
@@ -143690,7 +143930,7 @@ function codegenFunction(
143690
143930
  {uniqueIdentifiers: uniqueIdentifiers, fbtOperands: fbtOperands}
143691
143931
  ) {
143692
143932
  var _a, _b, _c;
143693
- const cx = new Context$2(
143933
+ const cx = new Context$1(
143694
143934
  fn.env,
143695
143935
  (_a = fn.id) !== null && _a !== void 0 ? _a : '[[ anonymous ]]',
143696
143936
  uniqueIdentifiers,
@@ -143855,7 +144095,7 @@ function codegenFunction(
143855
144095
  pruneHoistedContexts(reactiveFunction);
143856
144096
  const identifiers = renameVariables(reactiveFunction);
143857
144097
  const codegen = codegenReactiveFunction(
143858
- new Context$2(
144098
+ new Context$1(
143859
144099
  cx.env,
143860
144100
  (_c = reactiveFunction.id) !== null && _c !== void 0
143861
144101
  ? _c
@@ -143942,10 +144182,10 @@ function convertParameter(param) {
143942
144182
  return t__namespace.restElement(convertIdentifier(param.place.identifier));
143943
144183
  }
143944
144184
  }
143945
- let Context$2 = class Context {
144185
+ let Context$1 = class Context {
143946
144186
  constructor(env, fnName, uniqueIdentifiers, fbtOperands, temporaries = null) {
143947
144187
  _Context_nextCacheIndex.set(this, 0);
143948
- _Context_declarations$2.set(this, new Set());
144188
+ _Context_declarations$1.set(this, new Set());
143949
144189
  this.errors = new CompilerError();
143950
144190
  this.objectMethods = new Map();
143951
144191
  this.synthesizedNames = new Map();
@@ -143970,12 +144210,12 @@ let Context$2 = class Context {
143970
144210
  );
143971
144211
  }
143972
144212
  declare(identifier) {
143973
- __classPrivateFieldGet(this, _Context_declarations$2, 'f').add(
144213
+ __classPrivateFieldGet(this, _Context_declarations$1, 'f').add(
143974
144214
  identifier.declarationId
143975
144215
  );
143976
144216
  }
143977
144217
  hasDeclared(identifier) {
143978
- return __classPrivateFieldGet(this, _Context_declarations$2, 'f').has(
144218
+ return __classPrivateFieldGet(this, _Context_declarations$1, 'f').has(
143979
144219
  identifier.declarationId
143980
144220
  );
143981
144221
  }
@@ -143995,7 +144235,7 @@ let Context$2 = class Context {
143995
144235
  }
143996
144236
  };
143997
144237
  (_Context_nextCacheIndex = new WeakMap()),
143998
- (_Context_declarations$2 = new WeakMap());
144238
+ (_Context_declarations$1 = new WeakMap());
143999
144239
  function codegenBlock(cx, block) {
144000
144240
  const temp = new Map(cx.temp);
144001
144241
  const result = codegenBlockNoReset(cx, block);
@@ -144088,7 +144328,7 @@ function codegenReactiveScope(cx, statements, scope, block) {
144088
144328
  const changeExpressions = [];
144089
144329
  const changeExpressionComments = [];
144090
144330
  const outputComments = [];
144091
- for (const dep of scope.dependencies) {
144331
+ for (const dep of [...scope.dependencies].sort(compareScopeDependency)) {
144092
144332
  const index = cx.nextCacheIndex;
144093
144333
  changeExpressionComments.push(printDependencyComment(dep));
144094
144334
  const comparison = t__namespace.binaryExpression(
@@ -144128,7 +144368,9 @@ function codegenReactiveScope(cx, statements, scope, block) {
144128
144368
  );
144129
144369
  }
144130
144370
  let firstOutputIndex = null;
144131
- for (const [, {identifier: identifier}] of scope.declarations) {
144371
+ for (const [, {identifier: identifier}] of [...scope.declarations].sort(
144372
+ ([, a], [, b]) => compareScopeDeclaration(a, b)
144373
+ )) {
144132
144374
  const index = cx.nextCacheIndex;
144133
144375
  if (firstOutputIndex === null) {
144134
144376
  firstOutputIndex = index;
@@ -145271,7 +145513,7 @@ function codegenInstructionValue(cx, instrValue) {
145271
145513
  pruneUnusedLabels(reactiveFunction);
145272
145514
  pruneUnusedLValues(reactiveFunction);
145273
145515
  const fn = codegenReactiveFunction(
145274
- new Context$2(
145516
+ new Context$1(
145275
145517
  cx.env,
145276
145518
  (_e = reactiveFunction.id) !== null && _e !== void 0
145277
145519
  ? _e
@@ -145470,7 +145712,7 @@ function codegenInstructionValue(cx, instrValue) {
145470
145712
  pruneUnusedLValues(reactiveFunction);
145471
145713
  pruneHoistedContexts(reactiveFunction);
145472
145714
  const fn = codegenReactiveFunction(
145473
- new Context$2(
145715
+ new Context$1(
145474
145716
  cx.env,
145475
145717
  (_g = reactiveFunction.id) !== null && _g !== void 0
145476
145718
  ? _g
@@ -145939,6 +146181,50 @@ function convertIdentifier(identifier) {
145939
146181
  );
145940
146182
  return t__namespace.identifier(identifier.name.value);
145941
146183
  }
146184
+ function compareScopeDependency(a, b) {
146185
+ var _a, _b;
146186
+ CompilerError.invariant(
146187
+ ((_a = a.identifier.name) === null || _a === void 0 ? void 0 : _a.kind) ===
146188
+ 'named' &&
146189
+ ((_b = b.identifier.name) === null || _b === void 0
146190
+ ? void 0
146191
+ : _b.kind) === 'named',
146192
+ {
146193
+ reason: '[Codegen] Expected named identifier for dependency',
146194
+ loc: a.identifier.loc,
146195
+ }
146196
+ );
146197
+ const aName = [
146198
+ a.identifier.name.value,
146199
+ ...a.path.map(entry => `${entry.optional ? '?' : ''}${entry.property}`),
146200
+ ].join('.');
146201
+ const bName = [
146202
+ b.identifier.name.value,
146203
+ ...b.path.map(entry => `${entry.optional ? '?' : ''}${entry.property}`),
146204
+ ].join('.');
146205
+ if (aName < bName) return -1;
146206
+ else if (aName > bName) return 1;
146207
+ else return 0;
146208
+ }
146209
+ function compareScopeDeclaration(a, b) {
146210
+ var _a, _b;
146211
+ CompilerError.invariant(
146212
+ ((_a = a.identifier.name) === null || _a === void 0 ? void 0 : _a.kind) ===
146213
+ 'named' &&
146214
+ ((_b = b.identifier.name) === null || _b === void 0
146215
+ ? void 0
146216
+ : _b.kind) === 'named',
146217
+ {
146218
+ reason: '[Codegen] Expected named identifier for declaration',
146219
+ loc: a.identifier.loc,
146220
+ }
146221
+ );
146222
+ const aName = a.identifier.name.value;
146223
+ const bName = b.identifier.name.value;
146224
+ if (aName < bName) return -1;
146225
+ else if (aName > bName) return 1;
146226
+ else return 0;
146227
+ }
145942
146228
  function extractScopeDeclarationsFromDestructuring(fn) {
145943
146229
  const state = new State$1(fn.env);
145944
146230
  visitReactiveFunction(fn, new Visitor$9(), state);
@@ -146935,1651 +147221,42 @@ let Transform$3 = class Transform extends ReactiveFunctionTransform {
146935
147221
  return {kind: 'keep'};
146936
147222
  }
146937
147223
  };
146938
- var _Node_value, _Node_next;
146939
- function empty() {
146940
- return EMPTY;
146941
- }
146942
- class Node {
146943
- constructor(value, next = EMPTY) {
146944
- _Node_value.set(this, void 0);
146945
- _Node_next.set(this, void 0);
146946
- __classPrivateFieldSet(this, _Node_value, value, 'f');
146947
- __classPrivateFieldSet(this, _Node_next, next, 'f');
146948
- }
146949
- push(value) {
146950
- return new Node(value, this);
146951
- }
146952
- pop() {
146953
- return __classPrivateFieldGet(this, _Node_next, 'f');
146954
- }
146955
- find(fn) {
146956
- return fn(__classPrivateFieldGet(this, _Node_value, 'f'))
146957
- ? true
146958
- : __classPrivateFieldGet(this, _Node_next, 'f').find(fn);
146959
- }
146960
- contains(value) {
146961
- return (
146962
- value === __classPrivateFieldGet(this, _Node_value, 'f') ||
146963
- (__classPrivateFieldGet(this, _Node_next, 'f') !== null &&
146964
- __classPrivateFieldGet(this, _Node_next, 'f').contains(value))
146965
- );
146966
- }
146967
- each(fn) {
146968
- fn(__classPrivateFieldGet(this, _Node_value, 'f'));
146969
- __classPrivateFieldGet(this, _Node_next, 'f').each(fn);
146970
- }
146971
- get value() {
146972
- return __classPrivateFieldGet(this, _Node_value, 'f');
146973
- }
146974
- print(fn) {
146975
- return (
146976
- fn(__classPrivateFieldGet(this, _Node_value, 'f')) +
146977
- __classPrivateFieldGet(this, _Node_next, 'f').print(fn)
146978
- );
146979
- }
146980
- }
146981
- (_Node_value = new WeakMap()), (_Node_next = new WeakMap());
146982
- class Empty {
146983
- push(value) {
146984
- return new Node(value, this);
146985
- }
146986
- pop() {
146987
- return this;
146988
- }
146989
- find(_fn) {
146990
- return false;
146991
- }
146992
- contains(_value) {
146993
- return false;
146994
- }
146995
- each(_fn) {
146996
- return;
146997
- }
146998
- get value() {
146999
- return null;
147000
- }
147001
- print(_) {
147002
- return '';
147003
- }
147224
+ function pruneHoistedContexts(fn) {
147225
+ const hoistedIdentifiers = new Map();
147226
+ visitReactiveFunction(fn, new Visitor$8(), hoistedIdentifiers);
147004
147227
  }
147005
- const EMPTY = new Empty();
147006
- var _ReactiveScopeDependencyTree_instances,
147007
- _ReactiveScopeDependencyTree_roots,
147008
- _ReactiveScopeDependencyTree_getOrCreateRoot,
147009
- _ReactiveScopeDependencyTree_debugImpl;
147010
- class ReactiveScopeDependencyTree {
147011
- constructor() {
147012
- _ReactiveScopeDependencyTree_instances.add(this);
147013
- _ReactiveScopeDependencyTree_roots.set(this, new Map());
147014
- }
147015
- add(dep, inConditional) {
147016
- const {path: path} = dep;
147017
- let currNode = __classPrivateFieldGet(
147018
- this,
147019
- _ReactiveScopeDependencyTree_instances,
147020
- 'm',
147021
- _ReactiveScopeDependencyTree_getOrCreateRoot
147022
- ).call(this, dep.identifier);
147023
- for (const item of path) {
147024
- let currChild = getOrMakeProperty(currNode, item.property);
147025
- const accessType = inConditional
147026
- ? PropertyAccessType$1.ConditionalAccess
147027
- : item.optional
147028
- ? PropertyAccessType$1.OptionalAccess
147029
- : PropertyAccessType$1.UnconditionalAccess;
147030
- currChild.accessType = merge$1(currChild.accessType, accessType);
147031
- currNode = currChild;
147032
- }
147033
- const depType = inConditional
147034
- ? PropertyAccessType$1.ConditionalDependency
147035
- : isOptional$1(currNode.accessType)
147036
- ? PropertyAccessType$1.OptionalDependency
147037
- : PropertyAccessType$1.UnconditionalDependency;
147038
- currNode.accessType = merge$1(currNode.accessType, depType);
147039
- }
147040
- deriveMinimalDependencies() {
147041
- const results = new Set();
147042
- for (const [rootId, rootNode] of __classPrivateFieldGet(
147043
- this,
147044
- _ReactiveScopeDependencyTree_roots,
147045
- 'f'
147046
- ).entries()) {
147047
- const deps = deriveMinimalDependenciesInSubtree(rootNode, null);
147048
- CompilerError.invariant(
147049
- deps.every(
147050
- dep =>
147051
- dep.accessType === PropertyAccessType$1.UnconditionalDependency ||
147052
- dep.accessType == PropertyAccessType$1.OptionalDependency
147053
- ),
147054
- {
147055
- reason:
147056
- '[PropagateScopeDependencies] All dependencies must be reduced to unconditional dependencies.',
147057
- description: null,
147058
- loc: null,
147059
- suggestions: null,
147060
- }
147228
+ let Visitor$8 = class Visitor extends ReactiveFunctionTransform {
147229
+ transformInstruction(instruction, state) {
147230
+ this.visitInstruction(instruction, state);
147231
+ if (
147232
+ instruction.value.kind === 'DeclareContext' &&
147233
+ instruction.value.lvalue.kind === 'HoistedConst'
147234
+ ) {
147235
+ state.set(
147236
+ instruction.value.lvalue.place.identifier.declarationId,
147237
+ InstructionKind.Const
147061
147238
  );
147062
- for (const dep of deps) {
147063
- results.add({identifier: rootId, path: dep.relativePath});
147064
- }
147065
- }
147066
- return results;
147067
- }
147068
- addDepsFromInnerScope(
147069
- depsFromInnerScope,
147070
- innerScopeInConditionalWithinParent,
147071
- checkValidDepIdFn
147072
- ) {
147073
- for (const [id, otherRoot] of __classPrivateFieldGet(
147074
- depsFromInnerScope,
147075
- _ReactiveScopeDependencyTree_roots,
147076
- 'f'
147077
- )) {
147078
- if (!checkValidDepIdFn({identifier: id, path: []})) {
147079
- continue;
147080
- }
147081
- let currRoot = __classPrivateFieldGet(
147082
- this,
147083
- _ReactiveScopeDependencyTree_instances,
147084
- 'm',
147085
- _ReactiveScopeDependencyTree_getOrCreateRoot
147086
- ).call(this, id);
147087
- addSubtree(currRoot, otherRoot, innerScopeInConditionalWithinParent);
147088
- if (!isUnconditional(currRoot.accessType)) {
147089
- currRoot.accessType = isDependency$1(currRoot.accessType)
147090
- ? PropertyAccessType$1.UnconditionalDependency
147091
- : PropertyAccessType$1.UnconditionalAccess;
147092
- }
147093
- }
147094
- }
147095
- promoteDepsFromExhaustiveConditionals(trees) {
147096
- CompilerError.invariant(trees.length > 1, {
147097
- reason: 'Expected trees to be at least 2 elements long.',
147098
- description: null,
147099
- loc: null,
147100
- suggestions: null,
147101
- });
147102
- for (const [id, root] of __classPrivateFieldGet(
147103
- this,
147104
- _ReactiveScopeDependencyTree_roots,
147105
- 'f'
147106
- )) {
147107
- const nodesForRootId = mapNonNull(trees, tree => {
147108
- const node = __classPrivateFieldGet(
147109
- tree,
147110
- _ReactiveScopeDependencyTree_roots,
147111
- 'f'
147112
- ).get(id);
147113
- if (node != null && isUnconditional(node.accessType)) {
147114
- return node;
147115
- } else {
147116
- return null;
147117
- }
147118
- });
147119
- if (nodesForRootId) {
147120
- addSubtreeIntersection(
147121
- root.properties,
147122
- nodesForRootId.map(root => root.properties)
147123
- );
147124
- }
147239
+ return {kind: 'remove'};
147125
147240
  }
147126
- }
147127
- printDeps(includeAccesses) {
147128
- let res = [];
147129
- for (const [rootId, rootNode] of __classPrivateFieldGet(
147130
- this,
147131
- _ReactiveScopeDependencyTree_roots,
147132
- 'f'
147133
- ).entries()) {
147134
- const rootResults = printSubtree$1(rootNode, includeAccesses).map(
147135
- result => `${printIdentifier(rootId)}.${result}`
147241
+ if (
147242
+ instruction.value.kind === 'DeclareContext' &&
147243
+ instruction.value.lvalue.kind === 'HoistedLet'
147244
+ ) {
147245
+ state.set(
147246
+ instruction.value.lvalue.place.identifier.declarationId,
147247
+ InstructionKind.Let
147136
147248
  );
147137
- res.push(rootResults);
147249
+ return {kind: 'remove'};
147138
147250
  }
147139
- return res.flat().join('\n');
147140
- }
147141
- debug() {
147142
- const buf = [`tree() [`];
147143
- for (const [rootId, rootNode] of __classPrivateFieldGet(
147144
- this,
147145
- _ReactiveScopeDependencyTree_roots,
147146
- 'f'
147147
- )) {
147148
- buf.push(`${printIdentifier(rootId)} (${rootNode.accessType}):`);
147149
- __classPrivateFieldGet(
147150
- this,
147151
- _ReactiveScopeDependencyTree_instances,
147152
- 'm',
147153
- _ReactiveScopeDependencyTree_debugImpl
147154
- ).call(this, buf, rootNode, 1);
147155
- }
147156
- buf.push(']');
147157
- return buf.length > 2 ? buf.join('\n') : buf.join('');
147158
- }
147159
- }
147160
- (_ReactiveScopeDependencyTree_roots = new WeakMap()),
147161
- (_ReactiveScopeDependencyTree_instances = new WeakSet()),
147162
- (_ReactiveScopeDependencyTree_getOrCreateRoot =
147163
- function _ReactiveScopeDependencyTree_getOrCreateRoot(identifier) {
147164
- let rootNode = __classPrivateFieldGet(
147165
- this,
147166
- _ReactiveScopeDependencyTree_roots,
147167
- 'f'
147168
- ).get(identifier);
147169
- if (rootNode === undefined) {
147170
- rootNode = {
147171
- properties: new Map(),
147172
- accessType: PropertyAccessType$1.UnconditionalAccess,
147173
- };
147174
- __classPrivateFieldGet(
147175
- this,
147176
- _ReactiveScopeDependencyTree_roots,
147177
- 'f'
147178
- ).set(identifier, rootNode);
147179
- }
147180
- return rootNode;
147181
- }),
147182
- (_ReactiveScopeDependencyTree_debugImpl =
147183
- function _ReactiveScopeDependencyTree_debugImpl(buf, node, depth = 0) {
147184
- for (const [property, childNode] of node.properties) {
147185
- buf.push(
147186
- `${' '.repeat(depth)}.${property} (${childNode.accessType}):`
147187
- );
147188
- __classPrivateFieldGet(
147189
- this,
147190
- _ReactiveScopeDependencyTree_instances,
147191
- 'm',
147192
- _ReactiveScopeDependencyTree_debugImpl
147193
- ).call(this, buf, childNode, depth + 1);
147194
- }
147195
- });
147196
- var PropertyAccessType$1;
147197
- (function (PropertyAccessType) {
147198
- PropertyAccessType['ConditionalAccess'] = 'ConditionalAccess';
147199
- PropertyAccessType['OptionalAccess'] = 'OptionalAccess';
147200
- PropertyAccessType['UnconditionalAccess'] = 'UnconditionalAccess';
147201
- PropertyAccessType['ConditionalDependency'] = 'ConditionalDependency';
147202
- PropertyAccessType['OptionalDependency'] = 'OptionalDependency';
147203
- PropertyAccessType['UnconditionalDependency'] = 'UnconditionalDependency';
147204
- })(PropertyAccessType$1 || (PropertyAccessType$1 = {}));
147205
- const MIN_ACCESS_TYPE = PropertyAccessType$1.ConditionalAccess;
147206
- function isUnconditional(access) {
147207
- return (
147208
- access === PropertyAccessType$1.UnconditionalAccess ||
147209
- access === PropertyAccessType$1.UnconditionalDependency
147210
- );
147211
- }
147212
- function isDependency$1(access) {
147213
- return (
147214
- access === PropertyAccessType$1.ConditionalDependency ||
147215
- access === PropertyAccessType$1.OptionalDependency ||
147216
- access === PropertyAccessType$1.UnconditionalDependency
147217
- );
147218
- }
147219
- function isOptional$1(access) {
147220
- return (
147221
- access === PropertyAccessType$1.OptionalAccess ||
147222
- access === PropertyAccessType$1.OptionalDependency
147223
- );
147224
- }
147225
- function merge$1(access1, access2) {
147226
- const resultIsUnconditional =
147227
- isUnconditional(access1) || isUnconditional(access2);
147228
- const resultIsDependency = isDependency$1(access1) || isDependency$1(access2);
147229
- const resultIsOptional = isOptional$1(access1) || isOptional$1(access2);
147230
- if (resultIsUnconditional) {
147231
- if (resultIsDependency) {
147232
- return PropertyAccessType$1.UnconditionalDependency;
147233
- } else {
147234
- return PropertyAccessType$1.UnconditionalAccess;
147235
- }
147236
- } else if (resultIsOptional) {
147237
- if (resultIsDependency) {
147238
- return PropertyAccessType$1.OptionalDependency;
147239
- } else {
147240
- return PropertyAccessType$1.OptionalAccess;
147241
- }
147242
- } else {
147243
- if (resultIsDependency) {
147244
- return PropertyAccessType$1.ConditionalDependency;
147245
- } else {
147246
- return PropertyAccessType$1.ConditionalAccess;
147247
- }
147248
- }
147249
- }
147250
- function promoteResult(accessType, path) {
147251
- const result = {relativePath: [], accessType: accessType};
147252
- if (path !== null) {
147253
- result.relativePath.push(path);
147254
- }
147255
- return [result];
147256
- }
147257
- function prependPath(results, path) {
147258
- if (path === null) {
147259
- return results;
147260
- }
147261
- return results.map(result => ({
147262
- accessType: result.accessType,
147263
- relativePath: [path, ...result.relativePath],
147264
- }));
147265
- }
147266
- function deriveMinimalDependenciesInSubtree(dep, property) {
147267
- const results = [];
147268
- for (const [childName, childNode] of dep.properties) {
147269
- const childResult = deriveMinimalDependenciesInSubtree(
147270
- childNode,
147271
- childName
147272
- );
147273
- results.push(...childResult);
147274
- }
147275
- switch (dep.accessType) {
147276
- case PropertyAccessType$1.UnconditionalDependency: {
147277
- return promoteResult(
147278
- PropertyAccessType$1.UnconditionalDependency,
147279
- property !== null ? {property: property, optional: false} : null
147280
- );
147281
- }
147282
- case PropertyAccessType$1.UnconditionalAccess: {
147283
- if (
147284
- results.every(
147285
- ({accessType: accessType}) =>
147286
- accessType === PropertyAccessType$1.UnconditionalDependency ||
147287
- accessType === PropertyAccessType$1.OptionalDependency
147288
- )
147289
- ) {
147290
- return prependPath(
147291
- results,
147292
- property !== null ? {property: property, optional: false} : null
147293
- );
147294
- } else {
147295
- return promoteResult(
147296
- PropertyAccessType$1.UnconditionalDependency,
147297
- property !== null ? {property: property, optional: false} : null
147298
- );
147299
- }
147300
- }
147301
- case PropertyAccessType$1.OptionalDependency: {
147302
- return promoteResult(
147303
- PropertyAccessType$1.OptionalDependency,
147304
- property !== null ? {property: property, optional: true} : null
147305
- );
147306
- }
147307
- case PropertyAccessType$1.OptionalAccess: {
147308
- if (
147309
- results.every(
147310
- ({accessType: accessType}) =>
147311
- accessType === PropertyAccessType$1.UnconditionalDependency ||
147312
- accessType === PropertyAccessType$1.OptionalDependency
147313
- )
147314
- ) {
147315
- return prependPath(
147316
- results,
147317
- property !== null ? {property: property, optional: true} : null
147318
- );
147319
- } else {
147320
- return promoteResult(
147321
- PropertyAccessType$1.OptionalDependency,
147322
- property !== null ? {property: property, optional: true} : null
147323
- );
147324
- }
147325
- }
147326
- case PropertyAccessType$1.ConditionalAccess:
147327
- case PropertyAccessType$1.ConditionalDependency: {
147328
- if (
147329
- results.every(
147330
- ({accessType: accessType}) =>
147331
- accessType === PropertyAccessType$1.ConditionalDependency
147332
- )
147333
- ) {
147334
- return promoteResult(
147335
- PropertyAccessType$1.ConditionalDependency,
147336
- property !== null ? {property: property, optional: true} : null
147337
- );
147338
- } else {
147339
- return promoteResult(
147340
- PropertyAccessType$1.UnconditionalDependency,
147341
- property !== null ? {property: property, optional: true} : null
147342
- );
147343
- }
147344
- }
147345
- default: {
147346
- assertExhaustive(
147347
- dep.accessType,
147348
- '[PropgateScopeDependencies] Unhandled access type!'
147349
- );
147350
- }
147351
- }
147352
- }
147353
- function demoteSubtreeToConditional(subtree) {
147354
- const stack = [subtree];
147355
- let node;
147356
- while ((node = stack.pop()) !== undefined) {
147357
- const {accessType: accessType, properties: properties} = node;
147358
- if (!isUnconditional(accessType)) {
147359
- continue;
147360
- }
147361
- node.accessType = isDependency$1(accessType)
147362
- ? PropertyAccessType$1.ConditionalDependency
147363
- : PropertyAccessType$1.ConditionalAccess;
147364
- for (const childNode of properties.values()) {
147365
- if (isUnconditional(accessType)) {
147366
- stack.push(childNode);
147367
- }
147368
- }
147369
- }
147370
- }
147371
- function addSubtree(currNode, otherNode, demoteOtherNode) {
147372
- let otherType = otherNode.accessType;
147373
- if (demoteOtherNode) {
147374
- otherType = isDependency$1(otherType)
147375
- ? PropertyAccessType$1.ConditionalDependency
147376
- : PropertyAccessType$1.ConditionalAccess;
147377
- }
147378
- currNode.accessType = merge$1(currNode.accessType, otherType);
147379
- for (const [propertyName, otherChild] of otherNode.properties) {
147380
- const currChild = currNode.properties.get(propertyName);
147381
- if (currChild) {
147382
- addSubtree(currChild, otherChild, demoteOtherNode);
147383
- } else {
147384
- if (demoteOtherNode) {
147385
- demoteSubtreeToConditional(otherChild);
147386
- }
147387
- currNode.properties.set(propertyName, otherChild);
147388
- }
147389
- }
147390
- }
147391
- function addSubtreeIntersection(currProperties, otherProperties) {
147392
- CompilerError.invariant(otherProperties.length > 1, {
147393
- reason:
147394
- '[DeriveMinimalDependencies] Expected otherProperties to be at least 2 elements long.',
147395
- description: null,
147396
- loc: null,
147397
- suggestions: null,
147398
- });
147399
- for (const [propertyName, currNode] of currProperties) {
147400
- const otherNodes = mapNonNull(otherProperties, properties => {
147401
- const node = properties.get(propertyName);
147402
- if (node != null && isUnconditional(node.accessType)) {
147403
- return node;
147404
- } else {
147405
- return null;
147406
- }
147407
- });
147408
- if (otherNodes) {
147409
- addSubtreeIntersection(
147410
- currNode.properties,
147411
- otherNodes.map(node => node.properties)
147412
- );
147413
- const isDep = otherNodes.some(tree => isDependency$1(tree.accessType));
147414
- const externalAccessType = isDep
147415
- ? PropertyAccessType$1.UnconditionalDependency
147416
- : PropertyAccessType$1.UnconditionalAccess;
147417
- currNode.accessType = merge$1(externalAccessType, currNode.accessType);
147418
- }
147419
- }
147420
- }
147421
- function printSubtree$1(node, includeAccesses) {
147422
- const results = [];
147423
- for (const [propertyName, propertyNode] of node.properties) {
147424
- if (includeAccesses || isDependency$1(propertyNode.accessType)) {
147425
- results.push(`${propertyName} (${propertyNode.accessType})`);
147426
- }
147427
- const propertyResults = printSubtree$1(propertyNode, includeAccesses);
147428
- results.push(...propertyResults.map(result => `${propertyName}.${result}`));
147429
- }
147430
- return results;
147431
- }
147432
- function getOrMakeProperty(node, property) {
147433
- let child = node.properties.get(property);
147434
- if (child == null) {
147435
- child = {properties: new Map(), accessType: MIN_ACCESS_TYPE};
147436
- node.properties.set(property, child);
147437
- }
147438
- return child;
147439
- }
147440
- function mapNonNull(arr, fn) {
147441
- const result = [];
147442
- for (let i = 0; i < arr.length; i++) {
147443
- const element = fn(arr[i]);
147444
- if (element) {
147445
- result.push(element);
147446
- } else {
147447
- return null;
147448
- }
147449
- }
147450
- return result;
147451
- }
147452
- var _PoisonState_instances,
147453
- _PoisonState_invalidate,
147454
- _Context_instances$1,
147455
- _Context_temporariesUsedOutsideScope$1,
147456
- _Context_declarations$1,
147457
- _Context_reassignments$1,
147458
- _Context_dependencies$1,
147459
- _Context_properties,
147460
- _Context_temporaries$1,
147461
- _Context_inConditionalWithinScope,
147462
- _Context_depsInCurrentConditional,
147463
- _Context_scopes$1,
147464
- _Context_getProperty,
147465
- _Context_checkValidDependency$1,
147466
- _Context_isScopeActive$1;
147467
- function propagateScopeDependencies(fn) {
147468
- const escapingTemporaries = {
147469
- declarations: new Map(),
147470
- usedOutsideDeclaringScope: new Set(),
147471
- };
147472
- visitReactiveFunction(fn, new FindPromotedTemporaries(), escapingTemporaries);
147473
- const context = new Context$1(escapingTemporaries.usedOutsideDeclaringScope);
147474
- for (const param of fn.params) {
147475
- if (param.kind === 'Identifier') {
147476
- context.declare(param.identifier, {
147477
- id: makeInstructionId(0),
147478
- scope: empty(),
147479
- });
147480
- } else {
147481
- context.declare(param.place.identifier, {
147482
- id: makeInstructionId(0),
147483
- scope: empty(),
147484
- });
147485
- }
147486
- }
147487
- visitReactiveFunction(fn, new PropagationVisitor(fn.env), context);
147488
- }
147489
- class FindPromotedTemporaries extends ReactiveFunctionVisitor {
147490
- constructor() {
147491
- super(...arguments);
147492
- this.scopes = [];
147493
- }
147494
- visitScope(scope, state) {
147495
- this.scopes.push(scope.scope.id);
147496
- this.traverseScope(scope, state);
147497
- this.scopes.pop();
147498
- }
147499
- visitInstruction(instruction, state) {
147500
- this.traverseInstruction(instruction, state);
147501
- const scope = this.scopes.at(-1);
147502
- if (instruction.lvalue === null || scope === undefined) {
147503
- return;
147504
- }
147505
- switch (instruction.value.kind) {
147506
- case 'LoadLocal':
147507
- case 'LoadContext':
147508
- case 'PropertyLoad': {
147509
- state.declarations.set(
147510
- instruction.lvalue.identifier.declarationId,
147511
- scope
147512
- );
147513
- break;
147514
- }
147515
- }
147516
- }
147517
- visitPlace(_id, place, state) {
147518
- const declaringScope = state.declarations.get(
147519
- place.identifier.declarationId
147520
- );
147521
- if (declaringScope === undefined) {
147522
- return;
147523
- }
147524
- if (this.scopes.indexOf(declaringScope) === -1) {
147525
- state.usedOutsideDeclaringScope.add(place.identifier.declarationId);
147526
- }
147527
- }
147528
- }
147529
- class PoisonState {
147530
- constructor(poisonedBlocks, poisonedScopes, isPoisoned) {
147531
- _PoisonState_instances.add(this);
147532
- this.poisonedBlocks = new Set();
147533
- this.poisonedScopes = new Set();
147534
- this.isPoisoned = false;
147535
- this.poisonedBlocks = poisonedBlocks;
147536
- this.poisonedScopes = poisonedScopes;
147537
- this.isPoisoned = isPoisoned;
147538
- }
147539
- clone() {
147540
- return new PoisonState(
147541
- new Set(this.poisonedBlocks),
147542
- new Set(this.poisonedScopes),
147543
- this.isPoisoned
147544
- );
147545
- }
147546
- take(other) {
147547
- const copy = new PoisonState(
147548
- this.poisonedBlocks,
147549
- this.poisonedScopes,
147550
- this.isPoisoned
147551
- );
147552
- this.poisonedBlocks = other.poisonedBlocks;
147553
- this.poisonedScopes = other.poisonedScopes;
147554
- this.isPoisoned = other.isPoisoned;
147555
- return copy;
147556
- }
147557
- merge(others, currentScope) {
147558
- for (const other of others) {
147559
- for (const id of other.poisonedBlocks) {
147560
- this.poisonedBlocks.add(id);
147561
- }
147562
- for (const id of other.poisonedScopes) {
147563
- this.poisonedScopes.add(id);
147564
- }
147565
- }
147566
- __classPrivateFieldGet(
147567
- this,
147568
- _PoisonState_instances,
147569
- 'm',
147570
- _PoisonState_invalidate
147571
- ).call(this, currentScope);
147572
- }
147573
- addPoisonTarget(target, activeScopes) {
147574
- const currentScope = activeScopes.value;
147575
- if (target == null && currentScope != null) {
147576
- let cursor = activeScopes;
147577
- while (true) {
147578
- const next = cursor.pop();
147579
- if (next.value == null) {
147580
- const poisonedScope = cursor.value.value.id;
147581
- this.poisonedScopes.add(poisonedScope);
147582
- if (
147583
- poisonedScope ===
147584
- (currentScope === null || currentScope === void 0
147585
- ? void 0
147586
- : currentScope.value.id)
147587
- ) {
147588
- this.isPoisoned = true;
147589
- }
147590
- break;
147591
- } else {
147592
- cursor = next;
147593
- }
147594
- }
147595
- } else if (target != null) {
147596
- this.poisonedBlocks.add(target);
147597
- if (
147598
- !this.isPoisoned &&
147599
- (currentScope === null || currentScope === void 0
147600
- ? void 0
147601
- : currentScope.ownBlocks.find(blockId => blockId === target))
147602
- ) {
147603
- this.isPoisoned = true;
147604
- }
147605
- }
147606
- }
147607
- removeMaybePoisonedScope(id, currentScope) {
147608
- this.poisonedScopes.delete(id);
147609
- __classPrivateFieldGet(
147610
- this,
147611
- _PoisonState_instances,
147612
- 'm',
147613
- _PoisonState_invalidate
147614
- ).call(this, currentScope);
147615
- }
147616
- removeMaybePoisonedBlock(id, currentScope) {
147617
- this.poisonedBlocks.delete(id);
147618
- __classPrivateFieldGet(
147619
- this,
147620
- _PoisonState_instances,
147621
- 'm',
147622
- _PoisonState_invalidate
147623
- ).call(this, currentScope);
147624
- }
147625
- }
147626
- (_PoisonState_instances = new WeakSet()),
147627
- (_PoisonState_invalidate = function _PoisonState_invalidate(currentScope) {
147628
- if (currentScope != null) {
147629
- if (this.poisonedScopes.has(currentScope.value.id)) {
147630
- this.isPoisoned = true;
147631
- return;
147632
- } else if (
147633
- currentScope.ownBlocks.find(blockId => this.poisonedBlocks.has(blockId))
147634
- ) {
147635
- this.isPoisoned = true;
147636
- return;
147637
- }
147638
- }
147639
- this.isPoisoned = false;
147640
- });
147641
- let Context$1 = class Context {
147642
- constructor(temporariesUsedOutsideScope) {
147643
- _Context_instances$1.add(this);
147644
- _Context_temporariesUsedOutsideScope$1.set(this, void 0);
147645
- _Context_declarations$1.set(this, new Map());
147646
- _Context_reassignments$1.set(this, new Map());
147647
- _Context_dependencies$1.set(this, new ReactiveScopeDependencyTree());
147648
- _Context_properties.set(this, new Map());
147649
- _Context_temporaries$1.set(this, new Map());
147650
- _Context_inConditionalWithinScope.set(this, false);
147651
- _Context_depsInCurrentConditional.set(
147652
- this,
147653
- new ReactiveScopeDependencyTree()
147654
- );
147655
- _Context_scopes$1.set(this, empty());
147656
- this.poisonState = new PoisonState(new Set(), new Set(), false);
147657
- __classPrivateFieldSet(
147658
- this,
147659
- _Context_temporariesUsedOutsideScope$1,
147660
- temporariesUsedOutsideScope,
147661
- 'f'
147662
- );
147663
- }
147664
- enter(scope, fn) {
147665
- const prevInConditional = __classPrivateFieldGet(
147666
- this,
147667
- _Context_inConditionalWithinScope,
147668
- 'f'
147669
- );
147670
- const previousDependencies = __classPrivateFieldGet(
147671
- this,
147672
- _Context_dependencies$1,
147673
- 'f'
147674
- );
147675
- const prevDepsInConditional = this.isPoisoned
147676
- ? __classPrivateFieldGet(this, _Context_depsInCurrentConditional, 'f')
147677
- : null;
147678
- if (prevDepsInConditional != null) {
147679
- __classPrivateFieldSet(
147680
- this,
147681
- _Context_depsInCurrentConditional,
147682
- new ReactiveScopeDependencyTree(),
147683
- 'f'
147684
- );
147685
- }
147686
- const scopedDependencies = new ReactiveScopeDependencyTree();
147687
- __classPrivateFieldSet(this, _Context_inConditionalWithinScope, false, 'f');
147688
- __classPrivateFieldSet(
147689
- this,
147690
- _Context_dependencies$1,
147691
- scopedDependencies,
147692
- 'f'
147693
- );
147694
- __classPrivateFieldSet(
147695
- this,
147696
- _Context_scopes$1,
147697
- __classPrivateFieldGet(this, _Context_scopes$1, 'f').push({
147698
- value: scope,
147699
- ownBlocks: empty(),
147700
- }),
147701
- 'f'
147702
- );
147703
- this.poisonState.isPoisoned = false;
147704
- fn();
147705
- __classPrivateFieldSet(
147706
- this,
147707
- _Context_scopes$1,
147708
- __classPrivateFieldGet(this, _Context_scopes$1, 'f').pop(),
147709
- 'f'
147710
- );
147711
- this.poisonState.removeMaybePoisonedScope(
147712
- scope.id,
147713
- __classPrivateFieldGet(this, _Context_scopes$1, 'f').value
147714
- );
147715
- __classPrivateFieldSet(
147716
- this,
147717
- _Context_dependencies$1,
147718
- previousDependencies,
147719
- 'f'
147720
- );
147721
- __classPrivateFieldSet(
147722
- this,
147723
- _Context_inConditionalWithinScope,
147724
- prevInConditional,
147725
- 'f'
147726
- );
147727
- const minInnerScopeDependencies =
147728
- scopedDependencies.deriveMinimalDependencies();
147729
- __classPrivateFieldGet(
147730
- this,
147731
- _Context_dependencies$1,
147732
- 'f'
147733
- ).addDepsFromInnerScope(
147734
- scopedDependencies,
147735
- __classPrivateFieldGet(this, _Context_inConditionalWithinScope, 'f') ||
147736
- this.isPoisoned,
147737
- __classPrivateFieldGet(
147738
- this,
147739
- _Context_instances$1,
147740
- 'm',
147741
- _Context_checkValidDependency$1
147742
- ).bind(this)
147743
- );
147744
- if (prevDepsInConditional != null) {
147745
- prevDepsInConditional.addDepsFromInnerScope(
147746
- __classPrivateFieldGet(this, _Context_depsInCurrentConditional, 'f'),
147747
- true,
147748
- __classPrivateFieldGet(
147749
- this,
147750
- _Context_instances$1,
147751
- 'm',
147752
- _Context_checkValidDependency$1
147753
- ).bind(this)
147754
- );
147755
- __classPrivateFieldSet(
147756
- this,
147757
- _Context_depsInCurrentConditional,
147758
- prevDepsInConditional,
147759
- 'f'
147760
- );
147761
- }
147762
- return minInnerScopeDependencies;
147763
- }
147764
- isUsedOutsideDeclaringScope(place) {
147765
- return __classPrivateFieldGet(
147766
- this,
147767
- _Context_temporariesUsedOutsideScope$1,
147768
- 'f'
147769
- ).has(place.identifier.declarationId);
147770
- }
147771
- printDeps(includeAccesses = false) {
147772
- return __classPrivateFieldGet(this, _Context_dependencies$1, 'f').printDeps(
147773
- includeAccesses
147774
- );
147775
- }
147776
- enterConditional(fn) {
147777
- const prevInConditional = __classPrivateFieldGet(
147778
- this,
147779
- _Context_inConditionalWithinScope,
147780
- 'f'
147781
- );
147782
- const prevUncondAccessed = __classPrivateFieldGet(
147783
- this,
147784
- _Context_depsInCurrentConditional,
147785
- 'f'
147786
- );
147787
- __classPrivateFieldSet(this, _Context_inConditionalWithinScope, true, 'f');
147788
- __classPrivateFieldSet(
147789
- this,
147790
- _Context_depsInCurrentConditional,
147791
- new ReactiveScopeDependencyTree(),
147792
- 'f'
147793
- );
147794
- fn();
147795
- const result = __classPrivateFieldGet(
147796
- this,
147797
- _Context_depsInCurrentConditional,
147798
- 'f'
147799
- );
147800
- __classPrivateFieldSet(
147801
- this,
147802
- _Context_inConditionalWithinScope,
147803
- prevInConditional,
147804
- 'f'
147805
- );
147806
- __classPrivateFieldSet(
147807
- this,
147808
- _Context_depsInCurrentConditional,
147809
- prevUncondAccessed,
147810
- 'f'
147811
- );
147812
- return result;
147813
- }
147814
- promoteDepsFromExhaustiveConditionals(depsInConditionals) {
147815
- __classPrivateFieldGet(
147816
- this,
147817
- _Context_dependencies$1,
147818
- 'f'
147819
- ).promoteDepsFromExhaustiveConditionals(depsInConditionals);
147820
- __classPrivateFieldGet(
147821
- this,
147822
- _Context_depsInCurrentConditional,
147823
- 'f'
147824
- ).promoteDepsFromExhaustiveConditionals(depsInConditionals);
147825
- }
147826
- declare(identifier, decl) {
147827
- if (
147828
- !__classPrivateFieldGet(this, _Context_declarations$1, 'f').has(
147829
- identifier.declarationId
147830
- )
147831
- ) {
147832
- __classPrivateFieldGet(this, _Context_declarations$1, 'f').set(
147833
- identifier.declarationId,
147834
- decl
147835
- );
147836
- }
147837
- __classPrivateFieldGet(this, _Context_reassignments$1, 'f').set(
147838
- identifier,
147839
- decl
147840
- );
147841
- }
147842
- declareTemporary(lvalue, place) {
147843
- __classPrivateFieldGet(this, _Context_temporaries$1, 'f').set(
147844
- lvalue.identifier,
147845
- place
147846
- );
147847
- }
147848
- resolveTemporary(place) {
147849
- var _a;
147850
- return (_a = __classPrivateFieldGet(this, _Context_temporaries$1, 'f').get(
147851
- place.identifier
147852
- )) !== null && _a !== void 0
147853
- ? _a
147854
- : place;
147855
- }
147856
- declareProperty(lvalue, object, property, optional) {
147857
- const nextDependency = __classPrivateFieldGet(
147858
- this,
147859
- _Context_instances$1,
147860
- 'm',
147861
- _Context_getProperty
147862
- ).call(this, object, property, optional);
147863
- __classPrivateFieldGet(this, _Context_properties, 'f').set(
147864
- lvalue.identifier,
147865
- nextDependency
147866
- );
147867
- }
147868
- get currentScope() {
147869
- return __classPrivateFieldGet(this, _Context_scopes$1, 'f');
147870
- }
147871
- get isPoisoned() {
147872
- return this.poisonState.isPoisoned;
147873
- }
147874
- visitOperand(place) {
147875
- const resolved = this.resolveTemporary(place);
147876
- let dependency = {identifier: resolved.identifier, path: []};
147877
- if (resolved.identifier.name === null) {
147878
- const propertyDependency = __classPrivateFieldGet(
147879
- this,
147880
- _Context_properties,
147881
- 'f'
147882
- ).get(resolved.identifier);
147883
- if (propertyDependency !== undefined) {
147884
- dependency = Object.assign({}, propertyDependency);
147885
- }
147886
- }
147887
- this.visitDependency(dependency);
147888
- }
147889
- visitProperty(object, property, optional) {
147890
- const nextDependency = __classPrivateFieldGet(
147891
- this,
147892
- _Context_instances$1,
147893
- 'm',
147894
- _Context_getProperty
147895
- ).call(this, object, property, optional);
147896
- this.visitDependency(nextDependency);
147897
- }
147898
- visitDependency(maybeDependency) {
147899
- const originalDeclaration = __classPrivateFieldGet(
147900
- this,
147901
- _Context_declarations$1,
147902
- 'f'
147903
- ).get(maybeDependency.identifier.declarationId);
147904
- if (
147905
- originalDeclaration !== undefined &&
147906
- originalDeclaration.scope.value !== null
147907
- ) {
147908
- originalDeclaration.scope.each(scope => {
147909
- if (
147910
- !__classPrivateFieldGet(
147911
- this,
147912
- _Context_instances$1,
147913
- 'm',
147914
- _Context_isScopeActive$1
147915
- ).call(this, scope.value) &&
147916
- !Iterable_some(
147917
- scope.value.declarations.values(),
147918
- decl =>
147919
- decl.identifier.declarationId ===
147920
- maybeDependency.identifier.declarationId
147921
- )
147922
- ) {
147923
- scope.value.declarations.set(maybeDependency.identifier.id, {
147924
- identifier: maybeDependency.identifier,
147925
- scope: originalDeclaration.scope.value.value,
147926
- });
147927
- }
147928
- });
147929
- }
147930
- if (
147931
- __classPrivateFieldGet(
147932
- this,
147933
- _Context_instances$1,
147934
- 'm',
147935
- _Context_checkValidDependency$1
147936
- ).call(this, maybeDependency)
147937
- ) {
147938
- const isPoisoned = this.isPoisoned;
147939
- __classPrivateFieldGet(this, _Context_depsInCurrentConditional, 'f').add(
147940
- maybeDependency,
147941
- isPoisoned
147942
- );
147943
- __classPrivateFieldGet(this, _Context_dependencies$1, 'f').add(
147944
- maybeDependency,
147945
- __classPrivateFieldGet(this, _Context_inConditionalWithinScope, 'f') ||
147946
- isPoisoned
147947
- );
147948
- }
147949
- }
147950
- visitReassignment(place) {
147951
- var _a;
147952
- const currentScope =
147953
- (_a = this.currentScope.value) === null || _a === void 0
147954
- ? void 0
147955
- : _a.value;
147956
- if (
147957
- currentScope != null &&
147958
- !Iterable_some(
147959
- currentScope.reassignments,
147960
- identifier =>
147961
- identifier.declarationId === place.identifier.declarationId
147962
- ) &&
147963
- __classPrivateFieldGet(
147964
- this,
147965
- _Context_instances$1,
147966
- 'm',
147967
- _Context_checkValidDependency$1
147968
- ).call(this, {identifier: place.identifier, path: []})
147969
- ) {
147970
- currentScope.reassignments.add(place.identifier);
147971
- }
147972
- }
147973
- pushLabeledBlock(id) {
147974
- const currentScope = __classPrivateFieldGet(
147975
- this,
147976
- _Context_scopes$1,
147977
- 'f'
147978
- ).value;
147979
- if (currentScope != null) {
147980
- currentScope.ownBlocks = currentScope.ownBlocks.push(id);
147981
- }
147982
- }
147983
- popLabeledBlock(id) {
147984
- const currentScope = __classPrivateFieldGet(
147985
- this,
147986
- _Context_scopes$1,
147987
- 'f'
147988
- ).value;
147989
- if (currentScope != null) {
147990
- const last = currentScope.ownBlocks.value;
147991
- currentScope.ownBlocks = currentScope.ownBlocks.pop();
147992
- CompilerError.invariant(last != null && last === id, {
147993
- reason: '[PropagateScopeDependencies] Misformed block stack',
147994
- loc: GeneratedSource,
147995
- });
147996
- }
147997
- this.poisonState.removeMaybePoisonedBlock(id, currentScope);
147998
- }
147999
- };
148000
- (_Context_temporariesUsedOutsideScope$1 = new WeakMap()),
148001
- (_Context_declarations$1 = new WeakMap()),
148002
- (_Context_reassignments$1 = new WeakMap()),
148003
- (_Context_dependencies$1 = new WeakMap()),
148004
- (_Context_properties = new WeakMap()),
148005
- (_Context_temporaries$1 = new WeakMap()),
148006
- (_Context_inConditionalWithinScope = new WeakMap()),
148007
- (_Context_depsInCurrentConditional = new WeakMap()),
148008
- (_Context_scopes$1 = new WeakMap()),
148009
- (_Context_instances$1 = new WeakSet()),
148010
- (_Context_getProperty = function _Context_getProperty(
148011
- object,
148012
- property,
148013
- optional
148014
- ) {
148015
- const resolvedObject = this.resolveTemporary(object);
148016
- const resolvedDependency = __classPrivateFieldGet(
148017
- this,
148018
- _Context_properties,
148019
- 'f'
148020
- ).get(resolvedObject.identifier);
148021
- let objectDependency;
148022
- if (resolvedDependency === undefined) {
148023
- objectDependency = {identifier: resolvedObject.identifier, path: []};
148024
- } else {
148025
- objectDependency = {
148026
- identifier: resolvedDependency.identifier,
148027
- path: [...resolvedDependency.path],
148028
- };
148029
- }
148030
- objectDependency.path.push({property: property, optional: optional});
148031
- return objectDependency;
148032
- }),
148033
- (_Context_checkValidDependency$1 = function _Context_checkValidDependency(
148034
- maybeDependency
148035
- ) {
148036
- var _a, _b, _c, _d;
148037
- if (
148038
- isUseRefType(maybeDependency.identifier) &&
148039
- ((_a = maybeDependency.path.at(0)) === null || _a === void 0
148040
- ? void 0
148041
- : _a.property) === 'current'
148042
- ) {
148043
- return false;
148044
- }
148045
- if (isRefValueType(maybeDependency.identifier)) {
148046
- return false;
148047
- }
148048
- if (isObjectMethodType(maybeDependency.identifier)) {
148049
- return false;
148050
- }
148051
- const identifier = maybeDependency.identifier;
148052
- const currentDeclaration =
148053
- (_b = __classPrivateFieldGet(this, _Context_reassignments$1, 'f').get(
148054
- identifier
148055
- )) !== null && _b !== void 0
148056
- ? _b
148057
- : __classPrivateFieldGet(this, _Context_declarations$1, 'f').get(
148058
- identifier.declarationId
148059
- );
148060
- const currentScope =
148061
- (_c = this.currentScope.value) === null || _c === void 0
148062
- ? void 0
148063
- : _c.value;
148064
- return (
148065
- currentScope != null &&
148066
- currentDeclaration !== undefined &&
148067
- currentDeclaration.id < currentScope.range.start &&
148068
- (currentDeclaration.scope == null ||
148069
- ((_d = currentDeclaration.scope.value) === null || _d === void 0
148070
- ? void 0
148071
- : _d.value) !== currentScope)
148072
- );
148073
- }),
148074
- (_Context_isScopeActive$1 = function _Context_isScopeActive(scope) {
148075
- if (__classPrivateFieldGet(this, _Context_scopes$1, 'f') === null) {
148076
- return false;
148077
- }
148078
- return __classPrivateFieldGet(this, _Context_scopes$1, 'f').find(
148079
- state => state.value === scope
148080
- );
148081
- });
148082
- class PropagationVisitor extends ReactiveFunctionVisitor {
148083
- constructor(env) {
148084
- super();
148085
- this.env = env;
148086
- }
148087
- visitScope(scope, context) {
148088
- const scopeDependencies = context.enter(scope.scope, () => {
148089
- this.visitBlock(scope.instructions, context);
148090
- });
148091
- for (const candidateDep of scopeDependencies) {
148092
- if (
148093
- !Iterable_some(
148094
- scope.scope.dependencies,
148095
- existingDep =>
148096
- existingDep.identifier.declarationId ===
148097
- candidateDep.identifier.declarationId &&
148098
- areEqualPaths(existingDep.path, candidateDep.path)
148099
- )
148100
- ) {
148101
- scope.scope.dependencies.add(candidateDep);
148102
- }
148103
- }
148104
- }
148105
- visitPrunedScope(scopeBlock, context) {
148106
- context.enter(scopeBlock.scope, () => {
148107
- this.visitBlock(scopeBlock.instructions, context);
148108
- });
148109
- }
148110
- visitInstruction(instruction, context) {
148111
- const {id: id, value: value, lvalue: lvalue} = instruction;
148112
- this.visitInstructionValue(context, id, value, lvalue);
148113
- if (lvalue == null) {
148114
- return;
148115
- }
148116
- context.declare(lvalue.identifier, {id: id, scope: context.currentScope});
148117
- }
148118
- extractOptionalProperty(context, optionalValue, lvalue) {
148119
- const sequence = optionalValue.value;
148120
- CompilerError.invariant(sequence.kind === 'SequenceExpression', {
148121
- reason: 'Expected OptionalExpression value to be a SequenceExpression',
148122
- description: `Found a \`${sequence.kind}\``,
148123
- loc: sequence.loc,
148124
- });
148125
- if (
148126
- sequence.instructions.length === 1 &&
148127
- sequence.instructions[0].lvalue !== null &&
148128
- sequence.instructions[0].value.kind === 'LoadLocal' &&
148129
- sequence.instructions[0].value.place.identifier.name !== null &&
148130
- !context.isUsedOutsideDeclaringScope(sequence.instructions[0].lvalue) &&
148131
- sequence.value.kind === 'SequenceExpression' &&
148132
- sequence.value.instructions.length === 1 &&
148133
- sequence.value.instructions[0].value.kind === 'PropertyLoad' &&
148134
- sequence.value.instructions[0].value.object.identifier.id ===
148135
- sequence.instructions[0].lvalue.identifier.id &&
148136
- sequence.value.instructions[0].lvalue !== null &&
148137
- sequence.value.value.kind === 'LoadLocal' &&
148138
- sequence.value.value.place.identifier.id ===
148139
- sequence.value.instructions[0].lvalue.identifier.id
148140
- ) {
148141
- context.declareTemporary(
148142
- sequence.instructions[0].lvalue,
148143
- sequence.instructions[0].value.place
148144
- );
148145
- const propertyLoad = sequence.value.instructions[0].value;
148146
- return {
148147
- lvalue: lvalue,
148148
- object: propertyLoad.object,
148149
- property: propertyLoad.property,
148150
- optional: optionalValue.optional,
148151
- };
148152
- }
148153
- if (
148154
- sequence.instructions.length === 1 &&
148155
- sequence.instructions[0].lvalue !== null &&
148156
- sequence.instructions[0].value.kind === 'SequenceExpression' &&
148157
- sequence.instructions[0].value.instructions.length === 1 &&
148158
- sequence.instructions[0].value.instructions[0].lvalue !== null &&
148159
- sequence.instructions[0].value.instructions[0].value.kind ===
148160
- 'LoadLocal' &&
148161
- sequence.instructions[0].value.instructions[0].value.place.identifier
148162
- .name !== null &&
148163
- !context.isUsedOutsideDeclaringScope(
148164
- sequence.instructions[0].value.instructions[0].lvalue
148165
- ) &&
148166
- sequence.instructions[0].value.value.kind === 'PropertyLoad' &&
148167
- sequence.instructions[0].value.value.object.identifier.id ===
148168
- sequence.instructions[0].value.instructions[0].lvalue.identifier.id &&
148169
- sequence.value.kind === 'SequenceExpression' &&
148170
- sequence.value.instructions.length === 1 &&
148171
- sequence.value.instructions[0].lvalue !== null &&
148172
- sequence.value.instructions[0].value.kind === 'PropertyLoad' &&
148173
- sequence.value.instructions[0].value.object.identifier.id ===
148174
- sequence.instructions[0].lvalue.identifier.id &&
148175
- sequence.value.value.kind === 'LoadLocal' &&
148176
- sequence.value.value.place.identifier.id ===
148177
- sequence.value.instructions[0].lvalue.identifier.id
148178
- ) {
148179
- context.declareTemporary(
148180
- sequence.instructions[0].value.instructions[0].lvalue,
148181
- sequence.instructions[0].value.instructions[0].value.place
148182
- );
148183
- context.declareProperty(
148184
- sequence.instructions[0].lvalue,
148185
- sequence.instructions[0].value.value.object,
148186
- sequence.instructions[0].value.value.property,
148187
- false
148188
- );
148189
- const propertyLoad = sequence.value.instructions[0].value;
148190
- return {
148191
- lvalue: lvalue,
148192
- object: propertyLoad.object,
148193
- property: propertyLoad.property,
148194
- optional: optionalValue.optional,
148195
- };
148196
- }
148197
- if (
148198
- sequence.instructions.length === 1 &&
148199
- sequence.instructions[0].value.kind === 'SequenceExpression' &&
148200
- sequence.instructions[0].value.instructions.length === 1 &&
148201
- sequence.instructions[0].value.instructions[0].lvalue !== null &&
148202
- sequence.instructions[0].value.instructions[0].value.kind ===
148203
- 'OptionalExpression' &&
148204
- sequence.instructions[0].value.value.kind === 'LoadLocal' &&
148205
- sequence.instructions[0].value.value.place.identifier.id ===
148206
- sequence.instructions[0].value.instructions[0].lvalue.identifier.id &&
148207
- sequence.value.kind === 'SequenceExpression' &&
148208
- sequence.value.instructions.length === 1 &&
148209
- sequence.value.instructions[0].lvalue !== null &&
148210
- sequence.value.instructions[0].value.kind === 'PropertyLoad' &&
148211
- sequence.value.instructions[0].value.object.identifier.id ===
148212
- sequence.instructions[0].value.value.place.identifier.id &&
148213
- sequence.value.value.kind === 'LoadLocal' &&
148214
- sequence.value.value.place.identifier.id ===
148215
- sequence.value.instructions[0].lvalue.identifier.id
148216
- ) {
148217
- const {lvalue: innerLvalue, value: innerOptional} =
148218
- sequence.instructions[0].value.instructions[0];
148219
- const innerProperty = this.extractOptionalProperty(
148220
- context,
148221
- innerOptional,
148222
- innerLvalue
148223
- );
148224
- if (innerProperty === null) {
148225
- return null;
148226
- }
148227
- context.declareProperty(
148228
- innerProperty.lvalue,
148229
- innerProperty.object,
148230
- innerProperty.property,
148231
- innerProperty.optional
148232
- );
148233
- const propertyLoad = sequence.value.instructions[0].value;
148234
- return {
148235
- lvalue: lvalue,
148236
- object: propertyLoad.object,
148237
- property: propertyLoad.property,
148238
- optional: optionalValue.optional,
148239
- };
148240
- }
148241
- return null;
148242
- }
148243
- visitOptionalExpression(context, id, value, lvalue) {
148244
- if (
148245
- lvalue !== null &&
148246
- value.optional &&
148247
- this.env.config.enableOptionalDependencies
148248
- ) {
148249
- const inner = this.extractOptionalProperty(context, value, lvalue);
148250
- if (inner !== null) {
148251
- context.visitProperty(inner.object, inner.property, inner.optional);
148252
- return;
148253
- }
148254
- }
148255
- const inner = value.value;
148256
- CompilerError.invariant(inner.kind === 'SequenceExpression', {
148257
- reason: 'Expected OptionalExpression value to be a SequenceExpression',
148258
- description: `Found a \`${value.kind}\``,
148259
- loc: value.loc,
148260
- suggestions: null,
148261
- });
148262
- for (const instr of inner.instructions) {
148263
- this.visitInstruction(instr, context);
148264
- }
148265
- context.enterConditional(() => {
148266
- this.visitReactiveValue(context, id, inner.value, null);
148267
- });
148268
- }
148269
- visitReactiveValue(context, id, value, lvalue) {
148270
- switch (value.kind) {
148271
- case 'OptionalExpression': {
148272
- this.visitOptionalExpression(context, id, value, lvalue);
148273
- break;
148274
- }
148275
- case 'LogicalExpression': {
148276
- this.visitReactiveValue(context, id, value.left, null);
148277
- context.enterConditional(() => {
148278
- this.visitReactiveValue(context, id, value.right, null);
148279
- });
148280
- break;
148281
- }
148282
- case 'ConditionalExpression': {
148283
- this.visitReactiveValue(context, id, value.test, null);
148284
- const consequentDeps = context.enterConditional(() => {
148285
- this.visitReactiveValue(context, id, value.consequent, null);
148286
- });
148287
- const alternateDeps = context.enterConditional(() => {
148288
- this.visitReactiveValue(context, id, value.alternate, null);
148289
- });
148290
- context.promoteDepsFromExhaustiveConditionals([
148291
- consequentDeps,
148292
- alternateDeps,
148293
- ]);
148294
- break;
148295
- }
148296
- case 'SequenceExpression': {
148297
- for (const instr of value.instructions) {
148298
- this.visitInstruction(instr, context);
148299
- }
148300
- this.visitInstructionValue(context, id, value.value, null);
148301
- break;
148302
- }
148303
- case 'FunctionExpression': {
148304
- if (this.env.config.enableTreatFunctionDepsAsConditional) {
148305
- context.enterConditional(() => {
148306
- for (const operand of eachInstructionValueOperand(value)) {
148307
- context.visitOperand(operand);
148308
- }
148309
- });
148310
- } else {
148311
- for (const operand of eachInstructionValueOperand(value)) {
148312
- context.visitOperand(operand);
148313
- }
148314
- }
148315
- break;
148316
- }
148317
- case 'ReactiveFunctionValue': {
148318
- CompilerError.invariant(false, {
148319
- reason: `Unexpected ReactiveFunctionValue`,
148320
- loc: value.loc,
148321
- description: null,
148322
- suggestions: null,
148323
- });
148324
- }
148325
- default: {
148326
- for (const operand of eachInstructionValueOperand(value)) {
148327
- context.visitOperand(operand);
148328
- }
148329
- }
148330
- }
148331
- }
148332
- visitInstructionValue(context, id, value, lvalue) {
148333
- if (value.kind === 'LoadLocal' && lvalue !== null) {
148334
- if (
148335
- value.place.identifier.name !== null &&
148336
- lvalue.identifier.name === null &&
148337
- !context.isUsedOutsideDeclaringScope(lvalue)
148338
- ) {
148339
- context.declareTemporary(lvalue, value.place);
148340
- } else {
148341
- context.visitOperand(value.place);
148342
- }
148343
- } else if (value.kind === 'PropertyLoad') {
148344
- if (lvalue !== null && !context.isUsedOutsideDeclaringScope(lvalue)) {
148345
- context.declareProperty(lvalue, value.object, value.property, false);
148346
- } else {
148347
- context.visitProperty(value.object, value.property, false);
148348
- }
148349
- } else if (value.kind === 'StoreLocal') {
148350
- context.visitOperand(value.value);
148351
- if (value.lvalue.kind === InstructionKind.Reassign) {
148352
- context.visitReassignment(value.lvalue.place);
148353
- }
148354
- context.declare(value.lvalue.place.identifier, {
148355
- id: id,
148356
- scope: context.currentScope,
148357
- });
148358
- } else if (
148359
- value.kind === 'DeclareLocal' ||
148360
- value.kind === 'DeclareContext'
148361
- ) {
148362
- context.declare(value.lvalue.place.identifier, {
148363
- id: id,
148364
- scope: context.currentScope,
148365
- });
148366
- } else if (value.kind === 'Destructure') {
148367
- context.visitOperand(value.value);
148368
- for (const place of eachPatternOperand(value.lvalue.pattern)) {
148369
- if (value.lvalue.kind === InstructionKind.Reassign) {
148370
- context.visitReassignment(place);
148371
- }
148372
- context.declare(place.identifier, {
148373
- id: id,
148374
- scope: context.currentScope,
148375
- });
148376
- }
148377
- } else {
148378
- this.visitReactiveValue(context, id, value, lvalue);
148379
- }
148380
- }
148381
- enterTerminal(stmt, context) {
148382
- if (stmt.label != null) {
148383
- context.pushLabeledBlock(stmt.label.id);
148384
- }
148385
- const terminal = stmt.terminal;
148386
- switch (terminal.kind) {
148387
- case 'continue':
148388
- case 'break': {
148389
- context.poisonState.addPoisonTarget(
148390
- terminal.target,
148391
- context.currentScope
148392
- );
148393
- break;
148394
- }
148395
- case 'throw':
148396
- case 'return': {
148397
- context.poisonState.addPoisonTarget(null, context.currentScope);
148398
- break;
148399
- }
148400
- }
148401
- }
148402
- exitTerminal(stmt, context) {
148403
- if (stmt.label != null) {
148404
- context.popLabeledBlock(stmt.label.id);
148405
- }
148406
- }
148407
- visitTerminal(stmt, context) {
148408
- this.enterTerminal(stmt, context);
148409
- const terminal = stmt.terminal;
148410
- switch (terminal.kind) {
148411
- case 'break':
148412
- case 'continue': {
148413
- break;
148414
- }
148415
- case 'return': {
148416
- context.visitOperand(terminal.value);
148417
- break;
148418
- }
148419
- case 'throw': {
148420
- context.visitOperand(terminal.value);
148421
- break;
148422
- }
148423
- case 'for': {
148424
- this.visitReactiveValue(context, terminal.id, terminal.init, null);
148425
- this.visitReactiveValue(context, terminal.id, terminal.test, null);
148426
- context.enterConditional(() => {
148427
- this.visitBlock(terminal.loop, context);
148428
- if (terminal.update !== null) {
148429
- this.visitReactiveValue(
148430
- context,
148431
- terminal.id,
148432
- terminal.update,
148433
- null
148434
- );
148435
- }
148436
- });
148437
- break;
148438
- }
148439
- case 'for-of': {
148440
- this.visitReactiveValue(context, terminal.id, terminal.init, null);
148441
- context.enterConditional(() => {
148442
- this.visitBlock(terminal.loop, context);
148443
- });
148444
- break;
148445
- }
148446
- case 'for-in': {
148447
- this.visitReactiveValue(context, terminal.id, terminal.init, null);
148448
- context.enterConditional(() => {
148449
- this.visitBlock(terminal.loop, context);
148450
- });
148451
- break;
148452
- }
148453
- case 'do-while': {
148454
- this.visitBlock(terminal.loop, context);
148455
- context.enterConditional(() => {
148456
- this.visitReactiveValue(context, terminal.id, terminal.test, null);
148457
- });
148458
- break;
148459
- }
148460
- case 'while': {
148461
- this.visitReactiveValue(context, terminal.id, terminal.test, null);
148462
- context.enterConditional(() => {
148463
- this.visitBlock(terminal.loop, context);
148464
- });
148465
- break;
148466
- }
148467
- case 'if': {
148468
- context.visitOperand(terminal.test);
148469
- const {consequent: consequent, alternate: alternate} = terminal;
148470
- const prevPoisonState = context.poisonState.clone();
148471
- const depsInIf = context.enterConditional(() => {
148472
- this.visitBlock(consequent, context);
148473
- });
148474
- if (alternate !== null) {
148475
- const ifPoisonState = context.poisonState.take(prevPoisonState);
148476
- const depsInElse = context.enterConditional(() => {
148477
- this.visitBlock(alternate, context);
148478
- });
148479
- context.poisonState.merge(
148480
- [ifPoisonState],
148481
- context.currentScope.value
148482
- );
148483
- context.promoteDepsFromExhaustiveConditionals([depsInIf, depsInElse]);
148484
- }
148485
- break;
148486
- }
148487
- case 'switch': {
148488
- context.visitOperand(terminal.test);
148489
- const isDefaultOnly =
148490
- terminal.cases.length === 1 && terminal.cases[0].test == null;
148491
- if (isDefaultOnly) {
148492
- const case_ = terminal.cases[0];
148493
- if (case_.block != null) {
148494
- this.visitBlock(case_.block, context);
148495
- break;
148496
- }
148497
- }
148498
- const depsInCases = [];
148499
- let foundDefault = false;
148500
- const prevPoisonState = context.poisonState.clone();
148501
- const mutExPoisonStates = [];
148502
- for (const {test: test, block: block} of terminal.cases) {
148503
- if (test !== null) {
148504
- context.visitOperand(test);
148505
- } else {
148506
- foundDefault = true;
148507
- }
148508
- if (block !== undefined) {
148509
- mutExPoisonStates.push(
148510
- context.poisonState.take(prevPoisonState.clone())
148511
- );
148512
- depsInCases.push(
148513
- context.enterConditional(() => {
148514
- this.visitBlock(block, context);
148515
- })
148516
- );
148517
- }
148518
- }
148519
- if (foundDefault) {
148520
- context.promoteDepsFromExhaustiveConditionals(depsInCases);
148521
- }
148522
- context.poisonState.merge(
148523
- mutExPoisonStates,
148524
- context.currentScope.value
148525
- );
148526
- break;
148527
- }
148528
- case 'label': {
148529
- this.visitBlock(terminal.block, context);
148530
- break;
148531
- }
148532
- case 'try': {
148533
- this.visitBlock(terminal.block, context);
148534
- this.visitBlock(terminal.handler, context);
148535
- break;
148536
- }
148537
- default: {
148538
- assertExhaustive(
148539
- terminal,
148540
- `Unexpected terminal kind \`${terminal.kind}\``
148541
- );
148542
- }
148543
- }
148544
- this.exitTerminal(stmt, context);
148545
- }
148546
- }
148547
- function pruneHoistedContexts(fn) {
148548
- const hoistedIdentifiers = new Map();
148549
- visitReactiveFunction(fn, new Visitor$8(), hoistedIdentifiers);
148550
- }
148551
- let Visitor$8 = class Visitor extends ReactiveFunctionTransform {
148552
- transformInstruction(instruction, state) {
148553
- this.visitInstruction(instruction, state);
148554
- if (
148555
- instruction.value.kind === 'DeclareContext' &&
148556
- instruction.value.lvalue.kind === 'HoistedConst'
148557
- ) {
148558
- state.set(
148559
- instruction.value.lvalue.place.identifier.declarationId,
148560
- InstructionKind.Const
148561
- );
148562
- return {kind: 'remove'};
148563
- }
148564
- if (
148565
- instruction.value.kind === 'DeclareContext' &&
148566
- instruction.value.lvalue.kind === 'HoistedLet'
148567
- ) {
148568
- state.set(
148569
- instruction.value.lvalue.place.identifier.declarationId,
148570
- InstructionKind.Let
148571
- );
148572
- return {kind: 'remove'};
148573
- }
148574
- if (
148575
- instruction.value.kind === 'DeclareContext' &&
148576
- instruction.value.lvalue.kind === 'HoistedFunction'
148577
- ) {
148578
- state.set(
148579
- instruction.value.lvalue.place.identifier.declarationId,
148580
- InstructionKind.Function
148581
- );
148582
- return {kind: 'remove'};
147251
+ if (
147252
+ instruction.value.kind === 'DeclareContext' &&
147253
+ instruction.value.lvalue.kind === 'HoistedFunction'
147254
+ ) {
147255
+ state.set(
147256
+ instruction.value.lvalue.place.identifier.declarationId,
147257
+ InstructionKind.Function
147258
+ );
147259
+ return {kind: 'remove'};
148583
147260
  }
148584
147261
  if (
148585
147262
  instruction.value.kind === 'StoreContext' &&
@@ -156459,203 +155136,12 @@ function validateNoJSXInTryStatement(fn) {
156459
155136
  throw errors;
156460
155137
  }
156461
155138
  }
156462
- function collectOptionalChainSidemap(fn) {
156463
- const context = {
156464
- blocks: fn.body.blocks,
156465
- seenOptionals: new Set(),
156466
- processedInstrsInOptional: new Set(),
156467
- temporariesReadInOptional: new Map(),
156468
- hoistableObjects: new Map(),
156469
- };
156470
- for (const [_, block] of fn.body.blocks) {
156471
- if (
156472
- block.terminal.kind === 'optional' &&
156473
- !context.seenOptionals.has(block.id)
156474
- ) {
156475
- traverseOptionalBlock(block, context, null);
156476
- }
156477
- }
156478
- return {
156479
- temporariesReadInOptional: context.temporariesReadInOptional,
156480
- processedInstrsInOptional: context.processedInstrsInOptional,
156481
- hoistableObjects: context.hoistableObjects,
156482
- };
156483
- }
156484
- function matchOptionalTestBlock(terminal, blocks) {
156485
- const consequentBlock = assertNonNull(blocks.get(terminal.consequent));
156486
- if (
156487
- consequentBlock.instructions.length === 2 &&
156488
- consequentBlock.instructions[0].value.kind === 'PropertyLoad' &&
156489
- consequentBlock.instructions[1].value.kind === 'StoreLocal'
156490
- ) {
156491
- const propertyLoad = consequentBlock.instructions[0];
156492
- const storeLocal = consequentBlock.instructions[1].value;
156493
- const storeLocalInstrId = consequentBlock.instructions[1].id;
156494
- CompilerError.invariant(
156495
- propertyLoad.value.object.identifier.id === terminal.test.identifier.id,
156496
- {
156497
- reason:
156498
- '[OptionalChainDeps] Inconsistent optional chaining property load',
156499
- description: `Test=${printIdentifier(terminal.test.identifier)} PropertyLoad base=${printIdentifier(propertyLoad.value.object.identifier)}`,
156500
- loc: propertyLoad.loc,
156501
- }
156502
- );
156503
- CompilerError.invariant(
156504
- storeLocal.value.identifier.id === propertyLoad.lvalue.identifier.id,
156505
- {
156506
- reason: '[OptionalChainDeps] Unexpected storeLocal',
156507
- loc: propertyLoad.loc,
156508
- }
156509
- );
156510
- if (
156511
- consequentBlock.terminal.kind !== 'goto' ||
156512
- consequentBlock.terminal.variant !== GotoVariant.Break
156513
- ) {
156514
- return null;
156515
- }
156516
- const alternate = assertNonNull(blocks.get(terminal.alternate));
156517
- CompilerError.invariant(
156518
- alternate.instructions.length === 2 &&
156519
- alternate.instructions[0].value.kind === 'Primitive' &&
156520
- alternate.instructions[1].value.kind === 'StoreLocal',
156521
- {reason: 'Unexpected alternate structure', loc: terminal.loc}
156522
- );
156523
- return {
156524
- consequentId: storeLocal.lvalue.place.identifier.id,
156525
- property: propertyLoad.value.property,
156526
- propertyId: propertyLoad.lvalue.identifier.id,
156527
- storeLocalInstrId: storeLocalInstrId,
156528
- consequentGoto: consequentBlock.terminal.block,
156529
- };
156530
- }
156531
- return null;
156532
- }
156533
- function traverseOptionalBlock(optional, context, outerAlternate) {
156534
- context.seenOptionals.add(optional.id);
156535
- const maybeTest = context.blocks.get(optional.terminal.test);
156536
- let test;
156537
- let baseObject;
156538
- if (maybeTest.terminal.kind === 'branch') {
156539
- CompilerError.invariant(optional.terminal.optional, {
156540
- reason: '[OptionalChainDeps] Expect base case to be always optional',
156541
- loc: optional.terminal.loc,
156542
- });
156543
- if (
156544
- maybeTest.instructions.length === 0 ||
156545
- maybeTest.instructions[0].value.kind !== 'LoadLocal'
156546
- ) {
156547
- return null;
156548
- }
156549
- const path = [];
156550
- for (let i = 1; i < maybeTest.instructions.length; i++) {
156551
- const instrVal = maybeTest.instructions[i].value;
156552
- const prevInstr = maybeTest.instructions[i - 1];
156553
- if (
156554
- instrVal.kind === 'PropertyLoad' &&
156555
- instrVal.object.identifier.id === prevInstr.lvalue.identifier.id
156556
- ) {
156557
- path.push({property: instrVal.property, optional: false});
156558
- } else {
156559
- return null;
156560
- }
156561
- }
156562
- CompilerError.invariant(
156563
- maybeTest.terminal.test.identifier.id ===
156564
- maybeTest.instructions.at(-1).lvalue.identifier.id,
156565
- {
156566
- reason: '[OptionalChainDeps] Unexpected test expression',
156567
- loc: maybeTest.terminal.loc,
156568
- }
156569
- );
156570
- baseObject = {
156571
- identifier: maybeTest.instructions[0].value.place.identifier,
156572
- path: path,
156573
- };
156574
- test = maybeTest.terminal;
156575
- } else if (maybeTest.terminal.kind === 'optional') {
156576
- const testBlock = context.blocks.get(maybeTest.terminal.fallthrough);
156577
- if (testBlock.terminal.kind !== 'branch') {
156578
- CompilerError.throwTodo({
156579
- reason: `Unexpected terminal kind \`${testBlock.terminal.kind}\` for optional fallthrough block`,
156580
- loc: maybeTest.terminal.loc,
156581
- });
156582
- }
156583
- const innerOptional = traverseOptionalBlock(
156584
- maybeTest,
156585
- context,
156586
- testBlock.terminal.alternate
156587
- );
156588
- if (innerOptional == null) {
156589
- return null;
156590
- }
156591
- if (testBlock.terminal.test.identifier.id !== innerOptional) {
156592
- return null;
156593
- }
156594
- if (!optional.terminal.optional) {
156595
- context.hoistableObjects.set(
156596
- optional.id,
156597
- assertNonNull(context.temporariesReadInOptional.get(innerOptional))
156598
- );
156599
- }
156600
- baseObject = assertNonNull(
156601
- context.temporariesReadInOptional.get(innerOptional)
156602
- );
156603
- test = testBlock.terminal;
156604
- } else {
156605
- return null;
156606
- }
156607
- if (test.alternate === outerAlternate) {
156608
- CompilerError.invariant(optional.instructions.length === 0, {
156609
- reason:
156610
- '[OptionalChainDeps] Unexpected instructions an inner optional block. ' +
156611
- 'This indicates that the compiler may be incorrectly concatenating two unrelated optional chains',
156612
- loc: optional.terminal.loc,
156613
- });
156614
- }
156615
- const matchConsequentResult = matchOptionalTestBlock(test, context.blocks);
156616
- if (!matchConsequentResult) {
156617
- return null;
156618
- }
156619
- CompilerError.invariant(
156620
- matchConsequentResult.consequentGoto === optional.terminal.fallthrough,
156621
- {
156622
- reason: '[OptionalChainDeps] Unexpected optional goto-fallthrough',
156623
- description: `${matchConsequentResult.consequentGoto} != ${optional.terminal.fallthrough}`,
156624
- loc: optional.terminal.loc,
156625
- }
156626
- );
156627
- const load = {
156628
- identifier: baseObject.identifier,
156629
- path: [
156630
- ...baseObject.path,
156631
- {
156632
- property: matchConsequentResult.property,
156633
- optional: optional.terminal.optional,
156634
- },
156635
- ],
156636
- };
156637
- context.processedInstrsInOptional.add(
156638
- matchConsequentResult.storeLocalInstrId
156639
- );
156640
- context.processedInstrsInOptional.add(test.id);
156641
- context.temporariesReadInOptional.set(
156642
- matchConsequentResult.consequentId,
156643
- load
156644
- );
156645
- context.temporariesReadInOptional.set(matchConsequentResult.propertyId, load);
156646
- return matchConsequentResult.consequentId;
156647
- }
156648
155139
  function collectHoistablePropertyLoads(
156649
155140
  fn,
156650
155141
  temporaries,
156651
- hoistableFromOptionals,
156652
- nestedFnImmutableContext
155142
+ hoistableFromOptionals
156653
155143
  ) {
156654
155144
  const registry = new PropertyPathRegistry();
156655
- const functionExpressionLoads = collectFunctionExpressionFakeLoads(fn);
156656
- const actuallyEvaluatedTemporaries = new Map(
156657
- [...temporaries].filter(([id]) => !functionExpressionLoads.has(id))
156658
- );
156659
155145
  const knownImmutableIdentifiers = new Set();
156660
155146
  if (fn.fnType === 'Component' || fn.fnType === 'Hook') {
156661
155147
  for (const p of fn.params) {
@@ -156664,14 +155150,26 @@ function collectHoistablePropertyLoads(
156664
155150
  }
156665
155151
  }
156666
155152
  }
156667
- const nodes = collectNonNullsInBlocks(fn, {
156668
- temporaries: actuallyEvaluatedTemporaries,
155153
+ return collectHoistablePropertyLoadsImpl(fn, {
155154
+ temporaries: temporaries,
156669
155155
  knownImmutableIdentifiers: knownImmutableIdentifiers,
156670
155156
  hoistableFromOptionals: hoistableFromOptionals,
156671
155157
  registry: registry,
156672
- nestedFnImmutableContext: nestedFnImmutableContext,
155158
+ nestedFnImmutableContext: null,
156673
155159
  });
156674
- propagateNonNull(fn, nodes, registry);
155160
+ }
155161
+ function collectHoistablePropertyLoadsImpl(fn, context) {
155162
+ const functionExpressionLoads = collectFunctionExpressionFakeLoads(fn);
155163
+ const actuallyEvaluatedTemporaries = new Map(
155164
+ [...context.temporaries].filter(([id]) => !functionExpressionLoads.has(id))
155165
+ );
155166
+ const nodes = collectNonNullsInBlocks(
155167
+ fn,
155168
+ Object.assign(Object.assign({}, context), {
155169
+ temporaries: actuallyEvaluatedTemporaries,
155170
+ })
155171
+ );
155172
+ propagateNonNull(fn, nodes, context.registry);
156675
155173
  return nodes;
156676
155174
  }
156677
155175
  function keyByScopeId(fn, source) {
@@ -156808,28 +155306,25 @@ function collectNonNullsInBlocks(fn, context) {
156808
155306
  assumedNonNullObjects.add(maybeNonNull);
156809
155307
  }
156810
155308
  if (
156811
- instr.value.kind === 'FunctionExpression' &&
155309
+ (instr.value.kind === 'FunctionExpression' ||
155310
+ instr.value.kind === 'ObjectMethod') &&
156812
155311
  !fn.env.config.enableTreatFunctionDepsAsConditional
156813
155312
  ) {
156814
155313
  const innerFn = instr.value.loweredFunc;
156815
- const innerTemporaries = collectTemporariesSidemap(
156816
- innerFn.func,
156817
- new Set()
156818
- );
156819
- const innerOptionals = collectOptionalChainSidemap(innerFn.func);
156820
- const innerHoistableMap = collectHoistablePropertyLoads(
155314
+ const innerHoistableMap = collectHoistablePropertyLoadsImpl(
156821
155315
  innerFn.func,
156822
- innerTemporaries,
156823
- innerOptionals.hoistableObjects,
156824
- (_a = context.nestedFnImmutableContext) !== null && _a !== void 0
156825
- ? _a
156826
- : new Set(
156827
- innerFn.func.context
156828
- .filter(place =>
156829
- isImmutableAtInstr(place.identifier, instr.id, context)
156830
- )
156831
- .map(place => place.identifier.id)
156832
- )
155316
+ Object.assign(Object.assign({}, context), {
155317
+ nestedFnImmutableContext:
155318
+ (_a = context.nestedFnImmutableContext) !== null && _a !== void 0
155319
+ ? _a
155320
+ : new Set(
155321
+ innerFn.func.context
155322
+ .filter(place =>
155323
+ isImmutableAtInstr(place.identifier, instr.id, context)
155324
+ )
155325
+ .map(place => place.identifier.id)
155326
+ ),
155327
+ })
156833
155328
  );
156834
155329
  const innerHoistables = assertNonNull(
156835
155330
  innerHoistableMap.get(innerFn.func.body.entry)
@@ -156978,7 +155473,10 @@ function collectFunctionExpressionFakeLoads(fn) {
156978
155473
  const functionExpressionReferences = new Set();
156979
155474
  for (const [_, block] of fn.body.blocks) {
156980
155475
  for (const {lvalue: lvalue, value: value} of block.instructions) {
156981
- if (value.kind === 'FunctionExpression') {
155476
+ if (
155477
+ value.kind === 'FunctionExpression' ||
155478
+ value.kind === 'ObjectMethod'
155479
+ ) {
156982
155480
  for (const reference of value.loweredFunc.dependencies) {
156983
155481
  let curr = reference.identifier.id;
156984
155482
  while (curr != null) {
@@ -156993,6 +155491,74 @@ function collectFunctionExpressionFakeLoads(fn) {
156993
155491
  }
156994
155492
  return functionExpressionReferences;
156995
155493
  }
155494
+ var _Node_value, _Node_next;
155495
+ function empty() {
155496
+ return EMPTY;
155497
+ }
155498
+ class Node {
155499
+ constructor(value, next = EMPTY) {
155500
+ _Node_value.set(this, void 0);
155501
+ _Node_next.set(this, void 0);
155502
+ __classPrivateFieldSet(this, _Node_value, value, 'f');
155503
+ __classPrivateFieldSet(this, _Node_next, next, 'f');
155504
+ }
155505
+ push(value) {
155506
+ return new Node(value, this);
155507
+ }
155508
+ pop() {
155509
+ return __classPrivateFieldGet(this, _Node_next, 'f');
155510
+ }
155511
+ find(fn) {
155512
+ return fn(__classPrivateFieldGet(this, _Node_value, 'f'))
155513
+ ? true
155514
+ : __classPrivateFieldGet(this, _Node_next, 'f').find(fn);
155515
+ }
155516
+ contains(value) {
155517
+ return (
155518
+ value === __classPrivateFieldGet(this, _Node_value, 'f') ||
155519
+ (__classPrivateFieldGet(this, _Node_next, 'f') !== null &&
155520
+ __classPrivateFieldGet(this, _Node_next, 'f').contains(value))
155521
+ );
155522
+ }
155523
+ each(fn) {
155524
+ fn(__classPrivateFieldGet(this, _Node_value, 'f'));
155525
+ __classPrivateFieldGet(this, _Node_next, 'f').each(fn);
155526
+ }
155527
+ get value() {
155528
+ return __classPrivateFieldGet(this, _Node_value, 'f');
155529
+ }
155530
+ print(fn) {
155531
+ return (
155532
+ fn(__classPrivateFieldGet(this, _Node_value, 'f')) +
155533
+ __classPrivateFieldGet(this, _Node_next, 'f').print(fn)
155534
+ );
155535
+ }
155536
+ }
155537
+ (_Node_value = new WeakMap()), (_Node_next = new WeakMap());
155538
+ class Empty {
155539
+ push(value) {
155540
+ return new Node(value, this);
155541
+ }
155542
+ pop() {
155543
+ return this;
155544
+ }
155545
+ find(_fn) {
155546
+ return false;
155547
+ }
155548
+ contains(_value) {
155549
+ return false;
155550
+ }
155551
+ each(_fn) {
155552
+ return;
155553
+ }
155554
+ get value() {
155555
+ return null;
155556
+ }
155557
+ print(_) {
155558
+ return '';
155559
+ }
155560
+ }
155561
+ const EMPTY = new Empty();
156996
155562
  var _a,
156997
155563
  _ReactiveScopeDependencyTreeHIR_hoistableObjects,
156998
155564
  _ReactiveScopeDependencyTreeHIR_deps,
@@ -157152,105 +155718,307 @@ class ReactiveScopeDependencyTreeHIR {
157152
155718
  roots,
157153
155719
  defaultAccessType
157154
155720
  ) {
157155
- let rootNode = roots.get(identifier);
157156
- if (rootNode === undefined) {
157157
- rootNode = {properties: new Map(), accessType: defaultAccessType};
157158
- roots.set(identifier, rootNode);
155721
+ let rootNode = roots.get(identifier);
155722
+ if (rootNode === undefined) {
155723
+ rootNode = {properties: new Map(), accessType: defaultAccessType};
155724
+ roots.set(identifier, rootNode);
155725
+ }
155726
+ return rootNode;
155727
+ }),
155728
+ (_ReactiveScopeDependencyTreeHIR_debugImpl =
155729
+ function _ReactiveScopeDependencyTreeHIR_debugImpl(buf, node, depth = 0) {
155730
+ for (const [property, childNode] of node.properties) {
155731
+ buf.push(
155732
+ `${' '.repeat(depth)}.${property} (${childNode.accessType}):`
155733
+ );
155734
+ __classPrivateFieldGet(
155735
+ this,
155736
+ _a,
155737
+ 'm',
155738
+ _ReactiveScopeDependencyTreeHIR_debugImpl
155739
+ ).call(this, buf, childNode, depth + 1);
155740
+ }
155741
+ });
155742
+ var PropertyAccessType;
155743
+ (function (PropertyAccessType) {
155744
+ PropertyAccessType['OptionalAccess'] = 'OptionalAccess';
155745
+ PropertyAccessType['UnconditionalAccess'] = 'UnconditionalAccess';
155746
+ PropertyAccessType['OptionalDependency'] = 'OptionalDependency';
155747
+ PropertyAccessType['UnconditionalDependency'] = 'UnconditionalDependency';
155748
+ })(PropertyAccessType || (PropertyAccessType = {}));
155749
+ function isOptional(access) {
155750
+ return (
155751
+ access === PropertyAccessType.OptionalAccess ||
155752
+ access === PropertyAccessType.OptionalDependency
155753
+ );
155754
+ }
155755
+ function isDependency(access) {
155756
+ return (
155757
+ access === PropertyAccessType.OptionalDependency ||
155758
+ access === PropertyAccessType.UnconditionalDependency
155759
+ );
155760
+ }
155761
+ function merge(access1, access2) {
155762
+ const resultIsUnconditional = !(isOptional(access1) && isOptional(access2));
155763
+ const resultIsDependency = isDependency(access1) || isDependency(access2);
155764
+ if (resultIsUnconditional) {
155765
+ if (resultIsDependency) {
155766
+ return PropertyAccessType.UnconditionalDependency;
155767
+ } else {
155768
+ return PropertyAccessType.UnconditionalAccess;
155769
+ }
155770
+ } else {
155771
+ if (resultIsDependency) {
155772
+ return PropertyAccessType.OptionalDependency;
155773
+ } else {
155774
+ return PropertyAccessType.OptionalAccess;
155775
+ }
155776
+ }
155777
+ }
155778
+ function collectMinimalDependenciesInSubtree(
155779
+ node,
155780
+ rootIdentifier,
155781
+ path,
155782
+ results
155783
+ ) {
155784
+ if (isDependency(node.accessType)) {
155785
+ results.add({identifier: rootIdentifier, path: path});
155786
+ } else {
155787
+ for (const [childName, childNode] of node.properties) {
155788
+ collectMinimalDependenciesInSubtree(
155789
+ childNode,
155790
+ rootIdentifier,
155791
+ [
155792
+ ...path,
155793
+ {property: childName, optional: isOptional(childNode.accessType)},
155794
+ ],
155795
+ results
155796
+ );
155797
+ }
155798
+ }
155799
+ }
155800
+ function printSubtree(node, includeAccesses) {
155801
+ const results = [];
155802
+ for (const [propertyName, propertyNode] of node.properties) {
155803
+ if (includeAccesses || isDependency(propertyNode.accessType)) {
155804
+ results.push(`${propertyName} (${propertyNode.accessType})`);
155805
+ }
155806
+ const propertyResults = printSubtree(propertyNode, includeAccesses);
155807
+ results.push(...propertyResults.map(result => `${propertyName}.${result}`));
155808
+ }
155809
+ return results;
155810
+ }
155811
+ function makeOrMergeProperty(node, property, accessType) {
155812
+ let child = node.properties.get(property);
155813
+ if (child == null) {
155814
+ child = {properties: new Map(), accessType: accessType};
155815
+ node.properties.set(property, child);
155816
+ } else {
155817
+ child.accessType = merge(child.accessType, accessType);
155818
+ }
155819
+ return child;
155820
+ }
155821
+ function collectOptionalChainSidemap(fn) {
155822
+ const context = {
155823
+ currFn: fn,
155824
+ blocks: fn.body.blocks,
155825
+ seenOptionals: new Set(),
155826
+ processedInstrsInOptional: new Set(),
155827
+ temporariesReadInOptional: new Map(),
155828
+ hoistableObjects: new Map(),
155829
+ };
155830
+ traverseFunction(fn, context);
155831
+ return {
155832
+ temporariesReadInOptional: context.temporariesReadInOptional,
155833
+ processedInstrsInOptional: context.processedInstrsInOptional,
155834
+ hoistableObjects: context.hoistableObjects,
155835
+ };
155836
+ }
155837
+ function traverseFunction(fn, context) {
155838
+ for (const [_, block] of fn.body.blocks) {
155839
+ for (const instr of block.instructions) {
155840
+ if (
155841
+ instr.value.kind === 'FunctionExpression' ||
155842
+ instr.value.kind === 'ObjectMethod'
155843
+ ) {
155844
+ traverseFunction(
155845
+ instr.value.loweredFunc.func,
155846
+ Object.assign(Object.assign({}, context), {
155847
+ currFn: instr.value.loweredFunc.func,
155848
+ blocks: instr.value.loweredFunc.func.body.blocks,
155849
+ })
155850
+ );
155851
+ }
155852
+ }
155853
+ if (
155854
+ block.terminal.kind === 'optional' &&
155855
+ !context.seenOptionals.has(block.id)
155856
+ ) {
155857
+ traverseOptionalBlock(block, context, null);
155858
+ }
155859
+ }
155860
+ }
155861
+ function matchOptionalTestBlock(terminal, blocks) {
155862
+ const consequentBlock = assertNonNull(blocks.get(terminal.consequent));
155863
+ if (
155864
+ consequentBlock.instructions.length === 2 &&
155865
+ consequentBlock.instructions[0].value.kind === 'PropertyLoad' &&
155866
+ consequentBlock.instructions[1].value.kind === 'StoreLocal'
155867
+ ) {
155868
+ const propertyLoad = consequentBlock.instructions[0];
155869
+ const storeLocal = consequentBlock.instructions[1].value;
155870
+ const storeLocalInstr = consequentBlock.instructions[1];
155871
+ CompilerError.invariant(
155872
+ propertyLoad.value.object.identifier.id === terminal.test.identifier.id,
155873
+ {
155874
+ reason:
155875
+ '[OptionalChainDeps] Inconsistent optional chaining property load',
155876
+ description: `Test=${printIdentifier(terminal.test.identifier)} PropertyLoad base=${printIdentifier(propertyLoad.value.object.identifier)}`,
155877
+ loc: propertyLoad.loc,
155878
+ }
155879
+ );
155880
+ CompilerError.invariant(
155881
+ storeLocal.value.identifier.id === propertyLoad.lvalue.identifier.id,
155882
+ {
155883
+ reason: '[OptionalChainDeps] Unexpected storeLocal',
155884
+ loc: propertyLoad.loc,
155885
+ }
155886
+ );
155887
+ if (
155888
+ consequentBlock.terminal.kind !== 'goto' ||
155889
+ consequentBlock.terminal.variant !== GotoVariant.Break
155890
+ ) {
155891
+ return null;
155892
+ }
155893
+ const alternate = assertNonNull(blocks.get(terminal.alternate));
155894
+ CompilerError.invariant(
155895
+ alternate.instructions.length === 2 &&
155896
+ alternate.instructions[0].value.kind === 'Primitive' &&
155897
+ alternate.instructions[1].value.kind === 'StoreLocal',
155898
+ {reason: 'Unexpected alternate structure', loc: terminal.loc}
155899
+ );
155900
+ return {
155901
+ consequentId: storeLocal.lvalue.place.identifier.id,
155902
+ property: propertyLoad.value.property,
155903
+ propertyId: propertyLoad.lvalue.identifier.id,
155904
+ storeLocalInstr: storeLocalInstr,
155905
+ consequentGoto: consequentBlock.terminal.block,
155906
+ };
155907
+ }
155908
+ return null;
155909
+ }
155910
+ function traverseOptionalBlock(optional, context, outerAlternate) {
155911
+ context.seenOptionals.add(optional.id);
155912
+ const maybeTest = context.blocks.get(optional.terminal.test);
155913
+ let test;
155914
+ let baseObject;
155915
+ if (maybeTest.terminal.kind === 'branch') {
155916
+ CompilerError.invariant(optional.terminal.optional, {
155917
+ reason: '[OptionalChainDeps] Expect base case to be always optional',
155918
+ loc: optional.terminal.loc,
155919
+ });
155920
+ if (
155921
+ maybeTest.instructions.length === 0 ||
155922
+ maybeTest.instructions[0].value.kind !== 'LoadLocal'
155923
+ ) {
155924
+ return null;
155925
+ }
155926
+ const path = [];
155927
+ for (let i = 1; i < maybeTest.instructions.length; i++) {
155928
+ const instrVal = maybeTest.instructions[i].value;
155929
+ const prevInstr = maybeTest.instructions[i - 1];
155930
+ if (
155931
+ instrVal.kind === 'PropertyLoad' &&
155932
+ instrVal.object.identifier.id === prevInstr.lvalue.identifier.id
155933
+ ) {
155934
+ path.push({property: instrVal.property, optional: false});
155935
+ } else {
155936
+ return null;
157159
155937
  }
157160
- return rootNode;
157161
- }),
157162
- (_ReactiveScopeDependencyTreeHIR_debugImpl =
157163
- function _ReactiveScopeDependencyTreeHIR_debugImpl(buf, node, depth = 0) {
157164
- for (const [property, childNode] of node.properties) {
157165
- buf.push(
157166
- `${' '.repeat(depth)}.${property} (${childNode.accessType}):`
157167
- );
157168
- __classPrivateFieldGet(
157169
- this,
157170
- _a,
157171
- 'm',
157172
- _ReactiveScopeDependencyTreeHIR_debugImpl
157173
- ).call(this, buf, childNode, depth + 1);
155938
+ }
155939
+ CompilerError.invariant(
155940
+ maybeTest.terminal.test.identifier.id ===
155941
+ maybeTest.instructions.at(-1).lvalue.identifier.id,
155942
+ {
155943
+ reason: '[OptionalChainDeps] Unexpected test expression',
155944
+ loc: maybeTest.terminal.loc,
157174
155945
  }
157175
- });
157176
- var PropertyAccessType;
157177
- (function (PropertyAccessType) {
157178
- PropertyAccessType['OptionalAccess'] = 'OptionalAccess';
157179
- PropertyAccessType['UnconditionalAccess'] = 'UnconditionalAccess';
157180
- PropertyAccessType['OptionalDependency'] = 'OptionalDependency';
157181
- PropertyAccessType['UnconditionalDependency'] = 'UnconditionalDependency';
157182
- })(PropertyAccessType || (PropertyAccessType = {}));
157183
- function isOptional(access) {
157184
- return (
157185
- access === PropertyAccessType.OptionalAccess ||
157186
- access === PropertyAccessType.OptionalDependency
157187
- );
157188
- }
157189
- function isDependency(access) {
157190
- return (
157191
- access === PropertyAccessType.OptionalDependency ||
157192
- access === PropertyAccessType.UnconditionalDependency
157193
- );
157194
- }
157195
- function merge(access1, access2) {
157196
- const resultIsUnconditional = !(isOptional(access1) && isOptional(access2));
157197
- const resultIsDependency = isDependency(access1) || isDependency(access2);
157198
- if (resultIsUnconditional) {
157199
- if (resultIsDependency) {
157200
- return PropertyAccessType.UnconditionalDependency;
157201
- } else {
157202
- return PropertyAccessType.UnconditionalAccess;
155946
+ );
155947
+ baseObject = {
155948
+ identifier: maybeTest.instructions[0].value.place.identifier,
155949
+ path: path,
155950
+ };
155951
+ test = maybeTest.terminal;
155952
+ } else if (maybeTest.terminal.kind === 'optional') {
155953
+ const testBlock = context.blocks.get(maybeTest.terminal.fallthrough);
155954
+ if (testBlock.terminal.kind !== 'branch') {
155955
+ CompilerError.throwTodo({
155956
+ reason: `Unexpected terminal kind \`${testBlock.terminal.kind}\` for optional fallthrough block`,
155957
+ loc: maybeTest.terminal.loc,
155958
+ });
157203
155959
  }
157204
- } else {
157205
- if (resultIsDependency) {
157206
- return PropertyAccessType.OptionalDependency;
157207
- } else {
157208
- return PropertyAccessType.OptionalAccess;
155960
+ const innerOptional = traverseOptionalBlock(
155961
+ maybeTest,
155962
+ context,
155963
+ testBlock.terminal.alternate
155964
+ );
155965
+ if (innerOptional == null) {
155966
+ return null;
157209
155967
  }
157210
- }
157211
- }
157212
- function collectMinimalDependenciesInSubtree(
157213
- node,
157214
- rootIdentifier,
157215
- path,
157216
- results
157217
- ) {
157218
- if (isDependency(node.accessType)) {
157219
- results.add({identifier: rootIdentifier, path: path});
157220
- } else {
157221
- for (const [childName, childNode] of node.properties) {
157222
- collectMinimalDependenciesInSubtree(
157223
- childNode,
157224
- rootIdentifier,
157225
- [
157226
- ...path,
157227
- {property: childName, optional: isOptional(childNode.accessType)},
157228
- ],
157229
- results
155968
+ if (testBlock.terminal.test.identifier.id !== innerOptional) {
155969
+ return null;
155970
+ }
155971
+ if (!optional.terminal.optional) {
155972
+ context.hoistableObjects.set(
155973
+ optional.id,
155974
+ assertNonNull(context.temporariesReadInOptional.get(innerOptional))
157230
155975
  );
157231
155976
  }
155977
+ baseObject = assertNonNull(
155978
+ context.temporariesReadInOptional.get(innerOptional)
155979
+ );
155980
+ test = testBlock.terminal;
155981
+ } else {
155982
+ return null;
157232
155983
  }
157233
- }
157234
- function printSubtree(node, includeAccesses) {
157235
- const results = [];
157236
- for (const [propertyName, propertyNode] of node.properties) {
157237
- if (includeAccesses || isDependency(propertyNode.accessType)) {
157238
- results.push(`${propertyName} (${propertyNode.accessType})`);
157239
- }
157240
- const propertyResults = printSubtree(propertyNode, includeAccesses);
157241
- results.push(...propertyResults.map(result => `${propertyName}.${result}`));
155984
+ if (test.alternate === outerAlternate) {
155985
+ CompilerError.invariant(optional.instructions.length === 0, {
155986
+ reason:
155987
+ '[OptionalChainDeps] Unexpected instructions an inner optional block. ' +
155988
+ 'This indicates that the compiler may be incorrectly concatenating two unrelated optional chains',
155989
+ loc: optional.terminal.loc,
155990
+ });
157242
155991
  }
157243
- return results;
157244
- }
157245
- function makeOrMergeProperty(node, property, accessType) {
157246
- let child = node.properties.get(property);
157247
- if (child == null) {
157248
- child = {properties: new Map(), accessType: accessType};
157249
- node.properties.set(property, child);
157250
- } else {
157251
- child.accessType = merge(child.accessType, accessType);
155992
+ const matchConsequentResult = matchOptionalTestBlock(test, context.blocks);
155993
+ if (!matchConsequentResult) {
155994
+ return null;
157252
155995
  }
157253
- return child;
155996
+ CompilerError.invariant(
155997
+ matchConsequentResult.consequentGoto === optional.terminal.fallthrough,
155998
+ {
155999
+ reason: '[OptionalChainDeps] Unexpected optional goto-fallthrough',
156000
+ description: `${matchConsequentResult.consequentGoto} != ${optional.terminal.fallthrough}`,
156001
+ loc: optional.terminal.loc,
156002
+ }
156003
+ );
156004
+ const load = {
156005
+ identifier: baseObject.identifier,
156006
+ path: [
156007
+ ...baseObject.path,
156008
+ {
156009
+ property: matchConsequentResult.property,
156010
+ optional: optional.terminal.optional,
156011
+ },
156012
+ ],
156013
+ };
156014
+ context.processedInstrsInOptional.add(matchConsequentResult.storeLocalInstr);
156015
+ context.processedInstrsInOptional.add(test);
156016
+ context.temporariesReadInOptional.set(
156017
+ matchConsequentResult.consequentId,
156018
+ load
156019
+ );
156020
+ context.temporariesReadInOptional.set(matchConsequentResult.propertyId, load);
156021
+ return matchConsequentResult.consequentId;
157254
156022
  }
157255
156023
  var _Context_instances,
157256
156024
  _Context_declarations,
@@ -157272,7 +156040,7 @@ function propagateScopeDependenciesHIR(fn) {
157272
156040
  } = collectOptionalChainSidemap(fn);
157273
156041
  const hoistablePropertyLoads = keyByScopeId(
157274
156042
  fn,
157275
- collectHoistablePropertyLoads(fn, temporaries, hoistableObjects, null)
156043
+ collectHoistablePropertyLoads(fn, temporaries, hoistableObjects)
157276
156044
  );
157277
156045
  const scopeDeps = collectDependencies(
157278
156046
  fn,
@@ -157364,6 +156132,20 @@ function findTemporariesUsedOutsideDeclaringScope(fn) {
157364
156132
  }
157365
156133
  function collectTemporariesSidemap(fn, usedOutsideDeclaringScope) {
157366
156134
  const temporaries = new Map();
156135
+ collectTemporariesSidemapImpl(
156136
+ fn,
156137
+ usedOutsideDeclaringScope,
156138
+ temporaries,
156139
+ false
156140
+ );
156141
+ return temporaries;
156142
+ }
156143
+ function collectTemporariesSidemapImpl(
156144
+ fn,
156145
+ usedOutsideDeclaringScope,
156146
+ temporaries,
156147
+ isInnerFn
156148
+ ) {
157367
156149
  for (const [_, block] of fn.body.blocks) {
157368
156150
  for (const instr of block.instructions) {
157369
156151
  const {value: value, lvalue: lvalue} = instr;
@@ -157371,27 +156153,45 @@ function collectTemporariesSidemap(fn, usedOutsideDeclaringScope) {
157371
156153
  lvalue.identifier.declarationId
157372
156154
  );
157373
156155
  if (value.kind === 'PropertyLoad' && !usedOutside) {
157374
- const property = getProperty(
157375
- value.object,
157376
- value.property,
157377
- false,
157378
- temporaries
157379
- );
157380
- temporaries.set(lvalue.identifier.id, property);
156156
+ if (!isInnerFn || temporaries.has(value.object.identifier.id)) {
156157
+ const property = getProperty(
156158
+ value.object,
156159
+ value.property,
156160
+ false,
156161
+ temporaries
156162
+ );
156163
+ temporaries.set(lvalue.identifier.id, property);
156164
+ }
157381
156165
  } else if (
157382
156166
  value.kind === 'LoadLocal' &&
157383
156167
  lvalue.identifier.name == null &&
157384
156168
  value.place.identifier.name !== null &&
157385
156169
  !usedOutside
157386
156170
  ) {
157387
- temporaries.set(lvalue.identifier.id, {
157388
- identifier: value.place.identifier,
157389
- path: [],
157390
- });
156171
+ if (
156172
+ !isInnerFn ||
156173
+ fn.context.some(
156174
+ context => context.identifier.id === value.place.identifier.id
156175
+ )
156176
+ ) {
156177
+ temporaries.set(lvalue.identifier.id, {
156178
+ identifier: value.place.identifier,
156179
+ path: [],
156180
+ });
156181
+ }
156182
+ } else if (
156183
+ value.kind === 'FunctionExpression' ||
156184
+ value.kind === 'ObjectMethod'
156185
+ ) {
156186
+ collectTemporariesSidemapImpl(
156187
+ value.loweredFunc.func,
156188
+ usedOutsideDeclaringScope,
156189
+ temporaries,
156190
+ true
156191
+ );
157391
156192
  }
157392
156193
  }
157393
156194
  }
157394
- return temporaries;
157395
156195
  }
157396
156196
  function getProperty(object, propertyName, optional, temporaries) {
157397
156197
  const resolvedDependency = temporaries.get(object.identifier.id);
@@ -157422,6 +156222,7 @@ class Context {
157422
156222
  this.deps = new Map();
157423
156223
  _Context_temporaries.set(this, void 0);
157424
156224
  _Context_temporariesUsedOutsideScope.set(this, void 0);
156225
+ this.inInnerFn = false;
157425
156226
  __classPrivateFieldSet(
157426
156227
  this,
157427
156228
  _Context_temporariesUsedOutsideScope,
@@ -157497,6 +156298,7 @@ class Context {
157497
156298
  ).has(place.identifier.declarationId);
157498
156299
  }
157499
156300
  declare(identifier, decl) {
156301
+ if (this.inInnerFn) return;
157500
156302
  if (
157501
156303
  !__classPrivateFieldGet(this, _Context_declarations, 'f').has(
157502
156304
  identifier.declarationId
@@ -157742,11 +156544,11 @@ function collectDependencies(
157742
156544
  }
157743
156545
  }
157744
156546
  for (const instr of block.instructions) {
157745
- if (!processedInstrsInOptional.has(instr.id)) {
156547
+ if (!processedInstrsInOptional.has(instr)) {
157746
156548
  handleInstruction(instr, context);
157747
156549
  }
157748
156550
  }
157749
- if (!processedInstrsInOptional.has(block.terminal.id)) {
156551
+ if (!processedInstrsInOptional.has(block.terminal)) {
157750
156552
  for (const place of eachTerminalOperand(block.terminal)) {
157751
156553
  context.visitOperand(place);
157752
156554
  }
@@ -157884,6 +156686,15 @@ function process$1(fn, jsx, globals) {
157884
156686
  return {instrs: newInstrs, fn: outlinedFn};
157885
156687
  }
157886
156688
  function collectProps(instructions) {
156689
+ let id = 1;
156690
+ function generateName(oldName) {
156691
+ let newName = oldName;
156692
+ while (seen.has(newName)) {
156693
+ newName = `${oldName}${id++}`;
156694
+ }
156695
+ seen.add(newName);
156696
+ return newName;
156697
+ }
157887
156698
  const attributes = [];
157888
156699
  const jsxIds = new Set(instructions.map(i => i.lvalue.identifier.id));
157889
156700
  const seen = new Set();
@@ -157893,24 +156704,38 @@ function collectProps(instructions) {
157893
156704
  if (at.kind === 'JsxSpreadAttribute') {
157894
156705
  return null;
157895
156706
  }
157896
- if (seen.has(at.name)) {
157897
- return null;
157898
- }
157899
156707
  if (at.kind === 'JsxAttribute') {
157900
- seen.add(at.name);
157901
- attributes.push(at);
156708
+ const newName = generateName(at.name);
156709
+ attributes.push({
156710
+ originalName: at.name,
156711
+ newName: newName,
156712
+ place: at.place,
156713
+ });
157902
156714
  }
157903
156715
  }
157904
- if (
157905
- value.children &&
157906
- value.children.some(child => !jsxIds.has(child.identifier.id))
157907
- ) {
157908
- return null;
156716
+ if (value.children) {
156717
+ for (const child of value.children) {
156718
+ if (jsxIds.has(child.identifier.id)) {
156719
+ continue;
156720
+ }
156721
+ promoteTemporary(child.identifier);
156722
+ const newName = generateName('t');
156723
+ attributes.push({
156724
+ originalName: child.identifier.name.value,
156725
+ newName: newName,
156726
+ place: child,
156727
+ });
156728
+ }
157909
156729
  }
157910
156730
  }
157911
156731
  return attributes;
157912
156732
  }
157913
- function emitOutlinedJsx(env, instructions, props, outlinedTag) {
156733
+ function emitOutlinedJsx(env, instructions, outlinedProps, outlinedTag) {
156734
+ const props = outlinedProps.map(p => ({
156735
+ kind: 'JsxAttribute',
156736
+ name: p.newName,
156737
+ place: p.place,
156738
+ }));
157914
156739
  const loadJsx = {
157915
156740
  id: makeInstructionId(0),
157916
156741
  loc: GeneratedSource,
@@ -157943,9 +156768,11 @@ function emitOutlinedFn(env, jsx, oldProps, globals) {
157943
156768
  const oldToNewProps = createOldToNewPropsMapping(env, oldProps);
157944
156769
  const propsObj = createTemporaryPlace(env, GeneratedSource);
157945
156770
  promoteTemporary(propsObj.identifier);
157946
- const destructurePropsInstr = emitDestructureProps(env, propsObj, [
157947
- ...oldToNewProps.values(),
157948
- ]);
156771
+ const destructurePropsInstr = emitDestructureProps(
156772
+ env,
156773
+ propsObj,
156774
+ oldToNewProps
156775
+ );
157949
156776
  instructions.push(destructurePropsInstr);
157950
156777
  const updatedJsxInstructions = emitUpdatedJsx(jsx, oldToNewProps);
157951
156778
  const loadGlobalInstrs = emitLoadGlobals(jsx, globals);
@@ -157999,6 +156826,7 @@ function emitLoadGlobals(jsx, globals) {
157999
156826
  }
158000
156827
  function emitUpdatedJsx(jsx, oldToNewProps) {
158001
156828
  const newInstrs = [];
156829
+ const jsxIds = new Set(jsx.map(i => i.lvalue.identifier.id));
158002
156830
  for (const instr of jsx) {
158003
156831
  const {value: value} = instr;
158004
156832
  const newProps = [];
@@ -158015,13 +156843,34 @@ function emitUpdatedJsx(jsx, oldToNewProps) {
158015
156843
  newProp !== undefined,
158016
156844
  `Expected a new property for ${printIdentifier(prop.place.identifier)}`
158017
156845
  );
158018
- newProps.push(
158019
- Object.assign(Object.assign({}, prop), {place: newProp.place})
158020
- );
156846
+ newProps.push({
156847
+ kind: 'JsxAttribute',
156848
+ name: newProp.originalName,
156849
+ place: newProp.place,
156850
+ });
156851
+ }
156852
+ let newChildren = null;
156853
+ if (value.children) {
156854
+ newChildren = [];
156855
+ for (const child of value.children) {
156856
+ if (jsxIds.has(child.identifier.id)) {
156857
+ newChildren.push(Object.assign({}, child));
156858
+ continue;
156859
+ }
156860
+ const newChild = oldToNewProps.get(child.identifier.id);
156861
+ invariant$1(
156862
+ newChild !== undefined,
156863
+ `Expected a new prop for ${printIdentifier(child.identifier)}`
156864
+ );
156865
+ newChildren.push(Object.assign({}, newChild.place));
156866
+ }
158021
156867
  }
158022
156868
  newInstrs.push(
158023
156869
  Object.assign(Object.assign({}, instr), {
158024
- value: Object.assign(Object.assign({}, value), {props: newProps}),
156870
+ value: Object.assign(Object.assign({}, value), {
156871
+ props: newProps,
156872
+ children: newChildren,
156873
+ }),
158025
156874
  })
158026
156875
  );
158027
156876
  }
@@ -158030,25 +156879,27 @@ function emitUpdatedJsx(jsx, oldToNewProps) {
158030
156879
  function createOldToNewPropsMapping(env, oldProps) {
158031
156880
  const oldToNewProps = new Map();
158032
156881
  for (const oldProp of oldProps) {
158033
- invariant$1(
158034
- oldProp.kind === 'JsxAttribute',
158035
- `Expected only attributes but found ${oldProp.kind}`
158036
- );
158037
- if (oldProp.name === 'key') {
156882
+ if (oldProp.originalName === 'key') {
158038
156883
  continue;
158039
156884
  }
158040
- const newProp = {
158041
- kind: 'ObjectProperty',
158042
- key: {kind: 'string', name: oldProp.name},
158043
- type: 'property',
156885
+ const newProp = Object.assign(Object.assign({}, oldProp), {
158044
156886
  place: createTemporaryPlace(env, GeneratedSource),
158045
- };
158046
- newProp.place.identifier.name = makeIdentifierName(oldProp.name);
156887
+ });
156888
+ newProp.place.identifier.name = makeIdentifierName(oldProp.newName);
158047
156889
  oldToNewProps.set(oldProp.place.identifier.id, newProp);
158048
156890
  }
158049
156891
  return oldToNewProps;
158050
156892
  }
158051
- function emitDestructureProps(env, propsObj, properties) {
156893
+ function emitDestructureProps(env, propsObj, oldToNewProps) {
156894
+ const properties = [];
156895
+ for (const [_, prop] of oldToNewProps) {
156896
+ properties.push({
156897
+ kind: 'ObjectProperty',
156898
+ key: {kind: 'string', name: prop.newName},
156899
+ type: 'property',
156900
+ place: prop.place,
156901
+ });
156902
+ }
158052
156903
  const destructurePropsInstr = {
158053
156904
  id: makeInstructionId(0),
158054
156905
  lvalue: createTemporaryPlace(env, GeneratedSource),
@@ -158219,10 +157070,8 @@ function* runWithEnvironment(func, env) {
158219
157070
  yield log({kind: 'hir', name: 'FlattenScopesWithHooksOrUseHIR', value: hir});
158220
157071
  assertTerminalSuccessorsExist(hir);
158221
157072
  assertTerminalPredsExist(hir);
158222
- if (env.config.enablePropagateDepsInHIR) {
158223
- propagateScopeDependenciesHIR(hir);
158224
- yield log({kind: 'hir', name: 'PropagateScopeDependenciesHIR', value: hir});
158225
- }
157073
+ propagateScopeDependenciesHIR(hir);
157074
+ yield log({kind: 'hir', name: 'PropagateScopeDependenciesHIR', value: hir});
158226
157075
  if (env.config.inlineJsxTransform) {
158227
157076
  inlineJsxTransform(hir, env.config.inlineJsxTransform);
158228
157077
  yield log({kind: 'hir', name: 'inlineJsxTransform', value: hir});
@@ -158241,14 +157090,6 @@ function* runWithEnvironment(func, env) {
158241
157090
  value: reactiveFunction,
158242
157091
  });
158243
157092
  assertScopeInstructionsWithinScopes(reactiveFunction);
158244
- if (!env.config.enablePropagateDepsInHIR) {
158245
- propagateScopeDependencies(reactiveFunction);
158246
- yield log({
158247
- kind: 'reactive',
158248
- name: 'PropagateScopeDependencies',
158249
- value: reactiveFunction,
158250
- });
158251
- }
158252
157093
  pruneNonEscapingScopes(reactiveFunction);
158253
157094
  yield log({
158254
157095
  kind: 'reactive',
@@ -159479,7 +158320,7 @@ exports.OPT_OUT_DIRECTIVES = OPT_OUT_DIRECTIVES;
159479
158320
  exports.compile = compileFn;
159480
158321
  exports.compileProgram = compileProgram;
159481
158322
  exports.default = BabelPluginReactCompiler;
159482
- exports.parseConfigPragma = parseConfigPragma;
158323
+ exports.parseConfigPragmaForTests = parseConfigPragmaForTests;
159483
158324
  exports.parsePluginOptions = parsePluginOptions;
159484
158325
  exports.printHIR = printHIR;
159485
158326
  exports.printReactiveFunction = printReactiveFunction;