ronantakizawa/codereview-bench huggingface dataset:
Repository: withastro/astro
File: packages/astro/src/types/public/config.ts (TypeScript)

Code before:
		 *   body {
		 *     background: yellow;
		 *   }
		 * </style>
		 * ```
		 *
		 * By default, it will generate a CSS style where `red` will be applied:
		 *
		 * ```css
		 * body {background:#ff0} body {background:red}
		 * ```
		 *
		 * When this new option is set to `true`, the generated CSS style will apply `yellow`:
		 *
		 * ```css
		 * body {background:red} body {background:#ff0}
		 * ```
		 *
		 */
		preserveScriptOrder?: boolean;

		/**
		 * @name experimental.liveContentCollections
		 * @type {boolean}
		 * @default `false`
		 * @version 5.7
		 * @description
		 * Enables the use of live content collections.
		 *
		 */
		liveContentCollections?: boolean;
	};
}

/**
 * Resolved Astro Config
 *
 * Config with user settings along with all defaults filled in.
 */
export interface AstroConfig extends AstroConfigType {
	// Public:
	// This is a more detailed type than zod validation gives us.
	// TypeScript still confirms zod validation matches this type.
	integrations: AstroIntegration[];
}
/**
 * An inline Astro config that takes highest priority when merging with the user config,
 * and includes inline-specific options to configure how Astro runs.
 */
export interface AstroInlineConfig extends AstroUserConfig, AstroInlineOnlyConfig {}
export interface AstroInlineOnlyConfig {

Review comment (bug):
I know this is just a placeholder, but just in case you want a clearly wrong placeholder that will get caught easier when it's time to review! This is the kind of thing it can be easy to overlook because it scans fine.

```suggestion
		 * @version 5.x
```



Code after:
		 *   body {
		 *     background: yellow;
		 *   }
		 * </style>
		 * ```
		 *
		 * By default, it will generate a CSS style where `red` will be applied:
		 *
		 * ```css
		 * body {background:#ff0} body {background:red}
		 * ```
		 *
		 * When this new option is set to `true`, the generated CSS style will apply `yellow`:
		 *
		 * ```css
		 * body {background:red} body {background:#ff0}
		 * ```
		 *
		 */
		preserveScriptOrder?: boolean;

		/**
		 * @name experimental.liveContentCollections
		 * @type {boolean}
		 * @default `false`
		 * @version 5.x
		 * @description
		 * Enables the use of live content collections.
		 *
		 */
		liveContentCollections?: boolean;
	};
}

/**
 * Resolved Astro Config
 *
 * Config with user settings along with all defaults filled in.
 */
export interface AstroConfig extends AstroConfigType {
	// Public:
	// This is a more detailed type than zod validation gives us.
	// TypeScript still confirms zod validation matches this type.
	integrations: AstroIntegration[];
}
/**
 * An inline Astro config that takes highest priority when merging with the user config,
 * and includes inline-specific options to configure how Astro runs.
 */
export interface AstroInlineConfig extends AstroUserConfig, AstroInlineOnlyConfig {}
export interface AstroInlineOnlyConfig {
Repository: withastro/astro
File: packages/astro/src/types/public/config.ts (TypeScript)

Code before:
						 *
						 * export default defineConfig({
						 *   experimental: {
						 *     csp: {
						 *       scriptDirective: {
						 *         resources: [
						 *           "self",
						 *           "https://cdn.example.com"
						 *         ]
						 *       }
						 *     }
						 *   }
						 * });
						 * ```
						 *
						 */
						resources?: string[];

						/**
						 * @name experimental.csp.scriptDirective.strictDynamic
						 * @type {boolean}
						 * @default `false`
						 * @version 5.9.0
						 * @description
						 *
						 * Enables the keyword `strict-dynamic`, to support the dynamic injection of scripts.
						 *
						 * ```js
						 * import { defineConfig } from 'astro/config';
						 *
						 * export default defineConfig({
						 *   experimental: {
						 *     csp: {
						 *       scriptDirective: {
						 *         strictDynamic: true
						 *       }
						 *     }
						 *   }
						 * });
						 * ```
						 */
						strictDynamic?: boolean;
					};

					/**
					 * @name experimental.csp.directives
					 * @type {string[]}
					 * @default `[]`
					 * @version 5.9.0
					 * @description
					 *

Review comment (security):
```suggestion
						 * Enables the keyword `strict-dynamic` to support the dynamic injection of scripts.
```

Code after:
						 * import { defineConfig } from 'astro/config';
						 *
						 * export default defineConfig({
						 *   experimental: {
						 *     csp: {
						 *       scriptDirective: {
						 *         resources: [
						 *           "self",
						 *           "https://cdn.example.com"
						 *         ]
						 *       }
						 *     }
						 *   }
						 * });
						 * ```
						 *
						 */
						resources?: string[];

