mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 14:16:12 +03:00
feat(cli): Support generating .d.ts
files (#9097)
**Description:** I verified that `swc_cli` (Rust) works with ```json { "jsc": { "parser": { "syntax": "typescript" }, "experimental": { "emitIsolatedDts": true } } } ```
This commit is contained in:
parent
7c8397ddfb
commit
e71b6d31b1
@ -957,6 +957,13 @@ impl Compiler {
|
||||
) -> Result<TransformOutput, Error> {
|
||||
self.run(|| {
|
||||
let program = config.program;
|
||||
|
||||
if config.emit_isolated_dts && !config.syntax.typescript() {
|
||||
handler.warn(
|
||||
"jsc.experimental.emitIsolatedDts is enabled but the syntax is not TypeScript",
|
||||
);
|
||||
}
|
||||
|
||||
let emit_dts = config.syntax.typescript() && config.emit_isolated_dts;
|
||||
let source_map_names = if config.source_maps.enabled() {
|
||||
let mut v = swc_compiler_base::IdentCollector {
|
||||
|
3
crates/swc_cli_impl/examples/cli.rs
Normal file
3
crates/swc_cli_impl/examples/cli.rs
Normal file
@ -0,0 +1,3 @@
|
||||
fn main() -> anyhow::Result<()> {
|
||||
swc_cli_impl::run()
|
||||
}
|
@ -237,7 +237,17 @@ fn emit_output(
|
||||
fs::write(source_map_path, source_map)?;
|
||||
}
|
||||
|
||||
fs::write(output_file_path, &output.code)?;
|
||||
fs::write(&output_file_path, &output.code)?;
|
||||
|
||||
if let Some(extra) = &output.output {
|
||||
let mut extra: serde_json::Map<String, serde_json::Value> =
|
||||
serde_json::from_str(extra).context("failed to parse extra output")?;
|
||||
|
||||
if let Some(dts_code) = extra.remove("__swc_isolated_declarations__") {
|
||||
let dts_file_path = output_file_path.with_extension("d.ts");
|
||||
fs::write(dts_file_path, dts_code.as_str().unwrap())?;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let source_map = if let Some(ref source_map) = output.map {
|
||||
&**source_map
|
||||
|
@ -634,6 +634,11 @@ export interface JscConfig {
|
||||
* Disable builtin transforms. If enabled, only Wasm plugins are used.
|
||||
*/
|
||||
disableBuiltinTransformsForInternalTesting?: boolean;
|
||||
|
||||
/**
|
||||
* Emit isolated dts files for each module.
|
||||
*/
|
||||
emitIsolatedDts?: boolean;
|
||||
};
|
||||
|
||||
baseUrl?: string;
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@swc/types",
|
||||
"packageManager": "yarn@4.0.2",
|
||||
"version": "0.1.8",
|
||||
"version": "0.1.9",
|
||||
"description": "Typings for the swc project.",
|
||||
"sideEffects": false,
|
||||
"scripts": {
|
||||
|
Loading…
Reference in New Issue
Block a user