Skip to content

Commit 5576c3e

Browse files
committed
Remove ES2015 and ContainsDefaultValueassignments flags
1 parent f944ed6 commit 5576c3e

File tree

3 files changed

+62
-50
lines changed

3 files changed

+62
-50
lines changed

src/compiler/binder.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3186,7 +3186,7 @@ namespace ts {
31863186
// If a parameter has an initializer, a binding pattern or a dotDotDot token, then
31873187
// it is ES6 syntax and its container must emit default value assignments or parameter destructuring downlevel.
31883188
if (subtreeFlags & TransformFlags.ContainsBindingPattern || initializer || dotDotDotToken) {
3189-
transformFlags |= TransformFlags.AssertES2015 | TransformFlags.ContainsDefaultValueAssignments;
3189+
transformFlags |= TransformFlags.AssertES2015;
31903190
}
31913191

31923192
node.transformFlags = transformFlags | TransformFlags.HasComputedFlags;
@@ -3442,7 +3442,7 @@ namespace ts {
34423442
// If a FunctionDeclaration's subtree has marked the container as needing to capture the
34433443
// lexical this, or the function contains parameters with initializers, then this node is
34443444
// ES6 syntax.
3445-
if (subtreeFlags & TransformFlags.ES2015FunctionSyntaxMask) {
3445+
if (subtreeFlags & TransformFlags.ContainsCapturedLexicalThis) {
34463446
transformFlags |= TransformFlags.AssertES2015;
34473447
}
34483448

@@ -3485,7 +3485,7 @@ namespace ts {
34853485
// If a FunctionExpression's subtree has marked the container as needing to capture the
34863486
// lexical this, or the function contains parameters with initializers, then this node is
34873487
// ES6 syntax.
3488-
if (subtreeFlags & TransformFlags.ES2015FunctionSyntaxMask) {
3488+
if (subtreeFlags & TransformFlags.ContainsCapturedLexicalThis) {
34893489
transformFlags |= TransformFlags.AssertES2015;
34903490
}
34913491

@@ -3567,7 +3567,7 @@ namespace ts {
35673567

35683568
function computeVariableDeclaration(node: VariableDeclaration, subtreeFlags: TransformFlags) {
35693569
let transformFlags = subtreeFlags;
3570-
transformFlags |= TransformFlags.AssertES2015 | TransformFlags.ContainsBindingPattern;
3570+
transformFlags |= TransformFlags.AssertES2015 | TransformFlags.ContainsBindingPattern; // TODO(rbuckton): Why are these set unconditionally?
35713571

35723572
// A VariableDeclaration containing ObjectRest is ES2018 syntax
35733573
if (subtreeFlags & TransformFlags.ContainsObjectRestOrSpread) {
@@ -3890,14 +3890,7 @@ namespace ts {
38903890
break;
38913891

38923892
case SyntaxKind.ArrayLiteralExpression:
3893-
case SyntaxKind.NewExpression:
38943893
excludeFlags = TransformFlags.ArrayLiteralOrCallOrNewExcludes;
3895-
if (subtreeFlags & TransformFlags.ContainsRestOrSpread) {
3896-
// If the this node contains a SpreadExpression, then it is an ES6
3897-
// node.
3898-
transformFlags |= TransformFlags.AssertES2015;
3899-
}
3900-
39013894
break;
39023895

39033896
case SyntaxKind.DoStatement:

src/compiler/transformers/es2015.ts

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ namespace ts {
194194
ConstructorWithCapturedSuper = 1 << 12, // Enclosed in a constructor that captures 'this' for use with 'super'
195195
ComputedPropertyName = 1 << 13, // Enclosed in a computed property name
196196
// NOTE: do not add more ancestor flags without also updating AncestorFactsMask below.
197+
// NOTE: when adding a new ancestor flag, be sure to update the subtree flags below.
197198

198199
//
199200
// Ancestor masks
@@ -255,9 +256,11 @@ namespace ts {
255256
//
256257
// Subtree facts
257258
//
258-
NewTarget = 1 << 14, // Contains a 'new.target' meta-property
259-
NewTargetInComputedPropertyName = 1 << 15, // Contains a 'new.target' meta-property in a computed property name.
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.
260261

262+
LexicalThis = 1 << 16, // Contains a lexical `this` reference.
263+
LexicalThisInComputedPropertyName = 1 << 17, // Contains a lexical `this` reference in a computed property name.
261264

262265
//
263266
// Subtree masks
@@ -596,6 +599,12 @@ namespace ts {
596599
}
597600

598601
function visitThisKeyword(node: Node): Node {
602+
if (hierarchyFacts & HierarchyFacts.ComputedPropertyName) {
603+
hierarchyFacts |= HierarchyFacts.LexicalThisInComputedPropertyName;
604+
}
605+
else {
606+
hierarchyFacts |= HierarchyFacts.LexicalThis;
607+
}
599608
if (convertedLoopState) {
600609
if (hierarchyFacts & HierarchyFacts.ArrowFunction) {
601610
// if the enclosing function is an ArrowFunction then we use the captured 'this' keyword.
@@ -1214,14 +1223,14 @@ namespace ts {
12141223
}
12151224
}
12161225

1217-
/**
1218-
* Gets a value indicating whether we need to add default value assignments for a
1219-
* function-like node.
1220-
*
1221-
* @param node A function-like node.
1222-
*/
1223-
function shouldAddDefaultValueAssignments(node: FunctionLikeDeclaration): boolean {
1224-
return (node.transformFlags & TransformFlags.ContainsDefaultValueAssignments) !== 0;
1226+
function hasDefaultValueOrBindingPattern(node: ParameterDeclaration) {
1227+
return node.initializer !== undefined
1228+
|| isBindingPattern(node.name);
1229+
}
1230+
1231+
function hasDefaultValueOrBindingPatternOrRest(node: ParameterDeclaration) {
1232+
return hasDefaultValueOrBindingPattern(node)
1233+
|| node.dotDotDotToken !== undefined;
12251234
}
12261235

12271236
/**
@@ -1232,7 +1241,7 @@ namespace ts {
12321241
* @param node A function-like node.
12331242
*/
12341243
function addDefaultValueAssignmentsIfNeeded(statements: Statement[], node: FunctionLikeDeclaration): void {
1235-
if (!shouldAddDefaultValueAssignments(node)) {
1244+
if (!some(node.parameters, hasDefaultValueOrBindingPattern)) {
12361245
return;
12371246
}
12381247

@@ -1744,6 +1753,10 @@ namespace ts {
17441753
return func;
17451754
}
17461755

1756+
function containsCapturedLexicalThis(node: Node) {
1757+
return (node.transformFlags & TransformFlags.ContainsCapturedLexicalThis) !== 0;
1758+
}
1759+
17471760
/**
17481761
* Visits a FunctionExpression node.
17491762
*
@@ -1757,7 +1770,9 @@ namespace ts {
17571770
convertedLoopState = undefined;
17581771

17591772
const parameters = visitParameterList(node.parameters, visitor, context);
1760-
const body = node.transformFlags & TransformFlags.ES2015
1773+
const shouldTransform = forEachChild(node, containsCapturedLexicalThis)
1774+
|| some(node.parameters, hasDefaultValueOrBindingPatternOrRest);
1775+
const body = shouldTransform
17611776
? transformFunctionBody(node)
17621777
: visitFunctionBodyDownLevel(node);
17631778
const name = hierarchyFacts & HierarchyFacts.NewTarget
@@ -1788,7 +1803,9 @@ namespace ts {
17881803
convertedLoopState = undefined;
17891804
const ancestorFacts = enterSubtree(HierarchyFacts.FunctionExcludes, HierarchyFacts.FunctionIncludes);
17901805
const parameters = visitParameterList(node.parameters, visitor, context);
1791-
const body = node.transformFlags & TransformFlags.ES2015
1806+
const shouldTransform = forEachChild(node, containsCapturedLexicalThis)
1807+
|| some(node.parameters, hasDefaultValueOrBindingPatternOrRest);
1808+
const body = shouldTransform
17921809
? transformFunctionBody(node)
17931810
: visitFunctionBodyDownLevel(node);
17941811
const name = hierarchyFacts & HierarchyFacts.NewTarget
@@ -2074,7 +2091,7 @@ namespace ts {
20742091
* @param node A VariableDeclarationList node.
20752092
*/
20762093
function visitVariableDeclarationList(node: VariableDeclarationList): VariableDeclarationList {
2077-
if (node.transformFlags & TransformFlags.ES2015) {
2094+
if (node.flags & NodeFlags.BlockScoped || node.transformFlags & TransformFlags.ContainsBindingPattern) {
20782095
if (node.flags & NodeFlags.BlockScoped) {
20792096
enableSubstitutionsForBlockScopedBindings();
20802097
}
@@ -3561,7 +3578,7 @@ namespace ts {
35613578
* @param node An ArrayLiteralExpression node.
35623579
*/
35633580
function visitArrayLiteralExpression(node: ArrayLiteralExpression): Expression {
3564-
if (node.transformFlags & TransformFlags.ES2015) {
3581+
if (some(node.elements, isSpreadElement)) {
35653582
// We are here because we contain a SpreadElementExpression.
35663583
return transformAndSpreadElements(node.elements, /*needsUniqueCopy*/ true, !!node.multiLine, /*hasTrailingComma*/ !!node.elements.hasTrailingComma);
35673584
}
@@ -3578,7 +3595,10 @@ namespace ts {
35783595
return visitTypeScriptClassWrapper(node);
35793596
}
35803597

3581-
if (node.transformFlags & TransformFlags.ES2015) {
3598+
const expression = skipOuterExpressions(node.expression);
3599+
if (expression.kind === SyntaxKind.SuperKeyword ||
3600+
isSuperProperty(expression) ||
3601+
some(node.arguments, isSpreadElement)) {
35823602
return visitCallExpressionWithPotentialCapturedThisAssignment(node, /*assignToCapturedThis*/ true);
35833603
}
35843604

@@ -3820,7 +3840,7 @@ namespace ts {
38203840
* @param node A NewExpression node.
38213841
*/
38223842
function visitNewExpression(node: NewExpression): LeftHandSideExpression {
3823-
if (node.transformFlags & TransformFlags.ContainsRestOrSpread) {
3843+
if (some(node.arguments, isSpreadElement)) {
38243844
// We are here because we contain a SpreadElementExpression.
38253845
// [source]
38263846
// new C(...a)

src/compiler/types.ts

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5045,9 +5045,9 @@ namespace ts {
50455045
ContainsTypeScript = 1 << 1,
50465046
ContainsJsx = 1 << 2,
50475047
ContainsESNext = 1 << 3,
5048-
ContainsES2017 = 1 << 4,
5049-
ContainsES2016 = 1 << 5,
5050-
ES2015 = 1 << 6,
5048+
ContainsES2018 = 1 << 4,
5049+
ContainsES2017 = 1 << 5,
5050+
ContainsES2016 = 1 << 6,
50515051
ContainsES2015 = 1 << 7,
50525052
Generator = 1 << 8,
50535053
ContainsGenerator = 1 << 9,
@@ -5057,21 +5057,21 @@ namespace ts {
50575057
// Markers
50585058
// - Flags used to indicate that a subtree contains a specific transformation.
50595059
ContainsTypeScriptClassSyntax = 1 << 12, // Decorators, Property Initializers, Parameter Property Initializers
5060+
50605061
ContainsLexicalThis = 1 << 13,
50615062
ContainsCapturedLexicalThis = 1 << 14,
5063+
50625064
ContainsLexicalThisInComputedPropertyName = 1 << 15,
5063-
ContainsDefaultValueAssignments = 1 << 16,
5064-
ContainsRestOrSpread = 1 << 17,
5065-
ContainsObjectRestOrSpread = 1 << 18,
5066-
ContainsComputedPropertyName = 1 << 19,
5067-
ContainsBlockScopedBinding = 1 << 20,
5068-
ContainsBindingPattern = 1 << 21,
5069-
ContainsYield = 1 << 22,
5070-
ContainsHoistedDeclarationOrCompletion = 1 << 23,
5071-
ContainsDynamicImport = 1 << 24,
5072-
Super = 1 << 25,
5073-
ContainsSuper = 1 << 26,
5074-
ContainsES2018 = 1 << 27,
5065+
ContainsRestOrSpread = 1 << 16,
5066+
ContainsObjectRestOrSpread = 1 << 17,
5067+
ContainsComputedPropertyName = 1 << 18,
5068+
ContainsBlockScopedBinding = 1 << 19,
5069+
ContainsBindingPattern = 1 << 20,
5070+
ContainsYield = 1 << 21,
5071+
ContainsHoistedDeclarationOrCompletion = 1 << 22,
5072+
ContainsDynamicImport = 1 << 23,
5073+
Super = 1 << 24,
5074+
ContainsSuper = 1 << 25,
50755075

50765076
// Please leave this as 1 << 29.
50775077
// It is the maximum bit we can set before we outgrow the size of a v8 small integer (SMI) on an x86 system.
@@ -5086,20 +5086,20 @@ namespace ts {
50865086
AssertES2018 = ContainsES2018,
50875087
AssertES2017 = ContainsES2017,
50885088
AssertES2016 = ContainsES2016,
5089-
AssertES2015 = ES2015 | ContainsES2015,
5089+
AssertES2015 = ContainsES2015,
50905090
AssertGenerator = Generator | ContainsGenerator,
50915091
AssertDestructuringAssignment = DestructuringAssignment | ContainsDestructuringAssignment,
50925092

50935093
// Scope Exclusions
50945094
// - Bitmasks that exclude flags from propagating out of a specific context
50955095
// into the subtree flags of their container.
5096-
OuterExpressionExcludes = TypeScript | ES2015 | DestructuringAssignment | Generator | HasComputedFlags,
5096+
OuterExpressionExcludes = TypeScript | DestructuringAssignment | Generator | HasComputedFlags,
50975097
PropertyAccessExcludes = OuterExpressionExcludes | Super,
50985098
NodeExcludes = PropertyAccessExcludes | ContainsSuper,
5099-
ArrowFunctionExcludes = NodeExcludes | ContainsTypeScriptClassSyntax | ContainsDefaultValueAssignments | ContainsLexicalThis | ContainsBlockScopedBinding | ContainsYield | ContainsHoistedDeclarationOrCompletion | ContainsBindingPattern | ContainsObjectRestOrSpread,
5100-
FunctionExcludes = NodeExcludes | ContainsTypeScriptClassSyntax | ContainsDefaultValueAssignments | ContainsCapturedLexicalThis | ContainsLexicalThis | ContainsBlockScopedBinding | ContainsYield | ContainsHoistedDeclarationOrCompletion | ContainsBindingPattern | ContainsObjectRestOrSpread,
5101-
ConstructorExcludes = NodeExcludes | ContainsDefaultValueAssignments | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsBlockScopedBinding | ContainsYield | ContainsHoistedDeclarationOrCompletion | ContainsBindingPattern | ContainsObjectRestOrSpread,
5102-
MethodOrAccessorExcludes = NodeExcludes | ContainsDefaultValueAssignments | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsBlockScopedBinding | ContainsYield | ContainsHoistedDeclarationOrCompletion | ContainsBindingPattern | ContainsObjectRestOrSpread,
5099+
ArrowFunctionExcludes = NodeExcludes | ContainsTypeScriptClassSyntax | ContainsLexicalThis | ContainsBlockScopedBinding | ContainsYield | ContainsHoistedDeclarationOrCompletion | ContainsBindingPattern | ContainsObjectRestOrSpread,
5100+
FunctionExcludes = NodeExcludes | ContainsTypeScriptClassSyntax | ContainsCapturedLexicalThis | ContainsLexicalThis | ContainsBlockScopedBinding | ContainsYield | ContainsHoistedDeclarationOrCompletion | ContainsBindingPattern | ContainsObjectRestOrSpread,
5101+
ConstructorExcludes = NodeExcludes | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsBlockScopedBinding | ContainsYield | ContainsHoistedDeclarationOrCompletion | ContainsBindingPattern | ContainsObjectRestOrSpread,
5102+
MethodOrAccessorExcludes = NodeExcludes | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsBlockScopedBinding | ContainsYield | ContainsHoistedDeclarationOrCompletion | ContainsBindingPattern | ContainsObjectRestOrSpread,
51035103
ClassExcludes = NodeExcludes | ContainsTypeScriptClassSyntax | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsComputedPropertyName | ContainsLexicalThisInComputedPropertyName,
51045104
ModuleExcludes = NodeExcludes | ContainsTypeScriptClassSyntax | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsBlockScopedBinding | ContainsHoistedDeclarationOrCompletion,
51055105
TypeExcludes = ~ContainsTypeScript,
@@ -5112,7 +5112,6 @@ namespace ts {
51125112

51135113
// Masks
51145114
// - Additional bitmasks
5115-
ES2015FunctionSyntaxMask = ContainsCapturedLexicalThis | ContainsDefaultValueAssignments,
51165115
}
51175116

51185117
export interface SourceMapRange extends TextRange {

0 commit comments

Comments
 (0)