						/**
						 * @name experimental.csp.scriptDirective.strictDynamic
						 * @type {boolean}
						 * @default `false`
						 * @version 5.9.0
						 * @description
						 *
						 * Enables the keyword `strict-dynamic` to support the dynamic injection of scripts.
						 *
						 * ```js
						 * import { defineConfig } from 'astro/config';
						 *
						 * export default defineConfig({
						 *   experimental: {
						 *     csp: {
						 *       scriptDirective: {
						 *         strictDynamic: true
						 *       }
						 *     }
						 *   }
						 * });
						 * ```
						 */
						strictDynamic?: boolean;
					};

					/**
					 * @name experimental.csp.directives
					 * @type {string[]}
					 * @default `[]`
					 * @version 5.9.0
					 * @description
Repository: withastro/astro
File: packages/astro/src/types/public/config.ts (TypeScript)

Code before:
		 * ```
		 *
		 * By default, it will generate a CSS style where `red` will be applied:
		 *
		 * ```css
		 * body {background:#ff0} body {background:red}
		 * ```
		 *
		 * When this new option is set to `true`, the generated CSS style will apply `yellow`:
		 *
		 * ```css
		 * body {background:red} body {background:#ff0}
		 * ```
		 *
		 */
		preserveScriptOrder?: boolean;

		/**
		 * @docs
		 * @kind heading
		 * @name SVG Options
		 */
		svg?: {
			/**
			 * @docs
			 * @name svg.optimize
			 * @type {boolean}
			 * @default `true`
			 * @description
			 * Whether to enable SVG optimization using SVGO during build time.
			 *
			 * When enabled, all imported SVG files will be optimized for smaller file sizes
			 * and better performance while maintaining visual quality.
			 */
			optimize?: boolean;

			/**
			 * @docs
			 * @name svg.svgoConfig
			 * @type {SvgoConfig}
			 * @default `{}`
			 * @description
			 * Configuration object passed directly to SVGO for customizing SVG optimization.
			 *
			 * See [SVGO documentation](https://svgo.dev/) for available options.
			 *
			 * ```js
			 * {
			 *   svg: {
			 *     svgoConfig: {
			 *       plugins: [

Review comment (performance):
```suggestion
			 * @name experimental.svg.optimize
```

Code after:
		 *
		 * See the [experimental static `import.meta.env` docs](https://docs.astro.build/en/reference/experimental-flags/static-import-meta-env/) for more information.
		 */
		staticImportMetaEnv?: boolean;
		/**
		 * @name experimental.chromeDevtoolsWorkspace
		 * @type {boolean}
		 * @default `false`
		 * @version 5.13
		 * @description
		 *
		 * Enables Chrome DevTools workspace integration for the Astro dev server.
		 *
		 * When enabled, the dev server will automatically configure a [Chrome DevTools workspace](https://developer.chrome.com/docs/devtools/workspaces) for your project,
		 * allowing you to edit files directly in the browser and have those changes reflected in your local file system.
		 *
		 * ```js
		 * import { defineConfig } from 'astro/config';
		 *
		 * export default defineConfig({
		 *   experimental: {
		 *     chromeDevtoolsWorkspace: true,
		 *   },
		 * });
		 * ```
		 *
		 * See the [experimental Chrome DevTools workspace feature documentation](https://docs.astro.build/en/reference/experimental-flags/chrome-devtools-workspace/) for more information.
		 */
		chromeDevtoolsWorkspace?: boolean;

		/**
		 * @name experimental.svgo
		 * @type {boolean | SvgoConfig}
		 * @default `false`
		 * @description
		 * Enable SVG optimization using SVGO during build time.
		 *
		 * Set to `true` to enable optimization with default settings, or pass a configuration
		 * object to customize SVGO behavior.
		 *
		 * When enabled, all imported SVG files will be optimized for smaller file sizes
		 * and better performance while maintaining visual quality.
		 *
		 * ```js
		 * {
		 *   experimental: {
		 *     // Enable with defaults
		 *     svgo: true
		 *   }
		 * }
		 * ```
Repository: withastro/astro
File: packages/astro/src/types/public/config.ts (TypeScript)

Code before:
		 *
		 */
		preserveScriptOrder?: boolean;

		/**
		 * @docs
		 * @kind heading
		 * @name SVG Options
		 */
		svg?: {
			/**
			 * @docs
			 * @name svg.optimize
			 * @type {boolean}
			 * @default `true`
			 * @description
			 * Whether to enable SVG optimization using SVGO during build time.
			 *
			 * When enabled, all imported SVG files will be optimized for smaller file sizes
			 * and better performance while maintaining visual quality.
			 */
			optimize?: boolean;

			/**
			 * @docs
			 * @name svg.svgoConfig
			 * @type {SvgoConfig}
			 * @default `{}`
			 * @description
			 * Configuration object passed directly to SVGO for customizing SVG optimization.
			 *
			 * See [SVGO documentation](https://svgo.dev/) for available options.
			 *
			 * ```js
			 * {
			 *   svg: {
			 *     svgoConfig: {
			 *       plugins: [
			 *         'preset-default',
			 *         {
			 *           name: 'removeViewBox',
			 *           active: false
			 *         }
			 *       ]
			 *     }
			 *   }
			 * }
			 * ```
			 */
			svgoConfig?: SvgoConfig;
		};

Review comment (suggestion):
```suggestion
			 * @name experimental.svg.svgoConfig
```

Code after:
		 * When enabled, the dev server will automatically configure a [Chrome DevTools workspace](https://developer.chrome.com/docs/devtools/workspaces) for your project,
		 * allowing you to edit files directly in the browser and have those changes reflected in your local file system.
		 *
		 * ```js
		 * import { defineConfig } from 'astro/config';
		 *
		 * export default defineConfig({
		 *   experimental: {
		 *     chromeDevtoolsWorkspace: true,
		 *   },
		 * });
		 * ```
		 *
		 * See the [experimental Chrome DevTools workspace feature documentation](https://docs.astro.build/en/reference/experimental-flags/chrome-devtools-workspace/) for more information.
		 */
		chromeDevtoolsWorkspace?: boolean;

		/**
		 * @name experimental.svgo
		 * @type {boolean | SvgoConfig}
		 * @default `false`
		 * @description
		 * Enable SVG optimization using SVGO during build time.
		 *
		 * Set to `true` to enable optimization with default settings, or pass a configuration
		 * object to customize SVGO behavior.
		 *
		 * When enabled, all imported SVG files will be optimized for smaller file sizes
		 * and better performance while maintaining visual quality.
		 *
		 * ```js
		 * {
		 *   experimental: {
		 *     // Enable with defaults
		 *     svgo: true
		 *   }
		 * }
		 * ```
		 *
		 * To customize optimization, pass a [SVGO configuration object](https://svgo.dev/):
		 *
		 * ```js
		 * {
		 *   experimental: {
		 *     svgo: {
		 *       plugins: [
		 *         'preset-default',
		 *         {
		 *           name: 'removeViewBox',
		 *           active: false
		 *         }
Repository: withastro/astro
File: packages/astro/src/assets/utils/svg.ts (TypeScript)

Code before:
import { optimize } from 'svgo';

import { parse, renderSync } from 'ultrahtml';
import type { AstroConfig } from '../../types/public/config.js';

import type { SvgComponentProps } from '../runtime.js';
import { dropAttributes } from '../runtime.js';
import type { ImageMetadata } from '../types.js';

function parseSvg(contents: string, svgConfig?: AstroConfig['experimental']['svg']) {
	let processedContents = contents;
	if (svgConfig?.optimize) {
		try {
			const result = optimize(contents, svgConfig.svgoConfig);
			processedContents = result.data;
		} catch (error) {
			console.warn('SVGO optimization failed:', error);
			processedContents = contents;
		}
	}
	const root = parse(processedContents);
	const svgNode = root.children.find(
		({ name, type }: { name: string; type: number }) => type === 1 /* Element */ && name === 'svg',
	);
	if (!svgNode) {
		throw new Error('SVG file does not contain an <svg> element');
	}
	const { attributes, children } = svgNode;
	const body = renderSync({ ...root, children });

	return { attributes, body };
}

export function makeSvgComponent(
	meta: ImageMetadata,

Review comment (suggestion):
```suggestion
function parseSvg(contents: string, svgConfig: AstroConfig['experimental']['svg']) {
```

Code after:
import { optimize } from 'svgo';
import { parse, renderSync } from 'ultrahtml';
import { AstroError, AstroErrorData } from '../../core/errors/index.js';
import type { AstroConfig } from '../../types/public/config.js';
import type { SvgComponentProps } from '../runtime.js';
import { dropAttributes } from '../runtime.js';
import type { ImageMetadata } from '../types.js';

function parseSvg({
	path,
	contents,
	svgoConfig,
}: {
	path: string;
	contents: string;
	svgoConfig: AstroConfig['experimental']['svgo'];
}) {
	let processedContents = contents;
	if (svgoConfig) {
		try {
			const config = typeof svgoConfig === 'boolean' ? undefined : svgoConfig;
			const result = optimize(contents, config);
			processedContents = result.data;
		} catch (cause) {
			throw new AstroError(
				{
					...AstroErrorData.CannotOptimizeSvg,
					message: AstroErrorData.CannotOptimizeSvg.message(path),
				},
				{ cause },
			);
		}
	}
	const root = parse(processedContents);
	const svgNode = root.children.find(
Repository: withastro/astro
File: packages/astro/src/assets/utils/svg.ts (TypeScript)

Code before:
	if (svgConfig?.optimize) {
		try {
			const result = optimize(contents, svgConfig.svgoConfig);
			processedContents = result.data;
		} catch (error) {
			console.warn('SVGO optimization failed:', error);
			processedContents = contents;
		}
	}
	const root = parse(processedContents);
	const svgNode = root.children.find(
		({ name, type }: { name: string; type: number }) => type === 1 /* Element */ && name === 'svg',
	);
	if (!svgNode) {
		throw new Error('SVG file does not contain an <svg> element');
	}
	const { attributes, children } = svgNode;
	const body = renderSync({ ...root, children });

	return { attributes, body };
}

export function makeSvgComponent(
	meta: ImageMetadata,
	contents: Buffer | string,
	svgConfig?: AstroConfig['experimental']['svg'],
): string {
	const file = typeof contents === 'string' ? contents : contents.toString('utf-8');
	const { attributes, body: children } = parseSvg(file, svgConfig);
	const props: SvgComponentProps = {
		meta,
		attributes: dropAttributes(attributes),
		children,
	};

	return `import { createSvgComponent } from 'astro/assets/runtime';
export default createSvgComponent(${JSON.stringify(props)})`;
}


Review comment (suggestion):
```suggestion
	svgConfig: AstroConfig['experimental']['svg'],
```

Code after:
	svgoConfig,
}: {
	path: string;
	contents: string;
	svgoConfig: AstroConfig['experimental']['svgo'];
}) {
	let processedContents = contents;
	if (svgoConfig) {
		try {
			const config = typeof svgoConfig === 'boolean' ? undefined : svgoConfig;
			const result = optimize(contents, config);
			processedContents = result.data;
		} catch (cause) {
			throw new AstroError(
				{
					...AstroErrorData.CannotOptimizeSvg,
					message: AstroErrorData.CannotOptimizeSvg.message(path),
				},
				{ cause },
			);
		}
	}
	const root = parse(processedContents);
	const svgNode = root.children.find(
		({ name, type }: { name: string; type: number }) => type === 1 /* Element */ && name === 'svg',
	);
	if (!svgNode) {
		throw new Error('SVG file does not contain an <svg> element');
	}
	const { attributes, children } = svgNode;
	const body = renderSync({ ...root, children });

	return { attributes, body };
}

export function makeSvgComponent(
	meta: ImageMetadata,
	contents: Buffer | string,
	svgoConfig: AstroConfig['experimental']['svgo'],
): string {
	const file = typeof contents === 'string' ? contents : contents.toString('utf-8');
	const { attributes, body: children } = parseSvg({
		path: meta.fsPath,
		contents: file,
		svgoConfig,
	});
	const props: SvgComponentProps = {
		meta,
		attributes: dropAttributes(attributes),
		children,
	};
Repository: withastro/astro
File: packages/astro/src/core/config/schemas/base.ts (TypeScript)

Code before:
						scriptDirective: z
							.object({
								resources: z.array(z.string()).optional(),
								hashes: z.array(cspHashSchema).optional(),
								strictDynamic: z.boolean().optional(),
							})
							.optional(),
					}),
				])
				.optional()
				.default(ASTRO_CONFIG_DEFAULTS.experimental.csp),
			staticImportMetaEnv: z
				.boolean()
				.optional()
				.default(ASTRO_CONFIG_DEFAULTS.experimental.staticImportMetaEnv),
			chromeDevtoolsWorkspace: z
				.boolean()
				.optional()
				.default(ASTRO_CONFIG_DEFAULTS.experimental.chromeDevtoolsWorkspace),
			failOnPrerenderConflict: z
				.boolean()
				.optional()
				.default(ASTRO_CONFIG_DEFAULTS.experimental.failOnPrerenderConflict),
			svg: z
				.object({
					optimize: z.boolean().default(true),
					svgoConfig: z
						.custom<SvgoConfig>((value) => value && typeof value === 'object')
						.optional(),
				})
				.optional(),
		})
		.strict(
			`Invalid or outdated experimental feature.\nCheck for incorrect spelling or outdated Astro version.\nSee https://docs.astro.build/en/reference/experimental-flags/ for a list of all current experiments.`,
		)
		.default({}),
	legacy: z
		.object({
			collections: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.legacy.collections),
		})
		.default({}),
});

