Browse Source

guard against undefined `this` in post-processed UMD bundle - fixes #109

gh-109
Rich-Harris 9 years ago
parent
commit
5ff55bf7c7
  1. 2
      src/finalisers/umd.js
  2. 2
      test/cli/module-name/_expected.js
  3. 2
      test/form/banner-and-footer/_expected/umd.js
  4. 2
      test/form/block-comments/_expected/umd.js
  5. 2
      test/form/dedupes-external-imports/_expected/umd.js
  6. 2
      test/form/exclude-unnecessary-modifications/_expected/umd.js
  7. 2
      test/form/export-all-from-internal/_expected/umd.js
  8. 2
      test/form/export-default/_expected/umd.js
  9. 2
      test/form/exports-at-end-if-possible/_expected/umd.js
  10. 2
      test/form/external-imports-custom-names/_expected/umd.js
  11. 2
      test/form/external-imports/_expected/umd.js
  12. 2
      test/form/indent-false/_expected/umd.js
  13. 2
      test/form/indent-true-spaces/_expected/umd.js
  14. 2
      test/form/indent-true/_expected/umd.js
  15. 2
      test/form/internal-conflict-resolution/_expected/umd.js
  16. 2
      test/form/multiple-exports/_expected/umd.js
  17. 2
      test/form/namespace-optimization/_expected/umd.js
  18. 2
      test/form/no-imports-or-exports/_expected/umd.js
  19. 2
      test/form/preserves-comments-after-imports/_expected/umd.js
  20. 2
      test/form/removes-existing-sourcemap-comments/_expected/umd.js
  21. 2
      test/form/self-contained-bundle/_expected/umd.js
  22. 2
      test/form/sourcemaps-inline/_expected/umd.js
  23. 2
      test/form/sourcemaps/_expected/umd.js
  24. 2
      test/form/unmodified-default-exports-function-argument/_expected/umd.js
  25. 2
      test/form/unmodified-default-exports/_expected/umd.js
  26. 2
      test/form/unused-default-exports/_expected/umd.js
  27. 2
      test/form/unused-side-effect/_expected/umd.js

2
src/finalisers/umd.js

