Skip to content

Commit

Permalink
Fix multiple JSX tags
Browse files Browse the repository at this point in the history
Fixes #11
  • Loading branch information
deathaxe committed Nov 8, 2024
1 parent 436abca commit f484a82
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 1 deletion.
24 changes: 24 additions & 0 deletions Syntaxes/Embeddings/TSX (for Astro).sublime-syntax
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
%YAML 1.2
---
# http://www.sublimetext.com/docs/syntax.html
scope: source.tsx.embedded.astro
version: 2
hidden: true

extends: Packages/JavaScript/TSX.sublime-syntax

contexts:

jsx-meta:
# add support for multiple elements
# https://docs.astro.build/en/basics/astro-syntax/#multiple-elements
- meta_include_prototype: false
- meta_scope: meta.jsx.js
- match: '<(?=\s*[/>{{identifier_start}}])'
scope: punctuation.definition.tag.begin.js
push: jsx-tag-attributes-top
- include: else-pop

jsx-tag-attributes:
- meta_prepend: true
- include: HTML (Astro).sublime-syntax#astro-directives
2 changes: 1 addition & 1 deletion Syntaxes/HTML (Astro).sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -553,5 +553,5 @@ contexts:
- match: \}
scope: punctuation.section.interpolation.end.astro
pop: 1
- include: scope:source.tsx#script
- include: scope:source.tsx.embedded.astro#script
apply_prototype: true
87 changes: 87 additions & 0 deletions tests/syntax_test_astro.astro
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,90 @@
// ^ punctuation.section.interpolation.end.astro
// ^^ punctuation.definition.tag.end.astro
</Layout>

// Dynamic HTML

<ul>{items.map((item) => (<li>{item}</li>))}</ul>
//^^ meta.tag
//^ entity.name.tag.block.any.html
// ^ punctuation.definition.tag.end.html
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.interpolation.astro
// ^ punctuation.section.interpolation.begin.astro
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.tsx.embedded.astro
// ^^^^^ variable.other
// ^ punctuation.accessor
// ^^^ meta.function-call variable.function
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call meta.group
// ^^^^^^^^^^^^^^^^^ meta.block meta.group
// ^^^^^^^^^^^^^^^ meta.jsx
// ^^^^ meta.tag
// ^^^^^^ meta.interpolation
// ^^^^^ meta.tag
// ^^^^^ meta.tag

{visible && <p>Show me!</p>}
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.interpolation.astro
//^ punctuation.section.interpolation.begin.astro
// ^^^^^^^^^^^^^^^^^^^^^^^^^^ source.tsx.embedded.astro
// ^^^^^^^ variable.other
// ^^ keyword.operator.logical.js
// ^^^^^^^^^^^^^^^ meta.jsx.js
// ^^^ meta.tag
// ^^^^ meta.tag
// ^ punctuation.section.interpolation.end.astro

{visible ? <p>Show me!</p> : <p>Else show me!</p>}
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.interpolation.astro
//^ punctuation.section.interpolation.begin.astro
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.tsx.embedded.astro
// ^^^^^^^ variable.other
// ^ keyword.operator.ternary.js
// ^^^^^^^^^^^^^^^^ meta.jsx.js
// ^^^ meta.tag
// ^^^^ meta.tag
// ^ keyword.operator.ternary.js
// ^^^^^^^^^^^^^^^^^^^^ meta.jsx.js
// ^^^ meta.tag
// ^^^^ meta.tag
// ^ punctuation.section.interpolation.end.astro

// Multiple Elements

{(<p>Show</p><p>me</p>)}
//^^^^^^^^^^^^^^^^^^^^^^^^ meta.interpolation.astro
//^ punctuation.section.interpolation.begin.astro
// ^^^^^^^^^^^^^^^^^^^^^^ source.tsx.embedded.astro meta.group.js
// ^ punctuation.section.group.begin.js
// ^^^^^^^^^^^^^^^^^^^^ meta.jsx.js
// ^^^ meta.tag
// ^^^^^^^ meta.tag
// ^^^^ meta.tag
// ^ punctuation.section.interpolation.end.astro

// https://github.com/SublimeText/Astro/issues/11

{VITE_USE_VITE_WEB_COMPONENTS && (
<script type="module" src="http://localhost:5173/@vite/client" is:inline></script>
<script type="module" src="http://localhost:5173/src/main.js" is:inline></script>
// ^ meta.tag punctuation.definition.tag.begin.js
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.tag
// ^^^^^^ entity.name.tag.native.js
// ^^^^ entity.other.attribute-name.js
// ^ punctuation.separator.key-value.js
// ^^^^^^^^ string.quoted.double.js
// ^ punctuation.definition.string.begin.js
// ^ punctuation.definition.string.end.js
// ^^^ entity.other.attribute-name.js
// ^ punctuation.separator.key-value.js
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double.js
// ^ punctuation.definition.string.begin.js
// ^ punctuation.definition.string.end.js
// ^^^^^^^^^ meta.attribute-with-value.astro
// ^^ keyword.control.directive.astro
// ^ punctuation.separator.key-value.astro
// ^^^^^^ variable.parameter.astro
// ^ punctuation.definition.tag.end.js
// ^^ punctuation.definition.tag.begin.js
// ^^^^^^ entity.name.tag.native.js
// ^ punctuation.definition.tag.end.js
)}

0 comments on commit f484a82

Please sign in to comment.