Test Case:
const b = recast.types.builders;
const ast = recast.parse('');
const add = ast.program.body[0];
ast.program.body[0] = b.variableDeclaration(
'let',
[b.variableDeclarator(
b.identifier('a'),
b.binaryExpression(
"+",
b.logicalExpression(
"??",
b.optionalMemberExpression(
b.identifier('c'),
b.identifier('b')
),
b.numericLiteral(1)
),
b.numericLiteral(1)
)
)]
);
console.log(recast.print(ast).code);
Now:
Except:
It work well if logic expression operator is '||' or '&&'。