Skip to content
This repository was archived by the owner on May 19, 2025. It is now read-only.

Conversation

grit-app[bot]
Copy link

@grit-app grit-app bot commented Mar 15, 2024

✅ This migration is up to date! ✅

⚠️ This pull request was auto-generated with Grit. ⚠️

This pull request was created with these settings:

  • Target branch: master
  • Source files: **/*
  • Preset pattern: _convert_default_exports – Replaces export default $something with export const $name = $something. The chosen name matches the file name.
Pattern body
language js

function make_identifiable($original) js {
    return $original.text.replaceAll("-", "_");
}

function guess_name() {
    $original = current_filename_without_extension(),
    $identifiable = make_identifiable($original),
    return $identifiable
}


pattern convert_default_exports($export_name) {
  `export default $export` as $full_export where {
      $guess_name = guess_name(),
      $export_name = $guess_name,
      $export <: or {
          or {
              `async function $name() { $_ }` where { !$name <: ., $export_name = $name },
              `function $name() { $_ }` where { !$name <: ., $export_name = $name },
              `function* $name() { $_ }` where { !$name <: ., $export_name = $name },
              `class $name { $_ }` where { !$name <: ., $export_name = $name },
              `async function($params) { $body }` => `async function $guess_name($params) { $body }`,
              `function($params) { $body }` => `function $guess_name($params) { $body }`,
              `function* ($params) { $body }` => `function* $guess_name($params) { $body }`,
              `class { $body }` where {
                $class_name = capitalize($guess_name)
              } => `class $class_name { $body }`
          } where {
              $full_export => `export $export`
          },
          // handle expression statements
          `$_` where {
              $full_export => `export const $guess_name = $export;`
          }
      }
  }
}

convert_default_exports()

<!-- grit:execution_id:e97a86be-68d2-4f33-832f-42b4a60be8e7 -->
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants