Skip to content

Commit 4362b73

Browse files
authoredMar 17, 2025
Add qjsc -C flag to compile as classic script (#978)
Add -C as the complementary to the -m flag to qjsc that compiles the input as an ES module. Add -C as a shorthand alias for --script to qjs and harmonize the qjs and qjsc help messages. Capital C because -c is already taken.
1 parent bfc9e3c commit 4362b73

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed
 

‎qjs.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,8 @@ void help(void)
382382
"-h --help list options\n"
383383
"-e --eval EXPR evaluate EXPR\n"
384384
"-i --interactive go to interactive mode\n"
385-
"-m --module load as ES6 module (default=autodetect)\n"
386-
" --script load as ES6 script (default=autodetect)\n"
385+
"-C --script load as JS classic script (default=autodetect)\n"
386+
"-m --module load as ES module (default=autodetect)\n"
387387
"-I --include file include an additional file\n"
388388
" --std make 'std', 'os' and 'bjson' available to script\n"
389389
"-T --trace trace memory allocation\n"
@@ -498,7 +498,7 @@ int main(int argc, char **argv)
498498
module = 1;
499499
continue;
500500
}
501-
if (!strcmp(longopt, "script")) {
501+
if (opt == 'C' || !strcmp(longopt, "script")) {
502502
module = 0;
503503
continue;
504504
}

‎qjsc.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,8 @@ void help(void)
347347
"-o output set the output filename\n"
348348
"-n script_name set the script name (as used in stack traces)\n"
349349
"-N cname set the C name of the generated data\n"
350-
"-m compile as Javascript module (default=autodetect)\n"
350+
"-C compile as JS classic script (default=autodetect)\n"
351+
"-m compile as ES module (default=autodetect)\n"
351352
"-D module_name compile a dynamically loaded module or worker\n"
352353
"-M module_name[,cname] add initialization code for an external C module\n"
353354
"-p prefix set the prefix of the generated C names\n"
@@ -390,7 +391,7 @@ int main(int argc, char **argv)
390391
namelist_add(&cmodule_list, "bjson", "bjson", 0);
391392

392393
for(;;) {
393-
c = getopt(argc, argv, "ho:N:mn:bxesvM:p:S:D:");
394+
c = getopt(argc, argv, "ho:N:Cmn:bxesvM:p:S:D:");
394395
if (c == -1)
395396
break;
396397
switch(c) {
@@ -411,6 +412,9 @@ int main(int argc, char **argv)
411412
case 'N':
412413
cname = optarg;
413414
break;
415+
case 'C':
416+
module = 0;
417+
break;
414418
case 'm':
415419
module = 1;
416420
break;

0 commit comments

Comments
 (0)