Skip to content

Commit

Permalink
Update generated code of getInteropBlock() to work with null prototyp…
Browse files Browse the repository at this point in the history
…e objects (#3420)

Co-authored-by: Lukas Taegert-Atkinson <lukastaegert@users.noreply.github.com>
  • Loading branch information
jdalton and lukastaegert committed Mar 6, 2020
1 parent 85c54ee commit eeda078
Show file tree
Hide file tree
Showing 55 changed files with 76 additions and 55 deletions.
2 changes: 1 addition & 1 deletion src/finalisers/shared/getInteropBlock.ts
Expand Up @@ -20,7 +20,7 @@ export default function getInteropBlock(
}

return (
`${name}${_}=${_}${name}${_}&&${_}${name}.hasOwnProperty('default')${_}?` +
`${name}${_}=${_}${name}${_}&&${_}Object.prototype.hasOwnProperty.call(${name},${_}'default')${_}?` +
`${_}${name}['default']${_}:${_}${name};`
);
})
Expand Down
@@ -1,6 +1,6 @@
define(['exports', 'lib'], function (exports, value) { 'use strict';

value = value && value.hasOwnProperty('default') ? value['default'] : value;
value = value && Object.prototype.hasOwnProperty.call(value, 'default') ? value['default'] : value;

var dep = 2 * value;

Expand Down
@@ -1,6 +1,6 @@
define(['external'], function (external) { 'use strict';

external = external && external.hasOwnProperty('default') ? external['default'] : external;
external = external && Object.prototype.hasOwnProperty.call(external, 'default') ? external['default'] : external;



Expand Down
@@ -1,6 +1,6 @@
define(['exports', 'external', './other', './_virtual/_external_commonjs-external', './_virtual/other.js_commonjs-proxy'], function (exports, external, other, _external_commonjsExternal, other$1) { 'use strict';

external = external && external.hasOwnProperty('default') ? external['default'] : external;
external = external && Object.prototype.hasOwnProperty.call(external, 'default') ? external['default'] : external;

const { value } = other$1;

Expand Down
@@ -1,6 +1,6 @@
define(['external', './commonjs'], function (external, commonjs) { 'use strict';

external = external && external.hasOwnProperty('default') ? external['default'] : external;
external = external && Object.prototype.hasOwnProperty.call(external, 'default') ? external['default'] : external;

console.log(commonjs.default, external);

Expand Down
4 changes: 2 additions & 2 deletions test/form/samples/compact/_expected/amd.js
@@ -1,6 +1,6 @@
define(['external'],function(x){'use strict';x=x&&x.hasOwnProperty('default')?x['default']:x;var self=/*#__PURE__*/Object.freeze({[Symbol.toStringTag]:'Module',__proto__:null,get default(){return foo}});console.log(self);
define(['external'],function(x){'use strict';x=x&&Object.prototype.hasOwnProperty.call(x,'default')?x['default']:x;var self=/*#__PURE__*/Object.freeze({[Symbol.toStringTag]:'Module',__proto__:null,get default(){return foo}});console.log(self);
function foo () {
console.log( x );
}
// trailing comment
return foo;});
return foo;});
4 changes: 2 additions & 2 deletions test/form/samples/compact/_expected/iife.js
@@ -1,6 +1,6 @@
var foo=(function(x){'use strict';x=x&&x.hasOwnProperty('default')?x['default']:x;var self=/*#__PURE__*/Object.freeze({[Symbol.toStringTag]:'Module',__proto__:null,get default(){return foo}});console.log(self);
var foo=(function(x){'use strict';x=x&&Object.prototype.hasOwnProperty.call(x,'default')?x['default']:x;var self=/*#__PURE__*/Object.freeze({[Symbol.toStringTag]:'Module',__proto__:null,get default(){return foo}});console.log(self);
function foo () {
console.log( x );
}
// trailing comment
return foo;}(x));
return foo;}(x));
2 changes: 1 addition & 1 deletion test/form/samples/compact/_expected/umd.js
@@ -1,4 +1,4 @@
(function(g,f){typeof exports==='object'&&typeof module!=='undefined'?module.exports=f(require('external')):typeof define==='function'&&define.amd?define(['external'],f):(g=g||self,g.foo=f(g.x));}(this,(function(x){'use strict';x=x&&x.hasOwnProperty('default')?x['default']:x;var self=/*#__PURE__*/Object.freeze({[Symbol.toStringTag]:'Module',__proto__:null,get default(){return foo}});console.log(self);
(function(g,f){typeof exports==='object'&&typeof module!=='undefined'?module.exports=f(require('external')):typeof define==='function'&&define.amd?define(['external'],f):(g=g||self,g.foo=f(g.x));}(this,(function(x){'use strict';x=x&&Object.prototype.hasOwnProperty.call(x,'default')?x['default']:x;var self=/*#__PURE__*/Object.freeze({[Symbol.toStringTag]:'Module',__proto__:null,get default(){return foo}});console.log(self);
function foo () {
console.log( x );
}
Expand Down
Expand Up @@ -19,7 +19,7 @@ define(['module', 'require', 'external'], function (module, require, external) {
}
}

external = external && external.hasOwnProperty('default') ? external['default'] : external;
external = external && Object.prototype.hasOwnProperty.call(external, 'default') ? external['default'] : external;

console.log(external);

Expand Down
@@ -1,7 +1,7 @@
var bundle = (function (external) {
'use strict';

external = external && external.hasOwnProperty('default') ? external['default'] : external;
external = external && Object.prototype.hasOwnProperty.call(external, 'default') ? external['default'] : external;

console.log(external);

Expand Down
Expand Up @@ -4,7 +4,7 @@
(global = global || self, global.bundle = factory(global.external));
}(this, (function (external) { 'use strict';

external = external && external.hasOwnProperty('default') ? external['default'] : external;
external = external && Object.prototype.hasOwnProperty.call(external, 'default') ? external['default'] : external;

console.log(external);

Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/export-default-import/_expected/amd.js
@@ -1,6 +1,6 @@
define(['exports', 'x'], function (exports, x) { 'use strict';

x = x && x.hasOwnProperty('default') ? x['default'] : x;
x = x && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;



Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/export-default-import/_expected/iife.js
@@ -1,7 +1,7 @@
var myBundle = (function (exports, x) {
'use strict';

x = x && x.hasOwnProperty('default') ? x['default'] : x;
x = x && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;



Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/export-default-import/_expected/umd.js
Expand Up @@ -4,7 +4,7 @@
(global = global || self, factory(global.myBundle = {}, global.x));
}(this, (function (exports, x) { 'use strict';

x = x && x.hasOwnProperty('default') ? x['default'] : x;
x = x && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;



Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/external-deshadowing/_expected/amd.js
@@ -1,6 +1,6 @@
define(['exports', 'a', 'b'], function (exports, a, Test$1) { 'use strict';

Test$1 = Test$1 && Test$1.hasOwnProperty('default') ? Test$1['default'] : Test$1;
Test$1 = Test$1 && Object.prototype.hasOwnProperty.call(Test$1, 'default') ? Test$1['default'] : Test$1;

const Test = () => {
console.log(a.Test);
Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/external-deshadowing/_expected/iife.js
@@ -1,7 +1,7 @@
var myBundle = (function (exports, a, Test$1) {
'use strict';

Test$1 = Test$1 && Test$1.hasOwnProperty('default') ? Test$1['default'] : Test$1;
Test$1 = Test$1 && Object.prototype.hasOwnProperty.call(Test$1, 'default') ? Test$1['default'] : Test$1;

const Test = () => {
console.log(a.Test);
Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/external-deshadowing/_expected/umd.js
Expand Up @@ -4,7 +4,7 @@
(global = global || self, factory(global.myBundle = {}, global.a, global.b));
}(this, (function (exports, a, Test$1) { 'use strict';

Test$1 = Test$1 && Test$1.hasOwnProperty('default') ? Test$1['default'] : Test$1;
Test$1 = Test$1 && Object.prototype.hasOwnProperty.call(Test$1, 'default') ? Test$1['default'] : Test$1;

const Test = () => {
console.log(a.Test);
Expand Down
@@ -1,6 +1,6 @@
define(['jquery'], function ($) { 'use strict';

$ = $ && $.hasOwnProperty('default') ? $['default'] : $;
$ = $ && Object.prototype.hasOwnProperty.call($, 'default') ? $['default'] : $;

$( function () {
$( 'body' ).html( '<h1>hello world!</h1>' );
Expand Down
@@ -1,7 +1,7 @@
(function ($) {
'use strict';

$ = $ && $.hasOwnProperty('default') ? $['default'] : $;
$ = $ && Object.prototype.hasOwnProperty.call($, 'default') ? $['default'] : $;

$( function () {
$( 'body' ).html( '<h1>hello world!</h1>' );
Expand Down
Expand Up @@ -4,7 +4,7 @@
(global = global || self, factory(global.jQuery));
}(this, (function ($) { 'use strict';

$ = $ && $.hasOwnProperty('default') ? $['default'] : $;
$ = $ && Object.prototype.hasOwnProperty.call($, 'default') ? $['default'] : $;

$( function () {
$( 'body' ).html( '<h1>hello world!</h1>' );
Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/external-imports/_expected/amd.js
@@ -1,6 +1,6 @@
define(['factory', 'baz', 'shipping-port', 'alphabet'], function (factory, baz, containers, alphabet) { 'use strict';

factory = factory && factory.hasOwnProperty('default') ? factory['default'] : factory;
factory = factory && Object.prototype.hasOwnProperty.call(factory, 'default') ? factory['default'] : factory;
var alphabet__default = 'default' in alphabet ? alphabet['default'] : alphabet;

factory( null );
Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/external-imports/_expected/iife.js
@@ -1,7 +1,7 @@
(function (factory, baz, containers, alphabet) {
'use strict';

factory = factory && factory.hasOwnProperty('default') ? factory['default'] : factory;
factory = factory && Object.prototype.hasOwnProperty.call(factory, 'default') ? factory['default'] : factory;
var alphabet__default = 'default' in alphabet ? alphabet['default'] : alphabet;

factory( null );
Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/external-imports/_expected/umd.js
Expand Up @@ -4,7 +4,7 @@
(global = global || self, factory(global.factory, global.baz, global.containers, global.alphabet));
}(this, (function (factory, baz, containers, alphabet) { 'use strict';

factory = factory && factory.hasOwnProperty('default') ? factory['default'] : factory;
factory = factory && Object.prototype.hasOwnProperty.call(factory, 'default') ? factory['default'] : factory;
var alphabet__default = 'default' in alphabet ? alphabet['default'] : alphabet;

factory( null );
Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/guessed-global-names/_expected/amd.js
@@ -1,6 +1,6 @@
define(['unchanged', 'changed', 'special-character', 'with/slash', './relative'], function (unchanged, changedName, specialCharacter, slash, relative_js) { 'use strict';

changedName = changedName && changedName.hasOwnProperty('default') ? changedName['default'] : changedName;
changedName = changedName && Object.prototype.hasOwnProperty.call(changedName, 'default') ? changedName['default'] : changedName;

console.log(unchanged.foo, changedName, specialCharacter.bar, slash.baz, relative_js.quux);

Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/guessed-global-names/_expected/iife.js
@@ -1,7 +1,7 @@
(function (unchanged, changedName, specialCharacter, slash, relative_js) {
'use strict';

changedName = changedName && changedName.hasOwnProperty('default') ? changedName['default'] : changedName;
changedName = changedName && Object.prototype.hasOwnProperty.call(changedName, 'default') ? changedName['default'] : changedName;

console.log(unchanged.foo, changedName, specialCharacter.bar, slash.baz, relative_js.quux);

Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/guessed-global-names/_expected/umd.js
Expand Up @@ -4,7 +4,7 @@
(global = global || self, factory(global.unchanged, global.changedName, global.specialCharacter, global.slash, global.relative_js));
}(this, (function (unchanged, changedName, specialCharacter, slash, relative_js) { 'use strict';

changedName = changedName && changedName.hasOwnProperty('default') ? changedName['default'] : changedName;
changedName = changedName && Object.prototype.hasOwnProperty.call(changedName, 'default') ? changedName['default'] : changedName;

console.log(unchanged.foo, changedName, specialCharacter.bar, slash.baz, relative_js.quux);

Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/paths-function/_expected/amd.js
@@ -1,6 +1,6 @@
define(['https://unpkg.com/foo'], function (foo) { 'use strict';

foo = foo && foo.hasOwnProperty('default') ? foo['default'] : foo;
foo = foo && Object.prototype.hasOwnProperty.call(foo, 'default') ? foo['default'] : foo;

assert.equal( foo, 42 );

Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/paths-function/_expected/iife.js
@@ -1,7 +1,7 @@
(function (foo) {
'use strict';

foo = foo && foo.hasOwnProperty('default') ? foo['default'] : foo;
foo = foo && Object.prototype.hasOwnProperty.call(foo, 'default') ? foo['default'] : foo;

assert.equal( foo, 42 );

Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/paths-function/_expected/umd.js
Expand Up @@ -4,7 +4,7 @@
(global = global || self, factory(global.foo));
}(this, (function (foo) { 'use strict';

foo = foo && foo.hasOwnProperty('default') ? foo['default'] : foo;
foo = foo && Object.prototype.hasOwnProperty.call(foo, 'default') ? foo['default'] : foo;

assert.equal( foo, 42 );

Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/paths-relative/_expected/amd.js
@@ -1,6 +1,6 @@
define(['../foo'], function (foo) { 'use strict';

foo = foo && foo.hasOwnProperty('default') ? foo['default'] : foo;
foo = foo && Object.prototype.hasOwnProperty.call(foo, 'default') ? foo['default'] : foo;

assert.equal( foo, 42 );

Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/paths-relative/_expected/iife.js
@@ -1,7 +1,7 @@
(function (foo) {
'use strict';

foo = foo && foo.hasOwnProperty('default') ? foo['default'] : foo;
foo = foo && Object.prototype.hasOwnProperty.call(foo, 'default') ? foo['default'] : foo;

assert.equal( foo, 42 );

Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/paths-relative/_expected/umd.js
Expand Up @@ -4,7 +4,7 @@
(global = global || self, factory(global.foo));
}(this, (function (foo) { 'use strict';

foo = foo && foo.hasOwnProperty('default') ? foo['default'] : foo;
foo = foo && Object.prototype.hasOwnProperty.call(foo, 'default') ? foo['default'] : foo;

assert.equal( foo, 42 );

Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/paths/_expected/amd.js
@@ -1,6 +1,6 @@
define(['https://unpkg.com/foo'], function (foo) { 'use strict';

foo = foo && foo.hasOwnProperty('default') ? foo['default'] : foo;
foo = foo && Object.prototype.hasOwnProperty.call(foo, 'default') ? foo['default'] : foo;

assert.equal( foo, 42 );

Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/paths/_expected/iife.js
@@ -1,7 +1,7 @@
(function (foo) {
'use strict';

foo = foo && foo.hasOwnProperty('default') ? foo['default'] : foo;
foo = foo && Object.prototype.hasOwnProperty.call(foo, 'default') ? foo['default'] : foo;

assert.equal( foo, 42 );

Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/paths/_expected/umd.js
Expand Up @@ -4,7 +4,7 @@
(global = global || self, factory(global.foo));
}(this, (function (foo) { 'use strict';

foo = foo && foo.hasOwnProperty('default') ? foo['default'] : foo;
foo = foo && Object.prototype.hasOwnProperty.call(foo, 'default') ? foo['default'] : foo;

assert.equal( foo, 42 );

Expand Down
@@ -1,6 +1,6 @@
define(['exports', 'external'], function (exports, external) { 'use strict';

external = external && external.hasOwnProperty('default') ? external['default'] : external;
external = external && Object.prototype.hasOwnProperty.call(external, 'default') ? external['default'] : external;

const value = 42;

Expand Down
@@ -1,7 +1,7 @@
var bundle = (function (exports, external) {
'use strict';

external = external && external.hasOwnProperty('default') ? external['default'] : external;
external = external && Object.prototype.hasOwnProperty.call(external, 'default') ? external['default'] : external;

const value = 42;

Expand Down
Expand Up @@ -4,7 +4,7 @@
(global = global || self, factory(global.bundle = {}, global.external));
}(this, (function (exports, external) { 'use strict';

external = external && external.hasOwnProperty('default') ? external['default'] : external;
external = external && Object.prototype.hasOwnProperty.call(external, 'default') ? external['default'] : external;

const value = 42;

Expand Down
@@ -1,6 +1,6 @@
define(['external1', 'external2'], function (external1, external2) { 'use strict';

external2 = external2 && external2.hasOwnProperty('default') ? external2['default'] : external2;
external2 = external2 && Object.prototype.hasOwnProperty.call(external2, 'default') ? external2['default'] : external2;

console.log(external1.foo);

Expand Down
@@ -1,7 +1,7 @@
var bundle = (function (external1, external2) {
'use strict';

external2 = external2 && external2.hasOwnProperty('default') ? external2['default'] : external2;
external2 = external2 && Object.prototype.hasOwnProperty.call(external2, 'default') ? external2['default'] : external2;

console.log(external1.foo);

Expand Down
Expand Up @@ -4,7 +4,7 @@
(global = global || self, global.bundle = factory(global.external1, global.external2));
}(this, (function (external1, external2) { 'use strict';

external2 = external2 && external2.hasOwnProperty('default') ? external2['default'] : external2;
external2 = external2 && Object.prototype.hasOwnProperty.call(external2, 'default') ? external2['default'] : external2;

console.log(external1.foo);

Expand Down
@@ -1,6 +1,6 @@
define(['./lib/throttle'], function (throttle) { 'use strict';

throttle = throttle && throttle.hasOwnProperty('default') ? throttle['default'] : throttle;
throttle = throttle && Object.prototype.hasOwnProperty.call(throttle, 'default') ? throttle['default'] : throttle;

const fn = throttle( () => {
console.log( '.' );
Expand Down
@@ -1,7 +1,7 @@
(function (throttle) {
'use strict';

throttle = throttle && throttle.hasOwnProperty('default') ? throttle['default'] : throttle;
throttle = throttle && Object.prototype.hasOwnProperty.call(throttle, 'default') ? throttle['default'] : throttle;

const fn = throttle( () => {
console.log( '.' );
Expand Down
Expand Up @@ -4,7 +4,7 @@
(global = global || self, factory(global.Lib.throttle));
}(this, (function (throttle) { 'use strict';

throttle = throttle && throttle.hasOwnProperty('default') ? throttle['default'] : throttle;
throttle = throttle && Object.prototype.hasOwnProperty.call(throttle, 'default') ? throttle['default'] : throttle;

const fn = throttle( () => {
console.log( '.' );
Expand Down
Expand Up @@ -19,7 +19,7 @@ define(['require', 'exports', 'external'], function (require, exports, myExterna
}
}

myExternal = myExternal && myExternal.hasOwnProperty('default') ? myExternal['default'] : myExternal;
myExternal = myExternal && Object.prototype.hasOwnProperty.call(myExternal, 'default') ? myExternal['default'] : myExternal;

const test = () => myExternal;

Expand Down
@@ -1,7 +1,7 @@
var bundle = (function (exports, myExternal) {
'use strict';

myExternal = myExternal && myExternal.hasOwnProperty('default') ? myExternal['default'] : myExternal;
myExternal = myExternal && Object.prototype.hasOwnProperty.call(myExternal, 'default') ? myExternal['default'] : myExternal;

const test = () => myExternal;

Expand Down

0 comments on commit eeda078

Please sign in to comment.