aboutsummaryrefslogtreecommitdiffstats
path: root/build/tasks
diff options
context:
space:
mode:
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>2022-12-14 01:41:31 +0100
committerGitHub <noreply@github.com>2022-12-14 01:41:31 +0100
commit6306ca499433c45b58a02f1cf3a76cbafbc4a391 (patch)
treecf1c66f075ca92501a746646975f1fef046e27ec /build/tasks
parent96675fa7c82b350eea6a77a0cec1f9ad65c9f629 (diff)
downloadjquery-6306ca499433c45b58a02f1cf3a76cbafbc4a391.tar.gz
jquery-6306ca499433c45b58a02f1cf3a76cbafbc4a391.zip
Selector: Inline Sizzle into the selector module: 3.x version (#5113)
This commit removes Sizzle from jQuery, inlining its code & removing obsolete workarounds where applicable. The Sizzle AUTHORS.txt file has been merged with the jQuery one - people are sorted by their first contributions to either of the two repositories. The main `selector` module can be disabled in favor of `selector-native` via: grunt custom:-selector For backwards compatibility, the legacy `sizzle` alias is also supported (it will be dropped in jQuery `4.0.0`): grunt custom:-selector Sizzle tests have been ported to jQuery ones. Ones that are not compatible with the `selector-native` module are disabled if the regular selector module is excluded. Backwards compatibility is still kept for all `Sizzle` utils - they continue to be available under `jQuery.find` - but the primary implementation is now attached directly to jQuery. Some selector utils shared by `selector` & `selector-native` have been extracted & deduplicated. `jQuery.text` and `jQuery.isXMLDoc` have been moved to the `core` module. The commit reduces the gzipped jQuery size by 851 bytes compared to the `3.x-stable` branch. Closes gh-5113 Ref gh-4395 Ref gh-4406
Diffstat (limited to 'build/tasks')
-rw-r--r--build/tasks/build.js55
1 files changed, 29 insertions, 26 deletions
diff --git a/build/tasks/build.js b/build/tasks/build.js
index 71c20a81a..01b19e4d4 100644
--- a/build/tasks/build.js
+++ b/build/tasks/build.js
@@ -72,13 +72,6 @@ module.exports = function( grunt ) {
)
.replace( rdefineEnd, "" );
- // Sizzle treatment
- } else if ( /\/sizzle$/.test( name ) ) {
- contents = "var Sizzle =\n" + contents
-
- // Remove EXPOSE lines from Sizzle
- .replace( /\/\/\s*EXPOSE[\w\W]*\/\/\s*EXPOSE/, "return Sizzle;" );
-
} else {
contents = contents
@@ -101,7 +94,7 @@ module.exports = function( grunt ) {
// Remove empty definitions
contents = contents
- .replace( /define\(\[[^\]]*\]\)[\W\n]+$/, "" );
+ .replace( /define\(\s*\[[^\]]*\]\s*\)[\W\n]+$/, "" );
}
// AMD Name
@@ -178,14 +171,19 @@ module.exports = function( grunt ) {
* Adds the specified module to the excluded or included list, depending on the flag
* @param {String} flag A module path relative to
* the src directory starting with + or - to indicate
- * whether it should included or excluded
+ * whether it should be included or excluded
*/
excluder = function( flag ) {
var additional,
- m = /^(\+|\-|)([\w\/-]+)$/.exec( flag ),
+ m = /^(\+|-|)([\w\/-]+)$/.exec( flag ),
exclude = m[ 1 ] === "-",
module = m[ 2 ];
+ // Recognize the legacy `sizzle` alias
+ if ( module === "sizzle" ) {
+ module = "selector";
+ }
+
if ( exclude ) {
// Can't exclude certain modules
@@ -200,7 +198,16 @@ 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 );
+
+ // `selector` is a special case as we don't just remove
+ // the module, but we replace it with `selector-native`
+ // which re-uses parts of the `src/selector` folder.
+ if ( module !== "selector" ) {
+ excludeList(
+ fs.readdirSync( `${ srcFolder }/${ module }` ),
+ module
+ );
+ }
} catch ( e ) {
grunt.verbose.writeln( e );
}
@@ -218,11 +225,6 @@ module.exports = function( grunt ) {
}
} else {
grunt.log.error( "Module \"" + module + "\" is a minimum requirement." );
- if ( module === "selector" ) {
- grunt.log.error(
- "If you meant to replace Sizzle, use -sizzle instead."
- );
- }
}
} else {
grunt.log.writeln( flag );
@@ -259,17 +261,16 @@ module.exports = function( grunt ) {
excluder( flag );
}
- // Handle Sizzle exclusion
- // Replace with selector-native
- if ( ( index = excluded.indexOf( "sizzle" ) ) > -1 ) {
- config.rawText.selector = "define(['./selector-native']);";
- excluded.splice( index, 1 );
+ // Handle full selector module exclusion.
+ // Replace with selector-native.
+ if ( excluded.indexOf( "selector" ) > -1 ) {
+ config.rawText.selector = "define([ \"./selector-native\" ]);";
}
// 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});";
+ config.rawText[ "exports/global" ] = "define( [\n\t\"../core\"\n], " +
+ "function( jQuery ) {\n\tjQuery.noConflict = function() {};\n} );";
excluded.splice( index, 1 );
}
@@ -311,9 +312,11 @@ module.exports = function( grunt ) {
if ( !optIn ) {
// Overwrite the default inclusions with the explicit ones provided
- config.rawText.jquery = "define([" +
- ( included.length ? included.join( "," ) : "" ) +
- "]);";
+ config.rawText.jquery = "define( [\n" +
+ ( included.length ?
+ included.map( module => "\t\"./" + module + "\"" ).join( ",\n" ) :
+ "" ) +
+ "\n] );";
}
// Trace dependencies and concatenate files