Skip to content

Commit da86332

Browse files
authored
Limit export= js declaration emit to only json source files (#40882)
1 parent 3ea81e6 commit da86332

File tree

5 files changed

+172
-1
lines changed

5 files changed

+172
-1
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6800,7 +6800,9 @@ namespace ts {
68006800
}
68016801
// else fall through and treat commonjs require just like import=
68026802
case SyntaxKind.ImportEqualsDeclaration:
6803-
if (target.escapedName === InternalSymbolName.ExportEquals) {
6803+
// This _specifically_ only exists to handle json declarations - where we make aliases, but since
6804+
// we emit no declarations for the json document, must not refer to it in the declarations
6805+
if (target.escapedName === InternalSymbolName.ExportEquals && some(target.declarations, isJsonSourceFile)) {
68046806
serializeMaybeAliasAssignment(symbol);
68056807
break;
68066808
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportedClassAliases.ts] ////
2+
3+
//// [errors.js]
4+
class FancyError extends Error {
5+
constructor(status) {
6+
super(`error with status ${status}`);
7+
}
8+
}
9+
10+
module.exports = {
11+
FancyError
12+
};
13+
14+
//// [index.js]
15+
// issue arises here on compilation
16+
const errors = require("./errors");
17+
18+
module.exports = {
19+
errors
20+
};
21+
22+
//// [errors.js]
23+
var __extends = (this && this.__extends) || (function () {
24+
var extendStatics = function (d, b) {
25+
extendStatics = Object.setPrototypeOf ||
26+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
27+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
28+
return extendStatics(d, b);
29+
};
30+
return function (d, b) {
31+
extendStatics(d, b);
32+
function __() { this.constructor = d; }
33+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
34+
};
35+
})();
36+
var FancyError = /** @class */ (function (_super) {
37+
__extends(FancyError, _super);
38+
function FancyError(status) {
39+
return _super.call(this, "error with status " + status) || this;
40+
}
41+
return FancyError;
42+
}(Error));
43+
module.exports = {
44+
FancyError: FancyError
45+
};
46+
//// [index.js]
47+
// issue arises here on compilation
48+
var errors = require("./errors");
49+
module.exports = {
50+
errors: errors
51+
};
52+
53+
54+
//// [errors.d.ts]
55+
export class FancyError extends Error {
56+
constructor(status: any);
57+
}
58+
//// [index.d.ts]
59+
import errors = require("./errors");
60+
export { errors };
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
=== tests/cases/conformance/jsdoc/declarations/utils/index.js ===
2+
// issue arises here on compilation
3+
const errors = require("./errors");
4+
>errors : Symbol(errors, Decl(index.js, 1, 5))
5+
>require : Symbol(require)
6+
>"./errors" : Symbol("tests/cases/conformance/jsdoc/declarations/utils/errors", Decl(errors.js, 0, 0))
7+
8+
module.exports = {
9+
>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/utils/index", Decl(index.js, 0, 0))
10+
>module : Symbol(export=, Decl(index.js, 1, 35))
11+
>exports : Symbol(export=, Decl(index.js, 1, 35))
12+
13+
errors
14+
>errors : Symbol(errors, Decl(index.js, 3, 18))
15+
16+
};
17+
=== tests/cases/conformance/jsdoc/declarations/utils/errors.js ===
18+
class FancyError extends Error {
19+
>FancyError : Symbol(FancyError, Decl(errors.js, 0, 0))
20+
>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
21+
22+
constructor(status) {
23+
>status : Symbol(status, Decl(errors.js, 1, 16))
24+
25+
super(`error with status ${status}`);
26+
>super : Symbol(ErrorConstructor, Decl(lib.es5.d.ts, --, --))
27+
>status : Symbol(status, Decl(errors.js, 1, 16))
28+
}
29+
}
30+
31+
module.exports = {
32+
>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/utils/errors", Decl(errors.js, 0, 0))
33+
>module : Symbol(export=, Decl(errors.js, 4, 1))
34+
>exports : Symbol(export=, Decl(errors.js, 4, 1))
35+
36+
FancyError
37+
>FancyError : Symbol(FancyError, Decl(errors.js, 6, 18))
38+
39+
};
40+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
=== tests/cases/conformance/jsdoc/declarations/utils/index.js ===
2+
// issue arises here on compilation
3+
const errors = require("./errors");
4+
>errors : { FancyError: typeof FancyError; }
5+
>require("./errors") : { FancyError: typeof FancyError; }
6+
>require : any
7+
>"./errors" : "./errors"
8+
9+
module.exports = {
10+
>module.exports = { errors} : { errors: { FancyError: typeof FancyError; }; }
11+
>module.exports : { errors: { FancyError: typeof FancyError; }; }
12+
>module : { "\"tests/cases/conformance/jsdoc/declarations/utils/index\"": { errors: { FancyError: typeof FancyError; }; }; }
13+
>exports : { errors: { FancyError: typeof FancyError; }; }
14+
>{ errors} : { errors: { FancyError: typeof FancyError; }; }
15+
16+
errors
17+
>errors : { FancyError: typeof FancyError; }
18+
19+
};
20+
=== tests/cases/conformance/jsdoc/declarations/utils/errors.js ===
21+
class FancyError extends Error {
22+
>FancyError : FancyError
23+
>Error : Error
24+
25+
constructor(status) {
26+
>status : any
27+
28+
super(`error with status ${status}`);
29+
>super(`error with status ${status}`) : void
30+
>super : ErrorConstructor
31+
>`error with status ${status}` : string
32+
>status : any
33+
}
34+
}
35+
36+
module.exports = {
37+
>module.exports = { FancyError} : { FancyError: typeof FancyError; }
38+
>module.exports : { FancyError: typeof FancyError; }
39+
>module : { "\"tests/cases/conformance/jsdoc/declarations/utils/errors\"": { FancyError: typeof FancyError; }; }
40+
>exports : { FancyError: typeof FancyError; }
41+
>{ FancyError} : { FancyError: typeof FancyError; }
42+
43+
FancyError
44+
>FancyError : typeof FancyError
45+
46+
};
47+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// @allowJs: true
2+
// @checkJs: true
3+
// @outDir: ./out
4+
// @declaration: true
5+
// @filename: utils/errors.js
6+
class FancyError extends Error {
7+
constructor(status) {
8+
super(`error with status ${status}`);
9+
}
10+
}
11+
12+
module.exports = {
13+
FancyError
14+
};
15+
16+
// @filename: utils/index.js
17+
// issue arises here on compilation
18+
const errors = require("./errors");
19+
20+
module.exports = {
21+
errors
22+
};

0 commit comments

Comments
 (0)