From f316aaf7fd61fc86d4fc61dea0cdbaa155bed37d Mon Sep 17 00:00:00 2001 From: jmagaram Date: Fri, 24 Mar 2023 10:01:11 -0700 Subject: [PATCH 1/2] remove sub-modules --- src/Core__Error.mjs | 18 ---------------- src/Core__Error.res | 30 ++++++-------------------- src/Core__Error.resi | 50 +++++++++++++++++--------------------------- src/Core__Int.res | 2 +- test/IntTests.res | 4 ++-- test/TempTests.res | 2 +- 6 files changed, 29 insertions(+), 77 deletions(-) diff --git a/src/Core__Error.mjs b/src/Core__Error.mjs index 5c9e853f..eab17c84 100644 --- a/src/Core__Error.mjs +++ b/src/Core__Error.mjs @@ -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 */ diff --git a/src/Core__Error.res b/src/Core__Error.res index 408b08ff..716ff794 100644 --- a/src/Core__Error.res +++ b/src/Core__Error.res @@ -9,30 +9,12 @@ external toException: t => exn = "%identity" @get external fileName: t => option = "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" diff --git a/src/Core__Error.resi b/src/Core__Error.resi index 76c12c0c..3bb1e49b 100644 --- a/src/Core__Error.resi +++ b/src/Core__Error.resi @@ -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 diff --git a/src/Core__Int.res b/src/Core__Int.res index 743aaf64..617c8bd1 100644 --- a/src/Core__Int.res +++ b/src/Core__Int.res @@ -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 } diff --git a/test/IntTests.res b/test/IntTests.res index 373cf8c9..a5569bdc 100644 --- a/test/IntTests.res +++ b/test/IntTests.res @@ -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"), @@ -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"), diff --git a/test/TempTests.res b/test/TempTests.res index f7bf9d3b..8bac9e0a 100644 --- a/test/TempTests.res +++ b/test/TempTests.res @@ -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) From 2d18a18f68aa497287f7ad6a28e423fa8c5f2eab Mon Sep 17 00:00:00 2001 From: jmagaram Date: Fri, 24 Mar 2023 10:06:40 -0700 Subject: [PATCH 2/2] change log --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5df9f6b0..20634b67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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