From 6f34d457634988fc36d933c936daecfcda27c371 Mon Sep 17 00:00:00 2001 From: chouchouji <1305974212@qq.com> Date: Sat, 7 Dec 2024 11:35:40 +0800 Subject: [PATCH] refactor(json): simplify default options handling --- packages/json/src/index.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/json/src/index.js b/packages/json/src/index.js index dcb8f3333..f7549376f 100755 --- a/packages/json/src/index.js +++ b/packages/json/src/index.js @@ -1,8 +1,16 @@ import { createFilter, dataToEsm } from '@rollup/pluginutils'; export default function json(options = {}) { - const filter = createFilter(options.include, options.exclude); - const indent = 'indent' in options ? options.indent : '\t'; + const { + include, + exclude, + indent = '\t', + preferConst, + compact, + namedExports, + includeArbitraryNames + } = options; + const filter = createFilter(include, exclude); return { name: 'json', @@ -15,10 +23,10 @@ export default function json(options = {}) { const parsed = JSON.parse(code); return { code: dataToEsm(parsed, { - preferConst: options.preferConst, - compact: options.compact, - namedExports: options.namedExports, - includeArbitraryNames: options.includeArbitraryNames, + preferConst, + compact, + namedExports, + includeArbitraryNames, indent }), map: { mappings: '' }