1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 23:34:47 -05:00

Improve support for diagnostics from runtime compiler APIs (#3911)

- Exports diagnostic items from `diagnostics.ts` which are missing at
  runtime.
- Returns an array of diagnostics, instead of an object with a property
  of `items`.  This is because of the way Rust deals with certain
  structures, and shouldn't be exposed in the APIs.
This commit is contained in:
Kitson Kelly 2020-02-07 17:54:05 +11:00 committed by GitHub
parent 5a8ba3b114
commit ea6179f7dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 66 additions and 48 deletions

View file

@ -255,7 +255,9 @@ async function tsCompilerOnMessage({
assert(emitResult.emitSkipped === false, "Unexpected skip of the emit."); assert(emitResult.emitSkipped === false, "Unexpected skip of the emit.");
const result = [ const result = [
diagnostics.length ? fromTypeScriptDiagnostic(diagnostics) : undefined, diagnostics.length
? fromTypeScriptDiagnostic(diagnostics).items
: undefined,
bundle ? state.emitBundle : state.emitMap bundle ? state.emitBundle : state.emitMap
]; ];
globalThis.postMessage(result); globalThis.postMessage(result);

View file

@ -3,7 +3,7 @@
// This file contains the runtime APIs which will dispatch work to the internal // This file contains the runtime APIs which will dispatch work to the internal
// compiler within Deno. // compiler within Deno.
import { Diagnostic } from "./diagnostics.ts"; import { DiagnosticItem } from "./diagnostics.ts";
import * as dispatch from "./dispatch.ts"; import * as dispatch from "./dispatch.ts";
import { sendAsync } from "./dispatch_json.ts"; import { sendAsync } from "./dispatch_json.ts";
import * as util from "./util.ts"; import * as util from "./util.ts";
@ -328,7 +328,7 @@ export function compile(
rootName: string, rootName: string,
sources?: Record<string, string>, sources?: Record<string, string>,
options?: CompilerOptions options?: CompilerOptions
): Promise<[Diagnostic | undefined, Record<string, string>]> { ): Promise<[DiagnosticItem[] | undefined, Record<string, string>]> {
const payload = { const payload = {
rootName: sources ? rootName : checkRelative(rootName), rootName: sources ? rootName : checkRelative(rootName),
sources, sources,
@ -377,7 +377,7 @@ export function bundle(
rootName: string, rootName: string,
sources?: Record<string, string>, sources?: Record<string, string>,
options?: CompilerOptions options?: CompilerOptions
): Promise<[Diagnostic | undefined, string]> { ): Promise<[DiagnosticItem[] | undefined, string]> {
const payload = { const payload = {
rootName: sources ? rootName : checkRelative(rootName), rootName: sources ? rootName : checkRelative(rootName),
sources, sources,

View file

@ -103,3 +103,11 @@ test(async function bundleApiConfig() {
assert(diagnostics == null); assert(diagnostics == null);
assert(!actual.includes(`random`)); assert(!actual.includes(`random`));
}); });
test(async function diagnosticsTest() {
const [diagnostics] = await compile("/foo.ts", {
"/foo.ts": `document.getElementById("foo");`
});
assert(Array.isArray(diagnostics));
assert(diagnostics.length === 1);
});

View file

@ -44,7 +44,9 @@ function getExtension(fileName: string, mediaType: MediaType): ts.Extension {
return ts.Extension.Js; return ts.Extension.Js;
case MediaType.Unknown: case MediaType.Unknown:
default: default:
throw TypeError("Cannot resolve extension."); throw TypeError(
`Cannot resolve extension for "${fileName}" with mediaType "${MediaType[mediaType]}".`
);
} }
} }

View file

@ -1,8 +1,29 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
// Public deno module. // Public deno module.
export { dir, env, exit, isTTY, execPath, hostname } from "./os.ts"; export {
Buffer,
readAll,
readAllSync,
writeAll,
writeAllSync
} from "./buffer.ts";
export { build, OperatingSystem, Arch } from "./build.ts";
export { chmodSync, chmod } from "./chmod.ts";
export { chownSync, chown } from "./chown.ts";
export { transpileOnly, compile, bundle } from "./compiler_api.ts";
export { inspect } from "./console.ts";
export { copyFileSync, copyFile } from "./copy_file.ts";
export {
Diagnostic,
DiagnosticCategory,
DiagnosticItem,
DiagnosticMessageChain
} from "./diagnostics.ts";
export { chdir, cwd } from "./dir.ts"; export { chdir, cwd } from "./dir.ts";
export { applySourceMap } from "./error_stack.ts";
export { ErrorKind, DenoError } from "./errors.ts";
export { FileInfo } from "./file_info.ts";
export { export {
File, File,
open, open,
@ -41,45 +62,14 @@ export {
ReadWriteCloser, ReadWriteCloser,
ReadWriteSeeker ReadWriteSeeker
} from "./io.ts"; } from "./io.ts";
export { export { linkSync, link } from "./link.ts";
Buffer,
readAll,
readAllSync,
writeAll,
writeAllSync
} from "./buffer.ts";
export { mkdirSync, mkdir } from "./mkdir.ts";
export { export {
makeTempDirSync, makeTempDirSync,
makeTempDir, makeTempDir,
MakeTempDirOptions MakeTempDirOptions
} from "./make_temp_dir.ts"; } from "./make_temp_dir.ts";
export { chmodSync, chmod } from "./chmod.ts"; export { metrics, Metrics } from "./metrics.ts";
export { chownSync, chown } from "./chown.ts"; export { mkdirSync, mkdir } from "./mkdir.ts";
export { utimeSync, utime } from "./utime.ts";
export { removeSync, remove, RemoveOption } from "./remove.ts";
export { renameSync, rename } from "./rename.ts";
export { realpathSync, realpath } from "./realpath.ts";
export { readFileSync, readFile } from "./read_file.ts";
export { readDirSync, readDir } from "./read_dir.ts";
export { copyFileSync, copyFile } from "./copy_file.ts";
export { readlinkSync, readlink } from "./read_link.ts";
export { statSync, lstatSync, stat, lstat } from "./stat.ts";
export { linkSync, link } from "./link.ts";
export { symlinkSync, symlink } from "./symlink.ts";
export { writeFileSync, writeFile, WriteFileOptions } from "./write_file.ts";
export { applySourceMap } from "./error_stack.ts";
export { ErrorKind, DenoError } from "./errors.ts";
export {
permissions,
PermissionName,
PermissionState,
PermissionStatus,
Permissions
} from "./permissions.ts";
export { truncateSync, truncate } from "./truncate.ts";
export { FileInfo } from "./file_info.ts";
export { openPlugin } from "./plugins.ts";
export { export {
connect, connect,
listen, listen,
@ -88,9 +78,15 @@ export {
ShutdownMode, ShutdownMode,
shutdown shutdown
} from "./net.ts"; } from "./net.ts";
export { connectTLS, listenTLS } from "./tls.ts"; export { dir, env, exit, isTTY, execPath, hostname } from "./os.ts";
export { metrics, Metrics } from "./metrics.ts"; export {
export { resources } from "./resources.ts"; permissions,
PermissionName,
PermissionState,
PermissionStatus,
Permissions
} from "./permissions.ts";
export { openPlugin } from "./plugins.ts";
export { export {
kill, kill,
run, run,
@ -99,11 +95,21 @@ export {
ProcessStatus, ProcessStatus,
Signal Signal
} from "./process.ts"; } from "./process.ts";
export { transpileOnly, compile, bundle } from "./compiler_api.ts"; export { readDirSync, readDir } from "./read_dir.ts";
export { inspect } from "./console.ts"; export { readFileSync, readFile } from "./read_file.ts";
export { readlinkSync, readlink } from "./read_link.ts";
export { realpathSync, realpath } from "./realpath.ts";
export { removeSync, remove, RemoveOption } from "./remove.ts";
export { renameSync, rename } from "./rename.ts";
export { resources } from "./resources.ts";
export { signal, signals, SignalStream } from "./signals.ts"; export { signal, signals, SignalStream } from "./signals.ts";
export { build, OperatingSystem, Arch } from "./build.ts"; export { statSync, lstatSync, stat, lstat } from "./stat.ts";
export { symlinkSync, symlink } from "./symlink.ts";
export { connectTLS, listenTLS } from "./tls.ts";
export { truncateSync, truncate } from "./truncate.ts";
export { utimeSync, utime } from "./utime.ts";
export { version } from "./version.ts"; export { version } from "./version.ts";
export { writeFileSync, writeFile, WriteFileOptions } from "./write_file.ts";
export const args: string[] = []; export const args: string[] = [];
// These are internal Deno APIs. We are marking them as internal so they do not // These are internal Deno APIs. We are marking them as internal so they do not

View file

@ -2093,7 +2093,7 @@ declare namespace Deno {
rootName: string, rootName: string,
sources?: Record<string, string>, sources?: Record<string, string>,
options?: CompilerOptions options?: CompilerOptions
): Promise<[Diagnostic | undefined, Record<string, string>]>; ): Promise<[DiagnosticItem[] | undefined, Record<string, string>]>;
/** UNSTABLE: new API, yet to be vetted. /** UNSTABLE: new API, yet to be vetted.
* *
@ -2129,7 +2129,7 @@ declare namespace Deno {
rootName: string, rootName: string,
sources?: Record<string, string>, sources?: Record<string, string>,
options?: CompilerOptions options?: CompilerOptions
): Promise<[Diagnostic | undefined, string]>; ): Promise<[DiagnosticItem[] | undefined, string]>;
/** Returns the script arguments to the program. If for example we run a program /** Returns the script arguments to the program. If for example we run a program
* *