MCPcopy Index your code
hub / github.com/nodejs/node / parseTypeScript

Function parseTypeScript

lib/internal/modules/typescript.js:46–71  ·  view source on GitHub ↗

* * @param {string} source the source code * @param {object} options the options to pass to the parser * @returns {TransformOutput} an object with a `code` property.

(source, options)

Source from the content-addressed store, hash-verified

44 * @returns {TransformOutput} an object with a `code` property.
45 */
46function parseTypeScript(source, options) {
47 const parse = loadTypeScriptParser();
48 try {
49 return parse(source, options);
50 } catch (error) {
51 /**
52 * Amaro v0.3.0 (from SWC v1.10.7) throws an object with `message` and `code` properties.
53 * It allows us to distinguish between invalid syntax and unsupported syntax.
54 */
55 switch (error?.code) {
56 case 'UnsupportedSyntax': {
57 const unsupportedSyntaxError = new ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX(error.message);
58 throw decorateErrorWithSnippet(unsupportedSyntaxError, error); /* node-do-not-add-exception-line */
59 }
60 case 'InvalidSyntax': {
61 const invalidSyntaxError = new ERR_INVALID_TYPESCRIPT_SYNTAX(error.message);
62 throw decorateErrorWithSnippet(invalidSyntaxError, error); /* node-do-not-add-exception-line */
63 }
64 default:
65 // SWC may throw strings when something goes wrong.
66 if (typeof error === 'string') { assert.fail(error); }
67 assert(error != null && ObjectPrototypeHasOwnProperty(error, 'message'));
68 assert.fail(error.message);
69 }
70 }
71}
72
73/**
74 *

Callers 1

processTypeScriptCodeFunction · 0.85

Calls 4

decorateErrorWithSnippetFunction · 0.85
parseFunction · 0.50
assertFunction · 0.50
failMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…