Skip to content

Commit

Permalink
allow ellipses to occur in jsx elements
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonspark committed Jun 25, 2024
1 parent dc31834 commit 9406cae
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lang/semgrep-grammars/src/Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ test:
# messages when compiling 'parser.c'.
set -e; \
for dir in $$(find . | grep 'grammar.js$$' | xargs -L1 dirname); do \
echo "Test $$(pwd)"; \
echo "Test $$(pwd)/$$dir"; \
(cd "$$dir"; \
show_log() { echo "..."; tail -n 1000 test.log; }; \
if tree-sitter test > test.log 2>&1; then \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = {
*/

semgrep_ellipsis: $ => '...',
semgrep_metavar_ellipsis: $ => /\$\.\.\.[A-Z_][A-Z_0-9]*/,

/* In the expression context, there are LR(1) conflicts with spread and
* rest. I (nmote) don't think that these are true ambiguities, but just in
Expand All @@ -40,6 +41,12 @@ module.exports = {
$.semgrep_expression_ellipsis,
),

_jsx_attribute: ($, previous) => choice(
previous,
$.semgrep_ellipsis,
$.semgrep_metavar_ellipsis
),

// TODO Remove this when we update tree-sitter-typescript past
// https://github.com/tree-sitter/tree-sitter-typescript/pull/239. I (nmote)
// ran into unrelated issues updating it, documented in
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
==================================
JSX with ellipsis
==================================

<Switch .../>

---

(program
(expression_statement
(jsx_self_closing_element
(identifier)
(semgrep_ellipsis))))

==================================
JSX with ellipsis and other props
==================================

<Switch a="b" ... foo={bar}/>

---

(program
(expression_statement
(jsx_self_closing_element
(identifier)
(jsx_attribute
(property_identifier)
(string
(string_fragment)))
(semgrep_ellipsis)
(jsx_attribute
(property_identifier)
(jsx_expression
(identifier))))))

==================================
JSX with metavariable ellipsis
==================================

<Switch $...PROPS/>

---

(program
(expression_statement
(jsx_self_closing_element
(identifier)
(semgrep_metavar_ellipsis))))

0 comments on commit 9406cae

Please sign in to comment.