@@ -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 ,
@@ -144,6 +145,10 @@ typedef struct sTokenInfo {
144
145
int c ;
145
146
} tokenInfo ;
146
147
148
+ typedef enum {
149
+ F_STATIC ,
150
+ } jsField ;
151
+
147
152
/*
148
153
* DATA DEFINITIONS
149
154
*/
@@ -279,6 +284,14 @@ static kindDefinition JsKinds [] = {
279
284
{ true, 'M' , "field" , "fields" },
280
285
};
281
286
287
+ static fieldDefinition JsFields [] = {
288
+ {
289
+ .name = "properties" ,
290
+ .description = "properties (static)" ,
291
+ .enabled = false,
292
+ },
293
+ };
294
+
282
295
static const keywordTable JsKeywordTable [] = {
283
296
/* keyword keyword ID */
284
297
{ "function" , KEYWORD_function },
@@ -487,7 +500,7 @@ static int makeJsRefTagsForNameChain (char *name_chain, const tokenInfo *token,
487
500
488
501
static int makeJsTagCommon (const tokenInfo * const token , const jsKind kind ,
489
502
vString * const signature , vString * const inheritance ,
490
- bool anonymous , bool nulltag )
503
+ bool anonymous , bool is_static , bool is_private , bool nulltag )
491
504
{
492
505
int index = CORK_NIL ;
493
506
const char * name = vStringValue (token -> string );
@@ -526,6 +539,12 @@ static int makeJsTagCommon (const tokenInfo *const token, const jsKind kind,
526
539
updateTagLine (& e , token -> lineNumber , token -> filePosition );
527
540
e .extensionFields .scopeIndex = scope ;
528
541
542
+ if (is_private )
543
+ e .extensionFields .access = "private" ;
544
+
545
+ if (is_static )
546
+ attachParserField (& e , JsFields [F_STATIC ].ftype , "static" );
547
+
529
548
#ifdef DO_TRACING
530
549
{
531
550
const char * scope_str = getNameStringForCorkIndex (scope );
@@ -573,19 +592,33 @@ static int makeJsTagCommon (const tokenInfo *const token, const jsKind kind,
573
592
static int makeJsTag (const tokenInfo * const token , const jsKind kind ,
574
593
vString * const signature , vString * const inheritance )
575
594
{
576
- return makeJsTagCommon (token , kind , signature , inheritance , false, false);
595
+ return makeJsTagCommon (token , kind , signature , inheritance , false, false, false, false);
596
+ }
597
+
598
+ static int makeJsTagMaybePrivate (const tokenInfo * const token , const jsKind kind ,
599
+ vString * const signature , vString * const inheritance ,
600
+ const bool is_static , const bool is_private )
601
+ {
602
+ if (is_private ) {
603
+ vString * s = vStringNewInit ("#" );
604
+ vStringCat (s , token -> string );
605
+ vStringCopy (token -> string , s );
606
+ vStringDelete (s );
607
+ }
608
+
609
+ return makeJsTagCommon (token , kind , signature , inheritance , false, is_static , is_private , false);
577
610
}
578
611
579
612
static int makeJsNullTag (const tokenInfo * const token , const jsKind kind ,
580
613
vString * const signature , vString * const inheritance )
581
614
{
582
- return makeJsTagCommon (token , kind , signature , inheritance , false, true);
615
+ return makeJsTagCommon (token , kind , signature , inheritance , false, false, false, true);
583
616
}
584
617
585
618
static int makeClassTagCommon (tokenInfo * const token , vString * const signature ,
586
619
vString * const inheritance , bool anonymous )
587
620
{
588
- return makeJsTagCommon (token , JSTAG_CLASS , signature , inheritance , anonymous , false);
621
+ return makeJsTagCommon (token , JSTAG_CLASS , signature , inheritance , anonymous , false, false, false );
589
622
}
590
623
591
624
static int makeClassTag (tokenInfo * const token , vString * const signature ,
@@ -598,7 +631,7 @@ static int makeFunctionTagCommon (tokenInfo *const token, vString *const signatu
598
631
bool generator , bool anonymous )
599
632
{
600
633
return makeJsTagCommon (token , generator ? JSTAG_GENERATOR : JSTAG_FUNCTION , signature , NULL ,
601
- anonymous , false);
634
+ anonymous , false, false, false );
602
635
}
603
636
604
637
static int makeFunctionTag (tokenInfo * const token , vString * const signature , bool generator )
@@ -1300,11 +1333,11 @@ static void readTokenFullRaw (tokenInfo *const token, bool include_newlines, vSt
1300
1333
case '#' :
1301
1334
/* skip shebang in case of e.g. Node.js scripts */
1302
1335
if (token -> lineNumber > 1 )
1303
- token -> type = TOKEN_UNDEFINED ;
1336
+ token -> type = TOKEN_HASH ;
1304
1337
else if ((c = getcFromInputFile ()) != '!' )
1305
1338
{
1306
1339
ungetcToInputFile (c );
1307
- token -> type = TOKEN_UNDEFINED ;
1340
+ token -> type = TOKEN_HASH ;
1308
1341
}
1309
1342
else
1310
1343
{
@@ -1530,7 +1563,7 @@ static int parseMethodsInAnonymousObject (tokenInfo *const token)
1530
1563
anonGenerate (anon_object -> string , "anonymousObject" , JSTAG_VARIABLE );
1531
1564
anon_object -> type = TOKEN_IDENTIFIER ;
1532
1565
1533
- index = makeJsTagCommon (anon_object , JSTAG_VARIABLE , NULL , NULL , true, false);
1566
+ index = makeJsTagCommon (anon_object , JSTAG_VARIABLE , NULL , NULL , true, false, false, false );
1534
1567
if (! parseMethods (token , index , false))
1535
1568
{
1536
1569
/* If no method is found, the anonymous object
@@ -2162,6 +2195,7 @@ static bool parseMethods (tokenInfo *const token, int class_index,
2162
2195
{
2163
2196
bool is_setter = false;
2164
2197
bool is_getter = false;
2198
+ bool is_static = false;
2165
2199
2166
2200
if (!dont_read )
2167
2201
readToken (token );
@@ -2204,6 +2238,9 @@ static bool parseMethods (tokenInfo *const token, int class_index,
2204
2238
else if (isKeyword (saved_token , KEYWORD_async ) ||
2205
2239
isKeyword (saved_token , KEYWORD_static ))
2206
2240
{
2241
+ if (isKeyword (saved_token , KEYWORD_static ))
2242
+ is_static = true;
2243
+
2207
2244
/* can be a qualifier for another "keyword", so start over */
2208
2245
deleteToken (saved_token );
2209
2246
goto start ;
@@ -2222,6 +2259,7 @@ static bool parseMethods (tokenInfo *const token, int class_index,
2222
2259
! isType (token , TOKEN_SEMICOLON ))
2223
2260
{
2224
2261
bool is_generator = false;
2262
+ bool is_private = false;
2225
2263
bool is_shorthand = false; /* ES6 shorthand syntax */
2226
2264
bool is_computed_name = false; /* ES6 computed property name */
2227
2265
bool is_dynamic_prop = false;
@@ -2235,6 +2273,11 @@ static bool parseMethods (tokenInfo *const token, int class_index,
2235
2273
is_generator = true;
2236
2274
readToken (token );
2237
2275
}
2276
+ else if (isType (token , TOKEN_HASH ))
2277
+ {
2278
+ is_private = true;
2279
+ readToken (token );
2280
+ }
2238
2281
2239
2282
if (isType (token , TOKEN_OPEN_SQUARE ))
2240
2283
{
@@ -2352,7 +2395,7 @@ static bool parseMethods (tokenInfo *const token, int class_index,
2352
2395
else if (is_setter )
2353
2396
kind = JSTAG_SETTER ;
2354
2397
2355
- index_for_name = makeJsTag (name , kind , signature , NULL );
2398
+ index_for_name = makeJsTagMaybePrivate (name , kind , signature , NULL , is_static , is_private );
2356
2399
parseBlock (token , index_for_name );
2357
2400
2358
2401
/*
@@ -2448,7 +2491,7 @@ static bool parseMethods (tokenInfo *const token, int class_index,
2448
2491
else
2449
2492
{
2450
2493
bool is_property = isType (token , TOKEN_COMMA );
2451
- makeJsTag (name , is_property ? JSTAG_PROPERTY : JSTAG_FIELD , NULL , NULL );
2494
+ makeJsTagMaybePrivate (name , is_property ? JSTAG_PROPERTY : JSTAG_FIELD , NULL , NULL , is_static , is_private );
2452
2495
if (!isType (token , TOKEN_SEMICOLON ) && !is_property )
2453
2496
dont_read = true;
2454
2497
}
@@ -2517,7 +2560,7 @@ static bool parseES6Class (tokenInfo *const token, const tokenInfo *target_name)
2517
2560
TRACE_PRINT ("Emitting tag for class '%s'" , vStringValue (target_name -> string ));
2518
2561
2519
2562
int r = makeJsTagCommon (target_name , JSTAG_CLASS , NULL , inheritance ,
2520
- (is_anonymous && (target_name == class_name )), false);
2563
+ (is_anonymous && (target_name == class_name )), false, false, false );
2521
2564
2522
2565
if (! is_anonymous && target_name != class_name )
2523
2566
{
@@ -2855,7 +2898,7 @@ static bool parseStatementRHS (tokenInfo *const name, tokenInfo *const token, st
2855
2898
if ( parseMethods (token , p , false) )
2856
2899
{
2857
2900
jsKind kind = state -> foundThis || strchr (vStringValue (name -> string ), '.' ) != NULL ? JSTAG_PROPERTY : JSTAG_VARIABLE ;
2858
- state -> indexForName = makeJsTagCommon (name , kind , NULL , NULL , anon_object , false);
2901
+ state -> indexForName = makeJsTagCommon (name , kind , NULL , NULL , anon_object , false, false, false );
2859
2902
moveChildren (p , state -> indexForName );
2860
2903
}
2861
2904
else if ( token -> nestLevel == 0 && state -> isGlobal )
@@ -2902,7 +2945,7 @@ static bool parseStatementRHS (tokenInfo *const name, tokenInfo *const token, st
2902
2945
*/
2903
2946
if ( ( token -> nestLevel == 0 && state -> isGlobal ) || kind == JSTAG_PROPERTY )
2904
2947
{
2905
- state -> indexForName = makeJsTagCommon (name , kind , NULL , NULL , false, false);
2948
+ state -> indexForName = makeJsTagCommon (name , kind , NULL , NULL , false, false, false, false );
2906
2949
}
2907
2950
}
2908
2951
else if (isKeyword (token , KEYWORD_new ))
@@ -3762,6 +3805,8 @@ extern parserDefinition* JavaScriptParser (void)
3762
3805
*/
3763
3806
def -> kindTable = JsKinds ;
3764
3807
def -> kindCount = ARRAY_SIZE (JsKinds );
3808
+ def -> fieldTable = JsFields ;
3809
+ def -> fieldCount = ARRAY_SIZE (JsFields );
3765
3810
def -> parser = findJsTags ;
3766
3811
def -> initialize = initialize ;
3767
3812
def -> finalize = finalize ;
@@ -3773,8 +3818,8 @@ extern parserDefinition* JavaScriptParser (void)
3773
3818
def -> dependencies = dependencies ;
3774
3819
def -> dependencyCount = ARRAY_SIZE (dependencies );
3775
3820
3776
- def -> versionCurrent = 1 ;
3777
- def -> versionAge = 1 ;
3821
+ def -> versionCurrent = 2 ;
3822
+ def -> versionAge = 2 ;
3778
3823
3779
3824
return def ;
3780
3825
}
0 commit comments