From 8f1460eba3e6c08b4a20c135a2189468d763df08 Mon Sep 17 00:00:00 2001 From: DonIsaac <22823424+DonIsaac@users.noreply.github.com> Date: Tue, 29 Oct 2024 01:28:21 +0000 Subject: [PATCH 01/12] refactor(linter): move `LintPlugins` from `LintOptions` to `LintConfig` (#6932) Pure refactor. Moves plugin settings from linter options (which control the linter's behavior on a global level) and linter config ("which may or may not get adjusted on each file). --- crates/oxc_linter/src/builder.rs | 31 ++++++++++--------- crates/oxc_linter/src/config/mod.rs | 10 +++++- crates/oxc_linter/src/config/oxlintrc.rs | 6 ++-- .../src/{options => config}/plugins.rs | 0 crates/oxc_linter/src/context/host.rs | 18 ++++++++--- crates/oxc_linter/src/lib.rs | 8 ++--- crates/oxc_linter/src/options/filter.rs | 3 +- crates/oxc_linter/src/options/mod.rs | 3 -- crates/oxc_linter/src/tester.rs | 2 +- crates/oxc_linter/src/utils/jest.rs | 11 +++++-- 10 files changed, 58 insertions(+), 34 deletions(-) rename crates/oxc_linter/src/{options => config}/plugins.rs (100%) diff --git a/crates/oxc_linter/src/builder.rs b/crates/oxc_linter/src/builder.rs index 89b2669c17ca57..0ca05e142b763b 100644 --- a/crates/oxc_linter/src/builder.rs +++ b/crates/oxc_linter/src/builder.rs @@ -7,8 +7,7 @@ use oxc_span::CompactStr; use rustc_hash::FxHashSet; use crate::{ - config::{ESLintRule, OxlintRules}, - options::LintPlugins, + config::{ESLintRule, LintPlugins, OxlintRules}, rules::RULES, AllowWarnDeny, FixKind, FrameworkFlags, LintConfig, LintFilter, LintFilterKind, LintOptions, Linter, Oxlintrc, RuleCategory, RuleEnum, RuleWithSeverity, @@ -35,8 +34,11 @@ impl LinterBuilder { /// You can think of this as `oxlint -A all`. pub fn empty() -> Self { let options = LintOptions::default(); - let cache = RulesCache::new(options.plugins); - Self { rules: FxHashSet::default(), options, config: LintConfig::default(), cache } + let config = LintConfig::default(); + let rules = FxHashSet::default(); + let cache = RulesCache::new(config.plugins); + + Self { rules, options, config, cache } } /// Warn on all rules in all plugins and categories, including those in `nursery`. @@ -44,15 +46,16 @@ impl LinterBuilder { /// /// You can think of this as `oxlint -W all -W nursery`. pub fn all() -> Self { - let options = LintOptions { plugins: LintPlugins::all(), ..LintOptions::default() }; - let cache = RulesCache::new(options.plugins); + let options = LintOptions::default(); + let config = LintConfig { plugins: LintPlugins::all(), ..LintConfig::default() }; + let cache = RulesCache::new(config.plugins); Self { rules: RULES .iter() .map(|rule| RuleWithSeverity { rule: rule.clone(), severity: AllowWarnDeny::Warn }) .collect(), options, - config: LintConfig::default(), + config, cache, } } @@ -76,11 +79,11 @@ impl LinterBuilder { let Oxlintrc { plugins, settings, env, globals, categories, rules: oxlintrc_rules } = oxlintrc; - let config = LintConfig { settings, env, globals }; - let options = LintOptions { plugins, ..Default::default() }; + let config = LintConfig { plugins, settings, env, globals }; + let options = LintOptions::default(); let rules = if start_empty { FxHashSet::default() } else { Self::warn_correctness(plugins) }; - let cache = RulesCache::new(options.plugins); + let cache = RulesCache::new(config.plugins); let mut builder = Self { rules, options, config, cache }; if !categories.is_empty() { @@ -128,7 +131,7 @@ impl LinterBuilder { /// [`and_plugins`]: LinterBuilder::and_plugins #[inline] pub fn with_plugins(mut self, plugins: LintPlugins) -> Self { - self.options.plugins = plugins; + self.config.plugins = plugins; self.cache.set_plugins(plugins); self } @@ -139,14 +142,14 @@ impl LinterBuilder { /// rules. #[inline] pub fn and_plugins(mut self, plugins: LintPlugins, enabled: bool) -> Self { - self.options.plugins.set(plugins, enabled); - self.cache.set_plugins(self.options.plugins); + self.config.plugins.set(plugins, enabled); + self.cache.set_plugins(self.config.plugins); self } #[inline] pub fn plugins(&self) -> LintPlugins { - self.options.plugins + self.config.plugins } #[cfg(test)] diff --git a/crates/oxc_linter/src/config/mod.rs b/crates/oxc_linter/src/config/mod.rs index 67f86fd1966b6f..f0c87860e11b5a 100644 --- a/crates/oxc_linter/src/config/mod.rs +++ b/crates/oxc_linter/src/config/mod.rs @@ -2,6 +2,7 @@ mod categories; mod env; mod globals; mod oxlintrc; +mod plugins; mod rules; mod settings; @@ -9,6 +10,7 @@ pub use self::{ env::OxlintEnv, globals::OxlintGlobals, oxlintrc::Oxlintrc, + plugins::LintPlugins, rules::ESLintRule, rules::OxlintRules, settings::{jsdoc::JSDocPluginSettings, OxlintSettings}, @@ -16,6 +18,7 @@ pub use self::{ #[derive(Debug, Default)] pub(crate) struct LintConfig { + pub(crate) plugins: LintPlugins, pub(crate) settings: OxlintSettings, /// Environments enable and disable collections of global variables. pub(crate) env: OxlintEnv, @@ -25,7 +28,12 @@ pub(crate) struct LintConfig { impl From for LintConfig { fn from(config: Oxlintrc) -> Self { - Self { settings: config.settings, env: config.env, globals: config.globals } + Self { + plugins: config.plugins, + settings: config.settings, + env: config.env, + globals: config.globals, + } } } diff --git a/crates/oxc_linter/src/config/oxlintrc.rs b/crates/oxc_linter/src/config/oxlintrc.rs index db5676da1fbe11..21121a50fc238a 100644 --- a/crates/oxc_linter/src/config/oxlintrc.rs +++ b/crates/oxc_linter/src/config/oxlintrc.rs @@ -5,11 +5,11 @@ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use super::{ - categories::OxlintCategories, env::OxlintEnv, globals::OxlintGlobals, rules::OxlintRules, - settings::OxlintSettings, + categories::OxlintCategories, env::OxlintEnv, globals::OxlintGlobals, plugins::LintPlugins, + rules::OxlintRules, settings::OxlintSettings, }; -use crate::{options::LintPlugins, utils::read_to_string}; +use crate::utils::read_to_string; /// Oxlint Configuration File /// diff --git a/crates/oxc_linter/src/options/plugins.rs b/crates/oxc_linter/src/config/plugins.rs similarity index 100% rename from crates/oxc_linter/src/options/plugins.rs rename to crates/oxc_linter/src/config/plugins.rs diff --git a/crates/oxc_linter/src/context/host.rs b/crates/oxc_linter/src/context/host.rs index 12e1e74a85fa4c..c164de28bb6113 100644 --- a/crates/oxc_linter/src/context/host.rs +++ b/crates/oxc_linter/src/context/host.rs @@ -3,11 +3,11 @@ use oxc_span::SourceType; use std::{cell::RefCell, path::Path, rc::Rc, sync::Arc}; use crate::{ - config::LintConfig, + config::{LintConfig, LintPlugins}, disable_directives::{DisableDirectives, DisableDirectivesBuilder}, fixer::{FixKind, Message}, frameworks, - options::{LintOptions, LintPlugins}, + options::LintOptions, utils, FrameworkFlags, RuleWithSeverity, }; @@ -68,6 +68,7 @@ impl<'a> ContextHost<'a> { file_path: P, semantic: Rc>, options: LintOptions, + config: Arc, ) -> Self { const DIAGNOSTICS_INITIAL_CAPACITY: usize = 512; @@ -82,6 +83,7 @@ impl<'a> ContextHost<'a> { DisableDirectivesBuilder::new().build(semantic.source_text(), semantic.comments()); let file_path = file_path.as_ref().to_path_buf().into_boxed_path(); + let plugins = config.plugins; Self { semantic, @@ -89,17 +91,25 @@ impl<'a> ContextHost<'a> { diagnostics: RefCell::new(Vec::with_capacity(DIAGNOSTICS_INITIAL_CAPACITY)), fix: options.fix, file_path, - config: Arc::new(LintConfig::default()), + config, frameworks: options.framework_hints, - plugins: options.plugins, + plugins, } .sniff_for_frameworks() } /// Set the linter configuration for this context. #[inline] + #[allow(dead_code)] // will be used in up-stack PR pub fn with_config(mut self, config: &Arc) -> Self { + let plugins = config.plugins; self.config = Arc::clone(config); + + if self.plugins != plugins { + self.plugins = plugins; + return self.sniff_for_frameworks(); + } + self } diff --git a/crates/oxc_linter/src/lib.rs b/crates/oxc_linter/src/lib.rs index e8a590e605edca..03cf7542f6b7f3 100644 --- a/crates/oxc_linter/src/lib.rs +++ b/crates/oxc_linter/src/lib.rs @@ -31,11 +31,11 @@ use utils::iter_possible_jest_call_node; pub use crate::{ builder::LinterBuilder, - config::Oxlintrc, + config::{LintPlugins, Oxlintrc}, context::LintContext, fixer::FixKind, frameworks::FrameworkFlags, - options::{AllowWarnDeny, InvalidFilterKind, LintFilter, LintFilterKind, LintPlugins}, + options::{AllowWarnDeny, InvalidFilterKind, LintFilter, LintFilterKind}, rule::{RuleCategory, RuleFixMeta, RuleMeta, RuleWithSeverity}, service::{LintService, LintServiceOptions}, }; @@ -115,7 +115,7 @@ impl Linter { pub fn run<'a>(&self, path: &Path, semantic: Rc>) -> Vec> { let ctx_host = - Rc::new(ContextHost::new(path, semantic, self.options).with_config(&self.config)); + Rc::new(ContextHost::new(path, semantic, self.options, Arc::clone(&self.config))); let rules = self .rules @@ -126,7 +126,7 @@ impl Linter { let semantic = ctx_host.semantic(); let should_run_on_jest_node = - self.options.plugins.has_test() && ctx_host.frameworks().is_test(); + self.config.plugins.has_test() && ctx_host.frameworks().is_test(); // IMPORTANT: We have two branches here for performance reasons: // diff --git a/crates/oxc_linter/src/options/filter.rs b/crates/oxc_linter/src/options/filter.rs index b09f4df0a3e728..6ac054ba2287f5 100644 --- a/crates/oxc_linter/src/options/filter.rs +++ b/crates/oxc_linter/src/options/filter.rs @@ -1,6 +1,7 @@ use crate::RuleCategory; -use super::{plugins::LintPlugins, AllowWarnDeny}; +use super::AllowWarnDeny; +use crate::LintPlugins; use std::{borrow::Cow, fmt}; /// Enables, disables, and sets the severity of lint rules. diff --git a/crates/oxc_linter/src/options/mod.rs b/crates/oxc_linter/src/options/mod.rs index 4ce020dc5f9844..7012ac83995f56 100644 --- a/crates/oxc_linter/src/options/mod.rs +++ b/crates/oxc_linter/src/options/mod.rs @@ -1,10 +1,8 @@ mod allow_warn_deny; mod filter; -mod plugins; pub use allow_warn_deny::AllowWarnDeny; pub use filter::{InvalidFilterKind, LintFilter, LintFilterKind}; -pub use plugins::LintPlugins; use crate::{fixer::FixKind, FrameworkFlags}; @@ -14,5 +12,4 @@ use crate::{fixer::FixKind, FrameworkFlags}; pub(crate) struct LintOptions { pub fix: FixKind, pub framework_hints: FrameworkFlags, - pub plugins: LintPlugins, } diff --git a/crates/oxc_linter/src/tester.rs b/crates/oxc_linter/src/tester.rs index 981a07e3647c8c..8403dd394b44de 100644 --- a/crates/oxc_linter/src/tester.rs +++ b/crates/oxc_linter/src/tester.rs @@ -10,7 +10,7 @@ use serde::Deserialize; use serde_json::Value; use crate::{ - fixer::FixKind, options::LintPlugins, rules::RULES, AllowWarnDeny, Fixer, LintService, + fixer::FixKind, rules::RULES, AllowWarnDeny, Fixer, LintPlugins, LintService, LintServiceOptions, LinterBuilder, Oxlintrc, RuleEnum, RuleWithSeverity, }; diff --git a/crates/oxc_linter/src/utils/jest.rs b/crates/oxc_linter/src/utils/jest.rs index 4710c9a6476a84..8a16b773f9a410 100644 --- a/crates/oxc_linter/src/utils/jest.rs +++ b/crates/oxc_linter/src/utils/jest.rs @@ -303,7 +303,7 @@ pub fn is_equality_matcher(matcher: &KnownMemberExpressionProperty) -> bool { #[cfg(test)] mod test { - use std::rc::Rc; + use std::{rc::Rc, sync::Arc}; use oxc_allocator::Allocator; use oxc_parser::Parser; @@ -322,8 +322,13 @@ mod test { let semantic_ret = Rc::new(semantic_ret); let build_ctx = |path: &'static str| { - Rc::new(ContextHost::new(path, Rc::clone(&semantic_ret), LintOptions::default())) - .spawn_for_test() + Rc::new(ContextHost::new( + path, + Rc::clone(&semantic_ret), + LintOptions::default(), + Arc::default(), + )) + .spawn_for_test() }; let ctx = build_ctx("foo.js"); From 8cbf3f09d68804a27104c07dae89e9f0160155d2 Mon Sep 17 00:00:00 2001 From: Boshen Date: Tue, 29 Oct 2024 11:50:58 +0800 Subject: [PATCH 02/12] chore: replace `bacon` with `watchexec` --- bacon.toml | 19 ------------------- justfile | 47 ++++++++++++++++++++++++----------------------- 2 files changed, 24 insertions(+), 42 deletions(-) delete mode 100644 bacon.toml diff --git a/bacon.toml b/bacon.toml deleted file mode 100644 index b93078c3886908..00000000000000 --- a/bacon.toml +++ /dev/null @@ -1,19 +0,0 @@ -[jobs.example] -command = ["just", "example"] -allow_warnings = true -need_stdout = true - -[jobs.oxlint] -command = ["cargo", "--color", "always", "run", "-p", "oxlint"] -allow_warnings = true -need_stdout = true - -[jobs.wasm] -command = ["just", "build-wasm", "dev"] -allow_warnings = true -need_stdout = true - -[jobs.coverage] -command = ["cargo", "--color", "always", "run", "-p", "oxc_coverage"] -allow_warnings = true -need_stdout = true diff --git a/justfile b/justfile index 6afa5622463413..19a66d49ce418b 100755 --- a/justfile +++ b/justfile @@ -16,7 +16,7 @@ alias new-typescript-rule := new-ts-rule # or install via `cargo install cargo-binstall` # Initialize the project by installing all the necessary tools. init: - cargo binstall bacon cargo-insta typos-cli cargo-shear dprint -y + cargo binstall watchexec-cli cargo-insta typos-cli cargo-shear dprint -y # When ready, run the same CI commands ready: @@ -42,27 +42,23 @@ install-hook: echo -e "#!/bin/sh\njust fmt" > .git/hooks/pre-commit chmod +x .git/hooks/pre-commit -watch: - bacon +watch *args='': + watchexec {{args}} # Run the example in `parser`, `formatter`, `linter` example tool *args='': - cargo --color always run -p oxc_{{tool}} --example {{tool}} -- {{args}} + cargo run -p oxc_{{tool}} --example {{tool}} -- {{args}} watch-example *args='': - bacon example -- {{args}} + just watch 'just example {{args}}' -# Generate AST related boilerplate code. -# Run this when AST definition is changed. -ast: - cargo run -p oxc_ast_tools - just check +# Build oxlint in release build; Run with `./target/release/oxlint`. +oxlint : + cargo oxlint -# Format all files -fmt: - cargo shear --fix # remove all unused dependencies - cargo fmt --all - dprint fmt +# Watch oxlint +watch-oxlint *args='': + just watch 'cargo run -p oxlint -- {{args}}' # Run cargo check check: @@ -76,6 +72,12 @@ test: lint: cargo lint -- --deny warnings +# Format all files +fmt: + cargo shear --fix # remove all unused dependencies + cargo fmt --all + dprint fmt + [unix] doc: RUSTDOCFLAGS='-D warnings' cargo doc --no-deps --document-private-items @@ -98,16 +100,15 @@ coverage: cargo run -p oxc_prettier_conformance cargo minsize +# Run Test262, Babel and TypeScript conformance suite conformance *args='': cargo coverage -- {{args}} -# Build oxlint in release build -oxlint: - cargo oxlint - -# Watch oxlint -watch-oxlint *args='': - bacon oxlint -- {{args}} +# Generate AST related boilerplate code. +# Run this when AST definition is changed. +ast: + cargo run -p oxc_ast_tools + just check # Get code coverage codecov: @@ -132,7 +133,7 @@ install-wasm: cargo binstall wasm-pack watch-wasm: - bacon wasm + just watch 'just build-wasm dev' build-wasm mode="release": wasm-pack build --out-dir ../../npm/oxc-wasm --target web --{{mode}} --scope oxc crates/oxc_wasm From 9fd9f4f5b9de2f3f76998a130700a01eb4b4def5 Mon Sep 17 00:00:00 2001 From: Boshen <1430279+Boshen@users.noreply.github.com> Date: Tue, 29 Oct 2024 04:13:20 +0000 Subject: [PATCH 03/12] feat(linter)!: sync sindresorhus/globals; removed Object.prototype properties from builtin and es* globals (#6991) --- crates/oxc_linter/src/javascript_globals.rs | 659 ++++++++++++++++-- .../oxc_linter/src/rules/eslint/no_undef.rs | 4 +- crates/oxc_linter/src/snapshots/no_undef.snap | 12 + tasks/javascript_globals/template.hbs | 5 +- 4 files changed, 630 insertions(+), 50 deletions(-) diff --git a/crates/oxc_linter/src/javascript_globals.rs b/crates/oxc_linter/src/javascript_globals.rs index 33440433f21fe0..da2002aef7aa6c 100644 --- a/crates/oxc_linter/src/javascript_globals.rs +++ b/crates/oxc_linter/src/javascript_globals.rs @@ -1,3 +1,6 @@ +// Auto-generated code, DO NOT EDIT DIRECTLY! +// To edit this generated file you have to run `cargo run -p javascript_globals`. + use phf::{phf_map, Map}; pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { @@ -22,6 +25,7 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "Int16Array" => false, "Int32Array" => false, "Int8Array" => false, + "Intl" => false, "JSON" => false, "Map" => false, "Math" => false, @@ -48,7 +52,6 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "WeakMap" => false, "WeakRef" => false, "WeakSet" => false, - "constructor" => false, "decodeURI" => false, "decodeURIComponent" => false, "encodeURI" => false, @@ -56,18 +59,12 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "escape" => false, "eval" => false, "globalThis" => false, - "hasOwnProperty" => false, "isFinite" => false, "isNaN" => false, - "isPrototypeOf" => false, "parseFloat" => false, "parseInt" => false, - "propertyIsEnumerable" => false, - "toLocaleString" => false, - "toString" => false, "undefined" => false, "unescape" => false, - "valueOf" => false, }, "es6" => phf_map! { "ArrayBuffer" => false, @@ -77,6 +74,7 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "Int16Array" => false, "Int32Array" => false, "Int8Array" => false, + "Intl" => false, "Map" => false, "Promise" => false, "Proxy" => false, @@ -98,6 +96,7 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "Int16Array" => false, "Int32Array" => false, "Int8Array" => false, + "Intl" => false, "Map" => false, "Promise" => false, "Proxy" => false, @@ -119,6 +118,7 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "Int16Array" => false, "Int32Array" => false, "Int8Array" => false, + "Intl" => false, "Map" => false, "Promise" => false, "Proxy" => false, @@ -141,6 +141,7 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "Int16Array" => false, "Int32Array" => false, "Int8Array" => false, + "Intl" => false, "Map" => false, "Promise" => false, "Proxy" => false, @@ -164,6 +165,7 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "Int16Array" => false, "Int32Array" => false, "Int8Array" => false, + "Intl" => false, "Map" => false, "Promise" => false, "Proxy" => false, @@ -187,6 +189,7 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "Int16Array" => false, "Int32Array" => false, "Int8Array" => false, + "Intl" => false, "Map" => false, "Promise" => false, "Proxy" => false, @@ -213,6 +216,7 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "Int16Array" => false, "Int32Array" => false, "Int8Array" => false, + "Intl" => false, "Map" => false, "Promise" => false, "Proxy" => false, @@ -242,6 +246,7 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "Int16Array" => false, "Int32Array" => false, "Int8Array" => false, + "Intl" => false, "Map" => false, "Promise" => false, "Proxy" => false, @@ -272,6 +277,7 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "Int16Array" => false, "Int32Array" => false, "Int8Array" => false, + "Intl" => false, "Map" => false, "Promise" => false, "Proxy" => false, @@ -302,6 +308,7 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "Int16Array" => false, "Int32Array" => false, "Int8Array" => false, + "Intl" => false, "Map" => false, "Promise" => false, "Proxy" => false, @@ -332,6 +339,7 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "Int16Array" => false, "Int32Array" => false, "Int8Array" => false, + "Intl" => false, "Map" => false, "Promise" => false, "Proxy" => false, @@ -349,91 +357,161 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "globalThis" => false, }, "browser" => phf_map! { + "AI" => false, + "AITextSession" => false, "AbortController" => false, "AbortSignal" => false, + "AbsoluteOrientationSensor" => false, + "AbstractRange" => false, + "Accelerometer" => false, "AnalyserNode" => false, "Animation" => false, - "AnimationEffectReadOnly" => false, - "AnimationEffectTiming" => false, - "AnimationEffectTimingReadOnly" => false, + "AnimationEffect" => false, "AnimationEvent" => false, "AnimationPlaybackEvent" => false, "AnimationTimeline" => false, - "ApplicationCache" => false, - "ApplicationCacheErrorEvent" => false, "Attr" => false, "Audio" => false, "AudioBuffer" => false, "AudioBufferSourceNode" => false, "AudioContext" => false, + "AudioData" => false, + "AudioDecoder" => false, "AudioDestinationNode" => false, + "AudioEncoder" => false, "AudioListener" => false, "AudioNode" => false, "AudioParam" => false, + "AudioParamMap" => false, "AudioProcessingEvent" => false, "AudioScheduledSourceNode" => false, + "AudioSinkInfo" => false, + "AudioWorklet" => false, "AudioWorkletGlobalScope" => false, "AudioWorkletNode" => false, "AudioWorkletProcessor" => false, + "AuthenticatorAssertionResponse" => false, + "AuthenticatorAttestationResponse" => false, + "AuthenticatorResponse" => false, + "BackgroundFetchManager" => false, + "BackgroundFetchRecord" => false, + "BackgroundFetchRegistration" => false, "BarProp" => false, + "BarcodeDetector" => false, "BaseAudioContext" => false, "BatteryManager" => false, "BeforeUnloadEvent" => false, "BiquadFilterNode" => false, "Blob" => false, "BlobEvent" => false, + "Bluetooth" => false, + "BluetoothCharacteristicProperties" => false, + "BluetoothDevice" => false, + "BluetoothRemoteGATTCharacteristic" => false, + "BluetoothRemoteGATTDescriptor" => false, + "BluetoothRemoteGATTServer" => false, + "BluetoothRemoteGATTService" => false, + "BluetoothUUID" => false, "BroadcastChannel" => false, - "BudgetService" => false, + "BrowserCaptureMediaStreamTrack" => false, "ByteLengthQueuingStrategy" => false, + "CDATASection" => false, "CSS" => false, + "CSSAnimation" => false, "CSSConditionRule" => false, + "CSSContainerRule" => false, + "CSSCounterStyleRule" => false, "CSSFontFaceRule" => false, + "CSSFontFeatureValuesRule" => false, + "CSSFontPaletteValuesRule" => false, "CSSGroupingRule" => false, + "CSSImageValue" => false, "CSSImportRule" => false, "CSSKeyframeRule" => false, "CSSKeyframesRule" => false, + "CSSKeywordValue" => false, + "CSSLayerBlockRule" => false, + "CSSLayerStatementRule" => false, + "CSSMathClamp" => false, + "CSSMathInvert" => false, + "CSSMathMax" => false, + "CSSMathMin" => false, + "CSSMathNegate" => false, + "CSSMathProduct" => false, + "CSSMathSum" => false, + "CSSMathValue" => false, "CSSMatrixComponent" => false, "CSSMediaRule" => false, "CSSNamespaceRule" => false, + "CSSNumericArray" => false, + "CSSNumericValue" => false, + "CSSPageDescriptors" => false, "CSSPageRule" => false, "CSSPerspective" => false, + "CSSPositionTryDescriptors" => false, + "CSSPositionTryRule" => false, + "CSSPositionValue" => false, + "CSSPropertyRule" => false, "CSSRotate" => false, "CSSRule" => false, "CSSRuleList" => false, "CSSScale" => false, + "CSSScopeRule" => false, "CSSSkew" => false, "CSSSkewX" => false, "CSSSkewY" => false, + "CSSStartingStyleRule" => false, "CSSStyleDeclaration" => false, "CSSStyleRule" => false, "CSSStyleSheet" => false, + "CSSStyleValue" => false, "CSSSupportsRule" => false, + "CSSTransformComponent" => false, "CSSTransformValue" => false, + "CSSTransition" => false, "CSSTranslate" => false, + "CSSUnitValue" => false, + "CSSUnparsedValue" => false, + "CSSVariableReferenceValue" => false, + "CSSViewTransitionRule" => false, "Cache" => false, "CacheStorage" => false, + "CanvasCaptureMediaStream" => false, "CanvasCaptureMediaStreamTrack" => false, "CanvasGradient" => false, "CanvasPattern" => false, "CanvasRenderingContext2D" => false, + "CaptureController" => false, + "CaretPosition" => false, "ChannelMergerNode" => false, "ChannelSplitterNode" => false, + "ChapterInformation" => false, + "CharacterBoundsUpdateEvent" => false, "CharacterData" => false, + "Clipboard" => false, "ClipboardEvent" => false, "ClipboardItem" => false, "CloseEvent" => false, + "CloseWatcher" => false, "Comment" => false, "CompositionEvent" => false, "CompressionStream" => false, "ConstantSourceNode" => false, + "ContentVisibilityAutoStateChangeEvent" => false, "ConvolverNode" => false, + "CookieChangeEvent" => false, + "CookieDeprecationLabel" => false, + "CookieStore" => false, + "CookieStoreManager" => false, "CountQueuingStrategy" => false, "Credential" => false, "CredentialsContainer" => false, + "CropTarget" => false, "Crypto" => false, "CryptoKey" => false, "CustomElementRegistry" => false, "CustomEvent" => false, + "CustomStateSet" => false, "DOMError" => false, "DOMException" => false, "DOMImplementation" => false, @@ -454,30 +532,115 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "DataTransferItemList" => false, "DecompressionStream" => false, "DelayNode" => false, + "DelegatedInkTrailPresenter" => false, "DeviceMotionEvent" => false, + "DeviceMotionEventAcceleration" => false, + "DeviceMotionEventRotationRate" => false, "DeviceOrientationEvent" => false, "Document" => false, "DocumentFragment" => false, + "DocumentPictureInPicture" => false, + "DocumentPictureInPictureEvent" => false, + "DocumentTimeline" => false, "DocumentType" => false, "DragEvent" => false, "DynamicsCompressorNode" => false, + "EditContext" => false, "Element" => false, + "ElementInternals" => false, + "EncodedAudioChunk" => false, + "EncodedVideoChunk" => false, "ErrorEvent" => false, "Event" => false, + "EventCounts" => false, "EventSource" => false, "EventTarget" => false, + "External" => false, + "EyeDropper" => false, + "FeaturePolicy" => false, + "FederatedCredential" => false, + "Fence" => false, + "FencedFrameConfig" => false, + "FetchLaterResult" => false, "File" => false, "FileList" => false, "FileReader" => false, + "FileSystem" => false, + "FileSystemDirectoryEntry" => false, + "FileSystemDirectoryHandle" => false, + "FileSystemDirectoryReader" => false, + "FileSystemEntry" => false, + "FileSystemFileEntry" => false, + "FileSystemFileHandle" => false, + "FileSystemHandle" => false, + "FileSystemWritableFileStream" => false, + "Float16Array" => false, "FocusEvent" => false, + "FontData" => false, "FontFace" => false, + "FontFaceSet" => false, "FontFaceSetLoadEvent" => false, "FormData" => false, "FormDataEvent" => false, + "FragmentDirective" => false, + "GPU" => false, + "GPUAdapter" => false, + "GPUAdapterInfo" => false, + "GPUBindGroup" => false, + "GPUBindGroupLayout" => false, + "GPUBuffer" => false, + "GPUBufferUsage" => false, + "GPUCanvasContext" => false, + "GPUColorWrite" => false, + "GPUCommandBuffer" => false, + "GPUCommandEncoder" => false, + "GPUCompilationInfo" => false, + "GPUCompilationMessage" => false, + "GPUComputePassEncoder" => false, + "GPUComputePipeline" => false, + "GPUDevice" => false, + "GPUDeviceLostInfo" => false, + "GPUError" => false, + "GPUExternalTexture" => false, + "GPUInternalError" => false, + "GPUMapMode" => false, + "GPUOutOfMemoryError" => false, + "GPUPipelineError" => false, + "GPUPipelineLayout" => false, + "GPUQuerySet" => false, + "GPUQueue" => false, + "GPURenderBundle" => false, + "GPURenderBundleEncoder" => false, + "GPURenderPassEncoder" => false, + "GPURenderPipeline" => false, + "GPUSampler" => false, + "GPUShaderModule" => false, + "GPUShaderStage" => false, + "GPUSupportedFeatures" => false, + "GPUSupportedLimits" => false, + "GPUTexture" => false, + "GPUTextureUsage" => false, + "GPUTextureView" => false, + "GPUUncapturedErrorEvent" => false, + "GPUValidationError" => false, "GainNode" => false, "Gamepad" => false, + "GamepadAxisMoveEvent" => false, "GamepadButton" => false, + "GamepadButtonEvent" => false, "GamepadEvent" => false, + "GamepadHapticActuator" => false, + "GamepadPose" => false, + "Geolocation" => false, + "GeolocationCoordinates" => false, + "GeolocationPosition" => false, + "GeolocationPositionError" => false, + "GravitySensor" => false, + "Gyroscope" => false, + "HID" => false, + "HIDConnectionEvent" => false, + "HIDDevice" => false, + "HIDInputReportEvent" => false, "HTMLAllCollection" => false, "HTMLAnchorElement" => false, "HTMLAreaElement" => false, @@ -488,7 +651,6 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "HTMLButtonElement" => false, "HTMLCanvasElement" => false, "HTMLCollection" => false, - "HTMLContentElement" => false, "HTMLDListElement" => false, "HTMLDataElement" => false, "HTMLDataListElement" => false, @@ -499,6 +661,7 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "HTMLDocument" => false, "HTMLElement" => false, "HTMLEmbedElement" => false, + "HTMLFencedFrameElement" => false, "HTMLFieldSetElement" => false, "HTMLFontElement" => false, "HTMLFormControlsCollection" => false, @@ -537,7 +700,6 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "HTMLQuoteElement" => false, "HTMLScriptElement" => false, "HTMLSelectElement" => false, - "HTMLShadowElement" => false, "HTMLSlotElement" => false, "HTMLSourceElement" => false, "HTMLSpanElement" => false, @@ -558,6 +720,8 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "HTMLVideoElement" => false, "HashChangeEvent" => false, "Headers" => false, + "Highlight" => false, + "HighlightRegistry" => false, "History" => false, "IDBCursor" => false, "IDBCursorWithValue" => false, @@ -571,20 +735,39 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "IDBTransaction" => false, "IDBVersionChangeEvent" => false, "IIRFilterNode" => false, + "IdentityCredential" => false, + "IdentityCredentialError" => false, + "IdentityProvider" => false, "IdleDeadline" => false, + "IdleDetector" => false, "Image" => false, "ImageBitmap" => false, "ImageBitmapRenderingContext" => false, "ImageCapture" => false, "ImageData" => false, + "ImageDecoder" => false, + "ImageTrack" => false, + "ImageTrackList" => false, + "Ink" => false, + "InputDeviceCapabilities" => false, + "InputDeviceInfo" => false, "InputEvent" => false, "IntersectionObserver" => false, "IntersectionObserverEntry" => false, - "Intl" => false, + "Iterator" => false, + "Keyboard" => false, "KeyboardEvent" => false, + "KeyboardLayoutMap" => false, "KeyframeEffect" => false, - "KeyframeEffectReadOnly" => false, + "LargestContentfulPaint" => false, + "LaunchParams" => false, + "LaunchQueue" => false, + "LayoutShift" => false, + "LayoutShiftAttribution" => false, + "LinearAccelerationSensor" => false, "Location" => false, + "Lock" => false, + "LockManager" => false, "MIDIAccess" => false, "MIDIConnectionEvent" => false, "MIDIInput" => false, @@ -593,64 +776,100 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "MIDIOutput" => false, "MIDIOutputMap" => false, "MIDIPort" => false, + "MathMLElement" => false, + "MediaCapabilities" => false, + "MediaCapabilitiesInfo" => false, "MediaDeviceInfo" => false, "MediaDevices" => false, "MediaElementAudioSourceNode" => false, "MediaEncryptedEvent" => false, "MediaError" => false, + "MediaKeyError" => false, "MediaKeyMessageEvent" => false, "MediaKeySession" => false, "MediaKeyStatusMap" => false, "MediaKeySystemAccess" => false, + "MediaKeys" => false, "MediaList" => false, "MediaMetadata" => false, "MediaQueryList" => false, "MediaQueryListEvent" => false, "MediaRecorder" => false, - "MediaSettingsRange" => false, + "MediaRecorderErrorEvent" => false, + "MediaSession" => false, "MediaSource" => false, + "MediaSourceHandle" => false, "MediaStream" => false, "MediaStreamAudioDestinationNode" => false, "MediaStreamAudioSourceNode" => false, - "MediaStreamConstraints" => false, "MediaStreamEvent" => false, "MediaStreamTrack" => false, + "MediaStreamTrackAudioSourceNode" => false, + "MediaStreamTrackAudioStats" => false, "MediaStreamTrackEvent" => false, + "MediaStreamTrackGenerator" => false, + "MediaStreamTrackProcessor" => false, + "MediaStreamTrackVideoStats" => false, "MessageChannel" => false, "MessageEvent" => false, "MessagePort" => false, "MimeType" => false, "MimeTypeArray" => false, + "ModelGenericSession" => false, + "ModelManager" => false, "MouseEvent" => false, "MutationEvent" => false, "MutationObserver" => false, "MutationRecord" => false, "NamedNodeMap" => false, + "NavigateEvent" => false, + "Navigation" => false, + "NavigationActivation" => false, + "NavigationCurrentEntryChangeEvent" => false, + "NavigationDestination" => false, + "NavigationHistoryEntry" => false, "NavigationPreloadManager" => false, + "NavigationTransition" => false, "Navigator" => false, + "NavigatorLogin" => false, + "NavigatorManagedData" => false, "NavigatorUAData" => false, "NetworkInformation" => false, "Node" => false, "NodeFilter" => false, "NodeIterator" => false, "NodeList" => false, + "NotRestoredReasonDetails" => false, + "NotRestoredReasons" => false, "Notification" => false, + "NotifyPaintEvent" => false, + "OTPCredential" => false, "OfflineAudioCompletionEvent" => false, "OfflineAudioContext" => false, - "OffscreenCanvas" => true, + "OffscreenCanvas" => false, "OffscreenCanvasRenderingContext2D" => false, "Option" => false, + "OrientationSensor" => false, "OscillatorNode" => false, "OverconstrainedError" => false, + "PERSISTENT" => false, + "PageRevealEvent" => false, + "PageSwapEvent" => false, "PageTransitionEvent" => false, "PannerNode" => false, + "PasswordCredential" => false, "Path2D" => false, "PaymentAddress" => false, + "PaymentManager" => false, + "PaymentMethodChangeEvent" => false, "PaymentRequest" => false, "PaymentRequestUpdateEvent" => false, "PaymentResponse" => false, "Performance" => false, + "PerformanceElementTiming" => false, "PerformanceEntry" => false, + "PerformanceEventTiming" => false, + "PerformanceLongAnimationFrameTiming" => false, "PerformanceLongTaskTiming" => false, "PerformanceMark" => false, "PerformanceMeasure" => false, @@ -660,11 +879,15 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "PerformanceObserverEntryList" => false, "PerformancePaintTiming" => false, "PerformanceResourceTiming" => false, + "PerformanceScriptTiming" => false, + "PerformanceServerTiming" => false, "PerformanceTiming" => false, + "PeriodicSyncManager" => false, "PeriodicWave" => false, "PermissionStatus" => false, "Permissions" => false, - "PhotoCapabilities" => false, + "PictureInPictureEvent" => false, + "PictureInPictureWindow" => false, "Plugin" => false, "PluginArray" => false, "PointerEvent" => false, @@ -677,24 +900,36 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "PresentationConnectionList" => false, "PresentationReceiver" => false, "PresentationRequest" => false, + "PressureObserver" => false, + "PressureRecord" => false, "ProcessingInstruction" => false, + "Profiler" => false, "ProgressEvent" => false, "PromiseRejectionEvent" => false, + "ProtectedAudience" => false, + "PublicKeyCredential" => false, "PushManager" => false, "PushSubscription" => false, "PushSubscriptionOptions" => false, "RTCCertificate" => false, + "RTCDTMFSender" => false, + "RTCDTMFToneChangeEvent" => false, "RTCDataChannel" => false, "RTCDataChannelEvent" => false, "RTCDtlsTransport" => false, + "RTCEncodedAudioFrame" => false, + "RTCEncodedVideoFrame" => false, + "RTCError" => false, + "RTCErrorEvent" => false, "RTCIceCandidate" => false, - "RTCIceGatherer" => false, "RTCIceTransport" => false, "RTCPeerConnection" => false, + "RTCPeerConnectionIceErrorEvent" => false, "RTCPeerConnectionIceEvent" => false, - "RTCRtpContributingSource" => false, "RTCRtpReceiver" => false, + "RTCRtpScriptTransform" => false, "RTCRtpSender" => false, + "RTCRtpTransceiver" => false, "RTCSctpTransport" => false, "RTCSessionDescription" => false, "RTCStatsReport" => false, @@ -707,10 +942,13 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "ReadableStreamBYOBRequest" => false, "ReadableStreamDefaultController" => false, "ReadableStreamDefaultReader" => false, + "RelativeOrientationSensor" => false, "RemotePlayback" => false, + "ReportingObserver" => false, "Request" => false, "ResizeObserver" => false, "ResizeObserverEntry" => false, + "ResizeObserverSize" => false, "Response" => false, "SVGAElement" => false, "SVGAngle" => false, @@ -735,7 +973,6 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "SVGComponentTransferFunctionElement" => false, "SVGDefsElement" => false, "SVGDescElement" => false, - "SVGDiscardElement" => false, "SVGElement" => false, "SVGEllipseElement" => false, "SVGFEBlendElement" => false, @@ -810,41 +1047,69 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "SVGUnitTypes" => false, "SVGUseElement" => false, "SVGViewElement" => false, + "Scheduler" => false, + "Scheduling" => false, "Screen" => false, + "ScreenDetailed" => false, + "ScreenDetails" => false, "ScreenOrientation" => false, "ScriptProcessorNode" => false, + "ScrollTimeline" => false, "SecurityPolicyViolationEvent" => false, "Selection" => false, + "Sensor" => false, + "SensorErrorEvent" => false, + "Serial" => false, + "SerialPort" => false, "ServiceWorker" => false, "ServiceWorkerContainer" => false, "ServiceWorkerRegistration" => false, "ShadowRoot" => false, + "SharedStorage" => false, + "SharedStorageWorklet" => false, "SharedWorker" => false, + "SnapEvent" => false, "SourceBuffer" => false, "SourceBufferList" => false, + "SpeechSynthesis" => false, + "SpeechSynthesisErrorEvent" => false, "SpeechSynthesisEvent" => false, "SpeechSynthesisUtterance" => false, + "SpeechSynthesisVoice" => false, "StaticRange" => false, "StereoPannerNode" => false, "Storage" => false, + "StorageBucket" => false, + "StorageBucketManager" => false, "StorageEvent" => false, "StorageManager" => false, + "StylePropertyMap" => false, + "StylePropertyMapReadOnly" => false, "StyleSheet" => false, "StyleSheetList" => false, "SubmitEvent" => false, "SubtleCrypto" => false, + "SyncManager" => false, + "TEMPORARY" => false, "TaskAttributionTiming" => false, + "TaskController" => false, + "TaskPriorityChangeEvent" => false, + "TaskSignal" => false, "Text" => false, "TextDecoder" => false, "TextDecoderStream" => false, "TextEncoder" => false, "TextEncoderStream" => false, "TextEvent" => false, + "TextFormat" => false, + "TextFormatUpdateEvent" => false, "TextMetrics" => false, "TextTrack" => false, "TextTrackCue" => false, "TextTrackCueList" => false, "TextTrackList" => false, + "TextUpdateEvent" => false, + "TimeEvent" => false, "TimeRanges" => false, "ToggleEvent" => false, "Touch" => false, @@ -855,12 +1120,47 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "TransformStreamDefaultController" => false, "TransitionEvent" => false, "TreeWalker" => false, + "TrustedHTML" => false, + "TrustedScript" => false, + "TrustedScriptURL" => false, + "TrustedTypePolicy" => false, + "TrustedTypePolicyFactory" => false, "UIEvent" => false, "URL" => false, + "URLPattern" => false, "URLSearchParams" => false, + "USB" => false, + "USBAlternateInterface" => false, + "USBConfiguration" => false, + "USBConnectionEvent" => false, + "USBDevice" => false, + "USBEndpoint" => false, + "USBInTransferResult" => false, + "USBInterface" => false, + "USBIsochronousInTransferPacket" => false, + "USBIsochronousInTransferResult" => false, + "USBIsochronousOutTransferPacket" => false, + "USBIsochronousOutTransferResult" => false, + "USBOutTransferResult" => false, + "UserActivation" => false, "VTTCue" => false, + "VTTRegion" => false, "ValidityState" => false, + "VideoColorSpace" => false, + "VideoDecoder" => false, + "VideoEncoder" => false, + "VideoFrame" => false, + "VideoPlaybackQuality" => false, + "ViewTimeline" => false, + "ViewTransition" => false, + "ViewTransitionTypeSet" => false, + "VirtualKeyboard" => false, + "VirtualKeyboardGeometryChangeEvent" => false, + "VisibilityStateEntry" => false, "VisualViewport" => false, + "WGSLLanguageFeatures" => false, + "WakeLock" => false, + "WakeLockSentinel" => false, "WaveShaperNode" => false, "WebAssembly" => false, "WebGL2RenderingContext" => false, @@ -868,6 +1168,7 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "WebGLBuffer" => false, "WebGLContextEvent" => false, "WebGLFramebuffer" => false, + "WebGLObject" => false, "WebGLProgram" => false, "WebGLQuery" => false, "WebGLRenderbuffer" => false, @@ -881,9 +1182,21 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "WebGLUniformLocation" => false, "WebGLVertexArrayObject" => false, "WebSocket" => false, + "WebSocketError" => false, + "WebSocketStream" => false, + "WebTransport" => false, + "WebTransportBidirectionalStream" => false, + "WebTransportDatagramDuplexStream" => false, + "WebTransportError" => false, + "WebTransportReceiveStream" => false, + "WebTransportSendStream" => false, "WheelEvent" => false, "Window" => false, + "WindowControlsOverlay" => false, + "WindowControlsOverlayGeometryChangeEvent" => false, "Worker" => false, + "Worklet" => false, + "WorkletGlobalScope" => false, "WritableStream" => false, "WritableStreamDefaultController" => false, "WritableStreamDefaultWriter" => false, @@ -896,15 +1209,24 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "XPathExpression" => false, "XPathResult" => false, "XRAnchor" => false, + "XRAnchorSet" => false, "XRBoundedReferenceSpace" => false, "XRCPUDepthInformation" => false, + "XRCamera" => false, + "XRDOMOverlayState" => false, "XRDepthInformation" => false, "XRFrame" => false, + "XRHitTestResult" => false, + "XRHitTestSource" => false, "XRInputSource" => false, "XRInputSourceArray" => false, "XRInputSourceEvent" => false, "XRInputSourcesChangeEvent" => false, + "XRLayer" => false, + "XRLightEstimate" => false, + "XRLightProbe" => false, "XRPose" => false, + "XRRay" => false, "XRReferenceSpace" => false, "XRReferenceSpaceEvent" => false, "XRRenderState" => false, @@ -913,6 +1235,8 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "XRSessionEvent" => false, "XRSpace" => false, "XRSystem" => false, + "XRTransientInputHitTestResult" => false, + "XRTransientInputHitTestSource" => false, "XRView" => false, "XRViewerPose" => false, "XRViewport" => false, @@ -921,8 +1245,8 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "XRWebGLLayer" => false, "XSLTProcessor" => false, "addEventListener" => false, + "ai" => false, "alert" => false, - "applicationCache" => false, "atob" => false, "blur" => false, "btoa" => false, @@ -936,49 +1260,64 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "closed" => false, "confirm" => false, "console" => false, + "cookieStore" => false, "createImageBitmap" => false, + "credentialless" => false, + "crossOriginIsolated" => false, "crypto" => false, + "currentFrame" => false, + "currentTime" => false, "customElements" => false, - "defaultStatus" => false, - "defaultstatus" => false, "devicePixelRatio" => false, "dispatchEvent" => false, "document" => false, + "documentPictureInPicture" => false, "event" => false, "external" => false, + "fence" => false, "fetch" => false, + "fetchLater" => false, "find" => false, "focus" => false, "frameElement" => false, "frames" => false, "getComputedStyle" => false, + "getScreenDetails" => false, "getSelection" => false, "history" => false, "indexedDB" => false, "innerHeight" => false, "innerWidth" => false, "isSecureContext" => false, + "launchQueue" => false, "length" => false, "localStorage" => false, "location" => true, "locationbar" => false, "matchMedia" => false, "menubar" => false, + "model" => false, "moveBy" => false, "moveTo" => false, "name" => false, + "navigation" => false, "navigator" => false, "offscreenBuffering" => false, "onabort" => true, "onafterprint" => true, + "onanimationcancel" => true, "onanimationend" => true, "onanimationiteration" => true, "onanimationstart" => true, "onappinstalled" => true, "onauxclick" => true, + "onbeforeinput" => true, "onbeforeinstallprompt" => true, + "onbeforematch" => true, "onbeforeprint" => true, + "onbeforetoggle" => true, "onbeforeunload" => true, + "onbeforexrselect" => true, "onblur" => true, "oncancel" => true, "oncanplay" => true, @@ -986,8 +1325,13 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "onchange" => true, "onclick" => true, "onclose" => true, + "oncontentvisibilityautostatechange" => true, + "oncontextlost" => true, "oncontextmenu" => true, + "oncontextrestored" => true, + "oncopy" => true, "oncuechange" => true, + "oncut" => true, "ondblclick" => true, "ondevicemotion" => true, "ondeviceorientation" => true, @@ -1004,6 +1348,9 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "onended" => true, "onerror" => true, "onfocus" => true, + "onformdata" => true, + "ongamepadconnected" => true, + "ongamepaddisconnected" => true, "ongotpointercapture" => true, "onhashchange" => true, "oninput" => true, @@ -1030,7 +1377,10 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "onoffline" => true, "ononline" => true, "onpagehide" => true, + "onpagereveal" => true, "onpageshow" => true, + "onpageswap" => true, + "onpaste" => true, "onpause" => true, "onplay" => true, "onplaying" => true, @@ -1041,6 +1391,7 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "onpointermove" => true, "onpointerout" => true, "onpointerover" => true, + "onpointerrawupdate" => true, "onpointerup" => true, "onpopstate" => true, "onprogress" => true, @@ -1049,26 +1400,36 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "onreset" => true, "onresize" => true, "onscroll" => true, + "onscrollend" => true, + "onscrollsnapchange" => true, + "onscrollsnapchanging" => true, "onsearch" => true, + "onsecuritypolicyviolation" => true, "onseeked" => true, "onseeking" => true, "onselect" => true, + "onselectionchange" => true, + "onselectstart" => true, + "onslotchange" => true, "onstalled" => true, "onstorage" => true, "onsubmit" => true, "onsuspend" => true, "ontimeupdate" => true, "ontoggle" => true, + "ontransitioncancel" => true, "ontransitionend" => true, + "ontransitionrun" => true, + "ontransitionstart" => true, "onunhandledrejection" => true, "onunload" => true, "onvolumechange" => true, "onwaiting" => true, "onwheel" => true, "open" => false, - "openDatabase" => false, "opener" => false, "origin" => false, + "originAgentCluster" => false, "outerHeight" => false, "outerWidth" => false, "pageXOffset" => false, @@ -1079,6 +1440,7 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "postMessage" => false, "print" => false, "prompt" => false, + "queryLocalFonts" => false, "queueMicrotask" => false, "registerProcessor" => false, "removeEventListener" => false, @@ -1087,6 +1449,8 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "requestIdleCallback" => false, "resizeBy" => false, "resizeTo" => false, + "sampleRate" => false, + "scheduler" => false, "screen" => false, "screenLeft" => false, "screenTop" => false, @@ -1102,6 +1466,10 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "sessionStorage" => false, "setInterval" => false, "setTimeout" => false, + "sharedStorage" => false, + "showDirectoryPicker" => false, + "showOpenFilePicker" => false, + "showSaveFilePicker" => false, "speechSynthesis" => false, "status" => false, "statusbar" => false, @@ -1110,6 +1478,7 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "styleMedia" => false, "toolbar" => false, "top" => false, + "trustedTypes" => false, "visualViewport" => false, "window" => false, }, @@ -1132,10 +1501,12 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "File" => false, "FormData" => false, "Headers" => false, - "Intl" => false, + "Iterator" => false, "MessageChannel" => false, "MessageEvent" => false, "MessagePort" => false, + "Navigator" => false, + "Performance" => false, "PerformanceEntry" => false, "PerformanceMark" => false, "PerformanceMeasure" => false, @@ -1160,6 +1531,7 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "URL" => false, "URLSearchParams" => false, "WebAssembly" => false, + "WebSocket" => false, "WritableStream" => false, "WritableStreamDefaultController" => false, "WritableStreamDefaultWriter" => false, @@ -1176,6 +1548,7 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "fetch" => false, "global" => false, "module" => false, + "navigator" => false, "performance" => false, "process" => false, "queueMicrotask" => false, @@ -1203,10 +1576,12 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "File" => false, "FormData" => false, "Headers" => false, - "Intl" => false, + "Iterator" => false, "MessageChannel" => false, "MessageEvent" => false, "MessagePort" => false, + "Navigator" => false, + "Performance" => false, "PerformanceEntry" => false, "PerformanceMark" => false, "PerformanceMeasure" => false, @@ -1231,6 +1606,7 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "URL" => false, "URLSearchParams" => false, "WebAssembly" => false, + "WebSocket" => false, "WritableStream" => false, "WritableStreamDefaultController" => false, "WritableStreamDefaultWriter" => false, @@ -1241,6 +1617,7 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "console" => false, "crypto" => false, "fetch" => false, + "navigator" => false, "performance" => false, "queueMicrotask" => false, "setInterval" => false, @@ -1248,21 +1625,99 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "structuredClone" => false, }, "worker" => phf_map! { + "AbortController" => false, + "AbortSignal" => false, + "AudioData" => false, + "AudioDecoder" => false, + "AudioEncoder" => false, + "BackgroundFetchManager" => false, + "BackgroundFetchRecord" => false, + "BackgroundFetchRegistration" => false, + "BarcodeDetector" => false, "Blob" => false, "BroadcastChannel" => false, "ByteLengthQueuingStrategy" => false, + "CSSSkewX" => false, + "CSSSkewY" => false, "Cache" => false, + "CacheStorage" => false, + "CanvasGradient" => false, + "CanvasPattern" => false, + "CloseEvent" => false, "CompressionStream" => false, "CountQueuingStrategy" => false, + "CropTarget" => false, "Crypto" => false, "CryptoKey" => false, "CustomEvent" => false, + "DOMException" => false, + "DOMMatrix" => false, + "DOMMatrixReadOnly" => false, + "DOMPoint" => false, + "DOMPointReadOnly" => false, + "DOMQuad" => false, + "DOMRect" => false, + "DOMRectReadOnly" => false, + "DOMStringList" => false, "DecompressionStream" => false, + "DedicatedWorkerGlobalScope" => false, + "EncodedAudioChunk" => false, + "EncodedVideoChunk" => false, "ErrorEvent" => false, "Event" => false, + "EventSource" => false, + "EventTarget" => false, "File" => false, + "FileList" => false, + "FileReader" => false, "FileReaderSync" => false, + "FileSystemDirectoryHandle" => false, + "FileSystemFileHandle" => false, + "FileSystemHandle" => false, + "FileSystemSyncAccessHandle" => false, + "FileSystemWritableFileStream" => false, + "FontFace" => false, "FormData" => false, + "GPU" => false, + "GPUAdapter" => false, + "GPUAdapterInfo" => false, + "GPUBindGroup" => false, + "GPUBindGroupLayout" => false, + "GPUBuffer" => false, + "GPUBufferUsage" => false, + "GPUCanvasContext" => false, + "GPUColorWrite" => false, + "GPUCommandBuffer" => false, + "GPUCommandEncoder" => false, + "GPUCompilationInfo" => false, + "GPUCompilationMessage" => false, + "GPUComputePassEncoder" => false, + "GPUComputePipeline" => false, + "GPUDevice" => false, + "GPUDeviceLostInfo" => false, + "GPUError" => false, + "GPUExternalTexture" => false, + "GPUInternalError" => false, + "GPUMapMode" => false, + "GPUOutOfMemoryError" => false, + "GPUPipelineError" => false, + "GPUPipelineLayout" => false, + "GPUQuerySet" => false, + "GPUQueue" => false, + "GPURenderBundle" => false, + "GPURenderBundleEncoder" => false, + "GPURenderPassEncoder" => false, + "GPURenderPipeline" => false, + "GPUSampler" => false, + "GPUShaderModule" => false, + "GPUShaderStage" => false, + "GPUSupportedFeatures" => false, + "GPUSupportedLimits" => false, + "GPUTexture" => false, + "GPUTextureUsage" => false, + "GPUTextureView" => false, + "GPUUncapturedErrorEvent" => false, + "GPUValidationError" => false, "Headers" => false, "IDBCursor" => false, "IDBCursorWithValue" => false, @@ -1275,80 +1730,190 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "IDBRequest" => false, "IDBTransaction" => false, "IDBVersionChangeEvent" => false, + "IdleDetector" => false, + "ImageBitmap" => false, + "ImageBitmapRenderingContext" => false, "ImageData" => false, + "ImageDecoder" => false, + "ImageTrack" => false, + "ImageTrackList" => false, + "Iterator" => false, + "Lock" => false, + "LockManager" => false, + "MediaCapabilities" => false, + "MediaSource" => false, + "MediaSourceHandle" => false, "MessageChannel" => false, "MessageEvent" => false, "MessagePort" => false, + "NavigationPreloadManager" => false, + "NavigatorUAData" => false, + "NetworkInformation" => false, "Notification" => false, + "OffscreenCanvas" => false, + "OffscreenCanvasRenderingContext2D" => false, + "PERSISTENT" => false, + "Path2D" => false, "Performance" => false, "PerformanceEntry" => false, "PerformanceMark" => false, "PerformanceMeasure" => false, - "PerformanceNavigation" => false, "PerformanceObserver" => false, "PerformanceObserverEntryList" => false, "PerformanceResourceTiming" => false, - "PerformanceTiming" => false, - "Promise" => false, + "PerformanceServerTiming" => false, + "PeriodicSyncManager" => false, + "PermissionStatus" => false, + "Permissions" => false, + "PressureObserver" => false, + "PressureRecord" => false, + "ProgressEvent" => false, + "PromiseRejectionEvent" => false, + "PushManager" => false, + "PushSubscription" => false, + "PushSubscriptionOptions" => false, + "RTCEncodedAudioFrame" => false, + "RTCEncodedVideoFrame" => false, "ReadableByteStreamController" => false, "ReadableStream" => false, "ReadableStreamBYOBReader" => false, "ReadableStreamBYOBRequest" => false, "ReadableStreamDefaultController" => false, "ReadableStreamDefaultReader" => false, + "ReportingObserver" => false, "Request" => false, "Response" => false, + "Scheduler" => false, + "SecurityPolicyViolationEvent" => false, + "Serial" => false, + "SerialPort" => false, "ServiceWorkerRegistration" => false, + "SourceBuffer" => false, + "SourceBufferList" => false, + "StorageBucket" => false, + "StorageBucketManager" => false, + "StorageManager" => false, "SubtleCrypto" => false, + "SyncManager" => false, + "TEMPORARY" => false, + "TaskController" => false, + "TaskPriorityChangeEvent" => false, + "TaskSignal" => false, "TextDecoder" => false, "TextDecoderStream" => false, "TextEncoder" => false, "TextEncoderStream" => false, + "TextMetrics" => false, "TransformStream" => false, "TransformStreamDefaultController" => false, + "TrustedHTML" => false, + "TrustedScript" => false, + "TrustedScriptURL" => false, + "TrustedTypePolicy" => false, + "TrustedTypePolicyFactory" => false, "URL" => false, + "URLPattern" => false, "URLSearchParams" => false, + "USB" => false, + "USBAlternateInterface" => false, + "USBConfiguration" => false, + "USBConnectionEvent" => false, + "USBDevice" => false, + "USBEndpoint" => false, + "USBInTransferResult" => false, + "USBInterface" => false, + "USBIsochronousInTransferPacket" => false, + "USBIsochronousInTransferResult" => false, + "USBIsochronousOutTransferPacket" => false, + "USBIsochronousOutTransferResult" => false, + "USBOutTransferResult" => false, + "UserActivation" => false, + "VideoColorSpace" => false, + "VideoDecoder" => false, + "VideoEncoder" => false, + "VideoFrame" => false, + "WGSLLanguageFeatures" => false, "WebAssembly" => false, + "WebGL2RenderingContext" => false, + "WebGLActiveInfo" => false, + "WebGLBuffer" => false, + "WebGLContextEvent" => false, + "WebGLFramebuffer" => false, + "WebGLObject" => false, + "WebGLProgram" => false, + "WebGLQuery" => false, + "WebGLRenderbuffer" => false, + "WebGLRenderingContext" => false, + "WebGLSampler" => false, + "WebGLShader" => false, + "WebGLShaderPrecisionFormat" => false, + "WebGLSync" => false, + "WebGLTexture" => false, + "WebGLTransformFeedback" => false, + "WebGLUniformLocation" => false, + "WebGLVertexArrayObject" => false, "WebSocket" => false, + "WebSocketError" => false, + "WebSocketStream" => false, + "WebTransport" => false, + "WebTransportBidirectionalStream" => false, + "WebTransportDatagramDuplexStream" => false, + "WebTransportError" => false, "Worker" => false, "WorkerGlobalScope" => false, + "WorkerLocation" => false, + "WorkerNavigator" => false, "WritableStream" => false, "WritableStreamDefaultController" => false, "WritableStreamDefaultWriter" => false, "XMLHttpRequest" => false, + "XMLHttpRequestEventTarget" => false, + "XMLHttpRequestUpload" => false, "addEventListener" => false, - "applicationCache" => false, + "ai" => false, "atob" => false, "btoa" => false, "caches" => false, + "cancelAnimationFrame" => false, "clearInterval" => false, "clearTimeout" => false, - "close" => true, + "close" => false, "console" => false, + "createImageBitmap" => false, + "crossOriginIsolated" => false, "crypto" => false, + "dispatchEvent" => false, "fetch" => false, - "importScripts" => true, + "fonts" => false, + "importScripts" => false, "indexedDB" => false, + "isSecureContext" => false, "location" => false, "name" => false, "navigator" => false, - "onclose" => true, - "onconnect" => true, "onerror" => true, "onlanguagechange" => true, "onmessage" => true, - "onoffline" => true, - "ononline" => true, + "onmessageerror" => true, "onrejectionhandled" => true, "onunhandledrejection" => true, + "origin" => false, "performance" => false, - "postMessage" => true, + "postMessage" => false, "queueMicrotask" => false, "removeEventListener" => false, "reportError" => false, - "self" => true, + "requestAnimationFrame" => false, + "scheduler" => false, + "self" => false, "setInterval" => false, "setTimeout" => false, + "structuredClone" => false, + "trustedTypes" => false, + "webkitRequestFileSystem" => false, + "webkitRequestFileSystemSync" => false, + "webkitResolveLocalFileSystemSyncURL" => false, + "webkitResolveLocalFileSystemURL" => false, }, "serviceworker" => phf_map! { "Blob" => false, @@ -1398,7 +1963,6 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "PerformanceObserverEntryList" => false, "PerformanceResourceTiming" => false, "PerformanceTiming" => false, - "Promise" => false, "ReadableByteStreamController" => false, "ReadableStream" => false, "ReadableStreamBYOBReader" => false, @@ -1536,12 +2100,9 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "beforeEach" => false, "describe" => false, "expect" => false, - "fdescribe" => false, "fit" => false, "it" => false, "jest" => false, - "pit" => false, - "require" => false, "test" => false, "xdescribe" => false, "xit" => false, @@ -1620,6 +2181,7 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "Try" => false, }, "shelljs" => phf_map! { + "ShellString" => false, "cat" => false, "cd" => false, "chmod" => false, @@ -1633,6 +2195,7 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "exit" => false, "find" => false, "grep" => false, + "head" => false, "ln" => false, "ls" => false, "mkdir" => false, @@ -1643,10 +2206,12 @@ pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { "rm" => false, "sed" => false, "set" => false, - "target" => false, + "sort" => false, + "tail" => false, "tempdir" => false, "test" => false, "touch" => false, + "uniq" => false, "which" => false, }, "meteor" => phf_map! { diff --git a/crates/oxc_linter/src/rules/eslint/no_undef.rs b/crates/oxc_linter/src/rules/eslint/no_undef.rs index b2acc94262b750..959521a1fbb845 100644 --- a/crates/oxc_linter/src/rules/eslint/no_undef.rs +++ b/crates/oxc_linter/src/rules/eslint/no_undef.rs @@ -96,8 +96,6 @@ fn test() { // "/*eslint-env browser*/ window;", // "/*eslint-env node*/ require(\"a\");", "Object; isNaN();", - "toString()", - "hasOwnProperty()", "function evilEval(stuffToEval) { var ultimateAnswer; ultimateAnswer = 42; eval(stuffToEval); }", "typeof a", "typeof (a)", @@ -184,6 +182,8 @@ fn test() { "class C { static { let a; } [a]; }", "class C { static { function a() {} } [a]; }", "class C { static { var a; } } a;", + "toString()", + "hasOwnProperty()", ]; Tester::new(NoUndef::NAME, pass, fail).test_and_snapshot(); diff --git a/crates/oxc_linter/src/snapshots/no_undef.snap b/crates/oxc_linter/src/snapshots/no_undef.snap index a39f570593d8ef..ab1fd2134de645 100644 --- a/crates/oxc_linter/src/snapshots/no_undef.snap +++ b/crates/oxc_linter/src/snapshots/no_undef.snap @@ -156,3 +156,15 @@ source: crates/oxc_linter/src/tester.rs 1 │ class C { static { var a; } } a; · ─ ╰──── + + ⚠ eslint(no-undef): 'toString' is not defined. + ╭─[no_undef.tsx:1:1] + 1 │ toString() + · ──────── + ╰──── + + ⚠ eslint(no-undef): 'hasOwnProperty' is not defined. + ╭─[no_undef.tsx:1:1] + 1 │ hasOwnProperty() + · ────────────── + ╰──── diff --git a/tasks/javascript_globals/template.hbs b/tasks/javascript_globals/template.hbs index 55463e99311aae..5f17e8a577d6ea 100644 --- a/tasks/javascript_globals/template.hbs +++ b/tasks/javascript_globals/template.hbs @@ -1,6 +1,9 @@ +// Auto-generated code, DO NOT EDIT DIRECTLY! +// To edit this generated file you have to run `cargo run -p javascript_globals`. + use phf::{phf_map, Map}; -pub static ENVIRONMENTS: Map<&'static str, Map<&'static str, bool>> = phf_map! { +pub static GLOBALS: Map<&'static str, Map<&'static str, bool>> = phf_map! { {{#each envs }} "{{name}}" => phf_map! { {{#each vars}} From 63e8bfeeecd3d0b8d8d4657755d218a6f408d6c0 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Tue, 29 Oct 2024 13:00:48 +0000 Subject: [PATCH 04/12] refactor(transformer): rename `AString` to `ArenaString` (#6997) Part of #6996. --- crates/oxc_transformer/src/common/helper_loader.rs | 4 ++-- crates/oxc_transformer/src/es2022/class_static_block.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/oxc_transformer/src/common/helper_loader.rs b/crates/oxc_transformer/src/common/helper_loader.rs index 7169223514624f..326abe26025e34 100644 --- a/crates/oxc_transformer/src/common/helper_loader.rs +++ b/crates/oxc_transformer/src/common/helper_loader.rs @@ -70,7 +70,7 @@ use std::{borrow::Cow, cell::RefCell}; use rustc_hash::FxHashMap; use serde::Deserialize; -use oxc_allocator::{String as AString, Vec}; +use oxc_allocator::{String as ArenaString, Vec}; use oxc_ast::ast::{Argument, CallExpression, Expression, TSTypeParameterInstantiation}; use oxc_semantic::{ReferenceFlags, SymbolFlags}; use oxc_span::{Atom, SPAN}; @@ -247,7 +247,7 @@ impl<'a> HelperLoaderStore<'a> { // Construct string directly in arena without an intermediate temp allocation let len = self.module_name.len() + "/helpers/".len() + helper_name.len(); - let mut source = AString::with_capacity_in(len, ctx.ast.allocator); + let mut source = ArenaString::with_capacity_in(len, ctx.ast.allocator); source.push_str(&self.module_name); source.push_str("/helpers/"); source.push_str(helper_name); diff --git a/crates/oxc_transformer/src/es2022/class_static_block.rs b/crates/oxc_transformer/src/es2022/class_static_block.rs index 8f637a61f71dfb..233df0d48b4421 100644 --- a/crates/oxc_transformer/src/es2022/class_static_block.rs +++ b/crates/oxc_transformer/src/es2022/class_static_block.rs @@ -41,7 +41,7 @@ use itoa::Buffer as ItoaBuffer; -use oxc_allocator::String as AString; +use oxc_allocator::String as ArenaString; use oxc_ast::{ast::*, Visit, NONE}; use oxc_semantic::SymbolTable; use oxc_span::SPAN; @@ -295,7 +295,7 @@ impl<'a> Keys<'a> { i += 1; } - let mut key = AString::with_capacity_in(num_str.len() + 1, ctx.ast.allocator); + let mut key = ArenaString::with_capacity_in(num_str.len() + 1, ctx.ast.allocator); key.push('_'); key.push_str(num_str); let key = Atom::from(key.into_bump_str()); From fc1af2e9dad5982ec89eec847677a3b4acb84f58 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Tue, 29 Oct 2024 13:00:48 +0000 Subject: [PATCH 05/12] refactor(transformer): import `oxc_allocator::Vec` as `ArenaVec` (#6998) Part of #6996. --- .../oxc_transformer/src/common/helper_loader.rs | 6 +++--- crates/oxc_transformer/src/common/mod.rs | 14 +++++++++++--- .../src/common/statement_injector.rs | 6 +++--- .../src/common/var_declarations.rs | 14 +++++++++----- .../src/es2015/arrow_functions.rs | 4 ++-- .../src/es2016/exponentiation_operator.rs | 16 ++++++++-------- crates/oxc_transformer/src/jsx/jsx_impl.rs | 4 ++-- crates/oxc_transformer/src/lib.rs | 14 +++++++++++--- crates/oxc_transformer/src/typescript/enum.rs | 6 +++--- crates/oxc_transformer/src/typescript/mod.rs | 14 +++++++++++--- .../oxc_transformer/src/typescript/namespace.rs | 10 +++++----- 11 files changed, 68 insertions(+), 40 deletions(-) diff --git a/crates/oxc_transformer/src/common/helper_loader.rs b/crates/oxc_transformer/src/common/helper_loader.rs index 326abe26025e34..418b32c3f851b0 100644 --- a/crates/oxc_transformer/src/common/helper_loader.rs +++ b/crates/oxc_transformer/src/common/helper_loader.rs @@ -70,7 +70,7 @@ use std::{borrow::Cow, cell::RefCell}; use rustc_hash::FxHashMap; use serde::Deserialize; -use oxc_allocator::{String as ArenaString, Vec}; +use oxc_allocator::{String as ArenaString, Vec as ArenaVec}; use oxc_ast::ast::{Argument, CallExpression, Expression, TSTypeParameterInstantiation}; use oxc_semantic::{ReferenceFlags, SymbolFlags}; use oxc_span::{Atom, SPAN}; @@ -175,7 +175,7 @@ impl<'a> TransformCtx<'a> { pub fn helper_call( &self, helper: Helper, - arguments: Vec<'a, Argument<'a>>, + arguments: ArenaVec<'a, Argument<'a>>, ctx: &mut TraverseCtx<'a>, ) -> CallExpression<'a> { let callee = self.helper_load(helper, ctx); @@ -192,7 +192,7 @@ impl<'a> TransformCtx<'a> { pub fn helper_call_expr( &self, helper: Helper, - arguments: Vec<'a, Argument<'a>>, + arguments: ArenaVec<'a, Argument<'a>>, ctx: &mut TraverseCtx<'a>, ) -> Expression<'a> { let callee = self.helper_load(helper, ctx); diff --git a/crates/oxc_transformer/src/common/mod.rs b/crates/oxc_transformer/src/common/mod.rs index 50fd24a4b166c5..56d10c6bed5001 100644 --- a/crates/oxc_transformer/src/common/mod.rs +++ b/crates/oxc_transformer/src/common/mod.rs @@ -1,6 +1,6 @@ //! Utility transforms which are in common between other transforms. -use oxc_allocator::Vec; +use oxc_allocator::Vec as ArenaVec; use oxc_ast::ast::*; use oxc_traverse::{Traverse, TraverseCtx}; @@ -42,11 +42,19 @@ impl<'a, 'ctx> Traverse<'a> for Common<'a, 'ctx> { self.top_level_statements.exit_program(program, ctx); } - fn enter_statements(&mut self, stmts: &mut Vec<'a, Statement<'a>>, ctx: &mut TraverseCtx<'a>) { + fn enter_statements( + &mut self, + stmts: &mut ArenaVec<'a, Statement<'a>>, + ctx: &mut TraverseCtx<'a>, + ) { self.var_declarations.enter_statements(stmts, ctx); } - fn exit_statements(&mut self, stmts: &mut Vec<'a, Statement<'a>>, ctx: &mut TraverseCtx<'a>) { + fn exit_statements( + &mut self, + stmts: &mut ArenaVec<'a, Statement<'a>>, + ctx: &mut TraverseCtx<'a>, + ) { self.var_declarations.exit_statements(stmts, ctx); self.statement_injector.exit_statements(stmts, ctx); } diff --git a/crates/oxc_transformer/src/common/statement_injector.rs b/crates/oxc_transformer/src/common/statement_injector.rs index e580eda660efc8..7bb631c4799935 100644 --- a/crates/oxc_transformer/src/common/statement_injector.rs +++ b/crates/oxc_transformer/src/common/statement_injector.rs @@ -14,7 +14,7 @@ use std::cell::RefCell; -use oxc_allocator::{Address, GetAddress, Vec as AVec}; +use oxc_allocator::{Address, GetAddress, Vec as ArenaVec}; use oxc_ast::ast::*; use oxc_traverse::{Traverse, TraverseCtx}; @@ -36,7 +36,7 @@ impl<'a, 'ctx> StatementInjector<'a, 'ctx> { impl<'a, 'ctx> Traverse<'a> for StatementInjector<'a, 'ctx> { fn exit_statements( &mut self, - statements: &mut AVec<'a, Statement<'a>>, + statements: &mut ArenaVec<'a, Statement<'a>>, ctx: &mut TraverseCtx<'a>, ) { self.ctx.statement_injector.insert_into_statements(statements, ctx); @@ -150,7 +150,7 @@ impl<'a> StatementInjectorStore<'a> { /// Insert statements immediately before / after the target statement. fn insert_into_statements( &self, - statements: &mut AVec<'a, Statement<'a>>, + statements: &mut ArenaVec<'a, Statement<'a>>, ctx: &mut TraverseCtx<'a>, ) { let mut insertions = self.insertions.borrow_mut(); diff --git a/crates/oxc_transformer/src/common/var_declarations.rs b/crates/oxc_transformer/src/common/var_declarations.rs index 91ea4f114d929c..ec490f63908a44 100644 --- a/crates/oxc_transformer/src/common/var_declarations.rs +++ b/crates/oxc_transformer/src/common/var_declarations.rs @@ -14,7 +14,7 @@ use std::cell::RefCell; -use oxc_allocator::Vec; +use oxc_allocator::Vec as ArenaVec; use oxc_ast::ast::*; use oxc_data_structures::stack::SparseStack; use oxc_span::SPAN; @@ -39,13 +39,17 @@ impl<'a, 'ctx> VarDeclarations<'a, 'ctx> { impl<'a, 'ctx> Traverse<'a> for VarDeclarations<'a, 'ctx> { fn enter_statements( &mut self, - _stmts: &mut Vec<'a, Statement<'a>>, + _stmts: &mut ArenaVec<'a, Statement<'a>>, _ctx: &mut TraverseCtx<'a>, ) { self.ctx.var_declarations.record_entering_statements(); } - fn exit_statements(&mut self, stmts: &mut Vec<'a, Statement<'a>>, ctx: &mut TraverseCtx<'a>) { + fn exit_statements( + &mut self, + stmts: &mut ArenaVec<'a, Statement<'a>>, + ctx: &mut TraverseCtx<'a>, + ) { self.ctx.var_declarations.insert_into_statements(stmts, ctx); } @@ -56,7 +60,7 @@ impl<'a, 'ctx> Traverse<'a> for VarDeclarations<'a, 'ctx> { /// Store for `VariableDeclarator`s to be added to enclosing statement block. pub struct VarDeclarationsStore<'a> { - stack: RefCell>>>, + stack: RefCell>>>, } // Public methods @@ -107,7 +111,7 @@ impl<'a> VarDeclarationsStore<'a> { fn insert_into_statements( &self, - stmts: &mut Vec<'a, Statement<'a>>, + stmts: &mut ArenaVec<'a, Statement<'a>>, ctx: &mut TraverseCtx<'a>, ) { if matches!(ctx.parent(), Ancestor::ProgramBody(_)) { diff --git a/crates/oxc_transformer/src/es2015/arrow_functions.rs b/crates/oxc_transformer/src/es2015/arrow_functions.rs index 0df81e0caeeb62..a952fec321e7fa 100644 --- a/crates/oxc_transformer/src/es2015/arrow_functions.rs +++ b/crates/oxc_transformer/src/es2015/arrow_functions.rs @@ -126,7 +126,7 @@ use serde::Deserialize; -use oxc_allocator::Vec; +use oxc_allocator::Vec as ArenaVec; use oxc_ast::ast::*; use oxc_data_structures::stack::SparseStack; use oxc_span::SPAN; @@ -405,7 +405,7 @@ impl<'a> ArrowFunctions<'a> { #[expect(clippy::unused_self)] fn insert_this_var_statement_at_the_top_of_statements( &mut self, - statements: &mut Vec<'a, Statement<'a>>, + statements: &mut ArenaVec<'a, Statement<'a>>, this_var: &BoundIdentifier<'a>, ctx: &TraverseCtx<'a>, ) { diff --git a/crates/oxc_transformer/src/es2016/exponentiation_operator.rs b/crates/oxc_transformer/src/es2016/exponentiation_operator.rs index 4e94db22e18f01..2afd099f500f67 100644 --- a/crates/oxc_transformer/src/es2016/exponentiation_operator.rs +++ b/crates/oxc_transformer/src/es2016/exponentiation_operator.rs @@ -32,7 +32,7 @@ //! * Exponentiation operator TC39 proposal: //! * Exponentiation operator specification: -use oxc_allocator::{CloneIn, Vec}; +use oxc_allocator::{CloneIn, Vec as ArenaVec}; use oxc_ast::{ast::*, NONE}; use oxc_semantic::{ReferenceFlags, SymbolFlags}; use oxc_span::SPAN; @@ -149,7 +149,7 @@ impl<'a, 'ctx> ExponentiationOperator<'a, 'ctx> { // Left side of `Math.pow(pow_left, ...)` Expression<'a>, // Temporary var initializations - Vec<'a, Expression<'a>>, + ArenaVec<'a, Expression<'a>>, ) { let mut temp_var_inits = ctx.ast.vec(); @@ -232,7 +232,7 @@ impl<'a, 'ctx> ExponentiationOperator<'a, 'ctx> { // Left side of `Math.pow(pow_left, ...)` Expression<'a>, // Temporary var initializations - Vec<'a, Expression<'a>>, + ArenaVec<'a, Expression<'a>>, ) { // Object part of 2nd member expression // ``` @@ -326,7 +326,7 @@ impl<'a, 'ctx> ExponentiationOperator<'a, 'ctx> { // Left side of `Math.pow(pow_left, ...)` Expression<'a>, // Temporary var initializations - Vec<'a, Expression<'a>>, + ArenaVec<'a, Expression<'a>>, ) { // Object part of 2nd member expression // ``` @@ -408,7 +408,7 @@ impl<'a, 'ctx> ExponentiationOperator<'a, 'ctx> { // Left side of `Math.pow(pow_left, ...)` Expression<'a>, // Temporary var initializations - Vec<'a, Expression<'a>>, + ArenaVec<'a, Expression<'a>>, ) { // Object part of 2nd member expression // ``` @@ -482,7 +482,7 @@ impl<'a, 'ctx> ExponentiationOperator<'a, 'ctx> { fn get_second_member_expression_object( &mut self, obj: &mut Expression<'a>, - temp_var_inits: &mut Vec<'a, Expression<'a>>, + temp_var_inits: &mut ArenaVec<'a, Expression<'a>>, ctx: &mut TraverseCtx<'a>, ) -> Expression<'a> { // If the object reference that we need to save is locally declared, evaluating it multiple times @@ -532,7 +532,7 @@ impl<'a, 'ctx> ExponentiationOperator<'a, 'ctx> { /// If needs temp var initializers, replace expression `expr` with `(temp1, temp2, expr)`. fn revise_expression( expr: &mut Expression<'a>, - mut temp_var_inits: Vec<'a, Expression<'a>>, + mut temp_var_inits: ArenaVec<'a, Expression<'a>>, ctx: &mut TraverseCtx<'a>, ) { if !temp_var_inits.is_empty() { @@ -566,7 +566,7 @@ impl<'a, 'ctx> ExponentiationOperator<'a, 'ctx> { fn create_temp_var( &mut self, expr: Expression<'a>, - temp_var_inits: &mut Vec<'a, Expression<'a>>, + temp_var_inits: &mut ArenaVec<'a, Expression<'a>>, ctx: &mut TraverseCtx<'a>, ) -> BoundIdentifier<'a> { let binding = ctx.generate_uid_in_current_scope_based_on_node( diff --git a/crates/oxc_transformer/src/jsx/jsx_impl.rs b/crates/oxc_transformer/src/jsx/jsx_impl.rs index 39af58e77bc672..df96a05f880578 100644 --- a/crates/oxc_transformer/src/jsx/jsx_impl.rs +++ b/crates/oxc_transformer/src/jsx/jsx_impl.rs @@ -88,7 +88,7 @@ //! //! * Babel plugin implementation: -use oxc_allocator::Vec; +use oxc_allocator::Vec as ArenaVec; use oxc_ast::{ast::*, AstBuilder, NONE}; use oxc_ecmascript::PropName; use oxc_span::{Atom, GetSpan, Span, SPAN}; @@ -999,7 +999,7 @@ impl<'a, 'b> JSXElementOrFragment<'a, 'b> { } } - fn children(&self) -> &'b Vec<'a, JSXChild<'a>> { + fn children(&self) -> &'b ArenaVec<'a, JSXChild<'a>> { match self { Self::Element(e) => &e.children, Self::Fragment(e) => &e.children, diff --git a/crates/oxc_transformer/src/lib.rs b/crates/oxc_transformer/src/lib.rs index a75fbd545e380d..1f945142a9759d 100644 --- a/crates/oxc_transformer/src/lib.rs +++ b/crates/oxc_transformer/src/lib.rs @@ -7,7 +7,7 @@ use std::path::Path; -use oxc_allocator::{Allocator, Vec}; +use oxc_allocator::{Allocator, Vec as ArenaVec}; use oxc_ast::{ast::*, AstBuilder}; use oxc_diagnostics::OxcDiagnostic; use oxc_semantic::{ScopeTree, SymbolTable}; @@ -356,7 +356,11 @@ impl<'a, 'ctx> Traverse<'a> for TransformerImpl<'a, 'ctx> { } } - fn enter_statements(&mut self, stmts: &mut Vec<'a, Statement<'a>>, ctx: &mut TraverseCtx<'a>) { + fn enter_statements( + &mut self, + stmts: &mut ArenaVec<'a, Statement<'a>>, + ctx: &mut TraverseCtx<'a>, + ) { self.common.enter_statements(stmts, ctx); if let Some(typescript) = self.x0_typescript.as_mut() { typescript.enter_statements(stmts, ctx); @@ -387,7 +391,11 @@ impl<'a, 'ctx> Traverse<'a> for TransformerImpl<'a, 'ctx> { } } - fn exit_statements(&mut self, stmts: &mut Vec<'a, Statement<'a>>, ctx: &mut TraverseCtx<'a>) { + fn exit_statements( + &mut self, + stmts: &mut ArenaVec<'a, Statement<'a>>, + ctx: &mut TraverseCtx<'a>, + ) { if let Some(typescript) = self.x0_typescript.as_mut() { typescript.exit_statements(stmts, ctx); } diff --git a/crates/oxc_transformer/src/typescript/enum.rs b/crates/oxc_transformer/src/typescript/enum.rs index 291d58f49a61b2..e71d79fab69fb9 100644 --- a/crates/oxc_transformer/src/typescript/enum.rs +++ b/crates/oxc_transformer/src/typescript/enum.rs @@ -1,6 +1,6 @@ use rustc_hash::FxHashMap; -use oxc_allocator::Vec; +use oxc_allocator::Vec as ArenaVec; use oxc_ast::{ast::*, visit::walk_mut, VisitMut, NONE}; use oxc_ecmascript::ToInt32; use oxc_span::{Atom, Span, SPAN}; @@ -181,10 +181,10 @@ impl<'a> TypeScriptEnum<'a> { #[allow(clippy::needless_pass_by_value)] fn transform_ts_enum_members( &mut self, - members: &mut Vec<'a, TSEnumMember<'a>>, + members: &mut ArenaVec<'a, TSEnumMember<'a>>, param: &BindingIdentifier<'a>, ctx: &mut TraverseCtx<'a>, - ) -> Vec<'a, Statement<'a>> { + ) -> ArenaVec<'a, Statement<'a>> { let create_identifier_reference = |ctx: &mut TraverseCtx<'a>| { let ident = ctx.create_bound_reference_id( param.span, diff --git a/crates/oxc_transformer/src/typescript/mod.rs b/crates/oxc_transformer/src/typescript/mod.rs index eab719a6db09ad..be7c907eedf3c3 100644 --- a/crates/oxc_transformer/src/typescript/mod.rs +++ b/crates/oxc_transformer/src/typescript/mod.rs @@ -1,4 +1,4 @@ -use oxc_allocator::Vec; +use oxc_allocator::Vec as ArenaVec; use oxc_ast::ast::*; use oxc_traverse::{Traverse, TraverseCtx}; @@ -197,11 +197,19 @@ impl<'a, 'ctx> Traverse<'a> for TypeScript<'a, 'ctx> { self.annotations.enter_accessor_property(def, ctx); } - fn enter_statements(&mut self, stmts: &mut Vec<'a, Statement<'a>>, ctx: &mut TraverseCtx<'a>) { + fn enter_statements( + &mut self, + stmts: &mut ArenaVec<'a, Statement<'a>>, + ctx: &mut TraverseCtx<'a>, + ) { self.annotations.enter_statements(stmts, ctx); } - fn exit_statements(&mut self, stmts: &mut Vec<'a, Statement<'a>>, ctx: &mut TraverseCtx<'a>) { + fn exit_statements( + &mut self, + stmts: &mut ArenaVec<'a, Statement<'a>>, + ctx: &mut TraverseCtx<'a>, + ) { self.annotations.exit_statements(stmts, ctx); } diff --git a/crates/oxc_transformer/src/typescript/namespace.rs b/crates/oxc_transformer/src/typescript/namespace.rs index 69e4a49e9e410d..d8dafcd2afd784 100644 --- a/crates/oxc_transformer/src/typescript/namespace.rs +++ b/crates/oxc_transformer/src/typescript/namespace.rs @@ -1,6 +1,6 @@ use rustc_hash::FxHashSet; -use oxc_allocator::{Box, Vec}; +use oxc_allocator::{Box, Vec as ArenaVec}; use oxc_ast::{ast::*, NONE}; use oxc_ecmascript::BoundNames; use oxc_span::{Atom, CompactStr, SPAN}; @@ -320,8 +320,8 @@ impl<'a, 'ctx> TypeScriptNamespace<'a, 'ctx> { fn transform_namespace( arg_name: Atom<'a>, real_name: Atom<'a>, - stmts: Vec<'a, Statement<'a>>, - directives: Vec<'a, Directive<'a>>, + stmts: ArenaVec<'a, Statement<'a>>, + directives: ArenaVec<'a, Directive<'a>>, parent_export: Option>, scope_id: ScopeId, ctx: &mut TraverseCtx<'a>, @@ -414,7 +414,7 @@ impl<'a, 'ctx> TypeScriptNamespace<'a, 'ctx> { decl: Declaration<'a>, name: Atom<'a>, names: &mut FxHashSet>, - new_stmts: &mut Vec<'a, Statement<'a>>, + new_stmts: &mut ArenaVec<'a, Statement<'a>>, ctx: &TraverseCtx<'a>, ) { // This function is only called with a function, class, or enum declaration, @@ -449,7 +449,7 @@ impl<'a, 'ctx> TypeScriptNamespace<'a, 'ctx> { mut var_decl: Box<'a, VariableDeclaration<'a>>, name: Atom<'a>, ctx: &TraverseCtx<'a>, - ) -> Vec<'a, Statement<'a>> { + ) -> ArenaVec<'a, Statement<'a>> { let is_all_binding_identifier = var_decl .declarations .iter() From c945fe71b38a005333387f7dc84fcacd345d2916 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Tue, 29 Oct 2024 13:00:49 +0000 Subject: [PATCH 06/12] refactor(transformer): import `oxc_allocator::Box` as `ArenaBox` (#6999) Closes #6996. --- .../src/es2017/async_to_generator.rs | 22 +++++++++---------- .../oxc_transformer/src/jsx/display_name.rs | 4 ++-- .../oxc_transformer/src/typescript/module.rs | 4 ++-- .../src/typescript/namespace.rs | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/crates/oxc_transformer/src/es2017/async_to_generator.rs b/crates/oxc_transformer/src/es2017/async_to_generator.rs index 12ca8f21232e48..ea22f327a94df0 100644 --- a/crates/oxc_transformer/src/es2017/async_to_generator.rs +++ b/crates/oxc_transformer/src/es2017/async_to_generator.rs @@ -53,7 +53,7 @@ use std::mem; -use oxc_allocator::Box; +use oxc_allocator::Box as ArenaBox; use oxc_ast::{ast::*, Visit, NONE}; use oxc_semantic::{ReferenceFlags, ScopeFlags, ScopeId, SymbolFlags}; use oxc_span::{Atom, GetSpan, SPAN}; @@ -467,8 +467,8 @@ impl<'a, 'ctx> AsyncToGenerator<'a, 'ctx> { #[inline] fn create_function( id: Option>, - params: Box<'a, FormalParameters<'a>>, - body: Box<'a, FunctionBody<'a>>, + params: ArenaBox<'a, FormalParameters<'a>>, + body: ArenaBox<'a, FunctionBody<'a>>, scope_id: ScopeId, ctx: &mut TraverseCtx<'a>, ) -> Function<'a> { @@ -536,8 +536,8 @@ impl<'a, 'ctx> AsyncToGenerator<'a, 'ctx> { /// ``` fn create_async_to_generator_call( &self, - params: Box<'a, FormalParameters<'a>>, - body: Box<'a, FunctionBody<'a>>, + params: ArenaBox<'a, FormalParameters<'a>>, + body: ArenaBox<'a, FunctionBody<'a>>, scope_id: ScopeId, ctx: &mut TraverseCtx<'a>, ) -> Expression<'a> { @@ -560,8 +560,8 @@ impl<'a, 'ctx> AsyncToGenerator<'a, 'ctx> { fn create_async_to_generator_declaration( &self, bound_ident: &BoundIdentifier<'a>, - params: Box<'a, FormalParameters<'a>>, - body: Box<'a, FunctionBody<'a>>, + params: ArenaBox<'a, FormalParameters<'a>>, + body: ArenaBox<'a, FunctionBody<'a>>, scope_id: ScopeId, ctx: &mut TraverseCtx<'a>, ) -> Statement<'a> { @@ -592,8 +592,8 @@ impl<'a, 'ctx> AsyncToGenerator<'a, 'ctx> { fn create_async_to_generator_assignment( &self, bound: &BoundIdentifier<'a>, - params: Box<'a, FormalParameters<'a>>, - body: Box<'a, FunctionBody<'a>>, + params: ArenaBox<'a, FormalParameters<'a>>, + body: ArenaBox<'a, FunctionBody<'a>>, scope_id: ScopeId, ctx: &mut TraverseCtx<'a>, ) -> Statement<'a> { @@ -613,7 +613,7 @@ impl<'a, 'ctx> AsyncToGenerator<'a, 'ctx> { params: &FormalParameters<'a>, scope_id: ScopeId, ctx: &mut TraverseCtx<'a>, - ) -> Box<'a, FormalParameters<'a>> { + ) -> ArenaBox<'a, FormalParameters<'a>> { let mut parameters = ctx.ast.vec_with_capacity(params.items.len()); for param in ¶ms.items { if param.pattern.kind.is_assignment_pattern() { @@ -636,7 +636,7 @@ impl<'a, 'ctx> AsyncToGenerator<'a, 'ctx> { /// Creates an empty [FormalParameters] with [FormalParameterKind::FormalParameter]. #[inline] - fn create_empty_params(ctx: &mut TraverseCtx<'a>) -> Box<'a, FormalParameters<'a>> { + fn create_empty_params(ctx: &mut TraverseCtx<'a>) -> ArenaBox<'a, FormalParameters<'a>> { ctx.ast.alloc_formal_parameters( SPAN, FormalParameterKind::FormalParameter, diff --git a/crates/oxc_transformer/src/jsx/display_name.rs b/crates/oxc_transformer/src/jsx/display_name.rs index 54ae8ee586c5ea..249bd359ea60a2 100644 --- a/crates/oxc_transformer/src/jsx/display_name.rs +++ b/crates/oxc_transformer/src/jsx/display_name.rs @@ -45,7 +45,7 @@ //! //! * Babel plugin implementation: -use oxc_allocator::Box; +use oxc_allocator::Box as ArenaBox; use oxc_ast::ast::*; use oxc_span::{Atom, SPAN}; use oxc_traverse::{Ancestor, Traverse, TraverseCtx}; @@ -133,7 +133,7 @@ impl<'a, 'ctx> ReactDisplayName<'a, 'ctx> { /// Get the object from `React.createClass({})` or `createReactClass({})` fn get_object_from_create_class<'b>( call_expr: &'b mut CallExpression<'a>, - ) -> Option<&'b mut Box<'a, ObjectExpression<'a>>> { + ) -> Option<&'b mut ArenaBox<'a, ObjectExpression<'a>>> { if match &call_expr.callee { callee @ match_member_expression!(Expression) => { !callee.to_member_expression().is_specific_member_access("React", "createClass") diff --git a/crates/oxc_transformer/src/typescript/module.rs b/crates/oxc_transformer/src/typescript/module.rs index 0762f756e9ac3b..40aa7b31bdae58 100644 --- a/crates/oxc_transformer/src/typescript/module.rs +++ b/crates/oxc_transformer/src/typescript/module.rs @@ -1,4 +1,4 @@ -use oxc_allocator::Box; +use oxc_allocator::Box as ArenaBox; use oxc_ast::{ast::*, NONE}; use oxc_span::SPAN; use oxc_syntax::reference::ReferenceFlags; @@ -51,7 +51,7 @@ impl<'a, 'ctx> Traverse<'a> for TypeScriptModule<'a, 'ctx> { impl<'a, 'ctx> TypeScriptModule<'a, 'ctx> { fn transform_ts_import_equals( &self, - decl: &mut Box<'a, TSImportEqualsDeclaration<'a>>, + decl: &mut ArenaBox<'a, TSImportEqualsDeclaration<'a>>, ctx: &mut TraverseCtx<'a>, ) -> Declaration<'a> { let kind = VariableDeclarationKind::Var; diff --git a/crates/oxc_transformer/src/typescript/namespace.rs b/crates/oxc_transformer/src/typescript/namespace.rs index d8dafcd2afd784..3a4f99c6b6512f 100644 --- a/crates/oxc_transformer/src/typescript/namespace.rs +++ b/crates/oxc_transformer/src/typescript/namespace.rs @@ -1,6 +1,6 @@ use rustc_hash::FxHashSet; -use oxc_allocator::{Box, Vec as ArenaVec}; +use oxc_allocator::{Box as ArenaBox, Vec as ArenaVec}; use oxc_ast::{ast::*, NONE}; use oxc_ecmascript::BoundNames; use oxc_span::{Atom, CompactStr, SPAN}; @@ -446,7 +446,7 @@ impl<'a, 'ctx> TypeScriptNamespace<'a, 'ctx> { /// Convert `export const foo = 1` to `Namespace.foo = 1`; #[allow(clippy::needless_pass_by_value)] fn handle_variable_declaration( - mut var_decl: Box<'a, VariableDeclaration<'a>>, + mut var_decl: ArenaBox<'a, VariableDeclaration<'a>>, name: Atom<'a>, ctx: &TraverseCtx<'a>, ) -> ArenaVec<'a, Statement<'a>> { From ae226710f255d799664950b956e4258c5f14477b Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Tue, 29 Oct 2024 13:00:49 +0000 Subject: [PATCH 07/12] refactor(transformer/typescript): pass `&mut T` not `&mut ArenaBox` (#7000) `&mut ArenaBox` is a double-reference. `&mut T` is shorter and easier to read. --- crates/oxc_transformer/src/typescript/module.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/oxc_transformer/src/typescript/module.rs b/crates/oxc_transformer/src/typescript/module.rs index 40aa7b31bdae58..2516fa49176e86 100644 --- a/crates/oxc_transformer/src/typescript/module.rs +++ b/crates/oxc_transformer/src/typescript/module.rs @@ -1,4 +1,3 @@ -use oxc_allocator::Box as ArenaBox; use oxc_ast::{ast::*, NONE}; use oxc_span::SPAN; use oxc_syntax::reference::ReferenceFlags; @@ -51,7 +50,7 @@ impl<'a, 'ctx> Traverse<'a> for TypeScriptModule<'a, 'ctx> { impl<'a, 'ctx> TypeScriptModule<'a, 'ctx> { fn transform_ts_import_equals( &self, - decl: &mut ArenaBox<'a, TSImportEqualsDeclaration<'a>>, + decl: &mut TSImportEqualsDeclaration<'a>, ctx: &mut TraverseCtx<'a>, ) -> Declaration<'a> { let kind = VariableDeclarationKind::Var; From e5ecbb9bf19fb95f2a560c870e12a29e942430ae Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Tue, 29 Oct 2024 13:00:50 +0000 Subject: [PATCH 08/12] refactor(transformer/jsx): return `&mut T` not `&mut ArenaBox` (#7001) `&mut ArenaBox` is a double-reference. `&mut T` is shorter and easier to read. --- crates/oxc_transformer/src/jsx/display_name.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/oxc_transformer/src/jsx/display_name.rs b/crates/oxc_transformer/src/jsx/display_name.rs index 249bd359ea60a2..817886973bbc81 100644 --- a/crates/oxc_transformer/src/jsx/display_name.rs +++ b/crates/oxc_transformer/src/jsx/display_name.rs @@ -45,7 +45,6 @@ //! //! * Babel plugin implementation: -use oxc_allocator::Box as ArenaBox; use oxc_ast::ast::*; use oxc_span::{Atom, SPAN}; use oxc_traverse::{Ancestor, Traverse, TraverseCtx}; @@ -133,7 +132,7 @@ impl<'a, 'ctx> ReactDisplayName<'a, 'ctx> { /// Get the object from `React.createClass({})` or `createReactClass({})` fn get_object_from_create_class<'b>( call_expr: &'b mut CallExpression<'a>, - ) -> Option<&'b mut ArenaBox<'a, ObjectExpression<'a>>> { + ) -> Option<&'b mut ObjectExpression<'a>> { if match &call_expr.callee { callee @ match_member_expression!(Expression) => { !callee.to_member_expression().is_specific_member_access("React", "createClass") From d9edef6ae1dfd93a8aaf0b9480271971f5b60975 Mon Sep 17 00:00:00 2001 From: Boshen <1430279+Boshen@users.noreply.github.com> Date: Tue, 29 Oct 2024 13:21:46 +0000 Subject: [PATCH 09/12] refactor(transformer): combine ObjectRestSpread into a single file (#7002) --- ...object_spread.rs => object_rest_spread.rs} | 43 +++++++---- .../src/es2018/object_rest_spread/mod.rs | 73 ------------------- .../es2018/object_rest_spread/object_rest.rs | 37 ---------- .../src/options/transformer.rs | 2 +- .../src/context/bound_identifier.rs | 2 +- 5 files changed, 30 insertions(+), 127 deletions(-) rename crates/oxc_transformer/src/es2018/{object_rest_spread/object_spread.rs => object_rest_spread.rs} (82%) delete mode 100644 crates/oxc_transformer/src/es2018/object_rest_spread/mod.rs delete mode 100644 crates/oxc_transformer/src/es2018/object_rest_spread/object_rest.rs diff --git a/crates/oxc_transformer/src/es2018/object_rest_spread/object_spread.rs b/crates/oxc_transformer/src/es2018/object_rest_spread.rs similarity index 82% rename from crates/oxc_transformer/src/es2018/object_rest_spread/object_spread.rs rename to crates/oxc_transformer/src/es2018/object_rest_spread.rs index c9d9a20f117d7b..ba174c84505560 100644 --- a/crates/oxc_transformer/src/es2018/object_rest_spread/object_spread.rs +++ b/crates/oxc_transformer/src/es2018/object_rest_spread.rs @@ -1,6 +1,6 @@ //! ES2018 object spread transformation. //! -//! This plugin transforms object spread properties (`{ ...x }`) to a series of `_objectSpread` calls. +//! This plugin transforms rest properties for object destructuring assignment and spread properties for object literals. //! //! > This plugin is included in `preset-env`, in ES2018 //! @@ -26,6 +26,8 @@ //! * Babel plugin implementation: //! * Object rest/spread TC39 proposal: +use serde::Deserialize; + use oxc_ast::{ast::*, NONE}; use oxc_semantic::{ReferenceFlags, SymbolId}; use oxc_span::SPAN; @@ -33,20 +35,38 @@ use oxc_traverse::{Traverse, TraverseCtx}; use crate::{common::helper_loader::Helper, TransformCtx}; -use super::ObjectRestSpreadOptions; +#[derive(Debug, Default, Clone, Copy, Deserialize)] +#[serde(default, rename_all = "camelCase")] +pub struct ObjectRestSpreadOptions { + #[serde(alias = "loose")] + pub(crate) set_spread_properties: bool, -pub struct ObjectSpread<'a, 'ctx> { - options: ObjectRestSpreadOptions, + pub(crate) use_built_ins: bool, +} + +pub struct ObjectRestSpread<'a, 'ctx> { ctx: &'ctx TransformCtx<'a>, + options: ObjectRestSpreadOptions, } -impl<'a, 'ctx> ObjectSpread<'a, 'ctx> { +impl<'a, 'ctx> ObjectRestSpread<'a, 'ctx> { pub fn new(options: ObjectRestSpreadOptions, ctx: &'ctx TransformCtx<'a>) -> Self { - Self { options, ctx } + Self { ctx, options } } } -impl<'a, 'ctx> Traverse<'a> for ObjectSpread<'a, 'ctx> { + +impl<'a, 'ctx> Traverse<'a> for ObjectRestSpread<'a, 'ctx> { fn enter_expression(&mut self, expr: &mut Expression<'a>, ctx: &mut TraverseCtx<'a>) { + self.transform_object_expression(expr, ctx); + } +} + +impl<'a, 'ctx> ObjectRestSpread<'a, 'ctx> { + fn transform_object_expression( + &mut self, + expr: &mut Expression<'a>, + ctx: &mut TraverseCtx<'a>, + ) { let Expression::ObjectExpression(obj_expr) = expr else { return; }; @@ -97,9 +117,7 @@ impl<'a, 'ctx> Traverse<'a> for ObjectSpread<'a, 'ctx> { *expr = ctx.ast.expression_call(SPAN, callee, NONE, arguments, false); } } -} -impl<'a, 'ctx> ObjectSpread<'a, 'ctx> { #[expect(clippy::option_option)] fn get_object_symbol_id(&self, ctx: &mut TraverseCtx<'a>) -> Option> { if self.options.set_spread_properties { @@ -118,7 +136,7 @@ impl<'a, 'ctx> ObjectSpread<'a, 'ctx> { if let Some(object_id) = object_id { Self::object_assign(object_id, ctx) } else { - self.babel_external_helper(ctx) + self.ctx.helper_load(Helper::ObjectSpread2, ctx) } } @@ -127,11 +145,6 @@ impl<'a, 'ctx> ObjectSpread<'a, 'ctx> { ctx.create_reference_id(SPAN, Atom::from("Object"), symbol_id, ReferenceFlags::Read); let object = ctx.ast.expression_from_identifier_reference(ident); let property = ctx.ast.identifier_name(SPAN, Atom::from("assign")); - Expression::from(ctx.ast.member_expression_static(SPAN, object, property, false)) } - - fn babel_external_helper(&self, ctx: &mut TraverseCtx<'a>) -> Expression<'a> { - self.ctx.helper_load(Helper::ObjectSpread2, ctx) - } } diff --git a/crates/oxc_transformer/src/es2018/object_rest_spread/mod.rs b/crates/oxc_transformer/src/es2018/object_rest_spread/mod.rs deleted file mode 100644 index ed7741daefb330..00000000000000 --- a/crates/oxc_transformer/src/es2018/object_rest_spread/mod.rs +++ /dev/null @@ -1,73 +0,0 @@ -//! ES2018 object spread transformation. -//! -//! This plugin transforms rest properties for object destructuring assignment and spread properties for object literals. -//! -//! > This plugin is included in `preset-env`, in ES2018 -//! -//! ## Example -//! -//! Input: -//! ```js -//! var x = { a: 1, b: 2 }; -//! var y = { ...x, c: 3 }; -//! ``` -//! -//! Output: -//! ```js -//! var x = { a: 1, b: 2 }; -//! var y = _objectSpread({}, x, { c: 3 }); -//! ``` -//! -//! ## Implementation -//! -//! Implementation based on [@babel/plugin-transform-object-rest-spread](https://babeljs.io/docs/babel-plugin-transform-object-rest-spread). -//! -//! ## References: -//! * Babel plugin implementation: -//! * Object rest/spread TC39 proposal: - -use serde::Deserialize; - -use oxc_ast::ast::*; -use oxc_traverse::{Traverse, TraverseCtx}; - -use crate::TransformCtx; - -mod object_rest; -mod object_spread; -use object_rest::ObjectRest; -use object_spread::ObjectSpread; - -#[derive(Debug, Default, Clone, Copy, Deserialize)] -#[serde(default, rename_all = "camelCase")] -pub struct ObjectRestSpreadOptions { - #[serde(alias = "loose")] - pub(crate) set_spread_properties: bool, - pub(crate) use_built_ins: bool, -} - -pub struct ObjectRestSpread<'a, 'ctx> { - #[allow(dead_code)] - options: ObjectRestSpreadOptions, - - // Plugins - object_spread: ObjectSpread<'a, 'ctx>, - #[allow(dead_code)] - object_rest: ObjectRest, -} - -impl<'a, 'ctx> ObjectRestSpread<'a, 'ctx> { - pub fn new(options: ObjectRestSpreadOptions, ctx: &'ctx TransformCtx<'a>) -> Self { - Self { - object_spread: ObjectSpread::new(options, ctx), - object_rest: ObjectRest::new(options), - options, - } - } -} - -impl<'a, 'ctx> Traverse<'a> for ObjectRestSpread<'a, 'ctx> { - fn enter_expression(&mut self, expr: &mut Expression<'a>, ctx: &mut TraverseCtx<'a>) { - self.object_spread.enter_expression(expr, ctx); - } -} diff --git a/crates/oxc_transformer/src/es2018/object_rest_spread/object_rest.rs b/crates/oxc_transformer/src/es2018/object_rest_spread/object_rest.rs deleted file mode 100644 index 19a8455ff2ccfd..00000000000000 --- a/crates/oxc_transformer/src/es2018/object_rest_spread/object_rest.rs +++ /dev/null @@ -1,37 +0,0 @@ -//! ES2018 object spread transformation. -//! -//! PLACEHOLDER ONLY. NOT IMPLEMENTED YET. TODO. -//! -//! > This plugin is included in `preset-env`, in ES2018 -//! -//! ## Example -//! -//! Input: -//! ```js -//! var { a, ...b } = x; -//! ``` -//! -//! Output: -//! ```js -//! // TBD -//! ``` -//! -//! ## Implementation -//! -//! Implementation based on [@babel/plugin-transform-object-rest-spread](https://babeljs.io/docs/babel-plugin-transform-object-rest-spread). -//! -//! ## References: -//! * Babel plugin implementation: -//! * Object rest/spread TC39 proposal: - -use super::ObjectRestSpreadOptions; - -pub struct ObjectRest { - _options: ObjectRestSpreadOptions, -} - -impl ObjectRest { - pub fn new(options: ObjectRestSpreadOptions) -> Self { - Self { _options: options } - } -} diff --git a/crates/oxc_transformer/src/options/transformer.rs b/crates/oxc_transformer/src/options/transformer.rs index 01d7cb02a097a9..24972e25a52b85 100644 --- a/crates/oxc_transformer/src/options/transformer.rs +++ b/crates/oxc_transformer/src/options/transformer.rs @@ -94,11 +94,11 @@ impl TransformOptions { arrow_function: None, }, es2016: ES2016Options { exponentiation_operator: true }, - es2018: ES2018Options { object_rest_spread: Some(ObjectRestSpreadOptions::default()) }, es2017: ES2017Options { // Turned off because it is not ready. async_to_generator: false, }, + es2018: ES2018Options { object_rest_spread: Some(ObjectRestSpreadOptions::default()) }, es2019: ES2019Options { optional_catch_binding: true }, es2020: ES2020Options { nullish_coalescing_operator: true }, es2021: ES2021Options { logical_assignment_operators: true }, diff --git a/crates/oxc_traverse/src/context/bound_identifier.rs b/crates/oxc_traverse/src/context/bound_identifier.rs index 2863a2acb088f0..2e4a071d768c88 100644 --- a/crates/oxc_traverse/src/context/bound_identifier.rs +++ b/crates/oxc_traverse/src/context/bound_identifier.rs @@ -34,7 +34,7 @@ use crate::TraverseCtx; /// * `BoundIdentifier` is `Clone` (unlike `BindingIdentifier`). /// * `BoundIdentifier` re-uses the same `Atom` for all `BindingIdentifier` / `IdentifierReference`s /// created from it. -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct BoundIdentifier<'a> { pub name: Atom<'a>, pub symbol_id: SymbolId, From 562bb9af7f3ef0bdc1688d0f41c622040a679ef0 Mon Sep 17 00:00:00 2001 From: Dunqing <29533304+Dunqing@users.noreply.github.com> Date: Tue, 29 Oct 2024 13:54:21 +0000 Subject: [PATCH 10/12] refactor(transformer/async-to-generator): move transform methods to `AsyncGeneratorExecutor` and make it public (#6992) The `AsyncGeneratorExecutor` contains many transform methods which both can used in `async-to-generator` and `async-generator-functions` plugins, because their implementations are almost the same. I am still not sure where is the best place to place it. --- .../src/es2017/async_to_generator.rs | 129 +++++++++++------- crates/oxc_transformer/src/es2017/mod.rs | 14 +- 2 files changed, 86 insertions(+), 57 deletions(-) diff --git a/crates/oxc_transformer/src/es2017/async_to_generator.rs b/crates/oxc_transformer/src/es2017/async_to_generator.rs index ea22f327a94df0..d9b0e51c851ad6 100644 --- a/crates/oxc_transformer/src/es2017/async_to_generator.rs +++ b/crates/oxc_transformer/src/es2017/async_to_generator.rs @@ -63,11 +63,12 @@ use crate::{common::helper_loader::Helper, TransformCtx}; pub struct AsyncToGenerator<'a, 'ctx> { ctx: &'ctx TransformCtx<'a>, + executor: AsyncGeneratorExecutor<'a, 'ctx>, } impl<'a, 'ctx> AsyncToGenerator<'a, 'ctx> { pub fn new(ctx: &'ctx TransformCtx<'a>) -> Self { - Self { ctx } + Self { ctx, executor: AsyncGeneratorExecutor::new(Helper::AsyncToGenerator, ctx) } } } @@ -77,8 +78,20 @@ impl<'a, 'ctx> Traverse<'a> for AsyncToGenerator<'a, 'ctx> { Expression::AwaitExpression(await_expr) => { self.transform_await_expression(await_expr, ctx) } - Expression::FunctionExpression(func) => self.transform_function_expression(func, ctx), - Expression::ArrowFunctionExpression(arrow) => self.transform_arrow_function(arrow, ctx), + Expression::FunctionExpression(func) => { + if func.r#async && !func.generator && !func.is_typescript_syntax() { + Some(self.executor.transform_function_expression(func, ctx)) + } else { + None + } + } + Expression::ArrowFunctionExpression(arrow) => { + if arrow.r#async { + Some(self.executor.transform_arrow_function(arrow, ctx)) + } else { + None + } + } _ => None, }; @@ -88,20 +101,20 @@ impl<'a, 'ctx> Traverse<'a> for AsyncToGenerator<'a, 'ctx> { } fn exit_statement(&mut self, stmt: &mut Statement<'a>, ctx: &mut TraverseCtx<'a>) { - let new_statement = match stmt { - Statement::FunctionDeclaration(func) => self.transform_function_declaration(func, ctx), + let function = match stmt { + Statement::FunctionDeclaration(func) => Some(func), Statement::ExportDefaultDeclaration(decl) => { if let ExportDefaultDeclarationKind::FunctionDeclaration(func) = &mut decl.declaration { - self.transform_function_declaration(func, ctx) + Some(func) } else { None } } Statement::ExportNamedDeclaration(decl) => { if let Some(Declaration::FunctionDeclaration(func)) = &mut decl.declaration { - self.transform_function_declaration(func, ctx) + Some(func) } else { None } @@ -109,8 +122,11 @@ impl<'a, 'ctx> Traverse<'a> for AsyncToGenerator<'a, 'ctx> { _ => None, }; - if let Some(new_statement) = new_statement { - self.ctx.statement_injector.insert_after(stmt, new_statement); + if let Some(function) = function { + if function.r#async && !function.generator && !function.is_typescript_syntax() { + let new_statement = self.executor.transform_function_declaration(function, ctx); + self.ctx.statement_injector.insert_after(stmt, new_statement); + } } } @@ -119,7 +135,10 @@ impl<'a, 'ctx> Traverse<'a> for AsyncToGenerator<'a, 'ctx> { node: &mut MethodDefinition<'a>, ctx: &mut TraverseCtx<'a>, ) { - self.transform_function_for_method_definition(&mut node.value, ctx); + let function = &mut node.value; + if function.r#async && !function.generator && !function.is_typescript_syntax() { + self.executor.transform_function_for_method_definition(function, ctx); + } } } @@ -143,6 +162,17 @@ impl<'a, 'ctx> AsyncToGenerator<'a, 'ctx> { )) } } +} + +pub struct AsyncGeneratorExecutor<'a, 'ctx> { + helper: Helper, + ctx: &'ctx TransformCtx<'a>, +} + +impl<'a, 'ctx> AsyncGeneratorExecutor<'a, 'ctx> { + pub fn new(helper: Helper, ctx: &'ctx TransformCtx<'a>) -> Self { + Self { helper, ctx } + } /// Transforms async method definitions to generator functions wrapped in asyncToGenerator. /// @@ -162,15 +192,11 @@ impl<'a, 'ctx> AsyncToGenerator<'a, 'ctx> { /// })(); /// } /// ``` - fn transform_function_for_method_definition( + pub fn transform_function_for_method_definition( &self, func: &mut Function<'a>, ctx: &mut TraverseCtx<'a>, ) { - if !func.r#async { - return; - } - let Some(body) = func.body.take() else { return; }; @@ -183,7 +209,7 @@ impl<'a, 'ctx> AsyncToGenerator<'a, 'ctx> { ctx.scopes_mut().change_parent_id(scope_id, Some(new_scope_id)); // We need to transform formal parameters change back to the original scope, // because we only move out the function body. - BindingMover::new(new_scope_id, ctx).visit_formal_parameters(&func.params); + Self::move_formal_parameters_to_target_scope(new_scope_id, &func.params, ctx); (scope_id, new_scope_id) }; @@ -196,36 +222,30 @@ impl<'a, 'ctx> AsyncToGenerator<'a, 'ctx> { // Modify the wrapper function func.r#async = false; + func.generator = false; func.body = Some(ctx.ast.alloc_function_body(SPAN, ctx.ast.vec(), ctx.ast.vec1(statement))); func.scope_id.set(Some(wrapper_scope_id)); } /// Transforms [`Function`] whose type is [`FunctionType::FunctionExpression`] to a generator function /// and wraps it in asyncToGenerator helper function. - fn transform_function_expression( + pub fn transform_function_expression( &self, wrapper_function: &mut Function<'a>, ctx: &mut TraverseCtx<'a>, - ) -> Option> { - if !wrapper_function.r#async - || wrapper_function.generator - || wrapper_function.is_typescript_syntax() - { - return None; - } - + ) -> Expression<'a> { let body = wrapper_function.body.take().unwrap(); let params = ctx.alloc(ctx.ast.move_formal_parameters(&mut wrapper_function.params)); let id = wrapper_function.id.take(); let has_function_id = id.is_some(); if !has_function_id && !Self::is_function_length_affected(¶ms) { - return Some(self.create_async_to_generator_call( + return self.create_async_to_generator_call( params, body, wrapper_function.scope_id.take().unwrap(), ctx, - )); + ); } let (generator_scope_id, wrapper_scope_id) = { @@ -238,7 +258,7 @@ impl<'a, 'ctx> AsyncToGenerator<'a, 'ctx> { // and the caller_function is inside the wrapper function. // so we need to move the id to the new scope. if let Some(id) = id.as_ref() { - BindingMover::new(wrapper_scope_id, ctx).visit_binding_identifier(id); + Self::move_binding_identifier_to_target_scope(wrapper_scope_id, id, ctx); let symbol_id = id.symbol_id.get().unwrap(); *ctx.symbols_mut().get_flags_mut(symbol_id) = SymbolFlags::FunctionScopedVariable; } @@ -294,6 +314,7 @@ impl<'a, 'ctx> AsyncToGenerator<'a, 'ctx> { } debug_assert!(wrapper_function.body.is_none()); wrapper_function.r#async = false; + wrapper_function.generator = false; wrapper_function.body.replace(ctx.ast.alloc_function_body( SPAN, ctx.ast.vec(), @@ -303,22 +324,15 @@ impl<'a, 'ctx> AsyncToGenerator<'a, 'ctx> { // Construct the IIFE let callee = ctx.ast.expression_from_function(ctx.ast.move_function(wrapper_function)); - Some(ctx.ast.expression_call(SPAN, callee, NONE, ctx.ast.vec(), false)) + ctx.ast.expression_call(SPAN, callee, NONE, ctx.ast.vec(), false) } /// Transforms async function declarations into generator functions wrapped in the asyncToGenerator helper. - fn transform_function_declaration( + pub fn transform_function_declaration( &self, wrapper_function: &mut Function<'a>, ctx: &mut TraverseCtx<'a>, - ) -> Option> { - if !wrapper_function.r#async - || wrapper_function.generator - || wrapper_function.is_typescript_syntax() - { - return None; - } - + ) -> Statement<'a> { let (generator_scope_id, wrapper_scope_id) = { let wrapper_scope_id = ctx.create_child_scope(ctx.current_scope_id(), ScopeFlags::Function); @@ -340,6 +354,7 @@ impl<'a, 'ctx> AsyncToGenerator<'a, 'ctx> { // Modify the wrapper function { wrapper_function.r#async = false; + wrapper_function.generator = false; let statements = ctx.ast.vec1(Self::create_apply_call_statement(&bound_ident, ctx)); debug_assert!(wrapper_function.body.is_none()); wrapper_function.body.replace(ctx.ast.alloc_function_body( @@ -370,20 +385,16 @@ impl<'a, 'ctx> AsyncToGenerator<'a, 'ctx> { let params = Self::create_empty_params(ctx); let id = Some(bound_ident.create_binding_identifier(ctx)); let caller_function = Self::create_function(id, params, body, scope_id, ctx); - Some(Statement::from(ctx.ast.declaration_from_function(caller_function))) + Statement::from(ctx.ast.declaration_from_function(caller_function)) } } /// Transforms async arrow functions into generator functions wrapped in the asyncToGenerator helper. - fn transform_arrow_function( + pub(self) fn transform_arrow_function( &self, arrow: &mut ArrowFunctionExpression<'a>, ctx: &mut TraverseCtx<'a>, - ) -> Option> { - if !arrow.r#async { - return None; - } - + ) -> Expression<'a> { let mut body = ctx.ast.move_function_body(&mut arrow.body); // If the arrow's expression is true, we need to wrap the only one expression with return statement. @@ -401,12 +412,12 @@ impl<'a, 'ctx> AsyncToGenerator<'a, 'ctx> { ctx.scopes_mut().get_flags_mut(generator_function_id).remove(ScopeFlags::Arrow); if !Self::is_function_length_affected(¶ms) { - return Some(self.create_async_to_generator_call( + return self.create_async_to_generator_call( params, ctx.ast.alloc(body), generator_function_id, ctx, - )); + ); } let wrapper_scope_id = ctx.create_child_scope(ctx.current_scope_id(), ScopeFlags::Function); @@ -444,7 +455,7 @@ impl<'a, 'ctx> AsyncToGenerator<'a, 'ctx> { let wrapper_function = Self::create_function(None, params, body, wrapper_scope_id, ctx); // Construct the IIFE let callee = ctx.ast.expression_from_function(wrapper_function); - Some(ctx.ast.expression_call(SPAN, callee, NONE, ctx.ast.vec(), false)) + ctx.ast.expression_call(SPAN, callee, NONE, ctx.ast.vec(), false) } } @@ -523,7 +534,7 @@ impl<'a, 'ctx> AsyncToGenerator<'a, 'ctx> { ctx.ast.statement_return(SPAN, Some(argument)) } - /// Creates an [`Expression`] that calls the [`Helper::AsyncToGenerator`] helper function. + /// Creates an [`Expression`] that calls the [`AsyncGeneratorExecutor::helper`] helper function. /// /// This function constructs the helper call with arguments derived from the provided /// parameters, body, and scope_id. @@ -546,7 +557,7 @@ impl<'a, 'ctx> AsyncToGenerator<'a, 'ctx> { let function_expression = ctx.ast.expression_from_function(function); let argument = ctx.ast.argument_expression(function_expression); let arguments = ctx.ast.vec1(argument); - self.ctx.helper_call_expr(Helper::AsyncToGenerator, arguments, ctx) + self.ctx.helper_call_expr(self.helper, arguments, ctx) } /// Creates a helper declaration statement for async-to-generator transformation. @@ -667,6 +678,24 @@ impl<'a, 'ctx> AsyncToGenerator<'a, 'ctx> { fn is_function_length_affected(params: &FormalParameters<'_>) -> bool { params.items.first().is_some_and(|param| !param.pattern.kind.is_assignment_pattern()) } + + #[inline] + fn move_formal_parameters_to_target_scope( + target_scope_id: ScopeId, + params: &FormalParameters<'a>, + ctx: &mut TraverseCtx<'a>, + ) { + BindingMover::new(target_scope_id, ctx).visit_formal_parameters(params); + } + + #[inline] + fn move_binding_identifier_to_target_scope( + target_scope_id: ScopeId, + ident: &BindingIdentifier<'a>, + ctx: &mut TraverseCtx<'a>, + ) { + BindingMover::new(target_scope_id, ctx).visit_binding_identifier(ident); + } } /// Moves the bindings from original scope to target scope. diff --git a/crates/oxc_transformer/src/es2017/mod.rs b/crates/oxc_transformer/src/es2017/mod.rs index b2525e161c0f79..8dbb3a7bd96492 100644 --- a/crates/oxc_transformer/src/es2017/mod.rs +++ b/crates/oxc_transformer/src/es2017/mod.rs @@ -1,13 +1,13 @@ +mod async_to_generator; +pub mod options; + +use options::ES2017Options; use oxc_ast::ast::{Expression, Statement}; use oxc_traverse::{Traverse, TraverseCtx}; -use crate::{ - es2017::{async_to_generator::AsyncToGenerator, options::ES2017Options}, - TransformCtx, -}; - -mod async_to_generator; -pub mod options; +use crate::{es2017::async_to_generator::AsyncToGenerator, TransformCtx}; +#[expect(unused_imports)] +pub use async_to_generator::AsyncGeneratorExecutor; #[allow(dead_code)] pub struct ES2017<'a, 'ctx> { From f0c87d453dcc1278514dc494a404012a328427c0 Mon Sep 17 00:00:00 2001 From: Boshen <1430279+Boshen@users.noreply.github.com> Date: Tue, 29 Oct 2024 15:05:18 +0000 Subject: [PATCH 11/12] refactor(transformer): mark all EnvOptions as not implemented (#7004) --- crates/oxc_transformer/src/env/options.rs | 24 +++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/crates/oxc_transformer/src/env/options.rs b/crates/oxc_transformer/src/env/options.rs index 859bb0cd0222ed..b3c55bbf3fb679 100644 --- a/crates/oxc_transformer/src/env/options.rs +++ b/crates/oxc_transformer/src/env/options.rs @@ -18,40 +18,40 @@ pub struct EnvOptions { #[serde(default = "default_as_true")] pub bugfixes: bool, - /// Unused. + #[deprecated = "Not Implemented"] pub spec: bool, - /// Unused. + #[deprecated = "Not Implemented"] pub loose: bool, - /// Unused. + #[deprecated = "Not Implemented"] pub modules: Option, - /// Unused. + #[deprecated = "Not Implemented"] pub debug: bool, - /// Unused. + #[deprecated = "Not Implemented"] pub include: Option, - /// Unused. + #[deprecated = "Not Implemented"] pub exclude: Option, - /// Unused. + #[deprecated = "Not Implemented"] pub use_built_ins: Option, - /// Unused. + #[deprecated = "Not Implemented"] pub corejs: Option, - /// Unused. + #[deprecated = "Not Implemented"] pub force_all_transforms: bool, - /// Unused. + #[deprecated = "Not Implemented"] pub config_path: Option, - /// Unused. + #[deprecated = "Not Implemented"] pub ignore_browserslist_config: bool, - /// Unused. + #[deprecated = "Not Implemented"] pub shipped_proposals: bool, } From 55637c248e555ea46e3715a63e6c25e524da3618 Mon Sep 17 00:00:00 2001 From: Boshen Date: Wed, 30 Oct 2024 09:39:53 +0800 Subject: [PATCH 12/12] chore: remove assignee from linter bug report --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- .github/ISSUE_TEMPLATE/linter_bug_report.yaml | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index eeb7b54a4d9afc..1aadee86131cd2 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -8,5 +8,5 @@ labels: C-bug diff --git a/.github/ISSUE_TEMPLATE/linter_bug_report.yaml b/.github/ISSUE_TEMPLATE/linter_bug_report.yaml index bbf4d8820e1e8c..13a54b947ab4db 100644 --- a/.github/ISSUE_TEMPLATE/linter_bug_report.yaml +++ b/.github/ISSUE_TEMPLATE/linter_bug_report.yaml @@ -2,8 +2,6 @@ name: Linter bug report description: Report a bug in Oxlint title: "linter: " labels: ["C-bug", "A-linter"] -assignees: - - DonIsaac body: - type: markdown