MCPcopy Create free account
hub / github.com/mozilla/rhino / arrowFunction

Method arrowFunction

rhino/src/main/java/org/mozilla/javascript/Parser.java:1118–1195  ·  view source on GitHub ↗
(AstNode params, int startLine, int startColumn)

Source from the content-addressed store, hash-verified

1116 }
1117
1118 private AstNode arrowFunction(AstNode params, int startLine, int startColumn)
1119 throws IOException {
1120 int baseLineno = lineNumber(); // line number where source starts
1121 int functionSourceStart =
1122 params != null ? params.getPosition() : -1; // start of "function" kwd
1123
1124 FunctionNode fnNode = new FunctionNode(functionSourceStart);
1125 fnNode.setFunctionType(FunctionNode.ARROW_FUNCTION);
1126 fnNode.setJsDocNode(getAndResetJsDoc());
1127
1128 // Would prefer not to call createDestructuringAssignment until codegen,
1129 // but the symbol definitions have to happen now, before body is parsed.
1130 Map<String, Node> destructuring = new HashMap<>();
1131 Map<String, AstNode> destructuringDefault = new HashMap<>();
1132 Set<String> paramNames = new HashSet<>();
1133
1134 PerFunctionVariables savedVars = new PerFunctionVariables(fnNode);
1135 // Intentionally not overwriting "insideMethod" - we want to propagate this from the parent
1136 // function or scope
1137 try {
1138 if (params instanceof ParenthesizedExpression) {
1139 fnNode.setParens(0, params.getLength());
1140 if (params.getIntProp(Node.TRAILING_COMMA, 0) == 1) {
1141 fnNode.putIntProp(Node.TRAILING_COMMA, 1);
1142 }
1143 AstNode p = ((ParenthesizedExpression) params).getExpression();
1144 if (!(p instanceof EmptyExpression)) {
1145 arrowFunctionParams(fnNode, p, destructuring, destructuringDefault, paramNames);
1146 }
1147 // shouldn't have trailing comma after rest params
1148 if (fnNode.hasRestParameter() && fnNode.getIntProp(Node.TRAILING_COMMA, 0) == 1) {
1149 reportError("msg.parm.after.rest");
1150 }
1151 } else {
1152 arrowFunctionParams(
1153 fnNode, params, destructuring, destructuringDefault, paramNames);
1154 }
1155
1156 if (!destructuring.isEmpty()) {
1157 Node destructuringNode = new Node(Token.COMMA);
1158 // Add assignment helper for each destructuring parameter
1159 for (Map.Entry<String, Node> param : destructuring.entrySet()) {
1160 AstNode defaultValue = null;
1161 if (destructuringDefault != null) {
1162 defaultValue = destructuringDefault.get(param.getKey());
1163 }
1164 Node assign =
1165 createDestructuringAssignment(
1166 Token.VAR,
1167 param.getValue(),
1168 createName(param.getKey()),
1169 defaultValue);
1170 destructuringNode.addChildToBack(assign);
1171 }
1172 fnNode.putProp(Node.DESTRUCTURING_PARAMS, destructuringNode);
1173 }
1174
1175 AstNode body = parseFunctionBody(FunctionNode.ARROW_FUNCTION, fnNode);

Callers 1

assignExprMethod · 0.95

Calls 15

lineNumberMethod · 0.95
setFunctionTypeMethod · 0.95
getAndResetJsDocMethod · 0.95
setParensMethod · 0.95
arrowFunctionParamsMethod · 0.95
hasRestParameterMethod · 0.95
reportErrorMethod · 0.95
createNameMethod · 0.95
addChildToBackMethod · 0.95
parseFunctionBodyMethod · 0.95
setBodyMethod · 0.95

Tested by

no test coverage detected