Skip to content

Commit 7844a3c

Browse files
author
Wliu
authored
Merge pull request atom#494 from Cutlery-Drawer/array-hang
Fix atom#493: Remove matching of nested braces in computed keys
2 parents 4146e0f + 123c4c8 commit 7844a3c

File tree

2 files changed

+2
-86
lines changed

2 files changed

+2
-86
lines changed

grammars/javascript.cson

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,12 +472,12 @@
472472
(
473473
\\b(get|set) # Property getter/setter: get foo(){}
474474
(?:\\s+|(?=\\[)) # Followed by whitespace or square bracket
475-
)?
475+
)?+
476476
( # Method name
477477
\\b[a-zA-Z_$][\\w$]* # Fixed name
478478
|
479479
\\[ # Computed property key
480-
.*?[^\\[\\]\\s].*? # Contains at least one non-brace character
480+
[^\\[\\]]++ # Contains at least one non-brace character
481481
\\]
482482
)
483483
\\s*\\(\\s* # Start of arguments list

spec/javascript-spec.coffee

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,90 +1188,6 @@ describe "JavaScript grammar", ->
11881188
expect(tokens[11]).toEqual value: '{', scopes: ['source.js', 'punctuation.definition.function.body.begin.bracket.curly.js']
11891189
expect(tokens[13]).toEqual value: '}', scopes: ['source.js', 'punctuation.definition.function.body.end.bracket.curly.js']
11901190
1191-
{tokens} = grammar.tokenizeLine('get [ "Win" + bar[2] + quaz() ](){ }')
1192-
expect(tokens[0]).toEqual value: 'get', scopes: ['source.js', 'meta.function.method.definition.js', 'keyword.operator.getter.js']
1193-
expect(tokens[2]).toEqual value: '[', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'punctuation.definition.computed-key.begin.bracket.square.js']
1194-
expect(tokens[4]).toEqual value: '"', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'string.quoted.double.js', 'punctuation.definition.string.begin.js']
1195-
expect(tokens[5]).toEqual value: 'Win', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'string.quoted.double.js']
1196-
expect(tokens[6]).toEqual value: '"', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'string.quoted.double.js', 'punctuation.definition.string.end.js']
1197-
expect(tokens[8]).toEqual value: '+', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'keyword.operator.js']
1198-
expect(tokens[10]).toEqual value: 'bar', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'variable.parameter.property.js']
1199-
expect(tokens[11]).toEqual value: '[', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'meta.brace.square.js']
1200-
expect(tokens[12]).toEqual value: '2', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'constant.numeric.decimal.js']
1201-
expect(tokens[13]).toEqual value: ']', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'meta.brace.square.js']
1202-
expect(tokens[15]).toEqual value: '+', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'keyword.operator.js']
1203-
expect(tokens[17]).toEqual value: 'quaz', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'meta.function-call.js', 'entity.name.function.js']
1204-
expect(tokens[18]).toEqual value: '(', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'meta.function-call.js', 'meta.arguments.js', 'punctuation.definition.arguments.begin.bracket.round.js']
1205-
expect(tokens[19]).toEqual value: ')', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'meta.function-call.js', 'meta.arguments.js', 'punctuation.definition.arguments.end.bracket.round.js']
1206-
expect(tokens[21]).toEqual value: ']', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'punctuation.definition.computed-key.end.bracket.square.js']
1207-
expect(tokens[22]).toEqual value: '(', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.parameters.js', 'punctuation.definition.parameters.begin.bracket.round.js']
1208-
expect(tokens[23]).toEqual value: ')', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.parameters.js', 'punctuation.definition.parameters.end.bracket.round.js']
1209-
expect(tokens[24]).toEqual value: '{', scopes: ['source.js', 'punctuation.definition.function.body.begin.bracket.curly.js']
1210-
expect(tokens[26]).toEqual value: '}', scopes: ['source.js', 'punctuation.definition.function.body.end.bracket.curly.js']
1211-
1212-
{tokens} = grammar.tokenizeLine('get [\'string\' [ quaz()[2 + 2]] + this + "ABC" ](){ },')
1213-
expect(tokens[0]).toEqual value: 'get', scopes: ['source.js', 'meta.function.method.definition.js', 'keyword.operator.getter.js']
1214-
expect(tokens[2]).toEqual value: '[', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'punctuation.definition.computed-key.begin.bracket.square.js']
1215-
expect(tokens[3]).toEqual value: '\'', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'string.quoted.single.js', 'punctuation.definition.string.begin.js']
1216-
expect(tokens[4]).toEqual value: 'string', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'string.quoted.single.js']
1217-
expect(tokens[5]).toEqual value: '\'', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'string.quoted.single.js', 'punctuation.definition.string.end.js']
1218-
expect(tokens[7]).toEqual value: '[', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'meta.brace.square.js']
1219-
expect(tokens[9]).toEqual value: 'quaz', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'meta.function-call.js', 'entity.name.function.js']
1220-
expect(tokens[10]).toEqual value: '(', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'meta.function-call.js', 'meta.arguments.js', 'punctuation.definition.arguments.begin.bracket.round.js']
1221-
expect(tokens[11]).toEqual value: ')', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'meta.function-call.js', 'meta.arguments.js', 'punctuation.definition.arguments.end.bracket.round.js']
1222-
expect(tokens[12]).toEqual value: '[', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'meta.brace.square.js']
1223-
expect(tokens[13]).toEqual value: '2', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'constant.numeric.decimal.js']
1224-
expect(tokens[15]).toEqual value: '+', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'keyword.operator.js']
1225-
expect(tokens[17]).toEqual value: '2', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'constant.numeric.decimal.js']
1226-
expect(tokens[18]).toEqual value: ']', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'meta.brace.square.js']
1227-
expect(tokens[19]).toEqual value: ']', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'meta.brace.square.js']
1228-
expect(tokens[21]).toEqual value: '+', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'keyword.operator.js']
1229-
expect(tokens[23]).toEqual value: 'this', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'variable.language.js']
1230-
expect(tokens[25]).toEqual value: '+', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'keyword.operator.js']
1231-
expect(tokens[27]).toEqual value: '"', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'string.quoted.double.js', 'punctuation.definition.string.begin.js']
1232-
expect(tokens[28]).toEqual value: 'ABC', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'string.quoted.double.js']
1233-
expect(tokens[29]).toEqual value: '"', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'string.quoted.double.js', 'punctuation.definition.string.end.js']
1234-
expect(tokens[31]).toEqual value: ']', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'punctuation.definition.computed-key.end.bracket.square.js']
1235-
expect(tokens[32]).toEqual value: '(', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.parameters.js', 'punctuation.definition.parameters.begin.bracket.round.js']
1236-
expect(tokens[33]).toEqual value: ')', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.parameters.js', 'punctuation.definition.parameters.end.bracket.round.js']
1237-
expect(tokens[34]).toEqual value: '{', scopes: ['source.js', 'punctuation.definition.function.body.begin.bracket.curly.js']
1238-
expect(tokens[36]).toEqual value: '}', scopes: ['source.js', 'punctuation.definition.function.body.end.bracket.curly.js']
1239-
expect(tokens[37]).toEqual value: ',', scopes: ['source.js', 'meta.delimiter.object.comma.js']
1240-
1241-
{tokens} = grammar.tokenizeLine('set [\'string\' + ([ quaz()[2 + 2]]) + this + "ABC" ](k = 2){ }')
1242-
expect(tokens[0]).toEqual value: 'set', scopes: ['source.js', 'meta.function.method.definition.js', 'keyword.operator.setter.js']
1243-
expect(tokens[2]).toEqual value: '[', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'punctuation.definition.computed-key.begin.bracket.square.js']
1244-
expect(tokens[3]).toEqual value: '\'', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'string.quoted.single.js', 'punctuation.definition.string.begin.js']
1245-
expect(tokens[4]).toEqual value: 'string', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'string.quoted.single.js']
1246-
expect(tokens[5]).toEqual value: '\'', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'string.quoted.single.js', 'punctuation.definition.string.end.js']
1247-
expect(tokens[7]).toEqual value: '+', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'keyword.operator.js']
1248-
expect(tokens[9]).toEqual value: '(', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'meta.brace.round.js']
1249-
expect(tokens[10]).toEqual value: '[', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'meta.brace.square.js']
1250-
expect(tokens[12]).toEqual value: 'quaz', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'meta.function-call.js', 'entity.name.function.js']
1251-
expect(tokens[13]).toEqual value: '(', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'meta.function-call.js', 'meta.arguments.js', 'punctuation.definition.arguments.begin.bracket.round.js']
1252-
expect(tokens[14]).toEqual value: ')', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'meta.function-call.js', 'meta.arguments.js', 'punctuation.definition.arguments.end.bracket.round.js']
1253-
expect(tokens[15]).toEqual value: '[', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'meta.brace.square.js']
1254-
expect(tokens[16]).toEqual value: '2', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'constant.numeric.decimal.js']
1255-
expect(tokens[18]).toEqual value: '+', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'keyword.operator.js']
1256-
expect(tokens[20]).toEqual value: '2', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'constant.numeric.decimal.js']
1257-
expect(tokens[21]).toEqual value: ']', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'meta.brace.square.js']
1258-
expect(tokens[22]).toEqual value: ']', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'meta.brace.square.js']
1259-
expect(tokens[23]).toEqual value: ')', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'meta.brace.round.js']
1260-
expect(tokens[25]).toEqual value: '+', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'keyword.operator.js']
1261-
expect(tokens[27]).toEqual value: 'this', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'variable.language.js']
1262-
expect(tokens[29]).toEqual value: '+', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'keyword.operator.js']
1263-
expect(tokens[31]).toEqual value: '"', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'string.quoted.double.js', 'punctuation.definition.string.begin.js']
1264-
expect(tokens[32]).toEqual value: 'ABC', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'string.quoted.double.js']
1265-
expect(tokens[33]).toEqual value: '"', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'string.quoted.double.js', 'punctuation.definition.string.end.js']
1266-
expect(tokens[35]).toEqual value: ']', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.computed-key.js', 'punctuation.definition.computed-key.end.bracket.square.js']
1267-
expect(tokens[36]).toEqual value: '(', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.parameters.js', 'punctuation.definition.parameters.begin.bracket.round.js']
1268-
expect(tokens[37]).toEqual value: 'k', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.parameters.js', 'variable.parameter.function.js']
1269-
expect(tokens[39]).toEqual value: '=', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.parameters.js', 'keyword.operator.assignment.js']
1270-
expect(tokens[41]).toEqual value: '2', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.parameters.js', 'constant.numeric.decimal.js']
1271-
expect(tokens[42]).toEqual value: ')', scopes: ['source.js', 'meta.function.method.definition.js', 'meta.parameters.js', 'punctuation.definition.parameters.end.bracket.round.js']
1272-
expect(tokens[43]).toEqual value: '{', scopes: ['source.js', 'punctuation.definition.function.body.begin.bracket.curly.js']
1273-
expect(tokens[45]).toEqual value: '}', scopes: ['source.js', 'punctuation.definition.function.body.end.bracket.curly.js']
1274-
12751191
it "tokenizes constructors", ->
12761192
{tokens} = grammar.tokenizeLine('constructor(p1, p2) { this.p1 = p1; }')
12771193
expect(tokens[0]).toEqual value: 'constructor', scopes: ['source.js', 'meta.function.js', 'entity.name.function.constructor.js']

0 commit comments

Comments
 (0)