From: Timmy Willison <4timmywil@gmail.com> Date: Mon, 15 Aug 2016 15:41:11 +0000 (-0400) Subject: Core: expose noConflict in AMD mode X-Git-Tag: 3.1.1~10 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=52e24471c89b80e6208b4987bb76994e64c1e489;p=jquery.git 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 --- diff --git a/build/tasks/build.js b/build/tasks/build.js index 7f0da1d6b..1579691a0 100644 --- a/build/tasks/build.js +++ b/build/tasks/build.js @@ -17,7 +17,6 @@ module.exports = function( grunt ) { read = function( fileName ) { return grunt.file.read( srcFolder + fileName ); }, - globals = read( "exports/global.js" ), wrapper = read( "wrapper.js" ).split( /\/\/ \@CODE\n\/\/[^\n]+/ ), config = { baseUrl: "src", @@ -39,10 +38,7 @@ module.exports = function( grunt ) { skipSemiColonInsertion: true, wrap: { start: wrapper[ 0 ].replace( /\/\*\s*eslint(?: |-).*\s*\*\/\n/, "" ), - end: globals.replace( - /\/\*\s*ExcludeStart\s*\*\/[\w\W]*?\/\*\s*ExcludeEnd\s*\*\//ig, - "" - ) + wrapper[ 1 ] + end: wrapper[ 1 ] }, rawText: {}, onBuildWrite: convert diff --git a/src/exports/global.js b/src/exports/global.js index ebdb73b30..460b56e47 100644 --- a/src/exports/global.js +++ b/src/exports/global.js @@ -1,10 +1,8 @@ -/* ExcludeStart */ +define( [ + "../core" +], function( jQuery, noGlobal ) { -// This file is included in a different way from all the others -// so the "use strict" pragma is not needed. -/* eslint strict: "off" */ - -/* ExcludeEnd */ +"use strict"; var @@ -32,3 +30,5 @@ jQuery.noConflict = function( deep ) { if ( !noGlobal ) { window.jQuery = window.$ = jQuery; } + +} ); diff --git a/src/jquery.js b/src/jquery.js index 744a98e5d..52fc87dbd 100644 --- a/src/jquery.js +++ b/src/jquery.js @@ -30,11 +30,12 @@ define( [ "./offset", "./dimensions", "./deprecated", - "./exports/amd" + "./exports/amd", + "./exports/global" ], function( jQuery ) { "use strict"; -return ( window.jQuery = window.$ = jQuery ); +return jQuery; } ); diff --git a/test/data/testinit.js b/test/data/testinit.js index 9e2679654..ef210e739 100644 --- a/test/data/testinit.js +++ b/test/data/testinit.js @@ -320,9 +320,7 @@ this.loadTests = function() { /** * Run in noConflict mode */ - if ( jQuery.noConflict ) { - jQuery.noConflict(); - } + jQuery.noConflict(); // Load the TestSwarm listener if swarmURL is in the address. if ( QUnit.isSwarm ) { diff --git a/test/unit/core.js b/test/unit/core.js index b00db8c33..f5083b4a9 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -197,27 +197,24 @@ QUnit.test( "globalEval execution after script injection (#7862)", function( ass assert.ok( window.strictEvalTest - now < 500, "Code executed synchronously" ); } ); -// This is not run in AMD mode -if ( jQuery.noConflict ) { - QUnit.test( "noConflict", function( assert ) { - assert.expect( 7 ); +QUnit.test( "noConflict", function( assert ) { + assert.expect( 7 ); - var $$ = jQuery; + var $$ = jQuery; - assert.strictEqual( jQuery, jQuery.noConflict(), "noConflict returned the jQuery object" ); - assert.strictEqual( window[ "jQuery" ], $$, "Make sure jQuery wasn't touched." ); - assert.strictEqual( window[ "$" ], original$, "Make sure $ was reverted." ); + assert.strictEqual( jQuery, jQuery.noConflict(), "noConflict returned the jQuery object" ); + assert.strictEqual( window[ "jQuery" ], $$, "Make sure jQuery wasn't touched." ); + assert.strictEqual( window[ "$" ], original$, "Make sure $ was reverted." ); - jQuery = $ = $$; + jQuery = $ = $$; - assert.strictEqual( jQuery.noConflict( true ), $$, "noConflict returned the jQuery object" ); - assert.strictEqual( window[ "jQuery" ], originaljQuery, "Make sure jQuery was reverted." ); - assert.strictEqual( window[ "$" ], original$, "Make sure $ was reverted." ); - assert.ok( $$().pushStack( [] ), "Make sure that jQuery still works." ); + assert.strictEqual( jQuery.noConflict( true ), $$, "noConflict returned the jQuery object" ); + assert.strictEqual( window[ "jQuery" ], originaljQuery, "Make sure jQuery was reverted." ); + assert.strictEqual( window[ "$" ], original$, "Make sure $ was reverted." ); + assert.ok( $$().pushStack( [] ), "Make sure that jQuery still works." ); - window[ "jQuery" ] = jQuery = $$; - } ); -} + window[ "jQuery" ] = jQuery = $$; +} ); QUnit.test( "trim", function( assert ) { assert.expect( 13 );