mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 04:50:18 +00:00
Add babel-code-frame (#13102)
* Add babel-code-frame * Add babel-code-frame * index * Follow naming convention * tests * ref fix * Address issues raised in code review * CR fixes * make options... optional * Update test to not assert
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import codeFrame from "babel-code-frame";
|
||||
|
||||
describe('babel-code-frame', () => {
|
||||
it('frames given code', () => {
|
||||
const code = `
|
||||
const number = 1;
|
||||
var string = 'foo';
|
||||
|
||||
function print(name: string) {
|
||||
console.log(string + name);
|
||||
}
|
||||
`;
|
||||
|
||||
codeFrame(code, 5, 22);
|
||||
codeFrame(code, 5, 22, { forceColor: true });
|
||||
codeFrame(code, 2, 2, { highlightCode: true });
|
||||
});
|
||||
});
|
||||
Vendored
+36
@@ -0,0 +1,36 @@
|
||||
// Type definitions for babel-code-frame 6.16
|
||||
// Project: https://github.com/babel/babel/tree/master/packages
|
||||
// Definitions by: Mohsen Azimi <https://github.com/mohsen1>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
interface BabelCodeFrameOptions {
|
||||
/** Syntax highlight the code as JavaScript for terminals. default: false*/
|
||||
highlightCode?: boolean;
|
||||
/** The number of lines to show above the error. default: 2 */
|
||||
linesBelow?: number;
|
||||
/** The number of lines to show below the error. default: 3 */
|
||||
linesAbove?: number;
|
||||
/**
|
||||
* Forcibly syntax highlight the code as JavaScript (for non-terminals);
|
||||
* overrides highlightCode.
|
||||
* default: false
|
||||
*/
|
||||
forceColor?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate errors that contain a code frame that point to source locations.
|
||||
*
|
||||
* @param rawLines Raw lines to frame
|
||||
* @param lineNumber Line number (1 indexed)
|
||||
* @param colNumber Column number
|
||||
* @param options Additional options
|
||||
*
|
||||
* @returns Framed code
|
||||
*/
|
||||
export default function babelCodeFrame(
|
||||
rawLines: string,
|
||||
lineNumber: number,
|
||||
colNumber: number,
|
||||
options?: BabelCodeFrameOptions
|
||||
): string;
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [
|
||||
"mocha"
|
||||
],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"babel-code-frame-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "../tslint.json"
|
||||
}
|
||||
Reference in New Issue
Block a user