From 7e95c3364f4aa3b9e1f92e04d82121fb90d509b9 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Mon, 27 Jun 2022 20:33:55 +0200 Subject: [PATCH 1/5] Remove @optional from tests. --- .../grammar/expressions/expected/record.res.txt | 14 +++++++------- tests/parsing/grammar/expressions/record.res | 12 ++++++------ tests/printer/expr/expected/record.res.txt | 12 ++++++------ tests/printer/expr/record.res | 12 ++++++------ 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/tests/parsing/grammar/expressions/expected/record.res.txt b/tests/parsing/grammar/expressions/expected/record.res.txt index 6e4fc91f..e1836601 100644 --- a/tests/parsing/grammar/expressions/expected/record.res.txt +++ b/tests/parsing/grammar/expressions/expected/record.res.txt @@ -16,18 +16,18 @@ let r = { x = ((None)[@ns.optional ]); y = ((None)[@ns.optional ]); - z = (((None : tt))[@optional ]) + z = (((None : tt))[@ns.optional ]) } -let z name = { name = ((name)[@optional ]); x = 3 } let z name = { name = ((name)[@ns.optional ]); x = 3 } -let z name = { name; x = ((x)[@optional ]) } +let z name = { name = ((name)[@ns.optional ]); x = 3 } +let z name = { name; x = ((x)[@ns.optional ]) } let zz name = { name; x = ((x)[@ns.optional ]) } let _ = match z with - | { x = ((None)[@optional ]); y = ((None)[@optional ]); - z = (((None : tt))[@optional ]) } -> 11 - | { name = ((name)[@optional ]); x = 3 } -> 42 - | { name = ((name)[@optional ]); x = 3 } -> 4242 + | { x = ((None)[@ns.optional ]); y = ((None)[@ns.optional ]); + z = (((None : tt))[@ns.optional ]) } -> 11 + | { name = ((name)[@ns.optional ]); x = 3 } -> 42 + | { name = ((name)[@ns.optional ]); x = 3 } -> 4242 | { x = ((None)[@ns.optional ]); y = ((None)[@ns.optional ]); z = (((None : tt))[@ns.optional ]) } -> 11 | { name = ((name)[@ns.optional ]); x = 3 } -> 42 diff --git a/tests/parsing/grammar/expressions/record.res b/tests/parsing/grammar/expressions/record.res index 2f32f489..89ee47b6 100644 --- a/tests/parsing/grammar/expressions/record.res +++ b/tests/parsing/grammar/expressions/record.res @@ -24,20 +24,20 @@ let r = {...expr, pexp_attributes: [],} // trailing comma let r = {...make() : myRecord, foo: bar} let r = {...(make() : myRecord), foo: bar} // parens optional -let r = {x: ? None, y: ?None, z: @optional (None:tt)} +let r = {x: ? None, y: ?None, z: ? (None:tt)} -let z = name => { name : @optional name, x: 3} +let z = name => { name : ? name, x: 3} let z = name => { ? name, x: 3} -let z = name => { name, @optional x } +let z = name => { name, ? x } let zz = name => { name, ? x } let _ = switch z { - | {x: @optional None, y: @optional None, z: @optional (None:tt)} => 11 - | {name: @optional name, x: 3} => 42 - | {@optional name, x: 3} => 4242 + | {x: ? None, y: ? None, z: ? (None:tt)} => 11 + | {name: ? name, x: 3} => 42 + | {? name, x: 3} => 4242 | {x: ? None, y: ? None, z: ? (None:tt)} => 11 | {name: ? name, x: 3} => 42 | {? name, x: 3} => 4242 diff --git a/tests/printer/expr/expected/record.res.txt b/tests/printer/expr/expected/record.res.txt index b792483a..d67b073b 100644 --- a/tests/printer/expr/expected/record.res.txt +++ b/tests/printer/expr/expected/record.res.txt @@ -74,20 +74,20 @@ let r = { } let r = {a /* a */, b /* b */} -let r = {x: ?None, y: ?None, z: (@optional None: tt)} +let r = {x: ?None, y: ?None, z: ?(None: tt)} -let z = name => {@optional name, x: 3} +let z = name => {?name, x: 3} let z = name => {?name, x: 3} -let z = name => {name, @optional x} +let z = name => {name, ?x} let zz = name => {name, ?x} let _ = switch z { -| {x: @optional None, y: @optional None, z: (@optional None: tt)} => 11 -| {@optional name, x: 3} => 42 -| {name: @optional dd, x: 3} => 42 +| {x: ?None, y: ?None, z: ?(None: tt)} => 11 +| {?name, x: 3} => 42 +| {name: ?dd, x: 3} => 42 | {x: ?None, y: ?None, z: ?(None: tt)} => 11 | {?name, x: 3} => 42 | {?name, x: 3} => 4242 diff --git a/tests/printer/expr/record.res b/tests/printer/expr/record.res index 460bdd4e..bf7e9171 100644 --- a/tests/printer/expr/record.res +++ b/tests/printer/expr/record.res @@ -64,20 +64,20 @@ let r = { } let r = {a /* a */, b /* b */} -let r = {x: ? None, y: ?None, z: @optional (None:tt)} +let r = {x: ? None, y: ?None, z: ? (None:tt)} -let z = name => { name : @optional name, x: 3} +let z = name => { name : ? name, x: 3} let z = name => { ? name, x: 3} -let z = name => { name, @optional x } +let z = name => { name, ? x } let zz = name => { name, ? x } let _ = switch z { - | {x: @optional None, y: @optional None, z: @optional (None:tt)} => 11 - | {name: @optional name, x: 3} => 42 - | {name: @optional dd, x: 3} => 42 + | {x: ? None, y: ? None, z: ? (None:tt)} => 11 + | {name: ? name, x: 3} => 42 + | {name: ? dd, x: 3} => 42 | {x: ? None, y: ? None, z: ? (None:tt)} => 11 | {name: ? name, x: 3} => 42 | {? name, x: 3} => 4242 From 6e5e8ea930332106f80e90c583bc5863ea153236 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Mon, 27 Jun 2022 20:35:03 +0200 Subject: [PATCH 2/5] Remove `@optional` from outcome printer test. --- tests/oprint/expected/oprint.resi.txt | 1 - tests/oprint/oprint.res | 2 -- 2 files changed, 3 deletions(-) diff --git a/tests/oprint/expected/oprint.resi.txt b/tests/oprint/expected/oprint.resi.txt index f53406da..cb282946 100644 --- a/tests/oprint/expected/oprint.resi.txt +++ b/tests/oprint/expected/oprint.resi.txt @@ -486,5 +486,4 @@ type emptyObject = {.} let f: (~x: 'a=?, ~y: 'b) => option<'a> type call = CleanStart let f: (~a: int=?, unit) => int -type opt0 = {x: int, ?y: string} type opt = {x: int, ?y: string} \ No newline at end of file diff --git a/tests/oprint/oprint.res b/tests/oprint/oprint.res index ee4d4cf2..bc3e181b 100644 --- a/tests/oprint/oprint.res +++ b/tests/oprint/oprint.res @@ -360,6 +360,4 @@ type call = CleanStart let f = (~a=1, ()) => 1 -type opt0 = {x:int, @optional y: option} - type opt = {x:int, @ns.optional y: option} \ No newline at end of file From 83e1ff2bac061e8aadf99fd74353aac855754e06 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Mon, 27 Jun 2022 20:36:27 +0200 Subject: [PATCH 3/5] Remove "optional" from parser. --- src/res_core.ml | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/src/res_core.ml b/src/res_core.ml index 831fe435..2d854272 100644 --- a/src/res_core.ml +++ b/src/res_core.ml @@ -2705,7 +2705,6 @@ and parseJsxChildren p = and parseBracedOrRecordExpr p = let startPos = p.Parser.startPos in Parser.expect Lbrace p; - let attrsForFields = parseAttributesForFields p in match p.Parser.token with | Rbrace -> Parser.err p (Diagnostics.unexpected Rbrace p.breadcrumbs); @@ -2786,16 +2785,7 @@ and parseBracedOrRecordExpr p = | _ -> valueOrConstructor in let expr = - parseRecordExpr ~startPos - [ - ( pathIdent, - { - valueOrConstructor with - pexp_attributes = - attrsForFields @ valueOrConstructor.pexp_attributes; - } ); - ] - p + parseRecordExpr ~startPos [(pathIdent, valueOrConstructor)] p in Parser.expect Rbrace p; expr @@ -6318,29 +6308,9 @@ and parseAttribute p = ] ) | _ -> None -and parseAttributeForFields p = - let isAttributeForField p = - Parser.lookahead p (function state -> - (Parser.next state; - match state.token with - | Lident ident -> ident = "optional" - | _ -> false)) - in - match p.Parser.token with - | At when isAttributeForField p -> - let startPos = p.startPos in - Parser.next p; - let attrId = parseAttributeId ~startPos p in - let payload = parsePayload p in - Some (attrId, payload) - | _ -> None - and parseAttributes p = parseRegion p ~grammar:Grammar.Attribute ~f:parseAttribute -and parseAttributesForFields p = - parseRegion p ~grammar:Grammar.Attribute ~f:parseAttributeForFields - (* * standalone-attribute ::= * | @@ atribute-id From 19c41f6f15b6054101c40553b7ccd49c6eac0b42 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Mon, 27 Jun 2022 20:37:46 +0200 Subject: [PATCH 4/5] Remove `@optional` from outcome printer. --- compiler-libs-406/printtyp.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler-libs-406/printtyp.ml b/compiler-libs-406/printtyp.ml index 65772c7b..6b0c4ce4 100644 --- a/compiler-libs-406/printtyp.ml +++ b/compiler-libs-406/printtyp.ml @@ -926,7 +926,7 @@ and tree_of_constructor cd = (name, args, Some ret) and tree_of_label l = - let opt = l.ld_attributes |> List.exists (fun ({txt}, _) -> txt = "optional" || txt = "ns.optional") in + let opt = l.ld_attributes |> List.exists (fun ({txt}, _) -> txt = "ns.optional") in let typ = match l.ld_type.desc with | Tconstr (p, [t1], _) when opt && Path.same p Predef.path_option -> t1 | _ -> l.ld_type in From d6dc7755f7405df1af993baf47063bd357fa1074 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Mon, 27 Jun 2022 21:23:06 +0200 Subject: [PATCH 5/5] Remove `@optional` from JSX and use `ns.optional`. --- cli/reactjs_jsx_ppx_v4.ml | 2 +- tests/ppx/react/expected/commentAtTop.res_v4_auto.txt | 2 +- tests/ppx/react/expected/commentAtTop.res_v4_cls.txt | 2 +- .../expected/externalWithCustomName.res_v4_auto.txt | 2 +- .../expected/externalWithCustomName.res_v4_cls.txt | 2 +- tests/ppx/react/expected/forwardRef.res_v4_auto.txt | 10 +++++----- tests/ppx/react/expected/forwardRef.res_v4_cls.txt | 10 +++++----- tests/ppx/react/expected/innerModule.res_v4_auto.txt | 4 ++-- tests/ppx/react/expected/innerModule.res_v4_cls.txt | 4 ++-- tests/ppx/react/expected/newtype.res_v4_auto.txt | 2 +- tests/ppx/react/expected/newtype.res_v4_cls.txt | 2 +- tests/ppx/react/expected/topLevel.res_v4_auto.txt | 2 +- tests/ppx/react/expected/topLevel.res_v4_cls.txt | 2 +- .../ppx/react/expected/typeConstraint.res_v4_auto.txt | 2 +- tests/ppx/react/expected/typeConstraint.res_v4_cls.txt | 2 +- 15 files changed, 25 insertions(+), 25 deletions(-) diff --git a/cli/reactjs_jsx_ppx_v4.ml b/cli/reactjs_jsx_ppx_v4.ml index 9a14615c..544086f5 100644 --- a/cli/reactjs_jsx_ppx_v4.ml +++ b/cli/reactjs_jsx_ppx_v4.ml @@ -33,7 +33,7 @@ let getLabel str = let optionIdent = Lident "option" -let optionalAttr = [({txt = "optional"; loc = Location.none}, PStr [])] +let optionalAttr = [({txt = "ns.optional"; loc = Location.none}, PStr [])] let constantString ~loc str = Ast_helper.Exp.constant ~loc (Pconst_string (str, None)) diff --git a/tests/ppx/react/expected/commentAtTop.res_v4_auto.txt b/tests/ppx/react/expected/commentAtTop.res_v4_auto.txt index 1d536ca4..995073bc 100644 --- a/tests/ppx/react/expected/commentAtTop.res_v4_auto.txt +++ b/tests/ppx/react/expected/commentAtTop.res_v4_auto.txt @@ -1,4 +1,4 @@ -type props<'msg> = {@optional key: string, msg: 'msg} // test React JSX file +type props<'msg> = {key?: string, msg: 'msg} // test React JSX file let make = ({msg}: props<'msg>) => { ReactDOMRe.createDOMElementVariadic("div", [{msg->React.string}]) diff --git a/tests/ppx/react/expected/commentAtTop.res_v4_cls.txt b/tests/ppx/react/expected/commentAtTop.res_v4_cls.txt index 1d536ca4..995073bc 100644 --- a/tests/ppx/react/expected/commentAtTop.res_v4_cls.txt +++ b/tests/ppx/react/expected/commentAtTop.res_v4_cls.txt @@ -1,4 +1,4 @@ -type props<'msg> = {@optional key: string, msg: 'msg} // test React JSX file +type props<'msg> = {key?: string, msg: 'msg} // test React JSX file let make = ({msg}: props<'msg>) => { ReactDOMRe.createDOMElementVariadic("div", [{msg->React.string}]) diff --git a/tests/ppx/react/expected/externalWithCustomName.res_v4_auto.txt b/tests/ppx/react/expected/externalWithCustomName.res_v4_auto.txt index 0f56d93f..49e3e620 100644 --- a/tests/ppx/react/expected/externalWithCustomName.res_v4_auto.txt +++ b/tests/ppx/react/expected/externalWithCustomName.res_v4_auto.txt @@ -1,5 +1,5 @@ module Foo = { - type props<'a, 'b> = {@optional key: string, a: 'a, b: 'b} + type props<'a, 'b> = {key?: string, a: 'a, b: 'b} @module("Foo") external component: React.componentLike, React.element> = "component" } diff --git a/tests/ppx/react/expected/externalWithCustomName.res_v4_cls.txt b/tests/ppx/react/expected/externalWithCustomName.res_v4_cls.txt index d7d06db7..11d1b752 100644 --- a/tests/ppx/react/expected/externalWithCustomName.res_v4_cls.txt +++ b/tests/ppx/react/expected/externalWithCustomName.res_v4_cls.txt @@ -1,5 +1,5 @@ module Foo = { - type props<'a, 'b> = {@optional key: string, a: 'a, b: 'b} + type props<'a, 'b> = {key?: string, a: 'a, b: 'b} @module("Foo") external component: React.componentLike, React.element> = "component" } diff --git a/tests/ppx/react/expected/forwardRef.res_v4_auto.txt b/tests/ppx/react/expected/forwardRef.res_v4_auto.txt index d29dfe86..ce4b16bb 100644 --- a/tests/ppx/react/expected/forwardRef.res_v4_auto.txt +++ b/tests/ppx/react/expected/forwardRef.res_v4_auto.txt @@ -1,9 +1,9 @@ module FancyInput = { type props<'className, 'children> = { - @optional key: string, - @optional className: 'className, + key?: string, + className?: 'className, children: 'children, - @optional ref: ReactDOM.Ref.currentDomRef, + ref?: ReactDOM.Ref.currentDomRef, } let make = ({className, children, ref}: props<'className, 'children>) => { let ref = Js.Nullable.fromOption(ref) @@ -28,11 +28,11 @@ module FancyInput = { } let make = React.forwardRef({ let \"ForwardRef$FancyInput" = (props: props<_>, ref) => - make({...props, ref: @optional Js.Nullable.toOption(ref)}) + make({...props, ref: ?Js.Nullable.toOption(ref)}) \"ForwardRef$FancyInput" }) } -type props = {@optional key: string} +type props = {key?: string} let make = (_: props) => { let input = React.useRef(Js.Nullable.null) diff --git a/tests/ppx/react/expected/forwardRef.res_v4_cls.txt b/tests/ppx/react/expected/forwardRef.res_v4_cls.txt index da4ca0fa..872e550b 100644 --- a/tests/ppx/react/expected/forwardRef.res_v4_cls.txt +++ b/tests/ppx/react/expected/forwardRef.res_v4_cls.txt @@ -1,9 +1,9 @@ module FancyInput = { type props<'className, 'children> = { - @optional key: string, - @optional className: 'className, + key?: string, + className?: 'className, children: 'children, - @optional ref: ReactDOM.Ref.currentDomRef, + ref?: ReactDOM.Ref.currentDomRef, } let make = ({className, children, ref}: props<'className, 'children>) => { let ref = Js.Nullable.fromOption(ref) @@ -28,11 +28,11 @@ module FancyInput = { } let make = React.forwardRef({ let \"ForwardRef$FancyInput" = (props: props<_>, ref) => - make({...props, ref: @optional Js.Nullable.toOption(ref)}) + make({...props, ref: ?Js.Nullable.toOption(ref)}) \"ForwardRef$FancyInput" }) } -type props = {@optional key: string} +type props = {key?: string} let make = (_: props) => { let input = React.useRef(Js.Nullable.null) diff --git a/tests/ppx/react/expected/innerModule.res_v4_auto.txt b/tests/ppx/react/expected/innerModule.res_v4_auto.txt index a849bc72..ca414b0e 100644 --- a/tests/ppx/react/expected/innerModule.res_v4_auto.txt +++ b/tests/ppx/react/expected/innerModule.res_v4_auto.txt @@ -1,5 +1,5 @@ module Bar = { - type props<'a, 'b> = {@optional key: string, a: 'a, b: 'b} + type props<'a, 'b> = {key?: string, a: 'a, b: 'b} let make = ({a, b}: props<'a, 'b>) => { Js.log("This function should be named `InnerModule.react$Bar`") ReactDOMRe.createDOMElementVariadic("div", []) @@ -8,7 +8,7 @@ module Bar = { let \"InnerModule$Bar" = (props: props<_>) => make(props) \"InnerModule$Bar" } - type props<'a, 'b> = {@optional key: string, a: 'a, b: 'b} + type props<'a, 'b> = {key?: string, a: 'a, b: 'b} let component = ({a, b}: props<'a, 'b>) => { Js.log("This function should be named `InnerModule.react$Bar$component`") diff --git a/tests/ppx/react/expected/innerModule.res_v4_cls.txt b/tests/ppx/react/expected/innerModule.res_v4_cls.txt index a849bc72..ca414b0e 100644 --- a/tests/ppx/react/expected/innerModule.res_v4_cls.txt +++ b/tests/ppx/react/expected/innerModule.res_v4_cls.txt @@ -1,5 +1,5 @@ module Bar = { - type props<'a, 'b> = {@optional key: string, a: 'a, b: 'b} + type props<'a, 'b> = {key?: string, a: 'a, b: 'b} let make = ({a, b}: props<'a, 'b>) => { Js.log("This function should be named `InnerModule.react$Bar`") ReactDOMRe.createDOMElementVariadic("div", []) @@ -8,7 +8,7 @@ module Bar = { let \"InnerModule$Bar" = (props: props<_>) => make(props) \"InnerModule$Bar" } - type props<'a, 'b> = {@optional key: string, a: 'a, b: 'b} + type props<'a, 'b> = {key?: string, a: 'a, b: 'b} let component = ({a, b}: props<'a, 'b>) => { Js.log("This function should be named `InnerModule.react$Bar$component`") diff --git a/tests/ppx/react/expected/newtype.res_v4_auto.txt b/tests/ppx/react/expected/newtype.res_v4_auto.txt index 10bd9031..460c8382 100644 --- a/tests/ppx/react/expected/newtype.res_v4_auto.txt +++ b/tests/ppx/react/expected/newtype.res_v4_auto.txt @@ -1,4 +1,4 @@ -type props<'a, 'b, 'c> = {@optional key: string, a: 'a, b: 'b, c: 'c} +type props<'a, 'b, 'c> = {key?: string, a: 'a, b: 'b, c: 'c} let make = (_: props<'a, 'b, 'c>, type a, ~a: a, ~b: array>, ~c: 'a, _) => ReactDOMRe.createDOMElementVariadic("div", []) let make = { diff --git a/tests/ppx/react/expected/newtype.res_v4_cls.txt b/tests/ppx/react/expected/newtype.res_v4_cls.txt index 10bd9031..460c8382 100644 --- a/tests/ppx/react/expected/newtype.res_v4_cls.txt +++ b/tests/ppx/react/expected/newtype.res_v4_cls.txt @@ -1,4 +1,4 @@ -type props<'a, 'b, 'c> = {@optional key: string, a: 'a, b: 'b, c: 'c} +type props<'a, 'b, 'c> = {key?: string, a: 'a, b: 'b, c: 'c} let make = (_: props<'a, 'b, 'c>, type a, ~a: a, ~b: array>, ~c: 'a, _) => ReactDOMRe.createDOMElementVariadic("div", []) let make = { diff --git a/tests/ppx/react/expected/topLevel.res_v4_auto.txt b/tests/ppx/react/expected/topLevel.res_v4_auto.txt index 7694fd43..f05a7b1d 100644 --- a/tests/ppx/react/expected/topLevel.res_v4_auto.txt +++ b/tests/ppx/react/expected/topLevel.res_v4_auto.txt @@ -1,4 +1,4 @@ -type props<'a, 'b> = {@optional key: string, a: 'a, b: 'b} +type props<'a, 'b> = {key?: string, a: 'a, b: 'b} let make = ({a, b}: props<'a, 'b>) => { Js.log("This function should be named 'TopLevel.react'") ReactDOMRe.createDOMElementVariadic("div", []) diff --git a/tests/ppx/react/expected/topLevel.res_v4_cls.txt b/tests/ppx/react/expected/topLevel.res_v4_cls.txt index 7694fd43..f05a7b1d 100644 --- a/tests/ppx/react/expected/topLevel.res_v4_cls.txt +++ b/tests/ppx/react/expected/topLevel.res_v4_cls.txt @@ -1,4 +1,4 @@ -type props<'a, 'b> = {@optional key: string, a: 'a, b: 'b} +type props<'a, 'b> = {key?: string, a: 'a, b: 'b} let make = ({a, b}: props<'a, 'b>) => { Js.log("This function should be named 'TopLevel.react'") ReactDOMRe.createDOMElementVariadic("div", []) diff --git a/tests/ppx/react/expected/typeConstraint.res_v4_auto.txt b/tests/ppx/react/expected/typeConstraint.res_v4_auto.txt index 339cf97c..50156ade 100644 --- a/tests/ppx/react/expected/typeConstraint.res_v4_auto.txt +++ b/tests/ppx/react/expected/typeConstraint.res_v4_auto.txt @@ -1,4 +1,4 @@ -type props<'a, 'b> = {@optional key: string, a: 'a, b: 'b} +type props<'a, 'b> = {key?: string, a: 'a, b: 'b} let make: 'a. (~a: 'a, ~b: 'a, 'a) => React.element = (_: props<'a, 'b>, type a): ( (~a: a, ~b: a, a) => React.element ) => (~a, ~b, _) => ReactDOMRe.createDOMElementVariadic("div", []) diff --git a/tests/ppx/react/expected/typeConstraint.res_v4_cls.txt b/tests/ppx/react/expected/typeConstraint.res_v4_cls.txt index 339cf97c..50156ade 100644 --- a/tests/ppx/react/expected/typeConstraint.res_v4_cls.txt +++ b/tests/ppx/react/expected/typeConstraint.res_v4_cls.txt @@ -1,4 +1,4 @@ -type props<'a, 'b> = {@optional key: string, a: 'a, b: 'b} +type props<'a, 'b> = {key?: string, a: 'a, b: 'b} let make: 'a. (~a: 'a, ~b: 'a, 'a) => React.element = (_: props<'a, 'b>, type a): ( (~a: a, ~b: a, a) => React.element ) => (~a, ~b, _) => ReactDOMRe.createDOMElementVariadic("div", [])