I got case that may be relevant to #1057, since it's about SequenceExpressions. For such code:
const name = (FIRST || SECOND).VALUE || HELLO;
After instrumenting by coverage tool 🎩ESCover I receive next results.
✅ @babel/generate produces correct result:
const name = (__c4['🧨'](1, 13), ((__c4['🧨'](1, 14), FIRST) || (__c4['🧨'](1, 23), SECOND)).VALUE) || (__c4['🧨'](1, 40), HELLO);
// ^ opening round bracket closing round bracket ^
❌ recast produces incorrect result:
const name = (__c4['🧨'](1, 13), (__c4['🧨'](1, 14), FIRST) || (__c4['🧨'](1, 23), SECOND).VALUE) || (__c4['🧨'](1, 40), HELLO);
// ^ missing missing ^
Because if __c4['🧨'] calls are removed, code looks like this:
const name = (FIRST || SECOND.VALUE) || HELLO;
Which is absolutely wrong. Here is code (+ what inslide a fix function) of 🐊Putout plugin that does transforms with Babel API.
Here is test example:
it("sequence", async function() {
const source = 'const name = (a || b).value || value';
const expected = `const name = (__c4['🧨'](1, 13), ((__c4['🧨'](1, 14), a) || (__c4['🧨'](1, 19), b).value)) || (__c4['🧨'](1, 31), value)`;
// @ts-ignore
const plugin = await eval('import("escover/plugin")') as any;
// @ts-ignore
const {transform, parse, print} = await eval('import("putout")') as any;
const ast = parse(source);
transform(ast, source, {
plugins: [
['escover', plugin],
],
});
assert.strictEqual(
print(ast),
expected,
);
});
Only transformed made by 🐊Putout, parse and print it's recast.
Looks like it is related to
I got case that may be relevant to #1057, since it's about
SequenceExpressions. For such code:After instrumenting by coverage tool 🎩ESCover I receive next results.
✅
@babel/generateproduces correct result:❌
recastproduces incorrect result:Because if
__c4['🧨']calls are removed, code looks like this:Which is absolutely wrong. Here is code (+ what inslide a
fixfunction) of 🐊Putout plugin that does transforms with Babel API.Here is test example:
Only transformed made by 🐊
Putout,parseandprintit's recast.Looks like it is related to