@@ -318,34 +318,30 @@ public class JavaScriptEnvironment: ComponentBase {
318318 private var producingProperties : [ ILType : [ ( group: String , property: String ) ] ] = [ : ]
319319 private var subtypes : [ ILType : [ ILType ] ] = [ : ]
320320
321- private let validIdentifierOrIndex : Regex < AnyRegexOutput > ?
322- private let validDotNotationName : Regex < AnyRegexOutput > ?
323- private let validPropertyIndex : Regex < AnyRegexOutput > ?
324-
325- public init ( additionalBuiltins: [ String : ILType ] = [ : ] , additionalObjectGroups: [ ObjectGroup ] = [ ] , additionalEnumerations: [ ILType ] = [ ] ) {
321+ private struct ValidationRegexes {
326322 // A simple approximation of a valid JS identifier (used in dot
327323 // notation and for property and method names).
328- let simpleId = " [_$a-zA-Z][_$a-zA-Z0-9]* "
324+ static let simpleId = " [_$a-zA-Z][_$a-zA-Z0-9]* "
329325
330326 // A non-negative integer (with no leading zero) for index access
331327 // without quotes.
332- let index = " [1-9] \\ d*|0 "
333-
334- // Initialize regular expressions to determine valid property
335- // identifiers:
328+ static let index = " [1-9] \\ d*|0 "
336329
337330 // We support simple identifiers and non-negative numbers. Other
338331 // names will be quoted.
339332 // We don't support unquoted doubles.
340- self . validIdentifierOrIndex = try ! Regex ( " ^( \( index) | \( simpleId) )$ " )
333+ static let identifierOrIndex = try ! Regex ( " ^( \( index) | \( simpleId) )$ " )
341334
342335 // For dot notation we only support simple identifiers. We don't
343336 // support all possible names according to JS spec.
344337 // Unsupported names will be accessed with bracket notation.
345- self . validDotNotationName = try ! Regex ( " ^( \( simpleId) )$ " )
338+ static let dotNotationName = try ! Regex ( " ^( \( simpleId) )$ " )
346339
347340 // Valid indexes to use in bracket notation without quotes.
348- self . validPropertyIndex = try ! Regex ( " ^( \( index) )$ " )
341+ static let propertyIndex = try ! Regex ( " ^( \( index) )$ " )
342+ }
343+
344+ public init ( additionalBuiltins: [ String : ILType ] = [ : ] , additionalObjectGroups: [ ObjectGroup ] = [ ] , additionalEnumerations: [ ILType ] = [ ] ) {
349345
350346 super. init ( name: " JavaScriptEnvironment " )
351347
@@ -1005,15 +1001,15 @@ public class JavaScriptEnvironment: ComponentBase {
10051001 }
10061002
10071003 func isValidIdentifierOrIndex( _ name: String ) -> Bool {
1008- return ( try ? validIdentifierOrIndex ? . wholeMatch ( in: name) ) != nil
1004+ return ( try ? ValidationRegexes . identifierOrIndex . wholeMatch ( in: name) ) != nil
10091005 }
10101006
10111007 func isValidDotNotationName( _ name: String ) -> Bool {
1012- return ( try ? validDotNotationName ? . wholeMatch ( in: name) ) != nil
1008+ return ( try ? ValidationRegexes . dotNotationName . wholeMatch ( in: name) ) != nil
10131009 }
10141010
10151011 func isValidPropertyIndex( _ name: String ) -> Bool {
1016- return ( try ? validPropertyIndex ? . wholeMatch ( in: name) ) != nil
1012+ return ( try ? ValidationRegexes . propertyIndex . wholeMatch ( in: name) ) != nil
10171013 }
10181014}
10191015
0 commit comments