JSPM

babel-errors

1.1.1
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 3214
    • Score
      100M100P100Q117895F
    • License MIT

    Nicer error messages for Babel

    Package Exports

    • babel-errors

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (babel-errors) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    babel-errors

    Nicer error messages for Babel

    import createBabelFile from 'babel-file';
    import {BabelError, prettyError, buildCodeFrameError} from 'babel-errors';
    
    const file = createBabelFile(...);
    
    let path = file.path;
    let {line, column} = path.loc.start;
    
    throw prettyError(createErrorWithLoc('Error at this position', line, column));
    throw buildCodeFrameError(path, 'Error with this Path');

    createErrorWithLoc(message, line, column)

    This lets you add location information to your errors.

    wrapErrorWithCodeFrame(err)

    You can use this when capturing errors thrown by Babel or constructed using createErrorWithLoc to add a code frame when possible.

    buildCodeFrameError(path, message)

    You can use this to build a code frame error around a path with a specified message.

    Use this instead of path.buildCodeFrameError when you aren't running inside a Babel plugin.

    toErrorStack(error)

    Creates string with error name, message, stack/code frame.