Skip to content

Commit a5034af

Browse files
committed
refactor: drop redundant buffers() overrides that just return [this.buffer()]
Source.prototype.buffers() returns [this.buffer()] and naturally picks up subclass buffer() overrides through the prototype chain. The overrides on RawSource, OriginalSource, PrefixSource, and SourceMapSource simply repeated that same body, so remove them and let the base implementation handle those classes. ConcatSource, CachedSource, CompatSource, ReplaceSource, and SizeOnlySource keep their overrides since they each carry distinct logic (multi-buffer collection, caching, SourceLike delegation, no-replacements pass-through, throwing). Source.prototype.buffers() reverts from the inlined source()-based implementation back to [this.buffer()], so subclass buffer() optimizations (cached _valueAsBuffer in RawSource etc.) flow through without duplication. https://claude.ai/code/session_01EHhGq9PRFRGefVtwwasCqZ
1 parent 2a016a6 commit a5034af

5 files changed

Lines changed: 1 addition & 31 deletions

File tree

lib/OriginalSource.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,6 @@ class OriginalSource extends Source {
8282
return this._valueAsBuffer;
8383
}
8484

85-
/**
86-
* @returns {Buffer[]} buffers
87-
*/
88-
buffers() {
89-
return [this.buffer()];
90-
}
91-
9285
/**
9386
* Override Source.prototype.size (= `this.buffer().length`) to avoid
9487
* allocating a Buffer just to read the byte length, and memoize the

lib/PrefixSource.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,6 @@ class PrefixSource extends Source {
6464

6565
// TODO efficient buffer() implementation
6666

67-
/**
68-
* @returns {Buffer[]} buffers
69-
*/
70-
buffers() {
71-
return [this.buffer()];
72-
}
73-
7467
/**
7568
* @param {MapOptions=} options map options
7669
* @returns {RawSourceMap | null} map

lib/RawSource.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,6 @@ class RawSource extends Source {
9393
return this._valueAsBuffer;
9494
}
9595

96-
/**
97-
* @returns {Buffer[]} buffers
98-
*/
99-
buffers() {
100-
return [this.buffer()];
101-
}
102-
10396
/**
10497
* Override Source.prototype.size (= `this.buffer().length`) to avoid
10598
* allocating a Buffer just to read the byte length, and memoize the

lib/Source.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ class Source {
5959
* @returns {Buffer[]} buffers
6060
*/
6161
buffers() {
62-
const source = this.source();
63-
if (Buffer.isBuffer(source)) return [source];
64-
return [Buffer.from(source, "utf8")];
62+
return [this.buffer()];
6563
}
6664

6765
size() {

lib/SourceMapSource.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,6 @@ class SourceMapSource extends Source {
143143
return this._valueAsBuffer;
144144
}
145145

146-
/**
147-
* @returns {Buffer[]} buffers
148-
*/
149-
buffers() {
150-
return [this.buffer()];
151-
}
152-
153146
/**
154147
* Override Source.prototype.size (= `this.buffer().length`) to avoid
155148
* allocating a Buffer just to read the byte length, and memoize the

0 commit comments

Comments
 (0)