Skip to content

Commit 8aa1c1a

Browse files
author
codegen-bot
committed
.
1 parent 6c592e2 commit 8aa1c1a

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

docs/building-with-codegen/exports.mdx

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,27 @@ ExportStatement inherits from [Statement](/building-with-codegen/statements-and-
5151
Here are common operations for working with exports:
5252

5353
```python
54-
# Add new export
55-
file.add_export("MyComponent")
54+
# Add exports from source code
55+
file.add_export_from_source("export { MyComponent };")
56+
file.add_export_from_source("export type { MyType } from './types';")
5657

57-
# Add export with alias
58-
file.add_export("MyComponent", alias="default")
58+
# Export existing symbols
59+
component = file.get_function("MyComponent")
60+
file.add_export(component) # export { MyComponent }
61+
file.add_export(component, alias="default") # export { MyComponent as default }
5962

6063
# Convert to type export
6164
export = file.get_export("MyType")
6265
export.make_type_export()
6366

64-
# Remove export
65-
export.remove() # Removes export but keeps symbol
67+
# Remove exports
68+
export = file.get_export("MyComponent")
69+
export.remove() # Removes export but keeps the symbol
70+
71+
# Remove multiple exports
72+
for export in file.exports:
73+
if not export.is_type_export():
74+
export.remove()
6675

6776
# Update export properties
6877
export.update(
@@ -71,15 +80,28 @@ export.update(
7180
is_default=False
7281
)
7382

83+
# Export from another file
84+
other_file = codebase.get_file("./components.ts")
85+
component = other_file.get_class("Button")
86+
file.add_export(component, from_file=other_file) # export { Button } from './components';
87+
7488
# Analyze symbols being exported
7589
for export in file.exports:
7690
if isinstance(export.exported_symbol, ExternalModule):
7791
print('Exporting ExternalModule')
7892
else:
7993
...
80-
8194
```
8295

96+
<Note>
97+
When adding exports, you can:
98+
- Add from source code with `add_export_from_source()`
99+
- Export existing symbols with `add_export()`
100+
- Re-export from other files by specifying `from_file`
101+
102+
The export will automatically handle adding any required imports.
103+
</Note>
104+
83105
## Export Types
84106

85107
Codegen supports several types of exports:

0 commit comments

Comments
 (0)