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

  var _addSourceLocation, babelDefault, jsx, doExpressions, bind;

  return {
    setters: [function (_reactiveJsx) {
      _addSourceLocation = _reactiveJsx.addSourceLocation;
    }, function (_systemjsBabelBuild) {
      babelDefault = _systemjsBabelBuild.default;
    }, function (_babelPluginSyntaxJsx) {
      jsx = _babelPluginSyntaxJsx.default;
    }, function (_babelPluginSyntaxDoExpressions) {
      doExpressions = _babelPluginSyntaxDoExpressions.default;
    }, function (_babelPluginSyntaxFunctionBind) {
      bind = _babelPluginSyntaxFunctionBind.default;
    }],
    execute: function () {
      const __SystemJSRewritingHack = {};
      _recorder_._src_client_syntax_js = _recorder_._src_client_syntax_js || {};
      Object.defineProperty(_recorder_._src_client_syntax_js, "babelDefault", {
        get() {
          return babelDefault;
        },

        set(thisIsVererySecretVariableName) {
          babelDefault = thisIsVererySecretVariableName;
          return true;
        },

        enumerable: true,
        configurable: true
      });

      const babel = babelDefault.babel;

      Object.defineProperty(_recorder_._src_client_syntax_js, "babel", {
        get() {
          return babel;
        },

        set(thisIsVererySecretVariableName) {
          babel = thisIsVererySecretVariableName;
          return true;
        },

        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._src_client_syntax_js, "jsx", {
        get() {
          return jsx;
        },

        set(thisIsVererySecretVariableName) {
          jsx = thisIsVererySecretVariableName;
          return true;
        },

        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._src_client_syntax_js, "doExpressions", {
        get() {
          return doExpressions;
        },

        set(thisIsVererySecretVariableName) {
          doExpressions = thisIsVererySecretVariableName;
          return true;
        },

        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._src_client_syntax_js, "bind", {
        get() {
          return bind;
        },

        set(thisIsVererySecretVariableName) {
          bind = thisIsVererySecretVariableName;
          return true;
        },

        enumerable: true,
        configurable: true
      });

      let additionalSyntaxPlugins = [jsx, doExpressions, bind];

      Object.defineProperty(_recorder_._src_client_syntax_js, "additionalSyntaxPlugins", {
        get() {
          return additionalSyntaxPlugins;
        },

        set(thisIsVererySecretVariableName) {
          additionalSyntaxPlugins = thisIsVererySecretVariableName;
          return true;
        },

        enumerable: true,
        configurable: true
      });
      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 = babel.transform(src, {
              babelrc: false,
              plugins: 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-async-generators', 'babel-plugin-syntax-do-expressions', 'babel-plugin-syntax-function-bind'].map(syntaxPlugin => System.import(syntaxPlugin)))).map(m => m.default);
          try {
            var result = 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 = _addSourceLocation(document.createElement("div"), {
              file: 'https://lively-kernel.org/lively4/lively4-function-completion/src/client/syntax.js',
              end: {
                column: 51,
                line: 110
              },
              start: {
                column: 22,
                line: 110
              }
            });
            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);

      Object.defineProperty(_recorder_._src_client_syntax_js, "SyntaxChecker", {
        get() {
          return SyntaxChecker;
        },

        set(thisIsVererySecretVariableName) {
          _export("default", SyntaxChecker = thisIsVererySecretVariableName);

          return true;
        },

        enumerable: true,
        configurable: true
      });
    }
  };
});