JS beautifier: fix loop construct, fixes #3510

As JavaScript is the only language supported by the beautifier, and [CodeCombat is in the process of converting things to while (true)](https://github.com/codecombat/codecombat/issues/3510#issuecomment-201965310), I guess adding this quick hack to the view's code should suffice for now. Hopefully, the non-standard `loop` construct will be removed from other languages before they receive beautifier support.

If this doesn't seem good, I can move  this hack to `aether.beautify`, where it is possible to perform this substitution in a language-aware way (i.e. inside Aether's JavaScript implementation's [`beautify` method](418ccf2414/src/languages/javascript.coffee (L137))). Seeing as the `loop` construct is specific to CodeCombat, I'm not sure if that would be a good idea. Passing an options object with a flag to support the `loop` construct seems a bit overkill.

Let me know what works best for you.
This commit is contained in:
UltCombo 2016-03-27 23:55:55 -03:00
parent 539d0b01cc
commit 8326b5e182

View file

@ -1193,7 +1193,7 @@ module.exports = class SpellView extends CocoView
onSpellBeautify: (e) ->
return unless @spellThang and (@ace.isFocused() or e.spell is @spell)
ugly = @getSource()
pretty = @spellThang.aether.beautify ugly
pretty = @spellThang.aether.beautify(ugly.replace /\bloop\b/g, 'while (__COCO_LOOP_CONSTRUCT__)').replace /while \(__COCO_LOOP_CONSTRUCT__\)/g, 'loop'
@ace.setValue pretty
onMaximizeToggled: (e) ->