Skip to content

Commit

Permalink
feat: update test case
Browse files Browse the repository at this point in the history
  • Loading branch information
SyMind committed Sep 23, 2024
1 parent 9cc09f4 commit c69a361
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 22 deletions.
2 changes: 1 addition & 1 deletion crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class JsDependency {
get category(): string
get request(): string | undefined
get critical(): boolean | undefined
set critical(val: boolean)
set critical(val?: boolean | undefined | null)
}

export class JsEntries {
Expand Down
16 changes: 9 additions & 7 deletions crates/rspack_binding_values/src/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,17 @@ impl JsDependency {
}

#[napi(setter)]
pub fn set_critical(&mut self, val: bool) {
match self.0.as_context_dependency_mut() {
Some(dep) => {
let critical = dep.critical_mut();
if !val {
*critical = None;
pub fn set_critical(&mut self, val: Option<bool>) {
if let Some(val) = val {
match self.0.as_context_dependency_mut() {

Check failure on line 118 in crates/rspack_binding_values/src/dependency.rs

View workflow job for this annotation

GitHub Actions / Rust check

you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
Some(dep) => {
let critical = dep.critical_mut();
if !val {
*critical = None;
}
}
None => (),
}
None => (),
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ class Plugin {
resolveData.regExp = /[/\\](en(\.js)?|zh(\.js)?)$/;
return resolveData;
}
for (const d of resolveData.dependencies) {
if (d.critical) d.critical = false;
}
});
}
);
}
}

/**@type {import("@rspack/core").Configuration}*/
module.exports = {
context: __dirname,
Expand Down
42 changes: 35 additions & 7 deletions packages/rspack/etc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { cleanupGlobalTrace } from '@rspack/binding';
import { Compiler as Compiler_2 } from '../Compiler';
import { default as default_2 } from './util/hash';
import type { DependenciesBlockDTO } from '@rspack/binding';
import type { DependencyDTO } from '@rspack/binding';
import { RawEvalDevToolModulePluginOptions as EvalDevToolModulePluginOptions } from '@rspack/binding';
import { EventEmitter } from 'events';
import { ExternalObject } from '@rspack/binding';
Expand All @@ -39,8 +38,11 @@ import { JsChunkGroup } from '@rspack/binding';
import { JsChunkGroupOrigin } from '@rspack/binding';
import type { JsCodegenerationResult } from '@rspack/binding';
import { JsCompilation } from '@rspack/binding';
import { JsCompiledDependency } from '@rspack/binding';
import type { JsContextModuleFactoryAfterResolveData } from '@rspack/binding';
import type { JsContextModuleFactoryBeforeResolveData } from '@rspack/binding';
import type { JsCreateData } from '@rspack/binding';
import { JsDependency } from '@rspack/binding';
import type { JsFactoryMeta } from '@rspack/binding';
import { JsHtmlPluginTag } from '@rspack/binding';
import { JsLibraryOptions } from '@rspack/binding';
Expand Down Expand Up @@ -1577,7 +1579,8 @@ class ContextModuleFactory {

// @public (undocumented)
class ContextModuleFactoryAfterResolveData {
constructor(data: JsContextModuleFactoryAfterResolveData);
// (undocumented)
static __drop(data: ContextModuleFactoryAfterResolveData): void;
// (undocumented)
static __from_binding(binding: JsContextModuleFactoryAfterResolveData): ContextModuleFactoryAfterResolveData;
// (undocumented)
Expand Down Expand Up @@ -1605,10 +1608,29 @@ class ContextModuleFactoryAfterResolveData {
type ContextModuleFactoryAfterResolveResult = false | ContextModuleFactoryAfterResolveData;

// @public (undocumented)
type ContextModuleFactoryBeforeResolveResult = false | {
context: string;
request?: string;
};
class ContextModuleFactoryBeforeResolveData {
// (undocumented)
static __drop(data: ContextModuleFactoryBeforeResolveData): void;
// (undocumented)
static __from_binding(binding: JsContextModuleFactoryBeforeResolveData): ContextModuleFactoryBeforeResolveData;
// (undocumented)
static __to_binding(data: ContextModuleFactoryBeforeResolveData): JsContextModuleFactoryBeforeResolveData;
// (undocumented)
get context(): string;
set context(val: string);
// (undocumented)
get recursive(): boolean;
set recursive(val: boolean);
// (undocumented)
get regExp(): RegExp | undefined;
set regExp(val: RegExp | undefined);
// (undocumented)
get request(): string;
set request(val: string);
}

// @public (undocumented)
type ContextModuleFactoryBeforeResolveResult = false | ContextModuleFactoryBeforeResolveData;

// @public (undocumented)
export const ContextReplacementPlugin: {
Expand Down Expand Up @@ -1866,10 +1888,16 @@ class DependenciesBlock {

// @public (undocumented)
class Dependency {
constructor(binding: DependencyDTO);
// (undocumented)
static __drop(dependency: Dependency): void;
// (undocumented)
static __from_binding(binding: JsDependency | JsCompiledDependency): Dependency;
// (undocumented)
get category(): string;
// (undocumented)
get critital(): boolean | undefined;
set critital(critital: boolean | undefined);
// (undocumented)
get request(): string | undefined;
// (undocumented)
get type(): string;
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack/src/Dependency.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { JsDependency, JsCompiledDependency } from "@rspack/binding";
import { type JsCompiledDependency, JsDependency } from "@rspack/binding";

export class Dependency {
#binding: JsDependency | JsCompiledDependency;
Expand Down
10 changes: 4 additions & 6 deletions packages/rspack/src/Module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ export class ContextModuleFactoryAfterResolveData {
#inner: JsContextModuleFactoryAfterResolveData;
#resolvedDependencies?: Dependency[];
#dropped = false;
#dropWarningMessage?: string;

static __from_binding(binding: JsContextModuleFactoryAfterResolveData) {
return new ContextModuleFactoryAfterResolveData(binding);
Expand All @@ -141,17 +140,16 @@ export class ContextModuleFactoryAfterResolveData {
static __drop(data: ContextModuleFactoryAfterResolveData) {
data.#dropped = true;
if (data.#resolvedDependencies) {
data.#resolvedDependencies.forEach(dependency =>
Dependency.__drop(dependency)
);
for (const dependency of data.#resolvedDependencies) {
Dependency.__drop(dependency);
}
}
}

private ensureValidLifecycle() {
if (this.#dropped) {
throw new Error(
this.#dropWarningMessage ??
"The ContextModuleFactoryAfterResolveData has exceeded its lifecycle and has been dropped by Rust."
"The ContextModuleFactoryAfterResolveData has exceeded its lifecycle and has been dropped by Rust."
);
}
}
Expand Down

0 comments on commit c69a361

Please sign in to comment.