Skip to content

Commit f5751d0

Browse files
committed
[javascript mode] Support TypeScript return type annotations on arrow functions
Closes #4256
1 parent 6b3b6a6 commit f5751d0

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

mode/javascript/javascript.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
209209
var arrow = stream.string.indexOf("=>", stream.start);
210210
if (arrow < 0) return;
211211

212+
if (isTS) { // Try to skip TypeScript return type declarations after the arguments
213+
var m = /:\s*(?:\w+(?:<[^>]*>|\[\])?|\{[^}]*\})\s*$/.exec(stream.string.slice(stream.start, arrow))
214+
if (m) arrow = m.index
215+
}
216+
212217
var depth = 0, sawSomething = false;
213218
for (var pos = arrow - 1; pos >= 0; --pos) {
214219
var ch = stream.string.charAt(pos);

0 commit comments

Comments
 (0)