@@ -2613,11 +2613,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
26132613 return isSourceFileLevelDeclarationInSystemJsModule ( targetDeclaration , /*isExported*/ true ) ;
26142614 }
26152615
2616+ function isNameOfExportedDeclarationInNonES6Module ( node : Node ) : boolean {
2617+ if ( modulekind === ModuleKind . System || node . kind !== SyntaxKind . Identifier || nodeIsSynthesized ( node ) ) {
2618+ return false ;
2619+ }
2620+
2621+ return ! exportEquals && exportSpecifiers && hasProperty ( exportSpecifiers , ( < Identifier > node ) . text ) ;
2622+ }
2623+
26162624 function emitPrefixUnaryExpression ( node : PrefixUnaryExpression ) {
2617- const exportChanged = ( node . operator === SyntaxKind . PlusPlusToken || node . operator === SyntaxKind . MinusMinusToken ) &&
2625+ const isPlusPlusOrMinusMinus = ( node . operator === SyntaxKind . PlusPlusToken
2626+ || node . operator === SyntaxKind . MinusMinusToken ) ;
2627+ const externalExportChanged = isPlusPlusOrMinusMinus &&
26182628 isNameOfExportedSourceLevelDeclarationInSystemExternalModule ( node . operand ) ;
26192629
2620- if ( exportChanged ) {
2630+ if ( externalExportChanged ) {
26212631 // emit
26222632 // ++x
26232633 // as
@@ -2626,6 +2636,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
26262636 emitNodeWithoutSourceMap ( node . operand ) ;
26272637 write ( `", ` ) ;
26282638 }
2639+ const internalExportChanged = isPlusPlusOrMinusMinus &&
2640+ isNameOfExportedDeclarationInNonES6Module ( node . operand ) ;
2641+
2642+ if ( internalExportChanged ) {
2643+ emitAliasEqual ( < Identifier > node . operand ) ;
2644+ }
26292645
26302646 write ( tokenToString ( node . operator ) ) ;
26312647 // In some cases, we need to emit a space between the operator and the operand. One obvious case
@@ -2651,14 +2667,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
26512667 }
26522668 emit ( node . operand ) ;
26532669
2654- if ( exportChanged ) {
2670+ if ( externalExportChanged ) {
26552671 write ( ")" ) ;
26562672 }
26572673 }
26582674
26592675 function emitPostfixUnaryExpression ( node : PostfixUnaryExpression ) {
2660- const exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule ( node . operand ) ;
2661- if ( exportChanged ) {
2676+ const externalExportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule ( node . operand ) ;
2677+ const internalExportChanged = isNameOfExportedDeclarationInNonES6Module ( node . operand ) ;
2678+
2679+ if ( externalExportChanged ) {
26622680 // export function returns the value that was passes as the second argument
26632681 // however for postfix unary expressions result value should be the value before modification.
26642682 // emit 'x++' as '(export('x', ++x) - 1)' and 'x--' as '(export('x', --x) + 1)'
@@ -2676,6 +2694,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
26762694 write ( ") + 1)" ) ;
26772695 }
26782696 }
2697+ else if ( internalExportChanged ) {
2698+ emitAliasEqual ( < Identifier > node . operand ) ;
2699+ emit ( node . operand ) ;
2700+ if ( node . operator === SyntaxKind . PlusPlusToken ) {
2701+ write ( " += 1" ) ;
2702+ }
2703+ else {
2704+ write ( " -= 1" ) ;
2705+ }
2706+ }
26792707 else {
26802708 emit ( node . operand ) ;
26812709 write ( tokenToString ( node . operator ) ) ;
@@ -2777,24 +2805,50 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
27772805 }
27782806 }
27792807
2808+ function emitAliasEqual ( name : Identifier ) : boolean {
2809+ for ( const specifier of exportSpecifiers [ name . text ] ) {
2810+ emitStart ( specifier . name ) ;
2811+ emitContainingModuleName ( specifier ) ;
2812+ if ( languageVersion === ScriptTarget . ES3 && name . text === "default" ) {
2813+ write ( '["default"]' ) ;
2814+ }
2815+ else {
2816+ write ( "." ) ;
2817+ emitNodeWithCommentsAndWithoutSourcemap ( specifier . name ) ;
2818+ }
2819+ emitEnd ( specifier . name ) ;
2820+ write ( " = " ) ;
2821+ }
2822+ return true ;
2823+ }
2824+
27802825 function emitBinaryExpression ( node : BinaryExpression ) {
27812826 if ( languageVersion < ScriptTarget . ES6 && node . operatorToken . kind === SyntaxKind . EqualsToken &&
27822827 ( node . left . kind === SyntaxKind . ObjectLiteralExpression || node . left . kind === SyntaxKind . ArrayLiteralExpression ) ) {
27832828 emitDestructuring ( node , node . parent . kind === SyntaxKind . ExpressionStatement ) ;
27842829 }
27852830 else {
2786- const exportChanged =
2787- node . operatorToken . kind >= SyntaxKind . FirstAssignment &&
2788- node . operatorToken . kind <= SyntaxKind . LastAssignment &&
2831+ const isAssignment = isAssignmentOperator ( node . operatorToken . kind ) ;
2832+
2833+ const externalExportChanged = isAssignment &&
27892834 isNameOfExportedSourceLevelDeclarationInSystemExternalModule ( node . left ) ;
27902835
2791- if ( exportChanged ) {
2836+ if ( externalExportChanged ) {
27922837 // emit assignment 'x <op> y' as 'exports("x", x <op> y)'
27932838 write ( `${ exportFunctionForFile } ("` ) ;
27942839 emitNodeWithoutSourceMap ( node . left ) ;
27952840 write ( `", ` ) ;
27962841 }
27972842
2843+ const internalExportChanged = isAssignment &&
2844+ isNameOfExportedDeclarationInNonES6Module ( node . left ) ;
2845+
2846+ if ( internalExportChanged ) {
2847+ // export { foo }
2848+ // emit foo = 2 as exports.foo = foo = 2
2849+ emitAliasEqual ( < Identifier > node . left ) ;
2850+ }
2851+
27982852 if ( node . operatorToken . kind === SyntaxKind . AsteriskAsteriskToken || node . operatorToken . kind === SyntaxKind . AsteriskAsteriskEqualsToken ) {
27992853 // Downleveled emit exponentiation operator using Math.pow
28002854 emitExponentiationOperator ( node ) ;
@@ -2815,7 +2869,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
28152869 decreaseIndentIf ( indentedBeforeOperator , indentedAfterOperator ) ;
28162870 }
28172871
2818- if ( exportChanged ) {
2872+ if ( externalExportChanged ) {
28192873 write ( ")" ) ;
28202874 }
28212875 }
0 commit comments