Skip to content

Commit

Permalink
Merge branch 'master' into josh_patch_1
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomieju committed Oct 19, 2020
2 parents 2502e59 + 08441b8 commit 17aad6a
Show file tree
Hide file tree
Showing 25 changed files with 414 additions and 144 deletions.
54 changes: 0 additions & 54 deletions .github/workflows/ci.yml
Expand Up @@ -94,60 +94,6 @@ jobs:
rustc --version
cargo --version
- name: Configure cargo data directory
# After this point, all cargo registry and crate data is stored in
# $GITHUB_WORKSPACE/.cargo_home. This allows us to cache only the files
# that are needed during the build process. Additionally, this works
# around a bug in the 'cache' action that causes directories outside of
# the workspace dir to be saved/restored incorrectly.
run: echo "::set-env name=CARGO_HOME::$(pwd)/.cargo_home"

- name: Cache
uses: actions/cache@v2
with:
# Note: crates from the denoland/deno git repo always get rebuilt,
# and their outputs ('deno', 'libdeno.rlib' etc.) are quite big,
# so we cache only those subdirectories of target/{debug|release} that
# contain the build output for crates that come from the registry.
path: |-
.cargo_home
target/*/.*
target/*/build
target/*/deps
target/*/gn_out
key: deno-${{ matrix.os }}-${{ matrix.kind }}-${{ hashFiles('Cargo.lock') }}
restore-keys: |
deno-${{ matrix.os }}-${{ matrix.kind }}-
# It seems that the 'target' directory does not always get restored
# from cache correctly on MacOS. In the build log we see the following:
#
# Fresh serde_derive v1.0.115
#
# But a little while after that Cargo aborts because 'serde_derive' is
# now nowhere to be found. We're not the only ones experiencing this,
# see https://github.com/actions-rs/cargo/issues/111.
#
# error[E0463]: can't find crate for `serde_derive`
# ##[error] --> /Users/runner/.cargo/registry/src/github.com-
# | 1ecc6299db9ec823/serde-1.0.115/src/lib.rs:285:1
# |
# 285 | extern crate serde_derive;
# | ^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
- name: Work around MacOS + Cargo + Github Actions cache bug
if: runner.os == 'macOS'
run: |
cargo clean --locked --release \
-p ast_node \
-p is-macro \
-p serde_derive \
-p swc_ecma_codegen \
-p swc_ecma_codegen_macros \
-p swc_ecma_parser \
-p swc_ecma_parser_macros \
-p swc_visit \
-p swc_visit_macros
- name: lint.py
if: matrix.kind == 'lint'
run: python ./tools/lint.py
Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions cli/Cargo.toml
Expand Up @@ -20,7 +20,7 @@ harness = false
path = "./bench/main.rs"

[build-dependencies]
deno_core = { path = "../core", version = "0.63.0" }
deno_core = { path = "../core", version = "0.64.0" }
deno_web = { path = "../op_crates/web", version = "0.15.0" }
deno_fetch = { path = "../op_crates/fetch", version = "0.7.0" }

Expand All @@ -29,7 +29,7 @@ winres = "0.1.11"
winapi = "0.3.9"

