Don't try to remove a script element that has already removed itself.
Also, compress `DOMEval.js`.
Fixes gh-5377
Closes gh-5378
script = doc.createElement( "script" );
script.text = code;
- if ( node ) {
- for ( i in preservedScriptAttributes ) {
- if ( node[ i ] ) {
- script[ i ] = node[ i ];
- }
+ for ( i in preservedScriptAttributes ) {
+ if ( node && node[ i ] ) {
+ script[ i ] = node[ i ];
}
}
- doc.head.appendChild( script ).parentNode.removeChild( script );
+
+ if ( doc.head.appendChild( script ).parentNode ) {
+ script.parentNode.removeChild( script );
+ }
}
}, 1000 );
} );
+QUnit.test( "html(self-removing script) (gh-5377)", function( assert ) {
+ assert.expect( 2 );
+
+ var $fixture = jQuery( "#qunit-fixture" );
+
+ $fixture.html(
+ [
+ "<script>document.currentScript.parentNode.removeChild( document.currentScript ); QUnit.assert.ok( true, 'removed document.currentScript' );</script>",
+ "<div>",
+ "<script>document.currentScript.parentNode.removeChild( document.currentScript ); QUnit.assert.ok( true, 'removed inner document.currentScript' );</script>",
+ "</div>"
+ ].join( "" )
+ );
+} );
+
QUnit.test( "html(Function) with incoming value -- direct selection", function( assert ) {
assert.expect( 4 );