Skip to content

Commit a43fe66

Browse files
SamChou19815facebook-github-bot
authored andcommitted
Turn on various flags in hermes-parser that we plan to make on-by-default soon
Reviewed By: marcoww6 Differential Revision: D82697071 fbshipit-source-id: a581654a14468163de02df347a941a46d4f1c3fd
1 parent 5b91d78 commit a43fe66

File tree

9 files changed

+29
-0
lines changed

9 files changed

+29
-0
lines changed

tools/hermes-parser/js/.flowconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ component_syntax=true
2727
enums=true
2828
experimental.pattern_matching=true
2929

30+
experimental.constant_condition=true
31+
experimental.constant_condition.null_void.includes=<PROJECT_ROOT>
32+
experimental.constant_condition.boolean_literal.includes=<PROJECT_ROOT>
33+
experimental.constant_condition.function.includes=<PROJECT_ROOT>
34+
experimental.constant_condition.invalid_comparison.general.includes=<PROJECT_ROOT>
35+
experimental.constant_condition.invalid_comparison.null_check.includes=<PROJECT_ROOT>
36+
37+
experimental.natural_inference.array_object_literals.implicit_instantiation_fix=true
38+
experimental.natural_inference.jsx_literal=true
39+
3040
[version]
3141
^0.283.0
3242

tools/hermes-parser/js/hermes-eslint/src/scope-manager/scope/ScopeBase.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,17 +246,24 @@ type VariableScope =
246246
this.type = type;
247247

248248
this.__dynamic =
249+
// $FlowFixMe[invalid-compare]
249250
this.type === ScopeType.Global || this.type === ScopeType.With;
250251

251252
this.block = block;
252253

253254
this.variableScope =
254255
this.type === ScopeType.ClassFieldInitializer ||
256+
// $FlowFixMe[invalid-compare]
255257
this.type === ScopeType.ClassStaticBlock ||
258+
// $FlowFixMe[invalid-compare]
256259
this.type === ScopeType.Function ||
260+
// $FlowFixMe[invalid-compare]
257261
this.type === ScopeType.Global ||
262+
// $FlowFixMe[invalid-compare]
258263
this.type === ScopeType.Module ||
264+
// $FlowFixMe[invalid-compare]
259265
this.type === ScopeType.DeclareModule ||
266+
// $FlowFixMe[invalid-compare]
260267
this.type === ScopeType.DeclareNamespace
261268
? // $FlowFixMe[incompatible-type] not possible to teach flow this is safe
262269
this

tools/hermes-parser/js/hermes-estree/src/predicates.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export function isExpression(node /*: ESNode */) /*: implies node is Expression
135135
node.type === 'ArrayExpression' ||
136136
node.type === 'ObjectExpression' ||
137137
// $FlowFixMe[incompatible-type]
138+
// $FlowFixMe[invalid-compare]
138139
node.type === 'ObjectExpression' ||
139140
node.type === 'FunctionExpression' ||
140141
node.type === 'ArrowFunctionExpression' ||

tools/hermes-parser/js/hermes-parser/src/babel/TransformESTreeToBabel.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,7 @@ function mapTypeofTypeAnnotation(
753753
// $FlowExpectedError[cannot-write]
754754
delete node.typeArguments;
755755
// $FlowFixMe[incompatible-type]
756+
// $FlowFixMe[invalid-compare]
756757
if (node.argument.type !== 'GenericTypeAnnotation') {
757758
return nodeWith(node, {
758759
// $FlowExpectedError[incompatible-type] Special override for Babel
@@ -920,6 +921,7 @@ function transformNode(node: ESNodeOrBabelNode): ESNodeOrBabelNode | null {
920921
case 'Program': {
921922
// Check if we have already processed this node.
922923
// $FlowFixMe[incompatible-type]
924+
// $FlowFixMe[invalid-compare]
923925
if (node.parent?.type === 'File') {
924926
return node;
925927
}
@@ -1263,6 +1265,7 @@ export function transformProgram(
12631265
});
12641266

12651267
// $FlowFixMe[incompatible-type]
1268+
// $FlowFixMe[invalid-compare]
12661269
if (resultNode?.type === 'File') {
12671270
return resultNode;
12681271
}

tools/hermes-parser/js/hermes-parser/src/transform/astNodeMutationHelpers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ function getParentKey(
4848
parent[key],
4949
)
5050
) {
51+
// $FlowFixMe[invalid-compare]
5152
if (parent[key] === target) {
5253
return {type: 'single', node: parent, key};
5354
}

tools/hermes-parser/js/hermes-transform/src/transform/mutations/ModifyNodeInPlace.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export function performModifyNodeInPlaceMutation(
4040
const prevPropValue = target[key];
4141

4242
// If the value did not change, skip.
43+
// $FlowFixMe[invalid-compare]
4344
if (prevPropValue === newPropValue) {
4445
continue;
4546
}

tools/hermes-parser/js/hermes-transform/src/transform/mutations/RemoveNode.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ function getRemovalParent(node: RemoveNodeMutation['node']): $ReadOnly<{
216216
return 'properties';
217217

218218
// $FlowFixMe[incompatible-type]
219+
// $FlowFixMe[invalid-compare]
219220
case 'OptionalCallExpression':
220221
case 'CallExpression':
221222
case 'NewExpression':
@@ -247,6 +248,7 @@ function getRemovalParent(node: RemoveNodeMutation['node']): $ReadOnly<{
247248
return 'properties';
248249

249250
// $FlowFixMe[incompatible-type]
251+
// $FlowFixMe[invalid-compare]
250252
case 'OptionalCallExpression':
251253
case 'CallExpression':
252254
case 'NewExpression':
@@ -275,6 +277,7 @@ function getRemovalParent(node: RemoveNodeMutation['node']): $ReadOnly<{
275277
// $FlowExpectedError[prop-missing]
276278
const arr = node.parent[key];
277279
const idx = arr.indexOf(node);
280+
// $FlowFixMe[invalid-compare]
278281
if (idx === -1) {
279282
throw new InvalidRemovalError(
280283
`Could not find target in array of \`${node.parent.type}.${key}\`.`,

tools/hermes-parser/js/hermes-transform/src/transform/mutations/ReplaceNode.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ function getParentKey(target: ESNode): $ReadOnly<
9090
for (const key of getVisitorKeys(parent)) {
9191
const child = (parent: $FlowFixMe)[key];
9292
if (isNode(child)) {
93+
// $FlowFixMe[invalid-compare]
9394
if (child === target) {
9495
return {type: 'single', parent, key};
9596
}

tools/hermes-parser/js/hermes-transform/src/transform/mutations/utils/getStatementParent.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export function getStatementParent(
4545
const value = parentWithType[key];
4646

4747
if (
48+
// $FlowFixMe[invalid-compare]
4849
value === target ||
4950
(Array.isArray(value) && value.includes(target))
5051
) {
@@ -136,6 +137,7 @@ export function getStatementParent(
136137
// array insertions are already validated by the getAssertedIndex function
137138
result.targetIndex == null &&
138139
// $FlowExpectedError[prop-missing]
140+
// $FlowFixMe[invalid-compare]
139141
result.parent[result.key] !== target
140142
) {
141143
throw new InvalidStatementError(

0 commit comments

Comments
 (0)