Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
Define Lintable, Parseable, and Validate traits
Browse files Browse the repository at this point in the history
I keep making tons of changes without committing but I think that it
seems bigger than it actually is -- mostly what I've done here is
define a few traits

Lintable: a struct is able to lint itself with a given argument to check against
Parseable: a struct is able to create Self from a given input
Validate: a struct satisfies both Lintable and Parseable

The JS boilerplate is mostly done -- since we actually want to lint expressions,
and not statements, the bulk of the code at the moment is just about
getting to the expressions in each statement. Essentially a glorifed
switch case with a little recursion mixed in.

The webassembly is all todo!(), i just wanted to get typechecking working.

Basically, this is just yet another commit before we actually parse any
AST. But I did write some documentation, which is cool.
  • Loading branch information
caass committed Oct 3, 2020
1 parent 2ba95fb commit 0ace2ac
Show file tree
Hide file tree
Showing 10 changed files with 828 additions and 197 deletions.
47 changes: 47 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ semver = "0.11.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.57"
serde_with = "1.4.0"
sourcemap = "6.0.1"
swc_atoms = "0.2.3"
swc_common = { version = "0.10.3", features = ["concurrent"] }
swc_ecma_ast = "0.32.0"
swc_ecma_parser = "0.38.0"
Expand All @@ -65,6 +67,8 @@ toml = "0.5.6"
twox-hash = "1.5.0"
url = "2.1.1"
uuid = { version = "0.8", features = ["v4"] }
wasmparser = "0.63.0"
wast = "24.0.0"
which = "4.0.2"
ws = "0.9.1"

Expand Down
109 changes: 109 additions & 0 deletions src/build/check/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
use bytesize::ByteSize;
use swc_common::DUMMY_SP;
use swc_ecma_ast::{Expr, ThisExpr};
use swc_ecma_parser::{EsConfig, Syntax};
use wasmparser::WasmFeatures;

/// The parseable syntax we allow, as dictated by V8 stable.
/// Check the [SWC docs](https://swc.rs/rustdoc/swc_ecma_parser/struct.EsConfig.html) for the available options.
#[doc(inline)]
pub const V8_SUPPORTED_JS_FEATURES: Syntax = Syntax::Es(EsConfig {
// sir, this is a wendy's...
jsx: false,
// https://v8.dev/blog/v8-release-75#numeric-separators
num_sep: true,
// https://v8.dev/features/class-fields#private-class-fields
// applies to both props and methods i think
class_private_props: true,
class_private_methods: true,
// https://v8.dev/features/class-fields#public-class-fields
class_props: true,
// https://chromium.googlesource.com/v8/v8/+/3.0.12.1/test/mjsunit/function-bind.js
fn_bind: true,
// AFAIK this is still...due to be presented? it is now october but
// applies to both decorators and decorators_before_export
// rfc: https://github.com/tc39/proposal-decorators
// V8 team's feedback: https://docs.google.com/document/d/1GMp938qlmJlGkBZp6AerL-ewL1MWUDU8QzHBiNvs3MM/edit
decorators: false,
decorators_before_export: false,
// https://v8.dev/features/modules
export_default_from: true,
// https://v8.dev/features/module-namespace-exports
export_namespace_from: true,
// https://v8.dev/features/dynamic-import
dynamic_import: true,
// https://v8.dev/features/nullish-coalescing
nullish_coalescing: true,
// https://v8.dev/features/optional-chaining
optional_chaining: true,
// https://v8.dev/features/modules#import-meta
import_meta: true,
// ok so for top-level await, V8 says there's no support in
// "classic scripts", which i think is how workers are executed.
// i mean, they're certainly not modules.
// https://v8.dev/features/top-level-await#new
top_level_await: false,
// i literally cannot find a source on this
// i don't...is it `console.assert?`
// TODO: ask in the slack about this one
import_assertions: false,
});

/// The features we allow during our validation of WebAssembly, as per V8 stable.
/// Check the [wasmparser](https://docs.rs/wasmparser/0.63.0/wasmparser/struct.WasmFeatures.html)
/// for more.
#[doc(inline)]
pub const V8_SUPPORTED_WASM_FEATURES: WasmFeatures = WasmFeatures {
// https://www.chromestatus.com/feature/5166497248837632
reference_types: false,
// there's a proposal for module linking here
// https://github.com/WebAssembly/module-linking
// but it's different than the "dynamic linking" one the v8 team has talked about here
// https://v8.dev/blog/webassembly-experimental
// so i'm not sure what the right answer for this is.
// either way, i wasn't able to find a chromestatus page for it.
// based on the name, though, i don't think it matters
// because Workers only supports one WASM file anyway
module_linking: false,
// https://www.chromestatus.com/feature/6533147810332672
simd: false,
// https://www.chromestatus.com/feature/5192420329259008
multi_value: false,
// https://www.chromestatus.com/feature/5724132452859904
threads: true,
// https://www.chromestatus.com/feature/5423405012615168
tail_call: false,
// https://www.chromestatus.com/feature/4590306448113664
bulk_memory: true,
// TODO: i don't know what this is
deterministic_only: false,
// RFC: https://github.com/WebAssembly/multi-memory
// TODO: I also can't find a chromestatus for this
multi_memory: false,
// as far as I can tell, this isn't even in the works yet
// https://v8.dev/blog/4gb-wasm-memory
// https://github.com/WebAssembly/memory64
memory64: false,
};

/// For security reasons, [some javascript standards are unavailable](https://developers.cloudflare.com/workers/runtime-apis/web-standards#javascript-standards) in the Workers runtime.
#[doc(inline)]
pub const UNAVAILABLE_BUILTINS: [Expr; 1] = [Expr::This(ThisExpr { span: DUMMY_SP })];
/// Asynchronous operations are only available in the [request context](https://developers.cloudflare.com/workers/runtime-apis/request#the-request-context)
#[doc(inline)]
pub const AVAILABLE_WITHIN_REQUEST_CONTEXT: [Expr; 1] = [Expr::This(ThisExpr { span: DUMMY_SP })];

// TODO: these need to be...expressions? ask in the slack abt the best way to do this
// pub const UNAVAILABLE_BUILTINS: [&str; 2] = ["eval", "new Function"];
// pub const AVAILABLE_WITHIN_REQUEST_CONTEXT: [&str; 5] = [
// "setInterval",
// "clearInterval",
// "setTimeout",
// "clearTimeout",
// "fetch",
// ];

// TODO: is this...like does this mean JS + Sourcemap + WASM + WAST < 1mb, or each individual file?
/// The [maximum bundle size](https://developers.cloudflare.com/workers/platform/limits#script-size) we allow.
#[doc(inline)]
pub const MAX_FILE_SIZE: ByteSize = ByteSize(1_000_000);
123 changes: 0 additions & 123 deletions src/build/check/js.rs

This file was deleted.

Loading

0 comments on commit 0ace2ac

Please sign in to comment.