Skip to content

Commit

Permalink
refactor: separate raw_text usages in svelte statements to make inj…
Browse files Browse the repository at this point in the history
…ections easier
  • Loading branch information
amaanq committed Feb 19, 2024
1 parent afb12a1 commit 04a126d
Show file tree
Hide file tree
Showing 5 changed files with 878 additions and 906 deletions.
40 changes: 16 additions & 24 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ module.exports = grammar(HTML, {
$._implicit_end_tag,
$.raw_text,
$.comment,
$.raw_text_svelte,
$.raw_text_svelte_each,
$.svelte_raw_text,
$.svelte_raw_text_each,
'@',
'#',
'/',
Expand All @@ -42,10 +42,6 @@ module.exports = grammar(HTML, {
/\s+/,
],

inline: $ => [
$._raw_text_svelte,
],

supertypes: $ => [
$._node,
],
Expand Down Expand Up @@ -92,14 +88,14 @@ module.exports = grammar(HTML, {
$.if_end,
),

if_start: $ => seq('{', '#', token.immediate('if'), $._raw_text_svelte, '}'),
if_start: $ => seq('{', '#', token.immediate('if'), $.svelte_raw_text, '}'),

else_if_block: $ => seq(
'{',
':',
token.immediate('else'),
'if',
$._raw_text_svelte,
$.svelte_raw_text,
'}',
repeat($._node),
),
Expand All @@ -126,8 +122,8 @@ module.exports = grammar(HTML, {
'#',
token.immediate('each'),
choice(
$._raw_text_svelte,
seq($._raw_text_svelte_each, 'as', $._raw_text_svelte),
$.svelte_raw_text,
seq(alias($.svelte_raw_text_each, $.svelte_raw_text), 'as', $.svelte_raw_text),
),
'}',
),
Expand All @@ -142,11 +138,11 @@ module.exports = grammar(HTML, {
$.await_end,
),

await_start: $ => seq('{', '#', token.immediate('await'), $._raw_text_svelte, '}'),
await_start: $ => seq('{', '#', token.immediate('await'), $.svelte_raw_text, '}'),

then_block: $ => seq('{', ':', token.immediate('then'), optional($._raw_text_svelte), '}'),
then_block: $ => seq('{', ':', token.immediate('then'), optional($.svelte_raw_text), '}'),

catch_block: $ => seq('{', ':', 'catch', optional($._raw_text_svelte), '}'),
catch_block: $ => seq('{', ':', 'catch', optional($.svelte_raw_text), '}'),

await_end: _ => seq('{', '/', token.immediate('await'), '}'),

Expand All @@ -160,7 +156,7 @@ module.exports = grammar(HTML, {
'{',
'#',
token.immediate('key'),
$._raw_text_svelte,
$.svelte_raw_text,
'}',
),

Expand All @@ -176,43 +172,43 @@ module.exports = grammar(HTML, {
'{',
'#',
token.immediate('snippet'),
$._raw_text_svelte,
$.svelte_raw_text,
'}',
),

snippet_end: _ => seq('{', '/', token.immediate('snippet'), '}'),

expression: $ => seq('{', $._raw_text_svelte, '}'),
expression: $ => seq('{', $.svelte_raw_text, '}'),

html_tag: $ => seq(
'{',
'@',
token.immediate('html'),
$._raw_text_svelte,
$.svelte_raw_text,
'}',
),

const_tag: $ => seq(
'{',
'@',
token.immediate('const'),
$._raw_text_svelte,
$.svelte_raw_text,
'}',
),

debug_tag: $ => seq(
'{',
'@',
token.immediate('debug'),
$._raw_text_svelte,
$.svelte_raw_text,
'}',
),

render_tag: $ => seq(
'{',
'@',
token.immediate('render'),
$._raw_text_svelte,
$.svelte_raw_text,
'}',
),

Expand All @@ -221,9 +217,5 @@ module.exports = grammar(HTML, {
attribute_value: _ => /[^<>{}"'=\s]+/,

text: _ => /[^<>{}&\s]([^<>{}&]*[^<>{}&\s])?/,

_raw_text_svelte: $ => alias($.raw_text_svelte, $.raw_text),

_raw_text_svelte_each: $ => alias($.raw_text_svelte_each, $.raw_text),
},
});
63 changes: 24 additions & 39 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 04a126d

Please sign in to comment.