Skip to content

Commit

Permalink
Fix static codegen issues with uglifyjs3; New: Explicitly define serv…
Browse files Browse the repository at this point in the history
…ice method names when generating static code, see #857
  • Loading branch information
dcodeIO committed May 18, 2018
1 parent b611875 commit 996b3fa
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 56 deletions.
9 changes: 3 additions & 6 deletions cli/targets/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,9 @@ var shortVars = {
function beautifyCode(code) {
// Add semicolons
code = UglifyJS.minify(code, {
fromString: true,
compress: false,
mangle: false,
output: {
beautify: true
}
output: { beautify: true }
}).code;
// Properly beautify
var ast = espree.parse(code);
Expand Down Expand Up @@ -653,11 +650,11 @@ function buildService(ref, service) {
"@returns {undefined}",
"@variation 1"
]);
push(escapeName(service.name) + ".prototype" + util.safeProp(lcName) + " = function " + escapeName(lcName) + "(request, callback) {");
push("Object.defineProperty(" + escapeName(service.name) + ".prototype" + util.safeProp(lcName) + " = function " + escapeName(lcName) + "(request, callback) {");
++indent;
push("return this.rpcCall(" + escapeName(lcName) + ", $root." + exportName(method.resolvedRequestType) + ", $root." + exportName(method.resolvedResponseType) + ", request, callback);");
--indent;
push("};");
push("}, \"name\", { value: " + JSON.stringify(method.name) + " });");
if (config.comments)
push("");
pushComment([
Expand Down
2 changes: 1 addition & 1 deletion dist/light/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/light/protobuf.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/minimal/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/minimal/protobuf.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/protobuf.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 0 additions & 21 deletions google/protobuf/field_mask.json

This file was deleted.

7 changes: 0 additions & 7 deletions google/protobuf/field_mask.proto

This file was deleted.

1 change: 0 additions & 1 deletion scripts/gencommons.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ var pbjs = require("../cli/pbjs");
[
"google/protobuf/api.proto",
"google/protobuf/descriptor.proto",
"google/protobuf/field_mask.proto",
"google/protobuf/source_context.proto",
"google/protobuf/type.proto",

Expand Down
8 changes: 7 additions & 1 deletion tests/data/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,13 @@ $root.Message = (function() {
object.uint64Val = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long;
} else
object.uint64Val = options.longs === String ? "0" : 0;
object.bytesVal = options.bytes === String ? "" : [];
if (options.bytes === String)
object.bytesVal = "";
else {
object.bytesVal = [];
if (options.bytes !== Array)
object.bytesVal = $util.newBuffer(object.bytesVal);
}
object.enumVal = options.enums === String ? "ONE" : 1;
}
if (message.stringVal != null && message.hasOwnProperty("stringVal"))
Expand Down
4 changes: 2 additions & 2 deletions tests/data/rpc-es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ export const MyService = $root.MyService = (() => {
* @returns {undefined}
* @variation 1
*/
MyService.prototype.myMethod = function myMethod(request, callback) {
Object.defineProperty(MyService.prototype.myMethod = function myMethod(request, callback) {
return this.rpcCall(myMethod, $root.MyRequest, $root.MyResponse, request, callback);
};
}, "name", { value: "MyMethod" });

/**
* Calls MyMethod.
Expand Down
4 changes: 2 additions & 2 deletions tests/data/rpc-reserved.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ $root.MyService = (function() {
* @returns {undefined}
* @variation 1
*/
MyService.prototype["delete"] = function delete_(request, callback) {
Object.defineProperty(MyService.prototype["delete"] = function delete_(request, callback) {
return this.rpcCall(delete_, $root.MyRequest, $root.MyResponse, request, callback);
};
}, "name", { value: "Delete" });

/**
* Calls Delete.
Expand Down
4 changes: 2 additions & 2 deletions tests/data/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ $root.MyService = (function() {
* @returns {undefined}
* @variation 1
*/
MyService.prototype.myMethod = function myMethod(request, callback) {
Object.defineProperty(MyService.prototype.myMethod = function myMethod(request, callback) {
return this.rpcCall(myMethod, $root.MyRequest, $root.MyResponse, request, callback);
};
}, "name", { value: "MyMethod" });

/**
* Calls MyMethod.
Expand Down
40 changes: 32 additions & 8 deletions tests/data/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3550,11 +3550,17 @@ $root.jspb = (function() {
object.intField = options.longs === String ? "11" : 11;
object.enumField = options.enums === String ? "E1" : 13;
object.emptyField = "";
object.bytesField = options.bytes === String ? "moo" : [
109,
111,
111
];
if (options.bytes === String)
object.bytesField = "moo";
else {
object.bytesField = [
109,
111,
111
];
if (options.bytes !== Array)
object.bytesField = $util.newBuffer(object.bytesField);
}
}
if (message.stringField != null && message.hasOwnProperty("stringField"))
object.stringField = message.stringField;
Expand Down Expand Up @@ -4285,7 +4291,13 @@ $root.jspb = (function() {
if (options.defaults) {
object.str = "";
object.simple1 = null;
object.bytesField = options.bytes === String ? "" : [];
if (options.bytes === String)
object.bytesField = "";
else {
object.bytesField = [];
if (options.bytes !== Array)
object.bytesField = $util.newBuffer(object.bytesField);
}
object.unused = "";
object[".jspb.test.CloneExtension.extField"] = null;
}
Expand Down Expand Up @@ -6709,7 +6721,13 @@ $root.jspb = (function() {
var object = {};
if (options.defaults) {
object.value = 0;
object.data = options.bytes === String ? "" : [];
if (options.bytes === String)
object.data = "";
else {
object.data = [];
if (options.bytes !== Array)
object.data = $util.newBuffer(object.data);
}
}
if (message.value != null && message.hasOwnProperty("value"))
object.value = message.value;
Expand Down Expand Up @@ -14604,7 +14622,13 @@ $root.google = (function() {
} else
object.negativeIntValue = options.longs === String ? "0" : 0;
object.doubleValue = 0;
object.stringValue = options.bytes === String ? "" : [];
if (options.bytes === String)
object.stringValue = "";
else {
object.stringValue = [];
if (options.bytes !== Array)
object.stringValue = $util.newBuffer(object.stringValue);
}
object.aggregateValue = "";
}
if (message.name && message.name.length) {
Expand Down

0 comments on commit 996b3fa

Please sign in to comment.