const { parse } = require('@babel/parser')
const generator = require('@babel/generator')
const source = `const babel = {
version() {},
author: ''
};`
const ast = parse(source)
console.log(generator.default(ast).code === source) // false
console.log(generator.default(ast).code)
/*
const babel = {
version() {},
author: ''
};
*/
version
函数后面多了一个空格
我稍微修改了版本功能的实现。从以前FunctionExpression
到现在ArrowFunctionExpression
,结果符合预期。
const { parse } = require('@babel/parser')
const generator = require('@babel/generator')
const source = `const babel = {
version: () => {},
author: ''
};`
const ast = parse(source)
console.log(generator.default(ast).code === source) // true
我应该怎么做才能使它们保持一致?