UNPKG

decaffeinate-parser

Version:

A better AST for CoffeeScript, inspired by CoffeeScriptRedux.

17 lines (16 loc) 976 B
import { Class } from '../nodes'; import getLocation from '../util/getLocation'; import mapAny from './mapAny'; import mapPossiblyEmptyBlock from './mapPossiblyEmptyBlock'; export default function mapClass(context, node) { var _a = getLocation(context, node), line = _a.line, column = _a.column, start = _a.start, end = _a.end, raw = _a.raw; var nameAssignee = node.variable ? mapAny(context, node.variable) : null; var parent = node.parent ? mapAny(context, node.parent) : null; var childContext = context.updateState(function (s) { return s.pushCurrentClass(); }); var body = mapPossiblyEmptyBlock(childContext, node.body); var boundMethods = childContext.parseState.currentClassBoundMethods; if (!boundMethods) { throw new Error('Expected a non-null bound method name array.'); } return new Class(line, column, start, end, raw, nameAssignee, nameAssignee, body, boundMethods, parent, childContext.parseState.currentClassCtor); }