diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index cb4cd3b380..0d57bd1a6a 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2461,7 +2461,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi // let obj = { y }; // } // Here we need to emit obj = { y : m.y } regardless of the output target. - if (languageVersion < ScriptTarget.ES6 || isNamespaceExportReference(node.name)) { + if (modulekind !== ModuleKind.ES6 || isNamespaceExportReference(node.name)) { // Emit identifier as an identifier write(": "); emit(node.name); diff --git a/tests/baselines/reference/shorthandPropertyAssignmentInES6Module.errors.txt b/tests/baselines/reference/shorthandPropertyAssignmentInES6Module.errors.txt new file mode 100644 index 0000000000..6befffeee7 --- /dev/null +++ b/tests/baselines/reference/shorthandPropertyAssignmentInES6Module.errors.txt @@ -0,0 +1,23 @@ +tests/cases/compiler/test.ts(2,19): error TS2307: Cannot find module './foo2'. +tests/cases/compiler/test.ts(6,1): error TS2304: Cannot find name 'console'. +tests/cases/compiler/test.ts(7,1): error TS2304: Cannot find name 'console'. + + +==== tests/cases/compiler/foo1.ts (0 errors) ==== + + export var x = 1; + +==== tests/cases/compiler/test.ts (3 errors) ==== + import {x} from './foo1'; + import {foo} from './foo2'; + ~~~~~~~~ +!!! error TS2307: Cannot find module './foo2'. + + const test = { x, foo }; + + console.log(x); + ~~~~~~~ +!!! error TS2304: Cannot find name 'console'. + console.log(foo); + ~~~~~~~ +!!! error TS2304: Cannot find name 'console'. \ No newline at end of file diff --git a/tests/baselines/reference/shorthandPropertyAssignmentInES6Module.js b/tests/baselines/reference/shorthandPropertyAssignmentInES6Module.js new file mode 100644 index 0000000000..2865f244fc --- /dev/null +++ b/tests/baselines/reference/shorthandPropertyAssignmentInES6Module.js @@ -0,0 +1,23 @@ +//// [tests/cases/compiler/shorthandPropertyAssignmentInES6Module.ts] //// + +//// [foo1.ts] + +export var x = 1; + +//// [test.ts] +import {x} from './foo1'; +import {foo} from './foo2'; + +const test = { x, foo }; + +console.log(x); +console.log(foo); + +//// [foo1.js] +exports.x = 1; +//// [test.js] +var foo1_1 = require('./foo1'); +var foo2_1 = require('./foo2'); +const test = { x: foo1_1.x, foo: foo2_1.foo }; +console.log(foo1_1.x); +console.log(foo2_1.foo); diff --git a/tests/cases/compiler/shorthandPropertyAssignmentInES6Module.ts b/tests/cases/compiler/shorthandPropertyAssignmentInES6Module.ts new file mode 100644 index 0000000000..50e2d2cf99 --- /dev/null +++ b/tests/cases/compiler/shorthandPropertyAssignmentInES6Module.ts @@ -0,0 +1,14 @@ +// @target: ES6 +// @module: commonjs + +// @filename: foo1.ts +export var x = 1; + +// @filename: test.ts +import {x} from './foo1'; +import {foo} from './foo2'; + +const test = { x, foo }; + +console.log(x); +console.log(foo); \ No newline at end of file