@Override public boolean enterIndexNode(IndexNode indexNode) { indexNode.getBase().accept(this); return false; }
@Override public Node leaveObjectNode(ObjectNode objectNode) { Node lastVisited = getPreviousFromPath(2); if (lastVisited instanceof BinaryNode) { BinaryNode bNode = (BinaryNode)lastVisited; if (bNode.lhs().equals(objectNode)) { // case of destructuring assignment { a, b} = .... // we dob't create object in the model, but process the property nodes -> skip reseting modelBuilder return super.leaveObjectNode(objectNode); } } modelBuilder.reset(); return super.leaveObjectNode(objectNode); }
@Override public Node leaveUnaryNode(UnaryNode uNode) { if (Token.descType(uNode.getToken()) == TokenType.NEW) { int size = exp.size(); if (size > 1 && ST_CALL.equals(exp.get(size - 2))) { exp.remove(size - 2); } typeOffset = uNode.getExpression().getStart(); if (exp.size() > 0) { exp.add(exp.size() - 1, ST_NEW); } else { exp.add(ST_NEW); } } return super.leaveUnaryNode(uNode); }
@Override public boolean enterWithNode(WithNode withNode) { JsObjectImpl currentObject = modelBuilder.getCurrentObject(); Collection<TypeUsage> types = ModelUtils.resolveSemiTypeOfExpression(modelBuilder, withNode.getExpression()); JsWithObjectImpl withObject = new JsWithObjectImpl(currentObject, modelBuilder.getUnigueNameForWithObject(), types, new OffsetRange(withNode.getStart(), withNode.getFinish()), new OffsetRange(withNode.getExpression().getStart(), withNode.getExpression().getFinish()), modelBuilder.getCurrentWith(), parserResult.getSnapshot().getMimeType(), null); currentObject.addProperty(withObject.getName(), withObject); // withNode.getExpression().accept(this); // expression should be visted when the with object is the current object. modelBuilder.setCurrentObject(withObject); withNode.getBody().accept(this); modelBuilder.reset(); return false; }
if (lastNode instanceof BinaryNode) { BinaryNode bNode = (BinaryNode)lastNode; if (bNode.lhs().equals(accessNode)) { object = (JsObjectImpl) variable; if (lastVisited instanceof BinaryNode) { BinaryNode bNode = (BinaryNode)lastVisited; onLeftSite = bNode.tokenType() == TokenType.ASSIGN && bNode.lhs().equals(accessNode); int propertyOffsetStart = accessNode.getBase().getFinish() + 1; int propertyOffsetEnd = propertyOffsetStart + propertyName.length(); if (property != null) {
createVariable = false; if (parentFn.getProperty(varNode.getName().getName()) == null) { while (bNode.rhs() instanceof BinaryNode && bNode.rhs().isAssignment()) {
JsObjectImpl property = (JsObjectImpl)parent.getProperty(index); if (property != null) { property.addOccurrence(new OffsetRange(indexNode.getIndex().getStart(), indexNode.getIndex().getFinish())); } else { Identifier name = ModelElementFactory.create(parserResult, (LiteralNode)indexNode.getIndex());
@Override public boolean enterCallNode(CallNode callNode) { callNode.getFunction().accept(this); return false; }
private boolean canBeSingletonPattern(int pathIndex) { return (getPath().size() > pathIndex + 3 && getPreviousFromPath(pathIndex) instanceof FunctionNode && getPreviousFromPath(pathIndex + 1) instanceof CallNode && ((CallNode)getPreviousFromPath(pathIndex + 1)).getFunction().equals(getPreviousFromPath(pathIndex)) && getPreviousFromPath(pathIndex + 2) instanceof UnaryNode && (getPreviousFromPath(pathIndex + 3) instanceof BinaryNode || getPreviousFromPath(pathIndex + 3) instanceof VarNode)); }
functionCalls.put(interceptor, calls); int callOffset = callNode.getFunction().getStart(); if (callNode.getFunction() instanceof AccessNode) { AccessNode anode = (AccessNode)callNode.getFunction();
@Override public boolean enterAccessNode(AccessNode accessNode) { if (typeOffset == -1) { typeOffset = accessNode.getFinish() - accessNode.getProperty().length(); } accessNode.getBase().accept(this); exp.add(accessNode.getProperty()); return false; }
JoinPredecessorExpression trueExpression = tNode.getTrueExpression(); JoinPredecessorExpression falseExpression = tNode.getFalseExpression(); if (trueExpression.getExpression().equals(objectNode) || falseExpression.getExpression().equals(objectNode)) { if (bNode.lhs().equals(objectNode)) { } else if (bNode.lhs() instanceof ObjectNode && bNode.rhs().equals(objectNode)) {
variable.addAssignment(new TypeUsage(SemiTypeResolverVisitor.ST_NEW + variable.getName() + '.' + jsFunction.getName(), jsFunction.getDeclarationName().getOffsetRange().getStart()), init.getStart());
@Override public boolean enterIndexNode(IndexNode indexNode) { addToPath(indexNode); indexNode.getBase().accept(this); int size = exp.size(); if (size > 1 && ST_PRO.equals(exp.get(size - 2))) { exp.remove(size - 2); } if (exp.isEmpty()) { exp.add(ST_ARR); } else { boolean propertyAccess = false; if (indexNode.getIndex() instanceof LiteralNode) { LiteralNode lNode = (LiteralNode)indexNode.getIndex(); if (lNode.isString()) { exp.add(ST_PRO); exp.add(lNode.getPropertyName()); propertyAccess = true; } } if (!propertyAccess) { exp.add(exp.size() - 1, ST_ARR); } } //add(exp, indexNode.getStart(), false); //reset(); return false; }
@Override public boolean enterCallNode(CallNode callNode) { addToPath(callNode); if (!(callNode.getFunction() instanceof FunctionNode)) { callNode.getFunction().accept(this); } if (exp.size() == 2 && ST_NEW.equals(exp.get(0))) { return false; } if (callNode.getFunction() instanceof AccessNode) { int size = exp.size(); if (size > 1 && ST_PRO.equals(exp.get(size - 2))) { exp.remove(size - 2); } } else if (callNode.getFunction() instanceof FunctionNode) { FunctionNode function = (FunctionNode) callNode.getFunction(); String name = builder.getFunctionName(function); // String name = function.getIdent().getName(); add(new TypeUsage(ST_CALL + name, function.getStart(), false)); return false; } if (exp.isEmpty()) { exp.add(ST_CALL); } else { exp.add(exp.size() - 1, ST_CALL); } return false; }
expression.accept(this); removeFromPathTheLast();