diff --git a/mode/soy/soy.js b/mode/soy/soy.js index 0e24457042a6e1211d3c10cdcfa9e96dce3d4810..98f308658e0b72f9e9d9b891665f902e349bfe54 100644 --- a/mode/soy/soy.js +++ b/mode/soy/soy.js @@ -137,6 +137,25 @@ } 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": if (match = stream.match(/^\.?([\w]+(?!\.[\w]+)*)/)) { state.templates = prepend(state.templates, match[1]); @@ -242,36 +261,15 @@ return this.token(stream, state); } 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(/^\/\*/)) { - 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}/)) { + if (stream.match(/^\{literal}/)) { state.indent += config.indentUnit; state.soyState.push("literal"); return "keyword"; - // A tag-keyword must be followed by whitespace or a closing tag. - } else if (match = stream.match(/^\{([\/@\\]?\w+\??)(?=[\s\}])/)) { + // A tag-keyword must be followed by whitespace, comment 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];