diff --git a/packages/rspack/src/Chunk.ts b/packages/rspack/src/Chunk.ts index 83e07fa6ef9..699f114e5c9 100644 --- a/packages/rspack/src/Chunk.ts +++ b/packages/rspack/src/Chunk.ts @@ -38,84 +38,82 @@ export class Chunk { constructor(binding: JsChunk) { this.#inner = binding; - Object.defineProperties(this, { - name: { - enumerable: true, - get: () => { - return binding.name; - } - }, - id: { - enumerable: true, - get: () => { - return binding.id; - } - }, - ids: { - enumerable: true, - get: () => { - return binding.ids; - } - }, - idNameHints: { - enumerable: true, - get: () => { - return binding.idNameHints; - } - }, - filenameTemplate: { - enumerable: true, - get: () => { - return binding.filenameTemplate; - } - }, - cssFilenameTemplate: { - enumerable: true, - get: () => { - return binding.cssFilenameTemplate; - } - }, - files: { - enumerable: true, - get: () => { - return new Set(binding.files); - } - }, - runtime: { - enumerable: true, - get: () => { - return new Set(binding.runtime); - } - }, - hash: { - enumerable: true, - get: () => { - return binding.hash; - } - }, - contentHash: { - enumerable: true, - get: () => { - return binding.contentHash; - } - }, - renderedHash: { - enumerable: true, - get: () => { - return binding.renderedHash; - } - }, - chunkReason: { - enumerable: true, - get: () => { - return binding.chunkReason; - } - }, - auxiliaryFiles: { - enumerable: true, - get: () => { - return new Set(binding.auxiliaryFiles); - } + Object.defineProperty(this, "name", { + enumerable: true, + get: () => { + return binding.name; + } + }); + Object.defineProperty(this, "id", { + enumerable: true, + get: () => { + return binding.id; + } + }); + Object.defineProperty(this, "ids", { + enumerable: true, + get: () => { + return binding.ids; + } + }); + Object.defineProperty(this, "idNameHints", { + enumerable: true, + get: () => { + return binding.idNameHints; + } + }); + Object.defineProperty(this, "filenameTemplate", { + enumerable: true, + get: () => { + return binding.filenameTemplate; + } + }); + Object.defineProperty(this, "cssFilenameTemplate", { + enumerable: true, + get: () => { + return binding.cssFilenameTemplate; + } + }); + Object.defineProperty(this, "files", { + enumerable: true, + get: () => { + return new Set(binding.files); + } + }); + Object.defineProperty(this, "runtime", { + enumerable: true, + get: () => { + return new Set(binding.runtime); + } + }); + Object.defineProperty(this, "hash", { + enumerable: true, + get: () => { + return binding.hash; + } + }); + Object.defineProperty(this, "contentHash", { + enumerable: true, + get: () => { + return binding.contentHash; + } + }); + Object.defineProperty(this, "renderedHash", { + enumerable: true, + get: () => { + return binding.renderedHash; + } + }); + Object.defineProperty(this, "chunkReason", { + enumerable: true, + get: () => { + return binding.chunkReason; + } + }); + Object.defineProperty(this, "auxiliaryFiles", { + enumerable: true, + get: () => { + return new Set(binding.auxiliaryFiles); } }); } diff --git a/packages/rspack/src/ChunkGroup.ts b/packages/rspack/src/ChunkGroup.ts index 59614ff6781..2608640553e 100644 --- a/packages/rspack/src/ChunkGroup.ts +++ b/packages/rspack/src/ChunkGroup.ts @@ -26,37 +26,33 @@ export class ChunkGroup { protected constructor(inner: JsChunkGroup) { this.#inner = inner; - Object.defineProperties(this, { - chunks: { - enumerable: true, - get: () => { - return this.#inner.chunks.map(binding => - Chunk.__from_binding(binding) - ); - } - }, - index: { - enumerable: true, - get: () => { - return this.#inner.index; - } - }, - name: { - enumerable: true, - get: () => { - return this.#inner.name; - } - }, - origins: { - enumerable: true, - get: () => { - return this.#inner.origins.map(origin => ({ - module: origin.module - ? Module.__from_binding(origin.module) - : undefined, - request: origin.request - })); - } + Object.defineProperty(this, "chunks", { + enumerable: true, + get: () => { + return this.#inner.chunks.map(binding => Chunk.__from_binding(binding)); + } + }); + Object.defineProperty(this, "index", { + enumerable: true, + get: () => { + return this.#inner.index; + } + }); + Object.defineProperty(this, "name", { + enumerable: true, + get: () => { + return this.#inner.name; + } + }); + Object.defineProperty(this, "origins", { + enumerable: true, + get: () => { + return this.#inner.origins.map(origin => ({ + module: origin.module + ? Module.__from_binding(origin.module) + : undefined, + request: origin.request + })); } }); } diff --git a/packages/rspack/src/DependenciesBlock.ts b/packages/rspack/src/DependenciesBlock.ts index 4ae6fbea569..08b92d1a3e6 100644 --- a/packages/rspack/src/DependenciesBlock.ts +++ b/packages/rspack/src/DependenciesBlock.ts @@ -18,18 +18,16 @@ export class DependenciesBlock { private constructor(binding: JsDependenciesBlock) { this.#binding = binding; - Object.defineProperties(this, { - dependencies: { - enumerable: true, - get(): Dependency[] { - return binding.dependencies.map(d => Dependency.__from_binding(d)); - } - }, - blocks: { - enumerable: true, - get(): DependenciesBlock[] { - return binding.blocks.map(b => DependenciesBlock.__from_binding(b)); - } + Object.defineProperty(this, "dependencies", { + enumerable: true, + get(): Dependency[] { + return binding.dependencies.map(d => Dependency.__from_binding(d)); + } + }); + Object.defineProperty(this, "blocks", { + enumerable: true, + get(): DependenciesBlock[] { + return binding.blocks.map(b => DependenciesBlock.__from_binding(b)); } }); } diff --git a/packages/rspack/src/Dependency.ts b/packages/rspack/src/Dependency.ts index 4ce2d79eaea..d55c1bf62fe 100644 --- a/packages/rspack/src/Dependency.ts +++ b/packages/rspack/src/Dependency.ts @@ -19,33 +19,31 @@ export class Dependency { private constructor(binding: JsDependency) { this.#inner = binding; - Object.defineProperties(this, { - type: { - enumerable: true, - get(): string { - return binding.type; - } - }, - category: { - enumerable: true, - get(): string { - return binding.category; - } - }, - request: { - enumerable: true, - get(): string | undefined { - return binding.request; - } + Object.defineProperty(this, "type", { + enumerable: true, + get(): string { + return binding.type; + } + }); + Object.defineProperty(this, "category", { + enumerable: true, + get(): string { + return binding.category; + } + }); + Object.defineProperty(this, "request", { + enumerable: true, + get(): string | undefined { + return binding.request; + } + }); + Object.defineProperty(this, "critical", { + enumerable: true, + get(): boolean { + return binding.critical; }, - critical: { - enumerable: true, - get(): boolean { - return binding.critical; - }, - set(val: boolean) { - binding.critical = val; - } + set(val: boolean) { + binding.critical = val; } }); } diff --git a/packages/rspack/src/Module.ts b/packages/rspack/src/Module.ts index a36cb2d8205..c43d2a05f23 100644 --- a/packages/rspack/src/Module.ts +++ b/packages/rspack/src/Module.ts @@ -57,42 +57,40 @@ export class ContextModuleFactoryBeforeResolveData { private constructor(binding: JsContextModuleFactoryBeforeResolveData) { this.#inner = binding; - Object.defineProperties(this, { - context: { - enumerable: true, - get(): string { - return binding.context; - }, - set(val: string) { - binding.context = val; - } + Object.defineProperty(this, "context", { + enumerable: true, + get(): string { + return binding.context; }, - request: { - enumerable: true, - get(): string { - return binding.request; - }, - set(val: string) { - binding.request = val; - } + set(val: string) { + binding.context = val; + } + }); + Object.defineProperty(this, "request", { + enumerable: true, + get(): string { + return binding.request; }, - regExp: { - enumerable: true, - get(): RegExp | undefined { - return binding.regExp; - }, - set(val: RegExp | undefined) { - binding.regExp = val; - } + set(val: string) { + binding.request = val; + } + }); + Object.defineProperty(this, "regExp", { + enumerable: true, + get(): RegExp | undefined { + return binding.regExp; }, - recursive: { - enumerable: true, - get(this: ContextModuleFactoryAfterResolveData): boolean { - return binding.recursive; - }, - set(val: boolean) { - binding.recursive = val; - } + set(val: RegExp | undefined) { + binding.regExp = val; + } + }); + Object.defineProperty(this, "recursive", { + enumerable: true, + get(this: ContextModuleFactoryAfterResolveData): boolean { + return binding.recursive; + }, + set(val: boolean) { + binding.recursive = val; } }); } @@ -125,59 +123,55 @@ export class ContextModuleFactoryAfterResolveData { private constructor(binding: JsContextModuleFactoryAfterResolveData) { this.#inner = binding; - Object.defineProperties(this, { - resource: { - enumerable: true, - get(): string { - return binding.resource; - }, - set(val: string) { - binding.resource = val; - } + Object.defineProperty(this, "resource", { + enumerable: true, + get(): string { + return binding.resource; }, - context: { - enumerable: true, - get(): string { - return binding.context; - }, - set(val: string) { - binding.context = val; - } + set(val: string) { + binding.resource = val; + } + }); + Object.defineProperty(this, "context", { + enumerable: true, + get(): string { + return binding.context; }, - request: { - enumerable: true, - get(): string { - return binding.request; - }, - set(val: string) { - binding.request = val; - } + set(val: string) { + binding.context = val; + } + }); + Object.defineProperty(this, "request", { + enumerable: true, + get(): string { + return binding.request; }, - regExp: { - enumerable: true, - get(): RegExp | undefined { - return binding.regExp; - }, - set(val: RegExp | undefined) { - binding.regExp = val; - } + set(val: string) { + binding.request = val; + } + }); + Object.defineProperty(this, "regExp", { + enumerable: true, + get(): RegExp | undefined { + return binding.regExp; }, - recursive: { - enumerable: true, - get(): boolean { - return binding.recursive; - }, - set(val: boolean) { - binding.recursive = val; - } + set(val: RegExp | undefined) { + binding.regExp = val; + } + }); + Object.defineProperty(this, "recursive", { + enumerable: true, + get(): boolean { + return binding.recursive; }, - dependencies: { - enumerable: true, - get(): Dependency[] { - return binding.dependencies.map(dep => - Dependency.__from_binding(dep) - ); - } + set(val: boolean) { + binding.recursive = val; + } + }); + Object.defineProperty(this, "dependencies", { + enumerable: true, + get(): Dependency[] { + return binding.dependencies.map(dep => Dependency.__from_binding(dep)); } }); } @@ -235,110 +229,108 @@ export class Module { constructor(module: JsModule, compilation?: Compilation) { this.#inner = module; - Object.defineProperties(this, { - type: { - enumerable: true, - get(): string | null { - return module.type || null; - } - }, - layer: { - enumerable: true, - get(): string | undefined { - return module.layer; - } - }, - context: { - enumerable: true, - get(): string | undefined { - return module.context; - } - }, - resource: { - enumerable: true, - get(): string | undefined { - return module.resource; - } - }, - request: { - enumerable: true, - get(): string | undefined { - return module.request; - } - }, - userRequest: { - enumerable: true, - get(): string | undefined { - return module.userRequest; - }, - set(val: string) { - module.userRequest = val; - } - }, - rawRequest: { - enumerable: true, - get(): string | undefined { - return module.rawRequest; - } - }, - factoryMeta: { - enumerable: true, - get(): JsFactoryMeta | undefined | undefined { - return module.factoryMeta; - } - }, - modules: { - enumerable: true, - get(): Module[] | undefined { - if (module instanceof JsModule) { - return module.modules - ? module.modules.map(m => Module.__from_binding(m)) - : undefined; - } - return undefined; - } - }, - buildInfo: { - enumerable: true, - get(): Record { - const customModule = compilation?.__internal__getCustomModule( - module.moduleIdentifier - ); - return customModule?.buildInfo || {}; - } - }, - buildMeta: { - enumerable: true, - get(): Record { - const customModule = compilation?.__internal__getCustomModule( - module.moduleIdentifier - ); - return customModule?.buildMeta || {}; - } + Object.defineProperty(this, "type", { + enumerable: true, + get(): string | null { + return module.type || null; + } + }); + Object.defineProperty(this, "layer", { + enumerable: true, + get(): string | undefined { + return module.layer; + } + }); + Object.defineProperty(this, "context", { + enumerable: true, + get(): string | undefined { + return module.context; + } + }); + Object.defineProperty(this, "resource", { + enumerable: true, + get(): string | undefined { + return module.resource; + } + }); + Object.defineProperty(this, "request", { + enumerable: true, + get(): string | undefined { + return module.request; + } + }); + Object.defineProperty(this, "userRequest", { + enumerable: true, + get(): string | undefined { + return module.userRequest; }, - blocks: { - enumerable: true, - get(): DependenciesBlock[] { - if ("blocks" in module) { - return module.blocks.map(b => DependenciesBlock.__from_binding(b)); - } - return []; + set(val: string) { + module.userRequest = val; + } + }); + Object.defineProperty(this, "rawRequest", { + enumerable: true, + get(): string | undefined { + return module.rawRequest; + } + }); + Object.defineProperty(this, "factoryMeta", { + enumerable: true, + get(): JsFactoryMeta | undefined | undefined { + return module.factoryMeta; + } + }); + Object.defineProperty(this, "modules", { + enumerable: true, + get(): Module[] | undefined { + if (module instanceof JsModule) { + return module.modules + ? module.modules.map(m => Module.__from_binding(m)) + : undefined; } - }, - dependencies: { - enumerable: true, - get(): Dependency[] { - if ("dependencies" in module) { - return module.dependencies.map(d => Dependency.__from_binding(d)); - } - return []; + return undefined; + } + }); + Object.defineProperty(this, "buildInfo", { + enumerable: true, + get(): Record { + const customModule = compilation?.__internal__getCustomModule( + module.moduleIdentifier + ); + return customModule?.buildInfo || {}; + } + }); + Object.defineProperty(this, "buildMeta", { + enumerable: true, + get(): Record { + const customModule = compilation?.__internal__getCustomModule( + module.moduleIdentifier + ); + return customModule?.buildMeta || {}; + } + }); + Object.defineProperty(this, "blocks", { + enumerable: true, + get(): DependenciesBlock[] { + if ("blocks" in module) { + return module.blocks.map(b => DependenciesBlock.__from_binding(b)); } - }, - useSourceMap: { - enumerable: true, - get(): boolean { - return module.useSourceMap; + return []; + } + }); + Object.defineProperty(this, "dependencies", { + enumerable: true, + get(): Dependency[] { + if ("dependencies" in module) { + return module.dependencies.map(d => Dependency.__from_binding(d)); } + return []; + } + }); + Object.defineProperty(this, "useSourceMap", { + enumerable: true, + get(): boolean { + return module.useSourceMap; } }); }