This commit is contained in:
강동윤 2019-02-13 14:24:44 +09:00
parent a13e6a09b5
commit fedfea4e09
7 changed files with 40 additions and 25 deletions

View File

@ -147,8 +147,6 @@ impl<'a, I: Input> Iterator for Lexer<'a, I> {
if self.syntax.jsx() && !self.ctx.in_property_name {
//jsx
if self.state.context.current() == Some(TokenContext::JSXExpr) {
let start = self.cur_pos();
return self.read_jsx_token();
}

View File

@ -568,11 +568,6 @@ fn after_if() {
)
}
#[test]
fn empty() {
assert_eq!(lex(Syntax::default(), ""), vec![]);
}
// #[test]
// #[ignore]
// fn leading_comment() {
@ -904,6 +899,11 @@ fn shebang() {
);
}
#[test]
fn empty() {
assert_eq!(lex_tokens(::Syntax::default(), "",), vec![]);
}
#[bench]
fn lex_colors_js(b: &mut Bencher) {
b.bytes = include_str!("../../colors.js").len() as _;

View File

@ -242,12 +242,12 @@ impl<'a, I: Input> Parser<'a, I> {
// Literals
if {
match *cur!(false)? {
tok!("null")
| tok!("true")
| tok!("false")
| Token::Num(..)
| Token::Str { .. } => true,
match cur!(false) {
Ok(&tok!("null"))
| Ok(&tok!("true"))
| Ok(&tok!("false"))
| Ok(&Token::Num(..))
| Ok(Token::Str { .. }) => true,
_ => false,
}
} {
@ -256,8 +256,8 @@ impl<'a, I: Input> Parser<'a, I> {
// Regexp
if {
match *cur!(false)? {
Token::Regex(..) => true,
match cur!(false) {
Ok(&Token::Regex(..)) => true,
_ => false,
}
} {

View File

@ -371,8 +371,8 @@ impl<'a, I: Input> Parser<'a, I> {
pub(super) fn parse_jsx_text(&mut self) -> PResult<'a, JSXText> {
debug_assert!(self.input.syntax().jsx());
assert!({
match *cur!(false)? {
Token::JSXText { .. } => true,
match cur!(false) {
Ok(&Token::JSXText { .. }) => true,
_ => false,
}
});

View File

@ -78,8 +78,8 @@ impl<'a, I: Input> Parser<'a, I> {
pub fn parse_module(&mut self) -> PResult<'a, Module> {
let start = cur_pos!();
let shebang = self.parse_shebang()?;
//TODO: parse() -> PResult<'a, Program>
let ctx = Context {
module: true,
@ -97,8 +97,8 @@ impl<'a, I: Input> Parser<'a, I> {
}
fn parse_shebang(&mut self) -> PResult<'a, Option<JsWord>> {
match *cur!(false)? {
Token::Shebang(..) => match bump!() {
match cur!(false) {
Ok(&Token::Shebang(..)) => match bump!() {
Token::Shebang(v) => Ok(Some(v)),
_ => unreachable!(),
},

View File

@ -19,7 +19,8 @@ impl<'a, I: Input> Parser<'a, I> {
let mut stmts = vec![];
while {
let b = cur!(false).ok() != end;
let c = cur!(false).ok();
let b = c != end;
b
} {
let stmt = self.parse_stmt_like(true, top_level)?;
@ -1078,4 +1079,20 @@ export default App"#;
);
}
#[test]
fn empty() {
test_parser(
"",
Syntax::Es(EsConfig {
..Default::default()
}),
|p| {
p.parse_module().map_err(|mut e| {
e.emit();
()
})
},
);
}
}

View File

@ -16,8 +16,8 @@ impl<'a, I: Input> Parser<'a, I> {
// Handle import 'mod.js'
let str_start = cur_pos!();
match *cur!(false)? {
Token::Str { .. } => match bump!() {
match cur!(false) {
Ok(&Token::Str { .. }) => match bump!() {
Token::Str { value, has_escape } => {
expect!(';');
return Ok(ModuleDecl::Import(ImportDecl {
@ -89,8 +89,8 @@ impl<'a, I: Input> Parser<'a, I> {
/// Parse `foo`, `foo2 as bar` in `import { foo, foo2 as bar }`
fn parse_import_specifier(&mut self) -> PResult<'a, ImportSpecifier> {
let start = cur_pos!();
match *cur!(false)? {
Word(..) => {
match cur!(false) {
Ok(&Word(..)) => {
let orig_name = self.parse_ident_name()?;
if eat!("as") {