summaryrefslogtreecommitdiffstats
path: root/node_modules/@webassemblyjs/helper-code-frame/esm/index.js
diff options
context:
space:
mode:
authorGravatar Piotr Russ <mail@pruss.it> 2020-11-16 00:10:28 +0100
committerGravatar Piotr Russ <mail@pruss.it> 2020-11-16 00:10:28 +0100
commite06ec920f7a5d784e674c4c4b4e6d1da3dc7391d (patch)
tree55713f725f77b44ebfec86e4eec3ce33e71458ca /node_modules/@webassemblyjs/helper-code-frame/esm/index.js
downloadwebsite_creator-e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d.tar.gz
website_creator-e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d.tar.bz2
website_creator-e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d.zip
api, login, auth
Diffstat (limited to 'node_modules/@webassemblyjs/helper-code-frame/esm/index.js')
-rw-r--r--node_modules/@webassemblyjs/helper-code-frame/esm/index.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/node_modules/@webassemblyjs/helper-code-frame/esm/index.js b/node_modules/@webassemblyjs/helper-code-frame/esm/index.js
new file mode 100644
index 0000000..791c65e
--- /dev/null
+++ b/node_modules/@webassemblyjs/helper-code-frame/esm/index.js
@@ -0,0 +1,37 @@
+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;
+ }, "");
+} \ No newline at end of file