* Performs type-stripping to TypeScript source code. * @param {string} code TypeScript code to parse. * @param {TransformOptions} options The configuration for type stripping. * @returns {string} The stripped TypeScript code.
(code, options = kEmptyObject)
| 89 | * @returns {string} The stripped TypeScript code. |
| 90 | */ |
| 91 | function stripTypeScriptTypes(code, options = kEmptyObject) { |
| 92 | emitExperimentalWarning('stripTypeScriptTypes'); |
| 93 | validateString(code, 'code'); |
| 94 | validateObject(options, 'options'); |
| 95 | |
| 96 | const { |
| 97 | sourceMap = false, |
| 98 | sourceUrl = '', |
| 99 | } = options; |
| 100 | let { mode = 'strip' } = options; |
| 101 | validateOneOf(mode, 'options.mode', ['strip']); |
| 102 | validateString(sourceUrl, 'options.sourceUrl'); |
| 103 | if (mode === 'strip') { |
| 104 | validateOneOf(sourceMap, 'options.sourceMap', [false, undefined]); |
| 105 | // Rename mode from 'strip' to 'strip-only'. |
| 106 | // The reason is to match `process.features.typescript` which returns `strip`, |
| 107 | // but the parser expects `strip-only`. |
| 108 | mode = 'strip-only'; |
| 109 | } |
| 110 | |
| 111 | return processTypeScriptCode(code, { |
| 112 | mode, |
| 113 | filename: sourceUrl, |
| 114 | }); |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * @typedef {object} TypeScriptOptions |
no test coverage detected
searching dependent graphs…