@@ -5278,9 +5278,11 @@ const _super = (function (geti, seti) {
5278
5278
5279
5279
function emitClassLikeDeclarationForES6AndHigher ( node : ClassLikeDeclaration ) {
5280
5280
let decoratedClassAlias : string ;
5281
- const thisNodeIsDecorated = nodeIsDecorated ( node ) ;
5281
+ const isHoistedDeclarationInSystemModule = shouldHoistDeclarationInSystemJsModule ( node ) ;
5282
+ const isDecorated = nodeIsDecorated ( node ) ;
5283
+ const rewriteAsClassExpression = isDecorated || isHoistedDeclarationInSystemModule ;
5282
5284
if ( node . kind === SyntaxKind . ClassDeclaration ) {
5283
- if ( thisNodeIsDecorated ) {
5285
+ if ( rewriteAsClassExpression ) {
5284
5286
// When we emit an ES6 class that has a class decorator, we must tailor the
5285
5287
// emit to certain specific cases.
5286
5288
//
@@ -5361,7 +5363,10 @@ const _super = (function (geti, seti) {
5361
5363
// [Example 4]
5362
5364
//
5363
5365
5364
- if ( resolver . getNodeCheckFlags ( node ) & NodeCheckFlags . ClassWithBodyScopedClassBinding ) {
5366
+ // NOTE: we reuse the same rewriting logic for cases when targeting ES6 and module kind is System.
5367
+ // Because of hoisting top level class declaration need to be emitted as class expressions.
5368
+ // Double bind case is only required if node is decorated.
5369
+ if ( isDecorated && resolver . getNodeCheckFlags ( node ) & NodeCheckFlags . ClassWithBodyScopedClassBinding ) {
5365
5370
decoratedClassAlias = unescapeIdentifier ( makeUniqueName ( node . name ? node . name . text : "default" ) ) ;
5366
5371
decoratedClassAliases [ getNodeId ( node ) ] = decoratedClassAlias ;
5367
5372
write ( `let ${ decoratedClassAlias } ;` ) ;
@@ -5372,7 +5377,9 @@ const _super = (function (geti, seti) {
5372
5377
write ( "export " ) ;
5373
5378
}
5374
5379
5375
- write ( "let " ) ;
5380
+ if ( ! isHoistedDeclarationInSystemModule ) {
5381
+ write ( "let " ) ;
5382
+ }
5376
5383
emitDeclarationName ( node ) ;
5377
5384
if ( decoratedClassAlias !== undefined ) {
5378
5385
write ( ` = ${ decoratedClassAlias } ` ) ;
@@ -5416,7 +5423,7 @@ const _super = (function (geti, seti) {
5416
5423
// emit name if
5417
5424
// - node has a name
5418
5425
// - this is default export with static initializers
5419
- if ( node . name || ( node . flags & NodeFlags . Default && ( staticProperties . length > 0 || modulekind !== ModuleKind . ES6 ) && ! thisNodeIsDecorated ) ) {
5426
+ if ( node . name || ( node . flags & NodeFlags . Default && ( staticProperties . length > 0 || modulekind !== ModuleKind . ES6 ) && ! rewriteAsClassExpression ) ) {
5420
5427
write ( " " ) ;
5421
5428
emitDeclarationName ( node ) ;
5422
5429
}
@@ -5436,7 +5443,7 @@ const _super = (function (geti, seti) {
5436
5443
writeLine ( ) ;
5437
5444
emitToken ( SyntaxKind . CloseBraceToken , node . members . end ) ;
5438
5445
5439
- if ( thisNodeIsDecorated ) {
5446
+ if ( rewriteAsClassExpression ) {
5440
5447
decoratedClassAliases [ getNodeId ( node ) ] = undefined ;
5441
5448
write ( ";" ) ;
5442
5449
}
@@ -5476,7 +5483,7 @@ const _super = (function (geti, seti) {
5476
5483
// module), export it
5477
5484
if ( node . flags & NodeFlags . Default ) {
5478
5485
// if this is a top level default export of decorated class, write the export after the declaration.
5479
- if ( thisNodeIsDecorated ) {
5486
+ if ( isDecorated ) {
5480
5487
writeLine ( ) ;
5481
5488
write ( "export default " ) ;
5482
5489
emitDeclarationName ( node ) ;
0 commit comments