Skip to content

Commit

Permalink
Handle field declaration without type or assignment
Browse files Browse the repository at this point in the history
Fixes #643
  • Loading branch information
sheetalkamat committed Aug 2, 2018
1 parent 69d78f0 commit 3c90f24
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 167 deletions.
39 changes: 18 additions & 21 deletions TypeScript.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -586,31 +586,28 @@ repository:

field-declaration:
name: meta.field.declaration.ts
begin: (?x)(?<!\()(?:{{startOfIdentifier}}(readonly)\s+)?(?=\s*{{propertyName}}\s*(\?\s*)?(=|:))
begin: (?x)(?<!\()(?:{{startOfIdentifier}}(readonly)\s+)?(?=\s*{{propertyName}}\s*(\?\s*)?(=|:|;|$))
beginCaptures:
'1': { name: storage.modifier.ts }
end: (?x)(?=\}|;|,|$|(^(?!\s*{{propertyName}}\s*(\?\s*)?(=|:))))|(?<=\})
end: (?x)(?=\}|;|,|$|(^(?!\s*{{propertyName}}\s*(\?\s*)?(=|:|;|$))))|(?<=\})
patterns:
- include: '#variable-initializer'
- begin: (?x)(?={{propertyName}}\s*(\?\s*)?(=|:))
end: (?x)(?=[};,=]|$|(^(?!\s*{{propertyName}}\s*(\?\s*)?(=|:))))|(?<=\})
patterns:
- include: '#type-annotation'
- include: '#string'
- include: '#array-literal'
- include: '#numeric-literal'
- include: '#comment'
# function assignment |
# typeannotation is fn type: < | () | (... | (param: | (param, | (param? | (param= | (param) =>
- match: |-
(?x)({{identifier}})(\?)?(?=(\?\s*)?{{functionLikeAssignmentOrType}})
captures:
'1': { name: meta.definition.property.ts entity.name.function.ts }
'2': { name: keyword.operator.optional.ts }
- name: meta.definition.property.ts variable.object.property.ts
match: '{{identifier}}'
- name: keyword.operator.optional.ts
match: \?
- include: '#type-annotation'
- include: '#string'
- include: '#array-literal'
- include: '#numeric-literal'
- include: '#comment'
# function assignment |
# typeannotation is fn type: < | () | (... | (param: | (param, | (param? | (param= | (param) =>
- match: |-
(?x)({{identifier}})(\?)?(?=(\?\s*)?{{functionLikeAssignmentOrType}})
captures:
'1': { name: meta.definition.property.ts entity.name.function.ts }
'2': { name: keyword.operator.optional.ts }
- name: meta.definition.property.ts variable.object.property.ts
match: '{{identifier}}'
- name: keyword.operator.optional.ts
match: \?

