From 2bea2e632b0556da9f2acd4387dc12b279ccae92 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 5 Jan 2021 01:25:04 +0100 Subject: [PATCH 1/8] chore: use inline source maps when present in js --- cli/program_state.rs | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/cli/program_state.rs b/cli/program_state.rs index 5eda6b3fa1f221..dfe8aa6c3b881f 100644 --- a/cli/program_state.rs +++ b/cli/program_state.rs @@ -300,24 +300,10 @@ impl SourceMapGetter for ProgramState { maybe_map } else { let code = String::from_utf8(code).unwrap(); - let lines: Vec<&str> = code.split('\n').collect(); - if let Some(last_line) = lines.last() { - if last_line - .starts_with("//# sourceMappingURL=data:application/json;base64,") - { - let input = last_line.trim_start_matches( - "//# sourceMappingURL=data:application/json;base64,", - ); - let decoded_map = base64::decode(input) - .expect("Unable to decode source map from emitted file."); - Some(decoded_map) - } else { - None - } - } else { - None - } + source_map_from_code(code) } + } else if let Ok(source) = self.load(specifier, None) { + source_map_from_code(source.code) } else { None } @@ -345,6 +331,26 @@ impl SourceMapGetter for ProgramState { } } +fn source_map_from_code(code: String) -> Option> { + let lines: Vec<&str> = code.split('\n').collect(); + if let Some(last_line) = lines.last() { + if last_line + .starts_with("//# sourceMappingURL=data:application/json;base64,") + { + let input = last_line.trim_start_matches( + "//# sourceMappingURL=data:application/json;base64,", + ); + let decoded_map = base64::decode(input) + .expect("Unable to decode source map from emitted file."); + Some(decoded_map) + } else { + None + } + } else { + None + } +} + #[test] fn thread_safe() { fn f(_: S) {} From 6c10b56709e879d39618b0e95a1cca761ebf2de9 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 5 Jan 2021 03:15:45 +0100 Subject: [PATCH 2/8] add tests --- cli/ops/errors.rs | 3 +- cli/source_maps.rs | 83 ++++++++++++------- cli/tests/inline_js_source_map.ts | 6 ++ cli/tests/inline_js_source_map_2.js | 4 + cli/tests/inline_js_source_map_2.js.out | 4 + cli/tests/inline_js_source_map_2.ts | 6 ++ ...ne_js_source_map_2_with_inline_contents.js | 4 + ...s_source_map_2_with_inline_contents.js.out | 4 + ..._js_source_map_with_contents_from_graph.js | 4 + ...source_map_with_contents_from_graph.js.out | 4 + cli/tests/integration_tests.rs | 19 +++++ 11 files changed, 112 insertions(+), 29 deletions(-) create mode 100644 cli/tests/inline_js_source_map.ts create mode 100644 cli/tests/inline_js_source_map_2.js create mode 100644 cli/tests/inline_js_source_map_2.js.out create mode 100644 cli/tests/inline_js_source_map_2.ts create mode 100644 cli/tests/inline_js_source_map_2_with_inline_contents.js create mode 100644 cli/tests/inline_js_source_map_2_with_inline_contents.js.out create mode 100644 cli/tests/inline_js_source_map_with_contents_from_graph.js create mode 100644 cli/tests/inline_js_source_map_with_contents_from_graph.js.out diff --git a/cli/ops/errors.rs b/cli/ops/errors.rs index d9893b0ef8eda8..067e901ea8d3a0 100644 --- a/cli/ops/errors.rs +++ b/cli/ops/errors.rs @@ -37,11 +37,12 @@ fn op_apply_source_map( let mut mappings_map: CachedMaps = HashMap::new(); let program_state = state.borrow::>().clone(); - let (orig_file_name, orig_line_number, orig_column_number) = + let (orig_file_name, orig_line_number, orig_column_number, _) = get_orig_position( args.file_name, args.line_number.into(), args.column_number.into(), + None, &mut mappings_map, program_state, ); diff --git a/cli/source_maps.rs b/cli/source_maps.rs index 318665e9de8032..968338bddc86d4 100644 --- a/cli/source_maps.rs +++ b/cli/source_maps.rs @@ -33,12 +33,13 @@ pub fn apply_source_map( // prepareStackTrace(). let mut mappings_map: CachedMaps = HashMap::new(); - let (script_resource_name, line_number, start_column) = + let (script_resource_name, line_number, start_column, source_line) = get_maybe_orig_position( js_error.script_resource_name.clone(), js_error.line_number, // start_column is 0-based, we need 1-based here. js_error.start_column.map(|n| n + 1), + js_error.source_line.clone(), &mut mappings_map, getter.clone(), ); @@ -56,20 +57,6 @@ pub fn apply_source_map( } _ => None, }; - // if there is a source line that we might be different in the source file, we - // will go fetch it from the getter - let source_line = match line_number { - Some(ln) - if js_error.source_line.is_some() && script_resource_name.is_some() => - { - getter.get_source_line( - &js_error.script_resource_name.clone().unwrap(), - // Getter expects 0-based line numbers, but ours are 1-based. - ln as usize - 1, - ) - } - _ => js_error.source_line.clone(), - }; JsError { message: js_error.message.clone(), @@ -87,16 +74,29 @@ fn get_maybe_orig_position( file_name: Option, line_number: Option, column_number: Option, + source_line: Option, mappings_map: &mut CachedMaps, getter: Arc, -) -> (Option, Option, Option) { +) -> (Option, Option, Option, Option) { match (file_name, line_number, column_number) { (Some(file_name_v), Some(line_v), Some(column_v)) => { - let (file_name, line_number, column_number) = - get_orig_position(file_name_v, line_v, column_v, mappings_map, getter); - (Some(file_name), Some(line_number), Some(column_number)) + let (file_name, line_number, column_number, source_line) = + get_orig_position( + file_name_v, + line_v, + column_v, + source_line, + mappings_map, + getter, + ); + ( + Some(file_name), + Some(line_number), + Some(column_number), + source_line, + ) } - _ => (None, None, None), + _ => (None, None, None, source_line), } } @@ -104,11 +104,13 @@ pub fn get_orig_position( file_name: String, line_number: i64, column_number: i64, + source_line: Option, mappings_map: &mut CachedMaps, getter: Arc, -) -> (String, i64, i64) { - let maybe_source_map = get_mappings(&file_name, mappings_map, getter); - let default_pos = (file_name, line_number, column_number); +) -> (String, i64, i64, Option) { + let maybe_source_map = get_mappings(&file_name, mappings_map, getter.clone()); + let default_pos = + (file_name, line_number, column_number, source_line.clone()); // Lookup expects 0-based line and column numbers, but ours are 1-based. let line_number = line_number - 1; @@ -121,11 +123,36 @@ pub fn get_orig_position( None => default_pos, Some(token) => match token.get_source() { None => default_pos, - Some(original) => ( - original.to_string(), - i64::from(token.get_src_line()) + 1, - i64::from(token.get_src_col()) + 1, - ), + Some(original) => { + let maybe_source_line = + if let Some(source_view) = token.get_source_view() { + debug!("source view"); + source_view.get_line(token.get_src_line()) + } else { + None + }; + + let source_line = if let Some(source_line) = maybe_source_line { + Some(source_line.to_string()) + } else { + if let Some(source_line) = getter.get_source_line( + original, + // Getter expects 0-based line numbers, but ours are 1-based. + token.get_src_line() as usize, + ) { + Some(source_line) + } else { + source_line + } + }; + + ( + original.to_string(), + i64::from(token.get_src_line()) + 1, + i64::from(token.get_src_col()) + 1, + source_line, + ) + } }, } } diff --git a/cli/tests/inline_js_source_map.ts b/cli/tests/inline_js_source_map.ts new file mode 100644 index 00000000000000..529f3f42417dfd --- /dev/null +++ b/cli/tests/inline_js_source_map.ts @@ -0,0 +1,6 @@ +1+1; +interface Test { + hello: string; +} + +// throw new Error("Hello world!" as string); diff --git a/cli/tests/inline_js_source_map_2.js b/cli/tests/inline_js_source_map_2.js new file mode 100644 index 00000000000000..199ff7bb0ba2fc --- /dev/null +++ b/cli/tests/inline_js_source_map_2.js @@ -0,0 +1,4 @@ +"use strict"; +1 + 1; +throw new Error("Hello world!"); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiaHR0cDovL2xvY2FsaG9zdDo0NTQ1L2NsaS90ZXN0cy9pbmxpbmVfanNfc291cmNlX21hcF8yLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxDQUFDLEdBQUMsQ0FBQyxDQUFDO0FBS0osTUFBTSxJQUFJLEtBQUssQ0FBQyxjQUErQixDQUFDLENBQUMifQ== \ No newline at end of file diff --git a/cli/tests/inline_js_source_map_2.js.out b/cli/tests/inline_js_source_map_2.js.out new file mode 100644 index 00000000000000..008eb06573d341 --- /dev/null +++ b/cli/tests/inline_js_source_map_2.js.out @@ -0,0 +1,4 @@ +error: Uncaught Error: Hello world! +throw new Error("Hello world!"); + ^ + at http://localhost:4545/cli/tests/inline_js_source_map_2.ts:6:7 diff --git a/cli/tests/inline_js_source_map_2.ts b/cli/tests/inline_js_source_map_2.ts new file mode 100644 index 00000000000000..2c817bed4c0049 --- /dev/null +++ b/cli/tests/inline_js_source_map_2.ts @@ -0,0 +1,6 @@ +1+1; +interface Test { + hello: string; +} + +throw new Error("Hello world!" as any as string); diff --git a/cli/tests/inline_js_source_map_2_with_inline_contents.js b/cli/tests/inline_js_source_map_2_with_inline_contents.js new file mode 100644 index 00000000000000..dd289dc892e2ed --- /dev/null +++ b/cli/tests/inline_js_source_map_2_with_inline_contents.js @@ -0,0 +1,4 @@ +"use strict"; + +throw new Error("Hello world!"); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiaHR0cDovL2xvY2FsaG9zdDo0NTQ1L2NsaS90ZXN0cy9pbmxpbmVfanNfc291cmNlX21hcF8yLnRzIl0sInNvdXJjZXNDb250ZW50IjpbIjErMTtcbmludGVyZmFjZSBUZXN0IHtcbiAgaGVsbG86IHN0cmluZztcbn1cblxudGhyb3cgbmV3IEVycm9yKFwiSGVsbG8gd29ybGQhXCIgYXMgYW55IGFzIHN0cmluZyk7XG4iXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLENBQUMsR0FBQyxDQUFDLENBQUM7QUFLSixNQUFNLElBQUksS0FBSyxDQUFDLGNBQStCLENBQUMsQ0FBQyJ9 \ No newline at end of file diff --git a/cli/tests/inline_js_source_map_2_with_inline_contents.js.out b/cli/tests/inline_js_source_map_2_with_inline_contents.js.out new file mode 100644 index 00000000000000..fa82996bd881e7 --- /dev/null +++ b/cli/tests/inline_js_source_map_2_with_inline_contents.js.out @@ -0,0 +1,4 @@ +error: Uncaught Error: Hello world! +throw new Error("Hello world!" as any as string); + ^ + at http://localhost:4545/cli/tests/inline_js_source_map_2.ts:6:7 diff --git a/cli/tests/inline_js_source_map_with_contents_from_graph.js b/cli/tests/inline_js_source_map_with_contents_from_graph.js new file mode 100644 index 00000000000000..5324e0ed240796 --- /dev/null +++ b/cli/tests/inline_js_source_map_with_contents_from_graph.js @@ -0,0 +1,4 @@ +"use strict"; +import "http://localhost:4545/cli/tests/inline_js_source_map.ts"; +throw new Error("Hello world!"); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiaHR0cDovL2xvY2FsaG9zdDo0NTQ1L2NsaS90ZXN0cy9pbmxpbmVfanNfc291cmNlX21hcC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsQ0FBQyxHQUFDLENBQUMsQ0FBQztBQUtKLE1BQU0sSUFBSSxLQUFLLENBQUMsY0FBK0IsQ0FBQyxDQUFDIn0= \ No newline at end of file diff --git a/cli/tests/inline_js_source_map_with_contents_from_graph.js.out b/cli/tests/inline_js_source_map_with_contents_from_graph.js.out new file mode 100644 index 00000000000000..a0ba9fe9826258 --- /dev/null +++ b/cli/tests/inline_js_source_map_with_contents_from_graph.js.out @@ -0,0 +1,4 @@ +error: Uncaught Error: Hello world! +// throw new Error("Hello world!" as string); + ^ + at http://localhost:4545/cli/tests/inline_js_source_map.ts:6:7 diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index dd76c5782d3821..480f0cdafc8c61 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -3443,6 +3443,25 @@ itest!(local_sources_not_cached_in_memory { output: "no_mem_cache.js.out", }); +itest!(inline_js_source_map_2 { + args: "run --quiet inline_js_source_map_2.js", + output: "inline_js_source_map_2.js.out", + exit_code: 1, +}); + +itest!(inline_js_source_map_2_with_inline_contents { + args: "run --quiet inline_js_source_map_2_with_inline_contents.js", + output: "inline_js_source_map_2_with_inline_contents.js.out", + exit_code: 1, +}); + +itest!(inline_js_source_map_with_contents_from_graph { + args: "run --quiet inline_js_source_map_with_contents_from_graph.js", + output: "inline_js_source_map_with_contents_from_graph.js.out", + exit_code: 1, + http_server: true, +}); + #[test] fn cafile_env_fetch() { use deno_core::url::Url; From 138a2ae4ac0b4fb5a514d1b67a31dd1702e97865 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 5 Jan 2021 03:25:43 +0100 Subject: [PATCH 3/8] fmt + lint --- .dprintrc.json | 1 + cli/source_maps.rs | 18 ++++++++---------- cli/tests/inline_js_source_map_2.ts | 2 +- ...ine_js_source_map_2_with_inline_contents.js | 2 +- ...js_source_map_2_with_inline_contents.js.out | 2 +- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/.dprintrc.json b/.dprintrc.json index 9db9bca1a5d389..b5e9a1057bcac8 100644 --- a/.dprintrc.json +++ b/.dprintrc.json @@ -21,6 +21,7 @@ "cli/dts/lib.webworker*.d.ts", "cli/dts/typescript.d.ts", "cli/tests/encoding", + "cli/tests/inline_js_source_map*", "cli/tsc/*typescript.js", "gh-pages", "std/**/testdata", diff --git a/cli/source_maps.rs b/cli/source_maps.rs index 968338bddc86d4..23a8655cd35bea 100644 --- a/cli/source_maps.rs +++ b/cli/source_maps.rs @@ -41,7 +41,7 @@ pub fn apply_source_map( js_error.start_column.map(|n| n + 1), js_error.source_line.clone(), &mut mappings_map, - getter.clone(), + getter, ); let start_column = start_column.map(|n| n - 1); // It is better to just move end_column to be the same distance away from @@ -134,16 +134,14 @@ pub fn get_orig_position( let source_line = if let Some(source_line) = maybe_source_line { Some(source_line.to_string()) + } else if let Some(source_line) = getter.get_source_line( + original, + // Getter expects 0-based line numbers, but ours are 1-based. + token.get_src_line() as usize, + ) { + Some(source_line) } else { - if let Some(source_line) = getter.get_source_line( - original, - // Getter expects 0-based line numbers, but ours are 1-based. - token.get_src_line() as usize, - ) { - Some(source_line) - } else { - source_line - } + source_line }; ( diff --git a/cli/tests/inline_js_source_map_2.ts b/cli/tests/inline_js_source_map_2.ts index 2c817bed4c0049..41760b1ba49c9c 100644 --- a/cli/tests/inline_js_source_map_2.ts +++ b/cli/tests/inline_js_source_map_2.ts @@ -3,4 +3,4 @@ interface Test { hello: string; } -throw new Error("Hello world!" as any as string); +throw new Error("Hello world!" as unknown as string); diff --git a/cli/tests/inline_js_source_map_2_with_inline_contents.js b/cli/tests/inline_js_source_map_2_with_inline_contents.js index dd289dc892e2ed..a225b3975e9f0a 100644 --- a/cli/tests/inline_js_source_map_2_with_inline_contents.js +++ b/cli/tests/inline_js_source_map_2_with_inline_contents.js @@ -1,4 +1,4 @@ "use strict"; throw new Error("Hello world!"); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiaHR0cDovL2xvY2FsaG9zdDo0NTQ1L2NsaS90ZXN0cy9pbmxpbmVfanNfc291cmNlX21hcF8yLnRzIl0sInNvdXJjZXNDb250ZW50IjpbIjErMTtcbmludGVyZmFjZSBUZXN0IHtcbiAgaGVsbG86IHN0cmluZztcbn1cblxudGhyb3cgbmV3IEVycm9yKFwiSGVsbG8gd29ybGQhXCIgYXMgYW55IGFzIHN0cmluZyk7XG4iXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLENBQUMsR0FBQyxDQUFDLENBQUM7QUFLSixNQUFNLElBQUksS0FBSyxDQUFDLGNBQStCLENBQUMsQ0FBQyJ9 \ No newline at end of file +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiaHR0cDovL2xvY2FsaG9zdDo0NTQ1L2NsaS90ZXN0cy9pbmxpbmVfanNfc291cmNlX21hcF8yLnRzIl0sInNvdXJjZXNDb250ZW50IjpbIjErMTtcbmludGVyZmFjZSBUZXN0IHtcbiAgaGVsbG86IHN0cmluZztcbn1cblxudGhyb3cgbmV3IEVycm9yKFwiSGVsbG8gd29ybGQhXCIgYXMgdW5rbm93biBhcyBzdHJpbmcpO1xuIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxDQUFDLEdBQUMsQ0FBQyxDQUFDO0FBS0osTUFBTSxJQUFJLEtBQUssQ0FBQyxjQUErQixDQUFDLENBQUMifQ== \ No newline at end of file diff --git a/cli/tests/inline_js_source_map_2_with_inline_contents.js.out b/cli/tests/inline_js_source_map_2_with_inline_contents.js.out index fa82996bd881e7..c123de41e1ac84 100644 --- a/cli/tests/inline_js_source_map_2_with_inline_contents.js.out +++ b/cli/tests/inline_js_source_map_2_with_inline_contents.js.out @@ -1,4 +1,4 @@ error: Uncaught Error: Hello world! -throw new Error("Hello world!" as any as string); +throw new Error("Hello world!" as unknown as string); ^ at http://localhost:4545/cli/tests/inline_js_source_map_2.ts:6:7 From 5a616cd01ae3b25cfe51d9a364fcf85fdc4fec05 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 5 Jan 2021 12:21:00 +0100 Subject: [PATCH 4/8] fix tests --- cli/tests/059_fs_relative_path_perm.ts.out | 2 ++ cli/tests/073_worker_error.ts.out | 2 ++ cli/tests/074_worker_nested_error.ts.out | 2 ++ test_util/wpt | 1 + 4 files changed, 7 insertions(+) create mode 160000 test_util/wpt diff --git a/cli/tests/059_fs_relative_path_perm.ts.out b/cli/tests/059_fs_relative_path_perm.ts.out index 83df4190397de0..92d6b5966ca4e9 100644 --- a/cli/tests/059_fs_relative_path_perm.ts.out +++ b/cli/tests/059_fs_relative_path_perm.ts.out @@ -1,2 +1,4 @@ [WILDCARD]error: Uncaught PermissionDenied: read access to "non-existent", run again with the --allow-read flag + throw new ErrorClass(res.err.message); + ^ at [WILDCARD] diff --git a/cli/tests/073_worker_error.ts.out b/cli/tests/073_worker_error.ts.out index 244e56417536f6..e464789792c22c 100644 --- a/cli/tests/073_worker_error.ts.out +++ b/cli/tests/073_worker_error.ts.out @@ -2,4 +2,6 @@ at foo ([WILDCARD]) at [WILDCARD] error: Uncaught (in promise) Error: Unhandled error event reached main worker. + throw new Error("Unhandled error event reached main worker."); + ^ at Worker.#poll ([WILDCARD]) diff --git a/cli/tests/074_worker_nested_error.ts.out b/cli/tests/074_worker_nested_error.ts.out index 244e56417536f6..e464789792c22c 100644 --- a/cli/tests/074_worker_nested_error.ts.out +++ b/cli/tests/074_worker_nested_error.ts.out @@ -2,4 +2,6 @@ at foo ([WILDCARD]) at [WILDCARD] error: Uncaught (in promise) Error: Unhandled error event reached main worker. + throw new Error("Unhandled error event reached main worker."); + ^ at Worker.#poll ([WILDCARD]) diff --git a/test_util/wpt b/test_util/wpt new file mode 160000 index 00000000000000..077d53c8da8b47 --- /dev/null +++ b/test_util/wpt @@ -0,0 +1 @@ +Subproject commit 077d53c8da8b47c1d5060893af96a29f27b10008 From 60392b94329a3f26d6e219f482cff61469d76dc8 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 5 Jan 2021 13:33:56 +0100 Subject: [PATCH 5/8] fmt test --- cli/tests/fmt/expected_fmt_check_tests_dir.out | 2 +- cli/tests/inline_js_source_map.ts | 2 +- cli/tests/inline_js_source_map_2.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/tests/fmt/expected_fmt_check_tests_dir.out b/cli/tests/fmt/expected_fmt_check_tests_dir.out index e78b42db320240..00d7cb3fa40b69 100644 --- a/cli/tests/fmt/expected_fmt_check_tests_dir.out +++ b/cli/tests/fmt/expected_fmt_check_tests_dir.out @@ -1,2 +1,2 @@ [WILDCARD] -error: Found 2 not formatted files in [WILDCARD] files +error: Found 5 not formatted files in [WILDCARD] files diff --git a/cli/tests/inline_js_source_map.ts b/cli/tests/inline_js_source_map.ts index 529f3f42417dfd..5ae7c226a868e9 100644 --- a/cli/tests/inline_js_source_map.ts +++ b/cli/tests/inline_js_source_map.ts @@ -1,4 +1,4 @@ -1+1; +1 + 1; interface Test { hello: string; } diff --git a/cli/tests/inline_js_source_map_2.ts b/cli/tests/inline_js_source_map_2.ts index 41760b1ba49c9c..fa50586e6261cf 100644 --- a/cli/tests/inline_js_source_map_2.ts +++ b/cli/tests/inline_js_source_map_2.ts @@ -1,4 +1,4 @@ -1+1; +1 + 1; interface Test { hello: string; } From 1b40fa9e492b33a9f3181c74559ca51322c47ead Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 5 Jan 2021 23:20:23 +0100 Subject: [PATCH 6/8] add comments to inline_js_source_map tests --- cli/tests/integration_tests.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index aedb3f4c21a9fd..3930f2d4fea38c 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -3446,18 +3446,35 @@ itest!(local_sources_not_cached_in_memory { output: "no_mem_cache.js.out", }); + +/// This test checks that inline source map data is used. It uses a hand crafted +/// source map that maps to a file that exists, but is not loaded into the module +/// graph (inline_js_source_map_2.ts) (because there are no direct dependencies). +/// Source line is not remapped because no inline source contents are included in +/// the sourcemap and the file is not present in the dependency graph. itest!(inline_js_source_map_2 { args: "run --quiet inline_js_source_map_2.js", output: "inline_js_source_map_2.js.out", exit_code: 1, }); +/// This test checks that inline source map data is used. It uses a hand crafted +/// source map that maps to a file that exists, but is not loaded into the module +/// graph (inline_js_source_map_2.ts) (because there are no direct dependencies). +/// Source line remapped using th inline source contents that are included in the +/// inline source map. itest!(inline_js_source_map_2_with_inline_contents { args: "run --quiet inline_js_source_map_2_with_inline_contents.js", output: "inline_js_source_map_2_with_inline_contents.js.out", exit_code: 1, }); +/// This test checks that inline source map data is used. It uses a hand crafted +/// source map that maps to a file that exists, and is loaded into the module +/// graph because of a direct import statement (inline_js_source_map.ts). The +/// source map was generated from an earlier version of this file, where the throw +/// was not commented out. The source line is remapped using source contents that +/// from the module graph. itest!(inline_js_source_map_with_contents_from_graph { args: "run --quiet inline_js_source_map_with_contents_from_graph.js", output: "inline_js_source_map_with_contents_from_graph.js.out", From 9a01ef32f83388e0947d8aee9b527892c267fd6d Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 5 Jan 2021 23:21:07 +0100 Subject: [PATCH 7/8] remove debug comment --- cli/source_maps.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/cli/source_maps.rs b/cli/source_maps.rs index 23a8655cd35bea..26ba4ca294b0f9 100644 --- a/cli/source_maps.rs +++ b/cli/source_maps.rs @@ -126,7 +126,6 @@ pub fn get_orig_position( Some(original) => { let maybe_source_line = if let Some(source_view) = token.get_source_view() { - debug!("source view"); source_view.get_line(token.get_src_line()) } else { None From d882c1b899a283ccea9e319657270b487962459c Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 5 Jan 2021 23:32:14 +0100 Subject: [PATCH 8/8] lint --- cli/tests/integration_tests.rs | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 3930f2d4fea38c..f4081a7ea6300d 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -3446,35 +3446,34 @@ itest!(local_sources_not_cached_in_memory { output: "no_mem_cache.js.out", }); - -/// This test checks that inline source map data is used. It uses a hand crafted -/// source map that maps to a file that exists, but is not loaded into the module -/// graph (inline_js_source_map_2.ts) (because there are no direct dependencies). -/// Source line is not remapped because no inline source contents are included in -/// the sourcemap and the file is not present in the dependency graph. +// This test checks that inline source map data is used. It uses a hand crafted +// source map that maps to a file that exists, but is not loaded into the module +// graph (inline_js_source_map_2.ts) (because there are no direct dependencies). +// Source line is not remapped because no inline source contents are included in +// the sourcemap and the file is not present in the dependency graph. itest!(inline_js_source_map_2 { args: "run --quiet inline_js_source_map_2.js", output: "inline_js_source_map_2.js.out", exit_code: 1, }); -/// This test checks that inline source map data is used. It uses a hand crafted -/// source map that maps to a file that exists, but is not loaded into the module -/// graph (inline_js_source_map_2.ts) (because there are no direct dependencies). -/// Source line remapped using th inline source contents that are included in the -/// inline source map. +// This test checks that inline source map data is used. It uses a hand crafted +// source map that maps to a file that exists, but is not loaded into the module +// graph (inline_js_source_map_2.ts) (because there are no direct dependencies). +// Source line remapped using th inline source contents that are included in the +// inline source map. itest!(inline_js_source_map_2_with_inline_contents { args: "run --quiet inline_js_source_map_2_with_inline_contents.js", output: "inline_js_source_map_2_with_inline_contents.js.out", exit_code: 1, }); -/// This test checks that inline source map data is used. It uses a hand crafted -/// source map that maps to a file that exists, and is loaded into the module -/// graph because of a direct import statement (inline_js_source_map.ts). The -/// source map was generated from an earlier version of this file, where the throw -/// was not commented out. The source line is remapped using source contents that -/// from the module graph. +// This test checks that inline source map data is used. It uses a hand crafted +// source map that maps to a file that exists, and is loaded into the module +// graph because of a direct import statement (inline_js_source_map.ts). The +// source map was generated from an earlier version of this file, where the throw +// was not commented out. The source line is remapped using source contents that +// from the module graph. itest!(inline_js_source_map_with_contents_from_graph { args: "run --quiet inline_js_source_map_with_contents_from_graph.js", output: "inline_js_source_map_with_contents_from_graph.js.out",