Skip to content

Commit

Permalink
fix(es/parser): Report errors for multiple import/export specifiers w…
Browse files Browse the repository at this point in the history
…ithout comma (#2302)
  • Loading branch information
g-plane authored Sep 25, 2021
1 parent 83d88ce commit 83153a0
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 17 deletions.
26 changes: 12 additions & 14 deletions ecmascript/parser/src/parser/stmt/module_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,14 @@ impl<'a, I: Tokens> Parser<I> {
local,
}));
} else if eat!(self, '{') {
let mut first = true;
while !eof!(self) && !is!(self, '}') {
if first {
first = false;
} else if eat!(self, ',') && is!(self, '}') {
specifiers.push(self.parse_import_specifier()?);

if is!(self, '}') {
break;
} else {
expect!(self, ',');
}

specifiers.push(self.parse_import_specifier()?);
}
expect!(self, '}');
}
Expand Down Expand Up @@ -513,18 +512,17 @@ impl<'a, I: Tokens> Parser<I> {
exported: default,
}))
}
let mut first = true;
while is_one_of!(self, ',', IdentName) {
if first {
first = false;
} else if eat!(self, ',') && is!(self, '}') {
break;
}

while !eof!(self) && !is!(self, '}') {
specifiers.push(
self.parse_named_export_specifier()
.map(ExportSpecifier::Named)?,
);

if is!(self, '}') {
break;
} else {
expect!(self, ',');
}
}
expect!(self, '}');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
error: Unexpected token `a`. Expected a string literal
--> $DIR/tests/test262-parser/fail/26c0710a6449872a.module.js:1:20
error: Expected ,, got b
--> $DIR/tests/test262-parser/fail/26c0710a6449872a.module.js:1:12
|
1 | export {as b} from a
| ^
| ^

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { a b c }
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
error: Expected ,, got b
--> $DIR/tests/typescript-errors/multiple-specifiers/export/input.ts:1:12
|
1 | export { a b c }
| ^

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import { a b c } from 'mod'
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
error: Expected ,, got b
--> $DIR/tests/typescript-errors/multiple-specifiers/import/input.ts:1:12
|
1 | import { a b c } from 'mod'
| ^

0 comments on commit 83153a0

Please sign in to comment.