bring back json ops (#2815)

This commit is contained in:
Bartek Iwańczuk 2019-08-26 14:50:21 +02:00 committed by Ryan Dahl
parent 017f88ee99
commit 520f9631e0
45 changed files with 1045 additions and 1968 deletions

View file

@ -1,8 +1,8 @@
// Copyright 2018-2019 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, msg, flatbuffers } from "./dispatch_flatbuffers";
import * as dispatch from "./dispatch";
import { sendSync } from "./dispatch_json";
import { assert } from "./util";
export interface Location {
@ -17,40 +17,6 @@ export interface Location {
column: number;
}
function req(
filename: string,
line: number,
column: number
): [flatbuffers.Builder, msg.Any.ApplySourceMap, flatbuffers.Offset] {
const builder = flatbuffers.createBuilder();
const filename_ = builder.createString(filename);
const inner = msg.ApplySourceMap.createApplySourceMap(
builder,
filename_,
// 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
line - 1,
column - 1
);
return [builder, msg.Any.ApplySourceMap, inner];
}
function res(baseRes: msg.Base | null): Location {
assert(baseRes != null);
assert(baseRes!.innerType() === msg.Any.ApplySourceMap);
const res = new msg.ApplySourceMap();
assert(baseRes!.inner(res) != null);
const filename = res.filename()!;
assert(filename != null);
return {
filename,
// 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
line: res.line() + 1,
column: res.column() + 1
};
}
/** Given a current location in a module, lookup the source location and
* return it.
*
@ -75,7 +41,18 @@ function res(baseRes: msg.Base | null): Location {
*/
export function applySourceMap(location: Location): Location {
const { filename, line, column } = location;
return res(sendSync(...req(filename, line, column)));
// 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(dispatch.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