| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8eae0d3 commit 4050f68
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1968,6 +1968,19 @@ added: v0.5.3 | |||
| 1968 | 1968 | ||
| 1969 | 1969 | A boolean value that is `true` if the current Node.js build includes support for SNI in TLS. | |
| 1970 | 1970 | ||
| 1971 | + ## `process.features.typescript` | ||
| 1972 | + | ||
| 1973 | + <!-- YAML | ||
| 1974 | + added: REPLACEME | ||
| 1975 | + --> | ||
| 1976 | + | ||
| 1977 | + > Stability: 1.0 - Early development | ||
| 1978 | + | ||
| 1979 | + * {boolean|string} | ||
| 1980 | + | ||
| 1981 | + A value that is `"strip"` if Node.js is run with `--experimental-strip-types`, | ||
| 1982 | + `"transform"` if Node.js is run with `--experimental-transform-types`, and `false` otherwise. | ||
| 1983 | + | ||
| 1971 | 1984 | ## `process.features.uv` | |
| 1972 | 1985 | ||
| 1973 | 1986 | <!-- YAML | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -319,6 +319,29 @@ ObjectDefineProperty(process, 'features', { | |||
| 319 | 319 | } | |
| 320 | 320 | ||
| 321 | 321 | const { emitWarning, emitWarningSync } = require('internal/process/warning'); | |
| 322 | + const { getOptionValue } = require('internal/options'); | ||
| 323 | + | ||
| 324 | + let kTypeStrippingMode = null; | ||
| 325 | + // This must be a getter, as getOptionValue does not work | ||
| 326 | + // before bootstrapping. | ||
| 327 | + ObjectDefineProperty(process.features, 'typescript', { | ||
| 328 | + __proto__: null, | ||
| 329 | + get() { | ||
| 330 | + if (kTypeStrippingMode === null) { | ||
| 331 | + if (getOptionValue('--experimental-transform-types')) { | ||
| 332 | + kTypeStrippingMode = 'transform'; | ||
| 333 | + } else if (getOptionValue('--experimental-strip-types')) { | ||
| 334 | + kTypeStrippingMode = 'strip'; | ||
| 335 | + } else { | ||
| 336 | + kTypeStrippingMode = false; | ||
| 337 | + } | ||
| 338 | + } | ||
| 339 | + return kTypeStrippingMode; | ||
| 340 | + }, | ||
| 341 | + configurable: true, | ||
| 342 | + enumerable: true, | ||
| 343 | + }); | ||
| 344 | + | ||
| 322 | 345 | process.emitWarning = emitWarning; | |
| 323 | 346 | internalBinding('process_methods').setEmitWarningSync(emitWarningSync); | |
| 324 | 347 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -354,6 +354,34 @@ test('execute a TypeScript test mocking module', { skip: isWindows && process.ar | |||
| 354 | 354 | strictEqual(result.code, 0); | |
| 355 | 355 | }); | |
| 356 | 356 | ||
| 357 | + test('expect process.features.typescript to be \'strip\' when --experimental-strip-types', async () => { | ||
| 358 | + const result = await spawnPromisified(process.execPath, [ | ||
| 359 | + '--no-warnings', | ||
| 360 | + '--experimental-strip-types', | ||
| 361 | + '-p', 'process.features.typescript', | ||
| 362 | + ]); | ||
| 363 | + | ||
| 364 | + strictEqual(result.stderr, ''); | ||
| 365 | + strictEqual(result.stdout, 'strip\n'); | ||
| 366 | + strictEqual(result.code, 0); | ||
| 367 | + }); | ||
| 368 | + | ||
| 369 | + test('expect process.features.typescript to be \'transform\' when --experimental-transform-types', async () => { | ||
| 370 | + const result = await spawnPromisified(process.execPath, [ | ||
| 371 | + '--no-warnings', | ||
| 372 | + '--experimental-transform-types', | ||
| 373 | + '-p', 'process.features.typescript', | ||
| 374 | + ]); | ||
| 375 | + | ||
| 376 | + strictEqual(result.stderr, ''); | ||
| 377 | + strictEqual(result.stdout, 'transform\n'); | ||
| 378 | + strictEqual(result.code, 0); | ||
| 379 | + }); | ||
| 380 | + | ||
| 381 | + test('expect process.features.typescript to be false without type-stripping', async () => { | ||
| 382 | + strictEqual(process.features.typescript, false); | ||
| 383 | + }); | ||
| 384 | + | ||
| 357 | 385 | test('execute a TypeScript file with union types', async () => { | |
| 358 | 386 | const result = await spawnPromisified(process.execPath, [ | |
| 359 | 387 | '--experimental-strip-types', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,20 +3,22 @@ | |||
| 3 | 3 | require('../common'); | |
| 4 | 4 | const assert = require('assert'); | |
| 5 | 5 | ||
| 6 | - const keys = new Set(Object.keys(process.features)); | ||
| 6 | + const actualKeys = new Set(Object.keys(process.features)); | ||
| 7 | + const expectedKeys = new Map([ | ||
| 8 | + ['inspector', ['boolean']], | ||
| 9 | + ['debug', ['boolean']], | ||
| 10 | + ['uv', ['boolean']], | ||
| 11 | + ['ipv6', ['boolean']], | ||
| 12 | + ['tls_alpn', ['boolean']], | ||
| 13 | + ['tls_sni', ['boolean']], | ||
| 14 | + ['tls_ocsp', ['boolean']], | ||
| 15 | + ['tls', ['boolean']], | ||
| 16 | + ['cached_builtins', ['boolean']], | ||
| 17 | + ['typescript', ['boolean', 'string']], | ||
| 18 | + ]); | ||
| 7 | 19 | ||
| 8 | - assert.deepStrictEqual(keys, new Set([ | ||
| 9 | - 'inspector', | ||
| 10 | - 'debug', | ||
| 11 | - 'uv', | ||
| 12 | - 'ipv6', | ||
| 13 | - 'tls_alpn', | ||
| 14 | - 'tls_sni', | ||
| 15 | - 'tls_ocsp', | ||
| 16 | - 'tls', | ||
| 17 | - 'cached_builtins', | ||
| 18 | - ])); | ||
| 20 | + assert.deepStrictEqual(actualKeys, new Set(expectedKeys.keys())); | ||
| 19 | 21 | ||
| 20 | - for (const key of keys) { | ||
| 21 | - assert.strictEqual(typeof process.features[key], 'boolean'); | ||
| 22 | + for (const [key, expected] of expectedKeys) { | ||
| 23 | + assert.ok(expected.includes(typeof process.features[key]), `typeof process.features.${key} is not one of [${expected.join(', ')}]`); | ||
| 22 | 24 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments