File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -93,6 +93,9 @@ class Builder {
9393
9494 /** @var {string} _implodeString String to join with. */
9595 this . _implodeString = ''
96+
97+ /** @var {array} _captureNames Save capture names to map */
98+ this . _captureNames = [ ]
9699 }
97100
98101 /**********************************************************/
@@ -254,9 +257,14 @@ class Builder {
254257 * Create capture group of given conditions.
255258 *
256259 * @param {Closure|Builder|string } condition Anonymous function with its Builder as a first parameter.
260+ * @param {String } name
257261 * @return {Builder }
258262 */
259- capture ( conditions ) {
263+ capture ( conditions , name ) {
264+ if ( name ) {
265+ this . _captureNames . push ( name )
266+ }
267+
260268 this . _validateAndAddMethodType ( METHOD_TYPE_GROUP , METHOD_TYPES_ALLOWED_FOR_CHARACTERS )
261269
262270 return this . _addClosure ( new Builder ( ) . _extends ( '(%s)' ) , conditions )
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ const SimpleMethod = require('../Methods/SimpleMethod')
66const ToMethod = require ( '../Methods/ToMethod' )
77const TimesMethod = require ( '../Methods/TimesMethod' )
88const AndMethod = require ( '../Methods/AndMethod' )
9+ const AsMethod = require ( '../Methods/AsMethod' )
910
1011const SyntaxException = require ( '../../Exceptions/Syntax' )
1112
@@ -49,7 +50,7 @@ const mapper = {
4950 'exactly' : { 'class' : TimesMethod , 'method' : 'exactly' } ,
5051 'at least' : { 'class' : TimesMethod , 'method' : 'atLeast' } ,
5152 'between' : { 'class' : AndMethod , 'method' : 'between' } ,
52- 'capture' : { 'class' : DefaultMethod , 'method' : 'capture' }
53+ 'capture' : { 'class' : AsMethod , 'method' : 'capture' }
5354}
5455
5556/**
Original file line number Diff line number Diff line change 1+ 'use strict'
2+
3+ const Method = require ( './Method' )
4+
5+ /**
6+ * Method having simple parameter(s) ignoring "as".
7+ */
8+ class AsMethod extends Method {
9+ /**
10+ * @inheritdoc
11+ */
12+ setParameters ( parameters ) {
13+ parameters = parameters . filter ( ( parameter ) => {
14+ if ( typeof parameter !== 'string' ) {
15+ return true
16+ }
17+
18+ const lower = parameter . toLowerCase ( )
19+ return lower !== 'as'
20+ } )
21+
22+ return super . setParameters ( parameters )
23+ }
24+ }
25+
26+ module . exports = AsMethod
You can’t perform that action at this time.
0 commit comments