From 9fb1b40e4bafc7ba6b7a92aeba8eec2db83e5092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Isager=20Dalsgar=C3=B0?= Date: Fri, 1 Nov 2024 20:36:06 +0100 Subject: [PATCH] Support `require.addon()` with no specifier --- lex.h | 12 ++++++++++-- test.js | 7 +++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lex.h b/lex.h index a2f52f0..db048b5 100644 --- a/lex.h +++ b/lex.h @@ -47,7 +47,7 @@ bare_module_lexer__add_position (js_env_t *env, js_value_t *entry, size_t statem static inline int bare_module_lexer__add_import (js_env_t *env, js_value_t *imports, uint32_t *i, const utf8_t *source, size_t import_start, size_t specifier_start, size_t specifier_end, int type, js_value_t *names) { - assert(specifier_end > specifier_start); + assert(specifier_end >= specifier_start); int err; @@ -89,7 +89,7 @@ bare_module_lexer__add_import (js_env_t *env, js_value_t *imports, uint32_t *i, static inline int bare_module_lexer__add_export (js_env_t *env, js_value_t *exports, uint32_t *i, const utf8_t *source, size_t export_start, size_t name_start, size_t name_end) { - assert(name_end > name_start); + assert(name_end >= name_start); int err; @@ -483,6 +483,14 @@ bare_module_lexer__lex (js_env_t *env, js_value_t *imports, js_value_t *exports, } } } + + // require\.addon\(\) + else if (c(0) == ')' && (type & bare_module_lexer_addon)) { + ss = se = i++; + + err = bare_module_lexer__add_import(env, imports, &il, s, is, ss, se, type, names); + if (err < 0) goto err; + } } continue; diff --git a/test.js b/test.js index 2344416..3b8bf0e 100644 --- a/test.js +++ b/test.js @@ -17,6 +17,13 @@ test('require("id")', (t) => { }) }) +test('require.addon()', (t) => { + t.alike(lex('require.addon()'), { + imports: [{ specifier: '', type: REQUIRE | ADDON, names: [], position: [0, 14, 14] }], + exports: [] + }) +}) + test('require.addon(\'id\')', (t) => { t.alike(lex('require.addon(\'./foo.bare\')'), { imports: [{ specifier: './foo.bare', type: REQUIRE | ADDON, names: [], position: [0, 15, 25] }],