Skip to content

Commit 374a0d0

Browse files
committed
Update String doc samples
1 parent 4c86a31 commit 374a0d0

File tree

4 files changed

+10
-11
lines changed

4 files changed

+10
-11
lines changed

runtime/Stdlib_String.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
type t = string
22

3-
@new external make: 'a => string = "String"
3+
@val external make: 'a => string = "String"
44

55
@val external fromCharCode: int => string = "String.fromCharCode"
66
@variadic @val external fromCharCodeMany: array<int> => string = "String.fromCharCode"

runtime/Stdlib_String.resi

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ String.make(3.5) == "3.5"
4242
String.make([1, 2, 3]) == "1,2,3"
4343
```
4444
*/
45-
@new
45+
@val
4646
external make: 'a => string = "String"
4747

4848
/**
@@ -1119,10 +1119,9 @@ Returns `None` if the symbol property doesn't exist.
11191119
## Examples
11201120
11211121
```rescript
1122-
let mySymbol = Symbol.make("test")
11231122
let h = String.make("hello")
1124-
String.setSymbol(h, mySymbol, 42)
1125-
String.getSymbol(h, mySymbol) == Some(42)
1123+
let symbol = String.getSymbol(h, Symbol.iterator)
1124+
Option.isSome(symbol) == true
11261125
```
11271126
*/
11281127
@get_index external getSymbol: (string, Stdlib_Symbol.t) => option<'a> = ""
@@ -1135,10 +1134,10 @@ This is _unsafe_, meaning it will return `undefined` if the symbol property does
11351134
## Examples
11361135
11371136
```rescript
1138-
let mySymbol = Symbol.make("test")
11391137
let h = String.make("hello")
1140-
String.setSymbol(h, mySymbol, 43)
1141-
String.getSymbolUnsafe(h, mySymbol) == 43
1138+
// This does required direct access to the symbol property
1139+
// Storing the iterator in a variable first, will not work.
1140+
String.getSymbolUnsafe(h, Symbol.iterator)()->Iterator.toArray->Array.length == 5
11421141
```
11431142
*/
11441143
@get_index external getSymbolUnsafe: (string, Stdlib_Symbol.t) => 'a = ""
@@ -1150,7 +1149,7 @@ String.getSymbolUnsafe(h, mySymbol) == 43
11501149
11511150
```rescript
11521151
let mySymbol = Symbol.make("test")
1153-
let h = String.make("hello")
1152+
let h = %raw(`new String("hello")`)
11541153
String.setSymbol(h, mySymbol, 42)
11551154
String.getSymbol(h, mySymbol) == Some(42)
11561155
```

tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ Path s
874874
"kind": 12,
875875
"tags": [],
876876
"detail": "(string, Symbol.t, 'a) => unit",
877-
"documentation": {"kind": "markdown", "value": "\n`setSymbol(str, symbol, value)` sets the given symbol property on the string to the specified value.\n\n## Examples\n\n```rescript\nlet mySymbol = Symbol.make(\"test\")\nlet h = String.make(\"hello\")\nString.setSymbol(h, mySymbol, 42)\nString.getSymbol(h, mySymbol) == Some(42)\n```\n"},
877+
"documentation": {"kind": "markdown", "value": "\n`setSymbol(str, symbol, value)` sets the given symbol property on the string to the specified value.\n\n## Examples\n\n```rescript\nlet mySymbol = Symbol.make(\"test\")\nlet h = %raw(`new String(\"hello\")`)\nString.setSymbol(h, mySymbol, 42)\nString.getSymbol(h, mySymbol) == Some(42)\n```\n"},
878878
"sortText": "setSymbol",
879879
"insertText": "->String.setSymbol",
880880
"additionalTextEdits": [{

tests/tests/src/core/Test.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function print(value) {
1515
} else if (match === "string") {
1616
return Stdlib_Option.getExn(JSON.stringify(value), undefined);
1717
} else {
18-
return String(value);
18+
return new String(value);
1919
}
2020
}
2121

0 commit comments

Comments
 (0)