@@ -192,15 +192,14 @@ namespace ts {
192
192
ForStatement = 1 << 10 , // Enclosing block-scoped container is a ForStatement
193
193
ForInOrForOfStatement = 1 << 11 , // Enclosing block-scoped container is a ForInStatement or ForOfStatement
194
194
ConstructorWithCapturedSuper = 1 << 12 , // Enclosed in a constructor that captures 'this' for use with 'super'
195
- ComputedPropertyName = 1 << 13 , // Enclosed in a computed property name
196
195
// NOTE: do not add more ancestor flags without also updating AncestorFactsMask below.
197
196
// NOTE: when adding a new ancestor flag, be sure to update the subtree flags below.
198
197
199
198
//
200
199
// Ancestor masks
201
200
//
202
201
203
- AncestorFactsMask = ( ComputedPropertyName << 1 ) - 1 ,
202
+ AncestorFactsMask = ( ConstructorWithCapturedSuper << 1 ) - 1 ,
204
203
205
204
// We are always in *some* kind of block scope, but only specific block-scope containers are
206
205
// top-level or Blocks.
@@ -213,14 +212,14 @@ namespace ts {
213
212
214
213
// Functions, methods, and accessors are both new lexical scopes and new block scopes.
215
214
FunctionIncludes = Function | TopLevel ,
216
- FunctionExcludes = BlockScopeExcludes & ~ TopLevel | ArrowFunction | AsyncFunctionBody | CapturesThis | NonStaticClassElement | ConstructorWithCapturedSuper | ComputedPropertyName ,
215
+ FunctionExcludes = BlockScopeExcludes & ~ TopLevel | ArrowFunction | AsyncFunctionBody | CapturesThis | NonStaticClassElement | ConstructorWithCapturedSuper ,
217
216
218
217
AsyncFunctionBodyIncludes = FunctionIncludes | AsyncFunctionBody ,
219
218
AsyncFunctionBodyExcludes = FunctionExcludes & ~ NonStaticClassElement ,
220
219
221
220
// Arrow functions are lexically scoped to their container, but are new block scopes.
222
221
ArrowFunctionIncludes = ArrowFunction | TopLevel ,
223
- ArrowFunctionExcludes = BlockScopeExcludes & ~ TopLevel | ConstructorWithCapturedSuper | ComputedPropertyName ,
222
+ ArrowFunctionExcludes = BlockScopeExcludes & ~ TopLevel | ConstructorWithCapturedSuper ,
224
223
225
224
// Constructors are both new lexical scopes and new block scopes. Constructors are also
226
225
// always considered non-static members of a class.
@@ -249,25 +248,23 @@ namespace ts {
249
248
IterationStatementBlockIncludes = IterationStatementBlock ,
250
249
IterationStatementBlockExcludes = BlockScopeExcludes ,
251
250
252
- // Computed property names track subtree flags differently than their containing members.
253
- ComputedPropertyNameIncludes = ComputedPropertyName ,
254
- ComputedPropertyNameExcludes = None ,
255
-
256
251
//
257
252
// Subtree facts
258
253
//
259
- NewTarget = 1 << 14 , // Contains a 'new.target' meta-property
260
- NewTargetInComputedPropertyName = 1 << 15 , // Contains a 'new.target' meta-property in a computed property name.
261
254
262
- LexicalThis = 1 << 16 , // Contains a lexical `this` reference.
263
- LexicalThisInComputedPropertyName = 1 << 17 , // Contains a lexical `this` reference in a computed property name.
255
+ NewTarget = 1 << 13 , // Contains a 'new.target' meta-property
256
+ LexicalThis = 1 << 14 , // Contains a lexical `this` reference.
257
+ CapturedLexicalThis = 1 << 15 , // Contains a lexical `this` reference captured by an arrow function.
264
258
265
259
//
266
260
// Subtree masks
267
261
//
268
262
269
263
SubtreeFactsMask = ~ AncestorFactsMask ,
270
- PropagateNewTargetMask = NewTarget | NewTargetInComputedPropertyName ,
264
+
265
+ PropagateNewTargetMask = NewTarget ,
266
+ ArrowFunctionSubtreeExcludes = None ,
267
+ FunctionSubtreeExcludes = NewTarget | LexicalThis | CapturedLexicalThis ,
271
268
}
272
269
273
270
export function transformES2015 ( context : TransformationContext ) {
@@ -599,12 +596,7 @@ namespace ts {
599
596
}
600
597
601
598
function visitThisKeyword ( node : Node ) : Node {
602
- if ( hierarchyFacts & HierarchyFacts . ComputedPropertyName ) {
603
- hierarchyFacts |= HierarchyFacts . LexicalThisInComputedPropertyName ;
604
- }
605
- else {
606
- hierarchyFacts |= HierarchyFacts . LexicalThis ;
607
- }
599
+ hierarchyFacts |= HierarchyFacts . LexicalThis ;
608
600
if ( convertedLoopState ) {
609
601
if ( hierarchyFacts & HierarchyFacts . ArrowFunction ) {
610
602
// if the enclosing function is an ArrowFunction then we use the captured 'this' keyword.
@@ -913,7 +905,7 @@ namespace ts {
913
905
}
914
906
915
907
statements . push ( constructorFunction ) ;
916
- exitSubtree ( ancestorFacts , HierarchyFacts . PropagateNewTargetMask , HierarchyFacts . None ) ;
908
+ exitSubtree ( ancestorFacts , HierarchyFacts . FunctionSubtreeExcludes , HierarchyFacts . None ) ;
917
909
convertedLoopState = savedConvertedLoopState ;
918
910
}
919
911
@@ -1621,7 +1613,6 @@ namespace ts {
1621
1613
* @param member The MethodDeclaration node.
1622
1614
*/
1623
1615
function transformClassMethodDeclarationToStatement ( receiver : LeftHandSideExpression , member : MethodDeclaration , container : Node ) {
1624
- const ancestorFacts = enterSubtree ( HierarchyFacts . None , HierarchyFacts . None ) ;
1625
1616
const commentRange = getCommentRange ( member ) ;
1626
1617
const sourceMapRange = getSourceMapRange ( member ) ;
1627
1618
const memberName = createMemberAccessForPropertyName ( receiver , visitNode ( member . name , visitor , isPropertyName ) , /*location*/ member . name ) ;
@@ -1643,8 +1634,6 @@ namespace ts {
1643
1634
// No source map should be emitted for this statement to align with the
1644
1635
// old emitter.
1645
1636
setEmitFlags ( statement , EmitFlags . NoSourceMap ) ;
1646
-
1647
- exitSubtree ( ancestorFacts , HierarchyFacts . PropagateNewTargetMask , hierarchyFacts & HierarchyFacts . PropagateNewTargetMask ? HierarchyFacts . NewTarget : HierarchyFacts . None ) ;
1648
1637
return statement ;
1649
1638
}
1650
1639
@@ -1671,8 +1660,6 @@ namespace ts {
1671
1660
* @param receiver The receiver for the member.
1672
1661
*/
1673
1662
function transformAccessorsToExpression ( receiver : LeftHandSideExpression , { firstAccessor, getAccessor, setAccessor } : AllAccessorDeclarations , container : Node , startsOnNewLine : boolean ) : Expression {
1674
- const ancestorFacts = enterSubtree ( HierarchyFacts . None , HierarchyFacts . None ) ;
1675
-
1676
1663
// To align with source maps in the old emitter, the receiver and property name
1677
1664
// arguments are both mapped contiguously to the accessor name.
1678
1665
const target = getMutableClone ( receiver ) ;
@@ -1720,7 +1707,6 @@ namespace ts {
1720
1707
startOnNewLine ( call ) ;
1721
1708
}
1722
1709
1723
- exitSubtree ( ancestorFacts , HierarchyFacts . PropagateNewTargetMask , hierarchyFacts & HierarchyFacts . PropagateNewTargetMask ? HierarchyFacts . NewTarget : HierarchyFacts . None ) ;
1724
1710
return call ;
1725
1711
}
1726
1712
@@ -1779,7 +1765,7 @@ namespace ts {
1779
1765
? getLocalName ( node )
1780
1766
: node . name ;
1781
1767
1782
- exitSubtree ( ancestorFacts , HierarchyFacts . PropagateNewTargetMask , HierarchyFacts . None ) ;
1768
+ exitSubtree ( ancestorFacts , HierarchyFacts . FunctionSubtreeExcludes , HierarchyFacts . None ) ;
1783
1769
convertedLoopState = savedConvertedLoopState ;
1784
1770
return updateFunctionExpression (
1785
1771
node ,
@@ -1812,7 +1798,7 @@ namespace ts {
1812
1798
? getLocalName ( node )
1813
1799
: node . name ;
1814
1800
1815
- exitSubtree ( ancestorFacts , HierarchyFacts . PropagateNewTargetMask , HierarchyFacts . None ) ;
1801
+ exitSubtree ( ancestorFacts , HierarchyFacts . FunctionSubtreeExcludes , HierarchyFacts . None ) ;
1816
1802
convertedLoopState = savedConvertedLoopState ;
1817
1803
return updateFunctionDeclaration (
1818
1804
node ,
@@ -1846,7 +1832,7 @@ namespace ts {
1846
1832
name = getGeneratedNameForNode ( node ) ;
1847
1833
}
1848
1834
1849
- exitSubtree ( ancestorFacts , HierarchyFacts . PropagateNewTargetMask , HierarchyFacts . None ) ;
1835
+ exitSubtree ( ancestorFacts , HierarchyFacts . FunctionSubtreeExcludes , HierarchyFacts . None ) ;
1850
1836
convertedLoopState = savedConvertedLoopState ;
1851
1837
return setOriginalNode (
1852
1838
setTextRange (
@@ -3443,7 +3429,6 @@ namespace ts {
3443
3429
* @param receiver The receiver for the assignment.
3444
3430
*/
3445
3431
function transformObjectLiteralMethodDeclarationToExpression ( method : MethodDeclaration , receiver : Expression , container : Node , startsOnNewLine : boolean ) {
3446
- const ancestorFacts = enterSubtree ( HierarchyFacts . None , HierarchyFacts . None ) ;
3447
3432
const expression = createAssignment (
3448
3433
createMemberAccessForPropertyName (
3449
3434
receiver ,
@@ -3455,7 +3440,6 @@ namespace ts {
3455
3440
if ( startsOnNewLine ) {
3456
3441
startOnNewLine ( expression ) ;
3457
3442
}
3458
- exitSubtree ( ancestorFacts , HierarchyFacts . PropagateNewTargetMask , hierarchyFacts & HierarchyFacts . PropagateNewTargetMask ? HierarchyFacts . NewTarget : HierarchyFacts . None ) ;
3459
3443
return expression ;
3460
3444
}
3461
3445
@@ -3535,7 +3519,7 @@ namespace ts {
3535
3519
else {
3536
3520
updated = updateSetAccessor ( node , node . decorators , node . modifiers , node . name , parameters , body ) ;
3537
3521
}
3538
- exitSubtree ( ancestorFacts , HierarchyFacts . PropagateNewTargetMask , HierarchyFacts . None ) ;
3522
+ exitSubtree ( ancestorFacts , HierarchyFacts . FunctionSubtreeExcludes , HierarchyFacts . None ) ;
3539
3523
convertedLoopState = savedConvertedLoopState ;
3540
3524
return updated ;
3541
3525
}
@@ -3556,10 +3540,7 @@ namespace ts {
3556
3540
}
3557
3541
3558
3542
function visitComputedPropertyName ( node : ComputedPropertyName ) {
3559
- const ancestorFacts = enterSubtree ( HierarchyFacts . ComputedPropertyNameExcludes , HierarchyFacts . ComputedPropertyNameIncludes ) ;
3560
- const updated = visitEachChild ( node , visitor , context ) ;
3561
- exitSubtree ( ancestorFacts , HierarchyFacts . PropagateNewTargetMask , hierarchyFacts & HierarchyFacts . PropagateNewTargetMask ? HierarchyFacts . NewTargetInComputedPropertyName : HierarchyFacts . None ) ;
3562
- return updated ;
3543
+ return visitEachChild ( node , visitor , context ) ;
3563
3544
}
3564
3545
3565
3546
/**
@@ -4152,12 +4133,7 @@ namespace ts {
4152
4133
4153
4134
function visitMetaProperty ( node : MetaProperty ) {
4154
4135
if ( node . keywordToken === SyntaxKind . NewKeyword && node . name . escapedText === "target" ) {
4155
- if ( hierarchyFacts & HierarchyFacts . ComputedPropertyName ) {
4156
- hierarchyFacts |= HierarchyFacts . NewTargetInComputedPropertyName ;
4157
- }
4158
- else {
4159
- hierarchyFacts |= HierarchyFacts . NewTarget ;
4160
- }
4136
+ hierarchyFacts |= HierarchyFacts . NewTarget ;
4161
4137
return createFileLevelUniqueName ( "_newTarget" ) ;
4162
4138
}
4163
4139
return node ;
0 commit comments