Skip to content
Snippets Groups Projects
Commit a29e048d authored by Jakub Vrana's avatar Jakub Vrana
Browse files

[soy mode] Support comments in all contexts

parent 1ba861a0
No related branches found
No related tags found
No related merge requests found
...@@ -137,6 +137,25 @@ ...@@ -137,6 +137,25 @@
} }
return "comment"; return "comment";
case "string":
var match = stream.match(/^.*?(["']|\\[\s\S])/);
if (!match) {
stream.skipToEnd();
} else if (match[1] == state.quoteKind) {
state.quoteKind = null;
state.soyState.pop();
}
return "string";
}
if (stream.match(/^\/\*/)) {
state.soyState.push("comment");
return "comment";
} else if (stream.match(stream.sol() || (state.soyState.length && last(state.soyState) != "literal") ? /^\s*\/\/.*/ : /^\s+\/\/.*/)) {
return "comment";
}
switch (last(state.soyState)) {
case "templ-def": case "templ-def":
if (match = stream.match(/^\.?([\w]+(?!\.[\w]+)*)/)) { if (match = stream.match(/^\.?([\w]+(?!\.[\w]+)*)/)) {
state.templates = prepend(state.templates, match[1]); state.templates = prepend(state.templates, match[1]);
...@@ -242,36 +261,15 @@ ...@@ -242,36 +261,15 @@
return this.token(stream, state); return this.token(stream, state);
} }
return tokenUntil(stream, state, /\{\/literal}/); return tokenUntil(stream, state, /\{\/literal}/);
case "string":
var match = stream.match(/^.*?(["']|\\[\s\S])/);
if (!match) {
stream.skipToEnd();
} else if (match[1] == state.quoteKind) {
state.quoteKind = null;
state.soyState.pop();
}
return "string";
} }
if (stream.match(/^\/\*/)) { if (stream.match(/^\{literal}/)) {
state.soyState.push("comment");
if (!state.scopes) {
state.variables = prepend(null, 'ij');
}
return "comment";
} else if (stream.match(stream.sol() ? /^\s*\/\/.*/ : /^\s+\/\/.*/)) {
if (!state.scopes) {
state.variables = prepend(null, 'ij');
}
return "comment";
} else if (stream.match(/^\{literal}/)) {
state.indent += config.indentUnit; state.indent += config.indentUnit;
state.soyState.push("literal"); state.soyState.push("literal");
return "keyword"; return "keyword";
// A tag-keyword must be followed by whitespace or a closing tag. // A tag-keyword must be followed by whitespace, comment or a closing tag.
} else if (match = stream.match(/^\{([\/@\\]?\w+\??)(?=[\s\}])/)) { } else if (match = stream.match(/^\{([\/@\\]?\w+\??)(?=[\s\}]|\/[/*])/)) {
if (match[1] != "/switch") if (match[1] != "/switch")
state.indent += (/^(\/|(else|elseif|ifempty|case|fallbackmsg|default)$)/.test(match[1]) && state.tag != "switch" ? 1 : 2) * config.indentUnit; state.indent += (/^(\/|(else|elseif|ifempty|case|fallbackmsg|default)$)/.test(match[1]) && state.tag != "switch" ? 1 : 2) * config.indentUnit;
state.tag = match[1]; state.tag = match[1];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment