Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ So in both cases, the `BigInt` / `RegExp` can be reconstructed from this extra d

`Infinity` is serialized as `1e+400` - which `JSON.parse` converts back to `Infinity`.

A `decorators` field is added to `ClassDeclaration`, `ClassExpression`, `MethodDefinition`,
and `PropertyDefinition` (stage 3 proposal).

A `phase` field is added to `ImportDeclaration` and `ImportExpression` (stage 3 proposal).

A non-standard `hashbang` field is added to `Program`.
Expand Down
7 changes: 7 additions & 0 deletions src/utils/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const fieldOrders = JSON.parse(fieldOrdersJson);
// which will be replaced in JSON with `1e+400`.
// * Sort RegExp `Literal`s' `regex.flags` property in alphabetical order, the way V8 does.
// * Add `phase` field to `ImportDeclaration` and `ImportExpression`.
// * Add `decorators` field to classes, class methods, and class properties.
export function transformerAcorn(_key, value) {
if (typeof value === 'bigint') return null;
if (value === Infinity) return INFINITY_PLACEHOLDER;
Expand All @@ -27,6 +28,11 @@ export function transformerAcorn(_key, value) {
} else if (type === 'Literal' && Object.hasOwn(value, 'regex')) {
value.regex.flags = [...value.regex.flags].sort().join('');
value.value = null;
} else if (
type === 'ClassDeclaration' || type === 'ClassExpression' ||
type === 'MethodDefinition' || type === 'PropertyDefinition'
) {
if (!Object.hasOwn(value, 'decorators')) value.decorators = [];
}

// Re-order fields
Expand All @@ -50,6 +56,7 @@ export function transformerAcorn(_key, value) {
// Makes the same changes as `acornTransformer`, but also:
// * Converts location fields.
// * Replaces `undefined` with `null`.
// * Does not add `decorators` fields, as they already exist.
export function transformerTs(_key, value) {
if (typeof value === 'bigint') return null;
if (value === Infinity) return INFINITY_PLACEHOLDER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"type": "ClassDeclaration",
"start": 590,
"end": 622,
"decorators": [],
"id": {
"type": "Identifier",
"start": 596,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"type": "ClassDeclaration",
"start": 935,
"end": 967,
"decorators": [],
"id": {
"type": "Identifier",
"start": 941,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"type": "ClassDeclaration",
"start": 600,
"end": 632,
"decorators": [],
"id": {
"type": "Identifier",
"start": 606,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"type": "ClassDeclaration",
"start": 600,
"end": 632,
"decorators": [],
"id": {
"type": "Identifier",
"start": 606,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"type": "ClassDeclaration",
"start": 606,
"end": 638,
"decorators": [],
"id": {
"type": "Identifier",
"start": 612,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"type": "ClassDeclaration",
"start": 609,
"end": 641,
"decorators": [],
"id": {
"type": "Identifier",
"start": 615,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"type": "ClassExpression",
"start": 314,
"end": 337,
"decorators": [],
"id": null,
"superClass": {
"type": "Identifier",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
"type": "ClassDeclaration",
"start": 820,
"end": 849,
"decorators": [],
"id": {
"type": "Identifier",
"start": 826,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"type": "ClassDeclaration",
"start": 730,
"end": 759,
"decorators": [],
"id": {
"type": "Identifier",
"start": 736,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"type": "ClassDeclaration",
"start": 514,
"end": 624,
"decorators": [],
"id": {
"type": "Identifier",
"start": 520,
Expand All @@ -51,6 +52,7 @@
"type": "MethodDefinition",
"start": 534,
"end": 620,
"decorators": [],
"key": {
"type": "Identifier",
"start": 538,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"type": "ClassDeclaration",
"start": 383,
"end": 457,
"decorators": [],
"id": {
"type": "Identifier",
"start": 389,
Expand All @@ -23,6 +24,7 @@
"type": "MethodDefinition",
"start": 402,
"end": 455,
"decorators": [],
"key": {
"type": "Identifier",
"start": 402,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"type": "ClassDeclaration",
"start": 469,
"end": 497,
"decorators": [],
"id": {
"type": "Identifier",
"start": 475,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"type": "ClassDeclaration",
"start": 553,
"end": 577,
"decorators": [],
"id": {
"type": "Identifier",
"start": 559,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"type": "ClassDeclaration",
"start": 1073,
"end": 1099,
"decorators": [],
"id": {
"type": "Identifier",
"start": 1079,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"type": "ClassDeclaration",
"start": 1738,
"end": 1768,
"decorators": [],
"id": {
"type": "Identifier",
"start": 1744,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"type": "ClassDeclaration",
"start": 1761,
"end": 1791,
"decorators": [],
"id": {
"type": "Identifier",
"start": 1767,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"type": "ClassDeclaration",
"start": 1024,
"end": 1074,
"decorators": [],
"id": {
"type": "Identifier",
"start": 1030,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"type": "ClassDeclaration",
"start": 261,
"end": 291,
"decorators": [],
"id": {
"type": "Identifier",
"start": 267,
Expand All @@ -30,6 +31,7 @@
"type": "ClassDeclaration",
"start": 292,
"end": 330,
"decorators": [],
"id": {
"type": "Identifier",
"start": 298,
Expand All @@ -53,6 +55,7 @@
"type": "ClassDeclaration",
"start": 331,
"end": 371,
"decorators": [],
"id": {
"type": "Identifier",
"start": 337,
Expand All @@ -76,6 +79,7 @@
"type": "ClassDeclaration",
"start": 372,
"end": 420,
"decorators": [],
"id": {
"type": "Identifier",
"start": 378,
Expand All @@ -99,6 +103,7 @@
"type": "ClassDeclaration",
"start": 421,
"end": 463,
"decorators": [],
"id": {
"type": "Identifier",
"start": 427,
Expand All @@ -122,6 +127,7 @@
"type": "ClassDeclaration",
"start": 464,
"end": 502,
"decorators": [],
"id": {
"type": "Identifier",
"start": 470,
Expand All @@ -145,6 +151,7 @@
"type": "ClassDeclaration",
"start": 503,
"end": 539,
"decorators": [],
"id": {
"type": "Identifier",
"start": 509,
Expand Down Expand Up @@ -749,6 +756,7 @@
"type": "ClassDeclaration",
"start": 998,
"end": 1046,
"decorators": [],
"id": {
"type": "Identifier",
"start": 1004,
Expand Down Expand Up @@ -896,6 +904,7 @@
"type": "ClassDeclaration",
"start": 1166,
"end": 1216,
"decorators": [],
"id": {
"type": "Identifier",
"start": 1172,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"type": "ClassDeclaration",
"start": 408,
"end": 418,
"decorators": [],
"id": {
"type": "Identifier",
"start": 414,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"type": "ClassDeclaration",
"start": 621,
"end": 686,
"decorators": [],
"id": {
"type": "Identifier",
"start": 627,
Expand All @@ -28,6 +29,7 @@
"type": "MethodDefinition",
"start": 648,
"end": 684,
"decorators": [],
"key": {
"type": "Identifier",
"start": 648,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"type": "ClassDeclaration",
"start": 522,
"end": 567,
"decorators": [],
"id": {
"type": "Identifier",
"start": 528,
Expand All @@ -28,6 +29,7 @@
"type": "MethodDefinition",
"start": 549,
"end": 565,
"decorators": [],
"key": {
"type": "Identifier",
"start": 549,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"type": "ClassExpression",
"start": 333,
"end": 438,
"decorators": [],
"id": null,
"superClass": null,
"body": {
Expand All @@ -64,6 +65,7 @@
"type": "MethodDefinition",
"start": 341,
"end": 425,
"decorators": [],
"key": {
"type": "Identifier",
"start": 384,
Expand Down Expand Up @@ -129,6 +131,7 @@
"type": "ClassExpression",
"start": 450,
"end": 577,
"decorators": [],
"id": null,
"superClass": null,
"body": {
Expand All @@ -140,6 +143,7 @@
"type": "MethodDefinition",
"start": 458,
"end": 564,
"decorators": [],
"key": {
"type": "Literal",
"start": 511,
Expand Down Expand Up @@ -206,6 +210,7 @@
"type": "ClassExpression",
"start": 589,
"end": 714,
"decorators": [],
"id": null,
"superClass": null,
"body": {
Expand All @@ -217,6 +222,7 @@
"type": "MethodDefinition",
"start": 597,
"end": 701,
"decorators": [],
"key": {
"type": "Identifier",
"start": 650,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"type": "ClassExpression",
"start": 333,
"end": 431,
"decorators": [],
"id": null,
"superClass": null,
"body": {
Expand All @@ -68,6 +69,7 @@
"type": "MethodDefinition",
"start": 353,
"end": 418,
"decorators": [],
"key": {
"type": "Identifier",
"start": 377,
Expand Down Expand Up @@ -146,6 +148,7 @@
"type": "ClassExpression",
"start": 453,
"end": 573,
"decorators": [],
"id": null,
"superClass": null,
"body": {
Expand All @@ -157,6 +160,7 @@
"type": "MethodDefinition",
"start": 473,
"end": 560,
"decorators": [],
"key": {
"type": "Literal",
"start": 507,
Expand Down Expand Up @@ -236,6 +240,7 @@
"type": "ClassExpression",
"start": 595,
"end": 713,
"decorators": [],
"id": null,
"superClass": null,
"body": {
Expand All @@ -247,6 +252,7 @@
"type": "MethodDefinition",
"start": 615,
"end": 700,
"decorators": [],
"key": {
"type": "Identifier",
"start": 649,
Expand Down
Loading
Loading