Skip to content

Commit

Permalink
feat(next-swc): Update crates (#35133)
Browse files Browse the repository at this point in the history
This PR updates crates related to ecmascript to swc-project/swc@d62ef64

I'll update css crates separately.


This PR also reduces the size of binary.
  • Loading branch information
kdy1 committed Mar 11, 2022
1 parent f14f628 commit e57d621
Show file tree
Hide file tree
Showing 15 changed files with 199 additions and 148 deletions.
259 changes: 149 additions & 110 deletions packages/next-swc/Cargo.lock

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions packages/next-swc/crates/core/Cargo.toml
Expand Up @@ -15,19 +15,19 @@ fxhash = "0.2.1"
pathdiff = "0.2.0"
serde = "1"
serde_json = "1"
styled_components = "0.17.0"
swc = "0.138.0"
styled_components = "0.18.0"
swc = "0.146.0"
swc_atoms = "0.2.7"
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.123.0", features = ["codegen", "minifier", "optimization", "parser", "react", "transforms", "typescript", "utils", "visit"] }
swc_common = { version = "0.17.11", features = ["concurrent", "sourcemap"] }
swc_css = "0.98.0"
swc_ecma_loader = { version = "0.29.0", features = ["node", "lru"] }
swc_ecmascript = { version = "0.130.0", features = ["codegen", "minifier", "optimization", "parser", "react", "transforms", "typescript", "utils", "visit"] }
swc_node_base = "0.5.1"
swc_stylis = "0.90.0"
swc_stylis = "0.94.3"
tracing = {version = "0.1.28", features = ["release_max_level_off"]}
regex = "1.5"

[dev-dependencies]
swc_ecma_transforms_testing = "0.65.0"
swc_ecma_transforms_testing = "0.68.0"
testing = "0.18.1"
walkdir = "2.3.2"
11 changes: 4 additions & 7 deletions packages/next-swc/crates/core/src/lib.rs
Expand Up @@ -39,11 +39,9 @@ use swc::config::ModuleConfig;
use swc_common::{self, chain, pass::Optional};
use swc_common::{SourceFile, SourceMap};
use swc_ecmascript::ast::EsVersion;
use swc_ecmascript::parser::parse_file_as_module;
use swc_ecmascript::transforms::pass::noop;
use swc_ecmascript::{
parser::{lexer::Lexer, Parser, StringInput},
visit::Fold,
};
use swc_ecmascript::visit::Fold;

pub mod amp_attributes;
mod auto_cjs;
Expand Down Expand Up @@ -178,9 +176,8 @@ impl TransformOptions {
self.swc.config.module.is_none() && fm.src.contains("module.exports") && {
let syntax = self.swc.config.jsc.syntax.unwrap_or_default();
let target = self.swc.config.jsc.target.unwrap_or_else(EsVersion::latest);
let lexer = Lexer::new(syntax, target, StringInput::from(&*fm), None);
let mut p = Parser::new_from(lexer);
p.parse_module()

parse_file_as_module(fm, syntax, target, None, &mut vec![])
.map(|m| contains_cjs(&m))
.unwrap_or_default()
};
Expand Down
@@ -1,6 +1,7 @@
import _JSXStyle from "styled-jsx/style";
import styles from "./styles";
const styles2 = require("./styles2");
// external only
export const Test1 = ()=><div className={`jsx-${styles2.__hash} jsx-${styles.__hash}`}>

<p className={`jsx-${styles2.__hash} jsx-${styles.__hash}`}>external only</p>
Expand All @@ -11,6 +12,7 @@ export const Test1 = ()=><div className={`jsx-${styles2.__hash} jsx-${styles.__h

</div>
;
// external and static
export const Test2 = ()=><div className={"jsx-81a68341e430a972 " + `jsx-${styles.__hash}`}>

<p className={"jsx-81a68341e430a972 " + `jsx-${styles.__hash}`}>external and static</p>
Expand All @@ -21,6 +23,7 @@ export const Test2 = ()=><div className={"jsx-81a68341e430a972 " + `jsx-${styles

</div>
;
// external and dynamic
export const Test3 = ({ color })=><div className={`jsx-${styles.__hash}` + " " + _JSXStyle.dynamic([
[
"332b21af86b0ec6",
Expand All @@ -47,6 +50,7 @@ export const Test3 = ({ color })=><div className={`jsx-${styles.__hash}` + " "

</div>
;
// external, static and dynamic
export const Test4 = ({ color })=><div className={`jsx-${styles.__hash}` + " jsx-ceba8c9ce34e3d0c " + _JSXStyle.dynamic([
[
"ec8f36d08fa7aa2c",
Expand Down Expand Up @@ -75,6 +79,7 @@ export const Test4 = ({ color })=><div className={`jsx-${styles.__hash}` + " js

</div>
;
// static only
export const Test5 = ()=><div className={"jsx-df0159ebd3f9fb6f"}>

<p className={"jsx-df0159ebd3f9fb6f"}>static only</p>
Expand All @@ -85,6 +90,7 @@ export const Test5 = ()=><div className={"jsx-df0159ebd3f9fb6f"}>

</div>
;
// static and dynamic
export const Test6 = ({ color })=><div className={"jsx-ceba8c9ce34e3d0c " + _JSXStyle.dynamic([
[
"ec8f36d08fa7aa2c",
Expand All @@ -111,6 +117,7 @@ export const Test6 = ({ color })=><div className={"jsx-ceba8c9ce34e3d0c " + _JS

</div>
;
// dynamic only
export const Test7 = ({ color })=><div className={_JSXStyle.dynamic([
[
"332b21af86b0ec6",
Expand All @@ -135,6 +142,7 @@ export const Test7 = ({ color })=><div className={_JSXStyle.dynamic([

</div>
;
// dynamic with scoped compound variable
export const Test8 = ({ color })=>{
if (color) {
const innerProps = {
Expand Down Expand Up @@ -165,6 +173,7 @@ export const Test8 = ({ color })=>{
</div>;
}
};
// dynamic with compound variable
export const Test9 = ({ color })=>{
const innerProps = {
color
Expand Down Expand Up @@ -194,6 +203,7 @@ export const Test9 = ({ color })=>{
</div>;
};
const foo = "red";
// dynamic with constant variable
export const Test10 = ()=><div className={"jsx-64eb0b4e09da0dd3"}>

<p className={"jsx-64eb0b4e09da0dd3"}>dynamic with constant variable</p>
Expand All @@ -202,6 +212,7 @@ export const Test10 = ()=><div className={"jsx-64eb0b4e09da0dd3"}>

</div>
;
// dynamic with complex scope
export const Test11 = ({ color })=>{
const items = Array.from({
length: 5
Expand Down
@@ -1,5 +1,5 @@
import _JSXStyle from "styled-jsx/style";
function NavigationItem({ active , className }) {
function NavigationItem({ active , className , }) {
return <span className={"jsx-2342aae4628612c6" + " " + (cn({
active
}, className, "navigation-item") || "")}>
Expand Down
Expand Up @@ -75,9 +75,9 @@ export default (({ display })=><div className={"jsx-1ada4ad4dab7822f " + _JSXSt

<_JSXStyle id={"4e4be2da62837c76"}>{`@media(min-width:${mediumScreen}){p.jsx-1ada4ad4dab7822f{color:green}p.jsx-1ada4ad4dab7822f{color:${`red`}}}p.jsx-1ada4ad4dab7822f{color:red}`}</_JSXStyle>

<_JSXStyle id={"27040f0829fb73d4"}>{`p.jsx-1ada4ad4dab7822f{-webkit-animation-duration:${animationDuration};animation-duration:${animationDuration}}`}</_JSXStyle>
<_JSXStyle id={"27040f0829fb73d4"}>{`p.jsx-1ada4ad4dab7822f{-webkit-animation-duration:${animationDuration};-moz-animation-duration:${animationDuration};-o-animation-duration:${animationDuration};animation-duration:${animationDuration}}`}</_JSXStyle>

<_JSXStyle id={"3e72d735e703a530"}>{`p.jsx-1ada4ad4dab7822f{-webkit-animation:${animationDuration} forwards ${animationName};animation:${animationDuration} forwards ${animationName}}div.jsx-1ada4ad4dab7822f{background:${color}}`}</_JSXStyle>
<_JSXStyle id={"3e72d735e703a530"}>{`p.jsx-1ada4ad4dab7822f{-webkit-animation:${animationDuration} forwards ${animationName};-moz-animation:${animationDuration} forwards ${animationName};-o-animation:${animationDuration} forwards ${animationName};animation:${animationDuration} forwards ${animationName}}div.jsx-1ada4ad4dab7822f{background:${color}}`}</_JSXStyle>



Expand Down
@@ -1,7 +1,7 @@
import _JSXStyle from "styled-jsx/style";
const Test = ()=><div className={"jsx-d47d6adadf14e957"}>

<_JSXStyle id={"d47d6adadf14e957"}>{"body{color:red}:hover{color:red;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-animation:foo 1s ease-out;animation:foo 1s ease-out}div a{display:none}[data-test]>div{color:red}"}</_JSXStyle>
<_JSXStyle id={"d47d6adadf14e957"}>{"body{color:red}:hover{color:red;display:-webkit-box;display:-webkit-flex;display:-moz-box;display:-ms-flexbox;display:flex;-webkit-animation:foo 1s ease-out;-moz-animation:foo 1s ease-out;-o-animation:foo 1s ease-out;animation:foo 1s ease-out}div a{display:none}[data-test]>div{color:red}"}</_JSXStyle>

</div>
;
Expand Down
@@ -1,5 +1,5 @@
import _JSXStyle from "styled-jsx/style";
export const Red = ({ Component ="button" })=>{
export const Red = ({ Component ="button" , })=>{
return <Component className={_JSXStyle.dynamic([
[
"ca900d186ad0e495",
Expand Down

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

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

Expand Up @@ -2,7 +2,7 @@ import _JSXStyle from "styled-jsx/style";
export default function Foo() {
return(/*#__PURE__*/ React.createElement("div", {
render: function(v) {
/*#__PURE__*/ return(React.createElement("form", {
return(/*#__PURE__*/ React.createElement("form", {
className: "jsx-eb368961fd3b0a99"
}));
},
Expand Down
10 changes: 5 additions & 5 deletions packages/next-swc/crates/napi/Cargo.toml
Expand Up @@ -16,12 +16,12 @@ once_cell = "1.8.0"
serde = "1"
serde_json = "1"
next-swc = { version = "0.0.0", path = "../core" }
swc = "0.138.0"
swc = "0.146.0"
swc_atoms = "0.2.7"
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.123.0", features = ["codegen", "minifier", "optimization", "parser", "react", "transforms", "typescript", "utils", "visit"] }
swc_bundler = { version = "0.120.0", features = ["concurrent"] }
swc_common = { version = "0.17.11", features = ["concurrent", "sourcemap"] }
swc_ecma_loader = { version = "0.29.0", features = ["node", "lru"] }
swc_ecmascript = { version = "0.130.0", features = ["codegen", "minifier", "optimization", "parser", "react", "transforms", "typescript", "utils", "visit"] }
swc_node_base = "0.5.1"

[build-dependencies]
Expand Down
8 changes: 3 additions & 5 deletions packages/next-swc/crates/napi/src/bundle/mod.rs
Expand Up @@ -7,10 +7,7 @@ use napi::{CallContext, JsObject, Task};
use once_cell::sync::Lazy;
use serde::Deserialize;
use std::{collections::HashMap, path::PathBuf, sync::Arc};
use swc::{
config::{util::BoolOrObject, SourceMapsConfig},
try_with_handler, TransformOutput,
};
use swc::{config::SourceMapsConfig, try_with_handler, TransformOutput};
use swc_atoms::JsWord;
use swc_bundler::{Bundler, ModuleData, ModuleRecord};
use swc_common::{collections::AHashMap, errors::Handler, BytePos, FileName, SourceMap, Span};
Expand Down Expand Up @@ -62,6 +59,7 @@ impl Task for BundleTask {
.map(JsWord::from)
.collect::<Vec<_>>();

let comments = self.c.comments().clone();
//
let mut bundler = Bundler::new(
self.c.globals(),
Expand Down Expand Up @@ -114,7 +112,7 @@ impl Task for BundleTask {
&source_map_names,
None,
false,
Some(BoolOrObject::Bool(true)),
Some(&comments),
)?;

Ok(code)
Expand Down

0 comments on commit e57d621

Please sign in to comment.