Skip to content

Commit e1a88f0

Browse files
committed
Merge branch 'cuongvo-master'
2 parents ba4dd68 + ace7246 commit e1a88f0

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

index.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,25 @@
44
*/
55

66
function accesorString(value) {
7-
var depths = value.split(".");
8-
var length = depths.length;
7+
var childProperties = value.split(".");
8+
var length = childProperties.length;
9+
var propertyString = "global";
910
var result = "";
10-
11-
for (var i = 0; i < length; i++) {
12-
result += "[" + JSON.stringify(depths[i]) + "]";
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]) + "]";
1316
}
1417

18+
result += "module.exports = " + propertyString;
1519
return result;
1620
}
1721

1822
module.exports = function() {};
1923
module.exports.pitch = function(remainingRequest) {
2024
this.cacheable && this.cacheable();
2125
if(!this.query) throw new Error("query parameter is missing");
22-
return "module.exports = " +
23-
"global" + accesorString(this.query.substr(1)) + " = " +
26+
return accesorString(this.query.substr(1)) + " = " +
2427
"require(" + JSON.stringify("-!" + remainingRequest) + ");";
25-
};
28+
};

0 commit comments

Comments
 (0)