Skip to content

Commit

Permalink
prefix instead of suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
mununki committed Aug 30, 2023
1 parent ca5df4e commit f8e7e70
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 44 deletions.
8 changes: 4 additions & 4 deletions jscomp/syntax/src/reactjs_jsx_v4.ml
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ let vbMatch ~expr (name, default, _, alias, loc, _) =
Vb.mk
(Pat.var (Location.mkloc alias loc))
(Exp.match_
(Exp.ident {txt = Lident (alias ^ "__"); loc = Location.none})
(Exp.ident {txt = Lident ("__" ^ alias); loc = Location.none})
[
Exp.case
(Pat.construct
Expand Down Expand Up @@ -987,9 +987,9 @@ let mapBinding ~config ~emptyLoc ~pstr_loc ~fileName ~recFlag binding =
let safePatternLabel pattern =
match pattern with
| {ppat_desc = Ppat_var {txt; loc}} ->
{pattern with ppat_desc = Ppat_var {txt = txt ^ "__"; loc}}
{pattern with ppat_desc = Ppat_var {txt = "__" ^ txt; loc}}
| {ppat_desc = Ppat_alias (p, {txt; loc})} ->
{pattern with ppat_desc = Ppat_alias (p, {txt = txt ^ "__"; loc})}
{pattern with ppat_desc = Ppat_alias (p, {txt = "__" ^ txt; loc})}
| _ -> pattern
in
let rec returnedExpression patternsWithLabel patternsWithNolabel
Expand All @@ -1013,7 +1013,7 @@ let mapBinding ~config ~emptyLoc ~pstr_loc ~fileName ~recFlag binding =
(*
If prop has the default value as Ident, it will get a build error
when the referenced Ident value and the prop have the same name.
So we add a "__" after label to resolve the build error.
So we add a "__" to label to resolve the build error.
*)
let patternWithSafeLabel =
match default with
Expand Down
26 changes: 13 additions & 13 deletions jscomp/syntax/tests/ppx/react/expected/aliasProps.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
module C0 = {
type props<'priority, 'text> = {priority: 'priority, text?: 'text}

let make = ({priority: _, text: ?text__, _}: props<_, _>) => {
let text = switch text__ {
let make = ({priority: _, text: ?__text, _}: props<_, _>) => {
let text = switch __text {
| Some(text) => text
| None => "Test"
}
Expand All @@ -21,8 +21,8 @@ module C0 = {
module C1 = {
type props<'priority, 'text> = {priority: 'priority, text?: 'text}

let make = ({priority: p, text: ?text__, _}: props<_, _>) => {
let text = switch text__ {
let make = ({priority: p, text: ?__text, _}: props<_, _>) => {
let text = switch __text {
| Some(text) => text
| None => "Test"
}
Expand All @@ -39,8 +39,8 @@ module C1 = {
module C2 = {
type props<'foo> = {foo?: 'foo}

let make = ({foo: ?bar__, _}: props<_>) => {
let bar = switch bar__ {
let make = ({foo: ?__bar, _}: props<_>) => {
let bar = switch __bar {
| Some(foo) => foo
| None => ""
}
Expand All @@ -57,12 +57,12 @@ module C2 = {
module C3 = {
type props<'foo, 'a, 'b> = {foo?: 'foo, a?: 'a, b: 'b}

let make = ({foo: ?bar__, a: ?a__, b, _}: props<_, _, _>) => {
let bar = switch bar__ {
let make = ({foo: ?__bar, a: ?__a, b, _}: props<_, _, _>) => {
let bar = switch __bar {
| Some(foo) => foo
| None => ""
}
let a = switch a__ {
let a = switch __a {
| Some(a) => a
| None => bar
}
Expand All @@ -81,8 +81,8 @@ module C3 = {
module C4 = {
type props<'a, 'x> = {a: 'a, x?: 'x}

let make = ({a: b, x: ?x__, _}: props<_, _>) => {
let x = switch x__ {
let make = ({a: b, x: ?__x, _}: props<_, _>) => {
let x = switch __x {
| Some(x) => x
| None => true
}
Expand All @@ -99,8 +99,8 @@ module C4 = {
module C5 = {
type props<'a, 'z> = {a: 'a, z?: 'z}

let make = ({a: (x, y), z: ?z__, _}: props<_, _>) => {
let z = switch z__ {
let make = ({a: (x, y), z: ?__z, _}: props<_, _>) => {
let z = switch __z {
| Some(z) => z
| None => 3
}
Expand Down
18 changes: 9 additions & 9 deletions jscomp/syntax/tests/ppx/react/expected/defaultValueProp.res.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module C0 = {
type props<'a, 'b> = {a?: 'a, b?: 'b}
let make = ({a: ?a__, b: ?b__, _}: props<_, _>) => {
let a = switch a__ {
let make = ({a: ?__a, b: ?__b, _}: props<_, _>) => {
let a = switch __a {
| Some(a) => a
| None => 2
}
let b = switch b__ {
let b = switch __b {
| Some(b) => b
| None => a * 2
}
Expand All @@ -21,8 +21,8 @@ module C0 = {
module C1 = {
type props<'a, 'b> = {a?: 'a, b: 'b}

let make = ({a: ?a__, b, _}: props<_, _>) => {
let a = switch a__ {
let make = ({a: ?__a, b, _}: props<_, _>) => {
let a = switch __a {
| Some(a) => a
| None => 2
}
Expand All @@ -40,8 +40,8 @@ module C2 = {
let a = "foo"
type props<'a> = {a?: 'a}

let make = ({a: ?a__, _}: props<_>) => {
let a = switch a__ {
let make = ({a: ?__a, _}: props<_>) => {
let a = switch __a {
| Some(a) => a
| None => a
}
Expand All @@ -58,8 +58,8 @@ module C2 = {
module C3 = {
type props<'disabled> = {disabled?: 'disabled}

let make = ({disabled: ?everythingDisabled__, _}: props<bool>) => {
let everythingDisabled = switch everythingDisabled__ {
let make = ({disabled: ?__everythingDisabled, _}: props<bool>) => {
let everythingDisabled = switch __everythingDisabled {
| Some(disabled) => disabled
| None => false
}
Expand Down
8 changes: 4 additions & 4 deletions jscomp/syntax/tests/ppx/react/expected/uncurriedProps.res.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@@jsxConfig({version: 4})
type props<'a> = {a?: 'a}

let make = ({a: ?a__, _}: props<(. unit) => unit>) => {
let a = switch a__ {
let make = ({a: ?__a, _}: props<(. unit) => unit>) => {
let a = switch __a {
| Some(a) => a
| None => (. ()) => ()
}
Expand All @@ -28,8 +28,8 @@ func(~callback=(. str, a, b) => {
module Foo = {
type props<'callback> = {callback?: 'callback}

let make = ({callback: ?callback__, _}: props<(. string, bool, bool) => unit>) => {
let callback = switch callback__ {
let make = ({callback: ?__callback, _}: props<(. string, bool, bool) => unit>) => {
let callback = switch __callback {
| Some(callback) => callback
| None => (. _, _, _) => ()
}
Expand Down
28 changes: 14 additions & 14 deletions jscomp/test/alias_default_value_test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f8e7e70

Please sign in to comment.