diff --git a/cli/tests/020_json_modules.ts.out b/cli/tests/020_json_modules.ts.out index 6e933ef993..54db523a01 100644 --- a/cli/tests/020_json_modules.ts.out +++ b/cli/tests/020_json_modules.ts.out @@ -1,9 +1,3 @@ [WILDCARD] error: Uncaught TypeError: Cannot resolve extension for "[WILDCARD]config.json" with mediaType "Json". - at getExtension ([WILDCARD]99_main_compiler.js:[WILDCARD]) - at new SourceFile ([WILDCARD]99_main_compiler.js:[WILDCARD]) - at Function.addToCache ([WILDCARD]99_main_compiler.js:[WILDCARD]) - at buildSourceFileCache ([WILDCARD]99_main_compiler.js:[WILDCARD]) - at compile ([WILDCARD]99_main_compiler.js:[WILDCARD]) - at tsCompilerOnMessage ([WILDCARD]99_main_compiler.js:[WILDCARD]) [WILDCARD] \ No newline at end of file diff --git a/cli/tsc/06_util.js b/cli/tsc/06_util.js deleted file mode 100644 index b6a582f9e4..0000000000 --- a/cli/tsc/06_util.js +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. - -((window) => { - const core = Deno.core; - let logDebug = false; - let logSource = "JS"; - - function setLogDebug(debug, source) { - logDebug = debug; - if (source) { - logSource = source; - } - } - - function log(...args) { - if (logDebug) { - const stringifiedArgs = args.map(JSON.stringify).join(" "); - core.print(`DEBUG ${logSource} - ${stringifiedArgs}\n`); - } - } - - class AssertionError extends Error { - constructor(msg) { - super(msg); - this.name = "AssertionError"; - } - } - - function assert(cond, msg = "Assertion failed.") { - if (!cond) { - throw new AssertionError(msg); - } - } - - function createResolvable() { - let resolve; - let reject; - const promise = new Promise((res, rej) => { - resolve = res; - reject = rej; - }); - promise.resolve = resolve; - promise.reject = reject; - return promise; - } - - function notImplemented() { - throw new Error("not implemented"); - } - - window.__bootstrap.util = { - log, - setLogDebug, - notImplemented, - createResolvable, - assert, - AssertionError, - }; -})(this); diff --git a/cli/tsc/40_error_stack.js b/cli/tsc/40_error_stack.js deleted file mode 100644 index 7a91a15c8e..0000000000 --- a/cli/tsc/40_error_stack.js +++ /dev/null @@ -1,224 +0,0 @@ -// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. - -((window) => { - // 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 - const assert = window.__bootstrap.util.assert; - - function patchCallSite(callSite, location) { - return { - getThis() { - return callSite.getThis(); - }, - getTypeName() { - return callSite.getTypeName(); - }, - getFunction() { - return callSite.getFunction(); - }, - getFunctionName() { - return callSite.getFunctionName(); - }, - getMethodName() { - return callSite.getMethodName(); - }, - getFileName() { - return location.fileName; - }, - getLineNumber() { - return location.lineNumber; - }, - getColumnNumber() { - return location.columnNumber; - }, - getEvalOrigin() { - return callSite.getEvalOrigin(); - }, - isToplevel() { - return callSite.isToplevel(); - }, - isEval() { - return callSite.isEval(); - }, - isNative() { - return callSite.isNative(); - }, - isConstructor() { - return callSite.isConstructor(); - }, - isAsync() { - return callSite.isAsync(); - }, - isPromiseAll() { - return callSite.isPromiseAll(); - }, - getPromiseIndex() { - return callSite.getPromiseIndex(); - }, - }; - } - - // Keep in sync with `cli/fmt_errors.rs`. - function formatLocation(callSite) { - if (callSite.isNative()) { - return "native"; - } - - let result = ""; - - const fileName = callSite.getFileName(); - - if (fileName) { - result += fileName; - } else { - if (callSite.isEval()) { - const evalOrigin = callSite.getEvalOrigin(); - assert(evalOrigin != null); - result += `${evalOrigin}, `; - } - result += ""; - } - - const lineNumber = callSite.getLineNumber(); - if (lineNumber != null) { - result += `:${lineNumber}`; - - const columnNumber = callSite.getColumnNumber(); - if (columnNumber != null) { - result += `:${columnNumber}`; - } - } - - return result; - } - - // Keep in sync with `cli/fmt_errors.rs`. - function formatCallSite(callSite) { - let result = ""; - const functionName = callSite.getFunctionName(); - - const isTopLevel = callSite.isToplevel(); - const isAsync = callSite.isAsync(); - const isPromiseAll = callSite.isPromiseAll(); - const isConstructor = callSite.isConstructor(); - const isMethodCall = !(isTopLevel || isConstructor); - - if (isAsync) { - result += "async "; - } - if (isPromiseAll) { - result += `Promise.all (index ${callSite.getPromiseIndex()})`; - return result; - } - if (isMethodCall) { - const typeName = callSite.getTypeName(); - const methodName = callSite.getMethodName(); - - if (functionName) { - if (typeName) { - if (!functionName.startsWith(typeName)) { - result += `${typeName}.`; - } - } - result += functionName; - if (methodName) { - if (!functionName.endsWith(methodName)) { - result += ` [as ${methodName}]`; - } - } - } else { - if (typeName) { - result += `${typeName}.`; - } - if (methodName) { - result += methodName; - } else { - result += ""; - } - } - } else if (isConstructor) { - result += "new "; - if (functionName) { - result += functionName; - } else { - result += ""; - } - } else if (functionName) { - result += functionName; - } else { - result += formatLocation(callSite); - return result; - } - - result += ` (${formatLocation(callSite)})`; - return result; - } - - function evaluateCallSite(callSite) { - return { - this: callSite.getThis(), - typeName: callSite.getTypeName(), - function: callSite.getFunction(), - functionName: callSite.getFunctionName(), - methodName: callSite.getMethodName(), - fileName: callSite.getFileName(), - lineNumber: callSite.getLineNumber(), - columnNumber: callSite.getColumnNumber(), - evalOrigin: callSite.getEvalOrigin(), - isToplevel: callSite.isToplevel(), - isEval: callSite.isEval(), - isNative: callSite.isNative(), - isConstructor: callSite.isConstructor(), - isAsync: callSite.isAsync(), - isPromiseAll: callSite.isPromiseAll(), - promiseIndex: callSite.getPromiseIndex(), - }; - } - - function prepareStackTrace( - error, - callSites, - ) { - const mappedCallSites = callSites.map( - (callSite) => { - const fileName = callSite.getFileName(); - const lineNumber = callSite.getLineNumber(); - const columnNumber = callSite.getColumnNumber(); - if (fileName && lineNumber != null && columnNumber != null) { - return patchCallSite( - callSite, - { - fileName, - lineNumber, - columnNumber, - }, - ); - } - return callSite; - }, - ); - Object.defineProperties(error, { - __callSiteEvals: { value: [], configurable: true }, - }); - const formattedCallSites = []; - for (const callSite of mappedCallSites) { - error.__callSiteEvals.push(Object.freeze(evaluateCallSite(callSite))); - formattedCallSites.push(formatCallSite(callSite)); - } - Object.freeze(error.__callSiteEvals); - return ( - `${error.name}: ${error.message}\n` + - formattedCallSites - .map((s) => ` at ${s}`) - .join("\n") - ); - } - - function setPrepareStackTrace(ErrorConstructor) { - ErrorConstructor.prepareStackTrace = prepareStackTrace; - } - - window.__bootstrap.errorStack = { - setPrepareStackTrace, - }; -})(this); diff --git a/cli/tsc/99_main_compiler.js b/cli/tsc/99_main_compiler.js index 94a08e6aba..d06912b1f4 100644 --- a/cli/tsc/99_main_compiler.js +++ b/cli/tsc/99_main_compiler.js @@ -18,11 +18,42 @@ delete Object.prototype.__proto__; ((window) => { const core = window.Deno.core; - const { assert, log, notImplemented } = window.__bootstrap.util; - const util = window.__bootstrap.util; - const errorStack = window.__bootstrap.errorStack; const errors = window.__bootstrap.errors.errors; + let logDebug = false; + let logSource = "JS"; + + function setLogDebug(debug, source) { + logDebug = debug; + if (source) { + logSource = source; + } + } + + function log(...args) { + if (logDebug) { + const stringifiedArgs = args.map(JSON.stringify).join(" "); + core.print(`DEBUG ${logSource} - ${stringifiedArgs}\n`); + } + } + + class AssertionError extends Error { + constructor(msg) { + super(msg); + this.name = "AssertionError"; + } + } + + function assert(cond, msg = "Assertion failed.") { + if (!cond) { + throw new AssertionError(msg); + } + } + + function notImplemented() { + throw new Error("not implemented"); + } + /** * @param {import("../dts/typescript").DiagnosticRelatedInformation} diagnostic */ @@ -1303,8 +1334,7 @@ delete Object.prototype.__proto__; // are ready. The response should be a `StartRes` message containing the CLI // args and other info. const s = core.jsonOpSync("op_start"); - util.setLogDebug(s.debugFlag, source); - errorStack.setPrepareStackTrace(Error); + setLogDebug(s.debugFlag, source); return s; }