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
7 changed files
with
295 additions
and
139 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
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 |
---|---|---|
@@ -1,77 +1,67 @@ | ||
import {outdent} from 'outdent'; | ||
import {test} from './utils/test'; | ||
|
||
const MESSAGE_ID_MISSING_MESSAGE = 'constructorMissingMessage'; | ||
const MESSAGE_ID_EMPTY_MESSAGE = 'emptyMessage'; | ||
|
||
const emptyStringError = { | ||
messageId: MESSAGE_ID_EMPTY_MESSAGE | ||
}; | ||
|
||
const noMessageError = { | ||
messageId: MESSAGE_ID_MISSING_MESSAGE | ||
}; | ||
|
||
test({ | ||
// TODO: Check how should the last two tests work on default parserOptions | ||
testerOptions: { | ||
env: { | ||
es6: true | ||
}, | ||
parserOptions: undefined | ||
}, | ||
valid: [ | ||
'throw new Error(\'error\')', | ||
'throw new TypeError(\'error\')', | ||
'throw new MyCustomError(\'error\')', | ||
'throw new MyCustomError()', | ||
'throw generateError()', | ||
'throw new Error(lineNumber=2)', | ||
'throw new Error([])', | ||
'throw foo()', | ||
'throw err', | ||
'throw 1', | ||
outdent` | ||
const err = TypeError('error'); | ||
throw err; | ||
`, | ||
// Should not check other argument | ||
'new Error("message", 0, 0)', | ||
// We don't know the value | ||
'new Error(foo)', | ||
'new Error(...foo)', | ||
// #915, not a issue anymore, we don't track `ThrowStatement` | ||
outdent` | ||
/* global x */ | ||
const a = x; | ||
throw x; | ||
` | ||
], | ||
|
||
invalid: [ | ||
{ | ||
code: 'throw new Error()', | ||
errors: [noMessageError] | ||
}, | ||
{ | ||
code: 'throw Error()', | ||
errors: [noMessageError] | ||
}, | ||
{ | ||
code: 'throw new Error(\'\')', | ||
errors: [emptyStringError] | ||
}, | ||
{ | ||
code: outdent` | ||
const err = new Error(); | ||
throw err; | ||
`, | ||
errors: [noMessageError] | ||
}, | ||
{ | ||
code: outdent` | ||
let err = 1; | ||
err = new Error(); | ||
throw err; | ||
`, | ||
errors: [noMessageError] | ||
}, | ||
{ | ||
code: outdent` | ||
let err = new Error(); | ||
err = 1; | ||
throw err; | ||
`, | ||
errors: [noMessageError] | ||
} | ||
] | ||
}); | ||
|
||
test.visualize([ | ||
'throw new Error()', | ||
'throw Error()', | ||
'throw new Error(\'\')', | ||
'throw new Error(``)', | ||
outdent` | ||
const err = new Error(); | ||
throw err; | ||
`, | ||
outdent` | ||
let err = 1; | ||
err = new Error(); | ||
throw err; | ||
`, | ||
outdent` | ||
let err = new Error(); | ||
err = 1; | ||
throw err; | ||
`, | ||
'const foo = new TypeError()', | ||
'const foo = new SyntaxError()', | ||
outdent` | ||
const errorMessage = Object.freeze({errorMessage: 1}).errorMessage; | ||
throw new Error(errorMessage) | ||
`, | ||
'throw new Error([])', | ||
'throw new Error([foo])', | ||
'throw new Error([0][0])', | ||
'throw new Error({})', | ||
'throw new Error({foo})', | ||
'throw new Error({foo: 0}.foo)', | ||
'throw new Error(lineNumber=2)', | ||
'const error = new RangeError;' | ||
]); |
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
Oops, something went wrong.