-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathparse-json.js
50 lines (44 loc) · 1021 Bytes
/
parse-json.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// @ts-check
import { parseLocatedJson } from './json.js';
/**
* TypeScript cannot be relied upon to deal with the nuances of Readonly, so we
* borrow the pass-through type definition of harden here.
*
* @type {import('ses').Harden}
*/
const freeze = Object.freeze;
const textDecoder = new TextDecoder();
/** @type {import('./types.js').ParseFn} */
export const parseJson = async (
bytes,
_specifier,
location,
_packageLocation,
) => {
const source = textDecoder.decode(bytes);
const imports = freeze([]);
const jsonResult = parseLocatedJson(source, location);
/**
* @param {Object} exports
*/
const execute = exports => {
exports.default = jsonResult;
};
const record = freeze({
imports,
exports: freeze(['default']),
execute: freeze(execute),
jsonResult,
location,
})
return {
parser: 'json',
bytes,
record,
};
};
/** @type {import('./types.js').ParserImplementation} */
export default {
parse: parseJson,
heuristicImports: false,
};