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

Added support for properties #146

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion grammars/javascript.cson
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,10 @@
'match': '(?<=\\.)(s(hape|ystemId|c(heme|ope|rolling)|ta(ndby|rt)|ize|ummary|pecified|e(ctionRowIndex|lected(Index)?)|rc)|h(space|t(tpEquiv|mlFor)|e(ight|aders)|ref(lang)?)|n(o(Resize|tation(s|Name)|Shade|Href|de(Name|Type|Value)|Wrap)|extSibling|ame)|c(h(ildNodes|Off|ecked|arset)?|ite|o(ntent|o(kie|rds)|de(Base|Type)?|l(s|Span|or)|mpact)|ell(s|Spacing|Padding)|l(ear|assName)|aption)|t(ype|Bodies|itle|Head|ext|a(rget|gName)|Foot)|i(sMap|ndex|d|m(plementation|ages))|o(ptions|wnerDocument|bject)|d(i(sabled|r)|o(c(type|umentElement)|main)|e(clare|f(er|ault(Selected|Checked|Value)))|at(eTime|a))|useMap|p(ublicId|arentNode|r(o(file|fileEnd|mpt)|eviousSibling))|e(n(ctype|tities)|vent|lements)|v(space|ersion|alue(Type)?|Link|Align)|URL|f(irstChild|orm(s)?|ace|rame(Border)?)|width|l(ink(s)?|o(ngDesc|wSrc)|a(stChild|ng|bel))|a(nchors|c(ce(ssKey|pt(Charset)?)|tion)|ttributes|pplets|l(t|ign)|r(chive|eas)|xis|Link|bbr)|r(ow(s|Span|Index)|ules|e(v|ferrer|l|adOnly))|m(ultiple|e(thod|dia)|a(rgin(Height|Width)|xLength))|b(o(dy|rder)|ackground|gColor))\\b'
'name': 'support.constant.dom.js'
}
{
'match': '(?<=(?:[a-zA-Z_$0-9]\\.))([a-zA-Z_$][a-zA-Z_$0-9]*)'
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems a bit out-of-place since the surrounding capture rules all start with support. Is there by any chance a better place to put it?

'name': 'entity.name.property.js'
}
{
'match': '\\b(ELEMENT_NODE|ATTRIBUTE_NODE|TEXT_NODE|CDATA_SECTION_NODE|ENTITY_REFERENCE_NODE|ENTITY_NODE|PROCESSING_INSTRUCTION_NODE|COMMENT_NODE|DOCUMENT_NODE|DOCUMENT_TYPE_NODE|DOCUMENT_FRAGMENT_NODE|NOTATION_NODE|INDEX_SIZE_ERR|DOMSTRING_SIZE_ERR|HIERARCHY_REQUEST_ERR|WRONG_DOCUMENT_ERR|INVALID_CHARACTER_ERR|NO_DATA_ALLOWED_ERR|NO_MODIFICATION_ALLOWED_ERR|NOT_FOUND_ERR|NOT_SUPPORTED_ERR|INUSE_ATTRIBUTE_ERR)\\b'
'name': 'support.constant.dom.js'
Expand Down Expand Up @@ -573,7 +577,7 @@
'name': 'meta.method.js'
'comment': 'match regular function like: function myFunc(arg) { … }'

'begin': '\\b((?!(?:break|case|catch|continue|do|else|finally|for|function|if|export|import|package|return|switch|throw|try|while|with)[\\s\\(])(?:[a-zA-Z_$][a-zA-Z_$0-9]*))\\s*(\\()(?=(?:[^\\(\\)]*)?\\)\\s*\\{)'
'begin': '\\b((?!(?:break|case|catch|continue|do|else|finally|for|function|if|export|import|package|return|switch|throw|try|while|with)[\\s\\(])(?:[a-zA-Z_$][a-zA-Z_$0-9]*))\\s*(\\()(?![^a-zA-Z_$\\.\\)])(?=(?:[^\\(\\)]*)?\\)\\s*\\{)'
'beginCaptures':
'1':
'name': 'entity.name.function.js'
Expand Down
7 changes: 7 additions & 0 deletions spec/javascript-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ describe "Javascript grammar", ->
expect(tokens[6]).toEqual value: '42', scopes: ['source.js', 'constant.numeric.js']
expect(tokens[7]).toEqual value: ';', scopes: ['source.js', 'punctuation.terminator.statement.js']

describe "Properties", ->
it "tokenizes properties", ->
{tokens} = grammar.tokenizeLine('obj.prop1.prop2.prop3')
expect(tokens[2]).toEqual value: 'prop1', scopes: ['source.js', 'entity.name.property.js']
expect(tokens[4]).toEqual value: 'prop2', scopes: ['source.js', 'entity.name.property.js']
expect(tokens[6]).toEqual value: 'prop3', scopes: ['source.js', 'entity.name.property.js']

describe "ES6 string templates", ->
it "tokenizes them as strings", ->
{tokens} = grammar.tokenizeLine('`hey ${name}`')
Expand Down