"enable examples";
"disable deepeval";

System.register(["systemjs-babel-build", "babel-plugin-syntax-jsx", "babel-plugin-syntax-do-expressions", "babel-plugin-syntax-function-bind", "babel-plugin-syntax-async-generators", "babel-plugin-syntax-class-properties", "babel-plugin-syntax-object-rest-spread"], function (_export, _context) {
  "use strict";

  var babelDefault, babelPluginSyntaxJSX, babelPluginSyntaxDoExpressions, babelPluginSyntaxFunctionBind, babelPluginSyntaxGenerators, classProperties, objectRestSpread;
  return {
    setters: [function (_systemjsBabelBuild) {
      babelDefault = _systemjsBabelBuild.default;
    }, function (_babelPluginSyntaxJsx) {
      babelPluginSyntaxJSX = _babelPluginSyntaxJsx.default;
    }, function (_babelPluginSyntaxDoExpressions) {
      babelPluginSyntaxDoExpressions = _babelPluginSyntaxDoExpressions.default;
    }, function (_babelPluginSyntaxFunctionBind) {
      babelPluginSyntaxFunctionBind = _babelPluginSyntaxFunctionBind.default;
    }, function (_babelPluginSyntaxAsyncGenerators) {
      babelPluginSyntaxGenerators = _babelPluginSyntaxAsyncGenerators.default;
    }, function (_babelPluginSyntaxClassProperties) {
      classProperties = _babelPluginSyntaxClassProperties.default;
    }, function (_babelPluginSyntaxObjectRestSpread) {
      objectRestSpread = _babelPluginSyntaxObjectRestSpread.default;
    }],
    execute: function () {
      const __SystemJSRewritingHack = {};
      _recorder_._src_client_javascript_js = _recorder_._src_client_javascript_js || {};
      Object.defineProperty(_recorder_._src_client_javascript_js, "hasASTBinding", {
        get() {
          return hasASTBinding;
        },

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

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

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

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

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

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

        set(thisIsVererySecretVariableName) {
          _export("parseModuleSemantics", parseModuleSemantics = thisIsVererySecretVariableName);

          return true;
        },

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

        set(thisIsVererySecretVariableName) {
          _export("parseModuleSemanticsFromSource", parseModuleSemanticsFromSource = thisIsVererySecretVariableName);

          return true;
        },

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

        set(thisIsVererySecretVariableName) {
          _export("parseSource", parseSource = thisIsVererySecretVariableName);

          return true;
        },

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

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

        enumerable: true,
        configurable: true
      });

      const babel = babelDefault.babel;
      Object.defineProperty(_recorder_._src_client_javascript_js, "babel", {
        get() {
          return babel;
        },

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

        enumerable: true,
        configurable: true
      });
      const t = babel.types;

      Object.defineProperty(_recorder_._src_client_javascript_js, "t", {
        get() {
          return t;
        },

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

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

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

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

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

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

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

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

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

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

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

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

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

        enumerable: true,
        configurable: true
      });


      const syntaxPlugins = [babelPluginSyntaxJSX, babelPluginSyntaxDoExpressions, babelPluginSyntaxFunctionBind, babelPluginSyntaxGenerators, classProperties, objectRestSpread];

      Object.defineProperty(_recorder_._src_client_javascript_js, "syntaxPlugins", {
        get() {
          return syntaxPlugins;
        },

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

        enumerable: true,
        configurable: true
      });
      function /*example:*/parseSource /*{"id":"d471_7474_cb07","name":{"mode":"input","value":""},"color":"hsl(120, 30%, 70%)","values":{"filename":{"mode":"input","value":"\"f1\""},"source":{"mode":"select","value":"2025_8b45_d12e"}},"instanceId":{"mode":"input","value":""},"prescript":"","postscript":""}*/(filename, source) {
        try {
          return babel.transform( /*probe:*/source /*{}*/, {
            babelrc: false,
            plugins: [...syntaxPlugins],
            presets: [],
            filename: filename,
            sourceFileName: filename,
            moduleIds: false,
            sourceMaps: true,
            compact: false,
            comments: true,
            code: true,
            ast: true,
            resolveModuleSource: undefined
          }).ast;
        } catch (e) {
          console.log('FileIndex, could not parse: ' + filename, e);
          return undefined;
        }
      }

      _export("parseSource", parseSource);

      function parseModuleSemanticsFromSource(filename, source) {
        return parseModuleSemantics(parseSource(filename, source));
      }

      _export("parseModuleSemanticsFromSource", parseModuleSemanticsFromSource);

      function parseModuleSemantics(ast) {
        let classes = [];
        let dependencies = [];
        let importDeclarations = new Map();
        let functionExports = [];
        let classExports = [];
        let unboundIdentifiers = [];
        babel.traverse( /*probe:*/ast /*{}*/, {
          ImportDeclaration(path) {
            if (path.node.source && path.node.source.value) {
              let specifierNames = [];
              let moduleUrl = path.node.source.value;
              if (path.node.specifiers) {
                path.node.specifiers.forEach(function (item) {
                  if (item.type === "ImportNamespaceSpecifier") {
                    specifierNames.push('*');
                    importDeclarations.set('*', moduleUrl);
                  } else {
                    specifierNames.push(item.local.name);
                    importDeclarations.set(item.local.name, moduleUrl);
                  }
                });
              }
              let dependency = {
                url: path.node.source.value,
                names: specifierNames
              };
              dependencies.push(dependency);
            }
          },
          ClassDeclaration(path) {
            let superClassName = '';
            let superClassUrl = '';
            if (path.node.id) {
              let clazz = {
                name: path.node.id.name,
                start: path.node.start, // start byte 
                end: path.node.end, // end byte
                loc: path.node.loc.end.line - path.node.loc.start.line + 1
              };
              superClassName = path.node.superClass ? path.node.superClass.name : '';
              superClassUrl = importDeclarations.get(superClassName);
              let methods = [];

              if (path.node.body.body) {
                path.node.body.body.forEach(function (item) {
                  if (item.type === "ClassMethod") {
                    let method = {
                      name: item.key.name,
                      loc: item.loc.end.line - item.loc.start.line + 1,
                      start: item.start,
                      kind: item.kind,
                      static: item.static,
                      end: item.end,
                      leadingComments: item.leadingComments
                    };
                    methods.push(method);
                  }
                });
              }
              clazz.methods = methods;
              clazz.superClassName = superClassName;
              clazz.superClassUrl = superClassUrl;
              classes.push(clazz);
            }
          },
          ExportNamedDeclaration(path) {
            if (t.isFunctionDeclaration(path.node.declaration)) {
              functionExports.push(path.node.declaration.id.name);
            }
            if (t.isClassDeclaration(path.node.declaration)) {
              classExports.push(path.node.declaration.id.name);
            }
          },
          Identifier(path) {
            if (!hasASTBinding(path)) {
              unboundIdentifiers.push(path.node.name);
            }
          }
        });
        return { classes, dependencies, functionExports, classExports, unboundIdentifiers };
      }

      _export("parseModuleSemantics", parseModuleSemantics);

      function getBindingDeclarationIdentifierPath(binding) {
        return getFirstSelectedIdentifierWithName(binding.path, binding.identifier.name);
      }

      function getFirstSelectedIdentifierWithName(startPath, name) {
        if (t.isIdentifier(startPath.node, { name: name })) {
          return startPath;
        }
        var first;
        startPath.traverse({
          Identifier(path) {
            if (!first && t.isIdentifier(path.node, { name: name })) {
              first = path;
              path.stop();
            }
          }
        });
        return first;
      }

      function hasASTBinding(identifier) {
        if (!identifier.scope.hasBinding(identifier.node.name)) return false;

        const binding = identifier.scope.getBinding(identifier.node.name);
        if (!binding) return false;

        const identifierPaths = [...new Set([getBindingDeclarationIdentifierPath(binding), ...binding.referencePaths, ...binding.constantViolations.map(cv => getFirstSelectedIdentifierWithName(cv, binding.identifier.name))])];
        return identifierPaths.includes(identifier);
      } /* Context: {"context":{"prescript":"","postscript":""},"customInstances":[{"id":"2025_8b45_d12e","name":"source_f1","code":"return `\n\nfunction f1() {\n  return 3 + 4\n}\n\n`;"}]} */
    }
  };
});