Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests for alternative uses of @overload tag
  • Loading branch information
apendua committed Dec 3, 2022
commit f0ec97c59e9f64b231d13b4b05d06ecb2b735b73
121 changes: 121 additions & 0 deletions tests/baselines/reference/jsFileAlternativeUseOfOverloadTag.js
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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))

};

78 changes: 78 additions & 0 deletions tests/baselines/reference/jsFileAlternativeUseOfOverloadTag.types
Original file line number Diff line number Diff line change
@@ -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

};

56 changes: 56 additions & 0 deletions tests/cases/compiler/jsFileAlternativeUseOfOverloadTag.ts
Original file line number Diff line number Diff line change
@@ -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) {},
};