Skip to content

Commit

Permalink
fix(es/transforms/module): Fix paths bug. (#2043)
Browse files Browse the repository at this point in the history
swc_ecma_preset_env:
 - Update compat data.

swc_ecma_transforms_module:
 - Fix `paths`. (#1934, #1935)
  • Loading branch information
kdy1 authored Aug 9, 2021
1 parent 8cbbddb commit 2c52021
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 31 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2018"
license = "Apache-2.0/MIT"
name = "swc"
repository = "https://github.com/swc-project/swc.git"
version = "0.36.0"
version = "0.37.0"

[lib]
name = "swc"
Expand Down Expand Up @@ -37,7 +37,7 @@ swc_ecma_ext_transforms = {version = "0.24.0", path = "./ecmascript/ext-transfor
swc_ecma_loader = {version = "0.12.0", path = "./ecmascript/loader", features = ["lru", "node", "tsc"]}
swc_ecma_minifier = {version = "0.18.0", path = "./ecmascript/minifier"}
swc_ecma_parser = {version = "0.66.0", path = "./ecmascript/parser"}
swc_ecma_preset_env = {version = "0.33.0", path = "./ecmascript/preset-env"}
swc_ecma_preset_env = {version = "0.34.0", path = "./ecmascript/preset-env"}
swc_ecma_transforms = {version = "0.63.0", path = "./ecmascript/transforms", features = [
"compat",
"module",
Expand All @@ -49,7 +49,7 @@ swc_ecma_transforms = {version = "0.63.0", path = "./ecmascript/transforms", fea
swc_ecma_transforms_base = {version = "0.26.0", path = "./ecmascript/transforms/base"}
swc_ecma_utils = {version = "0.41.0", path = "./ecmascript/utils"}
swc_ecma_visit = {version = "0.35.0", path = "./ecmascript/visit"}
swc_ecmascript = {version = "0.52.0", path = "./ecmascript"}
swc_ecmascript = {version = "0.53.0", path = "./ecmascript"}
swc_node_base = {version = "0.2.0", path = "./node/base"}
swc_visit = {version = "0.2.3", path = "./visit"}

Expand Down
4 changes: 2 additions & 2 deletions ecmascript/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"
license = "Apache-2.0/MIT"
name = "swc_ecmascript"
repository = "https://github.com/swc-project/swc.git"
version = "0.52.1"
version = "0.53.0"

[package.metadata.docs.rs]
all-features = true
Expand Down Expand Up @@ -37,7 +37,7 @@ swc_ecma_codegen = {version = "0.66.0", path = "./codegen", optional = true}
swc_ecma_dep_graph = {version = "0.34.0", path = "./dep-graph", optional = true}
swc_ecma_minifier = {version = "0.18.0", path = "./minifier", optional = true}
swc_ecma_parser = {version = "0.66.0", path = "./parser", optional = true, default-features = false}
swc_ecma_preset_env = {version = "0.33.0", path = "./preset-env", optional = true}
swc_ecma_preset_env = {version = "0.34.0", path = "./preset-env", optional = true}
swc_ecma_transforms = {version = "0.63.0", path = "./transforms", optional = true}
swc_ecma_utils = {version = "0.41.0", path = "./utils", optional = true}
swc_ecma_visit = {version = "0.35.0", path = "./visit", optional = true}
Expand Down
2 changes: 1 addition & 1 deletion ecmascript/preset-env/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ documentation = "https://rustdoc.swc.rs/swc_ecma_preset_env/"
edition = "2018"
license = "Apache-2.0/MIT"
name = "swc_ecma_preset_env"
version = "0.33.0"
version = "0.34.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
13 changes: 9 additions & 4 deletions ecmascript/preset-env/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,18 @@ where

// Proposals

// ES2020

let pass = add!(pass, ExportNamespaceFrom, es2020::export_namespace_from());
let pass = add!(pass, NullishCoalescing, es2020::nullish_coalescing());
// ES2021
let pass = add!(
pass,
LogicalAssignmentOperators,
es2021::logical_assignments()
);

// ES2020

let pass = add!(pass, ExportNamespaceFrom, es2020::export_namespace_from());
let pass = add!(pass, NullishCoalescing, es2020::nullish_coalescing());

let pass = add!(pass, OptionalChaining, es2020::optional_chaining());
let pass = add!(pass, ClassProperties, es2020::class_properties());

Expand Down Expand Up @@ -224,6 +227,8 @@ pub struct BrowserData<T: Default> {
pub phantom: T,
#[serde(default)]
pub opera_mobile: T,
#[serde(default)]
pub rhino: T,
}

#[derive(Debug)]
Expand Down
32 changes: 20 additions & 12 deletions ecmascript/preset-env/src/transform_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"chrome": "74",
"opera": "62",
"edge": "79",
"firefox": "90",
"safari": "14.1",
"node": "12",
"samsung": "11",
Expand All @@ -12,6 +13,8 @@
"chrome": "84",
"opera": "70",
"edge": "84",
"firefox": "90",
"safari": "15",
"node": "14.6",
"electron": "10.0"
},
Expand All @@ -26,6 +29,16 @@
"samsung": "11",
"electron": "6.0"
},
"proposal-logical-assignment-operators": {
"chrome": "85",
"opera": "71",
"edge": "85",
"firefox": "79",
"safari": "14",
"node": "15",
"ios": "14",
"electron": "10.0"
},
"proposal-nullish-coalescing-operator": {
"chrome": "80",
"opera": "67",
Expand All @@ -37,16 +50,6 @@
"samsung": "13",
"electron": "8.0"
},
"proposal-logical-assignment-operators": {
"chrome": "85",
"opera": "71",
"edge": "85",
"firefox": "79",
"safari": "14",
"node": "15",
"ios": "14",
"electron": "10.0"
},
"proposal-optional-chaining": {
"firefox": "74",
"safari": "13.1",
Expand Down Expand Up @@ -199,11 +202,12 @@
"chrome": "47",
"opera": "34",
"edge": "13",
"firefox": "45",
"firefox": "43",
"safari": "10",
"node": "6",
"ios": "10",
"samsung": "5",
"rhino": "1.7.13",
"electron": "0.36"
},
"transform-block-scoped-functions": {
Expand Down Expand Up @@ -359,13 +363,14 @@
"node": "0.12",
"ios": "9",
"samsung": "3",
"rhino": "1.7.13",
"electron": "0.20"
},
"transform-new-target": {
"chrome": "46",
"opera": "33",
"edge": "14",
"firefox": "41",
"firefox": "45",
"safari": "10",
"node": "5",
"ios": "10",
Expand Down Expand Up @@ -395,6 +400,7 @@
"ios": "6",
"phantom": "2",
"samsung": "1",
"rhino": "1.7.13",
"electron": "0.20"
},
"transform-property-literals": {
Expand All @@ -409,6 +415,7 @@
"ios": "6",
"phantom": "2",
"samsung": "1",
"rhino": "1.7.13",
"electron": "0.20"
},
"transform-reserved-words": {
Expand All @@ -423,6 +430,7 @@
"ios": "6",
"phantom": "2",
"samsung": "1",
"rhino": "1.7.13",
"electron": "0.20"
},
"proposal-export-namespace-from": {
Expand Down
19 changes: 15 additions & 4 deletions ecmascript/transforms/module/src/path.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use anyhow::Error;
use pathdiff::diff_paths;
use std::{borrow::Cow, env::current_dir, path::Component, sync::Arc};
use std::{
borrow::Cow,
env::current_dir,
path::{Component, PathBuf},
sync::Arc,
};
use swc_atoms::JsWord;
use swc_common::FileName;
use swc_ecma_loader::resolve::Resolve;
Expand Down Expand Up @@ -47,6 +52,12 @@ where
R: Resolve,
{
fn resolve_import(&self, base: &FileName, module_specifier: &str) -> Result<JsWord, Error> {
fn strip_ext(s: &str) -> JsWord {
let mut p = PathBuf::from(s);
p.set_extension("");
p.display().to_string().into()
}

let target = self.resolver.resolve(base, module_specifier);
let target = match target {
Ok(v) => v,
Expand All @@ -55,7 +66,7 @@ where

let target = match target {
FileName::Real(v) => v,
FileName::Custom(s) => return Ok(s.into()),
FileName::Custom(s) => return Ok(strip_ext(&s)),
_ => {
unreachable!(
"Node path provider does not support using `{:?}` as a target file name",
Expand Down Expand Up @@ -121,9 +132,9 @@ where
Cow::Owned(format!("./{}", s))
};
if cfg!(target_os = "windows") {
Ok(s.replace('\\', "/").into())
Ok(strip_ext(&s.replace('\\', "/")))
} else {
Ok(s.into())
Ok(strip_ext(&s))
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions tests/fixture/.issue-1922/case1/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"env": {
"targets": {
"node": "16"
},
"mode": "entry",
"coreJs": 3
}
}
1 change: 1 addition & 0 deletions tests/fixture/.issue-1922/case1/input/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
globalThis?.hello?.world?.("sup?");
8 changes: 8 additions & 0 deletions tests/fixture/issue-2037/case1/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"jsc": {
"parser": {
"syntax": "ecmascript",
"jsx": true
}
}
}
3 changes: 3 additions & 0 deletions tests/fixture/issue-2037/case1/input/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const A = () => {
return <div>{...[]}</div>;
};
3 changes: 3 additions & 0 deletions tests/fixture/issue-2037/case1/output/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var A = function() {
return(/*#__PURE__*/ React.createElement("div", null));
};
4 changes: 2 additions & 2 deletions tests/fixture/paths/cjs-001/output/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"use strict";
require("./src/dep.ts");
require("./src2/dep-2.ts");
require("./src/dep");
require("./src2/dep-2");

0 comments on commit 2c52021

Please sign in to comment.