Skip to content

Commit

Permalink
Merge pull request #655 from mjbvz/fix-648
Browse files Browse the repository at this point in the history
Allow underscore in jsx attribute names
  • Loading branch information
mjbvz authored Aug 23, 2018
2 parents e2db601 + 38aa945 commit 6de67c7
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 13 deletions.
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
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=''
/>

0 comments on commit 6de67c7

Please sign in to comment.