mirror of https://github.com/webpack/webpack.git
add own webpack-sources typings
This commit is contained in:
parent
8300425e1c
commit
c5ad6df793
|
@ -220,6 +220,101 @@ declare module "@webassemblyjs/ast" {
|
|||
export function isFuncImportDescr(n: Node): boolean;
|
||||
}
|
||||
|
||||
declare module "webpack-sources" {
|
||||
type MapOptions = { columns?: boolean; module?: boolean };
|
||||
|
||||
export abstract class Source {
|
||||
size(): number;
|
||||
|
||||
map(options?: MapOptions): Object;
|
||||
|
||||
sourceAndMap(
|
||||
options?: MapOptions
|
||||
): {
|
||||
source: string | Buffer;
|
||||
map: Object;
|
||||
};
|
||||
|
||||
updateHash(hash: import("./lib/util/createHash").Hash): void;
|
||||
|
||||
source(): string | Buffer;
|
||||
}
|
||||
|
||||
export class RawSource extends Source {
|
||||
constructor(source: string | Buffer);
|
||||
|
||||
// TODO remove internals
|
||||
_value: string | Buffer;
|
||||
}
|
||||
|
||||
export class OriginalSource extends Source {
|
||||
constructor(source: string | Buffer, name: string);
|
||||
|
||||
// TODO remove internals
|
||||
_value: string | Buffer;
|
||||
_name: string;
|
||||
}
|
||||
|
||||
export class ReplaceSource extends Source {
|
||||
constructor(source: Source, name?: string);
|
||||
|
||||
replace(start: number, end: number, newValue: string, name?: string): void;
|
||||
insert(pos: number, newValue: string, name?: string): void;
|
||||
|
||||
// TODO remove internals
|
||||
_name: string;
|
||||
_source: string;
|
||||
_replacements: {
|
||||
start: number;
|
||||
end: number;
|
||||
content: string;
|
||||
insertIndex: number;
|
||||
name: string;
|
||||
}[];
|
||||
}
|
||||
|
||||
export class SourceMapSource extends Source {
|
||||
constructor(
|
||||
source: string,
|
||||
name: string,
|
||||
sourceMap: Object | string,
|
||||
originalSource?: string,
|
||||
innerSourceMap?: Object
|
||||
);
|
||||
}
|
||||
|
||||
export class ConcatSource extends Source {
|
||||
constructor(...args: (string | Source)[]);
|
||||
|
||||
children: (string | Source)[];
|
||||
|
||||
add(item: string | Source): void;
|
||||
}
|
||||
|
||||
export class PrefixSource extends Source {
|
||||
constructor(prefix: string, source: string | Source);
|
||||
|
||||
_source: string | Source;
|
||||
_prefix: string;
|
||||
}
|
||||
|
||||
export class CachedSource extends Source {
|
||||
constructor(source: Source);
|
||||
|
||||
_source: Source;
|
||||
_cachedSource: string | Buffer;
|
||||
_cachedBuffer: Buffer;
|
||||
_cachedSize: number;
|
||||
_cachedMaps: Object;
|
||||
}
|
||||
|
||||
export class SizeOnlySource extends Source {
|
||||
constructor(size: number);
|
||||
|
||||
_size: number;
|
||||
}
|
||||
}
|
||||
|
||||
// This "hack" is needed because typescript doesn't support recursive type definitions
|
||||
// It's referenced from "ruleSet-conditions" in schemas/WebpackOptions.json
|
||||
interface RuleSetConditionsRecursive
|
||||
|
|
|
@ -574,7 +574,7 @@ class NormalModule extends Module {
|
|||
}
|
||||
|
||||
const handleParseError = e => {
|
||||
const source = this._source.source();
|
||||
const source = /** @type {string} */ (this._source.source());
|
||||
const error = new ModuleParseError(source, e);
|
||||
this.markModuleAsErrored(error);
|
||||
this._initBuildHash(compilation);
|
||||
|
|
|
@ -38,7 +38,6 @@ register(
|
|||
*/
|
||||
serialize(source, { write }) {
|
||||
write(source._source);
|
||||
// @ts-ignore
|
||||
write(source._cachedBuffer);
|
||||
write(source._cachedSource);
|
||||
write(source._cachedSize);
|
||||
|
@ -51,7 +50,6 @@ register(
|
|||
*/
|
||||
deserialize({ read }) {
|
||||
const source = new CachedSource(read());
|
||||
// @ts-ignore
|
||||
source._cachedBuffer = read();
|
||||
source._cachedSource = read();
|
||||
source._cachedSize = read();
|
||||
|
@ -152,10 +150,7 @@ register(
|
|||
serialize(source, { write }) {
|
||||
write(source._source);
|
||||
write(source._name);
|
||||
const replacements = /** @type {TODO} */ (Array.from(
|
||||
// @ts-ignore
|
||||
source._replacements
|
||||
));
|
||||
const replacements = Array.from(source._replacements);
|
||||
replacements.sort((a, b) => {
|
||||
return a.insertIndex - b.insertIndex;
|
||||
});
|
||||
|
@ -176,7 +171,6 @@ register(
|
|||
const source = new ReplaceSource(read(), read());
|
||||
const len = read();
|
||||
for (let i = 0; i < len; i++) {
|
||||
// @ts-ignore TODO signature is missing one argument in typings
|
||||
source.replace(read(), read(), read(), read());
|
||||
}
|
||||
return source;
|
||||
|
|
|
@ -34,7 +34,6 @@
|
|||
"devDependencies": {
|
||||
"@types/node": "^10.12.3",
|
||||
"@types/tapable": "^1.0.1",
|
||||
"@types/webpack-sources": "^0.1.4",
|
||||
"benchmark": "^2.1.1",
|
||||
"bundle-loader": "~0.5.0",
|
||||
"codacy-coverage": "^3.1.0",
|
||||
|
|
14
yarn.lock
14
yarn.lock
|
@ -84,25 +84,11 @@
|
|||
resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-1.13.2.tgz#ffe96278e712a8d4e467e367a338b05e22872646"
|
||||
integrity sha512-k6MCN8WuDiCj6O+UJsVMbrreZxkbrhQbO02oDj6yuRu8UAkp0MDdEcDKif8/gBKuJbT84kkO+VHQAqXkumEklg==
|
||||
|
||||
"@types/source-list-map@*":
|
||||
version "0.1.2"
|
||||
resolved "https://registry.yarnpkg.com/@types/source-list-map/-/source-list-map-0.1.2.tgz#0078836063ffaf17412349bba364087e0ac02ec9"
|
||||
integrity sha512-K5K+yml8LTo9bWJI/rECfIPrGgxdpeNbj+d53lwN4QjW1MCwlkhUms+gtdzigTeUyBr09+u8BwOIY3MXvHdcsA==
|
||||
|
||||
"@types/tapable@^1.0.1":
|
||||
version "1.0.4"
|
||||
resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-1.0.4.tgz#b4ffc7dc97b498c969b360a41eee247f82616370"
|
||||
integrity sha512-78AdXtlhpCHT0K3EytMpn4JNxaf5tbqbLcbIRoQIHzpTIyjpxLQKRoxU55ujBXAtg3Nl2h/XWvfDa9dsMOd0pQ==
|
||||
|
||||
"@types/webpack-sources@^0.1.4":
|
||||
version "0.1.5"
|
||||
resolved "https://registry.yarnpkg.com/@types/webpack-sources/-/webpack-sources-0.1.5.tgz#be47c10f783d3d6efe1471ff7f042611bd464a92"
|
||||
integrity sha512-zfvjpp7jiafSmrzJ2/i3LqOyTYTuJ7u1KOXlKgDlvsj9Rr0x7ZiYu5lZbXwobL7lmsRNtPXlBfmaUD8eU2Hu8w==
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
"@types/source-list-map" "*"
|
||||
source-map "^0.6.1"
|
||||
|
||||
"@webassemblyjs/ast@1.7.11":
|
||||
version "1.7.11"
|
||||
resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.7.11.tgz#b988582cafbb2b095e8b556526f30c90d057cace"
|
||||
|
|
Loading…
Reference in New Issue