variable-initializer:
patterns:
Expand Down
111 changes: 42 additions & 69 deletions TypeScript.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -1783,7 +1783,7 @@
(?:\b[0-9][0-9_]*(\.)\B)| # 1.
(?:\B(\.)[0-9][0-9_]*\b)| # .1
(?:\b[0-9][0-9_]*\b(?!\.)) # 1
)(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\\'|\\)*\')|(\"([^\"\\]|\\\"|\\)*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\?\s*)?(=|:))</string>
)(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\\'|\\)*\')|(\"([^\"\\]|\\\"|\\)*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\?\s*)?(=|:|;|$))</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
Expand All @@ -1802,61 +1802,36 @@
(?:\b[0-9][0-9_]*(\.)\B)| # 1.
(?:\B(\.)[0-9][0-9_]*\b)| # .1
(?:\b[0-9][0-9_]*\b(?!\.)) # 1
)(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\\'|\\)*\')|(\"([^\"\\]|\\\"|\\)*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\?\s*)?(=|:))))|(?&lt;=\})</string>
)(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\\'|\\)*\')|(\"([^\"\\]|\\\"|\\)*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\?\s*)?(=|:|;|$))))|(?&lt;=\})</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#variable-initializer</string>
</dict>
<dict>
<key>begin</key>
<string>(?x)(?=((\b(?&lt;!\$)0(x|X)[0-9a-fA-F][0-9a-fA-F_]*\b(?!\$))|(\b(?&lt;!\$)0(b|B)[01][01_]*\b(?!\$))|(\b(?&lt;!\$)0(o|O)?[0-7][0-7_]*\b(?!\$))|((?&lt;!\$)(?:
(?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # 1.1E+3
(?:\b[0-9][0-9_]*(\.)[eE][+-]?[0-9][0-9_]*\b)| # 1.E+3
(?:\B(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # .1E+3
(?:\b[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # 1E+3
(?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*\b)| # 1.1
(?:\b[0-9][0-9_]*(\.)\B)| # 1.
(?:\B(\.)[0-9][0-9_]*\b)| # .1
(?:\b[0-9][0-9_]*\b(?!\.)) # 1
)(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\\'|\\)*\')|(\"([^\"\\]|\\\"|\\)*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\?\s*)?(=|:))</string>
<key>end</key>
<string>(?x)(?=[};,=]|$|(^(?!\s*((\b(?&lt;!\$)0(x|X)[0-9a-fA-F][0-9a-fA-F_]*\b(?!\$))|(\b(?&lt;!\$)0(b|B)[01][01_]*\b(?!\$))|(\b(?&lt;!\$)0(o|O)?[0-7][0-7_]*\b(?!\$))|((?&lt;!\$)(?:
(?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # 1.1E+3
(?:\b[0-9][0-9_]*(\.)[eE][+-]?[0-9][0-9_]*\b)| # 1.E+3
(?:\B(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # .1E+3
(?:\b[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # 1E+3
(?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*\b)| # 1.1
(?:\b[0-9][0-9_]*(\.)\B)| # 1.
(?:\B(\.)[0-9][0-9_]*\b)| # .1
(?:\b[0-9][0-9_]*\b(?!\.)) # 1
)(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\\'|\\)*\')|(\"([^\"\\]|\\\"|\\)*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\?\s*)?(=|:))))|(?&lt;=\})</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#type-annotation</string>
</dict>
<dict>
<key>include</key>
<string>#string</string>
</dict>
<dict>
<key>include</key>
<string>#array-literal</string>
</dict>
<dict>
<key>include</key>
<string>#numeric-literal</string>
</dict>
<dict>
<key>include</key>
<string>#comment</string>
</dict>
<dict>
<key>match</key>
<string>(?x)([_$[:alpha:]][_$[:alnum:]]*)(\?)?(?=(\?\s*)?\s*
<key>include</key>
<string>#type-annotation</string>
</dict>
<dict>
<key>include</key>
<string>#string</string>
</dict>
<dict>
<key>include</key>
<string>#array-literal</string>
</dict>
<dict>
<key>include</key>
<string>#numeric-literal</string>
</dict>
<dict>
<key>include</key>
<string>#comment</string>
</dict>
<dict>
<key>match</key>
<string>(?x)([_$[:alpha:]][_$[:alnum:]]*)(\?)?(?=(\?\s*)?\s*
# function assignment |
(=\s*(
((async\s+)?(
Expand Down Expand Up @@ -1929,33 +1904,31 @@
)
))
)))</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>meta.definition.property.ts entity.name.function.ts</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>keyword.operator.optional.ts</string>
</dict>
</dict>
</dict>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>meta.definition.property.ts variable.object.property.ts</string>
<key>match</key>
<string>[_$[:alpha:]][_$[:alnum:]]*</string>
<string>meta.definition.property.ts entity.name.function.ts</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>keyword.operator.optional.ts</string>
<key>match</key>
<string>\?</string>
</dict>
</array>
</dict>
</dict>
<dict>
<key>name</key>
<string>meta.definition.property.ts variable.object.property.ts</string>
<key>match</key>
<string>[_$[:alpha:]][_$[:alnum:]]*</string>
</dict>
<dict>
<key>name</key>
<string>keyword.operator.optional.ts</string>
<key>match</key>
<string>\?</string>
</dict>
</array>
</dict>
Expand Down
111 changes: 42 additions & 69 deletions TypeScriptReact.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -1787,7 +1787,7 @@
(?:\b[0-9][0-9_]*(\.)\B)| # 1.
(?:\B(\.)[0-9][0-9_]*\b)| # .1
(?:\b[0-9][0-9_]*\b(?!\.)) # 1
)(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\\'|\\)*\')|(\"([^\"\\]|\\\"|\\)*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\?\s*)?(=|:))</string>
)(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\\'|\\)*\')|(\"([^\"\\]|\\\"|\\)*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\?\s*)?(=|:|;|$))</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
Expand All @@ -1806,61 +1806,36 @@
(?:\b[0-9][0-9_]*(\.)\B)| # 1.
(?:\B(\.)[0-9][0-9_]*\b)| # .1
(?:\b[0-9][0-9_]*\b(?!\.)) # 1
)(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\\'|\\)*\')|(\"([^\"\\]|\\\"|\\)*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\?\s*)?(=|:))))|(?&lt;=\})</string>
)(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\\'|\\)*\')|(\"([^\"\\]|\\\"|\\)*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\?\s*)?(=|:|;|$))))|(?&lt;=\})</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#variable-initializer</string>
</dict>
<dict>
<key>begin</key>
<string>(?x)(?=((\b(?&lt;!\$)0(x|X)[0-9a-fA-F][0-9a-fA-F_]*\b(?!\$))|(\b(?&lt;!\$)0(b|B)[01][01_]*\b(?!\$))|(\b(?&lt;!\$)0(o|O)?[0-7][0-7_]*\b(?!\$))|((?&lt;!\$)(?:
(?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # 1.1E+3
(?:\b[0-9][0-9_]*(\.)[eE][+-]?[0-9][0-9_]*\b)| # 1.E+3
(?:\B(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # .1E+3
(?:\b[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # 1E+3
(?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*\b)| # 1.1
(?:\b[0-9][0-9_]*(\.)\B)| # 1.
(?:\B(\.)[0-9][0-9_]*\b)| # .1
(?:\b[0-9][0-9_]*\b(?!\.)) # 1
)(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\\'|\\)*\')|(\"([^\"\\]|\\\"|\\)*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\?\s*)?(=|:))</string>
<key>end</key>
<string>(?x)(?=[};,=]|$|(^(?!\s*((\b(?&lt;!\$)0(x|X)[0-9a-fA-F][0-9a-fA-F_]*\b(?!\$))|(\b(?&lt;!\$)0(b|B)[01][01_]*\b(?!\$))|(\b(?&lt;!\$)0(o|O)?[0-7][0-7_]*\b(?!\$))|((?&lt;!\$)(?:
(?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # 1.1E+3
(?:\b[0-9][0-9_]*(\.)[eE][+-]?[0-9][0-9_]*\b)| # 1.E+3
(?:\B(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # .1E+3
(?:\b[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # 1E+3
(?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*\b)| # 1.1
(?:\b[0-9][0-9_]*(\.)\B)| # 1.
(?:\B(\.)[0-9][0-9_]*\b)| # .1
(?:\b[0-9][0-9_]*\b(?!\.)) # 1
)(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\\'|\\)*\')|(\"([^\"\\]|\\\"|\\)*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\?\s*)?(=|:))))|(?&lt;=\})</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#type-annotation</string>
</dict>
<dict>
<key>include</key>
<string>#string</string>
</dict>
<dict>
<key>include</key>
<string>#array-literal</string>
</dict>
<dict>
<key>include</key>
<string>#numeric-literal</string>
</dict>
<dict>
<key>include</key>
<string>#comment</string>
</dict>
<dict>
<key>match</key>
<string>(?x)([_$[:alpha:]][_$[:alnum:]]*)(\?)?(?=(\?\s*)?\s*
<key>include</key>
<string>#type-annotation</string>
</dict>
<dict>
<key>include</key>
<string>#string</string>
</dict>
<dict>
<key>include</key>
<string>#array-literal</string>
</dict>
<dict>
<key>include</key>
<string>#numeric-literal</string>
</dict>
<dict>
<key>include</key>
<string>#comment</string>
</dict>
<dict>
<key>match</key>
<string>(?x)([_$[:alpha:]][_$[:alnum:]]*)(\?)?(?=(\?\s*)?\s*
# function assignment |
(=\s*(
((async\s+)?(
Expand Down Expand Up @@ -1933,33 +1908,31 @@
)
))
)))</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>meta.definition.property.tsx entity.name.function.tsx</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>keyword.operator.optional.tsx</string>
</dict>
</dict>
</dict>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>meta.definition.property.tsx variable.object.property.tsx</string>
<key>match</key>
<string>[_$[:alpha:]][_$[:alnum:]]*</string>
<string>meta.definition.property.tsx entity.name.function.tsx</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>keyword.operator.optional.tsx</string>
<key>match</key>
<string>\?</string>
</dict>
</array>
</dict>
</dict>
<dict>
<key>name</key>
<string>meta.definition.property.tsx variable.object.property.tsx</string>
<key>match</key>
<string>[_$[:alpha:]][_$[:alnum:]]*</string>
</dict>
<dict>
<key>name</key>
<string>keyword.operator.optional.tsx</string>
<key>match</key>
<string>\?</string>
</dict>
</array>
</dict>
Expand Down
6 changes: 3 additions & 3 deletions tests/baselines/Issue642.baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ Grammar: TypeScript.tmLanguage
^
source.ts meta.class.ts
^^^^^^^^
source.ts meta.class.ts storage.modifier.ts
source.ts meta.class.ts meta.field.declaration.ts storage.modifier.ts
^
source.ts meta.class.ts
source.ts meta.class.ts meta.field.declaration.ts
^^^^^
source.ts meta.class.ts variable.other.readwrite.ts
source.ts meta.class.ts meta.field.declaration.ts meta.definition.property.ts variable.object.property.ts
^
source.ts meta.class.ts punctuation.terminator.statement.ts
>}
Expand Down
Loading

0 comments on commit 3c90f24

Please sign in to comment.