Skip to content

Commit

Permalink
/ followed by parenthesized expression is arithmetic division instead…
Browse files Browse the repository at this point in the history
… of start of regexp

Fixes #377
  • Loading branch information
sheetalkamat committed Dec 8, 2016
1 parent e7aa4da commit 3ee427b
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 4 deletions.
4 changes: 2 additions & 2 deletions TypeScript.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -1564,8 +1564,8 @@ repository:
match: \+\+
- name: keyword.operator.arithmetic.ts
match: '%|\*|/|-|\+'
# capture the arithmetic sign followed by variable so that it is not interpreted as regex
- match: (?<=[_$[:alnum:]])\s*(/)(?![/*])
# capture the arithmetic sign followed by variable or parenthesized expression so that it is not interpreted as regex
- match: (?<=[_$[:alnum:])])\s*(/)(?![/*])
captures:
'1': { name: keyword.operator.arithmetic.ts }

Expand Down
2 changes: 1 addition & 1 deletion TypeScript.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -4356,7 +4356,7 @@
</dict>
<dict>
<key>match</key>
<string>(?&lt;=[_$[:alnum:]])\s*(/)(?![/*])</string>
<string>(?&lt;=[_$[:alnum:])])\s*(/)(?![/*])</string>
<key>captures</key>
<dict>
<key>1</key>
Expand Down
2 changes: 1 addition & 1 deletion TypeScriptReact.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -4338,7 +4338,7 @@
</dict>
<dict>
<key>match</key>
<string>(?&lt;=[_$[:alnum:]])\s*(/)(?![/*])</string>
<string>(?&lt;=[_$[:alnum:])])\s*(/)(?![/*])</string>
<key>captures</key>
<dict>
<key>1</key>
Expand Down
122 changes: 122 additions & 0 deletions tests/baselines/Issue377.baseline.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
original file
-----------------------------------
dt = ((dt[0] * 1e9 + dt[1]) / 1e6).toFixed(3).replace(/\.?0+$/, '') + 'ms';

-----------------------------------

Grammar: TypeScript.tmLanguage
-----------------------------------
>dt = ((dt[0] * 1e9 + dt[1]) / 1e6).toFixed(3).replace(/\.?0+$/, '') + 'ms';
^^
source.ts variable.other.readwrite.ts
^
source.ts
^
source.ts keyword.operator.assignment.ts
^
source.ts
^
source.ts meta.brace.round.ts
^
source.ts meta.brace.round.ts
^^
source.ts variable.other.readwrite.ts
^
source.ts meta.array.literal.ts meta.brace.square.ts
^
source.ts meta.array.literal.ts constant.numeric.decimal.ts
^
source.ts meta.array.literal.ts meta.brace.square.ts
^
source.ts
^
source.ts keyword.operator.arithmetic.ts
^
source.ts
^^^
source.ts constant.numeric.decimal.ts
^
source.ts
^
source.ts keyword.operator.arithmetic.ts
^
source.ts
^^
source.ts variable.other.readwrite.ts
^
source.ts meta.array.literal.ts meta.brace.square.ts
^
source.ts meta.array.literal.ts constant.numeric.decimal.ts
^
source.ts meta.array.literal.ts meta.brace.square.ts
^
source.ts meta.brace.round.ts
^
source.ts
^
source.ts keyword.operator.arithmetic.ts
^
source.ts
^^^
source.ts constant.numeric.decimal.ts
^
source.ts meta.brace.round.ts
^
source.ts punctuation.accessor.ts
^^^^^^^
source.ts entity.name.function.ts
^
source.ts meta.brace.round.ts
^
source.ts constant.numeric.decimal.ts
^
source.ts meta.brace.round.ts
^
source.ts punctuation.accessor.ts
^^^^^^^
source.ts support.function.ts
^
source.ts meta.brace.round.ts
^
source.ts string.regex.ts punctuation.definition.string.begin.ts
^^
source.ts string.regex.ts constant.character.escape.backslash.regexp
^
source.ts string.regex.ts keyword.operator.quantifier.regexp
^
source.ts string.regex.ts
^
source.ts string.regex.ts keyword.operator.quantifier.regexp
^
source.ts string.regex.ts keyword.control.anchor.regexp
^
source.ts string.regex.ts punctuation.definition.string.end.ts
^
source.ts punctuation.separator.comma.ts
^
source.ts
^
source.ts string.quoted.single.ts punctuation.definition.string.begin.ts
^
source.ts string.quoted.single.ts punctuation.definition.string.end.ts
^
source.ts meta.brace.round.ts
^
source.ts
^
source.ts keyword.operator.arithmetic.ts
^
source.ts
^
source.ts string.quoted.single.ts punctuation.definition.string.begin.ts
^^
source.ts string.quoted.single.ts
^
source.ts string.quoted.single.ts punctuation.definition.string.end.ts
^
source.ts punctuation.terminator.statement.ts
^^
source.ts
>
^
source.ts
1 change: 1 addition & 0 deletions tests/cases/Issue377.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dt = ((dt[0] * 1e9 + dt[1]) / 1e6).toFixed(3).replace(/\.?0+$/, '') + 'ms';

0 comments on commit 3ee427b

Please sign in to comment.