vuepress-plugin-live
Version:
Make your markdown code examples come alive
20 lines (16 loc) • 403 B
JavaScript
const { Parser } = require("acorn");
const ACORN_OPTIONS = {
ecmaVersion: 2019,
sourceType: "module"
};
/**
* Parse source code with Acorn and return AST, returns undefined in case of errors
*/
module.exports = function getAst(code, plugins = []) {
const parser = Parser.extend(...plugins);
try {
return parser.parse(code, ACORN_OPTIONS);
} catch (err) {
return undefined;
}
};