-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Add fallback error locations for nameless declarations, better class error locations #42585
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 1 commit into
microsoft:master
from
weswigham:declaration-emit-private-protected
Feb 5, 2021
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
53 changes: 53 additions & 0 deletions
53
tests/baselines/reference/declarationEmitMixinPrivateProtected.errors.txt
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,53 @@ | ||
tests/cases/compiler/another.ts(11,1): error TS4094: Property '_assertIsStripped' of exported class expression may not be private or protected. | ||
tests/cases/compiler/another.ts(11,1): error TS4094: Property '_onDispose' of exported class expression may not be private or protected. | ||
tests/cases/compiler/first.ts(12,1): error TS4094: Property '_assertIsStripped' of exported class expression may not be private or protected. | ||
tests/cases/compiler/first.ts(12,1): error TS4094: Property '_onDispose' of exported class expression may not be private or protected. | ||
tests/cases/compiler/first.ts(13,14): error TS4094: Property '_assertIsStripped' of exported class expression may not be private or protected. | ||
tests/cases/compiler/first.ts(13,14): error TS4094: Property '_onDispose' of exported class expression may not be private or protected. | ||
|
||
|
||
==== tests/cases/compiler/first.ts (4 errors) ==== | ||
declare function mix<TMix>(mixin: TMix): TMix; | ||
|
||
const DisposableMixin = class { | ||
protected _onDispose() { | ||
this._assertIsStripped() | ||
} | ||
private _assertIsStripped() { | ||
} | ||
}; | ||
|
||
// No error, but definition is wrong. | ||
export default mix(DisposableMixin); | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS4094: Property '_assertIsStripped' of exported class expression may not be private or protected. | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS4094: Property '_onDispose' of exported class expression may not be private or protected. | ||
export class Monitor extends mix(DisposableMixin) { | ||
~~~~~~~ | ||
!!! error TS4094: Property '_assertIsStripped' of exported class expression may not be private or protected. | ||
~~~~~~~ | ||
!!! error TS4094: Property '_onDispose' of exported class expression may not be private or protected. | ||
protected _onDispose() { | ||
} | ||
} | ||
|
||
==== tests/cases/compiler/another.ts (2 errors) ==== | ||
declare function mix<TMix>(mixin: TMix): TMix; | ||
|
||
const DisposableMixin = class { | ||
protected _onDispose() { | ||
this._assertIsStripped() | ||
} | ||
private _assertIsStripped() { | ||
} | ||
}; | ||
|
||
export default class extends mix(DisposableMixin) { | ||
~~~~~~ | ||
!!! error TS4094: Property '_assertIsStripped' of exported class expression may not be private or protected. | ||
~~~~~~ | ||
!!! error TS4094: Property '_onDispose' of exported class expression may not be private or protected. | ||
protected _onDispose() { | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
tests/baselines/reference/declarationEmitMixinPrivateProtected.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,115 @@ | ||
//// [tests/cases/compiler/declarationEmitMixinPrivateProtected.ts] //// | ||
|
||
//// [first.ts] | ||
declare function mix<TMix>(mixin: TMix): TMix; | ||
|
||
const DisposableMixin = class { | ||
protected _onDispose() { | ||
this._assertIsStripped() | ||
} | ||
private _assertIsStripped() { | ||
} | ||
}; | ||
|
||
// No error, but definition is wrong. | ||
export default mix(DisposableMixin); | ||
export class Monitor extends mix(DisposableMixin) { | ||
protected _onDispose() { | ||
} | ||
} | ||
|
||
//// [another.ts] | ||
declare function mix<TMix>(mixin: TMix): TMix; | ||
|
||
const DisposableMixin = class { | ||
protected _onDispose() { | ||
this._assertIsStripped() | ||
} | ||
private _assertIsStripped() { | ||
} | ||
}; | ||
|
||
export default class extends mix(DisposableMixin) { | ||
protected _onDispose() { | ||
} | ||
} | ||
|
||
//// [first.js] | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
exports.__esModule = true; | ||
exports.Monitor = void 0; | ||
var DisposableMixin = /** @class */ (function () { | ||
function class_1() { | ||
} | ||
class_1.prototype._onDispose = function () { | ||
this._assertIsStripped(); | ||
}; | ||
class_1.prototype._assertIsStripped = function () { | ||
}; | ||
return class_1; | ||
}()); | ||
// No error, but definition is wrong. | ||
exports["default"] = mix(DisposableMixin); | ||
var Monitor = /** @class */ (function (_super) { | ||
__extends(Monitor, _super); | ||
function Monitor() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
Monitor.prototype._onDispose = function () { | ||
}; | ||
return Monitor; | ||
}(mix(DisposableMixin))); | ||
exports.Monitor = Monitor; | ||
//// [another.js] | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
exports.__esModule = true; | ||
var DisposableMixin = /** @class */ (function () { | ||
function class_1() { | ||
} | ||
class_1.prototype._onDispose = function () { | ||
this._assertIsStripped(); | ||
}; | ||
class_1.prototype._assertIsStripped = function () { | ||
}; | ||
return class_1; | ||
}()); | ||
var default_1 = /** @class */ (function (_super) { | ||
__extends(default_1, _super); | ||
function default_1() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
default_1.prototype._onDispose = function () { | ||
}; | ||
return default_1; | ||
}(mix(DisposableMixin))); | ||
exports["default"] = default_1; |
71 changes: 71 additions & 0 deletions
71
tests/baselines/reference/declarationEmitMixinPrivateProtected.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,71 @@ | ||
=== tests/cases/compiler/first.ts === | ||
declare function mix<TMix>(mixin: TMix): TMix; | ||
>mix : Symbol(mix, Decl(first.ts, 0, 0)) | ||
>TMix : Symbol(TMix, Decl(first.ts, 0, 21)) | ||
>mixin : Symbol(mixin, Decl(first.ts, 0, 27)) | ||
>TMix : Symbol(TMix, Decl(first.ts, 0, 21)) | ||
>TMix : Symbol(TMix, Decl(first.ts, 0, 21)) | ||
|
||
const DisposableMixin = class { | ||
>DisposableMixin : Symbol(DisposableMixin, Decl(first.ts, 2, 5)) | ||
|
||
protected _onDispose() { | ||
>_onDispose : Symbol(DisposableMixin._onDispose, Decl(first.ts, 2, 31)) | ||
|
||
this._assertIsStripped() | ||
>this._assertIsStripped : Symbol(DisposableMixin._assertIsStripped, Decl(first.ts, 5, 5)) | ||
>this : Symbol(DisposableMixin, Decl(first.ts, 2, 23)) | ||
>_assertIsStripped : Symbol(DisposableMixin._assertIsStripped, Decl(first.ts, 5, 5)) | ||
} | ||
private _assertIsStripped() { | ||
>_assertIsStripped : Symbol(DisposableMixin._assertIsStripped, Decl(first.ts, 5, 5)) | ||
} | ||
}; | ||
|
||
// No error, but definition is wrong. | ||
export default mix(DisposableMixin); | ||
>mix : Symbol(mix, Decl(first.ts, 0, 0)) | ||
>DisposableMixin : Symbol(DisposableMixin, Decl(first.ts, 2, 5)) | ||
|
||
export class Monitor extends mix(DisposableMixin) { | ||
>Monitor : Symbol(Monitor, Decl(first.ts, 11, 36)) | ||
>mix : Symbol(mix, Decl(first.ts, 0, 0)) | ||
>DisposableMixin : Symbol(DisposableMixin, Decl(first.ts, 2, 5)) | ||
|
||
protected _onDispose() { | ||
>_onDispose : Symbol(Monitor._onDispose, Decl(first.ts, 12, 51)) | ||
} | ||
} | ||
|
||
=== tests/cases/compiler/another.ts === | ||
declare function mix<TMix>(mixin: TMix): TMix; | ||
>mix : Symbol(mix, Decl(another.ts, 0, 0)) | ||
>TMix : Symbol(TMix, Decl(another.ts, 0, 21)) | ||
>mixin : Symbol(mixin, Decl(another.ts, 0, 27)) | ||
>TMix : Symbol(TMix, Decl(another.ts, 0, 21)) | ||
>TMix : Symbol(TMix, Decl(another.ts, 0, 21)) | ||
|
||
const DisposableMixin = class { | ||
>DisposableMixin : Symbol(DisposableMixin, Decl(another.ts, 2, 5)) | ||
|
||
protected _onDispose() { | ||
>_onDispose : Symbol(DisposableMixin._onDispose, Decl(another.ts, 2, 31)) | ||
|
||
this._assertIsStripped() | ||
>this._assertIsStripped : Symbol(DisposableMixin._assertIsStripped, Decl(another.ts, 5, 5)) | ||
>this : Symbol(DisposableMixin, Decl(another.ts, 2, 23)) | ||
>_assertIsStripped : Symbol(DisposableMixin._assertIsStripped, Decl(another.ts, 5, 5)) | ||
} | ||
private _assertIsStripped() { | ||
>_assertIsStripped : Symbol(DisposableMixin._assertIsStripped, Decl(another.ts, 5, 5)) | ||
} | ||
}; | ||
|
||
export default class extends mix(DisposableMixin) { | ||
>mix : Symbol(mix, Decl(another.ts, 0, 0)) | ||
>DisposableMixin : Symbol(DisposableMixin, Decl(another.ts, 2, 5)) | ||
|
||
protected _onDispose() { | ||
>_onDispose : Symbol(default._onDispose, Decl(another.ts, 10, 51)) | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
tests/baselines/reference/declarationEmitMixinPrivateProtected.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,72 @@ | ||
=== tests/cases/compiler/first.ts === | ||
declare function mix<TMix>(mixin: TMix): TMix; | ||
>mix : <TMix>(mixin: TMix) => TMix | ||
>mixin : TMix | ||
|
||
const DisposableMixin = class { | ||
>DisposableMixin : typeof DisposableMixin | ||
>class { protected _onDispose() { this._assertIsStripped() } private _assertIsStripped() { }} : typeof DisposableMixin | ||
|
||
protected _onDispose() { | ||
>_onDispose : () => void | ||
|
||
this._assertIsStripped() | ||
>this._assertIsStripped() : void | ||
>this._assertIsStripped : () => void | ||
>this : this | ||
>_assertIsStripped : () => void | ||
} | ||
private _assertIsStripped() { | ||
>_assertIsStripped : () => void | ||
} | ||
}; | ||
|
||
// No error, but definition is wrong. | ||
export default mix(DisposableMixin); | ||
>mix(DisposableMixin) : typeof DisposableMixin | ||
>mix : <TMix>(mixin: TMix) => TMix | ||
>DisposableMixin : typeof DisposableMixin | ||
|
||
export class Monitor extends mix(DisposableMixin) { | ||
>Monitor : Monitor | ||
>mix(DisposableMixin) : DisposableMixin | ||
>mix : <TMix>(mixin: TMix) => TMix | ||
>DisposableMixin : typeof DisposableMixin | ||
|
||
protected _onDispose() { | ||
>_onDispose : () => void | ||
} | ||
} | ||
|
||
=== tests/cases/compiler/another.ts === | ||
declare function mix<TMix>(mixin: TMix): TMix; | ||
>mix : <TMix>(mixin: TMix) => TMix | ||
>mixin : TMix | ||
|
||
const DisposableMixin = class { | ||
>DisposableMixin : typeof DisposableMixin | ||
>class { protected _onDispose() { this._assertIsStripped() } private _assertIsStripped() { }} : typeof DisposableMixin | ||
|
||
protected _onDispose() { | ||
>_onDispose : () => void | ||
|
||
this._assertIsStripped() | ||
>this._assertIsStripped() : void | ||
>this._assertIsStripped : () => void | ||
>this : this | ||
>_assertIsStripped : () => void | ||
} | ||
private _assertIsStripped() { | ||
>_assertIsStripped : () => void | ||
} | ||
}; | ||
|
||
export default class extends mix(DisposableMixin) { | ||
>mix(DisposableMixin) : DisposableMixin | ||
>mix : <TMix>(mixin: TMix) => TMix | ||
>DisposableMixin : typeof DisposableMixin | ||
|
||
protected _onDispose() { | ||
>_onDispose : () => void | ||
} | ||
} |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd just capture these into a local so you can avoid the
!