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/api.js CHANGED
@@ -69,7 +69,7 @@
69
69
  // mapped there using the `paths` of `map` configuration properties.
70
70
  if ((sourcePath.charAt(0) === '.' && (sourcePath.charAt(1) === '/' ||
71
71
  sourcePath.charAt(1) === '.' && sourcePath.charAt(2) === '/')) &&
72
- !(needsResolve && needsResolve(sourcePath, currentFile))) {
72
+ !(needsResolve?.(sourcePath, currentFile))) {
73
73
  sourcePath = joinPath(parentDir(currentFile), sourcePath);
74
74
  if (sourcePath.endsWith('.js')) sourcePath = sourcePath.substring(0, sourcePath.length - 3);
75
75
  }
@@ -2080,7 +2080,7 @@
2080
2080
  advanceChar(parser);
2081
2081
  if (parser.currentChar === 61) {
2082
2082
  advanceChar(parser);
2083
- return 4194344;
2083
+ return 4718632;
2084
2084
  }
2085
2085
  return 8913465;
2086
2086
  }
@@ -2123,7 +2123,7 @@
2123
2123
  advanceChar(parser);
2124
2124
  if (parser.currentChar === 61) {
2125
2125
  advanceChar(parser);
2126
- return 4194345;
2126
+ return 4718633;
2127
2127
  }
2128
2128
  return 8913720;
2129
2129
  }
@@ -2139,7 +2139,7 @@
2139
2139
  advanceChar(parser);
2140
2140
  if (parser.currentChar === 61) {
2141
2141
  advanceChar(parser);
2142
- return 4194346;
2142
+ return 4718634;
2143
2143
  }
2144
2144
  return 276824445;
2145
2145
  }
@@ -4805,7 +4805,7 @@
4805
4805
  currentChar = 0;
4806
4806
  exportedNames = new Set();
4807
4807
  exportedBindings = new Set();
4808
- assignable = 1;
4808
+ assignable = 0;
4809
4809
  destructible = 0;
4810
4810
  leadingDecorators = { decorators: [] };
4811
4811
  constructor(source, rawOptions = {}) {
@@ -6094,6 +6094,8 @@
6094
6094
  if ((token & 4194304) === 4194304) {
6095
6095
  if (parser.assignable & 2)
6096
6096
  parser.report(26);
6097
+ if ((token & 524288) === 524288 && parser.assignable & 4)
6098
+ parser.report(26);
6097
6099
  if ((!isPattern && token === 1077936155 && left.type === 'ArrayExpression') ||
6098
6100
  left.type === 'ObjectExpression') {
6099
6101
  reinterpretToPattern(parser, left);
@@ -6459,7 +6461,12 @@
6459
6461
  parser.flags = (parser.flags | 2048) ^ 2048;
6460
6462
  }
6461
6463
  const args = parseArguments(parser, context, privateScope, inGroup);
6462
- parser.assignable = 2;
6464
+ if (!(context & 1) && parser.options.webcompat) {
6465
+ parser.assignable = 4;
6466
+ }
6467
+ else {
6468
+ parser.assignable = 2;
6469
+ }
6463
6470
  expr = parser.finishNode({
6464
6471
  type: 'CallExpression',
6465
6472
  callee: expr,
@@ -6527,7 +6534,12 @@
6527
6534
  }
6528
6535
  else if (parser.getToken() === 67174411) {
6529
6536
  const args = parseArguments(parser, context, privateScope, 0);
6530
- parser.assignable = 2;
6537
+ if (!(context & 1) && parser.options.webcompat) {
6538
+ parser.assignable = 4;
6539
+ }
6540
+ else {
6541
+ parser.assignable = 2;
6542
+ }
6531
6543
  node = parser.finishNode({
6532
6544
  type: 'CallExpression',
6533
6545
  callee: expr,
@@ -7132,9 +7144,9 @@
7132
7144
  }
7133
7145
  else if (parser.getToken() !== 1077936155) {
7134
7146
  destructible |=
7135
- parser.assignable & 2
7136
- ? 16
7137
- : 32;
7147
+ parser.assignable & 1
7148
+ ? 32
7149
+ : 16;
7138
7150
  }
7139
7151
  }
7140
7152
  }
@@ -7164,9 +7176,9 @@
7164
7176
  }
7165
7177
  else if (parser.getToken() !== 1077936155) {
7166
7178
  destructible |=
7167
- parser.assignable & 2
7168
- ? 16
7169
- : 32;
7179
+ parser.assignable & 1
7180
+ ? 32
7181
+ : 16;
7170
7182
  }
7171
7183
  }
7172
7184
  }
