Skip to content

Commit 400f00e

Browse files
committed
move JSON.parse source text access to stable ES
1 parent 332676c commit 400f00e

36 files changed

+575
-509
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22
### Unreleased
3+
- [`JSON.parse` source text access proposal](https://github.com/tc39/proposal-json-parse-with-source) :
4+
- Built-ins:
5+
- `JSON.isRawJSON`
6+
- `JSON.parse`
7+
- `JSON.rawJSON`
8+
- `JSON.stringify`
9+
- Moved to stable ES, November 2025 TC39 meeting
10+
- Added `es.` namespace modules, `/es/` and `/stable/` namespaces entries
11+
- Reworked `JSON.stringify` internals
312
- [`Iterator` sequencing proposal](https://github.com/tc39/proposal-iterator-sequencing):
413
- Built-ins:
514
- `Iterator.concat`

README.md

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,14 @@ structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])
164164
- [`Promise.withResolvers`](#promisewithresolvers)
165165
- [`Symbol.asyncIterator` for asynchronous iteration](#symbolasynciterator-for-asynchronous-iteration)
166166
- [`Symbol.prototype.description`](#symbolprototypedescription)
167+
- [`JSON.parse` source text access](#jsonparse-source-text-access)
167168
- [Well-formed `JSON.stringify`](#well-formed-jsonstringify)
168169
- [Well-formed unicode strings](#well-formed-unicode-strings)
169170
- [New `Set` methods](#new-set-methods)
170171
- [`Math.sumPrecise`](#mathsumprecise)
171172
- [Stage 3 proposals](#stage-3-proposals)
172173
- [Joint iteration](#joint-iteration)
173174
- [`Map` upsert](#map-upsert)
174-
- [`JSON.parse` source text access](#jsonparse-source-text-access)
175175
- [`Symbol.metadata` for decorators metadata proposal](#symbolmetadata-for-decorators-metadata-proposal)
176176
- [Stage 2.7 proposals](#stage-27-proposals)
177177
- [`Iterator` chunking](#iterator-chunking)
@@ -2139,23 +2139,47 @@ instance.c; // => 42
21392139
```
21402140

21412141
#### ECMAScript: JSON[](#index)
2142-
Since `JSON` object is missed only in very old engines like IE7-, `core-js` does not provide a full `JSON` polyfill, however, fix already existing implementations by the current standard, for example, [well-formed `JSON.stringify`](https://github.com/tc39/proposal-well-formed-stringify). `JSON` is also fixed in other modules - for example, `Symbol` polyfill fixes `JSON.stringify` for correct work with symbols.
2142+
Since `JSON` object is missed only in very old engines like IE7-, `core-js` does not provide a full `JSON.{ parse, stringify }` polyfill, however, fix already existing implementations by the current standard.
21432143

2144-
Module [`es.json.to-string-tag`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.json.to-string-tag.js) and [`es.json.stringify`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.json.stringify.js).
2144+
Modules [`es.json.is-raw-json`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.json.is-raw-json.js), [`es.json.parse`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.json.parse.js), [`es.json.raw-json`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.json.raw-json.js), [`es.json.stringify`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.json.stringify.js) and [`es.json.to-string-tag`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.json.to-string-tag.js) .
21452145
```ts
21462146
namespace JSON {
2147+
isRawJSON(O: any): boolean;
2148+
parse(text: string, reviver?: (this: any, key: string, value: any, context: { source?: string }) => any): any;
2149+
rawJSON(text: any): RawJSON;
21472150
stringify(value: any, replacer?: Array<string | number> | (this: any, key: string, value: any) => any, space?: string | number): string | void;
21482151
@@toStringTag: 'JSON';
21492152
}
21502153
```
21512154
[*CommonJS entry points:*](#commonjs-api)
21522155
```
2156+
core-js(-pure)/es|stable|actual|full/json/is-raw-json
2157+
core-js(-pure)/es|stable|actual|full/json/parse
2158+
core-js(-pure)/es|stable|actual|full/json/raw-json
2159+
core-js(-pure)/es|stable|actual|full/json/stringify
21532160
core-js(-pure)/es|stable|actual|full/json/stringify
21542161
core-js(-pure)/es|stable|actual|full/json/to-string-tag
21552162
```
2156-
[*Examples*](https://is.gd/izZqKn):
2163+
[*Examples*](https://tinyurl.com/34ctm7cn):
21572164
```js
21582165
JSON.stringify({ '𠮷': ['\uDF06\uD834'] }); // => '{"𠮷":["\\udf06\\ud834"]}'
2166+
2167+
function digitsToBigInt(key, val, { source }) {
2168+
return /^\d+$/.test(source) ? BigInt(source) : val;
2169+
}
2170+
2171+
function bigIntToRawJSON(key, val) {
2172+
return typeof val === 'bigint' ? JSON.rawJSON(String(val)) : val;
2173+
}
2174+
2175+
const tooBigForNumber = BigInt(Number.MAX_SAFE_INTEGER) + 2n;
2176+
JSON.parse(String(tooBigForNumber), digitsToBigInt) === tooBigForNumber; // true
2177+
2178+
const wayTooBig = BigInt(`1${ '0'.repeat(1000) }`);
2179+
JSON.parse(String(wayTooBig), digitsToBigInt) === wayTooBig; // true
2180+
2181+
const embedded = JSON.stringify({ tooBigForNumber }, bigIntToRawJSON);
2182+
embedded === '{"tooBigForNumber":9007199254740993}'; // true
21592183
```
21602184

21612185
#### ECMAScript: globalThis[](#index)
@@ -2649,6 +2673,23 @@ class Symbol {
26492673
```
26502674
core-js/proposals/symbol-description
26512675
```
2676+
2677+
##### [`JSON.parse` source text access](https://github.com/tc39/proposal-json-parse-with-source)[](#index)
2678+
```ts
2679+
namespace JSON {
2680+
isRawJSON(O: any): boolean;
2681+
// patched for source support
2682+
parse(text: string, reviver?: (this: any, key: string, value: any, context: { source?: string }) => any): any;
2683+
rawJSON(text: any): RawJSON;
2684+
// patched for `JSON.rawJSON` support
2685+
stringify(value: any, replacer?: Array<string | number> | (this: any, key: string, value: any) => any, space?: string | number): string | void;
2686+
}
2687+
```
2688+
[*CommonJS entry points:*](#commonjs-api)
2689+
```
2690+
core-js/proposals/json-parse-with-source
2691+
```
2692+
26522693
##### [Well-formed `JSON.stringify`](https://github.com/tc39/proposal-well-formed-stringify)[](#index)
26532694
```ts
26542695
namespace JSON {
@@ -2792,46 +2833,6 @@ map.getOrInsertComputed('c', key => key); // => 'c'
27922833
console.log(map); // => Map { 'a': 1, 'b': 3, 'c': 'c' }
27932834
```
27942835

2795-
##### [`JSON.parse` source text access](https://github.com/tc39/proposal-json-parse-with-source)[](#index)
2796-
Modules [`esnext.json.is-raw-json`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.json.is-raw-json.js), [`esnext.json.parse`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.json.parse.js), [`esnext.json.raw-json`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.json.raw-json.js).
2797-
```ts
2798-
namespace JSON {
2799-
isRawJSON(O: any): boolean;
2800-
// patched for source support
2801-
parse(text: string, reviver?: (this: any, key: string, value: any, context: { source?: string }) => any): any;
2802-
rawJSON(text: any): RawJSON;
2803-
// patched for `JSON.rawJSON` support
2804-
stringify(value: any, replacer?: Array<string | number> | (this: any, key: string, value: any) => any, space?: string | number): string | void;
2805-
}
2806-
```
2807-
[*CommonJS entry points:*](#commonjs-api)
2808-
```
2809-
core-js/proposals/json-parse-with-source
2810-
core-js(-pure)/actual|full/json/is-raw-json
2811-
core-js(-pure)/actual|full/json/parse
2812-
core-js(-pure)/actual|full/json/raw-json
2813-
core-js(-pure)/actual|full/json/stringify
2814-
```
2815-
[*Examples*](https://tinyurl.com/22phm569):
2816-
```js
2817-
function digitsToBigInt(key, val, { source }) {
2818-
return /^\d+$/.test(source) ? BigInt(source) : val;
2819-
}
2820-
2821-
function bigIntToRawJSON(key, val) {
2822-
return typeof val === 'bigint' ? JSON.rawJSON(String(val)) : val;
2823-
}
2824-
2825-
const tooBigForNumber = BigInt(Number.MAX_SAFE_INTEGER) + 2n;
2826-
JSON.parse(String(tooBigForNumber), digitsToBigInt) === tooBigForNumber; // true
2827-
2828-
const wayTooBig = BigInt(`1${ '0'.repeat(1000) }`);
2829-
JSON.parse(String(wayTooBig), digitsToBigInt) === wayTooBig; // true
2830-
2831-
const embedded = JSON.stringify({ tooBigForNumber }, bigIntToRawJSON);
2832-
embedded === '{"tooBigForNumber":9007199254740993}'; // true
2833-
```
2834-
28352836
##### [`Symbol.metadata` for decorators metadata proposal](https://github.com/tc39/proposal-decorator-metadata)[](#index)
28362837
Modules [`esnext.symbol.metadata`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.symbol.metadata.js) and [`esnext.function.metadata`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.function.metadata.js).
28372838
```ts
Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,45 @@
11
# ECMAScript: JSON
2-
Since `JSON` object is missed only in very old engines like IE7-, `core-js` does not provide a full `JSON` polyfill, however, fix already existing implementations by the current standard, for example, [well-formed `JSON.stringify`](https://github.com/tc39/proposal-well-formed-stringify). `JSON` is also fixed in other modules - for example, `Symbol` polyfill fixes `JSON.stringify` for correct work with symbols.
2+
Since `JSON` object is missed only in very old engines like IE7-, `core-js` does not provide a full `JSON.{ parse, stringify }` polyfill, however, fix already existing implementations by the current standard.
33

44
## Modules
5-
[`es.json.to-string-tag`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.json.to-string-tag.js) and [`es.json.stringify`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.json.stringify.js).
5+
[`es.json.is-raw-json`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.json.is-raw-json.js), [`es.json.parse`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.json.parse.js), [`es.json.raw-json`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.json.raw-json.js), [`es.json.stringify`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.json.stringify.js) and [`es.json.to-string-tag`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.json.to-string-tag.js).
66

77
## Built-ins signatures
88
```ts
99
namespace JSON {
10+
isRawJSON(O: any): boolean;
11+
parse(text: string, reviver?: (this: any, key: string, value: any, context: { source?: string }) => any): any;
12+
rawJSON(text: any): RawJSON;
1013
stringify(value: any, replacer?: Array<string | number> | (this: any, key: string, value: any) => any, space?: string | number): string | void;
1114
@@toStringTag: 'JSON';
1215
}
1316
```
1417

1518
## [Entry points]({docs-version}/docs/usage#h-entry-points)
1619
```
17-
core-js(-pure)/es|stable|actual|full/json/stringify
20+
core-js(-pure)/es|stable|actual|full/json/is-raw-json
21+
core-js(-pure)/es|stable|actual|full/json/parse
22+
core-js(-pure)/es|stable|actual|full/json/raw-json
1823
core-js(-pure)/es|stable|actual|full/json/to-string-tag
1924
```
2025

2126
## Examples
2227
```js
28+
function digitsToBigInt(key, val, { source }) {
29+
return /^\d+$/.test(source) ? BigInt(source) : val;
30+
}
31+
32+
function bigIntToRawJSON(key, val) {
33+
return typeof val === 'bigint' ? JSON.rawJSON(String(val)) : val;
34+
}
35+
36+
const tooBigForNumber = BigInt(Number.MAX_SAFE_INTEGER) + 2n;
37+
JSON.parse(String(tooBigForNumber), digitsToBigInt) === tooBigForNumber; // => true
38+
39+
const wayTooBig = BigInt(`1${ '0'.repeat(1000) }`);
40+
JSON.parse(String(wayTooBig), digitsToBigInt) === wayTooBig; // => true
41+
42+
JSON.stringify({ tooBigForNumber }, bigIntToRawJSON); // => '{"tooBigForNumber":9007199254740993}'
43+
2344
JSON.stringify({ '𠮷': ['\uDF06\uD834'] }); // => '{"𠮷":["\\udf06\\ud834"]}'
2445
```

docs/web/docs/features/proposals/json-parse-source-text-access.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[Proposal repo](https://github.com/tc39/proposal-json-parse-with-source)
44

55
## Modules
6-
[`esnext.json.is-raw-json`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.json.is-raw-json.js), [`esnext.json.parse`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.json.parse.js), [`esnext.json.raw-json`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.json.raw-json.js).
6+
[`es.json.is-raw-json`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.json.is-raw-json.js), [`es.json.parse`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.json.parse.js), [`es.json.raw-json`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.json.raw-json.js).
77

88
## Built-ins signatures
99
```ts
@@ -20,10 +20,10 @@ namespace JSON {
2020
## [Entry points]({docs-version}/docs/usage#h-entry-points)
2121
```ts
2222
core-js/proposals/json-parse-with-source
23-
core-js(-pure)/actual|full/json/is-raw-json
24-
core-js(-pure)/actual|full/json/parse
25-
core-js(-pure)/actual|full/json/raw-json
26-
core-js(-pure)/actual|full/json/stringify
23+
core-js(-pure)/es|stable|actual|full/json/is-raw-json
24+
core-js(-pure)/es|stable|actual|full/json/parse
25+
core-js(-pure)/es|stable|actual|full/json/raw-json
26+
core-js(-pure)/es|stable|actual|full/json/stringify
2727
```
2828

2929
## Examples

docs/web/docs/menu.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@
221221
"title": "Symbol.prototype.description",
222222
"url": "{docs-version}/docs/features/proposals/symbol-prototype-description"
223223
},
224+
{
225+
"title": "JSON.parse source text access",
226+
"url": "{docs-version}/docs/features/proposals/json-parse-source-text-access"
227+
},
224228
{
225229
"title": "Well-formed JSON.stringify",
226230
"url": "{docs-version}/docs/features/proposals/well-formed-jsonstringify"
@@ -250,10 +254,6 @@
250254
"title": "Map upsert",
251255
"url": "{docs-version}/docs/features/proposals/map-upsert"
252256
},
253-
{
254-
"title": "JSON.parse source text access",
255-
"url": "{docs-version}/docs/features/proposals/json-parse-source-text-access"
256-
},
257257
{
258258
"title": "Symbol.metadata for decorators metadata proposal",
259259
"url": "{docs-version}/docs/features/proposals/symbol-metadata"

packages/core-js-compat/src/data.mjs

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -806,13 +806,35 @@ export const data = {
806806
firefox: '131',
807807
safari: '18.4',
808808
},
809+
'es.json.is-raw-json': {
810+
bun: '1.1.43',
811+
chrome: '114',
812+
// enabled in 132 and disabled in 133 because of regression, https://bugzilla.mozilla.org/show_bug.cgi?id=1925334
813+
firefox: '135', // '132',
814+
safari: '18.4',
815+
},
816+
'es.json.parse': {
817+
bun: '1.1.43',
818+
chrome: '114',
819+
// enabled in 132 and disabled in 133 because of regression, https://bugzilla.mozilla.org/show_bug.cgi?id=1925334
820+
firefox: '135', // '132',
821+
safari: '18.4',
822+
},
823+
'es.json.raw-json': {
824+
bun: '1.1.43',
825+
chrome: '114',
826+
// enabled in 132 and disabled in 133 because of regression, https://bugzilla.mozilla.org/show_bug.cgi?id=1925334
827+
firefox: '135', // '132',
828+
safari: '18.4',
829+
},
809830
'es.json.stringify': {
810-
chrome: '72',
811-
firefox: '64',
812-
hermes: '0.13',
813-
'react-native': '0.72',
814-
rhino: '1.8.0',
815-
safari: '12.1',
831+
bun: '1.1.43',
832+
chrome: '114', // '72',
833+
firefox: '135', // '132', '64',
834+
// hermes: '0.13',
835+
// 'react-native': '0.72',
836+
// rhino: '1.8.0',
837+
safari: '18.4', // '12.1',
816838
},
817839
'es.json.to-string-tag': {
818840
chrome: '50',
@@ -2551,27 +2573,12 @@ export const data = {
25512573
},
25522574
'esnext.iterator.zip-keyed': {
25532575
},
2554-
'esnext.json.is-raw-json': {
2555-
bun: '1.1.43',
2556-
chrome: '114',
2557-
// enabled in 132 and disabled in 133 because of regression, https://bugzilla.mozilla.org/show_bug.cgi?id=1925334
2558-
firefox: '135', // '132',
2559-
safari: '18.4',
2560-
},
2561-
'esnext.json.parse': {
2562-
bun: '1.1.43',
2563-
chrome: '114',
2564-
// enabled in 132 and disabled in 133 because of regression, https://bugzilla.mozilla.org/show_bug.cgi?id=1925334
2565-
firefox: '135', // '132',
2566-
safari: '18.4',
2567-
},
2568-
'esnext.json.raw-json': {
2569-
bun: '1.1.43',
2570-
chrome: '114',
2571-
// enabled in 132 and disabled in 133 because of regression, https://bugzilla.mozilla.org/show_bug.cgi?id=1925334
2572-
firefox: '135', // '132',
2573-
safari: '18.4',
2574-
},
2576+
// TODO: Remove from `core-js@4`
2577+
'esnext.json.is-raw-json': null,
2578+
// TODO: Remove from `core-js@4`
2579+
'esnext.json.parse': null,
2580+
// TODO: Remove from `core-js@4`
2581+
'esnext.json.raw-json': null,
25752582
'esnext.map.delete-all': {
25762583
},
25772584
// TODO: Remove from `core-js@4`
@@ -3183,6 +3190,9 @@ export const renamed = new Map([
31833190
['esnext.iterator.some', 'es.iterator.some'],
31843191
['esnext.iterator.take', 'es.iterator.take'],
31853192
['esnext.iterator.to-array', 'es.iterator.to-array'],
3193+
['esnext.json.is-raw-json', 'es.json.is-raw-json'],
3194+
['esnext.json.parse', 'es.json.parse'],
3195+
['esnext.json.raw-json', 'es.json.raw-json'],
31863196
['esnext.map.group-by', 'es.map.group-by'],
31873197
['esnext.math.f16round', 'es.math.f16round'],
31883198
['esnext.math.sum-precise', 'es.math.sum-precise'],

packages/core-js-compat/src/modules-by-versions.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,5 +313,8 @@ export default {
313313
],
314314
3.47: [
315315
'es.iterator.concat',
316+
'es.json.is-raw-json',
317+
'es.json.parse',
318+
'es.json.raw-json',
316319
],
317320
};

packages/core-js/actual/json/index.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
'use strict';
22
var parent = require('../../stable/json');
3-
require('../../modules/es.object.create');
4-
require('../../modules/es.object.freeze');
5-
require('../../modules/es.object.keys');
63
require('../../modules/esnext.json.is-raw-json');
74
require('../../modules/esnext.json.parse');
85
require('../../modules/esnext.json.raw-json');
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2+
var parent = require('../../stable/json/is-raw-json');
23
require('../../modules/esnext.json.is-raw-json');
3-
var path = require('../../internals/path');
44

5-
module.exports = path.JSON.isRawJSON;
5+
module.exports = parent;
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
2-
require('../../modules/es.object.keys');
2+
var parent = require('../../stable/json/parse');
33
require('../../modules/esnext.json.parse');
4-
var path = require('../../internals/path');
54

6-
module.exports = path.JSON.parse;
5+
module.exports = parent;

0 commit comments

Comments
 (0)