Java Code Examples for com.google.javascript.rhino.Node#isFromExterns()

The following examples show how to use com.google.javascript.rhino.Node#isFromExterns() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BuildSymbolTablePass.java    From js-dossier with Apache License 2.0 6 votes vote down vote up
@Override
public void process(DossierCompiler compiler, Node root) {
  if (root.isFromExterns() || nodeLibrary.isModulePath(root.getSourceFileName())) {
    return;
  }
  checkArgument(root.isScript(), "process called with non-script node: %s", root);

  Module.Builder module = scanModule(root);
  SymbolTable table = module == null ? globalSymbolTable : module.getInternalSymbolTable();
  scan(module, table, root);

  if (module != null) {
    Module m = module.build();
    globalSymbolTable.add(m);
    typeRegistry.addModule(m);
  }
}
 
Example 2
Source File: Closure_48_TypedScopeCreator_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Defines a variable based on the {@link Token#NAME} node passed.
 * @param name The {@link Token#NAME} node.
 * @param var The parent of the {@code name} node, which must be a
 *     {@link Token#VAR} node.
 * @param parent {@code var}'s parent.
 * @param info the {@link JSDocInfo} information relating to this
 *     {@code name} node.
 */
private void defineName(Node name, Node var, Node parent, JSDocInfo info) {
  Node value = name.getFirstChild();

  // variable's type
  JSType type = getDeclaredType(sourceName, info, name, value);
  if (type == null) {
    // The variable's type will be inferred.
    type = name.isFromExterns() ?
        getNativeType(UNKNOWN_TYPE) : null;
  }
  defineSlot(name, var, type);
}
 
Example 3
Source File: TypedScopeCreator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Defines a variable based on the {@link Token#NAME} node passed.
 * @param name The {@link Token#NAME} node.
 * @param var The parent of the {@code name} node, which must be a
 *     {@link Token#VAR} node.
 * @param info the {@link JSDocInfo} information relating to this
 *     {@code name} node.
 */
private void defineName(Node name, Node var, JSDocInfo info) {
  Node value = name.getFirstChild();

  // variable's type
  JSType type = getDeclaredType(sourceName, info, name, value);
  if (type == null) {
    // The variable's type will be inferred.
    type = name.isFromExterns() ? unknownType : null;
  }
  defineSlot(name, var, type);
}
 
Example 4
Source File: Closure_54_TypedScopeCreator_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Defines a variable based on the {@link Token#NAME} node passed.
 * @param name The {@link Token#NAME} node.
 * @param var The parent of the {@code name} node, which must be a
 *     {@link Token#VAR} node.
 * @param parent {@code var}'s parent.
 * @param info the {@link JSDocInfo} information relating to this
 *     {@code name} node.
 */
private void defineName(Node name, Node var, Node parent, JSDocInfo info) {
  Node value = name.getFirstChild();

  // variable's type
  JSType type = getDeclaredType(sourceName, info, name, value);
  if (type == null) {
    // The variable's type will be inferred.
    type = name.isFromExterns() ?
        getNativeType(UNKNOWN_TYPE) : null;
  }
  defineSlot(name, var, type);
}
 
Example 5
Source File: Closure_54_TypedScopeCreator_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Defines a variable based on the {@link Token#NAME} node passed.
 * @param name The {@link Token#NAME} node.
 * @param var The parent of the {@code name} node, which must be a
 *     {@link Token#VAR} node.
 * @param parent {@code var}'s parent.
 * @param info the {@link JSDocInfo} information relating to this
 *     {@code name} node.
 */
private void defineName(Node name, Node var, Node parent, JSDocInfo info) {
  Node value = name.getFirstChild();

  // variable's type
  JSType type = getDeclaredType(sourceName, info, name, value);
  if (type == null) {
    // The variable's type will be inferred.
    type = name.isFromExterns() ?
        getNativeType(UNKNOWN_TYPE) : null;
  }
  defineSlot(name, var, type);
}
 
Example 6
Source File: Closure_43_TypedScopeCreator_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Defines a variable based on the {@link Token#NAME} node passed.
 * @param name The {@link Token#NAME} node.
 * @param var The parent of the {@code name} node, which must be a
 *     {@link Token#VAR} node.
 * @param parent {@code var}'s parent.
 * @param info the {@link JSDocInfo} information relating to this
 *     {@code name} node.
 */
private void defineName(Node name, Node var, Node parent, JSDocInfo info) {
  Node value = name.getFirstChild();

  // variable's type
  JSType type = getDeclaredType(sourceName, info, name, value);
  if (type == null) {
    // The variable's type will be inferred.
    type = name.isFromExterns() ?
        getNativeType(UNKNOWN_TYPE) : null;
  }
  defineSlot(name, var, type);
}
 
Example 7
Source File: Closure_43_TypedScopeCreator_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Defines a variable based on the {@link Token#NAME} node passed.
 * @param name The {@link Token#NAME} node.
 * @param var The parent of the {@code name} node, which must be a
 *     {@link Token#VAR} node.
 * @param parent {@code var}'s parent.
 * @param info the {@link JSDocInfo} information relating to this
 *     {@code name} node.
 */
private void defineName(Node name, Node var, Node parent, JSDocInfo info) {
  Node value = name.getFirstChild();

  // variable's type
  JSType type = getDeclaredType(sourceName, info, name, value);
  if (type == null) {
    // The variable's type will be inferred.
    type = name.isFromExterns() ?
        getNativeType(UNKNOWN_TYPE) : null;
  }
  defineSlot(name, var, type);
}
 
Example 8
Source File: Closure_48_TypedScopeCreator_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Defines a variable based on the {@link Token#NAME} node passed.
 * @param name The {@link Token#NAME} node.
 * @param var The parent of the {@code name} node, which must be a
 *     {@link Token#VAR} node.
 * @param parent {@code var}'s parent.
 * @param info the {@link JSDocInfo} information relating to this
 *     {@code name} node.
 */
private void defineName(Node name, Node var, Node parent, JSDocInfo info) {
  Node value = name.getFirstChild();

  // variable's type
  JSType type = getDeclaredType(sourceName, info, name, value);
  if (type == null) {
    // The variable's type will be inferred.
    type = name.isFromExterns() ?
        getNativeType(UNKNOWN_TYPE) : null;
  }
  defineSlot(name, var, type);
}
 
Example 9
Source File: Closure_17_TypedScopeCreator_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Defines a variable based on the {@link Token#NAME} node passed.
 * @param name The {@link Token#NAME} node.
 * @param var The parent of the {@code name} node, which must be a
 *     {@link Token#VAR} node.
 * @param parent {@code var}'s parent.
 * @param info the {@link JSDocInfo} information relating to this
 *     {@code name} node.
 */
private void defineName(Node name, Node var, Node parent, JSDocInfo info) {
  Node value = name.getFirstChild();

  // variable's type
  JSType type = getDeclaredType(sourceName, info, name, value);
  if (type == null) {
    // The variable's type will be inferred.
    type = name.isFromExterns() ?
        getNativeType(UNKNOWN_TYPE) : null;
  }
  defineSlot(name, var, type);
}
 
Example 10
Source File: LinkFactory.java    From js-dossier with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a link to the rendered source file for the given node, relative to this factory's
 * current context.
 */
public SourceLink createSourceLink(Node node) {
  if (node == null || node.isFromExterns()) {
    return SourceLink.newBuilder().setPath(SafeUrls.toProto(SafeUrls.fromConstant(""))).build();
  }
  Path sourcePath = dfs.getSourcePath(node);
  return createSourceLink(sourcePath, Position.of(node.getLineno(), 0));
}
 
Example 11
Source File: NodeModulePass.java    From js-dossier with Apache License 2.0 5 votes vote down vote up
@Override
public void process(DossierCompiler compiler, Node root) {
  if (root.isFromExterns()) {
    return;
  }

  CommonJsModuleCallback callback = new CommonJsModuleCallback();
  traverse(compiler, root, callback);
}
 
Example 12
Source File: Closure_11_TypeCheck_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Visits an object literal field definition <code>key : value</code>.
 *
 * If the <code>lvalue</code> is a prototype modification, we change the
 * schema of the object type it is referring to.
 *
 * @param t the traversal
 * @param key the assign node
 */
private void visitObjLitKey(NodeTraversal t, Node key, Node objlit) {
  // Do not validate object lit value types in externs. We don't really care,
  // and it makes it easier to generate externs.
  if (objlit.isFromExterns()) {
    ensureTyped(t, key);
    return;
  }

  // TODO(johnlenz): Validate get and set function declarations are valid
  // as is the functions can have "extraneous" bits.

  // For getter and setter property definitions the
  // r-value type != the property type.
  Node rvalue = key.getFirstChild();
  JSType rightType = NodeUtil.getObjectLitKeyTypeFromValueType(
      key, getJSType(rvalue));
  if (rightType == null) {
    rightType = getNativeType(UNKNOWN_TYPE);
  }

  Node owner = objlit;

  // Validate value is assignable to the key type.

  JSType keyType = getJSType(key);

  JSType allowedValueType = keyType;
  if (allowedValueType.isEnumElementType()) {
    allowedValueType =
        allowedValueType.toMaybeEnumElementType().getPrimitiveType();
  }

  boolean valid = validator.expectCanAssignToPropertyOf(t, key,
      rightType, allowedValueType,
      owner, NodeUtil.getObjectLitKeyName(key));
  if (valid) {
    ensureTyped(t, key, rightType);
  } else {
    ensureTyped(t, key);
  }

  // Validate that the key type is assignable to the object property type.
  // This is necessary as the objlit may have been cast to a non-literal
  // object type.
  // TODO(johnlenz): consider introducing a CAST node to the AST (or
  // perhaps a parentheses node).

  JSType objlitType = getJSType(objlit);
  ObjectType type = ObjectType.cast(
      objlitType.restrictByNotNullOrUndefined());
  if (type != null) {
    String property = NodeUtil.getObjectLitKeyName(key);
    if (type.hasProperty(property) &&
        !type.isPropertyTypeInferred(property) &&
        !propertyIsImplicitCast(type, property)) {
      validator.expectCanAssignToPropertyOf(
          t, key, keyType,
          type.getPropertyType(property), owner, property);
    }
    return;
  }
}
 
Example 13
Source File: Closure_11_TypeCheck_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Visits an object literal field definition <code>key : value</code>.
 *
 * If the <code>lvalue</code> is a prototype modification, we change the
 * schema of the object type it is referring to.
 *
 * @param t the traversal
 * @param key the assign node
 */
private void visitObjLitKey(NodeTraversal t, Node key, Node objlit) {
  // Do not validate object lit value types in externs. We don't really care,
  // and it makes it easier to generate externs.
  if (objlit.isFromExterns()) {
    ensureTyped(t, key);
    return;
  }

  // TODO(johnlenz): Validate get and set function declarations are valid
  // as is the functions can have "extraneous" bits.

  // For getter and setter property definitions the
  // r-value type != the property type.
  Node rvalue = key.getFirstChild();
  JSType rightType = NodeUtil.getObjectLitKeyTypeFromValueType(
      key, getJSType(rvalue));
  if (rightType == null) {
    rightType = getNativeType(UNKNOWN_TYPE);
  }

  Node owner = objlit;

  // Validate value is assignable to the key type.

  JSType keyType = getJSType(key);

  JSType allowedValueType = keyType;
  if (allowedValueType.isEnumElementType()) {
    allowedValueType =
        allowedValueType.toMaybeEnumElementType().getPrimitiveType();
  }

  boolean valid = validator.expectCanAssignToPropertyOf(t, key,
      rightType, allowedValueType,
      owner, NodeUtil.getObjectLitKeyName(key));
  if (valid) {
    ensureTyped(t, key, rightType);
  } else {
    ensureTyped(t, key);
  }

  // Validate that the key type is assignable to the object property type.
  // This is necessary as the objlit may have been cast to a non-literal
  // object type.
  // TODO(johnlenz): consider introducing a CAST node to the AST (or
  // perhaps a parentheses node).

  JSType objlitType = getJSType(objlit);
  ObjectType type = ObjectType.cast(
      objlitType.restrictByNotNullOrUndefined());
  if (type != null) {
    String property = NodeUtil.getObjectLitKeyName(key);
    if (type.hasProperty(property) &&
        !type.isPropertyTypeInferred(property) &&
        !propertyIsImplicitCast(type, property)) {
      validator.expectCanAssignToPropertyOf(
          t, key, keyType,
          type.getPropertyType(property), owner, property);
    }
    return;
  }
}
 
Example 14
Source File: ProvidedSymbolPass.java    From js-dossier with Apache License 2.0 4 votes vote down vote up
@Override
public void process(Node ignored, Node root) {
  if (!root.isFromExterns()) {
    scan(root);
  }
}
 
Example 15
Source File: Closure_125_TypeCheck_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Visits an object literal field definition <code>key : value</code>.
 *
 * If the <code>lvalue</code> is a prototype modification, we change the
 * schema of the object type it is referring to.
 *
 * @param t the traversal
 * @param key the assign node
 */
private void visitObjLitKey(
    NodeTraversal t, Node key, Node objlit, JSType litType) {
  // Do not validate object lit value types in externs. We don't really care,
  // and it makes it easier to generate externs.
  if (objlit.isFromExterns()) {
    ensureTyped(t, key);
    return;
  }

  // Structs must have unquoted keys and dicts must have quoted keys
  if (litType.isStruct() && key.isQuotedString()) {
    report(t, key, ILLEGAL_OBJLIT_KEY, "struct");
  } else if (litType.isDict() && !key.isQuotedString()) {
    report(t, key, ILLEGAL_OBJLIT_KEY, "dict");
  }

  // TODO(johnlenz): Validate get and set function declarations are valid
  // as is the functions can have "extraneous" bits.

  // For getter and setter property definitions the
  // r-value type != the property type.
  Node rvalue = key.getFirstChild();
  JSType rightType = NodeUtil.getObjectLitKeyTypeFromValueType(
      key, getJSType(rvalue));
  if (rightType == null) {
    rightType = getNativeType(UNKNOWN_TYPE);
  }

  Node owner = objlit;

  // Validate value is assignable to the key type.

  JSType keyType = getJSType(key);

  JSType allowedValueType = keyType;
  if (allowedValueType.isEnumElementType()) {
    allowedValueType =
        allowedValueType.toMaybeEnumElementType().getPrimitiveType();
  }

  boolean valid = validator.expectCanAssignToPropertyOf(t, key,
      rightType, allowedValueType,
      owner, NodeUtil.getObjectLitKeyName(key));
  if (valid) {
    ensureTyped(t, key, rightType);
  } else {
    ensureTyped(t, key);
  }

  // Validate that the key type is assignable to the object property type.
  // This is necessary as the objlit may have been cast to a non-literal
  // object type.
  // TODO(johnlenz): consider introducing a CAST node to the AST (or
  // perhaps a parentheses node).

  JSType objlitType = getJSType(objlit);
  ObjectType type = ObjectType.cast(
      objlitType.restrictByNotNullOrUndefined());
  if (type != null) {
    String property = NodeUtil.getObjectLitKeyName(key);
    if (type.hasProperty(property) &&
        !type.isPropertyTypeInferred(property) &&
        !propertyIsImplicitCast(type, property)) {
      validator.expectCanAssignToPropertyOf(
          t, key, keyType,
          type.getPropertyType(property), owner, property);
    }
    return;
  }
}
 
Example 16
Source File: Closure_125_TypeCheck_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Visits an object literal field definition <code>key : value</code>.
 *
 * If the <code>lvalue</code> is a prototype modification, we change the
 * schema of the object type it is referring to.
 *
 * @param t the traversal
 * @param key the assign node
 */
private void visitObjLitKey(
    NodeTraversal t, Node key, Node objlit, JSType litType) {
  // Do not validate object lit value types in externs. We don't really care,
  // and it makes it easier to generate externs.
  if (objlit.isFromExterns()) {
    ensureTyped(t, key);
    return;
  }

  // Structs must have unquoted keys and dicts must have quoted keys
  if (litType.isStruct() && key.isQuotedString()) {
    report(t, key, ILLEGAL_OBJLIT_KEY, "struct");
  } else if (litType.isDict() && !key.isQuotedString()) {
    report(t, key, ILLEGAL_OBJLIT_KEY, "dict");
  }

  // TODO(johnlenz): Validate get and set function declarations are valid
  // as is the functions can have "extraneous" bits.

  // For getter and setter property definitions the
  // r-value type != the property type.
  Node rvalue = key.getFirstChild();
  JSType rightType = NodeUtil.getObjectLitKeyTypeFromValueType(
      key, getJSType(rvalue));
  if (rightType == null) {
    rightType = getNativeType(UNKNOWN_TYPE);
  }

  Node owner = objlit;

  // Validate value is assignable to the key type.

  JSType keyType = getJSType(key);

  JSType allowedValueType = keyType;
  if (allowedValueType.isEnumElementType()) {
    allowedValueType =
        allowedValueType.toMaybeEnumElementType().getPrimitiveType();
  }

  boolean valid = validator.expectCanAssignToPropertyOf(t, key,
      rightType, allowedValueType,
      owner, NodeUtil.getObjectLitKeyName(key));
  if (valid) {
    ensureTyped(t, key, rightType);
  } else {
    ensureTyped(t, key);
  }

  // Validate that the key type is assignable to the object property type.
  // This is necessary as the objlit may have been cast to a non-literal
  // object type.
  // TODO(johnlenz): consider introducing a CAST node to the AST (or
  // perhaps a parentheses node).

  JSType objlitType = getJSType(objlit);
  ObjectType type = ObjectType.cast(
      objlitType.restrictByNotNullOrUndefined());
  if (type != null) {
    String property = NodeUtil.getObjectLitKeyName(key);
    if (type.hasProperty(property) &&
        !type.isPropertyTypeInferred(property) &&
        !propertyIsImplicitCast(type, property)) {
      validator.expectCanAssignToPropertyOf(
          t, key, keyType,
          type.getPropertyType(property), owner, property);
    }
    return;
  }
}
 
Example 17
Source File: SymbolTable.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public boolean inExterns() {
  Node n = getDeclarationNode();
  return n == null ? false : n.isFromExterns();
}
 
Example 18
Source File: Closure_2_TypeCheck_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Visits an object literal field definition <code>key : value</code>.
 *
 * If the <code>lvalue</code> is a prototype modification, we change the
 * schema of the object type it is referring to.
 *
 * @param t the traversal
 * @param key the assign node
 */
private void visitObjLitKey(
    NodeTraversal t, Node key, Node objlit, JSType litType) {
  // Do not validate object lit value types in externs. We don't really care,
  // and it makes it easier to generate externs.
  if (objlit.isFromExterns()) {
    ensureTyped(t, key);
    return;
  }

  // Structs must have unquoted keys and dicts must have quoted keys
  if (litType.isStruct() && key.isQuotedString()) {
    report(t, key, ILLEGAL_OBJLIT_KEY, "struct");
  } else if (litType.isDict() && !key.isQuotedString()) {
    report(t, key, ILLEGAL_OBJLIT_KEY, "dict");
  }

  // TODO(johnlenz): Validate get and set function declarations are valid
  // as is the functions can have "extraneous" bits.

  // For getter and setter property definitions the
  // r-value type != the property type.
  Node rvalue = key.getFirstChild();
  JSType rightType = NodeUtil.getObjectLitKeyTypeFromValueType(
      key, getJSType(rvalue));
  if (rightType == null) {
    rightType = getNativeType(UNKNOWN_TYPE);
  }

  Node owner = objlit;

  // Validate value is assignable to the key type.

  JSType keyType = getJSType(key);

  JSType allowedValueType = keyType;
  if (allowedValueType.isEnumElementType()) {
    allowedValueType =
        allowedValueType.toMaybeEnumElementType().getPrimitiveType();
  }

  boolean valid = validator.expectCanAssignToPropertyOf(t, key,
      rightType, allowedValueType,
      owner, NodeUtil.getObjectLitKeyName(key));
  if (valid) {
    ensureTyped(t, key, rightType);
  } else {
    ensureTyped(t, key);
  }

  // Validate that the key type is assignable to the object property type.
  // This is necessary as the objlit may have been cast to a non-literal
  // object type.
  // TODO(johnlenz): consider introducing a CAST node to the AST (or
  // perhaps a parentheses node).

  JSType objlitType = getJSType(objlit);
  ObjectType type = ObjectType.cast(
      objlitType.restrictByNotNullOrUndefined());
  if (type != null) {
    String property = NodeUtil.getObjectLitKeyName(key);
    if (type.hasProperty(property) &&
        !type.isPropertyTypeInferred(property) &&
        !propertyIsImplicitCast(type, property)) {
      validator.expectCanAssignToPropertyOf(
          t, key, keyType,
          type.getPropertyType(property), owner, property);
    }
    return;
  }
}
 
Example 19
Source File: Closure_2_TypeCheck_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Visits an object literal field definition <code>key : value</code>.
 *
 * If the <code>lvalue</code> is a prototype modification, we change the
 * schema of the object type it is referring to.
 *
 * @param t the traversal
 * @param key the assign node
 */
private void visitObjLitKey(
    NodeTraversal t, Node key, Node objlit, JSType litType) {
  // Do not validate object lit value types in externs. We don't really care,
  // and it makes it easier to generate externs.
  if (objlit.isFromExterns()) {
    ensureTyped(t, key);
    return;
  }

  // Structs must have unquoted keys and dicts must have quoted keys
  if (litType.isStruct() && key.isQuotedString()) {
    report(t, key, ILLEGAL_OBJLIT_KEY, "struct");
  } else if (litType.isDict() && !key.isQuotedString()) {
    report(t, key, ILLEGAL_OBJLIT_KEY, "dict");
  }

  // TODO(johnlenz): Validate get and set function declarations are valid
  // as is the functions can have "extraneous" bits.

  // For getter and setter property definitions the
  // r-value type != the property type.
  Node rvalue = key.getFirstChild();
  JSType rightType = NodeUtil.getObjectLitKeyTypeFromValueType(
      key, getJSType(rvalue));
  if (rightType == null) {
    rightType = getNativeType(UNKNOWN_TYPE);
  }

  Node owner = objlit;

  // Validate value is assignable to the key type.

  JSType keyType = getJSType(key);

  JSType allowedValueType = keyType;
  if (allowedValueType.isEnumElementType()) {
    allowedValueType =
        allowedValueType.toMaybeEnumElementType().getPrimitiveType();
  }

  boolean valid = validator.expectCanAssignToPropertyOf(t, key,
      rightType, allowedValueType,
      owner, NodeUtil.getObjectLitKeyName(key));
  if (valid) {
    ensureTyped(t, key, rightType);
  } else {
    ensureTyped(t, key);
  }

  // Validate that the key type is assignable to the object property type.
  // This is necessary as the objlit may have been cast to a non-literal
  // object type.
  // TODO(johnlenz): consider introducing a CAST node to the AST (or
  // perhaps a parentheses node).

  JSType objlitType = getJSType(objlit);
  ObjectType type = ObjectType.cast(
      objlitType.restrictByNotNullOrUndefined());
  if (type != null) {
    String property = NodeUtil.getObjectLitKeyName(key);
    if (type.hasProperty(property) &&
        !type.isPropertyTypeInferred(property) &&
        !propertyIsImplicitCast(type, property)) {
      validator.expectCanAssignToPropertyOf(
          t, key, keyType,
          type.getPropertyType(property), owner, property);
    }
    return;
  }
}
 
Example 20
Source File: TypedScopeCreator.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
private void finishConstructorDefinition(
    Node n, String variableName, FunctionType fnType,
    Scope scopeToDeclareIn, CompilerInput input, Var newVar) {
  // Declare var.prototype in the scope chain.
  FunctionType superClassCtor = fnType.getSuperClassConstructor();
  Property prototypeSlot = fnType.getSlot("prototype");

  // When we declare the function prototype implicitly, we
  // want to make sure that the function and its prototype
  // are declared at the same node. We also want to make sure
  // that the if a symbol has both a Var and a JSType, they have
  // the same node.
  //
  // This consistency is helpful to users of SymbolTable,
  // because everything gets declared at the same place.
  prototypeSlot.setNode(n);

  String prototypeName = variableName + ".prototype";

  // There are some rare cases where the prototype will already
  // be declared. See TypedScopeCreatorTest#testBogusPrototypeInit.
  // Fortunately, other warnings will complain if this happens.
  Var prototypeVar = scopeToDeclareIn.getVar(prototypeName);
  if (prototypeVar != null && prototypeVar.scope == scopeToDeclareIn) {
    scopeToDeclareIn.undeclare(prototypeVar);
  }

  scopeToDeclareIn.declare(prototypeName,
      n, prototypeSlot.getType(), input,
      /* declared iff there's an explicit supertype */
      superClassCtor == null ||
      superClassCtor.getInstanceType().isEquivalentTo(
          getNativeType(OBJECT_TYPE)));

  // Make sure the variable is initialized to something if
  // it constructs itself.
  if (newVar.getInitialValue() == null &&
      !n.isFromExterns()) {
    compiler.report(
        JSError.make(sourceName, n,
            fnType.isConstructor() ?
            CTOR_INITIALIZER : IFACE_INITIALIZER,
            variableName));
  }
}