@@ -7283,7 +7295,7 @@
7283
7295
  if (parser.destructible & 8)
7284
7296
  parser.report(71);
7285
7297
  argument = parseMemberOrUpdateExpression(parser, context, privateScope, argument, inGroup, 0, tokenStart);
7286
- destructible |= parser.assignable & 2 ? 16 : 0;
7298
+ destructible |= parser.assignable & 1 ? 0 : 16;
7287
7299
  if ((parser.getToken() & 4194304) === 4194304) {
7288
7300
  if (parser.getToken() !== 1077936155)
7289
7301
  destructible |= 16;
@@ -7297,9 +7309,9 @@
7297
7309
  argument = parseConditionalExpression(parser, context, privateScope, argument, tokenStart);
7298
7310
  }
7299
7311
  destructible |=
7300
- parser.assignable & 2
7301
- ? 16
7302
- : 32;
7312
+ parser.assignable & 1
7313
+ ? 32
7314
+ : 16;
7303
7315
  }
7304
7316
  }
7305
7317
  else {
@@ -7328,7 +7340,9 @@
7328
7340
  argument = parseAssignmentExpression(parser, context, privateScope, inGroup, isPattern, tokenStart, argument);
7329
7341
  }
7330
7342
  destructible |=
7331
- parser.assignable & 1 ? 32 : 16;
7343
+ parser.assignable & 1
7344
+ ? 32
7345
+ : 16;
7332
7346
  }
7333
7347
  parser.destructible = destructible;
7334
7348
  if (parser.getToken() !== closingToken && parser.getToken() !== 18)
@@ -7520,7 +7534,9 @@
7520
7534
  : parseObjectLiteralOrPattern(parser, context, scope, privateScope, 0, inGroup, isPattern, kind, origin);
7521
7535
  destructible = parser.destructible;
7522
7536
  parser.assignable =
7523
- destructible & 16 ? 2 : 1;
7537
+ destructible & 16
7538
+ ? 2
7539
+ : 1;
7524
7540
  if (parser.getToken() === 18 || parser.getToken() === 1074790415) {
7525
7541
  if (parser.assignable & 2)
7526
7542
  destructible |= 16;
@@ -7542,9 +7558,9 @@
7542
7558
  value = parseConditionalExpression(parser, context, privateScope, value, tokenStart);
7543
7559
  }
7544
7560
  destructible |=
7545
- parser.assignable & 2
7546
- ? 16
7547
- : 32;
7561
+ parser.assignable & 1
7562
+ ? 32
7563
+ : 16;
7548
7564
  }
7549
7565
  }
7550
7566
  }
@@ -7701,7 +7717,9 @@
7701
7717
  : parseObjectLiteralOrPattern(parser, context, scope, privateScope, 0, inGroup, isPattern, kind, origin);
7702
7718
  destructible = parser.destructible;
7703
7719
  parser.assignable =
7704
- destructible & 16 ? 2 : 1;
7720
+ destructible & 16
7721
+ ? 2
7722
+ : 1;
7705
7723
  if (parser.getToken() === 18 || parser.getToken() === 1074790415) {
7706
7724
  if (parser.assignable & 2) {
7707
7725
  destructible |= 16;
@@ -7721,9 +7739,9 @@
7721
7739
  value = parseConditionalExpression(parser, context, privateScope, value, tokenStart);
7722
7740
  }
7723
7741
  destructible |=
7724
- parser.assignable & 2
7725
- ? 16
7726
- : 32;
7742
+ parser.assignable & 1
7743
+ ? 32
7744
+ : 16;
7727
7745
  }
7728
7746
  }
7729
7747
  }
@@ -7752,7 +7770,7 @@
7752
7770
  else if (parser.getToken() === 67174411) {
7753
7771
  state |= 1;
7754
7772
  value = parseMethodDefinition(parser, context, privateScope, state, inGroup, parser.tokenStart);
7755
- destructible = parser.assignable | 16;
7773
+ destructible = 16;
7756
7774
  }
