From 4c625b7a68abd00eda9f3c3c4d1901cc1173c66d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Segersv=C3=A4rd?= <oseg@google.com> Date: Mon, 15 May 2017 14:28:00 +0200 Subject: [PATCH] [soy mode] Don't highlight functions in the start of tags as keywords --- mode/soy/soy.js | 11 ++++++++++- mode/soy/test.js | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/mode/soy/soy.js b/mode/soy/soy.js index 94ddad5f..ba163636 100644 --- a/mode/soy/soy.js +++ b/mode/soy/soy.js @@ -255,7 +255,9 @@ state.indent += config.indentUnit; state.soyState.push("literal"); return "keyword"; - } else if (match = stream.match(/^\{([\/@\\]?[\w?]*)/)) { + + // A tag-keyword must be followed by whitespace or a closing tag. + } else if (match = stream.match(/^\{([\/@\\]?\w+\??)(?=[\s\}])/)) { if (match[1] != "/switch") state.indent += (/^(\/|(else|elseif|ifempty|case|fallbackmsg|default)$)/.test(match[1]) && state.tag != "switch" ? 1 : 2) * config.indentUnit; state.tag = match[1]; @@ -287,6 +289,13 @@ state.soyState.push("param-def"); } return "keyword"; + + // Not a tag-keyword; it's an implicit print tag. + } else if (stream.eat('{')) { + state.tag = "print"; + state.indent += 2 * config.indentUnit; + state.soyState.push("tag"); + return "keyword"; } return tokenUntil(stream, state, /\{|\s+\/\/|\/\*/); diff --git a/mode/soy/test.js b/mode/soy/test.js index 7e0ed0f4..7cd111f2 100644 --- a/mode/soy/test.js +++ b/mode/soy/test.js @@ -93,6 +93,12 @@ '[keyword {/template}]', ''); + MT('tag-starting-with-function-call-is-not-a-keyword', + '[keyword {]index([variable-2&error $foo])[keyword }]', + '[keyword {css] [string "some-class"][keyword }]', + '[keyword {]css([string "some-class"])[keyword }]', + ''); + MT('allow-missing-colon-in-@param', '[keyword {template] [def .foo][keyword }]', ' [keyword {@param] [def showThing] [variable-3 bool][keyword }]', -- GitLab