@@ -263,6 +263,12 @@ func (n *Node) TemplateLiteralLikeData() *TemplateLiteralLikeBase {
263263}
264264func (n * Node ) KindString () string { return n .Kind .String () }
265265func (n * Node ) KindValue () int16 { return int16 (n .Kind ) }
266+ func (n * Node ) Decorators () []* Node {
267+ if n .Modifiers () == nil {
268+ return nil
269+ }
270+ return core .Filter (n .Modifiers ().Nodes , IsDecorator )
271+ }
266272
267273type MutableNode Node
268274
@@ -6141,15 +6147,16 @@ type StringLiteral struct {
61416147 LiteralLikeBase
61426148}
61436149
6144- func (f * NodeFactory ) NewStringLiteral (text string ) * Node {
6150+ func (f * NodeFactory ) NewStringLiteral (text string , flags TokenFlags ) * Node {
61456151 data := f .stringLiteralPool .New ()
61466152 data .Text = text
6153+ data .TokenFlags = flags & TokenFlagsStringLiteralFlags
61476154 f .textCount ++
61486155 return f .newNode (KindStringLiteral , data )
61496156}
61506157
61516158func (node * StringLiteral ) Clone (f NodeFactoryCoercible ) * Node {
6152- return cloneNode (f .AsNodeFactory ().NewStringLiteral (node .Text ), node .AsNode (), f .AsNodeFactory ().hooks )
6159+ return cloneNode (f .AsNodeFactory ().NewStringLiteral (node .Text , node . TokenFlags ), node .AsNode (), f .AsNodeFactory ().hooks )
61536160}
61546161
61556162func IsStringLiteral (node * Node ) bool {
@@ -6163,15 +6170,16 @@ type NumericLiteral struct {
61636170 LiteralLikeBase
61646171}
61656172
6166- func (f * NodeFactory ) NewNumericLiteral (text string ) * Node {
6173+ func (f * NodeFactory ) NewNumericLiteral (text string , flags TokenFlags ) * Node {
61676174 data := f .numericLiteralPool .New ()
61686175 data .Text = text
6176+ data .TokenFlags = flags & TokenFlagsNumericLiteralFlags
61696177 f .textCount ++
61706178 return f .newNode (KindNumericLiteral , data )
61716179}
61726180
61736181func (node * NumericLiteral ) Clone (f NodeFactoryCoercible ) * Node {
6174- return cloneNode (f .AsNodeFactory ().NewNumericLiteral (node .Text ), node .AsNode (), f .AsNodeFactory ().hooks )
6182+ return cloneNode (f .AsNodeFactory ().NewNumericLiteral (node .Text , node . TokenFlags ), node .AsNode (), f .AsNodeFactory ().hooks )
61756183}
61766184
61776185func IsNumericLiteral (node * Node ) bool {
@@ -6185,15 +6193,16 @@ type BigIntLiteral struct {
61856193 LiteralLikeBase
61866194}
61876195
6188- func (f * NodeFactory ) NewBigIntLiteral (text string ) * Node {
6196+ func (f * NodeFactory ) NewBigIntLiteral (text string , flags TokenFlags ) * Node {
61896197 data := & BigIntLiteral {}
61906198 data .Text = text
6199+ data .TokenFlags = flags & TokenFlagsNumericLiteralFlags
61916200 f .textCount ++
61926201 return f .newNode (KindBigIntLiteral , data )
61936202}
61946203
61956204func (node * BigIntLiteral ) Clone (f NodeFactoryCoercible ) * Node {
6196- return cloneNode (f .AsNodeFactory ().NewBigIntLiteral (node .Text ), node .AsNode (), f .AsNodeFactory ().hooks )
6205+ return cloneNode (f .AsNodeFactory ().NewBigIntLiteral (node .Text , node . TokenFlags ), node .AsNode (), f .AsNodeFactory ().hooks )
61976206}
61986207
61996208func (node * BigIntLiteral ) computeSubtreeFacts () SubtreeFacts {
@@ -6211,15 +6220,16 @@ type RegularExpressionLiteral struct {
62116220 LiteralLikeBase
62126221}
62136222
6214- func (f * NodeFactory ) NewRegularExpressionLiteral (text string ) * Node {
6223+ func (f * NodeFactory ) NewRegularExpressionLiteral (text string , flags TokenFlags ) * Node {
62156224 data := & RegularExpressionLiteral {}
62166225 data .Text = text
6226+ data .TokenFlags = flags & TokenFlagsRegularExpressionLiteralFlags
62176227 f .textCount ++
62186228 return f .newNode (KindRegularExpressionLiteral , data )
62196229}
62206230
62216231func (node * RegularExpressionLiteral ) Clone (f NodeFactoryCoercible ) * Node {
6222- return cloneNode (f .AsNodeFactory ().NewRegularExpressionLiteral (node .Text ), node .AsNode (), f .AsNodeFactory ().hooks )
6232+ return cloneNode (f .AsNodeFactory ().NewRegularExpressionLiteral (node .Text , node . TokenFlags ), node .AsNode (), f .AsNodeFactory ().hooks )
62236233}
62246234
62256235func IsRegularExpressionLiteral (node * Node ) bool {
@@ -6233,15 +6243,16 @@ type NoSubstitutionTemplateLiteral struct {
62336243 TemplateLiteralLikeBase
62346244}
62356245
6236- func (f * NodeFactory ) NewNoSubstitutionTemplateLiteral (text string ) * Node {
6246+ func (f * NodeFactory ) NewNoSubstitutionTemplateLiteral (text string , templateFlags TokenFlags ) * Node {
62376247 data := & NoSubstitutionTemplateLiteral {}
62386248 data .Text = text
6249+ data .TemplateFlags = templateFlags & TokenFlagsTemplateLiteralLikeFlags
62396250 f .textCount ++
62406251 return f .newNode (KindNoSubstitutionTemplateLiteral , data )
62416252}
62426253
62436254func (node * NoSubstitutionTemplateLiteral ) Clone (f NodeFactoryCoercible ) * Node {
6244- return cloneNode (f .AsNodeFactory ().NewNoSubstitutionTemplateLiteral (node .Text ), node .AsNode (), f .AsNodeFactory ().hooks )
6255+ return cloneNode (f .AsNodeFactory ().NewNoSubstitutionTemplateLiteral (node .Text , node . TemplateFlags ), node .AsNode (), f .AsNodeFactory ().hooks )
62456256}
62466257
62476258// BinaryExpression
@@ -6295,7 +6306,7 @@ func (node *BinaryExpression) computeSubtreeFacts() SubtreeFacts {
62956306 propagateSubtreeFacts (node .Type ) |
62966307 propagateSubtreeFacts (node .OperatorToken ) |
62976308 propagateSubtreeFacts (node .Right ) |
6298- core .IfElse (node .OperatorToken .Kind == KindInKeyword && IsPrivateIdentifier (node .Left ), SubtreeContainsClassFields , SubtreeFactsNone )
6309+ core .IfElse (node .OperatorToken .Kind == KindInKeyword && IsPrivateIdentifier (node .Left ), SubtreeContainsClassFields | SubtreeContainsPrivateIdentifierInExpression , SubtreeFactsNone )
62996310}
63006311
63016312func (node * BinaryExpression ) setModifiers (modifiers * ModifierList ) { node .modifiers = modifiers }
@@ -6748,9 +6759,13 @@ func (node *PropertyAccessExpression) Clone(f NodeFactoryCoercible) *Node {
67486759func (node * PropertyAccessExpression ) Name () * DeclarationName { return node .name }
67496760
67506761func (node * PropertyAccessExpression ) computeSubtreeFacts () SubtreeFacts {
6762+ privateName := SubtreeFactsNone
6763+ if ! IsIdentifier (node .name ) {
6764+ privateName = SubtreeContainsPrivateIdentifierInExpression
6765+ }
67516766 return propagateSubtreeFacts (node .Expression ) |
67526767 propagateSubtreeFacts (node .QuestionDotToken ) |
6753- propagateSubtreeFacts (node .name )
6768+ propagateSubtreeFacts (node .name ) | privateName
67546769}
67556770
67566771func (node * PropertyAccessExpression ) propagateSubtreeFacts () SubtreeFacts {
@@ -8722,7 +8737,7 @@ func (f *NodeFactory) NewTemplateHead(text string, rawText string, templateFlags
87228737 data := & TemplateHead {}
87238738 data .Text = text
87248739 data .RawText = rawText
8725- data .TemplateFlags = templateFlags
8740+ data .TemplateFlags = templateFlags & TokenFlagsTemplateLiteralLikeFlags
87268741 f .textCount ++
87278742 return f .newNode (KindTemplateHead , data )
87288743}
@@ -8746,7 +8761,7 @@ func (f *NodeFactory) NewTemplateMiddle(text string, rawText string, templateFla
87468761 data := & TemplateMiddle {}
87478762 data .Text = text
87488763 data .RawText = rawText
8749- data .TemplateFlags = templateFlags
8764+ data .TemplateFlags = templateFlags & TokenFlagsTemplateLiteralLikeFlags
87508765 f .textCount ++
87518766 return f .newNode (KindTemplateMiddle , data )
87528767}
@@ -8770,7 +8785,7 @@ func (f *NodeFactory) NewTemplateTail(text string, rawText string, templateFlags
87708785 data := & TemplateTail {}
87718786 data .Text = text
87728787 data .RawText = rawText
8773- data .TemplateFlags = templateFlags
8788+ data .TemplateFlags = templateFlags & TokenFlagsTemplateLiteralLikeFlags
87748789 f .textCount ++
87758790 return f .newNode (KindTemplateTail , data )
87768791}
@@ -10786,6 +10801,8 @@ type SourceFile struct {
1078610801 tokenFactory * NodeFactory
1078710802 declarationMapMu sync.Mutex
1078810803 declarationMap map [string ][]* Node
10804+ nameTableOnce sync.Once
10805+ nameTable map [string ]int
1078910806}
1079010807
1079110808func (f * NodeFactory ) NewSourceFile (opts SourceFileParseOptions , text string , statements * NodeList , endOfFileToken * TokenNode ) * Node {
@@ -10929,6 +10946,39 @@ func (node *SourceFile) ECMALineMap() []core.TextPos {
1092910946 return lineMap
1093010947}
1093110948
10949+ // GetNameTable returns a map of all names in the file to their positions.
10950+ // If the name appears more than once, the value is -1.
10951+ func (file * SourceFile ) GetNameTable () map [string ]int {
10952+ file .nameTableOnce .Do (func () {
10953+ nameTable := make (map [string ]int , file .IdentifierCount )
10954+
10955+ var walk func (node * Node ) bool
10956+ walk = func (node * Node ) bool {
10957+ if IsIdentifier (node ) && ! isTagName (node ) && node .Text () != "" ||
10958+ IsStringOrNumericLiteralLike (node ) && literalIsName (node ) ||
10959+ IsPrivateIdentifier (node ) {
10960+ text := node .Text ()
10961+ if _ , ok := nameTable [text ]; ok {
10962+ nameTable [text ] = - 1
10963+ } else {
10964+ nameTable [text ] = node .Pos ()
10965+ }
10966+ }
10967+
10968+ node .ForEachChild (walk )
10969+ jsdocNodes := node .JSDoc (file )
10970+ for _ , jsdoc := range jsdocNodes {
10971+ jsdoc .ForEachChild (walk )
10972+ }
10973+ return false
10974+ }
10975+ file .ForEachChild (walk )
10976+
10977+ file .nameTable = nameTable
10978+ })
10979+ return file .nameTable
10980+ }
10981+
1093210982func (node * SourceFile ) IsBound () bool {
1093310983 return node .isBound .Load ()
1093410984}
@@ -10980,33 +11030,23 @@ func createToken(kind Kind, file *SourceFile, pos, end int, flags TokenFlags) *N
1098011030 text := file .text [pos :end ]
1098111031 switch kind {
1098211032 case KindNumericLiteral :
10983- literal := file .tokenFactory .NewNumericLiteral (text )
10984- literal .AsNumericLiteral ().TokenFlags = flags & TokenFlagsNumericLiteralFlags
10985- return literal
11033+ return file .tokenFactory .NewNumericLiteral (text , flags )
1098611034 case KindBigIntLiteral :
10987- literal := file .tokenFactory .NewBigIntLiteral (text )
10988- literal .AsBigIntLiteral ().TokenFlags = flags & TokenFlagsNumericLiteralFlags
10989- return literal
11035+ return file .tokenFactory .NewBigIntLiteral (text , flags )
1099011036 case KindStringLiteral :
10991- literal := file .tokenFactory .NewStringLiteral (text )
10992- literal .AsStringLiteral ().TokenFlags = flags & TokenFlagsStringLiteralFlags
10993- return literal
11037+ return file .tokenFactory .NewStringLiteral (text , flags )
1099411038 case KindJsxText , KindJsxTextAllWhiteSpaces :
1099511039 return file .tokenFactory .NewJsxText (text , kind == KindJsxTextAllWhiteSpaces )
1099611040 case KindRegularExpressionLiteral :
10997- literal := file .tokenFactory .NewRegularExpressionLiteral (text )
10998- literal .AsRegularExpressionLiteral ().TokenFlags = flags & TokenFlagsRegularExpressionLiteralFlags
10999- return literal
11041+ return file .tokenFactory .NewRegularExpressionLiteral (text , flags )
1100011042 case KindNoSubstitutionTemplateLiteral :
11001- literal := file .tokenFactory .NewNoSubstitutionTemplateLiteral (text )
11002- literal .AsNoSubstitutionTemplateLiteral ().TokenFlags = flags & TokenFlagsTemplateLiteralLikeFlags
11003- return literal
11043+ return file .tokenFactory .NewNoSubstitutionTemplateLiteral (text , flags )
1100411044 case KindTemplateHead :
11005- return file .tokenFactory .NewTemplateHead (text , "" /*rawText*/ , flags & TokenFlagsTemplateLiteralLikeFlags )
11045+ return file .tokenFactory .NewTemplateHead (text , "" /*rawText*/ , flags )
1100611046 case KindTemplateMiddle :
11007- return file .tokenFactory .NewTemplateMiddle (text , "" /*rawText*/ , flags & TokenFlagsTemplateLiteralLikeFlags )
11047+ return file .tokenFactory .NewTemplateMiddle (text , "" /*rawText*/ , flags )
1100811048 case KindTemplateTail :
11009- return file .tokenFactory .NewTemplateTail (text , "" /*rawText*/ , flags & TokenFlagsTemplateLiteralLikeFlags )
11049+ return file .tokenFactory .NewTemplateTail (text , "" /*rawText*/ , flags )
1101011050 case KindIdentifier :
1101111051 return file .tokenFactory .NewIdentifier (text )
1101211052 case KindPrivateIdentifier :
0 commit comments