Skip to content

Commit

Permalink
Core: Use named exports in src/
Browse files Browse the repository at this point in the history
The `default` export is treated differently across tooling when transpiled
to CommonJS - tools differ on whether `module.exports` represents the full
module object or just its default export. Switch `src/` modules to named
exports for tooling consistency.

Fixes gh-5262
Closes gh-5292
  • Loading branch information
mgol committed Sep 12, 2023
1 parent 42e50f8 commit f75daab
Show file tree
Hide file tree
Showing 136 changed files with 424 additions and 478 deletions.
2 changes: 1 addition & 1 deletion build/tasks/build.js
Expand Up @@ -221,7 +221,7 @@ module.exports = function( grunt ) {
// Remove the jQuery export from the entry file, we'll use our own
// custom wrapper.
setOverride( inputRollupOptions.input,
read( inputFileName ).replace( /\n*export default jQuery;\n*/, "\n" ) );
read( inputFileName ).replace( /\n*export \{ jQuery, jQuery as \$ };\n*/, "\n" ) );

// Replace exports/global with a noop noConflict
if ( excluded.includes( "exports/global" ) ) {
Expand Down
14 changes: 7 additions & 7 deletions src/ajax.js
@@ -1,9 +1,9 @@
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";
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";

import "./core/init.js";
import "./core/parseXML.js";
Expand Down Expand Up @@ -874,4 +874,4 @@ jQuery.ajaxPrefilter( function( s ) {
}
} );

export default jQuery;
export { jQuery, jQuery as $ };
2 changes: 1 addition & 1 deletion src/ajax/binary.js
@@ -1,4 +1,4 @@
import jQuery from "../core.js";
import { jQuery } from "../core.js";

import "../ajax.js";

Expand Down
6 changes: 3 additions & 3 deletions src/ajax/jsonp.js
@@ -1,6 +1,6 @@
import jQuery from "../core.js";
import nonce from "./var/nonce.js";
import rquery from "./var/rquery.js";
import { jQuery } from "../core.js";
import { nonce } from "./var/nonce.js";
import { rquery } from "./var/rquery.js";

import "../ajax.js";

Expand Down
4 changes: 2 additions & 2 deletions src/ajax/load.js
@@ -1,5 +1,5 @@
import jQuery from "../core.js";
import stripAndCollapse from "../core/stripAndCollapse.js";
import { jQuery } from "../core.js";
import { stripAndCollapse } from "../core/stripAndCollapse.js";

import "../core/parseHTML.js";
import "../ajax.js";
Expand Down
4 changes: 2 additions & 2 deletions src/ajax/script.js
@@ -1,5 +1,5 @@
import jQuery from "../core.js";
import document from "../var/document.js";
import { jQuery } from "../core.js";
import { document } from "../var/document.js";

import "../ajax.js";

Expand Down
2 changes: 1 addition & 1 deletion src/ajax/var/location.js
@@ -1 +1 @@
export default window.location;
export var location = window.location;
2 changes: 1 addition & 1 deletion src/ajax/var/nonce.js
@@ -1 +1 @@
export default { guid: Date.now() };
export var nonce = { guid: Date.now() };
2 changes: 1 addition & 1 deletion src/ajax/var/rquery.js
@@ -1 +1 @@
export default ( /\?/ );
export var rquery = /\?/;
2 changes: 1 addition & 1 deletion src/ajax/xhr.js
@@ -1,4 +1,4 @@
import jQuery from "../core.js";
import { jQuery } from "../core.js";

import "../ajax.js";

Expand Down
4 changes: 2 additions & 2 deletions src/attributes.js
@@ -1,9 +1,9 @@
import jQuery from "./core.js";
import { jQuery } from "./core.js";

import "./attributes/attr.js";
import "./attributes/prop.js";
import "./attributes/classes.js";
import "./attributes/val.js";

// Return jQuery for attributes-only inclusion
export default jQuery;
export { jQuery, jQuery as $ };
10 changes: 5 additions & 5 deletions src/attributes/attr.js
@@ -1,8 +1,8 @@
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";
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";

import "../selector.js";

Expand Down
6 changes: 3 additions & 3 deletions src/attributes/classes.js
@@ -1,6 +1,6 @@
import jQuery from "../core.js";
import stripAndCollapse from "../core/stripAndCollapse.js";
import rnothtmlwhite from "../var/rnothtmlwhite.js";
import { jQuery } from "../core.js";
import { stripAndCollapse } from "../core/stripAndCollapse.js";
import { rnothtmlwhite } from "../var/rnothtmlwhite.js";