export type AstroConfigType = z.infer<typeof AstroConfigSchema>;


Review comment (performance):
```suggestion
					optimize: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.svg.optimize),
```

Code after:
								hashes: z.array(cspHashSchema).optional(),
								strictDynamic: z.boolean().optional(),
							})
							.optional(),
					}),
				])
				.optional()
				.default(ASTRO_CONFIG_DEFAULTS.experimental.csp),
			staticImportMetaEnv: z
				.boolean()
				.optional()
				.default(ASTRO_CONFIG_DEFAULTS.experimental.staticImportMetaEnv),
			chromeDevtoolsWorkspace: z
				.boolean()
				.optional()
				.default(ASTRO_CONFIG_DEFAULTS.experimental.chromeDevtoolsWorkspace),
			failOnPrerenderConflict: z
				.boolean()
				.optional()
				.default(ASTRO_CONFIG_DEFAULTS.experimental.failOnPrerenderConflict),
			svgo: z
				.union([z.boolean(), z.custom<SvgoConfig>((value) => value && typeof value === 'object')])
				.optional()
				.default(ASTRO_CONFIG_DEFAULTS.experimental.svgo),
		})
		.strict(
			`Invalid or outdated experimental feature.\nCheck for incorrect spelling or outdated Astro version.\nSee https://docs.astro.build/en/reference/experimental-flags/ for a list of all current experiments.`,
		)
		.default({}),
	legacy: z
		.object({
			collections: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.legacy.collections),
		})
		.default({}),
});

