Skip to content

Commit 0036f23

Browse files
committed
refactor: hoist regex
1 parent 4f3770e commit 0036f23

File tree

1 file changed

+3
-1
lines changed
  • packages/vite/src/node/plugins

1 file changed

+3
-1
lines changed

packages/vite/src/node/plugins/json.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export interface JsonOptions {
2929
// Custom json filter for vite
3030
const jsonExtRE = /\.json(?:$|\?)(?!commonjs-(?:proxy|external))/
3131

32+
const jsonObjRE = /^\s*\{/
33+
3234
const jsonLangs = `\\.(?:json|json5)(?:$|\\?)`
3335
const jsonLangRE = new RegExp(jsonLangs)
3436
export const isJSONRequest = (request: string): boolean =>
@@ -49,7 +51,7 @@ export function jsonPlugin(
4951

5052
try {
5153
if (options.stringify !== false) {
52-
if (options.namedExports && /^\s*\{/.test(json)) {
54+
if (options.namedExports && jsonObjRE.test(json)) {
5355
const parsed = JSON.parse(json)
5456
const keys = Object.keys(parsed)
5557

0 commit comments

Comments
 (0)