Last active
December 20, 2015 05:29
-
-
Save suzuki0keiichi/6078774 to your computer and use it in GitHub Desktop.
Scala.jsでパターンマッチがどのように変換されるか
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ScalaJS.c.helloworld\ufe33HelloWorld$.prototype.hoge\ufe34O\ufe34V = (function(arg$num) { | |
var rc6$jsid$17007 = false; | |
var x2$jsid$17002 = null; | |
var x1$jsid$17001 = arg$num; | |
var result$$jslabel$matchEnd7$17008; | |
// Someはそのままの機能、if文を並べつつ代入&ラベルでbreak(このbreakの機能初めて知った) | |
$jslabel$matchEnd7$17008: { | |
if (ScalaJS.is.scala\ufe33Some(x1$jsid$17001)) { | |
rc6$jsid$17007 = true; | |
x2$jsid$17002 = ScalaJS.as.scala\ufe33Some(x1$jsid$17001); | |
var hoge$jsid$12146 = x2$jsid$17002.x\ufe34O(); | |
if (ScalaJS.anyEqEq(hoge$jsid$12146, ScalaJS.bI(20))) { | |
result$$jslabel$matchEnd7$17008 = ScalaJS.bI(30); | |
break $jslabel$matchEnd7$17008 | |
} else { | |
/*<skip>*/ | |
} | |
} else { | |
/*<skip>*/ | |
}; | |
if (rc6$jsid$17007) { | |
result$$jslabel$matchEnd7$17008 = ScalaJS.bI(10); | |
break $jslabel$matchEnd7$17008 | |
} else { | |
/*<skip>*/ | |
}; | |
if (ScalaJS.anyRefEqEq(ScalaJS.modules.scala\ufe33None(), x1$jsid$17001)) { | |
result$$jslabel$matchEnd7$17008 = "40"; | |
break $jslabel$matchEnd7$17008 | |
} else { | |
/*<skip>*/ | |
}; | |
// 到達しなかったら例外が飛ぶ | |
throw new ScalaJS.c.scala\ufe33MatchError().init\ufe33\ufe34O(x1$jsid$17001); | |
break $jslabel$matchEnd7$17008 | |
}; | |
var value$jsid$11972 = result$$jslabel$matchEnd7$17008 | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 昔と比べて無駄なelse文がなくなった | |
ScalaJS.c.HelloWorld$.prototype.hoge__O__V = (function(num) { | |
var rc6 = false; | |
var x2 = null; | |
var x1 = num; | |
// Someはそのままの機能、if文を並べつつ代入&ラベルでbreak | |
matchEnd7: { | |
if (ScalaJS.is.scala_Some(x1)) { | |
rc6 = true; | |
x2 = ScalaJS.as.scala_Some(x1); | |
var hoge = x2.x__O(); | |
if (ScalaJS.anyEqEq(hoge, ScalaJS.bI(20))) { | |
var value = ScalaJS.bI(30); | |
break matchEnd7 | |
} | |
}; | |
if (rc6) { | |
var value = ScalaJS.bI(10); | |
break matchEnd7 | |
}; | |
if (ScalaJS.anyRefEqEq(ScalaJS.modules.scala_None(), x1)) { | |
var value = "40"; | |
break matchEnd7 | |
}; | |
// 到達しなかったら例外が飛ぶ | |
throw new ScalaJS.c.scala_MatchError().init___O(x1) | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object HelloWorld { | |
def hoge(num: Any) = { | |
var value = num match { | |
case Some(hoge) if (hoge == 20) => 30 | |
case Some(hoge) => 10 | |
case None => "40" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment