requirejs-esm 1.0.1 → 2.0.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
@@ -129,21 +129,24 @@
129
129
 
130
130
  // Ensures that every JavaScript dependency will be prefixed by `esm!`.
131
131
  // Relative paths will be converted to be relative to the parent module.
132
- function resolvePath$1 (sourcePath, currentFile, { pluginName }) {
132
+ function resolvePath$1 (sourcePath, currentFile, { pluginName, needsResolve } = {}) {
133
133
  // Ignore paths with other plugins applied and the three built-in
134
134
  // pseudo-modules of RequireJS.
135
- if (!pluginName || sourcePath.includes('!') || sourcePath === 'require' ||
135
+ if (sourcePath.includes('!') || sourcePath === 'require' ||
136
136
  sourcePath === 'module' || sourcePath === 'exports') return
137
137
 
138
138
  // If `sourcePath` is relative to `currentFile` - starts with ./ or ../ -
139
139
  // prepend the parent directory of `currentFile` to it. This was needed
140
140
  // for modules located outside the source root (`baseUrl`), which were
141
141
  // mapped there using the `paths` of `map` configuration properties.
142
- if (sourcePath.charAt(0) === '.' && (sourcePath.charAt(1) === '/' ||
143
- sourcePath.charAt(1) === '.' && sourcePath.charAt(2) === '/')) {
142
+ if ((sourcePath.charAt(0) === '.' && (sourcePath.charAt(1) === '/' ||
143
+ sourcePath.charAt(1) === '.' && sourcePath.charAt(2) === '/')) &&
144
+ !(needsResolve && needsResolve(sourcePath, currentFile))) {
144
145
  sourcePath = joinPath(parentDir(currentFile), sourcePath);
146
+ if (sourcePath.endsWith('.js')) sourcePath = sourcePath.substring(0, sourcePath.length - 3);
145
147
  }
146
- return `${pluginName}!${sourcePath}`
148
+
149
+ return pluginName ? `${pluginName}!${sourcePath}` : sourcePath
147
150
  }
148
151
 
149
152
  let skipModules$1 = [];
@@ -1039,9 +1042,9 @@
1039
1042
  mask |= 8;
1040
1043
  break;
1041
1044
  case 115:
1042
- if (mask & 12)
1045
+ if (mask & 32)
1043
1046
  report(parser, 34, 's');
1044
- mask |= 12;
1047
+ mask |= 32;
1045
1048
  break;
1046
1049
  default:
1047
1050
  report(parser, 33);
@@ -1954,7 +1957,7 @@
1954
1957
  }
1955
1958
  else if (ch === 61) {
1956
1959
  advanceChar(parser);
1957
- return 8456000;
1960
+ return 8456256;
1958
1961
  }
1959
1962
  if (ch === 33) {
1960
1963
  const index = parser.index + 1;
@@ -2137,7 +2140,7 @@
2137
2140
  const ch = parser.currentChar;
2138
2141
  if (ch === 61) {
2139
2142
  advanceChar(parser);
2140
- return 8456001;
2143
+ return 8456257;
2141
2144
  }
2142
2145
  if (ch !== 62)
2143
2146
  return 8456259;
@@ -5129,7 +5132,7 @@
5129
5132
  nextToken(parser, context | 32768);
5130
5133
  const argument = parser.flags & 1 || parser.token & 1048576
5131
5134
  ? null
5132
- : parseExpressions(parser, context, 0, 1, parser.tokenPos, parser.line, parser.column);
5135
+ : parseExpressions(parser, context, 0, 1, parser.tokenPos, parser.linePos, parser.colPos);
5133
5136
  matchOrInsertSemicolon(parser, context | 32768);
5134
5137
  return finishNode(parser, context, start, line, column, {
5135
5138
  type: 'ReturnStatement',
@@ -6245,7 +6248,7 @@
6245
6248
  if ((context & 524288) < 1)
6246
6249
  report(parser, 26);
6247
6250
  if (context & 16384)
6248
- report(parser, 143);
6251
+ report(parser, 27);
6249
6252
  parser.assignable = 2;
6250
6253
  break;
6251
6254
  }
@@ -6254,7 +6257,7 @@
6254
6257
  if ((context & 262144) < 1)
6255
6258
  report(parser, 27);
6256
6259
  if (context & 16384)
6257
- report(parser, 143);
6260
+ report(parser, 27);
6258
6261
  parser.assignable = 1;
6259
6262
  break;
6260
6263
  }
@@ -6285,10 +6288,10 @@
6285
6288
  expr = parseUpdateExpression(parser, context, expr, start, line, column);
6286
6289
  }
6287
6290
  else if ((parser.token & 67108864) === 67108864) {
6288
- context = (context | 134217728 | 8192) ^ (134217728 | 8192);
6291
+ context = (context | 134217728) ^ 134217728;
6289
6292
  switch (parser.token) {
6290
6293
  case 67108877: {
6291
- nextToken(parser, context | 1073741824);
6294
+ nextToken(parser, (context | 1073741824 | 8192) ^ 8192);
6292
6295
  parser.assignable = 1;
6293
6296
  const property = parsePropertyOrPrivatePropertyName(parser, context);
6294
6297
  expr = finishNode(parser, context, start, line, column, {
@@ -6344,7 +6347,7 @@
6344
6347
  break;
6345
6348
  }
6346
6349
  case 67108991: {
6347
- nextToken(parser, context);
6350
+ nextToken(parser, (context | 1073741824 | 8192) ^ 8192);
6348
6351
  parser.flags |= 2048;
6349
6352
  parser.assignable = 2;
6350
6353
  expr = parseOptionalChain(parser, context, expr, start, line, column);
@@ -8508,12 +8511,10 @@
8508
8511
  }
8509
8512
  else if (context & 1 && parser.token === 131) {
8510
8513
  kind |= 4096;
8511
- key = parsePrivateIdentifier(parser, context, tokenPos, linePos, colPos);
8512
- context = context | 16384;
8514
+ key = parsePrivateIdentifier(parser, context | 16384, tokenPos, linePos, colPos);
8513
8515
  }
8514
8516
  else if (context & 1 && (parser.token & 1073741824) === 1073741824) {
8515
8517
  kind |= 128;
8516
- context = context | 16384;
8517
8518
  }
8518
8519
  else if (token === 122) {
8519
8520
  key = parseIdentifier(parser, context, 0);
@@ -8879,7 +8880,7 @@
8879
8880
  });
8880
8881
  }
8881
8882
  function parseJSXExpressionContainer(parser, context, inJSXChild, isAttr, start, line, column) {
8882
- nextToken(parser, context);
8883
+ nextToken(parser, context | 32768);
8883
8884
  const { tokenPos, linePos, colPos } = parser;
8884
8885
  if (parser.token === 14)
8885
8886
  return parseJSXSpreadChild(parser, context, tokenPos, linePos, colPos);
@@ -81781,6 +81782,9 @@
81781
81782
  });
81782
81783
 
81783
81784
  obj[impl][utils$1.wrapperSymbol] = obj;
81785
+ if (Impl.init) {
81786
+ Impl.init(obj[impl], privateData);
81787
+ }
81784
81788
  return obj;
81785
81789
  },
81786
81790
  interface: URLSearchParams,
@@ -82332,6 +82336,9 @@
82332
82336
  });
