@@ -296,21 +296,21 @@ namespace ts {
296296 * If loop contains block scoped binding captured in some function then loop body is converted to a function.
297297 * Lexical bindings declared in loop initializer will be passed into the loop body function as parameters,
298298 * however if this binding is modified inside the body - this new value should be propagated back to the original binding.
299- * This is done by declaring new variable (out parameter holder) outside of the loop for every binding that is reassigned inside the body.
299+ * This is done by declaring new variable (out parameter holder) outside of the loop for every binding that is reassigned inside the body.
300300 * On every iteration this variable is initialized with value of corresponding binding.
301301 * At every point where control flow leaves the loop either explicitly (break/continue) or implicitly (at the end of loop body)
302302 * we copy the value inside the loop to the out parameter holder.
303- *
303+ *
304304 * for (let x;;) {
305305 * let a = 1;
306306 * let b = () => a;
307307 * x++
308308 * if (...) break;
309309 * ...
310310 * }
311- *
311+ *
312312 * will be converted to
313- *
313+ *
314314 * var out_x;
315315 * var loop = function(x) {
316316 * var a = 1;
@@ -326,7 +326,7 @@ namespace ts {
326326 * x = out_x;
327327 * if (state === "break") break;
328328 * }
329- *
329+ *
330330 * NOTE: values to out parameters are not copies if loop is abrupted with 'return' - in this case this will end the entire enclosing function
331331 * so nobody can observe this new value.
332332 */
@@ -2138,6 +2138,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
21382138 return container && container . kind !== SyntaxKind . SourceFile ;
21392139 }
21402140
2141+ // Return true if identifier resolves to an imported identifier
2142+ function isImportedReference ( node : Identifier ) {
2143+ const declaration = resolver . getReferencedImportDeclaration ( node ) ;
2144+ return declaration && ( declaration . kind === SyntaxKind . ImportClause || declaration . kind === SyntaxKind . ImportSpecifier ) ;
2145+ }
2146+
21412147 function emitShorthandPropertyAssignment ( node : ShorthandPropertyAssignment ) {
21422148 // The name property of a short-hand property assignment is considered an expression position, so here
21432149 // we manually emit the identifier to avoid rewriting.
@@ -2151,7 +2157,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
21512157 // let obj = { y };
21522158 // }
21532159 // Here we need to emit obj = { y : m.y } regardless of the output target.
2154- if ( modulekind !== ModuleKind . ES6 || isNamespaceExportReference ( node . name ) ) {
2160+ // The same rules apply for imported identifiers when targeting module formats with indirect access to
2161+ // the imported identifiers. For example, when targeting CommonJS:
2162+ //
2163+ // import {foo} from './foo';
2164+ // export const baz = { foo };
2165+ //
2166+ // Must be transformed into:
2167+ //
2168+ // const foo_1 = require('./foo');
2169+ // exports.baz = { foo: foo_1.foo };
2170+ //
2171+ if ( languageVersion < ScriptTarget . ES6 || ( modulekind !== ModuleKind . ES6 && isImportedReference ( node . name ) ) || isNamespaceExportReference ( node . name ) ) {
21552172 // Emit identifier as an identifier
21562173 write ( ": " ) ;
21572174 emit ( node . name ) ;
@@ -3073,7 +3090,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
30733090 }
30743091
30753092 writeLine ( ) ;
3076- // end of loop body -> copy out parameter
3093+ // end of loop body -> copy out parameter
30773094 copyLoopOutParameters ( convertedLoopState , CopyDirection . ToOutParameter , /*emitAsStatements*/ true ) ;
30783095
30793096 decreaseIndent ( ) ;
@@ -3572,7 +3589,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
35723589 }
35733590 else {
35743591 convertedLoopState . nonLocalJumps |= Jump . Continue ;
3575- // note: return value is emitted only to simplify debugging, call to converted loop body does not do any dispatching on it.
3592+ // note: return value is emitted only to simplify debugging, call to converted loop body does not do any dispatching on it.
35763593 write ( `"continue";` ) ;
35773594 }
35783595 }
@@ -7267,7 +7284,7 @@ const _super = (function (geti, seti) {
72677284 }
72687285
72697286 // text should be quoted string
7270- // for deduplication purposes in key remove leading and trailing quotes so 'a' and "a" will be considered the same
7287+ // for deduplication purposes in key remove leading and trailing quotes so 'a' and "a" will be considered the same
72717288 const key = text . substr ( 1 , text . length - 2 ) ;
72727289
72737290 if ( hasProperty ( groupIndices , key ) ) {
0 commit comments