Skip to content

Commit

Permalink
Merge branch 'canary' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Feb 21, 2022
2 parents 45ad0d3 + 7d98537 commit b4b5d58
Show file tree
Hide file tree
Showing 40 changed files with 424 additions and 441 deletions.
42 changes: 40 additions & 2 deletions .github/workflows/build_test_deploy.yml
Expand Up @@ -88,6 +88,44 @@ jobs:
- run: ./scripts/check-manifests.js
- run: yarn lint

rust-check:
runs-on: ubuntu-latest
needs: build
steps:
- name: Install
uses: actions-rs/toolchain@v1
if: ${{ steps.docs-change.outputs.DOCS_CHANGE != 'docs only change' }}
with:
profile: minimal
toolchain: nightly-2021-11-15
components: rustfmt, clippy

- name: Cache cargo registry
uses: actions/cache@v2
if: ${{ steps.docs-change.outputs.DOCS_CHANGE != 'docs only change' }}
with:
path: ~/.cargo/registry
key: stable-ubuntu-clippy-cargo-registry

- name: Cache cargo index
uses: actions/cache@v2
if: ${{ steps.docs-change.outputs.DOCS_CHANGE != 'docs only change' }}
with:
path: ~/.cargo/git
key: stable-ubuntu-clippy-cargo-index

