File tree Expand file tree Collapse file tree 2 files changed +29
-3
lines changed
packages/angular_devkit/build_optimizer/src/transforms Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -299,11 +299,16 @@ function findTs2_3EnumIife(
299
299
}
300
300
301
301
const memberArgument = assignment . argumentExpression ;
302
- if ( ! memberArgument || ! ts . isBinaryExpression ( memberArgument )
303
- || memberArgument . operatorToken . kind !== ts . SyntaxKind . FirstAssignment ) {
304
- return null ;
302
+ // String enum
303
+ if ( ts . isStringLiteral ( memberArgument ) ) {
304
+ return [ callExpression , exportExpression ] ;
305
305
}
306
306
307
+ // Non string enums
308
+ if ( ! ts . isBinaryExpression ( memberArgument )
309
+ || memberArgument . operatorToken . kind !== ts . SyntaxKind . FirstAssignment ) {
310
+ return null ;
311
+ }
307
312
308
313
if ( ! ts . isElementAccessExpression ( memberArgument . left ) ) {
309
314
return null ;
Original file line number Diff line number Diff line change @@ -514,6 +514,27 @@ describe('wrap enums and classes transformer', () => {
514
514
expect ( tags . oneLine `${ transform ( input ) } ` ) . toEqual ( tags . oneLine `${ output } ` ) ;
515
515
} ) ;
516
516
517
+ it ( 'wraps TS string enums in IIFE' , ( ) => {
518
+ const input = tags . stripIndent `
519
+ export var NotificationKind;
520
+ (function (NotificationKind) {
521
+ NotificationKind["NEXT"] = "N";
522
+ NotificationKind["ERROR"] = "E";
523
+ NotificationKind["COMPLETE"] = "C";
524
+ })(NotificationKind || (NotificationKind = {}));
525
+ ` ;
526
+ const output = tags . stripIndent `
527
+ export var NotificationKind = /*@__PURE__*/ (function (NotificationKind) {
528
+ NotificationKind["NEXT"] = "N";
529
+ NotificationKind["ERROR"] = "E";
530
+ NotificationKind["COMPLETE"] = "C";
531
+ return NotificationKind;
532
+ })({});
533
+ ` ;
534
+
535
+ expect ( tags . oneLine `${ transform ( input ) } ` ) . toEqual ( tags . oneLine `${ output } ` ) ;
536
+ } ) ;
537
+
517
538
it ( 'wraps tsickle enums in IIFE' , ( ) => {
518
539
const input = tags . stripIndent `
519
540
/** @enum {number} */
You can’t perform that action at this time.
0 commit comments