Issue with transpiling + destructuring
- Dominant language
- JavaScript
- Stars
- 38
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Description
I have a class w/ destructured params in its constructor like this:
```js
class Foo {
/**
* @param {?string} x - param.
*/
constructor({x}) {
this.x = x
```
My `.babelrc` looks like this:
```json
{
"presets": [["es2015", { "modules": false }], "stage-2"],
"plugins": [
"jsdoc-to-assert",
],
}
```
And the code is incorrectly generated like this:
```js
var Foo = function () {
/**
* @param {?string} x - param.
*/
function Foo(_ref) {
if (!(x == null || typeof x === "string")) {
console.assert(x == null || typeof x === "string", 'Expected type: @param {?string} x\nActual value:', x, '\nFailure assertion: (x == null || typeof x === "string")');
}
var x = _ref.x
```
*NOTE* The assert reads x before it's defined.
I'd expect it to be:
```js
var Foo = function () {
/**
* @param {?string} x - param.
*/
function Foo(_ref) {
var x = _ref.x
if (!(x == null || typeof x === "string")) {
console.assert(x == null || typeof x === "string", 'Expected type: @param {?string} x\nActual value:', x, '\nFailure assertion: (x == null || typeof x === "string")');
}
```
*NOTE* that the destructuring happens before the assertion. The current order would also work if the assertion were based on `_ref.x` instead of `x`.
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the constructor case using the Babel configuration and source example shown in the issue, then inspect how JSDoc assertions interact with destructured constructor parameters. Done means the generated code assigns _ref.x to x before evaluating the assertion, matching the expected output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- babel, javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100