TypeScript/tests/cases/conformance/jsdoc/declarations/jsDeclarationsClasses.ts
Wesley Wigham 61cb06ce40
Allow allowJs and declaration to be used together (#32372)
* Allow allowJs and declaration to be used together

This intorduces a new symbol-based declaration emitter - currently this
is only used for JSON and JavaScript, as the output is likely worse than
what the other declaration emitter is capable of. In addition, it is
still incomplete - it does not yet support serializaing namespaces.

* Add tests for various import/export forms, add notes on export as namespace and fix export * from

* Tests & fixes for computed names

* Add test with current @enum tag behavior

* fix declaration emit for jsdoc @enum tags

* Small adjustments to base class serialization to fix bugs in it

* Guard against type/type parameter confusion when using typeParameterToName a bit

* Integrate feedback from PR

* Fix issue with export= declarations visibility calculation and type declaration emit that impacted all forms of declaration emit

* Only make one merged getCommonJsExportEquals symbol for a symbol

* Support preserving type reference directives in js declarations

* Skip declare mdoifiers for namespace members in ambient contexts

* FAKE ALIASES AND NAMESPACES EVERYWHERE

* Dont do namespace sugar when type members contain keyword names

* Fix json source file export modifier under new output

* Such clean nested aliasing, very wow

* Fix lint

* Add visibility errors, reuse type nodes where possible

* Suppoer having correctly named import types in bundled js declaration emit & adjust binding to allow namespaces with aliases to merge when the aliases look to be type-only

* Better support for module.exports = class expression

* Fix discovered crash bug

* Allow export assigned class expressions to be reachable symbols from external declarations

* Add missing semicolon

* Support @enum tag post-merge

* preserve comments on signatures and declarations where possible

* Basic support for js classy functions

* Add example we should do better with

* Prototype assignments make things a bit wonky, but the example from the PR seems OK

* Make a ton of changes to support the new way js classes are bound

* Remove some old comments, fix import and export default names

* Fix bug in object define handling and add tests for object define property declaration emit

* Fix organization nits from PR comments

* Preserve comments from jsdoc declarations on properties and js declaration type aliases

* Merge export declarations with identical specifiers

* Remove completed TODO comment

* Split lint

* Remove now-unused function

* PR feedback

* Add some project references tests, remove some checks from project refs codepaths that are now invalid

* Update project references tests again

* Merge and update project references tests

* Rename case

* Update test to include declaration output

* Remove yet another project refernces redirect extension check

* Update comment

* Add additional import ref to test

* Add shorthand prop to test

* Fix comment text

* Extract var to temp

* Simplify function and add whitespace

* Update project refs test to use incremental edit entry

* Stylistic refactors in the symbol serializer

* Another round of PR feedback, mostly style, small bugfix with constructors, and test showing bug in export assigned class expression name shadowing

* Use x instead of index
2019-09-26 14:27:16 -07:00

200 lines
3 KiB
TypeScript

// @allowJs: true
// @checkJs: true
// @target: es5
// @outDir: ./out
// @declaration: true
// @filename: index.js
export class A {}
export class B {
static cat = "cat";
}
export class C {
static Cls = class {}
}
export class D {
/**
* @param {number} a
* @param {number} b
*/
constructor(a, b) {}
}
/**
* @template T,U
*/
export class E {
/**
* @type {T & U}
*/
field;
// @readonly is currently unsupported, it seems - included here just in case that changes
/**
* @type {T & U}
* @readonly
*/
readonlyField;
initializedField = 12;
/**
* @return {U}
*/
get f1() { return /** @type {*} */(null); }
/**
* @param {U} _p
*/
set f1(_p) {}
/**
* @return {U}
*/
get f2() { return /** @type {*} */(null); }
/**
* @param {U} _p
*/
set f3(_p) {}
/**
* @param {T} a
* @param {U} b
*/
constructor(a, b) {}
/**
* @type {string}
*/
static staticField;
// @readonly is currently unsupported, it seems - included here just in case that changes
/**
* @type {string}
* @readonly
*/
static staticReadonlyField;
static staticInitializedField = 12;
/**
* @return {string}
*/
static get s1() { return ""; }
/**
* @param {string} _p
*/
static set s1(_p) {}
/**
* @return {string}
*/
static get s2() { return ""; }
/**
* @param {string} _p
*/
static set s3(_p) {}
}
/**
* @template T,U
*/
export class F {
/**
* @type {T & U}
*/
field;
/**
* @param {T} a
* @param {U} b
*/
constructor(a, b) {}
/**
* @template A,B
* @param {A} a
* @param {B} b
*/
static create(a, b) { return new F(a, b); }
}
class G {}
export { G };
class HH {}
export { HH as H };
export class I {}
export { I as II };
export { J as JJ };
export class J {}
export class K {
constructor() {
this.p1 = 12;
this.p2 = "ok";
}
method() {
return this.p1;
}
}
export class L extends K {}
export class M extends null {
constructor() {
this.prop = 12;
}
}
/**
* @template T
*/
export class N extends L {
/**
* @param {T} param
*/
constructor(param) {
super();
this.another = param;
}
}
/**
* @template U
* @extends {N<U>}
*/
export class O extends N {
/**
* @param {U} param
*/
constructor(param) {
super(param);
this.another2 = param;
}
}
var x = /** @type {*} */(null);
export class VariableBase extends x {}
export class HasStatics {
static staticMethod() {}
}
export class ExtendsStatics extends HasStatics {
static also() {}
}