Skip to content

Commit

Permalink
add tests and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Mar 7, 2024
1 parent 6f2f66d commit 999f1fb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,14 @@ test-old-ts: platform-neutral | require/old-ts/node_modules
node-unref-tests: | scripts/node_modules
node scripts/node-unref-tests.js

lib-typecheck: lib-typecheck-node lib-typecheck-deno
lib-typecheck: lib-typecheck-node lib-typecheck-node-nolib lib-typecheck-deno

lib-typecheck-node: | lib/node_modules
cd lib && node_modules/.bin/tsc -noEmit -p tsconfig.json

lib-typecheck-node-nolib: | lib/node_modules
cd lib && node_modules/.bin/tsc -noEmit -p tsconfig-nolib.json

lib-typecheck-deno: lib/deno/lib.deno.d.ts | lib/node_modules
cd lib && node_modules/.bin/tsc -noEmit -p tsconfig-deno.json

Expand Down
28 changes: 22 additions & 6 deletions lib/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,12 +635,6 @@ export declare function analyzeMetafileSync(metafile: Metafile | string, options
*/
export declare function initialize(options: InitializeOptions): Promise<void>

declare global {
namespace WebAssembly {
interface Module {}
}
}

export interface InitializeOptions {
/**
* The URL of the "esbuild.wasm" file. This must be provided when running
Expand Down Expand Up @@ -683,3 +677,25 @@ export let version: string
// killing it before the test ends, so you have to call this function (and
// await the returned promise) in every Deno test that uses esbuild.
export declare function stop(): Promise<void>

// Note: These declarations exist to avoid type errors when you omit "dom" from
// "lib" in your "tsconfig.json" file. TypeScript confusingly declares the
// global "WebAssembly" type in "lib.dom.d.ts" even though it has nothing to do
// with the browser DOM and is present in many non-browser JavaScript runtimes
// (e.g. node and deno). Declaring it here allows esbuild's API to be used in
// these scenarios.
//
// There's an open issue about getting this problem corrected (although these
// declarations will need to remain even if this is fixed for backward
// compatibility with older TypeScript versions):
//
// https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/826
//
declare global {
namespace WebAssembly {
interface Module {
}
}
interface URL {
}
}
11 changes: 11 additions & 0 deletions lib/tsconfig-nolib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"module": "CommonJS", // Allow the "import assignment" syntax
"target": "es2017", // Allow calling APIs such as "Object.entries"
"strict": true,
"lib": [], // Omit "dom" to test what happens with the "WebAssembly" type, which is defined in "dom"
},
"include": [
"shared/types.ts",
],
}

0 comments on commit 999f1fb

Please sign in to comment.