Merge pull request #5576 from Microsoft/importsInShorthandProps

use modulekind to check if initializer for shorthand property assignm…
This commit is contained in:
Vladimir Matveev 2015-11-09 14:57:47 -08:00
commit 5d9e7e10c0
4 changed files with 61 additions and 1 deletions

View file

@ -2490,7 +2490,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);

View file

@ -0,0 +1,19 @@
tests/cases/compiler/test.ts(2,19): error TS2307: Cannot find module './missingModule'.
==== tests/cases/compiler/existingModule.ts (0 errors) ====
export var x = 1;
==== tests/cases/compiler/test.ts (1 errors) ====
import {x} from './existingModule';
import {foo} from './missingModule';
~~~~~~~~~~~~~~~~~
!!! error TS2307: Cannot find module './missingModule'.
declare function use(a: any): void;
const test = { x, foo };
use(x);
use(foo);

View file

@ -0,0 +1,25 @@
//// [tests/cases/compiler/shorthandPropertyAssignmentInES6Module.ts] ////
//// [existingModule.ts]
export var x = 1;
//// [test.ts]
import {x} from './existingModule';
import {foo} from './missingModule';
declare function use(a: any): void;
const test = { x, foo };
use(x);
use(foo);
//// [existingModule.js]
exports.x = 1;
//// [test.js]
var existingModule_1 = require('./existingModule');
var missingModule_1 = require('./missingModule');
const test = { x: existingModule_1.x, foo: missingModule_1.foo };
use(existingModule_1.x);
use(missingModule_1.foo);

View file

@ -0,0 +1,16 @@
// @target: ES6
// @module: commonjs
// @filename: existingModule.ts
export var x = 1;
// @filename: test.ts
import {x} from './existingModule';
import {foo} from './missingModule';
declare function use(a: any): void;
const test = { x, foo };
use(x);
use(foo);