case NJS_TOKEN_NUMBER:
case NJS_TOKEN_STRING:
node->index = njs_value_index(vm, &node->u.value, generator->runtime);
-
if (nxt_fast_path(node->index != NJS_INDEX_NONE)) {
return NXT_OK;
}
return njs_generate_name(vm, generator, node);
case NJS_TOKEN_GLOBAL_THIS:
+ if (vm->options.module) {
+ node->index = njs_value_index(vm, &node->u.value,
+ generator->runtime);
+ if (nxt_fast_path(node->index != NJS_INDEX_NONE)) {
+ return NXT_OK;
+ }
+
+ return NXT_ERROR;
+ }
+
+ /* Fall through. */
+
case NJS_TOKEN_NJS:
case NJS_TOKEN_MATH:
case NJS_TOKEN_JSON:
nxt_int_t interactive;
nxt_int_t sandbox;
nxt_int_t quiet;
+ nxt_int_t module;
} njs_opts_t;
vm_options.accumulative = opts.interactive;
vm_options.backtrace = 1;
vm_options.sandbox = opts.sandbox;
+ vm_options.module = opts.module;
vm_options.ops = &njs_console_ops;
vm_options.external = &njs_console;
"Interactive njs shell.\n"
"\n"
"Options:\n"
- " -d print disassembled code.\n"
- " -q disable interactive introduction prompt.\n"
- " -s sandbox mode.\n"
- " -p set path prefix for modules.\n"
- " -v print njs version and exit.\n"
- " <filename> | - run code from a file or stdin.\n";
+ " -d print disassembled code.\n"
+ " -q disable interactive introduction prompt.\n"
+ " -s sandbox mode.\n"
+ " -t script|module source code type (script is default).\n"
+ " -p set path prefix for modules.\n"
+ " -v print njs version and exit.\n"
+ " <filename> | - run code from a file or stdin.\n";
ret = NXT_DONE;
opts->sandbox = 1;
break;
+ case 't':
+ if (++i < argc) {
+ if (strcmp(argv[i], "module") == 0) {
+ opts->module = 1;
+
+ } else if (strcmp(argv[i], "script") != 0) {
+ nxt_error("option \"-t\" unexpected source type: %s\n",
+ argv[i]);
+ return NXT_ERROR;
+ }
+
+ break;
+ }
+
+ nxt_error("option \"-t\" requires source type\n");
+ return NXT_ERROR;
+
case 'p':
- if (argv[++i] != NULL) {
+ if (++i < argc) {
opts->n_paths++;
paths = realloc(opts->paths, opts->n_paths * sizeof(char *));
if (paths == NULL) {