Skip to content

Commit 82d0f4a

Browse files
axellewAxel Lewenhaupt
andauthored
[soy mode] Support template type
Co-authored-by: Axel Lewenhaupt <[email protected]>
1 parent a0179ed commit 82d0f4a

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

mode/soy/soy.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,11 @@
256256
// Otherwise
257257
return "variable";
258258
}
259+
if (match = stream.match(/^\$([\w]+)/)) {
260+
state.soyState.pop();
261+
return ref(state.variables, match[1], !state.lookupVariables);
262+
}
263+
259264
stream.next();
260265
return null;
261266

@@ -300,6 +305,9 @@
300305
} else if (peekChar == "[") {
301306
state.soyState.push('param-type-record');
302307
return null;
308+
} else if (peekChar == "(") {
309+
state.soyState.push('param-type-template');
310+
return null;
303311
} else if (peekChar == "<") {
304312
state.soyState.push('param-type-parameter');
305313
return null;
@@ -334,6 +342,19 @@
334342
stream.next();
335343
return null;
336344

345+
case "param-type-template":
346+
if (stream.match(/[>]/)) {
347+
state.soyState.pop();
348+
state.soyState.push('param-type');
349+
return null;
350+
}
351+
if (stream.match(/^\w+/)) {
352+
state.soyState.push('param-type');
353+
return "def";
354+
}
355+
stream.next();
356+
return null;
357+
337358
case "var-def":
338359
if (match = stream.match(/^\$([\w]+)/)) {
339360
state.variables = prepend(state.variables, match[1]);

mode/soy/test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,13 @@
178178
'[keyword {/template}]',
179179
'');
180180

181+
MT('param-type-template',
182+
'[keyword {template] [def .foo][keyword }]',
183+
' [keyword {@param] [def renderer]: ([def s]:[type string])=>[type html][keyword }]',
184+
' [keyword {call] [variable-2 $renderer] [keyword /}]',
185+
'[keyword {/template}]',
186+
'');
187+
181188
MT('single-quote-strings',
182189
'[keyword {][string "foo"] [string \'bar\'][keyword }]',
183190
'');

0 commit comments

Comments
 (0)