help icon indicating copy to clipboard operation
help copied to clipboard

node v12.10 unexpected error

Open hsocarras opened this issue 7 years ago • 3 comments

the following code is part of a package nodbus-plus 0.8.1. It work fine in node v10.

ParseResponse(id, resp){
      let resp = new PDU(resp);
      try{
        resp.ParseBuffer();
        return this.ParseResponsePDU(id, resp);
      }
      catch(err){
        throw err;
      }      
    }

But in node v12.10 I get the following error let resp = new PDU(resp); ^

SyntaxError: Identifier 'resp' has already been declared  at Module._compile (internal/modules/cjs/loader.js:872:18)  at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)  at Module.load (internal/modules/cjs/loader.js:790:32)  at Function.Module._load (internal/modules/cjs/loader.js:703:12)  at Module.require (internal/modules/cjs/loader.js:830:19)  at require (internal/modules/cjs/helpers.js:68:18) at Object. (C:\Users\hector\node_test\nodbus-plus\src\client\m_tcp_client.js:8:22)  at Module._compile (internal/modules/cjs/loader.js:936:30)  at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)  at Module.load (internal/modules/cjs/loader.js:790:32)

This is a bug on node v12.10?

hsocarras avatar Oct 04 '19 22:10 hsocarras

This is a programming error in nodbus-plus rather than a bug in Node.js v12.10. resp is declared as a parameter on this line:

ParseResponse(id, resp){

Howerver, the following line then attempts to declare resp a second time as a local variable:

      let resp = new PDU(resp);

The following should work, notice how let has been removed:

ParseResponse(id, resp){
      resp = new PDU(resp);
      try{
        resp.ParseBuffer();
        return this.ParseResponsePDU(id, resp);
      }
      catch(err){
        throw err;
      }      
    }

fivdi avatar Oct 05 '19 19:10 fivdi

@hsocarras That was a bug in old V8. Minimal repro is ~{a(a){let a}}. It should throw according to the spec.

Hakerh400 avatar Oct 05 '19 21:10 Hakerh400

OK, thanks.

hsocarras avatar Oct 15 '19 20:10 hsocarras