[dependencies]
deno_core = { path = "../core", version = "0.63.0" }
deno_core = { path = "../core", version = "0.64.0" }
deno_doc = "0.1.12"
deno_lint = "0.2.4"
deno_web = { path = "../op_crates/web", version = "0.15.0" }
Expand Down
4 changes: 2 additions & 2 deletions cli/dts/lib.deno.ns.d.ts
Expand Up @@ -1226,7 +1226,7 @@ declare namespace Deno {
export function rename(oldpath: string, newpath: string): Promise<void>;

/** Synchronously reads and returns the entire contents of a file as utf8
* encoded string. Reading a directory returns an empty string.
* encoded string. Reading a directory throws an error.
*
* ```ts
* const data = Deno.readTextFileSync("hello.txt");
Expand All @@ -1237,7 +1237,7 @@ declare namespace Deno {
export function readTextFileSync(path: string | URL): string;

/** Asynchronously reads and returns the entire contents of a file as utf8
* encoded string. Reading a directory returns an empty string.
* encoded string. Reading a directory throws an error.
*
* ```ts
* const data = await Deno.readTextFile("hello.txt");
Expand Down
25 changes: 19 additions & 6 deletions cli/lint.rs
Expand Up @@ -222,6 +222,7 @@ impl LintReporter for PrettyLintReporter {
&pretty_message,
&source_lines,
d.range.clone(),
d.hint.as_ref(),
&fmt_errors::format_location(&JsStackFrame::from_location(
Some(d.filename.clone()),
Some(d.range.start.line as i64),
Expand Down Expand Up @@ -256,6 +257,7 @@ pub fn format_diagnostic(
message_line: &str,
source_lines: &[&str],
range: deno_lint::diagnostic::Range,
maybe_hint: Option<&String>,
formatted_location: &str,
) -> String {
let mut lines = vec![];
Expand Down Expand Up @@ -284,12 +286,23 @@ pub fn format_diagnostic(
}
}

format!(
"{}\n{}\n at {}",
message_line,
lines.join("\n"),
formatted_location
)
if let Some(hint) = maybe_hint {
format!(
"{}\n{}\n at {}\n\n {} {}",
message_line,
lines.join("\n"),
formatted_location,
colors::gray("hint:"),
hint,
)
} else {
format!(
"{}\n{}\n at {}",
message_line,
lines.join("\n"),
formatted_location
)
}
}

#[derive(Serialize)]
Expand Down
108 changes: 71 additions & 37 deletions cli/repl.rs
Expand Up @@ -12,7 +12,6 @@ use regex::Captures;
use regex::Regex;
use rustyline::error::ReadlineError;
use rustyline::highlight::Highlighter;
use rustyline::validate::MatchingBracketValidator;
use rustyline::validate::ValidationContext;
use rustyline::validate::ValidationResult;
use rustyline::validate::Validator;
Expand All @@ -26,15 +25,49 @@ use std::sync::Mutex;
#[derive(Completer, Helper, Hinter)]
struct Helper {
highlighter: LineHighlighter,
validator: MatchingBracketValidator,
}

impl Validator for Helper {
fn validate(
&self,
ctx: &mut ValidationContext,
) -> Result<ValidationResult, ReadlineError> {
self.validator.validate(ctx)
let mut stack: Vec<char> = Vec::new();
for c in ctx.input().chars() {
match c {
'(' | '[' | '{' => stack.push(c),
')' | ']' | '}' => match (stack.pop(), c) {
(Some('('), ')') | (Some('['), ']') | (Some('{'), '}') => {}
(Some(left), _) => {
return Ok(ValidationResult::Invalid(Some(format!(
"Mismatched pairs: {:?} is not properly closed",
left
))))
}
(None, c) => {
return Ok(ValidationResult::Invalid(Some(format!(
"Mismatched pairs: {:?} is unpaired",
c
))))
}
},
'`' => {
if stack.is_empty() || stack.last().unwrap() != &c {
stack.push(c);
} else {
stack.pop();
}
}

_ => {}
}
}

if !stack.is_empty() {
return Ok(ValidationResult::Incomplete);
}

Ok(ValidationResult::Valid(None))
}
}

Expand Down Expand Up @@ -217,6 +250,31 @@ async fn inject_prelude(
Ok(())
}

pub async fn is_closing(
worker: &mut MainWorker,
session: &mut InspectorSession,
context_id: u64,
) -> Result<bool, AnyError> {
let closed = post_message_and_poll(
worker,
session,
"Runtime.evaluate",
Some(json!({
"expression": "(globalThis.closed)",
"contextId": context_id,
})),
)
.await?
.get("result")
.unwrap()
.get("value")
.unwrap()
.as_bool()
.unwrap();

Ok(closed)
}

pub async fn run(
program_state: &ProgramState,
mut worker: MainWorker,
Expand Down Expand Up @@ -249,7 +307,6 @@ pub async fn run(

let helper = Helper {
highlighter: LineHighlighter::new(),
validator: MatchingBracketValidator::new(),
};

let editor = Arc::new(Mutex::new(Editor::new()));
Expand All @@ -267,7 +324,7 @@ pub async fn run(

inject_prelude(&mut worker, &mut session, context_id).await?;

loop {
while !is_closing(&mut worker, &mut session, context_id).await? {
let line = read_line_and_poll(&mut *worker, editor.clone()).await;
match line {
Ok(line) => {
Expand Down Expand Up @@ -315,27 +372,6 @@ pub async fn run(
evaluate_response
};

let is_closing = post_message_and_poll(
&mut *worker,
&mut session,
"Runtime.evaluate",
Some(json!({
"expression": "(globalThis.closed)",
"contextId": context_id,
})),
)
.await?
.get("result")
.unwrap()
.get("value")
.unwrap()
.as_bool()
.unwrap();

if is_closing {
break;
}

let evaluate_result = evaluate_response.get("result").unwrap();
let evaluate_exception_details =
evaluate_response.get("exceptionDetails");
Expand Down Expand Up @@ -387,21 +423,19 @@ pub async fn run(

let inspect_result = inspect_response.get("result").unwrap();

match evaluate_exception_details {
Some(_) => eprintln!(
"Uncaught {}",
inspect_result.get("value").unwrap().as_str().unwrap()
),
None => println!(
"{}",
inspect_result.get("value").unwrap().as_str().unwrap()
),
}
let value = inspect_result.get("value").unwrap().as_str().unwrap();
let output = match evaluate_exception_details {
Some(_) => format!("Uncaught {}", value),
None => value.to_string(),
};

println!("{}", output);

editor.lock().unwrap().add_history_entry(line.as_str());
}
Err(ReadlineError::Interrupted) => {
break;
println!("exit using ctrl+d or close()");
continue;
}
Err(ReadlineError::Eof) => {
break;
Expand Down

0 comments on commit 17aad6a

Please sign in to comment.