Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(next-swc): Update swc crates #35395

Merged
merged 25 commits into from Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
440 changes: 231 additions & 209 deletions packages/next-swc/Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions packages/next-swc/Cargo.toml
Expand Up @@ -6,5 +6,8 @@ members = [
"crates/wasm"
]

[profile.dev.package.swc_css_prefixer]
opt-level = 2

[profile.release]
lto = true
20 changes: 10 additions & 10 deletions packages/next-swc/crates/core/Cargo.toml
Expand Up @@ -19,20 +19,20 @@ radix_fmt = "1"
regex = "1.5"
serde = "1"
serde_json = "1"
styled_components = "0.19.0"
swc = "0.150.1"
swc_atoms = "0.2.9"
swc_common = {version = "0.17.15", features = ["concurrent", "sourcemap"]}
swc_css = "0.100.0"
swc_ecma_loader = {version = "0.29.0", features = ["node", "lru"]}
swc_ecmascript = {version = "0.132.0", features = ["codegen", "minifier", "optimization", "parser", "react", "transforms", "typescript", "utils", "visit"]}
styled_components = "0.23.0"
swc = "0.161.1"
swc_atoms = "0.2.11"
swc_common = { version = "0.17.18", features = ["concurrent", "sourcemap"] }
swc_css = "0.103.0"
swc_ecma_loader = { version = "0.29.0", features = ["node", "lru"] }
swc_ecmascript = { version = "0.140.0", features = ["codegen", "minifier", "optimization", "parser", "react", "transforms", "typescript", "utils", "visit"] }
swc_node_base = "0.5.1"
swc_stylis = "0.96.1"
swc_cached = "0.1.1"
swc_css_prefixer = "0.99.3"
tracing = {version = "0.1.28", features = ["release_max_level_off"]}
handlebars = "4.2.1"

