逗号表达式

 

 

const fs = require('fs');
const { parse } = require("@babel/parser");
const traverse = require("@babel/traverse").default;
const types = require("@babel/types");
const generator = require("@babel/generator").default;

let jscode = `

function test2(a,b,c,d,e,f){
    return f = (e = (d = (c = (b = (a = 1000,a+50,b+60,c+70,a+2000), d+ 80,b+3000),e+90,c+4000),f+100,d+5000),e+6000);

}
console.log(test2());
`;

let ast = parse(jscode);


const visitor =
{
    SequenceExpression: {
        exit(path) {
            let expressions = path.node.expressions;
            let finalExpression = expressions.pop();
            let statement = path.getStatementParent();
            expressions.map(function (v) {
                statement.insertBefore(types.ExpressionStatement(v));
            });
            path.replaceInline(finalExpression);
        },
    }

}



traverse(ast, visitor);
let { code } = generator(ast);
console.log(code);

 

上一篇:Docker基础一(理论部分)


下一篇:Visio 2013 专业版密钥