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);
}
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();
}
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;
}
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"));
}
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);
}
Aggregations