This repository has been archived by the owner on Aug 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Define Lintable, Parseable, and Validate traits
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
Showing
10 changed files
with
828 additions
and
197 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,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); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.