-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(gatsby): only remove unused code when apis got removed (#33527)
- Loading branch information
Showing
11 changed files
with
99 additions
and
7 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
packages/gatsby/src/utils/babel/__tests__/fixtures/remove-apis/default/input.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { fetch, Response } from 'node-fetch'; | ||
|
||
const usedReference = 'my cool ref'; | ||
const unusedReference = 'I hope to be removed'; | ||
|
||
export default function () { | ||
const x = new Response({}) | ||
anotherSelfReferencedOne(); | ||
|
||
return usedReference | ||
} | ||
|
||
// such a structure is being generated by regenerator-runtime | ||
function renderPage() { | ||
renderPage = () => { }; | ||
} | ||
|
||
function anotherSelfReferencedOne() { | ||
anotherSelfReferencedOne = () => { }; | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/gatsby/src/utils/babel/__tests__/fixtures/remove-apis/default/output.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { fetch, Response } from 'node-fetch'; | ||
const usedReference = 'my cool ref'; | ||
const unusedReference = 'I hope to be removed'; | ||
export default function () { | ||
const x = new Response({}); | ||
anotherSelfReferencedOne(); | ||
return usedReference; | ||
} // such a structure is being generated by regenerator-runtime | ||
|
||
function renderPage() { | ||
renderPage = () => {}; | ||
} | ||
|
||
function anotherSelfReferencedOne() { | ||
anotherSelfReferencedOne = () => {}; | ||
} |
3 changes: 0 additions & 3 deletions
3
packages/gatsby/src/utils/babel/__tests__/fixtures/remove-apis/exports/input.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
packages/gatsby/src/utils/babel/__tests__/fixtures/remove-apis/jsx/input.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** @jsx jsx */ | ||
import { jsx } from 'react' | ||
|
||
export default function MyComponent() { | ||
return <div>Hello World</div> | ||
} | ||
|
16 changes: 16 additions & 0 deletions
16
packages/gatsby/src/utils/babel/__tests__/fixtures/remove-apis/jsx/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"presets": [ | ||
"@babel/preset-react" | ||
], | ||
"plugins": [ | ||
[ | ||
"../../../../babel-plugin-remove-api", | ||
{ | ||
"apis": [ | ||
"getServerData", | ||
"config" | ||
] | ||
} | ||
] | ||
] | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/gatsby/src/utils/babel/__tests__/fixtures/remove-apis/jsx/output.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** @jsx jsx */ | ||
import { jsx } from 'react'; | ||
export default function MyComponent() { | ||
return jsx("div", null, "Hello World"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,4 @@ | |
} | ||
] | ||
] | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/gatsby/src/utils/babel/__tests__/fixtures/remove-apis/react/input.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import React from 'react'; | ||
|
||
export default function MyComponent() { | ||
return <div>Hello World</div> | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/gatsby/src/utils/babel/__tests__/fixtures/remove-apis/react/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"presets": [ | ||
"@babel/preset-react" | ||
], | ||
"plugins": [ | ||
[ | ||
"../../../../babel-plugin-remove-api", | ||
{ | ||
"apis": [ | ||
"getServerData", | ||
"config" | ||
] | ||
} | ||
] | ||
] | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/gatsby/src/utils/babel/__tests__/fixtures/remove-apis/react/output.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import React from 'react'; | ||
export default function MyComponent() { | ||
return /*#__PURE__*/React.createElement("div", null, "Hello World"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters