parser->node = NULL;
module = njs_module_find(vm, &name, 0);
- if (module != NULL) {
+ if (module != NULL && module->function.native) {
goto found;
}
goto fail;
}
+ module = njs_module_find(vm, &info.file, 0);
+ if (module != NULL) {
+ (void) close(info.fd);
+ goto found;
+ }
+
ret = njs_module_read(vm, info.fd, &text);
(void) close(info.fd);
if (njs_slow_path(ret != NJS_OK)) {
- njs_internal_error(vm, "while reading \"%V\" module", &name);
+ njs_internal_error(vm, "while reading \"%V\" module", &info.file);
goto fail;
}
if (njs_module_realpath_equal(&prev->file, &info.file)) {
njs_parser_syntax_error(vm, parser, "Cannot import itself \"%V\"",
- &name);
+ &info.file);
goto fail;
}
goto fail;
}
- module = njs_module_add(vm, &name);
+ module = njs_module_add(vm, &info.file);
if (njs_slow_path(module == NULL)) {
goto fail;
}
}
ret = njs_module_relative_path(vm, cwd, info);
- if (ret == NJS_OK) {
+
+ if (ret != NJS_DECLINED) {
return ret;
}
for (i = 0; i < vm->paths->items; i++) {
ret = njs_module_relative_path(vm, path, info);
- if (ret == NJS_OK) {
+
+ if (ret != NJS_DECLINED) {
return ret;
}
return v;
}
+import hashlib from 'hash.js';
import crypto from 'crypto';
var state = {count:0}
return state.count;
}
-export default {hash, inc, get};
+export default {hash, inc, get, name: hashlib.name}
return v;
}
+import name from 'name.js';
import crypto from 'crypto';
-export default {hash};
+export default {hash, name};
--- /dev/null
+export default 'libs.name';
--- /dev/null
+export default 'name';
+import name from 'name.js';
import lib1 from 'lib1.js';
import lib2 from 'lib2.js';
import lib1_2 from 'lib1.js';
var hash = h.update('AB').digest('hex');
var fails = 0;
+
+if (name != 'name') {
+ fails++;
+}
+
+if (lib1.name != 'libs.name') {
+ fails++;
+}
+
if (lib1.hash() != hash) {
fails++;
}
-
-
-import lib from './recursive.js';
+import lib from 'recursive.js';
"passed!"
njs_run {"./test/module/normal.js"} \
- "SyntaxError: Cannot find module \"hash.js\" in sub2.js:5"
+ "SyntaxError: Cannot find module \"hash.js\" in lib1.js:13"
njs_run {"-p" "test/module/libs" "./test/module/exception.js"} \
"at error \\(sub1.js:5\\)"
njs_run {"-p" "test/module" "./test/module/recursive.js"} \
- "SyntaxError: Cannot import itself \"./recursive.js\" in recursive.js:3"
+ "SyntaxError: Cannot import itself \"./test/module/recursive.js\" in recursive.js:1"
# CLI OPTIONS
"Error: loading exception\r\n at module \\(loading_exception.js:1\\)"}
{"import lib3 from 'lib1.js'\r\n"
"undefined\r\n"}
-} "-p test/module/"
+} "-p test/module/ -p test/module/libs/"
njs_test {
{"import m from 'export_name.js'\r\n"
} "-p test/module/"
njs_run {"-q" "./test/module/normal.js"} \
- "SyntaxError: Cannot find module \"hash.js\" in 5"
+ "SyntaxError: Cannot find module \"hash.js\" in 13"
njs_run {"-p" "test/module/libs/" "-d" "./test/module/normal.js"} \
"passed!"