-
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.
Adds a codemod for `object.assign`. This also changes behaviour of `removeImport` to consider _all_ require calls with the target source, rather than only those which are directly call expressions.
- Loading branch information
Showing
16 changed files
with
159 additions
and
4 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,38 @@ | ||
import jscodeshift from 'jscodeshift'; | ||
import { removeImport } 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: 'object.assign', | ||
transform: ({ file }) => { | ||
const j = jscodeshift; | ||
const root = j(file.source); | ||
|
||
const { identifier } = removeImport('object.assign', root, j); | ||
|
||
root | ||
.find(j.CallExpression, { | ||
callee: { | ||
name: identifier, | ||
}, | ||
}) | ||
.replaceWith(({ node }) => { | ||
return j.callExpression( | ||
j.memberExpression(j.identifier('Object'), j.identifier('assign')), | ||
node.arguments, | ||
); | ||
}); | ||
|
||
return root.toSource(options); | ||
}, | ||
}; | ||
} |
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,8 @@ | ||
Object.assign({}, {foo: 303}, {bar: 808}); | ||
|
||
Object.assign({}, {}); | ||
|
||
const foo = {}; | ||
const bar = {}; | ||
|
||
Object.assign(foo, bar); |
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,10 @@ | ||
const assign = require('object.assign').getPolyfill(); | ||
|
||
assign({}, {foo: 303}, {bar: 808}); | ||
|
||
assign({}, {}); | ||
|
||
const foo = {}; | ||
const bar = {}; | ||
|
||
assign(foo, bar); |
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,8 @@ | ||
Object.assign({}, {foo: 303}, {bar: 808}); | ||
|
||
Object.assign({}, {}); | ||
|
||
const foo = {}; | ||
const bar = {}; | ||
|
||
Object.assign(foo, bar); |
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,8 @@ | ||
Object.assign({}, {foo: 303}, {bar: 808}); | ||
|
||
Object.assign({}, {}); | ||
|
||
const foo = {}; | ||
const bar = {}; | ||
|
||
Object.assign(foo, bar); |
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,10 @@ | ||
const assign = require('object.assign').shim(); | ||
|
||
assign({}, {foo: 303}, {bar: 808}); | ||
|
||
assign({}, {}); | ||
|
||
const foo = {}; | ||
const bar = {}; | ||
|
||
assign(foo, bar); |
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,8 @@ | ||
Object.assign({}, {foo: 303}, {bar: 808}); | ||
|
||
Object.assign({}, {}); | ||
|
||
const foo = {}; | ||
const bar = {}; | ||
|
||
Object.assign(foo, bar); |
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,8 @@ | ||
Object.assign({}, {foo: 303}, {bar: 808}); | ||
|
||
Object.assign({}, {}); | ||
|
||
const foo = {}; | ||
const bar = {}; | ||
|
||
Object.assign(foo, bar); |
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,10 @@ | ||
const assign = require('object.assign'); | ||
|
||
assign({}, {foo: 303}, {bar: 808}); | ||
|
||
assign({}, {}); | ||
|
||
const foo = {}; | ||
const bar = {}; | ||
|
||
assign(foo, bar); |
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,8 @@ | ||
Object.assign({}, {foo: 303}, {bar: 808}); | ||
|
||
Object.assign({}, {}); | ||
|
||
const foo = {}; | ||
const bar = {}; | ||
|
||
Object.assign(foo, bar); |
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,8 @@ | ||
Object.assign({}, {foo: 303}, {bar: 808}); | ||
|
||
Object.assign({}, {}); | ||
|
||
const foo = {}; | ||
const bar = {}; | ||
|
||
Object.assign(foo, bar); |
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,10 @@ | ||
import assign from 'object.assign'; | ||
|
||
assign({}, {foo: 303}, {bar: 808}); | ||
|
||
assign({}, {}); | ||
|
||
const foo = {}; | ||
const bar = {}; | ||
|
||
assign(foo, bar); |
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,8 @@ | ||
Object.assign({}, {foo: 303}, {bar: 808}); | ||
|
||
Object.assign({}, {}); | ||
|
||
const foo = {}; | ||
const bar = {}; | ||
|
||
Object.assign(foo, bar); |
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,11 @@ | ||
/** | ||
* @typedef {import('../../types.js').Codemod} Codemod | ||
* @typedef {import('../../types.js').CodemodOptions} CodemodOptions | ||
*/ | ||
/** | ||
* @param {CodemodOptions} [options] | ||
* @returns {Codemod} | ||
*/ | ||
export default function _default(options?: import("../../types.js").CodemodOptions | undefined): Codemod; | ||
export type Codemod = import("../../types.js").Codemod; | ||
export type CodemodOptions = import("../../types.js").CodemodOptions; |