Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into optional-chaining
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing committed Nov 17, 2024
2 parents 50f4520 + 7d75130 commit 0861fbf
Show file tree
Hide file tree
Showing 172 changed files with 3,299 additions and 1,297 deletions.
2 changes: 1 addition & 1 deletion crates/oxc/src/napi/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use napi_derive::napi;

/// Babel Parser Options
///
/// <https://github.com/babel/babel/blob/main/packages/babel-parser/typings/babel-parser.d.ts>
/// <https://github.com/babel/babel/blob/v7.26.2/packages/babel-parser/typings/babel-parser.d.ts>
#[napi(object)]
#[derive(Default)]
pub struct ParserOptions {
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc/src/napi/transform.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// NOTE: Types must be aligned with [@types/babel__core](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/babel__core/index.d.ts).
// NOTE: Types must be aligned with [@types/babel__core](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/b5dc32740d9b45d11cff9b025896dd333c795b39/types/babel__core/index.d.ts).

#![allow(rustdoc::bare_urls)]

Expand Down Expand Up @@ -241,7 +241,7 @@ pub struct JsxOptions {

/// Enable React Fast Refresh .
///
/// Conforms to the implementation in {@link https://github.com/facebook/react/tree/main/packages/react-refresh}
/// Conforms to the implementation in {@link https://github.com/facebook/react/tree/v18.3.1/packages/react-refresh}
///
/// @default false
pub refresh: Option<Either<bool, ReactRefreshOptions>>,
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_allocator/src/boxed.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Arena Box.
//!
//! Originally based on [jsparagus](https://github.com/mozilla-spidermonkey/jsparagus/blob/master/crates/ast/src/arena.rs)
//! Originally based on [jsparagus](https://github.com/mozilla-spidermonkey/jsparagus/blob/24004745a8ed4939fc0dc7332bfd1268ac52285f/crates/ast/src/arena.rs)
use std::{
self,
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_allocator/src/vec.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Arena Vec.
//!
//! Originally based on [jsparagus](https://github.com/mozilla-spidermonkey/jsparagus/blob/master/crates/ast/src/arena.rs)
//! Originally based on [jsparagus](https://github.com/mozilla-spidermonkey/jsparagus/blob/24004745a8ed4939fc0dc7332bfd1268ac52285f/crates/ast/src/arena.rs)
use std::{
self,
Expand Down
31 changes: 16 additions & 15 deletions crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1928,24 +1928,25 @@ pub struct PropertyDefinition<'a> {
/// Initialized value in the declaration.
///
/// ## Example
/// ```
/// ```ts
/// class Foo {
/// x = 5 // Some(NumericLiteral)
/// y: string // None
/// x = 5; // Some(NumericLiteral)
/// y; // None
/// z: string; // None
///
/// constructor() {
/// this.y = "hello"
/// this.z = "hello";
/// }
/// }
/// ```
pub value: Option<Expression<'a>>,
/// Property was declared with a computed key
///
/// ## Example
/// ```ts
/// ```js
/// class Foo {
/// ["a"]: string // true
/// b: number // false
/// ["a"]: 1; // true
/// b: 2; // false
/// }
/// ```
pub computed: bool,
Expand All @@ -1956,12 +1957,12 @@ pub struct PropertyDefinition<'a> {
/// ## Example
/// ```ts
/// class Foo {
/// x: number // false
/// declare y: string // true
/// x: number; // false
/// declare y: string; // true
/// }
///
/// declare class Bar {
/// x: number // false
/// x: number; // false
/// }
/// ```
#[ts]
Expand Down Expand Up @@ -1989,10 +1990,10 @@ pub struct PropertyDefinition<'a> {
///
/// ```ts
/// class Foo {
/// public w: number // Some(TSAccessibility::Public)
/// private x: string // Some(TSAccessibility::Private)
/// protected y: boolean // Some(TSAccessibility::Protected)
/// readonly z // None
/// public w: number; // Some(TSAccessibility::Public)
/// private x: string; // Some(TSAccessibility::Private)
/// protected y: boolean; // Some(TSAccessibility::Protected)
/// readonly z; // None
/// }
/// ```
#[ts]
Expand Down Expand Up @@ -2413,7 +2414,7 @@ pub enum ExportDefaultDeclarationKind<'a> {
/// Supports:
/// * `import {"\0 any unicode" as foo} from ""`
/// * `export {foo as "\0 any unicode"}`
/// * es2022: <https://github.com/estree/estree/blob/master/es2022.md#modules>
/// * es2022: <https://github.com/estree/estree/blob/e6015c4c63118634749001b1cd1c3f7a0388f16e/es2022.md#modules>
/// * <https://github.com/tc39/ecma262/pull/2154>
#[ast(visit)]
#[derive(Debug, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/ast/ts.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! TypeScript Definitions
//!
//! - [AST Spec](https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/ast-spec)
//! - [AST Spec](https://github.com/typescript-eslint/typescript-eslint/tree/v8.9.0/packages/ast-spec)
//! - [Archived TypeScript spec](https://github.com/microsoft/TypeScript/blob/3c99d50da5a579d9fa92d02664b1b66d4ff55944/doc/spec-ARCHIVED.md)
#![allow(missing_docs)] // FIXME

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/ast_impl/ts.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! TypeScript Definitions
//!
//! [AST Spec](https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/ast-spec)
//! [AST Spec](https://github.com/typescript-eslint/typescript-eslint/tree/v8.9.0/packages/ast-spec)
//! [Archived TypeScript spec](https://github.com/microsoft/TypeScript/blob/3c99d50da5a579d9fa92d02664b1b66d4ff55944/doc/spec-ARCHIVED.md)
#![warn(missing_docs)]

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/generated/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//!
//! See:
//! * [visitor pattern](https://rust-unofficial.github.io/patterns/patterns/behavioural/visitor.html)
//! * [rustc visitor](https://github.com/rust-lang/rust/blob/master/compiler/rustc_ast/src/visit.rs)
//! * [rustc visitor](https://github.com/rust-lang/rust/blob/1.82.0/compiler/rustc_ast/src/visit.rs)
#![allow(
unused_variables,
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/generated/visit_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//!
//! See:
//! * [visitor pattern](https://rust-unofficial.github.io/patterns/patterns/behavioural/visitor.html)
//! * [rustc visitor](https://github.com/rust-lang/rust/blob/master/compiler/rustc_ast/src/visit.rs)
//! * [rustc visitor](https://github.com/rust-lang/rust/blob/1.82.0/compiler/rustc_ast/src/visit.rs)
#![allow(
unused_variables,
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
//! [`oxc_parser`]: <https://docs.rs/oxc_parser>
//! [`Parser`]: <https://docs.rs/oxc_parser/latest/oxc_parser/struct.Parser.html>
//! [estree]: <https://github.com/estree/estree>
//! [typescript-eslint]: <https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/ast-spec>
//! [typescript-eslint]: <https://github.com/typescript-eslint/typescript-eslint/tree/v8.9.0/packages/ast-spec>
//! [ECMAScript spec]: <https://tc39.es/ecma262/>
//! [tsc]: <https://github.com/microsoft/TypeScript>
//! [`Traverse`]: <https://github.com/oxc-project/oxc/tree/main/crates/oxc_traverse>
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_codegen/src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl<'a> Codegen<'a> {

/// `#__PURE__` Notation Specification
///
/// <https://github.com/javascript-compiler-hints/compiler-notations-spec/blob/main/pure-notation-spec.md>
/// <https://github.com/javascript-compiler-hints/compiler-notations-spec/blob/c14f7e197cb225c9eee877143536665ce3150712/pure-notation-spec.md>
fn is_annotation_comment(&self, comment: &Comment) -> bool {
let s = comment.content_span().source_text(self.source_text).trim_start();
if let Some(s) = s.strip_prefix(['@', '#']) {
Expand Down
10 changes: 5 additions & 5 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl<'a> Gen for Directive<'a> {
p.print_indent();
// A Use Strict Directive may not contain an EscapeSequence or LineContinuation.
// So here should print original `directive` value, the `expression` value is escaped str.
// See https://github.com/babel/babel/blob/main/packages/babel-generator/src/generators/base.ts#L64
// See https://github.com/babel/babel/blob/v7.26.2/packages/babel-generator/src/generators/base.ts#L64
p.wrap_quote(|p, _| {
p.print_str(self.directive.as_str());
});
Expand Down Expand Up @@ -665,7 +665,7 @@ impl<'a> Gen for Function<'a> {
impl<'a> Gen for FunctionBody<'a> {
fn gen(&self, p: &mut Codegen, ctx: Context) {
let span_end = self.span.end;
let comments_at_end = if !p.options.minify && span_end != 0 {
let comments_at_end = if !p.options.minify && span_end > 0 {
p.get_statement_comments(span_end - 1)
} else {
None
Expand Down Expand Up @@ -1985,7 +1985,7 @@ impl<'a> GenExpr for ImportExpression<'a> {
}
if has_comment {
// Handle `/* comment */);`
if !p.print_expr_comments(self.span.end - 1) {
if self.span.end > 0 && !p.print_expr_comments(self.span.end - 1) {
p.print_soft_newline();
}
p.dedent();
Expand Down Expand Up @@ -2067,13 +2067,13 @@ impl<'a> GenExpr for NewExpression<'a> {
p.print_str("new ");
self.callee.print_expr(p, Precedence::New, Context::FORBID_CALL);
p.print_ascii_byte(b'(');
let has_comment = p.has_comment(self.span.end - 1)
let has_comment = (self.span.end > 0 && p.has_comment(self.span.end - 1))
|| self.arguments.iter().any(|item| p.has_comment(item.span().start));
if has_comment {
p.indent();
p.print_list_with_comments(&self.arguments, ctx);
// Handle `/* comment */);`
if !p.print_expr_comments(self.span.end - 1) {
if self.span.end > 0 && !p.print_expr_comments(self.span.end - 1) {
p.print_soft_newline();
}
p.dedent();
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_codegen/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Oxc Codegen
//!
//! Code adapted from
//! * [esbuild](https://github.com/evanw/esbuild/blob/main/internal/js_printer/js_printer.go)
//! * [esbuild](https://github.com/evanw/esbuild/blob/v0.24.0/internal/js_printer/js_printer.go)
#![warn(missing_docs)]

mod binary_expr_visitor;
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_codegen/tests/integration/esbuild.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Tests ported from `esbuild`
//! * <https://github.com/evanw/esbuild/blob/main/internal/js_printer/js_printer_test.go>
//! * <https://github.com/evanw/esbuild/blob/main/internal/js_parser/js_parser_test.go>
//! * <https://github.com/evanw/esbuild/blob/v0.24.0/internal/js_printer/js_printer_test.go>
//! * <https://github.com/evanw/esbuild/blob/v0.24.0/internal/js_parser/js_parser_test.go>
use crate::tester::{test, test_minify};

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_codegen/tests/integration/pure_comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const defineSSRCustomElement = () => {
const Component = // #__PURE__
React.forwardRef((props, ref) => {});
",
// Copy from <https://github.com/rolldown-rs/rolldown/blob/main/crates/rolldown/tests/esbuild/dce/remove_unused_pure_comment_calls/entry.js>
// Copy from <https://github.com/rolldown-rs/rolldown/blob/v0.14.0/crates/rolldown/tests/esbuild/dce/remove_unused_pure_comment_calls/entry.js>
"
function bar() {}
let bare = foo(bar);
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_codegen/tests/integration/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn shorthand() {
test("let { x } = y", "let { x } = y;\n");
test("({ x: (x) })", "({ x });\n");
test("({ x } = y)", "({x} = y);\n");
// https://github.com/tc39/test262/blob/main/test/language/expressions/object/__proto__-permitted-dup-shorthand.js
// https://github.com/tc39/test262/blob/05c45a4c430ab6fee3e0c7f0d47d8a30d8876a6d/test/language/expressions/object/__proto__-permitted-dup-shorthand.js
test("var obj = { __proto__, __proto__, };", "var obj = {\n\t__proto__,\n\t__proto__\n};\n");
test("var obj = { __proto__: __proto__, };", "var obj = { __proto__: __proto__ };\n");
}
Expand Down
18 changes: 18 additions & 0 deletions crates/oxc_data_structures/src/stack/sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ impl<T> SparseStack<T> {
self.has_values.len()
}

/// Get number of filled entries on the stack.
#[inline]
pub fn filled_len(&self) -> usize {
self.values.len()
}

/// Get capacity of stack for any entries (either `Some` or `None`).
///
/// Capacity is always at least 1. Stack is never empty.
Expand All @@ -209,4 +215,16 @@ impl<T> SparseStack<T> {
pub fn filled_capacity(&self) -> usize {
self.values.capacity()
}

/// Get filled entries of stack as a slice `&[T]`.
#[inline]
pub fn as_slice(&self) -> &[T] {
self.values.as_slice()
}

/// Get filled entries of stack as a mutable slice `&mut [T]`.
#[inline]
pub fn as_mut_slice(&mut self) -> &mut [T] {
self.values.as_mut_slice()
}
}
2 changes: 1 addition & 1 deletion crates/oxc_diagnostics/src/reporter/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl DiagnosticReporter for JsonReporter {
}
}

/// <https://github.com/fregante/eslint-formatters/tree/main/packages/eslint-formatter-json>
/// <https://github.com/fregante/eslint-formatters/tree/ae1fd9748596447d1fd09625c33d9e7ba9a3d06d/packages/eslint-formatter-json>
#[allow(clippy::print_stdout)]
fn format_json(diagnostics: &mut Vec<Error>) {
let handler = JSONReportHandler::new();
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_diagnostics/src/reporter/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl DiagnosticReporter for UnixReporter {
}
}

/// <https://github.com/fregante/eslint-formatters/tree/main/packages/eslint-formatter-unix>
/// <https://github.com/fregante/eslint-formatters/tree/ae1fd9748596447d1fd09625c33d9e7ba9a3d06d/packages/eslint-formatter-unix>
fn format_unix(diagnostic: &Error) -> String {
let Info { line, column, filename, message, severity, rule_id } = Info::new(diagnostic);
let severity = match severity {
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_isolated_declarations/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! References:
//! * <https://devblogs.microsoft.com/typescript/announcing-typescript-5-5-rc/#isolated-declarations>
//! * <https://www.typescriptlang.org/tsconfig#isolatedDeclarations>
//! * <https://github.com/microsoft/TypeScript/blob/main/src/compiler/transformers/declarations.ts>
//! * <https://github.com/microsoft/TypeScript/blob/v5.6.3/src/compiler/transformers/declarations.ts>
mod class;
mod declaration;
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_isolated_declarations/tests/deno/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Copy from <https://github.com/denoland/deno_graph/blob/main/src/fast_check/transform_dts.rs#L932-#L1532>
//! Copy from <https://github.com/denoland/deno_graph/blob/0.84.0/src/fast_check/transform_dts.rs#L932-#L1532>
//! Make some changes to conform to the Isolated Declarations output
#[cfg(test)]
Expand Down
35 changes: 17 additions & 18 deletions crates/oxc_linter/src/config/oxlintrc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,29 +142,28 @@ mod test {
#[test]
fn test_oxlintrc_de_plugins_empty_array() {
let config: Oxlintrc = serde_json::from_value(json!({ "plugins": [] })).unwrap();
assert_eq!(config.plugins, LintPlugins::default());
assert_eq!(config.plugins, LintPlugins::empty());
}

#[test]
fn test_oxlintrc_de_plugins_enabled_by_default() {
// NOTE(@DonIsaac): creating a Value with `json!` then deserializing it with serde_json::from_value
// Errs with "invalid type: string \"eslint\", expected a borrowed string" and I can't
// figure out why. This seems to work. Why???
let configs = [
r#"{ "plugins": ["eslint"] }"#,
r#"{ "plugins": ["oxc"] }"#,
r#"{ "plugins": ["deepscan"] }"#, // alias for oxc
];
// ^ these plugins are enabled by default already
for oxlintrc in configs {
let config: Oxlintrc = serde_json::from_str(oxlintrc).unwrap();
assert_eq!(config.plugins, LintPlugins::default());
}
fn test_oxlintrc_empty_config_plugins() {
let config: Oxlintrc = serde_json::from_str(r"{}").unwrap();
assert_eq!(config.plugins, LintPlugins::default());
}

#[test]
fn test_oxlintrc_de_plugins_new() {
let config: Oxlintrc = serde_json::from_str(r#"{ "plugins": ["import"] }"#).unwrap();
assert_eq!(config.plugins, LintPlugins::default().union(LintPlugins::IMPORT));
fn test_oxlintrc_specifying_plugins_will_override() {
let config: Oxlintrc = serde_json::from_str(r#"{ "plugins": ["react", "oxc"] }"#).unwrap();
assert_eq!(config.plugins, LintPlugins::REACT.union(LintPlugins::OXC));
let config: Oxlintrc =
serde_json::from_str(r#"{ "plugins": ["typescript", "unicorn"] }"#).unwrap();
assert_eq!(config.plugins, LintPlugins::TYPESCRIPT.union(LintPlugins::UNICORN));
let config: Oxlintrc =
serde_json::from_str(r#"{ "plugins": ["typescript", "unicorn", "react", "oxc", "import", "jsdoc", "jest", "vitest", "jsx-a11y", "nextjs", "react-perf", "promise", "node", "security"] }"#).unwrap();
assert_eq!(config.plugins, LintPlugins::all());

let config: Oxlintrc =
serde_json::from_str(r#"{ "plugins": ["typescript", "@typescript-eslint"] }"#).unwrap();
assert_eq!(config.plugins, LintPlugins::TYPESCRIPT);
}
}
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/config/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl<'de> Deserialize<'de> for LintPlugins {
where
A: de::SeqAccess<'de>,
{
let mut plugins = LintPlugins::default();
let mut plugins = LintPlugins::empty();
loop {
// serde_json::from_str will provide an &str, while
// serde_json::from_value provides a String. The former is
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/config/settings/jsdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};

use crate::utils::default_true;

// <https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/settings.md>
// <https://github.com/gajus/eslint-plugin-jsdoc/blob/v50.5.0/docs/settings.md>
#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema)]
#[cfg_attr(test, derive(PartialEq))]
pub struct JSDocPluginSettings {
Expand Down Expand Up @@ -123,7 +123,7 @@ impl JSDocPluginSettings {
Some(Cow::Borrowed(message))
}
_ => {
// https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/settings.md#default-preferred-aliases
// https://github.com/gajus/eslint-plugin-jsdoc/blob/v50.5.0/docs/settings.md#default-preferred-aliases
let aliased_name = match original_name {
"virtual" => "abstract",
"extends" => "augments",
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/fixer/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ impl<'a> CompositeFix<'a> {
// }

/// Gets one fix from the fixes. If we retrieve multiple fixes, this merges those into one.
/// <https://github.com/eslint/eslint/blob/main/lib/linter/report-translator.js#L181-L203>
/// <https://github.com/eslint/eslint/blob/v9.9.1/lib/linter/report-translator.js#L181-L203>
pub fn normalize_fixes(self, source_text: &str) -> Fix<'a> {
match self {
CompositeFix::Single(fix) => fix,
Expand All @@ -472,7 +472,7 @@ impl<'a> CompositeFix<'a> {
/// 2. contains overlapped ranges
/// 3. contains negative ranges (span.start > span.end)
///
/// <https://github.com/eslint/eslint/blob/main/lib/linter/report-translator.js#L147-L179>
/// <https://github.com/eslint/eslint/blob/v9.9.1/lib/linter/report-translator.js#L147-L179>
fn merge_fixes(fixes: Vec<Fix<'a>>, source_text: &str) -> Fix<'a> {
let mut fixes = fixes;
if fixes.is_empty() {
Expand Down
Loading

0 comments on commit 0861fbf

Please sign in to comment.