requirejs-esm 4.2.0 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/plugin.js CHANGED
@@ -38,7 +38,7 @@
38
38
  xhr.send(null);
39
39
  };
40
40
  } else {
41
- const { readFileSync } = require.nodeRequire ? require.nodeRequire('fs') : require('fs');
41
+ const { readFileSync } = require.nodeRequire ? require.nodeRequire('fs') : require('node:fs');
42
42
  fetchText = (path, callback) => {
43
43
  // Asynchronous reading is not possible during the build in the optimizer.
44
44
  try {
@@ -58,8 +58,8 @@
58
58
  // Initialise the writeText variable with a function to write to a file.
59
59
  /* istanbul ignore if */
60
60
  if (!(typeof window !== 'undefined' && window.navigator && window.document)) {
61
- const { writeFileSync, mkdirSync } = require.nodeRequire ? require.nodeRequire('fs') : require('fs');
62
- const { dirname } = require.nodeRequire ? require.nodeRequire('path') : require('path');
61
+ const { writeFileSync, mkdirSync } = require.nodeRequire ? require.nodeRequire('fs') : require('node:fs');
62
+ const { dirname } = require.nodeRequire ? require.nodeRequire('path') : require('node:path');
63
63
  writeText = (path, content) => {
64
64
  mkdirSync(dirname(path), { recursive: true });
65
65
  writeFileSync(path, content);
@@ -141,7 +141,7 @@
141
141
  // mapped there using the `paths` of `map` configuration properties.
142
142
  if ((sourcePath.charAt(0) === '.' && (sourcePath.charAt(1) === '/' ||
143
143
  sourcePath.charAt(1) === '.' && sourcePath.charAt(2) === '/')) &&
144
- !(needsResolve && needsResolve(sourcePath, currentFile))) {
144
+ !(needsResolve?.(sourcePath, currentFile))) {
145
145
  sourcePath = joinPath(parentDir(currentFile), sourcePath);
146
146
  if (sourcePath.endsWith('.js')) sourcePath = sourcePath.substring(0, sourcePath.length - 3);
147
147
  }
@@ -2171,7 +2171,7 @@
2171
2171
  advanceChar(parser);
2172
2172
  if (parser.currentChar === 61) {
2173
2173
  advanceChar(parser);
2174
- return 4194344;
2174
+ return 4718632;
2175
2175
  }
2176
2176
  return 8913465;
2177
2177
  }
@@ -2214,7 +2214,7 @@
2214
2214
  advanceChar(parser);
2215
2215
  if (parser.currentChar === 61) {
2216
2216
  advanceChar(parser);
2217
- return 4194345;
2217
+ return 4718633;
2218
2218
  }
2219
2219
  return 8913720;
2220
2220
  }
@@ -2230,7 +2230,7 @@
2230
2230
  advanceChar(parser);
2231
2231
  if (parser.currentChar === 61) {
2232
2232
  advanceChar(parser);
2233
- return 4194346;
2233
+ return 4718634;
2234
2234
  }
2235
2235
  return 276824445;
2236
2236
  }
@@ -4896,7 +4896,7 @@
4896
4896
  currentChar = 0;
4897
4897
  exportedNames = new Set();
4898
4898
  exportedBindings = new Set();
4899
- assignable = 1;
4899
+ assignable = 0;
4900
4900
  destructible = 0;
4901
4901
  leadingDecorators = { decorators: [] };
4902
4902
  constructor(source, rawOptions = {}) {
@@ -6185,6 +6185,8 @@
6185
6185
  if ((token & 4194304) === 4194304) {
6186
6186
  if (parser.assignable & 2)
6187
6187
  parser.report(26);
6188
+ if ((token & 524288) === 524288 && parser.assignable & 4)
6189
+ parser.report(26);
6188
6190
  if ((!isPattern && token === 1077936155 && left.type === 'ArrayExpression') ||
6189
6191
  left.type === 'ObjectExpression') {
6190
6192
  reinterpretToPattern(parser, left);
@@ -6550,7 +6552,12 @@
6550
6552
  parser.flags = (parser.flags | 2048) ^ 2048;
6551
6553
  }
6552
6554
  const args = parseArguments(parser, context, privateScope, inGroup);
6553
- parser.assignable = 2;
6555
+ if (!(context & 1) && parser.options.webcompat) {
6556
+ parser.assignable = 4;
6557
+ }
6558
+ else {
6559
+ parser.assignable = 2;
6560
+ }
6554
6561
  expr = parser.finishNode({
6555
6562
  type: 'CallExpression',
6556
6563
  callee: expr,
@@ -6618,7 +6625,12 @@
6618
6625
  }
6619
6626
  else if (parser.getToken() === 67174411) {
6620
6627
  const args = parseArguments(parser, context, privateScope, 0);
6621
- parser.assignable = 2;
6628
+ if (!(context & 1) && parser.options.webcompat) {
6629
+ parser.assignable = 4;
6630
+ }
6631
+ else {
6632
+ parser.assignable = 2;
6633
+ }
6622
6634
  node = parser.finishNode({
6623
6635
  type: 'CallExpression',
6624
6636
  callee: expr,
@@ -7223,9 +7235,9 @@
7223
7235
  }
7224
7236
  else if (parser.getToken() !== 1077936155) {
7225
7237
  destructible |=
7226
- parser.assignable & 2
7227
- ? 16
7228
- : 32;
7238
+ parser.assignable & 1
7239
+ ? 32
7240
+ : 16;
7229
7241
  }
7230
7242
  }
7231
7243
  }
@@ -7255,9 +7267,9 @@
7255
7267
  }
7256
7268
  else if (parser.getToken() !== 1077936155) {
7257
7269
  destructible |=
7258
- parser.assignable & 2
7259
- ? 16
7260
- : 32;
7270
+ parser.assignable & 1
7271
+ ? 32
7272
+ : 16;
7261
7273
  }
7262
7274
  }
7263
7275
  }
@@ -7374,7 +7386,7 @@
7374
7386
  if (parser.destructible & 8)
7375
7387
  parser.report(71);
7376
7388
  argument = parseMemberOrUpdateExpression(parser, context, privateScope, argument, inGroup, 0, tokenStart);
7377
- destructible |= parser.assignable & 2 ? 16 : 0;
7389
+ destructible |= parser.assignable & 1 ? 0 : 16;
7378
7390
  if ((parser.getToken() & 4194304) === 4194304) {
7379
7391
  if (parser.getToken() !== 1077936155)
7380
7392
  destructible |= 16;
@@ -7388,9 +7400,9 @@
7388
7400
  argument = parseConditionalExpression(parser, context, privateScope, argument, tokenStart);
7389
7401
  }
7390
7402
  destructible |=
7391
- parser.assignable & 2
7392
- ? 16
7393
- : 32;
7403
+ parser.assignable & 1
7404
+ ? 32
7405
+ : 16;
7394
7406
  }
7395
7407
  }
