], function( document ) {
"use strict";
- function DOMEval( code, doc ) {
+ var preservedScriptAttributes = {
+ type: true,
+ src: true,
+ noModule: true
+ };
+
+ function DOMEval( code, doc, node ) {
doc = doc || document;
- var script = doc.createElement( "script" );
+ var i,
+ script = doc.createElement( "script" );
script.text = code;
+ if ( node ) {
+ for ( i in preservedScriptAttributes ) {
+ if ( node[ i ] ) {
+ script[ i ] = node[ i ];
+ }
+ }
+ }
doc.head.appendChild( script ).parentNode.removeChild( script );
}
!dataPriv.access( node, "globalEval" ) &&
jQuery.contains( doc, node ) ) {
- if ( node.src ) {
+ if ( node.src && ( node.type || "" ).toLowerCase() !== "module" ) {
// Optional AJAX dependency, but won't run scripts if not present
if ( jQuery._evalUrl ) {
jQuery._evalUrl( node.src );
}
} else {
- DOMEval( node.textContent.replace( rcleanScript, "" ), doc );
+ DOMEval( node.textContent.replace( rcleanScript, "" ), doc, node );
}
}
}
define( function() {
"use strict";
- return ( /^$|\/(?:java|ecma)script/i );
+ return ( /^$|^module$|\/(?:java|ecma)script/i );
} );
--- /dev/null
+window.ok( true, "evaluated: innert module with src" );
--- /dev/null
+window.ok( true, "evaluated: module with src" );
testHtml( manipulationFunctionReturningObj, assert );
} );
+QUnit.test( "html(script type module)", function( assert ) {
+ assert.expect( 1 );
+ var fixture = jQuery( "#qunit-fixture" ),
+ tmp = fixture.html(
+ [
+ "<script type='module'>ok( true, 'evaluated: module' );</script>",
+ "<script type='module' src='./data/module.js'></script>",
+ "<div>",
+ "<script type='module'>ok( true, 'evaluated: inner module' );</script>",
+ "<script type='module' src='./data/inner_module.js'></script>",
+ "</div>"
+ ].join( "" )
+ ).find( "script" );
+ assert.equal( tmp.length, 4, "All script tags remain." );
+} );
+
QUnit.test( "html(Function) with incoming value -- direct selection", function( assert ) {
assert.expect( 4 );