-
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.
- Loading branch information
Showing
14 changed files
with
205 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
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.forEach', | ||
transform: ({ file }) => { | ||
const j = jscodeshift; | ||
const root = j(file.source); | ||
|
||
const dirty = transformArrayMethod( | ||
'array.prototype.forEach', | ||
'forEach', | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
var assert = require('assert'); | ||
|
||
assert.deepEqual( | ||
[1, 2, 3].forEach(function (x) { | ||
return x >= 2; | ||
}), | ||
[2, 3], | ||
); | ||
assert.deepEqual( | ||
[1, 2, 3].forEach(function (x) { | ||
return x <= 2; | ||
}), | ||
[1, 2], | ||
); |
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 @@ | ||
var forEach = require('array.prototype.forEach'); | ||
var assert = require('assert'); | ||
|
||
assert.deepEqual( | ||
forEach([1, 2, 3], function (x) { | ||
return x >= 2; | ||
}), | ||
[2, 3], | ||
); | ||
assert.deepEqual( | ||
forEach([1, 2, 3], function (x) { | ||
return x <= 2; | ||
}), | ||
[1, 2], | ||
); |
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 @@ | ||
var assert = require('assert'); | ||
|
||
assert.deepEqual( | ||
[1, 2, 3].forEach(function (x) { | ||
return x >= 2; | ||
}), | ||
[2, 3], | ||
); | ||
assert.deepEqual( | ||
[1, 2, 3].forEach(function (x) { | ||
return x <= 2; | ||
}), | ||
[1, 2], | ||
); |
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 @@ | ||
var assert = require('assert'); | ||
|
||
assert.deepEqual( | ||
[1, 2, 3].forEach(function (x) { | ||
return x >= 2; | ||
}), | ||
[2, 3], | ||
); | ||
assert.deepEqual( | ||
[1, 2, 3].forEach(function (x) { | ||
return x <= 2; | ||
}), | ||
[1, 2], | ||
); |
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 forEach from 'array.prototype.forEach'; | ||
var assert = require('assert'); | ||
|
||
assert.deepEqual( | ||
forEach([1, 2, 3], function (x) { | ||
return x >= 2; | ||
}), | ||
[2, 3], | ||
); | ||
assert.deepEqual( | ||
forEach([1, 2, 3], function (x) { | ||
return x <= 2; | ||
}), | ||
[1, 2], | ||
); |
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 @@ | ||
var assert = require('assert'); | ||
|
||
assert.deepEqual( | ||
[1, 2, 3].forEach(function (x) { | ||
return x >= 2; | ||
}), | ||
[2, 3], | ||
); | ||
assert.deepEqual( | ||
[1, 2, 3].forEach(function (x) { | ||
return x <= 2; | ||
}), | ||
[1, 2], | ||
); |
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 @@ | ||
var assert = require('assert'); | ||
|
||
assert.deepEqual( | ||
[1, 2, 3].forEach(function (x) { | ||
return x >= 2; | ||
}), | ||
[2, 3], | ||
); | ||
assert.deepEqual( | ||
[1, 2, 3].forEach(function (x) { | ||
return x <= 2; | ||
}), | ||
[1, 2], | ||
); |
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 @@ | ||
var banana = require('array.prototype.forEach'); | ||
var assert = require('assert'); | ||
|
||
assert.deepEqual( | ||
banana([1, 2, 3], function (x) { | ||
return x >= 2; | ||
}), | ||
[2, 3], | ||
); | ||
assert.deepEqual( | ||
banana([1, 2, 3], function (x) { | ||
return x <= 2; | ||
}), | ||
[1, 2], | ||
); |
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 @@ | ||
var assert = require('assert'); | ||
|
||
assert.deepEqual( | ||
[1, 2, 3].forEach(function (x) { | ||
return x >= 2; | ||
}), | ||
[2, 3], | ||
); | ||
assert.deepEqual( | ||
[1, 2, 3].forEach(function (x) { | ||
return x <= 2; | ||
}), | ||
[1, 2], | ||
); |
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 @@ | ||
var assert = require('assert'); | ||
|
||
assert.deepEqual( | ||
[1, 2, 3].forEach(function (x) { | ||
return x >= 2; | ||
}), | ||
[2, 3], | ||
); | ||
assert.deepEqual( | ||
[1, 2, 3].forEach(function (x) { | ||
return x <= 2; | ||
}), | ||
[1, 2], | ||
); |
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 banana from 'array.prototype.forEach'; | ||
var assert = require('assert'); | ||
|
||
assert.deepEqual( | ||
banana([1, 2, 3], function (x) { | ||
return x >= 2; | ||
}), | ||
[2, 3], | ||
); | ||
assert.deepEqual( | ||
banana([1, 2, 3], function (x) { | ||
return x <= 2; | ||
}), | ||
[1, 2], | ||
); |
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 @@ | ||
var assert = require('assert'); | ||
|
||
assert.deepEqual( | ||
[1, 2, 3].forEach(function (x) { | ||
return x >= 2; | ||
}), | ||
[2, 3], | ||
); | ||
assert.deepEqual( | ||
[1, 2, 3].forEach(function (x) { | ||
return x <= 2; | ||
}), | ||
[1, 2], | ||
); |