Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: check assertions per import statement #228

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
23bde67
refactor: check assertions per import statement
nayeemrmn Feb 12, 2023
0af4881
fmt
nayeemrmn Feb 12, 2023
af1009e
review
nayeemrmn Feb 12, 2023
e964794
Merge remote-tracking branch 'upstream/main' into import-errors
nayeemrmn Feb 12, 2023
d9d9c70
add comment for is_known_none()
nayeemrmn Feb 12, 2023
e8e71af
move dynamic import skip to validate()
nayeemrmn Feb 13, 2023
33cd066
use follow_dynamic
nayeemrmn Feb 13, 2023
8b55dff
better serialization for import assertions
nayeemrmn Feb 13, 2023
bae5aa5
populate module_metadata in fill()
nayeemrmn Feb 13, 2023
734fba4
remove unnecessary types / trait impls
nayeemrmn Feb 13, 2023
a3042b9
change ModuleGraphError::UnsupportedMediaType to unnamed tuple fields
nayeemrmn Feb 13, 2023
c625c53
collapse ModuleGraphError::ModuleError()
nayeemrmn Feb 13, 2023
7901e8c
Merge remote-tracking branch 'upstream/main' into import-errors
nayeemrmn Feb 14, 2023
fc487c5
remove ModuleKind::Asserted
nayeemrmn Feb 14, 2023
908cd6d
add ImportKind
nayeemrmn Feb 14, 2023
6750bb0
skip serializing ImportKind::Es
nayeemrmn Feb 14, 2023
604376c
fix: use same behaviour if has resolver or not
dsherret Feb 14, 2023
be06539
Move invalid local import checks to validate
dsherret Feb 15, 2023
0e8b76a
Test.
dsherret Feb 15, 2023
1ad47ec
Wasm
dsherret Feb 15, 2023
4db3546
Merge my work on main
dsherret Feb 15, 2023
637de8e
Merge branch 'main' into import-errors
dsherret Feb 15, 2023
b3a1998
Update wasm
dsherret Feb 15, 2023
ccb15a9
Merge remote-tracking branch 'upstream/main' into import-errors
nayeemrmn Feb 16, 2023
e386130
only enforce assertions on es runtime imports
nayeemrmn Feb 16, 2023
bfb545e
Merge remote-tracking branch 'upstream/main' into import-errors
nayeemrmn Feb 22, 2023
edbf9a3
Merge remote-tracking branch 'upstream/main' into import-errors
nayeemrmn Mar 1, 2023
6e68504
Merge remote-tracking branch 'upstream/main' into import-errors
nayeemrmn Mar 5, 2023
0171ce5
Merge remote-tracking branch 'upstream/main' into import-errors
nayeemrmn Mar 6, 2023
47ff14d
Merge remote-tracking branch 'upstream/main' into import-errors
nayeemrmn Mar 6, 2023
792196e
Merge remote-tracking branch 'upstream/main' into import-errors
nayeemrmn Apr 4, 2023
205b21e
don't serialize assertions, maybe unstable
nayeemrmn Apr 4, 2023
4b65693
restore Dependency::assertionType for legacy
nayeemrmn Apr 4, 2023
03f670c
fixup! restore Dependency::assertionType for legacy
nayeemrmn Apr 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/deno_graph_wasm.generated.js
Expand Up @@ -226,7 +226,7 @@ function makeMutClosure(arg0, arg1, dtor, f) {
}
function __wbg_adapter_48(arg0, arg1, arg2) {
wasm
._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hf0940dd4fdf51f25(
._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hec49a88a8b459e09(
arg0,
arg1,
addHeapObject(arg2),
Expand Down Expand Up @@ -383,7 +383,7 @@ function handleError(f, args) {
}
}
function __wbg_adapter_95(arg0, arg1, arg2, arg3) {
wasm.wasm_bindgen__convert__closures__invoke2_mut__h9adfd02b55150fae(
wasm.wasm_bindgen__convert__closures__invoke2_mut__h5fc0ee5e5d0575ff(
arg0,
arg1,
addHeapObject(arg2),
Expand All @@ -393,6 +393,9 @@ function __wbg_adapter_95(arg0, arg1, arg2, arg3) {

const imports = {
__wbindgen_placeholder__: {
__wbindgen_object_drop_ref: function (arg0) {
takeObject(arg0);
},
__wbindgen_cb_drop: function (arg0) {
const obj = takeObject(arg0).original;
if (obj.cnt-- == 1) {
Expand Down Expand Up @@ -428,9 +431,6 @@ const imports = {
state0.a = state0.b = 0;
}
},
__wbindgen_object_drop_ref: function (arg0) {
takeObject(arg0);
},
__wbg_length_6e3bbe7c8bd4dbd8: function (arg0) {
const ret = getObject(arg0).length;
return ret;
Expand Down
Binary file modified lib/deno_graph_wasm_bg.wasm
Binary file not shown.
16 changes: 15 additions & 1 deletion lib/types.d.ts
Expand Up @@ -105,6 +105,20 @@ export type ModuleKind =
| "external"
| "script";

export type ImportAssertion = "Unknown" | { "Known": string };

export type ImportAssertions = "Unknown" | {
"Known": Record<string, ImportAssertion>;
};

export interface ImportJson {
specifier: string;
range: RangeJson;
isDynamic?: true;
assertions?: ImportAssertions;
errors?: string[];
}

export interface DependencyJson {
/** The string specifier that was used for the dependency. */
specifier: string;
Expand All @@ -117,7 +131,7 @@ export interface DependencyJson {
/** A flag indicating if the dependency was dynamic. (e.g.
* `await import("mod.ts")`) */
isDynamic?: true;
assertionType?: string;
imports?: ImportJson[];
}

export interface ModuleJson extends CacheInfo {
Expand Down
21 changes: 21 additions & 0 deletions src/analyzer.rs
Expand Up @@ -182,6 +182,27 @@ impl ImportAssertions {
_ => None,
}
}

/// Check if a assertion key is known to be absent (not set to a value and not
/// undeterminable). This is significant because it is the precise case where
/// `type: "javascript"` is asserted.
pub fn is_known_none(&self, key: &str) -> bool {
nayeemrmn marked this conversation as resolved.
Show resolved Hide resolved
match self {
ImportAssertions::None => true,
ImportAssertions::Known(map) => !map.contains_key(key),
ImportAssertions::Unknown => false,
}
}

pub fn is_empty(&self) -> bool {
matches!(self, ImportAssertions::None)
}
}

impl Default for ImportAssertions {
fn default() -> Self {
Self::None
}
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
Expand Down