Skip to content

Commit 996b3fa

Browse files
committed
Fix static codegen issues with uglifyjs3; New: Explicitly define service method names when generating static code, see #857
1 parent b611875 commit 996b3fa

15 files changed

+54
-56
lines changed

cli/targets/static.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,9 @@ var shortVars = {
172172
function beautifyCode(code) {
173173
// Add semicolons
174174
code = UglifyJS.minify(code, {
175-
fromString: true,
176175
compress: false,
177176
mangle: false,
178-
output: {
179-
beautify: true
180-
}
177+
output: { beautify: true }
181178
}).code;
182179
// Properly beautify
183180
var ast = espree.parse(code);
@@ -653,11 +650,11 @@ function buildService(ref, service) {
653650
"@returns {undefined}",
654651
"@variation 1"
655652
]);
656-
push(escapeName(service.name) + ".prototype" + util.safeProp(lcName) + " = function " + escapeName(lcName) + "(request, callback) {");
653+
push("Object.defineProperty(" + escapeName(service.name) + ".prototype" + util.safeProp(lcName) + " = function " + escapeName(lcName) + "(request, callback) {");
657654
++indent;
658655
push("return this.rpcCall(" + escapeName(lcName) + ", $root." + exportName(method.resolvedRequestType) + ", $root." + exportName(method.resolvedResponseType) + ", request, callback);");
659656
--indent;
660-
push("};");
657+
push("}, \"name\", { value: " + JSON.stringify(method.name) + " });");
661658
if (config.comments)
662659
push("");
663660
pushComment([

dist/light/protobuf.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/light/protobuf.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/minimal/protobuf.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/minimal/protobuf.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/protobuf.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/protobuf.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

google/protobuf/field_mask.json

-21
This file was deleted.

google/protobuf/field_mask.proto

-7
This file was deleted.

scripts/gencommons.js

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ var pbjs = require("../cli/pbjs");
44
[
55
"google/protobuf/api.proto",
66
"google/protobuf/descriptor.proto",
7-
"google/protobuf/field_mask.proto",
87
"google/protobuf/source_context.proto",
98
"google/protobuf/type.proto",
109

tests/data/convert.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,13 @@ $root.Message = (function() {
482482
object.uint64Val = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long;
483483
} else
484484
object.uint64Val = options.longs === String ? "0" : 0;
485-
object.bytesVal = options.bytes === String ? "" : [];
485+
if (options.bytes === String)
486+
object.bytesVal = "";
487+
else {
488+
object.bytesVal = [];
489+
if (options.bytes !== Array)
490+
object.bytesVal = $util.newBuffer(object.bytesVal);
491+
}
486492
object.enumVal = options.enums === String ? "ONE" : 1;
487493
}
488494
if (message.stringVal != null && message.hasOwnProperty("stringVal"))

tests/data/rpc-es6.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ export const MyService = $root.MyService = (() => {
5858
* @returns {undefined}
5959
* @variation 1
6060
*/
61-
MyService.prototype.myMethod = function myMethod(request, callback) {
61+
Object.defineProperty(MyService.prototype.myMethod = function myMethod(request, callback) {
6262
return this.rpcCall(myMethod, $root.MyRequest, $root.MyResponse, request, callback);
63-
};
63+
}, "name", { value: "MyMethod" });
6464

6565
/**
6666
* Calls MyMethod.

tests/data/rpc-reserved.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ $root.MyService = (function() {
6060
* @returns {undefined}
6161
* @variation 1
6262
*/
63-
MyService.prototype["delete"] = function delete_(request, callback) {
63+
Object.defineProperty(MyService.prototype["delete"] = function delete_(request, callback) {
6464
return this.rpcCall(delete_, $root.MyRequest, $root.MyResponse, request, callback);
65-
};
65+
}, "name", { value: "Delete" });
6666

6767
/**
6868
* Calls Delete.

tests/data/rpc.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ $root.MyService = (function() {
6060
* @returns {undefined}
6161
* @variation 1
6262
*/
63-
MyService.prototype.myMethod = function myMethod(request, callback) {
63+
Object.defineProperty(MyService.prototype.myMethod = function myMethod(request, callback) {
6464
return this.rpcCall(myMethod, $root.MyRequest, $root.MyResponse, request, callback);
65-
};
65+
}, "name", { value: "MyMethod" });
6666

6767
/**
6868
* Calls MyMethod.

tests/data/test.js

+32-8
Original file line numberDiff line numberDiff line change
@@ -3550,11 +3550,17 @@ $root.jspb = (function() {
35503550
object.intField = options.longs === String ? "11" : 11;
35513551
object.enumField = options.enums === String ? "E1" : 13;
35523552
object.emptyField = "";
3553-
object.bytesField = options.bytes === String ? "moo" : [
3554-
109,
3555-
111,
3556-
111
3557-
];
3553+
if (options.bytes === String)
3554+
object.bytesField = "moo";
3555+
else {
3556+
object.bytesField = [
3557+
109,
3558+
111,
3559+
111
3560+
];
3561+
if (options.bytes !== Array)
3562+
object.bytesField = $util.newBuffer(object.bytesField);
3563+
}
35583564
}
35593565
if (message.stringField != null && message.hasOwnProperty("stringField"))
35603566
object.stringField = message.stringField;
@@ -4285,7 +4291,13 @@ $root.jspb = (function() {
42854291
if (options.defaults) {
42864292
object.str = "";
42874293
object.simple1 = null;
4288-
object.bytesField = options.bytes === String ? "" : [];
4294+
if (options.bytes === String)
4295+
object.bytesField = "";
4296+
else {
4297+
object.bytesField = [];
4298+
if (options.bytes !== Array)
4299+
object.bytesField = $util.newBuffer(object.bytesField);
4300+
}
42894301
object.unused = "";
42904302
object[".jspb.test.CloneExtension.extField"] = null;
42914303
}
@@ -6709,7 +6721,13 @@ $root.jspb = (function() {
67096721
var object = {};
67106722
if (options.defaults) {
67116723
object.value = 0;
6712-
object.data = options.bytes === String ? "" : [];
6724+
if (options.bytes === String)
6725+
object.data = "";
6726+
else {
6727+
object.data = [];
6728+
if (options.bytes !== Array)
6729+
object.data = $util.newBuffer(object.data);
6730+
}
67136731
}
67146732
if (message.value != null && message.hasOwnProperty("value"))
67156733
object.value = message.value;
@@ -14604,7 +14622,13 @@ $root.google = (function() {
1460414622
} else
1460514623
object.negativeIntValue = options.longs === String ? "0" : 0;
1460614624
object.doubleValue = 0;
14607-
object.stringValue = options.bytes === String ? "" : [];
14625+
if (options.bytes === String)
14626+
object.stringValue = "";
14627+
else {
14628+
object.stringValue = [];
14629+
if (options.bytes !== Array)
14630+
object.stringValue = $util.newBuffer(object.stringValue);
14631+
}
1460814632
object.aggregateValue = "";
1460914633
}
1461014634
if (message.name && message.name.length) {

0 commit comments

Comments
 (0)