Skip to content

Commit e5004da

Browse files
dsherretkdy1
authored andcommitted
- Spans of class members and classes should include decorators. (#581)
- spans of class members and classes should include decorators. - fix hi position for class parameter properties. - fix span of members with accessibility.
1 parent b7b7fda commit e5004da

File tree

12 files changed

+509
-59
lines changed

12 files changed

+509
-59
lines changed

ecmascript/parser/src/parser/class_and_fn.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,8 @@ impl<'a, I: Tokens> Parser<'a, I> {
295295
}
296296

297297
fn parse_class_member(&mut self) -> PResult<'a, ClassMember> {
298-
let decorators = self.parse_decorators(false)?;
299-
300298
let start = cur_pos!();
299+
let decorators = self.parse_decorators(false)?;
301300

302301
if eat!("declare") {
303302
self.emit_err(self.input.prev_span(), SyntaxError::TS1031);
@@ -364,19 +363,18 @@ impl<'a, I: Tokens> Parser<'a, I> {
364363
}
365364
}
366365

367-
self.parse_class_member_with_is_static(accessibility, static_token, decorators)
366+
self.parse_class_member_with_is_static(start, accessibility, static_token, decorators)
368367
}
369368

370369
#[allow(clippy::cognitive_complexity)]
371370
fn parse_class_member_with_is_static(
372371
&mut self,
372+
start: BytePos,
373373
accessibility: Option<Accessibility>,
374374
static_token: Option<Span>,
375375
decorators: Vec<Decorator>,
376376
) -> PResult<'a, ClassMember> {
377377
let is_static = static_token.is_some();
378-
let start = static_token.map(|s| s.lo()).unwrap_or(cur_pos!());
379-
380378
let modifier = self.parse_ts_modifier(&["abstract", "readonly"])?;
381379
let (is_abstract, readonly) = match modifier {
382380
Some("abstract") => (true, self.parse_ts_modifier(&["readonly"])?.is_some()),

ecmascript/parser/src/parser/pat.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,9 @@ impl<'a, I: Tokens> Parser<'a, I> {
275275
}
276276

277277
fn parse_constructor_param(&mut self) -> PResult<'a, PatOrTsParamProp> {
278+
let start = cur_pos!();
278279
let decorators = self.parse_decorators(false)?;
279280

280-
let start = cur_pos!();
281281
let (accessibility, readonly) = if self.input.syntax().typescript() {
282282
let accessibility = self.parse_access_modifier()?;
283283
(
@@ -290,16 +290,17 @@ impl<'a, I: Tokens> Parser<'a, I> {
290290
if accessibility == None && !readonly {
291291
self.parse_formal_param().map(PatOrTsParamProp::from)
292292
} else {
293+
let param = match self.parse_formal_param()? {
294+
Pat::Ident(i) => TsParamPropParam::Ident(i),
295+
Pat::Assign(a) => TsParamPropParam::Assign(a),
296+
node => syntax_error!(node.span(), SyntaxError::TsInvalidParamPropPat),
297+
};
293298
Ok(PatOrTsParamProp::TsParamProp(TsParamProp {
294299
span: span!(start),
295300
accessibility,
296301
readonly,
297302
decorators,
298-
param: match self.parse_formal_param()? {
299-
Pat::Ident(i) => TsParamPropParam::Ident(i),
300-
Pat::Assign(a) => TsParamPropParam::Assign(a),
301-
node => syntax_error!(node.span(), SyntaxError::TsInvalidParamPropPat),
302-
},
303+
param,
303304
}))
304305
}
305306
}

ecmascript/parser/src/parser/stmt.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,26 +72,26 @@ impl<'a, I: Tokens> Parser<'a, I> {
7272
Self: StmtLikeParser<'a, Type>,
7373
Type: IsDirective + From<Stmt>,
7474
{
75+
let start = cur_pos!();
7576
let decorators = self.parse_decorators(true)?;
7677

7778
if is_one_of!("import", "export") {
7879
return self.handle_import_export(top_level, decorators);
7980
}
8081

81-
self.parse_stmt_internal(include_decl, top_level, decorators)
82+
self.parse_stmt_internal(start, include_decl, top_level, decorators)
8283
.map(From::from)
8384
}
8485

8586
/// `parseStatementContent`
8687
#[allow(clippy::cognitive_complexity)]
8788
fn parse_stmt_internal(
8889
&mut self,
90+
start: BytePos,
8991
include_decl: bool,
9092
top_level: bool,
9193
decorators: Vec<Decorator>,
9294
) -> PResult<'a, Stmt> {
93-
let start = cur_pos!();
94-
9595
if self.input.syntax().typescript() && is!("const") && peeked_is!("enum") {
9696
assert_and_bump!("const");
9797
let _ = cur!(true)?;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@dec
2+
class C {
3+
constructor(@dec public param: string) {
4+
}
5+
6+
@dec
7+
@dec2
8+
method() {}
9+
10+
@dec
11+
prop;
12+
13+
@dec
14+
get prop2() { return 5; }
15+
16+
@dec
17+
static method() {}
18+
}

0 commit comments

Comments
 (0)