Skip to content

Commit 635144d

Browse files
fix: ensure arguments are reversed only if not already in correct order (#33)
* fix: ensure arguments are reversed only if not already in correct order * test: add new test --------- Co-authored-by: Sebastian Beltran <[email protected]>
1 parent a4f474a commit 635144d

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

transforms/__testfixtures__/v4-deprecated-signatures/redirect.input.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ app.get("/", function (req, response) {
1111
response.redirect("/other-page", 301);
1212
});
1313

14+
app.get("/", function (req, res) {
15+
res.redirect(301, "/other-page");
16+
});
17+
18+
app.get("/", function (req, res) {
19+
res.redirect("/other-page");
20+
});
21+
1422
app.get("/", function (req, res) {
1523
redirect(301, "/other-page");
1624
});

transforms/__testfixtures__/v4-deprecated-signatures/redirect.output.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ app.get("/", function (req, response) {
1111
response.redirect(301, "/other-page");
1212
});
1313

14+
app.get("/", function (req, res) {
15+
res.redirect(301, "/other-page");
16+
});
17+
18+
app.get("/", function (req, res) {
19+
res.redirect("/other-page");
20+
});
21+
1422
app.get("/", function (req, res) {
1523
redirect(301, "/other-page");
1624
});

transforms/v4-deprecated-signatures.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,11 @@ export default function transformer(file: FileInfo, _api: API): string {
124124
},
125125
})
126126
.map((path) => {
127-
if (path.value.arguments.length === 2) {
128-
path.value.arguments.reverse()
127+
const args = path.value.arguments
128+
129+
// if its already in the correct order, dont reverse
130+
if (args.length === 2 && args[0]?.type !== 'NumericLiteral') {
131+
args.reverse()
129132
}
130133

131134
return path

0 commit comments

Comments
 (0)