redeyed-jsx.js 936 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. 'use strict'
  2. /* eslint-disable no-template-curly-in-string */
  3. var test = require('tape')
  4. var util = require('util')
  5. var redeyed = require('..')
  6. function inspect(obj) {
  7. return util.inspect(obj, false, 5, true)
  8. }
  9. test('adding custom asserts ... ', function(t) {
  10. t.constructor.prototype.assertSurrounds = function(code, opts, expected) {
  11. var result = redeyed(code, opts, { jsx: true }).code
  12. if (expected == null) console.log(result)
  13. else this.equals(result, expected, inspect(code) + ' => ' + inspect(expected))
  14. return this
  15. }
  16. t.end()
  17. })
  18. test('\njsx support', function(t) {
  19. var config = {
  20. 'JSXIdentifier': {
  21. className: '$xc:cx%'
  22. , _default: '$x:x%'
  23. }
  24. , 'Punctuator': { _default: '$:%'
  25. }
  26. }
  27. t.assertSurrounds(
  28. '<Component start={1} className="hello" />'
  29. , config
  30. , '$<%$xComponentx% $xstartx%$=%${%1$}% $xcclassNamecx%$=%"hello" $/%$>%'
  31. )
  32. t.end()
  33. })