Skip to content

Commit

Permalink
Merge branch 'main' of github.com:oxc-project/oxc into don/07-10-feat…
Browse files Browse the repository at this point in the history
…_linter_add_fixer_for_jsx-a11y/aria-props
  • Loading branch information
DonIsaac committed Jul 11, 2024
2 parents cb896d9 + 07506ec commit efed477
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ jobs:
- run: cargo ck
- run: cargo test --no-run
- run: cargo test
- run: git diff --exit-code # Must commit everything

test-windows:
needs: optimize_ci
Expand Down
7 changes: 5 additions & 2 deletions crates/oxc_cfg/src/builder/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,12 @@ impl<'a, 'c> QueryCtx<'a, 'c> {

self.resolve_ctx(ctx);

// mark the upper label continue jump point the same as ours,
// mark the upper label continue jump point the same as ours if it isn't already assigned,
// NOTE: if it is already assigned there's a resolution before this context.
if let Some(jmp) = continue_jmp {
if let Some(label_ctx) = self.0.immediate_labeled_ctx() {
if let Some(label_ctx @ RefCtxCursor(Ctx { continue_jmp: None, .. })) =
self.0.immediate_labeled_ctx()
{
label_ctx.mark_continue(jmp);
}
}
Expand Down
38 changes: 38 additions & 0 deletions crates/oxc_cfg/tests/builder.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use oxc_cfg::{ControlFlowGraphBuilder, CtxCursor};
use oxc_syntax::node::AstNodeId;
/// same as but just the skeleton
/// ```js
/// A: {
/// do {} while (a);
/// do {} while (b);
/// break A;
/// }
/// ```
#[test]
fn labeled_statement_with_multiple_loops_continue_and_break() {
const A: Option<&str> = Some("A");

let mut cfg = ControlFlowGraphBuilder::default();
cfg.attach_error_harness(oxc_cfg::ErrorEdgeKind::Implicit);

// labeled block start
let labeled = cfg.new_basic_block_normal();
cfg.ctx(A).default().allow_break().allow_continue();

// loop context 1
let c1 = cfg.new_basic_block_normal();
cfg.ctx(None).default().allow_break().allow_continue();
cfg.ctx(None).mark_break(c1).mark_continue(c1).resolve_with_upper_label();

// loop context 2
let c2 = cfg.new_basic_block_normal();
cfg.ctx(None).default().allow_break().allow_continue();
cfg.ctx(None).mark_break(c2).mark_continue(c2).resolve_with_upper_label();

cfg.append_break(AstNodeId::dummy(), A);

// labeled block end
cfg.ctx(A).mark_break(labeled).resolve();

cfg.build();
}
11 changes: 6 additions & 5 deletions crates/oxc_diagnostics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod reporter;
mod service;

use std::{
borrow::Cow,
fmt::{self, Display},
ops::Deref,
};
Expand Down Expand Up @@ -42,9 +43,9 @@ impl Deref for OxcDiagnostic {

#[derive(Debug, Clone)]
pub struct OxcDiagnosticInner {
pub message: String,
pub message: Cow<'static, str>,
pub labels: Option<Vec<LabeledSpan>>,
pub help: Option<String>,
pub help: Option<Cow<'static, str>>,
pub severity: Severity,
}

Expand Down Expand Up @@ -76,7 +77,7 @@ impl Diagnostic for OxcDiagnostic {

impl OxcDiagnostic {
#[must_use]
pub fn error<T: Into<String>>(message: T) -> Self {
pub fn error<T: Into<Cow<'static, str>>>(message: T) -> Self {
Self {
inner: Box::new(OxcDiagnosticInner {
message: message.into(),
Expand All @@ -88,7 +89,7 @@ impl OxcDiagnostic {
}

#[must_use]
pub fn warn<T: Into<String>>(message: T) -> Self {
pub fn warn<T: Into<Cow<'static, str>>>(message: T) -> Self {
Self {
inner: Box::new(OxcDiagnosticInner {
message: message.into(),
Expand All @@ -106,7 +107,7 @@ impl OxcDiagnostic {
}

#[must_use]
pub fn with_help<T: Into<String>>(mut self, help: T) -> Self {
pub fn with_help<T: Into<Cow<'static, str>>>(mut self, help: T) -> Self {
self.inner.help = Some(help.into());
self
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/oxc/no_optional_chaining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn no_optional_chaining_diagnostic(span0: Span, x1: &str) -> OxcDiagnostic {
.with_label(span0)
} else {
OxcDiagnostic::warn("oxc(no-optional-chaining): Optional chaining is not allowed.")
.with_help(x1)
.with_help(x1.to_owned())
.with_label(span0)
}
}
Expand Down

0 comments on commit efed477

Please sign in to comment.