82333
82337
 
82334
82338
  obj[impl][utils$1.wrapperSymbol] = obj;
82339
+ if (Impl.init) {
82340
+ Impl.init(obj[impl], privateData);
82341
+ }
82335
82342
  return obj;
82336
82343
  },
82337
82344
  interface: URL,
@@ -85277,9 +85284,6 @@
85277
85284
 
85278
85285
  // Updates dependency paths to be prefixed by `esm!` or otherwise updated.
85279
85286
  function updateAmdDeps(amd, options) {
85280
- const { resolvePath } = options;
85281
- if (!resolvePath) return
85282
-
85283
85287
  const { deps } = amd;
85284
85288
  if (!deps) return
85285
85289
 
@@ -85287,6 +85291,7 @@
85287
85291
  const { elements } = deps;
85288
85292
  if (!elements.length) return
85289
85293
 
85294
+ const { resolvePath } = options;
85290
85295
  let updated;
85291
85296
  for (const element of elements) {
85292
85297
  if (element.type === 'Literal') {
@@ -85665,11 +85670,8 @@
85665
85670
  // Update dependency paths to be prefixed by `esm!` or otherwise updated.
85666
85671
  function prepareImportPaths(importPaths, options ) {
85667
85672
  const { resolvePath } = options;
85668
- if (!resolvePath) return
85669
-
85670
85673
  if (resolvePath) {
85671
85674
  const { sourceFileName: parentName } = options;
85672
-
85673
85675
  for (const importPath of importPaths) {
85674
85676
  if (importPath.type === 'Literal') {
85675
85677
  const moduleName = importPath.value;
@@ -85680,7 +85682,6 @@
85680
85682
  }
85681
85683
  }
85682
85684
  }
85683
-
85684
85685
  return arrayExpression(importPaths)
85685
85686
  }
85686
85687
 
@@ -85689,7 +85690,7 @@
85689
85690
  const { length } = amds;
85690
85691
  if (length) {
85691
85692
  options.amd = true;
85692
- if (options.pluginName) {
85693
+ if (options.resolvePath) {
85693
85694
  for (const amd of amds) {
85694
85695
  options.updated |= updateAmdDeps(amd, options);
85695
85696
  }