regexp.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. "use strict";
  6. // Make this available to both AMD and CJS environments
  7. define(function (require, exports, module) {
  8. // ReactJS
  9. const React = require("devtools/client/shared/vendor/react");
  10. // Reps
  11. const { isGrip } = require("./rep-utils");
  12. // Shortcuts
  13. const { span } = React.DOM;
  14. /**
  15. * Renders a grip object with regular expression.
  16. */
  17. let RegExp = React.createClass({
  18. displayName: "regexp",
  19. propTypes: {
  20. object: React.PropTypes.object.isRequired,
  21. },
  22. getSource: function (grip) {
  23. return grip.displayString;
  24. },
  25. render: function () {
  26. let grip = this.props.object;
  27. let objectLink = this.props.objectLink || span;
  28. return (
  29. span({className: "objectBox objectBox-regexp"},
  30. objectLink({
  31. object: grip,
  32. className: "regexpSource"
  33. }, this.getSource(grip))
  34. )
  35. );
  36. },
  37. });
  38. // Registration
  39. function supportsObject(object, type) {
  40. if (!isGrip(object)) {
  41. return false;
  42. }
  43. return (type == "RegExp");
  44. }
  45. // Exports from this module
  46. exports.RegExp = {
  47. rep: RegExp,
  48. supportsObject: supportsObject
  49. };
  50. });