Skip to content

Commit

Permalink
Handle optional fields followed by , and no type
Browse files Browse the repository at this point in the history
Fixes #651
  • Loading branch information
sheetalkamat committed Aug 21, 2018
1 parent 5cfc64b commit 94b95df
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 6 deletions.
4 changes: 2 additions & 2 deletions TypeScript.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -588,10 +588,10 @@ 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'
- include: '#type-annotation'
Expand Down
4 changes: 2 additions & 2 deletions TypeScript.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -1791,7 +1791,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 @@ -1810,7 +1810,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*)?(=|:|;|$))))|(?&lt;=\})</string>
)(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\\'|\\)*\')|(\"([^\"\\]|\\\"|\\)*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\?\s*)?(=|:|;|,|$))))|(?&lt;=\})</string>
<key>patterns</key>
<array>
<dict>
Expand Down
4 changes: 2 additions & 2 deletions TypeScriptReact.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -1795,7 +1795,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 @@ -1814,7 +1814,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*)?(=|:|;|$))))|(?&lt;=\})</string>
)(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\\'|\\)*\')|(\"([^\"\\]|\\\"|\\)*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\?\s*)?(=|:|;|,|$))))|(?&lt;=\})</string>
<key>patterns</key>
<array>
<dict>
Expand Down
56 changes: 56 additions & 0 deletions tests/baselines/Issue651.baseline.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
original file
-----------------------------------
interface DagEdge {
a?,
b
}
var a = 1;
-----------------------------------

Grammar: TypeScript.tmLanguage
-----------------------------------
>interface DagEdge {
^^^^^^^^^
source.ts meta.interface.ts storage.type.interface.ts
^
source.ts meta.interface.ts
^^^^^^^
source.ts meta.interface.ts entity.name.type.interface.ts
^
source.ts meta.interface.ts
^
source.ts meta.interface.ts punctuation.definition.block.ts
> a?,
^^^^
source.ts meta.interface.ts meta.field.declaration.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.definition.property.ts variable.object.property.ts
^
source.ts meta.interface.ts meta.field.declaration.ts keyword.operator.optional.ts
^
source.ts meta.interface.ts punctuation.separator.comma.ts
> b
^^^^
source.ts meta.interface.ts meta.field.declaration.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.definition.property.ts variable.object.property.ts
>}
^
source.ts meta.interface.ts punctuation.definition.block.ts
>var a = 1;
^^^
source.ts meta.var.expr.ts storage.type.ts
^
source.ts meta.var.expr.ts
^
source.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts variable.other.readwrite.ts
^
source.ts meta.var.expr.ts meta.var-single-variable.expr.ts
^
source.ts meta.var.expr.ts keyword.operator.assignment.ts
^
source.ts meta.var.expr.ts
^
source.ts meta.var.expr.ts constant.numeric.decimal.ts
^
source.ts punctuation.terminator.statement.ts
5 changes: 5 additions & 0 deletions tests/cases/Issue651.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
interface DagEdge {
a?,
b
}
var a = 1;

0 comments on commit 94b95df

Please sign in to comment.