| 9 | |
| 10 | // eslint-disable-next-line no-shadow |
| 11 | transform(code, id) { |
| 12 | if (id.slice(-5) !== '.json' || !filter(id)) return null; |
| 13 | |
| 14 | try { |
| 15 | const parsed = JSON.parse(code); |
| 16 | return { |
| 17 | code: dataToEsm(parsed, { |
| 18 | preferConst: options.preferConst, |
| 19 | compact: options.compact, |
| 20 | namedExports: options.namedExports, |
| 21 | includeArbitraryNames: options.includeArbitraryNames, |
| 22 | indent |
| 23 | }), |
| 24 | map: { mappings: '' } |
| 25 | }; |
| 26 | } catch (err) { |
| 27 | const message = 'Could not parse JSON file'; |
| 28 | this.error({ message, id, cause: err }); |
| 29 | return null; |
| 30 | } |
| 31 | } |
| 32 | }; |
| 33 | } |