Syntax.hx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package js;
  2. import haxe.extern.Rest;
  3. /**
  4. Generate JavaScript syntax not directly supported by Haxe.
  5. Use only at low-level when specific target-specific code-generation is required.
  6. **/
  7. extern class Syntax {
  8. /**
  9. Inject `code` directly into generated source.
  10. `code` must be a string constant.
  11. Additional `args` are supported to provide code interpolation, for example:
  12. ```
  13. Syntax.code("console.log({0}, {1})", "hi", 42);
  14. ```
  15. will generate
  16. ```
  17. console.log("hi", 42);
  18. ```
  19. **/
  20. static function code(code:String, args:Rest<Dynamic>):Dynamic;
  21. /**
  22. Generate `new cl(...args)` expression.
  23. **/
  24. @:overload(function(cl:String, args:Rest<Dynamic>):Dynamic {})
  25. static function construct<T>(cl:Class<T>, args:Rest<Dynamic>):T;
  26. /**
  27. Generate `v instanceof cl` expression.
  28. **/
  29. @:pure static function instanceof(v:Dynamic, cl:Class<Dynamic>):Bool;
  30. /**
  31. Generate `typeof o` expression.
  32. **/
  33. @:pure static function typeof(o:Dynamic):String;
  34. /**
  35. Genearte `a === b` expression.
  36. **/
  37. @:pure static function strictEq(a:Dynamic, b:Dynamic):Bool;
  38. /**
  39. Genearte `a !== b` expression.
  40. **/
  41. @:pure static function strictNeq(a:Dynamic, b:Dynamic):Bool;
  42. /**
  43. Generate `delete o[f]` expression.
  44. **/
  45. @:overload(function(o:Dynamic, f:Int):Bool {})
  46. static function delete(o:Dynamic, f:String):Bool;
  47. /**
  48. Generate `o[f]` expression
  49. */
  50. static inline function field(o:Dynamic, f:String):Dynamic {
  51. return code('{0}[{1}]', o, f);
  52. }
  53. }