Skip to content

Commit 52e2447

Browse files
committed
Core: expose noConflict in AMD mode
- For compability reasons, we had already added the global in AMD mode, but without noConflict. This adds back noConflict to AMD (which fixes noConflict mode in the tests). Fixes gh-2930
1 parent 560c0c6 commit 52e2447

File tree

5 files changed

+24
-32
lines changed

5 files changed

+24
-32
lines changed

build/tasks/build.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ module.exports = function( grunt ) {
1717
read = function( fileName ) {
1818
return grunt.file.read( srcFolder + fileName );
1919
},
20-
globals = read( "exports/global.js" ),
2120
wrapper = read( "wrapper.js" ).split( /\/\/ \@CODE\n\/\/[^\n]+/ ),
2221
config = {
2322
baseUrl: "src",
@@ -39,10 +38,7 @@ module.exports = function( grunt ) {
3938
skipSemiColonInsertion: true,
4039
wrap: {
4140
start: wrapper[ 0 ].replace( /\/\*\s*eslint(?: |-).*\s*\*\/\n/, "" ),
42-
end: globals.replace(
43-
/\/\*\s*ExcludeStart\s*\*\/[\w\W]*?\/\*\s*ExcludeEnd\s*\*\//ig,
44-
""
45-
) + wrapper[ 1 ]
41+
end: wrapper[ 1 ]
4642
},
4743
rawText: {},
4844
onBuildWrite: convert

src/exports/global.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
/* ExcludeStart */
1+
define( [
2+
"../core"
3+
], function( jQuery, noGlobal ) {
24

3-
// This file is included in a different way from all the others
4-
// so the "use strict" pragma is not needed.
5-
/* eslint strict: "off" */
6-
7-
/* ExcludeEnd */
5+
"use strict";
86

97
var
108

@@ -32,3 +30,5 @@ jQuery.noConflict = function( deep ) {
3230
if ( !noGlobal ) {
3331
window.jQuery = window.$ = jQuery;
3432
}
33+
34+
} );

src/jquery.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ define( [
3030
"./offset",
3131
"./dimensions",
3232
"./deprecated",
33-
"./exports/amd"
33+
"./exports/amd",
34+
"./exports/global"
3435
], function( jQuery ) {
3536

3637
"use strict";
3738

38-
return ( window.jQuery = window.$ = jQuery );
39+
return jQuery;
3940

4041
} );

test/data/testinit.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,7 @@ this.loadTests = function() {
320320
/**
321321
* Run in noConflict mode
322322
*/
323-
if ( jQuery.noConflict ) {
324-
jQuery.noConflict();
325-
}
323+
jQuery.noConflict();
326324

327325
// Load the TestSwarm listener if swarmURL is in the address.
328326
if ( QUnit.isSwarm ) {

test/unit/core.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -197,27 +197,24 @@ QUnit.test( "globalEval execution after script injection (#7862)", function( ass
197197
assert.ok( window.strictEvalTest - now < 500, "Code executed synchronously" );
198198
} );
199199

200-
// This is not run in AMD mode
201-
if ( jQuery.noConflict ) {
202-
QUnit.test( "noConflict", function( assert ) {
203-
assert.expect( 7 );
200+
QUnit.test( "noConflict", function( assert ) {
201+
assert.expect( 7 );
204202

205-
var $$ = jQuery;
203+
var $$ = jQuery;
206204

207-
assert.strictEqual( jQuery, jQuery.noConflict(), "noConflict returned the jQuery object" );
208-
assert.strictEqual( window[ "jQuery" ], $$, "Make sure jQuery wasn't touched." );
209-
assert.strictEqual( window[ "$" ], original$, "Make sure $ was reverted." );
205+
assert.strictEqual( jQuery, jQuery.noConflict(), "noConflict returned the jQuery object" );
206+
assert.strictEqual( window[ "jQuery" ], $$, "Make sure jQuery wasn't touched." );
207+
assert.strictEqual( window[ "$" ], original$, "Make sure $ was reverted." );
210208

211-
jQuery = $ = $$;
209+
jQuery = $ = $$;
212210

213-
assert.strictEqual( jQuery.noConflict( true ), $$, "noConflict returned the jQuery object" );
214-
assert.strictEqual( window[ "jQuery" ], originaljQuery, "Make sure jQuery was reverted." );
215-
assert.strictEqual( window[ "$" ], original$, "Make sure $ was reverted." );
216-
assert.ok( $$().pushStack( [] ), "Make sure that jQuery still works." );
211+
assert.strictEqual( jQuery.noConflict( true ), $$, "noConflict returned the jQuery object" );
212+
assert.strictEqual( window[ "jQuery" ], originaljQuery, "Make sure jQuery was reverted." );
213+
assert.strictEqual( window[ "$" ], original$, "Make sure $ was reverted." );
214+
assert.ok( $$().pushStack( [] ), "Make sure that jQuery still works." );
217215

218-
window[ "jQuery" ] = jQuery = $$;
219-
} );
220-
}
216+
window[ "jQuery" ] = jQuery = $$;
217+
} );
221218

222219
QUnit.test( "trim", function( assert ) {
223220
assert.expect( 13 );

0 commit comments

Comments
 (0)