character-escape.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. 'use strict'
  2. var assert = require('assert')
  3. var asciiPunctuation = require('../character/ascii-punctuation.js')
  4. var codes = require('../character/codes.js')
  5. var types = require('../constant/types.js')
  6. function _interopDefaultLegacy(e) {
  7. return e && typeof e === 'object' && 'default' in e ? e : {default: e}
  8. }
  9. var assert__default = /*#__PURE__*/ _interopDefaultLegacy(assert)
  10. var characterEscape = {
  11. name: 'characterEscape',
  12. tokenize: tokenizeCharacterEscape
  13. }
  14. function tokenizeCharacterEscape(effects, ok, nok) {
  15. return start
  16. function start(code) {
  17. assert__default['default'](code === codes.backslash, 'expected `\\`')
  18. effects.enter(types.characterEscape)
  19. effects.enter(types.escapeMarker)
  20. effects.consume(code)
  21. effects.exit(types.escapeMarker)
  22. return open
  23. }
  24. function open(code) {
  25. if (asciiPunctuation(code)) {
  26. effects.enter(types.characterEscapeValue)
  27. effects.consume(code)
  28. effects.exit(types.characterEscapeValue)
  29. effects.exit(types.characterEscape)
  30. return ok
  31. }
  32. return nok(code)
  33. }
  34. }
  35. module.exports = characterEscape