7396
7408
  else {
@@ -7419,7 +7431,9 @@
7419
7431
  argument = parseAssignmentExpression(parser, context, privateScope, inGroup, isPattern, tokenStart, argument);
7420
7432
  }
7421
7433
  destructible |=
7422
- parser.assignable & 1 ? 32 : 16;
7434
+ parser.assignable & 1
7435
+ ? 32
7436
+ : 16;
7423
7437
  }
7424
7438
  parser.destructible = destructible;
7425
7439
  if (parser.getToken() !== closingToken && parser.getToken() !== 18)
@@ -7611,7 +7625,9 @@
7611
7625
  : parseObjectLiteralOrPattern(parser, context, scope, privateScope, 0, inGroup, isPattern, kind, origin);
7612
7626
  destructible = parser.destructible;
7613
7627
  parser.assignable =
7614
- destructible & 16 ? 2 : 1;
7628
+ destructible & 16
7629
+ ? 2
7630
+ : 1;
7615
7631
  if (parser.getToken() === 18 || parser.getToken() === 1074790415) {
7616
7632
  if (parser.assignable & 2)
7617
7633
  destructible |= 16;
@@ -7633,9 +7649,9 @@
7633
7649
  value = parseConditionalExpression(parser, context, privateScope, value, tokenStart);
7634
7650
  }
7635
7651
  destructible |=
7636
- parser.assignable & 2
7637
- ? 16
7638
- : 32;
7652
+ parser.assignable & 1
7653
+ ? 32
7654
+ : 16;
7639
7655
  }
7640
7656
  }
7641
7657
  }
@@ -7792,7 +7808,9 @@
7792
7808
  : parseObjectLiteralOrPattern(parser, context, scope, privateScope, 0, inGroup, isPattern, kind, origin);
7793
7809
  destructible = parser.destructible;
7794
7810
  parser.assignable =
7795
- destructible & 16 ? 2 : 1;
7811
+ destructible & 16
7812
+ ? 2
7813
+ : 1;
7796
7814
  if (parser.getToken() === 18 || parser.getToken() === 1074790415) {
7797
7815
  if (parser.assignable & 2) {
7798
7816
  destructible |= 16;
@@ -7812,9 +7830,9 @@
7812
7830
  value = parseConditionalExpression(parser, context, privateScope, value, tokenStart);
7813
7831
  }
7814
7832
  destructible |=
7815
- parser.assignable & 2
7816
- ? 16
7817
- : 32;
7833
+ parser.assignable & 1
7834
+ ? 32
7835
+ : 16;
7818
7836
  }
7819
7837
  }
7820
7838
  }
@@ -7843,7 +7861,7 @@
7843
7861
  else if (parser.getToken() === 67174411) {
7844
7862
  state |= 1;
7845
7863
  value = parseMethodDefinition(parser, context, privateScope, state, inGroup, parser.tokenStart);
7846
- destructible = parser.assignable | 16;
7864
+ destructible = 16;
7847
7865
  }
7848
7866
  else {
7849
7867
  parser.report(134);
@@ -7863,11 +7881,11 @@
7863
7881
  value = parseMemberOrUpdateExpression(parser, context, privateScope, value, inGroup, 0, tokenStart);
7864
7882
  if ((parser.getToken() & 4194304) === 4194304) {
7865
7883
  destructible |=
7866
- parser.assignable & 2
7867
- ? 16
7868
- : token === 1077936155
7884
+ parser.assignable & 1
7885
+ ? token === 1077936155
7869
7886
  ? 0
7870
- : 32;
7887
+ : 32
7888
+ : 16;
7871
7889
  value = parseAssignmentExpressionOrPattern(parser, context, privateScope, inGroup, isPattern, tokenStart, value);
7872
7890
  }
7873
7891
  else if (parser.getToken() === 18 || parser.getToken() === 1074790415) {
@@ -7898,7 +7916,9 @@
7898
7916
  : parseObjectLiteralOrPattern(parser, context, scope, privateScope, 0, inGroup, isPattern, kind, origin);
7899
7917
  destructible = parser.destructible;
7900
7918
  parser.assignable =
7901
- destructible & 16 ? 2 : 1;
7919
+ destructible & 16
7920
+ ? 2
7921
+ : 1;
7902
7922
  if (parser.getToken() === 18 || parser.getToken() === 1074790415) {
7903
7923
  if (parser.assignable & 2)
7904
7924
  destructible |= 16;
@@ -7923,9 +7943,9 @@
7923
7943
  value = parseConditionalExpression(parser, context, privateScope, value, tokenStart);
7924
7944
  }
7925
7945
  destructible |=
7926
- parser.assignable & 2
7927
- ? 16
7928
- : 32;
7946
+ parser.assignable & 1
7947
+ ? 32
7948
+ : 16;
7929
7949
  }
7930
7950
  }
7931
7951
  }
@@ -8530,6 +8550,12 @@
8530
8550
  parser.report(48);
8531
8551
  return parseParenthesizedArrow(parser, context, scope, privateScope, [], canAssign, 1, start);
8532
8552
  }
