Skip to content

Js.log -> Console.log #768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 1, 2024
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
24 changes: 12 additions & 12 deletions pages/docs/manual/latest/async-await.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ let logUserDetails = async (userId: string) => {

await sendAnalytics(`User details have been logged for ${userId}`)

Js.log(`Email address for user ${userId}: ${email}`)
Console.log(`Email address for user ${userId}: ${email}`)
}
```

Expand Down Expand Up @@ -139,8 +139,8 @@ let checkAuth = async () => {
} catch {
| Js.Exn.Error(e) =>
switch Js.Exn.message(e) {
| Some(msg) => Js.log("JS error thrown: " ++ msg)
| None => Js.log("Some other exception has been thrown")
| Some(msg) => Console.log("JS error thrown: " ++ msg)
| None => Console.log("Some other exception has been thrown")
}
}
}
Expand All @@ -157,11 +157,11 @@ let authenticate = async () => {

let checkAuth = async () => {
switch await authenticate() {
| _ => Js.log("ok")
| _ => Console.log("ok")
| exception Js.Exn.Error(e) =>
switch Js.Exn.message(e) {
| Some(msg) => Js.log("JS error thrown: " ++ msg)
| None => Js.log("Some other exception has been thrown")
| Some(msg) => Console.log("JS error thrown: " ++ msg)
| None => Console.log("Some other exception has been thrown")
}
}
}
Expand All @@ -181,7 +181,7 @@ This can be done by wrapping your `await` calls in a new `{}` closure.

let fetchData = async () => {
let mail = {await fetchUserMail("1234")}->Js.String2.toUpperCase
Js.log(`All upper-cased mail: ${mail}`)
Console.log(`All upper-cased mail: ${mail}`)
}
```

Expand All @@ -208,11 +208,11 @@ Note how the original closure was removed in the final JS output. No extra alloc
let fetchData = async () => {
switch (await fetchUserMail("user1"), await fetchUserMail("user2")) {
| (user1Mail, user2Mail) => {
Js.log("user 1 mail: " ++ user1Mail)
Js.log("user 2 mail: " ++ user2Mail)
Console.log("user 1 mail: " ++ user1Mail)
Console.log("user 2 mail: " ++ user2Mail)
}

| exception JsError(err) => Js.log2("Some error occurred", err)
| exception JsError(err) => Console.log2("Some error occurred", err)
}
}
```
Expand Down Expand Up @@ -261,8 +261,8 @@ let logMultipleValues = async () => {
let all = await Js.Promise2.all([promise1, promise2, promise3])

switch all {
| [v1, v2, v3] => Js.log(`All values: ${v1}, ${v2}, ${v3}`)
| _ => Js.log("this should never happen")
| [v1, v2, v3] => Console.log(`All values: ${v1}, ${v2}, ${v3}`)
| _ => Console.log("this should never happen")
}
}
```
Expand Down
10 changes: 5 additions & 5 deletions pages/docs/manual/latest/bind-to-global-js-values.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type timerId
@val external setTimeout: (unit => unit, int) => timerId = "setTimeout"
@val external clearTimeout: timerId => unit = "clearTimeout"

let id = setTimeout(() => Js.log("hello"), 100)
let id = setTimeout(() => Console.log("hello"), 100)
clearTimeout(id)
```
```js
Expand Down Expand Up @@ -102,8 +102,8 @@ For these troublesome global values, ReScript provides a special approach: `%ext

```res example
switch %external(__DEV__) {
| Some(_) => Js.log("dev mode")
| None => Js.log("production mode")
| Some(_) => Console.log("dev mode")
| None => Console.log("production mode")
}
```
```js
Expand All @@ -126,8 +126,8 @@ Another example:

