@@ -47,8 +47,6 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
4747 "interface" : kw ( "class" ) ,
4848 "implements" : C ,
4949 "namespace" : C ,
50- "module" : kw ( "module" ) ,
51- "enum" : kw ( "module" ) ,
5250
5351 // scope modifiers
5452 "public" : kw ( "modifier" ) ,
@@ -155,7 +153,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
155153 var kw = keywords [ word ]
156154 return ret ( kw . type , kw . style , word )
157155 }
158- if ( word == "async" && stream . match ( / ^ \s * [ \( \w ] / , false ) )
156+ if ( word == "async" && stream . match ( / ^ ( \s | \/ \* . * ? \* \/ ) * [ \( \w ] / , false ) )
159157 return ret ( "async" , "keyword" , word )
160158 }
161159 return ret ( "variable" , "variable" , word )
@@ -372,9 +370,12 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
372370 if ( isTS && value == "type" ) {
373371 cx . marked = "keyword"
374372 return cont ( typeexpr , expect ( "operator" ) , typeexpr , expect ( ";" ) ) ;
375- } if ( isTS && value == "declare" ) {
373+ } else if ( isTS && value == "declare" ) {
376374 cx . marked = "keyword"
377375 return cont ( statement )
376+ } else if ( isTS && ( value == "module" || value == "enum" ) && cx . stream . match ( / ^ \s * \w / , false ) ) {
377+ cx . marked = "keyword"
378+ return cont ( pushlex ( "form" ) , pattern , expect ( "{" ) , pushlex ( "}" ) , block , poplex , poplex )
378379 } else {
379380 return cont ( pushlex ( "stat" ) , maybelabel ) ;
380381 }
@@ -388,7 +389,6 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
388389 if ( type == "class" ) return cont ( pushlex ( "form" ) , className , poplex ) ;
389390 if ( type == "export" ) return cont ( pushlex ( "stat" ) , afterExport , poplex ) ;
390391 if ( type == "import" ) return cont ( pushlex ( "stat" ) , afterImport , poplex ) ;
391- if ( type == "module" ) return cont ( pushlex ( "form" ) , pattern , expect ( "{" ) , pushlex ( "}" ) , block , poplex , poplex )
392392 if ( type == "async" ) return cont ( statement )
393393 if ( value == "@" ) return cont ( expression , statement )
394394 return pass ( pushlex ( "stat" ) , expression , expect ( ";" ) , poplex ) ;
@@ -438,6 +438,8 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
438438 if ( type == "=>" ) return cont ( pushcontext , noComma ? arrowBodyNoComma : arrowBody , popcontext ) ;
439439 if ( type == "operator" ) {
440440 if ( / \+ \+ | - - / . test ( value ) || isTS && value == "!" ) return cont ( me ) ;
441+ if ( isTS && value == "<" && cx . stream . match ( / ^ ( [ ^ > ] | < .* ?> ) * > \s * \( / , false ) )
442+ return cont ( pushlex ( ">" ) , commasep ( typeexpr , ">" ) , poplex , me ) ;
441443 if ( value == "?" ) return cont ( expression , expect ( ":" ) , expr ) ;
442444 return cont ( expr ) ;
443445 }
@@ -564,6 +566,18 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
564566 if ( value == "?" ) return cont ( maybetype ) ;
565567 }
566568 }
569+ function mayberettype ( type ) {
570+ if ( isTS && type == ":" ) {
571+ if ( cx . stream . match ( / ^ \s * \w + \s + i s \b / , false ) ) return cont ( expression , isKW , typeexpr )
572+ else return cont ( typeexpr )
573+ }
574+ }
575+ function isKW ( _ , value ) {
576+ if ( value == "is" ) {
577+ cx . marked = "keyword"
578+ return cont ( )
579+ }
580+ }
567581 function typeexpr ( type , value ) {
568582 if ( type == "variable" || value == "void" ) {
569583 if ( value == "keyof" ) {
@@ -607,6 +621,12 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
607621 function maybeTypeArgs ( _ , value ) {
608622 if ( value == "<" ) return cont ( pushlex ( ">" ) , commasep ( typeexpr , ">" ) , poplex , afterType )
609623 }
624+ function typeparam ( ) {
625+ return pass ( typeexpr , maybeTypeDefault )
626+ }
627+ function maybeTypeDefault ( _ , value ) {
628+ if ( value == "=" ) return cont ( typeexpr )
629+ }
610630 function vardef ( ) {
611631 return pass ( pattern , maybetype , maybeAssign , vardefCont ) ;
612632 }
@@ -660,8 +680,8 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
660680 function functiondef ( type , value ) {
661681 if ( value == "*" ) { cx . marked = "keyword" ; return cont ( functiondef ) ; }
662682 if ( type == "variable" ) { register ( value ) ; return cont ( functiondef ) ; }
663- if ( type == "(" ) return cont ( pushcontext , pushlex ( ")" ) , commasep ( funarg , ")" ) , poplex , maybetype , statement , popcontext ) ;
664- if ( isTS && value == "<" ) return cont ( pushlex ( ">" ) , commasep ( typeexpr , ">" ) , poplex , functiondef )
683+ if ( type == "(" ) return cont ( pushcontext , pushlex ( ")" ) , commasep ( funarg , ")" ) , poplex , mayberettype , statement , popcontext ) ;
684+ if ( isTS && value == "<" ) return cont ( pushlex ( ">" ) , commasep ( typeparam , ">" ) , poplex , functiondef )
665685 }
666686 function funarg ( type , value ) {
667687 if ( value == "@" ) cont ( expression , funarg )
@@ -677,7 +697,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
677697 if ( type == "variable" ) { register ( value ) ; return cont ( classNameAfter ) ; }
678698 }
679699 function classNameAfter ( type , value ) {
680- if ( value == "<" ) return cont ( pushlex ( ">" ) , commasep ( typeexpr , ">" ) , poplex , classNameAfter )
700+ if ( value == "<" ) return cont ( pushlex ( ">" ) , commasep ( typeparam , ">" ) , poplex , classNameAfter )
681701 if ( value == "extends" || value == "implements" || ( isTS && type == "," ) )
682702 return cont ( isTS ? typeexpr : expression , classNameAfter ) ;
683703 if ( type == "{" ) return cont ( pushlex ( "}" ) , classBody , poplex ) ;
0 commit comments