Skip to content
Permalink
Browse files

[parser] Allow '...' to indicate explicit inexact object

Summary: This diff adds syntax to express explicitly that an object type is inexact. This is part of a longer-term effort to make object types exact by default, which is an oft-requested change.

Reviewed By: gabelevi

Differential Revision: D10220687

fbshipit-source-id: d22374955de3aaab93201614cc4d894f98740a10
  • Loading branch information...
jbrown215 authored and facebook-github-bot committed Oct 12, 2018
1 parent 50e21a0 commit 1ac913040f38309480934ccb6717a3ffc65094a8
Showing with 1,256 additions and 77 deletions.
  1. +12 −0 src/parser/parse_error.ml
  2. +39 −0 src/parser/test/flow/types/annotations/explicit_inexact_disallowed_in_non_objects.js
  3. +448 −0 src/parser/test/flow/types/annotations/explicit_inexact_disallowed_in_non_objects.tree.json
  4. +1 −0 src/parser/test/flow/types/annotations/explicit_inexact_forbidden_in_exact.js
  5. +63 −0 src/parser/test/flow/types/annotations/explicit_inexact_forbidden_in_exact.tree.json
  6. +1 −0 src/parser/test/flow/types/annotations/explicit_inexact_must_appear_last.js
  7. +63 −0 src/parser/test/flow/types/annotations/explicit_inexact_must_appear_last.tree.json
  8. +3 −0 src/parser/test/flow/types/annotations/explicit_inexact_object.js
  9. +168 −0 src/parser/test/flow/types/annotations/explicit_inexact_object.tree.json
  10. +3 −0 src/parser/test/flow/types/annotations/explicit_inexact_object_invalid.js
  11. +212 −0 src/parser/test/flow/types/annotations/explicit_inexact_object_invalid.tree.json
  12. +10 −0 src/parser/test/flow/types/annotations/explicit_inexact_trailing_comma.js
  13. +154 −0 src/parser/test/flow/types/annotations/explicit_inexact_trailing_comma.tree.json
  14. +2 −35 src/parser/test/flow/types/instance_spread_invalid/migrated_0000.tree.json
  15. +2 −35 src/parser/test/flow/types/instance_spread_invalid/migrated_0001.tree.json
  16. +46 −7 src/parser/type_parser.ml
  17. 0 tests/explicit_inexact/.flowconfig
  18. +21 −0 tests/explicit_inexact/explicit_inexact.exp
  19. +8 −0 tests/explicit_inexact/test.js
@@ -27,6 +27,10 @@ type t =
| UnexpectedTypeImport
| UnexpectedTypeExport
| UnexpectedTypeInterface
| UnexpectedSpreadType
| UnexpectedExplicitInexactInObject
| InexactInsideExact
| InexactInsideNonObject
| NewlineAfterThrow
| InvalidRegExp
| InvalidRegExpFlags of string
@@ -146,6 +150,14 @@ module PP =
| UnexpectedTypeImport -> "Type imports are not allowed in untyped mode"
| UnexpectedTypeExport -> "Type exports are not allowed in untyped mode"
| UnexpectedTypeInterface -> "Interfaces are not allowed in untyped mode"
| UnexpectedSpreadType ->
"Spreading a type is only allowed inside an object type"
| UnexpectedExplicitInexactInObject ->
"Explicit inexact syntax must come at the end of an object type"
| InexactInsideExact ->
"Explicit inexact syntax cannot appear inside an explicit exact object type"
| InexactInsideNonObject ->
"Explicit inexact syntax can only appear inside an object type"
| NewlineAfterThrow -> "Illegal newline after throw"
| InvalidRegExp -> "Invalid regular expression"
| InvalidRegExpFlags flags -> "Invalid flags supplied to RegExp constructor '"^flags^"'"
@@ -0,0 +1,39 @@
declare class A {
...;
}

declare class B {
foo: number;
...;
}

declare class C {
...;
foo: number;
}

declare class D {
foo: number;
...;
bar: number;
}

interface E {
...;
}

interface F {
foo: number;
...;
}

interface G {
...;
foo: number;
}

interface H {
foo: number;
...;
bar: number;
}

0 comments on commit 1ac9130

Please sign in to comment.
You can’t perform that action at this time.