Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,37 @@ import express from "express";
const app = express();

app.get("/", (req, res) => {});

app.del([""],() => {
myImportantLogic();
});

app.del([],() => {
myImportantLogic();
});

app.del(/d/,() => {
myImportantLogic();
});

app.del(() => {
myImportantLogic();
});

app.del(function () {
myImportantLogic();
});

app.del("/old", () => {
myImportantLogic();
});

function noModify() {
let a

app.del(a)
}

const myImportantLogic = () => {
console.log("making sure it's there");
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,37 @@ import express from "express";
const app = express();

app.get("/", (req, res) => {});

app.delete([""],() => {
myImportantLogic();
});

app.delete([],() => {
myImportantLogic();
});

app.delete(/d/,() => {
myImportantLogic();
});

app.del(() => {
myImportantLogic();
});

app.del(function () {
myImportantLogic();
});

app.delete("/old", () => {
myImportantLogic();
});

function noModify() {
let a

app.del(a)
}

const myImportantLogic = () => {
console.log("making sure it's there");
};
14 changes: 14 additions & 0 deletions transforms/__testfixtures__/v4-deprecated-signatures/json.input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ import express from "express";

const app = express();

app.get("/json", function (...arg) {
const [, res] = arg
res.json();
});

app.get("/json", function (...arg) {
const [, res] = arg
res.json({ user: "Username", isValid: true }, 200);
});

app.get("/json", function (req, res) {
res.json();
});

app.get("/json", function (req, res) {
res.json({ user: "Username", isValid: true }, 200);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ import express from "express";

const app = express();

app.get("/json", function (...arg) {
const [, res] = arg
res.json();
});

app.get("/json", function (...arg) {
const [, res] = arg
res.status(200).json({ user: "Username", isValid: true });
});

app.get("/json", function (req, res) {
res.json();
});

app.get("/json", function (req, res) {
res.status(200).json({ user: "Username", isValid: true });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import express from "express";

const app = express();

app.get("/json", function (req, res) {
res.json();
});

app.get("/jsonp", function (req, res) {
res.jsonp({ user: "Username", isValid: true }, 200);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import express from "express";

const app = express();

app.get("/json", function (req, res) {
res.json();
});

app.get("/jsonp", function (req, res) {
res.status(200).jsonp({ user: "Username", isValid: true });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ import { redirect } from "somelibrary";

const app = express();

app.get("/", function (...arg) {
const [, res] = arg
res.redirect();
});

app.get("/", function (...arg) {
const [, res] = arg
res.redirect("/other-page", 301);
});

app.get("/", function (req, res) {
res.redirect();
});

app.get("/", function (req, res) {
res.redirect("/other-page", 301);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ import { redirect } from "somelibrary";

const app = express();

app.get("/", function (...arg) {
const [, res] = arg
res.redirect();
});

app.get("/", function (...arg) {
const [, res] = arg
res.redirect(301, "/other-page");
});

app.get("/", function (req, res) {
res.redirect();
});

app.get("/", function (req, res) {
res.redirect(301, "/other-page");
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ const sharedSendFile = (res, next, fileName) => {
})
}

app.get('/file/:name', (req, res, next) => {
res.sendfile()
})

app.get('/file/:name', (req, res, next) => {
res.sendfile("file.txt")
})

app.get('/file/:name', (req, res, next) => {
const fileName = req.params.name

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ const sharedSendFile = (res, next, fileName) => {
})
}

app.get('/file/:name', (req, res, next) => {
res.sendFile()
})

app.get('/file/:name', (req, res, next) => {
res.sendFile("file.txt")
})

app.get('/file/:name', (req, res, next) => {
const fileName = req.params.name

Expand Down
14 changes: 14 additions & 0 deletions transforms/__testfixtures__/v4-deprecated-signatures/send.input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ import express from "express";

const app = express();

app.get("/send", function (...arg) {
const [, res] = arg
res.send();
});

app.get("/send", function (...arg) {
const [, res] = arg
res.send(200, true);
});

app.get("/send", function (req, res) {
res.send();
});

app.get("/send", function (req, res) {
res.send(200, { hello: "world" });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ import express from "express";

const app = express();

app.get("/send", function (...arg) {
const [, res] = arg
res.send();
});

app.get("/send", function (...arg) {
const [, res] = arg
res.status(200).send(true);
});

app.get("/send", function (req, res) {
res.send();
});

app.get("/send", function (req, res) {
res.status(200).send({ hello: "world" });
});
Expand Down
27 changes: 23 additions & 4 deletions transforms/v4-deprecated-signatures.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { API, ASTPath, FileInfo } from 'jscodeshift'
import { CallExpression, Identifier, callExpression, identifier, memberExpression, withParser } from 'jscodeshift'
import { CallExpression, callExpression, identifier, memberExpression, withParser } from 'jscodeshift'
import { recursiveParent } from '../utils/recursiveParent'

const separateStatusAndBody = (path: ASTPath<CallExpression>, calleePropertyName: string) => {
Expand Down Expand Up @@ -94,10 +94,29 @@ export default function transformer(file: FileInfo, _api: API): string {
})

parsedFile
.find(Identifier, {
name: 'del',
.find(CallExpression, {
callee: {
property: {
name: 'del',
},
},
})
.map((path) => {
const pathArguments = path.node.arguments

if (
pathArguments[0].type !== 'RegExpLiteral' &&
pathArguments[0].type !== 'StringLiteral' &&
pathArguments[0].type !== 'ArrayExpression'
)
return path

if (path.node.callee.type === 'MemberExpression' && path.node.callee.property.type === 'Identifier') {
path.node.callee.property.name = 'delete'
}

return path
})
.replaceWith(() => identifier('delete'))

parsedFile
.find(CallExpression, {
Expand Down