Skip to content

Commit

Permalink
refactor: combine ModuleKind::BuiltIn and ModuleKind::External (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored Jan 23, 2023
1 parent 1001af2 commit 8c474ab
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 30 deletions.
6 changes: 3 additions & 3 deletions lib/deno_graph.generated.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @generated file from wasmbuild -- do not edit
// deno-lint-ignore-file
// deno-fmt-ignore-file
// source-hash: fc76c40e15d33e680bbaa02b316fb29c09fff90f
// source-hash: 0f28a4f2f624fbef067048830566e855129ba947
let wasm;

const heap = new Array(32).fill(undefined);
Expand Down Expand Up @@ -946,8 +946,8 @@ const imports = {
const ret = wasm.memory;
return addHeapObject(ret);
},
__wbindgen_closure_wrapper1371: function (arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 192, __wbg_adapter_48);
__wbindgen_closure_wrapper1346: function (arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 191, __wbg_adapter_48);
return addHeapObject(ret);
},
},
Expand Down
Binary file modified lib/deno_graph_bg.wasm
Binary file not shown.
7 changes: 3 additions & 4 deletions lib/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ export interface LoadResponseModule {
content: string;
}

export interface LoadResponseExternalBuiltIn {
export interface LoadResponseExternal {
/** The loaded module is either _external_ or _built-in_ to the runtime. */
kind: "external" | "builtIn";
kind: "external";
/** The strung URL of the resource. If there were redirects, the final
* specifier should be set here, otherwise the requested specifier. */
specifier: string;
}

export type LoadResponse = LoadResponseModule | LoadResponseExternalBuiltIn;
export type LoadResponse = LoadResponseModule | LoadResponseExternal;

export interface PositionJson {
/** The line number of a position within a source file. The number is a zero
Expand Down Expand Up @@ -101,7 +101,6 @@ export interface TypesDependencyJson {
* dependencies provided. */
export type ModuleKind =
| "asserted"
| "builtIn"
| "esm"
| "external"
| "script";
Expand Down
11 changes: 0 additions & 11 deletions src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,6 @@ pub enum ModuleKind {
/// `MediaType` matches the assertion. Dependency analysis does not occur on
/// asserted modules.
Asserted,
/// Represents a module which is built in to a runtime. The module does not
/// contain source and will have no dependencies.
BuiltIn,
/// An ECMAScript Module (JavaScript Module).
Esm,
/// Represents a module which is not statically analyzed and is only available
Expand Down Expand Up @@ -1522,14 +1519,6 @@ impl<'a> Builder<'a> {
maybe_assert_type: Option<String>,
) {
let (specifier, module_slot) = match response {
LoadResponse::BuiltIn { specifier } => {
self.check_specifier(requested_specifier, specifier);
let module_slot = ModuleSlot::Module(Module::new_without_source(
specifier.clone(),
ModuleKind::BuiltIn,
));
(specifier, module_slot)
}
LoadResponse::External { specifier } => {
self.check_specifier(requested_specifier, specifier);
let module_slot = ModuleSlot::Module(Module::new_without_source(
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2659,7 +2659,7 @@ export function a(a) {
"#,
},
),
("builtin:fs", Source::BuiltIn("builtin:fs")),
("builtin:fs", Source::External("builtin:fs")),
(
"https://example.com/bundle",
Source::External("https://example.com/bundle"),
Expand All @@ -2683,7 +2683,7 @@ export function a(a) {
],
"modules": [
{
"kind": "builtIn",
"kind": "external",
"specifier": "builtin:fs"
},
{
Expand Down
7 changes: 0 additions & 7 deletions src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ pub struct CacheInfo {
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
#[serde(tag = "kind", rename_all = "camelCase")]
pub enum LoadResponse {
/// A module which is built into the runtime. The module will be marked as
/// `ModuleKind::BuiltIn` and no dependency analysis will be performed.
BuiltIn { specifier: ModuleSpecifier },
/// A module where the content is not available when building the graph, but
/// will be available at runtime. The module will be marked as
/// `ModuleKind::External` and no dependency analysis will be performed.
Expand Down Expand Up @@ -162,7 +159,6 @@ pub enum Source<S> {
content: S,
},
External(S),
BuiltIn(S),
Err(Error),
}

Expand Down Expand Up @@ -196,9 +192,6 @@ impl MemoryLoader {
}),
content: content.as_ref().into(),
}),
Source::BuiltIn(specifier) => Ok(LoadResponse::BuiltIn {
specifier: ModuleSpecifier::parse(specifier.as_ref()).unwrap(),
}),
Source::External(specifier) => Ok(LoadResponse::External {
specifier: ModuleSpecifier::parse(specifier.as_ref()).unwrap(),
}),
Expand Down
6 changes: 3 additions & 3 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ Deno.test({
});

Deno.test({
name: "createGraph() - load - external and builtin",
name: "createGraph() - load - external",
async fn() {
const fixtures: Record<string, LoadResponse> = {
"file:///a/test.js": {
Expand All @@ -408,7 +408,7 @@ Deno.test({
import * as bundle from "https://example.com/bundle";`,
},
"builtin:fs": {
kind: "builtIn",
kind: "external",
specifier: "builtin:fs",
},
"https://example.com/bundle": {
Expand All @@ -427,7 +427,7 @@ Deno.test({
],
"modules": [
{
"kind": "builtIn",
"kind": "external",
"specifier": "builtin:fs",
},
{
Expand Down

0 comments on commit 8c474ab

Please sign in to comment.