From 27fe44c3cb75ab38c18846760d9c7815700ad864 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Fri, 19 Dec 2014 23:24:02 +0100 Subject: [PATCH] [javascript mode] Be more conservative about detecting fat arrow syntax So that => in a string or comment doesn't trigger weird indentation. Closes #2993 --- mode/javascript/javascript.js | 2 ++ mode/javascript/test.js | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/mode/javascript/javascript.js b/mode/javascript/javascript.js index b0ba8d017f..fac8d57769 100644 --- a/mode/javascript/javascript.js +++ b/mode/javascript/javascript.js @@ -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; diff --git a/mode/javascript/test.js b/mode/javascript/test.js index aaeb8e0c07..91b0e89a06 100644 --- a/mode/javascript/test.js +++ b/mode/javascript/test.js @@ -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