File: runner.html

package info (click to toggle)
node-esprima 3.1.3%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 16,628 kB
  • ctags: 372
  • sloc: makefile: 7; sh: 2
file content (67 lines) | stat: -rw-r--r-- 2,059 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<html>
    <head>
        <script src="../esprima.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.js"></script>

        <!-- JSON Editor  -->
        <link href="https://cdnjs.cloudflare.com/ajax/libs/jsoneditor/4.2.1/jsoneditor.css" rel="stylesheet" type="text/css">
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jsoneditor/4.2.1/jsoneditor.js"></script>


        <!-- CODE Mirror -->
        <link href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.6.0/codemirror.css" rel="stylesheet" type="text/css">
        <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.6.0/codemirror.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.6.0/mode/javascript/javascript.js"></script>

        <style>
          .CodeMirror {
            border-bottom: 1px solid #ccc;
          }

          #output-tree {
            height: calc(100% - 110px);
            margin-top: 10px;
          }
        </style>
    </head>
    <textarea id="source">x = function() {'use strict'; 2 +2; }</textarea>
    <div id="output-tree"></div>

    <script>
      var jsonViewer, jsEditor;

      function updateJsonViewer (editor, char) {
          var output;
          try {
              output = esprima.parse(editor.doc.getValue());
              jsonViewer.set(output);
          } catch (e) {
              output = e.stack;
          }
      }

      function setupEditor() {
        jsEditor = CodeMirror.fromTextArea($('#source').get(0), {
          mode: "javascript",
          gutter: true,
          lineNumbers: true
        })

        jsEditor.on("keyHandled", updateJsonViewer);
        jsEditor.setSize('100%', 100);
        jsEditor.gutter = true;
      }

      function setupJsonEditor() {
        jsonViewer = new JSONEditor($("#output-tree").get(0), {
           mode: 'view'
        });
      }

      $(function() {
        setupEditor();
        setupJsonEditor();
        updateJsonViewer(jsEditor);
      });
    </script>
</html>