Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,20 +773,14 @@ class CJSLexer {
const char* endPos = pos;
ch = commentWhitespace();

// Check if this is a getter syntax: get identifier()
if (ch != ':' && endPos - startPos == 3 && matchesAt(startPos, end, "get")) {
// Skip getter: get identifier() { ... }
if (identifier(ch)) {
ch = commentWhitespace();
if (ch == '(') {
// This is a getter, stop parsing here (early termination)
pos = revertPos;
return;
}
// Check if this is a getter syntax: get identifier() { ... }
if (ch != ':' && endPos - startPos == 3 && matchesAt(startPos, end, "get") && identifier(ch)) {
ch = commentWhitespace();
if (ch == '(') {
// This is a getter, stop parsing here (early termination)
pos = revertPos;
return;
}
// Not a getter, revert and fail
pos = revertPos;
return;
}

if (ch == ':') {
Expand Down
12 changes: 12 additions & 0 deletions tests/real_world_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,18 @@ TEST(real_world_tests, exports_shorthand_syntax) {
SUCCEED();
}

TEST(real_world_tests, exports_shorthand_syntax_get) {
auto result = lexer::parse_commonjs("\
const get = 1, set = 2;\
module.exports = { get, set };\
");
ASSERT_TRUE(result.has_value());
ASSERT_EQ(result->exports.size(), 2);
ASSERT_EQ(lexer::get_string_view(result->exports[0]), "get");
ASSERT_EQ(lexer::get_string_view(result->exports[1]), "set");
SUCCEED();
}

TEST(real_world_tests, line_numbers_lf) {
auto result = lexer::parse_commonjs(
"// line 1\n"
Expand Down
Loading