[dev-dependencies]
swc_ecma_transforms_testing = "0.69.0"
testing = "0.18.1"
swc_ecma_transforms_testing = "0.75.0"
testing = "0.19.1"
walkdir = "2.3.2"
3 changes: 1 addition & 2 deletions packages/next-swc/crates/core/src/emotion/mod.rs
Expand Up @@ -307,8 +307,7 @@ impl<C: Comments> EmotionTransformer<C> {
if index % 2 == 0 {
if let Some(q) = tagged_tpl.quasis.get_mut(i) {
let q = q.take();
let minified =
minify_css_string(&q.raw.value, index == 0, index == args_len - 1);
let minified = minify_css_string(&q.raw, index == 0, index == args_len - 1);
// Compress one more spaces into one space
if minified.replace(' ', "").is_empty() {
if index != 0 && index != args_len - 1 {
Expand Down
13 changes: 4 additions & 9 deletions packages/next-swc/crates/core/src/next_dynamic.rs
Expand Up @@ -6,7 +6,7 @@ use swc_common::{FileName, DUMMY_SP};
use swc_ecmascript::ast::{
ArrayLit, ArrowExpr, BinExpr, BinaryOp, BlockStmtOrExpr, Bool, CallExpr, Callee, Expr,
ExprOrSpread, Ident, ImportDecl, ImportSpecifier, KeyValueProp, Lit, MemberExpr, MemberProp,
Null, ObjectLit, Prop, PropName, PropOrSpread, Str, StrKind,
Null, ObjectLit, Prop, PropName, PropOrSpread, Str,
};
use swc_ecmascript::utils::ExprFactory;
use swc_ecmascript::utils::{
Expand Down Expand Up @@ -148,8 +148,7 @@ impl Fold for NextDynamicPatcher {
)
.into(),
span: DUMMY_SP,
kind: StrKind::Synthesized {},
has_escape: false,
raw: None,
}))),
right: Box::new(Expr::Lit(Lit::Str(Str {
value: self
Expand All @@ -159,10 +158,7 @@ impl Fold for NextDynamicPatcher {
.clone()
.into(),
span: DUMMY_SP,
kind: StrKind::Normal {
contains_quote: false,
},
has_escape: false,
raw: None,
}))),
})),
spread: None,
Expand Down Expand Up @@ -202,8 +198,7 @@ impl Fold for NextDynamicPatcher {
.clone()
.into(),
span: DUMMY_SP,
kind: StrKind::Synthesized {},
has_escape: false,
raw: None,
}))),
spread: None,
}],
Expand Down
3 changes: 1 addition & 2 deletions packages/next-swc/crates/core/src/page_config.rs
Expand Up @@ -54,8 +54,7 @@ impl Fold for PageConfig {
init: Some(Box::new(Expr::Lit(Lit::Str(Str {
value: format!("{} {}", STRING_LITERAL_DROP_BUNDLE, timestamp).into(),
span: DUMMY_SP,
kind: StrKind::Synthesized {},
has_escape: false,
raw: None,
})))),
span: DUMMY_SP,
definite: false,
Expand Down
5 changes: 2 additions & 3 deletions packages/next-swc/crates/core/src/relay.rs
Expand Up @@ -43,7 +43,7 @@ fn pull_first_operation_name_from_tpl(tpl: &TaggedTpl) -> Option<String> {
static OPERATION_REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new(r"(fragment|mutation|query|subscription) (\w+)").unwrap());

let capture_group = OPERATION_REGEX.captures_iter(&quasis.raw.value).next();
let capture_group = OPERATION_REGEX.captures_iter(&quasis.raw).next();

capture_group.map(|capture_group| capture_group[2].to_string())
})
Expand All @@ -56,8 +56,7 @@ fn build_require_expr_from_path(path: &str) -> Expr {
args: vec![Lit::Str(Str {
span: Default::default(),
value: JsWord::from(path),
has_escape: false,
kind: Default::default(),
raw: None,
})
.as_arg()],
type_args: None,
Expand Down
6 changes: 3 additions & 3 deletions packages/next-swc/crates/core/src/styled_jsx/mod.rs
Expand Up @@ -475,8 +475,8 @@ impl StyledJSXTransformer {
expr,
) => {
if exprs.is_empty() {
hasher.write(quasis[0].raw.value.as_bytes());
css = quasis[0].raw.value.to_string();
hasher.write(quasis[0].raw.as_bytes());
css = quasis[0].raw.to_string();
css_span = *span;
is_dynamic = false;
} else {
Expand All @@ -488,7 +488,7 @@ impl StyledJSXTransformer {
} else {
format!("__styled-jsx-placeholder-{}__", i)
};
s = format!("{}{}{}", s, quasis[i].raw.value, placeholder)
s = format!("{}{}{}", s, quasis[i].raw, placeholder)
}
css = s;
css_span = *span;
Expand Down
11 changes: 3 additions & 8 deletions packages/next-swc/crates/core/src/styled_jsx/transform_css.rs
Expand Up @@ -12,10 +12,10 @@ use swc_css::codegen::{
use swc_css::parser::parser::input::ParserInput;
use swc_css::parser::{parse_str, parse_tokens, parser::ParserConfig};
use swc_css::visit::{VisitMut, VisitMutWith};
use swc_ecmascript::ast::{Expr, Str, StrKind, Tpl, TplElement};
use swc_css_prefixer::prefixer;
use swc_ecmascript::ast::{Expr, Tpl, TplElement};
use swc_ecmascript::parser::StringInput;
use swc_ecmascript::utils::HANDLER;
use swc_stylis::prefixer::prefixer;
use tracing::{debug, trace};

use super::{hash_string, string_literal_expr, LocalStyle};
Expand Down Expand Up @@ -97,12 +97,7 @@ pub fn transform_css(
.map(|quasi| {
TplElement {
cooked: None, // ? Do we need cooked as well
raw: Str {
value: (*quasi).into(),
span: DUMMY_SP,
has_escape: false,
kind: StrKind::Synthesized {},
},
raw: quasi.replace('`', "\\`").into(),
span: DUMMY_SP,
tail: false,
}
Expand Down
13 changes: 3 additions & 10 deletions packages/next-swc/crates/core/src/styled_jsx/utils.rs
Expand Up @@ -7,12 +7,7 @@ use super::{ExternalStyle, JSXStyle, LocalStyle};

fn tpl_element(value: &str) -> TplElement {
TplElement {
raw: Str {
value: value.into(),
span: DUMMY_SP,
kind: StrKind::Synthesized,
has_escape: false,
},
raw: value.into(),
cooked: None,
span: DUMMY_SP,
tail: false,
Expand Down Expand Up @@ -314,10 +309,9 @@ pub fn styled_jsx_import_decl(style_import_name: &str) -> ModuleItem {
span: DUMMY_SP,
})],
src: Str {
has_escape: false,
kind: StrKind::Synthesized {},
span: DUMMY_SP,
value: "styled-jsx/style".into(),
raw: None,
},
}))
}
Expand All @@ -335,8 +329,7 @@ pub fn string_literal_expr(str: &str) -> Expr {
Expr::Lit(Lit::Str(Str {
value: str.into(),
span: DUMMY_SP,
has_escape: false,
kind: StrKind::Synthesized {},
raw: None,
}))
}

Expand Down
@@ -1,6 +1,6 @@
error: next/dynamic requires at least one argument
--> input.js:3:26
|
3 | const DynamicComponent = dynamic()
| ^^^^^^^

x next/dynamic requires at least one argument
,-[input.js:3:1]
3 | const DynamicComponent = dynamic()
: ^^^^^^^
`----
@@ -1,7 +1,7 @@
error: next/dynamic options must be an object literal.
Read more: https://nextjs.org/docs/messages/invalid-dynamic-options-type
--> input.js:4:43
|
4 | const DynamicComponentWithCustomLoading = dynamic(
| ^^^^^^^

x next/dynamic options must be an object literal.
| Read more: https://nextjs.org/docs/messages/invalid-dynamic-options-type
,-[input.js:4:1]
4 | const DynamicComponentWithCustomLoading = dynamic(
: ^^^^^^^
`----
@@ -1,6 +1,6 @@
error: next/dynamic only accepts 2 arguments
--> input.js:3:43
|
3 | const DynamicComponentWithCustomLoading = dynamic(
| ^^^^^^^

x next/dynamic only accepts 2 arguments
,-[input.js:3:1]
3 | const DynamicComponentWithCustomLoading = dynamic(
: ^^^^^^^
`----
@@ -1,6 +1,6 @@
error: You can not use getStaticProps or getStaticPaths with getServerSideProps. To use SSG, please remove getServerSideProps
--> input.js:2:14
|
2 | export const getServerSideProps = function getServerSideProps() {}
| ^^^^^^^^^^^^^^^^^^

x You can not use getStaticProps or getStaticPaths with getServerSideProps. To use SSG, please remove getServerSideProps
,-[input.js:2:1]
2 | export const getServerSideProps = function getServerSideProps() {}
: ^^^^^^^^^^^^^^^^^^
`----
@@ -1,6 +1,6 @@
error: You can not use getStaticProps or getStaticPaths with getServerSideProps. To use SSG, please remove getServerSideProps
--> input.js:2:15
|
2 | export { a as getServerSideProps }
| ^^^^^^^^^^^^^^^^^^

x You can not use getStaticProps or getStaticPaths with getServerSideProps. To use SSG, please remove getServerSideProps
,-[input.js:2:1]
2 | export { a as getServerSideProps }
: ^^^^^^^^^^^^^^^^^^
`----
@@ -1,6 +1,6 @@
error: You can not use getStaticProps or getStaticPaths with getServerSideProps. To use SSG, please remove getServerSideProps
--> input.js:2:10
|
2 | export { getStaticPaths } from 'a'
| ^^^^^^^^^^^^^^

x You can not use getStaticProps or getStaticPaths with getServerSideProps. To use SSG, please remove getServerSideProps
,-[input.js:2:1]
2 | export { getStaticPaths } from 'a'
: ^^^^^^^^^^^^^^
`----
@@ -1,6 +1,6 @@
error: You can not use getStaticProps or getStaticPaths with getServerSideProps. To use SSG, please remove getServerSideProps
--> input.js:1:26
|
1 | export { getStaticProps, getServerSideProps }
| ^^^^^^^^^^^^^^^^^^

x You can not use getStaticProps or getStaticPaths with getServerSideProps. To use SSG, please remove getServerSideProps
,-[input.js:1:1]
1 | export { getStaticProps, getServerSideProps }
: ^^^^^^^^^^^^^^^^^^
`----
@@ -1,7 +1,7 @@
error: Using `export * from '...'` in a page is disallowed. Please use `export { default } from '...'` instead.
Read more: https://nextjs.org/docs/messages/export-all-in-page
--> input.js:1:1
|
1 | export * from './other-page'
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

x Using `export * from '...'` in a page is disallowed. Please use `export { default } from '...'` instead.
| Read more: https://nextjs.org/docs/messages/export-all-in-page
,-[input.js:1:1]
1 | export * from './other-page'
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
@@ -1 +1 @@
export { default, getStaticProps, getStaticPaths } from "./other-page";
export { default, getStaticProps, getStaticPaths } from './other-page';
@@ -1,8 +1,7 @@
error: Expected one child under JSX style tag, but got 0.
Read more: https://nextjs.org/docs/messages/invalid-styled-jsx-children
--> input.js:3:5
|
3 | / <style jsx>
4 | | </style>
| |____________^

x Expected one child under JSX style tag, but got 0.
| Read more: https://nextjs.org/docs/messages/invalid-styled-jsx-children
,-[input.js:3:5]
3 | ,-> <style jsx>
4 | `-> </style>
`----
@@ -1,2 +1,2 @@
error: /some-project/src/some-file.ts uses `css.resolve`, but ends with `.ts`. The file extension needs to be `.tsx` so that the jsx injected by `css.resolve` will be transformed.

x /some-project/src/some-file.ts uses `css.resolve`, but ends with `.ts`. The file extension needs to be `.tsx` so that the jsx injected by `css.resolve` will be transformed.
@@ -1,10 +1,9 @@
error: Expected one child under JSX style tag, but got 2.
Read more: https://nextjs.org/docs/messages/invalid-styled-jsx-children
--> input.js:3:5
|
3 | / <style jsx>
4 | | {`.p {}`}
5 | | {`.p {}`}
6 | | </style>
| |____________^

x Expected one child under JSX style tag, but got 2.
| Read more: https://nextjs.org/docs/messages/invalid-styled-jsx-children
,-[input.js:3:5]
3 | ,-> <style jsx>
4 | | {`.p {}`}
5 | | {`.p {}`}
6 | `-> </style>
`----
@@ -1,9 +1,8 @@
error: Expected a single child of type JSXExpressionContainer under JSX Style tag.
Read more: https://nextjs.org/docs/messages/invalid-styled-jsx-children
--> input.js:3:5
|
3 | / <style jsx>
4 | | 10
5 | | </style>
| |____________^

x Expected a single child of type JSXExpressionContainer under JSX Style tag.
| Read more: https://nextjs.org/docs/messages/invalid-styled-jsx-children
,-[input.js:3:5]
3 | ,-> <style jsx>
4 | | 10
5 | `-> </style>
`----
@@ -1,9 +1,8 @@
error: Expected a template literal, string or identifier inside the JSXExpressionContainer.
Read more: https://nextjs.org/docs/messages/invalid-styled-jsx-children
--> input.js:3:5
|
3 | / <style jsx>
4 | | {[]}
5 | | </style>
| |____________^

x Expected a template literal, string or identifier inside the JSXExpressionContainer.
| Read more: https://nextjs.org/docs/messages/invalid-styled-jsx-children
,-[input.js:3:5]
3 | ,-> <style jsx>
4 | | {[]}
5 | `-> </style>
`----