Duplicate function names are disabled.
diff --git a/njs/njs_parser.c b/njs/njs_parser.c
index dce0ef5..20a00d1 100644
--- a/njs/njs_parser.c
+++ b/njs/njs_parser.c
@@ -290,7 +290,6 @@
 static njs_token_t
 njs_parser_function_declaration(njs_vm_t *vm, njs_parser_t *parser)
 {
-    nxt_uint_t         level;
     njs_token_t        token;
     njs_value_t        *value;
     njs_variable_t     *var;
@@ -313,7 +312,7 @@
         return NJS_TOKEN_ILLEGAL;
     }
 
-    var = njs_parser_variable(vm, parser, &level);
+    var = njs_parser_name_alloc(vm, parser);
     if (nxt_slow_path(var == NULL)) {
         return NJS_TOKEN_ERROR;
     }
@@ -2241,6 +2240,7 @@
         "SyntaxError: Invalid Unicode code point \"%.*s\" in %u",
         "SyntaxError: Unterminated RegExp \"%.*s\" in %u",
         "SyntaxError: Invalid RegExp flags \"%.*s\" in %u",
+        "SyntaxError: Duplicate declaration \"%.*s\" in %u",
     };
 
     msg = errors[err];
diff --git a/njs/njs_parser.h b/njs/njs_parser.h
index a40b4ae..359e92f 100644
--- a/njs/njs_parser.h
+++ b/njs/njs_parser.h
@@ -324,6 +324,7 @@
     NJS_PARSER_ERROR_UNICODE,
     NJS_PARSER_ERROR_UNTERMINATED_REGEXP,
     NJS_PARSER_ERROR_REGEXP_FLAGS,
+    NJS_PARSER_ERROR_DUPLICATE_DECLARATION,
 } njs_parser_error_t;
 
 
diff --git a/njs/njs_variable.c b/njs/njs_variable.c
index 7ad8c6b..46c34d8 100644
--- a/njs/njs_variable.c
+++ b/njs/njs_variable.c
@@ -54,6 +54,37 @@
 
 
 njs_variable_t *
+njs_parser_name_alloc(njs_vm_t *vm, njs_parser_t *parser)
+{
+    nxt_int_t           ret;
+    njs_variable_t      *var;
+    nxt_lvlhsh_query_t  lhq;
+
+    var = njs_variable_alloc(vm, parser, &parser->lexer->text);
+    if (nxt_slow_path(var == NULL)) {
+        return NULL;
+    }
+
+    lhq.key_hash = parser->lexer->key_hash;
+    lhq.key = parser->lexer->text;
+    lhq.replace = 0;
+    lhq.value = var;
+    lhq.proto = &njs_variables_hash_proto;
+    lhq.pool = vm->mem_cache_pool;
+
+    ret = nxt_lvlhsh_insert(&parser->variables_hash, &lhq);
+
+    if (nxt_fast_path(ret == NXT_OK)) {
+        return var;
+    }
+
+    (void) njs_parser_error(vm, parser, NJS_PARSER_ERROR_DUPLICATE_DECLARATION);
+
+    return NULL;
+}
+
+
+njs_variable_t *
 njs_parser_variable(njs_vm_t *vm, njs_parser_t *parser, nxt_uint_t *level)
 {
     nxt_int_t           ret;
diff --git a/njs/njs_variable.h b/njs/njs_variable.h
index edb500d..0d02d13 100644
--- a/njs/njs_variable.h
+++ b/njs/njs_variable.h
@@ -26,6 +26,7 @@
 } njs_variable_t;
 
 
+njs_variable_t *njs_parser_name_alloc(njs_vm_t *vm, njs_parser_t *parser);
 njs_variable_t *njs_parser_variable(njs_vm_t *vm, njs_parser_t *parser,
     nxt_uint_t *level);
 njs_value_t *njs_variable_value(njs_parser_t *parser, njs_index_t index);
diff --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c
index ca2f95d..d678e6f 100644
--- a/njs/test/njs_unit_test.c
+++ b/njs/test/njs_unit_test.c
@@ -67,6 +67,15 @@
     { nxt_string("var a = 1; var b; a"),
       nxt_string("1") },
 
+    { nxt_string("function f(){} function f(){}"),
+      nxt_string("SyntaxError: Duplicate declaration \"f\" in 1") },
+
+    { nxt_string("var f = 1; function f() {}"),
+      nxt_string("SyntaxError: Duplicate declaration \"f\" in 1") },
+
+    { nxt_string("function f() {} var f = 1; f"),
+      nxt_string("1") },
+
     /* Numbers. */
 
     { nxt_string("999999999999999999999"),