@@ -123,6 +123,7 @@ typedef enum eTokenType {
123123 TOKEN_REGEXP ,
124124 TOKEN_POSTFIX_OPERATOR ,
125125 TOKEN_STAR ,
126+ TOKEN_HASH ,
126127 /* To handle Babel's decorators.
127128 * Used only in readTokenFull or lower functions. */
128129 TOKEN_ATMARK ,
@@ -487,7 +488,7 @@ static int makeJsRefTagsForNameChain (char *name_chain, const tokenInfo *token,
487488
488489static int makeJsTagCommon (const tokenInfo * const token , const jsKind kind ,
489490 vString * const signature , vString * const inheritance ,
490- bool anonymous , bool nulltag )
491+ bool anonymous , bool is_private , bool nulltag )
491492{
492493 int index = CORK_NIL ;
493494 const char * name = vStringValue (token -> string );
@@ -526,6 +527,9 @@ static int makeJsTagCommon (const tokenInfo *const token, const jsKind kind,
526527 updateTagLine (& e , token -> lineNumber , token -> filePosition );
527528 e .extensionFields .scopeIndex = scope ;
528529
530+ if (is_private )
531+ e .extensionFields .access = "private" ;
532+
529533#ifdef DO_TRACING
530534 {
531535 const char * scope_str = getNameStringForCorkIndex (scope );
@@ -573,19 +577,26 @@ static int makeJsTagCommon (const tokenInfo *const token, const jsKind kind,
573577static int makeJsTag (const tokenInfo * const token , const jsKind kind ,
574578 vString * const signature , vString * const inheritance )
575579{
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);
577588}
578589
579590static int makeJsNullTag (const tokenInfo * const token , const jsKind kind ,
580591 vString * const signature , vString * const inheritance )
581592{
582- return makeJsTagCommon (token , kind , signature , inheritance , false, true);
593+ return makeJsTagCommon (token , kind , signature , inheritance , false, false, true);
583594}
584595
585596static int makeClassTagCommon (tokenInfo * const token , vString * const signature ,
586597 vString * const inheritance , bool anonymous )
587598{
588- return makeJsTagCommon (token , JSTAG_CLASS , signature , inheritance , anonymous , false);
599+ return makeJsTagCommon (token , JSTAG_CLASS , signature , inheritance , anonymous , false, false );
589600}
590601
591602static int makeClassTag (tokenInfo * const token , vString * const signature ,
@@ -598,7 +609,7 @@ static int makeFunctionTagCommon (tokenInfo *const token, vString *const signatu
598609 bool generator , bool anonymous )
599610{
600611 return makeJsTagCommon (token , generator ? JSTAG_GENERATOR : JSTAG_FUNCTION , signature , NULL ,
601- anonymous , false);
612+ anonymous , false, false );
602613}
603614
604615static int makeFunctionTag (tokenInfo * const token , vString * const signature , bool generator )
@@ -1300,11 +1311,11 @@ static void readTokenFullRaw (tokenInfo *const token, bool include_newlines, vSt
13001311 case '#' :
13011312 /* skip shebang in case of e.g. Node.js scripts */
13021313 if (token -> lineNumber > 1 )
1303- token -> type = TOKEN_UNDEFINED ;
1314+ token -> type = TOKEN_HASH ;
13041315 else if ((c = getcFromInputFile ()) != '!' )
13051316 {
13061317 ungetcToInputFile (c );
1307- token -> type = TOKEN_UNDEFINED ;
1318+ token -> type = TOKEN_HASH ;
13081319 }
13091320 else
13101321 {
@@ -1530,7 +1541,7 @@ static int parseMethodsInAnonymousObject (tokenInfo *const token)
15301541 anonGenerate (anon_object -> string , "anonymousObject" , JSTAG_VARIABLE );
15311542 anon_object -> type = TOKEN_IDENTIFIER ;
15321543
1533- index = makeJsTagCommon (anon_object , JSTAG_VARIABLE , NULL , NULL , true, false);
1544+ index = makeJsTagCommon (anon_object , JSTAG_VARIABLE , NULL , NULL , true, false, false );
15341545 if (! parseMethods (token , index , false))
15351546 {
15361547 /* If no method is found, the anonymous object
@@ -2222,6 +2233,7 @@ static bool parseMethods (tokenInfo *const token, int class_index,
22222233 ! isType (token , TOKEN_SEMICOLON ))
22232234 {
22242235 bool is_generator = false;
2236+ bool is_private = false;
22252237 bool is_shorthand = false; /* ES6 shorthand syntax */
22262238 bool is_computed_name = false; /* ES6 computed property name */
22272239 bool is_dynamic_prop = false;
@@ -2235,6 +2247,11 @@ static bool parseMethods (tokenInfo *const token, int class_index,
22352247 is_generator = true;
22362248 readToken (token );
22372249 }
2250+ else if (isType (token , TOKEN_HASH ))
2251+ {
2252+ is_private = true;
2253+ readToken (token );
2254+ }
22382255
22392256 if (isType (token , TOKEN_OPEN_SQUARE ))
22402257 {
@@ -2352,7 +2369,16 @@ static bool parseMethods (tokenInfo *const token, int class_index,
23522369 else if (is_setter )
23532370 kind = JSTAG_SETTER ;
23542371
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 );
23562382 parseBlock (token , index_for_name );
23572383
23582384 /*
@@ -2447,8 +2473,17 @@ static bool parseMethods (tokenInfo *const token, int class_index,
24472473 }
24482474 else
24492475 {
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+
24502485 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 );
24522487 if (!isType (token , TOKEN_SEMICOLON ) && !is_property )
24532488 dont_read = true;
24542489 }
@@ -2517,7 +2552,7 @@ static bool parseES6Class (tokenInfo *const token, const tokenInfo *target_name)
25172552 TRACE_PRINT ("Emitting tag for class '%s'" , vStringValue (target_name -> string ));
25182553
25192554 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 );
25212556
25222557 if (! is_anonymous && target_name != class_name )
25232558 {
@@ -2855,7 +2890,7 @@ static bool parseStatementRHS (tokenInfo *const name, tokenInfo *const token, st
28552890 if ( parseMethods (token , p , false) )
28562891 {
28572892 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 );
28592894 moveChildren (p , state -> indexForName );
28602895 }
28612896 else if ( token -> nestLevel == 0 && state -> isGlobal )
@@ -2902,7 +2937,7 @@ static bool parseStatementRHS (tokenInfo *const name, tokenInfo *const token, st
29022937 */
29032938 if ( ( token -> nestLevel == 0 && state -> isGlobal ) || kind == JSTAG_PROPERTY )
29042939 {
2905- state -> indexForName = makeJsTagCommon (name , kind , NULL , NULL , false, false);
2940+ state -> indexForName = makeJsTagCommon (name , kind , NULL , NULL , false, false, false );
29062941 }
29072942 }
29082943 else if (isKeyword (token , KEYWORD_new ))
0 commit comments