js.Dynamic.global.require 在 scala 2.12.0 中生成不同的代码
js.Dynamic.global.require generating different code in scala 2.12.0
示例 1:
import scala.scalajs.js.Dynamic.{global => g}
val image1 = g.require("./images/thumbnails/like.png")
scala 2.11.8 - fastOptJS 输出:
this.image1 = require("./images/thumbnails/like.png");
scala 2.12.0 - fastOptJS 输出:
this.image1 = require(($m_sjs_js_Any$(), "./images/thumbnails/like.png"));
示例 2:
import scala.scalajs.js.Dynamic.{global => g}
@inline def load[T](lib: String): T = g.require(lib).asInstanceOf[T]
@inline def loadDynamic(lib: String): js.Dynamic = load[js.Dynamic](lib)
val image2 = loadDynamic("./images/thumbnails/like.png")
scala 2.11.8 - fastOptJS 输出:
this.image2 = require("./images/thumbnails/like.png");
scala 2.12.0 - fastOptJS 输出:
this.image2 = ($m_Lsri_mobile_package$all$(), require(($m_sjs_js_Any$(), "./images/thumbnails/like.png")));
Scala.js 版本:0.6.13
这是一个已知的 Scala.js 优化器效率低下的问题,代码由 2.12 生成。是filed here and it has a pending fix there。请注意,生成的代码仍然正确,尽管效率低下。
示例 1:
import scala.scalajs.js.Dynamic.{global => g}
val image1 = g.require("./images/thumbnails/like.png")
scala 2.11.8 - fastOptJS 输出:
this.image1 = require("./images/thumbnails/like.png");
scala 2.12.0 - fastOptJS 输出:
this.image1 = require(($m_sjs_js_Any$(), "./images/thumbnails/like.png"));
示例 2:
import scala.scalajs.js.Dynamic.{global => g}
@inline def load[T](lib: String): T = g.require(lib).asInstanceOf[T]
@inline def loadDynamic(lib: String): js.Dynamic = load[js.Dynamic](lib)
val image2 = loadDynamic("./images/thumbnails/like.png")
scala 2.11.8 - fastOptJS 输出:
this.image2 = require("./images/thumbnails/like.png");
scala 2.12.0 - fastOptJS 输出:
this.image2 = ($m_Lsri_mobile_package$all$(), require(($m_sjs_js_Any$(), "./images/thumbnails/like.png")));
Scala.js 版本:0.6.13
这是一个已知的 Scala.js 优化器效率低下的问题,代码由 2.12 生成。是filed here and it has a pending fix there。请注意,生成的代码仍然正确,尽管效率低下。