Skip to content

Use the latest swc_core, fix compatibility with Next.js 15 #111

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

Draft
wants to merge 1 commit into
base: canary
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
725 changes: 539 additions & 186 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ crate-type = ["cdylib", "rlib"]
[dependencies]
serde = "1.0.144"
serde_json = "1.0.85"
swc_core = { version = "0.90.*", features = ["ecma_plugin_transform", "ecma_ast", "ecma_utils", "ecma_visit", "ecma_transforms", "ecma_parser", "common"] }
swc_core = { version = "1.*", features = ["ecma_plugin_transform", "ecma_ast", "ecma_utils", "ecma_visit", "ecma_transforms", "ecma_parser", "common"] }

[dev-dependencies]
testing = "0.33.11"
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2023-03-09
1.82.0
15 changes: 8 additions & 7 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl VisitMut for AppTransformer {
vec![
ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl {
specifiers: vec![ImportNamedSpecifier {
local: Ident::new(SERIALIZER_FUNCTION.into(), DUMMY_SP),
local: Ident::new_no_ctxt(SERIALIZER_FUNCTION.into(), DUMMY_SP),
span: DUMMY_SP,
imported: None,
is_type_only: false,
Expand All @@ -90,7 +90,7 @@ impl VisitMut for AppTransformer {
})),
ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl {
specifiers: vec![ImportDefaultSpecifier {
local: Ident::new(DESERIALIZER_COMPONENT.into(), DUMMY_SP),
local: Ident::new_no_ctxt(DESERIALIZER_COMPONENT.into(), DUMMY_SP),
span: DUMMY_SP,
}
.into()],
Expand Down Expand Up @@ -171,7 +171,7 @@ impl VisitMut for AppTransformer {
// replace attrs
elem.opening.attrs = vec![
JSXAttr {
name: Ident::new(DESERIALIZER_PROPS_ATTR.into(), DUMMY_SP).into(),
name: IdentName::new(DESERIALIZER_PROPS_ATTR.into(), DUMMY_SP).into(),
span: DUMMY_SP,
value: Some(
JSXExprContainer {
Expand All @@ -181,13 +181,14 @@ impl VisitMut for AppTransformer {
props: list,
})
.into()],
callee: Box::new(Expr::Ident(Ident::new(
callee: Box::new(Expr::Ident(Ident::new_no_ctxt(
SERIALIZER_FUNCTION.into(),
DUMMY_SP,
)))
.into(),
span: DUMMY_SP,
type_args: None,
..Default::default()
}))
.into(),
span: DUMMY_SP,
Expand All @@ -197,7 +198,7 @@ impl VisitMut for AppTransformer {
}
.into(),
JSXAttr {
name: Ident::new(DESERIALIZER_PROPS_COMPONENT.into(), DUMMY_SP).into(),
name: IdentName::new(DESERIALIZER_PROPS_COMPONENT.into(), DUMMY_SP).into(),
span: DUMMY_SP,
value: Some(
JSXExprContainer {
Expand All @@ -211,10 +212,10 @@ impl VisitMut for AppTransformer {
];

// change element name
elem.opening.name = Ident::new(DESERIALIZER_COMPONENT.into(), DUMMY_SP).into();
elem.opening.name = Ident::new_no_ctxt(DESERIALIZER_COMPONENT.into(), DUMMY_SP).into();

if let Some(closing) = &mut elem.closing {
closing.name = Ident::new(DESERIALIZER_COMPONENT.into(), DUMMY_SP).into();
closing.name = Ident::new_no_ctxt(DESERIALIZER_COMPONENT.into(), DUMMY_SP).into();
}

self.transformed = true;
Expand Down
8 changes: 4 additions & 4 deletions src/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ impl VisitMut for PageTransformer {
s.imported = Some(ModuleExportName::Ident(s.local.take()));
}

s.local = Ident::new(NEXT_SSG_PROPS_LOCAL.into(), DUMMY_SP);
s.local = Ident::new_no_ctxt(NEXT_SSG_PROPS_LOCAL.into(), DUMMY_SP);

new_items.push(item.take());

Expand Down Expand Up @@ -261,7 +261,7 @@ impl VisitMut for PageTransformer {
ExportNamedSpecifier {
exported: s.exported.take(),
is_type_only: false,
orig: ModuleExportName::Ident(Ident::new(
orig: ModuleExportName::Ident(Ident::new_no_ctxt(
NEXT_SSG_PROPS_ORIG.into(),
DUMMY_SP,
)),
Expand Down Expand Up @@ -297,7 +297,7 @@ impl VisitMut for PageTransformer {
// const gSSP = () => {}
// => gSSP
if self.props.ident.spec.is_some() {
s.orig = ModuleExportName::Ident(Ident::new(
s.orig = ModuleExportName::Ident(Ident::new_no_ctxt(
NEXT_SSG_PROPS_ORIG.into(),
DUMMY_SP,
));
Expand Down Expand Up @@ -401,7 +401,7 @@ impl VisitMut for PageTransformer {

let new_page = ModuleItem::ModuleDecl(
ModuleDecl::ExportDefaultExpr(ExportDefaultExpr {
expr: Box::new(Expr::Ident(Ident::new(
expr: Box::new(Expr::Ident(Ident::new_no_ctxt(
NEXT_PAGE_LOCAL.into(),
DUMMY_SP,
)))
Expand Down
19 changes: 13 additions & 6 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ pub fn superjson_import_decl(superjson_import_name: &str) -> ModuleItem {
sym: format!("_{superjson_import_name}").into(),
span: DUMMY_SP,
optional: false,
..Default::default()
},
span: DUMMY_SP,
imported: Some(ModuleExportName::Ident(Ident {
//sym: superjson_import_name.into(),
sym: superjson_import_name.into(),
span: DUMMY_SP,
optional: false,
..Default::default()
})),
is_type_only: false,
})],
Expand All @@ -43,20 +45,21 @@ pub fn temp_props_item(excluded: ExprOrSpread) -> ModuleItem {
decls: vec![VarDeclarator {
definite: false,
init: Some(
Box::new(Expr::Ident(Ident::new(
Box::new(Expr::Ident(Ident::new_no_ctxt(
NEXT_SSG_PROPS_LOCAL.into(),
DUMMY_SP,
)))
.wrap_props(excluded),
),
name: Pat::Ident(BindingIdent {
id: Ident::new(NEXT_SSG_PROPS_ORIG.into(), DUMMY_SP),
id: Ident::new_no_ctxt(NEXT_SSG_PROPS_ORIG.into(), DUMMY_SP),
type_ann: None,
}),
span: DUMMY_SP,
}],
kind: VarDeclKind::Const,
span: DUMMY_SP,
..Default::default()
}))))
}

Expand All @@ -68,7 +71,7 @@ pub fn temp_import_item(imported: ModuleExportName, local: &str, src: &mut Str)
specifiers: vec![ImportSpecifier::Named(ImportNamedSpecifier {
imported: Some(imported),
is_type_only: false,
local: Ident::new(local.into(), DUMMY_SP),
local: Ident::new_no_ctxt(local.into(), DUMMY_SP),
span: DUMMY_SP,
})],
// should clone
Expand All @@ -87,25 +90,28 @@ impl Wrapper for Box<Expr> {
fn wrap_props(self, excluded: ExprOrSpread) -> Box<Expr> {
Box::new(Expr::Call(CallExpr {
args: vec![self.as_arg(), excluded],
callee: Ident::new(SUPERJSON_PROPS_LOCAL.into(), DUMMY_SP).as_callee(),
callee: Ident::new_no_ctxt(SUPERJSON_PROPS_LOCAL.into(), DUMMY_SP).as_callee(),
span: DUMMY_SP,
type_args: None,
..Default::default()
}))
}
fn wrap_init_props(self, excluded: ExprOrSpread) -> Box<Expr> {
Box::new(Expr::Call(CallExpr {
args: vec![self.as_arg(), excluded],
callee: Ident::new(SUPERJSON_INIT_PROPS_LOCAL.into(), DUMMY_SP).as_callee(),
callee: Ident::new_no_ctxt(SUPERJSON_INIT_PROPS_LOCAL.into(), DUMMY_SP).as_callee(),
span: DUMMY_SP,
type_args: None,
..Default::default()
}))
}
fn wrap_page(self) -> Box<Expr> {
Box::new(Expr::Call(CallExpr {
args: vec![self.as_arg()],
callee: Ident::new(SUPERJSON_PAGE_LOCAL.into(), DUMMY_SP).as_callee(),
callee: Ident::new_no_ctxt(SUPERJSON_PAGE_LOCAL.into(), DUMMY_SP).as_callee(),
span: DUMMY_SP,
type_args: None,
..Default::default()
}))
}
}
Expand Down Expand Up @@ -135,6 +141,7 @@ impl DeclUtil for FnDecl {
}],
kind: VarDeclKind::Const,
span: DUMMY_SP,
..Default::default()
}))
}
}
2 changes: 0 additions & 2 deletions tests/fixture/app/children/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ export default function Page() {
date: date,
...rest
})} component={ClientComponent}>

<p>children</p>

</SuperJSONComponent>;
}
6 changes: 4 additions & 2 deletions tests/fixture/page/skip/gip-in-app-js/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function _appGetInitialProps() {
_appGetInitialProps = /**
* `App` component is used for initialize of pages. It allows for overwriting and full control of the `page` initialization.
* This allows for keeping state between navigation, custom error handling, injecting additional data.
*/ _async_to_generator(function*({ Component , ctx }) {
*/ _async_to_generator(function*({ Component, ctx }) {
const pageProps = yield (0, _utils).loadGetInitialProps(Component, ctx);
return {
pageProps
Expand All @@ -42,5 +42,7 @@ class App extends (_Component = _react.default.Component) {
}
}
App.origGetInitialProps = appGetInitialProps;
App.getInitialProps = appGetInitialProps;
App.getInitialProps = _withSuperJSONInitProps(appGetInitialProps, [
"smth"
]);
exports.default = App;