Skip to content

Commit

Permalink
NODE-2536 Move JsAPI classes into a package (#3784)
Browse files Browse the repository at this point in the history
  • Loading branch information
DrBlast authored Nov 11, 2022
1 parent 4d3650f commit 00ab821
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package com.wavesplatform

import JsApiUtils.*
import com.wavesplatform.DocSource
import com.wavesplatform.lang.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package com.wavesplatform

import com.wavesplatform.lang.contract.DApp
import com.wavesplatform.lang.v1.FunctionHeader.{Native, User}
import com.wavesplatform.lang.v1.compiler.CompilationError
Expand All @@ -14,7 +16,7 @@ import scala.scalajs.js.JSConverters._
object JsApiUtils {

def serPart[T](f: T => js.Any)(part: PART[T]): js.Object = {
val partValue = Expressions.PART.toOption(part).fold(null:Any)(f)
val partValue = Expressions.PART.toOption(part).fold(null: Any)(f)
jObj.applyDynamic("apply")(
"value" -> partValue,
"posStart" -> part.position.start,
Expand Down Expand Up @@ -55,11 +57,11 @@ object JsApiUtils {
}

jObj.applyDynamic("apply")(
"type" -> "DAPP",
"posStart" -> ast.position.start,
"posEnd" -> ast.position.end,
"decList" -> ast.decs.map(serDec).toJSArray,
"annFuncList" -> ast.fs.map(serAnnFunc).toJSArray
"type" -> "DAPP",
"posStart" -> ast.position.start,
"posEnd" -> ast.position.end,
"decList" -> ast.decs.map(serDec).toJSArray,
"annFuncList" -> ast.fs.map(serAnnFunc).toJSArray
)
}

Expand Down Expand Up @@ -146,8 +148,8 @@ object JsApiUtils {

case Expressions.FOLD(_, limit, value, acc, func, _, _) =>
val additionalDataObj = jObj.applyDynamic("apply")(
"name" -> s"FOLD<$limit>",
"args" -> js.Array(serExpr(value), serExpr(acc), func.key.toString: js.Any)
"name" -> s"FOLD<$limit>",
"args" -> js.Array(serExpr(value), serExpr(acc), func.key.toString: js.Any)
)
mergeJSObjects(commonDataObj, additionalDataObj)

Expand All @@ -173,7 +175,9 @@ object JsApiUtils {
}

def serMatchCase(c: Expressions.MATCH_CASE, simpleCtx: Map[String, Pos]): js.Object = {
val vars = c.pattern.subpatterns.collect { case (Expressions.TypedVar(Some(newVarName), caseType), _) => (serPartStr(newVarName), serType(caseType)) }
val vars = c.pattern.subpatterns.collect { case (Expressions.TypedVar(Some(newVarName), caseType), _) =>
(serPartStr(newVarName), serType(caseType))
}
jObj.applyDynamic("apply")(
"type" -> "MATCH_CASE",
"posStart" -> c.position.start,
Expand All @@ -200,7 +204,7 @@ object JsApiUtils {
t match {
case Expressions.AnyType(_) =>
jObj.applyDynamic("apply")(
"typeName" -> "Any"
"typeName" -> "Any"
)
case Expressions.Single(name, parameter) =>
jObj.applyDynamic("apply")(
Expand Down Expand Up @@ -255,21 +259,25 @@ object JsApiUtils {
def toJs(ast: EXPR): js.Object = {
def r(expr: EXPR): js.Object = {
expr match {
case CONST_LONG(t) => jObj.applyDynamic("apply")("type" -> "LONG", "value" -> t.toDouble)
case GETTER(ref, field) => jObj.applyDynamic("apply")("type" -> "GETTER", "ref" -> r(ref), "field" -> field)
case CONST_LONG(t) => jObj.applyDynamic("apply")("type" -> "LONG", "value" -> t.toDouble)
case GETTER(ref, field) => jObj.applyDynamic("apply")("type" -> "GETTER", "ref" -> r(ref), "field" -> field)
case CONST_BYTESTR(bs) => jObj.applyDynamic("apply")("type" -> "BYTESTR", "value" -> bs.arr.toJSArray)
case CONST_STRING(s) => jObj.applyDynamic("apply")("type" -> "STRING", "value" -> s)
case CONST_STRING(s) => jObj.applyDynamic("apply")("type" -> "STRING", "value" -> s)
case LET_BLOCK(let, body) =>
jObj.applyDynamic("apply")("type" -> "BLOCK", "let" -> jObj("name" -> let.name, "value" -> r(let.value)), "body" -> r(body))
case IF(cond, ifTrue, ifFalse) =>
jObj.applyDynamic("apply")("type" -> "IF", "condition" -> r(cond), "true" -> r(ifTrue), "false" -> r(ifFalse))
case REF(key) => jObj.applyDynamic("apply")("type" -> "REF", "key" -> key)
case REF(key) => jObj.applyDynamic("apply")("type" -> "REF", "key" -> key)
case CONST_BOOLEAN(b) => jObj.applyDynamic("apply")("type" -> "BOOL", "value" -> b)
case FUNCTION_CALL(function, args) =>
jObj.applyDynamic("apply")("type" -> "CALL", "name" -> (function match {
case Native(name) => name.toString()
case User(internalName, _) => internalName
}), "args" -> args.map(r).toJSArray)
jObj.applyDynamic("apply")(
"type" -> "CALL",
"name" -> (function match {
case Native(name) => name.toString()
case User(internalName, _) => internalName
}),
"args" -> args.map(r).toJSArray
)
case t => jObj.applyDynamic("apply")("[not_supported]stringRepr" -> t.toString)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package com.wavesplatform

case class DAppComplexities(
complexity: Int,
verifierComplexity: Int,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package com.wavesplatform

import scala.scalajs.js.annotation.JSExportTopLevel
import scala.scalajs.js.typedarray.ArrayBuffer

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package com.wavesplatform

import com.wavesplatform.lang.directives.values.{V5, V6}
import utest.*

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package com.wavesplatform

import com.wavesplatform.lang.directives.values.{StdLibVersion, V6}
import utest.{TestSuite, assert}

Expand Down

0 comments on commit 00ab821

Please sign in to comment.