UNPKG

@sudoo/marked

Version:

JavaScript & TypeScript code runner in JavaScript, safe with marked territory, asynchronous

30 lines (29 loc) 765 B
"use strict"; /** * @author WMXPY * @namespace Analysis * @description Find One */ Object.defineProperty(exports, "__esModule", { value: true }); exports.findOneESTNodeOrNull = void 0; const acorn_walk_1 = require("acorn-walk"); const FOUND_MESSAGE = "Found"; const findOneESTNodeOrNull = (estree, type) => { let result = null; try { (0, acorn_walk_1.full)(estree, (node, _state, nodeType) => { if (nodeType === type) { result = node; throw new Error(FOUND_MESSAGE); } }); return null; } catch (err) { if (err.message === FOUND_MESSAGE) { return result; } throw err; } }; exports.findOneESTNodeOrNull = findOneESTNodeOrNull;