- uses: actions/cache@v2
id: restore-build
with:
path: ./*
key: ${{ github.sha }}-${{ github.run_number }}-${{ github.run_attempt }}

- name: Check
run: |
cargo fmt -- --check
cargo clippy --all -- -D warnings
working-directory: packages/next-swc

checkPrecompiled:
name: Check Pre-compiled
runs-on: ubuntu-latest
Expand Down Expand Up @@ -610,14 +648,14 @@ jobs:
toolchain: nightly-2021-11-15

- name: Cache cargo registry
uses: actions/cache@v1
uses: actions/cache@v2
if: ${{ steps.docs-change.outputs.DOCS_CHANGE != 'docs only change' }}
with:
path: ~/.cargo/registry
key: stable-ubuntu-18.04-cargo-registry

- name: Cache cargo index
uses: actions/cache@v1
uses: actions/cache@v2
if: ${{ steps.docs-change.outputs.DOCS_CHANGE != 'docs only change' }}
with:
path: ~/.cargo/git
Expand Down
2 changes: 1 addition & 1 deletion docs/advanced-features/output-file-tracing.md
Expand Up @@ -34,7 +34,7 @@ module.exports = {

This will create a folder at `.next/standalone` which can then be deployed on it's own without installing `node_modules`.

Additionally, a minimal `server.js` file is also output which can be used instead of `next start`. This minimal server does not copy the `.next/static` directory by default as this should ideally be handled by a CDN instead, although it can be copied to the `standalone` folder manually and the `server.js` file will serve it automatically.
Additionally, a minimal `server.js` file is also output which can be used instead of `next start`. This minimal server does not copy the `public` or `.next/static` folders by default as these should ideally be handled by a CDN instead, although these folders can be copied to the `standalone` folder manually and the `server.js` file will serve it automatically.

## Caveats

Expand Down
2 changes: 1 addition & 1 deletion docs/faq.md
Expand Up @@ -7,7 +7,7 @@ description: Get to know more about Next.js with the frequently asked questions.
<details>
<summary>Is Next.js production ready?</summary>
<p>Yes! Next.js is used by many of the top websites in the world. See the
<a href="/showcase">Showcase</a> for more info.</p>
<a href="https://nextjs.org/showcase">Showcase</a> for more info.</p>
</details>

<details>
Expand Down
2 changes: 0 additions & 2 deletions errors/swc-disabled.md
Expand Up @@ -10,8 +10,6 @@ When an application has custom Babel configuration Next.js will automatically op

Many of the integrations with external libraries that currently require custom Babel transformations will be ported to Rust-based SWC transforms in the near future. These include but are not limited to:

- Styled Components
- Emotion
- Relay

In order to prioritize transforms that will help you adopt SWC please provide your `.babelrc` on [the feedback thread](https://github.com/vercel/next.js/discussions/30174).
2 changes: 0 additions & 2 deletions examples/with-tailwindcss/prettier.config.js
@@ -1,6 +1,4 @@
module.exports = {
arrowParens: 'always',
singleQuote: true,
tabWidth: 2,
semi: false,
}
90 changes: 45 additions & 45 deletions packages/next-swc/crates/core/src/amp_attributes.rs
@@ -1,63 +1,63 @@
use swc_atoms::JsWord;
use swc_ecmascript::ast::{
Ident, JSXAttr, JSXAttrName, JSXAttrOrSpread, JSXElementName, JSXOpeningElement,
Ident, JSXAttr, JSXAttrName, JSXAttrOrSpread, JSXElementName, JSXOpeningElement,
};
use swc_ecmascript::visit::Fold;

pub fn amp_attributes() -> impl Fold {
AmpAttributePatcher::default()
AmpAttributePatcher::default()
}

#[derive(Debug, Default)]
struct AmpAttributePatcher {}

impl Fold for AmpAttributePatcher {
fn fold_jsx_opening_element(&mut self, node: JSXOpeningElement) -> JSXOpeningElement {
let JSXOpeningElement {
name,
mut attrs,
span,
self_closing,
type_args,
} = node;
let n = name.clone();

if let JSXElementName::Ident(Ident { sym, .. }) = name {
if sym.starts_with("amp-") {
for i in 0..attrs.len() {
if let JSXAttrOrSpread::JSXAttr(JSXAttr {
name:
JSXAttrName::Ident(Ident {
sym,
span: s,
optional: o,
}),
fn fold_jsx_opening_element(&mut self, node: JSXOpeningElement) -> JSXOpeningElement {
let JSXOpeningElement {
name,
mut attrs,
span,
value,
}) = &attrs[i]
{
if sym as &str == "className" {
attrs[i] = JSXAttrOrSpread::JSXAttr(JSXAttr {
name: JSXAttrName::Ident(Ident {
sym: JsWord::from("class"),
span: s.clone(),
optional: o.clone(),
}),
span: span.clone(),
value: value.clone(),
})
self_closing,
type_args,
} = node;
let n = name.clone();

if let JSXElementName::Ident(Ident { sym, .. }) = name {
if sym.starts_with("amp-") {
for i in &mut attrs {
if let JSXAttrOrSpread::JSXAttr(JSXAttr {
name:
JSXAttrName::Ident(Ident {
sym,
span: s,
optional: o,
}),
span,
value,
}) = &i
{
if sym as &str == "className" {
*i = JSXAttrOrSpread::JSXAttr(JSXAttr {
name: JSXAttrName::Ident(Ident {
sym: JsWord::from("class"),
span: *s,
optional: *o,
}),
span: *span,
value: value.clone(),
})
}
}
}
}
}
}
}
}

JSXOpeningElement {
name: n,
attrs,
span,
self_closing,
type_args,
JSXOpeningElement {
name: n,
attrs,
span,
self_closing,
type_args,
}
}
}
}
16 changes: 6 additions & 10 deletions packages/next-swc/crates/core/src/auto_cjs/mod.rs
Expand Up @@ -18,17 +18,13 @@ struct CjsFinder {
/// does not support changing configuration based on content of the file.
impl Visit for CjsFinder {
fn visit_member_expr(&mut self, e: &MemberExpr) {
match &*e.obj {
Expr::Ident(obj) => match &e.prop {
MemberProp::Ident(prop) => {
if &*obj.sym == "module" && &*prop.sym == "exports" {
self.found = true;
return;
}
if let Expr::Ident(obj) = &*e.obj {
if let MemberProp::Ident(prop) = &e.prop {
if &*obj.sym == "module" && &*prop.sym == "exports" {
self.found = true;
return;
}
_ => {}
},
_ => {}
}
}

e.obj.visit_with(self);
Expand Down
Expand Up @@ -4,10 +4,7 @@ use swc_ecmascript::utils::HANDLER;
use swc_ecmascript::visit::{noop_fold_type, Fold};

pub fn disallow_re_export_all_in_page(is_page_file: bool) -> impl Fold {
Optional::new(
DisallowReExportAllInPage,
is_page_file
)
Optional::new(DisallowReExportAllInPage, is_page_file)
}

struct DisallowReExportAllInPage;
Expand Down
25 changes: 13 additions & 12 deletions packages/next-swc/crates/core/src/hook_optimizer.rs
Expand Up @@ -75,8 +75,8 @@ impl HookOptimizer {
if let Expr::Call(c) = &*init.as_deref().unwrap() {
if let Callee::Expr(i) = &c.callee {
if let Expr::Ident(Ident { sym, .. }) = &**i {
if self.hooks.contains(&sym) {
let name = get_object_pattern(&a);
if self.hooks.contains(sym) {
let name = get_object_pattern(a);
return VarDeclarator {
name,
init: init_clone,
Expand All @@ -89,7 +89,7 @@ impl HookOptimizer {
}
}

return decl;
decl
}
}

Expand All @@ -98,15 +98,16 @@ fn get_object_pattern(array_pattern: &ArrayPat) -> Pat {
.elems
.iter()
.enumerate()
.filter_map(|(i, elem)| match elem {
Some(elem) => Some(ObjectPatProp::KeyValue(KeyValuePatProp {
key: PropName::Num(Number {
value: i as f64,
span: DUMMY_SP,
}),
value: Box::new(elem.clone()),
})),
None => None,
.filter_map(|(i, elem)| {
elem.as_ref().map(|elem| {
ObjectPatProp::KeyValue(KeyValuePatProp {
key: PropName::Num(Number {
value: i as f64,
span: DUMMY_SP,
}),
value: Box::new(elem.clone()),
})
})
})
.collect();

Expand Down
12 changes: 8 additions & 4 deletions packages/next-swc/crates/core/src/lib.rs
Expand Up @@ -27,7 +27,7 @@ DEALINGS IN THE SOFTWARE.
*/

