Search in sources :

Example 1 with StaticScope

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;
}
Also used : Node(com.google.javascript.rhino.Node) StaticScope(com.google.javascript.rhino.StaticScope)

Example 2 with StaticScope

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);
}
Also used : StaticScope(com.google.javascript.rhino.StaticScope)

Example 3 with StaticScope

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();
}
Also used : StaticScope(com.google.javascript.rhino.StaticScope) Node(com.google.javascript.rhino.Node) NodeSubject.assertNode(com.google.javascript.rhino.testing.NodeSubject.assertNode) Test(org.junit.Test)

Example 4 with StaticScope

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"));
}
Also used : StaticScope(com.google.javascript.rhino.StaticScope) Test(org.junit.Test)

Example 5 with StaticScope

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);
}
Also used : StaticScope(com.google.javascript.rhino.StaticScope)

Aggregations

StaticScope (com.google.javascript.rhino.StaticScope)11 Node (com.google.javascript.rhino.Node)4 Test (org.junit.Test)4 StaticSlot (com.google.javascript.rhino.StaticSlot)2 NodeSubject.assertNode (com.google.javascript.rhino.testing.NodeSubject.assertNode)2 ImmutableList (com.google.common.collect.ImmutableList)1 QualifiedName (com.google.javascript.rhino.QualifiedName)1