-
Notifications
You must be signed in to change notification settings - Fork 664
Conversation
Deploying with Cloudflare Pages
|
@@ -0,0 +1,854 @@ | |||
use crate::state::StateGuard; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extracted from decl
. You can review the individual commits if you want to see what I've refactored (quiet a bit)
Test262 comparison coverage results on windows-latest
|
1 similar comment
Test262 comparison coverage results on windows-latest
|
// class bodies are implicitly strict | ||
let mut guard = p.with_state(ParserState { | ||
strict: Some(StrictMode::Class(p.cur_tok().range)), | ||
..p.state.clone() | ||
}); | ||
|
||
let idt = if (guard.at_ts(token_set![T![await], T![yield], T![ident]]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The opt_binding_identifier
already checks (guard.at_ts(token_set![T![await], T![yield], T![ident]])
so we can remove it from here
if guard.at(T![this]) { | ||
let m = guard.start(); | ||
guard.bump_remap(T![ident]); | ||
Some(m.complete(&mut *guard, NAME)) | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I played around with typescript but didn't find a way how to make this
a valid class id. So I decided to remove it
if p.nth_at(offset, T![?]) { | ||
offset += 1; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is_method_class_member
and the other is
helpers already handle this.
@@ -534,97 +537,97 @@ fn class_member_no_semi(p: &mut Parser) -> Option<CompletedMarker> { | |||
None | |||
} | |||
|
|||
fn is_prop(p: &Parser, offset: usize) -> bool { | |||
(p.at(T![?]) && is_prop(p, offset + 1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This must-have recursed forever because p.at(T![?])
doesn't respect the offset
@@ -0,0 +1,39 @@ | |||
use crate::{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, sorry. Don't know why git didn't recognise my renames of the formatter files, maybe because I rebased the commits?
Test262 comparison coverage results on ubuntu-latest
|
Test262 comparison coverage results on windows-latest
|
Test262 comparison coverage results on ubuntu-latest
|
Test262 comparison coverage results on windows-latest
|
Test262 comparison coverage results on ubuntu-latest
|
Test262 comparison coverage results on windows-latest
|
crates/rslint_parser/test_data/inline/ok/getter_class_member.rast
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing major popped into my eye! I am glad that we decoupled the parsing logic of classes into a separate file!
Summary
This PR refactors the AST structures for class declarations and class expressions as defined in #1725.
ClassDecl
/ClassExpr
toJsClassDeclaration
/JsClassExpression
name
toid
JsExtendsClause
that wraps theextends
keyword and the parent classbody
tomembers
and removed theClassBody
nodeConstructor
toJsConstructorClassMember
name
toid
JsConstructorClassMember
sMethod
toJsMethodClassMember
ClassProp
toJsPropertyClassMember
Getter
toJsGetterClassMember
Setter
toJsSetterClassMember
parameter
PrivateProp
and instead introduce aJsPrivatePropertyClassMemberName
type since all members can be private (except constructors)JsEmptyStatement
withJsEmptyMember
(these aren't proper statements)JsComputedObjectMemberName
andJsStaticObjectMemberName
toJsComputedMemberName
andJsLiteralMember
because they can be shared between classes and objectsTsReturnType
toTsTypeAnnotation
so that it can also be used for properties, parameters, etc.This PR also adds a set of new tests for classes to verify the member parsing. I did so because I had to refactor much of the parsing logic to make sense of it (and reduce some repetitive code and fix some parsing issues related to semicolons).
I further extracted the class parsing from the
decl.rs
into its ownclass.rs
. You can see my refactorings if you look at the individual commits.Test Plan
Added new tests, verified that coverage isn't changing.
Disclaimer
I didn't verify if the typescript parsing is working correctly or if the typescript grammar is correct. We need to tackle typescript support separately.