Merge pull request #30234 from leonard-thieu/jquery/text-comment-parameters

[jquery] Allow Text/Comment nodes for some APIs that accept an HTML string.
This commit is contained in:
Nathan Shively-Sanders
2018-12-18 13:12:20 -08:00
committed by GitHub
2 changed files with 43 additions and 6 deletions

View File

@@ -83,6 +83,7 @@ $( document.body )
* @since 1.4
*/
add(selector: JQuery.Selector, context: Element): this;
// TODO: The return type should reflect newly selected types.
/**
* Create a new jQuery object with elements added to the set of matched elements.
* @param selector_elements_html_selection _@param_ `selector_elements_html_selection`
@@ -226,7 +227,7 @@ collection.css( "background", "yellow" );
</html>
```
*/
add(selector_elements_html_selection: JQuery.Selector | JQuery.TypeOrArray<Element> | JQuery.htmlString | JQuery): this;
add(selector_elements_html_selection: JQuery.Selector | JQuery.TypeOrArray<Element> | JQuery.htmlString | JQuery | JQuery.Node): this;
/**
* Add the previous set of elements on the stack to the current set, optionally filtered by a selector.
* @param selector A string containing a selector expression to match the current set of elements against.
@@ -5141,7 +5142,9 @@ $( "div b" )
</html>
```
*/
html(htmlString_function: JQuery.htmlString | ((this: TElement, index: number, oldhtml: JQuery.htmlString) => JQuery.htmlString)): this;
html(htmlString_function: JQuery.htmlString |
JQuery.Node |
((this: TElement, index: number, oldhtml: JQuery.htmlString) => JQuery.htmlString | JQuery.Node)): this;
/**
* Get the HTML contents of the first element in the set of matched elements.
* @see \`{@link https://api.jquery.com/html/ }\`
@@ -9990,7 +9993,14 @@ $( "button" ).on( "click", function() {
</html>
```
*/
replaceWith(newContent_function: JQuery.htmlString | JQuery | JQuery.TypeOrArray<Element> | ((this: TElement) => any)): this;
replaceWith(newContent_function: JQuery.htmlString |
JQuery<JQuery.Node> |
JQuery.TypeOrArray<Element> |
JQuery.Node |
((this: TElement, index: number, oldhtml: JQuery.htmlString) => JQuery.htmlString |
JQuery<JQuery.Node> |
JQuery.TypeOrArray<Element> |
JQuery.Node)): this;
/**
* Bind an event handler to the "resize" JavaScript event, or trigger that event on an element.
* @param eventData An object containing data that will be passed to the event handler.

View File

@@ -5565,11 +5565,21 @@ function JQuery() {
$('p').replaceWith([new HTMLElement()]);
// $ExpectType JQuery<HTMLElement>
$('p').replaceWith(function() {
$('p').replaceWith(document.createTextNode('bar'));
// $ExpectType JQuery<HTMLElement>
$('p').replaceWith(document.createComment('bar'));
// $ExpectType JQuery<HTMLElement>
$('p').replaceWith(function(index, oldhtml) {
// $ExpectType HTMLElement
this;
// $ExpectType number
index;
// $ExpectType string
oldhtml;
return this;
return undefined! as JQuery.htmlString | JQuery<JQuery.Node> | JQuery.TypeOrArray<Element> | JQuery.Node;
});
}
@@ -5693,6 +5703,12 @@ function JQuery() {
// $ExpectType JQuery<HTMLElement>
$('p').html('<span></span>');
// $ExpectType JQuery<HTMLElement>
$('p').html(document.createTextNode('bar'));
// $ExpectType JQuery<HTMLElement>
$('p').html(document.createComment('bar'));
// $ExpectType JQuery<HTMLElement>
$('p').html(function(index, oldhtml) {
// $ExpectType HTMLElement
@@ -5702,7 +5718,12 @@ function JQuery() {
// $ExpectType string
oldhtml;
return oldhtml;
switch (index) {
case 0: return document.createTextNode('bar');
case 1: return document.createComment('bar');
default: return oldhtml;
}
});
// $ExpectType string
@@ -5805,6 +5826,12 @@ function JQuery() {
// $ExpectType JQuery<HTMLElement>
$('p').add($('span'));
// $ExpectType JQuery<HTMLElement>
$('p').add(document.createTextNode('bar'));
// $ExpectType JQuery<HTMLElement>
$('p').add(document.createComment('bar'));
}
function closest() {