Skip to content

Commit

Permalink
[flow][estree] make type param "const" property a boolean
Browse files Browse the repository at this point in the history
Summary:
Makes "const" a required boolean property of the TypeParameter estree node.

The main change is in estree_translator.ml and custom_ast_types.js. The rest is changes in the expected estree outputs.

Changelog: [internal]

Reviewed By: SamChou19815

Differential Revision: D66844177

fbshipit-source-id: 88e7c1c1991a695e6bcbae6ea726be4cc6182b86
  • Loading branch information
panagosg7 authored and facebook-github-bot committed Dec 7, 2024
1 parent 776e886 commit a03cc27
Show file tree
Hide file tree
Showing 137 changed files with 281 additions and 137 deletions.
3 changes: 1 addition & 2 deletions packages/flow-parser/test/custom_ast_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,11 @@ function custom_ast_types(fork) {
.field('argument', def('FlowType'));
def('TypeParameter')
.field('usesExtendsBound', or(undefined, Boolean))
.field('const', or(def('ConstModifier'), null), defaults['null']);
.field('const', Boolean);
def('Variance').field(
'kind',
or('plus', 'minus', 'readonly', 'in', 'out', 'in-out'),
);
def('ConstModifier').bases('Node');
def('AsExpression')
.bases('Expression')
.build('expression', 'typeAnnotation')
Expand Down
1 change: 1 addition & 0 deletions packages/flow-parser/test/esprima_test_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ function handleSpecialObjectCompare(esprima, flow, env) {
param.bound = param.typeAnnotation || null;
param.default = param.default || null;
param.variance = param.variance || null;
param.const = param.const || false;
delete param.typeAnnotation;
delete param.optional;
}
Expand Down
4 changes: 1 addition & 3 deletions src/parser/estree_translator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2199,12 +2199,10 @@ with type t = Impl.t = struct
backwards-compatibility. TODO: change this? *)
("name", string name);
("bound", hint type_annotation bound);
("const", bool (Option.is_some const));
("variance", option variance tp_var);
("default", option _type default);
]
@ (match const with
| Some (loc, comments) -> [("const", node ?comments "ConstModifier" loc [])]
| None -> [])
@
match bound_kind with
| Type.TypeParam.Colon -> []
Expand Down
1 change: 1 addition & 0 deletions src/parser/test/flow/ES6/modules/migrated_0023.tree.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"range":[24,25],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down
3 changes: 2 additions & 1 deletion src/parser/test/flow/ES6/modules/migrated_0024.tree.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"range":[23,25],
"body":[]
},
"superClass":null,
"typeParameters":{
"type":"TypeParameterDeclaration",
"loc":{"source":null,"start":{"line":1,"column":20},"end":{"line":1,"column":23}},
Expand All @@ -30,11 +29,13 @@
"range":[21,22],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
]
},
"superClass":null,
"superTypeParameters":null,
"implements":[],
"decorators":[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"range":[1,2],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
"range":[17,18],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
},
Expand All @@ -149,6 +150,7 @@
"range":[20,21],
"name":"R",
"bound":null,
"const":false,
"variance":null,
"default":null
},
Expand All @@ -158,6 +160,7 @@
"range":[23,24],
"name":"S",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"range":[9,10],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"range":[19,20],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"range":[20,21],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"range":[27,28],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"range":[25,26],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"range":[11,12],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"range": [8, 9],
"name": "T",
"bound": null,
"const":false,
"variance": null,
"default": null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"range":[18,19],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"range":[20,21],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"range":[16,17],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"range":[19,20],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"range":[26,27],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"range":[23,24],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"range":[23,24],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"range":[19,20],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"range":[19,20],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@
"range":[236,237],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down Expand Up @@ -360,6 +361,7 @@
"range":[395,396],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
"range":[143,144],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down Expand Up @@ -459,6 +460,7 @@
"range":[603,604],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down Expand Up @@ -915,6 +917,7 @@
"range":[1187,1188],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down Expand Up @@ -1022,6 +1025,7 @@
"range":[1388,1389],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"range":[84,85],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down Expand Up @@ -170,6 +171,7 @@
"range":[195,196],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down
3 changes: 3 additions & 0 deletions src/parser/test/flow/comment_interning/class_method.tree.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"range":[55,56],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down Expand Up @@ -823,6 +824,7 @@
"range":[814,815],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down Expand Up @@ -939,6 +941,7 @@
"range":[933,934],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"range":[147,148],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down Expand Up @@ -456,6 +457,7 @@
"range":[639,640],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
"range":[152,153],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down Expand Up @@ -427,6 +428,7 @@
"range":[592,593],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@
"range":[444,445],
"name":"U",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down Expand Up @@ -321,6 +322,7 @@
"range":[509,510],
"name":"U",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
"range":[268,269],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down Expand Up @@ -719,6 +720,7 @@
"range":[936,937],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down Expand Up @@ -867,6 +869,7 @@
"range":[1097,1098],
"name":"T",
"bound":null,
"const":false,
"variance":null,
"default":null
}
Expand Down
Loading

0 comments on commit a03cc27

Please sign in to comment.