Skip to content

Commit c5ad6df

Browse files
committed
add own webpack-sources typings
1 parent 8300425 commit c5ad6df

File tree

5 files changed

+97
-23
lines changed

5 files changed

+97
-23
lines changed

declarations.d.ts

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,101 @@ declare module "@webassemblyjs/ast" {
220220
export function isFuncImportDescr(n: Node): boolean;
221221
}
222222

223+
declare module "webpack-sources" {
224+
type MapOptions = { columns?: boolean; module?: boolean };
225+
226+
export abstract class Source {
227+
size(): number;
228+
229+
map(options?: MapOptions): Object;
230+
231+
sourceAndMap(
232+
options?: MapOptions
233+
): {
234+
source: string | Buffer;
235+
map: Object;
236+
};
237+
238+
updateHash(hash: import("./lib/util/createHash").Hash): void;
239+
240+
source(): string | Buffer;
241+
}
242+
243+
export class RawSource extends Source {
244+
constructor(source: string | Buffer);
245+
246+
// TODO remove internals
247+
_value: string | Buffer;
248+
}
249+
250+
export class OriginalSource extends Source {
251+
constructor(source: string | Buffer, name: string);
252+
253+
// TODO remove internals
254+
_value: string | Buffer;
255+
_name: string;
256+
}
257+
258+
export class ReplaceSource extends Source {
259+
constructor(source: Source, name?: string);
260+
261+
replace(start: number, end: number, newValue: string, name?: string): void;
262+
insert(pos: number, newValue: string, name?: string): void;
263+
264+
// TODO remove internals
265+
_name: string;
266+
_source: string;
267+
_replacements: {
268+
start: number;
269+
end: number;
270+
content: string;
271+
insertIndex: number;
272+
name: string;
273+
}[];
274+
}
275+
276+
export class SourceMapSource extends Source {
277+
constructor(
278+
source: string,
279+
name: string,
280+
sourceMap: Object | string,
281+
originalSource?: string,
282+
innerSourceMap?: Object
283+
);
284+
}
285+
286+
export class ConcatSource extends Source {
287+
constructor(...args: (string | Source)[]);
288+
289+
children: (string | Source)[];
290+
291+
add(item: string | Source): void;
292+
}
293+
294+
export class PrefixSource extends Source {
295+
constructor(prefix: string, source: string | Source);
296+
297+
_source: string | Source;
298+
_prefix: string;
299+
}
300+
301+
export class CachedSource extends Source {
302+
constructor(source: Source);
303+
304+
_source: Source;
305+
_cachedSource: string | Buffer;
306+
_cachedBuffer: Buffer;
307+
_cachedSize: number;
308+
_cachedMaps: Object;
309+
}
310+
311+
export class SizeOnlySource extends Source {
312+
constructor(size: number);
313+
314+
_size: number;
315+
}
316+
}
317+
223318
// This "hack" is needed because typescript doesn't support recursive type definitions
224319
// It's referenced from "ruleSet-conditions" in schemas/WebpackOptions.json
225320
interface RuleSetConditionsRecursive

lib/NormalModule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ class NormalModule extends Module {
574574
}
575575

576576
const handleParseError = e => {
577-
const source = this._source.source();
577+
const source = /** @type {string} */ (this._source.source());
578578
const error = new ModuleParseError(source, e);
579579
this.markModuleAsErrored(error);
580580
this._initBuildHash(compilation);

lib/util/registerExternalSerializer.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ register(
3838
*/
3939
serialize(source, { write }) {
4040
write(source._source);
41-
// @ts-ignore
4241
write(source._cachedBuffer);
4342
write(source._cachedSource);
4443
write(source._cachedSize);
@@ -51,7 +50,6 @@ register(
5150
*/
5251
deserialize({ read }) {
5352
const source = new CachedSource(read());
54-
// @ts-ignore
5553
source._cachedBuffer = read();
5654
source._cachedSource = read();
5755
source._cachedSize = read();
@@ -152,10 +150,7 @@ register(
152150
serialize(source, { write }) {
153151
write(source._source);
154152
write(source._name);
155-
const replacements = /** @type {TODO} */ (Array.from(
156-
// @ts-ignore
157-
source._replacements
158-
));
153+
const replacements = Array.from(source._replacements);
159154
replacements.sort((a, b) => {
160155
return a.insertIndex - b.insertIndex;
161156
});
@@ -176,7 +171,6 @@ register(
176171
const source = new ReplaceSource(read(), read());
177172
const len = read();
178173
for (let i = 0; i < len; i++) {
179-
// @ts-ignore TODO signature is missing one argument in typings
180174
source.replace(read(), read(), read(), read());
181175
}
182176
return source;

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
"devDependencies": {
3535
"@types/node": "^10.12.3",
3636
"@types/tapable": "^1.0.1",
37-
"@types/webpack-sources": "^0.1.4",
3837
"benchmark": "^2.1.1",
3938
"bundle-loader": "~0.5.0",
4039
"codacy-coverage": "^3.1.0",

yarn.lock

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,25 +84,11 @@
8484
resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-1.13.2.tgz#ffe96278e712a8d4e467e367a338b05e22872646"
8585
integrity sha512-k6MCN8WuDiCj6O+UJsVMbrreZxkbrhQbO02oDj6yuRu8UAkp0MDdEcDKif8/gBKuJbT84kkO+VHQAqXkumEklg==
8686

87-
"@types/source-list-map@*":
88-
version "0.1.2"
89-
resolved "https://registry.yarnpkg.com/@types/source-list-map/-/source-list-map-0.1.2.tgz#0078836063ffaf17412349bba364087e0ac02ec9"
90-
integrity sha512-K5K+yml8LTo9bWJI/rECfIPrGgxdpeNbj+d53lwN4QjW1MCwlkhUms+gtdzigTeUyBr09+u8BwOIY3MXvHdcsA==
91-
9287
"@types/tapable@^1.0.1":
9388
version "1.0.4"
9489
resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-1.0.4.tgz#b4ffc7dc97b498c969b360a41eee247f82616370"
9590
integrity sha512-78AdXtlhpCHT0K3EytMpn4JNxaf5tbqbLcbIRoQIHzpTIyjpxLQKRoxU55ujBXAtg3Nl2h/XWvfDa9dsMOd0pQ==
9691

97-
"@types/webpack-sources@^0.1.4":
98-
version "0.1.5"
99-
resolved "https://registry.yarnpkg.com/@types/webpack-sources/-/webpack-sources-0.1.5.tgz#be47c10f783d3d6efe1471ff7f042611bd464a92"
100-
integrity sha512-zfvjpp7jiafSmrzJ2/i3LqOyTYTuJ7u1KOXlKgDlvsj9Rr0x7ZiYu5lZbXwobL7lmsRNtPXlBfmaUD8eU2Hu8w==
101-
dependencies:
102-
"@types/node" "*"
103-
"@types/source-list-map" "*"
104-
source-map "^0.6.1"
105-
10692
"@webassemblyjs/[email protected]":
10793
version "1.7.11"
10894
resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.7.11.tgz#b988582cafbb2b095e8b556526f30c90d057cace"

0 commit comments

Comments
 (0)