Skip to content

Commit fcc3731

Browse files
committed
move JSON.parse source text access to stable ES
1 parent 8912936 commit fcc3731

35 files changed

+552
-505
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
- Fixed increasing `.size` in `URLSearchParams.prototype.append` polyfill in IE8-
413
- Compat data improvements:
514
- [`Map` upsert proposal](https://github.com/tc39/proposal-upsert) features marked as shipped in Safari 26.2

README.md

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,14 @@ structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])
163163
- [`Promise.withResolvers`](#promisewithresolvers)
164164
- [`Symbol.asyncIterator` for asynchronous iteration](#symbolasynciterator-for-asynchronous-iteration)
165165
- [`Symbol.prototype.description`](#symbolprototypedescription)
166+
- [`JSON.parse` source text access](#jsonparse-source-text-access)
166167
- [Well-formed `JSON.stringify`](#well-formed-jsonstringify)
167168
- [Well-formed unicode strings](#well-formed-unicode-strings)
168169
- [New `Set` methods](#new-set-methods)
169170
- [`Math.sumPrecise`](#mathsumprecise)
170171
- [Stage 3 proposals](#stage-3-proposals)
171172
- [`Iterator` sequencing](#iterator-sequencing)
172173
- [`Map` upsert](#map-upsert)
173-
- [`JSON.parse` source text access](#jsonparse-source-text-access)
174174
- [`Symbol.metadata` for decorators metadata proposal](#symbolmetadata-for-decorators-metadata-proposal)
175175
- [Stage 2.7 proposals](#stage-27-proposals)
176176
- [`Iterator` chunking](#iterator-chunking)
@@ -2134,21 +2134,45 @@ instance.c; // => 42
21342134
#### ECMAScript: JSON[](#index)
21352135
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.
21362136

2137-
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).
2137+
Module [`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) .
21382138
```ts
21392139
namespace JSON {
2140+
isRawJSON(O: any): boolean;
2141+
parse(text: string, reviver?: (this: any, key: string, value: any, context: { source?: string }) => any): any;
2142+
rawJSON(text: any): RawJSON;
21402143
stringify(value: any, replacer?: Array<string | number> | (this: any, key: string, value: any) => any, space?: string | number): string | void;
21412144
@@toStringTag: 'JSON';
21422145
}
21432146
```
21442147
[*CommonJS entry points:*](#commonjs-api)
21452148
```
2149+
core-js(-pure)/es|stable|actual|full/json/is-raw-json
2150+
core-js(-pure)/es|stable|actual|full/json/parse
2151+
core-js(-pure)/es|stable|actual|full/json/raw-json
2152+
core-js(-pure)/es|stable|actual|full/json/stringify
21462153
core-js(-pure)/es|stable|actual|full/json/stringify
21472154
core-js(-pure)/es|stable|actual|full/json/to-string-tag
21482155
```
2149-
[*Examples*](https://is.gd/izZqKn):
2156+
[*Examples*](https://tinyurl.com/34ctm7cn):
21502157
```js
21512158
JSON.stringify({ '𠮷': ['\uDF06\uD834'] }); // => '{"𠮷":["\\udf06\\ud834"]}'
2159+
2160+
function digitsToBigInt(key, val, { source }) {
2161+
return /^\d+$/.test(source) ? BigInt(source) : val;
2162+
}
2163+
2164+
function bigIntToRawJSON(key, val) {
2165+
return typeof val === 'bigint' ? JSON.rawJSON(String(val)) : val;
2166+
}
2167+
2168+
const tooBigForNumber = BigInt(Number.MAX_SAFE_INTEGER) + 2n;
2169+
JSON.parse(String(tooBigForNumber), digitsToBigInt) === tooBigForNumber; // true
2170+
2171+
const wayTooBig = BigInt(`1${ '0'.repeat(1000) }`);
2172+
JSON.parse(String(wayTooBig), digitsToBigInt) === wayTooBig; // true
2173+
2174+
const embedded = JSON.stringify({ tooBigForNumber }, bigIntToRawJSON);
2175+
embedded === '{"tooBigForNumber":9007199254740993}'; // true
21522176
```
21532177

21542178
#### ECMAScript: globalThis[](#index)
@@ -2631,6 +2655,23 @@ class Symbol {
26312655
```
26322656
core-js/proposals/symbol-description
26332657
```
2658+
2659+
##### [`JSON.parse` source text access](https://github.com/tc39/proposal-json-parse-with-source)[](#index)
2660+
```ts
2661+
namespace JSON {
2662+
isRawJSON(O: any): boolean;
2663+
// patched for source support
2664+
parse(text: string, reviver?: (this: any, key: string, value: any, context: { source?: string }) => any): any;
2665+
rawJSON(text: any): RawJSON;
2666+
// patched for `JSON.rawJSON` support
2667+
stringify(value: any, replacer?: Array<string | number> | (this: any, key: string, value: any) => any, space?: string | number): string | void;
2668+
}
2669+
```
2670+
[*CommonJS entry points:*](#commonjs-api)
2671+
```
2672+
core-js/proposals/json-parse-with-source
2673+
```
2674+
26342675
##### [Well-formed `JSON.stringify`](https://github.com/tc39/proposal-well-formed-stringify)[](#index)
26352676
```ts
26362677
namespace JSON {
@@ -2743,46 +2784,6 @@ map.getOrInsertComputed('c', key => key); // => 'c'
27432784
console.log(map); // => Map { 'a': 1, 'b': 3, 'c': 'c' }
27442785
```
27452786

2746-
##### [`JSON.parse` source text access](https://github.com/tc39/proposal-json-parse-with-source)[](#index)
2747-
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).
2748-
```ts
2749-
namespace JSON {
2750-
isRawJSON(O: any): boolean;
2751-
// patched for source support
2752-
parse(text: string, reviver?: (this: any, key: string, value: any, context: { source?: string }) => any): any;
2753-
rawJSON(text: any): RawJSON;
2754-
// patched for `JSON.rawJSON` support
2755-
stringify(value: any, replacer?: Array<string | number> | (this: any, key: string, value: any) => any, space?: string | number): string | void;
2756-
}
2757-
```
2758-
[*CommonJS entry points:*](#commonjs-api)
2759-
```
2760-
core-js/proposals/json-parse-with-source
2761-
core-js(-pure)/actual|full/json/is-raw-json
2762-
core-js(-pure)/actual|full/json/parse
2763-
core-js(-pure)/actual|full/json/raw-json
2764-
core-js(-pure)/actual|full/json/stringify
2765-
```
2766-
[*Examples*](https://tinyurl.com/22phm569):
2767-
```js
2768-
function digitsToBigInt(key, val, { source }) {
2769-
return /^\d+$/.test(source) ? BigInt(source) : val;
2770-
}
2771-
2772-
function bigIntToRawJSON(key, val) {
2773-
return typeof val === 'bigint' ? JSON.rawJSON(String(val)) : val;
2774-
}
2775-
2776-
const tooBigForNumber = BigInt(Number.MAX_SAFE_INTEGER) + 2n;
2777-
JSON.parse(String(tooBigForNumber), digitsToBigInt) === tooBigForNumber; // true
2778-
2779-
const wayTooBig = BigInt(`1${ '0'.repeat(1000) }`);
2780-
JSON.parse(String(wayTooBig), digitsToBigInt) === wayTooBig; // true
2781-
2782-
const embedded = JSON.stringify({ tooBigForNumber }, bigIntToRawJSON);
2783-
embedded === '{"tooBigForNumber":9007199254740993}'; // true
2784-
```
2785-
27862787
##### [`Symbol.metadata` for decorators metadata proposal](https://github.com/tc39/proposal-decorator-metadata)[](#index)
27872788
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).
27882789
```ts

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
@@ -217,6 +217,10 @@
217217
"title": "Symbol.prototype.description",
218218
"url": "{docs-version}/docs/features/proposals/symbol-prototype-description"
219219
},
220+
{
221+
"title": "JSON.parse source text access",
222+
"url": "{docs-version}/docs/features/proposals/json-parse-source-text-access"
223+
},
220224
{
221225
"title": "Well-formed JSON.stringify",
222226
"url": "{docs-version}/docs/features/proposals/well-formed-jsonstringify"
@@ -246,10 +250,6 @@
246250
"title": "Map upsert",
247251
"url": "{docs-version}/docs/features/proposals/map-upsert"
248252
},
249-
{
250-
"title": "JSON.parse source text access",
251-
"url": "{docs-version}/docs/features/proposals/json-parse-source-text-access"
252-
},
253253
{
254254
"title": "Symbol.metadata for decorators metadata proposal",
255255
"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
@@ -803,13 +803,35 @@ export const data = {
803803
firefox: '131',
804804
safari: '18.4',
805805
},
806+
'es.json.is-raw-json': {
807+
bun: '1.1.43',
808+
chrome: '114',
809+
// enabled in 132 and disabled in 133 because of regression, https://bugzilla.mozilla.org/show_bug.cgi?id=1925334
810+
firefox: '135', // '132',
811+
safari: '18.4',
812+
},
813+
'es.json.parse': {
814+
bun: '1.1.43',
815+
chrome: '114',
816+
// enabled in 132 and disabled in 133 because of regression, https://bugzilla.mozilla.org/show_bug.cgi?id=1925334
817+
firefox: '135', // '132',
818+
safari: '18.4',
819+
},
820+
'es.json.raw-json': {
821+
bun: '1.1.43',
822+
chrome: '114',
823+
// enabled in 132 and disabled in 133 because of regression, https://bugzilla.mozilla.org/show_bug.cgi?id=1925334
824+
firefox: '135', // '132',
825+
safari: '18.4',
826+
},
806827
'es.json.stringify': {
807-
chrome: '72',
808-
firefox: '64',
809-
hermes: '0.13',
810-
'react-native': '0.72',
811-
rhino: '1.8.0',
812-
safari: '12.1',
828+
bun: '1.1.43',
829+
chrome: '114', // '72',
830+
firefox: '135', // '132', '64',
831+
// hermes: '0.13',
832+
// 'react-native': '0.72',
833+
// rhino: '1.8.0',
834+
safari: '18.4', // '12.1',
813835
},
814836
'es.json.to-string-tag': {
815837
chrome: '50',
@@ -2548,27 +2570,12 @@ export const data = {
25482570
},
25492571
'esnext.iterator.zip-keyed': {
25502572
},
2551-
'esnext.json.is-raw-json': {
2552-
bun: '1.1.43',
2553-
chrome: '114',
2554-
// enabled in 132 and disabled in 133 because of regression, https://bugzilla.mozilla.org/show_bug.cgi?id=1925334
2555-
firefox: '135', // '132',
2556-
safari: '18.4',
2557-
},
2558-
'esnext.json.parse': {
2559-
bun: '1.1.43',
2560-
chrome: '114',
2561-
// enabled in 132 and disabled in 133 because of regression, https://bugzilla.mozilla.org/show_bug.cgi?id=1925334
2562-
firefox: '135', // '132',
2563-
safari: '18.4',
2564-
},
2565-
'esnext.json.raw-json': {
2566-
bun: '1.1.43',
2567-
chrome: '114',
2568-
// enabled in 132 and disabled in 133 because of regression, https://bugzilla.mozilla.org/show_bug.cgi?id=1925334
2569-
firefox: '135', // '132',
2570-
safari: '18.4',
2571-
},
2573+
// TODO: Remove from `core-js@4`
2574+
'esnext.json.is-raw-json': null,
2575+
// TODO: Remove from `core-js@4`
2576+
'esnext.json.parse': null,
2577+
// TODO: Remove from `core-js@4`
2578+
'esnext.json.raw-json': null,
25722579
'esnext.map.delete-all': {
25732580
},
25742581
// TODO: Remove from `core-js@4`
@@ -3179,6 +3186,9 @@ export const renamed = new Map([
31793186
['esnext.iterator.some', 'es.iterator.some'],
31803187
['esnext.iterator.take', 'es.iterator.take'],
31813188
['esnext.iterator.to-array', 'es.iterator.to-array'],
3189+
['esnext.json.is-raw-json', 'es.json.is-raw-json'],
3190+
['esnext.json.parse', 'es.json.parse'],
3191+
['esnext.json.raw-json', 'es.json.raw-json'],
31823192
['esnext.map.group-by', 'es.map.group-by'],
31833193
['esnext.math.f16round', 'es.math.f16round'],
31843194
['esnext.math.sum-precise', 'es.math.sum-precise'],

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,4 +311,9 @@ export default {
311311
'es.uint8-array.to-base64',
312312
'es.uint8-array.to-hex',
313313
],
314+
3.47: [
315+
'es.json.is-raw-json',
316+
'es.json.parse',
317+
'es.json.raw-json',
318+
],
314319
};

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;
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
2-
require('../../modules/es.object.create');
3-
require('../../modules/es.object.freeze');
2+
var parent = require('../../stable/json/raw-json');
3+
require('../../modules/es.json.stringify');
44
require('../../modules/esnext.json.raw-json');
5-
var path = require('../../internals/path');
65

7-
module.exports = path.JSON.rawJSON;
6+
module.exports = parent;

0 commit comments

Comments
 (0)