Skip to content

Commit

Permalink
Trailing comma in imports
Browse files Browse the repository at this point in the history
  • Loading branch information
lens0021 committed Nov 18, 2024
1 parent 6a08f86 commit f8c2267
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/modules/imports/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,24 @@ impl SyntaxModule<ParserMetadata> for Import {
token(meta, "{")?;
let mut exports = vec![];
loop {
if token(meta, "}").is_ok() {
break;
}
let tok = meta.get_current_token();
let name = variable(meta, variable_name_extensions())?;
let alias = match token(meta, "as") {
Ok(_) => Some(variable(meta, variable_name_extensions())?),
Err(_) => None
};
exports.push((name, alias, tok));
match token(meta, ",") {
Ok(_) => {},
Err(_) => break
if token(meta, "}").is_ok() {
break;
}
if token(meta, ",").is_err() {
return error!(meta, meta.get_current_token(), "Expected ',' or '}' after import");
}
}
self.export_defs = exports;
token(meta, "}")?;
}
}
token(meta, "from")?;
Expand Down
16 changes: 16 additions & 0 deletions src/tests/validity/import_with_trailing_comma.ab
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {
replace,
replace_regex,
} from "std/text"
import {
sum,
abs
} from "std/math"
import {} from "std/env"

// Output
// c0
// 3

echo replace(replace("a1", "a", "c"), "\d", "0")
echo sum([abs(-2), 1])

0 comments on commit f8c2267

Please sign in to comment.