Package com.google.javascript.jscomp.Scope

Examples of com.google.javascript.jscomp.Scope.Var


    }

    JSType type = n.getJSType();
    if (type == null) {
      type = getNativeType(UNKNOWN_TYPE);
      Var var = t.getScope().getVar(n.getString());
      if (var != null) {
        JSType varType = var.getType();
        if (varType != null) {
          type = varType;
        }
      }
    }
View Full Code Here


    // merge to fix this.
    JSDocInfo varInfo = n.hasOneChild() ? n.getJSDocInfo() : null;
    for (Node name : n.children()) {
      Node value = name.getFirstChild();
      // A null var would indicate a bug in the scope creation logic.
      Var var = t.getScope().getVar(name.getString());

      if (value != null) {
        JSType valueType = getJSType(value);
        JSType nameType = var.getType();
        nameType = (nameType == null) ? getNativeType(UNKNOWN_TYPE) : nameType;

        JSDocInfo info = name.getJSDocInfo();
        if (info == null) {
          info = varInfo;
        }

        checkEnumAlias(t, info, value);
        if (var.isTypeInferred()) {
          ensureTyped(t, name, valueType);
        } else {
          validator.expectCanAssignTo(
              t, value, valueType, nameType, "initializing variable");
        }
View Full Code Here

          "module.exports".equals(n.getQualifiedName())) {
        moduleExportRefs.add(n);
      }

      if (n.isName() && EXPORTS.equals(n.getString())) {
        Var v = t.getScope().getVar(n.getString());
        if (v == null || v.isGlobal()) {
          exportRefs.add(n);
        }
      }
    }
View Full Code Here

              .createScope(script, null);
          for (Node key = rhsValue.getFirstChild();
               key != null; key = key.getNext()) {
            if (key.getJSDocInfo() == null
                && key.getFirstChild().isName()) {
              Var aliasedVar =
                  globalScope.getVar(key.getFirstChild().getString());
              JSDocInfo info =
                  aliasedVar == null ? null : aliasedVar.getJSDocInfo();
              if (info != null &&
                  info.getVisibility() != JSDocInfo.Visibility.PRIVATE) {
                key.setJSDocInfo(info);
              }
            }
View Full Code Here

   *     be {@code var}, but in some rare cases we will need to declare
   *     a new var with new source info.
   */
  Var expectUndeclaredVariable(String sourceName, CompilerInput input,
      Node n, Node parent, Var var, String variableName, JSType newType) {
    Var newVar = var;
    boolean allowDupe = false;
    if (n.isGetProp() ||
        NodeUtil.isObjectLitKey(n)) {
      JSDocInfo info = n.getJSDocInfo();
      if (info == null) {
View Full Code Here

        "}", TypeCheck.NOT_A_CONSTRUCTOR);
  }

  public void testNew12() throws Exception {
    TypeCheckResult p = parseAndTypeCheckWithScope("var a = new Array();");
    Var a = p.scope.getVar("a");

    assertTypeEquals(ARRAY_TYPE, a.getType());
  }
View Full Code Here

  public void testNew13() throws Exception {
    TypeCheckResult p = parseAndTypeCheckWithScope(
        "/** @constructor */function FooBar(){};" +
        "var a = new FooBar();");
    Var a = p.scope.getVar("a");

    assertTrue(a.getType() instanceof ObjectType);
    assertEquals("FooBar", a.getType().toString());
  }
View Full Code Here

  public void testNew14() throws Exception {
    TypeCheckResult p = parseAndTypeCheckWithScope(
        "/** @constructor */var FooBar = function(){};" +
        "var a = new FooBar();");
    Var a = p.scope.getVar("a");

    assertTrue(a.getType() instanceof ObjectType);
    assertEquals("FooBar", a.getType().toString());
  }
View Full Code Here

  public void testNew15() throws Exception {
    TypeCheckResult p = parseAndTypeCheckWithScope(
        "var goog = {};" +
        "/** @constructor */goog.A = function(){};" +
        "var a = new goog.A();");
    Var a = p.scope.getVar("a");

    assertTrue(a.getType() instanceof ObjectType);
    assertEquals("goog.A", a.getType().toString());
  }
View Full Code Here

        if (jsScope == t.getScope() || !n.isName()
            || parent.isFunction()) {
          return;
        }
        String name = n.getString();
        Var var = t.getScope().getVar(name);
        if (var != null && var.scope == jsScope) {
          escaped.add(jsScope.getVar(name));
        }
      }
    };

    NodeTraversal t = new NodeTraversal(compiler, finder);
    t.traverseAtScope(jsScope);

    // 1: Remove the exception name in CATCH which technically isn't local to
    //    begin with.
    for (Iterator<Var> i = jsScope.getVars(); i.hasNext();) {
      Var var = i.next();
      if (var.getParentNode().isCatch() ||
          compiler.getCodingConvention().isExported(var.getName())) {
        escaped.add(var);
      }
    }
  }
View Full Code Here

TOP

Related Classes of com.google.javascript.jscomp.Scope.Var

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.