protobuf.js
protobuf.js copied to clipboard
fix code gen error, if proto pacakge name contains javascript reserved word
fix codegen error, if proto pacakge name contains javascript reserved word, codegen will gen error code in static/static-module target
e.g.
test.proto
package function.b; // `function` is a reserved word
message Msg {
optional int32 a = 1;
}
use pbjs -t static-module -w es6 -o test.js test.proto
incorrect result test.js
/// ...part of code
export const function_ = $root.function_ = (() => { // correct
/// ...part of code
Msg.decode = function decode(reader, length) {
if (!(reader instanceof $Reader))
reader = $Reader.create(reader);
let end = length === undefined ? reader.len : reader.pos + length, message = new $root.function.b.Msg(); // incorrect
/// ...part of code
Msg.fromObject = function fromObject(object) {
if (object instanceof $root.function.b.Msg) // incorrect
--> incorrect code $root.function.b.Msg()
--> correct code is $root.function_.b.Msg()
correct result after fix
/// ...part of code
export const function_ = $root.function_ = (() => { // correct
/// ...part of code
Msg.decode = function decode(reader, length) {
if (!(reader instanceof $Reader))
reader = $Reader.create(reader);
let end = length === undefined ? reader.len : reader.pos + length, message = new $root.function_.b.Msg(); // correct
/// ...part of code
Msg.fromObject = function fromObject(object) {
if (object instanceof $root.function_.b.Msg) // correct
Hi @alexander-fenster please merge this pr.
@jation Sorry, I don't have contributor access to this repo, please ask @dcodeIO for help with this.
Hi @dcodeIO , can you please merge this PR?