Skip to content

Incorrect paths in source maps in subfolders #855

Description

@tomblind

When a ts file in a subfolder is transpiled with a source map and output to another folder (using outDir), the source map does not contain the correct relative path information to find the original source.

Example:

tsconfig.json

{
    "compilerOptions": {
        "sourceMap": true,
        "rootDir": "ts",
        "outDir": "lua"
    },
    "include": [
        "ts/sub/foobar.ts"
    ]
}

lua/sub/foobar.lua.map

{"version":3,"sources":["foobar.ts"],"names":[],"mappings":";MAAY","file":"foobar.lua","sourceRoot":"..\\ts"}

In this example, the map would point to lua/ts/foobar.ts instead of ts/sub/foobar.ts.

The obvious thing to do would be to fix sourceRoot in these situations:

{"version":3,"sources":["foobar.ts"],"names":[],"mappings":";MAAY","file":"foobar.lua","sourceRoot":"..\\..\\ts\\sub"}

But, looking at typescript's output for the same project, it seems they opt to include the path information in sources:

{"version":3,"file":"foobar.js","sourceRoot":"","sources":["../../ts/sub/foobar.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC"}

TS only uses sourceRoot when it's explicitly declared in tsconfig.json:

{
    "compilerOptions": {
        ...
        "sourceRoot": "ts"
    },
    ...
}
{"version":3,"file":"foobar.js","sourceRoot":"ts/","sources":["sub/foobar.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC"}

Perhaps emulating that would be the ideal solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions