From 549d9594185e89d49cd0803c8ad77dea8bbb5495 Mon Sep 17 00:00:00 2001 From: exoego Date: Thu, 30 Jul 2020 15:04:23 +0900 Subject: [PATCH 1/3] Accept 0 arguments --- .../nodejs/console_module/ConsoleTest.scala | 27 +++++++++++++++++++ .../nodejs/console_module/Console.scala | 18 ++++++------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/app/nodejs-v10/src/test/scala/io/scalajs/nodejs/console_module/ConsoleTest.scala b/app/nodejs-v10/src/test/scala/io/scalajs/nodejs/console_module/ConsoleTest.scala index 2d564683e..22cbc764d 100644 --- a/app/nodejs-v10/src/test/scala/io/scalajs/nodejs/console_module/ConsoleTest.scala +++ b/app/nodejs-v10/src/test/scala/io/scalajs/nodejs/console_module/ConsoleTest.scala @@ -13,6 +13,33 @@ class ConsoleTest extends AnyFunSpec with BeforeAndAfterEach { if (Fs.existsSync(logFileName)) Fs.unlinkSync(logFileName) } + it("should accept no-arguments") { + Console.log() + Console.info() + Console.warn() + Console.debug() + Console.error() + Console.trace() + } + + it("should accept single arguments") { + Console.log("a") + Console.info("a") + Console.warn("a") + Console.debug("a") + Console.error("a") + Console.trace("") + } + + it("should accept multiple arguments") { + Console.log("a", 1) + Console.info("a", 2) + Console.warn("a", 3) + Console.debug("a", 4) + Console.error("a", 5) + Console.trace("", 6) + } + it("have table added in v10.0.0") { Console.table(js.Array("x", "y")) } diff --git a/app/nodejs-v14/src/main/scala/io/scalajs/nodejs/console_module/Console.scala b/app/nodejs-v14/src/main/scala/io/scalajs/nodejs/console_module/Console.scala index 21558452e..ef3941fa5 100644 --- a/app/nodejs-v14/src/main/scala/io/scalajs/nodejs/console_module/Console.scala +++ b/app/nodejs-v14/src/main/scala/io/scalajs/nodejs/console_module/Console.scala @@ -77,10 +77,9 @@ class Console protected () extends js.Object { /** * The `console.debug()` function is an alias for `console.log()`. - * @param message - * @param optionalParams + * @param args */ - def debug(message: js.Any, optionalParams: Any*): Unit = js.native + def debug(args: js.Any*): Unit = js.native /** * Uses [[io.scalajs.nodejs.util.Util.inspect()]] on `obj` and prints the resulting string to `stdout`. @@ -104,10 +103,9 @@ class Console protected () extends js.Object { * is called on each argument and the resulting string values are concatenated. See [[io.scalajs.nodejs.util.Util.format()]] * for more information. * - * @param message - * @param optionalParams + * @param args */ - def error(message: js.Any, optionalParams: Any*): Unit = js.native + def error(args: js.Any*): Unit = js.native /** * Increases indentation of subsequent lines by two spaces. @@ -132,14 +130,14 @@ class Console protected () extends js.Object { /** * The `console.info()` function is an alias for [[log()]]. */ - def info(message: js.Any, optionalParams: js.Any*): Unit = js.native + def info(args: js.Any*): Unit = js.native /** * Prints to `stdout` with newline. * Multiple arguments can be passed, with the first used as the primary message and all additional used as * substitution values similar to `printf(3)` (the arguments are all passed to `util.format()`). */ - def log(message: js.Any, optionalParams: Any*): Unit = js.native + def log(args: js.Any*): Unit = js.native /** * Try to construct a table with the columns of the properties of `tabularData` (or use `properties`) and @@ -176,12 +174,12 @@ class Console protected () extends js.Object { * Prints to `stderr` the string `'Trace: '`, followed by the [[io.scalajs.nodejs.util.Util.format()]] formatted * message and stack trace to the current position in the code. */ - def trace(message: js.Any, optionalParams: js.Any*): Unit = js.native + def trace(args: js.Any*): Unit = js.native /** * The `console.warn()` function is an alias for [[error()] */ - def warn(message: js.Any, optionalParams: js.Any*): Unit = js.native + def warn(args: js.Any*): Unit = js.native /** * This method does not display anything unless used in the inspector. From ca8bb1d83e3a0ff68afc392f4fbe5ca784052b2a Mon Sep 17 00:00:00 2001 From: exoego Date: Thu, 30 Jul 2020 15:06:51 +0900 Subject: [PATCH 2/3] Can be passed to foreach --- .../io/scalajs/nodejs/console_module/ConsoleTest.scala | 10 ++++++++++ .../io/scalajs/nodejs/console_module/Console.scala | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/app/nodejs-v10/src/test/scala/io/scalajs/nodejs/console_module/ConsoleTest.scala b/app/nodejs-v10/src/test/scala/io/scalajs/nodejs/console_module/ConsoleTest.scala index 22cbc764d..3f1062d17 100644 --- a/app/nodejs-v10/src/test/scala/io/scalajs/nodejs/console_module/ConsoleTest.scala +++ b/app/nodejs-v10/src/test/scala/io/scalajs/nodejs/console_module/ConsoleTest.scala @@ -40,6 +40,16 @@ class ConsoleTest extends AnyFunSpec with BeforeAndAfterEach { Console.trace("", 6) } + it("should be passed to foreach") { + val s: Seq[js.Any] = Seq("s", true) + s.foreach(Console.log) + s.foreach(Console.info) + s.foreach(Console.warn) + s.foreach(Console.debug) + s.foreach(Console.error) + s.foreach(Console.trace) + } + it("have table added in v10.0.0") { Console.table(js.Array("x", "y")) } diff --git a/app/nodejs-v14/src/main/scala/io/scalajs/nodejs/console_module/Console.scala b/app/nodejs-v14/src/main/scala/io/scalajs/nodejs/console_module/Console.scala index ef3941fa5..93b42006b 100644 --- a/app/nodejs-v14/src/main/scala/io/scalajs/nodejs/console_module/Console.scala +++ b/app/nodejs-v14/src/main/scala/io/scalajs/nodejs/console_module/Console.scala @@ -80,6 +80,7 @@ class Console protected () extends js.Object { * @param args */ def debug(args: js.Any*): Unit = js.native + def debug(arg: js.Any): Unit = js.native /** * Uses [[io.scalajs.nodejs.util.Util.inspect()]] on `obj` and prints the resulting string to `stdout`. @@ -106,6 +107,7 @@ class Console protected () extends js.Object { * @param args */ def error(args: js.Any*): Unit = js.native + def error(arg: js.Any): Unit = js.native /** * Increases indentation of subsequent lines by two spaces. @@ -131,6 +133,7 @@ class Console protected () extends js.Object { * The `console.info()` function is an alias for [[log()]]. */ def info(args: js.Any*): Unit = js.native + def info(arg: js.Any): Unit = js.native /** * Prints to `stdout` with newline. @@ -138,6 +141,7 @@ class Console protected () extends js.Object { * substitution values similar to `printf(3)` (the arguments are all passed to `util.format()`). */ def log(args: js.Any*): Unit = js.native + def log(arg: js.Any): Unit = js.native /** * Try to construct a table with the columns of the properties of `tabularData` (or use `properties`) and @@ -175,11 +179,13 @@ class Console protected () extends js.Object { * message and stack trace to the current position in the code. */ def trace(args: js.Any*): Unit = js.native + def trace(arg: js.Any): Unit = js.native /** * The `console.warn()` function is an alias for [[error()] */ def warn(args: js.Any*): Unit = js.native + def warn(arg: js.Any): Unit = js.native /** * This method does not display anything unless used in the inspector. From ea916660423fa72b83ebd32315df2f566bc2820c Mon Sep 17 00:00:00 2001 From: exoego Date: Thu, 30 Jul 2020 15:53:39 +0900 Subject: [PATCH 3/3] Fix for Scala 2.12: ambiguous reference to overloaded definition, --- .../nodejs/console_module/Console.scala | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/app/nodejs-v14/src/main/scala/io/scalajs/nodejs/console_module/Console.scala b/app/nodejs-v14/src/main/scala/io/scalajs/nodejs/console_module/Console.scala index 93b42006b..44ed50a28 100644 --- a/app/nodejs-v14/src/main/scala/io/scalajs/nodejs/console_module/Console.scala +++ b/app/nodejs-v14/src/main/scala/io/scalajs/nodejs/console_module/Console.scala @@ -77,10 +77,10 @@ class Console protected () extends js.Object { /** * The `console.debug()` function is an alias for `console.log()`. - * @param args */ - def debug(args: js.Any*): Unit = js.native - def debug(arg: js.Any): Unit = js.native + def debug(data: js.Any, args: js.Any*): Unit = js.native + def debug(data: js.Any): Unit = js.native + def debug(): Unit = js.native /** * Uses [[io.scalajs.nodejs.util.Util.inspect()]] on `obj` and prints the resulting string to `stdout`. @@ -106,8 +106,9 @@ class Console protected () extends js.Object { * * @param args */ - def error(args: js.Any*): Unit = js.native - def error(arg: js.Any): Unit = js.native + def error(data: js.Any, args: js.Any*): Unit = js.native + def error(data: js.Any): Unit = js.native + def error(): Unit = js.native /** * Increases indentation of subsequent lines by two spaces. @@ -132,16 +133,18 @@ class Console protected () extends js.Object { /** * The `console.info()` function is an alias for [[log()]]. */ - def info(args: js.Any*): Unit = js.native - def info(arg: js.Any): Unit = js.native + def info(data: js.Any, args: js.Any*): Unit = js.native + def info(data: js.Any): Unit = js.native + def info(): Unit = js.native /** * Prints to `stdout` with newline. * Multiple arguments can be passed, with the first used as the primary message and all additional used as * substitution values similar to `printf(3)` (the arguments are all passed to `util.format()`). */ - def log(args: js.Any*): Unit = js.native - def log(arg: js.Any): Unit = js.native + def log(data: js.Any, args: js.Any*): Unit = js.native + def log(data: js.Any): Unit = js.native + def log(): Unit = js.native /** * Try to construct a table with the columns of the properties of `tabularData` (or use `properties`) and @@ -178,14 +181,16 @@ class Console protected () extends js.Object { * Prints to `stderr` the string `'Trace: '`, followed by the [[io.scalajs.nodejs.util.Util.format()]] formatted * message and stack trace to the current position in the code. */ - def trace(args: js.Any*): Unit = js.native - def trace(arg: js.Any): Unit = js.native + def trace(data: js.Any, args: js.Any*): Unit = js.native + def trace(data: js.Any): Unit = js.native + def trace(): Unit = js.native /** * The `console.warn()` function is an alias for [[error()] */ - def warn(args: js.Any*): Unit = js.native - def warn(arg: js.Any): Unit = js.native + def warn(data: js.Any, args: js.Any*): Unit = js.native + def warn(data: js.Any): Unit = js.native + def warn(): Unit = js.native /** * This method does not display anything unless used in the inspector.