diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-03-08 13:09:22 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-08 13:09:22 +0100 |
commit | 1b6f8318750d319d689f7eeef9e7e1f2e56b94a6 (patch) | |
tree | b2e182b77cfbcd25ee893113de9f61509e16e787 /cli/js/error_stack.ts | |
parent | b9037c86ed8d1d55a59a1c1298fa12bbfcae6873 (diff) |
reorg: move JS ops implementations to cli/js/ops/, part 1 (#4264)
Following JS ops were moved to separate files in cli/js/ops directory:
- compiler
- dispatch_json
- dispatch_minimal
- errors
- fetch
- fs_events
- os
- random
- repl
- resources
- runtime_compiler
- runtime
- tty
Diffstat (limited to 'cli/js/error_stack.ts')
-rw-r--r-- | cli/js/error_stack.ts | 52 |
1 files changed, 1 insertions, 51 deletions
diff --git a/cli/js/error_stack.ts b/cli/js/error_stack.ts index ff15cee60..8d2badc20 100644 --- a/cli/js/error_stack.ts +++ b/cli/js/error_stack.ts @@ -1,60 +1,10 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. // Some of the code here is adapted directly from V8 and licensed under a BSD // style license available here: https://github.com/v8/v8/blob/24886f2d1c565287d33d71e4109a53bf0b54b75c/LICENSE.v8 -import { sendSync } from "./dispatch_json.ts"; +import { applySourceMap, Location } from "./ops/errors.ts"; import { assert } from "./util.ts"; import { exposeForTest } from "./internals.ts"; -export interface Location { - /** The full url for the module, e.g. `file://some/file.ts` or - * `https://some/file.ts`. */ - filename: string; - - /** The line number in the file. It is assumed to be 1-indexed. */ - line: number; - - /** The column number in the file. It is assumed to be 1-indexed. */ - column: number; -} - -/** Given a current location in a module, lookup the source location and - * return it. - * - * When Deno transpiles code, it keep source maps of the transpiled code. This - * function can be used to lookup the original location. This is automatically - * done when accessing the `.stack` of an error, or when an uncaught error is - * logged. This function can be used to perform the lookup for creating better - * error handling. - * - * **Note:** `line` and `column` are 1 indexed, which matches display - * expectations, but is not typical of most index numbers in Deno. - * - * An example: - * - * const orig = Deno.applySourceMap({ - * location: "file://my/module.ts", - * line: 5, - * column: 15 - * }); - * console.log(`${orig.filename}:${orig.line}:${orig.column}`); - * - */ -export function applySourceMap(location: Location): Location { - const { filename, line, column } = location; - // On this side, line/column are 1 based, but in the source maps, they are - // 0 based, so we have to convert back and forth - const res = sendSync("op_apply_source_map", { - filename, - line: line - 1, - column: column - 1 - }); - return { - filename: res.filename, - line: res.line + 1, - column: res.column + 1 - }; -} - /** Mutate the call site so that it returns the location, instead of its * original location. */ |