```res example
switch %external(__filename) {
| Some(f) => Js.log(f)
| None => Js.log("non-node environment")
| Some(f) => Console.log(f)
| None => Console.log("non-node environment")
};
```
```js
Expand Down
6 changes: 3 additions & 3 deletions pages/docs/manual/latest/bind-to-js-function.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ external on: (
let register = rl =>
rl
->on(#close(event => ()))
->on(#line(line => Js.log(line)));
->on(#line(line => Console.log(line)));
```
```js
function register(rl) {
Expand Down Expand Up @@ -313,7 +313,7 @@ external processOnExit: (
) => unit = "process.on"

processOnExit(exitCode =>
Js.log("error code: " ++ Js.Int.toString(exitCode))
Console.log("error code: " ++ Js.Int.toString(exitCode))
);
```
```js
Expand Down Expand Up @@ -365,7 +365,7 @@ type x
@val external x: x = "x"
@set external setOnload: (x, @this ((x, int) => unit)) => unit = "onload"
@get external resp: x => int = "response"
setOnload(x, @this (o, v) => Js.log(resp(o) + v))
setOnload(x, @this (o, v) => Console.log(resp(o) + v))
```
```js
x.onload = function (v) {
Expand Down
2 changes: 1 addition & 1 deletion pages/docs/manual/latest/bind-to-js-object.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ type t

let i32arr = create(3)
i32arr->set(0, 42)
Js.log(i32arr->get(0))
Console.log(i32arr->get(0))
```
```js
var i32arr = new Int32Array(3);
Expand Down
2 changes: 1 addition & 1 deletion pages/docs/manual/latest/build-external-stdlib.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Now the compiled JS code will import using the path defined by `external-stdlib`
<CodeTab labels={["ReScript", "JS output"]}>

```res
Array.forEach([1, 2, 3], num => Js.log(num))
Array.forEach([1, 2, 3], num => Console.log(num))
```

```js
Expand Down
10 changes: 5 additions & 5 deletions pages/docs/manual/latest/control-flow.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ For loops iterate from a starting value up to (and including) the ending value.

```res
for i in startValueInclusive to endValueInclusive {
Js.log(i)
Console.log(i)
}
```
```js
Expand All @@ -114,7 +114,7 @@ for(var i = startValueInclusive; i <= endValueInclusive; ++i){
```res example
// prints: 1 2 3, one per line
for x in 1 to 3 {
Js.log(x)
Console.log(x)
}
```
```js
Expand All @@ -131,7 +131,7 @@ You can make the `for` loop count in the opposite direction by using `downto`.

