-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Retain imports in declaration emit if they augment an export of the importing file #37820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
weswigham
merged 3 commits into
microsoft:master
from
weswigham:retain-imports-if-they-add-augmentations
Apr 13, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...s/baselines/reference/declarationEmitForModuleImportingModuleAugmentationRetainsImport.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| //// [tests/cases/compiler/declarationEmitForModuleImportingModuleAugmentationRetainsImport.ts] //// | ||
|
|
||
| //// [child1.ts] | ||
| import { ParentThing } from './parent'; | ||
|
|
||
| declare module './parent' { | ||
| interface ParentThing { | ||
| add: (a: number, b: number) => number; | ||
| } | ||
| } | ||
|
|
||
| export function child1(prototype: ParentThing) { | ||
| prototype.add = (a: number, b: number) => a + b; | ||
| } | ||
|
|
||
| //// [parent.ts] | ||
| import { child1 } from './child1'; // this import should still exist in some form in the output, since it augments this module | ||
|
|
||
| export class ParentThing implements ParentThing {} | ||
|
|
||
| child1(ParentThing.prototype); | ||
|
|
||
| //// [parent.js] | ||
| "use strict"; | ||
| exports.__esModule = true; | ||
| exports.ParentThing = void 0; | ||
| var child1_1 = require("./child1"); // this import should still exist in some form in the output, since it augments this module | ||
| var ParentThing = /** @class */ (function () { | ||
| function ParentThing() { | ||
| } | ||
| return ParentThing; | ||
| }()); | ||
| exports.ParentThing = ParentThing; | ||
| child1_1.child1(ParentThing.prototype); | ||
| //// [child1.js] | ||
| "use strict"; | ||
| exports.__esModule = true; | ||
| exports.child1 = void 0; | ||
| function child1(prototype) { | ||
| prototype.add = function (a, b) { return a + b; }; | ||
| } | ||
| exports.child1 = child1; | ||
|
|
||
|
|
||
| //// [parent.d.ts] | ||
| import './child1'; | ||
| export declare class ParentThing implements ParentThing { | ||
| } | ||
| //// [child1.d.ts] | ||
| import { ParentThing } from './parent'; | ||
| declare module './parent' { | ||
| interface ParentThing { | ||
| add: (a: number, b: number) => number; | ||
| } | ||
| } | ||
| export declare function child1(prototype: ParentThing): void; |
46 changes: 46 additions & 0 deletions
46
...elines/reference/declarationEmitForModuleImportingModuleAugmentationRetainsImport.symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| === tests/cases/compiler/child1.ts === | ||
| import { ParentThing } from './parent'; | ||
| >ParentThing : Symbol(ParentThing, Decl(child1.ts, 0, 8)) | ||
|
|
||
| declare module './parent' { | ||
| >'./parent' : Symbol("tests/cases/compiler/parent", Decl(parent.ts, 0, 0), Decl(child1.ts, 0, 39)) | ||
|
|
||
| interface ParentThing { | ||
| >ParentThing : Symbol(ParentThing, Decl(parent.ts, 0, 34), Decl(child1.ts, 2, 27)) | ||
|
|
||
| add: (a: number, b: number) => number; | ||
| >add : Symbol(ParentThing.add, Decl(child1.ts, 3, 27)) | ||
| >a : Symbol(a, Decl(child1.ts, 4, 14)) | ||
| >b : Symbol(b, Decl(child1.ts, 4, 24)) | ||
| } | ||
| } | ||
|
|
||
| export function child1(prototype: ParentThing) { | ||
| >child1 : Symbol(child1, Decl(child1.ts, 6, 1)) | ||
| >prototype : Symbol(prototype, Decl(child1.ts, 8, 23)) | ||
| >ParentThing : Symbol(ParentThing, Decl(child1.ts, 0, 8)) | ||
|
|
||
| prototype.add = (a: number, b: number) => a + b; | ||
| >prototype.add : Symbol(ParentThing.add, Decl(child1.ts, 3, 27)) | ||
| >prototype : Symbol(prototype, Decl(child1.ts, 8, 23)) | ||
| >add : Symbol(ParentThing.add, Decl(child1.ts, 3, 27)) | ||
| >a : Symbol(a, Decl(child1.ts, 9, 21)) | ||
| >b : Symbol(b, Decl(child1.ts, 9, 31)) | ||
| >a : Symbol(a, Decl(child1.ts, 9, 21)) | ||
| >b : Symbol(b, Decl(child1.ts, 9, 31)) | ||
| } | ||
|
|
||
| === tests/cases/compiler/parent.ts === | ||
| import { child1 } from './child1'; // this import should still exist in some form in the output, since it augments this module | ||
| >child1 : Symbol(child1, Decl(parent.ts, 0, 8)) | ||
|
|
||
| export class ParentThing implements ParentThing {} | ||
| >ParentThing : Symbol(ParentThing, Decl(parent.ts, 0, 34), Decl(child1.ts, 2, 27)) | ||
| >ParentThing : Symbol(ParentThing, Decl(parent.ts, 0, 34), Decl(child1.ts, 2, 27)) | ||
|
|
||
| child1(ParentThing.prototype); | ||
| >child1 : Symbol(child1, Decl(parent.ts, 0, 8)) | ||
| >ParentThing.prototype : Symbol(ParentThing.prototype) | ||
| >ParentThing : Symbol(ParentThing, Decl(parent.ts, 0, 34), Decl(child1.ts, 2, 27)) | ||
| >prototype : Symbol(ParentThing.prototype) | ||
|
|
46 changes: 46 additions & 0 deletions
46
...aselines/reference/declarationEmitForModuleImportingModuleAugmentationRetainsImport.types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| === tests/cases/compiler/child1.ts === | ||
| import { ParentThing } from './parent'; | ||
| >ParentThing : typeof ParentThing | ||
|
|
||
| declare module './parent' { | ||
| >'./parent' : typeof import("tests/cases/compiler/parent") | ||
|
|
||
| interface ParentThing { | ||
| add: (a: number, b: number) => number; | ||
| >add : (a: number, b: number) => number | ||
| >a : number | ||
| >b : number | ||
| } | ||
| } | ||
|
|
||
| export function child1(prototype: ParentThing) { | ||
| >child1 : (prototype: ParentThing) => void | ||
| >prototype : ParentThing | ||
|
|
||
| prototype.add = (a: number, b: number) => a + b; | ||
| >prototype.add = (a: number, b: number) => a + b : (a: number, b: number) => number | ||
| >prototype.add : (a: number, b: number) => number | ||
| >prototype : ParentThing | ||
| >add : (a: number, b: number) => number | ||
| >(a: number, b: number) => a + b : (a: number, b: number) => number | ||
| >a : number | ||
| >b : number | ||
| >a + b : number | ||
| >a : number | ||
| >b : number | ||
| } | ||
|
|
||
| === tests/cases/compiler/parent.ts === | ||
| import { child1 } from './child1'; // this import should still exist in some form in the output, since it augments this module | ||
| >child1 : (prototype: ParentThing) => void | ||
|
|
||
| export class ParentThing implements ParentThing {} | ||
| >ParentThing : ParentThing | ||
|
|
||
| child1(ParentThing.prototype); | ||
| >child1(ParentThing.prototype) : void | ||
| >child1 : (prototype: ParentThing) => void | ||
| >ParentThing.prototype : ParentThing | ||
| >ParentThing : typeof ParentThing | ||
| >prototype : ParentThing | ||
|
|
20 changes: 20 additions & 0 deletions
20
tests/cases/compiler/declarationEmitForModuleImportingModuleAugmentationRetainsImport.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // @declaration: true | ||
| // @filename: child1.ts | ||
| import { ParentThing } from './parent'; | ||
|
|
||
| declare module './parent' { | ||
| interface ParentThing { | ||
| add: (a: number, b: number) => number; | ||
| } | ||
| } | ||
|
|
||
| export function child1(prototype: ParentThing) { | ||
| prototype.add = (a: number, b: number) => a + b; | ||
| } | ||
|
|
||
| // @filename: parent.ts | ||
| import { child1 } from './child1'; // this import should still exist in some form in the output, since it augments this module | ||
|
|
||
| export class ParentThing implements ParentThing {} | ||
|
|
||
| child1(ParentThing.prototype); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.