Skip to content

Commit d6f0615

Browse files
authored
fix capture groups for "each" statements (#3274)
1 parent 73ea7cf commit d6f0615

File tree

3 files changed

+291
-7
lines changed

3 files changed

+291
-7
lines changed

packages/pug-lexer/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,7 @@ Lexer.prototype = {
10871087

10881088
eachOf: function() {
10891089
var captures;
1090-
if ((captures = /^(?:each|for) (.*) of *([^\n]+)/.exec(this.input))) {
1090+
if ((captures = /^(?:each|for) (.*?) of *([^\n]+)/.exec(this.input))) {
10911091
this.consume(captures[0].length);
10921092
var tok = this.tok('eachOf', captures[1]);
10931093
tok.value = captures[1];

packages/pug-lexer/test/__snapshots__/index.test.js.snap

+281-6
Original file line numberDiff line numberDiff line change
@@ -15468,12 +15468,12 @@ Array [
1546815468
"loc": Object {
1546915469
"end": Object {
1547015470
"column": 1,
15471-
"line": 44,
15471+
"line": 45,
1547215472
},
1547315473
"filename": "<basedir>/packages/pug-lexer/test/cases/each.else.pug",
1547415474
"start": Object {
1547515475
"column": 1,
15476-
"line": 44,
15476+
"line": 45,
1547715477
},
1547815478
},
1547915479
"type": "outdent",
@@ -15482,26 +15482,301 @@ Array [
1548215482
"loc": Object {
1548315483
"end": Object {
1548415484
"column": 1,
15485-
"line": 44,
15485+
"line": 45,
1548615486
},
1548715487
"filename": "<basedir>/packages/pug-lexer/test/cases/each.else.pug",
1548815488
"start": Object {
1548915489
"column": 1,
15490-
"line": 44,
15490+
"line": 45,
1549115491
},
1549215492
},
1549315493
"type": "outdent",
1549415494
},
1549515495
Object {
15496+
"buffer": false,
1549615497
"loc": Object {
1549715498
"end": Object {
15499+
"column": 74,
15500+
"line": 45,
15501+
},
15502+
"filename": "<basedir>/packages/pug-lexer/test/cases/each.else.pug",
15503+
"start": Object {
1549815504
"column": 1,
15499-
"line": 44,
15505+
"line": 45,
15506+
},
15507+
},
15508+
"mustEscape": false,
15509+
"type": "code",
15510+
"val": "var ofKeyword = [{ name: 'tobi', friends: ['loki'] }, { name: 'loki' }]",
15511+
},
15512+
Object {
15513+
"loc": Object {
15514+
"end": Object {
15515+
"column": 1,
15516+
"line": 46,
1550015517
},
1550115518
"filename": "<basedir>/packages/pug-lexer/test/cases/each.else.pug",
1550215519
"start": Object {
1550315520
"column": 1,
15504-
"line": 44,
15521+
"line": 46,
15522+
},
15523+
},
15524+
"type": "newline",
15525+
},
15526+
Object {
15527+
"loc": Object {
15528+
"end": Object {
15529+
"column": 3,
15530+
"line": 46,
15531+
},
15532+
"filename": "<basedir>/packages/pug-lexer/test/cases/each.else.pug",
15533+
"start": Object {
15534+
"column": 1,
15535+
"line": 46,
15536+
},
15537+
},
15538+
"type": "tag",
15539+
"val": "ul",
15540+
},
15541+
Object {
15542+
"loc": Object {
15543+
"end": Object {
15544+
"column": 3,
15545+
"line": 47,
15546+
},
15547+
"filename": "<basedir>/packages/pug-lexer/test/cases/each.else.pug",
15548+
"start": Object {
15549+
"column": 1,
15550+
"line": 47,
15551+
},
15552+
},
15553+
"type": "indent",
15554+
"val": 2,
15555+
},
15556+
Object {
15557+
"code": "ofKeyword",
15558+
"loc": Object {
15559+
"end": Object {
15560+
"column": 24,
15561+
"line": 47,
15562+
},
15563+
"filename": "<basedir>/packages/pug-lexer/test/cases/each.else.pug",
15564+
"start": Object {
15565+
"column": 3,
15566+
"line": 47,
15567+
},
15568+
},
15569+
"type": "eachOf",
15570+
"val": "val",
15571+
"value": "val",
15572+
},
15573+
Object {
15574+
"loc": Object {
15575+
"end": Object {
15576+
"column": 5,
15577+
"line": 48,
15578+
},
15579+
"filename": "<basedir>/packages/pug-lexer/test/cases/each.else.pug",
15580+
"start": Object {
15581+
"column": 1,
15582+
"line": 48,
15583+
},
15584+
},
15585+
"type": "indent",
15586+
"val": 4,
15587+
},
15588+
Object {
15589+
"loc": Object {
15590+
"end": Object {
15591+
"column": 7,
15592+
"line": 48,
15593+
},
15594+
"filename": "<basedir>/packages/pug-lexer/test/cases/each.else.pug",
15595+
"start": Object {
15596+
"column": 5,
15597+
"line": 48,
15598+
},
15599+
},
15600+
"type": "tag",
15601+
"val": "li",
15602+
},
15603+
Object {
15604+
"buffer": true,
15605+
"loc": Object {
15606+
"end": Object {
15607+
"column": 18,
15608+
"line": 48,
15609+
},
15610+
"filename": "<basedir>/packages/pug-lexer/test/cases/each.else.pug",
15611+
"start": Object {
15612+
"column": 7,
15613+
"line": 48,
15614+
},
15615+
},
15616+
"mustEscape": true,
15617+
"type": "code",
15618+
"val": "user.name",
15619+
},
15620+
Object {
15621+
"loc": Object {
15622+
"end": Object {
15623+
"column": 1,
15624+
"line": 50,
15625+
},
15626+
"filename": "<basedir>/packages/pug-lexer/test/cases/each.else.pug",
15627+
"start": Object {
15628+
"column": 1,
15629+
"line": 50,
15630+
},
15631+
},
15632+
"type": "outdent",
15633+
},
15634+
Object {
15635+
"loc": Object {
15636+
"end": Object {
15637+
"column": 1,
15638+
"line": 50,
15639+
},
15640+
"filename": "<basedir>/packages/pug-lexer/test/cases/each.else.pug",
15641+
"start": Object {
15642+
"column": 1,
15643+
"line": 50,
15644+
},
15645+
},
15646+
"type": "outdent",
15647+
},
15648+
Object {
15649+
"loc": Object {
15650+
"end": Object {
15651+
"column": 3,
15652+
"line": 50,
15653+
},
15654+
"filename": "<basedir>/packages/pug-lexer/test/cases/each.else.pug",
15655+
"start": Object {
15656+
"column": 1,
15657+
"line": 50,
15658+
},
15659+
},
15660+
"type": "tag",
15661+
"val": "ul",
15662+
},
15663+
Object {
15664+
"loc": Object {
15665+
"end": Object {
15666+
"column": 3,
15667+
"line": 51,
15668+
},
15669+
"filename": "<basedir>/packages/pug-lexer/test/cases/each.else.pug",
15670+
"start": Object {
15671+
"column": 1,
15672+
"line": 51,
15673+
},
15674+
},
15675+
"type": "indent",
15676+
"val": 2,
15677+
},
15678+
Object {
15679+
"code": "[\\"variable with of keyword\\"]",
15680+
"loc": Object {
15681+
"end": Object {
15682+
"column": 43,
15683+
"line": 51,
15684+
},
15685+
"filename": "<basedir>/packages/pug-lexer/test/cases/each.else.pug",
15686+
"start": Object {
15687+
"column": 3,
15688+
"line": 51,
15689+
},
15690+
},
15691+
"type": "eachOf",
15692+
"val": "val",
15693+
"value": "val",
15694+
},
15695+
Object {
15696+
"loc": Object {
15697+
"end": Object {
15698+
"column": 5,
15699+
"line": 52,
15700+
},
15701+
"filename": "<basedir>/packages/pug-lexer/test/cases/each.else.pug",
15702+
"start": Object {
15703+
"column": 1,
15704+
"line": 52,
15705+
},
15706+
},
15707+
"type": "indent",
15708+
"val": 4,
15709+
},
15710+
Object {
15711+
"loc": Object {
15712+
"end": Object {
15713+
"column": 7,
15714+
"line": 52,
15715+
},
15716+
"filename": "<basedir>/packages/pug-lexer/test/cases/each.else.pug",
15717+
"start": Object {
15718+
"column": 5,
15719+
"line": 52,
15720+
},
15721+
},
15722+
"type": "tag",
15723+
"val": "li",
15724+
},
15725+
Object {
15726+
"buffer": true,
15727+
"loc": Object {
15728+
"end": Object {
15729+
"column": 12,
15730+
"line": 52,
15731+
},
15732+
"filename": "<basedir>/packages/pug-lexer/test/cases/each.else.pug",
15733+
"start": Object {
15734+
"column": 7,
15735+
"line": 52,
15736+
},
15737+
},
15738+
"mustEscape": true,
15739+
"type": "code",
15740+
"val": "val",
15741+
},
15742+
Object {
15743+
"loc": Object {
15744+
"end": Object {
15745+
"column": 12,
15746+
"line": 52,
15747+
},
15748+
"filename": "<basedir>/packages/pug-lexer/test/cases/each.else.pug",
15749+
"start": Object {
15750+
"column": 12,
15751+
"line": 52,
15752+
},
15753+
},
15754+
"type": "outdent",
15755+
},
15756+
Object {
15757+
"loc": Object {
15758+
"end": Object {
15759+
"column": 12,
15760+
"line": 52,
15761+
},
15762+
"filename": "<basedir>/packages/pug-lexer/test/cases/each.else.pug",
15763+
"start": Object {
15764+
"column": 12,
15765+
"line": 52,
15766+
},
15767+
},
15768+
"type": "outdent",
15769+
},
15770+
Object {
15771+
"loc": Object {
15772+
"end": Object {
15773+
"column": 12,
15774+
"line": 52,
15775+
},
15776+
"filename": "<basedir>/packages/pug-lexer/test/cases/each.else.pug",
15777+
"start": Object {
15778+
"column": 12,
15779+
"line": 52,
1550515780
},
1550615781
},
1550715782
"type": "eos",

packages/pug-lexer/test/cases/each.else.pug

+9
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,12 @@ ul
4141
li #{key}: #{val}
4242
else
4343
li user has no details!
44+
45+
- var ofKeyword = [{ name: 'tobi', friends: ['loki'] }, { name: 'loki' }]
46+
ul
47+
each val of ofKeyword
48+
li= user.name
49+
50+
ul
51+
each val of ["variable with of keyword"]
52+
li= val

0 commit comments

Comments
 (0)