mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
feat: add support for --experimental-transform-types (#49881)
* feat: add support for `--experimental-transform-types` Co-authored-by: Niklas Wenzel <dev@nikwen.de> * chore: add tests Co-authored-by: Niklas Wenzel <dev@nikwen.de> * docs: add `--experimental-transform-types` to docs Co-authored-by: Niklas Wenzel <dev@nikwen.de> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Niklas Wenzel <dev@nikwen.de>
This commit is contained in:
@@ -345,6 +345,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.
|
||||
|
||||
@@ -412,6 +412,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
7
spec/fixtures/type-stripping/basic.ts
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import { app } from 'electron/main';
|
||||
|
||||
const logMessage = (message: string): void => console.log(message);
|
||||
|
||||
logMessage('running');
|
||||
|
||||
app.exit(0);
|
||||
9
spec/fixtures/type-stripping/transform-types-node.ts
vendored
Normal file
9
spec/fixtures/type-stripping/transform-types-node.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
enum Test {
|
||||
A,
|
||||
B,
|
||||
C,
|
||||
}
|
||||
|
||||
console.log(Test.A);
|
||||
|
||||
process.exit(0);
|
||||
11
spec/fixtures/type-stripping/transform-types.ts
vendored
Normal file
11
spec/fixtures/type-stripping/transform-types.ts
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import { app } from 'electron/main';
|
||||
|
||||
enum Test {
|
||||
A,
|
||||
B,
|
||||
C,
|
||||
}
|
||||
|
||||
console.log(Test.A);
|
||||
|
||||
app.exit(0);
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user