Sha256: cf5b4c24f2bde6f0b599dffcf031f4487353eee7fe44aa2326229c60b04390d5

Contents?: true

Size: 1.39 KB

Versions: 28

Compression:

Stored size: 1.39 KB

Contents

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.codeFrameFromAst = codeFrameFromAst;
exports.codeFrameFromSource = codeFrameFromSource;

var _wastPrinter = require("@webassemblyjs/wast-printer");

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

var SHOW_LINES_AROUND_POINTER = 5;

function repeat(char, nb) {
  return Array(nb).fill(char).join("");
} // TODO(sven): allow arbitrary ast nodes


function codeFrameFromAst(ast, loc) {
  return codeFrameFromSource((0, _wastPrinter.print)(ast), loc);
}

function codeFrameFromSource(source, loc) {
  var start = loc.start,
      end = loc.end;
  var length = 1;

  if (_typeof(end) === "object") {
    length = end.column - start.column + 1;
  }

  return source.split("\n").reduce(function (acc, line, lineNbr) {
    if (Math.abs(start.line - lineNbr) < SHOW_LINES_AROUND_POINTER) {
      acc += line + "\n";
    } // Add a new line with the pointer padded left


    if (lineNbr === start.line - 1) {
      acc += repeat(" ", start.column - 1);
      acc += repeat("^", length);
      acc += "\n";
    }

    return acc;
  }, "");
}

Version data entries

28 entries across 27 versions & 9 rubygems

Version Path
ezii-os-5.2.1 node_modules/@webassemblyjs/helper-code-frame/lib/index.js
ezii-os-2.0.1 node_modules/@webassemblyjs/helper-code-frame/lib/index.js
ezii-os-1.1.0 node_modules/@webassemblyjs/helper-code-frame/lib/index.js
ezii-os-1.0.0 node_modules/@webassemblyjs/helper-code-frame/lib/index.js
ezii-os-0.0.0.1.0 node_modules/@webassemblyjs/helper-code-frame/lib/index.js
ezii-os-0.0.0.0.1 node_modules/@webassemblyjs/helper-code-frame/lib/index.js
locomotivecms-4.0.0.alpha1 app/javascript/node_modules/@webassemblyjs/helper-code-frame/lib/index.js
locomotivecms-3.4.0 app/javascript/node_modules/@webassemblyjs/helper-code-frame/lib/index.js