1
1
'use strict' ;
2
2
3
+ const {
4
+ ObjectPrototypeHasOwnProperty,
5
+ } = primordials ;
3
6
const {
4
7
validateBoolean,
5
8
validateOneOf,
@@ -12,7 +15,6 @@ const { assertTypeScript,
12
15
isUnderNodeModules,
13
16
kEmptyObject } = require ( 'internal/util' ) ;
14
17
const {
15
- ERR_INTERNAL_ASSERTION ,
16
18
ERR_INVALID_TYPESCRIPT_SYNTAX ,
17
19
ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING ,
18
20
ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX ,
@@ -55,15 +57,16 @@ function parseTypeScript(source, options) {
55
57
* Amaro v0.3.0 (from SWC v1.10.7) throws an object with `message` and `code` properties.
56
58
* It allows us to distinguish between invalid syntax and unsupported syntax.
57
59
*/
58
- switch ( error . code ) {
60
+ switch ( error ? .code ) {
59
61
case 'UnsupportedSyntax' :
60
62
throw new ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX ( error . message ) ;
61
63
case 'InvalidSyntax' :
62
64
throw new ERR_INVALID_TYPESCRIPT_SYNTAX ( error . message ) ;
63
65
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 ) ;
67
70
}
68
71
}
69
72
}
0 commit comments