Skip to content

Commit

Permalink
Support require.addon() with no specifier
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperisager committed Nov 1, 2024
1 parent 6fae734 commit 9fb1b40
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lex.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] }],
Expand Down

0 comments on commit 9fb1b40

Please sign in to comment.