From d0ce00cdfa680f1f0c38460bc51ea14079ae8b07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Go=C5=82=C4=99biowski-Owczarek?= Date: Mon, 18 Nov 2019 21:15:03 +0100 Subject: [PATCH] =?UTF-8?q?Core:=20Migrate=20from=20AMD=20to=20ES=20module?= =?UTF-8?q?s=20=F0=9F=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Migrate all source AMD modules to ECMAScript modules. The final bundle is compiled by a custom build process that uses Rollup under the hood. Test files themselves are still loaded via RequireJS as that has to work in IE 11. Tests can now be run in "Load as modules" mode which replaces the previous "Load with AMD" option. That option of running tests doesn't work in IE and Edge as it requires support for dynamic imports. Some of the changes required by the migration: * check `typeof` of `noGlobal` instead of using the variable directly as it's not available when modules are used * change the nonce module to be an object as ECMASscript module exports are immutable * remove some unused exports * import `./core/parseHTML.js` directly in `jquery.js` so that it's not being cut out when the `ajax` module is excluded in a custom compilation Closes gh-4541 --- .eslintrc-browser.json | 4 +- .eslintrc-node.json | 2 +- .eslintrc.json | 11 +- CONTRIBUTING.md | 6 +- Gruntfile.js | 2 +- build/tasks/build.js | 373 +++++++++++++--------------- dist/.eslintrc.json | 11 + package.json | 4 +- src/.eslintrc.json | 33 ++- src/ajax.js | 32 ++- src/ajax/jsonp.js | 15 +- src/ajax/load.js | 19 +- src/ajax/parseXML.js | 10 +- src/ajax/script.js | 11 +- src/ajax/var/location.js | 6 +- src/ajax/var/nonce.js | 6 +- src/ajax/var/rquery.js | 6 +- src/ajax/xhr.js | 9 +- src/attributes.js | 16 +- src/attributes/attr.js | 17 +- src/attributes/classes.js | 15 +- src/attributes/prop.js | 13 +- src/attributes/val.js | 22 +- src/callbacks.js | 13 +- src/core.js | 45 ++-- src/core/DOMEval.js | 64 +++-- src/core/access.js | 12 +- src/core/camelCase.js | 8 +- src/core/init.js | 16 +- src/core/isAttached.js | 37 ++- src/core/nodeName.js | 8 +- src/core/parseHTML.js | 16 +- src/core/ready-no-deferred.js | 10 +- src/core/ready.js | 13 +- src/core/readyException.js | 8 +- src/core/stripAndCollapse.js | 20 +- src/core/toType.js | 11 +- src/core/var/rhtml.js | 8 +- src/core/var/rsingleTag.js | 10 +- src/css.js | 44 ++-- src/css/adjustCSS.js | 13 +- src/css/cssCamelCase.js | 10 +- src/css/curCSS.js | 13 +- src/css/finalPropName.js | 10 +- src/css/hiddenVisibleSelectors.js | 9 +- src/css/isAutoPx.js | 8 +- src/css/showHide.js | 13 +- src/css/support.js | 14 +- src/css/var/cssExpand.js | 6 +- src/css/var/getStyles.js | 28 +-- src/css/var/isHiddenWithinTree.js | 40 ++- src/css/var/rnumnonpx.js | 8 +- src/css/var/swap.js | 8 +- src/data.js | 17 +- src/data/Data.js | 15 +- src/data/var/acceptData.js | 8 +- src/data/var/dataPriv.js | 8 +- src/data/var/dataUser.js | 8 +- src/deferred.js | 12 +- src/deferred/exceptionHook.js | 9 +- src/deprecated.js | 12 +- src/dimensions.js | 14 +- src/effects.js | 47 ++-- src/effects/Tween.js | 14 +- src/effects/animatedSelector.js | 11 +- src/event.js | 28 +-- src/event/ajax.js | 9 +- src/event/alias.js | 12 +- src/event/trigger.js | 20 +- src/exports/amd.js | 8 +- src/exports/global.js | 10 +- src/jquery.js | 70 +++--- src/manipulation.js | 52 ++-- src/manipulation/_evalUrl.js | 10 +- src/manipulation/buildFragment.js | 23 +- src/manipulation/getAll.js | 11 +- src/manipulation/setGlobalEval.js | 9 +- src/manipulation/var/rscriptType.js | 6 +- src/manipulation/var/rtagName.js | 12 +- src/manipulation/wrapMap.js | 7 +- src/offset.js | 20 +- src/queue.js | 14 +- src/queue/delay.js | 12 +- src/selector.js | 33 +-- src/selector/contains.js | 8 +- src/selector/escapeSelector.js | 8 +- src/selector/rbuggyQSA.js | 12 +- src/selector/support.js | 12 +- src/selector/uniqueSort.js | 12 +- src/serialize.js | 18 +- src/traversing.js | 27 +- src/traversing/findFilter.js | 13 +- src/traversing/var/dir.js | 10 +- src/traversing/var/rneedsContext.js | 11 +- src/traversing/var/siblings.js | 8 +- src/var/ObjectFunctionString.js | 8 +- src/var/arr.js | 6 +- src/var/class2type.js | 8 +- src/var/document.js | 6 +- src/var/documentElement.js | 8 +- src/var/flat.js | 10 +- src/var/fnToString.js | 8 +- src/var/getProto.js | 6 +- src/var/hasOwn.js | 8 +- src/var/indexOf.js | 8 +- src/var/isIE.js | 8 +- src/var/isWindow.js | 11 +- src/var/pnum.js | 6 +- src/var/pop.js | 8 +- src/var/push.js | 8 +- src/var/rcheckableType.js | 6 +- src/var/rcssNum.js | 10 +- src/var/rnothtmlwhite.js | 12 +- src/var/slice.js | 8 +- src/var/sort.js | 8 +- src/var/support.js | 8 +- src/var/toString.js | 8 +- src/var/trim.js | 6 +- src/wrap.js | 14 +- src/wrapper.js | 1 - test/.eslintrc.json | 10 + test/data/testinit.js | 2 +- test/index.html | 4 +- test/jquery.js | 37 +-- 124 files changed, 787 insertions(+), 1310 deletions(-) diff --git a/.eslintrc-browser.json b/.eslintrc-browser.json index 146745d0e..127fc6ce8 100644 --- a/.eslintrc-browser.json +++ b/.eslintrc-browser.json @@ -15,9 +15,7 @@ "env": {}, "globals": { - "window": true, - "define": true, - "module": true + "window": true }, "rules": { diff --git a/.eslintrc-node.json b/.eslintrc-node.json index 544a92cdc..f1c44a382 100644 --- a/.eslintrc-node.json +++ b/.eslintrc-node.json @@ -4,7 +4,7 @@ "extends": "jquery", "parserOptions": { - "ecmaVersion": 2017 + "ecmaVersion": 2018 }, "env": { diff --git a/.eslintrc.json b/.eslintrc.json index d2c977ca8..2fad01637 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,5 +1,14 @@ { "root": true, - "extends": "./.eslintrc-node.json" + "extends": "./.eslintrc-node.json", + + "overrides": [ + { + "files": "rollup.config.js", + "parserOptions": { + "sourceType": "module" + } + } + ] } diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 18c6bc802..2deb7d180 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -129,14 +129,14 @@ Rather than rebuilding jQuery with `grunt` every time you make a change, you can $ grunt watch ``` -Alternatively, you can **load tests in AMD** to avoid the need for rebuilding altogether. +Alternatively, you can **load tests as ECMAScript modules** to avoid the need for rebuilding altogether. -Click "Load with AMD" after loading the test page. +Click "Load as modules" after loading the test page. ### Repo organization -The jQuery source is organized with AMD modules and then concatenated and compiled at build time. +The jQuery source is organized with ECMAScript modules and then compiled into one file at build time. jQuery also contains some special modules we call "var modules", which are placed in folders named "var". At build time, these small modules are compiled to simple var statements. This makes it easy for us to share variables across modules. Browse the "src" folder for examples. diff --git a/Gruntfile.js b/Gruntfile.js index 831ca4b88..9ed250a3e 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -177,7 +177,7 @@ module.exports = function( grunt ) { "test/unit/ready.js", { pattern: "dist/jquery.*", included: false, served: true }, - { pattern: "src/**", included: false, served: true }, + { pattern: "src/**", type: "module", included: false, served: true }, { pattern: "node_modules/**", included: false, served: true }, { pattern: "test/**/*.@(js|css|jpg|html|xml|svg)", diff --git a/build/tasks/build.js b/build/tasks/build.js index 63dfc1ee8..188e1e452 100644 --- a/build/tasks/build.js +++ b/build/tasks/build.js @@ -1,132 +1,66 @@ /** - * Special concat/build task to handle various jQuery build requirements - * Concats AMD modules, removes their definitions, + * Special build task to handle various jQuery build requirements. + * Compiles JS modules into one bundle, sets the custom AMD name, * and includes/excludes specified modules */ "use strict"; module.exports = function( grunt ) { - var fs = require( "fs" ), - requirejs = require( "requirejs" ), - Insight = require( "insight" ), - pkg = require( "../../package.json" ), - srcFolder = __dirname + "/../../src/", - rdefineEnd = /\}\s*?\);[^}\w]*$/, - read = function( fileName ) { - return grunt.file.read( srcFolder + fileName ); - }, + const fs = require( "fs" ); + const path = require( "path" ); + const rollup = require( "rollup" ); + const rollupHypothetical = require( "rollup-plugin-hypothetical" ); + const Insight = require( "insight" ); + const pkg = require( "../../package.json" ); + const srcFolder = path.resolve( `${ __dirname }/../../src` ); + const read = function( fileName ) { + return grunt.file.read( `${ srcFolder }/${ fileName }` ); + }; - // Catch `// @CODE` and subsequent comment lines event if they don't start - // in the first column. - wrapper = read( "wrapper.js" ).split( /[\x20\t]*\/\/ @CODE\n(?:[\x20\t]*\/\/[^\n]+\n)*/ ), + // Catch `// @CODE` and subsequent comment lines event if they don't start + // in the first column. + const wrapper = read( "wrapper.js" ) + .split( /[\x20\t]*\/\/ @CODE\n(?:[\x20\t]*\/\/[^\n]+\n)*/ ); - config = { - baseUrl: "src", - name: "jquery", + const inputFileName = "jquery.js"; + const inputRollupOptions = { + input: `${ srcFolder }/${ inputFileName }` + }; + const outputRollupOptions = { - // Allow strict mode - useStrict: true, + // The ESM format is not actually used as we strip it during + // the build; it's just that it doesn't generate any extra + // wrappers so there's nothing for us to remove. + format: "esm", - // We have multiple minify steps - optimize: "none", - - // Include dependencies loaded with require - findNestedDependencies: true, - - // Avoid inserting define() placeholder - skipModuleInsertion: true, - - // Avoid breaking semicolons inserted by r.js - skipSemiColonInsertion: true, - wrap: { - start: wrapper[ 0 ].replace( /\/\*\s*eslint(?: |-).*\s*\*\/\n/, "" ), - end: wrapper[ 1 ] - }, - rawText: {}, - onBuildWrite: convert - }; - - /** - * Strip all definitions generated by requirejs - * Convert "var" modules to var declarations - * "var module" means the module only contains a return - * statement that should be converted to a var declaration - * This is indicated by including the file in any "var" folder - * @param {String} name - * @param {String} path - * @param {String} contents The contents to be written (including their AMD wrappers) - */ - function convert( name, path, contents ) { - var amdName; - - // Convert var modules - if ( /.\/var\//.test( path.replace( process.cwd(), "" ) ) ) { - contents = contents - .replace( - /define\(\s*(["'])[\w\W]*?\1[\w\W]*?return/, - "var " + - ( /var\/([\w-]+)/.exec( name )[ 1 ] ) + - " =" - ) - .replace( rdefineEnd, "" ); - - } else { - - contents = contents - .replace( /\s*return\s+[^\}]+(\}\s*?\);[^\w\}]*)$/, "$1" ) - - // Multiple exports - .replace( /\s*exports\.\w+\s*=\s*\w+;/g, "" ); - - // Remove define wrappers, closure ends, and empty declarations - contents = contents - .replace( /define\([^{]*?{\s*(?:("|')use strict\1(?:;|))?/, "" ) - .replace( rdefineEnd, "" ); - - // Remove anything wrapped with - // /* ExcludeStart */ /* ExcludeEnd */ - // or a single line directly after a // BuildExclude comment - contents = contents - .replace( /\/\*\s*ExcludeStart\s*\*\/[\w\W]*?\/\*\s*ExcludeEnd\s*\*\//ig, "" ) - .replace( /\/\/\s*BuildExclude\n\r?[\w\W]*?\n\r?/ig, "" ); - - // Remove empty definitions - contents = contents - .replace( /define\(\[[^\]]*\]\)[\W\n]+$/, "" ); - } - - // AMD Name - if ( ( amdName = grunt.option( "amd" ) ) != null && /^exports\/amd$/.test( name ) ) { - if ( amdName ) { - grunt.log.writeln( "Naming jQuery with AMD name: " + amdName ); - } else { - grunt.log.writeln( "AMD name now anonymous" ); - } - - // Remove the comma for anonymous defines - contents = contents - .replace( /(\s*)"jquery"(\,\s*)/, amdName ? "$1\"" + amdName + "\"$2" : "" ); - - } - return contents; - } + intro: wrapper[ 0 ] + .replace( /\n*$/, "" ), + outro: wrapper[ 1 ] + .replace( /^\n*/, "" ) + }; + const rollupHypotheticalOptions = { + allowFallthrough: true, + files: {} + }; grunt.registerMultiTask( "build", "Concatenate source, remove sub AMD definitions, " + "(include/exclude modules with +/- flags), embed date/version", - function() { - var flag, index, - done = this.async(), - flags = this.flags, - optIn = flags[ "*" ], - name = grunt.option( "filename" ), - minimum = this.data.minimum, - removeWith = this.data.removeWith, - excluded = [], - included = [], - version = grunt.config( "pkg.version" ), + async function() { + const done = this.async(); + + try { + let flag, index; + const flags = this.flags; + const optIn = flags[ "*" ]; + let name = grunt.option( "filename" ); + const minimum = this.data.minimum; + const removeWith = this.data.removeWith; + const excluded = []; + const included = []; + let version = grunt.config( "pkg.version" ); /** * Recursively calls the excluder to remove on all modules in the list @@ -134,15 +68,16 @@ module.exports = function( grunt ) { * @param {String} [prepend] Prepend this to the module name. * Indicates we're walking a directory */ - excludeList = function( list, prepend ) { + const excludeList = ( list, prepend ) => { if ( list ) { - prepend = prepend ? prepend + "/" : ""; + prepend = prepend ? `${ prepend }/` : ""; list.forEach( function( module ) { // Exclude var modules as well if ( module === "var" ) { excludeList( - fs.readdirSync( srcFolder + prepend + module ), prepend + module + fs.readdirSync( `${ srcFolder }/${ prepend }${ module }` ), + prepend + module ); return; } @@ -164,7 +99,7 @@ module.exports = function( grunt ) { } } ); } - }, + }; /** * Adds the specified module to the excluded or included list, depending on the flag @@ -172,11 +107,11 @@ module.exports = function( grunt ) { * the src directory starting with + or - to indicate * whether it should included or excluded */ - excluder = function( flag ) { - var additional, - m = /^(\+|\-|)([\w\/-]+)$/.exec( flag ), - exclude = m[ 1 ] === "-", - module = m[ 2 ]; + const excluder = flag => { + let additional; + const m = /^(\+|\-|)([\w\/-]+)$/.exec( flag ); + const exclude = m[ 1 ] === "-"; + const module = m[ 2 ]; if ( exclude ) { @@ -192,7 +127,10 @@ module.exports = function( grunt ) { // These are the removable dependencies // It's fine if the directory is not there try { - excludeList( fs.readdirSync( srcFolder + module ), module ); + excludeList( + fs.readdirSync( `${ srcFolder }/${ module }` ), + module + ); } catch ( e ) { grunt.verbose.writeln( e ); } @@ -204,7 +142,7 @@ module.exports = function( grunt ) { if ( additional ) { excludeList( additional.remove || additional ); if ( additional.include ) { - included = included.concat( additional.include ); + included.push( ...additional.include ); grunt.log.writeln( "+" + additional.include ); } } @@ -217,93 +155,122 @@ module.exports = function( grunt ) { } }; - // Filename can be passed to the command line using - // command line options - // e.g. grunt build --filename=jquery-custom.js - name = name ? ( "dist/" + name ) : this.data.dest; + // Filename can be passed to the command line using + // command line options + // e.g. grunt build --filename=jquery-custom.js + name = name ? `dist/${ name }` : this.data.dest; - // append commit id to version - if ( process.env.COMMIT ) { - version += " " + process.env.COMMIT; - } + // append commit id to version + if ( process.env.COMMIT ) { + version += " " + process.env.COMMIT; + } - // figure out which files to exclude based on these rules in this order: - // dependency explicit exclude - // > explicit exclude - // > explicit include - // > dependency implicit exclude - // > implicit exclude - // examples: - // * none (implicit exclude) - // *:* all (implicit include) - // *:*:-css all except css and dependents (explicit > implicit) - // *:*:-css:+effects same (excludes effects because explicit include is - // trumped by explicit exclude of dependency) - // *:+effects none except effects and its dependencies - // (explicit include trumps implicit exclude of dependency) - delete flags[ "*" ]; - for ( flag in flags ) { - excluder( flag ); - } + // figure out which files to exclude based on these rules in this order: + // dependency explicit exclude + // > explicit exclude + // > explicit include + // > dependency implicit exclude + // > implicit exclude + // examples: + // * none (implicit exclude) + // *:* all (implicit include) + // *:*:-css all except css and dependents (explicit > implicit) + // *:*:-css:+effects same (excludes effects because explicit include is + // trumped by explicit exclude of dependency) + // *:+effects none except effects and its dependencies + // (explicit include trumps implicit exclude of dependency) + delete flags[ "*" ]; + for ( flag in flags ) { + excluder( flag ); + } - // Replace exports/global with a noop noConflict - if ( ( index = excluded.indexOf( "exports/global" ) ) > -1 ) { - config.rawText[ "exports/global" ] = "define(['../core']," + - "function( jQuery ) {\njQuery.noConflict = function() {};\n});"; - excluded.splice( index, 1 ); - } + // Remove the jQuery export from the entry file, we'll use our own + // custom wrapper. + rollupHypotheticalOptions.files[ inputRollupOptions.input ] = read( inputFileName ) + .replace( /\n*export default jQuery;\n*/, "\n" ); - grunt.verbose.writeflags( excluded, "Excluded" ); - grunt.verbose.writeflags( included, "Included" ); + // Replace exports/global with a noop noConflict + if ( ( index = excluded.indexOf( "exports/global" ) ) > -1 ) { + rollupHypotheticalOptions.files[ `${ srcFolder }/exports/global.js` ] = + "import jQuery from \"../core.js\";\n\n" + + "jQuery.noConflict = function() {};"; + excluded.splice( index, 1 ); + } - // append excluded modules to version - if ( excluded.length ) { - version += " -" + excluded.join( ",-" ); + // Set a desired AMD name. + let amdName = grunt.option( "amd" ); + if ( amdName != null ) { + if ( amdName ) { + grunt.log.writeln( "Naming jQuery with AMD name: " + amdName ); + } else { + grunt.log.writeln( "AMD name now anonymous" ); + } - // set pkg.version to version with excludes, so minified file picks it up - grunt.config.set( "pkg.version", version ); - grunt.verbose.writeln( "Version changed to " + version ); + // Remove the comma for anonymous defines + rollupHypotheticalOptions.files[ `${ srcFolder }/exports/amd.js` ] = + read( "exports/amd.js" ) + .replace( /(\s*)"jquery"(\,\s*)/, amdName ? "$1\"" + amdName + "\"$2" : "" ); + } - // Have to use shallow or core will get excluded since it is a dependency - config.excludeShallow = excluded; - } - config.include = included; + grunt.verbose.writeflags( excluded, "Excluded" ); + grunt.verbose.writeflags( included, "Included" ); - /** - * Handle Final output from the optimizer - * @param {String} compiled - */ - config.out = function( compiled ) { - compiled = compiled + // append excluded modules to version + if ( excluded.length ) { + version += " -" + excluded.join( ",-" ); + + // set pkg.version to version with excludes, so minified file picks it up + grunt.config.set( "pkg.version", version ); + grunt.verbose.writeln( "Version changed to " + version ); + + // Replace excluded modules with empty sources. + for ( const module of excluded ) { + rollupHypotheticalOptions.files[ `${ srcFolder }/${ module }.js` ] = ""; + } + } + + // Turn off opt-in if necessary + if ( !optIn ) { + + // Remove the default inclusions, they will be overwritten with the explicitly + // included ones. + rollupHypotheticalOptions.files[ inputRollupOptions.input ] = ""; + + } + + // Import the explicitly included modules. + if ( included.length ) { + rollupHypotheticalOptions.files[ inputRollupOptions.input ] += included + .map( module => `import "./${module}.js";` ) + .join( "\n" ); + } + + const bundle = await rollup.rollup( { + ...inputRollupOptions, + plugins: [ rollupHypothetical( rollupHypotheticalOptions ) ] + } ); + + const { output: [ { code } ] } = await bundle.generate( outputRollupOptions ); + + const compiledContents = code // Embed Version .replace( /@VERSION/g, version ) // Embed Date // yyyy-mm-ddThh:mmZ - .replace( /@DATE/g, ( new Date() ).toISOString().replace( /:\d+\.\d+Z$/, "Z" ) ); + .replace( + /@DATE/g, + ( new Date() ).toISOString() + .replace( /:\d+\.\d+Z$/, "Z" ) + ); - // Write concatenated source to file - grunt.file.write( name, compiled ); - }; - - // Turn off opt-in if necessary - if ( !optIn ) { - - // Overwrite the default inclusions with the explicit ones provided - config.rawText.jquery = "define([" + - ( included.length ? included.join( "," ) : "" ) + - "]);"; - } - - // Trace dependencies and concatenate files - requirejs.optimize( config, function( response ) { - grunt.verbose.writeln( response ); + grunt.file.write( name, compiledContents ); grunt.log.ok( "File '" + name + "' created." ); done(); - }, function( err ) { + } catch ( err ) { done( err ); - } ); + } } ); // Special "alias" task to make custom build creation less grawlix-y @@ -315,17 +282,17 @@ module.exports = function( grunt ) { // // grunt build:*:*:+ajax:-dimensions:-effects:-offset grunt.registerTask( "custom", function() { - var args = this.args, - modules = args.length ? args[ 0 ].replace( /,/g, ":" ) : "", - done = this.async(), - insight = new Insight( { - trackingCode: "UA-1076265-4", - pkg: pkg - } ); + const args = this.args; + const modules = args.length ? args[ 0 ].replace( /,/g, ":" ) : ""; + const done = this.async(); + const insight = new Insight( { + trackingCode: "UA-1076265-4", + pkg: pkg + } ); function exec( trackingAllowed ) { - var tracks = args.length ? args[ 0 ].split( "," ) : []; - var defaultPath = [ "build", "custom" ]; + let tracks = args.length ? args[ 0 ].split( "," ) : []; + const defaultPath = [ "build", "custom" ]; tracks = tracks.map( function( track ) { return track.replace( /\//g, "+" ); @@ -335,7 +302,7 @@ module.exports = function( grunt ) { // Track individuals tracks.forEach( function( module ) { - var path = defaultPath.concat( [ "individual" ], module ); + const path = defaultPath.concat( [ "individual" ], module ); insight.track.apply( insight, path ); } ); diff --git a/dist/.eslintrc.json b/dist/.eslintrc.json index 6108d1619..bf60c4c18 100644 --- a/dist/.eslintrc.json +++ b/dist/.eslintrc.json @@ -3,8 +3,19 @@ "extends": "../.eslintrc-browser.json", + "parserOptions": { + "ecmaVersion": 5, + "sourceType": "script" + }, + "rules": { // That is okay for the built version "no-multiple-empty-lines": "off" + }, + + "globals": { + "define": false, + "module": true, + "Symbol": false } } diff --git a/package.json b/package.json index 99ddba79e..106417d07 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "grunt-compare-size": "0.4.2", "grunt-contrib-uglify": "3.4.0", "grunt-contrib-watch": "1.1.0", - "grunt-eslint": "21.0.0", + "grunt-eslint": "22.0.0", "grunt-git-authors": "3.2.0", "grunt-jsonlint": "1.1.0", "grunt-karma": "3.0.1", @@ -59,6 +59,8 @@ "qunit": "2.9.2", "raw-body": "2.3.3", "requirejs": "2.3.6", + "rollup": "1.25.2", + "rollup-plugin-hypothetical": "2.1.0", "sinon": "7.3.1", "strip-json-comments": "2.0.1", "testswarm": "1.1.0", diff --git a/src/.eslintrc.json b/src/.eslintrc.json index 3d0ca185a..44cb3a179 100644 --- a/src/.eslintrc.json +++ b/src/.eslintrc.json @@ -3,11 +3,42 @@ "extends": "../.eslintrc-browser.json", + "parserOptions": { + "ecmaVersion": 2015, + "sourceType": "module" + }, + "overrides": [ { "files": "wrapper.js", + "parserOptions": { + "ecmaVersion": 5, + "sourceType": "script" + }, + "rules": { + "no-unused-vars": "off" + }, "globals": { - "jQuery": false + "jQuery": false, + "module": true + } + }, + + { + "files": "exports/amd.js", + "globals": { + "define": false + } + }, + + { + "files": "core.js", + "globals": { + + // Defining Symbol globally would create a danger of using + // it unguarded in another place, it seems safer to define + // it only for this module. + "Symbol": false } } ] diff --git a/src/ajax.js b/src/ajax.js index 53557253f..51bcf8a0e 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -1,19 +1,15 @@ -define( [ - "./core", - "./var/document", - "./var/rnothtmlwhite", - "./ajax/var/location", - "./ajax/var/nonce", - "./ajax/var/rquery", +import jQuery from "./core.js"; +import document from "./var/document.js"; +import rnothtmlwhite from "./var/rnothtmlwhite.js"; +import location from "./ajax/var/location.js"; +import nonce from "./ajax/var/nonce.js"; +import rquery from "./ajax/var/rquery.js"; - "./core/init", - "./ajax/parseXML", - "./event/trigger", - "./deferred", - "./serialize" // jQuery.param -], function( jQuery, document, rnothtmlwhite, location, nonce, rquery ) { - -"use strict"; +import "./core/init.js"; +import "./ajax/parseXML.js"; +import "./event/trigger.js"; +import "./deferred.js"; +import "./serialize"; // jQuery.param var r20 = /%20/g, @@ -615,7 +611,8 @@ jQuery.extend( { // Add or update anti-cache param if needed if ( s.cache === false ) { cacheURL = cacheURL.replace( rantiCache, "$1" ); - uncached = ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + ( nonce++ ) + uncached; + uncached = ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + + ( nonce.guid++ ) + uncached; } // Put hash and anti-cache on the URL that will be requested (gh-1732) @@ -864,5 +861,4 @@ jQuery.each( [ "get", "post" ], function( _i, method ) { }; } ); -return jQuery; -} ); +export default jQuery; diff --git a/src/ajax/jsonp.js b/src/ajax/jsonp.js index dbdb4dbb8..1d612c1a9 100644 --- a/src/ajax/jsonp.js +++ b/src/ajax/jsonp.js @@ -1,11 +1,8 @@ -define( [ - "../core", - "./var/nonce", - "./var/rquery", - "../ajax" -], function( jQuery, nonce, rquery ) { +import jQuery from "../core.js"; +import nonce from "./var/nonce.js"; +import rquery from "./var/rquery.js"; -"use strict"; +import "../ajax.js"; var oldCallbacks = [], rjsonp = /(=)\?(?=&|$)|\?\?/; @@ -14,7 +11,7 @@ var oldCallbacks = [], jQuery.ajaxSetup( { jsonp: "callback", jsonpCallback: function() { - var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) ); + var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce.guid++ ) ); this[ callback ] = true; return callback; } @@ -98,5 +95,3 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) { return "script"; } } ); - -} ); diff --git a/src/ajax/load.js b/src/ajax/load.js index 574d6b4a7..9a91b990b 100644 --- a/src/ajax/load.js +++ b/src/ajax/load.js @@ -1,14 +1,11 @@ -define( [ - "../core", - "../core/stripAndCollapse", - "../core/parseHTML", - "../ajax", - "../traversing", - "../manipulation", - "../selector" -], function( jQuery, stripAndCollapse ) { +import jQuery from "../core.js"; +import stripAndCollapse from "../core/stripAndCollapse.js"; -"use strict"; +import "../core/parseHTML.js"; +import "../ajax.js"; +import "../traversing.js"; +import "../manipulation.js"; +import "../selector.js"; /** * Load a url into a page @@ -72,5 +69,3 @@ jQuery.fn.load = function( url, params, callback ) { return this; }; - -} ); diff --git a/src/ajax/parseXML.js b/src/ajax/parseXML.js index 0bdc49a7c..d547eab53 100644 --- a/src/ajax/parseXML.js +++ b/src/ajax/parseXML.js @@ -1,8 +1,4 @@ -define( [ - "../core" -], function( jQuery ) { - -"use strict"; +import jQuery from "../core.js"; // Cross-browser xml parsing jQuery.parseXML = function( data ) { @@ -25,6 +21,4 @@ jQuery.parseXML = function( data ) { return xml; }; -return jQuery.parseXML; - -} ); +export default jQuery.parseXML; diff --git a/src/ajax/script.js b/src/ajax/script.js index 410c82cab..22dc29183 100644 --- a/src/ajax/script.js +++ b/src/ajax/script.js @@ -1,10 +1,7 @@ -define( [ - "../core", - "../var/document", - "../ajax" -], function( jQuery, document ) { +import jQuery from "../core.js"; +import document from "../var/document.js"; -"use strict"; +import "../ajax.js"; // Prevent auto-execution of scripts when no explicit dataType was provided (See gh-2432) jQuery.ajaxPrefilter( function( s ) { @@ -70,5 +67,3 @@ jQuery.ajaxTransport( "script", function( s ) { }; } } ); - -} ); diff --git a/src/ajax/var/location.js b/src/ajax/var/location.js index 4171d18c3..78e6f07b3 100644 --- a/src/ajax/var/location.js +++ b/src/ajax/var/location.js @@ -1,5 +1 @@ -define( function() { - "use strict"; - - return window.location; -} ); +export default window.location; diff --git a/src/ajax/var/nonce.js b/src/ajax/var/nonce.js index 33d0cffb6..b0070c699 100644 --- a/src/ajax/var/nonce.js +++ b/src/ajax/var/nonce.js @@ -1,5 +1 @@ -define( function() { - "use strict"; - - return Date.now(); -} ); +export default { guid: Date.now() }; diff --git a/src/ajax/var/rquery.js b/src/ajax/var/rquery.js index 06fc37439..f18f87661 100644 --- a/src/ajax/var/rquery.js +++ b/src/ajax/var/rquery.js @@ -1,5 +1 @@ -define( function() { - "use strict"; - - return ( /\?/ ); -} ); +export default ( /\?/ ); diff --git a/src/ajax/xhr.js b/src/ajax/xhr.js index 3578ba167..f6bd52337 100644 --- a/src/ajax/xhr.js +++ b/src/ajax/xhr.js @@ -1,9 +1,6 @@ -define( [ - "../core", - "../ajax" -], function( jQuery ) { +import jQuery from "../core.js"; -"use strict"; +import "../ajax.js"; jQuery.ajaxSettings.xhr = function() { return new window.XMLHttpRequest(); @@ -116,5 +113,3 @@ jQuery.ajaxTransport( function( options ) { } }; } ); - -} ); diff --git a/src/attributes.js b/src/attributes.js index 2d801e563..646107adc 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -1,13 +1,9 @@ -define( [ - "./core", - "./attributes/attr", - "./attributes/prop", - "./attributes/classes", - "./attributes/val" -], function( jQuery ) { +import jQuery from "./core.js"; -"use strict"; +import "./attributes/attr.js"; +import "./attributes/prop.js"; +import "./attributes/classes.js"; +import "./attributes/val.js"; // Return jQuery for attributes-only inclusion -return jQuery; -} ); +export default jQuery; diff --git a/src/attributes/attr.js b/src/attributes/attr.js index afa4f5775..cd34860e1 100644 --- a/src/attributes/attr.js +++ b/src/attributes/attr.js @@ -1,13 +1,10 @@ -define( [ - "../core", - "../core/access", - "../core/nodeName", - "../var/rnothtmlwhite", - "../var/isIE", - "../selector" -], function( jQuery, access, nodeName, rnothtmlwhite, isIE ) { +import jQuery from "../core.js"; +import access from "../core/access.js"; +import nodeName from "../core/nodeName.js"; +import rnothtmlwhite from "../var/rnothtmlwhite.js"; +import isIE from "../var/isIE.js"; -"use strict"; +import "../selector.js"; jQuery.fn.extend( { attr: function( name, value ) { @@ -128,5 +125,3 @@ jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( _i, name ) } }; } ); - -} ); diff --git a/src/attributes/classes.js b/src/attributes/classes.js index f1571eb5d..e020aa5cf 100644 --- a/src/attributes/classes.js +++ b/src/attributes/classes.js @@ -1,12 +1,9 @@ -define( [ - "../core", - "../core/stripAndCollapse", - "../var/rnothtmlwhite", - "../data/var/dataPriv", - "../core/init" -], function( jQuery, stripAndCollapse, rnothtmlwhite, dataPriv ) { +import jQuery from "../core.js"; +import stripAndCollapse from "../core/stripAndCollapse.js"; +import rnothtmlwhite from "../var/rnothtmlwhite.js"; +import dataPriv from "../data/var/dataPriv.js"; -"use strict"; +import "../core/init.js"; function getClass( elem ) { return elem.getAttribute && elem.getAttribute( "class" ) || ""; @@ -181,5 +178,3 @@ jQuery.fn.extend( { return false; } } ); - -} ); diff --git a/src/attributes/prop.js b/src/attributes/prop.js index 651d9e215..d58adf369 100644 --- a/src/attributes/prop.js +++ b/src/attributes/prop.js @@ -1,11 +1,8 @@ -define( [ - "../core", - "../core/access", - "../var/isIE", - "../selector" -], function( jQuery, access, isIE ) { +import jQuery from "../core.js"; +import access from "../core/access.js"; +import isIE from "../var/isIE.js"; -"use strict"; +import "../selector.js"; var rfocusable = /^(?:input|select|textarea|button)$/i, rclickable = /^(?:a|area)$/i; @@ -136,5 +133,3 @@ jQuery.each( [ ], function() { jQuery.propFix[ this.toLowerCase() ] = this; } ); - -} ); diff --git a/src/attributes/val.js b/src/attributes/val.js index 02559ffaa..38e170ba8 100644 --- a/src/attributes/val.js +++ b/src/attributes/val.js @@ -1,12 +1,8 @@ -define( [ - "../core", - "../core/stripAndCollapse", - "../core/nodeName", +import jQuery from "../core.js"; +import stripAndCollapse from "../core/stripAndCollapse.js"; +import nodeName from "../core/nodeName.js"; - "../core/init" -], function( jQuery, stripAndCollapse, nodeName ) { - -"use strict"; +import "../core/init.js"; var rreturn = /\r/g; @@ -147,15 +143,11 @@ jQuery.extend( { while ( i-- ) { option = options[ i ]; - /* eslint-disable no-cond-assign */ - - if ( option.selected = + if ( ( option.selected = jQuery.inArray( jQuery.valHooks.option.get( option ), values ) > -1 - ) { + ) ) { optionSet = true; } - - /* eslint-enable no-cond-assign */ } // Force browsers to behave consistently when non-matching value is set @@ -178,5 +170,3 @@ jQuery.each( [ "radio", "checkbox" ], function() { } }; } ); - -} ); diff --git a/src/callbacks.js b/src/callbacks.js index 140c4979e..19b3d7c1c 100644 --- a/src/callbacks.js +++ b/src/callbacks.js @@ -1,10 +1,6 @@ -define( [ - "./core", - "./core/toType", - "./var/rnothtmlwhite" -], function( jQuery, toType, rnothtmlwhite ) { - -"use strict"; +import jQuery from "./core.js"; +import toType from "./core/toType.js"; +import rnothtmlwhite from "./var/rnothtmlwhite.js"; // Convert String-formatted options into Object-formatted ones function createOptions( options ) { @@ -231,5 +227,4 @@ jQuery.Callbacks = function( options ) { return self; }; -return jQuery; -} ); +export default jQuery; diff --git a/src/core.js b/src/core.js index af5d44214..7ea77c4f0 100644 --- a/src/core.js +++ b/src/core.js @@ -1,29 +1,21 @@ -/* global Symbol */ -// Defining this global in .eslintrc.json would create a danger of using the global -// unguarded in another place, it seems safer to define global only for this module - -define( [ - "./var/arr", - "./var/getProto", - "./var/slice", - "./var/flat", - "./var/push", - "./var/indexOf", - "./var/class2type", - "./var/toString", - "./var/hasOwn", - "./var/fnToString", - "./var/ObjectFunctionString", - "./var/support", - "./var/isWindow", - "./core/DOMEval", - "./core/toType" -], function( arr, getProto, slice, flat, push, indexOf, - class2type, toString, hasOwn, fnToString, ObjectFunctionString, - support, isWindow, DOMEval, toType ) { - -"use strict"; +import arr from "./var/arr.js"; +import getProto from "./var/getProto.js"; +import slice from "./var/slice.js"; +import flat from "./var/flat.js"; +import push from "./var/push.js"; +import indexOf from "./var/indexOf.js"; +import class2type from "./var/class2type.js"; +import toString from "./var/toString.js"; +import hasOwn from "./var/hasOwn.js"; +import fnToString from "./var/fnToString.js"; +import ObjectFunctionString from "./var/ObjectFunctionString.js"; +import support from "./var/support.js"; +import isWindow from "./var/isWindow.js"; +import DOMEval from "./core/DOMEval.js"; +import toType from "./core/toType.js"; +// When custom compilation is used, the version string can get large. +// eslint-disable-next-line max-len var version = "@VERSION", rhtmlSuffix = /HTML$/i, @@ -431,5 +423,4 @@ function isArrayLike( obj ) { typeof length === "number" && length > 0 && ( length - 1 ) in obj; } -return jQuery; -} ); +export default jQuery; diff --git a/src/core/DOMEval.js b/src/core/DOMEval.js index df83cca52..b0238fd69 100644 --- a/src/core/DOMEval.js +++ b/src/core/DOMEval.js @@ -1,43 +1,39 @@ -define( [ - "../var/document" -], function( document ) { - "use strict"; +import document from "../var/document.js"; - var preservedScriptAttributes = { - type: true, - src: true, - nonce: true, - noModule: true - }; +var preservedScriptAttributes = { + type: true, + src: true, + nonce: true, + noModule: true +}; - function DOMEval( code, node, doc ) { - doc = doc || document; +function DOMEval( code, node, doc ) { + doc = doc || document; - var i, val, - script = doc.createElement( "script" ); + var i, val, + script = doc.createElement( "script" ); - script.text = code; - if ( node ) { - for ( i in preservedScriptAttributes ) { + script.text = code; + if ( node ) { + for ( i in preservedScriptAttributes ) { - // Support: Firefox <=64 - 66+, Edge <=18+ - // Some browsers don't support the "nonce" property on scripts. - // On the other hand, just using `getAttribute` is not enough as - // the `nonce` attribute is reset to an empty string whenever it - // becomes browsing-context connected. - // See https://github.com/whatwg/html/issues/2369 - // See https://html.spec.whatwg.org/#nonce-attributes - // The `node.getAttribute` check was added for the sake of - // `jQuery.globalEval` so that it can fake a nonce-containing node - // via an object. - val = node[ i ] || node.getAttribute && node.getAttribute( i ); - if ( val ) { - script.setAttribute( i, val ); - } + // Support: Firefox <=64 - 66+, Edge <=18+ + // Some browsers don't support the "nonce" property on scripts. + // On the other hand, just using `getAttribute` is not enough as + // the `nonce` attribute is reset to an empty string whenever it + // becomes browsing-context connected. + // See https://github.com/whatwg/html/issues/2369 + // See https://html.spec.whatwg.org/#nonce-attributes + // The `node.getAttribute` check was added for the sake of + // `jQuery.globalEval` so that it can fake a nonce-containing node + // via an object. + val = node[ i ] || node.getAttribute && node.getAttribute( i ); + if ( val ) { + script.setAttribute( i, val ); } } - doc.head.appendChild( script ).parentNode.removeChild( script ); } + doc.head.appendChild( script ).parentNode.removeChild( script ); +} - return DOMEval; -} ); +export default DOMEval; diff --git a/src/core/access.js b/src/core/access.js index e088a6557..4eaec4695 100644 --- a/src/core/access.js +++ b/src/core/access.js @@ -1,9 +1,5 @@ -define( [ - "../core", - "../core/toType" -], function( jQuery, toType ) { - -"use strict"; +import jQuery from "../core.js"; +import toType from "../core/toType.js"; // Multifunctional method to get and set values of a collection // The value/s can optionally be executed if it's a function @@ -66,6 +62,4 @@ var access = function( elems, fn, key, value, chainable, emptyGet, raw ) { return len ? fn( elems[ 0 ], key ) : emptyGet; }; -return access; - -} ); +export default access; diff --git a/src/core/camelCase.js b/src/core/camelCase.js index 61ed90d05..f12a2c67d 100644 --- a/src/core/camelCase.js +++ b/src/core/camelCase.js @@ -1,7 +1,3 @@ -define( [], function() { - -"use strict"; - // Matches dashed string for camelizing var rdashAlpha = /-([a-z])/g; @@ -15,6 +11,4 @@ function camelCase( string ) { return string.replace( rdashAlpha, fcamelCase ); } -return camelCase; - -} ); +export default camelCase; diff --git a/src/core/init.js b/src/core/init.js index 71f30e926..c2f35e1f4 100644 --- a/src/core/init.js +++ b/src/core/init.js @@ -1,13 +1,9 @@ // Initialize a jQuery object -define( [ - "../core", - "../var/document", - "./var/rsingleTag", +import jQuery from "../core.js"; +import document from "../var/document.js"; +import rsingleTag from "./var/rsingleTag.js"; - "../traversing/findFilter" -], function( jQuery, document, rsingleTag ) { - -"use strict"; +import "../traversing/findFilter.js"; // A central reference to the root jQuery(document) var rootjQuery, @@ -123,6 +119,4 @@ init.prototype = jQuery.fn; // Initialize central reference rootjQuery = jQuery( document ); -return init; - -} ); +export default init; diff --git a/src/core/isAttached.js b/src/core/isAttached.js index 579bcffb2..3857d94a8 100644 --- a/src/core/isAttached.js +++ b/src/core/isAttached.js @@ -1,23 +1,20 @@ -define( [ - "../core", - "../var/documentElement", - "../selector/contains" // jQuery.contains -], function( jQuery, documentElement ) { - "use strict"; +import jQuery from "../core.js"; +import documentElement from "../var/documentElement.js"; - var isAttached = function( elem ) { - return jQuery.contains( elem.ownerDocument, elem ); - }, - composed = { composed: true }; +import "../selector/contains.js"; // jQuery.contains - // Support: IE 9 - 11+, Edge 12 - 18+ - // Check attachment across shadow DOM boundaries when possible (gh-3504) - if ( documentElement.getRootNode ) { - isAttached = function( elem ) { - return jQuery.contains( elem.ownerDocument, elem ) || - elem.getRootNode( composed ) === elem.ownerDocument; - }; - } +var isAttached = function( elem ) { + return jQuery.contains( elem.ownerDocument, elem ); + }, + composed = { composed: true }; - return isAttached; -} ); +// Support: IE 9 - 11+, Edge 12 - 18+ +// Check attachment across shadow DOM boundaries when possible (gh-3504) +if ( documentElement.getRootNode ) { + isAttached = function( elem ) { + return jQuery.contains( elem.ownerDocument, elem ) || + elem.getRootNode( composed ) === elem.ownerDocument; + }; +} + +export default isAttached; diff --git a/src/core/nodeName.js b/src/core/nodeName.js index 8a5f5f036..d10e484bc 100644 --- a/src/core/nodeName.js +++ b/src/core/nodeName.js @@ -1,13 +1,7 @@ -define( function() { - -"use strict"; - function nodeName( elem, name ) { return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase(); }; -return nodeName; - -} ); +export default nodeName; diff --git a/src/core/parseHTML.js b/src/core/parseHTML.js index 8c5268fb1..15278fa02 100644 --- a/src/core/parseHTML.js +++ b/src/core/parseHTML.js @@ -1,11 +1,7 @@ -define( [ - "../core", - "../var/document", - "./var/rsingleTag", - "../manipulation/buildFragment" -], function( jQuery, document, rsingleTag, buildFragment ) { - -"use strict"; +import jQuery from "../core.js"; +import document from "../var/document.js"; +import rsingleTag from "./var/rsingleTag.js"; +import buildFragment from "../manipulation/buildFragment.js"; // Argument "data" should be string of html // context (optional): If specified, the fragment will be created in this context, @@ -52,7 +48,3 @@ jQuery.parseHTML = function( data, context, keepScripts ) { return jQuery.merge( [], parsed.childNodes ); }; - -return jQuery.parseHTML; - -} ); diff --git a/src/core/ready-no-deferred.js b/src/core/ready-no-deferred.js index 2c3fc1b84..51f6d7f6b 100644 --- a/src/core/ready-no-deferred.js +++ b/src/core/ready-no-deferred.js @@ -1,9 +1,5 @@ -define( [ - "../core", - "../var/document" -], function( jQuery, document ) { - -"use strict"; +import jQuery from "../core.js"; +import document from "../var/document.js"; var readyCallbacks = [], whenReady = function( fn ) { @@ -89,5 +85,3 @@ if ( document.readyState !== "loading" ) { // A fallback to window.onload, that will always work window.addEventListener( "load", completed ); } - -} ); diff --git a/src/core/ready.js b/src/core/ready.js index 3abb6c03a..d6c507e41 100644 --- a/src/core/ready.js +++ b/src/core/ready.js @@ -1,11 +1,8 @@ -define( [ - "../core", - "../var/document", - "../core/readyException", - "../deferred" -], function( jQuery, document ) { +import jQuery from "../core.js"; +import document from "../var/document.js"; -"use strict"; +import "../core/readyException.js"; +import "../deferred.js"; // The deferred used on DOM ready var readyList = jQuery.Deferred(); @@ -79,5 +76,3 @@ if ( document.readyState !== "loading" ) { // A fallback to window.onload, that will always work window.addEventListener( "load", completed ); } - -} ); diff --git a/src/core/readyException.js b/src/core/readyException.js index 72bdd90b5..1b5512c15 100644 --- a/src/core/readyException.js +++ b/src/core/readyException.js @@ -1,13 +1,7 @@ -define( [ - "../core" -], function( jQuery ) { - -"use strict"; +import jQuery from "../core.js"; jQuery.readyException = function( error ) { window.setTimeout( function() { throw error; } ); }; - -} ); diff --git a/src/core/stripAndCollapse.js b/src/core/stripAndCollapse.js index 2b63820da..944a79362 100644 --- a/src/core/stripAndCollapse.js +++ b/src/core/stripAndCollapse.js @@ -1,14 +1,10 @@ -define( [ - "../var/rnothtmlwhite" -], function( rnothtmlwhite ) { - "use strict"; +import rnothtmlwhite from "../var/rnothtmlwhite.js"; - // Strip and collapse whitespace according to HTML spec - // https://infra.spec.whatwg.org/#strip-and-collapse-ascii-whitespace - function stripAndCollapse( value ) { - var tokens = value.match( rnothtmlwhite ) || []; - return tokens.join( " " ); - } +// Strip and collapse whitespace according to HTML spec +// https://infra.spec.whatwg.org/#strip-and-collapse-ascii-whitespace +function stripAndCollapse( value ) { + var tokens = value.match( rnothtmlwhite ) || []; + return tokens.join( " " ); +} - return stripAndCollapse; -} ); +export default stripAndCollapse; diff --git a/src/core/toType.js b/src/core/toType.js index c555ef9df..67af8a67f 100644 --- a/src/core/toType.js +++ b/src/core/toType.js @@ -1,9 +1,5 @@ -define( [ - "../var/class2type", - "../var/toString" -], function( class2type, toString ) { - -"use strict"; +import class2type from "../var/class2type.js"; +import toString from "../var/toString.js"; function toType( obj ) { if ( obj == null ) { @@ -15,5 +11,4 @@ function toType( obj ) { typeof obj; } -return toType; -} ); +export default toType; diff --git a/src/core/var/rhtml.js b/src/core/var/rhtml.js index d7921aa3b..3dace14c5 100644 --- a/src/core/var/rhtml.js +++ b/src/core/var/rhtml.js @@ -1,7 +1 @@ -define( function() { - -"use strict"; - -return ( /HTML$/i ); - -} ); +export default ( /HTML$/i ); diff --git a/src/core/var/rsingleTag.js b/src/core/var/rsingleTag.js index 340b80db0..5bf52d568 100644 --- a/src/core/var/rsingleTag.js +++ b/src/core/var/rsingleTag.js @@ -1,7 +1,3 @@ -define( function() { - "use strict"; - - // rsingleTag matches a string consisting of a single HTML element with no attributes - // and captures the element's name - return ( /^<([a-z][^\/\0>:\x20\t\r\n\f]*)[\x20\t\r\n\f]*\/?>(?:<\/\1>|)$/i ); -} ); +// rsingleTag matches a string consisting of a single HTML element with no attributes +// and captures the element's name +export default ( /^<([a-z][^\/\0>:\x20\t\r\n\f]*)[\x20\t\r\n\f]*\/?>(?:<\/\1>|)$/i ); diff --git a/src/css.js b/src/css.js index c700c0aa5..6d67ffaa7 100644 --- a/src/css.js +++ b/src/css.js @@ -1,27 +1,22 @@ -define( [ - "./core", - "./core/access", - "./core/nodeName", - "./var/rcssNum", - "./var/isIE", - "./css/var/rnumnonpx", - "./css/var/cssExpand", - "./css/isAutoPx", - "./css/cssCamelCase", - "./css/var/getStyles", - "./css/var/swap", - "./css/curCSS", - "./css/adjustCSS", - "./css/support", - "./css/finalPropName", +import jQuery from "./core.js"; +import access from "./core/access.js"; +import nodeName from "./core/nodeName.js"; +import rcssNum from "./var/rcssNum.js"; +import isIE from "./var/isIE.js"; +import rnumnonpx from "./css/var/rnumnonpx.js"; +import cssExpand from "./css/var/cssExpand.js"; +import isAutoPx from "./css/isAutoPx.js"; +import cssCamelCase from "./css/cssCamelCase.js"; +import getStyles from "./css/var/getStyles.js"; +import swap from "./css/var/swap.js"; +import curCSS from "./css/curCSS.js"; +import adjustCSS from "./css/adjustCSS.js"; +import support from "./css/support.js"; +import finalPropName from "./css/finalPropName.js"; - "./core/init", - "./core/ready", - "./selector" // contains -], function( jQuery, access, nodeName, rcssNum, isIE, rnumnonpx, cssExpand, isAutoPx, - cssCamelCase, getStyles, swap, curCSS, adjustCSS, support, finalPropName ) { - -"use strict"; +import "./core/init.js"; +import "./core/ready.js"; +import "./selector.js"; // contains var @@ -426,5 +421,4 @@ jQuery.fn.extend( { } } ); -return jQuery; -} ); +export default jQuery; diff --git a/src/css/adjustCSS.js b/src/css/adjustCSS.js index 5341a7890..d973ff386 100644 --- a/src/css/adjustCSS.js +++ b/src/css/adjustCSS.js @@ -1,10 +1,6 @@ -define( [ - "../core", - "./isAutoPx", - "../var/rcssNum" -], function( jQuery, isAutoPx, rcssNum ) { - -"use strict"; +import jQuery from "../core.js"; +import isAutoPx from "./isAutoPx.js"; +import rcssNum from "../var/rcssNum.js"; function adjustCSS( elem, prop, valueParts, tween ) { var adjusted, scale, @@ -71,5 +67,4 @@ function adjustCSS( elem, prop, valueParts, tween ) { return adjusted; } -return adjustCSS; -} ); +export default adjustCSS; diff --git a/src/css/cssCamelCase.js b/src/css/cssCamelCase.js index 9b5c328ad..895303248 100644 --- a/src/css/cssCamelCase.js +++ b/src/css/cssCamelCase.js @@ -1,8 +1,4 @@ -define( [ - "../core/camelCase" -], function( camelCase ) { - -"use strict"; +import camelCase from "../core/camelCase.js"; // Matches dashed string for camelizing var rmsPrefix = /^-ms-/; @@ -15,6 +11,4 @@ function cssCamelCase( string ) { return camelCase( string.replace( rmsPrefix, "ms-" ) ); } -return cssCamelCase; - -} ); +export default cssCamelCase; diff --git a/src/css/curCSS.js b/src/css/curCSS.js index 882e7423e..59a639f68 100644 --- a/src/css/curCSS.js +++ b/src/css/curCSS.js @@ -1,10 +1,6 @@ -define( [ - "../core", - "../core/isAttached", - "./var/getStyles" -], function( jQuery, isAttached, getStyles ) { - -"use strict"; +import jQuery from "../core.js"; +import isAttached from "../core/isAttached.js"; +import getStyles from "./var/getStyles.js"; function curCSS( elem, name, computed ) { var ret; @@ -28,5 +24,4 @@ function curCSS( elem, name, computed ) { ret; } -return curCSS; -} ); +export default curCSS; diff --git a/src/css/finalPropName.js b/src/css/finalPropName.js index c290eb2b4..40d2fb193 100644 --- a/src/css/finalPropName.js +++ b/src/css/finalPropName.js @@ -1,8 +1,4 @@ -define( [ - "../var/document" -], function( document ) { - -"use strict"; +import document from "../var/document.js"; var cssPrefixes = [ "Webkit", "Moz", "ms" ], emptyStyle = document.createElement( "div" ).style, @@ -36,6 +32,4 @@ function finalPropName( name ) { return vendorProps[ name ] = vendorPropName( name ) || name; } -return finalPropName; - -} ); +export default finalPropName; diff --git a/src/css/hiddenVisibleSelectors.js b/src/css/hiddenVisibleSelectors.js index d7a9339dd..1f892dfe0 100644 --- a/src/css/hiddenVisibleSelectors.js +++ b/src/css/hiddenVisibleSelectors.js @@ -1,9 +1,6 @@ -define( [ - "../core", - "../selector" -], function( jQuery ) { +import jQuery from "../core.js"; -"use strict"; +import "../selector.js"; jQuery.expr.pseudos.hidden = function( elem ) { return !jQuery.expr.pseudos.visible( elem ); @@ -11,5 +8,3 @@ jQuery.expr.pseudos.hidden = function( elem ) { jQuery.expr.pseudos.visible = function( elem ) { return !!( elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length ); }; - -} ); diff --git a/src/css/isAutoPx.js b/src/css/isAutoPx.js index ff4b7def1..a55d5bbcc 100644 --- a/src/css/isAutoPx.js +++ b/src/css/isAutoPx.js @@ -1,7 +1,3 @@ -define( function() { - -"use strict"; - var ralphaStart = /^[a-z]/, // The regex visualized: @@ -36,6 +32,4 @@ function isAutoPx( prop ) { rautoPx.test( prop[ 0 ].toUpperCase() + prop.slice( 1 ) ); }; -return isAutoPx; - -} ); +export default isAutoPx; diff --git a/src/css/showHide.js b/src/css/showHide.js index 3eeafef11..dc273f98c 100644 --- a/src/css/showHide.js +++ b/src/css/showHide.js @@ -1,10 +1,6 @@ -define( [ - "../core", - "../data/var/dataPriv", - "../css/var/isHiddenWithinTree" -], function( jQuery, dataPriv, isHiddenWithinTree ) { - -"use strict"; +import jQuery from "../core.js"; +import dataPriv from "../data/var/dataPriv.js"; +import isHiddenWithinTree from "../css/var/isHiddenWithinTree.js"; var defaultDisplayMap = {}; @@ -101,5 +97,4 @@ jQuery.fn.extend( { } } ); -return showHide; -} ); +export default showHide; diff --git a/src/css/support.js b/src/css/support.js index 053f494b2..505adafb6 100644 --- a/src/css/support.js +++ b/src/css/support.js @@ -1,10 +1,6 @@ -define( [ - "../var/document", - "../var/documentElement", - "../var/support" -], function( document, documentElement, support ) { - -"use strict"; +import document from "../var/document.js"; +import documentElement from "../var/documentElement.js"; +import support from "../var/support.js"; var reliableTrDimensionsVal; @@ -35,6 +31,4 @@ support.reliableTrDimensions = function() { return reliableTrDimensionsVal; }; -return support; - -} ); +export default support; diff --git a/src/css/var/cssExpand.js b/src/css/var/cssExpand.js index dd2007c3f..66062e2ee 100644 --- a/src/css/var/cssExpand.js +++ b/src/css/var/cssExpand.js @@ -1,5 +1 @@ -define( function() { - "use strict"; - - return [ "Top", "Right", "Bottom", "Left" ]; -} ); +export default [ "Top", "Right", "Bottom", "Left" ]; diff --git a/src/css/var/getStyles.js b/src/css/var/getStyles.js index 7adbdcfb5..e55da23ef 100644 --- a/src/css/var/getStyles.js +++ b/src/css/var/getStyles.js @@ -1,19 +1,15 @@ -define( function() { - "use strict"; +export default function( elem ) { - return function( elem ) { + // Support: IE <=11+ (trac-14150) + // In IE popup's `window` is the opener window which makes `window.getComputedStyle( elem )` + // break. Using `elem.ownerDocument.defaultView` avoids the issue. + var view = elem.ownerDocument.defaultView; - // Support: IE <=11+ (trac-14150) - // In IE popup's `window` is the opener window which makes `window.getComputedStyle( elem )` - // break. Using `elem.ownerDocument.defaultView` avoids the issue. - var view = elem.ownerDocument.defaultView; + // `document.implementation.createHTMLDocument( "" )` has a `null` `defaultView` + // property; check `defaultView` truthiness to fallback to window in such a case. + if ( !view ) { + view = window; + } - // `document.implementation.createHTMLDocument( "" )` has a `null` `defaultView` - // property; check `defaultView` truthiness to fallback to window in such a case. - if ( !view ) { - view = window; - } - - return view.getComputedStyle( elem ); - }; -} ); + return view.getComputedStyle( elem ); +}; diff --git a/src/css/var/isHiddenWithinTree.js b/src/css/var/isHiddenWithinTree.js index 1e99b96d3..0cc163178 100644 --- a/src/css/var/isHiddenWithinTree.js +++ b/src/css/var/isHiddenWithinTree.js @@ -1,26 +1,20 @@ -define( [ - "../../core" +import jQuery from "../../core.js"; - // css is assumed -], function( jQuery ) { - "use strict"; +// isHiddenWithinTree reports if an element has a non-"none" display style (inline and/or +// through the CSS cascade), which is useful in deciding whether or not to make it visible. +// It differs from the :hidden selector (jQuery.expr.pseudos.hidden) in two important ways: +// * A hidden ancestor does not force an element to be classified as hidden. +// * Being disconnected from the document does not force an element to be classified as hidden. +// These differences improve the behavior of .toggle() et al. when applied to elements that are +// detached or contained within hidden ancestors (gh-2404, gh-2863). +export default function( elem, el ) { - // isHiddenWithinTree reports if an element has a non-"none" display style (inline and/or - // through the CSS cascade), which is useful in deciding whether or not to make it visible. - // It differs from the :hidden selector (jQuery.expr.pseudos.hidden) in two important ways: - // * A hidden ancestor does not force an element to be classified as hidden. - // * Being disconnected from the document does not force an element to be classified as hidden. - // These differences improve the behavior of .toggle() et al. when applied to elements that are - // detached or contained within hidden ancestors (gh-2404, gh-2863). - return function( elem, el ) { + // isHiddenWithinTree might be called from jQuery#filter function; + // in that case, element will be second argument + elem = el || elem; - // isHiddenWithinTree might be called from jQuery#filter function; - // in that case, element will be second argument - elem = el || elem; - - // Inline style trumps all - return elem.style.display === "none" || - elem.style.display === "" && - jQuery.css( elem, "display" ) === "none"; - }; -} ); + // Inline style trumps all + return elem.style.display === "none" || + elem.style.display === "" && + jQuery.css( elem, "display" ) === "none"; +}; diff --git a/src/css/var/rnumnonpx.js b/src/css/var/rnumnonpx.js index 056cda7ad..18a9dad6c 100644 --- a/src/css/var/rnumnonpx.js +++ b/src/css/var/rnumnonpx.js @@ -1,7 +1,3 @@ -define( [ - "../../var/pnum" -], function( pnum ) { - "use strict"; +import pnum from "../../var/pnum.js"; - return new RegExp( "^(" + pnum + ")(?!px)[a-z%]+$", "i" ); -} ); +export default new RegExp( "^(" + pnum + ")(?!px)[a-z%]+$", "i" ); diff --git a/src/css/var/swap.js b/src/css/var/swap.js index 69388e5f7..e720fff9b 100644 --- a/src/css/var/swap.js +++ b/src/css/var/swap.js @@ -1,9 +1,5 @@ -define( function() { - -"use strict"; - // A method for quickly swapping in/out CSS properties to get correct calculations. -return function( elem, options, callback ) { +export default function( elem, options, callback ) { var ret, name, old = {}; @@ -22,5 +18,3 @@ return function( elem, options, callback ) { return ret; }; - -} ); diff --git a/src/data.js b/src/data.js index d6706493a..cd658b386 100644 --- a/src/data.js +++ b/src/data.js @@ -1,12 +1,8 @@ -define( [ - "./core", - "./core/access", - "./core/camelCase", - "./data/var/dataPriv", - "./data/var/dataUser" -], function( jQuery, access, camelCase, dataPriv, dataUser ) { - -"use strict"; +import jQuery from "./core.js"; +import access from "./core/access.js"; +import camelCase from "./core/camelCase.js"; +import dataPriv from "./data/var/dataPriv.js"; +import dataUser from "./data/var/dataUser.js"; // Implementation Summary // @@ -176,5 +172,4 @@ jQuery.fn.extend( { } } ); -return jQuery; -} ); +export default jQuery; diff --git a/src/data/Data.js b/src/data/Data.js index c94480fcd..556f4e39c 100644 --- a/src/data/Data.js +++ b/src/data/Data.js @@ -1,11 +1,7 @@ -define( [ - "../core", - "../core/camelCase", - "../var/rnothtmlwhite", - "./var/acceptData" -], function( jQuery, camelCase, rnothtmlwhite, acceptData ) { - -"use strict"; +import jQuery from "../core.js"; +import camelCase from "../core/camelCase.js"; +import rnothtmlwhite from "../var/rnothtmlwhite.js"; +import acceptData from "./var/acceptData.js"; function Data() { this.expando = jQuery.expando + Data.uid++; @@ -158,5 +154,4 @@ Data.prototype = { } }; -return Data; -} ); +export default Data; diff --git a/src/data/var/acceptData.js b/src/data/var/acceptData.js index e00f7538b..4fc47b30a 100644 --- a/src/data/var/acceptData.js +++ b/src/data/var/acceptData.js @@ -1,11 +1,7 @@ -define( function() { - -"use strict"; - /** * Determines whether an object can have data */ -return function( owner ) { +export default function( owner ) { // Accepts only: // - Node @@ -15,5 +11,3 @@ return function( owner ) { // - Any return owner.nodeType === 1 || owner.nodeType === 9 || !( +owner.nodeType ); }; - -} ); diff --git a/src/data/var/dataPriv.js b/src/data/var/dataPriv.js index 72713c88c..94ea1190e 100644 --- a/src/data/var/dataPriv.js +++ b/src/data/var/dataPriv.js @@ -1,7 +1,3 @@ -define( [ - "../Data" -], function( Data ) { - "use strict"; +import Data from "../Data.js"; - return new Data(); -} ); +export default new Data(); diff --git a/src/data/var/dataUser.js b/src/data/var/dataUser.js index 72713c88c..94ea1190e 100644 --- a/src/data/var/dataUser.js +++ b/src/data/var/dataUser.js @@ -1,7 +1,3 @@ -define( [ - "../Data" -], function( Data ) { - "use strict"; +import Data from "../Data.js"; - return new Data(); -} ); +export default new Data(); diff --git a/src/deferred.js b/src/deferred.js index 771e8381b..d4eaf7a4b 100644 --- a/src/deferred.js +++ b/src/deferred.js @@ -1,10 +1,7 @@ -define( [ - "./core", - "./var/slice", - "./callbacks" -], function( jQuery, slice ) { +import jQuery from "./core.js"; +import slice from "./var/slice.js"; -"use strict"; +import "./callbacks.js"; function Identity( v ) { return v; @@ -392,5 +389,4 @@ jQuery.extend( { } } ); -return jQuery; -} ); +export default jQuery; diff --git a/src/deferred/exceptionHook.js b/src/deferred/exceptionHook.js index f6faf4123..2e3c7cc35 100644 --- a/src/deferred/exceptionHook.js +++ b/src/deferred/exceptionHook.js @@ -1,9 +1,6 @@ -define( [ - "../core", - "../deferred" -], function( jQuery ) { +import jQuery from "../core.js"; -"use strict"; +import "../deferred.js"; // These usually indicate a programmer mistake during development, // warn about them ASAP rather than swallowing them by default. @@ -19,5 +16,3 @@ jQuery.Deferred.exceptionHook = function( error, stack ) { ); } }; - -} ); diff --git a/src/deprecated.js b/src/deprecated.js index 11728081c..b7879c208 100644 --- a/src/deprecated.js +++ b/src/deprecated.js @@ -1,11 +1,8 @@ -define( [ - "./core", - "./var/slice", - "./var/trim", - "./event/alias" -], function( jQuery, slice, trim ) { +import jQuery from "./core.js"; +import slice from "./var/slice.js"; +import trim from "./var/trim.js"; -"use strict"; +import "./event/alias.js"; jQuery.fn.extend( { @@ -70,4 +67,3 @@ jQuery.holdReady = function( hold ) { jQuery.trim = function( text ) { return text == null ? "" : trim.call( text ); }; -} ); diff --git a/src/dimensions.js b/src/dimensions.js index 2a2c0391d..6f1bf7d2f 100644 --- a/src/dimensions.js +++ b/src/dimensions.js @@ -1,11 +1,8 @@ -define( [ - "./core", - "./core/access", - "./var/isWindow", - "./css" -], function( jQuery, access, isWindow ) { +import jQuery from "./core.js"; +import access from "./core/access.js"; +import isWindow from "./var/isWindow.js"; -"use strict"; +import "./css.js"; // Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods jQuery.each( { Height: "height", Width: "width" }, function( name, type ) { @@ -53,5 +50,4 @@ jQuery.each( { Height: "height", Width: "width" }, function( name, type ) { } ); } ); -return jQuery; -} ); +export default jQuery; diff --git a/src/effects.js b/src/effects.js index 46ad988ad..030d3c7ba 100644 --- a/src/effects.js +++ b/src/effects.js @@ -1,26 +1,21 @@ -define( [ - "./core", - "./var/document", - "./var/rcssNum", - "./var/rnothtmlwhite", - "./css/var/cssExpand", - "./css/var/isHiddenWithinTree", - "./css/adjustCSS", - "./css/cssCamelCase", - "./data/var/dataPriv", - "./css/showHide", +import jQuery from "./core.js"; +import document from "./var/document.js"; +import rcssNum from "./var/rcssNum.js"; +import rnothtmlwhite from "./var/rnothtmlwhite.js"; +import cssExpand from "./css/var/cssExpand.js"; +import isHiddenWithinTree from "./css/var/isHiddenWithinTree.js"; +import adjustCSS from "./css/adjustCSS.js"; +import cssCamelCase from "./css/cssCamelCase.js"; +import dataPriv from "./data/var/dataPriv.js"; +import showHide from "./css/showHide.js"; - "./core/init", - "./queue", - "./deferred", - "./traversing", - "./manipulation", - "./css", - "./effects/Tween" -], function( jQuery, document, rcssNum, rnothtmlwhite, cssExpand, - isHiddenWithinTree, adjustCSS, cssCamelCase, dataPriv, showHide ) { - -"use strict"; +import "./core/init.js"; +import "./queue.js"; +import "./deferred.js"; +import "./traversing.js"; +import "./manipulation.js"; +import "./css.js"; +import "./effects/Tween.js"; var fxNow, inProgress, @@ -225,12 +220,9 @@ function defaultPrefilter( elem, props, opts ) { showHide( [ elem ], true ); } - /* eslint-disable no-loop-func */ - + // eslint-disable-next-line no-loop-func anim.done( function() { - /* eslint-enable no-loop-func */ - // The final step of a "hide" animation is actually hiding the element if ( !hidden ) { showHide( [ elem ] ); @@ -693,5 +685,4 @@ jQuery.fx.speeds = { _default: 400 }; -return jQuery; -} ); +export default jQuery; diff --git a/src/effects/Tween.js b/src/effects/Tween.js index 0c5fe67d3..9a75a9af2 100644 --- a/src/effects/Tween.js +++ b/src/effects/Tween.js @@ -1,12 +1,8 @@ -define( [ - "../core", - "../css/isAutoPx", - "../css/finalPropName", +import jQuery from "../core.js"; +import isAutoPx from "../css/isAutoPx.js"; +import finalPropName from "../css/finalPropName.js"; - "../css" -], function( jQuery, isAutoPx, finalPropName ) { - -"use strict"; +import "../css.js"; function Tween( elem, options, prop, end, easing ) { return new Tween.prototype.init( elem, options, prop, end, easing ); @@ -112,5 +108,3 @@ jQuery.fx = Tween.prototype.init; // Back compat <1.8 extension point jQuery.fx.step = {}; - -} ); diff --git a/src/effects/animatedSelector.js b/src/effects/animatedSelector.js index 24c1bfba2..327956f72 100644 --- a/src/effects/animatedSelector.js +++ b/src/effects/animatedSelector.js @@ -1,15 +1,10 @@ -define( [ - "../core", - "../selector", - "../effects" -], function( jQuery ) { +import jQuery from "../core.js"; -"use strict"; +import "../selector.js"; +import "../effects.js"; jQuery.expr.pseudos.animated = function( elem ) { return jQuery.grep( jQuery.timers, function( fn ) { return elem === fn.elem; } ).length; }; - -} ); diff --git a/src/event.js b/src/event.js index 405d176a0..7f66d49de 100644 --- a/src/event.js +++ b/src/event.js @@ -1,19 +1,14 @@ -define( [ - "./core", - "./var/document", - "./var/documentElement", - "./var/rnothtmlwhite", - "./var/rcheckableType", - "./var/slice", - "./data/var/dataPriv", - "./core/nodeName", +import jQuery from "./core.js"; +import document from "./var/document.js"; +import documentElement from "./var/documentElement.js"; +import rnothtmlwhite from "./var/rnothtmlwhite.js"; +import rcheckableType from "./var/rcheckableType.js"; +import slice from "./var/slice.js"; +import dataPriv from "./data/var/dataPriv.js"; +import nodeName from "./core/nodeName.js"; - "./core/init", - "./selector" -], function( jQuery, document, documentElement, rnothtmlwhite, - rcheckableType, slice, dataPriv, nodeName ) { - -"use strict"; +import "./core/init.js"; +import "./selector.js"; var rkeyEvent = /^key/, @@ -857,5 +852,4 @@ jQuery.fn.extend( { } } ); -return jQuery; -} ); +export default jQuery; diff --git a/src/event/ajax.js b/src/event/ajax.js index dd9c0ffe2..8c64d9b3e 100644 --- a/src/event/ajax.js +++ b/src/event/ajax.js @@ -1,9 +1,6 @@ -define( [ - "../core", - "../event" -], function( jQuery ) { +import jQuery from "../core.js"; -"use strict"; +import "../event.js"; // Attach a bunch of functions for handling common AJAX events jQuery.each( [ @@ -18,5 +15,3 @@ jQuery.each( [ return this.on( type, fn ); }; } ); - -} ); diff --git a/src/event/alias.js b/src/event/alias.js index 46bd1ae80..346951b11 100644 --- a/src/event/alias.js +++ b/src/event/alias.js @@ -1,11 +1,7 @@ -define( [ - "../core", +import jQuery from "../core.js"; - "../event", - "./trigger" -], function( jQuery ) { - -"use strict"; +import "../event.js"; +import "./trigger.js"; jQuery.each( ( "blur focus focusin focusout resize scroll click dblclick " + "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " + @@ -25,5 +21,3 @@ jQuery.fn.extend( { return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver ); } } ); - -} ); diff --git a/src/event/trigger.js b/src/event/trigger.js index 39f641b70..aba4c7edd 100644 --- a/src/event/trigger.js +++ b/src/event/trigger.js @@ -1,14 +1,11 @@ -define( [ - "../core", - "../var/document", - "../data/var/dataPriv", - "../data/var/acceptData", - "../var/hasOwn", - "../var/isWindow", - "../event" -], function( jQuery, document, dataPriv, acceptData, hasOwn, isWindow ) { +import jQuery from "../core.js"; +import document from "../var/document.js"; +import dataPriv from "../data/var/dataPriv.js"; +import acceptData from "../data/var/acceptData.js"; +import hasOwn from "../var/hasOwn.js"; +import isWindow from "../var/isWindow.js"; -"use strict"; +import "../event.js"; var rfocusMorph = /^(?:focusinfocus|focusoutblur)$/, stopPropagationCallback = function( e ) { @@ -194,5 +191,4 @@ jQuery.fn.extend( { } } ); -return jQuery; -} ); +export default jQuery; diff --git a/src/exports/amd.js b/src/exports/amd.js index cbb1ef580..44587ab3a 100644 --- a/src/exports/amd.js +++ b/src/exports/amd.js @@ -1,8 +1,4 @@ -define( [ - "../core" -], function( jQuery ) { - -"use strict"; +import jQuery from "../core.js"; // Register as a named AMD module, since jQuery can be concatenated with other // files that may use define, but not via a proper concatenation script that @@ -22,5 +18,3 @@ if ( typeof define === "function" && define.amd ) { return jQuery; } ); } - -} ); diff --git a/src/exports/global.js b/src/exports/global.js index 460b56e47..b49496fbb 100644 --- a/src/exports/global.js +++ b/src/exports/global.js @@ -1,8 +1,4 @@ -define( [ - "../core" -], function( jQuery, noGlobal ) { - -"use strict"; +import jQuery from "../core.js"; var @@ -27,8 +23,6 @@ jQuery.noConflict = function( deep ) { // Expose jQuery and $ identifiers, even in AMD // (#7102#comment:10, https://github.com/jquery/jquery/pull/557) // and CommonJS for browser emulators (#13566) -if ( !noGlobal ) { +if ( typeof noGlobal === "undefined" ) { window.jQuery = window.$ = jQuery; } - -} ); diff --git a/src/jquery.js b/src/jquery.js index aee1a6387..24e58a93c 100644 --- a/src/jquery.js +++ b/src/jquery.js @@ -1,39 +1,35 @@ -define( [ - "./core", - "./selector", - "./traversing", - "./callbacks", - "./deferred", - "./deferred/exceptionHook", - "./core/ready", - "./data", - "./queue", - "./queue/delay", - "./attributes", - "./event", - "./manipulation", - "./manipulation/_evalUrl", - "./wrap", - "./css", - "./css/hiddenVisibleSelectors", - "./serialize", - "./ajax", - "./ajax/xhr", - "./ajax/script", - "./ajax/jsonp", - "./ajax/load", - "./event/ajax", - "./effects", - "./effects/animatedSelector", - "./offset", - "./dimensions", - "./deprecated", - "./exports/amd", - "./exports/global" -], function( jQuery ) { +import jQuery from "./core.js"; -"use strict"; +import "./selector.js"; +import "./traversing.js"; +import "./callbacks.js"; +import "./deferred.js"; +import "./deferred/exceptionHook.js"; +import "./core/ready.js"; +import "./data.js"; +import "./queue.js"; +import "./queue/delay.js"; +import "./attributes.js"; +import "./event.js"; +import "./manipulation.js"; +import "./manipulation/_evalUrl.js"; +import "./wrap.js"; +import "./css.js"; +import "./css/hiddenVisibleSelectors.js"; +import "./serialize.js"; +import "./ajax.js"; +import "./ajax/xhr.js"; +import "./ajax/script.js"; +import "./ajax/jsonp.js"; +import "./core/parseHTML.js"; +import "./ajax/load.js"; +import "./event/ajax.js"; +import "./effects.js"; +import "./effects/animatedSelector.js"; +import "./offset.js"; +import "./dimensions.js"; +import "./deprecated.js"; +import "./exports/amd.js"; +import "./exports/global.js"; -return jQuery; - -} ); +export default jQuery; diff --git a/src/manipulation.js b/src/manipulation.js index 803a67bd6..7140748ed 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -1,32 +1,25 @@ -define( [ - "./core", - "./core/isAttached", - "./var/flat", - "./var/isIE", - "./var/push", - "./core/access", - "./manipulation/var/rtagName", - "./manipulation/var/rscriptType", - "./manipulation/wrapMap", - "./manipulation/getAll", - "./manipulation/setGlobalEval", - "./manipulation/buildFragment", +import jQuery from "./core.js"; +import isAttached from "./core/isAttached.js"; +import flat from "./var/flat.js"; +import isIE from "./var/isIE.js"; +import push from "./var/push.js"; +import access from "./core/access.js"; +import rtagName from "./manipulation/var/rtagName.js"; +import rscriptType from "./manipulation/var/rscriptType.js"; +import wrapMap from "./manipulation/wrapMap.js"; +import getAll from "./manipulation/getAll.js"; +import setGlobalEval from "./manipulation/setGlobalEval.js"; +import buildFragment from "./manipulation/buildFragment.js"; +import dataPriv from "./data/var/dataPriv.js"; +import dataUser from "./data/var/dataUser.js"; +import acceptData from "./data/var/acceptData.js"; +import DOMEval from "./core/DOMEval.js"; +import nodeName from "./core/nodeName.js"; - "./data/var/dataPriv", - "./data/var/dataUser", - "./data/var/acceptData", - "./core/DOMEval", - "./core/nodeName", - - "./core/init", - "./traversing", - "./selector", - "./event" -], function( jQuery, isAttached, flat, isIE, push, access, rtagName, - rscriptType, wrapMap, getAll, setGlobalEval, buildFragment, - dataPriv, dataUser, acceptData, DOMEval, nodeName ) { - -"use strict"; +import "./core/init.js"; +import "./traversing.js"; +import "./selector.js"; +import "./event.js"; var @@ -458,5 +451,4 @@ jQuery.each( { }; } ); -return jQuery; -} ); +export default jQuery; diff --git a/src/manipulation/_evalUrl.js b/src/manipulation/_evalUrl.js index 9a4d2ac6f..54133fc9b 100644 --- a/src/manipulation/_evalUrl.js +++ b/src/manipulation/_evalUrl.js @@ -1,8 +1,4 @@ -define( [ - "../ajax" -], function( jQuery ) { - -"use strict"; +import jQuery from "../ajax.js"; jQuery._evalUrl = function( url, options ) { return jQuery.ajax( { @@ -27,6 +23,4 @@ jQuery._evalUrl = function( url, options ) { } ); }; -return jQuery._evalUrl; - -} ); +export default jQuery._evalUrl; diff --git a/src/manipulation/buildFragment.js b/src/manipulation/buildFragment.js index 01dcff6e5..daf383aea 100644 --- a/src/manipulation/buildFragment.js +++ b/src/manipulation/buildFragment.js @@ -1,15 +1,11 @@ -define( [ - "../core", - "../core/toType", - "../core/isAttached", - "./var/rtagName", - "./var/rscriptType", - "./wrapMap", - "./getAll", - "./setGlobalEval" -], function( jQuery, toType, isAttached, rtagName, rscriptType, wrapMap, getAll, setGlobalEval ) { - -"use strict"; +import jQuery from "../core.js"; +import toType from "../core/toType.js"; +import isAttached from "../core/isAttached.js"; +import rtagName from "./var/rtagName.js"; +import rscriptType from "./var/rscriptType.js"; +import wrapMap from "./wrapMap.js"; +import getAll from "./getAll.js"; +import setGlobalEval from "./setGlobalEval.js"; var rhtml = /<|&#?\w+;/; @@ -97,5 +93,4 @@ function buildFragment( elems, context, scripts, selection, ignored ) { return fragment; } -return buildFragment; -} ); +export default buildFragment; diff --git a/src/manipulation/getAll.js b/src/manipulation/getAll.js index 89634d694..995d22c0c 100644 --- a/src/manipulation/getAll.js +++ b/src/manipulation/getAll.js @@ -1,9 +1,5 @@ -define( [ - "../core", - "../core/nodeName" -], function( jQuery, nodeName ) { - -"use strict"; +import jQuery from "../core.js"; +import nodeName from "../core/nodeName.js"; function getAll( context, tag ) { @@ -28,5 +24,4 @@ function getAll( context, tag ) { return ret; } -return getAll; -} ); +export default getAll; diff --git a/src/manipulation/setGlobalEval.js b/src/manipulation/setGlobalEval.js index cf95240a4..c6f7ee9ab 100644 --- a/src/manipulation/setGlobalEval.js +++ b/src/manipulation/setGlobalEval.js @@ -1,8 +1,4 @@ -define( [ - "../data/var/dataPriv" -], function( dataPriv ) { - -"use strict"; +import dataPriv from "../data/var/dataPriv.js"; // Mark scripts as having already been evaluated function setGlobalEval( elems, refElements ) { @@ -18,5 +14,4 @@ function setGlobalEval( elems, refElements ) { } } -return setGlobalEval; -} ); +export default setGlobalEval; diff --git a/src/manipulation/var/rscriptType.js b/src/manipulation/var/rscriptType.js index cd1430a7e..879651c7c 100644 --- a/src/manipulation/var/rscriptType.js +++ b/src/manipulation/var/rscriptType.js @@ -1,5 +1 @@ -define( function() { - "use strict"; - - return ( /^$|^module$|\/(?:java|ecma)script/i ); -} ); +export default ( /^$|^module$|\/(?:java|ecma)script/i ); diff --git a/src/manipulation/var/rtagName.js b/src/manipulation/var/rtagName.js index 7435620c1..b35acc999 100644 --- a/src/manipulation/var/rtagName.js +++ b/src/manipulation/var/rtagName.js @@ -1,8 +1,4 @@ -define( function() { - "use strict"; - - // rtagName captures the name from the first start tag in a string of HTML - // https://html.spec.whatwg.org/multipage/syntax.html#tag-open-state - // https://html.spec.whatwg.org/multipage/syntax.html#tag-name-state - return ( /<([a-z][^\/\0>\x20\t\r\n\f]*)/i ); -} ); +// rtagName captures the name from the first start tag in a string of HTML +// https://html.spec.whatwg.org/multipage/syntax.html#tag-open-state +// https://html.spec.whatwg.org/multipage/syntax.html#tag-name-state +export default ( /<([a-z][^\/\0>\x20\t\r\n\f]*)/i ); diff --git a/src/manipulation/wrapMap.js b/src/manipulation/wrapMap.js index 065225928..01937ecc3 100644 --- a/src/manipulation/wrapMap.js +++ b/src/manipulation/wrapMap.js @@ -1,7 +1,3 @@ -define( function() { - -"use strict"; - // We have to close these tags to support XHTML (#13200) var wrapMap = { @@ -21,5 +17,4 @@ var wrapMap = { wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead; wrapMap.th = wrapMap.td; -return wrapMap; -} ); +export default wrapMap; diff --git a/src/offset.js b/src/offset.js index 91c96d877..7d98083b9 100644 --- a/src/offset.js +++ b/src/offset.js @@ -1,14 +1,11 @@ -define( [ - "./core", - "./core/access", - "./var/documentElement", - "./var/isWindow", - "./core/init", - "./css", - "./selector" // contains -], function( jQuery, access, documentElement, isWindow ) { +import jQuery from "./core.js"; +import access from "./core/access.js"; +import documentElement from "./var/documentElement.js"; +import isWindow from "./var/isWindow.js"; -"use strict"; +import "./core/init.js"; +import "./css.js"; +import "./selector.js"; // contains jQuery.offset = { setOffset: function( elem, options, i ) { @@ -201,5 +198,4 @@ jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function( }; } ); -return jQuery; -} ); +export default jQuery; diff --git a/src/queue.js b/src/queue.js index fbbbeab71..0028d7e7f 100644 --- a/src/queue.js +++ b/src/queue.js @@ -1,11 +1,8 @@ -define( [ - "./core", - "./data/var/dataPriv", - "./deferred", - "./callbacks" -], function( jQuery, dataPriv ) { +import jQuery from "./core.js"; +import dataPriv from "./data/var/dataPriv.js"; -"use strict"; +import "./deferred.js"; +import "./callbacks.js"; jQuery.extend( { queue: function( elem, type, data ) { @@ -141,5 +138,4 @@ jQuery.fn.extend( { } } ); -return jQuery; -} ); +export default jQuery; diff --git a/src/queue/delay.js b/src/queue/delay.js index d471eedc5..fe3a6f6b7 100644 --- a/src/queue/delay.js +++ b/src/queue/delay.js @@ -1,10 +1,7 @@ -define( [ - "../core", - "../queue", - "../effects" // Delay is optional because of this dependency -], function( jQuery ) { +import jQuery from "../core.js"; -"use strict"; +import "../queue.js"; +import "../effects.js"; // Delay is optional because of this dependency // Based off of the plugin by Clint Helfers, with permission. // https://web.archive.org/web/20100324014747/http://blindsignals.com/index.php/2009/07/jquery-delay/ @@ -19,6 +16,3 @@ jQuery.fn.delay = function( time, type ) { }; } ); }; - -return jQuery.fn.delay; -} ); diff --git a/src/selector.js b/src/selector.js index 8033f1115..019f25d62 100644 --- a/src/selector.js +++ b/src/selector.js @@ -1,22 +1,17 @@ -define( [ - "./core", - "./core/nodeName", - "./var/document", - "./var/documentElement", - "./var/indexOf", - "./var/pop", - "./var/push", - "./selector/rbuggyQSA", - "./selector/support", +import jQuery from "./core.js"; +import nodeName from "./core/nodeName.js"; +import document from "./var/document.js"; +import documentElement from "./var/documentElement.js"; +import indexOf from "./var/indexOf.js"; +import pop from "./var/pop.js"; +import push from "./var/push.js"; +import rbuggyQSA from "./selector/rbuggyQSA.js"; +import support from "./selector/support.js"; - // The following utils are attached directly to the jQuery object. - "./selector/contains", - "./selector/escapeSelector", - "./selector/uniqueSort" -], function( jQuery, nodeName, document, documentElement, indexOf, pop, push, - rbuggyQSA, support ) { - -"use strict"; +// The following utils are attached directly to the jQuery object. +import "./selector/contains.js"; +import "./selector/escapeSelector.js"; +import "./selector/uniqueSort.js"; var preferredDoc = document, matches = documentElement.matches || documentElement.msMatchesSelector; @@ -1642,5 +1637,3 @@ setDocument(); jQuery.find = find; } )(); - -} ); diff --git a/src/selector/contains.js b/src/selector/contains.js index 0d6273c28..a62b97ab5 100644 --- a/src/selector/contains.js +++ b/src/selector/contains.js @@ -1,8 +1,4 @@ -define( [ - "../core" -], function( jQuery ) { - -"use strict"; +import jQuery from "../core.js"; // Note: an element does not contain itself jQuery.contains = function( a, b ) { @@ -18,5 +14,3 @@ jQuery.contains = function( a, b ) { a.compareDocumentPosition && a.compareDocumentPosition( bup ) & 16 ) ); }; - -} ); diff --git a/src/selector/escapeSelector.js b/src/selector/escapeSelector.js index 1d89c2f00..bc61355fa 100644 --- a/src/selector/escapeSelector.js +++ b/src/selector/escapeSelector.js @@ -1,8 +1,4 @@ -define( [ - "../core" -], function( jQuery ) { - -"use strict"; +import jQuery from "../core.js"; // CSS string/identifier serialization // https://drafts.csswg.org/cssom/#common-serializing-idioms @@ -27,5 +23,3 @@ function fcssescape( ch, asCodePoint ) { jQuery.escapeSelector = function( sel ) { return ( sel + "" ).replace( rcssescape, fcssescape ); }; - -} ); diff --git a/src/selector/rbuggyQSA.js b/src/selector/rbuggyQSA.js index eee151afb..f638fc429 100644 --- a/src/selector/rbuggyQSA.js +++ b/src/selector/rbuggyQSA.js @@ -1,9 +1,5 @@ -define( [ - "../var/document", - "../var/isIE" -], function( document, isIE ) { - -"use strict"; +import document from "../var/document.js"; +import isIE from "../var/isIE.js"; var rbuggyQSA = [], testEl = document.createElement( "div" ); @@ -25,6 +21,4 @@ if ( isIE ) { rbuggyQSA = rbuggyQSA.length && new RegExp( rbuggyQSA.join( "|" ) ); -return rbuggyQSA; - -} ); +export default rbuggyQSA; diff --git a/src/selector/support.js b/src/selector/support.js index 86cd2d9ae..cc584bf66 100644 --- a/src/selector/support.js +++ b/src/selector/support.js @@ -1,9 +1,5 @@ -define( [ - "../var/document", - "../var/support" -], function( document, support ) { - -"use strict"; +import document from "../var/document.js"; +import support from "../var/support.js"; // Support: IE 9 - 11+, Edge 12 - 18+ // IE/Edge don't support the :scope pseudo-class. @@ -12,6 +8,4 @@ try { support.scope = true; } catch ( e ) {} -return support; - -} ); +export default support; diff --git a/src/selector/uniqueSort.js b/src/selector/uniqueSort.js index ec97de849..d0bf69198 100644 --- a/src/selector/uniqueSort.js +++ b/src/selector/uniqueSort.js @@ -1,10 +1,6 @@ -define( [ - "../core", - "../var/document", - "../var/sort" -], function( jQuery, document, sort ) { - -"use strict"; +import jQuery from "../core.js"; +import document from "../var/document.js"; +import sort from "../var/sort.js"; var hasDuplicate; @@ -90,5 +86,3 @@ jQuery.uniqueSort = function( results ) { return results; }; - -} ); diff --git a/src/serialize.js b/src/serialize.js index 6743b78e9..a25097edc 100644 --- a/src/serialize.js +++ b/src/serialize.js @@ -1,13 +1,10 @@ -define( [ - "./core", - "./core/toType", - "./var/rcheckableType", - "./core/init", - "./traversing", // filter - "./attributes/prop" -], function( jQuery, toType, rcheckableType ) { +import jQuery from "./core.js"; +import toType from "./core/toType.js"; +import rcheckableType from "./var/rcheckableType.js"; -"use strict"; +import "./core/init.js"; +import "./traversing.js"; // filter +import "./attributes/prop.js"; var rbracket = /\[\]$/, @@ -131,5 +128,4 @@ jQuery.fn.extend( { } } ); -return jQuery; -} ); +export default jQuery; diff --git a/src/traversing.js b/src/traversing.js index f71fbe69e..5ce33f317 100644 --- a/src/traversing.js +++ b/src/traversing.js @@ -1,18 +1,14 @@ -define( [ - "./core", - "./var/getProto", - "./var/indexOf", - "./traversing/var/dir", - "./traversing/var/siblings", - "./traversing/var/rneedsContext", - "./core/nodeName", +import jQuery from "./core.js"; +import getProto from "./var/getProto.js"; +import indexOf from "./var/indexOf.js"; +import dir from "./traversing/var/dir.js"; +import siblings from "./traversing/var/siblings.js"; +import rneedsContext from "./traversing/var/rneedsContext.js"; +import nodeName from "./core/nodeName.js"; - "./core/init", - "./traversing/findFilter", - "./selector" -], function( jQuery, getProto, indexOf, dir, siblings, rneedsContext, nodeName ) { - -"use strict"; +import "./core/init.js"; +import "./traversing/findFilter.js"; +import "./selector.js"; var rparentsprev = /^(?:parents|prev(?:Until|All))/, @@ -194,5 +190,4 @@ jQuery.each( { }; } ); -return jQuery; -} ); +export default jQuery; diff --git a/src/traversing/findFilter.js b/src/traversing/findFilter.js index 2f526b713..42022180c 100644 --- a/src/traversing/findFilter.js +++ b/src/traversing/findFilter.js @@ -1,11 +1,8 @@ -define( [ - "../core", - "../var/indexOf", - "./var/rneedsContext", - "../selector" -], function( jQuery, indexOf, rneedsContext ) { +import jQuery from "../core.js"; +import indexOf from "../var/indexOf.js"; +import rneedsContext from "./var/rneedsContext.js"; -"use strict"; +import "../selector.js"; // Implement the identical functionality for filter and not function winnow( elements, qualifier, not ) { @@ -92,5 +89,3 @@ jQuery.fn.extend( { ).length; } } ); - -} ); diff --git a/src/traversing/var/dir.js b/src/traversing/var/dir.js index 366a823d6..b34bfa4d4 100644 --- a/src/traversing/var/dir.js +++ b/src/traversing/var/dir.js @@ -1,10 +1,6 @@ -define( [ - "../../core" -], function( jQuery ) { +import jQuery from "../../core.js"; -"use strict"; - -return function( elem, dir, until ) { +export default function( elem, dir, until ) { var matched = [], truncate = until !== undefined; @@ -18,5 +14,3 @@ return function( elem, dir, until ) { } return matched; }; - -} ); diff --git a/src/traversing/var/rneedsContext.js b/src/traversing/var/rneedsContext.js index d0663cee8..9038e17cd 100644 --- a/src/traversing/var/rneedsContext.js +++ b/src/traversing/var/rneedsContext.js @@ -1,8 +1,5 @@ -define( [ - "../../core", - "../../selector" -], function( jQuery ) { - "use strict"; +import jQuery from "../../core.js"; - return jQuery.expr.match.needsContext; -} ); +import "../../selector.js"; + +export default jQuery.expr.match.needsContext; diff --git a/src/traversing/var/siblings.js b/src/traversing/var/siblings.js index 952629d0c..910b35a7c 100644 --- a/src/traversing/var/siblings.js +++ b/src/traversing/var/siblings.js @@ -1,8 +1,4 @@ -define( function() { - -"use strict"; - -return function( n, elem ) { +export default function( n, elem ) { var matched = []; for ( ; n; n = n.nextSibling ) { @@ -13,5 +9,3 @@ return function( n, elem ) { return matched; }; - -} ); diff --git a/src/var/ObjectFunctionString.js b/src/var/ObjectFunctionString.js index f9e850fd8..c8fdcd989 100644 --- a/src/var/ObjectFunctionString.js +++ b/src/var/ObjectFunctionString.js @@ -1,7 +1,3 @@ -define( [ - "./fnToString" -], function( fnToString ) { - "use strict"; +import fnToString from "./fnToString.js"; - return fnToString.call( Object ); -} ); +export default fnToString.call( Object ); diff --git a/src/var/arr.js b/src/var/arr.js index 84713d838..d6d1738de 100644 --- a/src/var/arr.js +++ b/src/var/arr.js @@ -1,5 +1 @@ -define( function() { - "use strict"; - - return []; -} ); +export default []; diff --git a/src/var/class2type.js b/src/var/class2type.js index 4365d46a2..758dff6de 100644 --- a/src/var/class2type.js +++ b/src/var/class2type.js @@ -1,6 +1,2 @@ -define( function() { - "use strict"; - - // [[Class]] -> type pairs - return {}; -} ); +// [[Class]] -> type pairs +export default {}; diff --git a/src/var/document.js b/src/var/document.js index dd3939df4..db89b6875 100644 --- a/src/var/document.js +++ b/src/var/document.js @@ -1,5 +1 @@ -define( function() { - "use strict"; - - return window.document; -} ); +export default window.document; diff --git a/src/var/documentElement.js b/src/var/documentElement.js index 0e3f8b48c..4bad20e54 100644 --- a/src/var/documentElement.js +++ b/src/var/documentElement.js @@ -1,7 +1,3 @@ -define( [ - "./document" -], function( document ) { - "use strict"; +import document from "./document.js"; - return document.documentElement; -} ); +export default document.documentElement; diff --git a/src/var/flat.js b/src/var/flat.js index 6c7a27169..172420552 100644 --- a/src/var/flat.js +++ b/src/var/flat.js @@ -1,15 +1,9 @@ -define( [ - "./arr" -], function( arr ) { - -"use strict"; +import arr from "./arr.js"; // Support: IE 11+, Edge 18+ // Provide fallback for browsers without Array#flat. -return arr.flat ? function( array ) { +export default arr.flat ? function( array ) { return arr.flat.call( array ); } : function( array ) { return arr.concat.apply( [], array ); }; - -} ); diff --git a/src/var/fnToString.js b/src/var/fnToString.js index 18c43ff30..10042138e 100644 --- a/src/var/fnToString.js +++ b/src/var/fnToString.js @@ -1,7 +1,3 @@ -define( [ - "./hasOwn" -], function( hasOwn ) { - "use strict"; +import hasOwn from "./hasOwn.js"; - return hasOwn.toString; -} ); +export default hasOwn.toString; diff --git a/src/var/getProto.js b/src/var/getProto.js index 965fab8fb..392cd3973 100644 --- a/src/var/getProto.js +++ b/src/var/getProto.js @@ -1,5 +1 @@ -define( function() { - "use strict"; - - return Object.getPrototypeOf; -} ); +export default Object.getPrototypeOf; diff --git a/src/var/hasOwn.js b/src/var/hasOwn.js index 44ab6807d..62f2c1852 100644 --- a/src/var/hasOwn.js +++ b/src/var/hasOwn.js @@ -1,7 +1,3 @@ -define( [ - "./class2type" -], function( class2type ) { - "use strict"; +import class2type from "./class2type.js"; - return class2type.hasOwnProperty; -} ); +export default class2type.hasOwnProperty; diff --git a/src/var/indexOf.js b/src/var/indexOf.js index 8320b98e5..f1342c8f7 100644 --- a/src/var/indexOf.js +++ b/src/var/indexOf.js @@ -1,7 +1,3 @@ -define( [ - "./arr" -], function( arr ) { - "use strict"; +import arr from "./arr.js"; - return arr.indexOf; -} ); +export default arr.indexOf; diff --git a/src/var/isIE.js b/src/var/isIE.js index e6a37cb5a..a239745ea 100644 --- a/src/var/isIE.js +++ b/src/var/isIE.js @@ -1,7 +1,3 @@ -define( [ - "./document" -], function( document ) { - "use strict"; +import document from "./document.js"; - return document.documentMode; -} ); +export default document.documentMode; diff --git a/src/var/isWindow.js b/src/var/isWindow.js index 2ba1168dd..fa64581ee 100644 --- a/src/var/isWindow.js +++ b/src/var/isWindow.js @@ -1,8 +1,3 @@ -define( function() { - "use strict"; - - return function isWindow( obj ) { - return obj != null && obj === obj.window; - }; - -} ); +export default function isWindow( obj ) { + return obj != null && obj === obj.window; +}; diff --git a/src/var/pnum.js b/src/var/pnum.js index 6f06d73b1..5f6bca473 100644 --- a/src/var/pnum.js +++ b/src/var/pnum.js @@ -1,5 +1 @@ -define( function() { - "use strict"; - - return ( /[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/ ).source; -} ); +export default ( /[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/ ).source; diff --git a/src/var/pop.js b/src/var/pop.js index 6f1eb903c..b1c9131c5 100644 --- a/src/var/pop.js +++ b/src/var/pop.js @@ -1,7 +1,3 @@ -define( [ - "./arr" -], function( arr ) { - "use strict"; +import arr from "./arr.js"; - return arr.pop; -} ); +export default arr.pop; diff --git a/src/var/push.js b/src/var/push.js index 94656209a..2758aa587 100644 --- a/src/var/push.js +++ b/src/var/push.js @@ -1,7 +1,3 @@ -define( [ - "./arr" -], function( arr ) { - "use strict"; +import arr from "./arr.js"; - return arr.push; -} ); +export default arr.push; diff --git a/src/var/rcheckableType.js b/src/var/rcheckableType.js index 25bbcb418..9fc4b55dc 100644 --- a/src/var/rcheckableType.js +++ b/src/var/rcheckableType.js @@ -1,5 +1 @@ -define( function() { - "use strict"; - - return ( /^(?:checkbox|radio)$/i ); -} ); +export default ( /^(?:checkbox|radio)$/i ); diff --git a/src/var/rcssNum.js b/src/var/rcssNum.js index 4214b14aa..c96eb65ca 100644 --- a/src/var/rcssNum.js +++ b/src/var/rcssNum.js @@ -1,9 +1,3 @@ -define( [ - "../var/pnum" -], function( pnum ) { +import pnum from "../var/pnum.js"; -"use strict"; - -return new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" ); - -} ); +export default new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" ); diff --git a/src/var/rnothtmlwhite.js b/src/var/rnothtmlwhite.js index 29eebf287..db2a9e360 100644 --- a/src/var/rnothtmlwhite.js +++ b/src/var/rnothtmlwhite.js @@ -1,8 +1,4 @@ -define( function() { - "use strict"; - - // Only count HTML whitespace - // Other whitespace should count in values - // https://infra.spec.whatwg.org/#ascii-whitespace - return ( /[^\x20\t\r\n\f]+/g ); -} ); +// Only count HTML whitespace +// Other whitespace should count in values +// https://infra.spec.whatwg.org/#ascii-whitespace +export default ( /[^\x20\t\r\n\f]+/g ); diff --git a/src/var/slice.js b/src/var/slice.js index 915f837be..4d767ac98 100644 --- a/src/var/slice.js +++ b/src/var/slice.js @@ -1,7 +1,3 @@ -define( [ - "./arr" -], function( arr ) { - "use strict"; +import arr from "./arr.js"; - return arr.slice; -} ); +export default arr.slice; diff --git a/src/var/sort.js b/src/var/sort.js index a943fa77c..031be7706 100644 --- a/src/var/sort.js +++ b/src/var/sort.js @@ -1,7 +1,3 @@ -define( [ - "./arr" -], function( arr ) { - "use strict"; +import arr from "./arr.js"; - return arr.sort; -} ); +export default arr.sort; diff --git a/src/var/support.js b/src/var/support.js index 094d0aece..cc0a15d15 100644 --- a/src/var/support.js +++ b/src/var/support.js @@ -1,6 +1,2 @@ -define( function() { - "use strict"; - - // All support tests are defined in their respective modules. - return {}; -} ); +// All support tests are defined in their respective modules. +export default {}; diff --git a/src/var/toString.js b/src/var/toString.js index ff4ecdc72..01682d601 100644 --- a/src/var/toString.js +++ b/src/var/toString.js @@ -1,7 +1,3 @@ -define( [ - "./class2type" -], function( class2type ) { - "use strict"; +import class2type from "./class2type.js"; - return class2type.toString; -} ); +export default class2type.toString; diff --git a/src/var/trim.js b/src/var/trim.js index a5e75af36..77d925fb0 100644 --- a/src/var/trim.js +++ b/src/var/trim.js @@ -1,5 +1 @@ -define( function() { - "use strict"; - - return "".trim; -} ); +export default "".trim; diff --git a/src/wrap.js b/src/wrap.js index a42c04da7..cd7636b8d 100644 --- a/src/wrap.js +++ b/src/wrap.js @@ -1,11 +1,8 @@ -define( [ - "./core", - "./core/init", - "./manipulation", // clone - "./traversing" // parent, contents -], function( jQuery ) { +import jQuery from "./core.js"; -"use strict"; +import "./core/init.js"; +import "./manipulation.js"; // clone +import "./traversing.js"; // parent, contents jQuery.fn.extend( { wrapAll: function( html ) { @@ -73,5 +70,4 @@ jQuery.fn.extend( { } } ); -return jQuery; -} ); +export default jQuery; diff --git a/src/wrapper.js b/src/wrapper.js index dfbd9a028..22ddbf812 100644 --- a/src/wrapper.js +++ b/src/wrapper.js @@ -1,4 +1,3 @@ -/* eslint-disable no-unused-vars*/ /*! * jQuery JavaScript Library v@VERSION * https://jquery.com/ diff --git a/test/.eslintrc.json b/test/.eslintrc.json index a6d8fc872..f5a3fa591 100644 --- a/test/.eslintrc.json +++ b/test/.eslintrc.json @@ -63,6 +63,16 @@ "parserOptions": { "ecmaVersion": 2015 } + }, + + { + "files": [ + "jquery.js", + "data/testinit.js" + ], + "parserOptions": { + "ecmaVersion": 2020 + } } ] } diff --git a/test/data/testinit.js b/test/data/testinit.js index a597ccb35..7a8697189 100644 --- a/test/data/testinit.js +++ b/test/data/testinit.js @@ -300,7 +300,7 @@ QUnit.testUnlessIE = QUnit.isIE ? QUnit.skip : QUnit.test; this.loadTests = function() { // Directly load tests that need synchronous evaluation - if ( !QUnit.urlParams.amd || document.readyState === "loading" ) { + if ( !QUnit.urlParams.esmodules || document.readyState === "loading" ) { document.write( " - + @@ -29,7 +29,7 @@ // Load tests if they have not been loaded // This is in a different script tag to ensure that // jQuery is on the page when the testrunner executes - if ( !QUnit.urlParams.amd ) { + if ( !QUnit.urlParams.esmodules ) { loadTests(); } diff --git a/test/jquery.js b/test/jquery.js index 6b1aef42f..d6d53fb26 100644 --- a/test/jquery.js +++ b/test/jquery.js @@ -2,7 +2,8 @@ ( function() { /* global loadTests: false */ - var FILEPATH = "/test/jquery.js", + var dynamicImportSource, + FILEPATH = "/test/jquery.js", activeScript = [].slice.call( document.getElementsByTagName( "script" ), -1 )[ 0 ], parentUrl = activeScript && activeScript.src ? activeScript.src.replace( /[?#].*/, "" ) + FILEPATH.replace( /[^/]+/g, ".." ) + "/" : @@ -21,12 +22,13 @@ // Define configuration parameters controlling how jQuery is loaded if ( QUnit ) { - // AMD loading is asynchronous and incompatible with synchronous test loading in Karma + // ES modules loading is asynchronous and incompatible with synchronous + // test loading in Karma. if ( !window.__karma__ ) { QUnit.config.urlConfig.push( { - id: "amd", - label: "Load with AMD", - tooltip: "Load the AMD jQuery file (and its dependencies)" + id: "esmodules", + label: "Load as modules", + tooltip: "Load a relevant jQuery module file (and its dependencies)" } ); } @@ -39,18 +41,21 @@ // Honor AMD loading on the main window (detected by seeing QUnit on it). // This doesn't apply to iframes because they synchronously expect jQuery to be there. - if ( urlParams.amd && window.QUnit ) { - require.config( { - baseUrl: parentUrl - } ); - src = "src/jquery"; + if ( urlParams.esmodules && window.QUnit ) { - // Include tests if specified - if ( typeof loadTests !== "undefined" ) { - require( [ src ], loadTests ); - } else { - require( [ src ] ); - } + // Support: IE 11+, Edge 12 - 18+ + // IE/Edge don't support the dynamic import syntax so they'd crash + // with a SyntaxError here. + dynamicImportSource = "" + + "import( `${ parentUrl }src/jquery.js` ).then( ( { default: jQuery } ) => {\n" + + " window.jQuery = jQuery;\n" + + " if ( typeof loadTests === \"function\" ) {\n" + + " // Include tests if specified\n" + + " loadTests();\n" + + " }\n" + + "} );"; + + eval( dynamicImportSource ); // Otherwise, load synchronously } else {