-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow free function exports in typewriter (#1379)
Typewriter does not allow free functions to be exported today. This PR enables exporting free functions. Required for aws/aws-cdk#31850. --------- Signed-off-by: github-actions <[email protected]> Co-authored-by: github-actions <[email protected]> Co-authored-by: Momo Kornher <[email protected]>
- Loading branch information
1 parent
12bebf9
commit 83ec1c3
Showing
4 changed files
with
58 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { FreeFunction, Module, TypeScriptRenderer } from '../src'; | ||
|
||
const renderer = new TypeScriptRenderer(); | ||
let scope: Module; | ||
|
||
beforeEach(() => { | ||
scope = new Module('typewriter.test'); | ||
}); | ||
|
||
describe('functions', () => { | ||
test('functions are implicitly not exported', () => { | ||
new FreeFunction(scope, { | ||
name: 'freeFunction', | ||
}); | ||
|
||
expect(renderer.render(scope)).toMatchInlineSnapshot(` | ||
"/* eslint-disable prettier/prettier, max-len */ | ||
// @ts-ignore TS6133 | ||
function freeFunction(): void;" | ||
`); | ||
}); | ||
|
||
test('functions can be explicitly exported', () => { | ||
new FreeFunction(scope, { | ||
name: 'freeFunction', | ||
export: true, | ||
}); | ||
|
||
expect(renderer.render(scope)).toMatchInlineSnapshot(` | ||
"/* eslint-disable prettier/prettier, max-len */ | ||
// @ts-ignore TS6133 | ||
export function freeFunction(): void;" | ||
`); | ||
}); | ||
|
||
test('functions can be explicitly not exported', () => { | ||
new FreeFunction(scope, { | ||
name: 'freeFunction', | ||
export: false, | ||
}); | ||
|
||
expect(renderer.render(scope)).toMatchInlineSnapshot(` | ||
"/* eslint-disable prettier/prettier, max-len */ | ||
// @ts-ignore TS6133 | ||
function freeFunction(): void;" | ||
`); | ||
}); | ||
}); |