Properly camelCase when translating to CommonJS.

This commit is contained in:
Josh Haberman 2016-02-18 10:46:44 -08:00
parent 29d58d3392
commit 907ad4a004

View File

@ -43,6 +43,22 @@ function tryStripPrefix(str, prefix) {
return str.substr(prefix.length); return str.substr(prefix.length);
} }
function camelCase(str) {
var ret = '';
var ucaseNext = false;
for (var i = 0; i < str.length; i++) {
if (str[i] == '-') {
ucaseNext = true;
} else if (ucaseNext) {
ret += str[i].toUpperCase();
ucaseNext = false;
} else {
ret += str[i];
}
}
return ret;
}
var module = null; var module = null;
var pkg = null; var pkg = null;
lineReader.on('line', function(line) { lineReader.on('line', function(line) {
@ -64,7 +80,7 @@ lineReader.on('line', function(line) {
console.log("// Bring asserts into the global namespace."); console.log("// Bring asserts into the global namespace.");
console.log("googleProtobuf.object.extend(global, asserts);"); console.log("googleProtobuf.object.extend(global, asserts);");
} }
module = isLoadFromFile[1].replace("-", "_"); module = camelCase(isLoadFromFile[1])
pkg = isLoadFromFile[2]; pkg = isLoadFromFile[2];
if (module != "googleProtobuf") { // We unconditionally require this in the header. if (module != "googleProtobuf") { // We unconditionally require this in the header.