Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Fix arrow functions inside ternary expressions #408

Merged
merged 6 commits into from
Aug 23, 2016
Merged
Show file tree
Hide file tree
Changes from 2 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
125 changes: 99 additions & 26 deletions grammars/javascript.cson
Original file line number Diff line number Diff line change
Expand Up @@ -279,16 +279,12 @@
(?<!\\.)\\b(super|this|arguments)(?!\\s*:)\\b
|
(?<=\\?)\\s*(super|this|arguments)(?=\\s*:)
|
(?<=[\\s}:;]case|^case)\\s+(super|this|arguments)(?=\\s*:)
'''
'captures':
'1':
'name': 'variable.language.js'
'2':
'name': 'variable.language.js'
'3':
'name': 'variable.language.js'
}
{
# [async] function [name](params)
Expand Down Expand Up @@ -899,12 +895,11 @@
'name': 'meta.control.yield.js'
}
{
'match': '(?<!\\.)\\b(await|break|case|catch|continue|do|else|finally|for|if|import|package|return|switch|throw|try|while|with)(?!\\s*:)\\b'
'match': '(?<!\\.)\\b(await|break|catch|continue|do|else|finally|for|if|import|package|return|throw|try|while|with)(?!\\s*:)\\b'
'name': 'keyword.control.js'
}
{
'match': '(?<!\\.)\\b(default)\\b'
'name': 'keyword.control.js'
'include': '#switch_statement'
}
{
'match': '(?<!\\.)\\b(delete|in|of|instanceof|new|typeof|void)(?!\\s*:)\\b'
Expand All @@ -919,40 +914,30 @@
(?<!\\.)\\b(true|false)(?!\\s*:)\\b
|
(?<=\\?)\\s*(true|false)(?=\\s*:)
|
(?<=[\\s}:;]case|^case)\\s+(true|false)(?=\\s*:)
'''
'captures':
'1':
'name': 'constant.language.boolean.$1.js'
'2':
'name': 'constant.language.boolean.$2.js'
'3':
'name': 'constant.language.boolean.$3.js'
}
{
'match': '''(?x)
(?<!\\.)\\b(null)(?!\\s*:)\\b
|
(?<=\\?)\\s*(null)(?=\\s*:)
|
(?<=[\\s}:;]case|^case)\\s+(null)(?=\\s*:)
'''
'captures':
'1':
'name': 'constant.language.null.js'
'2':
'name': 'constant.language.null.js'
'3':
'name': 'constant.language.null.js'
}
{
'match': '''(?x)
(?<!\\.)\\b(debugger)(?!\\s*:)\\b
|
(?<=\\?)\\s*(debugger)(?=\\s*:)
|
(?<=[\\s}:;]case|^case)\\s+(debugger)(?=\\s*:)
'''
'captures':
'1':
Expand Down Expand Up @@ -991,16 +976,12 @@
(?<!\\.)\\b(module|exports|__filename|__dirname|global|process)(?!\\s*:)\\b
|
(?<=\\?)\\s*(module|exports|__filename|__dirname|global|process)(?=\\s*:)
|
(?<=[\\s}:;]case|^case)\\s+(module|exports|__filename|__dirname|global|process)(?=\\s*:)
'''
'captures':
'1':
'name': 'support.variable.js'
'2':
'name': 'support.variable.js'
'3':
'name': 'support.variable.js'
}
{
'match': '\\b(Infinity|NaN|undefined)\\b'
Expand All @@ -1022,6 +1003,29 @@
}
]
}
{
'begin': '\\?'
'beginCaptures':
'0':
'name': 'keyword.operator.ternary.js'
'end': ':'
'endCaptures':
'0':
'name': 'keyword.operator.ternary.js'
'patterns': [
{
'match': '(\\w+)(?=\\s*:)'
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain what this match does in more detail?

In addition, why is the second $self needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See 157241d. There is no need to include $self here. Though most of the rules must be moved to the repo and it also requires addition testing, so I kept it as is for now. The second $self includes everything else between ? and :

'captures':
'1':
'patterns': [
'include': '$self'
]
}
{
'include': '$self'
}
]
}
{
'include': '#operators'
}
Expand Down Expand Up @@ -1180,11 +1184,7 @@
'name': 'keyword.operator.bitwise.js'
}
{
'match': '\\?|:'
'name': 'keyword.operator.js'
}
{
'match': '='
'match': '=|:'
'name': 'keyword.operator.assignment.js'
}
{
Expand Down Expand Up @@ -1730,3 +1730,76 @@
]
}
]
'switch_statement':
'patterns': [
{
# switch(expression) {...}
'begin': '\\bswitch\\b'
'beginCaptures':
'0':
'name': 'keyword.control.switch.js'
'end': '}'
'endCaptures':
'0':
'name': 'punctuation.definition.section.switch-block.end.bracket.curly.js'
'name': 'meta.switch-statement.js'
'patterns': [
{
'begin': '\\('
'beginCaptures':
'0':
'name': 'punctuation.definition.switch-expression.begin.bracket.round.js'
'end': '\\)'
'endCaptures':
'0':
'name': 'punctuation.definition.switch-expression.end.bracket.round.js'
'patterns': [
'include': '$self'
]
}
{
'begin': '{'
'beginCaptures':
'0':
'name': 'punctuation.definition.section.switch-block.begin.bracket.curly.js'
'end': '(?=})'
'patterns': [
{
'begin': '\\bcase\\b'
'beginCaptures':
'0':
'name': 'keyword.control.case.js'
'end': ':'
'endCaptures':
'0':
'name': 'punctuation.definition.section.case-statement.js'
'patterns': [
{
'match': '(\\w+)(?=\\s*:)'
'captures':
'1':
'patterns': [
'include': '$self'
]
}
{
'include': '$self'
}
]
}
{
'match': '(?:^\\s*)?\\b(default)\\b\\s*(:)'
'captures':
'1':
'name': 'keyword.control.default.js'
'2':
'name': 'punctuation.definition.section.case-statement.js'
}
{
'include': '$self'
}
]
}
]
}
]
Loading