Performs static checks, including resolution of identifiers in expr in the environment defined by module. Syntax must be resolved before it is evaluated. @param expr resolved and mutated by this method: Identifier nodes get bindings. @param module defines predeclared variabl
(Expression expr, Module module, FileOptions options)
| 1422 | * to have consistent behavior for {@link Module#resolve}. |
| 1423 | */ |
| 1424 | public static Function resolveExpr(Expression expr, Module module, FileOptions options) |
| 1425 | throws SyntaxError.Exception { |
| 1426 | List<SyntaxError> errors = new ArrayList<>(); |
| 1427 | Resolver r = new Resolver(errors, module, options, /* docCommentsMap= */ null); |
| 1428 | |
| 1429 | ArrayList<Binding> frame = new ArrayList<>(); |
| 1430 | r.pushLocalBlock(null, frame, /*freevars=*/ null); // for bindings in list comprehensions |
| 1431 | r.visit(expr); |
| 1432 | r.popLocalBlock(); |
| 1433 | |
| 1434 | if (!errors.isEmpty()) { |
| 1435 | throw new SyntaxError.Exception(errors); |
| 1436 | } |
| 1437 | |
| 1438 | // Return no-arg function that computes the expression. |
| 1439 | return new Function( |
| 1440 | "<expr>", |
| 1441 | expr.getStartLocation(), |
| 1442 | /* params= */ ImmutableList.of(), |
| 1443 | /* functionType= */ NO_PARAMS_CALLABLE, |
| 1444 | ImmutableList.of(ReturnStatement.make(expr)), |
| 1445 | /* hasVarargs= */ false, |
| 1446 | /* hasKwargs= */ false, |
| 1447 | /* numKeywordOnlyParams= */ 0, |
| 1448 | frame, |
| 1449 | /* freevars= */ ImmutableList.of(), |
| 1450 | r.globals); |
| 1451 | } |
| 1452 | |
| 1453 | private void pushLocalBlock( |
| 1454 | Node syntax, ArrayList<Binding> frame, @Nullable ArrayList<Binding> freevars) { |
no test coverage detected