lib: add util.stripTypescriptTypes

This commit is contained in:
stagas 2024-08-08 13:05:46 +03:00
parent a4f609faf5
commit e310d28b99
3 changed files with 32 additions and 0 deletions

View File

@ -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;
}

View File

@ -0,0 +1,6 @@
'use strict';
const assert = require('assert');
const util = require('util');
assert.strictEqual(util.stripTypescriptTypes('let s: string'), 'let s ');

View File

@ -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);
});