HaxeFoundation / haxe.org-comments

Repository to collect comments of our haxe.org websites
2 stars 2 forks source link

[code.haxe.org] Macros - Assert macro that shows sub-expression values #27

Open utterances-bot opened 5 years ago

utterances-bot commented 5 years ago

Assert macro that shows sub-expression values - Macros - Haxe programming language cookbook

Sometimes failed assertion checks make it difficult to tell what went wrong. For debugging the programmer not only wants to know that a check failed, but also why it failed. This macro outputs the values of all sub-expressions.

https://code.haxe.org/category/macros/assert-with-values.html

sonygod commented 5 years ago

how to add -D debug to use this function? I don't want use for Release version .

Aurel300 commented 5 years ago

@sonygod At the beginning of the assert macro function, you could put something like:

if (!haxe.macro.Context.defined("debug"))
  return macro {};

Keep in mind that this means whatever is inside the assert call will not be evaluated at all in release builds, so don't rely on any side effects.

sonygod commented 5 years ago

@Aurel300 is that possible support js map? current only support gen js?

Aurel300 commented 5 years ago

@sonygod I don't know what you're asking. Are you sure it's related to this article?

sonygod commented 5 years ago

I mean support *.js.map @Aurel300 image