Refine search
public String getIdentifier() { return node.getIdentifier(); }
name = createNameNode(true, Token.NAME); if (inUseStrictDirective) { String id = name.getIdentifier(); if ("eval".equals(id)|| "arguments".equals(id)) { reportError("msg.bad.id.strict", id); && name != null && name.length() > 0) { defineSymbol(Token.FUNCTION, name.getIdentifier()); FunctionNode fnNode = new FunctionNode(functionSourceStart, name); fnNode.setFunctionType(type); if (lpPos != -1) fnNode.setLp(lpPos - functionSourceStart); fnNode.setJsDocNode(getAndResetJsDoc()); && !fnNode.getBody().hasConsistentReturnUsage()) { String msg = (name != null && name.length() > 0) ? "msg.no.return.value" : "msg.anon.no.return.value"; addStrictWarning(msg, name == null ? "" : name.getIdentifier());
private Node initFunction(FunctionNode fnNode, int functionIndex, Node statements, int functionType) { fnNode.setFunctionType(functionType); fnNode.addChildToBack(statements); int functionCount = fnNode.getFunctionCount(); if (functionCount != 0) { Name name = fnNode.getFunctionName(); if (name != null && name.length() != 0 && fnNode.getSymbol(name.getIdentifier()) == null) { fnNode.putSymbol(new Symbol(Token.FUNCTION, name.getIdentifier())); Node setFn = new Node(Token.EXPR_VOID, new Node(Token.SETNAME, Node.newString(Token.BINDNAME, name.getIdentifier()), new Node(Token.THISFN))); statements.addChildrenToFront(setFn);
WalkContext child = new FunctionContext(context, fn); List<CAstNode> body = new ArrayList<>(); body.add(visit(fn.getBody(), child)); Name x = fn.getFunctionName(); if (x == null || x.getIdentifier() == null || x.getIdentifier().isEmpty()) { name = scriptName + '@' + fn.getAbsolutePosition(); String label = getParentName(fn); if (label != null) { name = fn.getFunctionName().getIdentifier();
&& nowAllSet(before, endFlags, Node.END_YIELDS|Node.END_RETURNS_VALUE)) { Name name = ((FunctionNode)currentScriptOrFn).getFunctionName(); if (name == null || name.length() == 0) addError("msg.anon.generator.returns", ""); else addError("msg.generator.returns", name.getIdentifier());
@Override public String toSource(int depth) { StringBuilder sb = new StringBuilder(); if (!isMethod()) { sb.append(makeIndent(depth)); sb.append("function"); sb.append(functionName.toSource(0)); } else { sb.append("("); printList(params, sb); sb.append(") ");
/** * Gets a Java-compatible "informative" name for the the ScriptOrFnNode */ String cleanName(final ScriptNode n) { String result = ""; if (n instanceof FunctionNode) { Name name = ((FunctionNode) n).getFunctionName(); if (name == null) { result = "anonymous"; } else { result = name.getIdentifier(); } } else { result = "script"; } return result; }
int paramCount = fn.getParamCount(); if (paramCount>0) { List<AstNode> fnParams = fn.getParams(); for (int i=0; i<paramCount; i++) { String paramName = null; switch (paramNode.getType()) { case Token.NAME: paramName = ((Name)paramNode).getIdentifier(); break; default:
/** * Returns the {@link Scope} in which this {@code Name} is defined. * @return the scope in which this name is defined, or {@code null} * if it's not defined in the current lexical scope chain */ public Scope getDefiningScope() { Scope enclosing = getEnclosingScope(); String name = getIdentifier(); return enclosing == null ? null : enclosing.getDefiningScope(name); }
public static Node newString(int type, String str) { Name name = new Name(); name.setIdentifier(str); name.setType(type); return name; }
varNameNode = (Name)target; varName = varNameNode.getIdentifier(); break; default: func.getBody().visit(this); curScopeTreeNode = (JavaScriptTreeNode)curScopeTreeNode.getParent();
@Override public String toSource(int depth) { StringBuilder sb = new StringBuilder(); sb.append(makeIndent(depth)); sb.append("break"); if (breakLabel != null) { sb.append(" "); sb.append(breakLabel.toSource(0)); } sb.append(";\n"); return sb.toString(); }
private ObjectProperty methodDefinition(int pos, AstNode propName, int entryKind) throws IOException { FunctionNode fn = function(FunctionNode.FUNCTION_EXPRESSION); // We've already parsed the function name, so fn should be anonymous. Name name = fn.getFunctionName(); if (name != null && name.length() != 0) { reportError("msg.bad.prop"); } ObjectProperty pn = new ObjectProperty(pos); switch (entryKind) { case GET_ENTRY: pn.setIsGetterMethod(); fn.setFunctionIsGetterMethod(); break; case SET_ENTRY: pn.setIsSetterMethod(); fn.setFunctionIsSetterMethod(); break; case METHOD_ENTRY: pn.setIsNormalMethod(); fn.setFunctionIsNormalMethod(); break; } int end = getNodeEnd(fn); pn.setLeft(propName); pn.setRight(fn); pn.setLength(end - pos); return pn; }
private ObjectProperty getterSetterProperty(int pos, AstNode propName, boolean isGetter) throws IOException { FunctionNode fn = function(FunctionNode.FUNCTION_EXPRESSION); // We've already parsed the function name, so fn should be anonymous. Name name = fn.getFunctionName(); if (name != null && name.length() != 0) { reportError("msg.bad.prop"); } ObjectProperty pn = new ObjectProperty(pos); if (isGetter) { pn.setIsGetter(); } else { pn.setIsSetter(); } int end = getNodeEnd(fn); pn.setLeft(propName); pn.setRight(fn); pn.setLength(end - pos); return pn; }
private ObjectProperty getterSetterProperty(int pos, AstNode propName, boolean isGetter) throws IOException { FunctionNode fn = function(FunctionNode.FUNCTION_EXPRESSION); // We've already parsed the function name, so fn should be anonymous. Name name = fn.getFunctionName(); if (name != null && name.length() != 0) { reportError("msg.bad.prop"); } ObjectProperty pn = new ObjectProperty(pos); if (isGetter) { pn.setIsGetter(); fn.setFunctionIsGetter(); } else { pn.setIsSetter(); fn.setFunctionIsSetter(); } int end = getNodeEnd(fn); pn.setLeft(propName); pn.setRight(fn); pn.setLength(end - pos); return pn; }
/** * Sets the node's identifier * @throws IllegalArgumentException if identifier is null */ public void setIdentifier(String identifier) { assertNotNull(identifier); this.identifier = identifier; setLength(identifier.length()); }
/** Can only be called when node has String context. */ public Scope getScope() { return ((Name)this).getScope(); }
@Override public String toSource(int depth) { return makeIndent(depth) + (identifier == null ? "<null>" : identifier); }
/** * Return true if this node is known to be defined as a symbol in a * lexical scope other than the top-level (global) scope. * * @return {@code true} if this name appears as local variable, a let-bound * variable not in the global scope, a function parameter, a loop * variable, the property named in a {@link PropertyGet}, or in any other * context where the node is known not to resolve to the global scope. * Returns {@code false} if the node is defined in the top-level scope * (i.e., its defining scope is an {@link AstRoot} object), or if its * name is not defined as a symbol in the symbol table, in which case it * may be an external or built-in name (or just an error of some sort.) */ public boolean isLocalName() { Scope scope = getDefiningScope(); return scope != null && scope.getParentScope() != null; }