import "../core/init.js";

Expand Down
6 changes: 3 additions & 3 deletions src/attributes/prop.js
@@ -1,6 +1,6 @@
import jQuery from "../core.js";
import access from "../core/access.js";
import isIE from "../var/isIE.js";
import { jQuery } from "../core.js";
import { access } from "../core/access.js";
import { isIE } from "../var/isIE.js";

import "../selector.js";

Expand Down
8 changes: 4 additions & 4 deletions src/attributes/val.js
@@ -1,7 +1,7 @@
import jQuery from "../core.js";
import isIE from "../var/isIE.js";
import stripAndCollapse from "../core/stripAndCollapse.js";
import nodeName from "../core/nodeName.js";
import { jQuery } from "../core.js";
import { isIE } from "../var/isIE.js";
import { stripAndCollapse } from "../core/stripAndCollapse.js";
import { nodeName } from "../core/nodeName.js";

import "../core/init.js";

Expand Down
8 changes: 4 additions & 4 deletions src/callbacks.js
@@ -1,6 +1,6 @@
import jQuery from "./core.js";
import toType from "./core/toType.js";
import rnothtmlwhite from "./var/rnothtmlwhite.js";
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 ) {
Expand Down Expand Up @@ -227,4 +227,4 @@ jQuery.Callbacks = function( options ) {
return self;
};

export default jQuery;
export { jQuery, jQuery as $ };
30 changes: 15 additions & 15 deletions src/core.js
@@ -1,17 +1,17 @@
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 isArrayLike from "./core/isArrayLike.js";
import DOMEval from "./core/DOMEval.js";
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 { isArrayLike } from "./core/isArrayLike.js";
import { DOMEval } from "./core/DOMEval.js";

var version = "@VERSION",

Expand Down Expand Up @@ -416,4 +416,4 @@ jQuery.each( "Boolean Number String Function Array Date RegExp Object Error Symb
class2type[ "[object " + name + "]" ] = name.toLowerCase();
} );

export default jQuery;
export { jQuery, jQuery as $ };
6 changes: 2 additions & 4 deletions src/core/DOMEval.js
@@ -1,4 +1,4 @@
import document from "../var/document.js";
import { document } from "../var/document.js";

