Compare commits

...

3 Commits

Author SHA1 Message Date
Niklas Wenzel
415a0a6197 docs: add --experimental-transform-types to docs 2026-02-06 23:34:05 +01:00
Niklas Wenzel
a7af53d292 chore: add tests 2026-02-06 23:15:19 +01:00
Niklas Wenzel
b4599a2cbc feat: add support for --experimental-transform-types 2026-02-06 23:15:10 +01:00
6 changed files with 55 additions and 0 deletions

View File

@@ -354,6 +354,11 @@ Affects the default output directory of [v8.setHeapSnapshotNearHeapLimit](https:
Disable exposition of [Navigator API][] on the global scope from Node.js.
### `--experimental-transform-types`
Enables the [transformation](https://nodejs.org/api/typescript.html#type-stripping)
of TypeScript-only syntax into JavaScript code.
## Chromium Flags
There isn't a documented list of all Chromium switches, but there are a few ways to find them.

View File

@@ -413,6 +413,7 @@ bool IsAllowedOption(const std::string_view option) {
"--inspect-port",
"--inspect-publish-uid",
"--experimental-network-inspection",
"--experimental-transform-types",
});
// This should be aligned with what's possible to set via the process object.

7
spec/fixtures/type-stripping/basic.ts vendored Normal file
View File

@@ -0,0 +1,7 @@
import { app } from 'electron/main';
const logMessage = (message: string): void => console.log(message);
logMessage('running');
app.exit(0);

View File

@@ -0,0 +1,9 @@
enum Test {
A,
B,
C,
}
console.log(Test.A);
process.exit(0);

View File

@@ -0,0 +1,11 @@
import { app } from 'electron/main';
enum Test {
A,
B,
C,
}
console.log(Test.A);
app.exit(0);

View File

@@ -1030,4 +1030,26 @@ describe('node feature', () => {
});
});
});
describe('type stripping', () => {
it('strips TypeScript types automatically in the main process', async () => {
const child = childProcess.spawn(process.execPath, [path.join(fixtures, 'type-stripping', 'basic.ts')]);
const [code] = await once(child, 'exit');
expect(code).to.equal(0);
});
it('will not transform TypeScript types without --experimental-transform-types', async () => {
const child = childProcess.spawn(process.execPath, [path.join(fixtures, 'type-stripping', 'transform-types-node.ts')], {
env: { ELECTRON_RUN_AS_NODE: 'true' }
});
const [code] = await once(child, 'exit');
expect(code).to.not.equal(0);
});
it('transforms TypeScript types with --experimental-transform-types', async () => {
const child = childProcess.spawn(process.execPath, ['--experimental-transform-types', path.join(fixtures, 'type-stripping', 'transform-types.ts')]);
const [code] = await once(child, 'exit');
expect(code).to.equal(0);
});
});
});