node v12.10 unexpected error
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
[90m at Module._compile (internal/modules/cjs/loader.js:872:18)[39m
[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)[39m
[90m at Module.load (internal/modules/cjs/loader.js:790:32)[39m
[90m at Function.Module._load (internal/modules/cjs/loader.js:703:12)[39m
[90m at Module.require (internal/modules/cjs/loader.js:830:19)[39m
[90m at require (internal/modules/cjs/helpers.js:68:18)[39m
at Object.
This is a bug on node v12.10?
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;
}
}
@hsocarras That was a bug in old V8. Minimal repro is ~{a(a){let a}}. It should throw according to the spec.
OK, thanks.