diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/wrapper-esm.js | 27 | ||||
-rw-r--r-- | src/wrapper-factory-esm.js | 33 | ||||
-rw-r--r-- | src/wrapper-factory.js | 38 | ||||
-rw-r--r-- | src/wrapper.js | 18 |
4 files changed, 84 insertions, 32 deletions
diff --git a/src/wrapper-esm.js b/src/wrapper-esm.js index 00ff2995c..a4574a3fa 100644 --- a/src/wrapper-esm.js +++ b/src/wrapper-esm.js @@ -10,22 +10,12 @@ */ // For ECMAScript module environments where a proper `window` // is present, execute the factory and get jQuery. -// For environments that do not have a `window` with a `document` -// (such as Node.js), expose a factory as module.exports. -// This accentuates the need for the creation of a real `window`. -// e.g. var jQuery = require("jquery")(window); -// See ticket trac-14549 for more info. -var jQueryOrJQueryFactory = typeof window !== "undefined" && window.document ? - jQueryFactory( window, true ) : - function( w ) { - if ( !w.document ) { - throw new Error( "jQuery requires a window with a document" ); - } - return jQueryFactory( w ); - }; - function jQueryFactory( window, noGlobal ) { +if ( typeof window === "undefined" || !window.document ) { + throw new Error( "jQuery requires a window with a document" ); +} + // @CODE // build.js inserts compiled jQuery here @@ -33,9 +23,8 @@ return jQuery; } -export { - jQueryOrJQueryFactory as jQuery, - jQueryOrJQueryFactory as $ -}; +var jQuery = jQueryFactory( window, true ); + +export { jQuery, jQuery as $ }; -export default jQueryOrJQueryFactory; +export default jQuery; diff --git a/src/wrapper-factory-esm.js b/src/wrapper-factory-esm.js new file mode 100644 index 000000000..9127d41e6 --- /dev/null +++ b/src/wrapper-factory-esm.js @@ -0,0 +1,33 @@ +/*! + * jQuery JavaScript Library v@VERSION + * https://jquery.com/ + * + * Copyright OpenJS Foundation and other contributors + * Released under the MIT license + * https://jquery.org/license + * + * Date: @DATE + */ +// Expose a factory as `jQueryFactory`. Aimed at environments without +// a real `window` where an emulated window needs to be constructed. Example: +// +// import { jQueryFactory } from "jquery/factory"; +// const jQuery = jQueryFactory( window ); +// +// See ticket trac-14549 for more info. +function jQueryFactoryWrapper( window, noGlobal ) { + +if ( !window.document ) { + throw new Error( "jQuery requires a window with a document" ); +} + +// @CODE +// build.js inserts compiled jQuery here + +return jQuery; + +} + +export function jQueryFactory( window ) { + return jQueryFactoryWrapper( window, true ); +} diff --git a/src/wrapper-factory.js b/src/wrapper-factory.js new file mode 100644 index 000000000..212ff33bf --- /dev/null +++ b/src/wrapper-factory.js @@ -0,0 +1,38 @@ +/*! + * jQuery JavaScript Library v@VERSION + * https://jquery.com/ + * + * Copyright OpenJS Foundation and other contributors + * Released under the MIT license + * https://jquery.org/license + * + * Date: @DATE + */ +// Expose a factory as `jQueryFactory`. Aimed at environments without +// a real `window` where an emulated window needs to be constructed. Example: +// +// const jQuery = require( "jquery/factory" )( window ); +// +// See ticket trac-14549 for more info. +function jQueryFactoryWrapper( window, noGlobal ) { + +"use strict"; + +if ( !window.document ) { + throw new Error( "jQuery requires a window with a document" ); +} + +// @CODE +// build.js inserts compiled jQuery here + +return jQuery; + +} + +function jQueryFactory( window ) { + "use strict"; + + return jQueryFactoryWrapper( window, true ); +} + +module.exports = { jQueryFactory: jQueryFactory }; diff --git a/src/wrapper.js b/src/wrapper.js index fa8240e1e..ce7637c63 100644 --- a/src/wrapper.js +++ b/src/wrapper.js @@ -16,19 +16,7 @@ // For CommonJS and CommonJS-like environments where a proper `window` // is present, execute the factory and get jQuery. - // For environments that do not have a `window` with a `document` - // (such as Node.js), expose a factory as module.exports. - // This accentuates the need for the creation of a real `window`. - // e.g. var jQuery = require("jquery")(window); - // See ticket trac-14549 for more info. - module.exports = global.document ? - factory( global, true ) : - function( w ) { - if ( !w.document ) { - throw new Error( "jQuery requires a window with a document" ); - } - return factory( w ); - }; + module.exports = factory( global, true ); } else { factory( global ); } @@ -38,6 +26,10 @@ "use strict"; +if ( !window.document ) { + throw new Error( "jQuery requires a window with a document" ); +} + // @CODE // build.js inserts compiled jQuery here |