babel-plugin-debug-macros
Version:
Debug macros and feature flag stripping
117 lines (116 loc) • 3.32 kB
TypeScript
import type * as Babel from '@babel/core';
import type { NodePath, types as t } from '@babel/core';
import { CallIdentifierExpression, CallStatementPath } from './babel-type-helpers';
import { ImportUtil } from 'babel-import-util';
export interface Options {
module: boolean | undefined;
global: string | undefined;
assertPredicateIndex: number | undefined;
isDebug: boolean | "@embroider/macros";
}
interface MacroExpressionOpts {
validate?: (expression: CallIdentifierExpression, args: t.CallExpression['arguments']) => void;
buildConsoleAPI?: (expression: CallIdentifierExpression, args: t.CallExpression['arguments']) => t.CallExpression;
consoleAPI?: t.Identifier;
predicate?: (expression: CallIdentifierExpression, args: t.CallExpression['arguments']) => t.CallExpression['arguments'][number] | undefined;
}
export default class Builder {
readonly t: typeof Babel.types;
private module;
private global;
private assertPredicateIndex;
private isDebug;
private util;
private expressions;
constructor(t: typeof Babel.types, util: ImportUtil, options: Options);
/**
* Expands:
*
* assert($PREDICATE, $MESSAGE)
*
* into
*
* ($DEBUG && console.assert($PREDICATE, $MESSAGE));
*
* or
*
* ($DEBUG && assert($PREDICATE, $MESSAGE));
*
* or
*
* ($DEBUG && $GLOBAL_NS.assert($PREDICATE, $MESSAGE));
*/
assert(path: CallStatementPath): void;
/**
* Expands:
*
* warn($MESSAGE)
*
* into
*
* ($DEBUG && console.warn($MESSAGE));
*
* or
*
* ($DEBUG && warn($MESSAGE));
*
* or
*
* ($DEBUG && $GLOBAL_NS.warn($MESSAGE));
*/
warn(path: CallStatementPath): void;
/**
* Expands:
*
* log($MESSAGE)
*
* into
*
* ($DEBUG && console.log($MESSAGE));
*
* or
*
* ($DEBUG && log($MESSAGE));
*
* or
*
* ($DEBUG && $GLOBAL_NS.log($MESSAGE));
*/
log(path: CallStatementPath): void;
_createMacroExpression(path: CallStatementPath, options?: MacroExpressionOpts): void;
/**
* Expands:
*
* deprecate($MESSAGE, $PREDICATE)
*
* or
*
* deprecate($MESSAGE, $PREDICATE, {
* $ID,
* $URL,
* $UNIL
* });
*
* into
*
* ($DEBUG && $PREDICATE && console.warn($MESSAGE));
*
* or
*
* ($DEBUG && $PREDICATE && deprecate($MESSAGE, $PREDICATE, { $ID, $URL, $UNTIL }));
*
* or
*
* ($DEBUG && $PREDICATE && $GLOBAL_NS.deprecate($MESSAGE, $PREDICATE, { $ID, $URL, $UNTIL }));
*/
deprecate(path: CallStatementPath): void;
/**
* Performs the actually expansion of macros
*/
expandMacros(): void;
_debugExpression(target: NodePath): Babel.types.CallExpression | Babel.types.BooleanLiteral;
_createGlobalExternalHelper(identifier: t.Identifier, args: t.CallExpression['arguments'], ns: string): Babel.types.CallExpression;
_createConsoleAPI(identifier: t.Identifier, args: t.CallExpression['arguments']): Babel.types.CallExpression;
_buildLogicalExpressions(identifiers: t.Expression[], callExpression: t.Expression): (debugIdentifier: t.Expression) => t.Expression;
}
export {};