From f0ec97c59e9f64b231d13b4b05d06ecb2b735b73 Mon Sep 17 00:00:00 2001 From: Tomasz Lenarcik Date: Sat, 3 Dec 2022 22:46:13 +0100 Subject: [PATCH] Add tests for alternative uses of @overload tag --- .../jsFileAlternativeUseOfOverloadTag.js | 121 ++++++++++++++++++ .../jsFileAlternativeUseOfOverloadTag.symbols | 72 +++++++++++ .../jsFileAlternativeUseOfOverloadTag.types | 78 +++++++++++ .../jsFileAlternativeUseOfOverloadTag.ts | 56 ++++++++ 4 files changed, 327 insertions(+) create mode 100644 tests/baselines/reference/jsFileAlternativeUseOfOverloadTag.js create mode 100644 tests/baselines/reference/jsFileAlternativeUseOfOverloadTag.symbols create mode 100644 tests/baselines/reference/jsFileAlternativeUseOfOverloadTag.types create mode 100644 tests/cases/compiler/jsFileAlternativeUseOfOverloadTag.ts diff --git a/tests/baselines/reference/jsFileAlternativeUseOfOverloadTag.js b/tests/baselines/reference/jsFileAlternativeUseOfOverloadTag.js new file mode 100644 index 0000000000000..a7e4cee8b4e96 --- /dev/null +++ b/tests/baselines/reference/jsFileAlternativeUseOfOverloadTag.js @@ -0,0 +1,121 @@ +//// [jsFileAlternativeUseOfOverloadTag.js] +// These are a few examples of existing alternative uses of @overload tag. +// They will not work as expected with our implementation, but we are +// trying to make sure that our changes do not result in any crashes here. + +const example1 = { + /** + * @overload Example1(value) + * Creates Example1 + * @param value [String] + */ + constructor: function Example1(value, options) {}, +}; + +const example2 = { + /** + * Example 2 + * + * @overload Example2(value) + * Creates Example2 + * @param value [String] + * @param secretAccessKey [String] + * @param sessionToken [String] + * @example Creates with string value + * const example = new Example(''); + * @overload Example2(options) + * Creates Example2 + * @option options value [String] + * @example Creates with options object + * const example = new Example2({ + * value: '', + * }); + */ + constructor: function Example2() {}, +}; + +const example3 = { + /** + * @overload evaluate(options = {}, [callback]) + * Evaluate something + * @note Something interesting + * @param options [map] + * @return [string] returns evaluation result + * @return [null] returns nothing if callback provided + * @callback callback function (error, result) + * If callback is provided it will be called with evaluation result + * @param error [Error] + * @param result [String] + * @see callback + */ + evaluate: function evaluate(options, callback) {}, +}; + + +//// [jsFileAlternativeUseOfOverloadTag.js] +// These are a few examples of existing alternative uses of @overload tag. +// They will not work as expected with our implementation, but we are +// trying to make sure that our changes do not result in any crashes here. +var example1 = { + /** + * @overload Example1(value) + * Creates Example1 + * @param value [String] + */ + constructor: function Example1(value, options) { } +}; +var example2 = { + /** + * Example 2 + * + * @overload Example2(value) + * Creates Example2 + * @param value [String] + * @param secretAccessKey [String] + * @param sessionToken [String] + * @example Creates with string value + * const example = new Example(''); + * @overload Example2(options) + * Creates Example2 + * @option options value [String] + * @example Creates with options object + * const example = new Example2({ + * value: '', + * }); + */ + constructor: function Example2() { } +}; +var example3 = { + /** + * @overload evaluate(options = {}, [callback]) + * Evaluate something + * @note Something interesting + * @param options [map] + * @return [string] returns evaluation result + * @return [null] returns nothing if callback provided + * @callback callback function (error, result) + * If callback is provided it will be called with evaluation result + * @param error [Error] + * @param result [String] + * @see callback + */ + evaluate: function evaluate(options, callback) { } +}; + + +//// [jsFileAlternativeUseOfOverloadTag.d.ts] +declare namespace example1 { + function constructor(value: any, options: any): void; +} +declare namespace example2 { + export function constructor_1(): void; + export { constructor_1 as constructor }; +} +declare namespace example3 { + function evaluate(options: any, callback: any): void; +} +/** + * function (error, result) + * If callback is provided it will be called with evaluation result + */ +type callback = (error: any, result: any) => any; diff --git a/tests/baselines/reference/jsFileAlternativeUseOfOverloadTag.symbols b/tests/baselines/reference/jsFileAlternativeUseOfOverloadTag.symbols new file mode 100644 index 0000000000000..3f378d40e61e7 --- /dev/null +++ b/tests/baselines/reference/jsFileAlternativeUseOfOverloadTag.symbols @@ -0,0 +1,72 @@ +=== tests/cases/compiler/jsFileAlternativeUseOfOverloadTag.js === +// These are a few examples of existing alternative uses of @overload tag. +// They will not work as expected with our implementation, but we are +// trying to make sure that our changes do not result in any crashes here. + +const example1 = { +>example1 : Symbol(example1, Decl(jsFileAlternativeUseOfOverloadTag.js, 4, 5)) + + /** + * @overload Example1(value) + * Creates Example1 + * @param value [String] + */ + constructor: function Example1(value, options) {}, +>constructor : Symbol(constructor, Decl(jsFileAlternativeUseOfOverloadTag.js, 4, 18)) +>Example1 : Symbol(Example1, Decl(jsFileAlternativeUseOfOverloadTag.js, 10, 14)) +>value : Symbol(value, Decl(jsFileAlternativeUseOfOverloadTag.js, 10, 33)) +>options : Symbol(options, Decl(jsFileAlternativeUseOfOverloadTag.js, 10, 39)) + +}; + +const example2 = { +>example2 : Symbol(example2, Decl(jsFileAlternativeUseOfOverloadTag.js, 13, 5)) + + /** + * Example 2 + * + * @overload Example2(value) + * Creates Example2 + * @param value [String] + * @param secretAccessKey [String] + * @param sessionToken [String] + * @example Creates with string value + * const example = new Example(''); + * @overload Example2(options) + * Creates Example2 + * @option options value [String] + * @example Creates with options object + * const example = new Example2({ + * value: '', + * }); + */ + constructor: function Example2() {}, +>constructor : Symbol(constructor, Decl(jsFileAlternativeUseOfOverloadTag.js, 13, 18)) +>Example2 : Symbol(Example2, Decl(jsFileAlternativeUseOfOverloadTag.js, 32, 14)) + +}; + +const example3 = { +>example3 : Symbol(example3, Decl(jsFileAlternativeUseOfOverloadTag.js, 35, 5)) + + /** + * @overload evaluate(options = {}, [callback]) + * Evaluate something + * @note Something interesting + * @param options [map] + * @return [string] returns evaluation result + * @return [null] returns nothing if callback provided + * @callback callback function (error, result) + * If callback is provided it will be called with evaluation result + * @param error [Error] + * @param result [String] + * @see callback + */ + evaluate: function evaluate(options, callback) {}, +>evaluate : Symbol(evaluate, Decl(jsFileAlternativeUseOfOverloadTag.js, 35, 18)) +>evaluate : Symbol(evaluate, Decl(jsFileAlternativeUseOfOverloadTag.js, 49, 11)) +>options : Symbol(options, Decl(jsFileAlternativeUseOfOverloadTag.js, 49, 30)) +>callback : Symbol(callback, Decl(jsFileAlternativeUseOfOverloadTag.js, 49, 38)) + +}; + diff --git a/tests/baselines/reference/jsFileAlternativeUseOfOverloadTag.types b/tests/baselines/reference/jsFileAlternativeUseOfOverloadTag.types new file mode 100644 index 0000000000000..aa606c5ade669 --- /dev/null +++ b/tests/baselines/reference/jsFileAlternativeUseOfOverloadTag.types @@ -0,0 +1,78 @@ +=== tests/cases/compiler/jsFileAlternativeUseOfOverloadTag.js === +// These are a few examples of existing alternative uses of @overload tag. +// They will not work as expected with our implementation, but we are +// trying to make sure that our changes do not result in any crashes here. + +const example1 = { +>example1 : { constructor: (value: any, options: any) => void; } +>{ /** * @overload Example1(value) * Creates Example1 * @param value [String] */ constructor: function Example1(value, options) {},} : { constructor: (value: any, options: any) => void; } + + /** + * @overload Example1(value) + * Creates Example1 + * @param value [String] + */ + constructor: function Example1(value, options) {}, +>constructor : (value: any, options: any) => void +>function Example1(value, options) {} : (value: any, options: any) => void +>Example1 : (value: any, options: any) => void +>value : any +>options : any + +}; + +const example2 = { +>example2 : { constructor: () => void; } +>{ /** * Example 2 * * @overload Example2(value) * Creates Example2 * @param value [String] * @param secretAccessKey [String] * @param sessionToken [String] * @example Creates with string value * const example = new Example(''); * @overload Example2(options) * Creates Example2 * @option options value [String] * @example Creates with options object * const example = new Example2({ * value: '', * }); */ constructor: function Example2() {},} : { constructor: () => void; } + + /** + * Example 2 + * + * @overload Example2(value) + * Creates Example2 + * @param value [String] + * @param secretAccessKey [String] + * @param sessionToken [String] + * @example Creates with string value + * const example = new Example(''); + * @overload Example2(options) + * Creates Example2 + * @option options value [String] + * @example Creates with options object + * const example = new Example2({ + * value: '', + * }); + */ + constructor: function Example2() {}, +>constructor : () => void +>function Example2() {} : () => void +>Example2 : () => void + +}; + +const example3 = { +>example3 : { evaluate: (options: any, callback: any) => void; } +>{ /** * @overload evaluate(options = {}, [callback]) * Evaluate something * @note Something interesting * @param options [map] * @return [string] returns evaluation result * @return [null] returns nothing if callback provided * @callback callback function (error, result) * If callback is provided it will be called with evaluation result * @param error [Error] * @param result [String] * @see callback */ evaluate: function evaluate(options, callback) {},} : { evaluate: (options: any, callback: any) => void; } + + /** + * @overload evaluate(options = {}, [callback]) + * Evaluate something + * @note Something interesting + * @param options [map] + * @return [string] returns evaluation result + * @return [null] returns nothing if callback provided + * @callback callback function (error, result) + * If callback is provided it will be called with evaluation result + * @param error [Error] + * @param result [String] + * @see callback + */ + evaluate: function evaluate(options, callback) {}, +>evaluate : (options: any, callback: any) => void +>function evaluate(options, callback) {} : (options: any, callback: any) => void +>evaluate : (options: any, callback: any) => void +>options : any +>callback : any + +}; + diff --git a/tests/cases/compiler/jsFileAlternativeUseOfOverloadTag.ts b/tests/cases/compiler/jsFileAlternativeUseOfOverloadTag.ts new file mode 100644 index 0000000000000..d3554f529c1e4 --- /dev/null +++ b/tests/cases/compiler/jsFileAlternativeUseOfOverloadTag.ts @@ -0,0 +1,56 @@ +// @allowJs: true +// @outDir: dist/ +// @declaration: true +// @filename: jsFileAlternativeUseOfOverloadTag.js + +// These are a few examples of existing alternative uses of @overload tag. +// They will not work as expected with our implementation, but we are +// trying to make sure that our changes do not result in any crashes here. + +const example1 = { + /** + * @overload Example1(value) + * Creates Example1 + * @param value [String] + */ + constructor: function Example1(value, options) {}, +}; + +const example2 = { + /** + * Example 2 + * + * @overload Example2(value) + * Creates Example2 + * @param value [String] + * @param secretAccessKey [String] + * @param sessionToken [String] + * @example Creates with string value + * const example = new Example(''); + * @overload Example2(options) + * Creates Example2 + * @option options value [String] + * @example Creates with options object + * const example = new Example2({ + * value: '', + * }); + */ + constructor: function Example2() {}, +}; + +const example3 = { + /** + * @overload evaluate(options = {}, [callback]) + * Evaluate something + * @note Something interesting + * @param options [map] + * @return [string] returns evaluation result + * @return [null] returns nothing if callback provided + * @callback callback function (error, result) + * If callback is provided it will be called with evaluation result + * @param error [Error] + * @param result [String] + * @see callback + */ + evaluate: function evaluate(options, callback) {}, +};