File tree Expand file tree Collapse file tree 4 files changed +43
-13
lines changed
Expand file tree Collapse file tree 4 files changed +43
-13
lines changed Original file line number Diff line number Diff line change 1+ "use strict" ;
2+ // deno-lint-ignore no-var
3+ var __importDefault = ( this && this . __importDefault ) || function ( mod ) {
4+ return ( mod && mod . __esModule ) ? mod : { "default" : mod } ;
5+ } ;
6+ Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
7+ const assert_1 = __importDefault ( require ( "assert" ) ) ;
8+ ( 0 , assert_1 . default ) ( true ) ;
Original file line number Diff line number Diff line change 1+ import * as maxmind from "../../fixtures/maxmind.cjs" ;
2+
3+ export default function Page ( ) {
4+ // deno-lint-ignore no-console
5+ console . log ( maxmind ) ;
6+ return < h1 > maxmind</ h1 > ;
7+ }
Original file line number Diff line number Diff line change @@ -425,20 +425,24 @@ export function cjsPlugin(
425425 t . isIdentifier ( path . parentPath . node . callee ) &&
426426 path . parentPath . node . callee . name === "__importDefault"
427427 ) {
428- if (
429- BUILTINS . has ( source . value ) ||
430- source . value . startsWith ( "node:" )
431- ? BUILTINS . has ( source . value . slice ( "node:" . length ) )
432- : BUILTINS . has ( `node:${ source . value } ` )
433- ) {
434- path . replaceWith ( t . logicalExpression (
435- "??" ,
436- t . memberExpression (
437- t . cloneNode ( id , true ) ,
428+ if ( isNodeBuiltin ( source . value ) ) {
429+ path . replaceWith ( t . objectExpression ( [
430+ t . objectProperty (
431+ t . identifier ( "__esModule" ) ,
432+ t . booleanLiteral ( true ) ,
433+ ) ,
434+ t . objectProperty (
438435 t . identifier ( "default" ) ,
436+ t . logicalExpression (
437+ "??" ,
438+ t . memberExpression (
439+ t . cloneNode ( id , true ) ,
440+ t . identifier ( "default" ) ,
441+ ) ,
442+ t . cloneNode ( id , true ) ,
443+ ) ,
439444 ) ,
440- t . cloneNode ( id , true ) ,
441- ) ) ;
445+ ] ) ) ;
442446 } else {
443447 path . replaceWith ( t . cloneNode ( id , true ) ) ;
444448 }
@@ -786,3 +790,11 @@ function isObjEsModuleFlag(
786790 node . arguments [ 1 ] . value === "__esModule" &&
787791 t . isObjectExpression ( node . arguments [ 2 ] ) ;
788792}
793+
794+ function isNodeBuiltin ( specifier : string ) : boolean {
795+ return BUILTINS . has ( specifier ) || (
796+ specifier . startsWith ( "node:" )
797+ ? BUILTINS . has ( specifier . slice ( "node:" . length ) )
798+ : BUILTINS . has ( `node:${ specifier } ` )
799+ ) ;
800+ }
Original file line number Diff line number Diff line change @@ -720,6 +720,9 @@ var __importDefault = this && this.__importDefault || function (mod) {
720720 "default": mod
721721 };
722722};
723- const node_events_1 = __importDefault(_mod.default ?? _mod);` ,
723+ const node_events_1 = __importDefault({
724+ __esModule: true,
725+ default: _mod.default ?? _mod
726+ });` ,
724727 } ) ;
725728} ) ;
You can’t perform that action at this time.
0 commit comments