Files
bun.sh/src/bundler
Claude Bot 4707a9e23a Implement comprehensive XML parser for Bun bundler & runtime
This commit adds full XML parsing support to Bun, following the same
architecture as the existing YAML and TOML parsers.

## Core Implementation
- **XML Parser**: Complete production-ready XML parser in Zig (src/interchange/xml.zig)
  - Supports XML 1.0 specification with elements, attributes, CDATA, comments
  - Handles XML namespaces, entity references, character references
  - Converts XML to JavaScript AST expressions for bundler integration
  - Memory-efficient with proper error handling and stack overflow protection

- **Runtime API**: Bun.XML.parse() JavaScript binding (src/bun.js/api/XMLObject.zig)
  - Follows same patterns as Bun.YAML.parse() and Bun.TOML.parse()
  - Supports XML to JavaScript object conversion with attribute prefix (@)
  - Proper circular reference detection and recursion protection
  - Analytics tracking and comprehensive error handling

## System Integration
- **Bundler Support**: XML files can be imported as ES modules
  - Added .xml loader to options.Loader enum (value 20)
  - Integrated into ModuleLoader, ParseTask, and transpiler
  - Supports both bundling and runtime transpilation

- **API Schema**: Updated all schema files (TypeScript, JavaScript, Zig)
  - Added XML loader to API definitions and error messages
  - Updated headers-handwritten.h with BunLoaderTypeXML constant

## XML to JavaScript Conversion
- Attributes: Prefixed with @ (e.g. @id, @class)
- Simple text-only elements: Return text as string
- Mixed content: Uses __text and __children properties
- Empty elements: Return null
- Entity references: Properly decoded (<, >, &, etc.)

## Test Coverage
- **Runtime Tests**: 25+ test cases covering all XML features
  - Basic parsing, attributes, nesting, CDATA, comments
  - Entity references, namespaces, error handling
  - Performance tests with large documents

- **Bundler Tests**: Integration tests for XML file imports
  - ESM/CommonJS compatibility, build configurations
  - Multiple file imports, nested directories

- **Test Fixtures**: 10 comprehensive XML fixtures
  - Real-world formats (RSS, SOAP, SVG)
  - Edge cases, malformed XML, performance tests

## Files Modified
- Core: options.zig, schema files, interchange.zig
- Bundler: ParseTask.zig, LinkerContext.zig, transpiler.zig
- Runtime: ModuleLoader.{zig,cpp}, headers-handwritten.h
- API: BunObject.zig, XMLObject.zig, analytics.zig

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-23 23:29:35 +00:00
..