-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from ajkl2533/array-fns-2
Add array.prototype codemods
- Loading branch information
Showing
54 changed files
with
169 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import jscodeshift from 'jscodeshift'; | ||
import { transformArrayMethod } from '../shared.js'; | ||
|
||
/** | ||
* @typedef {import('../../types.js').Codemod} Codemod | ||
* @typedef {import('../../types.js').CodemodOptions} CodemodOptions | ||
*/ | ||
|
||
/** | ||
* @param {CodemodOptions} [options] | ||
* @returns {Codemod} | ||
*/ | ||
export default function (options) { | ||
return { | ||
name: 'array.prototype.copywithin', | ||
transform: ({ file }) => { | ||
const j = jscodeshift; | ||
const root = j(file.source); | ||
|
||
const dirty = transformArrayMethod( | ||
'array.prototype.copywithin', | ||
'copyWithin', | ||
root, | ||
j, | ||
); | ||
|
||
return dirty ? root.toSource(options) : file.source; | ||
}, | ||
}; | ||
} |
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
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
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
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,30 @@ | ||
import jscodeshift from 'jscodeshift'; | ||
import { transformArrayMethod } from '../shared.js'; | ||
|
||
/** | ||
* @typedef {import('../../types.js').Codemod} Codemod | ||
* @typedef {import('../../types.js').CodemodOptions} CodemodOptions | ||
*/ | ||
|
||
/** | ||
* @param {CodemodOptions} [options] | ||
* @returns {Codemod} | ||
*/ | ||
export default function (options) { | ||
return { | ||
name: 'array.prototype.lastindexof', | ||
transform: ({ file }) => { | ||
const j = jscodeshift; | ||
const root = j(file.source); | ||
|
||
const dirty = transformArrayMethod( | ||
'array.prototype.lastindexof', | ||
'lastIndexOf', | ||
root, | ||
j, | ||
); | ||
|
||
return dirty ? root.toSource(options) : file.source; | ||
}, | ||
}; | ||
} |
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 @@ | ||
var assert = require('assert'); | ||
|
||
var arr = [1, 2, 3, 4, 5]; | ||
assert.deepEqual(arr.copyWithin(0, 3), [4, 5, 3, 4, 5]); | ||
assert.deepEqual(arr, [4, 5, 3, 4, 5]); |
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,6 @@ | ||
var copyWithin = require('array.prototype.copywithin'); | ||
var assert = require('assert'); | ||
|
||
var arr = [1, 2, 3, 4, 5]; | ||
assert.deepEqual(copyWithin(arr, 0, 3), [4, 5, 3, 4, 5]); | ||
assert.deepEqual(arr, [4, 5, 3, 4, 5]); |
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 @@ | ||
var assert = require('assert'); | ||
|
||
var arr = [1, 2, 3, 4, 5]; | ||
assert.deepEqual(arr.copyWithin(0, 3), [4, 5, 3, 4, 5]); | ||
assert.deepEqual(arr, [4, 5, 3, 4, 5]); |
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 @@ | ||
var assert = require('assert'); | ||
|
||
var arr = [1, 2, 3, 4, 5]; | ||
assert.deepEqual(arr.copyWithin(0, 3), [4, 5, 3, 4, 5]); | ||
assert.deepEqual(arr, [4, 5, 3, 4, 5]); |
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,6 @@ | ||
import banana from 'array.prototype.copywithin'; | ||
var assert = require('assert'); | ||
|
||
var arr = [1, 2, 3, 4, 5]; | ||
assert.deepEqual(banana(arr, 0, 3), [4, 5, 3, 4, 5]); | ||
assert.deepEqual(arr, [4, 5, 3, 4, 5]); |
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 @@ | ||
var assert = require('assert'); | ||
|
||
var arr = [1, 2, 3, 4, 5]; | ||
assert.deepEqual(arr.copyWithin(0, 3), [4, 5, 3, 4, 5]); | ||
assert.deepEqual(arr, [4, 5, 3, 4, 5]); |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...rray.prototype.findIndex/case-1/before.js → ...rray.prototype.findindex/case-1/before.js
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
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...rray.prototype.findIndex/case-2/before.js → ...rray.prototype.findindex/case-2/before.js
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
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...rray.prototype.findIndex/case-3/before.js → ...rray.prototype.findindex/case-3/before.js
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
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...rray.prototype.findIndex/case-4/before.js → ...rray.prototype.findindex/case-4/before.js
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
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
.../array.prototype.flatMap/case-1/before.js → .../array.prototype.flatmap/case-1/before.js
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
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
.../array.prototype.flatMap/case-2/before.js → .../array.prototype.flatmap/case-2/before.js
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
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
.../array.prototype.forEach/case-3/before.js → .../array.prototype.flatmap/case-3/before.js
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
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
.../array.prototype.flatMap/case-4/before.js → .../array.prototype.flatmap/case-4/before.js
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
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
.../array.prototype.forEach/case-1/before.js → .../array.prototype.foreach/case-1/before.js
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
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
.../array.prototype.forEach/case-2/before.js → .../array.prototype.foreach/case-2/before.js
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
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
.../array.prototype.flatMap/case-3/before.js → .../array.prototype.foreach/case-3/before.js
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
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
.../array.prototype.forEach/case-4/before.js → .../array.prototype.foreach/case-4/before.js
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
File renamed without changes.
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,6 @@ | ||
var assert = require('assert'); | ||
|
||
assert.equal([1, 2, 3].lastIndexOf(2), 1); | ||
assert.equal([1, 0, 1].lastIndexOf(1), 2); | ||
assert.equal([1, 2, 3].lastIndexOf(4), -1); | ||
assert.equal([NaN].lastIndexOf(NaN), -1); |
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 @@ | ||
var lastIndexOf = require('array.prototype.lastindexof'); | ||
var assert = require('assert'); | ||
|
||
assert.equal(lastIndexOf([1, 2, 3], 2), 1); | ||
assert.equal(lastIndexOf([1, 0, 1], 1), 2); | ||
assert.equal(lastIndexOf([1, 2, 3], 4), -1); | ||
assert.equal(lastIndexOf([NaN], NaN), -1); |
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,6 @@ | ||
var assert = require('assert'); | ||
|
||
assert.equal([1, 2, 3].lastIndexOf(2), 1); | ||
assert.equal([1, 0, 1].lastIndexOf(1), 2); | ||
assert.equal([1, 2, 3].lastIndexOf(4), -1); | ||
assert.equal([NaN].lastIndexOf(NaN), -1); |
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,6 @@ | ||
var assert = require('assert'); | ||
|
||
assert.equal([1, 2, 3].lastIndexOf(2), 1); | ||
assert.equal([1, 0, 1].lastIndexOf(1), 2); | ||
assert.equal([1, 2, 3].lastIndexOf(4), -1); | ||
assert.equal([NaN].lastIndexOf(NaN), -1); |
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 @@ | ||
import banana from 'array.prototype.lastindexof'; | ||
var assert = require('assert'); | ||
|
||
assert.equal(banana([1, 2, 3], 2), 1); | ||
assert.equal(banana([1, 0, 1], 1), 2); | ||
assert.equal(banana([1, 2, 3], 4), -1); | ||
assert.equal(banana([NaN], NaN), -1); |
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,6 @@ | ||
var assert = require('assert'); | ||
|
||
assert.equal([1, 2, 3].lastIndexOf(2), 1); | ||
assert.equal([1, 0, 1].lastIndexOf(1), 2); | ||
assert.equal([1, 2, 3].lastIndexOf(4), -1); | ||
assert.equal([NaN].lastIndexOf(NaN), -1); |
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 |
---|---|---|
@@ -1 +1,21 @@ | ||
// This file will contain the actual result of the codemod transformation after running the tests, this is expected to be equal to the `after.js` file. This file exists for easy debugging purposes. | ||
var assert = require('assert'); | ||
|
||
assert.deepEqual(Date, [ | ||
'Date', | ||
'Date.prototype.getFullYear', | ||
'Date.prototype.getMonth', | ||
'Date.prototype.getDate', | ||
'Date.prototype.getUTCDate', | ||
'Date.prototype.getUTCFullYear', | ||
'Date.prototype.getUTCMonth', | ||
'Date.prototype.toUTCString', | ||
'Date.prototype.toDateString', | ||
'Date.prototype.toString', | ||
'Date.prototype.toISOString', | ||
'Date.prototype.toJSON', | ||
'Date.now', | ||
'Date.parse', | ||
]); | ||
|
||
assert.ok(new Date() instanceof Date); | ||
assert.equal(typeof Date.now(), 'number'); |