本文整理汇总了TypeScript中@babel/code-frame.codeFrameColumns函数的典型用法代码示例。如果您正苦于以下问题:TypeScript codeFrameColumns函数的具体用法?TypeScript codeFrameColumns怎么用?TypeScript codeFrameColumns使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了codeFrameColumns函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: codeFrameError
export function codeFrameError (node, msg: string) {
let errMsg = ''
try {
errMsg = codeFrameColumns(setting.sourceCode, node && node.type && node.loc ? node.loc : node)
} catch (error) {
errMsg = 'failed to locate source'
}
return new Error(`${msg}
-----
${errMsg}`)
}
示例2: printCodeFrame
export function printCodeFrame(
output: PrintFunc,
filename: string | undefined,
line: number | undefined
) {
if (!filename || line == null) {
return
}
const fileContent = fs.readFileSync(filename, 'utf8')
output(
codeFrameColumns(fileContent, { start: { line } }, { forceColor: true })
)
}
示例3: codeFrameColumns
const getRenderedCallsite = (
fileContent: string,
line: number,
column?: number,
) => {
let renderedCallsite = codeFrameColumns(
fileContent,
{start: {column, line}},
{highlightCode: true},
);
renderedCallsite = indentAllLines(renderedCallsite, MESSAGE_INDENT);
renderedCallsite = `\n${renderedCallsite}\n`;
return renderedCallsite;
};
示例4: print
import codeFrame, { codeFrameColumns } from "@babel/code-frame";
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 });
codeFrameColumns(code, { start: { line: 5, column: 22 } });
codeFrameColumns(
code,
{ start: { line: 5, column: 22 } },
{ forceColor: true }
);
codeFrameColumns(
code,
{ start: { line: 2, column: 2 } },
{ highlightCode: true }
);
示例5: return
return (loc: t.SourceLocation) => codeFrameColumns(code, loc) as string
示例6: codeFrameError
export function codeFrameError (loc: t.SourceLocation, msg: string) {
return new Error(`${msg}
-----
${codeFrameColumns(setting.sourceCode, loc)}`)
}