Unverified Commit 6814852f authored by Donny/강동윤's avatar Donny/강동윤 Committed by GitHub

feat(next-swc): Update swc (#34878)

* Update swc

* lockfile

* Update more swc crates

* Update minifier

* chore: update types

* style: fix

* Update deps
Co-authored-by: 's avatarevilebottnawi <sheo13666q@gmail.com>
parent 721dc7bc
This diff is collapsed.
......@@ -15,19 +15,19 @@ fxhash = "0.2.1"
pathdiff = "0.2.0"
serde = "1"
serde_json = "1"
styled_components = "0.14.0"
swc = "0.126.2"
styled_components = "0.17.0"
swc = "0.138.0"
swc_atoms = "0.2.7"
swc_common = { version = "0.17.0", features = ["concurrent", "sourcemap"] }
swc_css = "0.87.0"
swc_common = { version = "0.17.9", features = ["concurrent", "sourcemap"] }
swc_css = "0.94.0"
swc_ecma_loader = { version = "0.28.0", features = ["node", "lru"] }
swc_ecmascript = { version = "0.114.2", features = ["codegen", "minifier", "optimization", "parser", "react", "transforms", "typescript", "utils", "visit"] }
swc_ecmascript = { version = "0.123.0", features = ["codegen", "minifier", "optimization", "parser", "react", "transforms", "typescript", "utils", "visit"] }
swc_node_base = "0.5.1"
swc_stylis = "0.83.0"
swc_stylis = "0.90.0"
tracing = {version = "0.1.28", features = ["release_max_level_off"]}
regex = "1.5"
[dev-dependencies]
swc_ecma_transforms_testing = "0.60.0"
testing = "0.18.0"
swc_ecma_transforms_testing = "0.65.0"
testing = "0.18.1"
walkdir = "2.3.2"
......@@ -2,8 +2,8 @@ use easy_error::{bail, Error};
use std::panic;
use std::sync::Arc;
use swc_common::util::take::Take;
use swc_common::SourceMap;
use swc_common::{source_map::Pos, BytePos, Span, SyntaxContext, DUMMY_SP};
use swc_common::{SourceMap, Spanned};
use swc_css::ast::*;
use swc_css::codegen::{
writer::basic::{BasicCssWriter, BasicCssWriterConfig},
......@@ -183,16 +183,12 @@ impl VisitMut for Namespacer {
combinator = None;
}
ComplexSelectorChildren::Combinator(v) => match v.value {
CombinatorValue::Descendant => {}
_ => {
combinator = Some(v.clone());
new_selectors.push(sel);
}
},
ComplexSelectorChildren::Combinator(v) => {
combinator = Some(v.clone());
}
};
}
node.children = new_selectors;
}
}
......@@ -204,8 +200,6 @@ impl Namespacer {
mut node: CompoundSelector,
) -> Result<Vec<ComplexSelectorChildren>, Error> {
let mut pseudo_index = None;
let empty_tokens = vec![];
let mut arg_tokens;
for (i, selector) in node.subclass_selectors.iter().enumerate() {
......@@ -215,8 +209,22 @@ impl Namespacer {
.iter()
.flatten()
.flat_map(|v| match v {
PseudoSelectorChildren::Nth(v) => nth_to_tokens(v).tokens,
PseudoSelectorChildren::PreservedToken(v) => vec![v.clone()],
PseudoClassSelectorChildren::PreservedToken(v) => vec![v.clone()],
PseudoClassSelectorChildren::AnPlusB(an_plus_b) => match an_plus_b {
AnPlusB::Ident(v) => to_tokens(v).tokens,
AnPlusB::AnPlusBNotation(v) => to_tokens(v).tokens,
},
PseudoClassSelectorChildren::Ident(v) => to_tokens(v).tokens,
PseudoClassSelectorChildren::Str(v) => to_tokens(v).tokens,
PseudoClassSelectorChildren::Delimiter(v) => to_tokens(v).tokens,
PseudoClassSelectorChildren::SelectorList(v) => to_tokens(v).tokens,
PseudoClassSelectorChildren::CompoundSelectorList(v) => {
to_tokens(v).tokens
}
PseudoClassSelectorChildren::RelativeSelectorList(v) => {
to_tokens(v).tokens
}
PseudoClassSelectorChildren::CompoundSelector(v) => to_tokens(v).tokens,
})
.collect::<Vec<_>>();
......@@ -224,10 +232,21 @@ impl Namespacer {
}
SubclassSelector::PseudoElement(PseudoElementSelector {
name, children, ..
}) => match children {
Some(children) => (name, children),
None => (name, &empty_tokens),
},
}) => {
arg_tokens = children
.iter()
.flatten()
.flat_map(|v| match v {
PseudoElementSelectorChildren::PreservedToken(v) => vec![v.clone()],
PseudoElementSelectorChildren::Ident(v) => to_tokens(v).tokens,
PseudoElementSelectorChildren::CompoundSelector(v) => {
to_tokens(v).tokens
}
})
.collect::<Vec<_>>();
(name, &arg_tokens)
}
_ => continue,
};
......@@ -282,12 +301,16 @@ impl Namespacer {
trace!("Combinator: {:?}", combinator);
trace!("v[0]: {:?}", v[0]);
let mut result = vec![];
if let Some(combinator) = combinator {
match v.get(0) {
Some(ComplexSelectorChildren::Combinator(..)) => {}
Some(..) => {}
// `Descendant` combinator can't be the first because we removed it
// above
Some(ComplexSelectorChildren::Combinator(..))
if combinator.value == CombinatorValue::Descendant => {}
_ => {
v.push(ComplexSelectorChildren::Combinator(combinator));
result.push(ComplexSelectorChildren::Combinator(combinator));
}
}
}
......@@ -301,7 +324,9 @@ impl Namespacer {
}
});
Ok(v)
result.extend(v);
Ok(result)
}
Err(_) => bail!("Failed to transform one off global selector"),
};
......@@ -332,7 +357,15 @@ impl Namespacer {
);
}
Ok(vec![ComplexSelectorChildren::CompoundSelector(node)])
let mut result = vec![];
if let Some(combinator) = combinator {
result.push(ComplexSelectorChildren::Combinator(combinator));
}
result.push(ComplexSelectorChildren::CompoundSelector(node));
Ok(result)
}
}
......@@ -461,17 +494,21 @@ fn get_block_tokens(selector_tokens: &Tokens) -> Vec<TokenAndSpan> {
]
}
fn nth_to_tokens(nth: &Nth) -> Tokens {
fn to_tokens<N: Spanned>(node: &N) -> Tokens
where
for<'aa> CodeGenerator<&'aa mut BasicCssWriter<'aa, &'aa mut std::string::String>>: Emit<N>,
{
let mut s = String::new();
{
let mut wr = BasicCssWriter::new(&mut s, BasicCssWriterConfig { indent: " " });
let mut gen = CodeGenerator::new(&mut wr, CodegenConfig { minify: true });
gen.emit(&nth).unwrap();
gen.emit(node).unwrap();
}
let span = node.span();
let mut lexer = swc_css::parser::lexer::Lexer::new(
StringInput::new(&s, nth.span.lo, nth.span.hi),
StringInput::new(&s, span.lo, span.hi),
ParserConfig {
allow_wrong_line_comments: true,
},
......@@ -484,7 +521,7 @@ fn nth_to_tokens(nth: &Nth) -> Tokens {
}
Tokens {
span: Span::new(nth.span.lo, nth.span.hi, Default::default()),
span: Span::new(span.lo, span.hi, Default::default()),
tokens,
}
}
function a(a, b) {
(null == b || b > a.length) && (b = a.length);
for(var c = 0, d = new Array(b); c < b; c++)d[c] = a[c];
function b(c, a) {
(null == a || a > c.length) && (a = c.length);
for(var b = 0, d = new Array(a); b < a; b++)d[b] = c[b];
return d;
}
import b from "other";
(function(a, c) {
return (function(a) {
if (Array.isArray(a)) return a;
})(a) || (function(a, c) {
var d, e, f = null == a ? null : "undefined" != typeof Symbol && a[Symbol.iterator] || a["@@iterator"];
if (null != f) {
var g = [], h = !0, i = !1;
import a from "other";
(function(c, b) {
return (function(c) {
if (Array.isArray(c)) return c;
})(c) || (function(c, b) {
var g, h, a = null == c ? null : "undefined" != typeof Symbol && c[Symbol.iterator] || c["@@iterator"];
if (null != a) {
var d = [], e = !0, i = !1;
try {
for(f = f.call(a); !(h = (d = f.next()).done) && (g.push(d.value), !c || g.length !== c); h = !0);
for(a = a.call(c); !(e = (g = a.next()).done) && (d.push(g.value), !b || d.length !== b); e = !0);
} catch (j) {
i = !0, e = j;
i = !0, h = j;
} finally{
try {
h || null == f.return || f.return();
e || null == a.return || a.return();
} finally{
if (i) throw e;
if (i) throw h;
}
}
return g;
return d;
}
})(a, c) || (function(b, c) {
if (b) {
if ("string" == typeof b) return a(b, c);
var d = Object.prototype.toString.call(b).slice(8, -1);
if ("Object" === d && b.constructor && (d = b.constructor.name), "Map" === d || "Set" === d) return Array.from(d);
if ("Arguments" === d || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(d)) return a(b, c);
})(c, b) || (function(a, d) {
if (a) {
if ("string" == typeof a) return b(a, d);
var c = Object.prototype.toString.call(a).slice(8, -1);
if ("Object" === c && a.constructor && (c = a.constructor.name), "Map" === c || "Set" === c) return Array.from(c);
if ("Arguments" === c || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)) return b(a, d);
}
})(a, c) || (function() {
})(c, b) || (function() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
})();
})(b, 1)[0];
})(a, 1)[0];
var c = function() {
"use strict";
!function(a, b) {
......
......@@ -16,12 +16,12 @@ once_cell = "1.8.0"
serde = "1"
serde_json = "1"
next-swc = { version = "0.0.0", path = "../core" }
swc = "0.126.2"
swc = "0.138.0"
swc_atoms = "0.2.7"
swc_bundler = { version = "0.107.0", features = ["concurrent"] }
swc_common = { version = "0.17.0", features = ["concurrent", "sourcemap"] }
swc_bundler = { version = "0.114.0", features = ["concurrent"] }
swc_common = { version = "0.17.9", features = ["concurrent", "sourcemap"] }
swc_ecma_loader = { version = "0.28.0", features = ["node", "lru"] }
swc_ecmascript = { version = "0.114.2", features = ["codegen", "minifier", "optimization", "parser", "react", "transforms", "typescript", "utils", "visit"] }
swc_ecmascript = { version = "0.123.0", features = ["codegen", "minifier", "optimization", "parser", "react", "transforms", "typescript", "utils", "visit"] }
swc_node_base = "0.5.1"
[build-dependencies]
......
......@@ -16,9 +16,9 @@ path-clean = "0.1"
serde = {version = "1", features = ["derive"]}
serde_json = "1"
next-swc = { version = "0.0.0", path = "../core" }
swc = "0.126.2"
swc_common = { version = "0.17.0", features = ["concurrent", "sourcemap"] }
swc_ecmascript = { version = "0.114.2", features = ["codegen", "minifier", "optimization", "parser", "react", "transforms", "typescript", "utils", "visit"] }
swc = "0.138.0"
swc_common = { version = "0.17.9", features = ["concurrent", "sourcemap"] }
swc_ecmascript = { version = "0.123.0", features = ["codegen", "minifier", "optimization", "parser", "react", "transforms", "typescript", "utils", "visit"] }
tracing = {version = "0.1.28", features = ["release_max_level_off"]}
wasm-bindgen = {version = "0.2", features = ["serde-serialize"]}
wasm-bindgen-futures = "0.4.8"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment