aboutsummaryrefslogtreecommitdiffstats
path: root/tests/query/highlights/xhp-intro.hack
blob: 0f8cffe02fbdb4120a0b36800bca998a5f8a7829 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// From https://docs.hhvm.com/hack/XHP/introduction (MIT licensed)

use namespace Facebook\XHP\Core as x;
use type Facebook\XHP\HTML\{XHPHTMLHelpers, a, form};


final xhp class a_post extends x\element {
// ^ @keyword.modifier
//     ^ @keyword.modifier
//                        ^ @keyword
  use XHPHTMLHelpers;

  attribute string href @required;
  //                      ^ @attribute
  attribute string target;
  // ^ @keyword

  <<__Override>>
  protected async function renderAsync(): Awaitable<x\node> {
    $id = $this->getID();

    $anchor = <a>{$this->getChildren()}</a>;
                                    // ^ @tag.delimiter
                                    // ^ @tag
    $form = (
      <form
        id={$id}
        method="post"
        action={$this->:href}
        target={$this->:target}
        class="postLink">
        {$anchor}
      </form>
    );

    $anchor->setAttribute(
      'onclick',
      'document.getElementById("'.$id.'").submit(); return false;',
    );
    $anchor->setAttribute('href', '#');
    //        ^ @function.method.call

    return $form;
  }
}