forked from gatsbyjs/gatsby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(gatsby): remove unused vars in remove api plugin (gatsbyjs#33476)
- Loading branch information
Showing
6 changed files
with
214 additions
and
0 deletions.
There are no files selected for viewing
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
35 changes: 35 additions & 0 deletions
35
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import * as fs from "fs" | ||
|
||
const { fetch, Response } = require('node-fetch'); | ||
const unusedReference = fs.readFileSync('./myfile.json'); | ||
const usedReference = 'used reference'; | ||
|
||
module.exports = function () { | ||
const x = new Response({}) | ||
|
||
return usedReference | ||
} | ||
|
||
exports.getServerData = async function getServerData() { | ||
const data = await fetch('https://example.com'); | ||
const file = fs.readFileSync('./unknown.tmp.json', 'utf8') | ||
|
||
return { | ||
props: { | ||
file, | ||
} | ||
} | ||
} | ||
|
||
exports.config = function config() { | ||
return { | ||
pageContext: { | ||
env: 'test', | ||
unusedReference, | ||
}, | ||
} | ||
} | ||
|
||
exports.anotherFunction = function anotherFunction() { | ||
return "test" | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/gatsby/src/utils/babel/__tests__/fixtures/remove-apis/exports/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,14 @@ | ||
const { | ||
Response | ||
} = require('node-fetch'); | ||
|
||
const usedReference = 'used reference'; | ||
|
||
module.exports = function () { | ||
const x = new Response({}); | ||
return usedReference; | ||
}; | ||
|
||
exports.anotherFunction = function anotherFunction() { | ||
return "test"; | ||
}; |
55 changes: 55 additions & 0 deletions
55
packages/gatsby/src/utils/babel/__tests__/fixtures/remove-apis/references/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,55 @@ | ||
import { fetch, Response } from 'node-fetch'; | ||
import something from 'my-import' | ||
import * as fs from "fs" | ||
|
||
const usedReference = 'my cool ref'; | ||
const unusedReference = 'I hope to be removed'; | ||
const { x, y } = require('some-import'); | ||
|
||
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 = () => { }; | ||
} | ||
|
||
export async function getServerData() { | ||
const data = await fetch('https://example.com'); | ||
const file = fs.readFileSync('./unknown.tmp.json', 'utf8') | ||
renderPage(); | ||
anotherSelfReferencedOne(); | ||
|
||
return { | ||
props: { | ||
x, | ||
y, | ||
file, | ||
data: await data.json(), | ||
unusedReference, | ||
test: something(), | ||
} | ||
|
||
} | ||
} | ||
|
||
export function config() { | ||
return { | ||
pageContext: { | ||
env: 'test', | ||
unusedReference, | ||
}, | ||
} | ||
} | ||
|
||
export function anotherFunction() { | ||
return "test" | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/gatsby/src/utils/babel/__tests__/fixtures/remove-apis/references/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,15 @@ | ||
import { Response } from 'node-fetch'; | ||
const usedReference = 'my cool ref'; | ||
export default function () { | ||
const x = new Response({}); | ||
anotherSelfReferencedOne(); | ||
return usedReference; | ||
} // such a structure is being generated by regenerator-runtime | ||
|
||
function anotherSelfReferencedOne() { | ||
anotherSelfReferencedOne = () => {}; | ||
} | ||
|
||
export function anotherFunction() { | ||
return "test"; | ||
} |
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