@@ -19,6 +19,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
1919 var jsonldMode = parserConfig . jsonld ;
2020 var jsonMode = parserConfig . json || jsonldMode ;
2121 var isTS = parserConfig . typescript ;
22+ var wordRE = parserConfig . wordCharacters || / [ \w $ \xa1 - \uffff ] / ;
2223
2324 // Tokenizer
2425
@@ -132,8 +133,8 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
132133 } else if ( isOperatorChar . test ( ch ) ) {
133134 stream . eatWhile ( isOperatorChar ) ;
134135 return ret ( "operator" , "operator" , stream . current ( ) ) ;
135- } else {
136- stream . eatWhile ( / [ \w \$ _ ] / ) ;
136+ } else if ( wordRE . test ( ch ) ) {
137+ stream . eatWhile ( wordRE ) ;
137138 var word = stream . current ( ) , known = keywords . propertyIsEnumerable ( word ) && keywords [ word ] ;
138139 return ( known && state . lastType != "." ) ? ret ( known . type , known . style , word ) :
139140 ret ( "variable" , "variable" , word ) ;
@@ -202,7 +203,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
202203 if ( -- depth == 0 ) break ;
203204 } else if ( bracket >= 3 && bracket < 6 ) {
204205 ++ depth ;
205- } else if ( / [ $ \w ] / . test ( ch ) ) {
206+ } else if ( wordRE . test ( ch ) ) {
206207 sawSomething = true ;
207208 } else if ( sawSomething && ! depth ) {
208209 ++ pos ;
@@ -238,7 +239,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
238239 var cc = state . cc ;
239240 // Communicate our context to the combinators.
240241 // (Less wasteful than consing up a hundred closures on every call.)
241- cx . state = state ; cx . stream = stream ; cx . marked = null , cx . cc = cc ;
242+ cx . state = state ; cx . stream = stream ; cx . marked = null , cx . cc = cc ; cx . style = style ;
242243
243244 if ( ! state . lexical . hasOwnProperty ( "align" ) )
244245 state . lexical . align = true ;
@@ -298,6 +299,8 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
298299 var result = function ( ) {
299300 var state = cx . state , indent = state . indented ;
300301 if ( state . lexical . type == "stat" ) indent = state . lexical . indented ;
302+ else for ( var outer = state . lexical ; outer && outer . type == ")" && outer . align ; outer = outer . prev )
303+ indent = outer . indented ;
301304 state . lexical = new JSLexical ( indent , cx . stream . column ( ) , type , null , state . lexical , info ) ;
302305 } ;
303306 result . lex = true ;
@@ -343,7 +346,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
343346 if ( type == "catch" ) return cont ( pushlex ( "form" ) , pushcontext , expect ( "(" ) , funarg , expect ( ")" ) ,
344347 statement , poplex , popcontext ) ;
345348 if ( type == "module" ) return cont ( pushlex ( "form" ) , pushcontext , afterModule , popcontext , poplex ) ;
346- if ( type == "class" ) return cont ( pushlex ( "form" ) , className , objlit , poplex ) ;
349+ if ( type == "class" ) return cont ( pushlex ( "form" ) , className , poplex ) ;
347350 if ( type == "export" ) return cont ( pushlex ( "form" ) , afterExport , poplex ) ;
348351 if ( type == "import" ) return cont ( pushlex ( "form" ) , afterImport , poplex ) ;
349352 return pass ( pushlex ( "stat" ) , expression , expect ( ";" ) , poplex ) ;
@@ -388,7 +391,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
388391 function maybeoperatorNoComma ( type , value , noComma ) {
389392 var me = noComma == false ? maybeoperatorComma : maybeoperatorNoComma ;
390393 var expr = noComma == false ? expression : expressionNoComma ;
391- if ( value == "=>" ) return cont ( pushcontext , noComma ? arrowBodyNoComma : arrowBody , popcontext ) ;
394+ if ( type == "=>" ) return cont ( pushcontext , noComma ? arrowBodyNoComma : arrowBody , popcontext ) ;
392395 if ( type == "operator" ) {
393396 if ( / \+ \+ | - - / . test ( value ) ) return cont ( me ) ;
394397 if ( value == "?" ) return cont ( expression , expect ( ":" ) , expr ) ;
@@ -414,13 +417,11 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
414417 }
415418 function arrowBody ( type ) {
416419 findFatArrow ( cx . stream , cx . state ) ;
417- if ( type == "{" ) return pass ( statement ) ;
418- return pass ( expression ) ;
420+ return pass ( type == "{" ? statement : expression ) ;
419421 }
420422 function arrowBodyNoComma ( type ) {
421423 findFatArrow ( cx . stream , cx . state ) ;
422- if ( type == "{" ) return pass ( statement ) ;
423- return pass ( expressionNoComma ) ;
424+ return pass ( type == "{" ? statement : expressionNoComma ) ;
424425 }
425426 function maybelabel ( type ) {
426427 if ( type == ":" ) return cont ( poplex , statement ) ;
@@ -430,15 +431,18 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
430431 if ( type == "variable" ) { cx . marked = "property" ; return cont ( ) ; }
431432 }
432433 function objprop ( type , value ) {
433- if ( type == "variable" ) {
434+ if ( type == "variable" || cx . style == "keyword" ) {
434435 cx . marked = "property" ;
435436 if ( value == "get" || value == "set" ) return cont ( getterSetter ) ;
437+ return cont ( afterprop ) ;
436438 } else if ( type == "number" || type == "string" ) {
437- cx . marked = jsonldMode ? "property" : ( type + " property" ) ;
439+ cx . marked = jsonldMode ? "property" : ( cx . style + " property" ) ;
440+ return cont ( afterprop ) ;
441+ } else if ( type == "jsonld-keyword" ) {
442+ return cont ( afterprop ) ;
438443 } else if ( type == "[" ) {
439444 return cont ( expression , expect ( "]" ) , afterprop ) ;
440445 }
441- if ( atomicTypes . hasOwnProperty ( type ) ) return cont ( afterprop ) ;
442446 }
443447 function getterSetter ( type ) {
444448 if ( type != "variable" ) return pass ( afterprop ) ;
@@ -537,11 +541,27 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
537541 function className ( type , value ) {
538542 if ( type == "variable" ) { register ( value ) ; return cont ( classNameAfter ) ; }
539543 }
540- function classNameAfter ( _type , value ) {
541- if ( value == "extends" ) return cont ( expression ) ;
544+ function classNameAfter ( type , value ) {
545+ if ( value == "extends" ) return cont ( expression , classNameAfter ) ;
546+ if ( type == "{" ) return cont ( pushlex ( "}" ) , classBody , poplex ) ;
547+ }
548+ function classBody ( type , value ) {
549+ if ( type == "variable" || cx . style == "keyword" ) {
550+ cx . marked = "property" ;
551+ if ( value == "get" || value == "set" ) return cont ( classGetterSetter , functiondef , classBody ) ;
552+ return cont ( functiondef , classBody ) ;
553+ }
554+ if ( value == "*" ) {
555+ cx . marked = "keyword" ;
556+ return cont ( classBody ) ;
557+ }
558+ if ( type == ";" ) return cont ( classBody ) ;
559+ if ( type == "}" ) return cont ( ) ;
542560 }
543- function objlit ( type ) {
544- if ( type == "{" ) return contCommasep ( objprop , "}" ) ;
561+ function classGetterSetter ( type ) {
562+ if ( type != "variable" ) return pass ( ) ;
563+ cx . marked = "property" ;
564+ return cont ( ) ;
545565 }
546566 function afterModule ( type , value ) {
547567 if ( type == "string" ) return cont ( statement ) ;
@@ -570,7 +590,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
570590 }
571591 function maybeArrayComprehension ( type ) {
572592 if ( type == "for" ) return pass ( comprehension , expect ( "]" ) ) ;
573- if ( type == "," ) return cont ( commasep ( expressionNoComma , "]" ) ) ;
593+ if ( type == "," ) return cont ( commasep ( maybeexpressionNoComma , "]" ) ) ;
574594 return pass ( commasep ( expressionNoComma , "]" ) ) ;
575595 }
576596 function comprehension ( type ) {
@@ -636,7 +656,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
636656 else return lexical . indented + ( closing ? 0 : indentUnit ) ;
637657 } ,
638658
639- electricChars : ":{}" ,
659+ electricInput : / ^ \s * (?: c a s e . * ? : | d e f a u l t : | \{ | \} ) $ / ,
640660 blockCommentStart : jsonMode ? null : "/*" ,
641661 blockCommentEnd : jsonMode ? null : "*/" ,
642662 lineComment : jsonMode ? null : "//" ,
@@ -648,11 +668,12 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
648668 } ;
649669} ) ;
650670
651- CodeMirror . registerHelper ( "wordChars" , "javascript" , / [ \\ w $ ] / ) ;
671+ CodeMirror . registerHelper ( "wordChars" , "javascript" , / [ \w $ ] / ) ;
652672
653673CodeMirror . defineMIME ( "text/javascript" , "javascript" ) ;
654674CodeMirror . defineMIME ( "text/ecmascript" , "javascript" ) ;
655675CodeMirror . defineMIME ( "application/javascript" , "javascript" ) ;
676+ CodeMirror . defineMIME ( "application/x-javascript" , "javascript" ) ;
656677CodeMirror . defineMIME ( "application/ecmascript" , "javascript" ) ;
657678CodeMirror . defineMIME ( "application/json" , { name : "javascript" , json : true } ) ;
658679CodeMirror . defineMIME ( "application/x-json" , { name : "javascript" , json : true } ) ;
0 commit comments