@@ -82,7 +82,7 @@ const sourcemap = {
82
82
// Adding the dynamic import helps test the import transformation's source map
83
83
test : (
84
84
extension : string ,
85
- ) => `import('node:fs');\nconst { stack } = new Error(); const searchString = 'index.${ extension } :SOURCEMAP_LINE'; assert(stack.includes(searchString), \`Expected \${searchString} in stack: \${stack}\`)` ,
85
+ ) => `import ('node:fs');\nconst { stack } = new Error(); const searchString = 'index.${ extension } :SOURCEMAP_LINE'; assert(stack.includes(searchString), \`Expected \${searchString} in stack: \${stack}\`)` ,
86
86
tag : (
87
87
strings : TemplateStringsArray ,
88
88
...values : string [ ]
@@ -108,11 +108,21 @@ const files = {
108
108
assert(${ cjsContextCheck } , 'Should have CJS context');
109
109
${ preserveName }
110
110
${ sourcemap . test ( 'cjs' ) }
111
+
112
+ // Assert __esModule is unwrapped
113
+ import ('../ts/index.ts').then((m) => assert(
114
+ !(typeof m.default === 'object' && ('default' in m.default)),
115
+ ));
111
116
exports.named = 'named';
112
117
` ,
113
118
114
119
'mjs/index.mjs' : `
120
+ import assert from 'assert';
115
121
export const mjsHasCjsContext = ${ cjsContextCheck } ;
122
+
123
+ import ('pkg-commonjs').then((m) => assert(
124
+ !(typeof m.default === 'object' && ('default' in m.default)),
125
+ ));
116
126
` ,
117
127
118
128
'ts/index.ts' : sourcemap . tag `
@@ -255,9 +265,9 @@ const files = {
255
265
[() => ${ jsxCheck } , 'React is not defined'],
256
266
257
267
// These should throw unless allowJs is set
258
- // [() => import('prefix/file'), "Cannot find package 'prefix'"],
259
- // [() => import('paths-exact-match'), "Cannot find package 'paths-exact-match'"],
260
- // [() => import('file'), "Cannot find package 'file'"],
268
+ // [() => import ('prefix/file'), "Cannot find package 'prefix'"],
269
+ // [() => import ('paths-exact-match'), "Cannot find package 'paths-exact-match'"],
270
+ // [() => import ('file'), "Cannot find package 'file'"],
261
271
);
262
272
` ,
263
273
@@ -271,9 +281,9 @@ const files = {
271
281
'index.mjs' : `
272
282
import { expectErrors } from '../../../expect-errors';
273
283
expectErrors(
274
- [() => import('prefix/file'), "Cannot find package 'prefix'"],
275
- [() => import('paths-exact-match'), "Cannot find package 'paths-exact-match'"],
276
- [() => import('file'), "Cannot find package 'file'"],
284
+ [() => import ('prefix/file'), "Cannot find package 'prefix'"],
285
+ [() => import ('paths-exact-match'), "Cannot find package 'paths-exact-match'"],
286
+ [() => import ('file'), "Cannot find package 'file'"],
277
287
);
278
288
` ,
279
289
'index.cjs' : `
@@ -366,7 +376,7 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
366
376
import './js/';
367
377
368
378
// No double .default.default in Dynamic Import
369
- import('./js/index.js').then(m => {
379
+ import/* comment */ ('./js/index.js').then(m => {
370
380
if (typeof m.default === 'object') {
371
381
assert(
372
382
!('default' in m.default),
@@ -375,7 +385,7 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
375
385
}
376
386
});
377
387
378
- const importWorksInEval = async () => await import('./js/index.js');
388
+ const importWorksInEval = async () => await import ('./js/index.js');
379
389
(0, eval)(importWorksInEval.toString())();
380
390
381
391
// .json
@@ -386,8 +396,8 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
386
396
// .cjs
387
397
import * as cjs from './cjs/index.cjs';
388
398
expectErrors(
389
- [() => import('./cjs/index'), 'Cannot find module'],
390
- [() => import('./cjs/'), 'Cannot find module'],
399
+ [() => import ('./cjs/index'), 'Cannot find module'],
400
+ [() => import ('./cjs/'), 'Cannot find module'],
391
401
${
392
402
isCommonJs
393
403
? `
@@ -401,8 +411,8 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
401
411
// .mjs
402
412
import * as mjs from './mjs/index.mjs';
403
413
expectErrors(
404
- [() => import('./mjs/index'), 'Cannot find module'],
405
- [() => import('./mjs/'), 'Cannot find module'],
414
+ [() => import ('./mjs/index'), 'Cannot find module'],
415
+ [() => import ('./mjs/'), 'Cannot find module'],
406
416
${
407
417
isCommonJs
408
418
? `
@@ -418,8 +428,8 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
418
428
419
429
// Unsupported files
420
430
expectErrors(
421
- [() => import('./file.txt'), 'Unknown file extension'],
422
- [() => import(${ JSON . stringify ( wasmPathUrl ) } ), 'Unknown file extension'],
431
+ [() => import ('./file.txt'), 'Unknown file extension'],
432
+ [() => import (${ JSON . stringify ( wasmPathUrl ) } ), 'Unknown file extension'],
423
433
${
424
434
isCommonJs
425
435
? `
@@ -433,7 +443,7 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
433
443
? '[() => require(\'./broken-syntax\'), \'Transform failed\'],'
434
444
: ''
435
445
}
436
- [() => import('./broken-syntax'), 'Transform failed'],
446
+ [() => import ('./broken-syntax'), 'Transform failed'],
437
447
);
438
448
439
449
console.log(JSON.stringify({
@@ -510,7 +520,7 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
510
520
) } ;
511
521
512
522
// No double .default.default in Dynamic Import
513
- import('./js/index.js').then(m => {
523
+ import/* comment */ ('./js/index.js').then(m => {
514
524
if (typeof m.default === 'object') {
515
525
assert(
516
526
!('default' in m.default),
@@ -527,8 +537,8 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
527
537
// .cjs
528
538
import * as cjs from './cjs/index.cjs';
529
539
expectErrors(
530
- [() => import('./cjs/index'), 'Cannot find module'],
531
- [() => import('./cjs/'), 'Cannot find module'],
540
+ [() => import ('./cjs/index'), 'Cannot find module'],
541
+ [() => import ('./cjs/'), 'Cannot find module'],
532
542
${
533
543
isCommonJs
534
544
? `
@@ -542,8 +552,8 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
542
552
// .mjs
543
553
import * as mjs from './mjs/index.mjs';
544
554
expectErrors(
545
- [() => import('./mjs/index'), 'Cannot find module'],
546
- [() => import('./mjs/'), 'Cannot find module'],
555
+ [() => import ('./mjs/index'), 'Cannot find module'],
556
+ [() => import ('./mjs/'), 'Cannot find module'],
547
557
${
548
558
isCommonJs
549
559
? `
@@ -578,9 +588,9 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
578
588
import './cts/index.cjs';
579
589
expectErrors(
580
590
// TODO:
581
- // [() => import('./cts/index.cts'), 'Cannot find module'],
582
- [() => import('./cts/index'), 'Cannot find module'],
583
- [() => import('./cts/'), 'Cannot find module'],
591
+ // [() => import ('./cts/index.cts'), 'Cannot find module'],
592
+ [() => import ('./cts/index'), 'Cannot find module'],
593
+ [() => import ('./cts/'), 'Cannot find module'],
584
594
${
585
595
isCommonJs
586
596
? `
@@ -596,9 +606,9 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
596
606
import './mts/index.mjs';
597
607
expectErrors(
598
608
// TODO:
599
- // [() => import('./mts/index.mts'), 'Cannot find module'],
600
- [() => import('./mts/index'), 'Cannot find module'],
601
- [() => import('./mts/'), 'Cannot find module'],
609
+ // [() => import ('./mts/index.mts'), 'Cannot find module'],
610
+ [() => import ('./mts/index'), 'Cannot find module'],
611
+ [() => import ('./mts/'), 'Cannot find module'],
602
612
${
603
613
isCommonJs
604
614
? `
@@ -612,8 +622,8 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
612
622
613
623
// Unsupported files
614
624
expectErrors(
615
- [() => import('./file.txt'), 'Unknown file extension'],
616
- [() => import(${ JSON . stringify ( wasmPathUrl ) } ), 'Unknown file extension'],
625
+ [() => import ('./file.txt'), 'Unknown file extension'],
626
+ [() => import (${ JSON . stringify ( wasmPathUrl ) } ), 'Unknown file extension'],
617
627
${
618
628
isCommonJs
619
629
? `
@@ -627,7 +637,7 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
627
637
? '[() => require(\'./broken-syntax\'), \'Transform failed\'],'
628
638
: ''
629
639
}
630
- [() => import('./broken-syntax'), 'Transform failed'],
640
+ [() => import ('./broken-syntax'), 'Transform failed'],
631
641
);
632
642
633
643
console.log(JSON.stringify({
0 commit comments