Function argument destructuring and default value generates "syntax" error
See original GitHub issueThis is a:
- Bug Report
- Feature Request
- Question
- Other
Which concerns:
- flow-runtime
- babel-plugin-flow-runtime
- flow-runtime-validators
- flow-runtime-mobx
- flow-config-parser
- The documentation website
What is the current behaviour?
const defaultTrx = 'abc'
class Test {
static async getLastUpdateTimestamp ({ trx }: { trx: any } = { trx: defaultTrx }) { /* do nothing */ }
}
- flow check itself (
flow check --strip-root
) does not complain about this - this function works as expected on runtime
However when I enable babel-plugin-flow-runtime
and then I start my program I get following error:
Duplicate declaration "trx"
.babelrc.js:
module.exports = {
presets: [
'@babel/flow',
[ '@babel/env', {
targets: {
node: 'current'
}
}]
],
plugins: [
'@babel/proposal-class-properties',
'@babel/proposal-object-rest-spread',
'@babel/proposal-export-namespace',
'@babel/proposal-decorators',
['root-import', {
rootPathPrefix: '@',
rootPathSuffix: 'src'
}],
['flow-runtime', {
assert: false,
annotate: false
}]
],
env: {
test: {
plugins: ['istanbul']
}
}
}
Without flow-runtime plugin in .babelrc.js it works during runtime (no syntax errors) and also flow does not complain about it during flow check.
What is the expected behaviour?
It should not throw error, this is correct syntax and it’s supported by flow.
Which package versions are you using?
"flow-runtime": "^0.17.0",
"babel-plugin-flow-runtime": "^0.17.0",
"@babel/preset-flow": "^7.0.0-beta.32"
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:10
Top Results From Across the Web
Destructuring assignment - JavaScript - MDN Web Docs
The destructuring assignment syntax is a JavaScript expression that makes it ... Each destructured property can have a default value.
Read more >Destructuring and Function Arguments - David Walsh Blog
The basic syntax for destructuring is fairly simple but using ... The following is a function with arguments having default values:
Read more >ES6 destructuring object assignment function parameter ...
The destructuring with defaults only does its thing when you pass an object which doesn't have the respective properties.
Read more >Prevent Error with Default {} when Destructuring
When you use destructuring, make sure to set a default value of empty {} to prevent it from throwing an error! function hi(person)...
Read more >Destructuring and parameter handling in ECMAScript 6 - 2ality
ECMAScript 6 (ES6) supports destructuring, a convenient way to extract values from data stored in (possibly nested) objects and arrays.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m having the same issue:
if I work around the destructuring I get another one in a much weirder place:
the variable ‘cache’ is the one in this helper (verified by renaming, the error log changes with it):
personally I don’t see any commonality between these two cases but maybe it can help someone else figure the issue out as it seems to be related as per the error message. Luckily in my project
flow-runtime
isn’t used extensively so I will be able to remove it for the time being.My God! Finally, thank you!