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

Ast typegen #114

Merged
merged 34 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
0ec5bdf
Get declarations to show up in built output (NB: required an upgrade …
H-Plus-Time Feb 4, 2024
c0938d3
Swap to wasm-pack for build (includes wasm-opt pass, identical output…
H-Plus-Time Feb 5, 2024
e7da497
Common deps-only changes (NB: source-map dep will need to be bumped o…
H-Plus-Time Feb 5, 2024
bc4aabd
Correct wasm-pack usage (apparently crate-relative outdir)
H-Plus-Time Feb 5, 2024
f5de30a
Partial wasm_bindings, build typings
H-Plus-Time Feb 5, 2024
bb0c2f1
Merge branch 'ast-typegen' into ast-typegen-direct
H-Plus-Time Feb 5, 2024
c11c9b6
Checker types
H-Plus-Time Feb 5, 2024
b5c12fd
Fundamental module, statement, expression, block types
H-Plus-Time Feb 5, 2024
0bd2b8a
Control flow types
H-Plus-Time Feb 5, 2024
218106a
Operators, basic parameters, assignment, uncomplicated literals
H-Plus-Time Feb 5, 2024
fb5b4d4
type annotations, declarations + variablefields, arraydestructuringfi…
H-Plus-Time Feb 5, 2024
e35efcb
Function-ish types - NB: associated types are generally incompatible …
H-Plus-Time Feb 5, 2024
4ca9db0
misc terminal / associated type free typedefs
H-Plus-Time Feb 5, 2024
c506eb2
Majority of declarations, StatementFunction, missed try catch excepti…
H-Plus-Time Feb 5, 2024
66e4bc0
Account for self-referential enums/structs, format
H-Plus-Time Feb 5, 2024
331d2ea
Annotate all jsx types
H-Plus-Time Feb 5, 2024
f00c0b4
Address PropertyKey, terminal variable fields
H-Plus-Time Feb 5, 2024
9512f12
Add standard tsify decorations to comments, classdeclarations, overri…
H-Plus-Time Feb 6, 2024
0c9dedb
Tweak - skip redundant cargo build in dev build
H-Plus-Time Feb 6, 2024
0ea3d4a
Co-locate all type overrides in wasm_bindgen with their corresponding…
H-Plus-Time Feb 6, 2024
4a83722
/Correct/ type overrides in wasm_bindings :|
H-Plus-Time Feb 6, 2024
9751f85
Missed the Comments struct :|
H-Plus-Time Feb 6, 2024
26b3d52
Typecheck the generated typedefs (with the... other checker)
H-Plus-Time Feb 6, 2024
076000d
Addition of macro rules attribute dependency, direct (non-bundled mac…
H-Plus-Time Feb 5, 2024
08eec87
Add findings re macro compatibility, apply to all operator structs/enums
H-Plus-Time Feb 6, 2024
a54a158
Mass-replace all instances of (serialize, self-rust-tokenize,tsify) d…
H-Plus-Time Feb 6, 2024
034c0f2
Fix .d.ts file path reference in CI
H-Plus-Time Feb 7, 2024
deb700f
Correct clippy errors
H-Plus-Time Feb 7, 2024
75eeb84
update source-map (with new type definition), add debug TEMP fix and …
kaleidawave Feb 10, 2024
3e78e0e
Use derive 'bundling' macro more & hopefully some fixes
kaleidawave Feb 11, 2024
15bfa43
Add back in 'missing types'
kaleidawave Feb 12, 2024
cb6a4d2
?
kaleidawave Feb 12, 2024
245e18b
Try out apparently magic combination that produces correct types in d…
H-Plus-Time Feb 13, 2024
016c09b
Remove the "fixes" for parser types from the debug build
kaleidawave Feb 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ jobs:
- uses: brndnmtthws/rust-action-cargo-binstall@v1
if: ${{ inputs.ezno-version != 'none' }}
with:
packages: wasm-bindgen-cli@0.2.89
packages: wasm-pack@0.12.1

- name: Set NPM package version & build
id: set-npm-version
Expand Down
14 changes: 12 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ jobs:
- uses: brndnmtthws/rust-action-cargo-binstall@v1
if: steps.changes.outputs.src == 'true'
with:
packages: wasm-bindgen-cli@0.2.89
packages: wasm-pack@0.12.1
- uses: denoland/setup-deno@v1
if: steps.changes.outputs.src == 'true'
with:
Expand All @@ -158,9 +158,19 @@ jobs:
rustup target add wasm32-unknown-unknown
npm ci
npm run build
npm run test
npm run run-tests

node ./dist/cli.cjs info
deno run -A ./dist/cli.mjs info

npx -p typescript tsc --strict --pretty ./build/ezno_lib.d.ts

# TODO temp as the types generated can be a bit unpredicatible
echo "::debug::On branch '${{ github.ref_name }}'"
if ${{ contains(fromJSON('["main", "ast-typegen-direct"]'), github.ref_name ) }}; then
npm run build-release
npx -p typescript tsc --strict --pretty ./build/ezno_lib.d.ts
fi
working-directory: src/js-cli-and-library
shell: bash

Expand Down
93 changes: 91 additions & 2 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ wasm-bindgen-derive = "0.2.1"
serde-wasm-bindgen = "0.6.3"
console_error_panic_hook = "0.1.7"
js-sys = "0.3"
tsify = "0.4.5"


[target.'cfg(not(target_family = "wasm"))'.dependencies]
multiline-term-input = "0.1.0"
notify = "6.1.0"

7 changes: 6 additions & 1 deletion checker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ezno-parser = ["dep:parser"]
serde-serialize = ["dep:serde"]

[dependencies]
source-map = { version = "0.14.9", features = [
source-map = { version = "0.14.10", features = [
"serde-serialize",
"self-rust-tokenize",
] }
Expand All @@ -47,6 +47,11 @@ map_vec = "0.3.0"

serde = { version = "1.0", features = ["derive"], optional = true }

[target.'cfg(target_family = "wasm")'.dependencies]
tsify = "0.4.5"
wasm-bindgen = "=0.2.89"


[dependencies.parser]
path = "../parser"
optional = true
Expand Down
3 changes: 3 additions & 0 deletions checker/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use std::{

#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "serde-serialize", derive(serde::Serialize), serde(rename_all = "lowercase"))]
#[cfg_attr(target_family = "wasm", derive(tsify::Tsify))]
pub enum DiagnosticKind {
Error,
Warning,
Expand All @@ -28,6 +29,7 @@ pub enum DiagnosticKind {
/// Contains information
#[derive(Debug)]
#[cfg_attr(feature = "serde-serialize", derive(serde::Serialize), serde(untagged))]
#[cfg_attr(target_family = "wasm", derive(tsify::Tsify))]
pub enum Diagnostic {
/// Does not have positional information
Global {
Expand Down Expand Up @@ -103,6 +105,7 @@ impl Diagnostic {
/// TODO this is one variant, others should pipe strait to stdout or put it on a channel etc
#[derive(Default)]
#[cfg_attr(feature = "serde-serialize", derive(serde::Serialize), serde(transparent))]
#[cfg_attr(target_family = "wasm", derive(tsify::Tsify))]
pub struct DiagnosticsContainer {
diagnostics: Vec<Diagnostic>,
// Quick way to check whether a error was added
Expand Down
1 change: 1 addition & 0 deletions checker/src/options.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// Options for type checking
/// TODO figure out compat with tsc
#[cfg_attr(feature = "serde-serialize", derive(serde::Deserialize), serde(default))]
#[cfg_attr(target_family = "wasm", derive(tsify::Tsify))]
#[allow(clippy::struct_excessive_bools)]
pub struct TypeCheckOptions {
/// Parameters cannot be reassigned
Expand Down
24 changes: 20 additions & 4 deletions checker/src/synthesis/classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ pub(super) fn synthesise_class_declaration<
match &member.on {
ClassMember::Method(false, method) => {
let publicity = match method.name.get_ast_ref() {
ParserPropertyKey::Ident(_, _, true) => Publicity::Private,
ParserPropertyKey::Ident(
_,
_,
parser::property_key::PublicOrPrivate::Private,
) => Publicity::Private,
_ => Publicity::Public,
};
let property_key = parser_property_key_to_checker_property_key(
Expand Down Expand Up @@ -109,7 +113,11 @@ pub(super) fn synthesise_class_declaration<
}
ClassMember::Property(false, property) => {
let publicity = match property.key.get_ast_ref() {
ParserPropertyKey::Ident(_, _, true) => Publicity::Private,
ParserPropertyKey::Ident(
_,
_,
parser::property_key::PublicOrPrivate::Private,
) => Publicity::Private,
_ => Publicity::Public,
};
let key = parser_property_key_to_checker_property_key(
Expand Down Expand Up @@ -160,7 +168,11 @@ pub(super) fn synthesise_class_declaration<
match &member.on {
ClassMember::Method(true, method) => {
let publicity_kind = match method.name.get_ast_ref() {
ParserPropertyKey::Ident(_, _, true) => Publicity::Private,
ParserPropertyKey::Ident(
_,
_,
parser::property_key::PublicOrPrivate::Private,
) => Publicity::Private,
_ => Publicity::Public,
};
let behavior = FunctionRegisterBehavior::ClassMethod {
Expand Down Expand Up @@ -193,7 +205,11 @@ pub(super) fn synthesise_class_declaration<
}
ClassMember::Property(true, property) => {
let publicity_kind = match property.key.get_ast_ref() {
ParserPropertyKey::Ident(_, _, true) => Publicity::Private,
ParserPropertyKey::Ident(
_,
_,
parser::property_key::PublicOrPrivate::Private,
) => Publicity::Private,
_ => Publicity::Public,
};
let value = if let Some(ref value) = property.value {
Expand Down
2 changes: 1 addition & 1 deletion checker/src/synthesis/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ fn param_name_to_string(param: &VariableField<parser::VariableFieldInSourceCode>
}
parser::ObjectDestructuringField::Map { from, name, .. } => {
match from {
parser::PropertyKey::Ident(ident, _, ()) => {
parser::PropertyKey::Ident(ident, _, _) => {
buf.push_str(ident);
}
parser::PropertyKey::StringLiteral(_, _, _) => todo!(),
Expand Down
9 changes: 8 additions & 1 deletion checker/src/synthesis/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,14 @@ impl SynthesiseInterfaceBehavior for OnToType {
) {
let (publicity, under) = match key {
ParserPropertyKeyType::ClassProperty(key) => (
if matches!(key, parser::PropertyKey::Ident(_, _, true)) {
if matches!(
key,
parser::PropertyKey::Ident(
_,
_,
parser::property_key::PublicOrPrivate::Private
)
) {
Publicity::Private
} else {
Publicity::Public
Expand Down
6 changes: 5 additions & 1 deletion parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ enum-variants-strings = "0.2"

get-field-by-type = "0.0.3"

macro_rules_attribute = { version = "0.2.0" }

serde = { version = "1.0", features = ["derive"], optional = true }
self-rust-tokenize = { version = "0.3.3", optional = true }

source-map = { version = "0.14.9", features = [
source-map = { version = "0.14.10", features = [
"serde-serialize",
"self-rust-tokenize",
] }
Expand All @@ -59,6 +61,8 @@ tokenizer-lib = { version = "1.5.1", features = [
"buffered",
"sized-tokens",
], default_features = false }
tsify = "0.4.5"
wasm-bindgen = "=0.2.89"

[target.'cfg(not(target_family = "wasm"))'.dependencies]
tokenizer-lib = { version = "1.5.1", features = [
Expand Down
Loading
Loading