Skip to content

Commit 478cc32

Browse files
committed
Merge pull request microsoft#4355 from DavidSouther/ts4354
Emits safe value for import.
2 parents 06841eb + 45688e4 commit 478cc32

File tree

5 files changed

+60
-1
lines changed

5 files changed

+60
-1
lines changed

src/compiler/utilities.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ namespace ts {
240240
// Make an identifier from an external module name by extracting the string after the last "/" and replacing
241241
// all non-alphanumeric characters with underscores
242242
export function makeIdentifierFromModuleName(moduleName: string): string {
243-
return getBaseFileName(moduleName).replace(/\W/g, "_");
243+
return getBaseFileName(moduleName).replace(/^(\d)/, "_$1").replace(/\W/g, "_");
244244
}
245245

246246
export function isBlockOrCatchScoped(declaration: Declaration) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//// [tests/cases/compiler/commonjsSafeImport.ts] ////
2+
3+
//// [10_lib.ts]
4+
5+
export function Foo() {}
6+
7+
//// [main.ts]
8+
import { Foo } from './10_lib';
9+
10+
Foo();
11+
12+
13+
//// [10_lib.js]
14+
function Foo() { }
15+
exports.Foo = Foo;
16+
//// [main.js]
17+
var _10_lib_1 = require('./10_lib');
18+
_10_lib_1.Foo();
19+
20+
21+
//// [10_lib.d.ts]
22+
export declare function Foo(): void;
23+
//// [main.d.ts]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== tests/cases/compiler/10_lib.ts ===
2+
3+
export function Foo() {}
4+
>Foo : Symbol(Foo, Decl(10_lib.ts, 0, 0))
5+
6+
=== tests/cases/compiler/main.ts ===
7+
import { Foo } from './10_lib';
8+
>Foo : Symbol(Foo, Decl(main.ts, 0, 8))
9+
10+
Foo();
11+
>Foo : Symbol(Foo, Decl(main.ts, 0, 8))
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=== tests/cases/compiler/10_lib.ts ===
2+
3+
export function Foo() {}
4+
>Foo : () => void
5+
6+
=== tests/cases/compiler/main.ts ===
7+
import { Foo } from './10_lib';
8+
>Foo : () => void
9+
10+
Foo();
11+
>Foo() : void
12+
>Foo : () => void
13+
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// @target: ES5
2+
// @module: commonjs
3+
// @declaration: true
4+
// @filename: 10_lib.ts
5+
6+
export function Foo() {}
7+
8+
// @filename: main.ts
9+
import { Foo } from './10_lib';
10+
11+
Foo();

0 commit comments

Comments
 (0)