Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fixed 'error' is not defined linter warning when using static/static-module and es6 #833

Merged
merged 1 commit into from
Jun 13, 2017

Conversation

adrianimboden
Copy link

I have found a little problem while using protobuf.js with react.js

I used the following proto file:

syntax = "proto3";

package api;

message Ping {
  string data = 1;
};

message Pong {
  string data = 1;
};

message Message {
  oneof message {
    Ping msg_ping = 1;
    Pong msg_pong = 2;
  };
}; 

with this compiler arguments:
pbjs -t static-module -p src/api/ -o gen/api.js src/api/messages.proto

Without the patch, the generated file contains this section:

Message.verify = function verify(message) {
    if (typeof message !== "object" || message === null)
        return "object expected";
    let properties = {};
    if (message.msgPing != null && message.hasOwnProperty("msgPing")) {
        properties.message = 1;
        let error = $root.api.Ping.verify(message.msgPing);
        if (error)
            return "msgPing." + error;
    }
    if (message.msgPong != null && message.hasOwnProperty("msgPong")) {
        if (properties.message === 1)
            return "message: multiple values";
        properties.message = 1;
        error = $root.api.Pong.verify(message.msgPong);
        if (error)
            return "msgPong." + error;
    }
    return null;
};

The problem is, that second error has no 'let' keyword before it. That generates a build error when I require(...) the generated file.
With the patch it looks like this:

Message.verify = function verify(message) {
    if (typeof message !== "object" || message === null)
        return "object expected";
    let properties = {};
    if (message.msgPing != null && message.hasOwnProperty("msgPing")) {
        properties.message = 1;
        {
            let error = $root.api.Ping.verify(message.msgPing);
            if (error)
                return "msgPing." + error;
        }
    }
    if (message.msgPong != null && message.hasOwnProperty("msgPong")) {
        if (properties.message === 1)
            return "message: multiple values";
        properties.message = 1;
        {
            let error = $root.api.Pong.verify(message.msgPong);
            if (error)
                return "msgPong." + error;
        }
    }
    return null;
};

@adrianimboden adrianimboden changed the title fixed 'error is not defined linter warning when using static/static-module and es6 fixed 'error' is not defined linter warning when using static/static-module and es6 Jun 13, 2017
@dcodeIO dcodeIO merged commit c43243b into protobufjs:master Jun 13, 2017
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants