Skip to content

Fix Intellisense menu for Error #122

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Next version

### API changes

- `Error.makeSyntaxError` not `Error.SyntaxError.make` and for all similar error types. Makes the Intellisense menu easier to navigate. https://github.com/rescript-association/rescript-core/pull/122

## 0.4.0

### API changes
Expand Down
18 changes: 0 additions & 18 deletions src/Core__Error.mjs
Original file line number Diff line number Diff line change
@@ -1,29 +1,11 @@
// Generated by ReScript, PLEASE EDIT WITH CARE


var $$EvalError = {};

var $$RangeError = {};

var $$ReferenceError = {};

var $$SyntaxError = {};

var $$TypeError = {};

var $$URIError = {};

function panic(msg) {
throw new Error("Panic! " + msg + "");
}

export {
$$EvalError ,
$$RangeError ,
$$ReferenceError ,
$$SyntaxError ,
$$TypeError ,
$$URIError ,
panic ,
}
/* No side effect */
30 changes: 6 additions & 24 deletions src/Core__Error.res
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,12 @@ external toException: t => exn = "%identity"
@get external fileName: t => option<string> = "fileName"

@new external make: string => t = "Error"

module EvalError = {
@new external make: string => t = "EvalError"
}

module RangeError = {
@new external make: string => t = "RangeError"
}

module ReferenceError = {
@new external make: string => t = "ReferenceError"
}

module SyntaxError = {
@new external make: string => t = "SyntaxError"
}

module TypeError = {
@new external make: string => t = "TypeError"
}

module URIError = {
@new external make: string => t = "URIError"
}
@new external makeEvalError: string => t = "EvalError"
@new external makeRangeError: string => t = "RangeError"
@new external makeReferenceError: string => t = "ReferenceError"
@new external makeSyntaxError: string => t = "SyntaxError"
@new external makeTypeError: string => t = "TypeError"
@new external makeURIError: string => t = "URIError"

external raise: t => 'a = "%raise"

Expand Down
50 changes: 19 additions & 31 deletions src/Core__Error.resi
Original file line number Diff line number Diff line change
Expand Up @@ -85,63 +85,51 @@ Console.log(error->Error.name) // Logs "Error" to the console, because this is a
@new
external make: string => t = "Error"

module EvalError: {
/**
/**
Creates a new `EvalError` with the provided `message`.

See [`EvalError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError) on MDN.
*/
@new
external make: string => t = "EvalError"
}
module RangeError: {
/**
@new
external makeEvalError: string => t = "EvalError"
/**
Creates a new `RangeError` with the provided `message`.

See [`RangeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError) on MDN.
*/
@new
external make: string => t = "RangeError"
}
module ReferenceError: {
/**
@new
external makeRangeError: string => t = "RangeError"
/**
Creates a new `ReferenceError` with the provided `message`.

See [`ReferenceError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError) on MDN.
*/
@new
external make: string => t = "ReferenceError"
}
module SyntaxError: {
/**
@new
external makeReferenceError: string => t = "ReferenceError"
/**
Creates a new `SyntaxError` with the provided `message`.

See [`SyntaxError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError) on MDN.
*/
@new
external make: string => t = "SyntaxError"
}
module TypeError: {
/**
@new
external makeSyntaxError: string => t = "SyntaxError"
/**
Creates a new `TypeError` with the provided `message`.

See [`TypeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) on MDN.
*/
@new
external make: string => t = "TypeError"
}
module URIError: {
/**
@new
external makeTypeError: string => t = "TypeError"
/**
Creates a new `URIError` with the provided `message`.

See [`URIError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError) on MDN.
*/
@new
external make: string => t = "URIError"
}
@new
external makeURIError: string => t = "URIError"

/**
Raises (throws in JavaScript language) the provided `Error.t`, which will stop execution.
Raises (throws in JavaScript language) the provided `Error.t`, which will stop execution. See [Exceptions in ReScript](https://rescript-lang.org/docs/manual/latest/exception)

## Examples
```rescript
Expand Down
2 changes: 1 addition & 1 deletion src/Core__Int.res
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ let rangeWithOptions = (start, end, options) => {
let step = switch options.step {
| None => isInverted ? -1 : 1
| Some(0) if start !== end =>
Core__Error.raise(Core__Error.RangeError.make("Incorrect range arguments"))
Core__Error.raise(Core__Error.makeRangeError("Incorrect range arguments"))
| Some(n) => n
}

Expand Down
4 changes: 2 additions & 2 deletions test/IntTests.res
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Test.run(
__POS_OF__("rangeWithOptions - positive, increasing, step 0"),
catch(() => Int.rangeWithOptions(3, 6, {step: 0})),
eq,
Error.RangeError.make("Incorrect range arguments"),
Error.makeRangeError("Incorrect range arguments"),
)
Test.run(
__POS_OF__("rangeWithOptions - start == end, step 0"),
Expand Down Expand Up @@ -117,7 +117,7 @@ Test.run(
__POS_OF__("rangeWithOptions - positive, increasing, step 0, inclusive"),
catch(() => Int.rangeWithOptions(3, 6, {step: 0, inclusive: true})),
eq,
Error.RangeError.make("Incorrect range arguments"),
Error.makeRangeError("Incorrect range arguments"),
)
Test.run(
__POS_OF__("rangeWithOptions - start == end, step 0, inclusive"),
Expand Down
2 changes: 1 addition & 1 deletion test/TempTests.res
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Console.info("Error")
Console.info("---")
let f = () => {
let error = Error.make("hello")
let typeError = Error.TypeError.make("error")
let typeError = Error.makeTypeError("error")
let g = () => Error.raise(error)
let h = () => Error.raise(typeError)
(g, h)
Expand Down