var preservedScriptAttributes = {
type: true,
Expand All @@ -7,7 +7,7 @@ var preservedScriptAttributes = {
noModule: true
};

function DOMEval( code, node, doc ) {
export function DOMEval( code, node, doc ) {
doc = doc || document;

var i,
Expand All @@ -23,5 +23,3 @@ function DOMEval( code, node, doc ) {
}
doc.head.appendChild( script ).parentNode.removeChild( script );
}

export default DOMEval;
10 changes: 4 additions & 6 deletions src/core/access.js
@@ -1,9 +1,9 @@
import jQuery from "../core.js";
import toType from "../core/toType.js";
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
var access = function( elems, fn, key, value, chainable, emptyGet, raw ) {
export function access( elems, fn, key, value, chainable, emptyGet, raw ) {
var i = 0,
len = elems.length,
bulk = key == null;
Expand Down Expand Up @@ -60,6 +60,4 @@ var access = function( elems, fn, key, value, chainable, emptyGet, raw ) {
}

return len ? fn( elems[ 0 ], key ) : emptyGet;
};

export default access;
}
4 changes: 1 addition & 3 deletions src/core/camelCase.js
Expand Up @@ -7,8 +7,6 @@ function fcamelCase( _all, letter ) {
}

// Convert dashed to camelCase
function camelCase( string ) {
export function camelCase( string ) {
return string.replace( rdashAlpha, fcamelCase );
}

export default camelCase;
8 changes: 4 additions & 4 deletions src/core/init.js
@@ -1,8 +1,8 @@
// Initialize a jQuery object
import jQuery from "../core.js";
import document from "../var/document.js";
import rsingleTag from "./var/rsingleTag.js";
import isObviousHtml from "./isObviousHtml.js";
import { jQuery } from "../core.js";
import { document } from "../var/document.js";
import { rsingleTag } from "./var/rsingleTag.js";
import { isObviousHtml } from "./isObviousHtml.js";

import "../traversing/findFilter.js";

Expand Down
8 changes: 3 additions & 5 deletions src/core/isArrayLike.js
@@ -1,7 +1,7 @@
import toType from "./toType.js";
import isWindow from "../var/isWindow.js";
import { toType } from "./toType.js";
import { isWindow } from "../var/isWindow.js";

function isArrayLike( obj ) {
export function isArrayLike( obj ) {

var length = !!obj && obj.length,
type = toType( obj );
Expand All @@ -13,5 +13,3 @@ function isArrayLike( obj ) {
return type === "array" || length === 0 ||
typeof length === "number" && length > 0 && ( length - 1 ) in obj;
}

export default isArrayLike;
6 changes: 3 additions & 3 deletions src/core/isAttached.js
@@ -1,5 +1,5 @@
import jQuery from "../core.js";
import documentElement from "../var/documentElement.js";
import { jQuery } from "../core.js";
import { documentElement } from "../var/documentElement.js";

var isAttached = function( elem ) {
return jQuery.contains( elem.ownerDocument, elem ) ||
Expand All @@ -16,4 +16,4 @@ if ( !documentElement.getRootNode ) {
};
}

export default isAttached;
export { isAttached };
4 changes: 1 addition & 3 deletions src/core/isObviousHtml.js
@@ -1,7 +1,5 @@
function isObviousHtml( input ) {
export function isObviousHtml( input ) {
return input[ 0 ] === "<" &&
input[ input.length - 1 ] === ">" &&
input.length >= 3;
}

export default isObviousHtml;
6 changes: 1 addition & 5 deletions src/core/nodeName.js
@@ -1,7 +1,3 @@
function nodeName( elem, name ) {

export function nodeName( elem, name ) {
return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();

}

export default nodeName;
10 changes: 5 additions & 5 deletions src/core/parseHTML.js
@@ -1,8 +1,8 @@
import jQuery from "../core.js";
import document from "../var/document.js";
import rsingleTag from "./var/rsingleTag.js";
import buildFragment from "../manipulation/buildFragment.js";
import isObviousHtml from "./isObviousHtml.js";
import { jQuery } from "../core.js";
import { document } from "../var/document.js";
import { rsingleTag } from "./var/rsingleTag.js";
import { buildFragment } from "../manipulation/buildFragment.js";
import { isObviousHtml } from "./isObviousHtml.js";

// Argument "data" should be string of html or a TrustedHTML wrapper of obvious HTML
// context (optional): If specified, the fragment will be created in this context,
Expand Down
2 changes: 1 addition & 1 deletion src/core/parseXML.js
@@ -1,4 +1,4 @@
import jQuery from "../core.js";
import { jQuery } from "../core.js";

// Cross-browser xml parsing
jQuery.parseXML = function( data ) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/ready-no-deferred.js
@@ -1,5 +1,5 @@
import jQuery from "../core.js";
import document from "../var/document.js";
import { jQuery } from "../core.js";
import { document } from "../var/document.js";

var readyCallbacks = [],
whenReady = function( fn ) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/ready.js
@@ -1,5 +1,5 @@
import jQuery from "../core.js";
import document from "../var/document.js";
import { jQuery } from "../core.js";
import { document } from "../var/document.js";

import "../core/readyException.js";
import "../deferred.js";
Expand Down
2 changes: 1 addition & 1 deletion src/core/readyException.js
@@ -1,4 +1,4 @@
import jQuery from "../core.js";
import { jQuery } from "../core.js";

jQuery.readyException = function( error ) {
window.setTimeout( function() {
Expand Down
6 changes: 2 additions & 4 deletions src/core/stripAndCollapse.js
@@ -1,10 +1,8 @@
import rnothtmlwhite from "../var/rnothtmlwhite.js";
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 ) {
export function stripAndCollapse( value ) {
var tokens = value.match( rnothtmlwhite ) || [];
return tokens.join( " " );
}

export default stripAndCollapse;
8 changes: 3 additions & 5 deletions src/core/toType.js
@@ -1,7 +1,7 @@
import class2type from "../var/class2type.js";
import toString from "../var/toString.js";
import { class2type } from "../var/class2type.js";
import { toString } from "../var/toString.js";

function toType( obj ) {
export function toType( obj ) {
if ( obj == null ) {
return obj + "";
}
Expand All @@ -10,5 +10,3 @@ function toType( obj ) {
class2type[ toString.call( obj ) ] || "object" :
typeof obj;
}

export default toType;
2 changes: 1 addition & 1 deletion src/core/var/rsingleTag.js
@@ -1,3 +1,3 @@
// 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 );
export var rsingleTag = /^<([a-z][^\/\0>:\x20\t\r\n\f]*)[\x20\t\r\n\f]*\/?>(?:<\/\1>|)$/i;

0 comments on commit f75daab

Please sign in to comment.