@@ -1564,65 +1564,6 @@ local scope, so the value `localVar` is changed. In this way
15641564`vm.runInThisContext()` is much like an [indirect `eval()` call][], e.g.
15651565`(0,eval)(' code' )`.
15661566
1567- ## `vm.stripTypeScriptTypes(code[, options])`
1568-
1569- <!-- YAML
1570- added: REPLACEME
1571- -->
1572-
1573- > Stability: 1.0 - Early development
1574-
1575- * `code` {string} The code to strip type annotations from.
1576- * `options` {Object}
1577- * `mode` {string} **Default:** `' strip- only' `. Possible values are:
1578- * `' strip- only' ` Only strip type annotations without performing the transformation of TypeScript features.
1579- * `' transform' ` Strip type annotations and transform TypeScript features to JavaScript.
1580- * `sourceMap` {boolean} **Default:** `false`. Only when `mode` is `' transform' `, if `true`, a source map
1581- will be generated for the transformed code.
1582- * `filename` {string} Only when `mode` is `' transform' `, specifies the filename used in the source map.
1583- * Returns: {string} The code with type annotations stripped.
1584-
1585- `vm.stripTypeScriptTypes()` removes type annotations from TypeScript code. It
1586- can be used to strip type annotations from TypeScript code before running it
1587- with `vm.runInContext()` or `vm.compileFunction()`.
1588- By default, it will throw an error if the code contains TypeScript features
1589- that require transformation such as `Enums`,
1590- see [type-stripping][] for more information.
1591- When mode is `' transform' `, it also transforms TypeScript features to JavaScript,
1592- see [transform TypeScript features][] for more information.
1593- When mode is `' strip- only' `, source maps are not generated, because locations are preserved.
1594- If `sourceMap` or `filename` is provided, when mode is `' strip- only' `, an error will be thrown.
1595-
1596- ```js
1597- const vm = require(' node: vm' );
1598-
1599- const code = `const a: number = 1;`;
1600- const strippedCode = vm.stripTypeScriptTypes(code);
1601- console.log(strippedCode);
1602- // Prints: const a = 1;
1603- ```
1604-
1605- When `mode` is `' transform' `, the code is transformed to JavaScript:
1606-
1607- ```js
1608- const vm = require(' node: vm' );
1609-
1610- const code = `
1611- namespace MathUtil {
1612- export const add = (a: number, b: number) => a + b;
1613- }`;
1614- const strippedCode = vm.stripTypeScriptTypes(code, { mode: ' transform' , sourceMap: true });
1615- console.log(strippedCode);
1616-
1617- // Prints:
1618- // var MathUtil;
1619- // (function(MathUtil) {
1620- // MathUtil.add = (a, b)=>a + b;
1621- // })(MathUtil || (MathUtil = {}));
1622-
1623- //# sourceMappingURL=data:application/json;base64, ...
1624- ```
1625-
16261567## Example: Running an HTTP server within a VM
16271568
16281569When using either [`script.runInThisContext()`][] or
@@ -2041,5 +1982,3 @@ const { Script, SyntheticModule } = require('node:vm');
20411982[global object]: https://es5.github.io/#x15.1
20421983[indirect ` eval ()` call]: https://es5.github.io/#x10.4.2
20431984[origin]: https://developer.mozilla.org/en-US/docs/Glossary/Origin
2044- [transform TypeScript features]: typescript.md#typescript-features
2045- [type-stripping]: typescript.md#type-stripping
0 commit comments