Commit ab6357a
authored
feat(typewriter): support aliased imports with tuple syntax (#2272)
This PR adds support for aliased selective imports using an intuitive
tuple syntax in the typewriter package.
## Changes
- Updated `importSelective()` to accept mixed arrays of strings and
tuples: `['regular', ['name', 'alias']]`
- Added `addAliasedImport()` method for dynamic aliased imports
- Introduced internal `aliasMap` to track name-to-alias mappings
- Updated `linkSymbol()` to handle both regular and aliased imports
- Modified TypeScript renderer to emit proper `import { name as alias }`
syntax
- Added comprehensive test coverage with inline snapshots
- Added extensive JSDoc documentation with examples
## Usage
```ts
// Mixed regular and aliased imports
source.importSelective(target, ['RegularImport', ['LongName', 'Short']]);
// Generates: import { RegularImport, LongName as Short } from "source";
// Avoiding name conflicts
reactModule.importSelective(myModule, [['Component', 'ReactComponent'], 'useState']);
// Generates: import { Component as ReactComponent, useState } from "react";
```1 parent 4740f3e commit ab6357a
File tree
3 files changed
+165
-9
lines changed- packages/@cdklabs/typewriter
- src
- renderer
- test
3 files changed
+165
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
96 | | - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
97 | 123 | | |
98 | | - | |
| 124 | + | |
99 | 125 | | |
100 | 126 | | |
101 | 127 | | |
| |||
157 | 183 | | |
158 | 184 | | |
159 | 185 | | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
160 | 201 | | |
161 | 202 | | |
162 | 203 | | |
| 204 | + | |
163 | 205 | | |
164 | 206 | | |
165 | | - | |
| 207 | + | |
166 | 208 | | |
167 | 209 | | |
168 | 210 | | |
169 | | - | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
170 | 216 | | |
171 | 217 | | |
172 | 218 | | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
173 | 229 | | |
174 | 230 | | |
175 | 231 | | |
176 | | - | |
| 232 | + | |
177 | 233 | | |
178 | 234 | | |
179 | 235 | | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
180 | 264 | | |
181 | 265 | | |
182 | | - | |
| 266 | + | |
| 267 | + | |
183 | 268 | | |
184 | 269 | | |
185 | 270 | | |
186 | 271 | | |
187 | | - | |
188 | | - | |
| 272 | + | |
| 273 | + | |
189 | 274 | | |
190 | 275 | | |
191 | 276 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
103 | | - | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
104 | 108 | | |
105 | 109 | | |
106 | 110 | | |
| |||
Lines changed: 67 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
0 commit comments