@markw65/monkeyc-optimizer 1.1.3 → 1.1.4

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.
@@ -3626,7 +3626,7 @@ async function checkManifest(manifest, products) {
3626
3626
  `${t}app` === type ||
3627
3627
  (type === "widget" && t === "watchapp"));
3628
3628
  }));
3629
- if (JSON.stringify(allowedProducts) !=
3629
+ if (JSON.stringify(allowedProducts) !==
3630
3630
  JSON.stringify(manifestProducts(manifest))) {
3631
3631
  ok = false;
3632
3632
  const products = app.children("iq:products");
@@ -3730,15 +3730,15 @@ function process_assignments(assignments, current) {
3730
3730
  const process_list = (values) => {
3731
3731
  for (let i = values.length; i--;) {
3732
3732
  const v = values[i];
3733
- if (v.type == "QualifiedName" &&
3733
+ if (v.type === "QualifiedName" &&
3734
3734
  v.names.every((n, i) => n === a.names[i])) {
3735
3735
  values.splice(i, 1, ...(dot
3736
- ? dot.map((v) => v.type == "QualifiedName"
3736
+ ? dot.map((v) => v.type === "QualifiedName"
3737
3737
  ? { ...v, names: v.names.concat(dotnames) }
3738
3738
  : v)
3739
3739
  : []));
3740
3740
  }
3741
- else if (v.type == "SubList") {
3741
+ else if (v.type === "SubList") {
3742
3742
  process_list(v.values);
3743
3743
  }
3744
3744
  }
@@ -3771,7 +3771,8 @@ function evaluate_locals(assignments) {
3771
3771
  const locals = {};
3772
3772
  while (true) {
3773
3773
  assignments = assignments.filter((a) => {
3774
- if (a.names.length == 1 && a.values.every((v) => typeof v === "string")) {
3774
+ if (a.names.length === 1 &&
3775
+ a.values.every((v) => typeof v === "string")) {
3775
3776
  locals[a.names[0]] = a.values;
3776
3777
  return false;
3777
3778
  }
@@ -3782,12 +3783,12 @@ function evaluate_locals(assignments) {
3782
3783
  const process_list = (values) => {
3783
3784
  for (let i = values.length; i--;) {
3784
3785
  const v = values[i];
3785
- if (v.type == "QualifiedName" &&
3786
- v.names.length == 1 &&
3786
+ if (v.type === "QualifiedName" &&
3787
+ v.names.length === 1 &&
3787
3788
  (0,external_api_cjs_namespaceObject.hasProperty)(locals, v.names[0])) {
3788
3789
  values.splice(i, 1, ...locals[v.names[0]]);
3789
3790
  }
3790
- else if (v.type == "SubList") {
3791
+ else if (v.type === "SubList") {
3791
3792
  process_list(v.values);
3792
3793
  }
3793
3794
  }
@@ -3866,7 +3867,7 @@ function resolve_node_by_path(state, path) {
3866
3867
  if (!resolved.length)
3867
3868
  return undefined;
3868
3869
  const r = resolved[0][n];
3869
- if (!r && sdot.every((e) => e.type == "Literal")) {
3870
+ if (!r && sdot.every((e) => e.type === "Literal")) {
3870
3871
  /*
3871
3872
  * We had something like:
3872
3873
  *
@@ -3944,10 +3945,10 @@ async function resolve_literals(qualifier, default_source, deviceInfo, cache) {
3944
3945
  if (!isJNode(v)) {
3945
3946
  return v;
3946
3947
  }
3947
- if (v.type == "QualifiedName") {
3948
+ if (v.type === "QualifiedName") {
3948
3949
  throw new Error("Unexpected QualifiedName found!");
3949
3950
  }
3950
- if (v.type == "SubList") {
3951
+ if (v.type === "SubList") {
3951
3952
  return resolve_file_list(v.values);
3952
3953
  }
3953
3954
  // Jungle files can contain "./**.mc" which is supposed to match
@@ -4741,6 +4742,9 @@ function withLoc(node, start, end) {
4741
4742
  if (!node.end)
4742
4743
  node.end = start.end;
4743
4744
  node.loc = { ...(node.loc || start.loc), start: start.loc.start };
4745
+ if (end === start && start.origins) {
4746
+ node.origins = start.origins;
4747
+ }
4744
4748
  }
4745
4749
  if (end === false) {
4746
4750
  if (node.loc) {
@@ -4773,17 +4777,17 @@ function cloneDeep(node) {
4773
4777
  return withLocDeep(node, null);
4774
4778
  }
4775
4779
  function getNodeValue(node) {
4776
- if (node.type == "BinaryExpression" &&
4777
- node.operator == "as" &&
4778
- node.right.type == "TypeSpecList" &&
4779
- node.right.ts.length == 1 &&
4780
- typeof node.right.ts[0] == "string") {
4780
+ if (node.type === "BinaryExpression" &&
4781
+ node.operator === "as" &&
4782
+ node.right.type === "TypeSpecList" &&
4783
+ node.right.ts.length === 1 &&
4784
+ typeof node.right.ts[0] === "string") {
4781
4785
  // this is a cast we inserted to retain the type of an enum
4782
4786
  // any arithmetic on it will revert to "Number", or "Long",
4783
4787
  // so just ignore it.
4784
4788
  return getNodeValue(node.left);
4785
4789
  }
4786
- if (node.type != "Literal") {
4790
+ if (node.type !== "Literal") {
4787
4791
  return [null, null];
4788
4792
  }
4789
4793
  if (node.value === null) {
@@ -4873,13 +4877,13 @@ function makeScopedName(dotted, l) {
4873
4877
  function ast_getLiteralNode(node) {
4874
4878
  if (node == null)
4875
4879
  return null;
4876
- if (node.type == "Literal")
4880
+ if (node.type === "Literal")
4877
4881
  return node;
4878
- if (node.type == "BinaryExpression" && node.operator == "as") {
4882
+ if (node.type === "BinaryExpression" && node.operator === "as") {
4879
4883
  return ast_getLiteralNode(node.left) && node;
4880
4884
  }
4881
- if (node.type == "UnaryExpression") {
4882
- if (node.argument.type != "Literal")
4885
+ if (node.type === "UnaryExpression") {
4886
+ if (node.argument.type !== "Literal")
4883
4887
  return null;
4884
4888
  switch (node.operator) {
4885
4889
  case "-": {
@@ -4910,7 +4914,7 @@ function recordModifiedDecl(func, decl) {
4910
4914
  }
4911
4915
  function recordModifiedDecls(func, lookupDefs) {
4912
4916
  lookupDefs.forEach((lookupDef) => lookupDef.results.forEach((result) => {
4913
- if (result.type == "VariableDeclarator" && result.node.kind === "var") {
4917
+ if (result.type === "VariableDeclarator" && result.node.kind === "var") {
4914
4918
  recordModifiedDecl(func, result);
4915
4919
  }
4916
4920
  }));
@@ -5262,7 +5266,7 @@ function getArgSafety(state, func, args, requireAll) {
5262
5266
  switch (node.type) {
5263
5267
  case "AssignmentExpression":
5264
5268
  case "UpdateExpression": {
5265
- const v = node.type == "UpdateExpression" ? node.argument : node.left;
5269
+ const v = node.type === "UpdateExpression" ? node.argument : node.left;
5266
5270
  if (v.type === "Identifier" && (0,external_api_cjs_namespaceObject.hasProperty)(params, v.name)) {
5267
5271
  // If a parameter is modified, we can't just substitute the
5268
5272
  // argument wherever the parameter is used.
@@ -5482,6 +5486,12 @@ function processInlineBody(state, func, call, root, params) {
5482
5486
  const ix = params[node.name];
5483
5487
  if (ix >= 0) {
5484
5488
  const replacement = { ...call.arguments[ix] };
5489
+ if (node.loc) {
5490
+ if (!replacement.origins) {
5491
+ replacement.origins = [];
5492
+ }
5493
+ replacement.origins.unshift({ loc: node.loc, func: func.fullName });
5494
+ }
5485
5495
  replacements.add(replacement);
5486
5496
  return replacement;
5487
5497
  }
@@ -5568,7 +5578,7 @@ function unused(state, expression, top) {
5568
5578
  body: [estmt(expression.right)],
5569
5579
  }, expression.right);
5570
5580
  let alternate;
5571
- if (expression.operator == "||" || expression.operator == "or") {
5581
+ if (expression.operator === "||" || expression.operator === "or") {
5572
5582
  alternate = { ...consequent };
5573
5583
  consequent.body = [];
5574
5584
  }
@@ -5629,7 +5639,10 @@ function unused(state, expression, top) {
5629
5639
  }
5630
5640
  function inlineDiagnostic(state, func, call, message) {
5631
5641
  if (inlineRequested(state, func)) {
5632
- (0,external_api_cjs_namespaceObject.diagnostic)(state, call, message && `While inlining ${func.node.id.name}: ${message}`);
5642
+ if (!state.inlineDiagnostics) {
5643
+ state.inlineDiagnostics = {};
5644
+ }
5645
+ (0,external_api_cjs_namespaceObject.diagnosticHelper)(state.inlineDiagnostics, call, message && `While inlining ${func.node.id.name}: ${message}`, "INFO", undefined, true);
5633
5646
  }
5634
5647
  }
5635
5648
  function inlineWithArgs(state, func, call, context) {
@@ -5688,10 +5701,10 @@ function inlineWithArgs(state, func, call, context) {
5688
5701
  if (!processInlineBody(state, func, call, body, params)) {
5689
5702
  return null;
5690
5703
  }
5691
- (0,external_api_cjs_namespaceObject.diagnostic)(state, call, null);
5704
+ inlineDiagnostic(state, func, call, null);
5692
5705
  if (context.type !== "ReturnStatement" && retStmtCount) {
5693
5706
  const [last, block] = lastStmt(body);
5694
- if (last.type != "ReturnStatement") {
5707
+ if (last.type !== "ReturnStatement") {
5695
5708
  throw new Error("ReturnStatement got lost!");
5696
5709
  }
5697
5710
  if (last.argument) {
@@ -5988,7 +6001,7 @@ function pragmaChecker(state, ast, diagnostics) {
5988
6001
  }
5989
6002
  };
5990
6003
  const matcher = (quote, needle, haystack) => {
5991
- if (quote == '"') {
6004
+ if (quote === '"') {
5992
6005
  return haystack.includes(needle);
5993
6006
  }
5994
6007
  const re = new RegExp(needle.replace(/@([-\d.\w]+|"[^"]*")/g, (_match, pat) => `(?:${pat}|pre_${pat.replace(/\W/g, "_")}(?:_\\d+)?)`));
@@ -6785,7 +6798,7 @@ function buildDataFlowGraph(state, func, wantsLiteral, trackInsertionPoints, wan
6785
6798
  uniqueDeclMap.set(decls[0], decls);
6786
6799
  return decls;
6787
6800
  }
6788
- if (canon.length != decls.length ||
6801
+ if (canon.length !== decls.length ||
6789
6802
  !canon.every((v, i) => v === decls[i])) {
6790
6803
  throw new Error(`Canonical representation of ${declFullName(canon)} did not match`);
6791
6804
  }
@@ -7376,7 +7389,7 @@ function anticipatedDecls() {
7376
7389
  return new Map();
7377
7390
  }
7378
7391
  function equalSet(a, b) {
7379
- if (a.size != b.size)
7392
+ if (a.size !== b.size)
7380
7393
  return false;
7381
7394
  for (const item of a) {
7382
7395
  if (!b.has(item))
@@ -7385,7 +7398,7 @@ function equalSet(a, b) {
7385
7398
  return true;
7386
7399
  }
7387
7400
  function equalMap(a, b) {
7388
- if (a.size != b.size)
7401
+ if (a.size !== b.size)
7389
7402
  return false;
7390
7403
  for (const [item, value] of a) {
7391
7404
  if (b.get(item) !== value)
@@ -7438,8 +7451,8 @@ function equalStates(a, b) {
7438
7451
  for (const [k, ae] of a) {
7439
7452
  const be = b.get(k);
7440
7453
  if (!be ||
7441
- be.live != ae.live ||
7442
- be.isIsolated != ae.isIsolated ||
7454
+ be.live !== ae.live ||
7455
+ be.isIsolated !== ae.isIsolated ||
7443
7456
  !equalSet(ae.ant, be.ant) ||
7444
7457
  !equalMap(ae.members, be.members)) {
7445
7458
  return false;
@@ -7471,8 +7484,8 @@ function refCost(node) {
7471
7484
  return cost;
7472
7485
  while (true) {
7473
7486
  const next = node.object;
7474
- if (next.type != "MemberExpression") {
7475
- if (next.type != "ThisExpression") {
7487
+ if (next.type !== "MemberExpression") {
7488
+ if (next.type !== "ThisExpression") {
7476
7489
  cost += next.type === "Identifier" && next.name === "$" ? 4 : 6;
7477
7490
  }
7478
7491
  return cost;
@@ -7728,7 +7741,7 @@ function computeAttributes(state, head) {
7728
7741
  delete existing.isIsolated;
7729
7742
  mergeAnticipatedState(events, existing);
7730
7743
  }
7731
- else if (candidateCost(events) != cost) {
7744
+ else if (candidateCost(events) !== cost) {
7732
7745
  throw new Error(`cost of block ${i} changed`);
7733
7746
  }
7734
7747
  candidateDecls.set(decl, events);
@@ -8014,7 +8027,7 @@ function describeEvent(event) {
8014
8027
  }
8015
8028
  function printBlockEvents(block, extra) {
8016
8029
  console.log("Events:");
8017
- (0,external_util_cjs_namespaceObject.forEach)(block.events, (event) => console.log(` ${describeEvent(event)} ${extra?.(event)}`));
8030
+ (0,external_util_cjs_namespaceObject.forEach)(block.events, (event) => console.log(` ${describeEvent(event)} ${extra ? extra(event) : ""}`));
8018
8031
  }
8019
8032
  function printBlockTrailer(block) {
8020
8033
  console.log(`Succs: ${(block.succs || [])
@@ -8090,19 +8103,20 @@ function findDeadStores(graph, logThisRun) {
8090
8103
  }
8091
8104
  break;
8092
8105
  case "def":
8093
- if (isTypeStateKey(event.decl) &&
8094
- ((event.node.type === "AssignmentExpression" &&
8095
- event.node.operator === "=") ||
8096
- (event.node.type === "VariableDeclarator" && event.node.init))) {
8106
+ if (isTypeStateKey(event.decl)) {
8097
8107
  if (curState.has(event.decl)) {
8098
8108
  deadStores.add(event.node);
8099
8109
  }
8100
8110
  else {
8101
8111
  deadStores.delete(event.node);
8102
8112
  }
8103
- curState.add(event.decl);
8104
- if (logThisRun) {
8105
- console.log(` anticipated => ${tsKey(event.decl)}`);
8113
+ if ((event.node.type === "AssignmentExpression" &&
8114
+ event.node.operator === "=") ||
8115
+ (event.node.type === "VariableDeclarator" && event.node.init)) {
8116
+ curState.add(event.decl);
8117
+ if (logThisRun) {
8118
+ console.log(` anticipated => ${tsKey(event.decl)}`);
8119
+ }
8106
8120
  }
8107
8121
  }
8108
8122
  break;
@@ -8156,12 +8170,23 @@ function eliminateDeadStores(state, func, graph, logThisRun) {
8156
8170
  node.expression.type === "AssignmentExpression" &&
8157
8171
  deadStores.has(node.expression)) {
8158
8172
  const body = unused(state, node.expression.left).concat(unused(state, node.expression.right));
8173
+ changes = true;
8159
8174
  if (body.length) {
8160
8175
  return withLoc({ type: "BlockStatement", body }, node, node);
8161
8176
  }
8162
- changes = true;
8163
8177
  return false;
8164
8178
  }
8179
+ if (node.type === "UpdateExpression" && deadStores.has(node)) {
8180
+ changes = true;
8181
+ return { type: "Literal", value: null, raw: "null" };
8182
+ }
8183
+ if (node.type === "AssignmentExpression" &&
8184
+ deadStores.has(node) &&
8185
+ unused(state, node.right, true)?.length === 0 &&
8186
+ unused(state, node.left, true)?.length === 0) {
8187
+ changes = true;
8188
+ return { type: "Literal", value: null, raw: "null" };
8189
+ }
8165
8190
  if (node.type === "VariableDeclaration") {
8166
8191
  const result = [];
8167
8192
  for (let i = 0; i < node.declarations.length; i++) {
@@ -8305,28 +8330,32 @@ function intersection(a, b) {
8305
8330
  }
8306
8331
  let mask = 0;
8307
8332
  const result = {};
8308
- forEachUnionComponent(a, common, (bit, avalue) => {
8309
- const bvalue = getUnionComponent(b, bit);
8310
- if (avalue == null) {
8333
+ forEachUnionComponent(a, common, (ac) => {
8334
+ const bvalue = getUnionComponent(b, ac.type);
8335
+ if (ac.value == null) {
8311
8336
  if (!bvalue)
8312
8337
  return;
8313
- result[bit] = bvalue;
8314
- mask |= bit;
8338
+ result[ac.type] = bvalue;
8339
+ mask |= ac.type;
8315
8340
  return;
8316
8341
  }
8317
- if (bvalue === null || avalue === bvalue) {
8318
- result[bit] = avalue;
8319
- mask |= bit;
8342
+ if (bvalue === null || ac.value === bvalue) {
8343
+ result[ac.type] = ac.value;
8344
+ mask |= ac.type;
8320
8345
  return;
8321
8346
  }
8322
- const ivalue = intersectionValue(bit, avalue, bvalue);
8347
+ const ivalue = intersectionValue({
8348
+ type: ac.type,
8349
+ avalue: ac.value,
8350
+ bvalue,
8351
+ });
8323
8352
  if (ivalue != null) {
8324
- result[bit] = ivalue;
8325
- mask |= bit;
8353
+ result[ac.type] = ivalue;
8354
+ mask |= ac.type;
8326
8355
  return;
8327
8356
  }
8328
8357
  else {
8329
- common -= bit;
8358
+ common -= ac.type;
8330
8359
  }
8331
8360
  });
8332
8361
  if (!mask)
@@ -8339,13 +8368,13 @@ function intersection(a, b) {
8339
8368
  }
8340
8369
  return { type: common, value: result[mask] };
8341
8370
  }
8342
- function intersectionValue(bit, avalue, bvalue) {
8343
- switch (bit) {
8371
+ function intersectionValue(pair) {
8372
+ switch (pair.type) {
8344
8373
  case 1 /* TypeTag.Null */:
8345
8374
  case 2 /* TypeTag.False */:
8346
8375
  case 4 /* TypeTag.True */:
8347
8376
  case 262144 /* TypeTag.Typedef */:
8348
- throw new Error(`Unexpected TypeTag '${typeTagName(bit)}'`);
8377
+ throw new Error(`Unexpected TypeTag '${typeTagName(pair.type)}'`);
8349
8378
  case 8 /* TypeTag.Number */:
8350
8379
  case 16 /* TypeTag.Long */:
8351
8380
  case 32 /* TypeTag.Float */:
@@ -8353,31 +8382,27 @@ function intersectionValue(bit, avalue, bvalue) {
8353
8382
  case 256 /* TypeTag.String */:
8354
8383
  case 128 /* TypeTag.Char */:
8355
8384
  case 131072 /* TypeTag.Symbol */:
8356
- return avalue === bvalue ? avalue : null;
8385
+ return pair.avalue === pair.bvalue ? pair.avalue : null;
8357
8386
  case 512 /* TypeTag.Array */: {
8358
- const atype = intersection(avalue, bvalue);
8387
+ const atype = intersection(pair.avalue, pair.bvalue);
8359
8388
  return atype.type === 0 /* TypeTag.Never */ ? null : atype;
8360
8389
  }
8361
8390
  case 1024 /* TypeTag.Dictionary */: {
8362
- const adict = avalue;
8363
- const bdict = bvalue;
8364
- const dkey = intersection(adict.key, bdict.key);
8365
- const dvalue = intersection(adict.value, bdict.value);
8391
+ const dkey = intersection(pair.avalue.key, pair.bvalue.key);
8392
+ const dvalue = intersection(pair.avalue.value, pair.bvalue.value);
8366
8393
  return dkey.type !== 0 /* TypeTag.Never */ && dvalue.type !== 0 /* TypeTag.Never */
8367
8394
  ? { key: dkey, value: dvalue }
8368
8395
  : null;
8369
8396
  }
8370
8397
  case 2048 /* TypeTag.Method */: {
8371
- const ameth = avalue;
8372
- const bmeth = bvalue;
8373
- if (ameth.args.length != bmeth.args.length)
8398
+ if (pair.avalue.args.length !== pair.bvalue.args.length)
8374
8399
  return null;
8375
- const mresult = intersection(ameth.result, bmeth.result);
8400
+ const mresult = intersection(pair.avalue.result, pair.bvalue.result);
8376
8401
  if (mresult.type === 0 /* TypeTag.Never */)
8377
8402
  return null;
8378
- const margs = ameth.args.map((aarg, i) => {
8403
+ const margs = pair.avalue.args.map((aarg, i) => {
8379
8404
  aarg = cloneType(aarg);
8380
- unionInto(aarg, bmeth.args[i]);
8405
+ unionInto(aarg, pair.bvalue.args[i]);
8381
8406
  return aarg;
8382
8407
  });
8383
8408
  if (margs.some((arg) => arg.type === 0 /* TypeTag.Never */))
@@ -8386,23 +8411,19 @@ function intersectionValue(bit, avalue, bvalue) {
8386
8411
  }
8387
8412
  case 4096 /* TypeTag.Module */:
8388
8413
  case 8192 /* TypeTag.Function */: {
8389
- const asd = avalue;
8390
- const bsd = bvalue;
8391
8414
  // quadratic :-(
8392
8415
  const common = [];
8393
- (0,external_util_cjs_namespaceObject.forEach)(asd, (sna) => (0,external_util_cjs_namespaceObject.some)(bsd, (snb) => sna === snb) &&
8416
+ (0,external_util_cjs_namespaceObject.forEach)(pair.avalue, (sna) => (0,external_util_cjs_namespaceObject.some)(pair.bvalue, (snb) => sna === snb) &&
8394
8417
  common.push(sna));
8395
8418
  if (!common.length)
8396
8419
  return null;
8397
8420
  return (common.length === 1 ? common[0] : common);
8398
8421
  }
8399
8422
  case 16384 /* TypeTag.Class */: {
8400
- const asd = avalue;
8401
- const bsd = bvalue;
8402
8423
  const common = [];
8403
- (0,external_util_cjs_namespaceObject.forEach)(asd, (sna) => {
8424
+ (0,external_util_cjs_namespaceObject.forEach)(pair.avalue, (sna) => {
8404
8425
  const superA = (0,external_api_cjs_namespaceObject.getSuperClasses)(sna);
8405
- (0,external_util_cjs_namespaceObject.forEach)(bsd, (snb) => {
8426
+ (0,external_util_cjs_namespaceObject.forEach)(pair.bvalue, (snb) => {
8406
8427
  if (sna === snb || (superA && superA.has(snb))) {
8407
8428
  common.push(sna);
8408
8429
  }
@@ -8417,10 +8438,8 @@ function intersectionValue(bit, avalue, bvalue) {
8417
8438
  return common.length === 1 ? common[0] : common;
8418
8439
  }
8419
8440
  case 32768 /* TypeTag.Object */: {
8420
- const aobj = avalue;
8421
- const bobj = bvalue;
8422
- const klass = intersection(aobj.klass, bobj.klass);
8423
- const obj = intersectObj(aobj.obj, bobj.obj);
8441
+ const klass = intersection(pair.avalue.klass, pair.bvalue.klass);
8442
+ const obj = intersectObj(pair.avalue.obj, pair.bvalue.obj);
8424
8443
  return klass.type !== 16384 /* TypeTag.Class */ || klass.value == null
8425
8444
  ? null
8426
8445
  : obj
@@ -8428,24 +8447,24 @@ function intersectionValue(bit, avalue, bvalue) {
8428
8447
  : { klass: klass };
8429
8448
  }
8430
8449
  case 65536 /* TypeTag.Enum */: {
8431
- const aenum = avalue;
8432
- const benum = bvalue;
8433
- if (aenum.enum !== benum.enum && aenum.enum && benum.enum) {
8450
+ if (pair.avalue.enum !== pair.bvalue.enum &&
8451
+ pair.avalue.enum &&
8452
+ pair.bvalue.enum) {
8434
8453
  return null;
8435
8454
  }
8436
- const enumDecl = aenum.enum || benum.enum;
8437
- if (aenum.value != null) {
8438
- if (benum.value != null) {
8439
- const value = intersection(aenum.value, benum.value);
8455
+ const enumDecl = pair.avalue.enum || pair.bvalue.enum;
8456
+ if (pair.avalue.value != null) {
8457
+ if (pair.bvalue.value != null) {
8458
+ const value = intersection(pair.avalue.value, pair.bvalue.value);
8440
8459
  const e = { enum: enumDecl, value };
8441
8460
  return e;
8442
8461
  }
8443
- return aenum.value;
8462
+ return pair.avalue.value;
8444
8463
  }
8445
- return benum;
8464
+ return pair.bvalue;
8446
8465
  }
8447
8466
  default:
8448
- unhandledType(bit);
8467
+ unhandledType(pair);
8449
8468
  }
8450
8469
  }
8451
8470
  function intersectObj(to, from) {
@@ -8509,9 +8528,11 @@ function restrictExactTypesByEquality(a, b) {
8509
8528
  extra_bits |= 4 /* TypeTag.True */;
8510
8529
  }
8511
8530
  let value_bits = b.type & (120 /* TypeTag.Numeric */ | 128 /* TypeTag.Char */);
8531
+ // Some Numbers don't fit exactly in a Float
8532
+ // We can eliminate Float from b's type in those cases.
8512
8533
  if (a.value != null &&
8513
8534
  value_bits & 32 /* TypeTag.Float */ &&
8514
- roundToFloat(Number(a.value)) != a.value) {
8535
+ roundToFloat(Number(a.value)) !== a.value) {
8515
8536
  value_bits -= 32 /* TypeTag.Float */;
8516
8537
  }
8517
8538
  let v = {
@@ -8540,14 +8561,15 @@ function restrictExactTypesByEquality(a, b) {
8540
8561
  let value_bits = b.type & 120 /* TypeTag.Numeric */;
8541
8562
  if (a.value != null) {
8542
8563
  if (value_bits & 8 /* TypeTag.Number */ &&
8543
- BigInt.asIntN(32, a.value) != a.value) {
8564
+ BigInt.asIntN(32, a.value) !== a.value) {
8544
8565
  value_bits -= 8 /* TypeTag.Number */;
8545
8566
  }
8546
8567
  if (value_bits & 32 /* TypeTag.Float */ &&
8547
- BigInt(roundToFloat(Number(a.value))) != a.value) {
8568
+ BigInt(roundToFloat(Number(a.value))) !== a.value) {
8548
8569
  value_bits -= 32 /* TypeTag.Float */;
8549
8570
  }
8550
- if (value_bits & 64 /* TypeTag.Double */ && BigInt(Number(a.value)) != a.value) {
8571
+ if (value_bits & 64 /* TypeTag.Double */ &&
8572
+ BigInt(Number(a.value)) !== a.value) {
8551
8573
  value_bits -= 64 /* TypeTag.Double */;
8552
8574
  }
8553
8575
  }
@@ -8648,7 +8670,7 @@ function restrictExactTypesByEquality(a, b) {
8648
8670
  }
8649
8671
  function restrictByEqualityByComponent(a, b) {
8650
8672
  let bits = a.type;
8651
- if (a.value == null && (b.type & bits) == b.type) {
8673
+ if (a.value == null && (b.type & bits) === b.type) {
8652
8674
  // shortcut:
8653
8675
  // if b.type is contained in a.type, and a has no
8654
8676
  // specialization, the result is just b.
@@ -8690,7 +8712,7 @@ function restrictByEqualityByComponent(a, b) {
8690
8712
  * 5.0 == 5, and 5.toChar() == 5.
8691
8713
  */
8692
8714
  function restrictByEquality(a, b) {
8693
- if (a.type == 0 /* TypeTag.Never */)
8715
+ if (a.type === 0 /* TypeTag.Never */)
8694
8716
  return a;
8695
8717
  if (isExact(a)) {
8696
8718
  return restrictExactTypesByEquality(a, b);
@@ -8741,11 +8763,12 @@ function subtypeOf(a, b) {
8741
8763
  if (b.value == null)
8742
8764
  return true;
8743
8765
  let result = true;
8744
- forEachUnionComponent(b, common, (bit, bvalue) => {
8745
- const avalue = getUnionComponent(a, bit);
8746
- if (bvalue == null || avalue === bvalue)
8766
+ forEachUnionComponent(b, common, (bc) => {
8767
+ const avalue = getUnionComponent(a, bc.type);
8768
+ if (bc.value == null || avalue === bc.value)
8747
8769
  return true;
8748
- if (avalue == null || !subtypeOfValue(bit, avalue, bvalue)) {
8770
+ if (avalue == null ||
8771
+ !subtypeOfValue({ type: bc.type, avalue, bvalue: bc.value })) {
8749
8772
  result = false;
8750
8773
  return false;
8751
8774
  }
@@ -8753,13 +8776,13 @@ function subtypeOf(a, b) {
8753
8776
  });
8754
8777
  return result;
8755
8778
  }
8756
- function subtypeOfValue(bit, avalue, bvalue) {
8757
- switch (bit) {
8779
+ function subtypeOfValue(pair) {
8780
+ switch (pair.type) {
8758
8781
  case 1 /* TypeTag.Null */:
8759
8782
  case 2 /* TypeTag.False */:
8760
8783
  case 4 /* TypeTag.True */:
8761
8784
  case 262144 /* TypeTag.Typedef */:
8762
- throw new Error(`Unexpected TypeTag '${typeTagName(bit)}'`);
8785
+ throw new Error(`Unexpected TypeTag '${typeTagName(pair.type)}'`);
8763
8786
  case 8 /* TypeTag.Number */:
8764
8787
  case 16 /* TypeTag.Long */:
8765
8788
  case 32 /* TypeTag.Float */:
@@ -8767,31 +8790,29 @@ function subtypeOfValue(bit, avalue, bvalue) {
8767
8790
  case 256 /* TypeTag.String */:
8768
8791
  case 128 /* TypeTag.Char */:
8769
8792
  case 131072 /* TypeTag.Symbol */:
8770
- return avalue === bvalue;
8793
+ return pair.avalue === pair.bvalue;
8771
8794
  case 512 /* TypeTag.Array */:
8772
- return subtypeOf(avalue, bvalue);
8795
+ return subtypeOf(pair.avalue, pair.bvalue);
8773
8796
  case 1024 /* TypeTag.Dictionary */: {
8774
- const adict = avalue;
8775
- const bdict = bvalue;
8797
+ const adict = pair.avalue;
8798
+ const bdict = pair.bvalue;
8776
8799
  return (subtypeOf(adict.key, bdict.key) && subtypeOf(adict.value, bdict.value));
8777
8800
  }
8778
8801
  case 2048 /* TypeTag.Method */: {
8779
- const ameth = avalue;
8780
- const bmeth = bvalue;
8781
- return (ameth.args.length === bmeth.args.length &&
8782
- subtypeOf(ameth.result, bmeth.result) &&
8783
- ameth.args.every((arg, i) => subtypeOf(bmeth.args[i], arg)));
8802
+ return (pair.avalue.args.length === pair.bvalue.args.length &&
8803
+ subtypeOf(pair.avalue.result, pair.bvalue.result) &&
8804
+ pair.avalue.args.every((arg, i) => subtypeOf(pair.bvalue.args[i], arg)));
8784
8805
  }
8785
8806
  case 4096 /* TypeTag.Module */:
8786
8807
  case 8192 /* TypeTag.Function */: {
8787
- const asd = avalue;
8788
- const bsd = bvalue;
8808
+ const asd = pair.avalue;
8809
+ const bsd = pair.bvalue;
8789
8810
  // quadratic :-(
8790
8811
  return (0,external_util_cjs_namespaceObject.some)(asd, (sna) => (0,external_util_cjs_namespaceObject.some)(bsd, (snb) => sna === snb));
8791
8812
  }
8792
8813
  case 16384 /* TypeTag.Class */: {
8793
- const asd = avalue;
8794
- const bsd = bvalue;
8814
+ const asd = pair.avalue;
8815
+ const bsd = pair.bvalue;
8795
8816
  return (0,external_util_cjs_namespaceObject.every)(asd, (sna) => {
8796
8817
  const superA = (0,external_api_cjs_namespaceObject.getSuperClasses)(sna);
8797
8818
  return (0,external_util_cjs_namespaceObject.some)(bsd, (snb) => {
@@ -8803,18 +8824,18 @@ function subtypeOfValue(bit, avalue, bvalue) {
8803
8824
  });
8804
8825
  }
8805
8826
  case 32768 /* TypeTag.Object */: {
8806
- const aobj = avalue;
8807
- const bobj = bvalue;
8827
+ const aobj = pair.avalue;
8828
+ const bobj = pair.bvalue;
8808
8829
  return (subtypeOf(aobj.klass, bobj.klass) && subtypeOfObj(aobj.obj, bobj.obj));
8809
8830
  }
8810
8831
  case 65536 /* TypeTag.Enum */: {
8811
- const aenum = avalue;
8812
- const benum = bvalue;
8832
+ const aenum = pair.avalue;
8833
+ const benum = pair.bvalue;
8813
8834
  return (aenum.enum === benum.enum &&
8814
8835
  (!aenum.value || !benum.value || subtypeOf(aenum.value, benum.value)));
8815
8836
  }
8816
8837
  default:
8817
- unhandledType(bit);
8838
+ unhandledType(pair);
8818
8839
  }
8819
8840
  }
8820
8841
  function subtypeOfObj(a, b) {
@@ -8835,6 +8856,9 @@ function subtypeOfObj(a, b) {
8835
8856
 
8836
8857
 
8837
8858
  function unionInto(to, from) {
8859
+ if (to == null || from == null) {
8860
+ throw new Error("Null");
8861
+ }
8838
8862
  if (from.type === 0 || to === from)
8839
8863
  return false;
8840
8864
  if (to.type === 0) {
@@ -8884,23 +8908,27 @@ function mergeMultiple(to, from) {
8884
8908
  let anyChanged = newTags !== to.type;
8885
8909
  let mask = 0;
8886
8910
  const result = {};
8887
- forEachUnionComponent(to, newTags, (tag, tov) => {
8888
- const fromv = getUnionComponent(from, tag);
8889
- if (tov != null) {
8911
+ forEachUnionComponent(to, newTags, (ac) => {
8912
+ const fromv = getUnionComponent(from, ac.type);
8913
+ if (ac.value != null) {
8890
8914
  if (fromv != null) {
8891
- const [value, changed] = mergeSingle(tag, tov, fromv);
8915
+ const [value, changed] = mergeSingle({
8916
+ type: ac.type,
8917
+ avalue: ac.value,
8918
+ bvalue: fromv,
8919
+ });
8892
8920
  if (changed)
8893
8921
  anyChanged = true;
8894
8922
  if (value) {
8895
- mask |= tag;
8896
- result[tag] = value;
8923
+ mask |= ac.type;
8924
+ result[ac.type] = value;
8897
8925
  }
8898
8926
  }
8899
- else if (!(from.type & tag)) {
8927
+ else if (!(from.type & ac.type)) {
8900
8928
  // from doesn't contribute to this tag,
8901
8929
  // so just keep it. No change.
8902
- mask |= tag;
8903
- result[tag] = tov;
8930
+ mask |= ac.type;
8931
+ result[ac.type] = ac.value;
8904
8932
  }
8905
8933
  else {
8906
8934
  // We dropped the data for this tag, so
@@ -8908,13 +8936,13 @@ function mergeMultiple(to, from) {
8908
8936
  anyChanged = true;
8909
8937
  }
8910
8938
  }
8911
- else if (fromv && !(to.type & tag)) {
8939
+ else if (fromv && !(to.type & ac.type)) {
8912
8940
  // to doesn't contribute to this tag,
8913
8941
  // so just keep from's component.
8914
8942
  // this is new, so it changed.
8915
8943
  anyChanged = true;
8916
- mask |= tag;
8917
- result[tag] = fromv;
8944
+ mask |= ac.type;
8945
+ result[ac.type] = fromv;
8918
8946
  }
8919
8947
  });
8920
8948
  if (!anyChanged)
@@ -8941,8 +8969,8 @@ function tryUnion(to, from) {
8941
8969
  return to;
8942
8970
  return null;
8943
8971
  }
8944
- function mergeSingle(type, to, from) {
8945
- switch (type) {
8972
+ function mergeSingle(pair) {
8973
+ switch (pair.type) {
8946
8974
  case 1 /* TypeTag.Null */:
8947
8975
  case 2 /* TypeTag.False */:
8948
8976
  case 4 /* TypeTag.True */:
@@ -8954,48 +8982,49 @@ function mergeSingle(type, to, from) {
8954
8982
  case 128 /* TypeTag.Char */:
8955
8983
  case 256 /* TypeTag.String */:
8956
8984
  case 131072 /* TypeTag.Symbol */:
8957
- if (to === from) {
8958
- return [to, false];
8985
+ if (pair.avalue === pair.bvalue) {
8986
+ return [pair.avalue, false];
8959
8987
  }
8960
8988
  return [null, true];
8961
8989
  case 512 /* TypeTag.Array */: {
8962
- const merged = tryUnion(to, from);
8963
- return [merged || to, merged != null];
8990
+ const merged = tryUnion(pair.avalue, pair.bvalue);
8991
+ return [merged || pair.avalue, merged != null];
8964
8992
  }
8965
8993
  case 1024 /* TypeTag.Dictionary */: {
8966
- const { key, value } = to;
8967
- const keyChange = tryUnion(key, from.key);
8968
- const valueChange = tryUnion(value, from.value);
8994
+ const { key, value } = pair.avalue;
8995
+ const keyChange = tryUnion(key, pair.bvalue.key);
8996
+ const valueChange = tryUnion(value, pair.bvalue.value);
8969
8997
  if (keyChange || valueChange) {
8970
8998
  return [{ key: keyChange || key, value: valueChange || value }, true];
8971
8999
  }
8972
- return [to, false];
9000
+ return [pair.avalue, false];
8973
9001
  }
8974
9002
  case 2048 /* TypeTag.Method */: {
8975
- const ameth = to;
8976
- const bmeth = from;
8977
- if (ameth.args.length != bmeth.args.length)
9003
+ if (pair.avalue.args.length !== pair.bvalue.args.length)
8978
9004
  return [null, true];
8979
- const resultChange = tryUnion(ameth.result, bmeth.result);
8980
- const args = ameth.args.map((arg, i) => intersection(arg, bmeth.args[i]));
9005
+ const resultChange = tryUnion(pair.avalue.result, pair.bvalue.result);
9006
+ const args = pair.avalue.args.map((arg, i) => intersection(arg, pair.bvalue.args[i]));
8981
9007
  if (args.some((arg) => arg.type === 0 /* TypeTag.Never */)) {
8982
9008
  return [null, true];
8983
9009
  }
8984
- const argsChanged = args.some((arg, i) => !subtypeOf(ameth.args[i], arg));
9010
+ const argsChanged = args.some((arg, i) => !subtypeOf(pair.avalue.args[i], arg));
8985
9011
  if (resultChange || argsChanged) {
8986
- return [{ result: resultChange || ameth.result, args }, true];
9012
+ return [{ result: resultChange || pair.avalue.result, args }, true];
8987
9013
  }
8988
- return [to, false];
9014
+ return [pair.avalue, false];
8989
9015
  }
8990
9016
  case 4096 /* TypeTag.Module */:
9017
+ return mergeStateDecls(pair.avalue, pair.bvalue);
8991
9018
  case 8192 /* TypeTag.Function */:
9019
+ return mergeStateDecls(pair.avalue, pair.bvalue);
8992
9020
  case 16384 /* TypeTag.Class */:
9021
+ return mergeStateDecls(pair.avalue, pair.bvalue);
8993
9022
  case 262144 /* TypeTag.Typedef */:
8994
- return mergeStateDecls(to, from);
9023
+ return mergeStateDecls(pair.avalue, pair.bvalue);
8995
9024
  case 32768 /* TypeTag.Object */: {
8996
- let klass = to.klass;
8997
- const [obj, objChanged] = mergeObjectValues(to.obj, from.obj);
8998
- const klassChanged = tryUnion(klass, from.klass);
9025
+ let klass = pair.avalue.klass;
9026
+ const [obj, objChanged] = mergeObjectValues(pair.avalue.obj, pair.bvalue.obj);
9027
+ const klassChanged = tryUnion(klass, pair.bvalue.klass);
8999
9028
  if (klassChanged || objChanged) {
9000
9029
  klass = (klassChanged || klass);
9001
9030
  if (obj) {
@@ -9003,11 +9032,11 @@ function mergeSingle(type, to, from) {
9003
9032
  }
9004
9033
  return [{ klass }, true];
9005
9034
  }
9006
- return [to, false];
9035
+ return [pair.avalue, false];
9007
9036
  }
9008
9037
  case 65536 /* TypeTag.Enum */: {
9009
- const toE = to;
9010
- const fromE = from;
9038
+ const toE = pair.avalue;
9039
+ const fromE = pair.bvalue;
9011
9040
  if (toE.enum !== fromE.enum) {
9012
9041
  return [null, true];
9013
9042
  }
@@ -9026,9 +9055,8 @@ function mergeSingle(type, to, from) {
9026
9055
  return [toE, false];
9027
9056
  }
9028
9057
  default:
9029
- unhandledType(type);
9058
+ unhandledType(pair);
9030
9059
  }
9031
- throw new Error(`Unexpected type ${type}`);
9032
9060
  }
9033
9061
  function mergeObjectValues(to, from) {
9034
9062
  if (!to) {
@@ -9172,22 +9200,22 @@ function clearValuesUnder(v, tag, clearTag = false) {
9172
9200
  }
9173
9201
  function widenTypeHelper(t, depth) {
9174
9202
  let result = null;
9175
- forEachUnionComponent(t, t.type & (512 /* TypeTag.Array */ | 1024 /* TypeTag.Dictionary */), (tag, value) => {
9176
- if (!value)
9203
+ forEachUnionComponent(t, t.type & (512 /* TypeTag.Array */ | 1024 /* TypeTag.Dictionary */), (ac) => {
9204
+ if (ac.value == null)
9177
9205
  return;
9178
- switch (tag) {
9206
+ switch (ac.type) {
9179
9207
  case 512 /* TypeTag.Array */:
9180
9208
  if (depth > 4) {
9181
9209
  if (!result)
9182
9210
  result = cloneType(t);
9183
- clearValuesUnder(result, tag);
9211
+ clearValuesUnder(result, ac.type);
9184
9212
  }
9185
9213
  else {
9186
- const v = widenTypeHelper(value, depth + 1);
9214
+ const v = widenTypeHelper(ac.value, depth + 1);
9187
9215
  if (v) {
9188
9216
  if (!result)
9189
9217
  result = cloneType(t);
9190
- setUnionComponent(result, tag, v);
9218
+ setUnionComponent(result, ac.type, v);
9191
9219
  }
9192
9220
  }
9193
9221
  return;
@@ -9195,10 +9223,10 @@ function widenTypeHelper(t, depth) {
9195
9223
  if (depth > 4) {
9196
9224
  if (!result)
9197
9225
  result = cloneType(t);
9198
- clearValuesUnder(result, tag);
9226
+ clearValuesUnder(result, ac.type);
9199
9227
  }
9200
9228
  else {
9201
- const ddata = value;
9229
+ const ddata = ac.value;
9202
9230
  const key = widenTypeHelper(ddata.key, depth + 1);
9203
9231
  const data = widenTypeHelper(ddata.value, depth + 1);
9204
9232
  if (key || data) {
@@ -9209,7 +9237,7 @@ function widenTypeHelper(t, depth) {
9209
9237
  newDData.key = key;
9210
9238
  if (data)
9211
9239
  newDData.value = data;
9212
- setUnionComponent(result, tag, newDData);
9240
+ setUnionComponent(result, ac.type, newDData);
9213
9241
  }
9214
9242
  }
9215
9243
  return;
@@ -9327,7 +9355,7 @@ function hasNoData(v, t) {
9327
9355
  return true;
9328
9356
  return ((hasUnionData(v.type)
9329
9357
  ? v.value.mask & t
9330
- : v.type & t & ~SingleTonTypeTagsConst) == 0);
9358
+ : v.type & t & ~SingleTonTypeTagsConst) === 0);
9331
9359
  }
9332
9360
  function lookupByFullName(state, fullName) {
9333
9361
  return fullName.split(".").reduce((results, part) => {
@@ -9742,7 +9770,7 @@ function castType(type, target) {
9742
9770
  // Number or Long operands to '&', '|', and '^' are coerced
9743
9771
  // to boolean if the other argument is boolean.
9744
9772
  if (type.type & (8 /* TypeTag.Number */ | 16 /* TypeTag.Long */)) {
9745
- result.type = type.value == 0 ? 2 /* TypeTag.False */ : 4 /* TypeTag.True */;
9773
+ result.type = Number(type.value) === 0 ? 2 /* TypeTag.False */ : 4 /* TypeTag.True */;
9746
9774
  return result;
9747
9775
  }
9748
9776
  }
@@ -9760,15 +9788,15 @@ const TruthyTypes = 4 /* TypeTag.True */ |
9760
9788
  function mustBeTrue(arg) {
9761
9789
  return (((arg.type === 8 /* TypeTag.Number */ || arg.type === 16 /* TypeTag.Long */) &&
9762
9790
  arg.value != null &&
9763
- arg.value != 0) ||
9764
- ((arg.type & TruthyTypes) != 0 && (arg.type & ~TruthyTypes) == 0));
9791
+ Number(arg.value) !== 0) ||
9792
+ ((arg.type & TruthyTypes) !== 0 && (arg.type & ~TruthyTypes) === 0));
9765
9793
  }
9766
9794
  function mustBeFalse(arg) {
9767
9795
  return (arg.type === 1 /* TypeTag.Null */ ||
9768
9796
  arg.type === 2 /* TypeTag.False */ ||
9769
9797
  ((arg.type === 8 /* TypeTag.Number */ || arg.type === 16 /* TypeTag.Long */) &&
9770
9798
  arg.value != null &&
9771
- arg.value == 0));
9799
+ Number(arg.value) === 0));
9772
9800
  }
9773
9801
  function display(type) {
9774
9802
  const names = (v, fn) => (0,external_util_cjs_namespaceObject.map)(v, fn)
@@ -9869,7 +9897,7 @@ function display(type) {
9869
9897
  }
9870
9898
  function hasUnionData(tag) {
9871
9899
  tag &= UnionDataTypeTagsConst;
9872
- return (tag & (tag - 1)) != 0;
9900
+ return (tag & (tag - 1)) !== 0;
9873
9901
  }
9874
9902
  function getObjectValue(t) {
9875
9903
  if (!(t.type & 32768 /* TypeTag.Object */) || t.value == null)
@@ -9903,7 +9931,7 @@ function forEachUnionComponent(v, bits, fn) {
9903
9931
  : bit & v.type
9904
9932
  ? v.value
9905
9933
  : null;
9906
- if (fn(bit, data) === false)
9934
+ if (fn({ type: bit, value: data }) === false)
9907
9935
  break;
9908
9936
  bits = next;
9909
9937
  } while (bits);
@@ -9945,27 +9973,30 @@ function getStateNodeDeclsFromType(state, object) {
9945
9973
  const decls = [];
9946
9974
  if (object.value != null &&
9947
9975
  object.type & (4096 /* TypeTag.Module */ | 16384 /* TypeTag.Class */ | 32768 /* TypeTag.Object */)) {
9948
- forEachUnionComponent(object, object.type & (4096 /* TypeTag.Module */ | 16384 /* TypeTag.Class */ | 32768 /* TypeTag.Object */), (tag, value) => {
9949
- if (!value)
9976
+ forEachUnionComponent(object, object.type & (4096 /* TypeTag.Module */ | 16384 /* TypeTag.Class */ | 32768 /* TypeTag.Object */), (type) => {
9977
+ if (type.value == null)
9950
9978
  return;
9951
- if (tag === 32768 /* TypeTag.Object */) {
9952
- const ovalue = value;
9953
- if (ovalue.klass.type === 16384 /* TypeTag.Class */ && ovalue.klass.value) {
9954
- if (Array.isArray(ovalue.klass.value)) {
9955
- decls.push(...ovalue.klass.value);
9979
+ switch (type.type) {
9980
+ case 32768 /* TypeTag.Object */:
9981
+ if (type.value.klass.type === 16384 /* TypeTag.Class */ &&
9982
+ type.value.klass.value) {
9983
+ if (Array.isArray(type.value.klass.value)) {
9984
+ decls.push(...type.value.klass.value);
9985
+ }
9986
+ else {
9987
+ decls.push(type.value.klass.value);
9988
+ }
9989
+ }
9990
+ break;
9991
+ case 4096 /* TypeTag.Module */:
9992
+ case 16384 /* TypeTag.Class */:
9993
+ if (Array.isArray(type.value)) {
9994
+ decls.push(...type.value);
9956
9995
  }
9957
9996
  else {
9958
- decls.push(ovalue.klass.value);
9997
+ decls.push(type.value);
9959
9998
  }
9960
- }
9961
- }
9962
- else {
9963
- if (Array.isArray(value)) {
9964
- decls.push(...value);
9965
- }
9966
- else {
9967
- decls.push(value);
9968
- }
9999
+ break;
9969
10000
  }
9970
10001
  });
9971
10002
  }
@@ -10014,15 +10045,15 @@ function couldBe(a, b) {
10014
10045
  return true;
10015
10046
  }
10016
10047
  let result = false;
10017
- forEachUnionComponent(a, common, (bit, avalue) => {
10018
- if (avalue == null) {
10048
+ forEachUnionComponent(a, common, (ac) => {
10049
+ if (ac.value == null) {
10019
10050
  result = true;
10020
10051
  return false;
10021
10052
  }
10022
- const bvalue = getUnionComponent(b, bit);
10053
+ const bvalue = getUnionComponent(b, ac.type);
10023
10054
  if (bvalue == null ||
10024
- avalue === bvalue ||
10025
- couldBeValue(bit, avalue, bvalue)) {
10055
+ ac.value === bvalue ||
10056
+ couldBeValue({ type: ac.type, avalue: ac.value, bvalue })) {
10026
10057
  result = true;
10027
10058
  return false;
10028
10059
  }
@@ -10077,13 +10108,13 @@ function couldBeWeak(a, b) {
10077
10108
  return true;
10078
10109
  return couldBe(a, b);
10079
10110
  }
10080
- function couldBeValue(bit, avalue, bvalue) {
10081
- switch (bit) {
10111
+ function couldBeValue(pair) {
10112
+ switch (pair.type) {
10082
10113
  case 1 /* TypeTag.Null */:
10083
10114
  case 2 /* TypeTag.False */:
10084
10115
  case 4 /* TypeTag.True */:
10085
10116
  case 262144 /* TypeTag.Typedef */:
10086
- throw new Error(`Unexpected TypeTag '${typeTagName(bit)}'`);
10117
+ throw new Error(`Unexpected TypeTag '${typeTagName(pair.type)}'`);
10087
10118
  case 8 /* TypeTag.Number */:
10088
10119
  case 16 /* TypeTag.Long */:
10089
10120
  case 32 /* TypeTag.Float */:
@@ -10091,34 +10122,27 @@ function couldBeValue(bit, avalue, bvalue) {
10091
10122
  case 256 /* TypeTag.String */:
10092
10123
  case 128 /* TypeTag.Char */:
10093
10124
  case 131072 /* TypeTag.Symbol */:
10094
- return avalue === bvalue;
10125
+ return pair.avalue === pair.bvalue;
10095
10126
  case 512 /* TypeTag.Array */:
10096
- return couldBe(avalue, bvalue);
10127
+ return couldBe(pair.avalue, pair.bvalue);
10097
10128
  case 1024 /* TypeTag.Dictionary */: {
10098
- const adict = avalue;
10099
- const bdict = bvalue;
10100
- return couldBe(adict.key, bdict.key) && couldBe(adict.value, bdict.value);
10129
+ return (couldBe(pair.avalue.key, pair.bvalue.key) &&
10130
+ couldBe(pair.avalue.value, pair.bvalue.value));
10101
10131
  }
10102
10132
  case 2048 /* TypeTag.Method */: {
10103
- const ameth = avalue;
10104
- const bmeth = bvalue;
10105
- return (ameth.args.length === bmeth.args.length &&
10106
- couldBe(ameth.result, bmeth.result) &&
10107
- ameth.args.every((arg, i) => couldBe(arg, bmeth.args[i])));
10133
+ return (pair.avalue.args.length === pair.bvalue.args.length &&
10134
+ couldBe(pair.avalue.result, pair.bvalue.result) &&
10135
+ pair.avalue.args.every((arg, i) => couldBe(arg, pair.bvalue.args[i])));
10108
10136
  }
10109
10137
  case 4096 /* TypeTag.Module */:
10110
10138
  case 8192 /* TypeTag.Function */: {
10111
- const asd = avalue;
10112
- const bsd = bvalue;
10113
10139
  // quadratic :-(
10114
- return (0,external_util_cjs_namespaceObject.some)(asd, (sna) => (0,external_util_cjs_namespaceObject.some)(bsd, (snb) => sna === snb));
10140
+ return (0,external_util_cjs_namespaceObject.some)(pair.avalue, (sna) => (0,external_util_cjs_namespaceObject.some)(pair.bvalue, (snb) => sna === snb));
10115
10141
  }
10116
10142
  case 16384 /* TypeTag.Class */: {
10117
- const asd = avalue;
10118
- const bsd = bvalue;
10119
- return (0,external_util_cjs_namespaceObject.some)(asd, (sna) => {
10143
+ return (0,external_util_cjs_namespaceObject.some)(pair.avalue, (sna) => {
10120
10144
  const superA = (0,external_api_cjs_namespaceObject.getSuperClasses)(sna);
10121
- return (0,external_util_cjs_namespaceObject.some)(bsd, (snb) => {
10145
+ return (0,external_util_cjs_namespaceObject.some)(pair.bvalue, (snb) => {
10122
10146
  if (sna === snb || (superA && superA.has(snb))) {
10123
10147
  return true;
10124
10148
  }
@@ -10128,18 +10152,17 @@ function couldBeValue(bit, avalue, bvalue) {
10128
10152
  });
10129
10153
  }
10130
10154
  case 32768 /* TypeTag.Object */: {
10131
- const aobj = avalue;
10132
- const bobj = bvalue;
10133
- return couldBe(aobj.klass, bobj.klass) && couldBeObj(aobj.obj, bobj.obj);
10155
+ return (couldBe(pair.avalue.klass, pair.bvalue.klass) &&
10156
+ couldBeObj(pair.avalue.obj, pair.bvalue.obj));
10134
10157
  }
10135
10158
  case 65536 /* TypeTag.Enum */: {
10136
- const aenum = avalue;
10137
- const benum = bvalue;
10138
- return (aenum.enum === benum.enum &&
10139
- (!aenum.value || !benum.value || couldBe(aenum.value, benum.value)));
10159
+ return (pair.avalue.enum === pair.bvalue.enum &&
10160
+ (!pair.avalue.value ||
10161
+ !pair.bvalue.value ||
10162
+ couldBe(pair.avalue.value, pair.bvalue.value)));
10140
10163
  }
10141
10164
  default:
10142
- unhandledType(bit);
10165
+ unhandledType(pair);
10143
10166
  }
10144
10167
  }
10145
10168
  function couldBeObj(a, b) {
@@ -10255,16 +10278,17 @@ function equalsCheck(left, right) {
10255
10278
  // Note that each type can only have a single bit set. This is important!
10256
10279
  const lrBits = left.type | right.type;
10257
10280
  return left.type & 120 /* TypeTag.Numeric */ && right.type & 120 /* TypeTag.Numeric */
10258
- ? left.value == right.value
10259
- : lrBits == (8 /* TypeTag.Number */ | 128 /* TypeTag.Char */)
10281
+ ? // eslint-disable-next-line eqeqeq
10282
+ left.value == right.value
10283
+ : lrBits === (8 /* TypeTag.Number */ | 128 /* TypeTag.Char */)
10260
10284
  ? // Char vs Number is true iff the number is the char-code of the char
10261
10285
  left.type === 128 /* TypeTag.Char */
10262
10286
  ? left.value.charCodeAt(0) === right.value
10263
10287
  : left.value === right.value.charCodeAt(0)
10264
- : left.type == 8 /* TypeTag.Number */ && right.type & 6 /* TypeTag.Boolean */
10265
- ? left.value == (right.value ? 1 : 0)
10266
- : right.type == 8 /* TypeTag.Number */ && left.type & 6 /* TypeTag.Boolean */
10267
- ? right.value == (left.value ? 1 : 0)
10288
+ : left.type === 8 /* TypeTag.Number */ && right.type & 6 /* TypeTag.Boolean */
10289
+ ? left.value === (right.value ? 1 : 0)
10290
+ : right.type === 8 /* TypeTag.Number */ && left.type & 6 /* TypeTag.Boolean */
10291
+ ? right.value === (left.value ? 1 : 0)
10268
10292
  : left.type !== right.type
10269
10293
  ? lrBits & 1 /* TypeTag.Null */
10270
10294
  ? lrBits & (32768 /* TypeTag.Object */ | 512 /* TypeTag.Array */ | 1024 /* TypeTag.Dictionary */)
@@ -10330,7 +10354,7 @@ function evaluateBinaryTypes(op, left, right) {
10330
10354
  "/": {
10331
10355
  allowed: 8 /* TypeTag.Number */ | 16 /* TypeTag.Long */ | 32 /* TypeTag.Float */ | 64 /* TypeTag.Double */,
10332
10356
  typeFn: common_types,
10333
- valueFn: (left, right) => right.value == 0 // "==" because it could be a bigint
10357
+ valueFn: (left, right) => Number(right.value) === 0
10334
10358
  ? { type: left.type }
10335
10359
  : left.type === 8 /* TypeTag.Number */
10336
10360
  ? {
@@ -10345,7 +10369,7 @@ function evaluateBinaryTypes(op, left, right) {
10345
10369
  "%": {
10346
10370
  allowed: 8 /* TypeTag.Number */ | 16 /* TypeTag.Long */,
10347
10371
  typeFn: common_types,
10348
- valueFn: (left, right) => right.value == 0 // "==" because it could be a bigint
10372
+ valueFn: (left, right) => Number(right.value) === 0
10349
10373
  ? { type: left.type }
10350
10374
  : {
10351
10375
  type: left.type,
@@ -11179,7 +11203,7 @@ function getLhsConstraint(istate, node) {
11179
11203
  }
11180
11204
  const object = istate.typeMap.get(node.object);
11181
11205
  if (object && !node.computed) {
11182
- const objDecls = findObjectDeclsByProperty(istate, object, node);
11206
+ const objDecls = findObjectDeclsByProperty(istate.state, object, node);
11183
11207
  if (objDecls) {
11184
11208
  lookupDefs = (0,external_api_cjs_namespaceObject.lookupNext)(istate.state, [{ parent: null, results: objDecls }], "decls", node.property);
11185
11209
  }
@@ -11242,6 +11266,17 @@ function pushScopedNameType(istate, node, object) {
11242
11266
  node,
11243
11267
  });
11244
11268
  }
11269
+ function byteArrayType(state) {
11270
+ return {
11271
+ type: 32768 /* TypeTag.Object */,
11272
+ value: {
11273
+ klass: {
11274
+ type: 16384 /* TypeTag.Class */,
11275
+ value: lookupByFullName(state, "Toybox.Lang.ByteArray"),
11276
+ },
11277
+ },
11278
+ };
11279
+ }
11245
11280
  function evaluateNode(istate, node) {
11246
11281
  const { state, stack } = istate;
11247
11282
  const push = (item) => {
@@ -11268,7 +11303,9 @@ function evaluateNode(istate, node) {
11268
11303
  // garmin's type checker.
11269
11304
  if (subtypeOf(left.value, right.value) &&
11270
11305
  !subtypeOf({ type: 1 /* TypeTag.Null */ | 32768 /* TypeTag.Object */ }, right.value) &&
11271
- (!(left.value.type & 65536 /* TypeTag.Enum */) || right.value.type & 65536 /* TypeTag.Enum */)) {
11306
+ (!(left.value.type & 65536 /* TypeTag.Enum */) ||
11307
+ right.value.type & 65536 /* TypeTag.Enum */) &&
11308
+ !couldBe({ type: 512 /* TypeTag.Array */ | 1024 /* TypeTag.Dictionary */ }, left.value)) {
11272
11309
  push({
11273
11310
  value: left.value,
11274
11311
  embeddedEffects: left.embeddedEffects,
@@ -11280,7 +11317,7 @@ function evaluateNode(istate, node) {
11280
11317
  (0,external_api_cjs_namespaceObject.diagnostic)(istate.state, node, `The type ${display(left.value)} cannot be converted to ${display(right.value)} because they have nothing in common`, istate.checkTypes);
11281
11318
  }
11282
11319
  if (hasValue(right.value) && right.value.type === 65536 /* TypeTag.Enum */) {
11283
- if ((left.value.type & EnumTagsConst) == left.value.type) {
11320
+ if ((left.value.type & EnumTagsConst) === left.value.type) {
11284
11321
  const result = cloneType(right.value);
11285
11322
  result.value = { ...result.value, value: left.value };
11286
11323
  stack.push({
@@ -11299,7 +11336,7 @@ function evaluateNode(istate, node) {
11299
11336
  }
11300
11337
  else {
11301
11338
  if (istate.checkTypes &&
11302
- (node.operator === "==" || node.operator == "!=") &&
11339
+ (node.operator === "==" || node.operator === "!=") &&
11303
11340
  ((left.value.type === 1 /* TypeTag.Null */ &&
11304
11341
  !(right.value.type & 1 /* TypeTag.Null */)) ||
11305
11342
  (right.value.type === 1 /* TypeTag.Null */ &&
@@ -11339,7 +11376,10 @@ function evaluateNode(istate, node) {
11339
11376
  case "SizedArrayExpression": {
11340
11377
  const arg = popIstate(istate, node.size);
11341
11378
  let type = { type: 512 /* TypeTag.Array */ };
11342
- if (node.ts) {
11379
+ if (node.byte) {
11380
+ type = byteArrayType(state);
11381
+ }
11382
+ else if (node.ts) {
11343
11383
  type = typeFromSingleTypeSpec(istate.state, node.ts);
11344
11384
  if (type.type !== 512 /* TypeTag.Array */) {
11345
11385
  type = { type: 512 /* TypeTag.Array */, value: type };
@@ -11359,15 +11399,7 @@ function evaluateNode(istate, node) {
11359
11399
  const embeddedEffects = args.some((arg) => arg.embeddedEffects);
11360
11400
  if (node.byte) {
11361
11401
  push({
11362
- value: {
11363
- type: 32768 /* TypeTag.Object */,
11364
- value: {
11365
- klass: {
11366
- type: 16384 /* TypeTag.Class */,
11367
- value: lookupByFullName(state, "Toybox.Lang.ByteArray"),
11368
- },
11369
- },
11370
- },
11402
+ value: byteArrayType(state),
11371
11403
  embeddedEffects,
11372
11404
  node,
11373
11405
  });
@@ -11551,6 +11583,13 @@ function evaluateNode(istate, node) {
11551
11583
  node,
11552
11584
  });
11553
11585
  }
11586
+ else {
11587
+ push({
11588
+ value: { type: 1 /* TypeTag.Null */ },
11589
+ embeddedEffects: false,
11590
+ node,
11591
+ });
11592
+ }
11554
11593
  break;
11555
11594
  }
11556
11595
  case "AssignmentExpression": {
@@ -11869,7 +11908,7 @@ function getEquivSet(ts, k) {
11869
11908
  }
11870
11909
  keys.add(s);
11871
11910
  s = next.equivSet.next;
11872
- } while (s != k);
11911
+ } while (s !== k);
11873
11912
  return keys;
11874
11913
  }
11875
11914
  function intersectEquiv(ts1, ts2, k) {
@@ -11894,7 +11933,7 @@ function intersectEquiv(ts1, ts2, k) {
11894
11933
  removeEquiv(ts1, s);
11895
11934
  }
11896
11935
  s = next.equivSet.next;
11897
- } while (s != k);
11936
+ } while (s !== k);
11898
11937
  return ret;
11899
11938
  }
11900
11939
  function mergeTypeState(blockStates, blockVisits, index, from) {
@@ -11954,7 +11993,7 @@ function tsEquivs(state, key) {
11954
11993
  throw new Error(`Inconsistent equivSet for ${tsKey(key)}: missing value for ${tsKey(s)}`);
11955
11994
  }
11956
11995
  s = next.equivSet.next;
11957
- } while (s != key);
11996
+ } while (s !== key);
11958
11997
  return `[(${result.join(", ")})]`;
11959
11998
  }
11960
11999
  function typeStateEntry(value, key) {
@@ -12002,12 +12041,12 @@ function filterDecls(decls, possible) {
12002
12041
  return cur;
12003
12042
  }, null);
12004
12043
  }
12005
- function findObjectDeclsByProperty(istate, object, next) {
12006
- const decls = getStateNodeDeclsFromType(istate.state, object);
12044
+ function findObjectDeclsByProperty(state, object, next) {
12045
+ const decls = getStateNodeDeclsFromType(state, object);
12007
12046
  if (!decls)
12008
12047
  return null;
12009
- const possibleDecls = (0,external_api_cjs_namespaceObject.hasProperty)(istate.state.allDeclarations, next.property.name) &&
12010
- istate.state.allDeclarations[next.property.name];
12048
+ const possibleDecls = (0,external_api_cjs_namespaceObject.hasProperty)(state.allDeclarations, next.property.name) &&
12049
+ state.allDeclarations[next.property.name];
12011
12050
  return filterDecls(decls, possibleDecls);
12012
12051
  }
12013
12052
  function refineObjectTypeByDecls(istate, object, trueDecls) {
@@ -12024,7 +12063,7 @@ function findNextObjectType(istate, trueDecls, next) {
12024
12063
  }, { type: 0 /* TypeTag.Never */ });
12025
12064
  }
12026
12065
  function resolveDottedMember(istate, object, next) {
12027
- const decls = findObjectDeclsByProperty(istate, object, next);
12066
+ const decls = findObjectDeclsByProperty(istate.state, object, next);
12028
12067
  if (!decls)
12029
12068
  return null;
12030
12069
  const property = findNextObjectType(istate, decls, next);
@@ -12067,9 +12106,8 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, logThisRun) {
12067
12106
  next = value.obj[me.property.name];
12068
12107
  }
12069
12108
  else {
12070
- const trueDecls = findObjectDeclsByProperty(istate, cur, me);
12071
- if (!trueDecls ||
12072
- (0,external_util_cjs_namespaceObject.some)(trueDecls, (decl) => decl.type !== "ClassDeclaration")) {
12109
+ const trueDecls = findObjectDeclsByProperty(istate.state, cur, me);
12110
+ if (!trueDecls) {
12073
12111
  return null;
12074
12112
  }
12075
12113
  cur = refineObjectTypeByDecls(istate, cur, trueDecls);
@@ -12389,10 +12427,10 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, logThisRun) {
12389
12427
  type: 32768 /* TypeTag.Object */,
12390
12428
  value: leftValue,
12391
12429
  });
12392
- const leftReduced = leftDecls.filter((ldec) => !rightDecls.every((rdec) => ldec == rdec ||
12430
+ const leftReduced = leftDecls.filter((ldec) => !rightDecls.every((rdec) => ldec === rdec ||
12393
12431
  (ldec.type === "ClassDeclaration" &&
12394
12432
  (0,external_api_cjs_namespaceObject.getSuperClasses)(ldec)?.has(rdec))));
12395
- if (leftReduced.length != leftDecls.length) {
12433
+ if (leftReduced.length !== leftDecls.length) {
12396
12434
  result = cloneType(left);
12397
12435
  clearValuesUnder(result, 32768 /* TypeTag.Object */, true);
12398
12436
  if (leftReduced.length) {
@@ -13033,7 +13071,15 @@ function beforeEvaluate(istate, node) {
13033
13071
  break;
13034
13072
  }
13035
13073
  case "ForStatement": {
13036
- if (node.init?.type === "Literal") {
13074
+ if (node.update?.type === "Literal" ||
13075
+ (node.update?.type === "SequenceExpression" &&
13076
+ node.update.expressions.length === 0)) {
13077
+ popIstate(istate, node.update);
13078
+ delete node.update;
13079
+ }
13080
+ if (node.init?.type === "Literal" ||
13081
+ (node.init?.type === "SequenceExpression" &&
13082
+ node.init.expressions.length === 0)) {
13037
13083
  delete node.init;
13038
13084
  const depth = -1 - (node.update ? 1 : 0) - (node.test ? 1 : 0);
13039
13085
  istate.stack.splice(depth, 1);
@@ -13057,7 +13103,7 @@ function beforeEvaluate(istate, node) {
13057
13103
  for (let i = node.expressions.length; i--;) {
13058
13104
  const expr = node.expressions[i];
13059
13105
  if (expr.type === "Literal") {
13060
- istate.stack.splice(i - node.expressions.length);
13106
+ istate.stack.splice(i - node.expressions.length, 1);
13061
13107
  node.expressions.splice(i, 1);
13062
13108
  }
13063
13109
  }
@@ -13411,7 +13457,7 @@ function cleanupUnusedVars(state, node) {
13411
13457
  if (parent.node !== node) {
13412
13458
  return false;
13413
13459
  }
13414
- if (parent.type != "BlockStatement") {
13460
+ if (parent.type !== "BlockStatement") {
13415
13461
  throw new Error(`Unexpected parent type '${parent.type}' for local declaration`);
13416
13462
  }
13417
13463
  if (!parent.decls)
@@ -13767,14 +13813,14 @@ async function analyze(fnMap, resourcesMap, manifestXML, config) {
13767
13813
  const excludeAnnotations = fnMap[node.loc.source].excludeAnnotations;
13768
13814
  if (excludeAnnotations) {
13769
13815
  return node.attrs.attributes.elements.reduce((drop, attr) => {
13770
- if (attr.type != "UnaryExpression")
13816
+ if (attr.type !== "UnaryExpression")
13771
13817
  return drop;
13772
- if (attr.argument.type != "Identifier")
13818
+ if (attr.argument.type !== "Identifier")
13773
13819
  return drop;
13774
13820
  if ((0,external_api_cjs_namespaceObject.hasProperty)(excludeAnnotations, attr.argument.name)) {
13775
13821
  return true;
13776
13822
  }
13777
- if (attr.argument.name == "test") {
13823
+ if (attr.argument.name === "test") {
13778
13824
  hasTests = true;
13779
13825
  }
13780
13826
  return drop;
@@ -13790,7 +13836,7 @@ async function analyze(fnMap, resourcesMap, manifestXML, config) {
13790
13836
  case "ClassDeclaration": {
13791
13837
  const [scope] = state.stack.slice(-1);
13792
13838
  scope.stack = state.stackClone().slice(0, -1);
13793
- if (scope.type == "FunctionDeclaration") {
13839
+ if (scope.type === "FunctionDeclaration") {
13794
13840
  if (markApi) {
13795
13841
  node.body = null;
13796
13842
  scope.info = (0,external_api_cjs_namespaceObject.getApiFunctionInfo)(state, scope);
@@ -13956,7 +14002,7 @@ function optimizeNode(istate, node) {
13956
14002
  function evaluateFunction(istate, func, args) {
13957
14003
  if (!func.body ||
13958
14004
  istate.state.inlining ||
13959
- (args && args.length != func.params.length)) {
14005
+ (args && args.length !== func.params.length)) {
13960
14006
  return false;
13961
14007
  }
13962
14008
  const paramValues = args &&
@@ -14051,11 +14097,11 @@ async function optimizeMonkeyC(fnMap, resourcesMap, manifestXML, config) {
14051
14097
  if (func.attrs &&
14052
14098
  func.attrs.attributes &&
14053
14099
  func.attrs.attributes.elements.some((attr) => {
14054
- if (attr.type != "UnaryExpression")
14100
+ if (attr.type !== "UnaryExpression")
14055
14101
  return false;
14056
- if (attr.argument.type != "Identifier")
14102
+ if (attr.argument.type !== "Identifier")
14057
14103
  return false;
14058
- return attr.argument.name == "test";
14104
+ return attr.argument.name === "test";
14059
14105
  })) {
14060
14106
  return true;
14061
14107
  }
@@ -14072,7 +14118,7 @@ async function optimizeMonkeyC(fnMap, resourcesMap, manifestXML, config) {
14072
14118
  (elm.superClass != null &&
14073
14119
  elm.superClass.some((sc) => ((0,external_api_cjs_namespaceObject.hasProperty)(sc.decls, name) &&
14074
14120
  sc.decls[name].some((f) => (0,external_api_cjs_namespaceObject.isStateNode)(f) &&
14075
- f.type == "FunctionDeclaration" &&
14121
+ f.type === "FunctionDeclaration" &&
14076
14122
  maybeCalled(f.node))) ||
14077
14123
  (sc.superClass && checkInherited(sc, name))));
14078
14124
  const renamer = (idnode) => {
@@ -14255,7 +14301,7 @@ async function optimizeMonkeyC(fnMap, resourcesMap, manifestXML, config) {
14255
14301
  }
14256
14302
  state.currentFunction = self;
14257
14303
  const is = !state.config?.propagateTypes ||
14258
- node.attrs?.attributes?.elements.find((attr) => attr.type == "UnaryExpression" &&
14304
+ node.attrs?.attributes?.elements.find((attr) => attr.type === "UnaryExpression" &&
14259
14305
  attr.argument.name === "noConstProp")
14260
14306
  ? null
14261
14307
  : type_flow_buildTypeInfo(state, state.currentFunction, true);
@@ -14276,9 +14322,9 @@ async function optimizeMonkeyC(fnMap, resourcesMap, manifestXML, config) {
14276
14322
  }
14277
14323
  istate = is;
14278
14324
  }
14279
- if (parent.type == "ClassDeclaration" && !maybeCalled(node)) {
14325
+ if (parent.type === "ClassDeclaration" && !maybeCalled(node)) {
14280
14326
  let used = false;
14281
- if (node.id.name == "initialize") {
14327
+ if (node.id.name === "initialize") {
14282
14328
  used = true;
14283
14329
  }
14284
14330
  else if (parent.superClass) {
@@ -14395,7 +14441,7 @@ async function optimizeMonkeyC(fnMap, resourcesMap, manifestXML, config) {
14395
14441
  const inlined = optimizeCallHelper(istate, call, decl);
14396
14442
  if (!inlined)
14397
14443
  continue;
14398
- if (Array.isArray(inlined) || inlined.type != "BlockStatement") {
14444
+ if (Array.isArray(inlined) || inlined.type !== "BlockStatement") {
14399
14445
  throw new Error("Unexpected inlined result");
14400
14446
  }
14401
14447
  if (!results) {
@@ -14435,7 +14481,7 @@ async function optimizeMonkeyC(fnMap, resourcesMap, manifestXML, config) {
14435
14481
  ok = true;
14436
14482
  }
14437
14483
  }
14438
- if (!ok && node.expression.operator == "=") {
14484
+ if (!ok && node.expression.operator === "=") {
14439
14485
  const [, result] = state.lookup(node.expression.left);
14440
14486
  ok = !!result;
14441
14487
  }
@@ -14588,6 +14634,22 @@ async function optimizeMonkeyC(fnMap, resourcesMap, manifestXML, config) {
14588
14634
  });
14589
14635
  });
14590
14636
  reportMissingSymbols(state, config);
14637
+ if (state.inlineDiagnostics) {
14638
+ if (!state.diagnostics) {
14639
+ state.diagnostics = state.inlineDiagnostics;
14640
+ }
14641
+ else {
14642
+ Object.entries(state.inlineDiagnostics).forEach(([key, diags]) => {
14643
+ if (!(0,external_api_cjs_namespaceObject.hasProperty)(state.diagnostics, key)) {
14644
+ state.diagnostics[key] = diags;
14645
+ }
14646
+ else {
14647
+ state.diagnostics[key].push(...diags);
14648
+ }
14649
+ });
14650
+ }
14651
+ delete state.inlineDiagnostics;
14652
+ }
14591
14653
  Object.entries(fnMap).forEach(([name, f]) => {
14592
14654
  if (state.config && state.config.checkBuildPragmas) {
14593
14655
  pragmaChecker(state, f.ast, state.diagnostics?.[name]);
@@ -14625,7 +14687,7 @@ function optimizeCall(istate, node, context) {
14625
14687
  if (state.currentFunction) {
14626
14688
  recordCalledFuncs(state.currentFunction, callees);
14627
14689
  }
14628
- if (callees.length == 1 && callees[0].type === "FunctionDeclaration") {
14690
+ if (callees.length === 1 && callees[0].type === "FunctionDeclaration") {
14629
14691
  const callee = callees[0].node;
14630
14692
  if (!context &&
14631
14693
  callee.optimizable &&
@@ -14826,7 +14888,7 @@ async function createLocalBarrels(targets, options) {
14826
14888
  }
14827
14889
  if (optBarrels[barrel].manifest !== manifest ||
14828
14890
  optBarrels[barrel].optBarrelDir !== optBarrelDir ||
14829
- optBarrels[barrel].rawBarrelDir != rawBarrelDir) {
14891
+ optBarrels[barrel].rawBarrelDir !== rawBarrelDir) {
14830
14892
  throw new Error(`For device ${target.product}, barrel ${barrel} was mapped to both ${external_path_.relative(optBarrels[barrel].rawBarrelDir, optBarrels[barrel].manifest)} in ${optBarrels[barrel].rawBarrelDir} and ${external_path_.relative(rawBarrelDir, manifest)} in ${rawBarrelDir}.`);
14831
14893
  }
14832
14894
  optBarrels[barrel].jungleFiles.push(...rawJungles);
@@ -15160,16 +15222,16 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
15160
15222
  if (hasTests != null &&
15161
15223
  !config.checkBuildPragmas &&
15162
15224
  configOptionsToCheck.every((option) => prevOptions[option] === config[option]) &&
15163
- actualOptimizedFiles.length == Object.values(fnMap).length &&
15225
+ actualOptimizedFiles.length === Object.values(fnMap).length &&
15164
15226
  Object.values(fnMap)
15165
15227
  .map((v) => v.output)
15166
15228
  .sort()
15167
- .every((f, i) => f == actualOptimizedFiles[i])) {
15229
+ .every((f, i) => f === actualOptimizedFiles[i])) {
15168
15230
  // now if the newest source file is older than
15169
15231
  // the oldest optimized file, we don't need to regenerate
15170
15232
  const source_time = await (0,external_util_cjs_namespaceObject.last_modified)(Object.keys(fnMap).concat(dependencyFiles));
15171
15233
  const opt_time = await (0,external_util_cjs_namespaceObject.first_modified)(Object.values(fnMap).map((v) => v.output));
15172
- if (source_time < opt_time && 1674436813829 < opt_time) {
15234
+ if (source_time < opt_time && 1674613939459 < opt_time) {
15173
15235
  return { hasTests, diagnostics: prevDiagnostics };
15174
15236
  }
15175
15237
  }
@@ -15196,7 +15258,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
15196
15258
  return promises_namespaceObject.writeFile(external_path_.join(output, "build-info.json"), JSON.stringify({
15197
15259
  hasTests,
15198
15260
  diagnostics,
15199
- optimizerVersion: "1.1.3",
15261
+ optimizerVersion: "1.1.4",
15200
15262
  ...Object.fromEntries(configOptionsToCheck.map((option) => [option, config[option]])),
15201
15263
  }))
15202
15264
  .then(() => ({ hasTests, diagnostics }));
@@ -15249,6 +15311,7 @@ async function getProjectAnalysis(targets, analysis, manifestXML, options) {
15249
15311
  });
15250
15312
  const state = await analyze(fnMap, resourcesMap, manifestXML, options);
15251
15313
  reportMissingSymbols(state, options);
15314
+ let typeMap = null;
15252
15315
  if (state.config?.propagateTypes &&
15253
15316
  state.config.trustDeclaredTypes &&
15254
15317
  state.config.checkTypes !== "OFF" &&
@@ -15271,6 +15334,14 @@ async function getProjectAnalysis(targets, analysis, manifestXML, options) {
15271
15334
  istate.typeChecker = gistate.typeChecker;
15272
15335
  istate.checkTypes = gistate.checkTypes;
15273
15336
  interp_evaluate(istate, node.body);
15337
+ if (istate.typeMap) {
15338
+ if (typeMap == null) {
15339
+ typeMap = istate.typeMap;
15340
+ }
15341
+ else {
15342
+ istate.typeMap.forEach((value, key) => typeMap.set(key, value));
15343
+ }
15344
+ }
15274
15345
  }
15275
15346
  return [];
15276
15347
  }
@@ -15280,8 +15351,9 @@ async function getProjectAnalysis(targets, analysis, manifestXML, options) {
15280
15351
  Object.values(state.fnMap).forEach((f) => {
15281
15352
  (0,external_api_cjs_namespaceObject.collectNamespaces)(f.ast, state);
15282
15353
  });
15354
+ delete state.pre;
15283
15355
  }
15284
- return { fnMap: fnMap, paths, state };
15356
+ return { fnMap: fnMap, paths, state, typeMap };
15285
15357
  }
15286
15358
  /**
15287
15359
  *
@@ -15300,7 +15372,7 @@ async function generateApiMirTests(options) {
15300
15372
  Object.entries(node.decls).forEach(([key, decl]) => {
15301
15373
  if (decl.length > 1)
15302
15374
  throw `Bad decl length:${node.fullName}.${key}`;
15303
- if (decl.length != 1)
15375
+ if (decl.length !== 1)
15304
15376
  return;
15305
15377
  const d = decl[0];
15306
15378
  if (d.type === "EnumStringMember" ||