grammars-v4 icon indicating copy to clipboard operation
grammars-v4 copied to clipboard

JSX: issue parsing tag with a dot

Open juli1 opened this issue 2 years ago • 2 comments

Hello,

I am using the JSX grammar. When parsing the following code, the HTML tag of Layout.Header, the HTML tag found is Header. A tag with a dot is not recognized. For example, in the code below, the HTML tag should be Layout.Header and not Layout.

Any idea how to address this?

Thanks,

// Layout.jsx

export { Header, Content, Footer }

// App.jsx
import * as Layout from "./Layout";

return (
    <div>
    {/*
              These components don't return any .[naming] info
              and they are missing the props
              */}
    <Layout.Header user='Daniel' />
    <Layout.Content color='purple' />
    <Layout.Footer />
    </div>
)

// look at the 5th and 6th console results

juli1 avatar Dec 18 '22 22:12 juli1

I think you want to change htmlTagName. See the diff below. I don't know if it's correct because I'm not familiar with jsx. Nor does there seem to be a formal spec for it.

diff --git a/javascript/jsx/JavaScriptParser.g4 b/javascript/jsx/JavaScriptParser.g4
index 9746a164..5ad2de30 100644
--- a/javascript/jsx/JavaScriptParser.g4
+++ b/javascript/jsx/JavaScriptParser.g4
@@ -385,9 +385,7 @@ htmlTagClosingName
     ;

 htmlTagName
-    : TagName
-    | keyword
-    | Identifier
+    : (TagName | keyword | Identifier) ('.' (TagName | keyword | Identifier))*
     ;

 htmlAttribute

kaby76 avatar Dec 20 '22 17:12 kaby76

It seems to work perfectly! Thank you so much!

juli1 avatar Dec 20 '22 22:12 juli1