-
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
4 changed files
with
66 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,38 @@ | ||
import jscodeshift from 'jscodeshift'; | ||
import { removeImport, transformMathPolyfill } 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: 'es-aggregate-error', | ||
transform: ({ file }) => { | ||
const j = jscodeshift; | ||
const root = j(file.source); | ||
|
||
const { identifier } = removeImport('es-aggregate-error', root, j); | ||
|
||
const expressions = root.find(j.NewExpression, { | ||
callee: { | ||
type: 'Identifier', | ||
name: identifier, | ||
}, | ||
}); | ||
|
||
if (!expressions.length) return file.source; | ||
|
||
expressions.replaceWith(({ node }) => | ||
j.newExpression(j.identifier('AggregateError'), 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
var assert = require("assert"); | ||
|
||
var oneError = new RangeError("hi!"); | ||
var otherError = new EvalError("oops"); | ||
var error = new AggregateError([oneError, otherError], "this is two kinds of errors"); | ||
|
||
assert.deepEqual(error.errors, [oneError, otherError]); | ||
assert.equal(error.message, "this is two kinds of errors"); |
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,12 @@ | ||
var assert = require("assert"); | ||
var AggregateError = require("es-aggregate-error"); | ||
|
||
var oneError = new RangeError("hi!"); | ||
var otherError = new EvalError("oops"); | ||
var error = new AggregateError( | ||
[oneError, otherError], | ||
"this is two kinds of errors", | ||
); | ||
|
||
assert.deepEqual(error.errors, [oneError, otherError]); | ||
assert.equal(error.message, "this is two kinds of errors"); |
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 @@ | ||
var assert = require("assert"); | ||
|
||
var oneError = new RangeError("hi!"); | ||
var otherError = new EvalError("oops"); | ||
var error = new AggregateError([oneError, otherError], "this is two kinds of errors"); | ||
|
||
assert.deepEqual(error.errors, [oneError, otherError]); | ||
assert.equal(error.message, "this is two kinds of errors"); |