mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-08 08:14:51 -06:00
Merge pull request #4355 from DavidSouther/ts4354
Emits safe value for import.
This commit is contained in:
commit
478cc32e5e
@ -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) {
|
||||
|
||||
23
tests/baselines/reference/commonjsSafeImport.js
Normal file
23
tests/baselines/reference/commonjsSafeImport.js
Normal 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]
|
||||
12
tests/baselines/reference/commonjsSafeImport.symbols
Normal file
12
tests/baselines/reference/commonjsSafeImport.symbols
Normal 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))
|
||||
|
||||
13
tests/baselines/reference/commonjsSafeImport.types
Normal file
13
tests/baselines/reference/commonjsSafeImport.types
Normal 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
|
||||
|
||||
11
tests/cases/compiler/commonjsSafeImport.ts
Normal file
11
tests/cases/compiler/commonjsSafeImport.ts
Normal 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();
|
||||
Loading…
x
Reference in New Issue
Block a user