diff --git a/.github/workflows/release_types.yml b/.github/workflows/release_types.yml index 5ba137eae5050..796d5a3eb15d8 100644 --- a/.github/workflows/release_types.yml +++ b/.github/workflows/release_types.yml @@ -1,4 +1,4 @@ -name: Release @oxc/types +name: Release @oxc-project/types on: workflow_dispatch: @@ -27,7 +27,7 @@ jobs: id: version with: static-checking: localIsNew - file-url: https://unpkg.com/@oxc/types/package.json + file-url: https://unpkg.com/@oxc-project/types/package.json file-name: npm/oxc-types/package.json - name: Set version name @@ -38,7 +38,7 @@ jobs: build: needs: check if: needs.check.outputs.version_changed == 'true' - name: Release @oxc/types + name: Release @oxc-project/types runs-on: ubuntu-latest permissions: id-token: write # for `pnpm publish --provenance` diff --git a/crates/oxc/src/napi/parse.rs b/crates/oxc/src/napi/parse.rs index 9a3fc3044736c..6ab5d3ce8e3df 100644 --- a/crates/oxc/src/napi/parse.rs +++ b/crates/oxc/src/napi/parse.rs @@ -21,7 +21,7 @@ pub struct ParserOptions { #[napi(object)] pub struct ParseResult { - #[napi(ts_type = "import(\"@oxc/types\").Program")] + #[napi(ts_type = "import(\"@oxc-project/types\").Program")] pub program: String, pub comments: Vec, pub errors: Vec, diff --git a/crates/oxc_ecmascript/src/lib.rs b/crates/oxc_ecmascript/src/lib.rs index ebc3612fa1d13..1c3d635c7623a 100644 --- a/crates/oxc_ecmascript/src/lib.rs +++ b/crates/oxc_ecmascript/src/lib.rs @@ -11,6 +11,7 @@ mod string_char_at; mod string_char_code_at; mod string_index_of; mod string_last_index_of; +mod string_substring; mod string_to_big_int; mod string_to_number; mod to_big_int; @@ -30,6 +31,7 @@ pub use self::{ private_bound_identifiers::PrivateBoundIdentifiers, prop_name::PropName, string_char_at::StringCharAt, string_char_code_at::StringCharCodeAt, string_index_of::StringIndexOf, string_last_index_of::StringLastIndexOf, - string_to_big_int::StringToBigInt, string_to_number::StringToNumber, to_big_int::ToBigInt, - to_boolean::ToBoolean, to_int_32::ToInt32, to_number::ToNumber, to_string::ToJsString, + string_substring::StringSubstring, string_to_big_int::StringToBigInt, + string_to_number::StringToNumber, to_big_int::ToBigInt, to_boolean::ToBoolean, + to_int_32::ToInt32, to_number::ToNumber, to_string::ToJsString, }; diff --git a/crates/oxc_ecmascript/src/string_substring.rs b/crates/oxc_ecmascript/src/string_substring.rs new file mode 100644 index 0000000000000..1518e688ba667 --- /dev/null +++ b/crates/oxc_ecmascript/src/string_substring.rs @@ -0,0 +1,37 @@ +use crate::ToInt32; + +pub trait StringSubstring { + /// `String.prototype.substring ( start , end ] )` + /// + fn substring(&self, start: Option, end: Option) -> String; +} + +impl StringSubstring for &str { + #[expect(clippy::cast_sign_loss)] + fn substring(&self, start: Option, end: Option) -> String { + let start = start.map_or(0, |x| x.to_int_32().max(0) as usize); + let end = end.map_or(usize::MAX, |x| x.to_int_32().max(0) as usize); + let start = start.min(self.len()); + let end = end.min(self.len()); + if start > end { + return String::new(); + } + self.chars().skip(start).take(end - start).collect() + } +} + +#[cfg(test)] +mod test { + #[test] + fn test_prototype_last_index_of() { + use super::StringSubstring; + assert_eq!("foo".substring(Some(1.0), None), "oo"); + assert_eq!("foo".substring(Some(1.0), Some(2.0)), "o"); + assert_eq!("foo".substring(Some(1.0), Some(1.0)), ""); + assert_eq!("foo".substring(Some(1.0), Some(0.0)), ""); + assert_eq!("foo".substring(Some(0.0), Some(0.0)), ""); + assert_eq!("foo".substring(Some(0.0), Some(1.0)), "f"); + assert_eq!("abc".substring(Some(0.0), Some(2.0)), "ab"); + assert_eq!("abcde".substring(Some(0.0), Some(2.0)), "ab"); + } +} diff --git a/crates/oxc_linter/src/rules/react/iframe_missing_sandbox.rs b/crates/oxc_linter/src/rules/react/iframe_missing_sandbox.rs index 0fcd3f4300beb..7d46bfca5aee1 100644 --- a/crates/oxc_linter/src/rules/react/iframe_missing_sandbox.rs +++ b/crates/oxc_linter/src/rules/react/iframe_missing_sandbox.rs @@ -8,6 +8,7 @@ use oxc_macros::declare_oxc_lint; use oxc_span::Span; use phf::{phf_set, Set}; +use crate::ast_util::is_method_call; use crate::utils::{get_prop_value, has_jsx_prop_ignore_case, is_create_element_call}; use crate::{context::LintContext, rule::Rule, AstNode}; @@ -57,12 +58,19 @@ declare_oxc_lint!( /// /// ### Why is this bad? /// - /// The sandbox attribute enables an extra set of restrictions for the content in the iframe. Using sandbox attribute is considered a good security practice. - /// To learn more about sandboxing, see [MDN's documentation on the `sandbox` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#sandbox). - + /// The sandbox attribute enables an extra set of restrictions for the + /// content in the iframe. Using sandbox attribute is considered a good + /// security practice. To learn more about sandboxing, see [MDN's + /// documentation on the `sandbox` + /// attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#sandbox). + /// + /// This rule checks all React `