summaryrefslogtreecommitdiff
path: root/cli/js
diff options
context:
space:
mode:
Diffstat (limited to 'cli/js')
-rw-r--r--cli/js/error_stack.ts55
-rw-r--r--cli/js/globals.ts12
-rw-r--r--cli/js/lib.deno.ns.d.ts12
-rw-r--r--cli/js/ops/errors.ts24
-rw-r--r--cli/js/tests/error_stack_test.ts36
5 files changed, 66 insertions, 73 deletions
diff --git a/cli/js/error_stack.ts b/cli/js/error_stack.ts
index 43723dff6..e77f0865c 100644
--- a/cli/js/error_stack.ts
+++ b/cli/js/error_stack.ts
@@ -11,31 +11,31 @@ function patchCallSite(callSite: CallSite, location: Location): CallSite {
getThis(): unknown {
return callSite.getThis();
},
- getTypeName(): string {
+ getTypeName(): string | null {
return callSite.getTypeName();
},
- getFunction(): Function {
+ getFunction(): Function | null {
return callSite.getFunction();
},
- getFunctionName(): string {
+ getFunctionName(): string | null {
return callSite.getFunctionName();
},
- getMethodName(): string {
+ getMethodName(): string | null {
return callSite.getMethodName();
},
- getFileName(): string {
- return location.filename;
+ getFileName(): string | null {
+ return location.fileName;
},
getLineNumber(): number {
- return location.line;
+ return location.lineNumber;
},
getColumnNumber(): number {
- return location.column;
+ return location.columnNumber;
},
getEvalOrigin(): string | null {
return callSite.getEvalOrigin();
},
- isToplevel(): boolean {
+ isToplevel(): boolean | null {
return callSite.isToplevel();
},
isEval(): boolean {
@@ -176,15 +176,15 @@ function callSiteToString(callSite: CallSite, isInternal = false): string {
interface CallSiteEval {
this: unknown;
- typeName: string;
- function: Function;
- functionName: string;
- methodName: string;
- fileName: string;
+ typeName: string | null;
+ function: Function | null;
+ functionName: string | null;
+ methodName: string | null;
+ fileName: string | null;
lineNumber: number | null;
columnNumber: number | null;
evalOrigin: string | null;
- isToplevel: boolean;
+ isToplevel: boolean | null;
isEval: boolean;
isNative: boolean;
isConstructor: boolean;
@@ -227,16 +227,16 @@ function prepareStackTrace(
structuredStackTrace
.map(
(callSite): CallSite => {
- const filename = callSite.getFileName();
- const line = callSite.getLineNumber();
- const column = callSite.getColumnNumber();
- if (filename && line != null && column != null) {
+ const fileName = callSite.getFileName();
+ const lineNumber = callSite.getLineNumber();
+ const columnNumber = callSite.getColumnNumber();
+ if (fileName && lineNumber != null && columnNumber != null) {
return patchCallSite(
callSite,
applySourceMap({
- filename,
- line,
- column,
+ fileName,
+ lineNumber,
+ columnNumber,
})
);
}
@@ -244,16 +244,13 @@ function prepareStackTrace(
}
)
.map((callSite): string => {
+ // @ts-ignore
+ error.__callSiteEvals.push(Object.freeze(evaluateCallSite(callSite)));
const isInternal =
callSite.getFileName()?.startsWith("$deno$") ?? false;
const string = callSiteToString(callSite, isInternal);
- const callSiteEv = Object.freeze(evaluateCallSite(callSite));
- if (callSiteEv.lineNumber != null && callSiteEv.columnNumber != null) {
- // @ts-ignore
- error.__callSiteEvals.push(callSiteEv);
- // @ts-ignore
- error.__formattedFrames.push(string);
- }
+ // @ts-ignore
+ error.__formattedFrames.push(string);
return ` at ${colors.stripColor(string)}`;
})
.join("\n");
diff --git a/cli/js/globals.ts b/cli/js/globals.ts
index 7e708d018..5a5f54ee1 100644
--- a/cli/js/globals.ts
+++ b/cli/js/globals.ts
@@ -31,15 +31,15 @@ import { core } from "./core.ts";
declare global {
interface CallSite {
getThis(): unknown;
- getTypeName(): string;
- getFunction(): Function;
- getFunctionName(): string;
- getMethodName(): string;
- getFileName(): string;
+ getTypeName(): string | null;
+ getFunction(): Function | null;
+ getFunctionName(): string | null;
+ getMethodName(): string | null;
+ getFileName(): string | null;
getLineNumber(): number | null;
getColumnNumber(): number | null;
getEvalOrigin(): string | null;
- isToplevel(): boolean;
+ isToplevel(): boolean | null;
isEval(): boolean;
isNative(): boolean;
isConstructor(): boolean;
diff --git a/cli/js/lib.deno.ns.d.ts b/cli/js/lib.deno.ns.d.ts
index 75d10642b..550b6cffc 100644
--- a/cli/js/lib.deno.ns.d.ts
+++ b/cli/js/lib.deno.ns.d.ts
@@ -1612,11 +1612,11 @@ declare namespace Deno {
interface Location {
/** The full url for the module, e.g. `file://some/file.ts` or
* `https://some/file.ts`. */
- filename: string;
+ fileName: string;
/** The line number in the file. It is assumed to be 1-indexed. */
- line: number;
+ lineNumber: number;
/** The column number in the file. It is assumed to be 1-indexed. */
- column: number;
+ columnNumber: number;
}
/** UNSTABLE: new API, yet to be vetted.
@@ -1636,9 +1636,9 @@ declare namespace Deno {
* An example:
*
* const orig = Deno.applySourceMap({
- * location: "file://my/module.ts",
- * line: 5,
- * column: 15
+ * fileName: "file://my/module.ts",
+ * lineNumber: 5,
+ * columnNumber: 15
* });
* console.log(`${orig.filename}:${orig.line}:${orig.column}`);
*/
diff --git a/cli/js/ops/errors.ts b/cli/js/ops/errors.ts
index 5b65d102a..bd3e6d809 100644
--- a/cli/js/ops/errors.ts
+++ b/cli/js/ops/errors.ts
@@ -7,25 +7,21 @@ export function formatDiagnostics(items: DiagnosticItem[]): string {
}
export interface Location {
- filename: string;
-
- line: number;
-
- column: number;
+ fileName: string;
+ lineNumber: number;
+ columnNumber: number;
}
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 { fileName, lineNumber, columnNumber } = location;
const res = sendSync("op_apply_source_map", {
- filename,
- line: line - 1,
- column: column - 1,
+ fileName,
+ lineNumber: lineNumber,
+ columnNumber: columnNumber,
});
return {
- filename: res.filename,
- line: res.line + 1,
- column: res.column + 1,
+ fileName: res.fileName,
+ lineNumber: res.lineNumber,
+ columnNumber: res.columnNumber,
};
}
diff --git a/cli/js/tests/error_stack_test.ts b/cli/js/tests/error_stack_test.ts
index 6868be215..83a2020ac 100644
--- a/cli/js/tests/error_stack_test.ts
+++ b/cli/js/tests/error_stack_test.ts
@@ -6,15 +6,15 @@ const { setPrepareStackTrace } = Deno[Deno.symbols.internal];
interface CallSite {
getThis(): unknown;
- getTypeName(): string;
- getFunction(): Function;
- getFunctionName(): string;
- getMethodName(): string;
- getFileName(): string;
+ getTypeName(): string | null;
+ getFunction(): Function | null;
+ getFunctionName(): string | null;
+ getMethodName(): string | null;
+ getFileName(): string | null;
getLineNumber(): number | null;
getColumnNumber(): number | null;
getEvalOrigin(): string | null;
- isToplevel(): boolean;
+ isToplevel(): boolean | null;
isEval(): boolean;
isNative(): boolean;
isConstructor(): boolean;
@@ -24,9 +24,9 @@ interface CallSite {
}
function getMockCallSite(
- filename: string,
- line: number | null,
- column: number | null
+ fileName: string,
+ lineNumber: number | null,
+ columnNumber: number | null
): CallSite {
return {
getThis(): unknown {
@@ -45,13 +45,13 @@ function getMockCallSite(
return "";
},
getFileName(): string {
- return filename;
+ return fileName;
},
getLineNumber(): number | null {
- return line;
+ return lineNumber;
},
getColumnNumber(): number | null {
- return column;
+ return columnNumber;
},
getEvalOrigin(): null {
return null;
@@ -98,11 +98,11 @@ unitTest(function prepareStackTrace(): void {
unitTest(function applySourceMap(): void {
const result = Deno.applySourceMap({
- filename: "CLI_SNAPSHOT.js",
- line: 23,
- column: 0,
+ fileName: "CLI_SNAPSHOT.js",
+ lineNumber: 23,
+ columnNumber: 0,
});
- assert(result.filename.endsWith(".ts"));
- assert(result.line != null);
- assert(result.column != null);
+ assert(result.fileName.endsWith(".ts"));
+ assert(result.lineNumber != null);
+ assert(result.columnNumber != null);
});