Repository: neovim/neovim
File: runtime/lua/vim/version.lua (Lua)

Code before:
    }, range_mt)
  end
  ---@type string, string
  local mods, version = spec:lower():match('^([%^=<>~]*)(.*)$')
  version = version:gsub('%.[%*x]', '')
  local parts = vim.split(version:gsub('%-.*', ''), '.', { plain = true })
  if #parts < 3 and mods == '' then
    mods = '~'
  end

  local semver = M.parse(version)
  if semver then
    local from = semver --- @type vim.Version?
    local to = vim.deepcopy(semver, true) --- @type vim.Version?
    ---@diagnostic disable: need-check-nil
    if mods == '<' then
      from = M._version({})
    elseif mods == '<=' then
      from = M._version({})
      -- HACK: construct the smallest reasonable version bigger than `to`
      -- to simulate `<=` while using exclusive right hand side
      if to.prerelease then
        to.prerelease = to.prerelease .. 'a'
      else
        to.patch = to.patch + 1
        to.prerelease = 'alpha'
      end
    elseif mods == '>' then
      from.patch = from.patch + 1
      -- HACK: construct the smallest reasonable version bigger than `from`
      -- to simulate `>` while using inclusive left hand side
      from.prerelease = 'alpha'
      to = nil
    elseif mods == '>=' then
      to = nil
    elseif mods == '~' then
      if #parts >= 2 then
        to[2] = to[2] + 1
        to[3] = 0
      else
        to[1] = to[1] + 1
        to[2] = 0
        to[3] = 0
      end
    elseif mods == '^' then
      for i = 1, 3 do
        if to[i] ~= 0 then
          to[i] = to[i] + 1
          for j = i + 1, 3 do
            to[j] = 0
          end

Review comment (suggestion):
From https://semver.org/#spec-item-9.
> A pre-release version MAY be denoted by appending a hyphen and a series of dot separated identifiers immediately following the patch version. Identifiers MUST comprise only ASCII alphanumerics and hyphens [0-9A-Za-z-]. Identifiers MUST NOT be empty. Numeric identifiers MUST NOT include leading zeroes. Pre-release versions have a lower precedence than the associated normal version. A pre-release version indicates that the version is unstable and might not satisfy the intended compatibility requirements as denoted by its associated normal version. Examples: 1.0.0-alpha, 1.0.0-alpha.1, 1.0.0-0.3.7, 1.0.0-x.7.z.92, 1.0.0-x-y-z.--.

```suggestion
        to.prerelease = '0'
```

Code after:
    }, range_mt)
  end
  ---@type string, string
  local mods, version = spec:lower():match('^([%^=<>~]*)(.*)$')
  version = version:gsub('%.[%*x]', '')
  local parts = vim.split(version:gsub('%-.*', ''), '.', { plain = true })
  if #parts < 3 and mods == '' then
    mods = '~'
  end

  local semver = M.parse(version)
  if semver then
    local from = semver --- @type vim.Version?
    local to = vim.deepcopy(semver, true) --- @type vim.Version?
    ---@diagnostic disable: need-check-nil
    if mods == '<' then
      from = M._version({})
    elseif mods == '<=' then
      from = M._version({})
      -- HACK: construct the smallest reasonable version bigger than `to`
      -- to simulate `<=` while using exclusive right hand side
      if to.prerelease then
        to.prerelease = to.prerelease .. '.0'
      else
        to.patch = to.patch + 1
        to.prerelease = '0'
      end
    elseif mods == '>' then
      -- HACK: construct the smallest reasonable version bigger than `from`
      -- to simulate `>` while using inclusive left hand side
      if from.prerelease then
        from.prerelease = from.prerelease .. '.0'
      else
        from.patch = from.patch + 1
        from.prerelease = '0'
      end
      to = nil
    elseif mods == '>=' then
      to = nil
    elseif mods == '~' then
      if #parts >= 2 then
        to[2] = to[2] + 1
        to[3] = 0
      else
        to[1] = to[1] + 1
        to[2] = 0
        to[3] = 0
      end
    elseif mods == '^' then
      for i = 1, 3 do
        if to[i] ~= 0 then