diff --git a/test/snapshots/throw-new-error.mjs.md b/test/snapshots/throw-new-error.mjs.md new file mode 100644 index 0000000000..5de5a7da48 --- /dev/null +++ b/test/snapshots/throw-new-error.mjs.md @@ -0,0 +1,467 @@ +# Snapshot report for `test/throw-new-error.mjs` + +The actual snapshot is saved in `throw-new-error.mjs.snap`. + +Generated by [AVA](https://avajs.dev). + +## invalid(1): throw Error() + +> Input + + `␊ + 1 | throw Error()␊ + ` + +> Output + + `␊ + 1 | throw new Error()␊ + ` + +> Error 1/1 + + `␊ + > 1 | throw Error()␊ + | ^^^^^^^ Use \`new\` when throwing an error.␊ + ` + +## invalid(2): throw (Error)() + +> Input + + `␊ + 1 | throw (Error)()␊ + ` + +> Output + + `␊ + 1 | throw new (Error)()␊ + ` + +> Error 1/1 + + `␊ + > 1 | throw (Error)()␊ + | ^^^^^^^^^ Use \`new\` when throwing an error.␊ + ` + +## invalid(3): throw lib.Error() + +> Input + + `␊ + 1 | throw lib.Error()␊ + ` + +> Output + + `␊ + 1 | throw new lib.Error()␊ + ` + +> Error 1/1 + + `␊ + > 1 | throw lib.Error()␊ + | ^^^^^^^^^^^ Use \`new\` when throwing an error.␊ + ` + +## invalid(4): throw lib.mod.Error() + +> Input + + `␊ + 1 | throw lib.mod.Error()␊ + ` + +> Output + + `␊ + 1 | throw new lib.mod.Error()␊ + ` + +> Error 1/1 + + `␊ + > 1 | throw lib.mod.Error()␊ + | ^^^^^^^^^^^^^^^ Use \`new\` when throwing an error.␊ + ` + +## invalid(5): throw lib[mod].Error() + +> Input + + `␊ + 1 | throw lib[mod].Error()␊ + ` + +> Output + + `␊ + 1 | throw new lib[mod].Error()␊ + ` + +> Error 1/1 + + `␊ + > 1 | throw lib[mod].Error()␊ + | ^^^^^^^^^^^^^^^^ Use \`new\` when throwing an error.␊ + ` + +## invalid(6): throw (lib.mod).Error() + +> Input + + `␊ + 1 | throw (lib.mod).Error()␊ + ` + +> Output + + `␊ + 1 | throw new (lib.mod).Error()␊ + ` + +> Error 1/1 + + `␊ + > 1 | throw (lib.mod).Error()␊ + | ^^^^^^^^^^^^^^^^^ Use \`new\` when throwing an error.␊ + ` + +## invalid(7): throw Error('foo') + +> Input + + `␊ + 1 | throw Error('foo')␊ + ` + +> Output + + `␊ + 1 | throw new Error('foo')␊ + ` + +> Error 1/1 + + `␊ + > 1 | throw Error('foo')␊ + | ^^^^^^^^^^^^ Use \`new\` when throwing an error.␊ + ` + +## invalid(8): throw CustomError('foo') + +> Input + + `␊ + 1 | throw CustomError('foo')␊ + ` + +> Output + + `␊ + 1 | throw new CustomError('foo')␊ + ` + +> Error 1/1 + + `␊ + > 1 | throw CustomError('foo')␊ + | ^^^^^^^^^^^^^^^^^^ Use \`new\` when throwing an error.␊ + ` + +## invalid(9): throw FooBarBazError('foo') + +> Input + + `␊ + 1 | throw FooBarBazError('foo')␊ + ` + +> Output + + `␊ + 1 | throw new FooBarBazError('foo')␊ + ` + +> Error 1/1 + + `␊ + > 1 | throw FooBarBazError('foo')␊ + | ^^^^^^^^^^^^^^^^^^^^^ Use \`new\` when throwing an error.␊ + ` + +## invalid(10): throw ABCError('foo') + +> Input + + `␊ + 1 | throw ABCError('foo')␊ + ` + +> Output + + `␊ + 1 | throw new ABCError('foo')␊ + ` + +> Error 1/1 + + `␊ + > 1 | throw ABCError('foo')␊ + | ^^^^^^^^^^^^^^^ Use \`new\` when throwing an error.␊ + ` + +## invalid(11): throw Abc3Error('foo') + +> Input + + `␊ + 1 | throw Abc3Error('foo')␊ + ` + +> Output + + `␊ + 1 | throw new Abc3Error('foo')␊ + ` + +> Error 1/1 + + `␊ + > 1 | throw Abc3Error('foo')␊ + | ^^^^^^^^^^^^^^^^ Use \`new\` when throwing an error.␊ + ` + +## invalid(12): throw TypeError() + +> Input + + `␊ + 1 | throw TypeError()␊ + ` + +> Output + + `␊ + 1 | throw new TypeError()␊ + ` + +> Error 1/1 + + `␊ + > 1 | throw TypeError()␊ + | ^^^^^^^^^^^ Use \`new\` when throwing an error.␊ + ` + +## invalid(13): throw EvalError() + +> Input + + `␊ + 1 | throw EvalError()␊ + ` + +> Output + + `␊ + 1 | throw new EvalError()␊ + ` + +> Error 1/1 + + `␊ + > 1 | throw EvalError()␊ + | ^^^^^^^^^^^ Use \`new\` when throwing an error.␊ + ` + +## invalid(14): throw RangeError() + +> Input + + `␊ + 1 | throw RangeError()␊ + ` + +> Output + + `␊ + 1 | throw new RangeError()␊ + ` + +> Error 1/1 + + `␊ + > 1 | throw RangeError()␊ + | ^^^^^^^^^^^^ Use \`new\` when throwing an error.␊ + ` + +## invalid(15): throw ReferenceError() + +> Input + + `␊ + 1 | throw ReferenceError()␊ + ` + +> Output + + `␊ + 1 | throw new ReferenceError()␊ + ` + +> Error 1/1 + + `␊ + > 1 | throw ReferenceError()␊ + | ^^^^^^^^^^^^^^^^ Use \`new\` when throwing an error.␊ + ` + +## invalid(16): throw SyntaxError() + +> Input + + `␊ + 1 | throw SyntaxError()␊ + ` + +> Output + + `␊ + 1 | throw new SyntaxError()␊ + ` + +> Error 1/1 + + `␊ + > 1 | throw SyntaxError()␊ + | ^^^^^^^^^^^^^ Use \`new\` when throwing an error.␊ + ` + +## invalid(17): throw URIError() + +> Input + + `␊ + 1 | throw URIError()␊ + ` + +> Output + + `␊ + 1 | throw new URIError()␊ + ` + +> Error 1/1 + + `␊ + > 1 | throw URIError()␊ + | ^^^^^^^^^^ Use \`new\` when throwing an error.␊ + ` + +## invalid(18): throw (( URIError() )) + +> Input + + `␊ + 1 | throw (( URIError() ))␊ + ` + +> Output + + `␊ + 1 | throw (( new URIError() ))␊ + ` + +> Error 1/1 + + `␊ + > 1 | throw (( URIError() ))␊ + | ^^^^^^^^^^ Use \`new\` when throwing an error.␊ + ` + +## invalid(19): throw (( URIError ))() + +> Input + + `␊ + 1 | throw (( URIError ))()␊ + ` + +> Output + + `␊ + 1 | throw new (( URIError ))()␊ + ` + +> Error 1/1 + + `␊ + > 1 | throw (( URIError ))()␊ + | ^^^^^^^^^^^^^^^^ Use \`new\` when throwing an error.␊ + ` + +## invalid(20): throw getGlobalThis().Error() + +> Input + + `␊ + 1 | throw getGlobalThis().Error()␊ + ` + +> Output + + `␊ + 1 | throw new (getGlobalThis().Error)()␊ + ` + +> Error 1/1 + + `␊ + > 1 | throw getGlobalThis().Error()␊ + | ^^^^^^^^^^^^^^^^^^^^^^^ Use \`new\` when throwing an error.␊ + ` + +## invalid(21): throw utils.getGlobalThis().Error() + +> Input + + `␊ + 1 | throw utils.getGlobalThis().Error()␊ + ` + +> Output + + `␊ + 1 | throw new (utils.getGlobalThis().Error)()␊ + ` + +> Error 1/1 + + `␊ + > 1 | throw utils.getGlobalThis().Error()␊ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use \`new\` when throwing an error.␊ + ` + +## invalid(22): throw (( getGlobalThis().Error ))() + +> Input + + `␊ + 1 | throw (( getGlobalThis().Error ))()␊ + ` + +> Output + + `␊ + 1 | throw new (( getGlobalThis().Error ))()␊ + ` + +> Error 1/1 + + `␊ + > 1 | throw (( getGlobalThis().Error ))()␊ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use \`new\` when throwing an error.␊ + ` diff --git a/test/snapshots/throw-new-error.mjs.snap b/test/snapshots/throw-new-error.mjs.snap new file mode 100644 index 0000000000..740e4683ae Binary files /dev/null and b/test/snapshots/throw-new-error.mjs.snap differ diff --git a/test/throw-new-error.mjs b/test/throw-new-error.mjs index 882a5f44ee..52b6512066 100644 --- a/test/throw-new-error.mjs +++ b/test/throw-new-error.mjs @@ -2,10 +2,7 @@ import {getTester} from './utils/test.mjs'; const {test} = getTester(import.meta); -const messageId = 'throw-new-error'; -const errors = [{messageId}]; - -test({ +test.snapshot({ valid: [ 'throw new Error()', 'new Error()', @@ -33,115 +30,27 @@ test({ 'throw lib.getError()', ], invalid: [ - { - code: 'throw Error()', - output: 'throw new Error()', - errors, - }, - { - code: 'throw (Error)()', - output: 'throw new (Error)()', - errors, - }, - { - code: 'throw lib.Error()', - output: 'throw new lib.Error()', - errors, - }, - { - code: 'throw lib.mod.Error()', - output: 'throw new lib.mod.Error()', - errors, - }, - { - code: 'throw lib[mod].Error()', - output: 'throw new lib[mod].Error()', - errors, - }, - { - code: 'throw (lib.mod).Error()', - output: 'throw new (lib.mod).Error()', - errors, - }, - { - code: 'throw Error(\'foo\')', - output: 'throw new Error(\'foo\')', - errors, - }, - { - code: 'throw CustomError(\'foo\')', - output: 'throw new CustomError(\'foo\')', - errors, - }, - { - code: 'throw FooBarBazError(\'foo\')', - output: 'throw new FooBarBazError(\'foo\')', - errors, - }, - { - code: 'throw ABCError(\'foo\')', - output: 'throw new ABCError(\'foo\')', - errors, - }, - { - code: 'throw Abc3Error(\'foo\')', - output: 'throw new Abc3Error(\'foo\')', - errors, - }, - { - code: 'throw TypeError()', - output: 'throw new TypeError()', - errors, - }, - { - code: 'throw EvalError()', - output: 'throw new EvalError()', - errors, - }, - { - code: 'throw RangeError()', - output: 'throw new RangeError()', - errors, - }, - { - code: 'throw ReferenceError()', - output: 'throw new ReferenceError()', - errors, - }, - { - code: 'throw SyntaxError()', - output: 'throw new SyntaxError()', - errors, - }, - { - code: 'throw URIError()', - output: 'throw new URIError()', - errors, - }, - { - code: 'throw (( URIError() ))', - output: 'throw (( new URIError() ))', - errors, - }, - { - code: 'throw (( URIError ))()', - output: 'throw new (( URIError ))()', - errors, - }, - { - code: 'throw getGlobalThis().Error()', - output: 'throw new (getGlobalThis().Error)()', - errors, - }, - { - code: 'throw utils.getGlobalThis().Error()', - output: 'throw new (utils.getGlobalThis().Error)()', - errors, - }, - { - code: 'throw (( getGlobalThis().Error ))()', - output: 'throw new (( getGlobalThis().Error ))()', - errors, - }, + 'throw Error()', + 'throw (Error)()', + 'throw lib.Error()', + 'throw lib.mod.Error()', + 'throw lib[mod].Error()', + 'throw (lib.mod).Error()', + 'throw Error(\'foo\')', + 'throw CustomError(\'foo\')', + 'throw FooBarBazError(\'foo\')', + 'throw ABCError(\'foo\')', + 'throw Abc3Error(\'foo\')', + 'throw TypeError()', + 'throw EvalError()', + 'throw RangeError()', + 'throw ReferenceError()', + 'throw SyntaxError()', + 'throw URIError()', + 'throw (( URIError() ))', + 'throw (( URIError ))()', + 'throw getGlobalThis().Error()', + 'throw utils.getGlobalThis().Error()', + 'throw (( getGlobalThis().Error ))()', ], });