Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: v8 coverage ranges that fall on \n characters cause exceptions (#96
) When a file has dos line endings \r\n we found a few instances in a large codebase where v8 would report the position of the \n as startCol for a range. This would cause the starting column supplied to sourceMap.originalPositionFor to be a -1 because the startColumns of the transpiled source lines were calculated as endCol + length of line break sequence. To replicate this condition, revert the fix but run the new unit test. The call to `applyCoverage` will crash. While the unit test range was hand crafted by me for this particular example, we saw this coming up in the wild. This change clamps the supplied value to max 0 and adds a test fixture (force encoded as \r\n) to test for it. Co-authored-by: Joe Mordetsky <jmordetsky@bloomberg.net>
- Loading branch information
Showing
7 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
test/fixtures/scripts/needs-compile.js eol=crlf | ||
test/fixtures/scripts/needs-compile.compiled.js eol=crlf | ||
test/fixtures/scripts/needs-compile.compiled.js.map eol=crlf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
coverage | ||
.nyc_output | ||
node_modules | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// compile me with babel 7+: | ||
// > babel --plugins @babel/plugin-proposal-class-properties test/fixtures/scripts/needs-compile.js --out-file test/fixtures/scripts/needs-compile.compiled.js --source-maps | ||
// in addition, a .gitattribute clause forces this file and its compilation assets to crlf | ||
|
||
// class uses private class fields - must be compiled | ||
// hello is called | ||
class Foo { | ||
a = 1 | ||
#b = 2 | ||
constructor () { | ||
this.c = this.a + this.#b; | ||
} | ||
hello (i) { | ||
console.info('hello:', this.c + i) | ||
} | ||
} | ||
|
||
// class uses private class fields - must be compiled | ||
// hello is never called | ||
class Bar { | ||
#test = 99 | ||
constructor () { | ||
} | ||
hello () { | ||
console.info(`Hello ${this.#test}`) | ||
} | ||
} | ||
|
||
const foo = new Foo(); | ||
foo.hello(1) | ||
const bar = new Bar() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters