@@ -517,6 +517,39 @@ describe ('API: Plugin Hooks', () => {
517517 fs . reset ( ) ;
518518 } ) ;
519519
520+ it ( 'should should accept a string for syntheticNamedExports' , async ( ) => {
521+ fs . stub ( './src/main.js' , ( ) => 'export { hello } from "./lol";' ) ;
522+ fs . stub ( './src/lol.js' , ( ) => 'export var __moduleExports = { hello: "world" };' )
523+ let phase = 0 ;
524+
525+ let bundle = await nollup ( {
526+ input : './src/main.js' ,
527+ plugins : [ {
528+ load ( id ) {
529+ if ( id . indexOf ( 'lol' ) > - 1 ) {
530+ return {
531+ code : fs . readFileSync ( id , 'utf8' ) ,
532+ syntheticNamedExports : phase === 0 ? false : '__moduleExports'
533+ }
534+ }
535+
536+ }
537+ } ]
538+ } ) ;
539+
540+ let output = ( await bundle . generate ( { format : 'iife' } ) ) . output ;
541+ let result = eval ( output [ 0 ] . code ) ;
542+ expect ( result . hello ) . to . be . undefined ;
543+
544+ phase = 1 ;
545+ bundle . invalidate ( './src/lol.js' ) ;
546+ output = ( await bundle . generate ( { format : 'iife' } ) ) . output ;
547+ result = eval ( output [ 0 ] . code ) ;
548+ expect ( result . hello ) . to . equal ( 'world' ) ;
549+
550+ fs . reset ( ) ;
551+ } ) ;
552+
520553 it ( 'should be allowed to return an AST' ) ;
521554 } ) ;
522555
@@ -715,6 +748,40 @@ describe ('API: Plugin Hooks', () => {
715748 fs . reset ( ) ;
716749 } ) ;
717750
751+ it ( 'should allow string for syntheticNamedExports' , async ( ) => {
752+ fs . stub ( './src/main.js' , ( ) => 'export { hello } from "./lol";' ) ;
753+ fs . stub ( './src/lol.js' , ( ) => 'export var __moduleExports = { hello: "world" };' )
754+ let phase = 0 ;
755+
756+ let bundle = await nollup ( {
757+ input : './src/main.js' ,
758+ plugins : [ {
759+ resolveId ( id ) {
760+ if ( id . indexOf ( 'lol' ) > - 1 ) {
761+ return {
762+ id : path . resolve ( process . cwd ( ) , './src/lol.js' ) ,
763+ syntheticNamedExports : phase === 0 ? false : '__moduleExports'
764+ }
765+ }
766+
767+ }
768+ } ]
769+ } ) ;
770+
771+ let output = ( await bundle . generate ( { format : 'iife' } ) ) . output ;
772+ let result = eval ( output [ 0 ] . code ) ;
773+ expect ( result . hello ) . to . be . undefined ;
774+
775+ phase = 1 ;
776+ bundle . invalidate ( './src/lol.js' ) ;
777+ bundle . invalidate ( './src/main.js' ) ;
778+ output = ( await bundle . generate ( { format : 'iife' } ) ) . output ;
779+ result = eval ( output [ 0 ] . code ) ;
780+ expect ( result . hello ) . to . equal ( 'world' ) ;
781+
782+ fs . reset ( ) ;
783+ } ) ;
784+
718785 it ( 'should trigger for input file' , async ( ) => {
719786 fs . stub ( './src/main.js' , ( ) => 'console.log(123)' ) ;
720787
@@ -1179,6 +1246,41 @@ describe ('API: Plugin Hooks', () => {
11791246 fs . reset ( ) ;
11801247 } ) ;
11811248
1249+ it ( 'should allow strings for syntheticNamedExports' , async ( ) => {
1250+ fs . stub ( './src/main.js' , ( ) => `
1251+ export { hello } from './lol'
1252+ ` ) ;
1253+ fs . stub ( './src/lol.js' , ( ) => 'export var __moduleExports = { hello: "world" };' )
1254+ let phase = 0 ;
1255+
1256+ let bundle = await nollup ( {
1257+ input : './src/main.js' ,
1258+ plugins : [ {
1259+ transform ( code , id ) {
1260+ if ( id . indexOf ( 'lol' ) > - 1 ) {
1261+ return {
1262+ code,
1263+ syntheticNamedExports : phase === 0 ? false : '__moduleExports'
1264+ }
1265+ }
1266+
1267+ }
1268+ } ]
1269+ } ) ;
1270+
1271+ let output = ( await bundle . generate ( { format : 'iife' } ) ) . output ;
1272+ let result = eval ( output [ 0 ] . code ) ;
1273+ expect ( result . hello ) . to . be . undefined ;
1274+
1275+ phase = 1 ;
1276+ bundle . invalidate ( './src/lol.js' ) ;
1277+ output = ( await bundle . generate ( { format : 'iife' } ) ) . output ;
1278+ result = eval ( output [ 0 ] . code ) ;
1279+ expect ( result . hello ) . to . equal ( 'world' ) ;
1280+
1281+ fs . reset ( ) ;
1282+ } ) ;
1283+
11821284 it ( 'should not fail if passing null sourcemap' ) ;
11831285
11841286 it ( 'should accept an object with code and map returned' ) ;
0 commit comments