11import { findLocalDeclarationEnd } from './schema-dsl-local-declarations' ;
22
3- const functionIdentifierPattern = / [ A - Z a - z _ $ ] [ \w $ ] * / g;
3+ const functionIdentifierPattern = / [ $ _ \p{ ID_Start} ] [ $ \u200c \u200d \p{ ID_Continue} ] * / gu;
4+ const simpleFunctionIdentifierPattern = / ^ [ $ _ \p{ ID_Start} ] [ $ \u200c \u200d \p{ ID_Continue} ] * $ / u;
5+ const functionIdentifierPartPattern = / [ $ \u200c \u200d \p{ ID_Continue} ] / u;
46
57export type FunctionScopeInfo = {
68 start : number ;
@@ -19,7 +21,7 @@ function addIdentifiersFromPattern(pattern: string, identifiers: Set<string>): v
1921}
2022
2123function isIdentifierPart ( char : string | undefined ) : boolean {
22- return char !== undefined && / [ A - Z a - z _ $ \d ] / . test ( char ) ;
24+ return char !== undefined && functionIdentifierPartPattern . test ( char ) ;
2325}
2426
2527function splitTopLevel ( source : string , delimiter : string ) : string [ ] {
@@ -114,7 +116,7 @@ function isIndexInRanges(index: number, ranges: ReadonlyArray<{ start: number; e
114116function addBindingIdentifiers ( pattern : string , identifiers : Set < string > ) : void {
115117 let binding = stripTopLevelDefault ( pattern ) . replace ( / ^ \s * \. \. \. / , '' ) . trim ( ) ;
116118 if ( ! binding ) return ;
117- if ( / ^ [ A - Z a - z _ $ ] [ \w $ ] * $ / . test ( binding ) ) {
119+ if ( simpleFunctionIdentifierPattern . test ( binding ) ) {
118120 identifiers . add ( binding ) ;
119121 return ;
120122 }
@@ -314,7 +316,7 @@ function getClassMethodNameBinding(header: string, headerStart: number): Functio
314316 if ( remaining . startsWith ( '[' ) ) {
315317 return null ;
316318 }
317- const match = / ^ # ? ( [ A - Z a - z _ $ ] [ \w $ ] * ) \s * \( / . exec ( remaining ) ;
319+ const match = / ^ # ? ( [ $ _ \p { ID_Start } ] [ $ \u200c \u200d \p { ID_Continue } ] * ) \s * \( / u . exec ( remaining ) ;
318320 if ( ! match ) {
319321 return null ;
320322 }
@@ -335,7 +337,7 @@ function stripClassMethodModifiers(header: string): string {
335337
336338function isClassMethodHeader ( header : string ) : boolean {
337339 const remaining = stripClassMethodModifiers ( header ) ;
338- return remaining . startsWith ( '[' ) || / ^ # ? [ A - Z a - z _ $ ] [ \w $ ] * \s * \( / . test ( remaining ) ;
340+ return remaining . startsWith ( '[' ) || / ^ # ? [ $ _ \p { ID_Start } ] [ $ \u200c \u200d \p { ID_Continue } ] * \s * \( / u . test ( remaining ) ;
339341}
340342
341343function getTrailingClassMethodHeader ( header : string ) : { header : string ; offset : number } | null {
@@ -357,7 +359,7 @@ function isObjectMethodHeader(header: string): boolean {
357359 }
358360 return remaining . startsWith ( '(' )
359361 || remaining . startsWith ( '[' )
360- || / ^ (?: \d + (?: \. \d + ) ? | # ? [ A - Z a - z _ $ ] [ \w $ ] * ) \s * \( / . test ( remaining ) ;
362+ || / ^ (?: \d + (?: \. \d + ) ? | # ? [ $ _ \p { ID_Start } ] [ $ \u200c \u200d \p { ID_Continue } ] * ) \s * \( / u . test ( remaining ) ;
361363}
362364
363365function includeMethodModifiers ( source : string , start : number ) : number {
@@ -424,7 +426,7 @@ function getClassFieldNameBinding(header: string, headerStart: number): Function
424426 if ( remaining . startsWith ( '[' ) ) {
425427 return null ;
426428 }
427- const match = / ^ # ? ( [ A - Z a - z _ $ ] [ \w $ ] * ) / . exec ( remaining ) ;
429+ const match = / ^ # ? ( [ $ _ \p { ID_Start } ] [ $ \u200c \u200d \p { ID_Continue } ] * ) / u . exec ( remaining ) ;
428430 if ( ! match ) {
429431 return null ;
430432 }
@@ -478,7 +480,7 @@ function isClassDeclarationBinding(source: string, classIndex: number): boolean
478480
479481function findClassMemberScopes ( source : string ) : FunctionScopeInfo [ ] {
480482 const scopes : FunctionScopeInfo [ ] = [ ] ;
481- for ( const match of source . matchAll ( / \b c l a s s (?: \s + ( [ A - Z a - z _ $ ] [ \w $ ] * ) ) ? / g ) ) {
483+ for ( const match of source . matchAll ( / \b c l a s s (?: \s + ( [ $ _ \p { ID_Start } ] [ $ \u200c \u200d \p { ID_Continue } ] * ) ) ? / gu ) ) {
482484 const classIndex = match . index ?? 0 ;
483485 const className = match [ 1 ] ;
484486 if ( className ) {
@@ -666,7 +668,7 @@ export function addScopedLocalIdentifiers(
666668 }
667669 declarationPattern . lastIndex = Math . max ( declarationPattern . lastIndex , declarationEnd ) ;
668670 }
669- for ( const match of scopeSource . matchAll ( / \b c l a s s \s + ( [ A - Z a - z _ $ ] [ \w $ ] * ) / g ) ) {
671+ for ( const match of scopeSource . matchAll ( / \b c l a s s \s + ( [ $ _ \p { ID_Start } ] [ $ \u200c \u200d \p { ID_Continue } ] * ) / gu ) ) {
670672 const matchIndex = start + ( match . index ?? 0 ) ;
671673 if ( isIndexInRanges ( matchIndex , excludedRanges ) ) {
672674 continue ;
@@ -711,7 +713,7 @@ export function findNestedFunctionScopes(source: string, rootArrowIndex: number,
711713 const bodyEnd = findMatchingBrace ( source , bodyStart ) ;
712714 if ( bodyEnd > bodyStart ) {
713715 const header = source . slice ( functionIndex , bodyStart ) ;
714- const functionMatch = / f u n c t i o n (?: \s + ( [ A - Z a - z _ $ ] [ \w $ ] * ) ) ? \s * \( ( [ ^ ) ] * ) \) / . exec ( header ) ;
716+ const functionMatch = / f u n c t i o n (?: \s + ( [ $ _ \p { ID_Start } ] [ $ \u200c \u200d \p { ID_Continue } ] * ) ) ? \s * \( ( [ ^ ) ] * ) \) / u . exec ( header ) ;
715717 const boundIdentifiers = new Set < string > ( ) ;
716718 if ( functionMatch ?. [ 1 ] ) {
717719 boundIdentifiers . add ( functionMatch [ 1 ] ) ;
0 commit comments