Skip to content

Commit f052334

Browse files
committed
do not treat class declarations as nodes that start lexical environment
1 parent 8e1d5d9 commit f052334

1 file changed

Lines changed: 25 additions & 8 deletions

File tree

  • src/compiler/transformers

src/compiler/transformers/es6.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,23 +189,30 @@ namespace ts {
189189
}
190190

191191
function visitor(node: Node): VisitResult<Node> {
192+
return saveStateAndInvoke(node, dispatcher);
193+
}
194+
195+
function dispatcher(node: Node): VisitResult<Node> {
196+
return convertedLoopState
197+
? visitorForConvertedLoopWorker(node)
198+
: visitorWorker(node);
199+
}
200+
201+
function saveStateAndInvoke<T>(node: Node, f: (node: Node) => T): T {
192202
const savedContainingNonArrowFunction = containingNonArrowFunction;
193203
const savedCurrentParent = currentParent;
194204
const savedCurrentNode = currentNode;
195205
const savedEnclosingBlockScopeContainer = enclosingBlockScopeContainer;
196206
const savedEnclosingBlockScopeContainerParent = enclosingBlockScopeContainerParent;
197207

198208
const savedConvertedLoopState = convertedLoopState;
199-
if (nodeStartsNewLexicalEnvironment(node) || isClassLike(node)) {
209+
if (nodeStartsNewLexicalEnvironment(node)) {
200210
// don't treat content of nodes that start new lexical environment or class-like nodes as part of converted loop copy
201211
convertedLoopState = undefined;
202212
}
203213

204214
onBeforeVisitNode(node);
205-
206-
const visited = convertedLoopState
207-
? visitorForConvertedLoopWorker(node)
208-
: visitorWorker(node);
215+
const visited = f(node);
209216

210217
convertedLoopState = savedConvertedLoopState;
211218
containingNonArrowFunction = savedContainingNonArrowFunction;
@@ -237,7 +244,7 @@ namespace ts {
237244
function visitorForConvertedLoopWorker(node: Node): VisitResult<Node> {
238245
const savedUseCapturedThis = useCapturedThis;
239246

240-
if (nodeStartsNewLexicalEnvironment(node) || isClassLike(node)) {
247+
if (nodeStartsNewLexicalEnvironment(node)) {
241248
useCapturedThis = false
242249
}
243250

@@ -703,13 +710,22 @@ namespace ts {
703710
addDefaultSuperCallIfNeeded(statements, constructor, hasExtendsClause, hasSynthesizedSuper);
704711

705712
if (constructor) {
706-
addRange(statements, visitNodes(constructor.body.statements, visitor, isStatement, hasSynthesizedSuper ? 1 : 0));
713+
const body = saveStateAndInvoke(constructor, hasSynthesizedSuper ? transformConstructorBodyWithSynthesizedSuper : transformConstructorBodyWithoutSynthesizedSuper);
714+
addRange(statements, body);
707715
}
708716

709717
addRange(statements, endLexicalEnvironment());
710718
return createBlock(statements, /*location*/ constructor && constructor.body, /*multiLine*/ true);
711719
}
712720

721+
function transformConstructorBodyWithSynthesizedSuper(node: ConstructorDeclaration) {
722+
return visitNodes(node.body.statements, visitor, isStatement, 1);
723+
}
724+
725+
function transformConstructorBodyWithoutSynthesizedSuper(node: ConstructorDeclaration) {
726+
return visitNodes(node.body.statements, visitor, isStatement, 0);
727+
}
728+
713729
/**
714730
* Adds a synthesized call to `_super` if it is needed.
715731
*
@@ -1141,7 +1157,7 @@ namespace ts {
11411157
/*asteriskToken*/ undefined,
11421158
name,
11431159
visitNodes(node.parameters, visitor, isParameter),
1144-
transformFunctionBody(node),
1160+
saveStateAndInvoke(node, transformFunctionBody),
11451161
location,
11461162
/*original*/ node
11471163
);
@@ -2483,6 +2499,7 @@ namespace ts {
24832499
return containingNonArrowFunction
24842500
&& isClassElement(containingNonArrowFunction)
24852501
&& !hasModifier(containingNonArrowFunction, ModifierFlags.Static)
2502+
&& currentParent.kind !== SyntaxKind.CallExpression
24862503
? createPropertyAccess(createIdentifier("_super"), "prototype")
24872504
: createIdentifier("_super");
24882505
}

0 commit comments

Comments
 (0)