mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
fix(cli): no-check respects inlineSources compiler option (#12559)
Fixes #12064
This commit is contained in:
parent
1c739470b5
commit
b44b26c884
3 changed files with 57 additions and 3 deletions
|
@ -203,6 +203,27 @@ fn strip_config_from_emit_options(
|
|||
}
|
||||
}
|
||||
|
||||
/// Implements a configuration trait for source maps that reflects the logic
|
||||
/// to embed sources in the source map or not.
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct SourceMapConfig {
|
||||
pub inline_sources: bool,
|
||||
}
|
||||
|
||||
impl deno_ast::swc::common::source_map::SourceMapGenConfig for SourceMapConfig {
|
||||
fn file_name_to_source(&self, f: &FileName) -> String {
|
||||
f.to_string()
|
||||
}
|
||||
|
||||
fn inline_sources_content(&self, f: &FileName) -> bool {
|
||||
match f {
|
||||
FileName::Real(..) | FileName::Custom(..) => false,
|
||||
FileName::Url(..) => self.inline_sources,
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Transform a TypeScript file into a JavaScript file, based on the supplied
|
||||
/// options.
|
||||
///
|
||||
|
@ -213,6 +234,9 @@ pub fn transpile(
|
|||
) -> Result<(String, Option<String>), AnyError> {
|
||||
let program: Program = (*parsed_source.program()).clone();
|
||||
let source_map = Rc::new(SourceMap::default());
|
||||
let source_map_config = SourceMapConfig {
|
||||
inline_sources: options.inline_sources,
|
||||
};
|
||||
let specifier = resolve_url_or_path(parsed_source.specifier())?;
|
||||
let file_name = FileName::Url(specifier);
|
||||
source_map
|
||||
|
@ -252,7 +276,7 @@ pub fn transpile(
|
|||
{
|
||||
let mut buf = Vec::new();
|
||||
source_map
|
||||
.build_source_map_from(&mut src_map_buf, None)
|
||||
.build_source_map_with_config(&mut src_map_buf, None, source_map_config)
|
||||
.to_writer(&mut buf)?;
|
||||
|
||||
if options.inline_source_map {
|
||||
|
|
|
@ -184,7 +184,6 @@ pub(crate) fn get_ts_config(
|
|||
"emitDecoratorMetadata": false,
|
||||
"importsNotUsedAsValues": "remove",
|
||||
"inlineSourceMap": true,
|
||||
// TODO(@kitsonk) make this actually work when https://github.com/swc-project/swc/issues/2218 addressed.
|
||||
"inlineSources": true,
|
||||
"sourceMap": false,
|
||||
"jsx": "react",
|
||||
|
@ -519,6 +518,9 @@ pub(crate) fn bundle(
|
|||
let globals = swc::common::Globals::new();
|
||||
deno_ast::swc::common::GLOBALS.set(&globals, || {
|
||||
let emit_options: ast::EmitOptions = options.ts_config.into();
|
||||
let source_map_config = ast::SourceMapConfig {
|
||||
inline_sources: emit_options.inline_sources,
|
||||
};
|
||||
|
||||
let cm = Rc::new(swc::common::SourceMap::new(
|
||||
swc::common::FilePathMapping::empty(),
|
||||
|
@ -577,7 +579,7 @@ pub(crate) fn bundle(
|
|||
let mut maybe_map: Option<String> = None;
|
||||
{
|
||||
let mut buf = Vec::new();
|
||||
cm.build_source_map_from(&mut srcmap, None)
|
||||
cm.build_source_map_with_config(&mut srcmap, None, source_map_config)
|
||||
.to_writer(&mut buf)?;
|
||||
if emit_options.inline_source_map {
|
||||
let encoded_map = format!(
|
||||
|
|
28
cli/tests/testdata/compiler_api_test.ts
vendored
28
cli/tests/testdata/compiler_api_test.ts
vendored
|
@ -529,3 +529,31 @@ Deno.test({
|
|||
);
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "Deno.emit() - no check respects inlineSources compiler option",
|
||||
async fn() {
|
||||
const { files } = await Deno.emit(
|
||||
"file:///a.ts",
|
||||
{
|
||||
check: false,
|
||||
compilerOptions: {
|
||||
types: ["file:///b.d.ts"],
|
||||
inlineSources: true,
|
||||
},
|
||||
sources: {
|
||||
"file:///a.ts": `const b = new B();
|
||||
console.log(b.b);`,
|
||||
"file:///b.d.ts": `declare class B {
|
||||
b: string;
|
||||
}`,
|
||||
},
|
||||
},
|
||||
);
|
||||
const sourceMap: { sourcesContent?: string[] } = JSON.parse(
|
||||
files["file:///a.ts.js.map"],
|
||||
);
|
||||
assert(sourceMap.sourcesContent);
|
||||
assertEquals(sourceMap.sourcesContent.length, 1);
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue