Skip to content

Commit 5f6995a

Browse files
rhendricerikd
authored andcommitted
Add support for classes
1 parent f8bfa31 commit 5f6995a

File tree

10 files changed

+143
-4
lines changed

10 files changed

+143
-4
lines changed

src/Language/JavaScript/Parser/AST.hs

+26
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ module Language.JavaScript.Parser.AST
2525
, JSCommaTrailingList (..)
2626
, JSArrowParameterList (..)
2727
, JSTemplatePart (..)
28+
, JSClassHeritage (..)
29+
, JSClassElement (..)
2830

2931
-- Modules
3032
, JSModuleItem (..)
@@ -128,6 +130,7 @@ data JSStatement
128130
= JSStatementBlock !JSAnnot ![JSStatement] !JSAnnot !JSSemi -- ^lbrace, stmts, rbrace, autosemi
129131
| JSBreak !JSAnnot !JSIdent !JSSemi -- ^break,optional identifier, autosemi
130132
| JSLet !JSAnnot !(JSCommaList JSExpression) !JSSemi -- ^const, decl, autosemi
133+
| JSClass !JSAnnot !JSIdent !JSClassHeritage !JSAnnot ![JSClassElement] !JSAnnot !JSSemi -- ^class, name, optional extends clause, lb, body, rb, autosemi
131134
| JSConstant !JSAnnot !(JSCommaList JSExpression) !JSSemi -- ^const, decl, autosemi
132135
| JSContinue !JSAnnot !JSIdent !JSSemi -- ^continue, optional identifier,autosemi
133136
| JSDoWhile !JSAnnot !JSStatement !JSAnnot !JSAnnot !JSExpression !JSAnnot !JSSemi -- ^do,stmt,while,lb,expr,rb,autosemi
@@ -177,6 +180,7 @@ data JSExpression
177180
| JSCallExpression !JSExpression !JSAnnot !(JSCommaList JSExpression) !JSAnnot -- ^expr, bl, args, rb
178181
| JSCallExpressionDot !JSExpression !JSAnnot !JSExpression -- ^expr, dot, expr
179182
| JSCallExpressionSquare !JSExpression !JSAnnot !JSExpression !JSAnnot -- ^expr, [, expr, ]
183+
| JSClassExpression !JSAnnot !JSIdent !JSClassHeritage !JSAnnot ![JSClassElement] !JSAnnot -- ^class, optional identifier, optional extends clause, lb, body, rb
180184
| JSCommaExpression !JSExpression !JSAnnot !JSExpression -- ^expression components
181185
| JSExpressionBinary !JSExpression !JSBinOp !JSExpression -- ^lhs, op, rhs
182186
| JSExpressionParen !JSAnnot !JSExpression !JSAnnot -- ^lb,expression,rb
@@ -339,6 +343,17 @@ data JSTemplatePart
339343
= JSTemplatePart !JSExpression !JSAnnot !String -- ^expr, rb, suffix
340344
deriving (Data, Eq, Show, Typeable)
341345

346+
data JSClassHeritage
347+
= JSExtends !JSAnnot !JSExpression
348+
| JSExtendsNone
349+
deriving (Data, Eq, Show, Typeable)
350+
351+
data JSClassElement
352+
= JSClassInstanceMethod !JSMethodDefinition
353+
| JSClassStaticMethod !JSAnnot !JSMethodDefinition
354+
| JSClassSemi !JSAnnot
355+
deriving (Data, Eq, Show, Typeable)
356+
342357
-- -----------------------------------------------------------------------------
343358
-- | Show the AST elements stripped of their JSAnnot data.
344359

@@ -358,6 +373,7 @@ instance ShowStripped JSStatement where
358373
ss (JSStatementBlock _ xs _ _) = "JSStatementBlock " ++ ss xs
359374
ss (JSBreak _ JSIdentNone s) = "JSBreak" ++ commaIf (ss s)
360375
ss (JSBreak _ (JSIdentName _ n) s) = "JSBreak " ++ singleQuote n ++ commaIf (ss s)
376+
ss (JSClass _ n h _lb xs _rb _) = "JSClass " ++ ssid n ++ " (" ++ ss h ++ ") " ++ ss xs
361377
ss (JSContinue _ JSIdentNone s) = "JSContinue" ++ commaIf (ss s)
362378
ss (JSContinue _ (JSIdentName _ n) s) = "JSContinue " ++ singleQuote n ++ commaIf (ss s)
363379
ss (JSConstant _ xs _as) = "JSConstant " ++ ss xs
@@ -399,6 +415,7 @@ instance ShowStripped JSExpression where
399415
ss (JSCallExpression ex _ xs _) = "JSCallExpression ("++ ss ex ++ ",JSArguments " ++ ss xs ++ ")"
400416
ss (JSCallExpressionDot ex _os xs) = "JSCallExpressionDot (" ++ ss ex ++ "," ++ ss xs ++ ")"
401417
ss (JSCallExpressionSquare ex _os xs _cs) = "JSCallExpressionSquare (" ++ ss ex ++ "," ++ ss xs ++ ")"
418+
ss (JSClassExpression _ n h _lb xs _rb) = "JSClassExpression " ++ ssid n ++ " (" ++ ss h ++ ") " ++ ss xs
402419
ss (JSDecimal _ s) = "JSDecimal " ++ singleQuote s
403420
ss (JSCommaExpression l _ r) = "JSExpression [" ++ ss l ++ "," ++ ss r ++ "]"
404421
ss (JSExpressionBinary x2 op x3) = "JSExpressionBinary (" ++ ss op ++ "," ++ ss x2 ++ "," ++ ss x3 ++ ")"
@@ -580,6 +597,15 @@ instance ShowStripped JSArrayElement where
580597
instance ShowStripped JSTemplatePart where
581598
ss (JSTemplatePart e _ s) = "(" ++ ss e ++ "," ++ singleQuote s ++ ")"
582599

600+
instance ShowStripped JSClassHeritage where
601+
ss JSExtendsNone = ""
602+
ss (JSExtends _ x) = ss x
603+
604+
instance ShowStripped JSClassElement where
605+
ss (JSClassInstanceMethod m) = ss m
606+
ss (JSClassStaticMethod _ m) = "JSClassStaticMethod (" ++ ss m ++ ")"
607+
ss (JSClassSemi _) = "JSClassSemi"
608+
583609
instance ShowStripped a => ShowStripped (JSCommaList a) where
584610
ss xs = "(" ++ commaJoin (map ss $ fromCommaList xs) ++ ")"
585611

src/Language/JavaScript/Parser/Grammar7.y

+58-1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ import qualified Language.JavaScript.Parser.AST as AST
8989
'break' { BreakToken {} }
9090
'case' { CaseToken {} }
9191
'catch' { CatchToken {} }
92+
'class' { ClassToken {} }
9293
'const' { ConstToken {} }
9394
'continue' { ContinueToken {} }
9495
'debugger' { DebuggerToken {} }
@@ -98,6 +99,7 @@ import qualified Language.JavaScript.Parser.AST as AST
9899
'else' { ElseToken {} }
99100
'enum' { EnumToken {} }
100101
'export' { ExportToken {} }
102+
'extends' { ExtendsToken {} }
101103
'false' { FalseToken {} }
102104
'finally' { FinallyToken {} }
103105
'for' { ForToken {} }
@@ -114,6 +116,7 @@ import qualified Language.JavaScript.Parser.AST as AST
114116
'of' { OfToken {} }
115117
'return' { ReturnToken {} }
116118
'set' { SetToken {} }
119+
'static' { StaticToken {} }
117120
'switch' { SwitchToken {} }
118121
'this' { ThisToken {} }
119122
'throw' { ThrowToken {} }
@@ -330,6 +333,7 @@ IdentifierName : Identifier {$1}
330333
| 'break' { AST.JSIdentifier (mkJSAnnot $1) "break" }
331334
| 'case' { AST.JSIdentifier (mkJSAnnot $1) "case" }
332335
| 'catch' { AST.JSIdentifier (mkJSAnnot $1) "catch" }
336+
| 'class' { AST.JSIdentifier (mkJSAnnot $1) "class" }
333337
| 'const' { AST.JSIdentifier (mkJSAnnot $1) "const" }
334338
| 'continue' { AST.JSIdentifier (mkJSAnnot $1) "continue" }
335339
| 'debugger' { AST.JSIdentifier (mkJSAnnot $1) "debugger" }
@@ -339,6 +343,7 @@ IdentifierName : Identifier {$1}
339343
| 'else' { AST.JSIdentifier (mkJSAnnot $1) "else" }
340344
| 'enum' { AST.JSIdentifier (mkJSAnnot $1) "enum" }
341345
| 'export' { AST.JSIdentifier (mkJSAnnot $1) "export" }
346+
| 'extends' { AST.JSIdentifier (mkJSAnnot $1) "extends" }
342347
| 'false' { AST.JSIdentifier (mkJSAnnot $1) "false" }
343348
| 'finally' { AST.JSIdentifier (mkJSAnnot $1) "finally" }
344349
| 'for' { AST.JSIdentifier (mkJSAnnot $1) "for" }
@@ -351,6 +356,7 @@ IdentifierName : Identifier {$1}
351356
| 'null' { AST.JSIdentifier (mkJSAnnot $1) "null" }
352357
| 'of' { AST.JSIdentifier (mkJSAnnot $1) "of" }
353358
| 'return' { AST.JSIdentifier (mkJSAnnot $1) "return" }
359+
| 'static' { AST.JSIdentifier (mkJSAnnot $1) "static" }
354360
| 'switch' { AST.JSIdentifier (mkJSAnnot $1) "switch" }
355361
| 'this' { AST.JSIdentifier (mkJSAnnot $1) "this" }
356362
| 'throw' { AST.JSIdentifier (mkJSAnnot $1) "throw" }
@@ -435,6 +441,15 @@ Function : 'function' { mkJSAnnot $1 {- 'Function' -} }
435441
New :: { AST.JSAnnot }
436442
New : 'new' { mkJSAnnot $1 }
437443

444+
Class :: { AST.JSAnnot }
445+
Class : 'class' { mkJSAnnot $1 }
446+
447+
Extends :: { AST.JSAnnot }
448+
Extends : 'extends' { mkJSAnnot $1 }
449+
450+
Static :: { AST.JSAnnot }
451+
Static : 'static' { mkJSAnnot $1 }
452+
438453

439454
Eof :: { AST.JSAnnot }
440455
Eof : 'tail' { mkJSAnnot $1 {- 'Eof' -} }
@@ -486,6 +501,7 @@ PrimaryExpression : 'this' { AST.JSLiteral (mkJSAnnot $1) "thi
486501
| Literal { $1 {- 'PrimaryExpression2' -} }
487502
| ArrayLiteral { $1 {- 'PrimaryExpression3' -} }
488503
| ObjectLiteral { $1 {- 'PrimaryExpression4' -} }
504+
| ClassExpression { $1 }
489505
| GeneratorExpression { $1 }
490506
| TemplateLiteral { mkJSTemplateLiteral Nothing $1 {- 'PrimaryExpression6' -} }
491507
| LParen Expression RParen { AST.JSExpressionParen $1 $2 $3 }
@@ -1272,6 +1288,44 @@ FormalParameterList : AssignmentExpression { AST.JSLOn
12721288
FunctionBody :: { AST.JSBlock }
12731289
FunctionBody : Block { $1 {- 'FunctionBody1' -} }
12741290

1291+
-- ClassDeclaration :
1292+
-- class BindingIdentifier ClassTail
1293+
-- class ClassTail
1294+
-- ClassExpression :
1295+
-- class BindingIdentifieropt ClassTail
1296+
-- ClassTail :
1297+
-- ClassHeritageopt { ClassBodyopt }
1298+
ClassDeclaration :: { AST.JSStatement }
1299+
ClassDeclaration : Class Identifier ClassHeritage LBrace ClassBody RBrace { AST.JSClass $1 (identName $2) $3 $4 $5 $6 AST.JSSemiAuto }
1300+
1301+
ClassExpression :: { AST.JSExpression }
1302+
ClassExpression : Class Identifier ClassHeritage LBrace ClassBody RBrace { AST.JSClassExpression $1 (identName $2) $3 $4 $5 $6 }
1303+
| Class ClassHeritage LBrace ClassBody RBrace { AST.JSClassExpression $1 AST.JSIdentNone $2 $3 $4 $5 }
1304+
1305+
-- ClassHeritage :
1306+
-- extends LeftHandSideExpression
1307+
ClassHeritage :: { AST.JSClassHeritage }
1308+
ClassHeritage : Extends LeftHandSideExpression { AST.JSExtends $1 $2 }
1309+
| { AST.JSExtendsNone }
1310+
1311+
-- ClassBody :
1312+
-- ClassElementList
1313+
-- ClassElementList :
1314+
-- ClassElement
1315+
-- ClassElementList ClassElement
1316+
ClassBody :: { [AST.JSClassElement] }
1317+
ClassBody : { [] }
1318+
| ClassBody ClassElement { $1 ++ [$2] }
1319+
1320+
-- ClassElement :
1321+
-- MethodDefinition
1322+
-- static MethodDefinition
1323+
-- ;
1324+
ClassElement :: { AST.JSClassElement }
1325+
ClassElement : MethodDefinition { AST.JSClassInstanceMethod $1 }
1326+
| Static MethodDefinition { AST.JSClassStaticMethod $1 $2 }
1327+
| Semi { AST.JSClassSemi $1 }
1328+
12751329
-- Program : See clause 14
12761330
-- SourceElementsopt
12771331

@@ -1357,7 +1411,7 @@ ImportSpecifier : IdentifierName
13571411
-- [ ] export Declaration
13581412
-- [ ] Declaration :
13591413
-- [ ] HoistableDeclaration
1360-
-- [ ] ClassDeclaration
1414+
-- [x] ClassDeclaration
13611415
-- [x] LexicalDeclaration
13621416
-- [ ] HoistableDeclaration :
13631417
-- [x] FunctionDeclaration
@@ -1378,6 +1432,8 @@ ExportDeclaration : ExportClause FromClause AutoSemi
13781432
{ AST.JSExport $1 $2 {- 'ExportDeclaration4' -} }
13791433
| GeneratorDeclaration AutoSemi
13801434
{ AST.JSExport $1 $2 {- 'ExportDeclaration5' -} }
1435+
| ClassDeclaration AutoSemi
1436+
{ AST.JSExport $1 $2 {- 'ExportDeclaration6' -} }
13811437

13821438
-- ExportClause :
13831439
-- { }
@@ -1431,6 +1487,7 @@ expressionToStatement (AST.JSFunctionExpression a b@(AST.JSIdentName{}) c d e f)
14311487
expressionToStatement (AST.JSGeneratorExpression a b c@(AST.JSIdentName{}) d e f g) s = AST.JSGenerator a b c d e f g s
14321488
expressionToStatement (AST.JSAssignExpression lhs op rhs) s = AST.JSAssignStatement lhs op rhs s
14331489
expressionToStatement (AST.JSMemberExpression e l a r) s = AST.JSMethodCall e l a r s
1490+
expressionToStatement (AST.JSClassExpression a b@(AST.JSIdentName{}) c d e f) s = AST.JSClass a b c d e f s
14341491
expressionToStatement exp s = AST.JSExpressionStatement exp s
14351492

14361493

src/Language/JavaScript/Parser/Lexer.x

+6-3
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ keywordNames =
533533
, ( "case", CaseToken )
534534
, ( "catch", CatchToken )
535535
536+
, ( "class", ClassToken )
536537
, ( "const", ConstToken ) -- not a keyword, nominally a future reserved word, but actually in use
537538
538539
, ( "continue", ContinueToken )
@@ -544,6 +545,7 @@ keywordNames =
544545
545546
, ( "enum", EnumToken ) -- not a keyword, nominally a future reserved word, but actually in use
546547
, ( "export", ExportToken )
548+
, ( "extends", ExtendsToken )
547549
548550
, ( "false", FalseToken ) -- boolean literal
549551
@@ -562,6 +564,7 @@ keywordNames =
562564
563565
, ( "of", OfToken )
564566
, ( "return", ReturnToken )
567+
, ( "static", StaticToken )
565568
, ( "switch", SwitchToken )
566569
, ( "this", ThisToken )
567570
, ( "throw", ThrowToken )
@@ -591,11 +594,11 @@ keywordNames =
591594
592595
593596
-- Future Reserved Words
594-
, ( "class", FutureToken )
597+
-- ( "class", FutureToken ) **** an actual token, used in productions
595598
-- ( "code", FutureToken ) **** not any more
596599
-- ( "const", FutureToken ) **** an actual token, used in productions
597600
-- enum **** an actual token, used in productions
598-
, ( "extends", FutureToken )
601+
-- ( "extends", FutureToken ) **** an actual token, used in productions
599602
, ( "super", FutureToken )
600603
601604
@@ -611,7 +614,7 @@ keywordNames =
611614
, ( "private", FutureToken )
612615
, ( "protected", FutureToken )
613616
, ( "public", FutureToken )
614-
, ( "static", FutureToken )
617+
-- ( "static", FutureToken ) **** an actual token, used in productions
615618
-- ( "strict", FutureToken ) *** not any more
616619
-- ( "yield", FutureToken) **** an actual token, used in productions
617620
]

src/Language/JavaScript/Parser/Token.hs

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ data Token
5959
| BreakToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
6060
| CaseToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
6161
| CatchToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
62+
| ClassToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
6263
| ConstToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
6364
| LetToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
6465
| ContinueToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
@@ -68,6 +69,7 @@ data Token
6869
| DoToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
6970
| ElseToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
7071
| EnumToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
72+
| ExtendsToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
7173
| FalseToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
7274
| FinallyToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
7375
| ForToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
@@ -80,6 +82,7 @@ data Token
8082
| NullToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
8183
| OfToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
8284
| ReturnToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
85+
| StaticToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
8386
| SwitchToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
8487
| ThisToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
8588
| ThrowToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }

src/Language/JavaScript/Pretty/Printer.hs

+14
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ instance RenderJS JSExpression where
7777
(|>) pacc (JSCallExpression ex lb xs rb) = pacc |> ex |> lb |> "(" |> xs |> rb |> ")"
7878
(|>) pacc (JSCallExpressionDot ex os xs) = pacc |> ex |> os |> "." |> xs
7979
(|>) pacc (JSCallExpressionSquare ex als xs ars) = pacc |> ex |> als |> "[" |> xs |> ars |> "]"
80+
(|>) pacc (JSClassExpression annot n h lb xs rb) = pacc |> annot |> "class" |> n |> h |> lb |> "{" |> xs |> rb |> "}"
8081
(|>) pacc (JSCommaExpression le c re) = pacc |> le |> c |> "," |> re
8182
(|>) pacc (JSExpressionBinary lhs op rhs) = pacc |> lhs |> op |> rhs
8283
(|>) pacc (JSExpressionParen alp e arp) = pacc |> alp |> "(" |> e |> arp |> ")"
@@ -224,6 +225,7 @@ instance RenderJS [JSSwitchParts] where
224225
instance RenderJS JSStatement where
225226
(|>) pacc (JSStatementBlock alb blk arb s) = pacc |> alb |> "{" |> blk |> arb |> "}" |> s
226227
(|>) pacc (JSBreak annot mi s) = pacc |> annot |> "break" |> mi |> s
228+
(|>) pacc (JSClass annot n h lb xs rb s) = pacc |> annot |> "class" |> n |> h |> lb |> "{" |> xs |> rb |> "}" |> s
227229
(|>) pacc (JSContinue annot mi s) = pacc |> annot |> "continue" |> mi |> s
228230
(|>) pacc (JSConstant annot xs s) = pacc |> annot |> "const" |> xs |> s
229231
(|>) pacc (JSDoWhile ad x1 aw alb x2 arb x3) = pacc |> ad |> "do" |> x1 |> aw |> "while" |> alb |> "(" |> x2 |> arb |> ")" |> x3
@@ -362,4 +364,16 @@ instance RenderJS [JSTemplatePart] where
362364
instance RenderJS JSTemplatePart where
363365
(|>) pacc (JSTemplatePart e a s) = pacc |> e |> a |> s
364366

367+
instance RenderJS JSClassHeritage where
368+
(|>) pacc (JSExtends a e) = pacc |> a |> "extends" |> e
369+
(|>) pacc JSExtendsNone = pacc
370+
371+
instance RenderJS [JSClassElement] where
372+
(|>) = foldl' (|>)
373+
374+
instance RenderJS JSClassElement where
375+
(|>) pacc (JSClassInstanceMethod m) = pacc |> m
376+
(|>) pacc (JSClassStaticMethod a m) = pacc |> a |> "static" |> m
377+
(|>) pacc (JSClassSemi a) = pacc |> a |> ";"
378+
365379
-- EOF

src/Language/JavaScript/Process/Minify.hs

+14
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ fixSpace = fix spaceAnnot
4141
fixStmt :: JSAnnot -> JSSemi -> JSStatement -> JSStatement
4242
fixStmt a s (JSStatementBlock _lb ss _rb _) = fixStatementBlock a s ss
4343
fixStmt a s (JSBreak _ i _) = JSBreak a (fixSpace i) s
44+
fixStmt a s (JSClass _ n h _ ms _ _) = JSClass a (fixSpace n) (fixSpace h) emptyAnnot (fixEmpty ms) emptyAnnot s
4445
fixStmt a s (JSConstant _ ss _) = JSConstant a (fixVarList ss) s
4546
fixStmt a s (JSContinue _ i _) = JSContinue a (fixSpace i) s
4647
fixStmt a s (JSDoWhile _ st _ _ e _ _) = JSDoWhile a (mkStatementBlock noSemi st) emptyAnnot emptyAnnot (fixEmpty e) emptyAnnot s
@@ -157,6 +158,7 @@ instance MinifyJS JSExpression where
157158
fix a (JSCallExpression ex _ xs _) = JSCallExpression (fix a ex) emptyAnnot (fixEmpty xs) emptyAnnot
158159
fix a (JSCallExpressionDot ex _ xs) = JSCallExpressionDot (fix a ex) emptyAnnot (fixEmpty xs)
159160
fix a (JSCallExpressionSquare ex _ xs _) = JSCallExpressionSquare (fix a ex) emptyAnnot (fixEmpty xs) emptyAnnot
161+
fix a (JSClassExpression _ n h _ ms _) = JSClassExpression a (fixSpace n) (fixSpace h) emptyAnnot (fixEmpty ms) emptyAnnot
160162
fix a (JSCommaExpression le _ re) = JSCommaExpression (fix a le) emptyAnnot (fixEmpty re)
161163
fix a (JSExpressionBinary lhs op rhs) = fixBinOpExpression a op lhs rhs
162164
fix _ (JSExpressionParen _ e _) = JSExpressionParen emptyAnnot (fixEmpty e) emptyAnnot
@@ -415,6 +417,18 @@ instance MinifyJS JSTemplatePart where
415417
fix _ (JSTemplatePart e _ s) = JSTemplatePart (fixEmpty e) emptyAnnot s
416418

417419

420+
instance MinifyJS JSClassHeritage where
421+
fix _ JSExtendsNone = JSExtendsNone
422+
fix a (JSExtends _ e) = JSExtends a (fixSpace e)
423+
424+
425+
instance MinifyJS [JSClassElement] where
426+
fix _ [] = []
427+
fix a (JSClassInstanceMethod m:t) = JSClassInstanceMethod (fix a m) : fixEmpty t
428+
fix a (JSClassStaticMethod _ m:t) = JSClassStaticMethod a (fixSpace m) : fixEmpty t
429+
fix a (JSClassSemi _:t) = fix a t
430+
431+
418432
spaceAnnot :: JSAnnot
419433
spaceAnnot = JSAnnot tokenPosnEmpty [WhiteSpace tokenPosnEmpty " "]
420434

0 commit comments

Comments
 (0)