mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
import statement from "node" in js source file could produce correct declaration path. (#41816)
* fix #41800 * add test * fix test
This commit is contained in:
parent
bf977ed918
commit
37e898cfd7
@ -1422,7 +1422,8 @@ namespace ts {
|
||||
export function getPackageNameFromTypesPackageName(mangledName: string): string {
|
||||
const withoutAtTypePrefix = removePrefix(mangledName, "@types/");
|
||||
if (withoutAtTypePrefix !== mangledName) {
|
||||
return unmangleScopedPackageName(withoutAtTypePrefix);
|
||||
const withoutAtTypeNodePrefix = removePrefix(withoutAtTypePrefix, "node/");
|
||||
return unmangleScopedPackageName(withoutAtTypeNodePrefix);
|
||||
}
|
||||
return mangledName;
|
||||
}
|
||||
|
||||
@ -0,0 +1,40 @@
|
||||
//// [tests/cases/compiler/importDeclFromTypeNodeInJsSource.ts] ////
|
||||
|
||||
//// [index.d.ts]
|
||||
/// <reference path="events.d.ts" />
|
||||
//// [events.d.ts]
|
||||
declare module "events" {
|
||||
namespace EventEmitter {
|
||||
class EventEmitter {
|
||||
constructor();
|
||||
}
|
||||
}
|
||||
export = EventEmitter;
|
||||
}
|
||||
|
||||
//// [b.js]
|
||||
import { EventEmitter } from 'events';
|
||||
class Foo extends EventEmitter {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
export default Foo;
|
||||
|
||||
//// [b.js]
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const events_1 = require("events");
|
||||
class Foo extends events_1.EventEmitter {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
exports.default = Foo;
|
||||
|
||||
|
||||
//// [b.d.ts]
|
||||
export default Foo;
|
||||
declare class Foo extends EventEmitter {
|
||||
}
|
||||
import { EventEmitter } from "events";
|
||||
@ -0,0 +1,35 @@
|
||||
=== /src/node_modules/@types/node/index.d.ts ===
|
||||
/// <reference path="events.d.ts" />
|
||||
No type information for this code.=== /src/node_modules/@types/node/events.d.ts ===
|
||||
declare module "events" {
|
||||
>"events" : Symbol("events", Decl(events.d.ts, 0, 0))
|
||||
|
||||
namespace EventEmitter {
|
||||
>EventEmitter : Symbol(EventEmitter, Decl(events.d.ts, 0, 25))
|
||||
|
||||
class EventEmitter {
|
||||
>EventEmitter : Symbol(EventEmitter, Decl(events.d.ts, 1, 28))
|
||||
|
||||
constructor();
|
||||
}
|
||||
}
|
||||
export = EventEmitter;
|
||||
>EventEmitter : Symbol(EventEmitter, Decl(events.d.ts, 0, 25))
|
||||
}
|
||||
|
||||
=== /src/b.js ===
|
||||
import { EventEmitter } from 'events';
|
||||
>EventEmitter : Symbol(EventEmitter, Decl(b.js, 0, 8))
|
||||
|
||||
class Foo extends EventEmitter {
|
||||
>Foo : Symbol(Foo, Decl(b.js, 0, 38))
|
||||
>EventEmitter : Symbol(EventEmitter, Decl(b.js, 0, 8))
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
>super : Symbol(EventEmitter, Decl(events.d.ts, 1, 28))
|
||||
}
|
||||
}
|
||||
export default Foo;
|
||||
>Foo : Symbol(Foo, Decl(b.js, 0, 38))
|
||||
|
||||
@ -0,0 +1,36 @@
|
||||
=== /src/node_modules/@types/node/index.d.ts ===
|
||||
/// <reference path="events.d.ts" />
|
||||
No type information for this code.=== /src/node_modules/@types/node/events.d.ts ===
|
||||
declare module "events" {
|
||||
>"events" : typeof import("events")
|
||||
|
||||
namespace EventEmitter {
|
||||
>EventEmitter : typeof EventEmitter
|
||||
|
||||
class EventEmitter {
|
||||
>EventEmitter : EventEmitter
|
||||
|
||||
constructor();
|
||||
}
|
||||
}
|
||||
export = EventEmitter;
|
||||
>EventEmitter : typeof EventEmitter
|
||||
}
|
||||
|
||||
=== /src/b.js ===
|
||||
import { EventEmitter } from 'events';
|
||||
>EventEmitter : typeof EventEmitter
|
||||
|
||||
class Foo extends EventEmitter {
|
||||
>Foo : Foo
|
||||
>EventEmitter : EventEmitter
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
>super() : void
|
||||
>super : typeof EventEmitter
|
||||
}
|
||||
}
|
||||
export default Foo;
|
||||
>Foo : Foo
|
||||
|
||||
26
tests/cases/compiler/importDeclFromTypeNodeInJsSource.ts
Normal file
26
tests/cases/compiler/importDeclFromTypeNodeInJsSource.ts
Normal file
@ -0,0 +1,26 @@
|
||||
// @target: esnext
|
||||
// @module: commonjs
|
||||
// @allowJs: true
|
||||
// @checkJs: true
|
||||
// @declaration: true
|
||||
// @outDir: ./dist
|
||||
// @filename: /src/node_modules/@types/node/index.d.ts
|
||||
/// <reference path="events.d.ts" />
|
||||
// @filename: /src/node_modules/@types/node/events.d.ts
|
||||
declare module "events" {
|
||||
namespace EventEmitter {
|
||||
class EventEmitter {
|
||||
constructor();
|
||||
}
|
||||
}
|
||||
export = EventEmitter;
|
||||
}
|
||||
|
||||
// @filename: /src/b.js
|
||||
import { EventEmitter } from 'events';
|
||||
class Foo extends EventEmitter {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
export default Foo;
|
||||
Loading…
x
Reference in New Issue
Block a user