UNPKG

858 BJavaScriptView Raw
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6function accesorString(value) {
7 var childProperties = value.split(".");
8 var length = childProperties.length;
9 var propertyString = "global";
10 var result = "";
11
12 for(var i = 0; i < length; i++) {
13 if(i > 0)
14 result += "if(!" + propertyString + ") " + propertyString + " = {};\n";
15 propertyString += "[" + JSON.stringify(childProperties[i]) + "]";
16 }
17
18 result += "module.exports = " + propertyString;
19 return result;
20}
21
22module.exports = function() {};
23module.exports.pitch = function(remainingRequest) {
24 this.cacheable && this.cacheable();
25 if(!this.query) throw new Error("query parameter is missing");
26 return accesorString(this.query.substr(1)) + " = " +
27 "require(" + JSON.stringify("-!" + remainingRequest) + ");";
28};