export type AstroConfigType = z.infer<typeof AstroConfigSchema>;
Repository: withastro/astro
File: packages/astro/src/types/public/config.ts (TypeScript)

Code before:
		 *   experimental: {
		 *     chromeDevtoolsWorkspace: true,
		 *   },
		 * });
		 * ```
		 *
		 * See the [experimental Chrome DevTools workspace feature documentation](https://docs.astro.build/en/reference/experimental-flags/chrome-devtools-workspace/) for more information.
		 */
		chromeDevtoolsWorkspace?: boolean;

		/**
		 * @kind heading
		 * @name SVG Options
		 */
		svg?: {
			/**
			 * @name experimental.svg.optimize
			 * @type {boolean}
			 * @default `true`
			 * @description
			 * Whether to enable SVG optimization using SVGO during build time.
			 *
			 * When enabled, all imported SVG files will be optimized for smaller file sizes
			 * and better performance while maintaining visual quality.
			 */
			optimize?: boolean;

			/**
			 * @name experimental.svg.svgoConfig
			 * @type {SvgoConfig}
			 * @default `{}`
			 * @description
			 * Configuration object passed directly to SVGO for customizing SVG optimization.
			 *
			 * See [SVGO documentation](https://svgo.dev/) for available options.
			 *
			 * ```js
			 * {
			 *   svg: {
			 *     svgoConfig: {
			 *       plugins: [
			 *         'preset-default',
			 *         {
			 *           name: 'removeViewBox',
			 *           active: false
			 *         }
			 *       ]
			 *     }
			 *   }
			 * }
			 * ```

Review comment (performance):
I think you brought this up sarah already, about directly having the config object as a root property instead of having `optimize: boolean`. What was the conclusion of that?

Because I think it could be nice to have `config.experimental.svgo: boolean | SvgoConfig` or something like that

Code after:
		 *   experimental: {
		 *     chromeDevtoolsWorkspace: true,
		 *   },
		 * });
		 * ```
		 *
		 * See the [experimental Chrome DevTools workspace feature documentation](https://docs.astro.build/en/reference/experimental-flags/chrome-devtools-workspace/) for more information.
		 */
		chromeDevtoolsWorkspace?: boolean;

		/**
		 * @name experimental.svgo
		 * @type {boolean | SvgoConfig}
		 * @default `false`
		 * @description
		 * Enable SVG optimization using SVGO during build time.
		 *
		 * Set to `true` to enable optimization with default settings, or pass a configuration
		 * object to customize SVGO behavior.
		 *
		 * When enabled, all imported SVG files will be optimized for smaller file sizes
		 * and better performance while maintaining visual quality.
		 *
		 * ```js
		 * {
		 *   experimental: {
		 *     // Enable with defaults
		 *     svgo: true
		 *   }
		 * }
		 * ```
		 *
		 * To customize optimization, pass a [SVGO configuration object](https://svgo.dev/):
		 *
		 * ```js
		 * {
		 *   experimental: {
		 *     svgo: {
		 *       plugins: [
		 *         'preset-default',
		 *         {
		 *           name: 'removeViewBox',
		 *           active: false
		 *         }
		 *       ]
		 *     }
		 *   }
		 * }
		 * ```
		 *
		 * See the [experimental SVGO optimization docs](https://docs.astro.build/en/reference/experimental-flags/svg-optimization/) for more information.