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

Allow underscore in jsx attribute names #655

Merged
merged 4 commits into from
Aug 23, 2018
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
4 changes: 2 additions & 2 deletions TypeScriptReact.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ uuid: 805375ec-d614-41f5-8993-5843fe63ea82
variables:
#possiblyMultilineArrowExpressionBeforeEndOfLine: ({{typeParameters}})?\(
possiblyMultilineArrow: ((<\s*$)|([\(]\s*([\{\[]\s*)?$)) # during lookup treat ( followed by line end as arrow
jsxTagOrAtrributeIdentifier: '[_$[:alpha:]][-$[:alnum:].]*'
jsxTagOrAtrributeIdentifier: '[_$[:alpha:]][-_$[:alnum:].]*'
jsxTagNamespace: (?:({{jsxTagOrAtrributeIdentifier}})(?<!\.|-)(:))?
jsxTagName: \s*{{jsxTagNamespace}}((?:[a-z][a-z0-9]*|({{jsxTagOrAtrributeIdentifier}}))(?<!\.|-))
jsxOpeningTagWithoutAttributes: (<){{jsxTagName}}?\s*(>)
Expand Down Expand Up @@ -164,7 +164,7 @@ repository:
(?x)
\s*
(?:({{jsxTagOrAtrributeIdentifier}})(:))?
([_$[:alpha:]][-$[:alnum:]]*)
([_$[:alpha:]][-_$[:alnum:]]*)
(?=\s|=|/?>|/\*|//)
captures:
'1': {name: entity.other.attribute-name.namespace.tsx}
Expand Down
22 changes: 11 additions & 11 deletions TypeScriptReact.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -8317,9 +8317,9 @@
<key>jsx-tag-without-attributes-in-expression</key>
<dict>
<key>begin</key>
<string>(?&lt;!\+\+|--)(?&lt;=[({\[,?=&gt;:*]|&amp;&amp;|\|\||\?|^await|[^\._$[:alnum:]]await|^return|[^\._$[:alnum:]]return|^default|[^\._$[:alnum:]]default|^yield|[^\._$[:alnum:]]yield|^)\s*(?=(&lt;)\s*(?:([_$[:alpha:]][-$[:alnum:].]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$[:alpha:]][-$[:alnum:].]*))(?&lt;!\.|-))?\s*(&gt;))</string>
<string>(?&lt;!\+\+|--)(?&lt;=[({\[,?=&gt;:*]|&amp;&amp;|\|\||\?|^await|[^\._$[:alnum:]]await|^return|[^\._$[:alnum:]]return|^default|[^\._$[:alnum:]]default|^yield|[^\._$[:alnum:]]yield|^)\s*(?=(&lt;)\s*(?:([_$[:alpha:]][-_$[:alnum:].]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$[:alpha:]][-_$[:alnum:].]*))(?&lt;!\.|-))?\s*(&gt;))</string>
<key>end</key>
<string>(?!(&lt;)\s*(?:([_$[:alpha:]][-$[:alnum:].]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$[:alpha:]][-$[:alnum:].]*))(?&lt;!\.|-))?\s*(&gt;))</string>
<string>(?!(&lt;)\s*(?:([_$[:alpha:]][-_$[:alnum:].]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$[:alpha:]][-_$[:alnum:].]*))(?&lt;!\.|-))?\s*(&gt;))</string>
<key>patterns</key>
<array>
<dict>
Expand All @@ -8333,9 +8333,9 @@
<key>name</key>
<string>meta.tag.without-attributes.tsx</string>
<key>begin</key>
<string>(&lt;)\s*(?:([_$[:alpha:]][-$[:alnum:].]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$[:alpha:]][-$[:alnum:].]*))(?&lt;!\.|-))?\s*(&gt;)</string>
<string>(&lt;)\s*(?:([_$[:alpha:]][-_$[:alnum:].]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$[:alpha:]][-_$[:alnum:].]*))(?&lt;!\.|-))?\s*(&gt;)</string>
<key>end</key>
<string>(&lt;/)\s*(?:([_$[:alpha:]][-$[:alnum:].]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$[:alpha:]][-$[:alnum:].]*))(?&lt;!\.|-))?\s*(&gt;)</string>
<string>(&lt;/)\s*(?:([_$[:alpha:]][-_$[:alnum:].]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$[:alpha:]][-_$[:alnum:].]*))(?&lt;!\.|-))?\s*(&gt;)</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
Expand Down Expand Up @@ -8418,9 +8418,9 @@
<string>(?x)
(?&lt;!\+\+|--)(?&lt;=[({\[,?=&gt;:*]|&amp;&amp;|\|\||\?|^await|[^\._$[:alnum:]]await|^return|[^\._$[:alnum:]]return|^default|[^\._$[:alnum:]]default|^yield|[^\._$[:alnum:]]yield|^)\s*
(?!&lt;\s*[_$[:alpha:]][_$[:alnum:]]*((\s+extends\s+[^=&gt;])|,)) # look ahead is not type parameter of arrow
(?=(&lt;)\s*(?:([_$[:alpha:]][-$[:alnum:].]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$[:alpha:]][-$[:alnum:].]*))(?&lt;!\.|-))(?=((&lt;\s*)|(\s+))(?!\?)|\/?&gt;))</string>
(?=(&lt;)\s*(?:([_$[:alpha:]][-_$[:alnum:].]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$[:alpha:]][-_$[:alnum:].]*))(?&lt;!\.|-))(?=((&lt;\s*)|(\s+))(?!\?)|\/?&gt;))</string>
<key>end</key>
<string>(?!(&lt;)\s*(?:([_$[:alpha:]][-$[:alnum:].]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$[:alpha:]][-$[:alnum:].]*))(?&lt;!\.|-))(?=((&lt;\s*)|(\s+))(?!\?)|\/?&gt;))</string>
<string>(?!(&lt;)\s*(?:([_$[:alpha:]][-_$[:alnum:].]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$[:alpha:]][-_$[:alnum:].]*))(?&lt;!\.|-))(?=((&lt;\s*)|(\s+))(?!\?)|\/?&gt;))</string>
<key>patterns</key>
<array>
<dict>
Expand All @@ -8434,9 +8434,9 @@
<key>name</key>
<string>meta.tag.tsx</string>
<key>begin</key>
<string>(?=(&lt;)\s*(?:([_$[:alpha:]][-$[:alnum:].]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$[:alpha:]][-$[:alnum:].]*))(?&lt;!\.|-))(?=((&lt;\s*)|(\s+))(?!\?)|\/?&gt;))</string>
<string>(?=(&lt;)\s*(?:([_$[:alpha:]][-_$[:alnum:].]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$[:alpha:]][-_$[:alnum:].]*))(?&lt;!\.|-))(?=((&lt;\s*)|(\s+))(?!\?)|\/?&gt;))</string>
<key>end</key>
<string>(/&gt;)|(?:(&lt;/)\s*(?:([_$[:alpha:]][-$[:alnum:].]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$[:alpha:]][-$[:alnum:].]*))(?&lt;!\.|-))?\s*(&gt;))</string>
<string>(/&gt;)|(?:(&lt;/)\s*(?:([_$[:alpha:]][-_$[:alnum:].]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$[:alpha:]][-_$[:alnum:].]*))(?&lt;!\.|-))?\s*(&gt;))</string>
<key>endCaptures</key>
<dict>
<key>1</key>
Expand Down Expand Up @@ -8479,7 +8479,7 @@
<array>
<dict>
<key>begin</key>
<string>(&lt;)\s*(?:([_$[:alpha:]][-$[:alnum:].]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$[:alpha:]][-$[:alnum:].]*))(?&lt;!\.|-))(?=((&lt;\s*)|(\s+))(?!\?)|\/?&gt;)</string>
<string>(&lt;)\s*(?:([_$[:alpha:]][-_$[:alnum:].]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$[:alpha:]][-_$[:alnum:].]*))(?&lt;!\.|-))(?=((&lt;\s*)|(\s+))(?!\?)|\/?&gt;)</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
Expand Down Expand Up @@ -8681,8 +8681,8 @@
<key>match</key>
<string>(?x)
\s*
(?:([_$[:alpha:]][-$[:alnum:].]*)(:))?
([_$[:alpha:]][-$[:alnum:]]*)
(?:([_$[:alpha:]][-_$[:alnum:].]*)(:))?
([_$[:alpha:]][-_$[:alnum:]]*)
(?=\s|=|/?&gt;|/\*|//)</string>
<key>captures</key>
<dict>
Expand Down
60 changes: 60 additions & 0 deletions tests/baselines/Issues648.baseline.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
original file
-----------------------------------
// @onlyOwnGrammar - As this has jsx
<Test
a=''
b_c='111'
d=''
/>
-----------------------------------

Grammar: TypeScriptReact.tmLanguage
-----------------------------------
>// @onlyOwnGrammar - As this has jsx
^^
source.tsx comment.line.double-slash.tsx punctuation.definition.comment.tsx
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
source.tsx comment.line.double-slash.tsx
><Test
^
source.tsx meta.tag.tsx punctuation.definition.tag.begin.tsx
^^^^
source.tsx meta.tag.tsx entity.name.tag.tsx support.class.component.tsx
> a=''
^^^^
source.tsx meta.tag.tsx meta.tag.attributes.tsx
^
source.tsx meta.tag.tsx meta.tag.attributes.tsx entity.other.attribute-name.tsx
^
source.tsx meta.tag.tsx meta.tag.attributes.tsx keyword.operator.assignment.tsx
^
source.tsx meta.tag.tsx meta.tag.attributes.tsx string.quoted.single.tsx punctuation.definition.string.begin.tsx
^
source.tsx meta.tag.tsx meta.tag.attributes.tsx string.quoted.single.tsx punctuation.definition.string.end.tsx
> b_c='111'
^^^^
source.tsx meta.tag.tsx meta.tag.attributes.tsx
^^^
source.tsx meta.tag.tsx meta.tag.attributes.tsx entity.other.attribute-name.tsx
^
source.tsx meta.tag.tsx meta.tag.attributes.tsx keyword.operator.assignment.tsx
^
source.tsx meta.tag.tsx meta.tag.attributes.tsx string.quoted.single.tsx punctuation.definition.string.begin.tsx
^^^
source.tsx meta.tag.tsx meta.tag.attributes.tsx string.quoted.single.tsx
^
source.tsx meta.tag.tsx meta.tag.attributes.tsx string.quoted.single.tsx punctuation.definition.string.end.tsx
> d=''
^^^^
source.tsx meta.tag.tsx meta.tag.attributes.tsx
^
source.tsx meta.tag.tsx meta.tag.attributes.tsx entity.other.attribute-name.tsx
^
source.tsx meta.tag.tsx meta.tag.attributes.tsx keyword.operator.assignment.tsx
^
source.tsx meta.tag.tsx meta.tag.attributes.tsx string.quoted.single.tsx punctuation.definition.string.begin.tsx
^
source.tsx meta.tag.tsx meta.tag.attributes.tsx string.quoted.single.tsx punctuation.definition.string.end.tsx
>/>
^^
source.tsx meta.tag.tsx punctuation.definition.tag.end.tsx
60 changes: 60 additions & 0 deletions tests/baselines/Issues649.baseline.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
original file
-----------------------------------
// @onlyOwnGrammar - As this has jsx
<Test_Component
a=''
b_c='111'
d=''
/>
-----------------------------------

Grammar: TypeScriptReact.tmLanguage
-----------------------------------
>// @onlyOwnGrammar - As this has jsx
^^
source.tsx comment.line.double-slash.tsx punctuation.definition.comment.tsx
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
source.tsx comment.line.double-slash.tsx
><Test_Component
^
source.tsx meta.tag.tsx punctuation.definition.tag.begin.tsx
^^^^^^^^^^^^^^
source.tsx meta.tag.tsx entity.name.tag.tsx support.class.component.tsx
> a=''
^^^^
source.tsx meta.tag.tsx meta.tag.attributes.tsx
^
source.tsx meta.tag.tsx meta.tag.attributes.tsx entity.other.attribute-name.tsx
^
source.tsx meta.tag.tsx meta.tag.attributes.tsx keyword.operator.assignment.tsx
^
source.tsx meta.tag.tsx meta.tag.attributes.tsx string.quoted.single.tsx punctuation.definition.string.begin.tsx
^
source.tsx meta.tag.tsx meta.tag.attributes.tsx string.quoted.single.tsx punctuation.definition.string.end.tsx
> b_c='111'
^^^^
source.tsx meta.tag.tsx meta.tag.attributes.tsx
^^^
source.tsx meta.tag.tsx meta.tag.attributes.tsx entity.other.attribute-name.tsx
^
source.tsx meta.tag.tsx meta.tag.attributes.tsx keyword.operator.assignment.tsx
^
source.tsx meta.tag.tsx meta.tag.attributes.tsx string.quoted.single.tsx punctuation.definition.string.begin.tsx
^^^
source.tsx meta.tag.tsx meta.tag.attributes.tsx string.quoted.single.tsx
^
source.tsx meta.tag.tsx meta.tag.attributes.tsx string.quoted.single.tsx punctuation.definition.string.end.tsx
> d=''
^^^^
source.tsx meta.tag.tsx meta.tag.attributes.tsx
^
source.tsx meta.tag.tsx meta.tag.attributes.tsx entity.other.attribute-name.tsx
^
source.tsx meta.tag.tsx meta.tag.attributes.tsx keyword.operator.assignment.tsx
^
source.tsx meta.tag.tsx meta.tag.attributes.tsx string.quoted.single.tsx punctuation.definition.string.begin.tsx
^
source.tsx meta.tag.tsx meta.tag.attributes.tsx string.quoted.single.tsx punctuation.definition.string.end.tsx
>/>
^^
source.tsx meta.tag.tsx punctuation.definition.tag.end.tsx
6 changes: 6 additions & 0 deletions tests/cases/Issues648.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// @onlyOwnGrammar - As this has jsx
<Test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add line at the beginning of file to avoid generating ts grammar baseline

// @onlyOwnGrammar - As this has jsx

a=''
b_c='111'
d=''
/>
6 changes: 6 additions & 0 deletions tests/cases/Issues649.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// @onlyOwnGrammar - As this has jsx
<Test_Component
a=''
b_c='111'
d=''
/>