Skip to content

Commit

Permalink
[flow][as-const] hints propagate through "as const"
Browse files Browse the repository at this point in the history
Summary: Changelog: [internal]

Reviewed By: SamChou19815

Differential Revision: D56888740

fbshipit-source-id: b6f972716b5bedeaaf337eb03a4c74fa3c7c872f
  • Loading branch information
panagosg7 authored and facebook-github-bot committed May 2, 2024
1 parent eab2383 commit 812dd64
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/analysis/env_builder/name_def.ml
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,8 @@ let expression_is_definitely_synthesizable ~autocomplete_hooks =
| Ast.Expression.TaggedTemplate _ -> false
| Ast.Expression.Identifier id -> not (identifier_has_autocomplete ~autocomplete_hooks id)
| Ast.Expression.StringLiteral _ -> not (literal_has_autocomplete ~autocomplete_hooks loc)
| Ast.Expression.AsConstExpression { Ast.Expression.AsConstExpression.expression; _ } ->
synthesizable expression
| Ast.Expression.NumberLiteral _
| Ast.Expression.BooleanLiteral _
| Ast.Expression.NullLiteral _
Expand All @@ -587,7 +589,6 @@ let expression_is_definitely_synthesizable ~autocomplete_hooks =
| Ast.Expression.TemplateLiteral _
| Ast.Expression.This _
| Ast.Expression.TypeCast _
| Ast.Expression.AsConstExpression _
| Ast.Expression.AsExpression _
| Ast.Expression.TSSatisfies _
| Ast.Expression.Update _
Expand Down Expand Up @@ -2768,6 +2769,8 @@ class def_finder ~autocomplete_hooks env_info toplevel_scope =
| Ast.Expression.New expr -> this#visit_new_expression ~hints loc expr
| Ast.Expression.Unary expr -> this#visit_unary_expression ~hints expr
| Ast.Expression.Conditional expr -> this#visit_conditional ~hints expr
| Ast.Expression.AsConstExpression { Ast.Expression.AsConstExpression.expression; _ } ->
this#visit_expression ~hints ~cond expression
| Ast.Expression.Class _
| Ast.Expression.Identifier _
| Ast.Expression.Import _
Expand All @@ -2788,7 +2791,6 @@ class def_finder ~autocomplete_hooks env_info toplevel_scope =
| Ast.Expression.This _
| Ast.Expression.TypeCast _
| Ast.Expression.AsExpression _
| Ast.Expression.AsConstExpression _
| Ast.Expression.TSSatisfies _
| Ast.Expression.Update _
| Ast.Expression.Yield _ ->
Expand Down
1 change: 1 addition & 0 deletions tests/as_const/.flowconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[options]
all=true
as_const=true
experimental.ts_syntax=true
3 changes: 3 additions & 0 deletions tests/as_const/hint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// hints propagate through "as const"
const arr: readonly [(x: string) => void] = [(x) => {}] as const; // okay
const obj: {+f: (x: string) => void} = {f: (x) => {}} as const; // okay

0 comments on commit 812dd64

Please sign in to comment.