forked from bazel-contrib/rules_nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(terser): support source map files (bazel-contrib#1195)
- Loading branch information
1 parent
be2e3ea
commit 6433822
Showing
7 changed files
with
80 additions
and
7 deletions.
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
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,26 @@ | ||
load("@npm_bazel_jasmine//:index.from_src.bzl", "jasmine_node_test") | ||
load("@npm_bazel_terser//:index.from_src.bzl", "terser_minified") | ||
|
||
filegroup( | ||
name = "src1_and_map", | ||
srcs = [ | ||
"src1.js", | ||
"src1.js.map", | ||
], | ||
) | ||
|
||
terser_minified( | ||
name = "src1.min", | ||
src = ":src1_and_map", | ||
) | ||
|
||
jasmine_node_test( | ||
name = "test", | ||
srcs = [ | ||
"terser_spec.js", | ||
], | ||
data = ["@npm//source-map"], | ||
deps = [ | ||
":src1.min", | ||
], | ||
) |
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 @@ | ||
The src1.js{,.map} files were generated from running `tsc --lib es2015,dom --sourcemap --noImplicitUseStrict src1.ts`. |
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,7 @@ | ||
// clang-format off | ||
/*a comment*/ export class MyClass { | ||
constructor(s: string) { | ||
console.log(s); | ||
} | ||
field: string|undefined; | ||
} |
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,20 @@ | ||
const fs = require('fs'); | ||
const sm = require('source-map'); | ||
const DIR = 'build_bazel_rules_nodejs/packages/terser/test/sourcemap'; | ||
|
||
describe('terser sourcemap handling', () => { | ||
it('should produce a sourcemap output', async () => { | ||
const file = require.resolve(DIR + '/src1.min.js.map'); | ||
const rawSourceMap = JSON.parse(fs.readFileSync(file, 'utf-8')); | ||
await sm.SourceMapConsumer.with(rawSourceMap, null, consumer => { | ||
const pos = consumer.originalPositionFor( | ||
// position of MyClass in terser_minified output src1.min.js | ||
// depends on DEBUG flag | ||
!process.env['DEBUG'] ? {line: 1, column: 18} : {line: 3, column: 5}); | ||
expect(pos.source).toBe('src1.ts'); | ||
expect(pos.line).toBe(2); | ||
expect(pos.column).toBe(14); | ||
expect(pos.name).toBe('MyClass'); | ||
}); | ||
}); | ||
}); |