Skip to content

Commit 5d9e7e1

Browse files
committed
Merge pull request #5576 from Microsoft/importsInShorthandProps
use modulekind to check if initializer for shorthand property assignm…
2 parents 14d6509 + fe770bd commit 5d9e7e1

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

src/compiler/emitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2490,7 +2490,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
24902490
// let obj = { y };
24912491
// }
24922492
// Here we need to emit obj = { y : m.y } regardless of the output target.
2493-
if (languageVersion < ScriptTarget.ES6 || isNamespaceExportReference(node.name)) {
2493+
if (modulekind !== ModuleKind.ES6 || isNamespaceExportReference(node.name)) {
24942494
// Emit identifier as an identifier
24952495
write(": ");
24962496
emit(node.name);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
tests/cases/compiler/test.ts(2,19): error TS2307: Cannot find module './missingModule'.
2+
3+
4+
==== tests/cases/compiler/existingModule.ts (0 errors) ====
5+
6+
export var x = 1;
7+
8+
==== tests/cases/compiler/test.ts (1 errors) ====
9+
import {x} from './existingModule';
10+
import {foo} from './missingModule';
11+
~~~~~~~~~~~~~~~~~
12+
!!! error TS2307: Cannot find module './missingModule'.
13+
14+
declare function use(a: any): void;
15+
16+
const test = { x, foo };
17+
18+
use(x);
19+
use(foo);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//// [tests/cases/compiler/shorthandPropertyAssignmentInES6Module.ts] ////
2+
3+
//// [existingModule.ts]
4+
5+
export var x = 1;
6+
7+
//// [test.ts]
8+
import {x} from './existingModule';
9+
import {foo} from './missingModule';
10+
11+
declare function use(a: any): void;
12+
13+
const test = { x, foo };
14+
15+
use(x);
16+
use(foo);
17+
18+
//// [existingModule.js]
19+
exports.x = 1;
20+
//// [test.js]
21+
var existingModule_1 = require('./existingModule');
22+
var missingModule_1 = require('./missingModule');
23+
const test = { x: existingModule_1.x, foo: missingModule_1.foo };
24+
use(existingModule_1.x);
25+
use(missingModule_1.foo);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// @target: ES6
2+
// @module: commonjs
3+
4+
// @filename: existingModule.ts
5+
export var x = 1;
6+
7+
// @filename: test.ts
8+
import {x} from './existingModule';
9+
import {foo} from './missingModule';
10+
11+
declare function use(a: any): void;
12+
13+
const test = { x, foo };
14+
15+
use(x);
16+
use(foo);

0 commit comments

Comments
 (0)