Skip to content

Commit 6dd2ce3

Browse files
committed
Fix JS_DetectModule if the first statement is an await
1 parent 902cc2c commit 6dd2ce3

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

.github/workflows/ci.yml

+3
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ jobs:
218218
build\${{matrix.buildType}}\qjs.exe tests\test_std.js
219219
build\${{matrix.buildType}}\qjs.exe tests\test_worker.js
220220
build\${{matrix.buildType}}\qjs.exe tests\test_queue_microtask.js
221+
build\${{matrix.buildType}}\qjs.exe tests\test_module_detect.js
221222
build\${{matrix.buildType}}\function_source.exe
222223
223224
windows-clang:
@@ -253,6 +254,7 @@ jobs:
253254
build\${{matrix.buildType}}\qjs.exe tests\test_std.js
254255
build\${{matrix.buildType}}\qjs.exe tests\test_worker.js
255256
build\${{matrix.buildType}}\qjs.exe tests\test_queue_microtask.js
257+
build\${{matrix.buildType}}\qjs.exe tests\test_module_detect.js
256258
build\${{matrix.buildType}}\function_source.exe
257259
258260
windows-ninja:
@@ -292,6 +294,7 @@ jobs:
292294
build\qjs.exe tests\test_std.js
293295
build\qjs.exe tests\test_worker.js
294296
build\qjs.exe tests\test_queue_microtask.js
297+
build\qjs.exe tests\test_module_detect.js
295298
build\function_source.exe
296299
297300
windows-mingw:

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ test: $(QJS)
8888
$(QJS) tests/test_std.js
8989
$(QJS) tests/test_worker.js
9090
$(QJS) tests/test_queue_microtask.js
91+
$(QJS) tests/test_module_detect.js
9192

9293
testconv: $(BUILD_DIR)/test_conv
9394
$(BUILD_DIR)/test_conv

quickjs.c

+9-2
Original file line numberDiff line numberDiff line change
@@ -20007,6 +20007,9 @@ static int simple_next_token(const uint8_t **pp, BOOL no_line_terminator)
2000720007
p[2] == 'c' && p[3] == 't' && p[4] == 'i' &&
2000820008
p[5] == 'o' && p[6] == 'n' && !lre_js_is_ident_next(p[7])) {
2000920009
return TOK_FUNCTION;
20010+
} else if (c == 'a' && p[0] == 'w' && p[1] == 'a' &&
20011+
p[2] == 'i' && p[3] == 't' && !lre_js_is_ident_next(p[4])) {
20012+
return TOK_AWAIT;
2001020013
}
2001120014
return TOK_IDENT;
2001220015
}
@@ -20048,8 +20051,11 @@ static void skip_shebang(const uint8_t **pp, const uint8_t *buf_end)
2004820051
/* return true if 'input' contains the source of a module
2004920052
(heuristic). 'input' must be a zero terminated.
2005020053

20051-
Heuristic: skip comments and expect 'import' keyword not followed
20052-
by '(' or '.' or export keyword.
20054+
Heuristic:
20055+
- Skip comments
20056+
- Expect 'import' keyword not followed by '(' or '.'
20057+
- Expect 'export' keyword
20058+
- Expect 'await' keyword
2005320059
*/
2005420060
/* input is pure ASCII or UTF-8 encoded source code */
2005520061
BOOL JS_DetectModule(const char *input, size_t input_len)
@@ -20062,6 +20068,7 @@ BOOL JS_DetectModule(const char *input, size_t input_len)
2006220068
case TOK_IMPORT:
2006320069
tok = simple_next_token(&p, FALSE);
2006420070
return (tok != '.' && tok != '(');
20071+
case TOK_AWAIT:
2006520072
case TOK_EXPORT:
2006620073
return TRUE;
2006720074
default:

tests/test_module_detect.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// This needs to be parsed as a module or will throw SyntaxError.
2+
//
3+
4+
await 0;
5+

0 commit comments

Comments
 (0)