-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from tomvanenckevort/module-importmap-support
Added support for JS modules and importmaps
- Loading branch information
Showing
10 changed files
with
566 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
namespace AngleSharp.Js.Tests.Mocks | ||
{ | ||
using AngleSharp.Io; | ||
using AngleSharp.Io.Network; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Net; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
/// <summary> | ||
/// Mock HttpClientRequester which returns content for a specific request from a local dictionary. | ||
/// </summary> | ||
internal class MockHttpClientRequester : HttpClientRequester | ||
{ | ||
private readonly Dictionary<string, string> _mockResponses; | ||
|
||
public MockHttpClientRequester(Dictionary<string, string> mockResponses) : base() | ||
{ | ||
_mockResponses = mockResponses; | ||
} | ||
|
||
protected override async Task<IResponse> PerformRequestAsync(Request request, CancellationToken cancel) | ||
{ | ||
var response = new DefaultResponse(); | ||
|
||
if (_mockResponses.TryGetValue(request.Address.PathName, out var responseContent)) | ||
{ | ||
response.StatusCode = HttpStatusCode.OK; | ||
response.Content = new MemoryStream(Encoding.UTF8.GetBytes(responseContent)); | ||
} | ||
else | ||
{ | ||
response.StatusCode = HttpStatusCode.NotFound; | ||
response.Content = new MemoryStream(Encoding.UTF8.GetBytes(string.Empty)); | ||
} | ||
|
||
return response; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
namespace AngleSharp.Js | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
/// <summary> | ||
/// https://html.spec.whatwg.org/multipage/webappapis.html#import-map | ||
/// </summary> | ||
sealed class JsImportMap | ||
{ | ||
public JsImportMap() | ||
{ | ||
Imports = new Dictionary<string, Uri>(); | ||
Scopes = new Dictionary<string, Dictionary<string, Uri>>(); | ||
} | ||
|
||
/// <summary> | ||
/// Provides the mappings between module specifier text that might appear in an import statement or import() operator, | ||
/// and the text that will replace it when the specifier is resolved. | ||
/// </summary> | ||
public Dictionary<string, Uri> Imports { get; set; } | ||
|
||
/// <summary> | ||
/// Mappings that are only used if the script importing the module contains a particular URL path. | ||
/// If the URL of the loading script matches the supplied path, the mapping associated with the scope will be used. | ||
/// </summary> | ||
public Dictionary<string, Dictionary<string, Uri>> Scopes { get; set; } | ||
} | ||
} |
Oops, something went wrong.