JS: fix issues with js() usage in inline functions
This commit is contained in:
@@ -20,11 +20,12 @@ import com.google.dart.compiler.backend.js.ast.*
|
||||
|
||||
import java.util.Stack
|
||||
|
||||
class ScopeContext(private val rootScope: JsScope) {
|
||||
class ScopeContext(scope: JsScope) {
|
||||
private val rootScope = sequence(scope) { it.getParent() }.first { it is JsRootScope }
|
||||
private val scopes = Stack<JsScope>();
|
||||
|
||||
{
|
||||
scopes.push(rootScope)
|
||||
init {
|
||||
scopes.push(scope)
|
||||
}
|
||||
|
||||
fun enterFunction(): JsFunction {
|
||||
|
||||
@@ -27,14 +27,17 @@ import java.util.*
|
||||
|
||||
private val FAKE_SOURCE_INFO = SourceInfoImpl(null, 0, 0, 0, 0)
|
||||
|
||||
public fun parse(code: String, reporter: ErrorReporter, insideFunction: Boolean): List<JsStatement> =
|
||||
parse(code, 0, reporter, insideFunction, Parser::parse).toJsAst(JsAstMapper::mapStatements)
|
||||
public fun parse(code: String, reporter: ErrorReporter, scope: JsScope): List<JsStatement> {
|
||||
val insideFunction = scope is JsFunctionScope
|
||||
val node = parse(code, 0, reporter, insideFunction, Parser::parse)
|
||||
return node.toJsAst(scope, JsAstMapper::mapStatements)
|
||||
}
|
||||
|
||||
public fun parseFunction(code: String, offset: Int, reporter: ErrorReporter): JsFunction =
|
||||
public fun parseFunction(code: String, offset: Int, reporter: ErrorReporter, scope: JsScope): JsFunction =
|
||||
parse(code, offset, reporter, insideFunction = false) {
|
||||
addObserver(FunctionParsingObserver())
|
||||
primaryExpr(it)
|
||||
}.toJsAst(JsAstMapper::mapFunction)
|
||||
}.toJsAst(scope, JsAstMapper::mapFunction)
|
||||
|
||||
private class FunctionParsingObserver : Observer {
|
||||
var functionsStarted = 0
|
||||
@@ -74,15 +77,11 @@ private fun parse(
|
||||
}
|
||||
|
||||
inline
|
||||
private fun Node.toJsAst<T>(mapAction: JsAstMapper.(Node)->T): T =
|
||||
JsAstMapper(RootScope()).mapAction(this)
|
||||
private fun Node.toJsAst<T>(scope: JsScope, mapAction: JsAstMapper.(Node)->T): T =
|
||||
JsAstMapper(scope).mapAction(this)
|
||||
|
||||
private fun StringReader(string: String, offset: Int): Reader {
|
||||
val reader = StringReader(string)
|
||||
reader.skip(offset.toLong())
|
||||
return reader
|
||||
}
|
||||
|
||||
private fun RootScope(): JsScope {
|
||||
return JsRootScope(JsProgram("<parser>"))
|
||||
}
|
||||
Reference in New Issue
Block a user