Skip to content

Commit 6c592e2

Browse files
author
codegen-bot
committed
fixed up export docs
1 parent 5ca6327 commit 6c592e2

File tree

2 files changed

+47
-424
lines changed

2 files changed

+47
-424
lines changed

docs/building-with-codegen/exports.mdx

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ iconType: "solid"
77

88
The [Export](/api-reference/core/Export) API provides tools for managing exports and module boundaries in TypeScript codebases.
99

10+
<Note>Exports are a TS-only language feature</Note>
11+
1012
## Export Statements vs Exports
1113

1214
Similar to imports, Codegen provides two levels of abstraction for working with exports:
@@ -30,19 +32,54 @@ export function process() {}
3032
You can access these through your file's collections:
3133

3234
```python
35+
# Access all exports in the codebase
36+
for export in codebase.exports:
37+
...
38+
3339
# Access all export statements
3440
for stmt in file.export_statements:
35-
print(f"Statement: {stmt.source}")
36-
37-
# Access individual exports in the statement
3841
for exp in stmt.exports:
39-
print(f" Export: {exp.name}")
42+
...
4043
```
4144

4245
<Note>
4346
ExportStatement inherits from [Statement](/building-with-codegen/statements-and-code-blocks), providing operations like `remove()` and `insert_before()`. This is particularly useful when you want to manipulate the entire export declaration.
4447
</Note>
4548

49+
## Common Operations
50+
51+
Here are common operations for working with exports:
52+
53+
```python
54+
# Add new export
55+
file.add_export("MyComponent")
56+
57+
# Add export with alias
58+
file.add_export("MyComponent", alias="default")
59+
60+
# Convert to type export
61+
export = file.get_export("MyType")
62+
export.make_type_export()
63+
64+
# Remove export
65+
export.remove() # Removes export but keeps symbol
66+
67+
# Update export properties
68+
export.update(
69+
name="NewName",
70+
is_type=True,
71+
is_default=False
72+
)
73+
74+
# Analyze symbols being exported
75+
for export in file.exports:
76+
if isinstance(export.exported_symbol, ExternalModule):
77+
print('Exporting ExternalModule')
78+
else:
79+
...
80+
81+
```
82+
4683
## Export Types
4784

4885
Codegen supports several types of exports:
@@ -68,9 +105,13 @@ export { foo as default }; // Default export alias
68105
export { bar as baz } from './other-file'; // Re-export with alias
69106
```
70107

71-
## Working with Exports
108+
## Identifying Export Types
72109

73110
The Export API provides methods to identify and filter exports:
111+
- [.is_type_export()](/api-reference/typescript/TSExport#is-type-export)
112+
- [.is_default_export()](/api-reference/typescript/TSExport#is-default-export)
113+
- [.is_wildcard_export()](/api-reference/typescript/TSExport#is-wildcard-export)
114+
74115

75116
```python
76117
# Check export types
@@ -81,14 +122,6 @@ for exp in file.exports:
81122
print(f"Default export: {exp.name}")
82123
elif exp.is_wildcard_export():
83124
print(f"Wildcard export from: {exp.from_file.filepath}")
84-
85-
# Work with re-exports
86-
for exp in file.exports:
87-
if exp.is_reexport():
88-
if exp.is_external_export:
89-
print(f"External re-export: {exp.name} from {exp.from_file.filepath}")
90-
else:
91-
print(f"Internal re-export: {exp.name}")
92125
```
93126

94127
## Export Resolution
@@ -106,35 +139,9 @@ for exp in file.exports:
106139
print(f"Through: {' -> '.join(e.file.filepath for e in exp.export_chain)}")
107140
```
108141

109-
## Common Operations
110-
111-
Here are common operations for working with exports:
112-
113-
```python
114-
# Add new export
115-
file.add_export("MyComponent")
116-
117-
# Add export with alias
118-
file.add_export("MyComponent", alias="default")
119-
120-
# Convert to type export
121-
export = file.get_export("MyType")
122-
export.make_type_export()
123-
124-
# Remove export
125-
export.remove() # Removes export but keeps symbol
126-
127-
# Update export properties
128-
export.update(
129-
name="NewName",
130-
is_type=True,
131-
is_default=False
132-
)
133-
```
134-
135142
## Managing Re-exports
136143

137-
Common patterns for working with re-exports:
144+
You can manage re-exports with the [TSExport.is_reexport()](/api-reference/typescript/TSExport#is-reexport) API:
138145

139146
```python
140147
# Create public API

0 commit comments

Comments
 (0)