A Parcel transformer plugin that transforms JavaScript code using Babel with automatic configuration discovery and intelligent defaults for modern JavaScript, TypeScript, JSX, and Flow.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
The core transformer that integrates with Parcel's build pipeline to apply Babel transformations to JavaScript, TypeScript, and JSX assets.
The default export is a Transformer instance (not a class) that implements Parcel's Transformer interface for Babel processing.
/**
* Default export - Babel transformer instance for Parcel
* This is a pre-configured Transformer instance, not a class or constructor
* Implements the complete Transformer interface for Babel compilation
*/
export default BabelTransformer: Transformer;
interface Transformer {
loadConfig(options: LoadConfigOptions): Promise<BabelConfigResult | null>;
canReuseAST(options: CanReuseASTOptions): boolean;
transform(options: TransformOptions): Promise<MutableAsset[]>;
generate(options: GenerateOptions): Promise<GenerateResult>;
}Loads and validates Babel configuration for the current asset being processed.
/**
* Loads Babel configuration for the current asset
* @param options - Configuration loading options
* @returns Promise resolving to BabelConfigResult or null if no config needed
*/
loadConfig(options: LoadConfigOptions): Promise<BabelConfigResult | null>;
interface LoadConfigOptions {
config: Config;
options: PluginOptions;
logger: PluginLogger;
}Usage Example:
// Called internally by Parcel
const configResult = await transformer.loadConfig({
config: parcelConfig,
options: pluginOptions,
logger: parcelLogger
});Determines if an existing AST can be reused for the current transformation.
/**
* Determines if the provided AST can be reused for transformation
* @param options - AST reuse check options
* @returns True if AST can be reused, false otherwise
*/
canReuseAST(options: CanReuseASTOptions): boolean;
interface CanReuseASTOptions {
ast: AST;
}
interface AST {
type: string;
version: string;
program: any;
}Implementation Details:
true if AST type is 'babel' and version satisfies '^7.0.0'Performs the core Babel transformation on JavaScript assets.
/**
* Transforms JavaScript/TypeScript/JSX assets using Babel
* @param options - Transformation options
* @returns Promise resolving to array containing the transformed asset
*/
transform(options: TransformOptions): Promise<MutableAsset[]>;
interface TransformOptions {
asset: MutableAsset;
config: BabelConfigResult | null;
logger: PluginLogger;
options: PluginOptions;
tracer: PluginTracer;
}Usage Example:
// Called internally by Parcel
const transformedAssets = await transformer.transform({
asset: jsAsset,
config: babelConfig,
logger: parcelLogger,
options: pluginOptions,
tracer: performanceTracer
});Transformation Process:
babel7() function to perform actual transformationGenerates final JavaScript code and source maps from the transformed AST.
/**
* Generates JavaScript code and source maps from Babel AST
* @param options - Code generation options
* @returns Promise resolving to generated code and source map
*/
generate(options: GenerateOptions): Promise<GenerateResult>;
interface GenerateOptions {
asset: MutableAsset;
ast: AST;
options: PluginOptions;
}
interface GenerateResult {
content: string;
map: SourceMap;
}Generation Process:
Usage Example:
// Called internally by Parcel during code generation phase
const result = await transformer.generate({
asset: processedAsset,
ast: babelAST,
options: pluginOptions
});
console.log(result.content); // Generated JavaScript code
console.log(result.map); // Source map for debuggingThe transformer includes comprehensive error handling:
All errors are enhanced with source context using the babelErrorEnhancer function before being thrown.
Install with Tessl CLI
npx tessl i tessl/npm-parcel--transformer-babel