private String debugInfo(Node node) { StringBuilder sb = new StringBuilder(); if (node instanceof FunctionNode) { FunctionNode fn = (FunctionNode)node; sb.append("FunctionNode name: ").append(fn.getName()); sb.append(", Ident: ").append(fn.getIdent()); if (fn.allVarsInScope()) sb.append(", allVarsInScope"); if (fn.isAnonymous()) sb.append(", isAnonymous"); if (fn.isDeclared()) sb.append(", isDeclared"); if (fn.isMethod()) sb.append(", isMethod"); if (fn.isNamedFunctionExpression()) sb.append(", isNamedFunctionExpression"); if (fn.isVarArg()) sb.append(", isVarArg"); if (fn.hasDeclaredFunctions()) sb.append(", hasDeclaredFunctions"); if (fn.hasDirectSuper()) sb.append(", hasDirectSuper"); // if (fn.hasScopeBlock()) sb.append(", hasScoprBlock"); } else if (node instanceof VarNode) { VarNode vn = (VarNode)node; sb.append("VarNode ").append(vn.getName()); if (vn.isBlockScoped()) sb.append(", isBlockScoped"); if (vn.isConst()) sb.append(", isConst"); if (vn.isFunctionDeclaration()) sb.append(", isFunctionDeclaration"); if (vn.isLet()) sb.append(", isLet"); } else { sb.append(node.getClass().getName()); } return sb.toString(); }
public String getFunctionName(FunctionNode node) { if (node.isAnonymous() ) { return globalObject.getName() + node.getName().replace(':', '#'); } else { if (node.isNamedFunctionExpression()) { return node.getName(); } return node.getIdent().getName(); } } }
private void handleDeclaredFunction(DeclarationScopeImpl inScope, JsObject parent, FunctionNode fnNode) { LOGGER.log(Level.FINEST, " function: " + debugInfo(fnNode)); // NOI18N String name = fnNode.isAnonymous() ? modelBuilder.getFunctionName(fnNode) : fnNode.getIdent().getName(); Identifier fnName = new Identifier(name, new OffsetRange(fnNode.getIdent().getStart(), fnNode.getIdent().getFinish())); if (fnNode.isClassConstructor() && !ModelUtils.CONSTRUCTOR.equals(fnName.getName())) { // skip artifical/ syntetic constructor nodes, that are created // when a class extends different class return; } // process parameters List<Identifier> parameters = new ArrayList(fnNode.getParameters().size()); for(IdentNode node: fnNode.getParameters()) { Identifier param = create(parserResult, node); if (param != null && !node.isDestructuredParameter()) { // can be null, if it's a generated embeding. parameters.add(param); } } // The parent can be changed in the later processing JsFunctionImpl declaredFn = new JsFunctionImpl(inScope, parent, fnName, parameters, getOffsetRange(fnNode), inScope.getMimeType(), inScope.getSourceLabel()); inScope.addProperty(modelBuilder.getFunctionName(fnNode), declaredFn); if (fnName.getOffsetRange().getLength() > 0 && !fnNode.isNamedFunctionExpression()) { declaredFn.addOccurrence(fnName.getOffsetRange()); } }
} else if (lastVisited instanceof VarNode) { VarNode varNode = (VarNode)lastVisited; if (fn.isNamedFunctionExpression()) { parent = jsObject.getParent(); if (fn.isNamedFunctionExpression()) { if (fn.isNamedFunctionExpression() && fn.getName().equals(varName.getName())) {
if (!varNode.isFunctionDeclaration() // we skip syntetic variables created from case: function f1(){} if (init instanceof FunctionNode && !((FunctionNode) init).isNamedFunctionExpression()) {