mirror of
https://github.com/SamEyeBam/animate.git
synced 2026-11-17 12:55:42 +00:00
larry babby and threejs for glsl
This commit is contained in:
1 parent
87d5dc634d
commit
907ebae4c0
6474 files changed
+1279596
-8
No files matched your search
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017-present Devon Govett
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+36050
File diff suppressed because it is too large.
Load diff
+1
@@ -0,0 +1 @@
|
||||
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;AAKA,GAEA,SAAS,0BAAI,IAAI;IAEf,gDAAgD;IAChD,IAAI,sBAAsB;IAE1B,+DAA+D;IAC/D,IAAI,cACJ;IAEA,gCAAgC;IAChC,IAAI,cACJ;IAGA,2BAA2B;IAC3B,IAAI,UAAU,cAAc;IAE5B,+DAA+D;IAC/D,IA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WAAW;gBACX,eAAe;gBACf,KAAK;gBACL,YAAY;gBACZ,SAAS;gBACT,UAAU;oBACR,KAAK,UAAU;oBACf;wBACE,WAAW;wBACX,OAAO;wBACP,KAAK;wBACL,UAAU;4BACR,KAAK,gBAAgB;4BACrB,KAAK,iBAAiB;4BACtB,KAAK,mBAAmB;4BACxB,KAAK,oBAAoB;4BACzB;yBACD;oBACH;oBACA;wBAAE,OAAO,UAAU;oBAA0B;iBAC9C;YACH;YACA,KAAK,YAAY;SAClB;QACD,SAAS;IACX;AACF;AAEA,iBAAiB;;;;;ACtFjB;;;;;;;AAOA,GAEA,iCAAiC;AACjC,EAAE;AACF,yFAAyF;AACzF,uDAAuD;AACvD,kCAAkC;ALine truncated
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"name": "@parcel/codeframe",
|
||||
"version": "2.12.0",
|
||||
"description": "Blazing fast, zero configuration web application bundler",
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/parcel"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/parcel-bundler/parcel.git"
|
||||
},
|
||||
"main": "lib/codeframe.js",
|
||||
"source": "src/codeframe.js",
|
||||
"engines": {
|
||||
"node": ">= 12.0.0"
|
||||
},
|
||||
"targets": {
|
||||
"main": {
|
||||
"includeNodeModules": {
|
||||
"chalk": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"chalk": "^4.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"emphasize": "^4.2.0",
|
||||
"slice-ansi": "^4.0.0",
|
||||
"string-width": "^4.2.0"
|
||||
},
|
||||
"gitHead": "2059029ee91e5f03a273b0954d3e629d7375f986"
|
||||
}
|
||||
+302
@@ -0,0 +1,302 @@
|
||||
// @flow
|
||||
import type {DiagnosticCodeHighlight} from '@parcel/diagnostic';
|
||||
|
||||
import chalk from 'chalk';
|
||||
import emphasize from 'emphasize';
|
||||
import stringWidth from 'string-width';
|
||||
import sliceAnsi from 'slice-ansi';
|
||||
|
||||
type CodeFramePadding = {|
|
||||
before: number,
|
||||
after: number,
|
||||
|};
|
||||
|
||||
type CodeFrameOptionsInput = $Shape<CodeFrameOptions>;
|
||||
|
||||
type CodeFrameOptions = {|
|
||||
useColor: boolean,
|
||||
syntaxHighlighting: boolean,
|
||||
maxLines: number,
|
||||
padding: CodeFramePadding,
|
||||
terminalWidth: number,
|
||||
language?: string,
|
||||
|};
|
||||
|
||||
const NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
|
||||
const TAB_REPLACE_REGEX = /\t/g;
|
||||
const TAB_REPLACEMENT = ' ';
|
||||
const DEFAULT_TERMINAL_WIDTH = 80;
|
||||
|
||||
const highlightSyntax = (txt: string, lang?: string): string => {
|
||||
if (lang) {
|
||||
try {
|
||||
return emphasize.highlight(lang, txt).value;
|
||||
} catch (e) {
|
||||
// fallback for unknown languages...
|
||||
}
|
||||
}
|
||||
|
||||
return emphasize.highlightAuto(txt).value;
|
||||
};
|
||||
|
||||
export default function codeFrame(
|
||||
code: string,
|
||||
highlights: Array<DiagnosticCodeHighlight>,
|
||||
inputOpts: CodeFrameOptionsInput = {},
|
||||
): string {
|
||||
if (highlights.length < 1) return '';
|
||||
|
||||
let opts: CodeFrameOptions = {
|
||||
useColor: !!inputOpts.useColor,
|
||||
syntaxHighlighting: !!inputOpts.syntaxHighlighting,
|
||||
language: inputOpts.language,
|
||||
maxLines: inputOpts.maxLines ?? 12,
|
||||
terminalWidth: inputOpts.terminalWidth || DEFAULT_TERMINAL_WIDTH,
|
||||
padding: inputOpts.padding || {
|
||||
before: 1,
|
||||
after: 2,
|
||||
},
|
||||
};
|
||||
|
||||
// Highlights messages and prefixes when colors are enabled
|
||||
const highlighter = (s: string, bold?: boolean) => {
|
||||
if (opts.useColor) {
|
||||
let redString = chalk.red(s);
|
||||
return bold ? chalk.bold(redString) : redString;
|
||||
}
|
||||
|
||||
return s;
|
||||
};
|
||||
|
||||
// Prefix lines with the line number
|
||||
const lineNumberPrefixer = (params: {|
|
||||
lineNumber?: string,
|
||||
lineNumberLength: number,
|
||||
isHighlighted: boolean,
|
||||
|}) => {
|
||||
let {lineNumber, lineNumberLength, isHighlighted} = params;
|
||||
|
||||
return `${isHighlighted ? highlighter('>') : ' '} ${
|
||||
lineNumber
|
||||
? lineNumber.padStart(lineNumberLength, ' ')
|
||||
: ' '.repeat(lineNumberLength)
|
||||
} | `;
|
||||
};
|
||||
|
||||
// Make columns/lines start at 1
|
||||
let originalHighlights = highlights;
|
||||
highlights = highlights.map(h => {
|
||||
return {
|
||||
start: {
|
||||
column: h.start.column - 1,
|
||||
line: h.start.line - 1,
|
||||
},
|
||||
end: {
|
||||
column: h.end.column - 1,
|
||||
line: h.end.line - 1,
|
||||
},
|
||||
message: h.message,
|
||||
};
|
||||
});
|
||||
|
||||
// Find first and last highlight
|
||||
let firstHighlight =
|
||||
highlights.length > 1
|
||||
? highlights.sort((a, b) => a.start.line - b.start.line)[0]
|
||||
: highlights[0];
|
||||
let lastHighlight =
|
||||
highlights.length > 1
|
||||
? highlights.sort((a, b) => b.end.line - a.end.line)[0]
|
||||
: highlights[0];
|
||||
|
||||
// Calculate first and last line index of codeframe
|
||||
let startLine = firstHighlight.start.line - opts.padding.before;
|
||||
startLine = startLine < 0 ? 0 : startLine;
|
||||
let endLineIndex = lastHighlight.end.line + opts.padding.after;
|
||||
let tail;
|
||||
if (endLineIndex - startLine > opts.maxLines) {
|
||||
let maxLine = startLine + opts.maxLines - 1;
|
||||
highlights = highlights.filter(h => h.start.line < maxLine);
|
||||
lastHighlight = highlights[0];
|
||||
endLineIndex = Math.min(
|
||||
maxLine,
|
||||
lastHighlight.end.line + opts.padding.after,
|
||||
);
|
||||
tail = originalHighlights.filter(h => h.start.line > endLineIndex);
|
||||
}
|
||||
|
||||
let lineNumberLength = (endLineIndex + 1).toString(10).length;
|
||||
|
||||
// Split input into lines and highlight syntax
|
||||
let lines = code.split(NEWLINE);
|
||||
let syntaxHighlightedLines = (
|
||||
opts.syntaxHighlighting ? highlightSyntax(code, opts.language) : code
|
||||
)
|
||||
.replace(TAB_REPLACE_REGEX, TAB_REPLACEMENT)
|
||||
.split(NEWLINE);
|
||||
|
||||
// Loop over all lines and create codeframe
|
||||
let resultLines = [];
|
||||
for (
|
||||
let currentLineIndex = startLine;
|
||||
currentLineIndex < syntaxHighlightedLines.length;
|
||||
currentLineIndex++
|
||||
) {
|
||||
if (currentLineIndex > endLineIndex) break;
|
||||
if (currentLineIndex > syntaxHighlightedLines.length - 1) break;
|
||||
|
||||
// Find highlights that need to get rendered on the current line
|
||||
let lineHighlights = highlights
|
||||
.filter(
|
||||
highlight =>
|
||||
highlight.start.line <= currentLineIndex &&
|
||||
highlight.end.line >= currentLineIndex,
|
||||
)
|
||||
.sort(
|
||||
(a, b) =>
|
||||
(a.start.line < currentLineIndex ? 0 : a.start.column) -
|
||||
(b.start.line < currentLineIndex ? 0 : b.start.column),
|
||||
);
|
||||
|
||||
// Check if this line has a full line highlight
|
||||
let isWholeLine =
|
||||
lineHighlights.length &&
|
||||
!!lineHighlights.find(
|
||||
h => h.start.line < currentLineIndex && h.end.line > currentLineIndex,
|
||||
);
|
||||
|
||||
let lineLengthLimit =
|
||||
opts.terminalWidth > lineNumberLength + 7
|
||||
? opts.terminalWidth - (lineNumberLength + 5)
|
||||
: 10;
|
||||
|
||||
// Split the line into line parts that will fit the provided terminal width
|
||||
let colOffset = 0;
|
||||
let lineEndCol = lineLengthLimit;
|
||||
let syntaxHighlightedLine = syntaxHighlightedLines[currentLineIndex];
|
||||
if (stringWidth(syntaxHighlightedLine) > lineLengthLimit) {
|
||||
if (lineHighlights.length > 0) {
|
||||
if (lineHighlights[0].start.line === currentLineIndex) {
|
||||
colOffset = lineHighlights[0].start.column - 5;
|
||||
} else if (lineHighlights[0].end.line === currentLineIndex) {
|
||||
colOffset = lineHighlights[0].end.column - 5;
|
||||
}
|
||||
}
|
||||
|
||||
colOffset = colOffset > 0 ? colOffset : 0;
|
||||
lineEndCol = colOffset + lineLengthLimit;
|
||||
|
||||
syntaxHighlightedLine = sliceAnsi(
|
||||
syntaxHighlightedLine,
|
||||
colOffset,
|
||||
lineEndCol,
|
||||
);
|
||||
}
|
||||
|
||||
// Write the syntax highlighted line part
|
||||
resultLines.push(
|
||||
lineNumberPrefixer({
|
||||
lineNumber: (currentLineIndex + 1).toString(10),
|
||||
lineNumberLength,
|
||||
isHighlighted: lineHighlights.length > 0,
|
||||
}) + syntaxHighlightedLine,
|
||||
);
|
||||
|
||||
let lineWidth = stringWidth(syntaxHighlightedLine);
|
||||
let highlightLine = '';
|
||||
if (isWholeLine) {
|
||||
highlightLine = highlighter('^'.repeat(lineWidth));
|
||||
} else if (lineHighlights.length > 0) {
|
||||
let lastCol = 0;
|
||||
let highlight = null;
|
||||
let highlightHasEnded = false;
|
||||
|
||||
for (
|
||||
let highlightIndex = 0;
|
||||
highlightIndex < lineHighlights.length;
|
||||
highlightIndex++
|
||||
) {
|
||||
// Set highlight to current highlight
|
||||
highlight = lineHighlights[highlightIndex];
|
||||
highlightHasEnded = false;
|
||||
|
||||
// Calculate the startColumn and get the real width by doing a substring of the original
|
||||
// line and replacing tabs with our tab replacement to support tab handling
|
||||
let startCol = 0;
|
||||
if (
|
||||
highlight.start.line === currentLineIndex &&
|
||||
highlight.start.column > colOffset
|
||||
) {
|
||||
startCol = lines[currentLineIndex]
|
||||
.substring(colOffset, highlight.start.column)
|
||||
.replace(TAB_REPLACE_REGEX, TAB_REPLACEMENT).length;
|
||||
}
|
||||
|
||||
// Calculate the endColumn and get the real width by doing a substring of the original
|
||||
// line and replacing tabs with our tab replacement to support tab handling
|
||||
let endCol = lineWidth - 1;
|
||||
if (highlight.end.line === currentLineIndex) {
|
||||
endCol = lines[currentLineIndex]
|
||||
.substring(colOffset, highlight.end.column)
|
||||
.replace(TAB_REPLACE_REGEX, TAB_REPLACEMENT).length;
|
||||
|
||||
// If the endCol is too big for this line part, trim it so we can handle it in the next one
|
||||
if (endCol > lineWidth) {
|
||||
endCol = lineWidth - 1;
|
||||
}
|
||||
|
||||
highlightHasEnded = true;
|
||||
}
|
||||
|
||||
// If endcol is smaller than lastCol it overlaps with another highlight and is no longer visible, we can skip those
|
||||
if (endCol >= lastCol) {
|
||||
let characters = endCol - startCol + 1;
|
||||
if (startCol > lastCol) {
|
||||
// startCol is before lastCol, so add spaces as padding before the highlight indicators
|
||||
highlightLine += ' '.repeat(startCol - lastCol);
|
||||
} else if (lastCol > startCol) {
|
||||
// If last column is larger than the start, there's overlap in highlights
|
||||
// This line adjusts the characters count to ensure we don't add too many characters
|
||||
characters += startCol - lastCol;
|
||||
}
|
||||
|
||||
// Don't crash (and swallow the original message) if the diagnostic is malformed (end is before start).
|
||||
characters = Math.max(1, characters);
|
||||
|
||||
// Append the highlight indicators
|
||||
highlightLine += highlighter('^'.repeat(characters));
|
||||
|
||||
// Set the lastCol equal to character count between start of line part and highlight end-column
|
||||
lastCol = endCol + 1;
|
||||
}
|
||||
|
||||
// There's no point in processing more highlights if we reached the end of the line
|
||||
if (endCol >= lineEndCol - 1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Append the highlight message if the current highlights ends on this line part
|
||||
if (highlight && highlight.message && highlightHasEnded) {
|
||||
highlightLine += ' ' + highlighter(highlight.message, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (highlightLine) {
|
||||
resultLines.push(
|
||||
lineNumberPrefixer({
|
||||
lineNumberLength,
|
||||
isHighlighted: true,
|
||||
}) + highlightLine,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
let result = resultLines.join('\n');
|
||||
|
||||
if (tail && tail.length > 0) {
|
||||
result += '\n\n' + codeFrame(code, tail, inputOpts);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
+822
@@ -0,0 +1,822 @@
|
||||
import assert from 'assert';
|
||||
import {readFileSync} from 'fs';
|
||||
import {join as joinPath} from 'path';
|
||||
|
||||
import codeframe from '../src/codeframe';
|
||||
|
||||
const LINE_END = '\n';
|
||||
|
||||
describe('codeframe', () => {
|
||||
it('should create a codeframe', () => {
|
||||
let codeframeString = codeframe(
|
||||
'hello world',
|
||||
[
|
||||
{
|
||||
start: {
|
||||
column: 1,
|
||||
line: 1,
|
||||
},
|
||||
end: {
|
||||
column: 1,
|
||||
line: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
start: {
|
||||
column: 3,
|
||||
line: 1,
|
||||
},
|
||||
end: {
|
||||
column: 5,
|
||||
line: 1,
|
||||
},
|
||||
},
|
||||
],
|
||||
{useColor: false},
|
||||
);
|
||||
|
||||
let lines = codeframeString.split(LINE_END);
|
||||
assert.equal(lines[0], '> 1 | hello world');
|
||||
assert.equal(lines[1], '> | ^ ^^^');
|
||||
});
|
||||
|
||||
it('should create a codeframe with multiple lines', () => {
|
||||
let codeframeString = codeframe(
|
||||
'hello world\nEnjoy this nice codeframe',
|
||||
[
|
||||
{
|
||||
start: {
|
||||
column: 1,
|
||||
line: 1,
|
||||
},
|
||||
end: {
|
||||
column: 1,
|
||||
line: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
start: {
|
||||
column: 7,
|
||||
line: 1,
|
||||
},
|
||||
end: {
|
||||
column: 10,
|
||||
line: 2,
|
||||
},
|
||||
},
|
||||
],
|
||||
{useColor: false},
|
||||
);
|
||||
|
||||
let lines = codeframeString.split(LINE_END);
|
||||
assert.equal(lines[0], '> 1 | hello world');
|
||||
assert.equal(lines[1], '> | ^ ^^^^^');
|
||||
assert.equal(lines[2], '> 2 | Enjoy this nice codeframe');
|
||||
assert.equal(lines[3], '> | ^^^^^^^^^^');
|
||||
});
|
||||
|
||||
it('should handle unordered overlapping highlights properly', () => {
|
||||
let codeframeString = codeframe(
|
||||
'hello world\nEnjoy this nice codeframe',
|
||||
[
|
||||
{
|
||||
start: {
|
||||
column: 1,
|
||||
line: 1,
|
||||
},
|
||||
end: {
|
||||
column: 1,
|
||||
line: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
start: {
|
||||
column: 7,
|
||||
line: 1,
|
||||
},
|
||||
end: {
|
||||
column: 10,
|
||||
line: 2,
|
||||
},
|
||||
},
|
||||
{
|
||||
start: {
|
||||
column: 4,
|
||||
line: 2,
|
||||
},
|
||||
end: {
|
||||
column: 7,
|
||||
line: 2,
|
||||
},
|
||||
},
|
||||
],
|
||||
{useColor: false},
|
||||
);
|
||||
|
||||
let lines = codeframeString.split(LINE_END);
|
||||
assert.equal(lines[0], '> 1 | hello world');
|
||||
assert.equal(lines[1], '> | ^ ^^^^^');
|
||||
assert.equal(lines[2], '> 2 | Enjoy this nice codeframe');
|
||||
assert.equal(lines[3], '> | ^^^^^^^^^^');
|
||||
});
|
||||
|
||||
it('should handle partial overlapping highlights properly', () => {
|
||||
let codeframeString = codeframe(
|
||||
'hello world\nEnjoy this nice codeframe',
|
||||
[
|
||||
{
|
||||
start: {
|
||||
column: 1,
|
||||
line: 1,
|
||||
},
|
||||
end: {
|
||||
column: 1,
|
||||
line: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
start: {
|
||||
column: 7,
|
||||
line: 1,
|
||||
},
|
||||
end: {
|
||||
column: 10,
|
||||
line: 2,
|
||||
},
|
||||
},
|
||||
{
|
||||
start: {
|
||||
column: 4,
|
||||
line: 2,
|
||||
},
|
||||
end: {
|
||||
column: 12,
|
||||
line: 2,
|
||||
},
|
||||
},
|
||||
],
|
||||
{useColor: false},
|
||||
);
|
||||
|
||||
let lines = codeframeString.split(LINE_END);
|
||||
assert.equal(lines[0], '> 1 | hello world');
|
||||
assert.equal(lines[1], '> | ^ ^^^^^');
|
||||
assert.equal(lines[2], '> 2 | Enjoy this nice codeframe');
|
||||
assert.equal(lines[3], '> | ^^^^^^^^^^^^');
|
||||
});
|
||||
|
||||
it('should be able to render inline messages', () => {
|
||||
let codeframeString = codeframe(
|
||||
'hello world\nEnjoy this nice codeframe',
|
||||
[
|
||||
{
|
||||
start: {
|
||||
column: 1,
|
||||
line: 1,
|
||||
},
|
||||
end: {
|
||||
column: 6,
|
||||
line: 1,
|
||||
},
|
||||
message: 'test',
|
||||
},
|
||||
],
|
||||
{useColor: false},
|
||||
);
|
||||
|
||||
let lines = codeframeString.split(LINE_END);
|
||||
assert.equal(lines[0], '> 1 | hello world');
|
||||
assert.equal(lines[1], '> | ^^^^^^ test');
|
||||
assert.equal(lines[2], ' 2 | Enjoy this nice codeframe');
|
||||
});
|
||||
|
||||
it('should only render last inline message of a column', () => {
|
||||
let codeframeString = codeframe(
|
||||
'hello world\nEnjoy this nice codeframe',
|
||||
[
|
||||
{
|
||||
start: {
|
||||
column: 1,
|
||||
line: 1,
|
||||
},
|
||||
end: {
|
||||
column: 3,
|
||||
line: 1,
|
||||
},
|
||||
message: 'test',
|
||||
},
|
||||
{
|
||||
start: {
|
||||
column: 1,
|
||||
line: 1,
|
||||
},
|
||||
end: {
|
||||
column: 6,
|
||||
line: 1,
|
||||
},
|
||||
message: 'this should be printed',
|
||||
},
|
||||
],
|
||||
{useColor: false},
|
||||
);
|
||||
|
||||
let lines = codeframeString.split(LINE_END);
|
||||
assert.equal(lines[0], '> 1 | hello world');
|
||||
assert.equal(lines[1], '> | ^^^^^^ this should be printed');
|
||||
assert.equal(lines[2], ' 2 | Enjoy this nice codeframe');
|
||||
});
|
||||
|
||||
it('should only render last inline message of a column with space', () => {
|
||||
let codeframeString = codeframe(
|
||||
'hello world\nEnjoy this nice codeframe',
|
||||
[
|
||||
{
|
||||
start: {
|
||||
column: 1,
|
||||
line: 1,
|
||||
},
|
||||
end: {
|
||||
column: 1,
|
||||
line: 1,
|
||||
},
|
||||
message: 'test',
|
||||
},
|
||||
{
|
||||
start: {
|
||||
column: 3,
|
||||
line: 1,
|
||||
},
|
||||
end: {
|
||||
column: 7,
|
||||
line: 1,
|
||||
},
|
||||
message: 'this should be printed',
|
||||
},
|
||||
],
|
||||
{useColor: false},
|
||||
);
|
||||
|
||||
let lines = codeframeString.split(LINE_END);
|
||||
assert.equal(lines[0], '> 1 | hello world');
|
||||
assert.equal(lines[1], '> | ^ ^^^^^ this should be printed');
|
||||
assert.equal(lines[2], ' 2 | Enjoy this nice codeframe');
|
||||
});
|
||||
|
||||
it('should only render last inline message of a column with multiple lines and space', () => {
|
||||
let codeframeString = codeframe(
|
||||
'hello world\nEnjoy this nice codeframe\nThis is another line',
|
||||
[
|
||||
{
|
||||
start: {
|
||||
column: 1,
|
||||
line: 1,
|
||||
},
|
||||
end: {
|
||||
column: 1,
|
||||
line: 1,
|
||||
},
|
||||
message: 'test',
|
||||
},
|
||||
{
|
||||
start: {
|
||||
column: 3,
|
||||
line: 1,
|
||||
},
|
||||
end: {
|
||||
column: 7,
|
||||
line: 1,
|
||||
},
|
||||
message: 'this should be printed',
|
||||
},
|
||||
{
|
||||
start: {
|
||||
column: 3,
|
||||
line: 2,
|
||||
},
|
||||
end: {
|
||||
column: 7,
|
||||
line: 3,
|
||||
},
|
||||
message: 'message line 2',
|
||||
},
|
||||
],
|
||||
{useColor: false},
|
||||
);
|
||||
|
||||
let lines = codeframeString.split(LINE_END);
|
||||
assert.equal(lines[0], '> 1 | hello world');
|
||||
assert.equal(lines[1], '> | ^ ^^^^^ this should be printed');
|
||||
assert.equal(lines[2], '> 2 | Enjoy this nice codeframe');
|
||||
assert.equal(lines[3], '> | ^^^^^^^^^^^^^^^^^^^^^^^');
|
||||
assert.equal(lines[4], '> 3 | This is another line');
|
||||
assert.equal(lines[5], '> | ^^^^^^^ message line 2');
|
||||
});
|
||||
|
||||
it('should only render last inline message of a column with multiple lines and space', () => {
|
||||
let codeframeString = codeframe(
|
||||
'hello world\nEnjoy this nice codeframe\nThis is another line',
|
||||
[
|
||||
{
|
||||
start: {
|
||||
column: 1,
|
||||
line: 1,
|
||||
},
|
||||
end: {
|
||||
column: 1,
|
||||
line: 1,
|
||||
},
|
||||
message: 'test',
|
||||
},
|
||||
{
|
||||
start: {
|
||||
column: 3,
|
||||
line: 1,
|
||||
},
|
||||
end: {
|
||||
column: 7,
|
||||
line: 1,
|
||||
},
|
||||
message: 'this should be printed',
|
||||
},
|
||||
{
|
||||
start: {
|
||||
column: 3,
|
||||
line: 2,
|
||||
},
|
||||
end: {
|
||||
column: 7,
|
||||
line: 3,
|
||||
},
|
||||
message: 'message line 2',
|
||||
},
|
||||
],
|
||||
{useColor: false},
|
||||
);
|
||||
|
||||
let lines = codeframeString.split(LINE_END);
|
||||
assert.equal(lines[0], '> 1 | hello world');
|
||||
assert.equal(lines[1], '> | ^ ^^^^^ this should be printed');
|
||||
assert.equal(lines[2], '> 2 | Enjoy this nice codeframe');
|
||||
assert.equal(lines[3], '> | ^^^^^^^^^^^^^^^^^^^^^^^');
|
||||
assert.equal(lines[4], '> 3 | This is another line');
|
||||
assert.equal(lines[5], '> | ^^^^^^^ message line 2');
|
||||
});
|
||||
|
||||
it('should properly use padding', () => {
|
||||
let codeframeString = codeframe(
|
||||
'test\n'.repeat(100),
|
||||
[
|
||||
{
|
||||
start: {
|
||||
column: 2,
|
||||
line: 5,
|
||||
},
|
||||
end: {
|
||||
column: 2,
|
||||
line: 5,
|
||||
},
|
||||
message: 'test',
|
||||
},
|
||||
],
|
||||
{
|
||||
useColor: false,
|
||||
padding: {
|
||||
before: 2,
|
||||
after: 4,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
let lines = codeframeString.split(LINE_END);
|
||||
assert.equal(lines.length, 8);
|
||||
assert.equal(lines[0], ' 3 | test');
|
||||
assert.equal(lines[2], '> 5 | test');
|
||||
assert.equal(lines[3], '> | ^ test');
|
||||
assert.equal(lines[7], ' 9 | test');
|
||||
});
|
||||
|
||||
it('should properly pad numbers for large files', () => {
|
||||
let codeframeString = codeframe('test\n'.repeat(1000), [
|
||||
{
|
||||
start: {
|
||||
column: 2,
|
||||
line: 99,
|
||||
},
|
||||
end: {
|
||||
column: 2,
|
||||
line: 99,
|
||||
},
|
||||
message: 'test',
|
||||
},
|
||||
{
|
||||
start: {
|
||||
column: 2,
|
||||
line: 100,
|
||||
},
|
||||
end: {
|
||||
column: 2,
|
||||
line: 100,
|
||||
},
|
||||
message: 'test 2',
|
||||
},
|
||||
]);
|
||||
|
||||
let lines = codeframeString.split(LINE_END);
|
||||
assert.equal(lines.length, 7);
|
||||
assert.equal(lines[0], ' 98 | test');
|
||||
assert.equal(lines[1], '> 99 | test');
|
||||
assert.equal(lines[2], '> | ^ test');
|
||||
assert.equal(lines[3], '> 100 | test');
|
||||
assert.equal(lines[4], '> | ^ test 2');
|
||||
assert.equal(lines[5], ' 101 | test');
|
||||
assert.equal(lines[6], ' 102 | test');
|
||||
});
|
||||
|
||||
it('should properly pad numbers for short files', () => {
|
||||
let codeframeString = codeframe('test\n'.repeat(1000), [
|
||||
{
|
||||
start: {
|
||||
column: 2,
|
||||
line: 7,
|
||||
},
|
||||
end: {
|
||||
column: 2,
|
||||
line: 7,
|
||||
},
|
||||
message: 'test',
|
||||
},
|
||||
{
|
||||
start: {
|
||||
column: 2,
|
||||
line: 12,
|
||||
},
|
||||
end: {
|
||||
column: 2,
|
||||
line: 12,
|
||||
},
|
||||
message: 'test',
|
||||
},
|
||||
]);
|
||||
|
||||
let lines = codeframeString.split(LINE_END);
|
||||
assert.equal(lines.length, 11);
|
||||
assert.equal(lines[0], ' 6 | test');
|
||||
assert.equal(lines[4], ' 9 | test');
|
||||
assert.equal(lines[5], ' 10 | test');
|
||||
assert.equal(lines[6], ' 11 | test');
|
||||
assert.equal(lines[10], ' 14 | test');
|
||||
});
|
||||
|
||||
it('should properly use maxLines', () => {
|
||||
let line = 'test '.repeat(100);
|
||||
let codeframeString = codeframe(
|
||||
`${line}\n`.repeat(100),
|
||||
[
|
||||
{
|
||||
start: {
|
||||
column: 2,
|
||||
line: 5,
|
||||
},
|
||||
end: {
|
||||
column: 2,
|
||||
line: 5,
|
||||
},
|
||||
message: 'test',
|
||||
},
|
||||
{
|
||||
start: {
|
||||
column: 2,
|
||||
line: 12,
|
||||
},
|
||||
end: {
|
||||
column: 2,
|
||||
line: 20,
|
||||
},
|
||||
message: 'test',
|
||||
},
|
||||
],
|
||||
{
|
||||
useColor: false,
|
||||
maxLines: 10,
|
||||
terminalWidth: 5,
|
||||
},
|
||||
);
|
||||
|
||||
let lines = codeframeString.split(LINE_END);
|
||||
assert.equal(lines.length, 13);
|
||||
assert.equal(lines[0], ' 4 | test test ');
|
||||
assert.equal(lines[7], ' 10 | test test ');
|
||||
assert.equal(lines[11], '> 13 | test test ');
|
||||
assert.equal(lines[12], '> | ^^^^^^^^^^');
|
||||
});
|
||||
|
||||
it('should be able to handle tabs', () => {
|
||||
let codeframeString = codeframe(
|
||||
'hel\tlo wor\tld\nEnjoy thi\ts nice cod\teframe',
|
||||
[
|
||||
{
|
||||
start: {
|
||||
column: 5,
|
||||
line: 1,
|
||||
},
|
||||
end: {
|
||||
column: 8,
|
||||
line: 1,
|
||||
},
|
||||
message: 'test',
|
||||
},
|
||||
],
|
||||
{useColor: false},
|
||||
);
|
||||
|
||||
let lines = codeframeString.split(LINE_END);
|
||||
assert.equal(lines[0], '> 1 | hel lo wor ld');
|
||||
assert.equal(lines[1], '> | ^^^^ test');
|
||||
assert.equal(lines[2], ' 2 | Enjoy thi s nice cod eframe');
|
||||
});
|
||||
|
||||
it('should be able to handle tabs with multiple highlights', () => {
|
||||
let codeframeString = codeframe(
|
||||
'hel\tlo wor\tld\nEnjoy thi\ts nice cod\teframe',
|
||||
[
|
||||
{
|
||||
start: {
|
||||
column: 3,
|
||||
line: 1,
|
||||
},
|
||||
end: {
|
||||
column: 5,
|
||||
line: 1,
|
||||
},
|
||||
message: 'test',
|
||||
},
|
||||
{
|
||||
start: {
|
||||
column: 7,
|
||||
line: 1,
|
||||
},
|
||||
end: {
|
||||
column: 8,
|
||||
line: 1,
|
||||
},
|
||||
message: 'test',
|
||||
},
|
||||
],
|
||||
{useColor: false},
|
||||
);
|
||||
|
||||
let lines = codeframeString.split(LINE_END);
|
||||
assert.equal(lines[0], '> 1 | hel lo wor ld');
|
||||
assert.equal(lines[1], '> | ^^^^ ^^ test');
|
||||
assert.equal(lines[2], ' 2 | Enjoy thi s nice cod eframe');
|
||||
});
|
||||
|
||||
it('multiline highlights with tabs', () => {
|
||||
let codeframeString = codeframe(
|
||||
'hel\tlo wor\tld\nEnjoy thi\ts nice cod\teframe\ntest',
|
||||
[
|
||||
{
|
||||
start: {
|
||||
column: 3,
|
||||
line: 1,
|
||||
},
|
||||
end: {
|
||||
column: 2,
|
||||
line: 3,
|
||||
},
|
||||
message: 'test',
|
||||
},
|
||||
],
|
||||
{useColor: false},
|
||||
);
|
||||
|
||||
let lines = codeframeString.split(LINE_END);
|
||||
assert.equal(lines[0], '> 1 | hel lo wor ld');
|
||||
assert.equal(lines[1], '> | ^^^^^^^^^^^^^');
|
||||
assert.equal(lines[2], '> 2 | Enjoy thi s nice cod eframe');
|
||||
assert.equal(lines[3], '> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^');
|
||||
assert.equal(lines[4], '> 3 | test');
|
||||
assert.equal(lines[5], '> | ^^ test');
|
||||
});
|
||||
|
||||
it('Should truncate long lines and print message', () => {
|
||||
let originalLine = 'hello world '.repeat(1000);
|
||||
let codeframeString = codeframe(
|
||||
originalLine,
|
||||
[
|
||||
{
|
||||
start: {
|
||||
column: 1000,
|
||||
line: 1,
|
||||
},
|
||||
end: {
|
||||
column: 1200,
|
||||
line: 1,
|
||||
},
|
||||
message: 'This is a message',
|
||||
},
|
||||
],
|
||||
{useColor: false, terminalWidth: 25},
|
||||
);
|
||||
|
||||
let lines = codeframeString.split(LINE_END);
|
||||
assert.equal(lines.length, 2);
|
||||
assert.equal(lines[0], '> 1 | d hello world hello');
|
||||
assert.equal(lines[1], '> | ^^^^^^^^^^^^^^ This is a message');
|
||||
});
|
||||
|
||||
it('Truncation across multiple lines', () => {
|
||||
let originalLine =
|
||||
'hello world '.repeat(100) + '\n' + 'new line '.repeat(100);
|
||||
let codeframeString = codeframe(
|
||||
originalLine,
|
||||
[
|
||||
{
|
||||
start: {
|
||||
column: 15,
|
||||
line: 1,
|
||||
},
|
||||
end: {
|
||||
column: 400,
|
||||
line: 1,
|
||||
},
|
||||
message: 'This is the first line',
|
||||
},
|
||||
{
|
||||
start: {
|
||||
column: 2,
|
||||
line: 2,
|
||||
},
|
||||
end: {
|
||||
column: 100,
|
||||
line: 2,
|
||||
},
|
||||
message: 'This is the second line',
|
||||
},
|
||||
],
|
||||
{useColor: false, terminalWidth: 25},
|
||||
);
|
||||
|
||||
let lines = codeframeString.split(LINE_END);
|
||||
assert.equal(lines.length, 4);
|
||||
assert.equal(lines[0], '> 1 | ld hello world hell');
|
||||
assert.equal(lines[1], '> | ^^^^^^^^^^^^^^ This is the first line');
|
||||
assert.equal(lines[2], '> 2 | new line new line n');
|
||||
assert.equal(lines[3], '> | ^^^^^^^^^^^^^^^^^^ This is the second line');
|
||||
});
|
||||
|
||||
it('Truncation across various types and positions of highlights', () => {
|
||||
let originalLine =
|
||||
'hello world '.repeat(100) + '\n' + 'new line '.repeat(100);
|
||||
let codeframeString = codeframe(
|
||||
originalLine,
|
||||
[
|
||||
{
|
||||
start: {
|
||||
column: 2,
|
||||
line: 1,
|
||||
},
|
||||
end: {
|
||||
column: 5,
|
||||
line: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
start: {
|
||||
column: 6,
|
||||
line: 1,
|
||||
},
|
||||
end: {
|
||||
column: 10,
|
||||
line: 1,
|
||||
},
|
||||
message: 'I have a message',
|
||||
},
|
||||
{
|
||||
start: {
|
||||
column: 15,
|
||||
line: 1,
|
||||
},
|
||||
end: {
|
||||
column: 25,
|
||||
line: 1,
|
||||
},
|
||||
message: 'I also have a message',
|
||||
},
|
||||
{
|
||||
start: {
|
||||
column: 2,
|
||||
line: 2,
|
||||
},
|
||||
end: {
|
||||
column: 5,
|
||||
line: 2,
|
||||
},
|
||||
message: 'This is the second line',
|
||||
},
|
||||
],
|
||||
{useColor: false, terminalWidth: 25},
|
||||
);
|
||||
|
||||
let lines = codeframeString.split(LINE_END);
|
||||
assert.equal(lines.length, 4);
|
||||
assert.equal(lines[0], '> 1 | hello world hello w');
|
||||
assert.equal(lines[1], '> | ^^^^^^^^^ ^^^^^ I also have a message');
|
||||
assert.equal(lines[2], '> 2 | new line new line n');
|
||||
assert.equal(lines[3], '> | ^^^^ This is the second line');
|
||||
});
|
||||
|
||||
it('Multi-line highlight w/ truncation', () => {
|
||||
let originalLine =
|
||||
'hello world '.repeat(100) + '\n' + 'new line '.repeat(100);
|
||||
let codeframeString = codeframe(
|
||||
originalLine,
|
||||
[
|
||||
{
|
||||
start: {
|
||||
column: 2,
|
||||
line: 1,
|
||||
},
|
||||
end: {
|
||||
column: 151,
|
||||
line: 2,
|
||||
},
|
||||
message: 'I have a message',
|
||||
},
|
||||
],
|
||||
{useColor: false, terminalWidth: 25},
|
||||
);
|
||||
|
||||
let lines = codeframeString.split(LINE_END);
|
||||
assert.equal(lines.length, 4);
|
||||
assert.equal(lines[0], '> 1 | hello world hello w');
|
||||
assert.equal(lines[1], '> | ^^^^^^^^^^^^^^^^^^');
|
||||
assert.equal(lines[2], '> 2 | ew line new line ne');
|
||||
assert.equal(lines[3], '> | ^^^^^^ I have a message');
|
||||
});
|
||||
|
||||
it('Should pad properly, T-650', () => {
|
||||
let fileContent = readFileSync(
|
||||
joinPath(__dirname, './fixtures/a.js'),
|
||||
'utf8',
|
||||
);
|
||||
let codeframeString = codeframe(
|
||||
fileContent,
|
||||
[
|
||||
{
|
||||
start: {
|
||||
line: 8,
|
||||
column: 10,
|
||||
},
|
||||
end: {
|
||||
line: 8,
|
||||
column: 48,
|
||||
},
|
||||
},
|
||||
],
|
||||
{
|
||||
useColor: false,
|
||||
syntaxHighlighting: false,
|
||||
language: 'js',
|
||||
terminalWidth: 100,
|
||||
},
|
||||
);
|
||||
|
||||
let lines = codeframeString.split(LINE_END);
|
||||
assert.equal(lines.length, 5);
|
||||
assert.equal(lines[0], ` 7 | import Tooltip from '../tooltip';`);
|
||||
assert.equal(
|
||||
lines[1],
|
||||
`> 8 | import VisuallyHidden from '../visually-hidden';`,
|
||||
);
|
||||
assert.equal(
|
||||
lines[2],
|
||||
'> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^',
|
||||
);
|
||||
assert.equal(lines[3], ' 9 | ');
|
||||
assert.equal(lines[4], ' 10 | /**');
|
||||
});
|
||||
|
||||
it('should still generate a codeframe when end is before start', () => {
|
||||
let codeframeString = codeframe(
|
||||
'hello world',
|
||||
[
|
||||
{
|
||||
start: {
|
||||
column: 5,
|
||||
line: 1,
|
||||
},
|
||||
end: {
|
||||
column: 1,
|
||||
line: 1,
|
||||
},
|
||||
},
|
||||
],
|
||||
{useColor: false},
|
||||
);
|
||||
|
||||
let lines = codeframeString.split(LINE_END);
|
||||
assert.equal(lines[0], '> 1 | hello world');
|
||||
assert.equal(lines[1], '> | ^');
|
||||
});
|
||||
});
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import test from 'test';
|
||||
import component from './component';
|
||||
|
||||
/**
|
||||
* This is a comment
|
||||
*/
|
||||
import Tooltip from '../tooltip';
|
||||
import VisuallyHidden from '../visually-hidden';
|
||||
|
||||
/**
|
||||
* This is another comment
|
||||
*/
|
||||
import {Label} from './label';
|
||||
Reference in new issue
Block a user