fix: convert import statements inside function bodies to require() calls#1901
fix: convert import statements inside function bodies to require() calls#1901mohammedahmed18 wants to merge 1 commit intomainfrom
Conversation
|
Claude finished @mohammedahmed18's task in 1m 38s —— View job PR Review Summary
Prek Checks✅ All checks passed ( Code ReviewOne style violation:
One design note: The indentation-based heuristic (any Everything else looks correct:
Duplicate DetectionNo duplicates detected. The function is unique to the JS language module. |
⚡️ Codeflash found optimizations for this PR📄 171% (1.71x) speedup for
|
…2026-03-25T17.27.15 ⚡️ Speed up function `fix_imports_inside_blocks` by 171% in PR #1901 (`cf-fix-imports-inside-blocks`)
|
This PR is now faster! 🚀 @mohammedahmed18 accepted my optimizations from: |
AI-generated tests sometimes place `import X from 'Y'` inside jest.mock() callbacks, describe() blocks, or other function bodies. This is invalid JavaScript syntax (import must be top-level). Add a post-processing step that converts indented import statements to equivalent require() calls. Affects ~79/1026 Strapi log files showing "import/export cannot be used outside of module code" SWC syntax errors. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
5a05a77 to
c9855e4
Compare
Summary
import X from 'Y'insidejest.mock()callbacks,describe()blocks, or other function bodies — this is invalid JS syntax (imports must be top-level)fix_imports_inside_blocks()toedit_tests.pythat converts indentedimportstatements to equivalentconst X = require('Y')callspostprocess_generated_tests()so all generated tests are automatically fixedimport X from 'Y'), named imports (import { X } from 'Y'), and namespace imports (import * as X from 'Y')Test plan
uv run prekpasses🤖 Generated with Claude Code