Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
feat(rome_js_parser): EcmaScript @decorators #4252
Browse files Browse the repository at this point in the history
  • Loading branch information
denbezrukov committed May 1, 2023
1 parent 0fb680c commit 676af18
Show file tree
Hide file tree
Showing 3 changed files with 2,452 additions and 541 deletions.
35 changes: 25 additions & 10 deletions crates/rome_js_parser/src/syntax/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1723,36 +1723,55 @@ fn parse_modifier(p: &mut JsParser, constructor_parameter: bool) -> Option<Class
// class Foo {
// // properties
// @dec foo = 2;
// @dec @(await dec) @dec() foo = 2;
// @dec public foo = 1;
// @dec @(await dec) @dec() public foo = 1;
// @dec static foo = 2;
// @dec @(await dec) @dec() static foo = 2;
// @dec accessor foo = 2;
// @dec @(await dec) @dec() accessor foo = 2;
// @dec readonly foo = 2;
// @dec @(await dec) @dec() readonly foo = 2;
// @dec override foo = 2;
// @dec @(await dec) @dec() override foo = 2;
// // methods
// @dec foo() {}
// @dec @(await dec) @dec() foo() {}
// @dec public foo() {}
// @dec @(await dec) @dec() public foo() {}
// @dec static foo() {}
// @dec @(await dec) @dec() static foo() {}
// @dec override foo() {}
// @dec @(await dec) @dec() override foo() {}
// // getters
// @dec get foo() {}
// @dec @(await dec) @dec() get foo() {}
// @dec public get foo() {}
// @dec @(await dec) @dec() public get foo() {}
// @dec static get foo() {}
// @dec @(await dec) @dec() static get foo() {}
// @dec override get foo() {}
// @dec @(await dec) @dec() override get foo() {}
// // setters
// @dec set foo(val) {}
// @dec @(await dec) @dec() set foo(val) {}
// @dec public set foo(val) {}
// @dec @(await dec) @dec() public set foo(val) {}
// @dec static set foo(val) {}
// @dec @(await dec) @dec() static set foo(val) {}
// @dec override set foo(val) {}
// @dec @(await dec) @dec() override set foo(val) {}
// }

// SAFETY: Guaranteed to succeed because the parser is at @ token.
// SAFETY: Success is guaranteed since the parser is at the @ token.
// The function takes care of handling any potential syntax errors.
let decorator = parse_decorator(p).unwrap();

let range = decorator.range(p);

Some(ClassMemberModifier {
start: range.start(),
length: u32::from(range.len()) as u8,
length: range.len(),
kind: modifier_kind,
})
}
Expand All @@ -1764,7 +1783,7 @@ fn parse_modifier(p: &mut JsParser, constructor_parameter: bool) -> Option<Class

Some(ClassMemberModifier {
start: range.start(),
length: u32::from(range.len()) as u8,
length: range.len(),
kind: modifier_kind,
})
}
Expand Down Expand Up @@ -1866,17 +1885,13 @@ struct ClassMemberModifier {
// The start position of the modifier in the source text
start: TextSize,

// The length of the modifier text. Storage optimization because none of the modifiers exceeds
// a length of 128 (even if encoded)
length: u8,
// The length of the modifier text.
length: TextSize,
}

impl ClassMemberModifier {
fn as_text_range(&self) -> TextRange {
TextRange::new(
self.start,
self.start.add(TextSize::from(self.length as u32)),
)
TextRange::new(self.start, self.start.add(self.length))
}
}

Expand Down
Loading

0 comments on commit 676af18

Please sign in to comment.