use of com.google.javascript.rhino.StaticScope in project closure-compiler by google.
the class SymbolTable method createScopeFrom.
/**
* Given a scope from another symbol table, returns the {@code SymbolScope} rooted at the same
* node. Creates one if it doesn't exist yet.
*/
private SymbolScope createScopeFrom(StaticScope otherScope) {
Node otherScopeRoot = otherScope.getRootNode();
SymbolScope myScope = scopes.get(otherScopeRoot);
if (myScope == null) {
StaticScope otherScopeParent = otherScope.getParentScope();
if (otherScopeParent == null) {
// The global scope must be created before any local scopes.
checkState(globalScope == null, "Global scopes found at different roots");
}
myScope = new SymbolScope(otherScopeRoot, otherScopeParent == null ? null : createScopeFrom(otherScopeParent), getTypeOfThis(otherScope), null);
scopes.put(otherScopeRoot, myScope);
if (myScope.isGlobalScope()) {
globalScope = myScope;
}
}
return myScope;
}
use of com.google.javascript.rhino.StaticScope in project closure-compiler by google.
the class RewriteAsyncIteration method create.
static RewriteAsyncIteration create(AbstractCompiler compiler) {
AstFactory astFactory = compiler.createAstFactory();
StaticScope namespace = compiler.getTranspilationNamespace();
return new RewriteAsyncIteration(compiler, astFactory, namespace);
}
use of com.google.javascript.rhino.StaticScope in project closure-compiler by google.
the class AstFactoryTest method testCreateQNameFromBaseNamePlusStringIterable.
@Test
public void testCreateQNameFromBaseNamePlusStringIterable() {
AstFactory astFactory = createTestAstFactory();
parseAndAddTypes(lines(//
"", "const obj = {", " inner: {", " str: 'hi',", " }", "};", ""));
StaticScope scope = compiler.getTranspilationNamespace();
Node objDotInnerDotStr = astFactory.createQName(scope, "obj", ImmutableList.of("inner", "str"));
assertNode(objDotInnerDotStr).matchesQualifiedName("obj.inner.str");
Node objDotInner = objDotInnerDotStr.getFirstChild();
Node obj = objDotInner.getFirstChild();
assertNode(obj).hasJSTypeThat().toStringIsEqualTo("{inner: {str: string}}");
assertNode(objDotInner).hasJSTypeThat().toStringIsEqualTo("{str: string}");
assertNode(objDotInnerDotStr).hasJSTypeThat().isString();
}
use of com.google.javascript.rhino.StaticScope in project closure-compiler by google.
the class AstFactoryTest method testCreateStaticMethodCallDotCallThrows.
@Test
public void testCreateStaticMethodCallDotCallThrows() {
// NOTE: This method is testing both createCall() and createQName()
AstFactory astFactory = createTestAstFactory();
parseAndAddTypes(lines("class Foo {", " /**", " * @param {string} arg1", " * @param {number} arg2", " * @return {string}", " */", " static method(arg1, arg2) { return arg1; }", "}"));
StaticScope scope = compiler.getTranspilationNamespace();
// createQName only accepts globally qualified qnames. While Foo.method is a global qualified
// name, its '.call' property is not.
// Foo.method.call(null, "hi", 2112)
assertThrows(Exception.class, () -> astFactory.createQName(scope, "Foo.method.call"));
}
use of com.google.javascript.rhino.StaticScope in project closure-compiler by google.
the class JSTypeRegistry method getTypeInternal.
private JSType getTypeInternal(StaticScope scope, String name) {
checkTypeName(name);
if (scope instanceof SyntheticTemplateScope) {
TemplateType type = ((SyntheticTemplateScope) scope).getTemplateType(name);
if (type != null) {
return type;
}
}
StaticScope declarationScope = getLookupScope(scope, name);
JSType resolvedViaTable = getTypeForScopeInternal(declarationScope, name);
if (resolvedViaTable != null) {
return resolvedViaTable;
}
StaticScope bestScope = declarationScope != null ? declarationScope : scope;
return resolveViaComponents(bestScope, name);
}
Aggregations