@ -40,7 +40,7 @@ export default function umd ( bundle, magicString, { exportMode, indentString },
typeof exports === 'object' && typeof module !== 'undefined' ? ${cjsExport}factory(${cjsDeps.join( ', ' )}) : typeof exports === 'object' && typeof module !== 'undefined' ? ${cjsExport}factory(${cjsDeps.join( ', ' )}) :
typeof define === 'function' && define.amd ? define(${amdParams}factory) : typeof define === 'function' && define.amd ? define(${amdParams}factory) :
${defaultExport}factory(${globalDeps}); ${defaultExport}factory(${globalDeps});
}(this, function (${args}) {${useStrict} }(this || (typeof window !== 'undefined' && window), function (${args}) {${useStrict}
`.replace( /^\t\t/gm, '' ).replace( /^\t/gm, magicString.getIndentString() ); `.replace( /^\t\t/gm, '' ).replace( /^\t/gm, magicString.getIndentString() );

2
test/cli/module-name/_expected.js

@ -2,7 +2,7 @@
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) : typeof define === 'function' && define.amd ? define(factory) :
global.myBundle = factory(); global.myBundle = factory();
}(this, function () { 'use strict'; }(this || (typeof window !== 'undefined' && window), function () { 'use strict';
var main = 42; var main = 42;

2
test/form/banner-and-footer/_expected/umd.js

@ -3,7 +3,7 @@
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) : typeof define === 'function' && define.amd ? define(factory) :
factory(); factory();
}(this, function () { 'use strict'; }(this || (typeof window !== 'undefined' && window), function () { 'use strict';
console.log( 'hello world' ); console.log( 'hello world' );

2
test/form/block-comments/_expected/umd.js

@ -2,7 +2,7 @@
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) : typeof define === 'function' && define.amd ? define(factory) :
factory(); factory();
}(this, function () { 'use strict'; }(this || (typeof window !== 'undefined' && window), function () { 'use strict';
function foo () { function foo () {
return embiggen( 6, 7 ); return embiggen( 6, 7 );

2
test/form/dedupes-external-imports/_expected/umd.js

@ -2,7 +2,7 @@
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('external')) : typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('external')) :
typeof define === 'function' && define.amd ? define(['external'], factory) : typeof define === 'function' && define.amd ? define(['external'], factory) :
factory(global.external); factory(global.external);
}(this, function (external) { 'use strict'; }(this || (typeof window !== 'undefined' && window), function (external) { 'use strict';
class Foo extends external.Component { class Foo extends external.Component {
constructor () { constructor () {

2
test/form/exclude-unnecessary-modifications/_expected/umd.js

@ -2,7 +2,7 @@
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) : typeof define === 'function' && define.amd ? define(factory) :
factory(); factory();
}(this, function () { 'use strict'; }(this || (typeof window !== 'undefined' && window), function () { 'use strict';
var foo = {}; var foo = {};

2
test/form/export-all-from-internal/_expected/umd.js

@ -2,7 +2,7 @@
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) : typeof define === 'function' && define.amd ? define(['exports'], factory) :
factory((global.exposedInternals = {})); factory((global.exposedInternals = {}));
}(this, function (exports) { 'use strict'; }(this || (typeof window !== 'undefined' && window), function (exports) { 'use strict';
const a = 1; const a = 1;
const b = 2; const b = 2;

2
test/form/export-default/_expected/umd.js

@ -2,7 +2,7 @@
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) : typeof define === 'function' && define.amd ? define(factory) :
global.myBundle = factory(); global.myBundle = factory();
}(this, function () { 'use strict'; }(this || (typeof window !== 'undefined' && window), function () { 'use strict';
var main = 42; var main = 42;

2
test/form/exports-at-end-if-possible/_expected/umd.js

@ -2,7 +2,7 @@
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) : typeof define === 'function' && define.amd ? define(['exports'], factory) :
factory((global.myBundle = {})); factory((global.myBundle = {}));
}(this, function (exports) { 'use strict'; }(this || (typeof window !== 'undefined' && window), function (exports) { 'use strict';
var FOO = 'foo'; var FOO = 'foo';

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

@ -2,7 +2,7 @@
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('jquery')) : typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('jquery')) :
typeof define === 'function' && define.amd ? define(['jquery'], factory) : typeof define === 'function' && define.amd ? define(['jquery'], factory) :
factory(global.jQuery); factory(global.jQuery);
}(this, function ($) { 'use strict'; }(this || (typeof window !== 'undefined' && window), function ($) { 'use strict';
$ = 'default' in $ ? $['default'] : $; $ = 'default' in $ ? $['default'] : $;

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

@ -2,7 +2,7 @@
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('factory'), require('baz'), require('shipping-port'), require('alphabet')) : typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('factory'), require('baz'), require('shipping-port'), require('alphabet')) :
typeof define === 'function' && define.amd ? define(['factory', 'baz', 'shipping-port', 'alphabet'], factory) : typeof define === 'function' && define.amd ? define(['factory', 'baz', 'shipping-port', 'alphabet'], factory) :
factory(global.factory,global.baz,global.containers,global.alphabet); factory(global.factory,global.baz,global.containers,global.alphabet);
}(this, function (factory,baz,containers,alphabet) { 'use strict'; }(this || (typeof window !== 'undefined' && window), function (factory,baz,containers,alphabet) { 'use strict';
factory = 'default' in factory ? factory['default'] : factory; factory = 'default' in factory ? factory['default'] : factory;
var alphabet__default = 'default' in alphabet ? alphabet['default'] : alphabet; var alphabet__default = 'default' in alphabet ? alphabet['default'] : alphabet;

2
test/form/indent-false/_expected/umd.js

@ -2,7 +2,7 @@
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) : typeof define === 'function' && define.amd ? define(factory) :
global.foo = factory(); global.foo = factory();
}(this, function () { 'use strict'; }(this || (typeof window !== 'undefined' && window), function () { 'use strict';
function foo () { function foo () {
console.log( 'indented with tabs' ); console.log( 'indented with tabs' );

2
test/form/indent-true-spaces/_expected/umd.js

@ -2,7 +2,7 @@
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) : typeof define === 'function' && define.amd ? define(factory) :
global.foo = factory(); global.foo = factory();
}(this, function () { 'use strict'; }(this || (typeof window !== 'undefined' && window), function () { 'use strict';
function foo () { function foo () {
console.log( 'indented with spaces' ); console.log( 'indented with spaces' );

2
test/form/indent-true/_expected/umd.js

@ -2,7 +2,7 @@
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) : typeof define === 'function' && define.amd ? define(factory) :
global.foo = factory(); global.foo = factory();
}(this, function () { 'use strict'; }(this || (typeof window !== 'undefined' && window), function () { 'use strict';
function foo () { function foo () {
console.log( 'indented with tabs' ); console.log( 'indented with tabs' );

2
test/form/internal-conflict-resolution/_expected/umd.js

@ -2,7 +2,7 @@
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) : typeof define === 'function' && define.amd ? define(factory) :
factory(); factory();
}(this, function () { 'use strict'; }(this || (typeof window !== 'undefined' && window), function () { 'use strict';
var bar = 42; var bar = 42;

2
test/form/multiple-exports/_expected/umd.js

@ -2,7 +2,7 @@
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) : typeof define === 'function' && define.amd ? define(['exports'], factory) :
factory((global.myBundle = {})); factory((global.myBundle = {}));
}(this, function (exports) { 'use strict'; }(this || (typeof window !== 'undefined' && window), function (exports) { 'use strict';
var foo = 1; var foo = 1;
var bar = 2; var bar = 2;

2
test/form/namespace-optimization/_expected/umd.js

@ -2,7 +2,7 @@
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) : typeof define === 'function' && define.amd ? define(factory) :
factory(); factory();
}(this, function () { 'use strict'; }(this || (typeof window !== 'undefined' && window), function () { 'use strict';
function a () {} function a () {}

2
test/form/no-imports-or-exports/_expected/umd.js

@ -2,7 +2,7 @@
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) : typeof define === 'function' && define.amd ? define(factory) :
factory(); factory();
}(this, function () { 'use strict'; }(this || (typeof window !== 'undefined' && window), function () { 'use strict';
console.log( 'this is it' ); console.log( 'this is it' );

2
test/form/preserves-comments-after-imports/_expected/umd.js

@ -2,7 +2,7 @@
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) : typeof define === 'function' && define.amd ? define(['exports'], factory) :
factory((global.myBundle = {})); factory((global.myBundle = {}));
}(this, function (exports) { 'use strict'; }(this || (typeof window !== 'undefined' && window), function (exports) { 'use strict';
/** A comment for a number */ /** A comment for a number */
var number = 5; var number = 5;

2
test/form/removes-existing-sourcemap-comments/_expected/umd.js

@ -2,7 +2,7 @@
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) : typeof define === 'function' && define.amd ? define(factory) :
factory(); factory();
}(this, function () { 'use strict'; }(this || (typeof window !== 'undefined' && window), function () { 'use strict';
function foo () { function foo () {
return 42; return 42;

2
test/form/self-contained-bundle/_expected/umd.js

@ -2,7 +2,7 @@
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) : typeof define === 'function' && define.amd ? define(factory) :
factory(); factory();
}(this, function () { 'use strict'; }(this || (typeof window !== 'undefined' && window), function () { 'use strict';
function foo () { function foo () {
return bar(); return bar();

2
test/form/sourcemaps-inline/_expected/umd.js

@ -2,7 +2,7 @@
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) : typeof define === 'function' && define.amd ? define(factory) :
factory(); factory();
}(this, function () { 'use strict'; }(this || (typeof window !== 'undefined' && window), function () { 'use strict';
function foo () { function foo () {
console.log( 'hello from foo.js' ); console.log( 'hello from foo.js' );

2
test/form/sourcemaps/_expected/umd.js

@ -2,7 +2,7 @@
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) : typeof define === 'function' && define.amd ? define(factory) :
factory(); factory();
}(this, function () { 'use strict'; }(this || (typeof window !== 'undefined' && window), function () { 'use strict';
function foo () { function foo () {
console.log( 'hello from foo.js' ); console.log( 'hello from foo.js' );

2
test/form/unmodified-default-exports-function-argument/_expected/umd.js

@ -2,7 +2,7 @@
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) : typeof define === 'function' && define.amd ? define(factory) :
factory(); factory();
}(this, function () { 'use strict'; }(this || (typeof window !== 'undefined' && window), function () { 'use strict';
var foo = function () { var foo = function () {
return 42; return 42;

2
test/form/unmodified-default-exports/_expected/umd.js

@ -2,7 +2,7 @@
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) : typeof define === 'function' && define.amd ? define(factory) :
factory(); factory();
}(this, function () { 'use strict'; }(this || (typeof window !== 'undefined' && window), function () { 'use strict';
var Foo = function () { var Foo = function () {
this.isFoo = true; this.isFoo = true;

2
test/form/unused-default-exports/_expected/umd.js

@ -2,7 +2,7 @@
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) : typeof define === 'function' && define.amd ? define(factory) :
factory(); factory();
}(this, function () { 'use strict'; }(this || (typeof window !== 'undefined' && window), function () { 'use strict';
var foo = { value: 1 }; var foo = { value: 1 };

2
test/form/unused-side-effect/_expected/umd.js

@ -2,7 +2,7 @@
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) : typeof define === 'function' && define.amd ? define(factory) :
factory(); factory();
}(this, function () { 'use strict'; }(this || (typeof window !== 'undefined' && window), function () { 'use strict';
var foo = 42; var foo = 42;

Loading…
Cancel
Save