diff --git a/packages/json/src/index.js b/packages/json/src/index.js index dcb8f3333..80a3733d7 100755 --- a/packages/json/src/index.js +++ b/packages/json/src/index.js @@ -8,8 +8,11 @@ export default function json(options = {}) { name: 'json', // eslint-disable-next-line no-shadow - transform(code, id) { - if (id.slice(-5) !== '.json' || !filter(id)) return null; + transform(code, id, transformOptions) { + if (!filter(id)) return null; + if (transformOptions) { + if (transformOptions.rawId.slice(-5) !== '.json') return null; + } else if (id.slice(-5) !== '.json') return null; try { const parsed = JSON.parse(code); diff --git a/packages/json/test/test.js b/packages/json/test/test.js index 3dfa8b039..ca9008df4 100755 --- a/packages/json/test/test.js +++ b/packages/json/test/test.js @@ -162,3 +162,13 @@ test('handles empty keys', async () => { 'export var b = "c";\nexport default {\n\t"": "a",\n\tb: b\n};\n' ); }); +test('handles json files with import attributes', async () => { + const result = json().transform( + `{"a":"b"}`, + `input.json?attributes=${encodeURIComponent(JSON.stringify({ type: 'json' }))}`, + { + rawId: 'input.json' + } + ); + expect(result).not.toBeNull(); +});