Skip to content

Commit

Permalink
Updates to the parser and CLI (#142)
Browse files Browse the repository at this point in the history
- Fixed array destruction syntax (and added support to checker)
- Update CLI things
- Added retaining blank lines for formatting
- Use BufferedStandardStream
- Updated release compiler options
- Added missing `run` checker example
- Optional class properties
- Removed Eq from parser items
- More additional syntax for destructuring with type annotations
- Change variable declaration overflow line splitting
- Add conditional ternary overflow line splitting
- Fixed precedence of condition types (fixes issue raised in type checking)
- Try add trailing new lines as empty
- Ignore whitespace during fuzzing trip
  • Loading branch information
kaleidawave authored May 20, 2024
1 parent c1ecf40 commit bfd2133
Show file tree
Hide file tree
Showing 64 changed files with 1,291 additions and 701 deletions.
25 changes: 11 additions & 14 deletions .github/workflows/performance-and-size.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,31 +53,26 @@ jobs:
cargo run -p ezno-parser --example code_blocks_to_script ./checker/specification/specification.md ./demo.ts
echo "::info::Finished file generation"
LINES_OF_CODE=$(scc -c --no-cocomo -f json demo.ts | jq ".[0].Code")
echo "<details>
<summary>Input</summary>
\`\`\`ts
" >> $GITHUB_STEP_SUMMARY
echo "// $(scc -c --no-cocomo -f json demo.ts | jq ".[0].Code") lines of TypeScript" >> $GITHUB_STEP_SUMMARY
cat ./demo.ts >> $GITHUB_STEP_SUMMARY
echo "\`\`\`
// $LINES_OF_CODE lines of TypeScript generated from specification.md
$(cat ./demo.ts)
\`\`\`
</details>
" >> $GITHUB_STEP_SUMMARY
echo "::info::Wrote code to summary"
echo "<details>
<summary>Diagnostics</summary>
\`\`\`" >> $GITHUB_STEP_SUMMARY
# Printing diagnostics, so turn colors off for GH Summary (also affects printing perf I think)
NO_COLOR=1
(./target/release/ezno check demo.ts --timings &>> $GITHUB_STEP_SUMMARY) || true
echo "\`\`\`
\`\`\`
$(./target/release/ezno check demo.ts --timings || true)
\`\`\`
</details>
" >> $GITHUB_STEP_SUMMARY
Expand All @@ -102,6 +97,8 @@ jobs:
"https://esm.sh/v135/[email protected]/es2022/typescript.mjs"
)
// TODO hyperfine
for url in "${strings[@]}"; do
curl -sS $url > input.js
echo "--- debug: $url ---"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ jobs:
if: steps.changes.outputs.src == 'true' || github.ref_name == 'main'
with:
deno-version: v1.x
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
if: steps.changes.outputs.src == 'true' || github.ref_name == 'main'
with:
node-version: 18
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ target
/private
.vscode
.env
/checker/examples
**/examples/private-*.rs
build
node_modules
/TODO.txt
Expand Down
6 changes: 2 additions & 4 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 @@ -70,6 +70,10 @@ tsify = "0.4.5"
multiline-term-input = "0.1.0"
notify = "6.1.0"

# TODO temporary testing, doesn't change API (or break anything)
[patch.crates-io]
source-map = { git = 'https://github.com/kaleidawave/source-map.git', branch = 'codespan-use-str' }
codespan-reporting = { git = 'https://github.com/kaleidawave/codespan.git', branch = 'static-dispatch-writecolor' }

[workspace.lints.clippy]
all = "deny"
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ A JavaScript compiler and TypeScript checker written in Rust with a focus on sta

What Ezno is
- A type checker for JavaScript usable through a CLI ([with a LSP also in the works](https://github.com/kaleidawave/ezno/issues/22))
- [A high level library](https://docs.rs/ezno-checker/latest/ezno_checker/) that allows [type checking to be added to other tools!](https://github.com/web-infra-dev/oxc/tree/main/crates/oxc_type_synthesis)
- Checks programs with guaranteed type safety (no runtime [`TypeError`s](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)) (**as long as definitions are sound**)
- Types aimed at soundness and tracing for better static analysis
- A *imperative* type system that tracks and evaluates the side effects of functions and control flow structures. It is similar to an interpreter, but acts with types instead of *values* and does not run IO side effects etc
Expand Down
99 changes: 99 additions & 0 deletions checker/examples/run.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#[cfg(feature = "ezno-parser")]
fn main() {
use ezno_checker::{check_project, synthesis, Diagnostic, TypeCheckOptions};
use std::{collections::HashSet, fs, path::Path, time::Instant};

let default_path = Path::new("private").join("tocheck").join("aaa.tsx");
let simple_dts_path = Path::new("checker").join("definitions").join("simple.d.ts");
let overrides_dts_path = Path::new("checker").join("definitions").join("overrides.d.ts");

let args: Vec<_> = std::env::args().skip(1).collect();

let path = args
.first()
.and_then(|arg| (!arg.starts_with("--")).then_some(arg))
.map(Path::new)
.unwrap_or(default_path.as_path());

let use_simple = args.iter().any(|item| item == "--simple-dts");
let no_cache = args.iter().any(|item| item == "--no-cache");

let now = Instant::now();

let resolver = |path: &std::path::Path| fs::read(path).ok();

let definition_file = if use_simple {
simple_dts_path.to_path_buf()
} else if no_cache {
overrides_dts_path.to_path_buf()
} else {
ezno_checker::INTERNAL_DEFINITION_FILE_PATH.into()
};
let type_definition_files = HashSet::from_iter([definition_file]);

let debug_types = false;
let options = TypeCheckOptions { debug_types, ..Default::default() };

let result = check_project::<_, synthesis::EznoParser>(
vec![path.to_path_buf()],
type_definition_files,
resolver,
options,
(),
None,
);

if args.iter().any(|arg| arg == "--types") {
eprintln!("Types:");
for (type_id, item) in result.types.into_vec_temp() {
eprintln!("\t{type_id:?}: {item:?}");
}
}

if args.iter().any(|arg| arg == "--events") {
eprintln!("Events on entry:");
let (_, entry_module) = result.modules.into_iter().next().unwrap();
for item in entry_module.info.get_events() {
eprintln!("\t{item:?}");
}
}

if args.iter().any(|arg| arg == "--time") {
let end = now.elapsed();
let count = result.diagnostics.into_iter().len();
eprintln!("Found {count} diagnostics in {end:?}");
} else if args.iter().any(|arg| arg == "--debug-diagnostics") {
eprintln!("Diagnostics:");
for diagnostic in result.diagnostics {
eprintln!("{diagnostic:?}");
}
} else {
eprintln!("Diagnostics:");
for diagnostic in result.diagnostics {
let prefix: &str = match diagnostic.kind() {
ezno_checker::DiagnosticKind::Error => "ERROR",
ezno_checker::DiagnosticKind::Warning => "WARNING",
ezno_checker::DiagnosticKind::Info => "INFO",
};
match diagnostic {
Diagnostic::Global { reason, kind: _ } => {
eprintln!("\t{prefix}: {reason}");
}
Diagnostic::Position { reason, position, kind: _ } => {
eprintln!("\t{prefix} (@{position:?}): {reason} ");
}
Diagnostic::PositionWithAdditionalLabels { reason, position, labels, kind: _ } => {
eprintln!("\t{prefix} (@{position:?}): {reason}");
for (reason, position) in labels {
eprintln!("\t\t{reason} {position:?}");
}
}
}
}
}
}

#[cfg(not(feature = "ezno-parser"))]
fn main() {
println!("Requires 'ezno-parser'")
}
Loading

0 comments on commit bfd2133

Please sign in to comment.