```res
for i in startValueInclusive downto endValueInclusive {
Js.log(i)
Console.log(i)
}
```
```js
Expand All @@ -147,7 +147,7 @@ for(var i = startValueInclusive; i >= endValueInclusive; --i){
```res example
// prints: 3 2 1, one per line
for x in 3 downto 1 {
Js.log(x)
Console.log(x)
}
```
```js
Expand Down Expand Up @@ -190,7 +190,7 @@ while !break.contents {
if Js.Math.random() > 0.3 {
break := true
} else {
Js.log("Still running")
Console.log("Still running")
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion pages/docs/manual/latest/embed-raw-javascript.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ let add = %raw(`
}
`)

Js.log(add(1, 2))
Console.log(add(1, 2))
```
```js
var add = function(a, b) {
Expand Down
6 changes: 3 additions & 3 deletions pages/docs/manual/latest/exception.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ You can directly match on exceptions _while_ getting another return value from a

```res prelude
switch list{1, 2, 3}->List.getExn(4) {
| item => Js.log(item)
| exception Not_found => Js.log("No such item found!")
| item => Console.log(item)
| exception Not_found => Console.log("No such item found!")
}
```
```js
Expand Down Expand Up @@ -160,7 +160,7 @@ try {
} catch {
| Js.Exn.Error(obj) =>
switch Js.Exn.message(obj) {
| Some(m) => Js.log("Caught a JS exception! Message: " ++ m)
| Some(m) => Console.log("Caught a JS exception! Message: " ++ m)
| None => ()
}
}
Expand Down
6 changes: 3 additions & 3 deletions pages/docs/manual/latest/extensible-variant.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ Extensible variants are open-ended, so the compiler will not be able to exhausti
```res
let print = v =>
switch v {
| Point(x, y) => Js.log2("Point", (x, y))
| Line(ax, ay, bx, by) => Js.log2("Line", (ax, ay, bx, by))
| Point(x, y) => Console.log2("Point", (x, y))
| Line(ax, ay, bx, by) => Console.log2("Line", (ax, ay, bx, by))
| Other
| _ => Js.log("Other")
| _ => Console.log("Other")
}
```
```js
Expand Down
2 changes: 1 addition & 1 deletion pages/docs/manual/latest/external.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Once declared, you can use an `external` as a normal value, just like a let bind

// call a method
document["addEventListener"](."mouseup", _event => {
Js.log("clicked!")
Console.log("clicked!")
})

// get a property
Expand Down
2 changes: 1 addition & 1 deletion pages/docs/manual/latest/generate-converters-accessors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ let pets = [{name: "bob"}, {name: "bob2"}]
pets
->Array.map(name)
->Array.joinWith("&")
->Js.log
->Console.log
```

```js
Expand Down
2 changes: 1 addition & 1 deletion pages/docs/manual/latest/import-from-export-to-js.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Use the value `"default"` on the right hand side:

```res example
@module("./student") external studentName: string = "default"
Js.log(studentName)
Console.log(studentName)
```
```js
import Student from "./student";
Expand Down
4 changes: 2 additions & 2 deletions pages/docs/manual/latest/inlining-constants.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ So, in ReScript, producing that example `if (process.env.mode === 'development')
let mode = "development"
if (process["env"]["mode"] === mode) {
Js.log("Dev-only code here!")
Console.log("Dev-only code here!")
}
```
```js
Expand All @@ -58,7 +58,7 @@ The JS output shows `if (process.env.mode === mode)`, which isn't what we wanted
let mode = "development"
if (process["env"]["mode"] === mode) {
Js.log("Dev-only code here!")
Console.log("Dev-only code here!")
}
```
```js
Expand Down
2 changes: 1 addition & 1 deletion pages/docs/manual/latest/interop-cheatsheet.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ var result3 = Caml_option.nullable_to_opt(10);
[1, 2, 3]
->map(a => a + 1)
->filter(a => mod(a, 2) == 0)
->Js.log
->Console.log
```
```js
console.log(
Expand Down
2 changes: 1 addition & 1 deletion pages/docs/manual/latest/json.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Use `Js.Json.stringify`:
<CodeTab labels={["ReScript", "JS Output"]}>

```res example
Js.log(Js.Json.stringifyAny(["Amy", "Joe"]))
Console.log(Js.Json.stringifyAny(["Amy", "Joe"]))
```
```js
console.log(JSON.stringify([
Expand Down
10 changes: 5 additions & 5 deletions pages/docs/manual/latest/lazy-values.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ external readdirSync: string => array<string> = "readdirSync"

// Read the directory, only once
let expensiveFilesRead = lazy({
Js.log("Reading dir")
Console.log("Reading dir")
readdirSync("./pages")
})
```
Expand Down Expand Up @@ -46,10 +46,10 @@ To actually run the lazy value's computation, use `Lazy.force` from the globally

```res example
// First call. The computation happens
Js.log(Lazy.force(expensiveFilesRead)) // logs "Reading dir" and the directory content
Console.log(Lazy.force(expensiveFilesRead)) // logs "Reading dir" and the directory content

// Second call. Will just return the already calculated result
Js.log(Lazy.force(expensiveFilesRead)) // logs the directory content
Console.log(Lazy.force(expensiveFilesRead)) // logs the directory content
```
```js
console.log(CamlinternalLazy.force(expensiveFilesRead));
Expand All @@ -69,7 +69,7 @@ Instead of using `Lazy.force`, you can also use [pattern matching](pattern-match

```res example
switch expensiveFilesRead {
| lazy(result) => Js.log(result)
| lazy(result) => Console.log(result)
}
```
```js
Expand All @@ -84,7 +84,7 @@ Since pattern matching also works on a `let` binding, you can also do:

```res example
let lazy(result) = expensiveFilesRead
Js.log(result)
Console.log(result)
```
```js
var result = CamlinternalLazy.force(expensiveFilesRead);
Expand Down
2 changes: 1 addition & 1 deletion pages/docs/manual/latest/let-binding.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ ReScript's `if`, `while` and functions all use the same block scoping mechanism.
```res
if displayGreeting {
let message = "Enjoying the docs so far?"
Js.log(message)
Console.log(message)
}
// `message` not accessible here!
```
Expand Down
2 changes: 1 addition & 1 deletion pages/docs/manual/latest/module.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ using the `.` notation. This demonstrates modules' utility for namespacing.

```res
let anotherPerson: School.profession = School.Teacher
Js.log(School.getProfession(anotherPerson)) /* "A teacher" */
Console.log(School.getProfession(anotherPerson)) /* "A teacher" */
```
```js
var anotherPerson = /* Teacher */0;
Expand Down
4 changes: 2 additions & 2 deletions pages/docs/manual/latest/newcomer-examples.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ let possiblyNullValue1 = None
let possiblyNullValue2 = Some("Hello")

switch possiblyNullValue2 {
| None => Js.log("Nothing to see here.")
| Some(message) => Js.log(message)
| None => Console.log("Nothing to see here.")
| Some(message) => Console.log(message)
}
```
```js
Expand Down
4 changes: 2 additions & 2 deletions pages/docs/manual/latest/null-undefined-option.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ Later on, when another piece of code receives such value, it'd be forced to hand
```res
switch licenseNumber {
| None =>
Js.log("The person doesn't have a car")
Console.log("The person doesn't have a car")
| Some(number) =>
Js.log("The person's license number is " ++ Js.Int.toString(number))
Console.log("The person's license number is " ++ Js.Int.toString(number))
}
```
```js
Expand Down
2 changes: 1 addition & 1 deletion pages/docs/manual/latest/object.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ Since objects don't require type declarations, and since ReScript infers all the

// call a method
document["addEventListener"](. "mouseup", _event => {
Js.log("clicked!")
Console.log("clicked!")
})

// get a property
Expand Down
Loading