Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Source code handling classes for webpack

License

NotificationsYou must be signed in to change notification settings

webpack/webpack-sources

Repository files navigation

Contains multiple classes which represent aSource. ASource can be asked for source code, size, source map and hash.

Source

Base class for all sources.

Public methods

All methods should be considered as expensive as they may need to do computations.

source

Source.prototype.source()->String|Buffer

Returns the represented source code as string or Buffer (for binary Sources).

buffer

Source.prototype.buffer()->Buffer

Returns the represented source code as Buffer. Strings are converted to utf-8.

size

Source.prototype.size()->Number

Returns the size in bytes of the represented source code.

map

Source.prototype.map(options?:Object)->Object|null

Returns the SourceMap of the represented source code as JSON. May returnnull if no SourceMap is available.

Theoptions object can contain the following keys:

  • columns: Boolean (defaulttrue): If set to false the implementation may omit mappings for columns.

sourceAndMap

Source.prototype.sourceAndMap(options?:Object)->{source:String|Buffer,map:Object|null}

Returns both, source code (likeSource.prototype.source() and SourceMap (likeSource.prototype.map()). This method could have better performance than callingsource() andmap() separately.

Seemap() foroptions.

updateHash

Source.prototype.updateHash(hash:Hash)->void

Updates the providedHash object with the content of the represented source code. (Hash is an object with anupdate method, which is called with string values)

RawSource

Represents source code without SourceMap.

newRawSource(sourceCode:String|Buffer)

OriginalSource

Represents source code, which is a copy of the original file.

newOriginalSource(sourceCode:String|Buffer,name:String)
  • sourceCode: The source code.
  • name: The filename of the original source code.

OriginalSource tries to create column mappings if requested, by splitting the source code at typical statement borders (;,{,}).

SourceMapSource

Represents source code with SourceMap, optionally having an additional SourceMap for the original source.

newSourceMapSource(sourceCode:String|Buffer,name:String,sourceMap:Object|String|Buffer,originalSource?:String|Buffer,innerSourceMap?:Object|String|Buffer,removeOriginalSource?: boolean)
  • sourceCode: The source code.
  • name: The filename of the original source code.
  • sourceMap: The SourceMap for the source code.
  • originalSource: The source code of the original file. Can be omitted if thesourceMap already contains the original source code.
  • innerSourceMap: The SourceMap for theoriginalSource/name.
  • removeOriginalSource: Removes the source code forname from the final map, keeping only the deeper mappings for that file.

TheSourceMapSource supports "identity" mappings for theinnerSourceMap.When original source matches generated source for a mapping it's assumed to be mapped char by char allowing to keep finer mappings fromsourceMap.

CachedSource

Decorates aSource and caches returned results ofmap,source,buffer,size andsourceAndMap in memory.updateHash is not cached.It tries to reused cached results from other methods to avoid calculations, i. e. whensource is already cached, callingsize will get the size from the cached source, callingsourceAndMap will only callmap on the wrapped Source.

newCachedSource(source:Source)newCachedSource(source:Source|()=>Source,cachedData?:CachedData)

Instead of passing aSource object directly one can pass an function that returns aSource object. The function is only called when needed and once.

Public methods

getCachedData()

Returns the cached data for passing to the constructor. All cached entries are converted to Buffers and strings are avoided.

original()

Returns the originalSource object.

originalLazy()

Returns the originalSource object or a function returning these.

PrefixSource

Prefix every line of the decoratedSource with a provided string.

newPrefixSource(prefix:String,source:Source|String|Buffer)

ConcatSource

Concatenate multipleSources or strings to a single source.

newConcatSource(...items?:Source|String)

Public methods

add

ConcatSource.prototype.add(item:Source|String)

Adds an item to the source.

ReplaceSource

Decorates aSource with replacements and insertions of source code.

TheReplaceSource supports "identity" mappings for child source.When original source matches generated source for a mapping it's assumed to be mapped char by char allowing to split mappings at replacements/insertions.

Public methods

replace

ReplaceSource.prototype.replace(start:Number,end:Number,replacement:String)

Replaces chars fromstart (0-indexed, inclusive) toend (0-indexed, inclusive) withreplacement.

Locations represents locations in the original source and are not influenced by other replacements or insertions.

insert

ReplaceSource.prototype.insert(pos:Number,insertion:String)

Inserts theinsertion before charpos (0-indexed).

Location represents location in the original source and is not influenced by other replacements or insertions.

original

Get decoratedSource.

CompatSource

Converts a Source-like object into a real Source object.

Public methods

staticfrom

CompatSource.from(sourceLike: any|Source)

IfsourceLike is a real Source it returns it unmodified. Otherwise it returns it wrapped in a CompatSource.

About

Source code handling classes for webpack

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

    Packages

    No packages published

    Contributors27


    [8]ページ先頭

    ©2009-2025 Movatter.jp