Unverified Commit 9b3bd73b authored by Leah's avatar Leah Committed by GitHub

prettier fix for `next-swc` (#47873)

This enables the existing prettier config to auto apply to code inside
the `next-swc` package
parent 191acdf8
...@@ -13,7 +13,8 @@ lerna.json ...@@ -13,7 +13,8 @@ lerna.json
.github/actions/next-stats-action/.work .github/actions/next-stats-action/.work
.github/actions/issue-validator/index.mjs .github/actions/issue-validator/index.mjs
.github/actions/issue-labeler/lib/index.js .github/actions/issue-labeler/lib/index.js
packages/next-swc/crates/**/* packages/next-swc/crates/next-core/js/src/compiled/**/*
packages/next-swc/crates/**/tests/**/output*
packages/next-swc/target/**/* packages/next-swc/target/**/*
packages/next-swc/native/**/* packages/next-swc/native/**/*
packages/next-codemod/transforms/__testfixtures__/**/* packages/next-codemod/transforms/__testfixtures__/**/*
......
...@@ -3,5 +3,5 @@ import dynamic from 'next/dynamic' ...@@ -3,5 +3,5 @@ import dynamic from 'next/dynamic'
const DynamicComponentWithCustomLoading = dynamic( const DynamicComponentWithCustomLoading = dynamic(
() => import('../components/hello'), () => import('../components/hello'),
{ loading: () => <p>...</p> }, { loading: () => <p>...</p> },
"3rd" '3rd'
) )
import dynamic from 'next/dynamic' import dynamic from 'next/dynamic';
const DynamicComponentWithCustomLoading = dynamic(()=>import('../components/hello'), {
const DynamicComponentWithCustomLoading = dynamic( loading: ()=><p>...</p>
() => import('../components/hello'), }, '3rd');
{ loading: () => <p>...</p> },
"3rd"
)
const getStaticProps = async () => {} const getStaticProps = async () => {}
export { a as getServerSideProps } export { a as getServerSideProps }
export { a as getServerSideProps } from './input' export { a as getServerSideProps } from './input'
export { getStaticPaths } from 'a' export { getStaticPaths } from 'a'
// This is a comment. // This is a comment.
"use strict"; 'use strict'
/** /**
* This is a comment. * This is a comment.
*/ */
import "client-only" import 'client-only'
export default function () { export default function () {
return null; return null
} }
// This is a comment. // This is a comment.
"use strict"; 'use strict';
/** /**
* This is a comment. * This is a comment.
*/ import "client-only"; */ import 'client-only';
export default function() { export default function() {
return null; return null;
} }
export function getServerSideProps (){ export function getServerSideProps() {}
}
export default function () { export default function () {
return null; return null
} }
x NEXT_RSC_ERR_INVALID_API: getServerSideProps x NEXT_RSC_ERR_INVALID_API: getServerSideProps
,-[input.js:1:1] ,-[input.js:1:1]
1 | export function getServerSideProps (){ 1 | export function getServerSideProps() {}
: ^^^^^^^^^^^^^^^^^^ : ^^^^^^^^^^^^^^^^^^
2 | }
`---- `----
export function getStaticProps (){ export function getStaticProps() {}
}
export default function () { export default function () {
return null; return null
} }
x NEXT_RSC_ERR_INVALID_API: getStaticProps x NEXT_RSC_ERR_INVALID_API: getStaticProps
,-[input.js:1:1] ,-[input.js:1:1]
1 | export function getStaticProps (){ 1 | export function getStaticProps() {}
: ^^^^^^^^^^^^^^ : ^^^^^^^^^^^^^^
2 | }
`---- `----
// This is a comment. // This is a comment.
"use strict"; 'use strict'
/** /**
* This is a comment. * This is a comment.
*/ */
import "server-only" import 'server-only'
export default function () { export default function () {
return null; return null
} }
// This is a comment. // This is a comment.
"use strict"; 'use strict';
/** /**
* This is a comment. * This is a comment.
*/ import "server-only"; */ import 'server-only';
export default function() { export default function() {
return null; return null;
} }
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
x NEXT_RSC_ERR_CLIENT_IMPORT: server-only x NEXT_RSC_ERR_CLIENT_IMPORT: server-only
,-[input.js:8:1] ,-[input.js:8:1]
8 | 8 |
9 | import "server-only" 9 | import 'server-only'
: ^^^^^^^^^^^^^^^^^^^^ : ^^^^^^^^^^^^^^^^^^^^
`---- `----
import "react" import 'react'
;('use client')
"use client"
export default function () { export default function () {
return null; return null
} }
import "react"; import 'react';
export default function () { 'use client';
export default function() {
return null; return null;
} }
x NEXT_RSC_ERR_CLIENT_DIRECTIVE x NEXT_RSC_ERR_CLIENT_DIRECTIVE_PAREN
,-[input.js:2:1] ,-[input.js:1:1]
2 | 1 | import 'react'
3 | "use client" 2 | ;('use client')
: ^^^^^^^^^^^^ : ^^^^^^^^^^^^^^
`---- `----
// This is a comment. // This is a comment.
"use strict"; 'use strict'
/** /**
* This is a comment. * This is a comment.
*/ */
import "client-only" import 'client-only'
export default function () { export default function () {
return null; return null
} }
// This is a comment. // This is a comment.
"use strict"; 'use strict';
/** /**
* This is a comment. * This is a comment.
*/ import "client-only"; */ import 'client-only';
export default function() { export default function() {
return null; return null;
} }
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
x NEXT_RSC_ERR_SERVER_IMPORT: client-only x NEXT_RSC_ERR_SERVER_IMPORT: client-only
,-[input.js:8:1] ,-[input.js:8:1]
8 | 8 |
9 | import "client-only" 9 | import 'client-only'
: ^^^^^^^^^^^^^^^^^^^^ : ^^^^^^^^^^^^^^^^^^^^
`---- `----
export function getServerSideProps (){ export function getServerSideProps() {}
}
export default function () { export default function () {
return null; return null
} }
x NEXT_RSC_ERR_INVALID_API: getServerSideProps x NEXT_RSC_ERR_INVALID_API: getServerSideProps
,-[input.js:1:1] ,-[input.js:1:1]
1 | export function getServerSideProps (){ 1 | export function getServerSideProps() {}
: ^^^^^^^^^^^^^^^^^^ : ^^^^^^^^^^^^^^^^^^
2 | }
`---- `----
export function getStaticProps (){ export function getStaticProps() {}
}
export default function () { export default function () {
return null; return null
} }
x NEXT_RSC_ERR_INVALID_API: getStaticProps x NEXT_RSC_ERR_INVALID_API: getStaticProps
,-[input.js:1:1] ,-[input.js:1:1]
1 | export function getStaticProps (){ 1 | export function getStaticProps() {}
: ^^^^^^^^^^^^^^ : ^^^^^^^^^^^^^^
2 | }
`---- `----
...@@ -13,9 +13,9 @@ import { ...@@ -13,9 +13,9 @@ import {
useLayoutEffect, useLayoutEffect,
useReducer, useReducer,
useRef, useRef,
useSyncExternalStore useSyncExternalStore,
} from "react" } from 'react'
export default function () { export default function () {
return null; return null
} }
import { useState } from 'react'; import { useState } from 'react';
import { createContext } from 'react'; import { createContext } from 'react';
import { useEffect, useImperativeHandle } from 'react'; import { useEffect, useImperativeHandle } from 'react';
import { Component, createFactory, PureComponent, useDeferredValue, useInsertionEffect, useLayoutEffect, useReducer, useRef, useSyncExternalStore } from "react"; import { Component, createFactory, PureComponent, useDeferredValue, useInsertionEffect, useLayoutEffect, useReducer, useRef, useSyncExternalStore } from 'react';
export default function() { export default function() {
return null; return null;
} }
...@@ -87,13 +87,13 @@ ...@@ -87,13 +87,13 @@
14 | useReducer, 14 | useReducer,
15 | useRef, 15 | useRef,
: ^^^^^^ : ^^^^^^
16 | useSyncExternalStore 16 | useSyncExternalStore,
`---- `----
x NEXT_RSC_ERR_REACT_API: useSyncExternalStore x NEXT_RSC_ERR_REACT_API: useSyncExternalStore
,-[input.js:15:1] ,-[input.js:15:1]
15 | useRef, 15 | useRef,
16 | useSyncExternalStore 16 | useSyncExternalStore,
: ^^^^^^^^^^^^^^^^^^^^ : ^^^^^^^^^^^^^^^^^^^^
17 | } from "react" 17 | } from 'react'
`---- `----
import { import { findDOMNode, flushSync, unstable_batchedUpdates } from 'react-dom'
findDOMNode,
flushSync,
unstable_batchedUpdates,
} from "react-dom"
export default function () { export default function () {
return null; return null
} }
import { findDOMNode, flushSync, unstable_batchedUpdates } from "react-dom"; import { findDOMNode, flushSync, unstable_batchedUpdates } from 'react-dom';
export default function() { export default function() {
return null; return null;
} }
x NEXT_RSC_ERR_REACT_API: findDOMNode x NEXT_RSC_ERR_REACT_API: findDOMNode
,-[input.js:1:1] ,-[input.js:1:1]
1 | import { 1 | import { findDOMNode, flushSync, unstable_batchedUpdates } from 'react-dom'
2 | findDOMNode,
: ^^^^^^^^^^^ : ^^^^^^^^^^^
3 | flushSync,
`---- `----
x NEXT_RSC_ERR_REACT_API: flushSync x NEXT_RSC_ERR_REACT_API: flushSync
,-[input.js:2:1] ,-[input.js:1:1]
2 | findDOMNode, 1 | import { findDOMNode, flushSync, unstable_batchedUpdates } from 'react-dom'
3 | flushSync,
: ^^^^^^^^^ : ^^^^^^^^^
4 | unstable_batchedUpdates,
`---- `----
x NEXT_RSC_ERR_REACT_API: unstable_batchedUpdates x NEXT_RSC_ERR_REACT_API: unstable_batchedUpdates
,-[input.js:3:1] ,-[input.js:1:1]
3 | flushSync, 1 | import { findDOMNode, flushSync, unstable_batchedUpdates } from 'react-dom'
4 | unstable_batchedUpdates,
: ^^^^^^^^^^^^^^^^^^^^^^^ : ^^^^^^^^^^^^^^^^^^^^^^^
5 | } from "react-dom"
`---- `----
// This is a comment. // This is a comment.
"use strict"; 'use strict'
/** /**
* This is a comment. * This is a comment.
*/ */
import "react-dom/server" import 'react-dom/server'
import "react-dom/client" import 'react-dom/client'
export default function () { export default function () {
return null; return null
} }
// This is a comment. // This is a comment.
"use strict"; 'use strict';
/** /**
* This is a comment. * This is a comment.
*/ import "react-dom/server"; */ import 'react-dom/server';
import "react-dom/client"; import 'react-dom/client';
export default function() { export default function() {
return null; return null;
} }
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
x NEXT_RSC_ERR_SERVER_IMPORT: react-dom/server x NEXT_RSC_ERR_SERVER_IMPORT: react-dom/server
,-[input.js:8:1] ,-[input.js:8:1]
8 | 8 |
9 | import "react-dom/server" 9 | import 'react-dom/server'
: ^^^^^^^^^^^^^^^^^^^^^^^^^ : ^^^^^^^^^^^^^^^^^^^^^^^^^
`---- `----
x NEXT_RSC_ERR_SERVER_IMPORT: react-dom/client x NEXT_RSC_ERR_SERVER_IMPORT: react-dom/client
,-[input.js:10:1] ,-[input.js:10:1]
10 | 10 |
11 | import "react-dom/client" 11 | import 'react-dom/client'
: ^^^^^^^^^^^^^^^^^^^^^^^^^ : ^^^^^^^^^^^^^^^^^^^^^^^^^
`---- `----
'use server'; 'use server'
export function foo() {} export function foo() {}
'use sevrer' 'use sevrer'
export async function foo () {} export async function foo() {}
import 'react' import 'react'
;('use sevrer')
('use sevrer')
// ^Tools like Prettier sometimes do this. // ^Tools like Prettier sometimes do this.
x The "use server" directive must be at the top of the file, and cannot be wrapped in parentheses. x The "use server" directive must be at the top of the file, and cannot be wrapped in parentheses.
,-[input.js:2:1] ,-[input.js:1:1]
2 | 1 | import 'react'
3 | ('use sevrer') 2 | ;('use sevrer')
: ^^^^^^^^^^^^^^ : ^^^^^^^^^^^^^^
`---- `----
'use strict'; 'use strict'
// comment // comment
'use server'; 'use server'
export function bar() {} export function bar() {}
'use server'; 'use server'
export const x = 1 export const x = 1
'use server'; 'use server'
export default class Component { export default class Component {
render() { render() {
return null; return null
} }
} }
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
2 | 2 |
3 | ,-> export default class Component { 3 | ,-> export default class Component {
4 | | render() { 4 | | render() {
5 | | return null; 5 | | return null
6 | | } 6 | | }
7 | `-> } 7 | `-> }
`---- `----
'use server'; 'use server'
export * from 'foo' export * from 'foo'
'use server'; 'use server'
export default () => {} export default () => {}
...@@ -5,5 +5,5 @@ const foo = async () => { ...@@ -5,5 +5,5 @@ const foo = async () => {
const bar = async () => { const bar = async () => {
const x = 1 const x = 1
'use server' ;('use server')
} }
x The "use server" directive must be at the top of the function body.
,-[input.js:7:1]
7 | const x = 1
8 | 'use server'
: ^^^^^^^^^^^^
9 | }
`----
import 'my-module' import 'my-module'
;('use server')
'use server'
x The "use server" directive must be at the top of the file. x The "use server" directive must be at the top of the file, and cannot be wrapped in parentheses.
,-[input.js:2:1] ,-[input.js:1:1]
2 | 1 | import 'my-module'
3 | 'use server' 2 | ;('use server')
: ^^^^^^^^^^^^ : ^^^^^^^^^^^^^^
`---- `----
...@@ -3,5 +3,5 @@ import dynamic from 'next/dynamic' ...@@ -3,5 +3,5 @@ import dynamic from 'next/dynamic'
const DynamicComponent = dynamic(() => import(`../components/hello`)) const DynamicComponent = dynamic(() => import(`../components/hello`))
const componentRoot = '@/some-components' const componentRoot = '@/some-components'
const Component1 = dynamic(() => import(`${componentRoot}/component1`)); const Component1 = dynamic(() => import(`${componentRoot}/component1`))
const Component2 = dynamic(() => import(`${componentRoot}/component2`)); const Component2 = dynamic(() => import(`${componentRoot}/component2`))
\ No newline at end of file
import dynamic from 'next/dynamic' import dynamic from 'next/dynamic'
const DynamicComponent = dynamic(() => handleImport(import('./components/hello')), { const DynamicComponent = dynamic(
() => handleImport(import('./components/hello')),
{
loading: () => null, loading: () => null,
ssr: false, ssr: false,
}); }
\ No newline at end of file )
export default function Home() { export default function Home() {
return <div data-test-id="1" data-custom="1a"> return (
<div data-test-id="1" data-custom="1a">
<div data-custom="2"> <div data-custom="2">
<h1 data-testid="3">Hello World!</h1> <h1 data-testid="3">Hello World!</h1>
</div> </div>
</div> </div>
)
} }
export default function Home() { export default function Home() {
return <div data-test-id="1" data-custom="1a"> return (
<div data-test-id="1" data-custom="1a">
<div data-custom="2"> <div data-custom="2">
<h1 data-testid="3" nested={() => (<div data-testid="4">nested</div>)}>Hello World!</h1> <h1 data-testid="3" nested={() => <div data-testid="4">nested</div>}>
Hello World!
</h1>
</div> </div>
</div> </div>
)
} }
...@@ -3,7 +3,11 @@ export default function Home() { ...@@ -3,7 +3,11 @@ export default function Home() {
<div data-custom="2"> <div data-custom="2">
<h1 nested={()=><div>nested</div>}>Hello World!</h1> <h1 nested={()=><div>nested</div>}>
Hello World!
</h1>
</div> </div>
......
// This is a comment. // This is a comment.
"use strict"; 'use strict'
/** /**
* This is a comment. * This is a comment.
*/ */
"use client"; 'use client'
// This is a comment. // This is a comment.
"foo"; 'foo'
"use client"; 'use client'
import "fs" import 'fs'
;('bar')
"bar";
// This is a comment. // This is a comment.
1 + 1; 1 + 1
;('baz')
"baz";
export default function () { export default function () {
return null; return null
} }
// This is a comment. // This is a comment.
/* __next_internal_client_entry_do_not_use__ default auto */ "use strict"; /* __next_internal_client_entry_do_not_use__ default auto */ 'use strict';
// This is a comment. // This is a comment.
"foo"; 'foo';
import "fs"; import 'fs';
"bar"; 'bar';
// This is a comment. // This is a comment.
1 + 1; 1 + 1;
"baz"; 'baz';
export default function() { export default function() {
return null; return null;
} }
"use client"; 'use client'
module.exports = function () {} module.exports = function () {}
// This is a comment. // This is a comment.
"use strict"; 'use strict'
/** /**
* This is a comment. * This is a comment.
*/ */
"use client"; 'use client'
// This is a comment. // This is a comment.
"random-directive"; 'random-directive'
import "fs" import 'fs'
;('qwerty')
"qwerty";
// This is a comment. // This is a comment.
1 + 1; 1 + 1
;('sasaya')
"sasaya";
export default function () { export default function () {
return null; return null
} }
export const a = 1 export const a = 1
......
console.log("remove console test at top level"); console.log('remove console test at top level')
export function shouldRemove() { export function shouldRemove() {
console.log("remove console test in function"); console.log('remove console test in function')
console.error("remove console test in function / error"); console.error('remove console test in function / error')
} }
export function locallyDefinedConsole() { export function locallyDefinedConsole() {
let console = { let console = {
log: () => { }, log: () => {},
}; }
console.log(); console.log()
} }
export function capturedConsole() { export function capturedConsole() {
let console = { let console = {
log: () => { }, log: () => {},
}; }
function innerFunc() { function innerFunc() {
console.log(); console.log()
} }
} }
export function overrideInParam(console) { export function overrideInParam(console) {
console.log("") console.log('')
} }
export function overrideInParamObjectPatPropAssign({ console }) { export function overrideInParamObjectPatPropAssign({ console }) {
console.log("") console.log('')
} }
export function overrideInParamObjectPatPropKeyValue({ c: console }) { export function overrideInParamObjectPatPropKeyValue({ c: console }) {
console.log("") console.log('')
} }
export function overrideInParamObjectPatPropKeyValueNested({ c: { console } }) { export function overrideInParamObjectPatPropKeyValueNested({ c: { console } }) {
console.log("") console.log('')
} }
export function overrideInParamArray([ console ]) { export function overrideInParamArray([console]) {
console.log("") console.log('')
} }
...@@ -5,32 +5,30 @@ export function shouldRemove() { ...@@ -5,32 +5,30 @@ export function shouldRemove() {
} }
export function locallyDefinedConsole() { export function locallyDefinedConsole() {
let console = { let console = {
log: ()=>{ log: ()=>{}
}
}; };
console.log(); console.log();
} }
export function capturedConsole() { export function capturedConsole() {
let console = { let console = {
log: ()=>{ log: ()=>{}
}
}; };
function innerFunc() { function innerFunc() {
console.log(); console.log();
} }
} }
export function overrideInParam(console) { export function overrideInParam(console) {
console.log(""); console.log('');
} }
export function overrideInParamObjectPatPropAssign({ console }) { export function overrideInParamObjectPatPropAssign({ console }) {
console.log(""); console.log('');
} }
export function overrideInParamObjectPatPropKeyValue({ c: console }) { export function overrideInParamObjectPatPropKeyValue({ c: console }) {
console.log(""); console.log('');
} }
export function overrideInParamObjectPatPropKeyValueNested({ c: { console } }) { export function overrideInParamObjectPatPropKeyValueNested({ c: { console } }) {
console.log(""); console.log('');
} }
export function overrideInParamArray([console]) { export function overrideInParamArray([console]) {
console.log(""); console.log('');
} }
let console = { let console = {
log: (msg) => {}, log: (msg) => {},
}; }
function func1() { function func1() {
console.log("remove console test in function"); console.log('remove console test in function')
} }
console.log("remove console test at top level"); console.log('remove console test at top level')
let console = { let console = {
log: (msg)=>{ log: (msg)=>{}
}
}; };
function func1() { function func1() {
console.log("remove console test in function"); console.log('remove console test in function');
} }
console.log("remove console test at top level"); console.log('remove console test at top level');
// app/send.ts // app/send.ts
"use server"; 'use server'
export async function myAction(a, b, c) { export async function myAction(a, b, c) {
console.log('a') console.log('a')
} }
......
// app/send.ts // app/send.ts
"use server"; 'use server'
import 'db' import 'db'
......
...@@ -2,9 +2,9 @@ import deleteFromDb from 'db' ...@@ -2,9 +2,9 @@ import deleteFromDb from 'db'
export function Item({ id1, id2 }) { export function Item({ id1, id2 }) {
async function deleteItem() { async function deleteItem() {
"use server"; 'use server'
await deleteFromDb(id1); await deleteFromDb(id1)
await deleteFromDb(id2); await deleteFromDb(id2)
} }
return <Button action={deleteItem}>Delete</Button>; return <Button action={deleteItem}>Delete</Button>
} }
"use server"; 'use server'
export default async function foo() {} export default async function foo() {}
'use server' 'use server'
async function foo () {} async function foo() {}
export default foo export default foo
...@@ -3,5 +3,5 @@ ...@@ -3,5 +3,5 @@
const foo = async function () {} const foo = async function () {}
export default foo export default foo
const bar = async function() {} const bar = async function () {}
export { bar } export { bar }
'use server' 'use server'
export default async (a, b) => { console.log(a, b) } export default async (a, b) => {
console.log(a, b)
}
import deleteFromDb from 'db' import deleteFromDb from 'db'
const v1 = 'v1'; const v1 = 'v1'
export function Item({ id1, id2 }) { export function Item({ id1, id2 }) {
const v2 = id2; const v2 = id2
const deleteItem = async () => { const deleteItem = async () => {
"use server"; 'use server'
await deleteFromDb(id1); await deleteFromDb(id1)
await deleteFromDb(v1); await deleteFromDb(v1)
await deleteFromDb(v2); await deleteFromDb(v2)
} }
return <Button action={deleteItem}>Delete</Button>; return <Button action={deleteItem}>Delete</Button>
} }
const f = (x) => { const f = (x) => {
......
import deleteFromDb from 'db' import deleteFromDb from 'db'
const v1 = 'v1'; const v1 = 'v1'
export function Item({ id1, id2 }) { export function Item({ id1, id2 }) {
const v2 = id2; const v2 = id2
return <> return (
<Button action={async () => { <>
"use server"; <Button
await deleteFromDb(id1); action={async () => {
await deleteFromDb(v1); 'use server'
await deleteFromDb(v2); await deleteFromDb(id1)
}}>Delete</Button> await deleteFromDb(v1)
<Button action={async function () { await deleteFromDb(v2)
"use server"; }}
await deleteFromDb(id1); >
await deleteFromDb(v1); Delete
await deleteFromDb(v2); </Button>
}}>Delete</Button> <Button
action={async function () {
'use server'
await deleteFromDb(id1)
await deleteFromDb(v1)
await deleteFromDb(v2)
}}
>
Delete
</Button>
</> </>
)
} }
...@@ -7,14 +7,22 @@ export function Item({ id1 , id2 }) { ...@@ -7,14 +7,22 @@ export function Item({ id1 , id2 }) {
<Button action={$$ACTION_0 = async ()=>$$ACTION_1($$ACTION_0.$$bound), $$ACTION_0.$$typeof = Symbol.for("react.server.reference"), $$ACTION_0.$$id = "188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_0.$$bound = [ <Button action={$$ACTION_0 = async ()=>$$ACTION_1($$ACTION_0.$$bound), $$ACTION_0.$$typeof = Symbol.for("react.server.reference"), $$ACTION_0.$$id = "188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_0.$$bound = [
id1, id1,
v2 v2
], $$ACTION_0}>Delete</Button> ], $$ACTION_0}>
Delete
</Button>
<Button action={$$ACTION_2 = async function() { <Button action={$$ACTION_2 = async function() {
return $$ACTION_3($$ACTION_2.$$bound); return $$ACTION_3($$ACTION_2.$$bound);
}, $$ACTION_2.$$typeof = Symbol.for("react.server.reference"), $$ACTION_2.$$id = "56a859f462d35a297c46a1bbd1e6a9058c104ab8", $$ACTION_2.$$bound = [ }, $$ACTION_2.$$typeof = Symbol.for("react.server.reference"), $$ACTION_2.$$id = "56a859f462d35a297c46a1bbd1e6a9058c104ab8", $$ACTION_2.$$bound = [
id1, id1,
v2 v2
], $$ACTION_2}>Delete</Button> ], $$ACTION_2}>
Delete
</Button>
</>; </>;
} }
......
export function Item({ value }) { export function Item({ value }) {
return <> return (
<Button action={async (value2) => { <>
"use server"; <Button
return value * value2; action={async (value2) => {
}}>Multiple</Button> 'use server'
return value * value2
}}
>
Multiple
</Button>
</> </>
)
} }
...@@ -3,7 +3,11 @@ ...@@ -3,7 +3,11 @@
<Button action={$$ACTION_0 = async (value2)=>$$ACTION_1($$ACTION_0.$$bound), $$ACTION_0.$$typeof = Symbol.for("react.server.reference"), $$ACTION_0.$$id = "188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_0.$$bound = [ <Button action={$$ACTION_0 = async (value2)=>$$ACTION_1($$ACTION_0.$$bound), $$ACTION_0.$$typeof = Symbol.for("react.server.reference"), $$ACTION_0.$$id = "188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_0.$$bound = [
value value
], $$ACTION_0}>Multiple</Button> ], $$ACTION_0}>
Multiple
</Button>
</>; </>;
} }
......
async function myAction(a, b, c) { async function myAction(a, b, c) {
"use server"; 'use server'
console.log('a') console.log('a')
} }
export default function Page() { export default function Page() {
return <Button action={myAction}>Delete</Button>; return <Button action={myAction}>Delete</Button>
} }
...@@ -2,18 +2,24 @@ import { validator, another } from 'auth' ...@@ -2,18 +2,24 @@ import { validator, another } from 'auth'
const x = 1 const x = 1
export default function Page () { export default function Page() {
const y = 1 const y = 1
return <Foo action={validator(async function (z) { return (
<Foo
action={validator(async function (z) {
'use server' 'use server'
return x + y + z return x + y + z
})} /> })}
/>
)
} }
validator(async () => { validator(async () => {
'use server' 'use server'
}) })
another(validator(async () => { another(
validator(async () => {
'use server' 'use server'
})) })
)
// app/send.ts // app/send.ts
"use server"; 'use server'
export async function myAction(a, b, c) { export async function myAction(a, b, c) {
console.log('a') console.log('a')
} }
"use server"; 'use server'
export async function a() {} export async function a() {}
export async function b() {} export async function b() {}
export async function c() {} export async function c() {}
...@@ -7,6 +7,6 @@ function d() {} ...@@ -7,6 +7,6 @@ function d() {}
function Foo() { function Foo() {
async function e() { async function e() {
"use server" 'use server'
} }
} }
import deleteFromDb from 'db' import deleteFromDb from 'db'
const v1 = 'v1'; const v1 = 'v1'
export function Item({ id1, id2 }) { export function Item({ id1, id2 }) {
const v2 = id2; const v2 = id2
async function deleteItem() { async function deleteItem() {
"use server"; 'use server'
await deleteFromDb(id1); await deleteFromDb(id1)
await deleteFromDb(v1); await deleteFromDb(v1)
await deleteFromDb(v2); await deleteFromDb(v2)
} }
return <Button action={deleteItem}>Delete</Button>; return <Button action={deleteItem}>Delete</Button>
} }
...@@ -4,15 +4,27 @@ const f3 = 1 ...@@ -4,15 +4,27 @@ const f3 = 1
var f4 var f4
let f5 let f5
const [f6, [f7, ...f8], {f9}, { f10, f11: [f12], f13: f14, f15: { f16 }, ...f17 }, ...f18] = [] const [
f6,
[f7, ...f8],
{ f9 },
{
f10,
f11: [f12],
f13: f14,
f15: { f16 },
...f17
},
...f18
] = []
if (true) { if (true) {
const g19 = 1; const g19 = 1
} }
function x() { function x() {
const f2 = 1; const f2 = 1
const g20 = 1; const g20 = 1
} }
export function y(p, [p1, { p2 }], ...p3) { export function y(p, [p1, { p2 }], ...p3) {
...@@ -25,7 +37,7 @@ export function y(p, [p1, { p2 }], ...p3) { ...@@ -25,7 +37,7 @@ export function y(p, [p1, { p2 }], ...p3) {
} }
async function action() { async function action() {
"use server"; 'use server'
const f17 = 1 const f17 = 1
......
import deleteFromDb from 'db' import deleteFromDb from 'db'
export function Item(product,foo ,bar) { export function Item(product, foo, bar) {
async function deleteItem() { async function deleteItem() {
"use server"; 'use server'
await deleteFromDb(product.id,product?.foo,product.bar.baz,product[foo, bar]); await deleteFromDb(
product.id,
product?.foo,
product.bar.baz,
product[(foo, bar)]
)
} }
return <Button action={deleteItem}>Delete</Button>; return <Button action={deleteItem}>Delete</Button>
} }
async function myAction(a, b, c) { async function myAction(a, b, c) {
// comment // comment
"use strict"; 'use strict'
"use server"; 'use server'
console.log('a') console.log('a')
} }
export default function Page() { export default function Page() {
return <Button action={myAction}>Delete</Button>; return <Button action={myAction}>Delete</Button>
} }
/* __next_internal_action_entry_do_not_use__ $$ACTION_0 */ async function myAction(a, b, c) { /* __next_internal_action_entry_do_not_use__ $$ACTION_0 */ async function myAction(a, b, c) {
// comment // comment
"use strict"; 'use strict';
console.log('a'); console.log('a');
} }
myAction.$$typeof = Symbol.for("react.server.reference"); myAction.$$typeof = Symbol.for("react.server.reference");
......
// app/send.ts // app/send.ts
"use server"; 'use server'
async function foo () {} async function foo() {}
export { foo } export { foo }
async function bar() {} async function bar() {}
......
let shouldBeRemoved = 'should be removed' let shouldBeRemoved = 'should be removed'
export function removeFunction() { export function removeFunction() {
console.log(shouldBeRemoved); console.log(shouldBeRemoved)
} }
let shouldBeKept = 'should be kept' let shouldBeKept = 'should be kept'
......
...@@ -5,12 +5,13 @@ export async function keep() { ...@@ -5,12 +5,13 @@ export async function keep() {
let shouldBeRemoved = 'should be removed' let shouldBeRemoved = 'should be removed'
export function removeFunction() { export function removeFunction() {
console.log(shouldBeRemoved); console.log(shouldBeRemoved)
} }
export let removeVarDeclaration = 'should be removed' export let removeVarDeclaration = 'should be removed'
export let removeVarDeclarationUndefined // should also be removed export let removeVarDeclarationUndefined // should also be removed
export let multipleDecl = 'should be removed', keep1 = 'should be kept' export let multipleDecl = 'should be removed',
keep1 = 'should be kept'
export let keep2 = 'should be kept' export let keep2 = 'should be kept'
export class RemoveClass { export class RemoveClass {
...@@ -23,13 +24,13 @@ let x = 'x' ...@@ -23,13 +24,13 @@ let x = 'x'
let y = 'y' let y = 'y'
// This should be removed // This should be removed
export {x, y as z} export { x, y as z }
let keep3 = 'should be kept' let keep3 = 'should be kept'
let asKeep = 'should be kept' let asKeep = 'should be kept'
let removeNamed = 'should be removed' let removeNamed = 'should be removed'
export {keep3, asKeep as keep4, removeNamed} export { keep3, asKeep as keep4, removeNamed }
export default function removeDefault() { export default function removeDefault() {
console.log('should be removed') console.log('should be removed')
......
export async function getServerSideProps({ query }) { export async function getServerSideProps({ query }) {
return { props: { prop: query.prop } }; return { props: { prop: query.prop } }
} }
export default function GspPage({ prop }) { export default function GspPage({ prop }) {
return <div id="prop">{prop}</div>; return <div id="prop">{prop}</div>
} }
export const revalidateInSeconds = 5 * 60; export const revalidateInSeconds = 5 * 60
export const getStaticProps = async () => { export const getStaticProps = async () => {
return { return {
props: {}, props: {},
revalidate: revalidateInSeconds, revalidate: revalidateInSeconds,
}; }
}; }
export default function Home({}) { export default function Home({}) {
return ( return (
......
import { useState, useEffect } from 'react' import { useState, useEffect } from 'react'
import { Root, Children, JSXMemberExpression, AttributeValue, AttributeJSX, ValueInRender, ValueInEffect, UnusedInRender } from '../' import {
Root,
Children,
JSXMemberExpression,
AttributeValue,
AttributeJSX,
ValueInRender,
ValueInEffect,
UnusedInRender,
} from '../'
export default function Test() { export default function Test() {
const [x, setX] = useState(ValueInRender.value) const [x, setX] = useState(ValueInRender.value)
...@@ -33,6 +42,6 @@ export async function getStaticProps() { ...@@ -33,6 +42,6 @@ export async function getStaticProps() {
// this import reference should be removed // this import reference should be removed
UnusedInRender.value, UnusedInRender.value,
], ],
} },
} }
} }
import mixed from 'esm'; import mixed from 'esm'
console.log(mixed.foo)
console.log(mixed.foo); module.exports = mixed
module.exports = mixed;
\ No newline at end of file
export default 1 export default 1
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, '__esModule', { value: true })
export default 1 export default 1
console.log("__esModule") console.log('__esModule')
Object.defineProperty({}, '__esModule', { value: true }) Object.defineProperty({}, '__esModule', { value: true })
Object.defineProperty() Object.defineProperty()
import css from 'styled-jsx/css'; import css from 'styled-jsx/css'
export default css` export default css`
@media (max-width: 870px) { @media (max-width: 870px) {
...@@ -7,4 +7,4 @@ export default css` ...@@ -7,4 +7,4 @@ export default css`
display: none; display: none;
} }
} }
`; `
\ No newline at end of file
import fs from 'fs' import fs from 'fs'
import other from 'other' import other from 'other'
...@@ -15,7 +13,6 @@ export async function getStaticProps() { ...@@ -15,7 +13,6 @@ export async function getStaticProps() {
class Foo {} class Foo {}
export default function Home() { export default function Home() {
return <div /> return <div />
} }
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