@@ -123,6 +123,7 @@ typedef enum eTokenType {
123
123
TOKEN_REGEXP ,
124
124
TOKEN_POSTFIX_OPERATOR ,
125
125
TOKEN_STAR ,
126
+ TOKEN_HASH ,
126
127
/* To handle Babel's decorators.
127
128
* Used only in readTokenFull or lower functions. */
128
129
TOKEN_ATMARK ,
@@ -487,7 +488,7 @@ static int makeJsRefTagsForNameChain (char *name_chain, const tokenInfo *token,
487
488
488
489
static int makeJsTagCommon (const tokenInfo * const token , const jsKind kind ,
489
490
vString * const signature , vString * const inheritance ,
490
- bool anonymous , bool nulltag )
491
+ bool anonymous , bool is_private , bool nulltag )
491
492
{
492
493
int index = CORK_NIL ;
493
494
const char * name = vStringValue (token -> string );
@@ -526,6 +527,9 @@ static int makeJsTagCommon (const tokenInfo *const token, const jsKind kind,
526
527
updateTagLine (& e , token -> lineNumber , token -> filePosition );
527
528
e .extensionFields .scopeIndex = scope ;
528
529
530
+ if (is_private )
531
+ e .extensionFields .access = "private" ;
532
+
529
533
#ifdef DO_TRACING
530
534
{
531
535
const char * scope_str = getNameStringForCorkIndex (scope );
@@ -573,19 +577,26 @@ static int makeJsTagCommon (const tokenInfo *const token, const jsKind kind,
573
577
static int makeJsTag (const tokenInfo * const token , const jsKind kind ,
574
578
vString * const signature , vString * const inheritance )
575
579
{
576
- return makeJsTagCommon (token , kind , signature , inheritance , false, false);
580
+ return makeJsTagCommon (token , kind , signature , inheritance , false, false, false);
581
+ }
582
+
583
+ static int makeJsTagMaybePrivate (const tokenInfo * const token , const jsKind kind ,
584
+ vString * const signature , vString * const inheritance ,
585
+ const bool is_private )
586
+ {
587
+ return makeJsTagCommon (token , kind , signature , inheritance , false, is_private , false);
577
588
}
578
589
579
590
static int makeJsNullTag (const tokenInfo * const token , const jsKind kind ,
580
591
vString * const signature , vString * const inheritance )
581
592
{
582
- return makeJsTagCommon (token , kind , signature , inheritance , false, true);
593
+ return makeJsTagCommon (token , kind , signature , inheritance , false, false, true);
583
594
}
584
595
585
596
static int makeClassTagCommon (tokenInfo * const token , vString * const signature ,
586
597
vString * const inheritance , bool anonymous )
587
598
{
588
- return makeJsTagCommon (token , JSTAG_CLASS , signature , inheritance , anonymous , false);
599
+ return makeJsTagCommon (token , JSTAG_CLASS , signature , inheritance , anonymous , false, false );
589
600
}
590
601
591
602
static int makeClassTag (tokenInfo * const token , vString * const signature ,
@@ -598,7 +609,7 @@ static int makeFunctionTagCommon (tokenInfo *const token, vString *const signatu
598
609
bool generator , bool anonymous )
599
610
{
600
611
return makeJsTagCommon (token , generator ? JSTAG_GENERATOR : JSTAG_FUNCTION , signature , NULL ,
601
- anonymous , false);
612
+ anonymous , false, false );
602
613
}
603
614
604
615
static int makeFunctionTag (tokenInfo * const token , vString * const signature , bool generator )
@@ -1300,11 +1311,11 @@ static void readTokenFullRaw (tokenInfo *const token, bool include_newlines, vSt
1300
1311
case '#' :
1301
1312
/* skip shebang in case of e.g. Node.js scripts */
1302
1313
if (token -> lineNumber > 1 )
1303
- token -> type = TOKEN_UNDEFINED ;
1314
+ token -> type = TOKEN_HASH ;
1304
1315
else if ((c = getcFromInputFile ()) != '!' )
1305
1316
{
1306
1317
ungetcToInputFile (c );
1307
- token -> type = TOKEN_UNDEFINED ;
1318
+ token -> type = TOKEN_HASH ;
1308
1319
}
1309
1320
else
1310
1321
{
@@ -1530,7 +1541,7 @@ static int parseMethodsInAnonymousObject (tokenInfo *const token)
1530
1541
anonGenerate (anon_object -> string , "anonymousObject" , JSTAG_VARIABLE );
1531
1542
anon_object -> type = TOKEN_IDENTIFIER ;
1532
1543
1533
- index = makeJsTagCommon (anon_object , JSTAG_VARIABLE , NULL , NULL , true, false);
1544
+ index = makeJsTagCommon (anon_object , JSTAG_VARIABLE , NULL , NULL , true, false, false );
1534
1545
if (! parseMethods (token , index , false))
1535
1546
{
1536
1547
/* If no method is found, the anonymous object
@@ -2222,6 +2233,7 @@ static bool parseMethods (tokenInfo *const token, int class_index,
2222
2233
! isType (token , TOKEN_SEMICOLON ))
2223
2234
{
2224
2235
bool is_generator = false;
2236
+ bool is_private = false;
2225
2237
bool is_shorthand = false; /* ES6 shorthand syntax */
2226
2238
bool is_computed_name = false; /* ES6 computed property name */
2227
2239
bool is_dynamic_prop = false;
@@ -2235,6 +2247,11 @@ static bool parseMethods (tokenInfo *const token, int class_index,
2235
2247
is_generator = true;
2236
2248
readToken (token );
2237
2249
}
2250
+ else if (isType (token , TOKEN_HASH ))
2251
+ {
2252
+ is_private = true;
2253
+ readToken (token );
2254
+ }
2238
2255
2239
2256
if (isType (token , TOKEN_OPEN_SQUARE ))
2240
2257
{
@@ -2352,7 +2369,16 @@ static bool parseMethods (tokenInfo *const token, int class_index,
2352
2369
else if (is_setter )
2353
2370
kind = JSTAG_SETTER ;
2354
2371
2355
- index_for_name = makeJsTag (name , kind , signature , NULL );
2372
+ if (is_private )
2373
+ {
2374
+ vString * s = vStringNew ();
2375
+ vStringPut (s , '#' );
2376
+ vStringCat (s , name -> string );
2377
+ vStringCopy (name -> string , s );
2378
+ vStringDelete (s );
2379
+ }
2380
+
2381
+ index_for_name = makeJsTagMaybePrivate (name , kind , signature , NULL , is_private );
2356
2382
parseBlock (token , index_for_name );
2357
2383
2358
2384
/*
@@ -2447,8 +2473,17 @@ static bool parseMethods (tokenInfo *const token, int class_index,
2447
2473
}
2448
2474
else
2449
2475
{
2476
+ if (is_private )
2477
+ {
2478
+ vString * s = vStringNew ();
2479
+ vStringPut (s , '#' );
2480
+ vStringCat (s , name -> string );
2481
+ vStringCopy (name -> string , s );
2482
+ vStringDelete (s );
2483
+ }
2484
+
2450
2485
bool is_property = isType (token , TOKEN_COMMA );
2451
- makeJsTag (name , is_property ? JSTAG_PROPERTY : JSTAG_FIELD , NULL , NULL );
2486
+ makeJsTagMaybePrivate (name , is_property ? JSTAG_PROPERTY : JSTAG_FIELD , NULL , NULL , is_private );
2452
2487
if (!isType (token , TOKEN_SEMICOLON ) && !is_property )
2453
2488
dont_read = true;
2454
2489
}
@@ -2517,7 +2552,7 @@ static bool parseES6Class (tokenInfo *const token, const tokenInfo *target_name)
2517
2552
TRACE_PRINT ("Emitting tag for class '%s'" , vStringValue (target_name -> string ));
2518
2553
2519
2554
int r = makeJsTagCommon (target_name , JSTAG_CLASS , NULL , inheritance ,
2520
- (is_anonymous && (target_name == class_name )), false);
2555
+ (is_anonymous && (target_name == class_name )), false, false );
2521
2556
2522
2557
if (! is_anonymous && target_name != class_name )
2523
2558
{
@@ -2855,7 +2890,7 @@ static bool parseStatementRHS (tokenInfo *const name, tokenInfo *const token, st
2855
2890
if ( parseMethods (token , p , false) )
2856
2891
{
2857
2892
jsKind kind = state -> foundThis || strchr (vStringValue (name -> string ), '.' ) != NULL ? JSTAG_PROPERTY : JSTAG_VARIABLE ;
2858
- state -> indexForName = makeJsTagCommon (name , kind , NULL , NULL , anon_object , false);
2893
+ state -> indexForName = makeJsTagCommon (name , kind , NULL , NULL , anon_object , false, false );
2859
2894
moveChildren (p , state -> indexForName );
2860
2895
}
2861
2896
else if ( token -> nestLevel == 0 && state -> isGlobal )
@@ -2902,7 +2937,7 @@ static bool parseStatementRHS (tokenInfo *const name, tokenInfo *const token, st
2902
2937
*/
2903
2938
if ( ( token -> nestLevel == 0 && state -> isGlobal ) || kind == JSTAG_PROPERTY )
2904
2939
{
2905
- state -> indexForName = makeJsTagCommon (name , kind , NULL , NULL , false, false);
2940
+ state -> indexForName = makeJsTagCommon (name , kind , NULL , NULL , false, false, false );
2906
2941
}
2907
2942
}
2908
2943
else if (isKeyword (token , KEYWORD_new ))
0 commit comments