mirror of
https://github.com/swc-project/swc.git
synced 2024-12-23 21:54:36 +03:00
fix(swc): Fix bugs (#1932)
swc_common: - Fix handling of input source map. (#1930) swc: - Respect `paths`. (#1858) node: - Fix typings of `paths`.
This commit is contained in:
parent
4a9b31df3e
commit
ff47e2539e
@ -11,7 +11,7 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.29.0"
|
||||
version = "0.29.1"
|
||||
|
||||
[lib]
|
||||
name = "swc"
|
||||
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_common"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.11.0"
|
||||
version = "0.11.1"
|
||||
|
||||
[features]
|
||||
concurrent = ["parking_lot"]
|
||||
|
@ -1074,8 +1074,8 @@ impl SourceMap {
|
||||
let mut src_id = 0u32;
|
||||
|
||||
if let Some(orig) = orig {
|
||||
for (idx, src) in orig.sources().enumerate() {
|
||||
builder.set_source(idx as _, src);
|
||||
for src in orig.sources() {
|
||||
let idx = builder.add_source(src);
|
||||
src_id = idx as u32 + 1;
|
||||
}
|
||||
for (idx, contents) in orig.source_contents().enumerate() {
|
||||
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_loader"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.11.0"
|
||||
version = "0.11.1"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
|
@ -126,7 +126,11 @@ where
|
||||
Some(v) => v,
|
||||
None => continue,
|
||||
};
|
||||
let capture = captures.iter().next().flatten().expect(
|
||||
|
||||
let mut iter = captures.iter();
|
||||
let _ = iter.next();
|
||||
|
||||
let capture = iter.next().flatten().expect(
|
||||
"capture group should be created by initializer of TsConfigResolver",
|
||||
);
|
||||
let mut errors = vec![];
|
||||
@ -140,10 +144,15 @@ where
|
||||
replaced, src
|
||||
)
|
||||
});
|
||||
|
||||
errors.push(match res {
|
||||
Ok(v) => return Ok(v),
|
||||
Err(err) => err,
|
||||
})
|
||||
});
|
||||
|
||||
if to.len() == 1 {
|
||||
return Ok(FileName::Custom(replaced));
|
||||
}
|
||||
}
|
||||
|
||||
bail!(
|
||||
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_transforms_module"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.26.0"
|
||||
version = "0.26.1"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
|
@ -1,6 +1,6 @@
|
||||
use anyhow::Error;
|
||||
use pathdiff::diff_paths;
|
||||
use std::{borrow::Cow, path::Component, sync::Arc};
|
||||
use std::{borrow::Cow, env::current_dir, path::Component, sync::Arc};
|
||||
use swc_atoms::JsWord;
|
||||
use swc_common::FileName;
|
||||
use swc_ecma_loader::resolve::Resolve;
|
||||
@ -22,8 +22,8 @@ impl ImportResolver for NoopImportResolver {
|
||||
|
||||
/// [ImportResolver] implementation for node.js
|
||||
///
|
||||
/// Supports [FileName::Real] for `base`, [FileName::Real] and
|
||||
/// [FileName::Custom] for `target`. ([FileName::Custom] is used for core
|
||||
/// Supports [FileName::Real] and [FileName::Anon] for `base`, [FileName::Real]
|
||||
/// and [FileName::Custom] for `target`. ([FileName::Custom] is used for core
|
||||
/// modules)
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct NodeImportResolver<R>
|
||||
@ -64,7 +64,8 @@ where
|
||||
}
|
||||
};
|
||||
let base = match base {
|
||||
FileName::Real(v) => v,
|
||||
FileName::Real(v) => Cow::Borrowed(v),
|
||||
FileName::Anon => Cow::Owned(current_dir().expect("failed to get current directory")),
|
||||
_ => {
|
||||
unreachable!(
|
||||
"Node path provider does not support using `{:?}` as a base file name",
|
||||
|
26
node-swc/__tests__/paths_test.mjs
Normal file
26
node-swc/__tests__/paths_test.mjs
Normal file
@ -0,0 +1,26 @@
|
||||
import swc from "../..";
|
||||
|
||||
it("should respect paths", async () => {
|
||||
const { code } = await swc.transform(`
|
||||
import foo from '@src/app';
|
||||
console.log(foo)
|
||||
`, {
|
||||
jsc: {
|
||||
parser: {
|
||||
syntax: 'typescript',
|
||||
},
|
||||
target: 'es2021',
|
||||
transform: {
|
||||
|
||||
},
|
||||
paths: {
|
||||
'@src/*': ['bar/*']
|
||||
}
|
||||
},
|
||||
module: {
|
||||
type: 'commonjs'
|
||||
},
|
||||
});
|
||||
|
||||
expect(code).toContain(`bar/app`);
|
||||
})
|
@ -281,6 +281,10 @@ export interface JscConfig {
|
||||
* Keep class names.
|
||||
*/
|
||||
keepClassNames?: boolean
|
||||
|
||||
paths?: {
|
||||
[from: string]: [string]
|
||||
}
|
||||
}
|
||||
|
||||
export type JscTarget =
|
||||
|
@ -5,6 +5,7 @@ use either::Either;
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::hash::BuildHasher;
|
||||
use std::rc::Rc as RustRc;
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
@ -908,6 +909,24 @@ impl Merge for JscConfig {
|
||||
self.target.merge(&from.target);
|
||||
self.external_helpers.merge(&from.external_helpers);
|
||||
self.keep_class_names.merge(&from.keep_class_names);
|
||||
self.paths.merge(&from.paths);
|
||||
}
|
||||
}
|
||||
|
||||
impl<K, V, S> Merge for HashMap<K, V, S>
|
||||
where
|
||||
K: Clone + Eq + std::hash::Hash,
|
||||
V: Clone,
|
||||
S: Clone + BuildHasher,
|
||||
{
|
||||
fn merge(&mut self, from: &Self) {
|
||||
if self.is_empty() {
|
||||
*self = (*from).clone();
|
||||
} else {
|
||||
for (k, v) in from {
|
||||
self.entry(k.clone()).or_insert(v.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user