Skip to content

Commit

Permalink
Merge pull request #221 from timocov/allowJs-support
Browse files Browse the repository at this point in the history
Added support for allowJs compiler option
  • Loading branch information
timocov committed Sep 4, 2022
2 parents 725d4f3 + b6bd34d commit 1c3daa1
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/compile-dts.ts
Expand Up @@ -96,10 +96,14 @@ function changeExtensionToDts(fileName: string): string {
function getDeclarationFiles(rootFiles: readonly string[], compilerOptions: ts.CompilerOptions): Map<string, string> {
// we must pass `declaration: true` and `noEmit: false` if we want to generate declaration files
// see https://github.com/microsoft/TypeScript/issues/24002#issuecomment-550549393
// also, we don't want to generate anything apart from declarations so that's why `emitDeclarationOnly: true` is here
// it allows to run the tool for projects with allowJs flag enabled to avoid errors like:
// error TS5055: Cannot write file '<filename>' because it would overwrite input file.
compilerOptions = {
...compilerOptions,
noEmit: false,
declaration: true,
emitDeclarationOnly: true,
};

const program = ts.createProgram(rootFiles, compilerOptions);
Expand Down
5 changes: 5 additions & 0 deletions tests/e2e/test-cases/allow-js/config.ts
@@ -0,0 +1,5 @@
import { TestCaseConfig } from '../../test-cases/test-case-config';

const config: TestCaseConfig = {};

export = config;
3 changes: 3 additions & 0 deletions tests/e2e/test-cases/allow-js/hello.js
@@ -0,0 +1,3 @@
const hello = { test: 1 };

export { hello }
5 changes: 5 additions & 0 deletions tests/e2e/test-cases/allow-js/input.ts
@@ -0,0 +1,5 @@
import { hello } from "./hello.js";

export function test() {
return hello
}
5 changes: 5 additions & 0 deletions tests/e2e/test-cases/allow-js/output.d.ts
@@ -0,0 +1,5 @@
export declare function test(): {
test: number;
};

export {};
6 changes: 6 additions & 0 deletions tests/e2e/test-cases/allow-js/tsconfig.json
@@ -0,0 +1,6 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"allowJs": true
}
}

0 comments on commit 1c3daa1

Please sign in to comment.