Skip to content

Commit

Permalink
[javascript mode] Be more conservative about detecting fat arrow syntax
Browse files Browse the repository at this point in the history
So that => in a string or comment doesn't trigger weird indentation.

Closes codemirror#2993
  • Loading branch information
marijnh committed Dec 19, 2014
1 parent 965b8dd commit 27fe44c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mode/javascript/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
++depth;
} else if (wordRE.test(ch)) {
sawSomething = true;
} else if (/["'\/]/.test(ch)) {
return;
} else if (sawSomething && !depth) {
++pos;
break;
Expand Down
6 changes: 6 additions & 0 deletions mode/javascript/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@
" [keyword yield] [variable-2 i];",
"}");

MT("quotedStringAddition",
"[keyword let] [variable f] [operator =] [variable a] [operator +] [string 'fatarrow'] [operator +] [variable c];");

MT("quotedFatArrow",
"[keyword let] [variable f] [operator =] [variable a] [operator +] [string '=>'] [operator +] [variable c];");

MT("fatArrow",
"[variable array].[property filter]([def a] [operator =>] [variable-2 a] [operator +] [number 1]);",
"[variable a];", // No longer in scope
Expand Down

0 comments on commit 27fe44c

Please sign in to comment.