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

chore(js/ts): allow ellipses to occur in jsx elements #488

Merged
merged 1 commit into from
Jun 27, 2024
Merged
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
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))))
Loading