1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-26 16:09:27 -05:00

fix(cli): allow setting of importsNotUsedAsValues in Deno.compile() (#8306)

Fixes #6663
This commit is contained in:
Kitson Kelly 2020-11-10 06:50:33 +11:00 committed by GitHub
parent 5375bf2e3f
commit b402b75c1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 0 deletions

View file

@ -318,6 +318,20 @@ declare namespace Deno {
/** Import emit helpers (e.g. `__extends`, `__rest`, etc..) from
* [tslib](https://www.npmjs.com/package/tslib). */
importHelpers?: boolean;
/** This flag controls how `import` works, there are 3 different options:
*
* - `remove`: The default behavior of dropping import statements which only
* reference types.
* - `preserve`: Preserves all `import` statements whose values or types are
* never used. This can cause imports/side-effects to be preserved.
* - `error`: This preserves all imports (the same as the preserve option),
* but will error when a value import is only used as a type. This might
* be useful if you want to ensure no values are being accidentally
* imported, but still make side-effect imports explicit.
*
* This flag works because you can use `import type` to explicitly create an
* `import` statement which should never be emitted into JavaScript. */
importsNotUsedAsValues?: "remove" | "preserve" | "error";
/** Emit a single file with source maps instead of having a separate file.
* Defaults to `false`. */
inlineSourceMap?: boolean;

View file

@ -199,3 +199,24 @@ Deno.test({
});
},
});
Deno.test({
name: `Deno.compile() - Allows setting of "importsNotUsedAsValues"`,
async fn() {
const [diagnostics] = await Deno.compile("/a.ts", {
"/a.ts": `import { B } from "./b.ts";
const b: B = { b: "b" };
`,
"/b.ts": `export interface B {
b: string;
};
`,
}, {
importsNotUsedAsValues: "error",
});
assert(diagnostics);
assertEquals(diagnostics.length, 1);
assert(diagnostics[0].messageText);
assert(diagnostics[0].messageText.includes("This import is never used"));
},
});