11'use strict' ;
22
3+ const {
4+ ObjectPrototypeHasOwnProperty,
5+ } = primordials ;
36const {
47 validateBoolean,
58 validateOneOf,
@@ -12,7 +15,6 @@ const { assertTypeScript,
1215 isUnderNodeModules,
1316 kEmptyObject } = require ( 'internal/util' ) ;
1417const {
15- ERR_INTERNAL_ASSERTION ,
1618 ERR_INVALID_TYPESCRIPT_SYNTAX ,
1719 ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING ,
1820 ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX ,
@@ -55,15 +57,16 @@ function parseTypeScript(source, options) {
5557 * Amaro v0.3.0 (from SWC v1.10.7) throws an object with `message` and `code` properties.
5658 * It allows us to distinguish between invalid syntax and unsupported syntax.
5759 */
58- switch ( error . code ) {
60+ switch ( error ? .code ) {
5961 case 'UnsupportedSyntax' :
6062 throw new ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX ( error . message ) ;
6163 case 'InvalidSyntax' :
6264 throw new ERR_INVALID_TYPESCRIPT_SYNTAX ( error . message ) ;
6365 default :
64- // SWC will throw strings when something goes wrong.
65- // Check if has the `message` property or treat it as a string.
66- throw new ERR_INTERNAL_ASSERTION ( error . message ?? error ) ;
66+ // SWC may throw strings when something goes wrong.
67+ if ( typeof error === 'string' ) { assert . fail ( error ) ; }
68+ assert ( error != null && ObjectPrototypeHasOwnProperty ( error , 'message' ) ) ;
69+ assert . fail ( error . message ) ;
6770 }
6871 }
6972}
0 commit comments