Contains multiple classes which represent aSource. ASource can be asked for source code, size, source map and hash.
Base class for all sources.
All methods should be considered as expensive as they may need to do computations.
Source.prototype.source()->String|Buffer
Returns the represented source code as string or Buffer (for binary Sources).
Source.prototype.buffer()->Buffer
Returns the represented source code as Buffer. Strings are converted to utf-8.
Source.prototype.size()->Number
Returns the size in bytes of the represented source code.
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.
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.
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)
Represents source code without SourceMap.
newRawSource(sourceCode:String|Buffer)
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 (;,{,}).
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.
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.
Returns the cached data for passing to the constructor. All cached entries are converted to Buffers and strings are avoided.
Returns the originalSource object.
Returns the originalSource object or a function returning these.
Prefix every line of the decoratedSource with a provided string.
newPrefixSource(prefix:String,source:Source|String|Buffer)
Concatenate multipleSources or strings to a single source.
newConcatSource(...items?:Source|String)
ConcatSource.prototype.add(item:Source|String)
Adds an item to the source.
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.
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.
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.
Get decoratedSource.
Converts a Source-like object into a real Source object.
CompatSource.from(sourceLike: any|Source)
IfsourceLike is a real Source it returns it unmodified. Otherwise it returns it wrapped in a CompatSource.