Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

Deprecate harmful or redundant things. #97

Merged
merged 1 commit into from
Oct 4, 2019
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.scalajs.nodejs.buffer

import com.thoughtworks.enableIf
import io.scalajs.collection.Iterator

import scala.scalajs.js
import scala.scalajs.js.annotation.{JSBracketAccess, JSGlobal, JSImport}
Expand Down Expand Up @@ -148,7 +147,7 @@ class Buffer protected () extends Uint8Array( /* dummy to trick constructor */ -
*
* @see [[https://nodejs.org/api/buffer.html#buffer_buf_entries]]
*/
def entries(): Iterator[js.Array[Int]] = js.native
def entries(): js.Iterator[js.Array[Int]] = js.native

/**
* Returns true if both buf and otherBuffer have exactly the same bytes, false otherwise.
Expand Down Expand Up @@ -201,7 +200,7 @@ class Buffer protected () extends Uint8Array( /* dummy to trick constructor */ -
* @return an [[Iterator]]
* @example buf.keys()
*/
def keys(): Iterator[Int] = js.native
def keys(): js.Iterator[Int] = js.native

/**
* The largest size allowed for a single Buffer instance.
Expand Down Expand Up @@ -548,7 +547,7 @@ class Buffer protected () extends Uint8Array( /* dummy to trick constructor */ -
* @return an iterator for buf values (bytes)
* @example buf.values()
*/
def values(): Iterator[Int] = js.native
def values(): js.Iterator[Int] = js.native

/**
* Writes string to buf at offset according to the character encoding in encoding. The length parameter is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ package object buffer {
* @return the hex-formatted string
*/
@inline
def toHexString: String = buffer.entries().flatMap(_.lastOption).map(n => f"$n%02x").mkString
def toHexString: String = buffer.entries().toIterator.flatMap(_.lastOption).map(n => f"$n%02x").mkString
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.scalajs.nodejs.child_process

import io.scalajs.JsNumber
import io.scalajs.nodejs.{GID, UID}

import scala.scalajs.js
import scala.scalajs.js.|
Expand Down Expand Up @@ -35,10 +35,10 @@ class ExecFileSyncOptions(val cwd: js.UndefOr[String] = js.undefined,
val env: js.UndefOr[js.Object] = js.undefined,
val encoding: js.UndefOr[String] = js.undefined,
val shell: js.UndefOr[Boolean | String] = js.undefined,
val timeout: js.UndefOr[JsNumber] = js.undefined,
val maxBuffer: js.UndefOr[JsNumber] = js.undefined,
val timeout: js.UndefOr[Int] = js.undefined,
val maxBuffer: js.UndefOr[Int] = js.undefined,
val killSignal: js.UndefOr[KillSignal] = js.undefined,
val uid: js.UndefOr[JsNumber] = js.undefined,
val gid: js.UndefOr[JsNumber] = js.undefined,
val uid: js.UndefOr[UID] = js.undefined,
val gid: js.UndefOr[GID] = js.undefined,
val windowsHide: js.UndefOr[Boolean] = js.undefined)
extends js.Object
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package io.scalajs.nodejs
package child_process

import io.scalajs.JsNumber

import scala.scalajs.js
import scala.scalajs.js.|

Expand Down Expand Up @@ -31,11 +29,11 @@ class ExecOptions(val cwd: js.UndefOr[String] = js.undefined,
val env: js.UndefOr[js.Object] = js.undefined,
val encoding: js.UndefOr[String] = js.undefined,
val shell: js.UndefOr[Boolean | String] = js.undefined,
val timeout: js.UndefOr[JsNumber] = js.undefined,
val maxBuffer: js.UndefOr[JsNumber] = js.undefined,
val timeout: js.UndefOr[Int] = js.undefined,
val maxBuffer: js.UndefOr[Int] = js.undefined,
val killSignal: js.UndefOr[KillSignal] = js.undefined,
val uid: js.UndefOr[JsNumber] = js.undefined,
val gid: js.UndefOr[JsNumber] = js.undefined,
val uid: js.UndefOr[UID] = js.undefined,
val gid: js.UndefOr[GID] = js.undefined,
val windowsHide: js.UndefOr[Boolean] = js.undefined,
val windowsVerbatimArguments: js.UndefOr[Boolean] = js.undefined)
extends js.Object
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package io.scalajs.nodejs
package child_process

import io.scalajs.JsNumber

import scala.scalajs.js
import scala.scalajs.js.|

Expand Down Expand Up @@ -30,6 +28,6 @@ class ForkOptions(val cwd: js.UndefOr[String] = js.undefined,
val execArgv: js.UndefOr[Array[String]] = js.undefined,
val silent: js.UndefOr[Boolean] = js.undefined,
val stdio: js.UndefOr[String | Array[String]] = js.undefined,
val uid: js.UndefOr[JsNumber] = js.undefined,
val gid: js.UndefOr[JsNumber] = js.undefined)
val uid: js.UndefOr[UID] = js.undefined,
val gid: js.UndefOr[GID] = js.undefined)
extends js.Object
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.scalajs.nodejs.child_process

import io.scalajs.JsNumber
import io.scalajs.nodejs.{GID, UID}

import scala.scalajs.js
import scala.scalajs.js.|
Expand Down Expand Up @@ -40,11 +40,11 @@ class SpawnSyncOptions(val cwd: js.UndefOr[String] = js.undefined,
val env: js.UndefOr[js.Object] = js.undefined,
val encoding: js.UndefOr[String] = js.undefined,
val shell: js.UndefOr[Boolean | String] = js.undefined,
val timeout: js.UndefOr[JsNumber] = js.undefined,
val maxBuffer: js.UndefOr[JsNumber] = js.undefined,
val timeout: js.UndefOr[Int] = js.undefined,
val maxBuffer: js.UndefOr[Int] = js.undefined,
val killSignal: js.UndefOr[KillSignal] = js.undefined,
val uid: js.UndefOr[JsNumber] = js.undefined,
val gid: js.UndefOr[JsNumber] = js.undefined,
val uid: js.UndefOr[UID] = js.undefined,
val gid: js.UndefOr[GID] = js.undefined,
val windowsHide: js.UndefOr[Boolean] = js.undefined,
val windowsVerbatimArguments: js.UndefOr[Boolean] = js.undefined)
extends js.Object
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.scalajs.nodejs.cluster

import com.thoughtworks.enableIf
import io.scalajs.JsNumber
import io.scalajs.nodejs.{GID, UID}

import scala.scalajs.js
Expand Down Expand Up @@ -33,7 +32,7 @@ trait ClusterSettings extends js.Object {

var stdio: js.Array[js.Any] = js.native

var inspectPort: JsNumber | js.Function = js.native
var inspectPort: Int | js.Function = js.native

@enableIf(io.scalajs.nodejs.CompilerSwitches.gteNodeJs10)
var cwd: String = js.native
Expand All @@ -51,7 +50,7 @@ object ClusterSettings {
args: js.Array[String] = null,
silent: Boolean = false,
stdio: js.Array[js.Any] = null,
inspectPort: JsNumber | js.Function = null,
inspectPort: Int | js.Function = null,
cwd: String = null,
windowsHide: Boolean = false): ClusterSettings = {
val settings = js.Dynamic.literal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class BufferTest extends FunSpec {
val buf = Buffer.from("Hello!")
val it = buf.entries()
assert(
it.toSeq.map(_.toSeq) === Seq(
it.toIterator.toSeq.map(_.toSeq) === Seq(
Seq(0, 72),
Seq(1, 101),
Seq(2, 108),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.scalajs.nodejs.cluster

import io.scalajs.nodejs.setTimeout
import io.scalajs.util.DurationHelper._
import org.scalatest.FunSpec

import scala.concurrent.duration._
Expand Down Expand Up @@ -51,7 +50,7 @@ class ClusterTest extends FunSpec {
setTimeout(() => {
info(s"Shutting down worker ${worker.id}...")
worker.disconnect()
}, 0.5.seconds)
}, 0.5.seconds.toMillis.toInt)
}

Cluster.onExit((worker, code, signal) => info(s"worker ${worker.process.pid} died"))
Expand Down
5 changes: 4 additions & 1 deletion core/src/main/scala/io/scalajs/JSON.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ trait JSON extends js.Object {
* before being returned.
* @return The Object corresponding to the given JSON text.
*/
@deprecated("Use scala.scalajs.js.JSON instead", "0.9.0")
def parse(text: String, reviver: js.Function = js.native): js.Any = js.native

/**
Expand All @@ -39,13 +40,15 @@ trait JSON extends js.Object {
* (or is null), no white space is used.
* @return A JSON string representing the given value.
*/
@deprecated("Use scala.scalajs.js.JSON instead", "0.9.0")
def stringify(value: js.Any, replacer: js.Function = js.native, space: String | Int = js.native): String = js.native

}

/**
* JSON Singleton Object
*/
@deprecated("Use scala.scalajs.js.JSON instead", "0.9.0")
@js.native
@JSGlobal("JSON")
object JSON extends JSON
object JSON extends JSON {}
5 changes: 5 additions & 0 deletions core/src/main/scala/io/scalajs/collection/Iterator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import scala.scalajs.js
* with a default iteration behavior, such as Array or Map, while other types (such as Object) are not.
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols
*/
@deprecated("Use scala.scalajs.js.Iterator", "0.9.0")
@js.native
trait Iterator[+A] extends js.Object {

Expand All @@ -26,17 +27,20 @@ trait Iterator[+A] extends js.Object {
/**
* Iterator Companion
*/
@deprecated("Use scala.scalajs.js.Iterator", "0.9.0")
object Iterator {

/**
* Implicit conversion for a js.Iterator to Scala Iterator
* @param jsIt the given JavaScript [[Iterator]]
*/
@deprecated("Use scala.scalajs.js.Iterator", "0.9.0")
implicit def toIterator[T](jsIt: Iterator[T]): scala.Iterator[T] = new IteratorWrapper[T](jsIt)

/**
* Iterator Entry
*/
@deprecated("Use scala.scalajs.js.Iterator", "0.9.0")
@js.native
trait Entry[+A] extends js.Object {

Expand All @@ -59,6 +63,7 @@ object Iterator {
/**
* Iterator Wrapper
*/
@deprecated("Use scala.scalajs.js.Iterator", "0.9.0")
class IteratorWrapper[T](it: Iterator[T]) extends scala.Iterator[T] {
private var result = it.next()

Expand Down
5 changes: 5 additions & 0 deletions core/src/main/scala/io/scalajs/collection/JsCollection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import scala.scalajs.js.annotation.JSBracketAccess
* JavaScript Collection
*/
@js.native
@deprecated("Use methods in js.Array or other js collections", "0.9.0")
trait JsCollection[A] extends js.Object {

/**
Expand All @@ -29,17 +30,20 @@ trait JsCollection[A] extends js.Object {
/**
* JsCollection Companion
*/
@deprecated("Use methods in js.Array or other js collections", "0.9.0")
object JsCollection {

/**
* Implicit conversion for a js.Iterator to Scala Iterator
*/
@deprecated("Use promise.future", "0.9.0")
implicit def toIterator[T](collection: JsCollection[T]): scala.Iterator[T] = new JsCollectionWrapper[T](collection)

/**
* JavaScript Collection Enrichment
* @param collection the given [[JsCollection collection]]
*/
@deprecated("Use methods in js.Array or other js collections", "0.9.0")
implicit final class JsCollectionEnrichment[T](val collection: JsCollection[T]) extends AnyVal {

@inline
Expand All @@ -66,6 +70,7 @@ object JsCollection {
* JsCollection Iterator Wrapper
* @param collection the given [[JsCollection]]
*/
@deprecated("Use methods in js.Array or other js collections", "0.9.0")
class JsCollectionWrapper[T](collection: JsCollection[T]) extends scala.Iterator[T] {
private var pos = 0

Expand Down
10 changes: 8 additions & 2 deletions core/src/main/scala/io/scalajs/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,29 @@ import scala.scalajs.js.|
*/
package object scalajs {

@deprecated("Use js.Any", "0.9.0")
type JsAnything = js.Any // js.Any | js.Object | JsNumber | String | Boolean

@deprecated("Use Double or specific Number sub type", "0.9.0")
type JsNumber = Byte | Double | Float | Int | Long | Short | java.lang.Number

@deprecated("Use specific type", "0.9.0")
type RawOptions = js.Dictionary[_] | js.Object

/**
* JSON Enrichment
* @param json the given [[JSON]] object
*/
@deprecated("Use scala.scalajs.js.JSON and io.scalajs.util.JSONHelper.", "0.9.0")
implicit final class JSONEnrichment(val json: JSON) extends AnyVal {
import io.scalajs.util.JSONHelper._

@inline
def parseAs[T](text: String): T = json.parse(text).asInstanceOf[T]
def parseAs[T](text: String): T = js.JSON.parseAs[T](text)

@inline
def parseAs[T](text: String, reviver: js.Function): T = json.parse(text, reviver).asInstanceOf[T]
def parseAs[T](text: String, reviver: js.Function): T =
js.JSON.parseAs[T](text, reviver.asInstanceOf[js.Function2[js.Any, js.Any, js.Any]])

}

Expand Down
1 change: 1 addition & 0 deletions core/src/main/scala/io/scalajs/util/DurationHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import scala.concurrent.duration._
/**
* Duration Helper
*/
@deprecated("Use scala.concurrent.duration.DurationConversions._ instead.", "0.9.0")
object DurationHelper {

/////////////////////////////////////////////////////////////////////////
Expand Down
17 changes: 12 additions & 5 deletions core/src/main/scala/io/scalajs/util/JSONHelper.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.scalajs.util

import io.scalajs.JSON

import scala.scalajs.js

/**
Expand All @@ -16,10 +14,10 @@ object JSONHelper {
implicit final class JSONConversionsToJson[T <: js.Any](val value: T) extends AnyVal {

@inline
def toJson: String = JSON.stringify(value)
def toJson: String = js.JSON.stringify(value)

@inline
def toPrettyJson: String = JSON.stringify(value, null, 4)
def toPrettyJson: String = js.JSON.stringify(value, null.asInstanceOf[js.Array[js.Any]], 4)

}

Expand All @@ -30,8 +28,17 @@ object JSONHelper {
implicit final class JSONConversionFromJson(val text: String) extends AnyVal {

@inline
def fromJson[T <: js.Any]: T = JSON.parse(text).asInstanceOf[T]
def fromJson[T <: js.Any]: T = js.JSON.parse(text).asInstanceOf[T]

}

implicit final class ScalaJsJSONEnrichment(val json: js.JSON.type) extends AnyVal {
@inline
def parseAs[T](text: String): T =
js.JSON.parse(text).asInstanceOf[T]

@inline
def parseAs[T](text: String, reviver: js.Function2[js.Any, js.Any, js.Any]): T =
js.JSON.parse(text, reviver).asInstanceOf[T]
}
}
Loading