Brunobkr/llama.cpp_AlgMor24_github
ΩFFFΣLLIa • llama.cpp • AlgMor24 ██████╗ ███████╗███████╗███████╗██╗ ██╗ ██╗ █████╗ ██╔═══██╗██╔════╝██╔════╝██╔════╝██║ ██║ ██║██╔══██╗ ██║ ██║█████╗ █████╗ █████╗ ██║ ██║ ██║███████║ ██║ ██║██╔══╝ ██╔══╝ ██╔══╝ ██║ ██║ ██║██╔══██║ ╚██████╔╝██║ ██║ ███████╗███████╗███████╗██║██║ ██║ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚══════╝╚═╝╚═╝ ╚═╝ High-Performance LLM / VLM Inference & Autonomous Agentic Ecosystem… See the full description on the dataset page: https://huggingface.co/datasets/Brunobkr/llama.cpp_AlgMor24_github.
03.1k
1/** @import { TSESTree } from '@typescript-eslint/types' */2/** @import { Visitors } from '../../types.js' */3/** @import { TSOptions, BaseComment } from '../types.js' */4import { Context } from 'esrap';5 6/** @typedef {TSESTree.Node} Node */7 8/** @type {Record<TSESTree.Expression['type'] | 'Super' | 'RestElement', number>} */9export const EXPRESSIONS_PRECEDENCE = {10 JSXFragment: 20,11 JSXElement: 20,12 ArrayPattern: 20,13 ObjectPattern: 20,14 ArrayExpression: 20,15 TaggedTemplateExpression: 20,16 ThisExpression: 20,17 Identifier: 20,18 TemplateLiteral: 20,19 Super: 20,20 SequenceExpression: 20,21 MemberExpression: 19,22 MetaProperty: 19,23 CallExpression: 19,24 ChainExpression: 19,25 ImportExpression: 19,26 NewExpression: 19,27 Literal: 18,28 TSInstantiationExpression: 18,29 TSNonNullExpression: 18,30 TSTypeAssertion: 18,31 AwaitExpression: 17,32 ClassExpression: 17,33 FunctionExpression: 17,34 ObjectExpression: 17,35 UpdateExpression: 16,36 UnaryExpression: 15,37 BinaryExpression: 14,38 // `as`/`satisfies` sit between binary and logical operators39 TSAsExpression: 13,40 TSSatisfiesExpression: 13,41 LogicalExpression: 12,42 ConditionalExpression: 4,43 ArrowFunctionExpression: 3,44 AssignmentExpression: 3,45 YieldExpression: 2,46 RestElement: 147};48 49const OPERATOR_PRECEDENCE = {50 '||': 2,51 '&&': 3,52 '??': 4,53 '|': 5,54 '^': 6,55 '&': 7,56 '==': 8,57 '!=': 8,58 '===': 8,59 '!==': 8,60 '<': 9,61 '>': 9,62 '<=': 9,63 '>=': 9,64 in: 9,65 instanceof: 9,66 '<<': 10,67 '>>': 10,68 '>>>': 10,69 '+': 11,70 '-': 11,71 '*': 12,72 '%': 12,73 '/': 12,74 '**': 1375};76 77/**78 * Writes `keyword` bounded by source map locations for the exact character span,79 * so breakpoints line up on keywords (not only identifiers and braces).80 *81 * @param {import('esrap').Context} context82 * @param {number} line ESTree / acorn 1-based line83 * @param {number} column 0-based ESTree column (UTF-16 indices, same as emitted JS)84 * @param {string} keyword85 */86function write_source_keyword(context, line, column, keyword) {87 context.location(line, column);88 context.write(keyword);89 context.location(line, column + keyword.length);90}91 92/**93 * Sequential fragments from one ESTree `loc.start`, advancing columns for source mappings.94 * Pass each printed fragment exactly (usually including trailing spaces), e.g. `declare `, `class `.95 * Usage: `const kw = create_keyword_write(context, node, predicate);`96 *97 * @param {import('esrap').Context} context98 * @param {TSESTree.Node} node99 * @param {(n: any) => boolean} [map_ok] When false or missing `loc`, writes go through `context.write` only.100 * @returns {(fragment: string) => void}101 */102function create_keyword_write(context, node, map_ok) {103 let cursor =104 node.loc && (!map_ok || map_ok(node))105 ? { line: node.loc.start.line, col: node.loc.start.column }106 : null;107 108 return (fragment) => {109 if (cursor) {110 write_source_keyword(context, cursor.line, cursor.col, fragment);111 cursor.col += fragment.length;112 } else {113 context.write(fragment);114 }115 };116}117 118/**119 * Map one keyword at `node.loc.start`, then append unmapped `suffix` (spaces, punctuation, etc.).120 *121 * @param {import('esrap').Context} context122 * @param {TSESTree.Node} node123 * @param {string} keyword124 * @param {string} [suffix='']125 */126function write_keyword(context, node, keyword, suffix = '') {127 if (node.loc) {128 write_source_keyword(context, node.loc.start.line, node.loc.start.column, keyword);129 context.write(suffix);130 } else {131 context.write(keyword + suffix);132 }133}134 135/**136 * `async function` offset heuristics assume the `function` token is on the same line as `async`137 * and anchored with the function `id`/`body` ESTree locations.138 *139 * @param {TSESTree.FunctionDeclaration | TSESTree.FunctionExpression} node140 */141function function_async_function_offset_ok(node) {142 const line = /** @type {{ loc?: { start: { line: number } } }} */ (node).loc?.start.line;143 if (line === undefined) return false;144 145 return node.id?.loc?.start.line === line || node.body?.loc?.start.line === line;146}147 148/** @param {{ loc?: { start: { line: number }, end: { line: number } } }} node */149function single_line_node(node) {150 return !!(node.loc && node.loc.start.line === node.loc.end.line);151}152 153/**154 * @param {TSESTree.ClassDeclaration | TSESTree.ClassExpression} node155 * @returns {boolean}156 */157function class_modifier_keywords_map_ok(node) {158 return (159 !!node.loc &&160 !node.decorators?.length &&161 (node.id162 ? node.id.loc?.start.line === node.loc.start.line163 : node.body.loc.start.line === node.loc.start.line)164 );165}166 167/**168 * @param {TSESTree.MethodDefinition | TSESTree.TSAbstractMethodDefinition} node169 * @returns {boolean}170 */171function method_modifiers_keywords_map_ok(node) {172 return !!(173 node.loc &&174 !node.decorators?.length &&175 node.loc.start.line === node.value.loc?.start.line176 );177}178 179/**180 * @param {TSESTree.PropertyDefinition | TSESTree.TSAbstractPropertyDefinition | TSESTree.AccessorProperty | TSESTree.TSAbstractAccessorProperty} node181 * @returns {boolean}182 */183function field_modifiers_keywords_map_ok(node) {184 if (!node.loc || node.decorators?.length) return false;185 if (!node.value?.loc) return true;186 return node.loc.start.line === node.value.loc.start.line;187}188 189/**190 * @param {BaseComment} comment191 * @param {Context} context192 */193function write_comment(comment, context) {194 if (comment.type === 'Line') {195 context.write(`//${comment.value}`);196 } else {197 context.write('/*');198 const lines = comment.value.split('\n');199 200 for (let i = 0; i < lines.length; i += 1) {201 if (i > 0) context.newline();202 context.write(lines[i]);203 }204 205 context.write('*/');206 if (lines.length > 1) context.newline();207 }208}209 210/**211 * @param {TSOptions} [options]212 * @returns {Visitors<TSESTree.Node>}213 */214export default (options = {}) => {215 const quote_char = options.quotes === 'double' ? '"' : "'";216 217 const comments = options.comments ?? [];218 219 let comment_index = 0;220 221 /**222 * Write additional comments for a node223 * @param {Context} context224 * @param {BaseComment[] | undefined} comments225 * @param {('leading' | 'trailing')} position226 */227 function write_additional_comments(context, comments, position) {228 if (!comments) {229 return;230 }231 232 for (let i = 0; i < comments.length; i += 1) {233 const comment = comments[i];234 235 if (position === 'trailing' && i === 0) {236 context.write(' ');237 }238 239 write_comment(comment, context);240 241 if (position === 'leading') {242 if (comment.type === 'Line') {243 context.newline();244 } else if (comment.type === 'Block' && !comment.value.includes('\n')) {245 context.write(' ');246 }247 }248 }249 }250 251 /**252 * Set `comment_index` to be the first comment after `start`.253 * Most of the time this is already correct, but if nodes254 * have been moved around we may need to search for it255 * @param {TSESTree.Node} node256 */257 function reset_comment_index(node) {258 if (!node.loc) {259 comment_index = comments.length;260 return;261 }262 263 let previous = comments[comment_index - 1];264 let comment = comments[comment_index];265 266 if (267 comment &&268 comment.loc &&269 !before(comment.loc.start, node.loc.start) &&270 (!previous || (previous.loc && before(previous.loc.start, node.loc.start)))271 ) {272 return;273 }274 275 // TODO use a binary search here, account for synthetic nodes (without `loc`)276 comment_index = comments.findIndex(277 (comment) => comment.loc && node.loc && !before(comment.loc.start, node.loc.start)278 );279 if (comment_index === -1) comment_index = comments.length;280 }281 282 /**283 * @param {Context} context284 * @param {{ line: number, column: number } | null} prev285 * @param {{ line: number, column: number } | null} next286 */287 function flush_trailing_comments(context, prev, next) {288 while (comment_index < comments.length) {289 const comment = comments[comment_index];290 291 if (292 comment &&293 prev &&294 comment.loc.start.line === prev.line &&295 (next === null || before(comment.loc.end, next))296 ) {297 context.write(' ');298 write_comment(comment, context);299 300 comment_index += 1;301 302 if (comment.type === 'Line') {303 context.newline();304 } else {305 continue;306 }307 }308 309 break;310 }311 }312 313 /**314 * @param {Context} context315 * @param {{ line: number, column: number } | null} from316 * @param {{ line: number, column: number }} to317 * @param {boolean} pad318 */319 function flush_comments_until(context, from, to, pad) {320 let first = true;321 322 while (comment_index < comments.length) {323 const comment = comments[comment_index];324 325 if (comment && comment.loc && to && before(comment.loc.start, to)) {326 if (first && from !== null && comment.loc.start.line > from.line) {327 context.margin();328 context.newline();329 }330 331 first = false;332 333 write_comment(comment, context);334 335 if (comment.loc.end.line < to.line) {336 context.newline();337 } else if (pad) {338 context.write(' ');339 }340 341 comment_index += 1;342 } else {343 break;344 }345 }346 }347 348 /**349 * @param {TSESTree.Node} node350 * @returns {boolean}351 */352 function has_object_or_array_value(node) {353 if (!node || node.type !== 'Property') return false;354 const value = node.value?.type === 'AssignmentPattern' ? node.value.left : node.value;355 return value?.type === 'ObjectExpression' || value?.type === 'ArrayExpression';356 }357 358 /**359 * @param {Context} context360 * @param {TSESTree.Node[]} nodes361 * @param {{ line: number, column: number }} until362 * @param {boolean} pad363 */364 function sequence(context, nodes, until, pad, separator = ',', trailing_newline = true) {365 let multiline = false;366 let length = -1;367 368 /** @type {boolean[]} */369 const multiline_nodes = [];370 371 const children = nodes.map((child, i) => {372 const child_context = context.new();373 if (child) child_context.visit(child);374 375 multiline_nodes[i] = child_context.multiline;376 377 if (i < nodes.length - 1 || !child) {378 child_context.write(separator);379 }380 381 const next = i === nodes.length - 1 ? until : nodes[i + 1]?.loc?.start || null;382 flush_trailing_comments(child_context, child?.loc?.end || null, next);383 384 length += child_context.measure() + 1;385 multiline ||= child_context.multiline;386 387 return child_context;388 });389 390 multiline ||= length > 60;391 392 if (multiline) {393 context.indent();394 context.newline();395 } else if (pad && length > 0) {396 context.write(' ');397 }398 399 /** @type {Context | null} */400 let prev = null;401 402 for (let i = 0; i < nodes.length; i += 1) {403 const child = children[i];404 405 if (prev !== null) {406 if (multiline_nodes[i - 1] && multiline_nodes[i]) {407 if (!has_object_or_array_value(nodes[i - 1]) || !has_object_or_array_value(nodes[i])) {408 context.margin();409 }410 }411 412 if (nodes[i]) {413 if (multiline) {414 context.newline();415 } else {416 context.write(' ');417 }418 }419 }420 421 context.append(child);422 423 prev = child;424 }425 426 flush_comments_until(context, nodes[nodes.length - 1]?.loc?.end ?? null, until, false);427 428 if (multiline) {429 context.dedent();430 if (trailing_newline) context.newline();431 } else if (pad && length > 0) {432 context.write(' ');433 }434 }435 436 /**437 * Push a sequence of nodes onto separate lines, separating them with438 * an extra newline where appropriate439 * @param {Context} context440 * @param {TSESTree.Node & { body: TSESTree.Node[] }} node441 */442 function body(context, node) {443 reset_comment_index(node);444 445 /** @type {string | null} */446 let prev_type = null;447 let prev_multiline = false;448 449 for (let i = 0; i < node.body.length; i += 1) {450 const child = node.body[i];451 if (child.type === 'EmptyStatement') continue;452 453 const child_context = context.new();454 child_context.visit(child);455 456 if (prev_type !== null) {457 if (child_context.multiline || prev_multiline || child.type !== prev_type) {458 context.margin();459 }460 461 context.newline();462 }463 464 context.append(child_context);465 466 flush_trailing_comments(467 context,468 child.loc?.end || null,469 node.body[i + 1]?.loc?.end ?? node.loc?.end ?? null470 );471 472 prev_type = child.type;473 prev_multiline = child_context.multiline;474 }475 476 if (node.loc) {477 context.newline();478 flush_comments_until(479 context,480 node.body[node.body.length - 1]?.loc?.end ?? null,481 node.loc.end,482 false483 );484 }485 }486 487 const shared = {488 /**489 * @param {TSESTree.ArrayExpression | TSESTree.ArrayPattern} node490 * @param {Context} context491 */492 'ArrayExpression|ArrayPattern': (node, context) => {493 context.write('[');494 sequence(495 context,496 /** @type {TSESTree.Node[]} */ (node.elements),497 node.loc?.end ?? null,498 false499 );500 context.write(']');501 },502 503 /**504 * @param {TSESTree.BinaryExpression | TSESTree.LogicalExpression} node505 * @param {Context} context506 */507 'BinaryExpression|LogicalExpression': (node, context) => {508 // TODO509 // const is_in = node.operator === 'in';510 // if (is_in) {511 // // Avoids confusion in `for` loops initializers512 // chunks.write('(');513 // }514 if (needs_parens(node.left, node, false)) {515 context.write('(');516 context.visit(node.left);517 context.write(')');518 } else {519 context.visit(node.left);520 }521 522 context.write(` ${node.operator} `);523 524 if (needs_parens(node.right, node, true)) {525 context.write('(');526 context.visit(node.right);527 context.write(')');528 } else {529 context.visit(node.right);530 }531 },532 533 /**534 * @param {TSESTree.BlockStatement | TSESTree.ClassBody} node535 * @param {Context} context536 */537 'BlockStatement|ClassBody': (node, context) => {538 if (node.loc) {539 const { line, column } = node.loc.start;540 context.location(line, column);541 context.write('{');542 context.location(line, column + 1);543 } else {544 context.write('{');545 }546 547 const child_context = context.new();548 body(child_context, node);549 550 if (!child_context.empty()) {551 context.indent();552 context.newline();553 context.append(child_context);554 context.dedent();555 context.newline();556 }557 558 if (node.loc) {559 const { line, column } = node.loc.end;560 561 context.location(line, column - 1);562 context.write('}');563 context.location(line, column);564 } else {565 context.write('}');566 }567 },568 569 /**570 * @param {TSESTree.CallExpression | TSESTree.NewExpression} node571 * @param {Context} context572 */573 'CallExpression|NewExpression': (node, context) => {574 if (node.type === 'NewExpression') {575 write_keyword(context, node, 'new', ' ');576 }577 578 const needs_parens =579 EXPRESSIONS_PRECEDENCE[node.callee.type] < EXPRESSIONS_PRECEDENCE.CallExpression ||580 (node.type === 'NewExpression' && has_call_expression(node.callee));581 582 if (needs_parens) {583 context.write('(');584 context.visit(node.callee);585 context.write(')');586 } else {587 context.visit(node.callee);588 }589 590 if (/** @type {TSESTree.CallExpression} */ (node).optional) {591 context.write('?.');592 }593 594 if (node.typeArguments) context.visit(node.typeArguments);595 596 const open = context.new();597 const join = context.new();598 599 context.write('(');600 context.append(open);601 602 // if the final argument is multiline, it doesn't need to force all the603 // other arguments to also be multiline604 const child_context = context.new();605 const final_context = context.new();606 607 context.append(child_context);608 context.append(final_context);609 610 for (let i = 0; i < node.arguments.length; i += 1) {611 const is_last = i === node.arguments.length - 1;612 const context = is_last ? final_context : child_context;613 const arg = node.arguments[i];614 615 // special case — if final argument has a comment above it,616 // we make the whole sequence multiline617 if (618 is_last &&619 arg.loc &&620 comments[comment_index] &&621 comments[comment_index].loc &&622 comments[comment_index].loc.start.line < arg.loc.start.line623 ) {624 child_context.multiline = true;625 }626 627 context.visit(arg);628 629 if (!is_last) context.write(',');630 631 const next = is_last632 ? (node.loc?.end ?? null)633 : (node.arguments[i + 1]?.loc?.start ?? null);634 635 flush_trailing_comments(context, arg.loc?.end ?? null, next);636 637 if (!is_last) context.append(join);638 }639 640 context.multiline ||= child_context.multiline || final_context.multiline;641 642 if (child_context.multiline) {643 open.indent();644 open.newline();645 join.newline();646 context.dedent();647 context.newline();648 } else {649 join.write(' ');650 }651 652 context.write(')');653 },654 655 /**656 * @param {TSESTree.ClassDeclaration | TSESTree.ClassExpression} node657 * @param {Context} context658 */659 'ClassDeclaration|ClassExpression': (node, context) => {660 if (node.decorators) {661 for (const decorator of node.decorators) {662 context.visit(decorator);663 }664 }665 666 const kw = create_keyword_write(context, node, class_modifier_keywords_map_ok);667 668 if (node.declare) kw('declare ');669 if (node.abstract) kw('abstract ');670 kw('class ');671 672 if (node.id) {673 context.visit(node.id);674 context.write(' ');675 }676 677 if (node.superClass) {678 context.write('extends ');679 context.visit(node.superClass);680 681 // @ts-expect-error `acorn-typescript` and `@typescript-eslint/types` have slightly different type definitions682 var type_arguments = node.superTypeParameters ?? node.superTypeArguments;683 if (type_arguments) {684 context.visit(type_arguments);685 }686 687 context.write(' ');688 }689 690 if (node.implements && node.implements.length > 0) {691 context.write('implements');692 sequence(context, node.implements, node.body.loc?.start ?? null, true);693 }694 695 context.visit(node.body);696 },697 698 /**699 * @param {TSESTree.ForInStatement | TSESTree.ForOfStatement} node700 * @param {Context} context701 */702 'ForInStatement|ForOfStatement': (node, context) => {703 const kw = create_keyword_write(context, node);704 705 kw('for ');706 if (node.type === 'ForOfStatement' && node.await) {707 if (single_line_node(node)) kw('await ');708 else context.write('await ');709 }710 711 context.write('(');712 713 if (node.left.type === 'VariableDeclaration') {714 handle_var_declaration(node.left, context);715 } else {716 context.visit(node.left);717 }718 719 context.write(node.type === 'ForInStatement' ? ' in ' : ' of ');720 context.visit(node.right);721 context.write(') ');722 context.visit(node.body);723 },724 725 /**726 * @param {TSESTree.FunctionDeclaration | TSESTree.FunctionExpression} node727 * @param {Context} context728 */729 'FunctionDeclaration|FunctionExpression': (node, context) => {730 if (!node.loc?.start) {731 if (node.async) context.write('async ');732 context.write(node.generator ? 'function* ' : 'function ');733 } else {734 const { line, column } = node.loc.start;735 736 if (node.async) {737 if (function_async_function_offset_ok(node)) {738 write_source_keyword(context, line, column, 'async ');739 const col2 = column + 'async '.length;740 write_source_keyword(context, line, col2, 'function');741 context.write(node.generator ? '* ' : ' ');742 } else {743 context.write('async ');744 context.write(node.generator ? 'function* ' : 'function ');745 }746 } else if (node.generator) {747 write_source_keyword(context, line, column, 'function');748 context.write('* ');749 } else {750 write_source_keyword(context, line, column, 'function');751 context.write(' ');752 }753 }754 755 if (node.id) context.visit(node.id);756 757 if (node.typeParameters) {758 context.visit(node.typeParameters);759 }760 761 context.write('(');762 sequence(context, node.params, (node.returnType ?? node.body).loc?.start ?? null, false);763 context.write(')');764 765 if (node.returnType) context.visit(node.returnType);766 767 context.write(' ');768 769 context.visit(node.body);770 },771 772 /**773 * @param {TSESTree.MethodDefinition | TSESTree.TSAbstractMethodDefinition} node774 * @param {Context} context775 */776 'MethodDefinition|TSAbstractMethodDefinition': (node, context) => {777 if (node.decorators) {778 for (const decorator of node.decorators) {779 context.visit(decorator);780 }781 }782 783 const kw = create_keyword_write(context, node, method_modifiers_keywords_map_ok);784 785 // @ts-expect-error `acorn-typescript` and `@typescript-eslint/types` have slightly different type definitions786 if (node.abstract || node.type === 'TSAbstractMethodDefinition') {787 kw('abstract ');788 }789 790 if (node.accessibility) {791 kw(node.accessibility + ' ');792 }793 794 if (node.override) {795 kw('override ');796 }797 798 if (node.static) {799 kw('static ');800 }801 802 if (node.kind === 'get' || node.kind === 'set') {803 kw(node.kind + ' ');804 }805 806 if (node.value.async) {807 kw('async ');808 }809 810 if (node.value.generator) context.write('*');811 812 if (node.computed) context.write('[');813 context.visit(node.key);814 if (node.computed) context.write(']');815 816 context.write('(');817 sequence(818 context,819 node.value.params,820 (node.value.returnType ?? node.value.body)?.loc?.start ?? node.loc?.end ?? null,821 false822 );823 context.write(')');824 825 if (node.value.returnType) context.visit(node.value.returnType);826 827 context.write(' ');828 829 if (node.value.body) context.visit(node.value.body);830 },831 832 /**833 * @param {TSESTree.PropertyDefinition | TSESTree.TSAbstractPropertyDefinition | TSESTree.AccessorProperty | TSESTree.TSAbstractAccessorProperty} node834 * @param {Context} context835 */836 'PropertyDefinition|TSAbstractPropertyDefinition|AccessorProperty|TSAbstractAccessorProperty': (837 node,838 context839 ) => {840 if (node.decorators) {841 for (const decorator of node.decorators) {842 context.visit(decorator);843 }844 }845 846 const kw = create_keyword_write(context, node, field_modifiers_keywords_map_ok);847 848 if (node.accessibility) {849 kw(node.accessibility + ' ');850 }851 852 if (853 // @ts-expect-error `acorn-typescript` and `@typescript-eslint/types` have slightly different type definitions854 node.abstract ||855 node.type === 'TSAbstractPropertyDefinition' ||856 node.type === 'TSAbstractAccessorProperty'857 ) {858 kw('abstract ');859 }860 861 if (node.static) {862 kw('static ');863 }864 865 if (866 // @ts-expect-error `acorn-typescript` and `@typescript-eslint/types` have slightly different type definitions867 node.accessor ||868 node.type === 'AccessorProperty' ||869 node.type === 'TSAbstractAccessorProperty'870 ) {871 kw('accessor ');872 }873 874 if (node.computed) {875 context.write('[');876 context.visit(node.key);877 context.write(']');878 } else {879 context.visit(node.key);880 }881 882 if (node.typeAnnotation) {883 if (node.type === 'AccessorProperty' || node.type === 'TSAbstractAccessorProperty') {884 context.visit(node.typeAnnotation);885 } else {886 context.write(': ');887 context.visit(node.typeAnnotation.typeAnnotation);888 }889 }890 891 if (node.value) {892 context.write(' = ');893 context.visit(node.value);894 }895 896 context.write(';');897 898 flush_trailing_comments(899 context,900 (node.value ?? node.typeAnnotation ?? node.key).loc?.end ?? null,901 null902 );903 },904 905 /**906 * @param {TSESTree.RestElement | TSESTree.SpreadElement} node907 * @param {Context} context908 */909 'RestElement|SpreadElement': (node, context) => {910 context.write('...');911 context.visit(node.argument);912 913 // @ts-expect-error `acorn-typescript` and `@typescript-eslint/types` have slightly different type definitions914 if (node.typeAnnotation) context.visit(node.typeAnnotation);915 },916 917 /**918 * @param {TSESTree.TSConstructSignatureDeclaration | TSESTree.TSCallSignatureDeclaration} node919 * @param {Context} context920 */921 'TSConstructSignatureDeclaration|TSCallSignatureDeclaration': (node, context) => {922 if (node.type === 'TSConstructSignatureDeclaration') context.write('new');923 924 if (node.typeParameters) {925 context.visit(node.typeParameters);926 }927 928 context.write('(');929 930 sequence(931 context,932 // @ts-expect-error `acorn-typescript` and `@typescript-eslint/types` have slightly different type definitions933 node.parameters ?? node.params,934 // @ts-expect-error `acorn-typescript` and `@typescript-eslint/types` have slightly different type definitions935 (node.typeAnnotation ?? node.returnType)?.loc?.start ?? null,936 false937 );938 context.write(')');939 940 // @ts-expect-error `acorn-typescript` and `@typescript-eslint/types` have slightly different type definitions941 if (node.typeAnnotation || node.returnType) {942 // @ts-expect-error `acorn-typescript` and `@typescript-eslint/types` have slightly different type definitions943 context.visit(node.typeAnnotation ?? node.returnType);944 }945 },946 947 /**948 * @param {TSESTree.TSFunctionType | TSESTree.TSConstructorType} node949 * @param {Context} context950 */951 'TSFunctionType|TSConstructorType': (node, context) => {952 if (node.type === 'TSConstructorType') context.write('new ');953 if (node.typeParameters) context.visit(node.typeParameters);954 955 context.write('(');956 957 sequence(958 context,959 // @ts-expect-error `acorn-typescript` and `@typescript-eslint/types` have slightly different type definitions960 node.parameters ?? node.params,961 // @ts-expect-error `acorn-typescript` and `@typescript-eslint/types` have slightly different type definitions962 node.typeAnnotation?.typeAnnotation?.loc?.start ??963 node.returnType?.typeAnnotation?.loc?.start ??964 null,965 false966 );967 968 context.write(') => ');969 970 // @ts-expect-error `acorn-typescript` and `@typescript-eslint/types` have slightly different type definitions971 context.visit(node.typeAnnotation?.typeAnnotation ?? node.returnType?.typeAnnotation);972 }973 };974 975 return {976 _(node, context, visit) {977 write_additional_comments(context, options.getLeadingComments?.(node), 'leading');978 979 if (node.loc) {980 flush_comments_until(context, null, node.loc.start, true);981 }982 983 visit(node);984 985 write_additional_comments(context, options.getTrailingComments?.(node), 'trailing');986 },987 988 AccessorProperty:989 shared[990 'PropertyDefinition|TSAbstractPropertyDefinition|AccessorProperty|TSAbstractAccessorProperty'991 ],992 993 ArrayExpression: shared['ArrayExpression|ArrayPattern'],994 995 ArrayPattern: shared['ArrayExpression|ArrayPattern'],996 997 ArrowFunctionExpression: (node, context) => {998 if (node.async) {999 write_keyword(context, node, 'async', ' ');1000 }1001 1002 if (node.typeParameters) {1003 context.visit(node.typeParameters);1004 }1005 1006 context.write('(');1007 sequence(context, node.params, (node.returnType ?? node.body).loc?.start ?? null, false);1008 context.write(')');1009 1010 if (node.returnType) context.visit(node.returnType);1011 1012 context.write(' => ');1013 1014 if (arrow_concise_body_needs_wrap(node.body)) {1015 context.write('(');1016 context.visit(node.body);1017 context.write(')');1018 } else {1019 context.visit(node.body);1020 }1021 },1022 1023 AssignmentExpression(node, context) {1024 context.visit(node.left);1025 context.write(` ${node.operator} `);1026 context.visit(node.right);1027 },1028 1029 AssignmentPattern(node, context) {1030 context.visit(node.left);1031 context.write(' = ');1032 context.visit(node.right);1033 },1034 1035 AwaitExpression(node, context) {1036 if (node.argument) {1037 const precedence = EXPRESSIONS_PRECEDENCE[node.argument.type];1038 1039 if (precedence && precedence < EXPRESSIONS_PRECEDENCE.AwaitExpression) {1040 write_keyword(context, node, 'await', ' (');1041 context.visit(node.argument);1042 context.write(')');1043 } else {1044 write_keyword(context, node, 'await', ' ');1045 context.visit(node.argument);1046 }1047 } else {1048 write_keyword(context, node, 'await', '');1049 }1050 },1051 1052 BinaryExpression: shared['BinaryExpression|LogicalExpression'],1053 1054 BlockStatement: shared['BlockStatement|ClassBody'],1055 1056 BreakStatement(node, context) {1057 if (node.label) {1058 write_keyword(context, node, 'break', ' ');1059 context.visit(node.label);1060 context.write(';');1061 } else {1062 write_keyword(context, node, 'break', ';');1063 }1064 },1065 1066 CallExpression: shared['CallExpression|NewExpression'],1067 1068 ChainExpression(node, context) {1069 context.visit(node.expression);1070 },1071 1072 ClassBody: shared['BlockStatement|ClassBody'],1073 1074 ClassDeclaration: shared['ClassDeclaration|ClassExpression'],1075 1076 ClassExpression: shared['ClassDeclaration|ClassExpression'],1077 1078 ConditionalExpression(node, context) {1079 if (EXPRESSIONS_PRECEDENCE[node.test.type] > EXPRESSIONS_PRECEDENCE.ConditionalExpression) {1080 context.visit(node.test);1081 } else {1082 context.write('(');1083 context.visit(node.test);1084 context.write(')');1085 }1086 1087 const consequent = context.new();1088 const alternate = context.new();1089 1090 // TODO flush comments here, rather than in visitors1091 1092 consequent.visit(node.consequent);1093 alternate.visit(node.alternate);1094 1095 if (1096 consequent.multiline ||1097 alternate.multiline ||1098 consequent.measure() + alternate.measure() > 501099 ) {1100 context.indent();1101 context.newline();1102 context.write('? ');1103 context.append(consequent);1104 context.newline();1105 context.write(': ');1106 context.append(alternate);1107 context.dedent();1108 } else {1109 context.write(' ? ');1110 context.append(consequent);1111 context.write(' : ');1112 context.append(alternate);1113 }1114 },1115 1116 ContinueStatement(node, context) {1117 if (node.label) {1118 write_keyword(context, node, 'continue', ' ');1119 context.visit(node.label);1120 context.write(';');1121 } else {1122 write_keyword(context, node, 'continue', ';');1123 }1124 },1125 1126 DebuggerStatement(node, context) {1127 context.write('debugger', node);1128 context.write(';');1129 },1130 1131 Decorator(node, context) {1132 context.write('@');1133 context.visit(node.expression);1134 context.newline();1135 },1136 1137 DoWhileStatement(node, context) {1138 write_keyword(context, node, 'do', ' ');1139 context.visit(node.body);1140 1141 const test_loc = node.test.loc?.start;1142 const body_end = node.body.loc?.end;1143 if (test_loc && body_end && body_end.line === test_loc.line && test_loc.column >= 6) {1144 context.write(' ');1145 write_source_keyword(context, body_end.line, body_end.column + 1, 'while');1146 context.write(' (');1147 } else {1148 context.write(' while (');1149 }1150 1151 context.visit(node.test);1152 context.write(');');1153 },1154 1155 EmptyStatement(node, context) {1156 context.write(';');1157 },1158 1159 ExportAllDeclaration(node, context) {1160 context.write(node.exportKind === 'type' ? 'export type * ' : 'export * ');1161 1162 if (node.exported) {1163 context.write('as ');1164 context.visit(node.exported);1165 }1166 1167 context.write(' from ');1168 context.visit(node.source);1169 context.write(';');1170 },1171 1172 ExportDefaultDeclaration(node, context) {1173 const kw = create_keyword_write(context, node, single_line_node);1174 kw('export ');1175 kw('default ');1176 1177 context.visit(node.declaration);1178 1179 if (node.declaration.type !== 'FunctionDeclaration') {1180 context.write(';');1181 }1182 },1183 1184 ExportNamedDeclaration(node, context) {1185 if (node.declaration) {1186 // Check if declaration has decorators (ClassDeclaration, ClassExpression can have them)1187 const decl = /** @type {any} */ (node.declaration);1188 if (decl.decorators && decl.decorators.length > 0) {1189 for (const decorator of decl.decorators) {1190 context.visit(decorator);1191 }1192 write_keyword(context, node, 'export', ' ');1193 // Temporarily remove decorators so ClassDeclaration doesn't print them again1194 const savedDecorators = decl.decorators;1195 decl.decorators = [];1196 context.visit(node.declaration);1197 decl.decorators = savedDecorators;1198 } else {1199 write_keyword(context, node, 'export', ' ');1200 context.visit(node.declaration);