UNPKG

estree-to-babel

Version:
47 lines (36 loc) 920 B
const isString = (a) => typeof a === 'string'; const isNumber = (a) => typeof a === 'number'; const isNull = (a) => a === null; const isBool = (a) => typeof a === 'boolean'; export default (node) => { const {type, value} = node; if (type !== 'Literal') return; if (isNull(value)) { node.type = 'NullLiteral'; return; } if (isString(value)) { node.type = 'StringLiteral'; return; } if (isNumber(value)) { node.type = 'NumericLiteral'; return; } if (isBool(value)) { node.type = 'BooleanLiteral'; return; } if (node.regex) { transformRegExp(node); return; } }; function transformRegExp(node) { node.type = 'RegExpLiteral'; for (const key of Object.keys(node.regex)) { node[key] = node.regex[key]; } delete node.regex; }