Skip to content

Commit 6b61bec

Browse files
committed
lib: add util.stripTypescriptTypes
1 parent a4f609f commit 6b61bec

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

lib/util.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ const {
7272
defineLazyProperties,
7373
} = require('internal/util');
7474

75+
const { getOptionValue } = require('internal/options');
76+
7577
let abortController;
7678

7779
function lazyAbortController() {
@@ -338,3 +340,8 @@ defineLazyProperties(
338340
'internal/mime',
339341
['MIMEType', 'MIMEParams'],
340342
);
343+
344+
if (getOptionValue('--experimental-strip-types')) {
345+
const { tsParse } = require('internal/modules/helpers');
346+
module.exports.stripTypescriptTypes = tsParse;
347+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
'use strict';
2+
3+
const assert = require('assert');
4+
const util = require('util');
5+
6+
assert.strictEqual(util.stripTypescriptTypes('let s: string'), 'let s ');
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { skip, spawnPromisified } from '../common/index.mjs';
2+
import * as fixtures from '../common/fixtures.mjs';
3+
import { strictEqual } from 'node:assert';
4+
import { test } from 'node:test';
5+
6+
if (!process.config.variables.node_use_amaro) skip('Requires Amaro');
7+
8+
test('util.stripTypescriptTypes', async () => {
9+
const result = await spawnPromisified(process.execPath, [
10+
'--experimental-strip-types',
11+
fixtures.path('test-util-stripTypescriptTypes.js'),
12+
]);
13+
14+
strictEqual(result.stdout, '');
15+
strictEqual(result.stderr, '');
16+
strictEqual(result.code, 0);
17+
});

0 commit comments

Comments
 (0)