Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Remove "export". #599

Merged
merged 2 commits into from
Jul 3, 2022
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Implement syntax for arity zero vs arity one in uncurried application in [#139](https://github.com/rescript-lang/syntax/pull/139)
* Fix parsing of first class module exprs as part of binary/ternary expr in [#256](https://github.com/rescript-lang/syntax/pull/256)
* Fix formatter hanging on deeply nested function calls [#261](https://github.com/rescript-lang/syntax/issues/261)
* Remove parsing of "import" and "export" which was never officially supported.

## ReScript 9.0.0

Expand Down
69 changes: 0 additions & 69 deletions src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2403,17 +2403,6 @@ and parseLetBindings ~attrs p =
match p.Parser.token with
| And ->
Parser.next p;
let attrs =
match p.token with
| Export ->
let exportLoc = mkLoc p.startPos p.endPos in
Parser.next p;
let genTypeAttr =
(Location.mkloc "genType" exportLoc, Parsetree.PStr [])
in
genTypeAttr :: attrs
| _ -> attrs
in
ignore (Parser.optional p Let);
(* overparse for fault tolerance *)
let letBinding = parseLetBindingBody ~startPos ~attrs p in
Expand Down Expand Up @@ -5138,17 +5127,6 @@ and parseTypeDefinitions ~attrs ~name ~params ~startPos p =
match p.Parser.token with
| And ->
Parser.next p;
let attrs =
match p.token with
| Export ->
let exportLoc = mkLoc p.startPos p.endPos in
Parser.next p;
let genTypeAttr =
(Location.mkloc "genType" exportLoc, Parsetree.PStr [])
in
genTypeAttr :: attrs
| _ -> attrs
in
let typeDef = parseTypeDef ~attrs ~startPos p in
loop p (typeDef :: defs)
| _ -> List.rev defs
Expand Down Expand Up @@ -5321,11 +5299,6 @@ and parseStructureItemRegion p =
parseNewlineOrSemicolonStructure p;
let loc = mkLoc startPos p.prevEndPos in
Some (Ast_helper.Str.include_ ~loc includeStatement)
| Export ->
let structureItem = parseJsExport ~attrs p in
parseNewlineOrSemicolonStructure p;
let loc = mkLoc startPos p.prevEndPos in
Some {structureItem with pstr_loc = loc}
| Module ->
Parser.beginRegion p;
let structureItem = parseModuleOrModuleTypeImplOrPackExpr ~attrs p in
Expand Down Expand Up @@ -5372,43 +5345,6 @@ and parseStructureItemRegion p =
| _ -> None)
[@@progress Parser.next, Parser.expect]

and parseJsExport ~attrs p =
let exportStart = p.Parser.startPos in
Parser.expect Token.Export p;
let exportLoc = mkLoc exportStart p.prevEndPos in
let genTypeAttr = (Location.mkloc "genType" exportLoc, Parsetree.PStr []) in
let attrs = genTypeAttr :: attrs in
match p.Parser.token with
| Typ -> (
match parseTypeDefinitionOrExtension ~attrs p with
| TypeDef {recFlag; types} -> Ast_helper.Str.type_ recFlag types
| TypeExt ext -> Ast_helper.Str.type_extension ext)
(* Let *)
| _ ->
let recFlag, letBindings = parseLetBindings ~attrs p in
Ast_helper.Str.value recFlag letBindings

and parseSignJsExport ~attrs p =
let exportStart = p.Parser.startPos in
Parser.expect Token.Export p;
let exportLoc = mkLoc exportStart p.prevEndPos in
let genTypeAttr = (Location.mkloc "genType" exportLoc, Parsetree.PStr []) in
let attrs = genTypeAttr :: attrs in
match p.Parser.token with
| Typ -> (
match parseTypeDefinitionOrExtension ~attrs p with
| TypeDef {recFlag; types} ->
let loc = mkLoc exportStart p.prevEndPos in
Ast_helper.Sig.type_ recFlag types ~loc
| TypeExt ext ->
let loc = mkLoc exportStart p.prevEndPos in
Ast_helper.Sig.type_extension ext ~loc)
(* Let *)
| _ ->
let valueDesc = parseSignLetDesc ~attrs p in
let loc = mkLoc exportStart p.prevEndPos in
Ast_helper.Sig.value valueDesc ~loc

(* include-statement ::= include module-expr *)
and parseIncludeStatement ~attrs p =
let startPos = p.Parser.startPos in
Expand Down Expand Up @@ -5952,11 +5888,6 @@ and parseSignatureItemRegion p =
parseNewlineOrSemicolonSignature p;
let loc = mkLoc startPos p.prevEndPos in
Some (Ast_helper.Sig.value ~loc externalDef)
| Export ->
let signatureItem = parseSignJsExport ~attrs p in
parseNewlineOrSemicolonSignature p;
let loc = mkLoc startPos p.prevEndPos in
Some {signatureItem with psig_loc = loc}
| Exception ->
let exceptionDef = parseExceptionDef ~attrs p in
parseNewlineOrSemicolonSignature p;
Expand Down
6 changes: 3 additions & 3 deletions src/res_grammar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ let toString = function

let isSignatureItemStart = function
| Token.At | Let | Typ | External | Exception | Open | Include | Module | AtAt
| Export | PercentPercent ->
| PercentPercent ->
true
| _ -> false

Expand Down Expand Up @@ -160,8 +160,8 @@ let isJsxAttributeStart = function
| _ -> false

let isStructureItemStart = function
| Token.Open | Let | Typ | External | Export | Exception | Include | Module
| AtAt | PercentPercent | At ->
| Token.Open | Let | Typ | External | Exception | Include | Module | AtAt
| PercentPercent | At ->
true
| t when isExprStart t -> true
| _ -> false
Expand Down
10 changes: 3 additions & 7 deletions src/res_token.ml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ type t =
| Backtick
| BarGreater
| Try
| Export
| DocComment of Location.t * string
| ModuleComment of Location.t * string

Expand Down Expand Up @@ -204,7 +203,6 @@ let toString = function
| Backtick -> "`"
| BarGreater -> "|>"
| Try -> "try"
| Export -> "export"
| DocComment (_loc, s) -> "DocComment " ^ s
| ModuleComment (_loc, s) -> "ModuleComment " ^ s

Expand All @@ -215,7 +213,6 @@ let keywordTable = function
| "constraint" -> Constraint
| "else" -> Else
| "exception" -> Exception
| "export" -> Export
| "external" -> External
| "false" -> False
| "for" -> For
Expand All @@ -241,10 +238,9 @@ let keywordTable = function
[@@raises Not_found]

let isKeyword = function
| And | As | Assert | Constraint | Else | Exception | Export | External
| False | For | If | In | Include | Land | Lazy | Let | List | Lor | Module
| Mutable | Of | Open | Private | Rec | Switch | True | Try | Typ | When
| While ->
| And | As | Assert | Constraint | Else | Exception | External | False | For
| If | In | Include | Land | Lazy | Let | List | Lor | Module | Mutable | Of
| Open | Private | Rec | Switch | True | Try | Typ | When | While ->
true
| _ -> false

Expand Down
3 changes: 0 additions & 3 deletions tests/parsing/errors/signature/consecutive.resi

This file was deleted.

25 changes: 0 additions & 25 deletions tests/parsing/errors/signature/expected/consecutive.resi.txt

This file was deleted.

72 changes: 57 additions & 15 deletions tests/parsing/grammar/ffi/expected/export.res.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,57 @@
type nonrec callback = ReactEvent.Mouse.t -> unit[@@genType ]
type nonrec t = int[@@genType ]
and s = string[@@genType ]
type nonrec t = int[@@genType ]
and s = string
type nonrec t = int
and s = string[@@genType ]
let callback _ = Js.log {js|Clicked|js}[@@genType ]
let callback _ = Js.log {js|Clicked|js}[@@genType ]
let x = {js|hello world|js}[@@genType ]
and y = 2[@@genType ]
let x = {js|hello world|js}[@@genType ]
and y = 2[@@genType ]
let x = {js|hello world|js}
and y = 2[@@genType ]

Syntax error!
tests/parsing/grammar/ffi/export.res:1:7-11

1 │ export type callback = ReactEvent.Mouse.t => unit
2 │
3 │ export type t = int and export s = string

consecutive statements on a line must be separated by ';' or a newline


Syntax error!
tests/parsing/grammar/ffi/export.res:3:31-32

1 │ export type callback = ReactEvent.Mouse.t => unit
2 │
3 │ export type t = int and export s = string
4 │ export type t = int and s = string
5 │ type t = int and export s = string

consecutive statements on a line must be separated by ';' or a newline


Syntax error!
tests/parsing/grammar/ffi/export.res:5:24-25

3 │ export type t = int and export s = string
4 │ export type t = int and s = string
5 │ type t = int and export s = string
6 │
7 │ export let callback = _ => Js.log("Clicked")

consecutive statements on a line must be separated by ';' or a newline


Syntax error!
tests/parsing/grammar/ffi/export.res:10:40-41

8 │ export callback = _ => Js.log("Clicked")
9 │
10 │ export let x = "hello world" and export y = 2
11 │ export x = "hello world" and export y = 2
12 │ let x = "hello world" and export y = 2

Did you forget a `=` here?


Syntax error!
tests/parsing/grammar/ffi/export.res:12:33-34

10 │ export let x = "hello world" and export y = 2
11 │ export x = "hello world" and export y = 2
12 │ let x = "hello world" and export y = 2
13 │

Did you forget a `=` here?

25 changes: 22 additions & 3 deletions tests/parsing/other/expected/gentype.res.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
module M : sig type nonrec t = int[@@genType ] val x : int[@@genType ] end =
struct type nonrec t = int
let x = 34 end

Syntax error!
tests/parsing/other/gentype.res:1:12-2:8

1 │ module M: {
2 │ export type t = int
3 │ export x: int
4 │ } = {

Did you forget a `}` here?


Syntax error!
tests/parsing/other/gentype.res:2:9-13

1 │ module M: {
2 │ export type t = int
3 │ export x: int
4 │ } = {

consecutive statements on a line must be separated by ';' or a newline

63 changes: 54 additions & 9 deletions tests/printer/ffi/expected/export.res.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,57 @@
@genType type callback = ReactEvent.Mouse.t => unit

@genType type t = int @genType and s = string
@genType type t = int and s = string
type t = int @genType and s = string
Syntax error!
tests/printer/ffi/export.res:1:7-11

@genType let callback = _ => Js.log("Clicked")
@genType let callback = _ => Js.log("Clicked")
1 │ export type callback = ReactEvent.Mouse.t => unit
2 │
3 │ export type t = int and export s = string

consecutive statements on a line must be separated by ';' or a newline


Syntax error!
tests/printer/ffi/export.res:3:31-32

1 │ export type callback = ReactEvent.Mouse.t => unit
2 │
3 │ export type t = int and export s = string
4 │ export type t = int and s = string
5 │ type t = int and export s = string

consecutive statements on a line must be separated by ';' or a newline


Syntax error!
tests/printer/ffi/export.res:5:24-25

3 │ export type t = int and export s = string
4 │ export type t = int and s = string
5 │ type t = int and export s = string
6 │
7 │ export let callback = _ => Js.log("Clicked")

consecutive statements on a line must be separated by ';' or a newline


Syntax error!
tests/printer/ffi/export.res:10:40-41

8 │ export callback = _ => Js.log("Clicked")
9 │
10 │ export let x = "hello world" and export y = 2
11 │ export x = "hello world" and export y = 2
12 │ let x = "hello world" and export y = 2

Did you forget a `=` here?


Syntax error!
tests/printer/ffi/export.res:12:33-34

10 │ export let x = "hello world" and export y = 2
11 │ export x = "hello world" and export y = 2
12 │ let x = "hello world" and export y = 2
13 │

Did you forget a `=` here?

@genType let x = "hello world" @genType and y = 2
@genType let x = "hello world" @genType and y = 2
let x = "hello world" @genType and y = 2
12 changes: 0 additions & 12 deletions tests/printer/ffi/export.res

This file was deleted.