Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AstroJSX syntax [WIP] #828

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions packages/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@
"source.stylus": "stylus",
"source.js": "javascript",
"source.ts": "typescript",
"source.json": "json",
"source.tsx": "typescriptreact"
"source.json": "json"
},
"unbalancedBracketScopes": [
"keyword.operator.relational",
Expand All @@ -176,19 +175,24 @@
{
"scopeName": "text.html.markdown.astro",
"path": "./syntaxes/markdown.astro.tmLanguage.json",
"injectTo": ["text.html.markdown", "source.astro"],
"injectTo": ["text.html.markdown"],
"embeddedLanguages": {
"meta.embedded.block.astro": "astro",
"meta.embedded.block.astro.frontmatter": "typescriptreact"
}
},
{
"scopeName": "source.astroJSX",
"path": "./syntaxes/astroJSX.tmLanguage.json",
"injectTo": ["source.astro"]
}
]
},
"scripts": {
"prebuild": "cd ../ts-plugin && pnpm build",
"build": "pnpm prebuild && node scripts/build.mjs -- --minify",
"dev": "node scripts/build.mjs -- --watch",
"build:grammar": "npx js-yaml syntaxes/astro.tmLanguage.src.yaml > syntaxes/astro.tmLanguage.json",
"build:grammar": "npx js-yaml syntaxes/astro.tmLanguage.src.yaml > syntaxes/astro.tmLanguage.json && npx js-yaml syntaxes/astroJSX.tmLanguage.src.yaml > syntaxes/astroJSX.tmLanguage.json",
"test": "pnpm test:vscode && pnpm test:grammar",
"test:vscode": "node ./test/runTest.js",
"test:grammar": "pnpm build:grammar && node ./test/grammar/test.mjs",
Expand Down
4 changes: 2 additions & 2 deletions packages/vscode/syntaxes/astro.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@
"name": "punctuation.section.embedded.end.astro"
}
},
"contentName": "meta.embedded.expression.astro source.tsx",
"contentName": "meta.embedded.expression.astro source.astroJSX",
"patterns": [
{
"begin": "\\G\\s*(?={)",
Expand All @@ -260,7 +260,7 @@
]
},
{
"include": "source.tsx"
"include": "source.astroJSX"
}
]
}
Expand Down
4 changes: 2 additions & 2 deletions packages/vscode/syntaxes/astro.tmLanguage.src.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,13 @@ repository:
end: \}
beginCaptures: { 0: { name: punctuation.section.embedded.begin.astro } }
endCaptures: { 0: { name: punctuation.section.embedded.end.astro } }
contentName: meta.embedded.expression.astro source.tsx
contentName: meta.embedded.expression.astro source.astroJSX
patterns:
# Object literals - usually used within attributes.
- begin: \G\s*(?={)
end: (?<=})
patterns: [include: source.tsx#object-literal]
- include: source.tsx
- include: source.astroJSX

# Entities
# Adapted from https://github.com/microsoft/vscode/blob/12605e53052114df3ac512c59936e69c331f0337/extensions/html/syntaxes/html.tmLanguage.json#L532
Expand Down
37 changes: 37 additions & 0 deletions packages/vscode/syntaxes/astroJSX.tmLanguage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "AstroJSX",
"scopeName": "source.astroJSX",
"patterns": [
{
"include": "#comments"
},
{
"include": "#jsx"
}
],
"repository": {
"comments": {
"begin": "<!--",
"end": "-->",
"captures": {
"0": {
"name": "punctuation.definition.comment.astroJSX"
}
},
"name": "comment.block.astroJSX",
"patterns": [
{
"match": "\\G-?>|<!--(?!>)|<!-(?=-->)|--!>",
"name": "invalid.illegal.characters-not-allowed-here.astroJSX"
}
]
},
"jsx": {
"patterns": [
{
"include": "source.js.jsx"
}
]
}
}
}
36 changes: 36 additions & 0 deletions packages/vscode/syntaxes/astroJSX.tmLanguage.src.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
# Let's take down Microsoft! 🦜🏴‍☠️
# Astro expression syntax is really similar to JSX, but it's not JSX.
# So, we need to create a new syntax for it, where we include the JSX syntax as a base,
# and add some Astro specific patterns over it.
name: AstroJSX
scopeName: source.astroJSX

patterns:
- include: '#comments'
- include: '#jsx'

repository:
# ----------
# HTML PATTERNS

# Basic HTML comments - not supported by JSX in expressions, but Astro does.
comments:
begin: <!--
end: -->
captures:
0: { name: punctuation.definition.comment.astroJSX }
name: comment.block.astroJSX
patterns:
# Validations
- {
match: '\G-?>|<!--(?!>)|<!-(?=-->)|--!>',
name: invalid.illegal.characters-not-allowed-here.astroJSX,
}

# ----------
# JSX PATTERNS
# The foundation for AstroJSX.
jsx:
patterns:
- include: 'source.js.jsx'
2 changes: 1 addition & 1 deletion packages/vscode/syntaxes/markdown.astro.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"contentName": "meta.embedded.block.astro.frontmatter",
"patterns": [
{
"include": "source.tsx"
"include": "source.ts"
}
]
},
Expand Down
Loading