Skip to content

incorrect source map #4003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ecp3 opened this issue Jul 23, 2015 · 6 comments
Closed

incorrect source map #4003

ecp3 opened this issue Jul 23, 2015 · 6 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@ecp3
Copy link

ecp3 commented Jul 23, 2015

I think the source maps being generated are incorrect in some instances. I had an IntelliJ 'node' project working in 1.5.0-beta that experienced debugging problems (not stopping at some breakpoints, and not stopping at each line when stepping) when I moved to 1.5.3. I have tracked down the problem (I think) to a difference in the source maps being generated if there are comments involved. Some simplified code:

module sas.tools
{
    export class Test
    {
        public doX():void
        {
            let f:number=2;
            switch (f)
            {
                case 1:
                    break;
                case 2:
                    //line comment 1
                    //line comment 2
                    break;
                case 3:
                    //a comment
                    break;
            }
        }
    }

}

These json options:
"removeComments": false,
"preserveConstEnums": true,
"sourceMap": true,
"noImplicitAny":true,
"suppressImplicitAnyIndexErrors":true,
"target": "ES5",

1.5.0-beta sourcemap data: {"version":3,"file":"Test.js","sourceRoot":"","sources":["sourceMapTest/sas/tools/Test.ts"],"names":["sas","sas.tools","sas.tools.Test","sas.tools.Test.constructor","sas.tools.Test.doX"],"mappings":"AAAI,IAAO,GAAG,CAsBT;AAtBD,WAAO,GAAG;IAACA,IAAAA,KAAKA,CAsBfA;IAtBUA,WAAAA,KAAKA,EAChBA,CAACA;QACGC;YAAAC;YAkBAC,CAACA;YAhBUD,kBAAGA,GAAVA;gBAEIE,IAAIA,CAACA,GAAQA,CAACA,CAACA;gBACfA,MAAMA,CAACA,CAACA,CAACA,CAACA,CACVA,CAACA;oBACGA,KAAKA,CAACA;wBACFA,KAAKA,CAACA;oBACVA,KAAKA,CAACA;wBACFA,gBAAgBA;wBAChBA,gBAAgBA;wBAChBA,KAAKA,CAACA;oBACVA,KAAKA,CAACA;wBACFA,WAAWA;wBACXA,KAAKA,CAACA;gBACdA,CAACA;YACLA,CAACA;YACLF,WAACA;QAADA,CAACA,AAlBDD,IAkBCA;QAlBYA,UAAIA,OAkBhBA,CAAAA;IAELA,CAACA,EAtBUD,KAAKA,GAALA,SAAKA,KAALA,SAAKA,QAsBfA;AAADA,CAACA,EAtBM,GAAG,KAAH,GAAG,QAsBT"}
1.5.3 sourcemap data: {"version":3,"file":"Test.js","sourceRoot":"","sources":["sourceMapTest/sas/tools/Test.ts"],"names":["sas","sas.tools","sas.tools.Test","sas.tools.Test.constructor","sas.tools.Test.doX"],"mappings":"AAAA,IAAO,GAAG,CAsBT;AAtBD,WAAO,GAAG;IAACA,IAAAA,KAAKA,CAsBfA;IAtBUA,WAAAA,KAAKA,EAChBA,CAACA;QACGC;YAAAC;YAkBAC,CAACA;YAhBUD,kBAAGA,GAAVA;gBAEIE,IAAIA,CAACA,GAAQA,CAACA,CAACA;gBACfA,MAAMA,CAACA,CAACA,CAACA,CAACA,CACVA,CAACA;oBACGA,KAAKA,CAACA;wBACFA,KAAKA,CAACA;oBACVA,KAAKA,CAACA;wBAGFA,AAFAA,gBAAgBA;wBAChBA,gBAAgBA;wBAChBA,KAAKA,CAACA;oBACVA,KAAKA,CAACA;wBAEFA,AADAA,WAAWA;wBACXA,KAAKA,CAACA;gBACdA,CAACA;YACLA,CAACA;YACLF,WAACA;QAADA,CAACA,AAlBDD,IAkBCA;QAlBYA,UAAIA,OAkBhBA,CAAAA;IAELA,CAACA,EAtBUD,KAAKA,GAALA,SAAKA,KAALA,SAAKA,QAsBfA;AAADA,CAACA,EAtBM,GAAG,KAAH,GAAG,QAsBT"}

There are two differences, both at the comments inside the switch cases. In both cases, the 1.5.3 map reports an entry at
The main difference seems to be that the beta map lists (12, 20) as a location, while the 1.5.3 version doesn't (it lists 14, 20) instead. The line returned appears to be the start of the last comment after the case keyword. I don't know much about source maps, but I assume that the debugger is adding a breakpoint at a location that isn't valid, so the debugger just misses those locations.

@ecp3
Copy link
Author

ecp3 commented Jul 23, 2015

It seems like turning preserveComments off might fix this...at least my first attempt at debugging stopped at a breakpoint I had been missing.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jul 23, 2015
@weswigham
Copy link
Member

There's a possibility this is related to #2546 - it looks like it surfaces in the same circumstances.

@LPGhatguy
Copy link
Contributor

I'm seeing this same issue with a project I'm working on.

@kitsonk
Copy link
Contributor

kitsonk commented Jul 26, 2015

@weswigham they might be related... It seems the compiler is not updating the source map internally wit the current position when consuming a comment. I just ran across this one (the source file maps being wrong with preserveComments: true.

Here is a link to a visualisation of the following:

Given this sourcemap.ts:

function foo(str: string, num: number): void {
    return;
}

/**
 * some sort of block quote
 */
function bar(str: string, num: number): void {
    return;
}

// some sort of comment
function baz(str: string, num: number): void {
    return;
}

function qat(str: string, num: number): void {
    return;
}

The following will be emitted:

function foo(str, num) {
    return;
}
/**
 * some sort of block quote
 */
function bar(str, num) {
    return;
}
// some sort of comment
function baz(str, num) {
    return;
}
function qat(str, num) {
    return;
}
//# sourceMappingURL=sourcemap.js.map

With the following map:

{
  "version":3,
  "file":"sourcemap.js",
  "sourceRoot":"",
  "sources":["sourcemap.ts"],
  "names":["foo","bar","baz","qat"],
  "mappings":"AACA,aAAa,GAAW,EAAE,GAAW;IACjCA,MAAMA,CAACA;AACXA,CAACA;AAKD,AAHA;;GAEG;aACU,GAAW,EAAE,GAAW;IACjCC,MAAMA,CAACA;AACXA,CAACA;AAGD,AADA,uBAAuB;aACV,GAAW,EAAE,GAAW;IACjCC,MAAMA,CAACA;AACXA,CAACA;AAED,aAAa,GAAW,EAAE,GAAW;IACjCC,MAAMA,CAACA;AACXA,CAACA"
}

@mhegazy mhegazy added this to the TypeScript 1.6 milestone Jul 26, 2015
@ecp3
Copy link
Author

ecp3 commented Jul 27, 2015

Incidentally, I tried switching to VS Code (using the same tsconfig file) to see if I could move off of IntelliJ. Breakpoints in Code often seem not to get hit (where IntelliJ works fine). I assume this means that there are also some problems with Code breakpoint setting that aren't sourcemap problems.

@kitsonk
Copy link
Contributor

kitsonk commented Aug 18, 2015

Thank you @sheetalkamat!!!!! 😄

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

8 participants