8553
+ if (!(context & 1) && parser.options.webcompat) {
8554
+ parser.assignable = 4;
8555
+ }
8556
+ else {
8557
+ parser.assignable = 2;
8558
+ }
8533
8559
  return parser.finishNode({
8534
8560
  type: 'CallExpression',
8535
8561
  callee,
@@ -8603,7 +8629,7 @@
8603
8629
  }
8604
8630
  else {
8605
8631
  expr = parseExpression(parser, context, privateScope, 1, 0, tokenStart);
8606
- destructible = parser.assignable;
8632
+ destructible = 0;
8607
8633
  params.push(expr);
8608
8634
  while (consumeOpt(parser, context | 32, 18)) {
8609
8635
  params.push(parseExpression(parser, context, privateScope, 1, 0, tokenStart));
@@ -8611,7 +8637,12 @@
8611
8637
  destructible |= parser.assignable;
8612
8638
  consume(parser, context, 16);
8613
8639
  parser.destructible = destructible | 16;
8614
- parser.assignable = 2;
8640
+ if (!(context & 1) && parser.options.webcompat) {
8641
+ parser.assignable = 4;
8642
+ }
8643
+ else {
8644
+ parser.assignable = 2;
8645
+ }
8615
8646
  return parser.finishNode({
8616
8647
  type: 'CallExpression',
8617
8648
  callee,
@@ -8649,7 +8680,12 @@
8649
8680
  if (destructible & 8) {
8650
8681
  parser.report(62);
8651
8682
  }
8652
- parser.assignable = 2;
8683
+ if (!(context & 1) && parser.options.webcompat) {
8684
+ parser.assignable = 4;
8685
+ }
8686
+ else {
8687
+ parser.assignable = 2;
8688
+ }
8653
8689
  return parser.finishNode({
8654
8690
  type: 'CallExpression',
8655
8691
  callee,
@@ -10596,7 +10632,7 @@
10596
10632
  var isInstance = false;
10597
10633
  try {
10598
10634
  isInstance = this instanceof a;
10599
- } catch {}
10635
+ } catch (e) {}
10600
10636
  if (isInstance) {
10601
10637
  return Reflect.construct(f, arguments, this.constructor);
10602
10638
  }
@@ -10770,7 +10806,7 @@
10770
10806
  function requireLib () {
10771
10807
  if (hasRequiredLib) return lib;
10772
10808
  hasRequiredLib = 1;
10773
- (function (exports$1) {
10809
+ (function (exports) {
10774
10810
 
10775
10811
  function _(message, opts) {
10776
10812
  return `${opts && opts.context ? opts.context : "Value"} ${message}.`;
@@ -10913,31 +10949,31 @@
10913
10949
  };
10914
10950
  }
10915
10951
 
10916
- exports$1.any = V => {
10952
+ exports.any = V => {
10917
10953
  return V;
10918
10954
  };
10919
10955
 
10920
- exports$1.void = function () {
10956
+ exports.void = function () {
10921
10957
  return undefined;
10922
10958
  };
10923
10959
 
10924
- exports$1.boolean = function (val) {
10960
+ exports.boolean = function (val) {
10925
10961
  return !!val;
10926
10962
  };
10927
10963
 
10928
- exports$1.byte = createIntegerConversion(8, { unsigned: false });
10929
- exports$1.octet = createIntegerConversion(8, { unsigned: true });
10964
+ exports.byte = createIntegerConversion(8, { unsigned: false });
10965
+ exports.octet = createIntegerConversion(8, { unsigned: true });
10930
10966
 
10931
- exports$1.short = createIntegerConversion(16, { unsigned: false });
10932
- exports$1["unsigned short"] = createIntegerConversion(16, { unsigned: true });
10967
+ exports.short = createIntegerConversion(16, { unsigned: false });
10968
+ exports["unsigned short"] = createIntegerConversion(16, { unsigned: true });
10933
10969
 
10934
- exports$1.long = createIntegerConversion(32, { unsigned: false });
10935
- exports$1["unsigned long"] = createIntegerConversion(32, { unsigned: true });
10970
+ exports.long = createIntegerConversion(32, { unsigned: false });
10971
+ exports["unsigned long"] = createIntegerConversion(32, { unsigned: true });
10936
10972
 
10937
- exports$1["long long"] = createIntegerConversion(64, { unsigned: false });
10938
- exports$1["unsigned long long"] = createIntegerConversion(64, { unsigned: true });
10973
+ exports["long long"] = createIntegerConversion(64, { unsigned: false });
10974
+ exports["unsigned long long"] = createIntegerConversion(64, { unsigned: true });
10939
10975
 
10940
- exports$1.double = (V, opts) => {
10976
+ exports.double = (V, opts) => {
10941
10977
  const x = +V;
10942
10978
 
10943
10979
  if (!Number.isFinite(x)) {
@@ -10947,13 +10983,13 @@
10947
10983
  return x;
10948
10984
  };
10949
10985
 
10950
- exports$1["unrestricted double"] = V => {
10986
+ exports["unrestricted double"] = V => {
10951
10987
  const x = +V;
10952
10988
 
10953
10989
  return x;
10954
10990
  };
10955
10991
 
10956
- exports$1.float = (V, opts) => {
10992
+ exports.float = (V, opts) => {
10957
10993
  const x = +V;
10958
10994
 
10959
10995
  if (!Number.isFinite(x)) {
@@ -10973,7 +11009,7 @@
10973
11009
  return y;
10974
11010
  };
10975
11011
 
10976
- exports$1["unrestricted float"] = V => {
11012
+ exports["unrestricted float"] = V => {
10977
11013
  const x = +V;
10978
11014
 
10979
11015
  if (isNaN(x)) {
@@ -10987,7 +11023,7 @@
10987
11023
  return Math.fround(x);
10988
11024
  };
10989
11025
 
10990
- exports$1.DOMString = function (V, opts) {
11026
+ exports.DOMString = function (V, opts) {
10991
11027
  if (opts === undefined) {
10992
11028
  opts = {};
10993
11029
  }
@@ -11003,8 +11039,8 @@
11003
11039
  return String(V);
11004
11040
  };
11005
11041
 
11006
- exports$1.ByteString = (V, opts) => {
11007
- const x = exports$1.DOMString(V, opts);
11042
+ exports.ByteString = (V, opts) => {
11043
+ const x = exports.DOMString(V, opts);
11008
11044
  let c;
11009
11045
  for (let i = 0; (c = x.codePointAt(i)) !== undefined; ++i) {
11010
11046
  if (c > 255) {
@@ -11015,8 +11051,8 @@
11015
11051
  return x;
11016
11052
  };
11017
11053
 
11018
- exports$1.USVString = (V, opts) => {
11019
- const S = exports$1.DOMString(V, opts);
11054
+ exports.USVString = (V, opts) => {
11055
+ const S = exports.DOMString(V, opts);
11020
11056
  const n = S.length;
11021
11057
  const U = [];
11022
11058
  for (let i = 0; i < n; ++i) {
@@ -11043,7 +11079,7 @@
11043
11079
  return U.join("");
11044
11080
  };
11045
11081
 
11046
- exports$1.object = (V, opts) => {
11082
+ exports.object = (V, opts) => {
11047
11083
  if (type(V) !== "Object") {
11048
11084
  throw new TypeError(_("is not an object", opts));
11049
11085
  }
@@ -11070,7 +11106,7 @@
11070
11106
  ].forEach(func => {
11071
11107
  const name = func.name;
11072
11108
  const article = /^[AEIOU]/.test(name) ? "an" : "a";
11073
- exports$1[name] = (V, opts) => {
11109
+ exports[name] = (V, opts) => {
11074
11110
  if (!(V instanceof func)) {
11075
11111
  throw new TypeError(_(`is not ${article} ${name} object`, opts));
11076
11112
  }
@@ -11081,7 +11117,7 @@
11081
11117
 
11082
11118
  // Common definitions
11083
11119
 
11084
- exports$1.ArrayBufferView = (V, opts) => {
11120
+ exports.ArrayBufferView = (V, opts) => {
11085
11121
  if (!ArrayBuffer.isView(V)) {
11086
11122
  throw new TypeError(_("is not a view on an ArrayBuffer object", opts));
11087
11123
  }
@@ -11089,7 +11125,7 @@
11089
11125
  return V;
11090
11126
  };
11091
11127
 
11092
- exports$1.BufferSource = (V, opts) => {
11128
+ exports.BufferSource = (V, opts) => {
11093
11129
  if (!(ArrayBuffer.isView(V) || V instanceof ArrayBuffer)) {
11094
11130
  throw new TypeError(_("is not an ArrayBuffer object or a view on one", opts));
11095
11131
  }
@@ -11097,11 +11133,11 @@
11097
11133
  return V;
11098
11134
  };
11099
11135
 
11100
- exports$1.DOMTimeStamp = exports$1["unsigned long long"];
11136
+ exports.DOMTimeStamp = exports["unsigned long long"];
11101
11137
 
11102
- exports$1.Function = convertCallbackFunction;
11138
+ exports.Function = convertCallbackFunction;
11103
11139
 
11104
- exports$1.VoidFunction = convertCallbackFunction;
11140
+ exports.VoidFunction = convertCallbackFunction;
11105
11141
  } (lib));
11106
11142
  return lib;
11107
11143
  }
@@ -11113,7 +11149,7 @@
11113
11149
  function requireUtils () {
11114
11150
  if (hasRequiredUtils) return utils.exports;
11115
11151
  hasRequiredUtils = 1;
11116
- (function (module, exports$1) {
11152
+ (function (module, exports) {
11117
11153
 
11118
11154
  // Returns "Type(value) is Object" in ES terminology.
11119
11155
  function isObject(value) {
@@ -79203,7 +79239,7 @@
79203
79239
  function requireLodash_sortby () {
79204
79240
  if (hasRequiredLodash_sortby) return lodash_sortby.exports;
79205
79241
  hasRequiredLodash_sortby = 1;
79206
- (function (module, exports$1) {
79242
+ (function (module, exports) {
79207
79243
  /** Used as the size to enable large array optimizations. */
79208
79244
  var LARGE_ARRAY_SIZE = 200;
79209
79245
 
@@ -79297,7 +79333,7 @@
79297
79333
  var root = freeGlobal || freeSelf || Function('return this')();
79298
79334
 
79299
79335
  /** Detect free variable `exports`. */
79300
- var freeExports = exports$1 && !exports$1.nodeType && exports$1;
79336
+ var freeExports = exports && !exports.nodeType && exports;
79301
79337
 
79302
79338
  /** Detect free variable `module`. */
79303
79339
  var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module;
@@ -84086,15 +84122,15 @@
84086
84122
  function requireBinarySearch () {
84087
84123
  if (hasRequiredBinarySearch) return binarySearch;
84088
84124
  hasRequiredBinarySearch = 1;
84089
- (function (exports$1) {
84125
+ (function (exports) {
84090
84126
  /*
84091
84127
  * Copyright 2011 Mozilla Foundation and contributors
84092
84128
  * Licensed under the New BSD license. See LICENSE or:
84093
84129
  * http://opensource.org/licenses/BSD-3-Clause
84094
84130
  */
84095
84131
 
84096
- exports$1.GREATEST_LOWER_BOUND = 1;
84097
- exports$1.LEAST_UPPER_BOUND = 2;
84132
+ exports.GREATEST_LOWER_BOUND = 1;
84133
+ exports.LEAST_UPPER_BOUND = 2;
84098
84134
 
84099
84135
  /**
84100
84136
  * Recursive implementation of binary search.
@@ -84133,7 +84169,7 @@
84133
84169
 
84134
84170
  // The exact needle element was not found in this haystack. Determine if
84135
84171
  // we are in termination case (3) or (2) and return the appropriate thing.
84136
- if (aBias == exports$1.LEAST_UPPER_BOUND) {
84172
+ if (aBias == exports.LEAST_UPPER_BOUND) {
84137
84173
  return aHigh < aHaystack.length ? aHigh : -1;
84138
84174
  }
84139
84175
  return mid;
@@ -84146,7 +84182,7 @@
84146
84182
  }
84147
84183
 
84148
84184
  // we are in termination case (3) or (2) and return the appropriate thing.
84149
- if (aBias == exports$1.LEAST_UPPER_BOUND) {
84185
+ if (aBias == exports.LEAST_UPPER_BOUND) {
84150
84186
  return mid;
84151
84187
  }
84152
84188
  return aLow < 0 ? -1 : aLow;
@@ -84170,13 +84206,13 @@
84170
84206
  * searching for, respectively, if the exact element cannot be found.
84171
84207
  * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'.
84172
84208
  */
84173
- exports$1.search = function search(aNeedle, aHaystack, aCompare, aBias) {
84209
+ exports.search = function search(aNeedle, aHaystack, aCompare, aBias) {
84174
84210
  if (aHaystack.length === 0) {
84175
84211
  return -1;
84176
84212
  }
84177
84213
 
84178
84214
  let index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack,
84179
- aCompare, aBias || exports$1.GREATEST_LOWER_BOUND);
84215
+ aCompare, aBias || exports.GREATEST_LOWER_BOUND);
84180
84216
  if (index < 0) {
84181
84217
  return -1;
84182
84218
  }
@@ -86181,7 +86217,7 @@
86181
86217
  }
86182
86218
 
86183
86219
  function toIdentifier(input) {
86184
- input = input + '';
86220
+ input = `${input}`;
86185
86221
 
86186
86222
  let name = '';
86187
86223
  for (const c of input) {
@@ -86190,9 +86226,7 @@
86190
86226
 
86191
86227
  name = name.replace(/^[-0-9]+/, '');
86192
86228
 
86193
- name = name.replace(/[-\s]+(.)?/g, function (match, c) {
86194
- return c ? c.toUpperCase() : ''
86195
- });
86229
+ name = name.replace(/[-\s]+(.)?/g, (_match, c) => c ? c.toUpperCase() : '');
86196
86230
 
86197
86231
  if (!isValidIdentifier(name)) {
86198
86232
  name = `_${name}`;
@@ -86581,6 +86615,7 @@
86581
86615
  program
86582
86616
  });
86583
86617
 
86618
+ const { splitDefaultNamedDeclarations } = options;
86584
86619
  const { body } = program;
86585
86620
  let { length } = body;
86586
86621
 
@@ -86642,46 +86677,52 @@
86642
86677
 
86643
86678
  // expression after keyword default
86644
86679
  const { declaration } = statement;
86680
+ // export default X
86645
86681
  let exportValue = declaration;
86646
-
86647
- if (declaration.type === 'FunctionDeclaration') {
86648
- exportValue = toExpression(exportValue);
86649
- }
86650
- if (declaration.type === 'ClassDeclaration') {
86651
- exportValue = toExpression(exportValue);
86652
- // const classNode = exportValue
86653
-
86654
- // if (classNode.id) {
86655
- // body[i] = classNode
86656
-
86657
- // const className = identifier(classNode.id.name)
86658
- // let exportStat
86659
- // if (i + 1 === length && isOnlyDefaultExport) {
86660
- // exportStat = returnStatement(identifier(className))
86661
- // needReturnExport = false
86662
- // } else {
86663
- // exportStat = exportStatement(exportsVar, 'default', className)
86664
- // }
86665
-
86666
- // program.pushContainer('body', [exportStat])
86667
- // needExportExpression = false
86668
- // } else {
86669
- // exportValue = toExpression(classNode)
86670
- // }
86682
+ let keepDeclaration;
86683
+
86684
+ if (declaration.type === 'FunctionDeclaration' ||
86685
+ declaration.type === 'ClassDeclaration') {
86686
+ const { id } = declaration;
86687
+ if (id && splitDefaultNamedDeclarations) {
86688
+ // export default function X() {}
86689
+ // export default class X {}
86690
+ exportValue = identifier(declaration.id.name);
86691
+ keepDeclaration = true;
86692
+ } else {
86693
+ // export default function () {}
86694
+ // export default class {}
86695
+ exportValue = toExpression(declaration);
86696
+ }
86671
86697
  }
86672
86698
 
86673
- {
86674
- let exportStat;
86699
+ let exportStat;
86675
86700
 
86676
- if (i + 1 === length && isOnlyDefaultExport) {
86677
- exportStat = returnStatement(exportValue);
86678
- needReturnExport = false;
86679
- } else {
86680
- exportStat = exportStatement(exportsVar, 'default', exportValue);
86681
- }
86701
+ if (i + 1 === length && isOnlyDefaultExport) {
86702
+ exportStat = returnStatement(exportValue);
86703
+ needReturnExport = false;
86704
+ } else {
86705
+ exportStat = exportStatement(exportsVar, 'default', exportValue);
86706
+ }
86682
86707
 
86683
- body[i] = exportStat;
86708
+ // This changes the original code by putting the name of the exported
86709
+ // function or class to the module scope. Being able to access the class
86710
+ // by name simplifies other AST manipulations, which would have to be more
86711
+ // complicated. Or the developer would have to help the manipulator
86712
+ // by separating the export expression to a declaration and an export
86713
+ // of an identifier. Use it if it doesn't break your code.
86714
+ //
86715
+ // // original, the name X is not in the module scope
86716
+ // export default class X {}
86717
+ //
86718
+ // // converted, the name X is in the module scope
86719
+ // class X {}
86720
+ // export default X
86721
+ if (keepDeclaration) {
86722
+ body.splice(i++, 0, declaration);
86723
+ ++length;
86684
86724
  }
86725
+ body[i] = exportStat;
86685
86726
  }
86686
86727
 
86687
86728
  // export {x as y}
@@ -86737,7 +86778,7 @@
86737
86778
  const importVar = generateUidIdentifier(exportSource.value, program);
86738
86779
  importVars.push(importVar);
86739
86780
 
86740
- for (let specifier of specifiers) {
86781
+ for (const specifier of specifiers) {
86741
86782
  const { exported, local } = specifier;
86742
86783
  const { name } = local;
86743
86784
  let localName;
@@ -86811,6 +86852,17 @@
86811
86852
  }
86812
86853
  }
86813
86854
 
86855
+ // no imports and exports, do not wrap to AMD module, if AMD/UMD should be assumed
86856
+ if (options.skipIfNoImportExport && !(importPaths.length || hasExport)) {
86857
+ options.onAfterTransform?.({
86858
+ ...options,
86859
+ updated: false,
86860
+ program,
86861
+ callbackBody: body
86862
+ });
86863
+ return false
86864
+ }
86865
+
86814
86866
  // adding define wrapper
86815
86867
  if (hasExport && needReturnExport) {
86816
86868
  let returnStat;
@@ -86843,10 +86895,13 @@
86843
86895
 
86844
86896
  options.onAfterTransform?.({
86845
86897
  ...options,
86898
+ updated: true,
86846
86899
  program,
86847
86900
  callbackBody: body
86848
86901
  });
86849
86902
 
86903
+ return true
86904
+
86850
86905
  function addExportStatement({ exported, local }) {
86851
86906
  const asName = exported.name;
86852
86907
  if (asName !== 'default') {
@@ -86928,6 +86983,23 @@
86928
86983
  return arrayExpression(importPaths)
86929
86984
  }
86930
86985
 
86986
+ // Check if one of the first 10 lines shorter than 100 characters contains
86987
+ // "// requirejs-esm-skip-file" or // requirejs-esm-process-file".
86988
+ function processOrSkipByComment(text) {
86989
+ for (let start = 0, i = 0; i < 10; ++i) {
86990
+ const endLine = text.indexOf('\n', start);
86991
+ if (endLine < 0 || endLine > 100) break
86992
+ const line = text.substring(start, endLine);
86993
+ const comment = /^\s*\/\//.test(line);
86994
+ if (!comment) break
86995
+ const directive = /^\s*\/\/\s*requirejs-esm-(skip|process)-file\s*$/.exec(line);
86996
+ if (directive) {
86997
+ return directive[1] === 'process'
86998
+ }
86999
+ start = endLine + 1;
87000
+ }
87001
+ }
87002
+
86931
87003
  function transformAst(program, options = {}) {
86932
87004
  const amds = detectDefinesOrRequires(program);
86933
87005
  const { length } = amds;
@@ -86941,8 +87013,7 @@
86941
87013
  result.updated ||= updated;
86942
87014
  }
86943
87015
  } else {
86944
- transformEsmToAmd(program, options);
86945
- result.updated = true;
87016
+ result.updated = transformEsmToAmd(program, options);
86946
87017
  }
86947
87018
  return result
86948
87019
  }
@@ -86953,10 +87024,15 @@
86953
87024
  // Method to update paths of module dependencies, to prefix JavaScript module
86954
87025
  // name with `esm!`, above all.
86955
87026
  resolvePath = resolvePath$1,
87027
+ // Assume AMD/UMD if there're no import or export statements.
87028
+ skipIfNoImportExport,
86956
87029
  // ecmaVersion = 2020,
86957
87030
  // Do not insert `"use strict"` expression to the AMD modules. You'd set it
86958
87031
  // to `false` if your bundler inserts `"use strict"` to the outer scope.
86959
87032
  useStrict,
87033
+ // Split `export default class A {}` to `class A {}; export default A`
87034
+ // to trade easier AST manipulation for 100% code compatibility.
87035
+ splitDefaultNamedDeclarations,
86960
87036
  // Enable source maps, can be an object with booleans { inline, content }.
86961
87037
  // If set to true, the object will be set to { inline: true, content: true }.
86962
87038
  sourceMap,
@@ -86967,8 +87043,15 @@
86967
87043
  onBeforeUpdate,
86968
87044
  onAfterUpdate
86969
87045
  } = {}) {
87046
+ const processOrSkip = processOrSkipByComment(text);
87047
+ if (processOrSkip === false) {
87048
+ return { code: text, map: null, updated: false }
87049
+ } else if (processOrSkip === true) {
87050
+ skipIfNoImportExport = undefined;
87051
+ }
87052
+
86970
87053
  // const ast = parse(text, { ecmaVersion, sourceType: 'module', locations: true })
86971
- let ast = parseModule(text, { next: true, loc: true });
87054
+ const ast = parseModule(text, { next: true, loc: true });
86972
87055
 
86973
87056
  const options = {
86974
87057
  sourceFileName: file,
@@ -86976,6 +87059,8 @@
86976
87059
  resolvePath,
86977
87060
  originalResolvePath: resolvePath$1,
86978
87061
  useStrict,
87062
+ skipIfNoImportExport,
87063
+ splitDefaultNamedDeclarations,
86979
87064
  onBeforeTransform,
86980
87065
  onAfterTransform,
86981
87066
  onBeforeUpdate,
@@ -87020,6 +87105,8 @@
87020
87105
  onlyAmd,
87021
87106
  // List of module names not to check and transform.
87022
87107
  skipModules = [],
87108
+ // Assume AMD/UMD if there're no import or export statements.
87109
+ skipIfNoImportExport,
87023
87110
  // Method to update paths of module dependencies, to prefix JavaScript module
87024
87111
  // name with `esm!`, above all.
87025
87112
  resolvePath,
@@ -87027,6 +87114,9 @@
87027
87114
  // Do not insert `"use strict"` expression to the AMD modules. You'd set it
87028
87115
  // to `false` if your bundler inserts `"use strict"` to the outer scope.
87029
87116
  useStrict,
87117
+ // Split `export default class A {}` to `class A {}; export default A`
87118
+ // to trade easier AST manipulation for 100% code compatibility.
87119
+ splitDefaultNamedDeclarations,
87030
87120
  // Boolean or object with booleans { inline, content }.
87031
87121
  sourceMap,
87032
87122
  // Enable console logging.
@@ -87116,6 +87206,8 @@
87116
87206
  resolvePath,
87117
87207
  /*ecmaVersion,*/
87118
87208
  useStrict,
87209
+ skipIfNoImportExport,
87210
+ splitDefaultNamedDeclarations,
87119
87211
  // Always produce the source maps when transpiling in the browser, otherwise
87120
87212
  // the debugging would me impossible. When building and bundling, check if
87121
87213
  // the source maps were enabled for the output.
@@ -87160,7 +87252,7 @@
87160
87252
  // compiled with esm refer it with that name and this stub will simplify
87161
87253
  // the module loading by skipping the plugin evaluation.
87162
87254
  write.asModule(`${pluginName}!${moduleName}`,
87163
- '\ndefine([\'' + moduleName + '\'], res => res);\n');
87255
+ `\ndefine(['${moduleName}'], res => res);\n`);
87164
87256
  }
87165
87257
  //>>excludeEnd('excludeEsm')
87166
87258
  }