2
0

ModuleRequest.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. namespace Jint.Runtime.Modules;
  2. public readonly record struct ModuleImportAttribute(string Key, string Value);
  3. public readonly record struct ModuleRequest(string Specifier, ModuleImportAttribute[] Attributes)
  4. {
  5. /// <summary>
  6. /// https://tc39.es/proposal-import-attributes/#sec-ModuleRequestsEqual
  7. /// </summary>
  8. public bool Equals(ModuleRequest other)
  9. {
  10. if (!string.Equals(Specifier, other.Specifier, StringComparison.Ordinal))
  11. {
  12. return false;
  13. }
  14. if (this.Attributes.Length != other.Attributes.Length)
  15. {
  16. return false;
  17. }
  18. if (Attributes.Length == 0
  19. || (Attributes.Length == 1 && Attributes[0].Equals(other.Attributes[0])))
  20. {
  21. return true;
  22. }
  23. foreach (var pair in Attributes)
  24. {
  25. if (Array.IndexOf(other.Attributes, pair) == -1)
  26. {
  27. return false;
  28. }
  29. }
  30. return true;
  31. }
  32. public override int GetHashCode()
  33. {
  34. return StringComparer.Ordinal.GetHashCode(Specifier);
  35. }
  36. }