mirror of
https://github.com/swc-project/swc.git
synced 2024-11-28 02:29:04 +03:00
Fix async arrow expression and TsIndexSignature param ident spans (#721)
- Fix async arrow expression start. - Fix TsIndexSignature inner ident and type ann spans.
This commit is contained in:
parent
c7b12cd408
commit
b677115702
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "swc_ecma_parser"
|
||||
version = "0.21.4"
|
||||
version = "0.21.5"
|
||||
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
|
||||
license = "Apache-2.0/MIT"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
|
@ -572,7 +572,7 @@ impl<'a, I: Tokens> Parser<'a, I> {
|
||||
) -> PResult<'a, Box<Expr>> {
|
||||
trace_cur!(parse_paren_expr_or_arrow_fn);
|
||||
|
||||
let start = cur_pos!();
|
||||
let expr_start = async_span.map(|x| x.lo()).unwrap_or(cur_pos!());
|
||||
|
||||
// At this point, we can't know if it's parenthesized
|
||||
// expression or head of arrow function.
|
||||
@ -602,7 +602,7 @@ impl<'a, I: Tokens> Parser<'a, I> {
|
||||
let body: BlockStmtOrExpr = p.parse_fn_body(async_span.is_some(), false)?;
|
||||
|
||||
Ok(Some(Box::new(Expr::Arrow(ArrowExpr {
|
||||
span: span!(start),
|
||||
span: span!(expr_start),
|
||||
is_async: async_span.is_some(),
|
||||
is_generator: false,
|
||||
params,
|
||||
@ -625,7 +625,7 @@ impl<'a, I: Tokens> Parser<'a, I> {
|
||||
// we parse arrow function at here, to handle it efficiently.
|
||||
if has_pattern || return_type.is_some() || is!("=>") {
|
||||
if self.input.had_line_break_before_cur() {
|
||||
syntax_error!(span!(start), SyntaxError::LineBreakBeforeArrow);
|
||||
syntax_error!(span!(expr_start), SyntaxError::LineBreakBeforeArrow);
|
||||
}
|
||||
if !can_be_arrow {
|
||||
unexpected!()
|
||||
@ -639,7 +639,7 @@ impl<'a, I: Tokens> Parser<'a, I> {
|
||||
|
||||
let body: BlockStmtOrExpr = self.parse_fn_body(async_span.is_some(), false)?;
|
||||
let arrow_expr = ArrowExpr {
|
||||
span: span!(start),
|
||||
span: span!(expr_start),
|
||||
is_async: async_span.is_some(),
|
||||
is_generator: false,
|
||||
params,
|
||||
@ -695,7 +695,7 @@ impl<'a, I: Tokens> Parser<'a, I> {
|
||||
|
||||
if expr_or_spreads.is_empty() {
|
||||
syntax_error!(
|
||||
Span::new(start, last_pos!(), Default::default()),
|
||||
Span::new(expr_start, last_pos!(), Default::default()),
|
||||
SyntaxError::EmptyParenExpr
|
||||
);
|
||||
}
|
||||
@ -712,7 +712,7 @@ impl<'a, I: Tokens> Parser<'a, I> {
|
||||
ExprOrSpread { expr, .. } => expr,
|
||||
};
|
||||
Ok(Box::new(Expr::Paren(ParenExpr {
|
||||
span: span!(start),
|
||||
span: span!(expr_start),
|
||||
expr,
|
||||
})))
|
||||
} else {
|
||||
@ -740,7 +740,7 @@ impl<'a, I: Tokens> Parser<'a, I> {
|
||||
exprs,
|
||||
}));
|
||||
Ok(Box::new(Expr::Paren(ParenExpr {
|
||||
span: span!(start),
|
||||
span: span!(expr_start),
|
||||
expr: seq_expr,
|
||||
})))
|
||||
}
|
||||
|
@ -1143,7 +1143,7 @@ impl<'a, I: Tokens> Parser<'a, I> {
|
||||
/// `tsTryParseIndexSignature`
|
||||
pub(super) fn try_parse_ts_index_signature(
|
||||
&mut self,
|
||||
start: BytePos,
|
||||
index_signature_start: BytePos,
|
||||
readonly: bool,
|
||||
) -> PResult<'a, Option<TsIndexSignature>> {
|
||||
if !(is!('[') && self.ts_look_ahead(|p| p.is_ts_unambiguously_index_signature())?) {
|
||||
@ -1152,7 +1152,9 @@ impl<'a, I: Tokens> Parser<'a, I> {
|
||||
|
||||
expect!('[');
|
||||
|
||||
let ident_start = cur_pos!();
|
||||
let mut id = self.parse_ident_name()?;
|
||||
let type_ann_start = cur_pos!();
|
||||
|
||||
if eat!(',') {
|
||||
self.emit_err(id.span, SyntaxError::TS1096);
|
||||
@ -1160,10 +1162,10 @@ impl<'a, I: Tokens> Parser<'a, I> {
|
||||
expect!(':');
|
||||
}
|
||||
|
||||
let cur_pos = cur_pos!();
|
||||
id.type_ann = self
|
||||
.parse_ts_type_ann(/* eat_colon */ false, cur_pos)
|
||||
.map(Some)?;
|
||||
let type_ann = self.parse_ts_type_ann(/* eat_colon */ false, type_ann_start)?;
|
||||
id.span = span!(ident_start);
|
||||
id.type_ann = Some(type_ann);
|
||||
|
||||
expect!(']');
|
||||
let params = vec![TsFnParam::Ident(id)];
|
||||
|
||||
@ -1172,7 +1174,7 @@ impl<'a, I: Tokens> Parser<'a, I> {
|
||||
|
||||
self.parse_ts_type_member_semicolon()?;
|
||||
Ok(Some(TsIndexSignature {
|
||||
span: span!(start),
|
||||
span: span!(index_signature_start),
|
||||
readonly,
|
||||
params,
|
||||
type_ann,
|
||||
|
@ -16,7 +16,7 @@
|
||||
"expression": {
|
||||
"type": "ArrowFunctionExpression",
|
||||
"span": {
|
||||
"start": 6,
|
||||
"start": 0,
|
||||
"end": 34,
|
||||
"ctxt": 0
|
||||
},
|
||||
|
@ -16,7 +16,7 @@
|
||||
"expression": {
|
||||
"type": "ArrowFunctionExpression",
|
||||
"span": {
|
||||
"start": 6,
|
||||
"start": 0,
|
||||
"end": 28,
|
||||
"ctxt": 0
|
||||
},
|
||||
|
@ -34,14 +34,14 @@
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 23,
|
||||
"end": 24,
|
||||
"end": 32,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "x",
|
||||
"typeAnnotation": {
|
||||
"type": "TsTypeAnnotation",
|
||||
"span": {
|
||||
"start": 26,
|
||||
"start": 24,
|
||||
"end": 32,
|
||||
"ctxt": 0
|
||||
},
|
||||
|
@ -34,14 +34,14 @@
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 15,
|
||||
"end": 16,
|
||||
"end": 24,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "x",
|
||||
"typeAnnotation": {
|
||||
"type": "TsTypeAnnotation",
|
||||
"span": {
|
||||
"start": 18,
|
||||
"start": 16,
|
||||
"end": 24,
|
||||
"ctxt": 0
|
||||
},
|
||||
@ -89,14 +89,14 @@
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 46,
|
||||
"end": 47,
|
||||
"end": 55,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "x",
|
||||
"typeAnnotation": {
|
||||
"type": "TsTypeAnnotation",
|
||||
"span": {
|
||||
"start": 49,
|
||||
"start": 47,
|
||||
"end": 55,
|
||||
"ctxt": 0
|
||||
},
|
||||
|
@ -30,7 +30,7 @@
|
||||
"expression": {
|
||||
"type": "ArrowFunctionExpression",
|
||||
"span": {
|
||||
"start": 7,
|
||||
"start": 1,
|
||||
"end": 15,
|
||||
"ctxt": 0
|
||||
},
|
||||
|
@ -16,7 +16,7 @@
|
||||
"expression": {
|
||||
"type": "ArrowFunctionExpression",
|
||||
"span": {
|
||||
"start": 6,
|
||||
"start": 0,
|
||||
"end": 14,
|
||||
"ctxt": 0
|
||||
},
|
||||
|
@ -42,14 +42,14 @@
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 19,
|
||||
"end": 20,
|
||||
"end": 28,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "s",
|
||||
"typeAnnotation": {
|
||||
"type": "TsTypeAnnotation",
|
||||
"span": {
|
||||
"start": 22,
|
||||
"start": 20,
|
||||
"end": 28,
|
||||
"ctxt": 0
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user