Skip to content

1.8.0-beta: ts.transpile now errors for .js files #6766

Description

@frankwallis

The ts.transpile method now throws an error when given a file with a .js extension:

test.js:

var ts = require("typescript");
var diags = [];
var output = ts.transpile("const a = 10; export default a;", { module: 1 }, "input.js", diags);
console.log(output);
console.log(JSON.stringify(diags));

output:

Heracles:plugin-typescript frank$ node test.js
/Users/frank/work/plugin-typescript/node_modules/typescript/lib/typescript.js:1682
                throw new Error("Debug Failure. False expression: " + (message || "") + verboseDebugString);
                ^

Error: Debug Failure. False expression: Output generation failed
    at Object.assert (/Users/frank/work/plugin-typescript/node_modules/typescript/lib/typescript.js:1682:23)
    at transpileModule (/Users/frank/work/plugin-typescript/node_modules/typescript/lib/typescript.js:47824:18)
    at Object.transpile (/Users/frank/work/plugin-typescript/node_modules/typescript/lib/typescript.js:47832:22)
    at Object.<anonymous> (/Users/frank/work/plugin-typescript/test.js:3:4)
    at Module._compile (module.js:425:26)
    at Object.Module._extensions..js (module.js:432:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Function.Module.runMain (module.js:457:10)
    at startup (node.js:138:18)

The actual error causing this is TS5055:

Cannot write file 'input.js' because it would overwrite input file.

This breaks e.g. the systemjs built-in typescript transpilation:(https://github.com/systemjs/systemjs/blob/6243d0c7700ca802699796cfae0f9e213072e077/dist/system.src.js#L1210)
Looks to be caused by the changes made for allowJs option in #5471.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions