Syntax.hx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright (C)2005-2019 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. package js;
  23. import haxe.extern.Rest;
  24. /**
  25. Generate JavaScript syntax not directly supported by Haxe.
  26. Use only at low-level when specific target-specific code-generation is required.
  27. **/
  28. extern class Syntax {
  29. /**
  30. Inject `code` directly into generated source.
  31. `code` must be a string constant.
  32. Additional `args` are supported to provide code interpolation, for example:
  33. ```haxe
  34. Syntax.code("console.log({0}, {1})", "hi", 42);
  35. ```
  36. will generate
  37. ```haxe
  38. console.log("hi", 42);
  39. ```
  40. **/
  41. static function code(code:String, args:Rest<Dynamic>):Dynamic;
  42. /**
  43. Generate `new cl(...args)` expression.
  44. **/
  45. @:overload(function(cl:String, args:Rest<Dynamic>):Dynamic {})
  46. static function construct<T>(cl:Class<T>, args:Rest<Dynamic>):T;
  47. /**
  48. Generate `v instanceof cl` expression.
  49. **/
  50. @:pure static function instanceof(v:Dynamic, cl:Class<Dynamic>):Bool;
  51. /**
  52. Generate `typeof o` expression.
  53. **/
  54. @:pure static function typeof(o:Dynamic):String;
  55. /**
  56. Genearte `a === b` expression.
  57. **/
  58. @:pure static function strictEq(a:Dynamic, b:Dynamic):Bool;
  59. /**
  60. Genearte `a !== b` expression.
  61. **/
  62. @:pure static function strictNeq(a:Dynamic, b:Dynamic):Bool;
  63. /**
  64. Generate `delete o[f]` expression.
  65. **/
  66. @:overload(function(o:Dynamic, f:Int):Bool {})
  67. static function delete(o:Dynamic, f:String):Bool;
  68. /**
  69. Generate `o.f` expression, if `f` is a constant string,
  70. or `o[f]` if it's any other expression.
  71. **/
  72. static function field(o:Dynamic, f:String):Dynamic;
  73. }