Browse Source

more robust interop

contingency-plan
Rich-Harris 10 years ago
parent
commit
688d66698a
  1. 10
      src/finalisers/shared/getInteropBlock.js
  2. 2
      test/form/external-imports-custom-names/_expected/amd.js
  3. 2
      test/form/external-imports-custom-names/_expected/iife.js
  4. 2
      test/form/external-imports-custom-names/_expected/umd.js
  5. 1
      test/form/external-imports/_expected/amd.js
  6. 1
      test/form/external-imports/_expected/iife.js
  7. 1
      test/form/external-imports/_expected/umd.js

10
src/finalisers/shared/getInteropBlock.js

@ -1,6 +1,12 @@
export default function getInteropBlock ( bundle ) {
return bundle.externalModules
.filter( module => module.needsDefault && module.needsNamed )
.map( module => `var ${module.name}__default = 'default' in ${module.name} ? ${module.name}['default'] : ${module.name};` )
.map( module => {
return module.needsDefault ?
( module.needsNamed ?
`var ${module.name}__default = 'default' in ${module.name} ? ${module.name}['default'] : ${module.name};` :
`${module.name} = 'default' in ${module.name} ? ${module.name}['default'] : ${module.name};` ) :
null;
})
.filter( Boolean )
.join( '\n' );
}

2
test/form/external-imports-custom-names/_expected/amd.js

@ -1,5 +1,7 @@
define(['jquery'], function ($) { 'use strict';
$ = 'default' in $ ? $['default'] : $;
$( function () {
$( 'body' ).html( '<h1>hello world!</h1>' );
});

2
test/form/external-imports-custom-names/_expected/iife.js

@ -1,5 +1,7 @@
(function ($) { 'use strict';
$ = 'default' in $ ? $['default'] : $;
$( function () {
$( 'body' ).html( '<h1>hello world!</h1>' );
});

2
test/form/external-imports-custom-names/_expected/umd.js

@ -4,6 +4,8 @@
factory(global.jQuery);
}(this, function ($) { 'use strict';
$ = 'default' in $ ? $['default'] : $;
$( function () {
$( 'body' ).html( '<h1>hello world!</h1>' );
});

1
test/form/external-imports/_expected/amd.js

@ -1,5 +1,6 @@
define(['factory', 'baz', 'shipping-port', 'alphabet'], function (factory, baz, containers, alphabet) { 'use strict';
factory = 'default' in factory ? factory['default'] : factory;
var alphabet__default = 'default' in alphabet ? alphabet['default'] : alphabet;
factory( null );

1
test/form/external-imports/_expected/iife.js

@ -1,5 +1,6 @@
(function (factory,baz,containers,alphabet) { 'use strict';
factory = 'default' in factory ? factory['default'] : factory;
var alphabet__default = 'default' in alphabet ? alphabet['default'] : alphabet;
factory( null );

1
test/form/external-imports/_expected/umd.js

@ -4,6 +4,7 @@
factory(global.factory,global.baz,global.containers,global.alphabet);
}(this, function (factory,baz,containers,alphabet) { 'use strict';
factory = 'default' in factory ? factory['default'] : factory;
var alphabet__default = 'default' in alphabet ? alphabet['default'] : alphabet;
factory( null );

Loading…
Cancel
Save