[483] | 1 | define(["dojo/regexp"], function(dojoRegExp) { |
---|
| 2 | return { |
---|
| 3 | start:function( |
---|
| 4 | id, |
---|
| 5 | referenceModule, |
---|
| 6 | bc |
---|
| 7 | ) { |
---|
| 8 | var |
---|
| 9 | getHasPluginDependency = function(){ |
---|
| 10 | var hasPlugin = bc.amdResources["dojo/has"]; |
---|
| 11 | if(!hasPlugin){ |
---|
| 12 | bc.log("dojoHasMissingPlugin"); |
---|
| 13 | return []; |
---|
| 14 | }else{ |
---|
| 15 | return [hasPlugin]; |
---|
| 16 | } |
---|
| 17 | }, |
---|
| 18 | |
---|
| 19 | has = function(featureId) { |
---|
| 20 | var value = bc.staticHasFeatures[featureId]; |
---|
| 21 | return (value===undefined || value==-1) ? undefined : value; |
---|
| 22 | }, |
---|
| 23 | |
---|
| 24 | tokens = id.match(/[\?:]|[^:\?]*/g), |
---|
| 25 | |
---|
| 26 | i = 0, |
---|
| 27 | |
---|
| 28 | get = function(skip){ |
---|
| 29 | var operator, term = tokens[i++]; |
---|
| 30 | if(term == ":"){ |
---|
| 31 | // empty string module name; therefore, no dependency |
---|
| 32 | return ""; |
---|
| 33 | }else{ |
---|
| 34 | // postfixed with a ? means it is a feature to branch on, the term is the name of the feature |
---|
| 35 | if(tokens[i++] == "?"){ |
---|
| 36 | var hasResult = has(term); |
---|
| 37 | if(hasResult===undefined){ |
---|
| 38 | return undefined; |
---|
| 39 | }else if(!skip && hasResult){ |
---|
| 40 | // matched the feature, get the first value from the options |
---|
| 41 | return get(); |
---|
| 42 | }else{ |
---|
| 43 | // did not match, get the second value, passing over the first |
---|
| 44 | get(true); |
---|
| 45 | return get(skip); |
---|
| 46 | } |
---|
| 47 | } |
---|
| 48 | // a module |
---|
| 49 | return term===undefined ? "" : term; |
---|
| 50 | } |
---|
| 51 | }, |
---|
| 52 | |
---|
| 53 | resolvedId = get(); |
---|
| 54 | |
---|
| 55 | // we only need the plugin if we need to resolve at run time |
---|
| 56 | if(resolvedId===undefined){ |
---|
| 57 | bc.log("dojoHasUnresolvedMid", ["plugin resource id", id, "reference module id", referenceModule && referenceModule.mid]); |
---|
| 58 | return getHasPluginDependency(); |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | var regex = new RegExp("((dojo\\/)|([./]+))has\\!" + dojoRegExp.escapeString(id)); |
---|
| 62 | if(!resolvedId){ |
---|
| 63 | // replace the unneeded module with a module that's guaranteed available |
---|
| 64 | // this keeps the module order, and therefore, argument order to the factory correct |
---|
| 65 | referenceModule.text = referenceModule.text.replace(regex, "require"); |
---|
| 66 | return []; |
---|
| 67 | }else{ |
---|
| 68 | var |
---|
| 69 | module = bc.getAmdModule(resolvedId, referenceModule); |
---|
| 70 | if(module){ |
---|
| 71 | referenceModule.text = referenceModule.text.replace(regex, resolvedId); |
---|
| 72 | return [module]; |
---|
| 73 | }else{ |
---|
| 74 | bc.log("dojoHasMissingMid", ["plugin resource id", id, "resolved plugin resource id", moduleInfo.mid, "reference module id", referenceModule && referenceModule.mid]); |
---|
| 75 | return getHasPluginDependency(); |
---|
| 76 | } |
---|
| 77 | } |
---|
| 78 | } |
---|
| 79 | }; |
---|
| 80 | }); |
---|