UNPKG

remark-plugin-vue-live

Version:

Remark plugin to transform fenced code into examples in vue-live

20 lines (16 loc) 404 B
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; } };