Skip to content

Commit f35206d

Browse files
TypeScript Botjakebailey
TypeScript Bot
andauthored
🤖 Pick PR #59325 (Don't skip markLinkedReferences on ...) into release-5.5 (#59336)
Co-authored-by: Jake Bailey <[email protected]>
1 parent 1109550 commit f35206d

8 files changed

+208
-2
lines changed

‎src/compiler/checker.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -29672,8 +29672,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2967229672
if (!canCollectSymbolAliasAccessabilityData) {
2967329673
return;
2967429674
}
29675-
if (location.flags & NodeFlags.Ambient) {
29676-
return; // References within types and declaration files are never going to contribute to retaining a JS import
29675+
if (location.flags & NodeFlags.Ambient && !isPropertySignature(location) && !isPropertyDeclaration(location)) {
29676+
// References within types and declaration files are never going to contribute to retaining a JS import,
29677+
// except for properties (which can be decorated).
29678+
return;
2967729679
}
2967829680
switch (hint) {
2967929681
case ReferenceHint.Identifier:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//// [tests/cases/compiler/decoratorMetadataElidedImportOnDeclare.ts] ////
2+
3+
//// [observable.d.ts]
4+
export declare class Observable<T> {}
5+
6+
//// [index.ts]
7+
import { Observable } from './observable';
8+
9+
function whatever(a: any, b: any) {}
10+
11+
class Test {
12+
@whatever
13+
declare prop: Observable<string>;
14+
}
15+
16+
17+
//// [index.js]
18+
"use strict";
19+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
20+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
21+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
22+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
23+
return c > 3 && r && Object.defineProperty(target, key, r), r;
24+
};
25+
var __metadata = (this && this.__metadata) || function (k, v) {
26+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
27+
};
28+
Object.defineProperty(exports, "__esModule", { value: true });
29+
const observable_1 = require("./observable");
30+
function whatever(a, b) { }
31+
class Test {
32+
}
33+
__decorate([
34+
whatever,
35+
__metadata("design:type", observable_1.Observable)
36+
], Test.prototype, "prop", void 0);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//// [tests/cases/compiler/decoratorMetadataElidedImportOnDeclare.ts] ////
2+
3+
=== observable.d.ts ===
4+
export declare class Observable<T> {}
5+
>Observable : Symbol(Observable, Decl(observable.d.ts, 0, 0))
6+
>T : Symbol(T, Decl(observable.d.ts, 0, 32))
7+
8+
=== index.ts ===
9+
import { Observable } from './observable';
10+
>Observable : Symbol(Observable, Decl(index.ts, 0, 8))
11+
12+
function whatever(a: any, b: any) {}
13+
>whatever : Symbol(whatever, Decl(index.ts, 0, 42))
14+
>a : Symbol(a, Decl(index.ts, 2, 18))
15+
>b : Symbol(b, Decl(index.ts, 2, 25))
16+
17+
class Test {
18+
>Test : Symbol(Test, Decl(index.ts, 2, 36))
19+
20+
@whatever
21+
>whatever : Symbol(whatever, Decl(index.ts, 0, 42))
22+
23+
declare prop: Observable<string>;
24+
>prop : Symbol(Test.prop, Decl(index.ts, 4, 12))
25+
>Observable : Symbol(Observable, Decl(index.ts, 0, 8))
26+
}
27+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//// [tests/cases/compiler/decoratorMetadataElidedImportOnDeclare.ts] ////
2+
3+
=== observable.d.ts ===
4+
export declare class Observable<T> {}
5+
>Observable : Observable<T>
6+
> : ^^^^^^^^^^^^^
7+
8+
=== index.ts ===
9+
import { Observable } from './observable';
10+
>Observable : typeof Observable
11+
> : ^^^^^^^^^^^^^^^^^
12+
13+
function whatever(a: any, b: any) {}
14+
>whatever : (a: any, b: any) => void
15+
> : ^ ^^ ^^ ^^ ^^^^^^^^^
16+
>a : any
17+
>b : any
18+
19+
class Test {
20+
>Test : Test
21+
> : ^^^^
22+
23+
@whatever
24+
>whatever : (a: any, b: any) => void
25+
> : ^ ^^ ^^ ^^ ^^^^^^^^^
26+
27+
declare prop: Observable<string>;
28+
>prop : Observable<string>
29+
> : ^^^^^^^^^^^^^^^^^^
30+
}
31+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//// [tests/cases/compiler/decoratorMetadataElidedImportOnDeclare.ts] ////
2+
3+
//// [observable.d.ts]
4+
export declare class Observable<T> {}
5+
6+
//// [index.ts]
7+
import { Observable } from './observable';
8+
9+
function whatever(a: any, b: any) {}
10+
11+
class Test {
12+
@whatever
13+
declare prop: Observable<string>;
14+
}
15+
16+
17+
//// [index.js]
18+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22+
return c > 3 && r && Object.defineProperty(target, key, r), r;
23+
};
24+
var __metadata = (this && this.__metadata) || function (k, v) {
25+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
26+
};
27+
import { Observable } from './observable';
28+
function whatever(a, b) { }
29+
class Test {
30+
}
31+
__decorate([
32+
whatever,
33+
__metadata("design:type", Observable)
34+
], Test.prototype, "prop", void 0);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//// [tests/cases/compiler/decoratorMetadataElidedImportOnDeclare.ts] ////
2+
3+
=== observable.d.ts ===
4+
export declare class Observable<T> {}
5+
>Observable : Symbol(Observable, Decl(observable.d.ts, 0, 0))
6+
>T : Symbol(T, Decl(observable.d.ts, 0, 32))
7+
8+
=== index.ts ===
9+
import { Observable } from './observable';
10+
>Observable : Symbol(Observable, Decl(index.ts, 0, 8))
11+
12+
function whatever(a: any, b: any) {}
13+
>whatever : Symbol(whatever, Decl(index.ts, 0, 42))
14+
>a : Symbol(a, Decl(index.ts, 2, 18))
15+
>b : Symbol(b, Decl(index.ts, 2, 25))
16+
17+
class Test {
18+
>Test : Symbol(Test, Decl(index.ts, 2, 36))
19+
20+
@whatever
21+
>whatever : Symbol(whatever, Decl(index.ts, 0, 42))
22+
23+
declare prop: Observable<string>;
24+
>prop : Symbol(Test.prop, Decl(index.ts, 4, 12))
25+
>Observable : Symbol(Observable, Decl(index.ts, 0, 8))
26+
}
27+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//// [tests/cases/compiler/decoratorMetadataElidedImportOnDeclare.ts] ////
2+
3+
=== observable.d.ts ===
4+
export declare class Observable<T> {}
5+
>Observable : Observable<T>
6+
> : ^^^^^^^^^^^^^
7+
8+
=== index.ts ===
9+
import { Observable } from './observable';
10+
>Observable : typeof Observable
11+
> : ^^^^^^^^^^^^^^^^^
12+
13+
function whatever(a: any, b: any) {}
14+
>whatever : (a: any, b: any) => void
15+
> : ^ ^^ ^^ ^^ ^^^^^^^^^
16+
>a : any
17+
>b : any
18+
19+
class Test {
20+
>Test : Test
21+
> : ^^^^
22+
23+
@whatever
24+
>whatever : (a: any, b: any) => void
25+
> : ^ ^^ ^^ ^^ ^^^^^^^^^
26+
27+
declare prop: Observable<string>;
28+
>prop : Observable<string>
29+
> : ^^^^^^^^^^^^^^^^^^
30+
}
31+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// @target: es2020
2+
// @module: commonjs, esnext
3+
// @strict: true
4+
// @experimentalDecorators: true
5+
// @emitDecoratorMetadata: true
6+
7+
// @filename: observable.d.ts
8+
export declare class Observable<T> {}
9+
10+
// @filename: index.ts
11+
import { Observable } from './observable';
12+
13+
function whatever(a: any, b: any) {}
14+
15+
class Test {
16+
@whatever
17+
declare prop: Observable<string>;
18+
}

0 commit comments

Comments
 (0)