for (let token of acorn.tokenizer(str)) {
// iterate over the tokens
}
// transform code to array of tokens:
var tokens = [...acorn.tokenizer(str)];
function rename(code, tokenTo, tokenFrom) {
//...
try {
ast = acorn.parse(code, {
ecmaVersion: 11,
ranges: true,
allowReturnOutsideFunction: true
});
} catch(err) {
// this should probably log something and/or exit violently
return code;
}
//...
}
const acornAst = recast.parse(source, {
parser: {
parse(source) {
return require("acorn").parse(source, {
// additional options
});
}
}
});
let acorn = require("acorn");
console.log(acorn.parse("1 + 1", {ecmaVersion: 2020}));
var acorn = require("acorn");
var jsx = require("acorn-jsx");
var JSXParser = acorn.Parser.extend(jsx());
JSXParser.parse("foo(<bar/>)", {ecmaVersion: 2020});