mirror of
https://github.com/oven-sh/bun
synced 2026-02-13 20:39:05 +00:00
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:
@@ -835,7 +835,7 @@ pub fn transpileSourceCode(
|
||||
const disable_transpilying = comptime flags.disableTranspiling();
|
||||
|
||||
if (comptime disable_transpilying) {
|
||||
if (!(loader.isJavaScriptLike() or loader == .toml or loader == .text or loader == .json or loader == .jsonc)) {
|
||||
if (!(loader.isJavaScriptLike() or loader == .toml or loader == .yaml or loader == .text or loader == .json or loader == .jsonc)) {
|
||||
// Don't print "export default <file path>"
|
||||
return ResolvedSource{
|
||||
.allocator = null,
|
||||
@@ -847,7 +847,7 @@ pub fn transpileSourceCode(
|
||||
}
|
||||
|
||||
switch (loader) {
|
||||
.js, .jsx, .ts, .tsx, .json, .jsonc, .toml, .text => {
|
||||
.js, .jsx, .ts, .tsx, .json, .jsonc, .toml, .yaml, .text => {
|
||||
// Ensure that if there was an ASTMemoryAllocator in use, it's not used anymore.
|
||||
var ast_scope = js_ast.ASTMemoryAllocator.Scope{};
|
||||
ast_scope.enter();
|
||||
@@ -1096,7 +1096,7 @@ pub fn transpileSourceCode(
|
||||
};
|
||||
}
|
||||
|
||||
if (loader == .json or loader == .jsonc or loader == .toml) {
|
||||
if (loader == .json or loader == .jsonc or loader == .toml or loader == .yaml) {
|
||||
if (parse_result.empty) {
|
||||
return ResolvedSource{
|
||||
.allocator = null,
|
||||
|
||||
Reference in New Issue
Block a user