From 85b6d448cebcb305dce4dee4b7fb96e309e5b94e Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Sun, 1 Aug 2021 19:04:38 -0700 Subject: hm Former-commit-id: 0dc1c1a74b845d037326f4f2facd786924ca722e --- src/runtime/errors.ts | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/runtime/errors.ts (limited to 'src/runtime/errors.ts') diff --git a/src/runtime/errors.ts b/src/runtime/errors.ts new file mode 100644 index 000000000..ad54cc322 --- /dev/null +++ b/src/runtime/errors.ts @@ -0,0 +1,82 @@ +var __BuildError; +var __ResolveError; +var __ImportKind; +{ + enum ImportKind { + entry_point = 0, + stmt = 1, + require = 2, + dynamic = 3, + require_resolve = 4, + at = 5, + at_conditional = 6, + url = 7, + } + + type ErrorPosition = { + file: string; + namespace: string; + line: number; // 1-based + column: number; // 0-based, byte offset relative to lineText + length: number; // in bytes + /** line of text, possibly empty */ + lineText: string; + /** byte offset relative to the start of the file */ + offset: number; + }; + + interface BuildErrorImplementation { + position: ErrorPosition; + name: string; + message: string; + } + + interface ResolveErrorImplementation extends BuildErrorImplementation { + specifier: string; + importKind: ImportKind; + } + + class BuildError extends Error { + constructor(data: BuildErrorImplementation) { + super(data.message); + this.name = data.name; + this.data = data; + } + data: BuildErrorImplementation; + + get position() { + return this.data.position; + } + + get [Symbol.toStringTag]() { + return `${this.name}: ${this.message}`; + } + } + + class ResolveError extends BuildError { + constructor(data: ResolveErrorImplementation) { + super(data); + this.name = data.name; + this.data = data; + } + data: ResolveErrorImplementation; + + get importKind() { + return this.data.importKind; + } + + get specifier() { + return this.data.specifier || ""; + } + } + + __ResolveError = ResolveError; + __BuildError = BuildError; + __ImportKind = ImportKind; +} + +export { + __ResolveError as ResolveError, + __BuildError as BuildError, + __ImportKind as ImportKind, +}; -- cgit v1.2.3