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 }
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
x You can not use getStaticProps or getStaticPaths with getServerSideProps. To use SSG, please remove getServerSideProps x You can not use getStaticProps or getStaticPaths with getServerSideProps. To use SSG, please remove getServerSideProps
,-[input.js:1:1] ,-[input.js:1:1]
1 | const getStaticProps = async () => {} 1 | const getStaticProps = async () => {}
2 | export { a as getServerSideProps } 2 | 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';
return null; export default function() {
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 | }
`---- `----
...@@ -5,17 +5,17 @@ import { createContext } from 'react' ...@@ -5,17 +5,17 @@ import { createContext } from 'react'
import { useEffect, useImperativeHandle } from 'react' import { useEffect, useImperativeHandle } from 'react'
import { import {
Component, Component,
createFactory, createFactory,
PureComponent, PureComponent,
useDeferredValue, useDeferredValue,
useInsertionEffect, useInsertionEffect,
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;
} }
...@@ -29,71 +29,71 @@ ...@@ -29,71 +29,71 @@
x NEXT_RSC_ERR_REACT_API: Component x NEXT_RSC_ERR_REACT_API: Component
,-[input.js:7:1] ,-[input.js:7:1]
7 | import { 7 | import {
8 | Component, 8 | Component,
: ^^^^^^^^^ : ^^^^^^^^^
9 | createFactory, 9 | createFactory,
`---- `----
x NEXT_RSC_ERR_REACT_API: createFactory x NEXT_RSC_ERR_REACT_API: createFactory
,-[input.js:8:1] ,-[input.js:8:1]
8 | Component, 8 | Component,
9 | createFactory, 9 | createFactory,
: ^^^^^^^^^^^^^ : ^^^^^^^^^^^^^
10 | PureComponent, 10 | PureComponent,
`---- `----
x NEXT_RSC_ERR_REACT_API: PureComponent x NEXT_RSC_ERR_REACT_API: PureComponent
,-[input.js:9:1] ,-[input.js:9:1]
9 | createFactory, 9 | createFactory,
10 | PureComponent, 10 | PureComponent,
: ^^^^^^^^^^^^^ : ^^^^^^^^^^^^^
11 | useDeferredValue, 11 | useDeferredValue,
`---- `----
x NEXT_RSC_ERR_REACT_API: useDeferredValue x NEXT_RSC_ERR_REACT_API: useDeferredValue
,-[input.js:10:1] ,-[input.js:10:1]
10 | PureComponent, 10 | PureComponent,
11 | useDeferredValue, 11 | useDeferredValue,
: ^^^^^^^^^^^^^^^^ : ^^^^^^^^^^^^^^^^
12 | useInsertionEffect, 12 | useInsertionEffect,
`---- `----
x NEXT_RSC_ERR_REACT_API: useInsertionEffect x NEXT_RSC_ERR_REACT_API: useInsertionEffect
,-[input.js:11:1] ,-[input.js:11:1]
11 | useDeferredValue, 11 | useDeferredValue,
12 | useInsertionEffect, 12 | useInsertionEffect,
: ^^^^^^^^^^^^^^^^^^ : ^^^^^^^^^^^^^^^^^^
13 | useLayoutEffect, 13 | useLayoutEffect,
`---- `----
x NEXT_RSC_ERR_REACT_API: useLayoutEffect x NEXT_RSC_ERR_REACT_API: useLayoutEffect
,-[input.js:12:1] ,-[input.js:12:1]
12 | useInsertionEffect, 12 | useInsertionEffect,
13 | useLayoutEffect, 13 | useLayoutEffect,
: ^^^^^^^^^^^^^^^ : ^^^^^^^^^^^^^^^
14 | useReducer, 14 | useReducer,
`---- `----
x NEXT_RSC_ERR_REACT_API: useReducer x NEXT_RSC_ERR_REACT_API: useReducer
,-[input.js:13:1] ,-[input.js:13:1]
13 | useLayoutEffect, 13 | useLayoutEffect,
14 | useReducer, 14 | useReducer,
: ^^^^^^^^^^ : ^^^^^^^^^^
15 | useRef, 15 | useRef,
`---- `----
x NEXT_RSC_ERR_REACT_API: useRef x NEXT_RSC_ERR_REACT_API: useRef
,-[input.js:14:1] ,-[input.js:14:1]
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(
loading: () => null, () => handleImport(import('./components/hello')),
ssr: false, {
}); loading: () => null,
\ No newline at end of file ssr: false,
}
)
...@@ -4,4 +4,4 @@ function About(props) { ...@@ -4,4 +4,4 @@ function About(props) {
return <h3>My AMP About Page!</h3> return <h3>My AMP About Page!</h3>
} }
export default About export default About
\ No newline at end of file
...@@ -4,4 +4,4 @@ function About(props) { ...@@ -4,4 +4,4 @@ function About(props) {
return <h3>My AMP About Page!</h3> return <h3>My AMP About Page!</h3>
} }
export default About export default About
\ 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-custom="2"> <div data-test-id="1" data-custom="1a">
<h1 data-testid="3">Hello World!</h1> <div data-custom="2">
<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"> return <div data-test-id="1">
<div> <div>
<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-custom="2"> <div data-test-id="1" data-custom="1a">
<h1 data-testid="3" nested={() => (<div data-testid="4">nested</div>)}>Hello World!</h1> <div data-custom="2">
<h1 data-testid="3" nested={() => <div data-testid="4">nested</div>}>
Hello World!
</h1>
</div>
</div> </div>
</div> )
} }
export default function Home() { export default function Home() {
return <div data-custom="1a"> return <div data-custom="1a">
<div data-custom="2"> <div data-custom="2">
<h1 nested={()=><div>nested</div>}>Hello World!</h1> <h1 nested={()=><div>nested</div>}>
</div> Hello World!
</div>; </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
......
...@@ -25,12 +25,12 @@ const variableMutation = graphql` ...@@ -25,12 +25,12 @@ const variableMutation = graphql`
` `
commitMutation( commitMutation(
environment, environment,
graphql` graphql`
query InputUsedInFunctionCallMutation { query InputUsedInFunctionCallMutation {
someMutation someMutation
} }
` `
) )
function SomeMutationComponent() { function SomeMutationComponent() {
......
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'
...@@ -8,4 +8,4 @@ console.log('side effect') ...@@ -8,4 +8,4 @@ console.log('side effect')
const foo = async () => { const foo = async () => {
console.log('function body') console.log('function body')
} }
export { foo } export { foo }
\ No newline at end of file
import deleteFromDb from 'db' 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>
} }
\ No newline at end of file
"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
\ No newline at end of file
...@@ -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 }
...@@ -2,4 +2,4 @@ ...@@ -2,4 +2,4 @@
export async function foo() { export async function foo() {
async function bar() {} async function bar() {}
} }
\ No newline at end of file
'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) => {
async function g(y, ...z) { async function g(y, ...z) {
'use server' 'use server'
return x + y + z[0] return x + y + z[0]
} }
} }
const g = (x) => { const g = (x) => {
f = async (y, ...z) => { f = async (y, ...z) => {
'use server' 'use server'
return x + y + z[0] return x + y + z[0]
} }
} }
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>
</> </>
)
} }
...@@ -4,17 +4,25 @@ export function Item({ id1 , id2 }) { ...@@ -4,17 +4,25 @@ export function Item({ id1 , id2 }) {
const v2 = id2; const v2 = id2;
return <> return <>
<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}>
<Button action={$$ACTION_2 = async function() { Delete
</Button>
<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>
</> </>
)
} }
/* __next_internal_action_entry_do_not_use__ $$ACTION_1 */ export function Item({ value }) { /* __next_internal_action_entry_do_not_use__ $$ACTION_1 */ export function Item({ value }) {
return <> return <>
<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>
} }
\ No newline at end of file
...@@ -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 (
'use server' <Foo
return x + y + z action={validator(async function (z) {
})} /> 'use server'
return x + y + z
})}
/>
)
} }
validator(async () => { validator(async () => {
'use server' 'use server'
}) })
another(validator(async () => { another(
'use server' validator(async () => {
})) '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')
} }
\ No newline at end of file
"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>
} }
\ No newline at end of file
...@@ -4,61 +4,73 @@ const f3 = 1 ...@@ -4,61 +4,73 @@ 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) {
const f2 = 1 const f2 = 1
const f11 = 1 const f11 = 1
const f19 = 1 const f19 = 1
if (true) { if (true) {
const f8 = 1 const f8 = 1
} }
async function action() {
"use server";
const f17 = 1 async function action() {
'use server'
if (true) { const f17 = 1
const f18 = 1
const f19 = 1
}
console.log( if (true) {
f, const f18 = 1
f1, const f19 = 1
f2,
f3,
f4,
f5,
f6,
f7,
f8,
f2(f9),
f12,
f11,
f16.x,
f17,
f18,
p,
p1,
p2,
p3,
g19,
g20,
globalThis
)
} }
return <Button action={action}>Delete</Button> console.log(
f,
f1,
f2,
f3,
f4,
f5,
f6,
f7,
f8,
f2(f9),
f12,
f11,
f16.x,
f17,
f18,
p,
p1,
p2,
p3,
g19,
g20,
globalThis
)
}
return <Button action={action}>Delete</Button>
} }
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,
return <Button action={deleteItem}>Delete</Button>; product?.foo,
} product.bar.baz,
\ No newline at end of file product[(foo, bar)]
)
}
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>
} }
\ No newline at end of file
/* __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");
...@@ -10,4 +10,4 @@ myAction.$$with_bound = false; ...@@ -10,4 +10,4 @@ myAction.$$with_bound = false;
export const $$ACTION_0 = myAction; export const $$ACTION_0 = myAction;
export default function Page() { export default function Page() {
return <Button action={myAction}>Delete</Button>; return <Button action={myAction}>Delete</Button>;
} }
\ No newline at end of file
// 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'
export default function shouldBeKept() { export default function shouldBeKept() {
console.log(shouldBeKept) console.log(shouldBeKept)
} }
\ No newline at end of file
...@@ -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>
} }
\ No newline at end of file
export default function Home({}) { export default function Home({}) {
return ( return (
<div> <div>
<p>Hello World</p> <p>Hello World</p>
</div> </div>
) )
} }
export async function getStaticProps() { export async function getStaticProps() {
await import('_http_common').then((http) => console.log(http)) await import('_http_common').then((http) => console.log(http))
return { return {
props: {}, props: {},
} }
} }
\ No newline at end of file
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 (
<div> <div>
<p>Hello World</p> <p>Hello World</p>
</div> </div>
) )
} }
\ No newline at end of file
export default function Home() { export default function Home() {
return <h1>Hello World!</h1> return <h1>Hello World!</h1>
} }
\ No newline at end of file
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