7cda045d52
* Always export typedefs This actually just required deleting a check in declareModuleMembers and checking for external AND commonjs modules in a couple of places. However, while experimenting with this feature, I discovered that even previously-exported typedefs would only be exported if they came after a commonjs export node. So I added a commonjs check to the pass in the parser. It will not catch nested module.exports, but it will catch top-level assignments. The new test tests both changes. * Post-bind typedef instead of pre-checking for commonjs * Duplicate identifier errors * Fix class type reference resolution+update baselines * Move to a type-based check for duplicate identifiers
44 lines
973 B
TypeScript
44 lines
973 B
TypeScript
// @noEmit: true
|
|
// @allowJs: true
|
|
// @checkJs: true
|
|
// @Filename: commonjs.d.ts
|
|
declare var module: { exports: any};
|
|
// @Filename: mod1.js
|
|
/// <reference path="./commonjs.d.ts"/>
|
|
/** @typedef {{ type: "a", x: 1 }} A */
|
|
/** @typedef {{ type: "b", y: 1 }} B */
|
|
/** @typedef {A | B} Both */
|
|
module.exports = C
|
|
function C() {
|
|
this.p = 1
|
|
}
|
|
|
|
// @Filename: mod2.js
|
|
/// <reference path="./commonjs.d.ts"/>
|
|
/** @typedef {{ type: "a", x: 1 }} A */
|
|
/** @typedef {{ type: "b", y: 1 }} B */
|
|
/** @typedef {A | B} Both */
|
|
|
|
export function C() {
|
|
this.p = 1
|
|
}
|
|
|
|
// @Filename: mod3.js
|
|
/// <reference path="./commonjs.d.ts"/>
|
|
/** @typedef {{ type: "a", x: 1 }} A */
|
|
/** @typedef {{ type: "b", y: 1 }} B */
|
|
/** @typedef {A | B} Both */
|
|
|
|
exports.C = function() {
|
|
this.p = 1
|
|
}
|
|
|
|
// @Filename: use.js
|
|
/** @type {import('./mod1').Both} */
|
|
var both1 = { type: 'a', x: 1 };
|
|
/** @type {import('./mod2').Both} */
|
|
var both2 = both1;
|
|
/** @type {import('./mod3').Both} */
|
|
var both3 = both2;
|
|
|
|
|