diff --git a/lib/util.js b/lib/util.js index e3f3b11bda8333..d8230148d6d8e9 100644 --- a/lib/util.js +++ b/lib/util.js @@ -72,6 +72,8 @@ const { defineLazyProperties, } = require('internal/util'); +const { getOptionValue } = require('internal/options'); + let abortController; function lazyAbortController() { @@ -338,3 +340,8 @@ defineLazyProperties( 'internal/mime', ['MIMEType', 'MIMEParams'], ); + +if (getOptionValue('--experimental-strip-types')) { + const { tsParse } = require('internal/modules/helpers'); + module.exports.stripTypescriptTypes = tsParse; +} diff --git a/test/fixtures/test-util-stripTypescriptTypes.js b/test/fixtures/test-util-stripTypescriptTypes.js new file mode 100644 index 00000000000000..ab664e015f97cb --- /dev/null +++ b/test/fixtures/test-util-stripTypescriptTypes.js @@ -0,0 +1,6 @@ +'use strict'; + +const assert = require('assert'); +const util = require('util'); + +assert.strictEqual(util.stripTypescriptTypes('let s: string'), 'let s '); diff --git a/test/parallel/test-util-stripTypescriptTypes.js b/test/parallel/test-util-stripTypescriptTypes.js new file mode 100644 index 00000000000000..81b0860e096918 --- /dev/null +++ b/test/parallel/test-util-stripTypescriptTypes.js @@ -0,0 +1,19 @@ +'use strict'; + +const { skip, spawnPromisified } = require('../common'); +const fixtures = require('../common/fixtures'); +const { strictEqual } = require('node:assert'); +const { test } = require('node:test'); + +if (!process.config.variables.node_use_amaro) skip('Requires Amaro'); + +test('util.stripTypescriptTypes', async () => { + const result = await spawnPromisified(process.execPath, [ + '--experimental-strip-types', + fixtures.path('test-util-stripTypescriptTypes.js'), + ]); + + strictEqual(result.stdout, ''); + strictEqual(result.stderr, ''); + strictEqual(result.code, 0); +});