Skip to content

Commit

Permalink
[@typescript/vfs] Fix moduleDetection compiler option is not work…
Browse files Browse the repository at this point in the history
…ing.
  • Loading branch information
xiaoxiyao committed Mar 2, 2024
1 parent 2fa00c5 commit 3458b37
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/typescript-vfs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,14 +555,14 @@ export function createVirtualCompilerHost(sys: System, compilerOptions: Compiler
// getDefaultLibLocation: () => '/',
getDirectories: () => [],
getNewLine: () => sys.newLine,
getSourceFile: fileName => {
getSourceFile: (fileName, languageVersionOrOptions) => {
return (
sourceFiles.get(fileName) ||
save(
ts.createSourceFile(
fileName,
sys.readFile(fileName)!,
compilerOptions.target || defaultCompilerOptions(ts).target!,
languageVersionOrOptions,
false
)
)
Expand Down
17 changes: 17 additions & 0 deletions packages/typescript-vfs/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,20 @@ it("empty file content", async () => {
})
})

it("moduleDetection options", async () => {
const options: ts.CompilerOptions = {
module: ts.ModuleKind.AMD,
moduleDetection: ts.ModuleDetectionKind.Force,
}
const fsMap = createDefaultMapFromNodeModules(options, ts)
fsMap.set("index.ts", "let foo = 'foo'")
const system = createSystem(fsMap)
const host = createVirtualCompilerHost(system, options, ts)
const program = ts.createProgram({
rootNames: ["index.ts"],
options,
host: host.compilerHost,
})
program.emit()
expect(fsMap.get("index.js")).toEqual(`define(["require", "exports"], function (require, exports) {\n "use strict";\n Object.defineProperty(exports, "__esModule", { value: true });\n var foo = 'foo';\n});\n`)
})

0 comments on commit 3458b37

Please sign in to comment.