7757
7775
  else {
7758
7776
  parser.report(134);
@@ -7772,11 +7790,11 @@
7772
7790
  value = parseMemberOrUpdateExpression(parser, context, privateScope, value, inGroup, 0, tokenStart);
7773
7791
  if ((parser.getToken() & 4194304) === 4194304) {
7774
7792
  destructible |=
7775
- parser.assignable & 2
7776
- ? 16
7777
- : token === 1077936155
7793
+ parser.assignable & 1
7794
+ ? token === 1077936155
7778
7795
  ? 0
7779
- : 32;
7796
+ : 32
7797
+ : 16;
7780
7798
  value = parseAssignmentExpressionOrPattern(parser, context, privateScope, inGroup, isPattern, tokenStart, value);
7781
7799
  }
7782
7800
  else if (parser.getToken() === 18 || parser.getToken() === 1074790415) {
@@ -7807,7 +7825,9 @@
7807
7825
  : parseObjectLiteralOrPattern(parser, context, scope, privateScope, 0, inGroup, isPattern, kind, origin);
7808
7826
  destructible = parser.destructible;
7809
7827
  parser.assignable =
7810
- destructible & 16 ? 2 : 1;
7828
+ destructible & 16
7829
+ ? 2
7830
+ : 1;
7811
7831
  if (parser.getToken() === 18 || parser.getToken() === 1074790415) {
7812
7832
  if (parser.assignable & 2)
7813
7833
  destructible |= 16;
@@ -7832,9 +7852,9 @@
7832
7852
  value = parseConditionalExpression(parser, context, privateScope, value, tokenStart);
7833
7853
  }
7834
7854
  destructible |=
7835
- parser.assignable & 2
7836
- ? 16
7837
- : 32;
7855
+ parser.assignable & 1
7856
+ ? 32
7857
+ : 16;
7838
7858
  }
7839
7859
  }
7840
7860
  }
@@ -8439,6 +8459,12 @@
8439
8459
  parser.report(48);
8440
8460
  return parseParenthesizedArrow(parser, context, scope, privateScope, [], canAssign, 1, start);
8441
8461
  }
