System.register(["systemjs-babel-build", "babel-plugin-syntax-jsx", "babel-plugin-syntax-do-expressions", "babel-plugin-syntax-function-bind"], function (_export, _context) {
  "use strict";

  var babelDefault, jsx, doExpressions, bind;
  return {
    setters: [function (_systemjsBabelBuild) {
      babelDefault = _systemjsBabelBuild.default;
    }, function (_babelPluginSyntaxJsx) {
      jsx = _babelPluginSyntaxJsx.default;
    }, function (_babelPluginSyntaxDoExpressions) {
      doExpressions = _babelPluginSyntaxDoExpressions.default;
    }, function (_babelPluginSyntaxFunctionBind) {
      bind = _babelPluginSyntaxFunctionBind.default;
    }],
    execute: function () {
      _recorder_._src_client_syntax_js = _recorder_._src_client_syntax_js || {};
      _recorder_._src_client_syntax_js.babelDefault = babelDefault;

      const babel = _recorder_._src_client_syntax_js.babelDefault.babel;

      _recorder_._src_client_syntax_js.babel = babel;
      _recorder_._src_client_syntax_js.jsx = jsx;
      _recorder_._src_client_syntax_js.doExpressions = doExpressions;
      _recorder_._src_client_syntax_js.bind = bind;

      let additionalSyntaxPlugins = [_recorder_._src_client_syntax_js.jsx, _recorder_._src_client_syntax_js.doExpressions, _recorder_._src_client_syntax_js.bind];

      _recorder_._src_client_syntax_js.additionalSyntaxPlugins = additionalSyntaxPlugins;
      class SyntaxChecker {

        static checkForSyntaxErrors(editor) {
          if (!editor.getSession) {
            // we assume we are a code mirror, what else should we be? #HACK
            return this.checkForSyntaxErrorsCodeMirror(editor);
          }

          var Range = ace.require('ace/range').Range;
          var doc = editor.getSession().getDocument();
          var src = editor.getValue();

          // clear annotations
          editor.getSession().setAnnotations([]);

          // clear markers
          var markers = editor.getSession().getMarkers();
          for (var i in markers) {
            if (markers[i].clazz == "marked") {
              editor.getSession().removeMarker(i);
            }
          }

          try {
            var result = _recorder_._src_client_syntax_js.babel.transform(src, {
              babelrc: false,
              plugins: _recorder_._src_client_syntax_js.additionalSyntaxPlugins,
              presets: [],
              filename: undefined,
              sourceFileName: undefined,
              moduleIds: false,
              sourceMaps: false,
              compact: false,
              comments: true,
              code: true,
              ast: true,
              resolveModuleSource: undefined
            });
            var ast = result.ast;
            return false;
          } catch (e) {
            editor.session.addMarker(Range.fromPoints(doc.indexToPosition(e.pos), doc.indexToPosition(e.raisedAt)), "marked", "text", false);

            editor.getSession().setAnnotations([{
              row: e.loc.line - 1,
              column: e.loc.column,
              text: e.message,
              type: "error"
            }]);

            return true;
          }
        }

        static async checkForSyntaxErrorsCodeMirror(editor) {
          var src = editor.getValue();

          editor.clearGutter("leftgutter"

          // clear markers
          );editor.getAllMarks().filter(ea => ea.isSyntaxError).forEach(ea => ea.clear());

          const syntaxPlugins = (await Promise.all(['babel-plugin-syntax-jsx', 'babel-plugin-syntax-do-expressions', 'babel-plugin-syntax-function-bind'].map(syntaxPlugin => System.import(syntaxPlugin)))).map(m => m.default);
          try {
            var result = _recorder_._src_client_syntax_js.babel.transform(src, {
              babelrc: false,
              plugins: syntaxPlugins,
              presets: [],
              filename: undefined,
              sourceFileName: undefined,
              moduleIds: false,
              sourceMaps: false,
              compact: false,
              comments: true,
              code: true,
              ast: true,
              resolveModuleSource: undefined
            });
            var ast = result.ast;
            return false;
          } catch (e) {
            var line = e.loc.line - 1;
            var errorMark = document.createElement("div");
            errorMark.style.color = "red";
            errorMark.style.marginLeft = "5px";
            errorMark.innerHTML = "<b>!</b>";
            errorMark.classList.add("errorMark");
            errorMark.setAttribute("title", "" + e);
            editor.setGutterMarker(line, "leftgutter", errorMark);

            var marker = editor.markText({ line: line, ch: 0 }, // e.loc.column
            { line: line, ch: 100 }, {
              isSyntaxError: true,
              css: "background-color: rgba(255,0,0,0.3)",
              title: "" + e
            });

            // editor.getSession().setAnnotations([{
            //   row: e.loc.line - 1,
            //   column: e.loc.column,
            //   text: e.message,
            //   type: "error"
            // }]);

            return true;
          }
        }

      }

      _export("default", SyntaxChecker);

      _recorder_._src_client_syntax_js.SyntaxChecker = SyntaxChecker;
    }
  };
});