Skip to content

Commit 678df8e

Browse files
committed
Use JS in operator
1 parent 1f3ee58 commit 678df8e

File tree

2 files changed

+184
-189
lines changed

2 files changed

+184
-189
lines changed

packages/sury/src/Sury.res

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,6 @@ module X = {
126126

127127
@get_index
128128
external getUnsafeOptionBySymbol: (dict<'a>, Js.Types.symbol) => option<'a> = ""
129-
130-
@inline
131-
let has = (dict, key) => {
132-
dict->Js.Dict.unsafeGet(key)->(Obj.magic: 'a => bool)
133-
}
134129
}
135130

136131
module Float = {
@@ -594,13 +589,13 @@ external untag: t<'any> => untagged = "%identity"
594589
@inline
595590
let isSchemaObject = obj => (obj->Obj.magic).standard->Obj.magic
596591

597-
// TODO: Can be improved after ReScript supports `in` (https://github.com/rescript-lang/rescript/issues/7313)
598-
let isLiteral: internal => bool = %raw(`s => "const" in s`)
592+
let constField = "const"
593+
let isLiteral = (schema: internal) => schema->Obj.magic->Dict.has(constField)
599594

600595
let isOptional = schema => {
601596
switch schema.tag {
602597
| Undefined => true
603-
| Union => schema.has->X.Option.getUnsafe->X.Dict.has((Undefined: tag :> string))
598+
| Union => schema.has->X.Option.getUnsafe->Dict.has((Undefined: tag :> string))
604599
| _ => false
605600
}
606601
}
@@ -2660,8 +2655,8 @@ module Union = {
26602655

26612656
let isPriority = (tagFlag, byKey: dict<array<internal>>) => {
26622657
(tagFlag->Flag.unsafeHas(TagFlag.array->Flag.with(TagFlag.instance)) &&
2663-
byKey->X.Dict.has((Object: tag :> string))) ||
2664-
(tagFlag->Flag.unsafeHas(TagFlag.nan) && byKey->X.Dict.has((Number: tag :> string)))
2658+
byKey->Dict.has((Object: tag :> string))) ||
2659+
(tagFlag->Flag.unsafeHas(TagFlag.nan) && byKey->Dict.has((Number: tag :> string)))
26652660
}
26662661

26672662
let isWiderUnionSchema = (~schemaAnyOf, ~inputAnyOf) => {
@@ -2742,7 +2737,7 @@ module Union = {
27422737

27432738
if (
27442739
tagFlag->Flag.unsafeHas(TagFlag.undefined) &&
2745-
selfSchema->Obj.magic->X.Dict.has("fromDefault")
2740+
selfSchema->Obj.magic->Dict.has("fromDefault")
27462741
) {
27472742
// skip it
27482743
()
@@ -4240,7 +4235,7 @@ module Schema = {
42404235
let item: item = items->Js.Array2.unsafe_get(idx)
42414236

42424237
// TODO: Improve the hack to ignore items belonging to a flattened schema
4243-
if !(objectVal.properties->X.Option.getUnsafe->X.Dict.has(item.location)) {
4238+
if !(objectVal.properties->X.Option.getUnsafe->Stdlib.Dict.has(item.location)) {
42444239
objectVal->B.Val.Object.add(
42454240
~location=item.location,
42464241
item
@@ -4326,7 +4321,7 @@ module Schema = {
43264321
(fieldName, schema) => {
43274322
let schema = schema->castToInternal
43284323
let inlinedLocation = fieldName->X.Inlined.Value.fromString
4329-
if properties->X.Dict.has(fieldName) {
4324+
if properties->Stdlib.Dict.has(fieldName) {
43304325
InternalError.panic(`The field ${inlinedLocation} defined twice`)
43314326
}
43324327
let ditem: ditem = ItemField({
@@ -4441,7 +4436,7 @@ module Schema = {
44414436
(fieldName, schema) => {
44424437
let schema = schema->castToInternal
44434438

4444-
if properties->X.Dict.has(fieldName) {
4439+
if properties->Stdlib.Dict.has(fieldName) {
44454440
InternalError.panic(`The field "${fieldName}" defined twice with incompatible schemas`)
44464441
}
44474442
let ditem: ditem = Item({
@@ -5473,7 +5468,7 @@ let js_merge = (s1, s2) => {
54735468
}
54745469
for idx in 0 to items2->Js.Array2.length - 1 {
54755470
let item = items2->Js.Array2.unsafe_get(idx)
5476-
if !(properties->X.Dict.has(item.location)) {
5471+
if !(properties->Stdlib.Dict.has(item.location)) {
54775472
locations->Js.Array2.push(item.location)->ignore
54785473
}
54795474
properties->Js.Dict.set(item.location, item.schema->castToInternal)

0 commit comments

Comments
 (0)