From 81ff51fa9ac665057ea70ad32bbc73df67cb4f3a Mon Sep 17 00:00:00 2001 From: iteriani Date: Fri, 18 Jun 2021 00:01:31 -0700 Subject: [PATCH] [soy mode] Add support for {extern and {export extern --- mode/soy/soy.js | 8 +++++++- mode/soy/test.js | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/mode/soy/soy.js b/mode/soy/soy.js index 9361b0590e..614c3f2316 100644 --- a/mode/soy/soy.js +++ b/mode/soy/soy.js @@ -24,6 +24,8 @@ "@inject?": paramData, "@state": paramData, "template": { soyState: "templ-def", variableScope: true}, + "extern": {soyState: "param-def"}, + "export": {soyState: "param-def"}, "literal": { }, "msg": {}, "fallbackmsg": { noEndTag: true, reduceIndent: true}, @@ -283,6 +285,9 @@ return "type"; } if (match = stream.match(/^\w+/)) { + if (match[0] == 'extern') { + return 'keyword'; + } state.variables = prepend(state.variables, match[0]); state.soyState.pop(); state.soyState.push("param-type"); @@ -553,7 +558,8 @@ state.context = new Context(state.context, state.tag, tag.variableScope ? state.variables : null); // Otherwise close the current context. } else if (endTag) { - if (!state.context || state.context.tag != tagName) { + var isBalancedForExtern = tagName == 'extern' && (state.context && state.context.tag == 'export'); + if (!state.context || ((state.context.tag != tagName) && !isBalancedForExtern)) { tagError = true; } else if (state.context) { if (state.context.kind) { diff --git a/mode/soy/test.js b/mode/soy/test.js index f44263171e..37f252530b 100644 --- a/mode/soy/test.js +++ b/mode/soy/test.js @@ -311,4 +311,8 @@ MT('velog', '[keyword {velog] [variable-2&error $data][keyword }] Logged [keyword {/velog}]'); + + MT('extern', '[keyword {extern] [def renderer]: ([def s]:[type string])=>[type string][keyword }] [keyword {/extern}]'); + + MT('export extern', '[keyword {export] [keyword extern] [def renderer]: ([def s]:[type string])=>[type string][keyword }] [keyword {/extern}]'); })();