How to use the acorn.getLineInfo function in acorn

To help you get started, we’ve selected a few acorn examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eslint / espree / lib / espree.js View on Github external
raise(pos, message) {
        const loc = acorn.getLineInfo(this.input, pos);
        const err = new SyntaxError(message);

        err.index = pos;
        err.lineNumber = loc.line;
        err.column = loc.column + 1; // acorn uses 0-based columns
        throw err;
    }
github acornjs / acorn / acorn-loose / src / tokenize.js View on Github external
}
      } else if (/unexpected character/i.test(msg)) {
        pos++
        replace = false
      } else if (/regular expression/i.test(msg)) {
        replace = true
      } else {
        throw e
      }
      this.resetTo(pos)
      if (replace === true) replace = {start: pos, end: pos, type: tt.name, value: "✖"}
      if (replace) {
        if (this.options.locations)
          replace.loc = new SourceLocation(
            this.toks,
            getLineInfo(this.input, replace.start),
            getLineInfo(this.input, replace.end))
        return replace
      }
    }
  }
}
github observablehq / parser / src / parse.js View on Github external
function parseFileAttachments(cell, input) {
  if (cell.body && cell.body.type !== "ImportDeclaration") {
    try {
      cell.fileAttachments = findFileAttachments(cell);
    } catch (error) {
      if (error.node) {
        const loc = getLineInfo(input, error.node.start);
        error.message += ` (${loc.line}:${loc.column})`;
        error.pos = error.node.start;
        error.loc = loc;
        delete error.node;
      }
      throw error;
    }
  } else {
    cell.fileAttachments = new Map();
  }
  return cell;
}
github wrleskovec / react-week-scheduler / node_modules / acorn / src / loose / statement.js View on Github external
lp.parseTopLevel = function() {
  let node = this.startNodeAt(this.options.locations ? [0, getLineInfo(this.input, 0)] : 0)
  node.body = []
  while (this.tok.type !== tt.eof) node.body.push(this.parseStatement())
  this.last = this.tok
  if (this.options.ecmaVersion >= 6) {
    node.sourceType = this.options.sourceType
  }
  return this.finishNode(node, "Program")
}
github acornjs / acorn / acorn-loose / src / statement.js View on Github external
lp.parseTopLevel = function() {
  let node = this.startNodeAt(this.options.locations ? [0, getLineInfo(this.input, 0)] : 0)
  node.body = []
  while (this.tok.type !== tt.eof) node.body.push(this.parseStatement())
  this.toks.adaptDirectivePrologue(node.body)
  this.last = this.tok
  node.sourceType = this.options.sourceType
  return this.finishNode(node, "Program")
}
github cappuccino / objjc / lib / compiler.js View on Github external
getImportStackDump()
    {
        if (this.compilerStateStack.length === 0)
            return null;

        let stack = "";

        for (const state of this.compilerStateStack)
        {
            const
                sourcePath = utils.getRelativeSourcePath(state.sourcePath),
                line = acorn.getLineInfo(state.source, state.node.start).line;

            stack += `In file imported from '${sourcePath}':${line}\n`;
        }

        return stack;
    }