8462
+ if (!(context & 1) && parser.options.webcompat) {
8463
+ parser.assignable = 4;
8464
+ }
8465
+ else {
8466
+ parser.assignable = 2;
8467
+ }
8442
8468
  return parser.finishNode({
8443
8469
  type: 'CallExpression',
8444
8470
  callee,
@@ -8512,7 +8538,7 @@
8512
8538
  }
8513
8539
  else {
8514
8540
  expr = parseExpression(parser, context, privateScope, 1, 0, tokenStart);
8515
- destructible = parser.assignable;
8541
+ destructible = 0;
8516
8542
  params.push(expr);
8517
8543
  while (consumeOpt(parser, context | 32, 18)) {
8518
8544
  params.push(parseExpression(parser, context, privateScope, 1, 0, tokenStart));
@@ -8520,7 +8546,12 @@
8520
8546
  destructible |= parser.assignable;
8521
8547
  consume(parser, context, 16);
8522
8548
  parser.destructible = destructible | 16;
8523
- parser.assignable = 2;
8549
+ if (!(context & 1) && parser.options.webcompat) {
8550
+ parser.assignable = 4;
8551
+ }
8552
+ else {
8553
+ parser.assignable = 2;
8554
+ }
8524
8555
  return parser.finishNode({
8525
8556
  type: 'CallExpression',
8526
8557
  callee,
@@ -8558,7 +8589,12 @@
8558
8589
  if (destructible & 8) {
8559
8590
  parser.report(62);
8560
8591
  }
8561
- parser.assignable = 2;
8592
+ if (!(context & 1) && parser.options.webcompat) {
8593
+ parser.assignable = 4;
8594
+ }
8595
+ else {
8596
+ parser.assignable = 2;
8597
+ }
8562
8598
  return parser.finishNode({
8563
8599
  type: 'CallExpression',
8564
8600
  callee,
@@ -10505,7 +10541,7 @@
10505
10541
  var isInstance = false;
10506
10542
  try {
10507
10543
  isInstance = this instanceof a;
10508
- } catch {}
10544
+ } catch (e) {}
10509
10545
  if (isInstance) {
10510
10546
  return Reflect.construct(f, arguments, this.constructor);
10511
10547
  }
@@ -10679,7 +10715,7 @@
10679
10715
  function requireLib () {
10680
10716
  if (hasRequiredLib) return lib;
10681
10717
  hasRequiredLib = 1;
10682
- (function (exports$1) {
10718
+ (function (exports) {
10683
10719
 
10684
10720
  function _(message, opts) {
10685
10721
  return `${opts && opts.context ? opts.context : "Value"} ${message}.`;
@@ -10822,31 +10858,31 @@
10822
10858
  };
10823
10859
  }
10824
10860
 
10825
- exports$1.any = V => {
10861
+ exports.any = V => {
10826
10862
  return V;
10827
10863
  };
10828
10864
 
10829
- exports$1.void = function () {
10865
+ exports.void = function () {
10830
10866
  return undefined;
10831
10867
  };
10832
10868
 
10833
- exports$1.boolean = function (val) {
10869
+ exports.boolean = function (val) {
10834
10870
  return !!val;
10835
10871
  };
10836
10872
 
10837
- exports$1.byte = createIntegerConversion(8, { unsigned: false });
10838
- exports$1.octet = createIntegerConversion(8, { unsigned: true });
10873
+ exports.byte = createIntegerConversion(8, { unsigned: false });
10874
+ exports.octet = createIntegerConversion(8, { unsigned: true });
10839
10875
 
10840
- exports$1.short = createIntegerConversion(16, { unsigned: false });
10841
- exports$1["unsigned short"] = createIntegerConversion(16, { unsigned: true });
10876
+ exports.short = createIntegerConversion(16, { unsigned: false });
10877
+ exports["unsigned short"] = createIntegerConversion(16, { unsigned: true });
10842
10878
 
10843
- exports$1.long = createIntegerConversion(32, { unsigned: false });
10844
- exports$1["unsigned long"] = createIntegerConversion(32, { unsigned: true });
10879
+ exports.long = createIntegerConversion(32, { unsigned: false });
10880
+ exports["unsigned long"] = createIntegerConversion(32, { unsigned: true });
10845
10881
 
10846
- exports$1["long long"] = createIntegerConversion(64, { unsigned: false });
10847
- exports$1["unsigned long long"] = createIntegerConversion(64, { unsigned: true });
10882
+ exports["long long"] = createIntegerConversion(64, { unsigned: false });
10883
+ exports["unsigned long long"] = createIntegerConversion(64, { unsigned: true });
10848
10884
 
10849
- exports$1.double = (V, opts) => {
10885
+ exports.double = (V, opts) => {
10850
10886
  const x = +V;
10851
10887
 
10852
10888
  if (!Number.isFinite(x)) {
@@ -10856,13 +10892,13 @@
10856
10892
  return x;
10857
10893
  };
10858
10894
 
10859
- exports$1["unrestricted double"] = V => {
10895
+ exports["unrestricted double"] = V => {
10860
10896
  const x = +V;
10861
10897
 
10862
10898
  return x;
10863
10899
  };
10864
10900
 
10865
- exports$1.float = (V, opts) => {
10901
+ exports.float = (V, opts) => {
10866
10902
  const x = +V;
10867
10903
 
10868
10904
  if (!Number.isFinite(x)) {
@@ -10882,7 +10918,7 @@
10882
10918
  return y;
10883
10919
  };
10884
10920
 
10885
- exports$1["unrestricted float"] = V => {
10921
+ exports["unrestricted float"] = V => {
10886
10922
  const x = +V;
10887
10923
 
10888
10924
  if (isNaN(x)) {
@@ -10896,7 +10932,7 @@
10896
10932
  return Math.fround(x);
10897
10933
  };
10898
10934
 
10899
- exports$1.DOMString = function (V, opts) {
10935
+ exports.DOMString = function (V, opts) {
10900
10936
  if (opts === undefined) {
10901
10937
  opts = {};
10902
10938
  }
@@ -10912,8 +10948,8 @@
10912
10948
  return String(V);
10913
10949
  };
10914
10950
 
10915
- exports$1.ByteString = (V, opts) => {
10916
- const x = exports$1.DOMString(V, opts);
10951
+ exports.ByteString = (V, opts) => {
10952
+ const x = exports.DOMString(V, opts);
10917
10953
  let c;
10918
10954
  for (let i = 0; (c = x.codePointAt(i)) !== undefined; ++i) {
10919
10955
  if (c > 255) {
@@ -10924,8 +10960,8 @@
10924
10960
  return x;
10925
10961
  };
10926
10962
 
10927
- exports$1.USVString = (V, opts) => {
10928
- const S = exports$1.DOMString(V, opts);
10963
+ exports.USVString = (V, opts) => {
10964
+ const S = exports.DOMString(V, opts);
10929
10965
  const n = S.length;
10930
10966
  const U = [];
10931
10967
  for (let i = 0; i < n; ++i) {
@@ -10952,7 +10988,7 @@
10952
10988
  return U.join("");
10953
10989
  };
10954
10990
 
10955
- exports$1.object = (V, opts) => {
10991
+ exports.object = (V, opts) => {
10956
10992
  if (type(V) !== "Object") {
10957
10993
  throw new TypeError(_("is not an object", opts));
10958
10994
  }
@@ -10979,7 +11015,7 @@
10979
11015
  ].forEach(func => {
10980
11016
  const name = func.name;
10981
11017
  const article = /^[AEIOU]/.test(name) ? "an" : "a";
10982
- exports$1[name] = (V, opts) => {
11018
+ exports[name] = (V, opts) => {
10983
11019
  if (!(V instanceof func)) {
10984
11020
  throw new TypeError(_(`is not ${article} ${name} object`, opts));
10985
11021
  }
@@ -10990,7 +11026,7 @@
10990
11026
 
10991
11027
  // Common definitions
10992
11028
 
10993
- exports$1.ArrayBufferView = (V, opts) => {
11029
+ exports.ArrayBufferView = (V, opts) => {
10994
11030
  if (!ArrayBuffer.isView(V)) {
10995
11031
  throw new TypeError(_("is not a view on an ArrayBuffer object", opts));
10996
11032
  }
@@ -10998,7 +11034,7 @@
10998
11034
  return V;
10999
11035
  };
11000
11036
 
11001
- exports$1.BufferSource = (V, opts) => {
11037
+ exports.BufferSource = (V, opts) => {
11002
11038
  if (!(ArrayBuffer.isView(V) || V instanceof ArrayBuffer)) {
11003
11039
  throw new TypeError(_("is not an ArrayBuffer object or a view on one", opts));
11004
11040
  }
@@ -11006,11 +11042,11 @@
11006
11042
  return V;
11007
11043
  };
11008
11044
 
11009
- exports$1.DOMTimeStamp = exports$1["unsigned long long"];
11045
+ exports.DOMTimeStamp = exports["unsigned long long"];
11010
11046
 
11011
- exports$1.Function = convertCallbackFunction;
11047
+ exports.Function = convertCallbackFunction;
11012
11048
 
11013
- exports$1.VoidFunction = convertCallbackFunction;
11049
+ exports.VoidFunction = convertCallbackFunction;
11014
11050
  } (lib));
11015
11051
  return lib;
11016
11052
  }
@@ -11022,7 +11058,7 @@
11022
11058
  function requireUtils () {
11023
11059
  if (hasRequiredUtils) return utils.exports;
11024
11060
  hasRequiredUtils = 1;
11025
- (function (module, exports$1) {
11061
+ (function (module, exports) {
11026
11062
 
11027
11063
  // Returns "Type(value) is Object" in ES terminology.
11028
11064
  function isObject(value) {
@@ -79112,7 +79148,7 @@
79112
79148
  function requireLodash_sortby () {
79113
79149
  if (hasRequiredLodash_sortby) return lodash_sortby.exports;
79114
79150
  hasRequiredLodash_sortby = 1;
79115
- (function (module, exports$1) {
79151
+ (function (module, exports) {
79116
79152
  /** Used as the size to enable large array optimizations. */
79117
79153
  var LARGE_ARRAY_SIZE = 200;
79118
79154
 
@@ -79206,7 +79242,7 @@
79206
79242
  var root = freeGlobal || freeSelf || Function('return this')();
79207
79243
 
79208
79244
  /** Detect free variable `exports`. */
79209
- var freeExports = exports$1 && !exports$1.nodeType && exports$1;
79245
+ var freeExports = exports && !exports.nodeType && exports;
79210
79246
 
79211
79247
  /** Detect free variable `module`. */
79212
79248
  var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module;
@@ -83995,15 +84031,15 @@
83995
84031
  function requireBinarySearch () {
83996
84032
  if (hasRequiredBinarySearch) return binarySearch;
83997
84033
  hasRequiredBinarySearch = 1;
83998
- (function (exports$1) {
84034
+ (function (exports) {
83999
84035
  /*
84000
84036
  * Copyright 2011 Mozilla Foundation and contributors
84001
84037
  * Licensed under the New BSD license. See LICENSE or:
84002
84038
  * http://opensource.org/licenses/BSD-3-Clause
84003
84039
  */
84004
84040
 
84005
- exports$1.GREATEST_LOWER_BOUND = 1;
84006
- exports$1.LEAST_UPPER_BOUND = 2;
84041
+ exports.GREATEST_LOWER_BOUND = 1;
84042
+ exports.LEAST_UPPER_BOUND = 2;
84007
84043
 
84008
84044
  /**
84009
84045
  * Recursive implementation of binary search.
@@ -84042,7 +84078,7 @@
84042
84078
 
84043
84079
  // The exact needle element was not found in this haystack. Determine if
84044
84080
  // we are in termination case (3) or (2) and return the appropriate thing.
84045
- if (aBias == exports$1.LEAST_UPPER_BOUND) {
84081
+ if (aBias == exports.LEAST_UPPER_BOUND) {
84046
84082
  return aHigh < aHaystack.length ? aHigh : -1;
84047
84083
  }
84048
84084
  return mid;
@@ -84055,7 +84091,7 @@
84055
84091
  }
84056
84092
 
84057
84093
  // we are in termination case (3) or (2) and return the appropriate thing.
84058
- if (aBias == exports$1.LEAST_UPPER_BOUND) {
84094
+ if (aBias == exports.LEAST_UPPER_BOUND) {
84059
84095
  return mid;
84060
84096
  }
84061
84097
  return aLow < 0 ? -1 : aLow;
@@ -84079,13 +84115,13 @@
84079
84115
  * searching for, respectively, if the exact element cannot be found.
84080
84116
  * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'.
84081
84117
  */
84082
- exports$1.search = function search(aNeedle, aHaystack, aCompare, aBias) {
84118
+ exports.search = function search(aNeedle, aHaystack, aCompare, aBias) {
84083
84119
  if (aHaystack.length === 0) {
84084
84120
  return -1;
84085
84121
  }
84086
84122
 
84087
84123
  let index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack,
84088
- aCompare, aBias || exports$1.GREATEST_LOWER_BOUND);
84124
+ aCompare, aBias || exports.GREATEST_LOWER_BOUND);
84089
84125
  if (index < 0) {
84090
84126
  return -1;
84091
84127
  }
@@ -86090,7 +86126,7 @@
86090
86126
  }
86091
86127
 
86092
86128
  function toIdentifier(input) {
86093
- input = input + '';
86129
+ input = `${input}`;
86094
86130
 
86095
86131
  let name = '';
86096
86132
  for (const c of input) {
@@ -86099,9 +86135,7 @@
86099
86135
 
86100
86136
  name = name.replace(/^[-0-9]+/, '');
86101
86137
 
86102
- name = name.replace(/[-\s]+(.)?/g, function (match, c) {
86103
- return c ? c.toUpperCase() : ''
86104
- });
86138
+ name = name.replace(/[-\s]+(.)?/g, (_match, c) => c ? c.toUpperCase() : '');
86105
86139
 
86106
86140
  if (!isValidIdentifier(name)) {
86107
86141
  name = `_${name}`;
@@ -86490,7 +86524,7 @@
86490
86524
  const { length } = body;
86491
86525
 
86492
86526
  const imports = [];
86493
- const exports$1 = [];
86527
+ const exports = [];
86494
86528
 
86495
86529
  for (let i = 0; i < length; ++i) {
86496
86530
  const node = body[i];
@@ -86518,7 +86552,7 @@
86518
86552
 
86519
86553
  // export default
86520
86554
  else if (node.type === 'ExportDefaultDeclaration') {
86521
- exports$1.push({ node, default: true });
86555
+ exports.push({ node, default: true });
86522
86556
  }
86523
86557
 
86524
86558
  // export {x as y}
@@ -86530,29 +86564,29 @@
86530
86564
 
86531
86565
  // export var a = 1
86532
86566
  if (!specifiers.length) {
86533
- exports$1.push({ node });
86567
+ exports.push({ node });
86534
86568
  } else { // export {x as y}
86535
86569
  // export { ... } from "module"
86536
86570
  const { source } = node;
86537
86571
  if (source) {
86538
- exports$1.push({ node, source, import: true });
86572
+ exports.push({ node, source, import: true });
86539
86573
  const specifiers = node.specifiers.map(({ exported: imported, local }) => ({ imported, local }));
86540
86574
  imports.push({ node, source, specifiers, export: true });
86541
86575
  } else {
86542
- exports$1.push({ node });
86576
+ exports.push({ node });
86543
86577
  }
86544
86578
  }
86545
86579
  }
86546
86580
 
86547
86581
  // export * from "module"
86548
86582
  if (node.type === 'ExportAllDeclaration') {
86549
- exports$1.push({ node, import: true });
86583
+ exports.push({ node, import: true });
86550
86584
  const { source } = node;
86551
86585
  imports.push({ node, source, export: true });
86552
86586
  }
86553
86587
  }
86554
86588
 
86555
- return { imports, exports: exports$1 }
86589
+ return { imports, exports }
86556
86590
  }
86557
86591
 
86558
86592
  // Transforms the module format from ESM to AMD.
@@ -86562,6 +86596,7 @@
86562
86596
  program
86563
86597
  });
86564
86598
 
86599
+ const { splitDefaultNamedDeclarations } = options;
86565
86600
  const { body } = program;
86566
86601
  let { length } = body;
86567
86602
 
@@ -86623,46 +86658,52 @@
86623
86658
 
86624
86659
  // expression after keyword default
86625
86660
  const { declaration } = statement;
86661
+ // export default X
86626
86662
  let exportValue = declaration;
86627
-
86628
- if (declaration.type === 'FunctionDeclaration') {
86629
- exportValue = toExpression(exportValue);
86630
- }
86631
- if (declaration.type === 'ClassDeclaration') {
86632
- exportValue = toExpression(exportValue);
86633
- // const classNode = exportValue
86634
-
86635
- // if (classNode.id) {
86636
- // body[i] = classNode
86637
-
86638
- // const className = identifier(classNode.id.name)
86639
- // let exportStat
86640
- // if (i + 1 === length && isOnlyDefaultExport) {
86641
- // exportStat = returnStatement(identifier(className))
86642
- // needReturnExport = false
86643
- // } else {
86644
- // exportStat = exportStatement(exportsVar, 'default', className)
86645
- // }
86646
-
86647
- // program.pushContainer('body', [exportStat])
86648
- // needExportExpression = false
86649
- // } else {
86650
- // exportValue = toExpression(classNode)
86651
- // }
86663
+ let keepDeclaration;
86664
+
86665
+ if (declaration.type === 'FunctionDeclaration' ||
86666
+ declaration.type === 'ClassDeclaration') {
86667
+ const { id } = declaration;
86668
+ if (id && splitDefaultNamedDeclarations) {
86669
+ // export default function X() {}
86670
+ // export default class X {}
86671
+ exportValue = identifier(declaration.id.name);
86672
+ keepDeclaration = true;
86673
+ } else {
86674
+ // export default function () {}
86675
+ // export default class {}
86676
+ exportValue = toExpression(declaration);
86677
+ }
86652
86678
  }
86653
86679
 
86654
- {
86655
- let exportStat;
86680
+ let exportStat;
86656
86681
 
86657
- if (i + 1 === length && isOnlyDefaultExport) {
86658
- exportStat = returnStatement(exportValue);
86659
- needReturnExport = false;
86660
- } else {
86661
- exportStat = exportStatement(exportsVar, 'default', exportValue);
86662
- }
86682
+ if (i + 1 === length && isOnlyDefaultExport) {
86683
+ exportStat = returnStatement(exportValue);
86684
+ needReturnExport = false;
86685
+ } else {
86686
+ exportStat = exportStatement(exportsVar, 'default', exportValue);
86687
+ }
86663
86688
 
86664
- body[i] = exportStat;
86689
+ // This changes the original code by putting the name of the exported
86690
+ // function or class to the module scope. Being able to access the class
86691
+ // by name simplifies other AST manipulations, which would have to be more
86692
+ // complicated. Or the developer would have to help the manipulator
86693
+ // by separating the export expression to a declaration and an export
86694
+ // of an identifier. Use it if it doesn't break your code.
86695
+ //
86696
+ // // original, the name X is not in the module scope
86697
+ // export default class X {}
86698
+ //
86699
+ // // converted, the name X is in the module scope
86700
+ // class X {}
86701
+ // export default X
86702
+ if (keepDeclaration) {
86703
+ body.splice(i++, 0, declaration);
86704
+ ++length;
86665
86705
  }
86706
+ body[i] = exportStat;
86666
86707
  }
86667
86708
 
86668
86709
  // export {x as y}
@@ -86718,7 +86759,7 @@
86718
86759
  const importVar = generateUidIdentifier(exportSource.value, program);
86719
86760
  importVars.push(importVar);
86720
86761
 
86721
- for (let specifier of specifiers) {
86762
+ for (const specifier of specifiers) {
86722
86763
  const { exported, local } = specifier;
86723
86764
  const { name } = local;
86724
86765
  let localName;
@@ -86792,6 +86833,17 @@
86792
86833
  }
86793
86834
  }
86794
86835
 
86836
+ // no imports and exports, do not wrap to AMD module, if AMD/UMD should be assumed
86837
+ if (options.skipIfNoImportExport && !(importPaths.length || hasExport)) {
86838
+ options.onAfterTransform?.({
86839
+ ...options,
86840
+ updated: false,
86841
+ program,
86842
+ callbackBody: body
86843
+ });
86844
+ return false
86845
+ }
86846
+
86795
86847
  // adding define wrapper
86796
86848
  if (hasExport && needReturnExport) {
86797
86849
  let returnStat;
@@ -86824,10 +86876,13 @@
86824
86876
 
86825
86877
  options.onAfterTransform?.({
86826
86878
  ...options,
86879
+ updated: true,
86827
86880
  program,
86828
86881
  callbackBody: body
86829
86882
  });
86830
86883
 
86884
+ return true
86885
+
86831
86886
  function addExportStatement({ exported, local }) {
86832
86887
  const asName = exported.name;
86833
86888
  if (asName !== 'default') {
@@ -86909,6 +86964,23 @@
86909
86964
  return arrayExpression(importPaths)
86910
86965
  }
86911
86966
 
86967
+ // Check if one of the first 10 lines shorter than 100 characters contains
86968
+ // "// requirejs-esm-skip-file" or // requirejs-esm-process-file".
86969
+ function processOrSkipByComment(text) {
86970
+ for (let start = 0, i = 0; i < 10; ++i) {
86971
+ const endLine = text.indexOf('\n', start);
86972
+ if (endLine < 0 || endLine > 100) break
86973
+ const line = text.substring(start, endLine);
86974
+ const comment = /^\s*\/\//.test(line);
86975
+ if (!comment) break
86976
+ const directive = /^\s*\/\/\s*requirejs-esm-(skip|process)-file\s*$/.exec(line);
86977
+ if (directive) {
86978
+ return directive[1] === 'process'
86979
+ }
86980
+ start = endLine + 1;
86981
+ }
86982
+ }
86983
+
86912
86984
  function transformAst(program, options = {}) {
86913
86985
  const amds = detectDefinesOrRequires(program);
86914
86986
  const { length } = amds;
@@ -86922,8 +86994,7 @@
86922
86994
  result.updated ||= updated;
86923
86995
  }
86924
86996
  } else {
86925
- transformEsmToAmd(program, options);
86926
- result.updated = true;
86997
+ result.updated = transformEsmToAmd(program, options);
86927
86998
  }
86928
86999
  return result
86929
87000
  }
@@ -86934,10 +87005,15 @@
86934
87005
  // Method to update paths of module dependencies, to prefix JavaScript module
86935
87006
  // name with `esm!`, above all.
86936
87007
  resolvePath: resolvePath$1 = resolvePath,
87008
+ // Assume AMD/UMD if there're no import or export statements.
87009
+ skipIfNoImportExport,
86937
87010
  // ecmaVersion = 2020,
86938
87011
  // Do not insert `"use strict"` expression to the AMD modules. You'd set it
86939
87012
  // to `false` if your bundler inserts `"use strict"` to the outer scope.
86940
87013
  useStrict,
87014
+ // Split `export default class A {}` to `class A {}; export default A`
87015
+ // to trade easier AST manipulation for 100% code compatibility.
87016
+ splitDefaultNamedDeclarations,
86941
87017
  // Enable source maps, can be an object with booleans { inline, content }.
86942
87018
  // If set to true, the object will be set to { inline: true, content: true }.
86943
87019
  sourceMap,
@@ -86948,8 +87024,15 @@
86948
87024
  onBeforeUpdate,
86949
87025
  onAfterUpdate
86950
87026
  } = {}) {
87027
+ const processOrSkip = processOrSkipByComment(text);
87028
+ if (processOrSkip === false) {
87029
+ return { code: text, map: null, updated: false }
87030
+ } else if (processOrSkip === true) {
87031
+ skipIfNoImportExport = undefined;
87032
+ }
87033
+
86951
87034
  // const ast = parse(text, { ecmaVersion, sourceType: 'module', locations: true })
86952
- let ast = parseModule(text, { next: true, loc: true });
87035
+ const ast = parseModule(text, { next: true, loc: true });
86953
87036
 
86954
87037
  const options = {
86955
87038
  sourceFileName: file,
@@ -86957,6 +87040,8 @@
86957
87040
  resolvePath: resolvePath$1,
86958
87041
  originalResolvePath: resolvePath,
86959
87042
  useStrict,
87043
+ skipIfNoImportExport,
87044
+ splitDefaultNamedDeclarations,
86960
87045
  onBeforeTransform,
86961
87046
  onAfterTransform,
86962
87047
  onBeforeUpdate,
@@ -86990,6 +87075,7 @@
86990
87075
 
86991
87076
  exports.detectDefinesOrRequires = detectDefinesOrRequires;
86992
87077
  exports.detectImportsAndExports = detectImportsAndExports;
87078
+ exports.processOrSkipByComment = processOrSkipByComment;
86993
87079
  exports.resolvePath = resolvePath;
86994
87080
  exports.transform = transform;
86995
87081
  exports.transformAst = transformAst;