1. babel-code-frame
Generate errors that contain a code frame that point to source locations.
babel-code-frame
Package: babel-code-frame
Created by: babel
Last modified: Mon, 13 Jun 2022 03:59:44 GMT
Version: 6.26.0
License: MIT
Downloads: 18,332,173
Repository: https://github.com/babel/babel/tree/master/packages/babel-code-frame

Install

npm install babel-code-frame
yarn add babel-code-frame

babel-code-frame

Generate errors that contain a code frame that point to source locations.

Install

 npm install --save-dev babel-code-frame

Usage

 import codeFrame from 'babel-code-frame';

const rawLines = `class Foo {
  constructor()
}`;
const lineNumber = 2;
const colNumber = 16;

const result = codeFrame(rawLines, lineNumber, colNumber, { /* options */ });

console.log(result);
   1 | class Foo {
> 2 |   constructor()
    |                ^
  3 | }

If the column number is not known, you may pass null instead.

Options

highlightCode

boolean, defaults to false.

Toggles syntax highlighting the code as JavaScript for terminals.

linesAbove

number, defaults to 2.

Adjust the number of lines to show above the error.

linesBelow

number, defaults to 3.

Adjust the number of lines to show below the error.

forceColor

boolean, defaults to false.

Enable this to forcibly syntax highlight the code as JavaScript (for non-terminals); overrides highlightCode.

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin