fix(35050): Decorator emit incorrect within try block (#41951)

* fix(35050): fix decorated block-scoped class emit

* Only use internal name when targeting ES5/3

Co-authored-by: Ron Buckton <ron.buckton@microsoft.com>
This commit is contained in:
Oleksandr T
2021-07-08 20:48:02 +03:00
committed by GitHub
parent e881a69939
commit a15030ff6f
13 changed files with 455 additions and 2 deletions

View File

@@ -823,7 +823,12 @@ namespace ts {
const location = moveRangePastDecorators(node);
const classAlias = getClassAliasIfNeeded(node);
const declName = factory.getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true);
// When we transform to ES5/3 this will be moved inside an IIFE and should reference the name
// without any block-scoped variable collision handling
const declName = languageVersion <= ScriptTarget.ES2015 ?
factory.getInternalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true) :
factory.getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true);
// ... = class ${name} ${heritageClauses} {
// ${members}
@@ -1233,7 +1238,12 @@ namespace ts {
}
const classAlias = classAliases && classAliases[getOriginalNodeId(node)];
const localName = factory.getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true);
// When we transform to ES5/3 this will be moved inside an IIFE and should reference the name
// without any block-scoped variable collision handling
const localName = languageVersion <= ScriptTarget.ES2015 ?
factory.getInternalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true) :
factory.getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true);
const decorate = emitHelpers().createDecorateHelper(decoratorExpressions, localName);
const expression = factory.createAssignment(localName, classAlias ? factory.createAssignment(classAlias, decorate) : decorate);
setEmitFlags(expression, EmitFlags.NoComments);