Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: dependeny js api constructor #8817

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 76 additions & 78 deletions packages/rspack/src/Chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
}
Expand Down
58 changes: 27 additions & 31 deletions packages/rspack/src/ChunkGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}));
}
});
}
Expand Down
22 changes: 10 additions & 12 deletions packages/rspack/src/DependenciesBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
});
}
Expand Down
50 changes: 24 additions & 26 deletions packages/rspack/src/Dependency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});
}
Expand Down
Loading
Loading