Repository: babel/babel
File: packages/babel-parser/src/parser/statement.ts (TypeScript)

Code before:
    decorators: N.Decorator[] | null,
  ): N.AnyExport {
    const maybeDefaultIdentifier = this.parseMaybeImportPhase(
      node,
      /* isExport */ true,
    );
    const hasDefault = this.maybeParseExportDefaultSpecifier(
      node,
      maybeDefaultIdentifier,
    );
    const parseAfterDefault = !hasDefault || this.eat(tt.comma);
    const hasStar = parseAfterDefault && this.eatExportStar(node);
    const hasNamespace =
      hasStar && this.maybeParseExportNamespaceSpecifier(node);
    const parseAfterNamespace =
      parseAfterDefault && (!hasNamespace || this.eat(tt.comma));
    const isFromRequired = hasDefault || hasStar;

    if (hasStar && !hasNamespace) {
      if (hasDefault) this.unexpected();
      if (decorators) {
        throw this.raise(Errors.UnsupportedDecoratorExport, node);
      }
      this.parseExportFrom(node, true);

      if (node.exportKind !== "type") {
        this.sawUnambiguousESM = true;
      }

      return this.finishNode(node, "ExportAllDeclaration");
    }

    const hasSpecifiers = this.maybeParseExportNamedSpecifiers(node);

    if (hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers) {
      this.unexpected(null, tt.braceL);
    }

    if (hasNamespace && parseAfterNamespace) {
      this.unexpected(null, tt._from);
    }

    let hasDeclaration;
    if (isFromRequired || hasSpecifiers) {
      hasDeclaration = false;
      if (decorators) {
        throw this.raise(Errors.UnsupportedDecoratorExport, node);
      }
      this.parseExportFrom(
        node as Undone<N.ExportNamedDeclaration>,
        isFromRequired,

Review comment (suggestion):
Here is one thing typescript-eslint differs: they set the `sourceType` to `module` even when the source only includes type imports/exports: AFAIK TS does not offer ways to include types via commonJS require, so I am not convinced that we should do so as well. To align with their AST we can monkey patch the eslint-parser instead.

@bradzacher Could you shred some light here? Thank you.

Code after:
      node,
      maybeDefaultIdentifier,
    );
    const parseAfterDefault = !hasDefault || this.eat(tt.comma);
    const hasStar = parseAfterDefault && this.eatExportStar(node);
    const hasNamespace =
      hasStar && this.maybeParseExportNamespaceSpecifier(node);
    const parseAfterNamespace =
      parseAfterDefault && (!hasNamespace || this.eat(tt.comma));
    const isFromRequired = hasDefault || hasStar;

    if (hasStar && !hasNamespace) {
      if (hasDefault) this.unexpected();
      if (decorators) {
        throw this.raise(Errors.UnsupportedDecoratorExport, node);
      }
      this.parseExportFrom(node, true);

      this.sawUnambiguousESM = true;

      return this.finishNode(node, "ExportAllDeclaration");
    }

    const hasSpecifiers = this.maybeParseExportNamedSpecifiers(node);

    if (hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers) {
      this.unexpected(null, tt.braceL);
    }

    if (hasNamespace && parseAfterNamespace) {
      this.unexpected(null, tt._from);
    }

    let hasDeclaration;
    if (isFromRequired || hasSpecifiers) {
      hasDeclaration = false;
      if (decorators) {
        throw this.raise(Errors.UnsupportedDecoratorExport, node);
      }
      this.parseExportFrom(
        node as Undone<N.ExportNamedDeclaration>,
        isFromRequired,
      );
    } else {
      hasDeclaration = this.maybeParseExportDeclaration(
        node as Undone<N.ExportNamedDeclaration>,
      );
    }

    if (isFromRequired || hasSpecifiers || hasDeclaration) {
      const node2 = node as Undone<N.ExportNamedDeclaration>;