nl_tokens: Make functions that will define virtual modules
pl_tokens: function makeDefineVirtualModule ( loader , load , addDep , args ) { function namer ( loadName ) { var baseName = loadName . substr ( 0 , loadName . indexOf ( "!" ) ) ; return function ( part , plugin ) { return baseName + "-" + part + ( plugin ? ( "." + plugin ) : "" ) ; } ; } function addresser ( loadAddress ) { return function ( part , plugin ) { var base = loadAddress + "." + part ; return base + ( plugin ? ( "." + plugin ) : "" ) ; } ; } var name = namer ( load . <mask> ) ; var address = addresser ( load . address ) ; // A function for disposing of modules during live-reload var disposeModule = function ( moduleName ) { if ( loader . has ( moduleName ) ) loader [ "delete" ] ( moduleName ) ; } ; if ( loader . liveReloadInstalled || loader . has ( "live-reload" ) ) { loader . import ( "live-reload" , { name : module . id } ) . then ( function ( reload ) { disposeModule = reload . disposeModule || disposeModule ; } ) ; } return function ( defn ) { if ( defn . condition ) { if ( defn . arg ) { // viewModel args . push ( defn . arg ) ; } var moduleName = typeof defn . name === "function" ? defn . name ( name ) : name ( defn . name ) ; var moduleAddress = typeof defn . address === "function" ? defn . address ( address ) : address ( defn . address ) ; // from="something.js" if ( defn . from ) { addDep ( defn . from , false ) ; } else if ( defn . getLoad ) { var moduleSource = defn . source ( ) ; return defn . getLoad ( moduleName ) . then ( function ( newLoad ) { moduleName = newLoad . name || moduleName ; // For live-reload disposeModule ( moduleName ) ; loader . define ( moduleName , moduleSource , { metadata : newLoad . metadata , address : moduleAddress } ) ; addDep ( moduleName ) ; } ) ; } else if ( defn . source ) { addDep ( moduleName ) ; if ( loader . has ( moduleName ) ) loader [ "delete" ] ( moduleName ) ; if ( typeof defn . source !== "string" ) { return Promise . resolve ( defn . source ) . then ( function ( source ) { loader . define ( moduleName , source , { address : address ( defn . name ) , metadata : defn . metadata } ) ; } ) ; } return loader . define ( moduleName , defn . source , { address : address ( defn . name ) } ) ; } } } }