Search in sources :

Example 6 with StaticScope

use of com.google.javascript.rhino.StaticScope in project closure-compiler by google.

the class RewriteAsyncFunctions method create.

static RewriteAsyncFunctions create(AbstractCompiler compiler) {
    AstFactory astFactory = compiler.createAstFactory();
    StaticScope namespace = compiler.getTranspilationNamespace();
    return new RewriteAsyncFunctions(compiler, astFactory, namespace);
}
Also used : StaticScope(com.google.javascript.rhino.StaticScope)

Example 7 with StaticScope

use of com.google.javascript.rhino.StaticScope in project closure-compiler by google.

the class AstFactoryTest method testCreateQNameFromString.

@Test
public void testCreateQNameFromString() {
    AstFactory astFactory = createTestAstFactory();
    parseAndAddTypes(lines(// 
    "", "const obj = {", "  inner: {", "    str: 'hi',", "  }", "};", ""));
    StaticScope scope = compiler.getTranspilationNamespace();
    Node objDotInnerDotStr = astFactory.createQName(scope, "obj.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 8 with StaticScope

use of com.google.javascript.rhino.StaticScope in project closure-compiler by google.

the class NamedType method localVariableShadowsGlobalNamespace.

/**
 * Check for an obscure but very confusing error condition where a local variable shadows a
 * global namespace.
 */
private boolean localVariableShadowsGlobalNamespace(String root) {
    StaticSlot rootVar = resolutionScope.getSlot(root);
    if (rootVar != null) {
        checkNotNull(rootVar.getScope(), rootVar);
        StaticScope parent = rootVar.getScope().getParentScope();
        if (parent != null) {
            StaticSlot globalVar = parent.getSlot(root);
            return globalVar != null;
        }
    }
    return false;
}
Also used : StaticSlot(com.google.javascript.rhino.StaticSlot) StaticScope(com.google.javascript.rhino.StaticScope)

Example 9 with StaticScope

use of com.google.javascript.rhino.StaticScope in project closure-compiler by google.

the class AstFactoryTest method testCreateMethodCall_throws.

@Test
public void testCreateMethodCall_throws() {
    AstFactory astFactory = createTestAstFactory();
    parseAndAddTypes(lines("class Foo {", "  /**", "   * @param {string} arg1", "   * @param {number} arg2", "   * @return {string}", "   */", "  method(arg1, arg2) { return arg1; }", "}", "const foo = new Foo();"));
    StaticScope scope = compiler.getTranspilationNamespace();
    // createQName only accepts globally qualified qnames. foo.method is a prototype method access.
    // foo.method("hi", 2112)
    assertThrows(Exception.class, () -> astFactory.createQName(scope, "foo.method"));
}
Also used : StaticScope(com.google.javascript.rhino.StaticScope) Test(org.junit.Test)

Example 10 with StaticScope

use of com.google.javascript.rhino.StaticScope in project closure-compiler by google.

the class JSTypeRegistry method identifyNonNullableName.

/**
 * Identifies the name of a typedef or enum before we actually declare it.
 */
public void identifyNonNullableName(StaticScope scope, String name) {
    checkNotNull(name);
    StaticScope lookupScope = getLookupScope(scope, name);
    nonNullableTypeNames.put(getRootNodeForScope(lookupScope), 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