ast-builder
ast-builder copied to clipboard
Arrow function destructuring is not parsed
First, thanks for this tool that heps a lot when it is time to write codemods. I found one little annoyance, and it is that arrow function destructuring is not parsed. For example this:
const x = ({a}) => {a}
Is output as :
const x = () => {
a;
};
I understand that this is not trivial because the API does not provide a way to use shorthand object properties, so you have to workaround like this:
const a = j.objectProperty(x, x);
a.shorthand = true;
The correct code for this would be:
j.variableDeclaration("const", [
j.variableDeclarator(
j.identifier("x"),
j.arrowFunctionExpression(
[
j.objectPattern([
j.objectProperty(j.identifier("a"), j.identifier("a"))
])
],
j.blockStatement([
j.expressionStatement(j.identifier("a"))
])
)
)
]);
Is this supposed to be deployed to the app?
The current outcome is even worse than the previous:

@danielo515 Deployed the new changes just now and verified, please ensure your browser cache is cleared. Hope the issue is resolved.
Hello @rajasegar , I tried it on an incognito window and I can see it is loading the new library version you updated (look at the bottom of the screenshot I just added), but it is still not working. Have you tried it? Is it working for you?

@danielo515 Yes I checked the following ones are working
const x = ({x}) => { x };
const x = ({x}) => x;
This pattern has not been handled yet with the expression statement,
({x}) => x
can you please give me a list of such patterns so that I can add tests for them and verify..
Oh, you're right, that works nice. This works as well:
setTimeout(({a}) => a, 300, {a:1})
the current limitation is not a problem for me.