Add Bun.YAML.parse and YAML imports (#22073)

### What does this PR do?
This PR adds builtin YAML parsing with `Bun.YAML.parse`
```js
import { YAML } from "bun";
const items = YAML.parse("- item1");
console.log(items); // [ "item1" ]
```

Also YAML imports work just like JSON and TOML imports
```js
import pkg from "./package.yaml"
console.log({ pkg }); // { pkg: { name: "pkg", version: "1.1.1" } }
```
### How did you verify your code works?
Added some tests for YAML imports and parsed values.

---------

Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
This commit is contained in:
Dylan Conway
2025-08-23 06:55:30 -07:00
committed by GitHub
parent 75f0ac4395
commit 8fad98ffdb
56 changed files with 7617 additions and 391 deletions

View File

@@ -267,13 +267,15 @@ OnLoadResult handleOnLoadResultNotPromise(Zig::GlobalObject* globalObject, JSC::
loader = BunLoaderTypeJSON;
} else if (loaderString == "toml"_s) {
loader = BunLoaderTypeTOML;
} else if (loaderString == "yaml"_s) {
loader = BunLoaderTypeYAML;
}
}
}
}
if (loader == BunLoaderTypeNone) [[unlikely]] {
throwException(globalObject, scope, createError(globalObject, "Expected loader to be one of \"js\", \"jsx\", \"object\", \"ts\", \"tsx\", \"toml\", or \"json\""_s));
throwException(globalObject, scope, createError(globalObject, "Expected loader to be one of \"js\", \"jsx\", \"object\", \"ts\", \"tsx\", \"toml\", \"yaml\", or \"json\""_s));
result.value.error = scope.exception();
scope.clearException();
return result;