njs_parser_node_t *node)
{
nxt_int_t ret;
+ njs_index_t index;
njs_vmcode_stop_t *code;
ret = njs_generator(vm, parser, node->right);
code->code.operation = njs_vmcode_return;
code->code.operands = NJS_VMCODE_1OPERAND;
code->code.retval = NJS_VMCODE_NO_RETVAL;
- code->retval = node->right->index;
- node->index = node->right->index;
+
+ if (node->right != NULL) {
+ index = node->right->index;
+
+ } else {
+ index = njs_value_index(vm, parser, &njs_value_void);
+ }
+
+ code->retval = index;
+ node->index = index;
}
return ret;
njs_token_t token;
njs_parser_node_t *node;
- token = njs_parser_token(parser);
- if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
- return token;
- }
-
node = njs_parser_node_alloc(vm);
if (nxt_slow_path(node == NULL)) {
return NJS_TOKEN_ERROR;
}
node->token = NJS_TOKEN_RETURN;
+ parser->node = node;
+ parser->code_size += sizeof(njs_vmcode_stop_t);
- token = njs_parser_expression(vm, parser, token);
+ token = njs_lexer_token(parser->lexer);
if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
return token;
}
- if (parser->node->token == NJS_TOKEN_FUNCTION) {
- /* TODO: test closure */
- }
+ switch (token) {
- node->right = parser->node;
- parser->node = node;
+ case NJS_TOKEN_SEMICOLON:
+ case NJS_TOKEN_LINE_END:
+ return njs_parser_token(parser);
- parser->code_size += sizeof(njs_vmcode_stop_t);
+ case NJS_TOKEN_CLOSE_BRACE:
+ return token;
+
+ default:
+ token = njs_parser_expression(vm, parser, token);
+ if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
+ return token;
+ }
+
+ if (parser->node->token == NJS_TOKEN_FUNCTION) {
+ /* TODO: test closure */
+ }
+
+ node->right = parser->node;
+ parser->node = node;
- if (token != NJS_TOKEN_SEMICOLON) {
return token;
}
-
- return njs_parser_token(parser);
}
{ nxt_string("function f() {} f()"),
nxt_string("undefined") },
+ { nxt_string("function f() {;} f()"),
+ nxt_string("undefined") },
+
+ { nxt_string("function f(){return} f()"),
+ nxt_string("undefined") },
+
+ { nxt_string("function f(){return;} f()"),
+ nxt_string("undefined") },
+
+ { nxt_string("function f(){return\n1} f()"),
+ nxt_string("undefined") },
+
{ nxt_string("function f(a) { return a + 1 } b = f(2)"),
nxt_string("3") },