Merge pull request #4355 from DavidSouther/ts4354

Emits safe value for import.
This commit is contained in:
Mohamed Hegazy 2015-08-19 10:25:25 -07:00
commit 478cc32e5e
5 changed files with 60 additions and 1 deletions

View File

@ -240,7 +240,7 @@ namespace ts {
// Make an identifier from an external module name by extracting the string after the last "/" and replacing
// all non-alphanumeric characters with underscores
export function makeIdentifierFromModuleName(moduleName: string): string {
return getBaseFileName(moduleName).replace(/\W/g, "_");
return getBaseFileName(moduleName).replace(/^(\d)/, "_$1").replace(/\W/g, "_");
}
export function isBlockOrCatchScoped(declaration: Declaration) {

View File

@ -0,0 +1,23 @@
//// [tests/cases/compiler/commonjsSafeImport.ts] ////
//// [10_lib.ts]
export function Foo() {}
//// [main.ts]
import { Foo } from './10_lib';
Foo();
//// [10_lib.js]
function Foo() { }
exports.Foo = Foo;
//// [main.js]
var _10_lib_1 = require('./10_lib');
_10_lib_1.Foo();
//// [10_lib.d.ts]
export declare function Foo(): void;
//// [main.d.ts]

View File

@ -0,0 +1,12 @@
=== tests/cases/compiler/10_lib.ts ===
export function Foo() {}
>Foo : Symbol(Foo, Decl(10_lib.ts, 0, 0))
=== tests/cases/compiler/main.ts ===
import { Foo } from './10_lib';
>Foo : Symbol(Foo, Decl(main.ts, 0, 8))
Foo();
>Foo : Symbol(Foo, Decl(main.ts, 0, 8))

View File

@ -0,0 +1,13 @@
=== tests/cases/compiler/10_lib.ts ===
export function Foo() {}
>Foo : () => void
=== tests/cases/compiler/main.ts ===
import { Foo } from './10_lib';
>Foo : () => void
Foo();
>Foo() : void
>Foo : () => void

View File

@ -0,0 +1,11 @@
// @target: ES5
// @module: commonjs
// @declaration: true
// @filename: 10_lib.ts
export function Foo() {}
// @filename: main.ts
import { Foo } from './10_lib';
Foo();