8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 538e194 commit 9f99a6aCopy full SHA for 9f99a6a
lib/internal/modules/typescript.js
@@ -1,5 +1,8 @@
1
'use strict';
2
3
+const {
4
+ ObjectPrototypeHasOwnProperty,
5
+} = primordials;
6
const {
7
validateBoolean,
8
validateOneOf,
@@ -12,7 +15,6 @@ const { assertTypeScript,
12
15
isUnderNodeModules,
13
16
kEmptyObject } = require('internal/util');
14
17
- ERR_INTERNAL_ASSERTION,
18
ERR_INVALID_TYPESCRIPT_SYNTAX,
19
ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING,
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.
59
*/
- switch (error.code) {
60
+ switch (error?.code) {
61
case 'UnsupportedSyntax':
62
throw new ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX(error.message);
63
case 'InvalidSyntax':
64
throw new ERR_INVALID_TYPESCRIPT_SYNTAX(error.message);
65
default:
- // SWC will throw strings when something goes wrong.
- // Check if has the `message` property or treat it as a string.
66
- throw new ERR_INTERNAL_ASSERTION(error.message ?? error);
+ // 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);
70
}
71
72