mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-31 08:07:10 -05:00
Fix CJS local binding emit for ES decorators (#53725)
This commit is contained in:
@@ -46,6 +46,7 @@ import {
|
||||
getAllDecoratorsOfClassElement,
|
||||
getCommentRange,
|
||||
getEffectiveBaseTypeNode,
|
||||
getEmitScriptTarget,
|
||||
getFirstConstructorWithBody,
|
||||
getHeritageClause,
|
||||
getNonAssignmentOperatorForCompoundAssignment,
|
||||
@@ -279,6 +280,9 @@ export function transformESDecorators(context: TransformationContext): (x: Sourc
|
||||
hoistVariableDeclaration,
|
||||
} = context;
|
||||
|
||||
const compilerOptions = context.getCompilerOptions();
|
||||
const languageVersion = getEmitScriptTarget(compilerOptions);
|
||||
|
||||
let top: LexicalEnvironmentStackEntry | undefined;
|
||||
let classInfo: ClassInfo | undefined;
|
||||
let classThis: Identifier | undefined;
|
||||
@@ -1003,7 +1007,12 @@ export function transformESDecorators(context: TransformationContext): (x: Sourc
|
||||
Debug.assertIsDefined(node.name, "A class declaration that is not a default export must have a name.");
|
||||
const iife = transformClassLike(node, factory.createStringLiteralFromNode(node.name));
|
||||
const modifiers = visitNodes(node.modifiers, modifierVisitor, isModifier);
|
||||
const varDecl = factory.createVariableDeclaration(node.name, /*exclamationToken*/ undefined, /*type*/ undefined, iife);
|
||||
// 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);
|
||||
const varDecl = factory.createVariableDeclaration(declName, /*exclamationToken*/ undefined, /*type*/ undefined, iife);
|
||||
const varDecls = factory.createVariableDeclarationList([varDecl], NodeFlags.Let);
|
||||
const statement = factory.createVariableStatement(modifiers, varDecls);
|
||||
setOriginalNode(statement, node);
|
||||
|
||||
Reference in New Issue
Block a user