|
7 | 7 | * @typedef {import('estree-jsx').Expression} Expression |
8 | 8 | * @typedef {import('estree-jsx').FunctionDeclaration} FunctionDeclaration |
9 | 9 | * @typedef {import('estree-jsx').ImportDeclaration} ImportDeclaration |
| 10 | + * @typedef {import('estree-jsx').ImportDefaultSpecifier} ImportDefaultSpecifier |
| 11 | + * @typedef {import('estree-jsx').ImportExpression} ImportExpression |
| 12 | + * @typedef {import('estree-jsx').ImportSpecifier} ImportSpecifier |
| 13 | + * @typedef {import('estree-jsx').Literal} Literal |
10 | 14 | * @typedef {import('estree-jsx').JSXElement} JSXElement |
11 | 15 | * @typedef {import('estree-jsx').ModuleDeclaration} ModuleDeclaration |
12 | 16 | * @typedef {import('estree-jsx').Node} Node |
@@ -186,25 +190,38 @@ export function recmaDocument(options) { |
186 | 190 | layout = specifier |
187 | 191 |
|
188 | 192 | // Make it just an import: `import MDXLayout from '…'`. |
189 | | - handleEsm( |
190 | | - create(specifier, { |
191 | | - type: 'ImportDeclaration', |
192 | | - specifiers: [ |
193 | | - // Default as default / something else as default. |
194 | | - specifier.local.name === 'default' |
195 | | - ? { |
196 | | - type: 'ImportDefaultSpecifier', |
197 | | - local: {type: 'Identifier', name: 'MDXLayout'} |
198 | | - } |
199 | | - : create(specifier.local, { |
200 | | - type: 'ImportSpecifier', |
201 | | - imported: specifier.local, |
202 | | - local: {type: 'Identifier', name: 'MDXLayout'} |
203 | | - }) |
204 | | - ], |
205 | | - source: create(source, {type: 'Literal', value: source.value}) |
| 193 | + /** @type {Array<ImportDefaultSpecifier | ImportSpecifier>} */ |
| 194 | + const specifiers = [] |
| 195 | + |
| 196 | + // Default as default / something else as default. |
| 197 | + if (specifier.local.name === 'default') { |
| 198 | + specifiers.push({ |
| 199 | + type: 'ImportDefaultSpecifier', |
| 200 | + local: {type: 'Identifier', name: 'MDXLayout'} |
206 | 201 | }) |
207 | | - ) |
| 202 | + } else { |
| 203 | + /** @type {ImportSpecifier} */ |
| 204 | + const importSpecifier = { |
| 205 | + type: 'ImportSpecifier', |
| 206 | + imported: specifier.local, |
| 207 | + local: {type: 'Identifier', name: 'MDXLayout'} |
| 208 | + } |
| 209 | + create(specifier.local, importSpecifier) |
| 210 | + specifiers.push(importSpecifier) |
| 211 | + } |
| 212 | + |
| 213 | + /** @type {Literal} */ |
| 214 | + const from = {type: 'Literal', value: source.value} |
| 215 | + create(source, from) |
| 216 | + |
| 217 | + /** @type {ImportDeclaration} */ |
| 218 | + const declaration = { |
| 219 | + type: 'ImportDeclaration', |
| 220 | + specifiers, |
| 221 | + source: from |
| 222 | + } |
| 223 | + create(specifier, declaration) |
| 224 | + handleEsm(declaration) |
208 | 225 |
|
209 | 226 | return false |
210 | 227 | } |
@@ -376,7 +393,10 @@ export function recmaDocument(options) { |
376 | 393 | // with import maps (<https://github.com/WICG/import-maps>). |
377 | 394 | } |
378 | 395 |
|
379 | | - node.source = create(node.source, {type: 'Literal', value}) |
| 396 | + /** @type {Literal} */ |
| 397 | + const literal = {type: 'Literal', value} |
| 398 | + create(node.source, literal) |
| 399 | + node.source = literal |
380 | 400 | } |
381 | 401 |
|
382 | 402 | /** @type {ModuleDeclaration | Statement | undefined} */ |
@@ -416,13 +436,10 @@ export function recmaDocument(options) { |
416 | 436 | // export * from 'a' |
417 | 437 | // //=> const _exportAll0 = await import('a') |
418 | 438 | // ``` |
419 | | - init = { |
420 | | - type: 'AwaitExpression', |
421 | | - argument: create(node, { |
422 | | - type: 'ImportExpression', |
423 | | - source: node.source |
424 | | - }) |
425 | | - } |
| 439 | + /** @type {ImportExpression} */ |
| 440 | + const argument = {type: 'ImportExpression', source: node.source} |
| 441 | + create(node, argument) |
| 442 | + init = {type: 'AwaitExpression', argument} |
426 | 443 |
|
427 | 444 | if ( |
428 | 445 | (node.type === 'ImportDeclaration' || |
|
0 commit comments