(code, id)
| 425 | code: { include: KEYED_FUNCTION_FACTORY_NAMES_RE }, |
| 426 | }, |
| 427 | async handler (code, id) { |
| 428 | const s = new MagicString(code) |
| 429 | const scopeTracker = new ScopeTracker({ |
| 430 | preserveExitedScopes: true, |
| 431 | }) |
| 432 | const autoImports = await options.getAutoImports() |
| 433 | const autoImportsToSources = new Map<string, string>(autoImports.map(i => [i.as || i.name, i.from])) |
| 434 | const { processFactory } = createFactoryProcessor( |
| 435 | id, |
| 436 | scopeTracker, |
| 437 | namesToFactoryMeta, |
| 438 | findStaticImports(code).map(i => parseStaticImport(i)), |
| 439 | autoImportsToSources, |
| 440 | options.alias, |
| 441 | ) |
| 442 | |
| 443 | function rewriteFactoryMacro (node: IdentifierReference | MemberExpression | ParenthesizedExpression) { |
| 444 | // TODO: use sth more robust for rewriting optionals |
| 445 | if (node.type === 'Identifier') { |
| 446 | // createUseFetch?.() -> createUseFetch?.__nuxt_factory() |
| 447 | if (code[node.end] === '?' && code[node.end + 1] === '.') { |
| 448 | s.overwrite( |
| 449 | node.start, |
| 450 | node.end + 2, |
| 451 | `${node.name}?.__nuxt_factory`, |
| 452 | ) |
| 453 | } else { |
| 454 | // createUseFetch() -> createUseFetch.__nuxt_factory() |
| 455 | s.overwrite( |
| 456 | node.start, |
| 457 | node.end, |
| 458 | `${node.name}.__nuxt_factory`, |
| 459 | ) |
| 460 | } |
| 461 | } else if (code[node.end] === '?' && code[node.end + 1] === '.') { |
| 462 | // ['createUseFetch']?.() -> ['createUseFetch']?.__nuxt_factory() |
| 463 | s.appendLeft(node.end + 2, '__nuxt_factory') |
| 464 | } else { |
| 465 | // ['createUseFetch']() -> ['createUseFetch'].__nuxt_factory() |
| 466 | s.appendLeft(node.end, '.__nuxt_factory') |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | const { program } = parseAndWalk(code, id, { |
| 471 | scopeTracker, |
| 472 | }) |
| 473 | |
| 474 | scopeTracker.freeze() |
| 475 | |
| 476 | walk(program, { |
| 477 | // no need for a scope tracker pre-pass, since we only care about imports |
| 478 | // and we only consider the root scope (because that's where an export would be - so no shadowing) |
| 479 | scopeTracker, |
| 480 | enter (node) { |
| 481 | if (node.type !== 'ExportNamedDeclaration' && node.type !== 'ExportDefaultDeclaration') { |
| 482 | return |
| 483 | } |
| 484 | processFactory(this, node, ({ parseFactoryResult }) => { |
no test coverage detected
searching dependent graphs…