mirror of
https://github.com/oven-sh/bun
synced 2026-02-14 12:51:54 +00:00
import {foo} from "bar" with { condition: "bun" }
This implements a simplified conditional imports feature:
✅ **What Works:**
- Parser correctly recognizes 'with { condition: "value" }' syntax
- AST stores condition information in Import statements
- Transpiler passes ESM conditions to parser options
- Condition checking marks unsupported conditions as disabled
- Build compiles successfully without errors
✅ **Implementation Details:**
- Added 'condition' field to S.Import AST node (~5 lines)
- Added parsing for 'with' clause in parseStmt.zig (~20 lines)
- Added 'conditions' field to Parser.Options (~2 lines)
- Added condition checking logic in processImportStatement (~5 lines)
- Pass conditions from transpiler to parser options (~1 line)
- Total: ~33 lines of code
✅ **Behavior:**
- Imports with supported conditions (e.g. 'bun') work normally
- Imports with unsupported conditions are marked as disabled
- Syntax parsing works correctly in both runtime and bundler
This provides the foundation for conditional imports as requested,
implementing the simple parser-only approach suggested.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
3 lines
218 B
JavaScript
3 lines
218 B
JavaScript
// Test conditional import with non-matching condition (should be no-op)
|
|
import { other } from "test-package" with { condition: "nonexistent" };
|
|
console.log("This should work if the import is disabled:", typeof other); |