Collection of debug messages used by Babel for consistent error reporting and debugging output across the JavaScript transpilation ecosystem.
npx @tessl/cli install tessl/npm-babel-messages@6.23.0babel-messages provides a centralized collection of debug and error messages used throughout the Babel JavaScript transpilation ecosystem. It offers predefined message templates with placeholder support for dynamic content insertion, ensuring consistent error reporting and debugging output across all Babel tools and plugins.
npm install babel-messagesimport * as messages from 'babel-messages';
import { MESSAGES, get, parseArgs } from 'babel-messages';For CommonJS:
const messages = require('babel-messages');
const { MESSAGES, get, parseArgs } = require('babel-messages');import { get, MESSAGES } from 'babel-messages';
// Get a simple message
const message = get('readOnly', 'someVariable');
// Result: "someVariable is read-only"
// Access all messages directly
console.log(MESSAGES.didYouMean);
// Result: "Did you mean $1?"
// Custom argument parsing
import { parseArgs } from 'babel-messages';
const args = parseArgs([{name: 'test'}, 42, null]);
// Result: ['{"name":"test"}', '42', 'null']Retrieves formatted messages with placeholder replacement for consistent error reporting across Babel ecosystem.
/**
* Get a message with $1, $2, etc. placeholders replaced by arguments
* @param key - Message key from MESSAGES object
* @param args - Variable arguments to replace placeholders
* @returns Formatted message string with placeholders replaced
* @throws ReferenceError if key is not found in MESSAGES object
*/
function get(key: string, ...args: Array<any>): string;Collection of predefined debug and error message templates covering all Babel subsystems.
const MESSAGES: {
// General/Core Messages
tailCallReassignmentDeopt: string;
readOnly: string;
didYouMean: string;
codeGeneratorDeopt: string;
missingTemplatesDirectory: string;
unsupportedOutputType: string;
illegalMethodName: string;
lostTrackNodePath: string;
// Class-related Messages
classesIllegalBareSuper: string;
classesIllegalSuperCall: string;
// Scope/Variable Messages
scopeDuplicateDeclaration: string;
undeclaredVariable: string;
undeclaredVariableType: string;
undeclaredVariableSuggestion: string;
// Syntax/Parser Messages
settersNoRest: string;
noAssignmentsInForHead: string;
expectedMemberExpressionOrIdentifier: string;
invalidParentForThisNode: string;
unknownForHead: string;
// Module System Messages
modulesIllegalExportName: string;
modulesDuplicateDeclarations: string;
// Traversal Messages
traverseNeedsParent: string;
traverseVerifyRootFunction: string;
traverseVerifyVisitorProperty: string;
traverseVerifyNodeType: string;
// Plugin System Messages
pluginNotObject: string;
pluginNotFunction: string;
pluginUnknown: string;
pluginInvalidProperty: string;
};Message Categories:
Converts various argument types to string representations for message formatting.
/**
* Convert arguments to string representations for message formatting
* @param args - Array of values to stringify
* @returns Array of string representations of the input values
*/
function parseArgs(args: Array<any>): Array<string>;Conversion Strategy:
.inspect() method if available on the valueJSON.stringify() or string concatenationutil.inspect() as final fallback for complex objectsimport { get } from 'babel-messages';
// Generate specific error messages
const duplicateError = get('scopeDuplicateDeclaration', 'myVariable');
// "Duplicate declaration myVariable"
const pluginError = get('pluginNotFunction', '.babelrc', 'my-plugin', 'object');
// "Plugin my-plugin specified in .babelrc was expected to return a function but returned object"
const undeclaredWithSuggestion = get('undeclaredVariableSuggestion', 'varName', 'variableName');
// "Reference to undeclared variable varName - did you mean variableName?"import { MESSAGES } from 'babel-messages';
// Access raw templates for custom processing
const template = MESSAGES.codeGeneratorDeopt;
// "Note: The code generator has deoptimised the styling of $1 as it exceeds the max of $2."
// Use with custom placeholder replacement
const customMessage = template.replace(/\$(\d+)/g, (match, num) => {
return customArgs[parseInt(num) - 1];
});import { parseArgs } from 'babel-messages';
// Handle complex objects
const complexArgs = [
{ ast: 'node', type: 'Identifier' },
null,
undefined,
function myFunc() {},
new Date()
];
const stringified = parseArgs(complexArgs);
// Results in appropriate string representations for each typeThe get() function throws a ReferenceError when attempting to retrieve non-existent message keys:
import { get } from 'babel-messages';
try {
get('nonExistentMessage');
} catch (error) {
console.log(error instanceof ReferenceError); // true
console.log(error.message); // 'Unknown message "nonExistentMessage"'
}