UNPKG

decaffeinate-parser

Version:

A better AST for CoffeeScript, inspired by CoffeeScriptRedux.

19 lines (18 loc) 955 B
import { SourceType } from 'coffee-lex'; import { Super } from '../nodes'; import getLocation from '../util/getLocation'; import { reduceProperty } from './mapValue'; export default function mapSuper(context, node) { var location = getLocation(context, node); var line = location.line, column = location.column, start = location.start; var superTokenIndex = context.sourceTokens.indexOfTokenStartingAtSourceIndex(start); if (!superTokenIndex) { throw new Error('Expected token at the start of super node.'); } var superToken = context.sourceTokens.tokenAtIndex(superTokenIndex); if (!superToken || superToken.type !== SourceType.SUPER) { throw new Error('Expected super token at the start of super node.'); } var superNode = new Super(line, column, start, superToken.end, context.source.slice(superToken.start, superToken.end)); return reduceProperty(context, location, superNode, node.accessor); }