#![recursion_limit = "2048"]
//#![deny(clippy::all)]
#![deny(clippy::all)]

use auto_cjs::contains_cjs;
use either::Either;
Expand Down Expand Up @@ -112,15 +112,19 @@ pub fn custom_before_pass(
#[cfg(not(target_arch = "wasm32"))]
let relay_plugin = {
if let Some(config) = &opts.relay {
Either::Left(relay::relay(config, file.name.clone(), opts.pages_dir.clone()))
Either::Left(relay::relay(
config,
file.name.clone(),
opts.pages_dir.clone(),
))
} else {
Either::Right(noop())
}
};

chain!(
disallow_re_export_all_in_page::disallow_re_export_all_in_page(opts.is_page_file),
styled_jsx::styled_jsx(cm.clone(), file.name.clone()),
styled_jsx::styled_jsx(cm, file.name.clone()),
hook_optimizer::hook_optimizer(),
match &opts.styled_components {
Some(config) => {
Expand Down Expand Up @@ -173,7 +177,7 @@ impl TransformOptions {
let should_enable_commonjs =
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(EsVersion::latest());
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()
Expand Down
4 changes: 2 additions & 2 deletions packages/next-swc/crates/core/src/next_dynamic.rs
Expand Up @@ -74,7 +74,7 @@ impl Fold for NextDynamicPatcher {
if let Callee::Expr(i) = &expr.callee {
if let Expr::Ident(identifier) = &**i {
if self.dynamic_bindings.contains(&identifier.to_id()) {
if expr.args.len() == 0 {
if expr.args.is_empty() {
HANDLER.with(|handler| {
handler
.struct_span_err(
Expand Down Expand Up @@ -116,7 +116,7 @@ impl Fold for NextDynamicPatcher {
expr.args[0].expr = expr.args[0].expr.clone().fold_with(self);
self.is_next_dynamic_first_arg = false;

if let None = self.dynamically_imported_specifier {
if self.dynamically_imported_specifier.is_none() {
return expr;
}

Expand Down

0 comments on commit b4b5d58

Please sign in to comment.