Sha256: 394cb16f100f1e8971cb6a4c7c32aa97eebfadfcc79abe1b91ae357a521916d4

Contents?: true

Size: 1.21 KB

Versions: 27

Compression:

Stored size: 1.21 KB

Contents

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); }

import { print } from "@webassemblyjs/wast-printer";
var SHOW_LINES_AROUND_POINTER = 5;

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


export function codeFrameFromAst(ast, loc) {
  return codeFrameFromSource(print(ast), loc);
}
export 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

27 entries across 26 versions & 9 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/@webassemblyjs/helper-code-frame/esm/index.js
disco_app-0.18.0 test/dummy/node_modules/@webassemblyjs/helper-code-frame/esm/index.js
disco_app-0.18.2 test/dummy/node_modules/@webassemblyjs/helper-code-frame/esm/index.js
disco_app-0.16.1 test/dummy/node_modules/@webassemblyjs/helper-code-frame/esm/index.js
disco_app-0.15.2 test/dummy/node_modules/@webassemblyjs/helper-code-frame/esm/index.js
disco_app-0.18.4 test/dummy/node_modules/@webassemblyjs/helper-code-frame/esm/index.js
disco_app-0.18.1 test/dummy/node_modules/@webassemblyjs/helper-code-frame/esm/index.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/@webassemblyjs/helper-code-frame/esm/index.js
disco_app-0.14.0 test/dummy/node_modules/@webassemblyjs/helper-code-frame/esm/index.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/@webassemblyjs/helper-code-frame/esm/index.js
tang-0.2.1 spec/tang_app/node_modules/@webassemblyjs/helper-code-frame/esm/index.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/@webassemblyjs/helper-code-frame/esm/index.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/@webassemblyjs/helper-code-frame/esm/index.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/@webassemblyjs/helper-code-frame/esm/index.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/@webassemblyjs/helper-code-frame/esm/index.js
tang-0.2.0 spec/tang_app/node_modules/@webassemblyjs/helper-code-frame/esm/index.js
tang-0.1.0 spec/tang_app/node_modules/@webassemblyjs/helper-code-frame/esm/index.js
tang-0.0.9 spec/tang_app/node_modules/@webassemblyjs/helper-code-frame/esm/index.js
enju_library-0.3.8 spec/dummy/node_modules/@webassemblyjs/helper-code-frame/esm/index.js
jester-data-8.0.0 node_modules/@webassemblyjs/helper-code-frame/esm/index.js