Skip to content

Commit 9bab1b4

Browse files
committed
process: add process.features.typescript
1 parent 7c76fa0 commit 9bab1b4

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

lib/internal/bootstrap/node.js

+15
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,21 @@ ObjectDefineProperty(process, 'features', {
319319
}
320320

321321
const { emitWarning, emitWarningSync } = require('internal/process/warning');
322+
const { getOptionValue } = require('internal/options');
323+
324+
let kTypeStrippingMode;
325+
ObjectDefineProperty(process.features, 'typescript', {
326+
__proto__: null,
327+
get() {
328+
return kTypeStrippingMode ??= (
329+
getOptionValue('--experimental-transform-types') ? 'transform' :
330+
getOptionValue('--experimental-strip-types') ? 'strip' : ''
331+
);
332+
},
333+
configurable: false,
334+
enumerable: true,
335+
});
336+
322337
process.emitWarning = emitWarning;
323338
internalBinding('process_methods').setEmitWarningSync(emitWarningSync);
324339

test/es-module/test-typescript.mjs

+25
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,28 @@ test('execute a TypeScript file with CommonJS syntax requiring .mts with require
313313
match(result.stdout, /Hello, TypeScript!/);
314314
strictEqual(result.code, 0);
315315
});
316+
317+
test('expect process.features.typescript to be \'strip\' when --experimental-strip-types', async () => {
318+
const result = await spawnPromisified(process.execPath, [
319+
'--experimental-strip-types',
320+
'-p', 'process.features.typescript',
321+
]);
322+
323+
strictEqual(result.stdout, 'strip\n');
324+
strictEqual(result.code, 0);
325+
strictEqual(process.features.typescript, false);
326+
});
327+
328+
test('expect process.features.typescript to be \'transform\' when --experimental-transform-types', async () => {
329+
const result = await spawnPromisified(process.execPath, [
330+
'--experimental-transform-types',
331+
'-p', 'process.features.typescript',
332+
]);
333+
334+
strictEqual(result.stdout, 'transform\n');
335+
strictEqual(result.code, 0);
336+
});
337+
338+
test('expect process.features.typescript to be \'\' without type-stripping', async () => {
339+
strictEqual(process.features.typescript, '');
340+
});

test/parallel/test-process-features.js

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ assert.deepStrictEqual(keys, new Set([
1515
'tls_ocsp',
1616
'tls',
1717
'cached_builtins',
18+
'typescript',
1819
]));
1920

2021
for (const key of keys) {

0 commit comments

Comments
 (0)