C# Class React.Babel

Handles compiling JavaScript files via Babel (http://babeljs.io/).
Inheritance: IBabel
显示文件 Open project: reactjs/React.NET Class Usage Examples

Protected Properties

Property Type Description
_babelConfig string
_cache ICache
_config IReactSiteConfiguration
_environment IReactEnvironment
_fileCacheHash IFileCacheHash
_fileSystem IFileSystem

Public Methods

Method Description
Babel ( IReactEnvironment environment, ICache cache, IFileSystem fileSystem, IFileCacheHash fileCacheHash, IReactSiteConfiguration siteConfig ) : System

Initializes a new instance of the Babel class.

CacheIsValid ( string inputFileContents, string outputPath ) : bool

Checks whether an input file (given as inputFileContents) should be transpiled by calculating the hash and comparing it to the hash value stored in the file given by outputPath. If the outputPath file does not exist the input file should always be transpiled.

GetOutputPath ( string path ) : string

Returns the path the specified file's compilation will be cached to

GetSourceMapOutputPath ( string path ) : string

Returns the path the specified file's source map will be cached to if TransformAndSaveFile is called.

Transform ( string input, string filename = "unknown" ) : string

Transforms JavaScript via Babel. The result is not cached. Use TransformFile if loading from a file since this will cache the result.

TransformAndSaveFile ( string filename ) : string

Transforms JavaScript via Babel and saves the result into a ".generated.js" file alongside the original file.

TransformFile ( string filename ) : string

Transforms a JavaScript file. Results of the transformation are cached.

TransformFileWithSourceMap ( string filename, bool forceGenerateSourceMap = false ) : JavaScriptWithSourceMap

Transforms a JavaScript file via Babel and also returns a source map to map the compiled source to the original version. Results of the transformation are cached.

TransformWithSourceMap ( string input, string filename = "unknown" ) : JavaScriptWithSourceMap

Transforms JavaScript via Babel and also returns a source map to map the compiled source to the original version. The result is not cached.

Protected Methods

Method Description
GetFileHeader ( string hash, string babelVersion ) : string

Gets the header prepended to transformed files. Contains a hash that is used to validate the cache.

LoadFromFileCache ( string filename, string hash, bool forceGenerateSourceMap ) : JavaScriptWithSourceMap

Loads a transformed JavaScript file from the disk cache. If the cache is invalid or there is no cached version, returns null.

TransformWithHeader ( string filename, string contents, string hash = null ) : JavaScriptWithSourceMap

Transforms JavaScript via Babel, and prepends a header used for caching purposes.

Method Details

Babel() public method

Initializes a new instance of the Babel class.
public Babel ( IReactEnvironment environment, ICache cache, IFileSystem fileSystem, IFileCacheHash fileCacheHash, IReactSiteConfiguration siteConfig ) : System
environment IReactEnvironment The ReactJS.NET environment
cache ICache The cache to use for compilation
fileSystem IFileSystem File system wrapper
fileCacheHash IFileCacheHash Hash algorithm for file-based cache
siteConfig IReactSiteConfiguration Site-wide configuration
return System

CacheIsValid() public method

Checks whether an input file (given as inputFileContents) should be transpiled by calculating the hash and comparing it to the hash value stored in the file given by outputPath. If the outputPath file does not exist the input file should always be transpiled.
public CacheIsValid ( string inputFileContents, string outputPath ) : bool
inputFileContents string The contents of the input file.
outputPath string The output path of the (possibly previously) generated file.
return bool

GetFileHeader() protected method

Gets the header prepended to transformed files. Contains a hash that is used to validate the cache.
protected GetFileHeader ( string hash, string babelVersion ) : string
hash string Hash of the input
babelVersion string Version of Babel used to perform this transformation
return string

GetOutputPath() public method

Returns the path the specified file's compilation will be cached to
public GetOutputPath ( string path ) : string
path string Path of the input file
return string

GetSourceMapOutputPath() public method

Returns the path the specified file's source map will be cached to if TransformAndSaveFile is called.
public GetSourceMapOutputPath ( string path ) : string
path string Path of the input file
return string

LoadFromFileCache() protected method

Loads a transformed JavaScript file from the disk cache. If the cache is invalid or there is no cached version, returns null.
protected LoadFromFileCache ( string filename, string hash, bool forceGenerateSourceMap ) : JavaScriptWithSourceMap
filename string Name of the file to load
hash string Hash of the input file, to validate the cache
forceGenerateSourceMap bool /// true to re-transform the file if a cached version with no source map is available ///
return JavaScriptWithSourceMap

Transform() public method

Transforms JavaScript via Babel. The result is not cached. Use TransformFile if loading from a file since this will cache the result.
public Transform ( string input, string filename = "unknown" ) : string
input string JavaScript
filename string Name of the file being transformed
return string

TransformAndSaveFile() public method

Transforms JavaScript via Babel and saves the result into a ".generated.js" file alongside the original file.
public TransformAndSaveFile ( string filename ) : string
filename string Name of the file to load
return string

TransformFile() public method

Transforms a JavaScript file. Results of the transformation are cached.
public TransformFile ( string filename ) : string
filename string Name of the file to load
return string

TransformFileWithSourceMap() public method

Transforms a JavaScript file via Babel and also returns a source map to map the compiled source to the original version. Results of the transformation are cached.
public TransformFileWithSourceMap ( string filename, bool forceGenerateSourceMap = false ) : JavaScriptWithSourceMap
filename string Name of the file to load
forceGenerateSourceMap bool /// true to re-transform the file if a cached version with no source map is available ///
return JavaScriptWithSourceMap

TransformWithHeader() protected method

Transforms JavaScript via Babel, and prepends a header used for caching purposes.
protected TransformWithHeader ( string filename, string contents, string hash = null ) : JavaScriptWithSourceMap
filename string Name of the file being transformed
contents string Contents of the input file
hash string Hash of the input. If null, it will be calculated
return JavaScriptWithSourceMap

TransformWithSourceMap() public method

Transforms JavaScript via Babel and also returns a source map to map the compiled source to the original version. The result is not cached.
public TransformWithSourceMap ( string input, string filename = "unknown" ) : JavaScriptWithSourceMap
input string JavaScript
filename string Name of the file being transformed
return JavaScriptWithSourceMap

Property Details

_babelConfig protected_oe property

The serialized Babel configuration
protected string _babelConfig
return string

_cache protected_oe property

Cache used for storing compiled JavaScript
protected ICache _cache
return ICache

_config protected_oe property

Site-wide configuration
protected IReactSiteConfiguration _config
return IReactSiteConfiguration

_environment protected_oe property

Environment this transformer has been created in
protected IReactEnvironment _environment
return IReactEnvironment

_fileCacheHash protected_oe property

Hash algorithm for file-based cache
protected IFileCacheHash _fileCacheHash
return IFileCacheHash

_fileSystem protected_oe property

File system wrapper
protected IFileSystem _fileSystem
return IFileSystem