diff --git a/.formatignore b/.formatignore new file mode 100644 index 000000000..3cca0e0f4 --- /dev/null +++ b/.formatignore @@ -0,0 +1,11 @@ +# The fixture trees are DATA, not source. Their `unformatted_*` / `variant_*` / +# `output_prettier.*` / `input_invalid_*` files are deliberately NOT format fixed +# points — each one's whole claim is the state it is committed in — so a stray +# `tsv format .` at the repo root would destroy them. They are regenerated with +# `deno task fixtures:update` / `fixture_init`, never with `tsv format`. +# +# A directory arg can't step past this (`tsv format tests/fixtures` finds nothing); +# only an explicitly named FILE bypasses the ignore files — see docs/cli.md +# §Multi-File Formatting. +tests/fixtures/ +tests/fixtures_compile/ diff --git a/crates/tsv_debug/src/cli/commands/blank_audit_known.txt b/crates/tsv_debug/src/cli/commands/blank_audit_known.txt index aa393cffb..fb8c20eb2 100644 --- a/crates/tsv_debug/src/cli/commands/blank_audit_known.txt +++ b/crates/tsv_debug/src/cli/commands/blank_audit_known.txt @@ -15,7 +15,7 @@ # it is reported but never gated. It is excluded from this file by construction. # # Format: KINDSHAPE -# shapes: 178 +# shapes: 181 NON-IDEMPOTENT ').⟨⟩IDENT NON-IDEMPOTENT ')⟨⟩. NON-IDEMPOTENT (({⟨⟩IDENT @@ -98,6 +98,7 @@ NON-IDEMPOTENT IDENT⟨⟩/* NON-IDEMPOTENT IDENT⟨⟩> NON-IDEMPOTENT IDENT⟨⟩]; NON-IDEMPOTENT IDENT⟨⟩␣ +NON-IDEMPOTENT NUM⟨⟩), NON-IDEMPOTENT [,,⟨⟩/* NON-IDEMPOTENT [{⟨⟩␣ NON-IDEMPOTENT [⟨⟩IDENT @@ -166,7 +167,6 @@ DROPPED /⟨⟩/* DROPPED /⟨⟩␣ DROPPED ?.⟨⟩[ DROPPED IDENT⟨⟩) -DROPPED IDENT⟨⟩), DROPPED IDENT⟨⟩, DROPPED IDENT⟨⟩,[' DROPPED IDENT⟨⟩/* @@ -178,6 +178,8 @@ DROPPED yield⟨⟩␣ DROPPED {},⟨⟩␣ DROPPED {}⟨⟩, DROPPED })⟨⟩␣ +DROPPED },⟨⟩␣ +DROPPED }⟨⟩, DROPPED ␣⟨⟩( DROPPED ␣⟨⟩() DROPPED ␣⟨⟩({} @@ -186,6 +188,7 @@ DROPPED ␣⟨⟩/** DROPPED ␣⟨⟩// DROPPED ␣⟨⟩IDENT DROPPED ␣⟨⟩[' +DROPPED ␣⟨⟩{ DROPPED ␣⟨⟩{} DROPPED ␣⟨⟩␣ DOUBLE-PRINTED */⟨⟩,/* diff --git a/crates/tsv_debug/src/cli/commands/gap_audit_known.txt b/crates/tsv_debug/src/cli/commands/gap_audit_known.txt index 0f7ea8df4..8eb4251e8 100644 --- a/crates/tsv_debug/src/cli/commands/gap_audit_known.txt +++ b/crates/tsv_debug/src/cli/commands/gap_audit_known.txt @@ -12,7 +12,7 @@ # the gate rather than being pinned. # # Format: KINDSHAPEPAYLOADS -# shapes: 577 +# shapes: 570 DROPPED !)⟨⟩!. annotation,block,jsdoc_cast DROPPED #⟨⟩IDENT annotation,block,jsdoc_cast,line,multiline DROPPED #⟨⟩\ annotation,block,jsdoc_cast,line,multiline @@ -21,7 +21,6 @@ DROPPED &&⟨⟩␣ annotation,block,jsdoc_cast,multiline DROPPED &⟨⟩␣ annotation,block,jsdoc_cast,line,multiline DROPPED ')⟨⟩); annotation,block,jsdoc_cast,line,multiline DROPPED ',,⟨⟩,' annotation,block,jsdoc_cast -DROPPED ',⟨⟩()= line DROPPED ',⟨⟩,' annotation,block,jsdoc_cast DROPPED ',⟨⟩,,' annotation,block,jsdoc_cast DROPPED ',⟨⟩,]; annotation,block,jsdoc_cast @@ -34,7 +33,6 @@ DROPPED '},⟨⟩␣ annotation,block,jsdoc_cast,multiline DROPPED '⟨⟩)); annotation,block,jsdoc_cast,line,multiline DROPPED '⟨⟩); annotation,block,jsdoc_cast,line,multiline DROPPED '⟨⟩, annotation,block,jsdoc_cast,line,multiline -DROPPED '⟨⟩,() annotation,block,jsdoc_cast,line,multiline DROPPED '⟨⟩,/* line DROPPED '⟨⟩/* line,multiline DROPPED '⟨⟩// line,multiline @@ -76,12 +74,10 @@ DROPPED (⟨⟩()= line DROPPED (⟨⟩(.. line DROPPED (⟨⟩([ annotation,block,jsdoc_cast,line,multiline DROPPED (⟨⟩({ line -DROPPED (⟨⟩/* annotation,block,jsdoc_cast,line,multiline DROPPED (⟨⟩< line DROPPED (⟨⟩IDENT annotation,block,jsdoc_cast,line,multiline DROPPED (⟨⟩NUM line DROPPED (⟨⟩[ annotation,block,jsdoc_cast,line,multiline -DROPPED (⟨⟩[[' line DROPPED (⟨⟩async line DROPPED (⟨⟩await line DROPPED (⟨⟩function line @@ -135,7 +131,6 @@ DROPPED */,⟨⟩␣ annotation,block,jsdoc_cast DROPPED */⟨⟩, annotation,block,jsdoc_cast,line,multiline DROPPED */⟨⟩,/* line DROPPED */⟨⟩/* line,multiline -DROPPED */⟨⟩␣ line DROPPED ++(⟨⟩IDENT line DROPPED ++(⟨⟩␣ line DROPPED ++⟨⟩( annotation,block,line,multiline @@ -228,15 +223,13 @@ DROPPED IDENT⟨⟩!!; annotation,block,jsdoc_cast DROPPED IDENT⟨⟩!() annotation,block,jsdoc_cast DROPPED IDENT⟨⟩!. annotation,block,jsdoc_cast DROPPED IDENT⟨⟩( annotation,block,jsdoc_cast,line,multiline -DROPPED IDENT⟨⟩(' annotation,block,jsdoc_cast,line,multiline -DROPPED IDENT⟨⟩(( annotation,block,jsdoc_cast,line,multiline +DROPPED IDENT⟨⟩(' line +DROPPED IDENT⟨⟩(( line DROPPED IDENT⟨⟩(() line DROPPED IDENT⟨⟩(({ line -DROPPED IDENT⟨⟩(/* annotation,block,jsdoc_cast,line,multiline -DROPPED IDENT⟨⟩([ annotation,block,jsdoc_cast,line,multiline -DROPPED IDENT⟨⟩([[ annotation,block,jsdoc_cast,line,multiline +DROPPED IDENT⟨⟩([ annotation,block,jsdoc_cast,multiline DROPPED IDENT⟨⟩(` annotation,block,jsdoc_cast,line,multiline -DROPPED IDENT⟨⟩({ annotation,block,jsdoc_cast,line,multiline +DROPPED IDENT⟨⟩({ annotation,block,jsdoc_cast,multiline DROPPED IDENT⟨⟩) annotation,block,jsdoc_cast,line,multiline DROPPED IDENT⟨⟩)!( annotation,block,jsdoc_cast,line,multiline DROPPED IDENT⟨⟩)!` annotation,block,jsdoc_cast,line,multiline @@ -397,9 +390,9 @@ DROPPED {#⟨⟩IDENT annotation,block,jsdoc_cast,line,multiline DROPPED {(<⟨⟩IDENT annotation,block,jsdoc_cast,multiline DROPPED {++⟨⟩IDENT line DROPPED {})⟨⟩); annotation,block,jsdoc_cast,multiline -DROPPED {},⟨⟩␣ annotation,block,jsdoc_cast,line,multiline +DROPPED {},⟨⟩␣ annotation,block,jsdoc_cast,multiline DROPPED {}⟨⟩); annotation,block,jsdoc_cast,line,multiline -DROPPED {}⟨⟩, annotation,block,jsdoc_cast,line,multiline +DROPPED {}⟨⟩, annotation,block,jsdoc_cast,multiline DROPPED {}⟨⟩: annotation,block,jsdoc_cast,multiline DROPPED {}⟨⟩␣ multiline DROPPED {⟨⟩IDENT annotation,block,jsdoc_cast,multiline diff --git a/crates/tsv_debug/src/cli/commands/ignore_audit_known.txt b/crates/tsv_debug/src/cli/commands/ignore_audit_known.txt index 5c0a04c8d..7cf6efafb 100644 --- a/crates/tsv_debug/src/cli/commands/ignore_audit_known.txt +++ b/crates/tsv_debug/src/cli/commands/ignore_audit_known.txt @@ -23,16 +23,13 @@ # ARE pinned (this is a ratchet over a live bug family, born red). # # Format: KINDPOSITION -# shapes: 68 -UNHONORED ArrayExpression.elements -UNHONORED ArrayPattern.elements +# shapes: 62 UNHONORED ArrowFunctionExpression.body UNHONORED ArrowFunctionExpression.typeParameters UNHONORED AssignmentExpression.right UNHONORED BinaryExpression.left UNHONORED BinaryExpression.right UNHONORED BindDirective.expression -UNHONORED CallExpression.arguments UNHONORED CallExpression.callee UNHONORED ChainExpression.expression UNHONORED ClassDeclaration.body @@ -55,12 +52,10 @@ UNHONORED IfStatement.consequent UNHONORED IfStatement.test UNHONORED ImportDeclaration.attributes UNHONORED ImportDeclaration.specifiers -UNHONORED ImportExpression.arguments UNHONORED LabeledStatement.body UNHONORED LogicalExpression.left UNHONORED LogicalExpression.right UNHONORED MemberExpression.object -UNHONORED NewExpression.arguments UNHONORED NewExpression.callee UNHONORED OnDirective.expression UNHONORED Program.body @@ -75,7 +70,6 @@ UNHONORED TSAsExpression.expression UNHONORED TSImportEqualsDeclaration.moduleReference UNHONORED TSNonNullExpression.expression UNHONORED TSParenthesizedType.typeAnnotation -UNHONORED TSSatisfiesExpression.expression UNHONORED TSTypeAssertion.expression UNHONORED TSTypeLiteral.members UNHONORED TemplateLiteral.expressions diff --git a/crates/tsv_ts/src/printer/calls/arg_wrapping.rs b/crates/tsv_ts/src/printer/calls/arg_wrapping.rs index b883e98ca..f2a6c5fad 100644 --- a/crates/tsv_ts/src/printer/calls/arg_wrapping.rs +++ b/crates/tsv_ts/src/printer/calls/arg_wrapping.rs @@ -450,8 +450,13 @@ pub(crate) fn build_args_split_last( // reaching `printArrowFunctionSignatures`. let arg_docs: DocBuf = arguments .iter() - .map(|arg| { - if is_curried_arrow_chain(arg) { + .enumerate() + .map(|(i, arg)| { + // Rule A first: an own-line directive in this argument's gap freezes it + // verbatim, so no layout context applies to it. + if let Some(frozen) = printer.args_frozen_span(paren_open, arguments, i) { + printer.build_frozen_arg_doc(arg, frozen) + } else if is_curried_arrow_chain(arg) { printer .build_with_arrow_chain_context(ArrowChainContext::CallArgOrBinaryish, || { printer.build_arg_expression_doc(arg) @@ -760,22 +765,24 @@ pub(crate) fn build_arrow_call_body_states( /// between arguments. Used by expansion paths (all-arrows, function composition) /// that would otherwise lose comments with simple `join_doc`. /// -/// When `use_hardline` is true, separators are hardlines (forced expansion). -/// When false, separators are soft lines (break only when the group breaks). -/// Trailing line comments always force a hardline regardless of this setting. +/// `join` picks the separator style and says whether the `(`→first-argument gap is this +/// builder's to emit; `item` picks the per-argument builder. pub(crate) fn build_args_joined_with_comments( printer: &Printer<'_>, arguments: &[internal::Expression<'_>], paren_open: u32, - use_hardline: bool, - build_arg: impl Fn(&Printer<'_>, &internal::Expression<'_>) -> DocId, + join: ArgsJoin, + item: ArgItem, ) -> DocId { let d = printer.d(); let mut parts = DocBuf::new(); + let use_hardline = join.use_hardline(); // Leading comments before first arg (e.g., `fn(/* c */ arg)`) let first_arg_start = arguments[0].span().start; - emit_first_arg_leading_comments(printer, &mut parts, paren_open, first_arg_start); + if !matches!(join, ArgsJoin::HardlineLeadingGapEmitted) { + emit_first_arg_leading_comments(printer, &mut parts, paren_open, first_arg_start); + } let no_comment_sep = if use_hardline { d.comma_hardline() @@ -784,7 +791,7 @@ pub(crate) fn build_args_joined_with_comments( }; for (i, arg) in arguments.iter().enumerate() { - parts.push(build_arg(printer, arg)); + parts.push(item.build(printer, paren_open, arguments, i)); if i < arguments.len() - 1 { let arg_end = arg.span().end; @@ -809,6 +816,80 @@ pub(crate) fn build_args_joined_with_comments( d.concat(&parts) } +/// The forced-expansion argument layout the call and `new` hardline arms share (multiline +/// content, function composition, all-arrows, the expand-first fallback): one argument per +/// line with the gap comments preserved, wrapped in the call's hard-broken parens. +pub(crate) fn build_call_args_expanded( + printer: &Printer<'_>, + callee: DocId, + arguments: &[internal::Expression<'_>], + paren_open: u32, + item: ArgItem, +) -> DocId { + let args = + build_args_joined_with_comments(printer, arguments, paren_open, ArgsJoin::Hardline, item); + wrap_call_with_hard_breaks(printer.d(), callee, args) +} + +/// How [`build_args_joined_with_comments`] separates arguments, and who owns the +/// `(`→first-argument gap. +#[derive(Clone, Copy)] +pub(crate) enum ArgsJoin { + /// Hardline separators — forced expansion, one argument per line. + Hardline, + /// [`Self::Hardline`], but the caller has already emitted the `(`→first-argument gap + /// itself (the `new` paren-line-prefix path does), so this builder must not print it a + /// second time. A variant rather than a narrowed `paren_open`, because `paren_open` + /// also anchors the first argument's FREEZE window: a directive alone on its line + /// inside an already-emitted gap still freezes the first argument, and passing the + /// first argument's own start as `paren_open` would leave that window empty. + HardlineLeadingGapEmitted, + /// Soft-line separators — break only when the enclosing group breaks. A trailing line + /// comment in a gap still forces a hardline. + SoftLine, +} + +impl ArgsJoin { + fn use_hardline(self) -> bool { + !matches!(self, Self::SoftLine) + } +} + +/// Which ordinary builder a joined-argument layout uses for an argument Rule A hasn't +/// frozen. An enum rather than a closure parameter: the family wants exactly these two, +/// and a closure here trips the HRTB lifetime check at every call site. +#[derive(Clone, Copy)] +pub(crate) enum ArgItem { + /// `build_arg_expression_doc` — argument context, so a binary/logical chain (or + /// conditional) keeps its continuation indent and an assignment gets clarity parens. + ArgContext, + /// `build_expression_doc` — the plain builder, for the arms that print their + /// arguments without that context (all-arrows, expand-first's broken-out fallback). + Plain, +} + +impl ArgItem { + /// The doc for argument `i`: the verbatim slice when an own-line format-ignore + /// directive in its gap freezes it (Rule A), else this variant's ordinary builder. + /// The frozen slice is the same whichever builder the variant names, so the dispatch + /// lives here rather than at each layout arm. + fn build( + self, + printer: &Printer<'_>, + paren_open: u32, + args: &[internal::Expression<'_>], + i: usize, + ) -> DocId { + match self { + Self::ArgContext => printer.build_arg_item_doc(paren_open, args, i), + Self::Plain => printer.args_frozen_span(paren_open, args, i).map_or_else( + || printer.build_expression_doc(&args[i]), + |frozen| printer.build_frozen_arg_doc(&args[i], frozen), + ), + } + } +} + /// Check if a call/new should use the "expand first arg" pattern. /// /// This matches prettier's behavior for calls like `setTimeout(() => {...}, 100)`: @@ -942,12 +1023,22 @@ pub(super) fn try_hug_multiline_template_arg( /// Handles comments in the gaps; a gap without comments preserves its blank /// line at the top of the next iteration. The caller wraps the result with /// `wrap_call_with_hard_breaks`. +/// +/// The per-argument loop below only opens the gaps BETWEEN arguments (each via the +/// previous argument's end), so the `(`→first-argument gap is emitted up front or its +/// comments are DROPPED — the hazard-4 shape in docs/comments.md. Reachable from the +/// `new` cascade, whose comment paths do not preempt this one the way the plain call's do; +/// `blanks:audit` found it by injecting a blank line beside a leading comment. pub(super) fn build_args_with_blank_lines( printer: &Printer<'_>, args: &[internal::Expression<'_>], + paren_open: u32, ) -> DocId { let d = printer.d(); let mut arg_parts = DocBuf::new(); + if let Some(first) = args.first() { + emit_first_arg_leading_comments(printer, &mut arg_parts, paren_open, first.span().start); + } // Whether the gap just closed — between `args[i - 1]` and `args[i]` — carries an // author blank line. Computed once at the bottom of the previous iteration (the // no-comment branch below) and reused here, since the top of this iteration and @@ -973,8 +1064,9 @@ pub(super) fn build_args_with_blank_lines( // Argument-context builder so a binary/logical chain (or conditional) keeps // its continuation indent, and an assignment gets clarity parens — same as // the no-blank-line path; the blank-line forced expansion is just another - // reason the args break. - arg_parts.push(printer.build_arg_expression_doc(arg)); + // reason the args break. An own-line directive in this argument's gap freezes + // it verbatim (Rule A). + arg_parts.push(printer.build_arg_item_doc(paren_open, args, i)); if i < args.len() - 1 { let arg_end = arg.span().end; diff --git a/crates/tsv_ts/src/printer/calls/call_formatting.rs b/crates/tsv_ts/src/printer/calls/call_formatting.rs index 6a6afc694..dae76d414 100644 --- a/crates/tsv_ts/src/printer/calls/call_formatting.rs +++ b/crates/tsv_ts/src/printer/calls/call_formatting.rs @@ -17,16 +17,17 @@ use super::arg_predicates::{ is_function_composition_args, is_ternary_arrow_body, last_arg_is_array_or_object, }; use super::arg_wrapping::{ - append_type_args_with_gap_comments, arg_needs_soft_wrap, build_args_joined_with_comments, - build_args_split_last, build_args_with_blank_lines, build_arrow_call_body_states, - build_arrow_sig_doc, build_break_body_state, build_empty_args_doc, build_expand_all_args, + ArgItem, append_type_args_with_gap_comments, arg_needs_soft_wrap, build_args_split_last, + build_args_with_blank_lines, build_arrow_call_body_states, build_arrow_sig_doc, + build_break_body_state, build_call_args_expanded, build_empty_args_doc, build_expand_all_args, build_inline_args, build_inline_or_expand_all, could_expand_arrow_chain, last_two_args_same_type, prebuild_expand_last_break_body, prebuild_expand_last_obj_array_body, prepend_arrow_body_comments, should_expand_first_arg, try_hug_multiline_template_arg, wrap_call_with_hard_breaks, wrap_call_with_soft_breaks, }; +use super::call_paren_open; use super::module_paths::{get_module_path_chain_break, is_boolean_call, is_module_path_no_break}; -use super::test_patterns::{build_test_callee_flat_doc, is_test_call}; +use super::test_patterns::{build_test_callee_flat_doc, test_call_flat_layout_applies}; use crate::ast::internal; use crate::printer::CommentVec; use crate::printer::expressions::functions::arrow_signature_has_breaking_comments; @@ -114,9 +115,14 @@ pub(super) fn build_call_doc_with_wrapping( return doc; } + // Position the `(` follows — every argument-gap window (the comment scans, and Rule A's + // first-argument freeze) opens here. + let paren_open = call_paren_open(call); + // Test function calls (it, test, describe, etc.) stay on one line - // even if they exceed print width - if is_test_call(call, printer) { + // even if they exceed print width — unless an argument gap holds a comment the + // flat layout has no emitter for (it would be dropped); such a call expands. + if test_call_flat_layout_applies(call, printer) { // Build callee as a flat doc (no conditionalGroup) straight from the // span-identity chain parts — this prevents breaking at `.skip` etc. even when // very long, without materializing a throwaway callee `String`. @@ -126,7 +132,7 @@ pub(super) fn build_call_doc_with_wrapping( // above, so `arguments` is non-empty here and `.last()` is always `Some`. #[allow(clippy::unreachable)] // empty args already returned above ⇒ last() is Some let Some(last_arg) = call.arguments.last() else { - unreachable!("is_test_call requires arguments"); + unreachable!("a test call requires arguments"); }; let paren_close = call.span.end; let mut parts: DocBuf = smallvec![ @@ -151,12 +157,6 @@ pub(super) fn build_call_doc_with_wrapping( return d.concat(&parts); } - // Position after type args (or callee if no type args) — the `(` follows this. - let paren_open = call - .type_arguments - .as_ref() - .map_or_else(|| call.callee.span().end, |ta| ta.span.end); - // Whole-call comment-presence gate: one binary search over the entire argument // window. Every per-argument comment sub-query below (the leading / inter-arg / // trailing predicates, each O(n) over args, plus the general comment path) lies @@ -167,11 +167,20 @@ pub(super) fn build_call_doc_with_wrapping( // the page (a *layout* question), not who emits it — see `has_comments_on_page_between`. let call_has_comments = printer.has_comments_on_page_between(paren_open, call.span.end); + // A trailing LINE comment on an argument (`fn(a, // c⏎ b)`) rules out every layout + // below that would have to place the arguments itself: each joins them with `", "` or + // hugs them, and a comment running to EOL can't survive either — so they all decline + // and the call falls through to the comment-aware paths. Computed once: it is pure in + // `(call, printer)`, six arms ask it, and each ask walks the arguments with a binary + // search per gap. (`build_call_with_arg_comments` hoists the same predicate for the + // same reason.) The `call_has_comments` conjunct keeps a comment-free call at the one + // window-wide binary search above. + let arg_trailing_line_comment = + call_has_comments && has_trailing_comments_on_args(call, printer); + // Module path calls that should not break at arguments (e.g., require.resolve) // Keep the call on one line; let assignment/parent break instead - if is_module_path_no_break(call, printer) - && !(call_has_comments && has_trailing_comments_on_args(call, printer)) - { + if is_module_path_no_break(call, printer) && !arg_trailing_line_comment { return d.concat(&[ callee, d.text("("), @@ -187,8 +196,8 @@ pub(super) fn build_call_doc_with_wrapping( // Module path calls (require.resolve.paths, import.meta.resolve) break at chain // rather than at arguments, keeping the path on the same line as the method - if let Some((base_expr, method_name)) = get_module_path_chain_break(call, printer) - .filter(|_| !(call_has_comments && has_trailing_comments_on_args(call, printer))) + if let Some((base_expr, method_name)) = + get_module_path_chain_break(call, printer).filter(|_| !arg_trailing_line_comment) { let base_doc = printer.build_expression_doc(base_expr); let method_doc = printer.identifier_name_doc(method_name); @@ -220,7 +229,7 @@ pub(super) fn build_call_doc_with_wrapping( .any(|c| c.is_block) }); if call.arguments.len() == 1 - && !(call_has_comments && has_trailing_comments_on_args(call, printer)) + && !arg_trailing_line_comment && !has_trailing_block_comment && let Some(doc) = try_single_arg_hug(printer, call, callee) { @@ -247,32 +256,34 @@ pub(super) fn build_call_doc_with_wrapping( if has_multiline { // Force expansion with hardlines for multiline content - let arg_parts = - build_args_joined_with_comments(printer, call.arguments, paren_open, true, |p, a| { - p.build_arg_expression_doc(a) - }); - return wrap_call_with_hard_breaks(d, callee, arg_parts); + return build_call_args_expanded( + printer, + callee, + call.arguments, + paren_open, + ArgItem::ArgContext, + ); } // Function composition pattern: when any argument is a call containing a callback // e.g., fn(arr.map((x) => x), b) → fn(\n\tarr.map((x) => x),\n\tb,\n) // Prettier's isFunctionCompositionArgs: 2+ args, any arg is call with function/arrow inside // Skip if there are trailing comments - let the comment handling code deal with expansion - if is_function_composition_args(call.arguments) - && !(call_has_comments && has_trailing_comments_on_args(call, printer)) - { - let arg_parts = - build_args_joined_with_comments(printer, call.arguments, paren_open, true, |p, a| { - p.build_arg_expression_doc(a) - }); - return wrap_call_with_hard_breaks(d, callee, arg_parts); + if is_function_composition_args(call.arguments) && !arg_trailing_line_comment { + return build_call_args_expanded( + printer, + callee, + call.arguments, + paren_open, + ArgItem::ArgContext, + ); } // "Expand first arg" pattern: when first arg is a function with block body // and remaining args are short, hug the function and put tail args after closing } // e.g., setTimeout(() => { tick(); }, 100); if should_expand_first_arg(printer, call.arguments) - && !(call_has_comments && has_trailing_comments_on_args(call, printer)) + && !arg_trailing_line_comment && !(call_has_comments && first_arg_has_any_comments(call.arguments, printer, paren_open)) { let first_arg_doc = printer.build_expression_doc(&call.arguments[0]); @@ -296,16 +307,13 @@ pub(super) fn build_call_doc_with_wrapping( // Prettier: if (tailArgs.some(willBreak)) return allArgsBrokenOut() // When any tail arg's doc will break, the inline tail won't work. if tail_parts.iter().any(|&id| d.will_break(id)) { - let arg_parts = build_args_joined_with_comments( + return build_call_args_expanded( printer, + callee, call.arguments, paren_open, - true, - // Closure required: method references cause HRTB lifetime errors - #[allow(clippy::redundant_closure_for_method_calls)] - |p, a| p.build_expression_doc(a), + ArgItem::Plain, ); - return wrap_call_with_hard_breaks(d, callee, arg_parts); } // Structure: callee + ( + first_arg_with_breaks + , + tail_args + ) @@ -328,12 +336,14 @@ pub(super) fn build_call_doc_with_wrapping( .iter() .all(|arg| matches!(arg, internal::Expression::ArrowFunctionExpression(_))); - if all_args_are_arrows && !(call_has_comments && has_trailing_comments_on_args(call, printer)) { - let arg_parts = - build_args_joined_with_comments(printer, call.arguments, paren_open, true, |p, a| { - p.build_expression_doc(a) - }); - return wrap_call_with_hard_breaks(d, callee, arg_parts); + if all_args_are_arrows && !arg_trailing_line_comment { + return build_call_args_expanded( + printer, + callee, + call.arguments, + paren_open, + ArgItem::Plain, + ); } // Expand-last pattern for function/arrow last arguments. Returns `None` when @@ -383,7 +393,7 @@ pub(super) fn build_call_doc_with_wrapping( // Build arguments with blank line preservation (forced expansion). // The shared builder's comment branches never fire here: the comment // handling path above returns early when any inter-arg comments exist. - let arg_doc = build_args_with_blank_lines(printer, call.arguments); + let arg_doc = build_args_with_blank_lines(printer, call.arguments, paren_open); return wrap_call_with_hard_breaks(d, callee, arg_doc); } @@ -494,7 +504,9 @@ fn try_single_arg_comment_paths( // conditional) gets its continuation indent — matching the no-leading- // comment path. `build_expression_doc` would emit the Grouped chain // (flush continuation), losing the indent prettier applies here. - inner.push(printer.build_arg_expression_doc(first_arg)); + // An own-line directive in the gap freezes the argument verbatim (Rule A); + // this branch already keeps such a comment on its own line. + inner.push(printer.build_arg_item_doc(paren_open, call.arguments, 0)); return Some(d.concat(&[ callee, @@ -522,8 +534,10 @@ fn try_single_arg_comment_paths( let inline_comments = printer.build_rhs_comments_glued_opt(paren_open, arg_start); // Argument-context builder so a binary/logical chain gets its // continuation indent (matches the no-comment path); see the leading - // line-comment branch above for the same reasoning. - let arg_doc = printer.build_arg_expression_doc(first_arg); + // line-comment branch above for the same reasoning. A directive alone on its + // line freezes the argument (Rule A) — only the BLOCK spelling reaches here + // (a line comment routes to the branch above). + let arg_doc = printer.build_arg_item_doc(paren_open, call.arguments, 0); // Build comment + arg, including any trailing comments after the arg // Note: build_rhs_comments_opt already adds trailing space after each comment @@ -1329,8 +1343,9 @@ fn build_call_with_arg_comments( // Build the argument with the argument-context builder so a binary/logical // chain (or conditional) keeps its continuation indent — matching the // no-comment path (the single-arg comment path does the same via - // build_arg_expression_doc). - arg_parts.push(printer.build_arg_expression_doc(arg)); + // build_arg_expression_doc). An own-line format-ignore directive in this + // argument's gap freezes it verbatim (Rule A). + arg_parts.push(printer.build_arg_item_doc(paren_open, call.arguments, i)); // Check for comments after this argument (before next arg or closing paren) if i < call.arguments.len() - 1 { diff --git a/crates/tsv_ts/src/printer/calls/chain_args.rs b/crates/tsv_ts/src/printer/calls/chain_args.rs index 44f4737e7..23e4aa645 100644 --- a/crates/tsv_ts/src/printer/calls/chain_args.rs +++ b/crates/tsv_ts/src/printer/calls/chain_args.rs @@ -540,7 +540,11 @@ fn build_chain_args_force_expand( } } - arg_parts.push(printer.build_arg_expression_doc(arg)); + // An own-line format-ignore directive in this argument's gap freezes it verbatim + // (Rule A). The three hugging special cases above all decline once a comment + // forces expansion, so this is the only argument builder a directive reaches in + // the chain family. + arg_parts.push(printer.build_arg_item_doc(paren_open, call.arguments, i)); // Handle trailing comments and comma placement let arg_end = arg.span().end; @@ -632,6 +636,14 @@ fn build_chain_args_single( .. } = ctx; + // Whether a comment on the page attaches to the last argument — the predicate that + // refuses every argument hug below. Computed once: it walks the arguments with a + // `find_comma_pos` source scan plus two binary searches, and three arms ask it with + // identical arguments. Guarded by the same `has_any_comment_text`, so a comment-free + // call still pays nothing beyond the one window-wide search that set that flag. + let last_arg_commented = has_any_comment_text + && last_arg_has_comments(call.arguments, printer, call.span.end, paren_open); + let arg = &call.arguments[0]; // Special case: arrow function with call expression body @@ -649,8 +661,7 @@ fn build_chain_args_single( && arrow_body_is_call_through_non_null(body_expr) // `has_any_comment_text`: refusing the hug is a LAYOUT decision, so it must see a // comment the argument owns and prints itself (see `build_chain_args_multi`). - && !(has_any_comment_text - && last_arg_has_comments(call.arguments, printer, call.span.end, paren_open)) + && !last_arg_commented { let arrow_doc = printer.build_arg_expression_doc(arg); let arrow_doc = prepend_leading(d, leading_comment_doc, arrow_doc); @@ -709,8 +720,7 @@ fn build_chain_args_single( && let internal::ArrowFunctionBody::Expression(body_expr) = &arrow.body && is_ternary_arrow_body(body_expr) // `has_any_comment_text`: see above — a layout gate counts an owned comment. - && !(has_any_comment_text - && last_arg_has_comments(call.arguments, printer, call.span.end, paren_open)) + && !last_arg_commented { let arrow_doc = printer.build_arg_expression_doc(arg); let arrow_doc = prepend_leading(d, leading_comment_doc, arrow_doc); @@ -778,8 +788,7 @@ fn build_chain_args_single( // `has_any_comment_text` (on page), not `has_any_comments` (to emit): an owned // leading comment defeats the expand-last hug just like an ordinary one, so the // hug must refuse it too — a to-emit gate would hug blind. - && !(has_any_comment_text - && last_arg_has_comments(call.arguments, printer, call.span.end, paren_open)) + && !last_arg_commented // A comment LEADING the arg isn't the only shape that defeats the hug: one INSIDE // the signature forces a break the one-line hug can't honor. Same predicate as the // non-chain path — see `arrow_signature_has_breaking_comments`. @@ -983,6 +992,14 @@ fn build_chain_args_multi( .. } = ctx; + // Whether a comment on the page attaches to the last argument — the predicate that + // refuses the expand-last hugs below. Computed once (see `build_chain_args_single`); + // four arms ask it, two through the narrower **to-emit** `has_any_comments`, which is + // a subset of the `has_any_comment_text` guarding this binding, so each arm keeps + // saying which axis it means. + let last_arg_commented = has_any_comment_text + && last_arg_has_comments(call.arguments, printer, call.span.end, paren_open); + // Multiple arguments with block-body callback: // Use conditional_group to try inline first, then expand-all. // fits() checks actual width, handling both short and non-short preceding args. @@ -996,8 +1013,7 @@ fn build_chain_args_multi( // `has_any_comment_text`, not `has_any_comments`: refusing the expand-last hug is a // LAYOUT decision, so it must see a comment the last argument owns and prints // itself (a bundler annotation) — prettier's `shouldExpandLastArg` sees it too. - && !(has_any_comment_text - && last_arg_has_comments(call.arguments, printer, call.span.end, paren_open)) + && !last_arg_commented { let (head_parts, last_arg_doc, all_args_broken) = build_args_split_last(call.arguments, printer, paren_open, has_any_comments); @@ -1028,8 +1044,7 @@ fn build_chain_args_multi( // signature is emitted via build_arrow_sig_doc). if call.arguments.len() >= 2 && !comments_force_expansion - && !(has_any_comments - && last_arg_has_comments(call.arguments, printer, call.span.end, paren_open)) + && !(has_any_comments && last_arg_commented) && let Some(Expression::ArrowFunctionExpression(arrow)) = call.arguments.last() && let internal::ArrowFunctionBody::Expression(body_expr) = &arrow.body && matches!( @@ -1099,8 +1114,7 @@ fn build_chain_args_multi( // way (its full signature is emitted via build_arrow_sig_doc). if call.arguments.len() >= 2 && !comments_force_expansion - && !(has_any_comments - && last_arg_has_comments(call.arguments, printer, call.span.end, paren_open)) + && !(has_any_comments && last_arg_commented) && let Some(Expression::ArrowFunctionExpression(arrow)) = call.arguments.last() && let internal::ArrowFunctionBody::Expression(body_expr) = &arrow.body && matches!( @@ -1236,8 +1250,7 @@ fn build_chain_args_multi( // `has_any_comment_text` (on page), not `has_any_comments` (to emit): an owned // comment leading the last array/object argument defeats the expand-last hug just // like an ordinary one — a to-emit gate would hug blind. - && !(has_any_comment_text - && last_arg_has_comments(call.arguments, printer, call.span.end, paren_open)) + && !last_arg_commented // Prettier blocks expand-last for 2-arg arrow+array (React hook pattern) && !(call.arguments.len() == 2 && matches!( diff --git a/crates/tsv_ts/src/printer/calls/import_expr.rs b/crates/tsv_ts/src/printer/calls/import_expr.rs index ef5c286a1..c7fee4736 100644 --- a/crates/tsv_ts/src/printer/calls/import_expr.rs +++ b/crates/tsv_ts/src/printer/calls/import_expr.rs @@ -114,12 +114,24 @@ pub(super) fn build_import_expression_doc( let (open, leading_scan_start) = build_import_open_doc(printer, import_expr); let source_start = import_expr.source.span().start; + // Rule A over the two arguments: `import()`'s source and options are an argument list + // like any other, so an own-line directive in the head→source gap (which spans the + // `(`, matching the leading-comment scan above it) or in the source→options gap + // freezes the argument that follows it. The two items are named fields rather than a + // slice, so each asks the seam with its own gap anchor. + let frozen_source = printer.gap_frozen_span(leading_scan_start, import_expr.source.span()); + // Parenthesize an `in` argument inside a for-header init (`for (a = import(m, // (b in c));…)`); a no-op elsewhere. Dynamic-import args are hand-rolled here // rather than routed through `needs_parens(Argument)`, so apply the rule directly. - let raw_source_doc = printer.wrap_for_init_in( - import_expr.source, - printer.build_expression_doc(import_expr.source), + let raw_source_doc = frozen_source.map_or_else( + || { + printer.wrap_for_init_in( + import_expr.source, + printer.build_expression_doc(import_expr.source), + ) + }, + |frozen| printer.build_frozen_arg_doc(import_expr.source, frozen), ); let (source_doc, leading_forces_break) = printer.build_paren_leading_value_doc(leading_scan_start, source_start, raw_source_doc); @@ -168,7 +180,12 @@ pub(super) fn build_import_expression_doc( return wrap_import_group(d, open, source_doc); }; - let options_doc = printer.wrap_for_init_in(options, printer.build_expression_doc(options)); + let options_doc = printer + .gap_frozen_span(source_end, options.span()) + .map_or_else( + || printer.wrap_for_init_in(options, printer.build_expression_doc(options)), + |frozen| printer.build_frozen_arg_doc(options, frozen), + ); let options_end = options.span().end; let options_start = options.span().start; diff --git a/crates/tsv_ts/src/printer/calls/mod.rs b/crates/tsv_ts/src/printer/calls/mod.rs index 30221343d..abda32945 100644 --- a/crates/tsv_ts/src/printer/calls/mod.rs +++ b/crates/tsv_ts/src/printer/calls/mod.rs @@ -37,11 +37,11 @@ pub(crate) use arg_comments::{ should_force_expansion_for_comments, skip_stripped_open_paren, }; pub(crate) use arg_wrapping::{ - build_args_joined_with_comments, build_args_split_last, build_arrow_call_body_states, - build_arrow_sig_doc, build_break_body_state, build_expand_all_args, build_inline_args, - build_inline_or_expand_all, could_expand_arrow_chain, last_two_args_same_type, - prebuild_expand_last_break_body, prepend_arrow_body_comments, wrap_call_with_hard_breaks, - wrap_call_with_will_break_guard, + ArgItem, ArgsJoin, build_args_joined_with_comments, build_args_split_last, + build_arrow_call_body_states, build_arrow_sig_doc, build_break_body_state, + build_call_args_expanded, build_expand_all_args, build_inline_args, build_inline_or_expand_all, + could_expand_arrow_chain, last_two_args_same_type, prebuild_expand_last_break_body, + prepend_arrow_body_comments, wrap_call_with_hard_breaks, wrap_call_with_will_break_guard, }; use super::Printer; @@ -51,6 +51,17 @@ use arg_comments::{any_comment_forces_expansion, last_arg_has_comments}; use arg_predicates::is_block_function; use tsv_lang::doc::arena::DocId; +/// The position the call's `(` follows — the end of the type-argument list when the call +/// has one (`fn(a)`), else the callee's end. Every argument-gap window in this family +/// opens here: the leading-argument comment scans, and Rule A's first-argument freeze +/// window ([`Printer::args_frozen_span`]). One spelling, so a caller can't accidentally +/// open the window at the callee and swallow the type arguments' own comments. +pub(super) fn call_paren_open(call: &internal::CallExpression<'_>) -> u32 { + call.type_arguments + .as_ref() + .map_or_else(|| call.callee.span().end, |ta| ta.span.end) +} + /// Check if a chain expression contains any call expressions fn chain_has_calls(expr: &internal::Expression<'_>) -> bool { match expr { @@ -160,7 +171,7 @@ impl<'a> Printer<'a> { // if they exceed print width. Must check BEFORE chain routing, because // memberish callees like `it.skip(...)` would otherwise be routed through // the chain path which doesn't know about test call special-casing. - if test_patterns::is_test_call(call, self) { + if test_patterns::test_call_flat_layout_applies(call, self) { return self.build_call_doc_with_wrapping(call); } diff --git a/crates/tsv_ts/src/printer/calls/new_expression.rs b/crates/tsv_ts/src/printer/calls/new_expression.rs index da3b1bf39..bf8da8cac 100644 --- a/crates/tsv_ts/src/printer/calls/new_expression.rs +++ b/crates/tsv_ts/src/printer/calls/new_expression.rs @@ -16,10 +16,10 @@ use crate::printer::calls::arg_predicates::{ is_ternary_arrow_body, }; use crate::printer::calls::{ - PartitionedComments, build_args_joined_with_comments, build_args_split_last, + ArgItem, ArgsJoin, PartitionedComments, build_args_joined_with_comments, build_args_split_last, build_arrow_call_body_states, build_arrow_sig_doc, build_break_body_state, - build_expand_all_args, build_inline_args, build_inline_or_expand_all, could_expand_arrow_chain, - emit_first_arg_leading_comments, has_inter_argument_comments_slice, + build_call_args_expanded, build_expand_all_args, build_inline_args, build_inline_or_expand_all, + could_expand_arrow_chain, emit_first_arg_leading_comments, has_inter_argument_comments_slice, has_trailing_comments_slice, has_trailing_line_comments_slice, last_two_args_same_type, prebuild_expand_last_break_body, prepend_arrow_body_comments, should_force_expansion_for_comments, wrap_call_with_hard_breaks, @@ -130,7 +130,26 @@ impl<'a> Printer<'a> { && new_has_comments && has_trailing_comments_slice(new_expr.arguments, new_expr.span.end, self); - if new_expr.arguments.len() == 1 && !single_arg_has_trailing_comment { + // A comment in the `(`→argument gap that this expression would have to EMIT + // disqualifies the three hug arms below (object / array / function expression): + // they emit the argument's doc alone, with no gap emitter, so the comment would be + // DROPPED (the hazard-4 shape in docs/comments.md). Such a call falls through to + // the comment-aware paths and expands, matching prettier. + // + // **To-emit axis**, deliberately: a GLUED block comment is owned by the argument + // and rides inside its doc, so the hug does print it — and hugging there matches + // prettier (`new A(/* c */ { a: 1 })`). The question is exactly "would a comment be + // dropped?". The arrow arm asks the wider ON-PAGE question for its own reason (an + // owned comment must still defeat the hug, per prettier's `couldExpandArg`), which + // is why the gate sits on the three arms rather than on the outer guard. + let single_arg_leading_emit_comment = new_expr.arguments.len() == 1 + && new_has_comments + && self.has_comments_to_emit_between(paren_open, new_expr.arguments[0].span().start); + + if new_expr.arguments.len() == 1 + && !single_arg_has_trailing_comment + && !single_arg_leading_emit_comment + { match &new_expr.arguments[0] { // Object literal: hug it internal::Expression::ObjectExpression(_) => { @@ -319,15 +338,13 @@ impl<'a> Printer<'a> { && !(new_has_comments && has_trailing_comments_slice(new_expr.arguments, new_expr.span.end, self)) { - let arg_parts = build_args_joined_with_comments( + return build_call_args_expanded( self, + callee_with_types, new_expr.arguments, paren_open, - true, - #[allow(clippy::redundant_closure_for_method_calls)] - |p, a| p.build_arg_expression_doc(a), + ArgItem::ArgContext, ); - return wrap_call_with_hard_breaks(d, callee_with_types, arg_parts); } // Single template literal argument with embedded newlines on the same line @@ -351,15 +368,13 @@ impl<'a> Printer<'a> { if has_multiline { // Force expansion with hardlines for multiline content - let arg_parts = build_args_joined_with_comments( + return build_call_args_expanded( self, + callee_with_types, new_expr.arguments, paren_open, - true, - #[allow(clippy::redundant_closure_for_method_calls)] - |p, a| p.build_arg_expression_doc(a), + ArgItem::ArgContext, ); - return wrap_call_with_hard_breaks(d, callee_with_types, arg_parts); } // Check for blank lines between arguments (forces expansion and preservation). @@ -372,7 +387,7 @@ impl<'a> Printer<'a> { .any(|window| self.is_next_line_empty(window[0].span().end, window[1].span().start)); if has_blank_lines { - let arg_doc = build_args_with_blank_lines(self, new_expr.arguments); + let arg_doc = build_args_with_blank_lines(self, new_expr.arguments, paren_open); return wrap_call_with_hard_breaks(d, callee_with_types, arg_doc); } @@ -438,8 +453,9 @@ impl<'a> Printer<'a> { // Build the argument with the argument-context builder so a binary/ // logical chain (or conditional) keeps its continuation indent in this // trailing-line-comment path — matching the no-comment path (the - // call/member-chain comment paths do the same). - arg_parts.push(self.build_arg_expression_doc(arg)); + // call/member-chain comment paths do the same). An own-line directive in + // this argument's gap freezes it verbatim (Rule A). + arg_parts.push(self.build_arg_item_doc(paren_open, new_expr.arguments, i)); // Check for comments after this argument if i < new_expr.arguments.len() - 1 { @@ -489,10 +505,8 @@ impl<'a> Printer<'a> { if has_trailing_block_only { // Build args with trailing block comment let last_idx = new_expr.arguments.len() - 1; - let mut arg_docs: DocBuf = new_expr - .arguments - .iter() - .map(|arg| self.build_arg_expression_doc(arg)) + let mut arg_docs: DocBuf = (0..new_expr.arguments.len()) + .map(|i| self.build_arg_item_doc(paren_open, new_expr.arguments, i)) .collect(); // Prepend leading comments before the first arg (e.g. `new Foo(/* c */ a /* t */)`); @@ -757,15 +771,14 @@ impl<'a> Printer<'a> { inner.push(self.build_comment_doc(comment)); inner.push(d.hardline()); } - // Build the args without re-emitting the first-arg leading gap - // (pass first_arg_start so the gap scan finds nothing). + // The `(`→first-argument gap is emitted above (the paren-line prefix and + // the leading run), so the builder must not print it a second time. inner.push(build_args_joined_with_comments( self, new_expr.arguments, - first_arg_start, - true, - #[allow(clippy::redundant_closure_for_method_calls)] - |p, a| p.build_arg_expression_doc(a), + paren_open, + ArgsJoin::HardlineLeadingGapEmitted, + ArgItem::ArgContext, )); return d.concat(&[ @@ -784,9 +797,8 @@ impl<'a> Printer<'a> { self, new_expr.arguments, paren_open, - false, - #[allow(clippy::redundant_closure_for_method_calls)] - |p, a| p.build_arg_expression_doc(a), + ArgsJoin::SoftLine, + ArgItem::ArgContext, ); return wrap_call_with_will_break_guard(d, callee_with_types, arg_parts); } diff --git a/crates/tsv_ts/src/printer/calls/test_patterns.rs b/crates/tsv_ts/src/printer/calls/test_patterns.rs index 0e278f256..7e7409825 100644 --- a/crates/tsv_ts/src/printer/calls/test_patterns.rs +++ b/crates/tsv_ts/src/printer/calls/test_patterns.rs @@ -4,6 +4,8 @@ // Jest, Mocha, Jasmine, Playwright, Vitest patterns use super::super::Printer; +use super::arg_comments::has_inter_argument_comments_slice; +use super::call_paren_open; use crate::ast::internal::{self, IdentName}; use smallvec::SmallVec; use tsv_lang::doc::arena::DocId; @@ -125,6 +127,64 @@ fn get_member_chain_parts<'a>( } } +/// Whether the test-call FLAT layout applies to `call` — [`is_test_call`] plus the one +/// thing that layout cannot do: print a comment sitting in an argument gap. +/// +/// The flat layout joins the argument docs with `", "` and appends a trailing-comment +/// suffix after the last argument; it never opens the `(`→first-argument gap or any +/// inter-argument gap, so a comment there is DROPPED outright (the hazard-4 shape in +/// docs/comments.md — an alternate-layout builder that emits only its children's docs). +/// A layout that cannot print a comment must not be chosen for a call that has one, so +/// such a call falls through and expands like any other. +/// +/// **To-emit axis**, deliberately: a GLUED block comment is owned by the argument it +/// precedes and rides inside that argument's own doc, so the flat layout does print it +/// — and keeping the flat layout there matches prettier. The question here is exactly +/// "would a comment be dropped?", which is the to-emit axis's question. A comment +/// trailing the whole call is likewise fine — the layout emits that itself. +/// +/// Both routing sites ask this rather than [`is_test_call`] (`calls/mod.rs`'s +/// chain-bypass and `call_formatting.rs`'s layout branch), so they cannot disagree about +/// which calls take the flat form. See conformance_prettier.md §Comment relocation. +pub(super) fn test_call_flat_layout_applies( + call: &internal::CallExpression<'_>, + printer: &Printer<'_>, +) -> bool { + if !is_test_call(call, printer) { + return false; + } + let paren_open = call_paren_open(call); + // Zero-comment fast gate: ONE binary search over `[paren_open, last argument's start)`, + // which strictly contains every gap the check below looks at — the `(`→first-argument + // gap and each inter-argument gap all end at or before the last argument. So with no + // comment in it they are provably all empty. + // + // The window deliberately stops at the LAST argument rather than at the call's end: the + // last argument of a test call is its callback body, which is where a test file's + // comments overwhelmingly live, so a gate spanning it fires on nearly every call and + // gates nothing. Canonical reference: `build_params_doc_with_comments`. + let Some(last_start) = call.arguments.last().map(|a| a.span().start) else { + return true; + }; + !(printer.has_comments_to_emit_between(paren_open, last_start) + && test_call_gaps_have_comments(call, printer, paren_open)) +} + +/// Whether any argument gap of `call` holds a comment this call would have to emit — +/// the `(`→first-argument gap or an inter-argument gap. Only the gaps, never an +/// argument's interior: a comment inside an argument is printed by that argument's own +/// doc. +fn test_call_gaps_have_comments( + call: &internal::CallExpression<'_>, + printer: &Printer<'_>, + paren_open: u32, +) -> bool { + call.arguments + .first() + .is_some_and(|first| printer.has_comments_to_emit_between(paren_open, first.span().start)) + || has_inter_argument_comments_slice(call.arguments, printer) +} + /// Check if a call expression is a test function call that should stay on one line pub(super) fn is_test_call(call: &internal::CallExpression<'_>, printer: &Printer<'_>) -> bool { // Optional calls (`describe?.(...)`) are never test calls — they format like diff --git a/crates/tsv_ts/src/printer/expressions/arrays.rs b/crates/tsv_ts/src/printer/expressions/arrays.rs index d1ae5c5f5..966b12496 100644 --- a/crates/tsv_ts/src/printer/expressions/arrays.rs +++ b/crates/tsv_ts/src/printer/expressions/arrays.rs @@ -772,12 +772,20 @@ impl<'a> Printer<'a> { } // The element's leading run and the element form one group — see - // `build_list_element_group` for why. A hole takes neither. + // `build_list_element_group` for why. A hole takes neither. An own-line + // format-ignore directive in the element's gap freezes it verbatim (Rule A); + // this is the only element printer a directive reaches, since either spelling + // of an own-line comment routes the whole array here. if let Some(e) = elem { + let element_doc = + match self.element_frozen_span(arr.span.start + 1, arr.elements, i) { + Some(frozen) => self.build_frozen_arg_doc(e, frozen), + None => self.build_arg_expression_doc(e), + }; parts.push(self.build_list_element_group_from_comments( leading_comments.iter().copied(), elem_start, - self.build_arg_expression_doc(e), + element_doc, )); } diff --git a/crates/tsv_ts/src/printer/expressions/mod.rs b/crates/tsv_ts/src/printer/expressions/mod.rs index 21e10a2b0..f68d60fbd 100644 --- a/crates/tsv_ts/src/printer/expressions/mod.rs +++ b/crates/tsv_ts/src/printer/expressions/mod.rs @@ -248,7 +248,21 @@ impl<'a> Printer<'a> { let d = self.d(); let open = cast.span.start; // the `(` let inner_start = cast.inner.span().start; - let inner_doc = self.build_expression_doc(cast.inner); + // Rule A inside the cast's own parens: a directive alone on its line in the + // `(`→inner gap freezes the INNER verbatim, with the cast's comment and parens + // printing around the frozen slice. Freezing the paren-stripped inner rather than + // the whole shell is the same choice the type side makes + // (`paren_interior_routed_inner`), and it is what keeps the shell's own comments + // with the shell's emitters below. Prettier agrees on both the scope and the + // preserved parens here. + let frozen_inner = self.gap_frozen_span(open + 1, cast.inner.span()); + let inner_doc = frozen_inner.map_or_else( + || self.build_expression_doc(cast.inner), + // Built bare, like the ordinary arm: the cast's parens already group it. The + // owned-comment claim still applies — a block glued before the inner rides + // inside its doc, which the slice replaces. + |frozen| self.build_frozen_expression_doc(cast.inner, frozen), + ); // The owned comment, glued to the `(`. A comment the author gave a line of its // own keeps it (the same predicate drives the enclosing assignment to hang, so @@ -274,13 +288,22 @@ impl<'a> Printer<'a> { // A line comment on either side of the inner must force a hardline layout — // otherwise `(// c )` runs the inner and the `)` into the comment // (silent content loss). Mirrors `build_expression_doc_keep_paren_comments`. - if self.has_line_comments_between(open + 1, inner_start) || trailing_needs_break { + // A frozen inner joins the two content-loss triggers: the block spelling of an + // honored directive would otherwise collapse onto the frozen value's line, which + // is a glued — hence inert — placement, so the freeze would be lost on the second + // pass. (The line spelling already lands here via the scan above.) + if self.has_line_comments_between(open + 1, inner_start) + || trailing_needs_break + || frozen_inner.is_some() + { let mut parts: DocBuf = smallvec![d.hardline()]; for comment in comments_to_emit_in_range(self.comments, open + 1, inner_start) { parts.push(self.build_comment_doc(comment)); // A line comment runs to end-of-line, so it must break; a block - // comment hugs the next token inline (`/** @type {B} */ (x)`). - parts.push(if comment.is_block { + // comment hugs the next token inline (`/** @type {B} */ (x)`) — unless + // it is an honored directive, which must keep its own line for the + // freeze to survive the next pass. + parts.push(if comment.is_block && !self.is_honored_directive(comment) { d.text(" ") } else { d.hardline() diff --git a/crates/tsv_ts/src/printer/expressions/patterns.rs b/crates/tsv_ts/src/printer/expressions/patterns.rs index aa6d4b550..d0a6b9c4c 100644 --- a/crates/tsv_ts/src/printer/expressions/patterns.rs +++ b/crates/tsv_ts/src/printer/expressions/patterns.rs @@ -1021,11 +1021,19 @@ impl<'a> Printer<'a> { .collect(); // The element's leading run and the element form one group — see // `build_list_element_group` for why (prettier routes `ArrayPattern` - // through the same `printArray` as an array literal). + // through the same `printArray` as an array literal). An own-line + // format-ignore directive in the element's gap freezes it verbatim + // (Rule A) — the array literal's expanding printer does the same, and + // either spelling of an own-line comment routes the pattern here. + let element_doc = + match self.element_frozen_span(arr.span.start + 1, arr.elements, i) { + Some(frozen) => self.build_frozen_arg_doc(e, frozen), + None => self.build_expression_doc(e), + }; parts.push(self.build_list_element_group_from_comments( leading_comments.iter().copied(), elem_start, - self.build_expression_doc(e), + element_doc, )); let elem_end = e.span().end; diff --git a/crates/tsv_ts/src/printer/ignore.rs b/crates/tsv_ts/src/printer/ignore.rs index 984c33ac1..658d7a141 100644 --- a/crates/tsv_ts/src/printer/ignore.rs +++ b/crates/tsv_ts/src/printer/ignore.rs @@ -6,6 +6,16 @@ // index signature's value, a signature's return type — where the whole `: type` // freezes). // +// Value-side argument and element lists join the list family through +// `args_frozen_span` / `element_frozen_span` and the freeze-aware item builder +// `build_arg_item_doc` — a call's, a `new`'s and a member chain's arguments, and an +// array literal's or array pattern's elements. A lone item whose gap anchor its +// printer already holds (dynamic `import()`'s two named fields, a JSDoc cast's +// interior) asks `gap_frozen_span` instead, the same question without the list +// index. Each freezes over the item's own node span, so a spread or rest `...` rides +// inside; an element SLOT may be a hole, which never freezes and contributes only +// its comma to the next slot's gap. +// // Parameter lists (value-side and type-side alike) join the list family through // `param_frozen_span`, over each parameter's RENDER span so a decorated parameter // freezes from its first decorator. A decorated parameter has a SECOND freeze position @@ -53,6 +63,7 @@ // comment survives — comment preservation outranks redundant-paren removal under a freeze // (`union_prettier_ignore_paren_shell_comment` exercises it, `comments:audit` guards it). +use super::ParenContext; use super::Printer; use super::has_newline_after_position; use super::has_newline_before_position; @@ -241,10 +252,18 @@ impl<'a> Printer<'a> { /// about the directive's own placement, not the freeze target. pub(in crate::printer) fn member_gap_frozen(&self, prev_end: u32, member_start: u32) -> bool { self.has_format_ignore - && comments_in_source_range(self.comments, prev_end, member_start).any(|c| { - is_format_ignore_directive(c.content(self.source)) - && self.directive_alone_on_line(c) - }) + && comments_in_source_range(self.comments, prev_end, member_start) + .any(|c| self.is_honored_directive(c)) + } + + /// Whether comment `c` is a format-ignore directive that HONORS — the recognizer plus + /// the placement floor below, in one predicate. The freeze tests ask it through + /// [`Self::member_gap_frozen`]; an emitter asks it directly when a comment's own + /// layout depends on the answer, because an honored directive must keep the line the + /// author gave it — collapsing it onto the frozen value's line would make it glued, + /// hence inert, and the freeze would be lost on the next pass. + pub(in crate::printer) fn is_honored_directive(&self, c: &Comment) -> bool { + is_format_ignore_directive(c.content(self.source)) && self.directive_alone_on_line(c) } /// The placement floor: whether comment `c` is the only thing on its physical line @@ -493,6 +512,72 @@ impl<'a> Printer<'a> { .then(|| item_span(i)) } + /// [`Self::member_gap_frozen`] resolved to the span it freezes, for a value-side item + /// whose gap anchor the caller already holds — a lone argument (the JSDoc cast's + /// interior, dynamic `import()`'s two named fields, which are not a slice at all) or + /// an element slot, whose anchor skips the holes before it. + /// + /// `Some` is the span to freeze: the item's own node span, so a spread or rest `...` + /// rides inside the freeze (the node starts at the `...`, so its span already covers + /// it), matching prettier. The list's `,` is parent-owned and stays outside. + #[inline] + pub(in crate::printer) fn gap_frozen_span(&self, prev_end: u32, span: Span) -> Option { + self.member_gap_frozen(prev_end, span.start).then_some(span) + } + + /// [`Self::list_item_frozen`] for a value-side ARGUMENT list item `i` — a call's, + /// a `new`'s or a member chain's arguments. `Some` is the span to freeze, per + /// [`Self::gap_frozen_span`]. + /// + /// `container_start` is where the FIRST item's gap opens, per each family's own + /// convention: just past the `[` for a bracketed list, and for a call the position + /// the `(` follows (the callee's, or the type-argument list's, end) — the same window + /// every leading-argument-comment emitter at those sites already opens, so a + /// directive written above the `(` leads the first argument exactly as it does for + /// those emitters (prettier-confirmed). + #[inline] + pub(in crate::printer) fn args_frozen_span( + &self, + container_start: u32, + args: &[internal::Expression<'_>], + i: usize, + ) -> Option { + if !self.has_format_ignore { + return None; + } + let item_span = |j: usize| args[j].span(); + self.list_item_frozen(container_start, &item_span, i) + .then(|| item_span(i)) + } + + /// [`Self::args_frozen_span`] over an ELEMENT slot slice — an array literal's or + /// array pattern's `elements`, where a slot may be a HOLE (elision). + /// + /// A hole never freezes: it has no span for a verbatim slice to cover. And a run of + /// holes before slot `i` contributes only its commas, so the gap window keeps the + /// same shape (commas, whitespace, comments) when anchored at the previous PRESENT + /// element's end — or at `container_start` when every earlier slot is a hole. That + /// anchor rule is why this is spelled here beside [`Self::list_item_frozen`], the + /// other home of the gap-anchor convention, rather than at the element loops. + pub(in crate::printer) fn element_frozen_span( + &self, + container_start: u32, + elements: &[Option>], + i: usize, + ) -> Option { + if !self.has_format_ignore { + return None; + } + let elem = elements[i].as_ref()?; + let prev_end = elements[..i] + .iter() + .rev() + .flatten() + .next() + .map_or(container_start, |e| e.span().end); + self.gap_frozen_span(prev_end, elem.span()) + } + /// [`Self::list_item_frozen`] over a `TSType` slice, plus the union / /// intersection `freeze_first` arm (the out-of-span leading-run directive, which /// applies only to the first member of an undelimited list). @@ -547,6 +632,95 @@ impl<'a> Printer<'a> { self.with_frozen_must_break(self.raw_source_range(span.start, span.end), span) } + /// The frozen verbatim slice for an ARGUMENT or ELEMENT item, with the + /// argument-context clarity parens re-synthesized around it: an assignment argument + /// prints as `fn((a = b))`, and those parens are the printer's rather than the + /// author's, so they belong OUTSIDE the frozen slice — prettier freezes the inner and + /// keeps them too (`fn(⏎// prettier-ignore⏎(a = b + c))`). Same rule, and the same + /// reason, as [`Self::build_frozen_member_doc`]'s bare-member arm. + /// + /// The must-break rides in the doc ([`Self::build_frozen_span_doc`]): every layout in + /// this family is width-decided, and a `verbatim_source_span` is `will_break`-opaque, + /// so a multi-line frozen item has to say so explicitly. + pub(in crate::printer) fn build_frozen_arg_doc( + &self, + arg: &internal::Expression<'_>, + frozen: Span, + ) -> DocId { + let doc = self.build_frozen_expression_doc(arg, frozen); + if self.needs_parens(arg, ParenContext::Argument) { + // Parens outside the claimed comment, exactly as the ordinary path nests them + // (`d.parens(build_expression_doc(..))`, whose owned-comment prepend is inside). + self.d().parens(doc) + } else { + doc + } + } + + /// The frozen verbatim slice for an EXPRESSION, with the glued leading comment the + /// expression OWNS claimed onto it. + /// + /// A block comment glued before a node is owned by it and rides *inside* that node's + /// ordinary doc, which is exactly the doc a freeze replaces — and the slice starts at + /// the node's own span, so the comment is not in it either. Nothing else prints it (the + /// gap emitters all skip owned comments), so without this claim it is DROPPED: + /// docs/comments.md hazard 1, the ownership-is-about-who-PRINTS rule. Prettier keeps + /// the comment right where it is, glued before the frozen slice. + /// + /// Found by `gaps:audit` injecting a block comment before a frozen argument — the + /// print-once ledger over the fixtures as authored could not see it, since no fixture + /// glues a comment to a frozen item. + /// + /// A **`SequenceExpression`** additionally gets back the grouping parens it prints for + /// itself. Those parens are required (`fn((0, 1))` passes ONE argument; `fn(0, 1)` + /// passes two) but they are printed by `build_sequence_doc`, not by the enclosing + /// context — which is why `needs_parens` deliberately answers `false` for it — and they + /// sit OUTSIDE the node's span, so a verbatim slice of the span alone drops them and + /// changes the meaning. The rule belongs here rather than at + /// [`Self::build_frozen_arg_doc`] because it is a property of the node, not of the + /// position: the cast interior needs it too. + pub(in crate::printer) fn build_frozen_expression_doc( + &self, + expr: &internal::Expression<'_>, + frozen: Span, + ) -> DocId { + let doc = + self.prepend_owned_leading_comment_at(frozen.start, self.build_frozen_span_doc(frozen)); + if matches!(expr, internal::Expression::SequenceExpression(_)) { + self.d().parens(doc) + } else { + doc + } + } + + /// The doc for argument item `i`: the frozen verbatim slice when Rule A fires + /// ([`Self::args_frozen_span`]), else the ordinary argument-context doc. The one + /// freeze-aware twin of `build_arg_expression_doc`, so no argument loop spells the + /// dispatch itself — every call, `new` and member-chain argument loop routes here. + /// + /// The document-level flag is read HERE, with the ordinary build on its own arm, rather + /// than left to [`Self::args_frozen_span`] one call down: this is the hottest position + /// in the module — every argument of every call, `new` and chain call asks it — so a + /// directive-free document (≈ every document) pays exactly one predicted branch and + /// never the `Option` or the span closure behind it. The same reason + /// [`Self::list_item_frozen`] and [`Self::single_child_frozen`] open with it. (Measured + /// as null either way on real corpora — the shape is doctrine, not a won benchmark.) + #[inline] + pub(in crate::printer) fn build_arg_item_doc( + &self, + container_start: u32, + args: &[internal::Expression<'_>], + i: usize, + ) -> DocId { + if !self.has_format_ignore { + return self.build_arg_expression_doc(&args[i]); + } + self.args_frozen_span(container_start, args, i).map_or_else( + || self.build_arg_expression_doc(&args[i]), + |frozen| self.build_frozen_arg_doc(&args[i], frozen), + ) + } + /// Paren-transparent frozen doc for a union / intersection member — and, through /// [`Self::build_frozen_head_doc`], for a single-child head's frozen value too (the /// type-parameter constraint/default site passes a `member_parens` that keeps a diff --git a/docs/cli.md b/docs/cli.md index 9c72884eb..896a22949 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -79,7 +79,7 @@ Implemented in `tsv_cli/src/cli/input.rs` `tsv format` accepts any mix of files and directories: -- **Discovery**: directories recurse over the JS/TS family (`.ts`/`.mts`/`.cts`/`.js`/`.mjs`/`.cjs`, all parsed as TypeScript — `.jsx`/`.tsx` are out of scope), `.svelte`, and `.css` (compound forms like `.svelte.ts` included). The **safety nets** `.git`, `node_modules`, `.sl`, `.hg`, `.svn`, `.jj` are always pruned. Explicit args are trusted: file args are included regardless of extension (and regardless of the ignore files), and an ignored/hidden dir passed explicitly recurses. Symlinks inside directories are not followed; pass them explicitly. +- **Discovery**: directories recurse over the JS/TS family (`.ts`/`.mts`/`.cts`/`.js`/`.mjs`/`.cjs`, all parsed as TypeScript — `.jsx`/`.tsx` are out of scope), `.svelte`, and `.css` (compound forms like `.svelte.ts` included). The **safety nets** `.git`, `node_modules`, `.sl`, `.hg`, `.svn`, `.jj` are always pruned. Explicit args are trusted to the extent the caller named the target: a **file** arg is included regardless of extension *and* regardless of the ignore files, and a **hidden** dir passed explicitly recurses (the heuristic doesn't prune the root it was pointed at). A **directory** arg is still subject to the ignore files, including via an ignored ancestor — naming `pkg/dist` doesn't override a `dist/` rule, so an ignore rule is a scope boundary a directory arg can't step past. Symlinks inside directories are not followed; pass them explicitly. - **Ignore files (two regimes, keyed on `.git`)**: for each directory root, the **format root** — the scope boundary, derived from the argument, never the cwd — is the **repo root** inside a git tree (a hard stop where the upward walk ends, so nothing above the repo is read and `--check` is reproducible) or the **filesystem root** outside one. The regime is decided **once at the target root**, and any ignored directory is pruned (its whole subtree is skipped). - **Inside a repo**, discovery honors, relative to the repo root: - **`.gitignore`** — hierarchical and repo-rooted exactly like git ([gitignore syntax](https://git-scm.com/docs/gitignore#_pattern_format), matched against `git check-ignore` on case-sensitive filesystems). This goes beyond Prettier, which reads only one `.gitignore` and one `.prettierignore`, both relative to its own directory (the cwd by default), and ignores nested ones entirely. diff --git a/docs/conformance_prettier.md b/docs/conformance_prettier.md index 7c0800496..710d21ebc 100644 --- a/docs/conformance_prettier.md +++ b/docs/conformance_prettier.md @@ -986,6 +986,7 @@ Prettier moves comments between syntactic boundaries into adjacent blocks, paren - Call arg after-comma block, **stranded** (newline before the next arg) → Block relocated before the comma (tsv respects the newline and keeps the stranded block on the comma line). A block instead **hugging** the next arg leads it (`C`) and both formatters agree (plain match) — [stranded](../tests/fixtures/typescript/expressions/calls/nonlast_arg_after_comma_block_stranded_prettier_divergence/), [import](../tests/fixtures/typescript/expressions/calls/import_inter_arg_stranded_prettier_divergence/) (dynamic `import()` source→options gap; hugging match at [import_inter_arg_comment](../tests/fixtures/typescript/expressions/calls/import_inter_arg_comment/)) - Comma-separated-item after-comma block, **stranded** (newline before the next item) → Block relocated before the comma; tsv keeps the stranded block on the comma line (`a, /* c */⏎ b`), a before-comma and a stranded after-comma block in the same gap each preserved independently. One rule (`is_stranded_after_comma_block`) across every comma-separated site: a block **hugging** the next item leads it (both formatters agree); a **stranded** block stays trailing the comma. The stranded block is a **stable** form only when the items sit on separate lines: the multi-declarator statement always breaks its declarators, while the for-init, heritage (`extends`/`implements`), and function-parameter-list gaps collapse to one line when they fit (there the block hugs the next item and both agree) and diverge the same way only once the items wrap. The regular heritage [interface](../tests/fixtures/typescript/declarations/interface/heritage_item_after_comma_block/) / [class](../tests/fixtures/typescript/declarations/class/heritage/heritage_item_after_comma_block/) fixtures pin the hugging case (leads the next item, matching prettier). Function-parameter lists trail the comma like every other site (function declarations, methods, arrows, constructors, Svelte `{#snippet}` params, plus function/constructor **types** via their separate printer). Stranded fixtures: [declarator](../tests/fixtures/typescript/declarations/variable/multiple/after_comma_block_stranded_prettier_divergence/), [for-init](../tests/fixtures/typescript/statements/for/init_after_comma_block_stranded_prettier_divergence/), heritage [interface](../tests/fixtures/typescript/declarations/interface/heritage_item_after_comma_block_stranded_prettier_divergence/) / [class](../tests/fixtures/typescript/declarations/class/heritage/heritage_item_after_comma_block_stranded_prettier_divergence/), function-param [param](../tests/fixtures/typescript/syntax/comments/param_after_comma_block_stranded_prettier_divergence/), function/constructor-type [param](../tests/fixtures/typescript/types/function_type/param_after_comma_block_stranded_prettier_divergence/) - Call open paren `(` trailing → Onto its own line — [open_paren_comment](../tests/fixtures/typescript/expressions/calls/open_paren_comment_prettier_divergence/), [chain](../tests/fixtures/typescript/expressions/calls/chain_open_paren_comment_prettier_divergence/), [new](../tests/fixtures/typescript/expressions/calls/new_open_paren_comment_prettier_divergence/) +- Test-call (`it`/`test`/`describe`) argument-gap comment → Kept on the flat one-line layout, relocated onto the `(` line (leading gap) or past the previous argument (inter-argument gap), and prettier's own later passes then re-bind an inter-argument comment **into the callback body** (pass 2 `() => { // c`, pass 3 its own line inside the body — `audit_signature.txt` pins the chain). tsv gives up the flat layout for a call whose gaps hold a comment to emit: it expands like any other call and every comment keeps its line. Also a content-loss fix — the flat layout has no gap emitter at all, so those comments were dropped ([comments.md](./comments.md) hazard 4). A **glued** block comment is owned by its argument and rides inside that argument's doc, so it keeps the flat layout and matches prettier; so does a comment trailing the whole call — [test_call_arg_comment](../tests/fixtures/typescript/expressions/calls/test_call_arg_comment_prettier_divergence/) - Object literal `{` trailing → Onto its own line — [open_brace_comment](../tests/fixtures/typescript/expressions/objects/open_brace_comment_prettier_divergence/) - Array literal `[` trailing → Onto its own line — [open_bracket_comment](../tests/fixtures/typescript/expressions/arrays/open_bracket_comment_prettier_divergence/) - Block body `{` trailing → Onto its own line — [block_open_brace_comment](../tests/fixtures/typescript/statements/block_open_brace_comment_prettier_divergence/) @@ -1600,6 +1601,30 @@ position, and under the standing glued classification: (`prettier_variant_frozen` pins its stable form) — [params glued](../tests/fixtures/typescript/declarations/function/params_prettier_ignore_glued_inert_prettier_divergence/) +**On argument and element lists.** Rule A again, unchanged: an own-line directive in the +`(`→first-argument / `[`→first-element gap or between two items freezes the **following +item** — a call's, a `new`'s and a dynamic `import()`'s arguments, and an array literal's +or array pattern's elements. The slice is the item's own node span, so a spread or rest +`...` rides inside it (the `...` is part of what the directive precedes), and an argument +needing clarity parens keeps them around the frozen slice (`(a = b + c)`). A lone +huggable argument expands rather than hugging, for the same reason as a lone parameter. +An array hole contributes only its comma, so the element after one still freezes. +Two node-level facts ride with the slice, both because the printed form of an argument is +wider than its own span: a block comment **glued** before the item is OWNED by it and would +travel inside the doc the slice replaces, so the freeze claims it; and a +`SequenceExpression` prints its own grouping parens (`fn((0, 1))` passes ONE argument), so +the freeze re-synthesizes those too. Prettier agrees at every one of these positions, so the +ordinary fixtures `calls/args_prettier_ignore_member`, +`calls/chained/args_prettier_ignore_member`, `calls/import_args_prettier_ignore_member`, +`new/args_prettier_ignore_member`, `arrays/elements_prettier_ignore_member`, +`patterns/prettier_ignore_element`, `parenthesized/jsdoc_cast_prettier_ignore_interior` (the +directive inside a JSDoc cast's own parens, which freezes the cast's inner), and the Svelte +`expressions/call_args_prettier_ignore_member` (the embedded-TS route, where the frozen +slice is a raw range in host coordinates) all **match** prettier — no divergence in this +family. The one place the two tools part is the flat **test-call** layout, and that is a +comment-position question rather than a freeze one: see §Comment relocation's test-call +entry. + See [directives.md](./directives.md) for the user-facing reference. --- diff --git a/docs/directives.md b/docs/directives.md index 677f58937..5802ba66f 100644 --- a/docs/directives.md +++ b/docs/directives.md @@ -146,6 +146,29 @@ normally hug (`fn({ a, b }: T)`) expands instead, so the directive keeps its own line. A directive written *between* a parameter's decorators and its binding freezes just the binding, leaving the decorators to format normally. +### On argument and element lists + +Call, `new`, and dynamic-`import()` **arguments** and array literal / array +pattern **elements** are member lists too, under the same rule: an own-line +directive after the `(` / `[` or between two items freezes the **next item** +only. + +```ts +fn( + a, + // format-ignore + { x:1, y:2 }, // ← frozen verbatim; the `,` stays parent-owned + b +); +``` + +A spread or rest `...` is part of what the directive precedes, so it rides inside +the frozen slice (`... a . b` is kept verbatim). An argument that needs +clarity parens keeps them around the frozen slice (`(a = b + c)`). An +argument or element that would normally hug (`fn({ a, b })`, `new A([a, b])`) +expands instead, so the directive keeps its own line. An array hole contributes +only its comma, so the element after one still freezes. + ## `format-ignore-start` / `format-ignore-end` In Svelte templates, a pair of range markers preserves every node between them: diff --git a/tests/fixtures/svelte/expressions/call_args_prettier_ignore_member/expected.json b/tests/fixtures/svelte/expressions/call_args_prettier_ignore_member/expected.json new file mode 100644 index 000000000..dc91ebb98 --- /dev/null +++ b/tests/fixtures/svelte/expressions/call_args_prettier_ignore_member/expected.json @@ -0,0 +1,909 @@ +{ + "css": null, + "js": [], + "start": 0, + "end": 456, + "type": "Root", + "fragment": { + "type": "Fragment", + "nodes": [ + { + "type": "Text", + "start": 86, + "end": 88, + "raw": "\n\n", + "data": "\n\n" + }, + { + "type": "Comment", + "start": 88, + "end": 241, + "data": " a template expression is embedded TS: the frozen slice is a raw range in HOST\n\tcoordinates, so this pins the embedding route as well as the rule " + }, + { + "type": "Text", + "start": 241, + "end": 242, + "raw": "\n", + "data": "\n" + }, + { + "type": "ExpressionTag", + "start": 242, + "end": 285, + "expression": { + "type": "CallExpression", + "start": 243, + "end": 284, + "loc": { + "start": { + "line": 11, + "column": 1 + }, + "end": { + "line": 15, + "column": 1 + } + }, + "callee": { + "type": "Identifier", + "start": 243, + "end": 245, + "loc": { + "start": { + "line": 11, + "column": 1 + }, + "end": { + "line": 11, + "column": 3 + } + }, + "name": "fn" + }, + "arguments": [ + { + "type": "ObjectExpression", + "start": 268, + "end": 278, + "loc": { + "start": { + "line": 13, + "column": 1 + }, + "end": { + "line": 13, + "column": 11 + } + }, + "properties": [ + { + "type": "Property", + "start": 270, + "end": 276, + "loc": { + "start": { + "line": 13, + "column": 3 + }, + "end": { + "line": 13, + "column": 9 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 270, + "end": 271, + "loc": { + "start": { + "line": 13, + "column": 3 + }, + "end": { + "line": 13, + "column": 4 + } + }, + "name": "x" + }, + "value": { + "type": "Literal", + "start": 275, + "end": 276, + "loc": { + "start": { + "line": 13, + "column": 8 + }, + "end": { + "line": 13, + "column": 9 + } + }, + "value": 1, + "raw": "1" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 248, + "end": 266 + } + ] + }, + { + "type": "Identifier", + "start": 281, + "end": 282, + "loc": { + "start": { + "line": 14, + "column": 1 + }, + "end": { + "line": 14, + "column": 2 + } + }, + "name": "b" + } + ], + "optional": false + } + }, + { + "type": "Text", + "start": 285, + "end": 287, + "raw": "\n\n", + "data": "\n\n" + }, + { + "type": "IfBlock", + "elseif": false, + "start": 287, + "end": 365, + "test": { + "type": "Identifier", + "start": 292, + "end": 293, + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 6 + } + }, + "name": "a" + }, + "consequent": { + "type": "Fragment", + "nodes": [ + { + "type": "Text", + "start": 294, + "end": 296, + "raw": "\n\t", + "data": "\n\t" + }, + { + "type": "ConstTag", + "start": 296, + "end": 354, + "declaration": { + "type": "VariableDeclaration", + "kind": "const", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "c", + "start": 304, + "end": 305, + "loc": { + "start": { + "line": 18, + "column": 9, + "character": 304 + }, + "end": { + "line": 18, + "column": 10, + "character": 305 + } + } + }, + "init": { + "type": "CallExpression", + "start": 308, + "end": 353, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 22, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 308, + "end": 310, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 15 + } + }, + "name": "fn" + }, + "arguments": [ + { + "type": "ObjectExpression", + "start": 335, + "end": 345, + "loc": { + "start": { + "line": 20, + "column": 2 + }, + "end": { + "line": 20, + "column": 12 + } + }, + "properties": [ + { + "type": "Property", + "start": 337, + "end": 343, + "loc": { + "start": { + "line": 20, + "column": 4 + }, + "end": { + "line": 20, + "column": 10 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 337, + "end": 338, + "loc": { + "start": { + "line": 20, + "column": 4 + }, + "end": { + "line": 20, + "column": 5 + } + }, + "name": "x" + }, + "value": { + "type": "Literal", + "start": 342, + "end": 343, + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 20, + "column": 10 + } + }, + "value": 1, + "raw": "1" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 314, + "end": 332 + } + ] + }, + { + "type": "Identifier", + "start": 349, + "end": 350, + "loc": { + "start": { + "line": 21, + "column": 2 + }, + "end": { + "line": 21, + "column": 3 + } + }, + "name": "b" + } + ], + "optional": false + }, + "start": 304, + "end": 353 + } + ], + "start": 298, + "end": 353 + } + }, + { + "type": "Text", + "start": 354, + "end": 356, + "raw": "\n\t", + "data": "\n\t" + }, + { + "type": "ExpressionTag", + "start": 356, + "end": 359, + "expression": { + "type": "Identifier", + "start": 357, + "end": 358, + "loc": { + "start": { + "line": 23, + "column": 2 + }, + "end": { + "line": 23, + "column": 3 + } + }, + "name": "c" + } + }, + { + "type": "Text", + "start": 359, + "end": 360, + "raw": "\n", + "data": "\n" + } + ] + }, + "alternate": null + }, + { + "type": "Text", + "start": 365, + "end": 367, + "raw": "\n\n", + "data": "\n\n" + }, + { + "type": "RegularElement", + "start": 367, + "end": 455, + "name": "div", + "name_loc": { + "start": { + "line": 26, + "column": 1, + "character": 368 + }, + "end": { + "line": 26, + "column": 4, + "character": 371 + } + }, + "attributes": [ + { + "type": "Attribute", + "start": 373, + "end": 440, + "name": "onclick", + "name_loc": { + "start": { + "line": 27, + "column": 1, + "character": 373 + }, + "end": { + "line": 27, + "column": 8, + "character": 380 + } + }, + "value": { + "type": "ExpressionTag", + "start": 381, + "end": 440, + "expression": { + "type": "ArrowFunctionExpression", + "start": 382, + "end": 439, + "loc": { + "start": { + "line": 27, + "column": 10 + }, + "end": { + "line": 32, + "column": 3 + } + }, + "id": null, + "expression": true, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "CallExpression", + "start": 390, + "end": 439, + "loc": { + "start": { + "line": 28, + "column": 2 + }, + "end": { + "line": 32, + "column": 3 + } + }, + "callee": { + "type": "Identifier", + "start": 390, + "end": 392, + "loc": { + "start": { + "line": 28, + "column": 2 + }, + "end": { + "line": 28, + "column": 4 + } + }, + "name": "fn" + }, + "arguments": [ + { + "type": "ObjectExpression", + "start": 419, + "end": 429, + "loc": { + "start": { + "line": 30, + "column": 3 + }, + "end": { + "line": 30, + "column": 13 + } + }, + "properties": [ + { + "type": "Property", + "start": 421, + "end": 427, + "loc": { + "start": { + "line": 30, + "column": 5 + }, + "end": { + "line": 30, + "column": 11 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 421, + "end": 422, + "loc": { + "start": { + "line": 30, + "column": 5 + }, + "end": { + "line": 30, + "column": 6 + } + }, + "name": "x" + }, + "value": { + "type": "Literal", + "start": 426, + "end": 427, + "loc": { + "start": { + "line": 30, + "column": 10 + }, + "end": { + "line": 30, + "column": 11 + } + }, + "value": 1, + "raw": "1" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 397, + "end": 415 + } + ] + }, + { + "type": "Identifier", + "start": 434, + "end": 435, + "loc": { + "start": { + "line": 31, + "column": 3 + }, + "end": { + "line": 31, + "column": 4 + } + }, + "name": "b" + } + ], + "optional": false + } + } + } + } + ], + "fragment": { + "type": "Fragment", + "nodes": [ + { + "type": "Text", + "start": 442, + "end": 449, + "raw": "\n\ttext\n", + "data": "\n\ttext\n" + } + ] + } + } + ] + }, + "options": null, + "comments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 36, + "end": 54, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 248, + "end": 266, + "loc": { + "start": { + "line": 12, + "column": 1 + }, + "end": { + "line": 12, + "column": 19 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 314, + "end": 332, + "loc": { + "start": { + "line": 19, + "column": 2 + }, + "end": { + "line": 19, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 397, + "end": 415, + "loc": { + "start": { + "line": 29, + "column": 3 + }, + "end": { + "line": 29, + "column": 21 + } + } + } + ], + "instance": { + "type": "Script", + "start": 0, + "end": 86, + "context": "default", + "content": { + "type": "Program", + "start": 18, + "end": 77, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 9 + } + }, + "body": [ + { + "type": "VariableDeclaration", + "start": 20, + "end": 76, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 26, + "end": 75, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "id": { + "type": "Identifier", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "name": "a" + }, + "init": { + "type": "CallExpression", + "start": 30, + "end": 75, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 30, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "name": "fn" + }, + "arguments": [ + { + "type": "ObjectExpression", + "start": 57, + "end": 67, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 12 + } + }, + "properties": [ + { + "type": "Property", + "start": 59, + "end": 65, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 10 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 59, + "end": 60, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 5 + } + }, + "name": "x" + }, + "value": { + "type": "Literal", + "start": 64, + "end": 65, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 10 + } + }, + "value": 1, + "raw": "1" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 36, + "end": 54 + } + ] + }, + { + "type": "Identifier", + "start": 71, + "end": 72, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 3 + } + }, + "name": "b" + } + ], + "optional": false + } + } + ], + "kind": "const" + } + ], + "sourceType": "module" + }, + "attributes": [ + { + "type": "Attribute", + "start": 8, + "end": 17, + "name": "lang", + "name_loc": { + "start": { + "line": 1, + "column": 8, + "character": 8 + }, + "end": { + "line": 1, + "column": 12, + "character": 12 + } + }, + "value": [ + { + "start": 14, + "end": 16, + "type": "Text", + "raw": "ts", + "data": "ts" + } + ] + } + ] + } +} diff --git a/tests/fixtures/svelte/expressions/call_args_prettier_ignore_member/input.svelte b/tests/fixtures/svelte/expressions/call_args_prettier_ignore_member/input.svelte new file mode 100644 index 000000000..b71ab32fc --- /dev/null +++ b/tests/fixtures/svelte/expressions/call_args_prettier_ignore_member/input.svelte @@ -0,0 +1,35 @@ + + + +{fn( + // prettier-ignore + { x: 1 }, + b +)} + +{#if a} + {@const c = fn( + // prettier-ignore + { x: 1 }, + b + )} + {c} +{/if} + +
+ fn( + // prettier-ignore + { x: 1 }, + b + )} +> + text +
diff --git a/tests/fixtures/svelte/expressions/call_args_prettier_ignore_member/unformatted_spaces.svelte b/tests/fixtures/svelte/expressions/call_args_prettier_ignore_member/unformatted_spaces.svelte new file mode 100644 index 000000000..43b370a42 --- /dev/null +++ b/tests/fixtures/svelte/expressions/call_args_prettier_ignore_member/unformatted_spaces.svelte @@ -0,0 +1,35 @@ + + + +{fn( + // prettier-ignore + { x: 1 }, + b +)} + +{#if a} + {@const c = fn( + // prettier-ignore + { x: 1 }, + b + )} + {c} +{/if} + +
+ fn( + // prettier-ignore + { x: 1 }, + b + )} +> + text +
diff --git a/tests/fixtures/typescript/expressions/arrays/elements_prettier_ignore_member/expected.json b/tests/fixtures/typescript/expressions/arrays/elements_prettier_ignore_member/expected.json new file mode 100644 index 000000000..2ec40616b --- /dev/null +++ b/tests/fixtures/typescript/expressions/arrays/elements_prettier_ignore_member/expected.json @@ -0,0 +1,2442 @@ +{ + "css": null, + "js": [], + "start": 0, + "end": 1225, + "type": "Root", + "fragment": { + "type": "Fragment", + "nodes": [] + }, + "options": null, + "comments": [ + { + "type": "Line", + "value": " an own-line directive in an element gap freezes only the following element", + "start": 20, + "end": 97, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 78 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 125, + "end": 143, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " before the first element", + "start": 175, + "end": 202, + "loc": { + "start": { + "line": 10, + "column": 1 + }, + "end": { + "line": 10, + "column": 28 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 218, + "end": 236, + "loc": { + "start": { + "line": 12, + "column": 2 + }, + "end": { + "line": 12, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " an own-line block comment behaves identically", + "start": 268, + "end": 316, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 49 + } + } + }, + { + "type": "Block", + "value": " prettier-ignore ", + "start": 332, + "end": 353, + "loc": { + "start": { + "line": 19, + "column": 2 + }, + "end": { + "line": 19, + "column": 23 + } + } + }, + { + "type": "Line", + "value": " a hole contributes only its comma, so the element after one still freezes", + "start": 385, + "end": 461, + "loc": { + "start": { + "line": 24, + "column": 1 + }, + "end": { + "line": 24, + "column": 77 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 486, + "end": 504, + "loc": { + "start": { + "line": 28, + "column": 2 + }, + "end": { + "line": 28, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " a lone element", + "start": 524, + "end": 541, + "loc": { + "start": { + "line": 32, + "column": 1 + }, + "end": { + "line": 32, + "column": 18 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 557, + "end": 575, + "loc": { + "start": { + "line": 34, + "column": 2 + }, + "end": { + "line": 34, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " a spread rides inside the frozen slice", + "start": 595, + "end": 636, + "loc": { + "start": { + "line": 38, + "column": 1 + }, + "end": { + "line": 38, + "column": 42 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 652, + "end": 670, + "loc": { + "start": { + "line": 40, + "column": 2 + }, + "end": { + "line": 40, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " a multi-line frozen element keeps its verbatim layout", + "start": 697, + "end": 753, + "loc": { + "start": { + "line": 45, + "column": 1 + }, + "end": { + "line": 45, + "column": 57 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 774, + "end": 792, + "loc": { + "start": { + "line": 48, + "column": 2 + }, + "end": { + "line": 48, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " nested inside a call argument", + "start": 832, + "end": 864, + "loc": { + "start": { + "line": 56, + "column": 1 + }, + "end": { + "line": 56, + "column": 33 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 884, + "end": 902, + "loc": { + "start": { + "line": 59, + "column": 3 + }, + "end": { + "line": 59, + "column": 21 + } + } + }, + { + "type": "Line", + "value": " a block comment glued before a frozen element is owned by it and stays put", + "start": 941, + "end": 1018, + "loc": { + "start": { + "line": 65, + "column": 1 + }, + "end": { + "line": 65, + "column": 78 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 1034, + "end": 1052, + "loc": { + "start": { + "line": 67, + "column": 2 + }, + "end": { + "line": 67, + "column": 20 + } + } + }, + { + "type": "Block", + "value": " c ", + "start": 1055, + "end": 1062, + "loc": { + "start": { + "line": 68, + "column": 2 + }, + "end": { + "line": 68, + "column": 9 + } + } + }, + { + "type": "Line", + "value": " a sequence element keeps its own grouping parens around the frozen slice", + "start": 1085, + "end": 1160, + "loc": { + "start": { + "line": 72, + "column": 1 + }, + "end": { + "line": 72, + "column": 76 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 1176, + "end": 1194, + "loc": { + "start": { + "line": 74, + "column": 2 + }, + "end": { + "line": 74, + "column": 20 + } + } + } + ], + "instance": { + "type": "Script", + "start": 0, + "end": 1224, + "context": "default", + "content": { + "type": "Program", + "start": 18, + "end": 1215, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 78, + "column": 9 + } + }, + "body": [ + { + "type": "VariableDeclaration", + "start": 99, + "end": 172, + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 8, + "column": 3 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 105, + "end": 171, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 8, + "column": 2 + } + }, + "id": { + "type": "Identifier", + "start": 105, + "end": 106, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "name": "a" + }, + "init": { + "type": "ArrayExpression", + "start": 109, + "end": 171, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 8, + "column": 2 + } + }, + "elements": [ + { + "type": "ObjectExpression", + "start": 113, + "end": 121, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 10 + } + }, + "properties": [ + { + "type": "Property", + "start": 115, + "end": 119, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 8 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 115, + "end": 116, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 5 + } + }, + "name": "a" + }, + "value": { + "type": "Literal", + "start": 118, + "end": 119, + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 8 + } + }, + "value": 1, + "raw": "1" + }, + "kind": "init" + } + ] + }, + { + "type": "ObjectExpression", + "start": 146, + "end": 156, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 12 + } + }, + "properties": [ + { + "type": "Property", + "start": 148, + "end": 154, + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 10 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 148, + "end": 149, + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 5 + } + }, + "name": "b" + }, + "value": { + "type": "Literal", + "start": 153, + "end": 154, + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 6, + "column": 10 + } + }, + "value": 2, + "raw": "2" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 125, + "end": 143 + } + ] + }, + { + "type": "ObjectExpression", + "start": 160, + "end": 168, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 10 + } + }, + "properties": [ + { + "type": "Property", + "start": 162, + "end": 166, + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 8 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 162, + "end": 163, + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 5 + } + }, + "name": "c" + }, + "value": { + "type": "Literal", + "start": 165, + "end": 166, + "loc": { + "start": { + "line": 7, + "column": 7 + }, + "end": { + "line": 7, + "column": 8 + } + }, + "value": 3, + "raw": "3" + }, + "kind": "init" + } + ] + } + ] + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "Line", + "value": " an own-line directive in an element gap freezes only the following element", + "start": 20, + "end": 97 + } + ] + }, + { + "type": "VariableDeclaration", + "start": 204, + "end": 265, + "loc": { + "start": { + "line": 11, + "column": 1 + }, + "end": { + "line": 15, + "column": 3 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 210, + "end": 264, + "loc": { + "start": { + "line": 11, + "column": 7 + }, + "end": { + "line": 15, + "column": 2 + } + }, + "id": { + "type": "Identifier", + "start": 210, + "end": 211, + "loc": { + "start": { + "line": 11, + "column": 7 + }, + "end": { + "line": 11, + "column": 8 + } + }, + "name": "b" + }, + "init": { + "type": "ArrayExpression", + "start": 214, + "end": 264, + "loc": { + "start": { + "line": 11, + "column": 11 + }, + "end": { + "line": 15, + "column": 2 + } + }, + "elements": [ + { + "type": "ObjectExpression", + "start": 239, + "end": 249, + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 12 + } + }, + "properties": [ + { + "type": "Property", + "start": 241, + "end": 247, + "loc": { + "start": { + "line": 13, + "column": 4 + }, + "end": { + "line": 13, + "column": 10 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 241, + "end": 242, + "loc": { + "start": { + "line": 13, + "column": 4 + }, + "end": { + "line": 13, + "column": 5 + } + }, + "name": "a" + }, + "value": { + "type": "Literal", + "start": 246, + "end": 247, + "loc": { + "start": { + "line": 13, + "column": 9 + }, + "end": { + "line": 13, + "column": 10 + } + }, + "value": 1, + "raw": "1" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 218, + "end": 236 + } + ] + }, + { + "type": "ObjectExpression", + "start": 253, + "end": 261, + "loc": { + "start": { + "line": 14, + "column": 2 + }, + "end": { + "line": 14, + "column": 10 + } + }, + "properties": [ + { + "type": "Property", + "start": 255, + "end": 259, + "loc": { + "start": { + "line": 14, + "column": 4 + }, + "end": { + "line": 14, + "column": 8 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 255, + "end": 256, + "loc": { + "start": { + "line": 14, + "column": 4 + }, + "end": { + "line": 14, + "column": 5 + } + }, + "name": "b" + }, + "value": { + "type": "Literal", + "start": 258, + "end": 259, + "loc": { + "start": { + "line": 14, + "column": 7 + }, + "end": { + "line": 14, + "column": 8 + } + }, + "value": 2, + "raw": "2" + }, + "kind": "init" + } + ] + } + ] + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "Line", + "value": " before the first element", + "start": 175, + "end": 202 + } + ] + }, + { + "type": "VariableDeclaration", + "start": 318, + "end": 382, + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 22, + "column": 3 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 324, + "end": 381, + "loc": { + "start": { + "line": 18, + "column": 7 + }, + "end": { + "line": 22, + "column": 2 + } + }, + "id": { + "type": "Identifier", + "start": 324, + "end": 325, + "loc": { + "start": { + "line": 18, + "column": 7 + }, + "end": { + "line": 18, + "column": 8 + } + }, + "name": "c" + }, + "init": { + "type": "ArrayExpression", + "start": 328, + "end": 381, + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 22, + "column": 2 + } + }, + "elements": [ + { + "type": "ObjectExpression", + "start": 356, + "end": 366, + "loc": { + "start": { + "line": 20, + "column": 2 + }, + "end": { + "line": 20, + "column": 12 + } + }, + "properties": [ + { + "type": "Property", + "start": 358, + "end": 364, + "loc": { + "start": { + "line": 20, + "column": 4 + }, + "end": { + "line": 20, + "column": 10 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 358, + "end": 359, + "loc": { + "start": { + "line": 20, + "column": 4 + }, + "end": { + "line": 20, + "column": 5 + } + }, + "name": "a" + }, + "value": { + "type": "Literal", + "start": 363, + "end": 364, + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 20, + "column": 10 + } + }, + "value": 1, + "raw": "1" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Block", + "value": " prettier-ignore ", + "start": 332, + "end": 353 + } + ] + }, + { + "type": "ObjectExpression", + "start": 370, + "end": 378, + "loc": { + "start": { + "line": 21, + "column": 2 + }, + "end": { + "line": 21, + "column": 10 + } + }, + "properties": [ + { + "type": "Property", + "start": 372, + "end": 376, + "loc": { + "start": { + "line": 21, + "column": 4 + }, + "end": { + "line": 21, + "column": 8 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 372, + "end": 373, + "loc": { + "start": { + "line": 21, + "column": 4 + }, + "end": { + "line": 21, + "column": 5 + } + }, + "name": "b" + }, + "value": { + "type": "Literal", + "start": 375, + "end": 376, + "loc": { + "start": { + "line": 21, + "column": 7 + }, + "end": { + "line": 21, + "column": 8 + } + }, + "value": 2, + "raw": "2" + }, + "kind": "init" + } + ] + } + ] + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "Line", + "value": " an own-line block comment behaves identically", + "start": 268, + "end": 316 + } + ] + }, + { + "type": "VariableDeclaration", + "start": 463, + "end": 521, + "loc": { + "start": { + "line": 25, + "column": 1 + }, + "end": { + "line": 30, + "column": 3 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 469, + "end": 520, + "loc": { + "start": { + "line": 25, + "column": 7 + }, + "end": { + "line": 30, + "column": 2 + } + }, + "id": { + "type": "Identifier", + "start": 469, + "end": 470, + "loc": { + "start": { + "line": 25, + "column": 7 + }, + "end": { + "line": 25, + "column": 8 + } + }, + "name": "d" + }, + "init": { + "type": "ArrayExpression", + "start": 473, + "end": 520, + "loc": { + "start": { + "line": 25, + "column": 11 + }, + "end": { + "line": 30, + "column": 2 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 477, + "end": 478, + "loc": { + "start": { + "line": 26, + "column": 2 + }, + "end": { + "line": 26, + "column": 3 + } + }, + "name": "a" + }, + null, + { + "type": "ObjectExpression", + "start": 507, + "end": 517, + "loc": { + "start": { + "line": 29, + "column": 2 + }, + "end": { + "line": 29, + "column": 12 + } + }, + "properties": [ + { + "type": "Property", + "start": 509, + "end": 515, + "loc": { + "start": { + "line": 29, + "column": 4 + }, + "end": { + "line": 29, + "column": 10 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 509, + "end": 510, + "loc": { + "start": { + "line": 29, + "column": 4 + }, + "end": { + "line": 29, + "column": 5 + } + }, + "name": "b" + }, + "value": { + "type": "Literal", + "start": 514, + "end": 515, + "loc": { + "start": { + "line": 29, + "column": 9 + }, + "end": { + "line": 29, + "column": 10 + } + }, + "value": 2, + "raw": "2" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 486, + "end": 504 + } + ] + } + ] + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "Line", + "value": " a hole contributes only its comma, so the element after one still freezes", + "start": 385, + "end": 461 + } + ] + }, + { + "type": "VariableDeclaration", + "start": 543, + "end": 592, + "loc": { + "start": { + "line": 33, + "column": 1 + }, + "end": { + "line": 36, + "column": 3 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 549, + "end": 591, + "loc": { + "start": { + "line": 33, + "column": 7 + }, + "end": { + "line": 36, + "column": 2 + } + }, + "id": { + "type": "Identifier", + "start": 549, + "end": 550, + "loc": { + "start": { + "line": 33, + "column": 7 + }, + "end": { + "line": 33, + "column": 8 + } + }, + "name": "e" + }, + "init": { + "type": "ArrayExpression", + "start": 553, + "end": 591, + "loc": { + "start": { + "line": 33, + "column": 11 + }, + "end": { + "line": 36, + "column": 2 + } + }, + "elements": [ + { + "type": "ObjectExpression", + "start": 578, + "end": 588, + "loc": { + "start": { + "line": 35, + "column": 2 + }, + "end": { + "line": 35, + "column": 12 + } + }, + "properties": [ + { + "type": "Property", + "start": 580, + "end": 586, + "loc": { + "start": { + "line": 35, + "column": 4 + }, + "end": { + "line": 35, + "column": 10 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 580, + "end": 581, + "loc": { + "start": { + "line": 35, + "column": 4 + }, + "end": { + "line": 35, + "column": 5 + } + }, + "name": "a" + }, + "value": { + "type": "Literal", + "start": 585, + "end": 586, + "loc": { + "start": { + "line": 35, + "column": 9 + }, + "end": { + "line": 35, + "column": 10 + } + }, + "value": 1, + "raw": "1" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 557, + "end": 575 + } + ] + } + ] + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "Line", + "value": " a lone element", + "start": 524, + "end": 541 + } + ] + }, + { + "type": "VariableDeclaration", + "start": 638, + "end": 694, + "loc": { + "start": { + "line": 39, + "column": 1 + }, + "end": { + "line": 43, + "column": 3 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 644, + "end": 693, + "loc": { + "start": { + "line": 39, + "column": 7 + }, + "end": { + "line": 43, + "column": 2 + } + }, + "id": { + "type": "Identifier", + "start": 644, + "end": 645, + "loc": { + "start": { + "line": 39, + "column": 7 + }, + "end": { + "line": 39, + "column": 8 + } + }, + "name": "f" + }, + "init": { + "type": "ArrayExpression", + "start": 648, + "end": 693, + "loc": { + "start": { + "line": 39, + "column": 11 + }, + "end": { + "line": 43, + "column": 2 + } + }, + "elements": [ + { + "type": "SpreadElement", + "start": 673, + "end": 685, + "loc": { + "start": { + "line": 41, + "column": 2 + }, + "end": { + "line": 41, + "column": 14 + } + }, + "argument": { + "type": "MemberExpression", + "start": 678, + "end": 685, + "loc": { + "start": { + "line": 41, + "column": 7 + }, + "end": { + "line": 41, + "column": 14 + } + }, + "object": { + "type": "Identifier", + "start": 678, + "end": 679, + "loc": { + "start": { + "line": 41, + "column": 7 + }, + "end": { + "line": 41, + "column": 8 + } + }, + "name": "a" + }, + "property": { + "type": "Identifier", + "start": 684, + "end": 685, + "loc": { + "start": { + "line": 41, + "column": 13 + }, + "end": { + "line": 41, + "column": 14 + } + }, + "name": "b" + }, + "computed": false, + "optional": false + }, + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 652, + "end": 670 + } + ] + }, + { + "type": "Identifier", + "start": 689, + "end": 690, + "loc": { + "start": { + "line": 42, + "column": 2 + }, + "end": { + "line": 42, + "column": 3 + } + }, + "name": "c" + } + ] + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "Line", + "value": " a spread rides inside the frozen slice", + "start": 595, + "end": 636 + } + ] + }, + { + "type": "VariableDeclaration", + "start": 755, + "end": 829, + "loc": { + "start": { + "line": 46, + "column": 1 + }, + "end": { + "line": 54, + "column": 3 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 761, + "end": 828, + "loc": { + "start": { + "line": 46, + "column": 7 + }, + "end": { + "line": 54, + "column": 2 + } + }, + "id": { + "type": "Identifier", + "start": 761, + "end": 762, + "loc": { + "start": { + "line": 46, + "column": 7 + }, + "end": { + "line": 46, + "column": 8 + } + }, + "name": "g" + }, + "init": { + "type": "ArrayExpression", + "start": 765, + "end": 828, + "loc": { + "start": { + "line": 46, + "column": 11 + }, + "end": { + "line": 54, + "column": 2 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 769, + "end": 770, + "loc": { + "start": { + "line": 47, + "column": 2 + }, + "end": { + "line": 47, + "column": 3 + } + }, + "name": "a" + }, + { + "type": "ObjectExpression", + "start": 795, + "end": 820, + "loc": { + "start": { + "line": 49, + "column": 2 + }, + "end": { + "line": 52, + "column": 3 + } + }, + "properties": [ + { + "type": "Property", + "start": 800, + "end": 806, + "loc": { + "start": { + "line": 50, + "column": 3 + }, + "end": { + "line": 50, + "column": 9 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 800, + "end": 801, + "loc": { + "start": { + "line": 50, + "column": 3 + }, + "end": { + "line": 50, + "column": 4 + } + }, + "name": "b" + }, + "value": { + "type": "Literal", + "start": 805, + "end": 806, + "loc": { + "start": { + "line": 50, + "column": 8 + }, + "end": { + "line": 50, + "column": 9 + } + }, + "value": 2, + "raw": "2" + }, + "kind": "init" + }, + { + "type": "Property", + "start": 812, + "end": 816, + "loc": { + "start": { + "line": 51, + "column": 4 + }, + "end": { + "line": 51, + "column": 8 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 812, + "end": 813, + "loc": { + "start": { + "line": 51, + "column": 4 + }, + "end": { + "line": 51, + "column": 5 + } + }, + "name": "c" + }, + "value": { + "type": "Literal", + "start": 815, + "end": 816, + "loc": { + "start": { + "line": 51, + "column": 7 + }, + "end": { + "line": 51, + "column": 8 + } + }, + "value": 3, + "raw": "3" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 774, + "end": 792 + } + ] + }, + { + "type": "Identifier", + "start": 824, + "end": 825, + "loc": { + "start": { + "line": 53, + "column": 2 + }, + "end": { + "line": 53, + "column": 3 + } + }, + "name": "d" + } + ] + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "Line", + "value": " a multi-line frozen element keeps its verbatim layout", + "start": 697, + "end": 753 + } + ] + }, + { + "type": "ExpressionStatement", + "start": 866, + "end": 938, + "loc": { + "start": { + "line": 57, + "column": 1 + }, + "end": { + "line": 63, + "column": 4 + } + }, + "expression": { + "type": "CallExpression", + "start": 866, + "end": 937, + "loc": { + "start": { + "line": 57, + "column": 1 + }, + "end": { + "line": 63, + "column": 3 + } + }, + "callee": { + "type": "Identifier", + "start": 866, + "end": 868, + "loc": { + "start": { + "line": 57, + "column": 1 + }, + "end": { + "line": 57, + "column": 3 + } + }, + "name": "fn" + }, + "arguments": [ + { + "type": "ObjectExpression", + "start": 869, + "end": 936, + "loc": { + "start": { + "line": 57, + "column": 4 + }, + "end": { + "line": 63, + "column": 2 + } + }, + "properties": [ + { + "type": "Property", + "start": 873, + "end": 933, + "loc": { + "start": { + "line": 58, + "column": 2 + }, + "end": { + "line": 62, + "column": 3 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 873, + "end": 877, + "loc": { + "start": { + "line": 58, + "column": 2 + }, + "end": { + "line": 58, + "column": 6 + } + }, + "name": "list" + }, + "value": { + "type": "ArrayExpression", + "start": 879, + "end": 933, + "loc": { + "start": { + "line": 58, + "column": 8 + }, + "end": { + "line": 62, + "column": 3 + } + }, + "elements": [ + { + "type": "ObjectExpression", + "start": 906, + "end": 916, + "loc": { + "start": { + "line": 60, + "column": 3 + }, + "end": { + "line": 60, + "column": 13 + } + }, + "properties": [ + { + "type": "Property", + "start": 908, + "end": 914, + "loc": { + "start": { + "line": 60, + "column": 5 + }, + "end": { + "line": 60, + "column": 11 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 908, + "end": 909, + "loc": { + "start": { + "line": 60, + "column": 5 + }, + "end": { + "line": 60, + "column": 6 + } + }, + "name": "a" + }, + "value": { + "type": "Literal", + "start": 913, + "end": 914, + "loc": { + "start": { + "line": 60, + "column": 10 + }, + "end": { + "line": 60, + "column": 11 + } + }, + "value": 1, + "raw": "1" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 884, + "end": 902 + } + ] + }, + { + "type": "ObjectExpression", + "start": 921, + "end": 929, + "loc": { + "start": { + "line": 61, + "column": 3 + }, + "end": { + "line": 61, + "column": 11 + } + }, + "properties": [ + { + "type": "Property", + "start": 923, + "end": 927, + "loc": { + "start": { + "line": 61, + "column": 5 + }, + "end": { + "line": 61, + "column": 9 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 923, + "end": 924, + "loc": { + "start": { + "line": 61, + "column": 5 + }, + "end": { + "line": 61, + "column": 6 + } + }, + "name": "b" + }, + "value": { + "type": "Literal", + "start": 926, + "end": 927, + "loc": { + "start": { + "line": 61, + "column": 8 + }, + "end": { + "line": 61, + "column": 9 + } + }, + "value": 2, + "raw": "2" + }, + "kind": "init" + } + ] + } + ] + }, + "kind": "init" + } + ] + } + ], + "optional": false + }, + "leadingComments": [ + { + "type": "Line", + "value": " nested inside a call argument", + "start": 832, + "end": 864 + } + ] + }, + { + "type": "VariableDeclaration", + "start": 1020, + "end": 1082, + "loc": { + "start": { + "line": 66, + "column": 1 + }, + "end": { + "line": 70, + "column": 3 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 1026, + "end": 1081, + "loc": { + "start": { + "line": 66, + "column": 7 + }, + "end": { + "line": 70, + "column": 2 + } + }, + "id": { + "type": "Identifier", + "start": 1026, + "end": 1027, + "loc": { + "start": { + "line": 66, + "column": 7 + }, + "end": { + "line": 66, + "column": 8 + } + }, + "name": "i" + }, + "init": { + "type": "ArrayExpression", + "start": 1030, + "end": 1081, + "loc": { + "start": { + "line": 66, + "column": 11 + }, + "end": { + "line": 70, + "column": 2 + } + }, + "elements": [ + { + "type": "ObjectExpression", + "start": 1063, + "end": 1073, + "loc": { + "start": { + "line": 68, + "column": 10 + }, + "end": { + "line": 68, + "column": 20 + } + }, + "properties": [ + { + "type": "Property", + "start": 1065, + "end": 1071, + "loc": { + "start": { + "line": 68, + "column": 12 + }, + "end": { + "line": 68, + "column": 18 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 1065, + "end": 1066, + "loc": { + "start": { + "line": 68, + "column": 12 + }, + "end": { + "line": 68, + "column": 13 + } + }, + "name": "a" + }, + "value": { + "type": "Literal", + "start": 1070, + "end": 1071, + "loc": { + "start": { + "line": 68, + "column": 17 + }, + "end": { + "line": 68, + "column": 18 + } + }, + "value": 1, + "raw": "1" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 1034, + "end": 1052 + }, + { + "type": "Block", + "value": " c ", + "start": 1055, + "end": 1062 + } + ] + }, + { + "type": "Identifier", + "start": 1077, + "end": 1078, + "loc": { + "start": { + "line": 69, + "column": 2 + }, + "end": { + "line": 69, + "column": 3 + } + }, + "name": "b" + } + ] + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "Line", + "value": " a block comment glued before a frozen element is owned by it and stays put", + "start": 941, + "end": 1018 + } + ] + }, + { + "type": "VariableDeclaration", + "start": 1162, + "end": 1214, + "loc": { + "start": { + "line": 73, + "column": 1 + }, + "end": { + "line": 77, + "column": 3 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 1168, + "end": 1213, + "loc": { + "start": { + "line": 73, + "column": 7 + }, + "end": { + "line": 77, + "column": 2 + } + }, + "id": { + "type": "Identifier", + "start": 1168, + "end": 1169, + "loc": { + "start": { + "line": 73, + "column": 7 + }, + "end": { + "line": 73, + "column": 8 + } + }, + "name": "j" + }, + "init": { + "type": "ArrayExpression", + "start": 1172, + "end": 1213, + "loc": { + "start": { + "line": 73, + "column": 11 + }, + "end": { + "line": 77, + "column": 2 + } + }, + "elements": [ + { + "type": "SequenceExpression", + "start": 1198, + "end": 1204, + "loc": { + "start": { + "line": 75, + "column": 3 + }, + "end": { + "line": 75, + "column": 9 + } + }, + "expressions": [ + { + "type": "Literal", + "start": 1198, + "end": 1199, + "loc": { + "start": { + "line": 75, + "column": 3 + }, + "end": { + "line": 75, + "column": 4 + } + }, + "value": 0, + "raw": "0" + }, + { + "type": "Literal", + "start": 1203, + "end": 1204, + "loc": { + "start": { + "line": 75, + "column": 8 + }, + "end": { + "line": 75, + "column": 9 + } + }, + "value": 1, + "raw": "1" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 1176, + "end": 1194 + } + ] + }, + { + "type": "Identifier", + "start": 1209, + "end": 1210, + "loc": { + "start": { + "line": 76, + "column": 2 + }, + "end": { + "line": 76, + "column": 3 + } + }, + "name": "b" + } + ] + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "Line", + "value": " a sequence element keeps its own grouping parens around the frozen slice", + "start": 1085, + "end": 1160 + } + ] + } + ], + "sourceType": "module" + }, + "attributes": [ + { + "type": "Attribute", + "start": 8, + "end": 17, + "name": "lang", + "name_loc": { + "start": { + "line": 1, + "column": 8, + "character": 8 + }, + "end": { + "line": 1, + "column": 12, + "character": 12 + } + }, + "value": [ + { + "start": 14, + "end": 16, + "type": "Text", + "raw": "ts", + "data": "ts" + } + ] + } + ] + } +} diff --git a/tests/fixtures/typescript/expressions/arrays/elements_prettier_ignore_member/input.svelte b/tests/fixtures/typescript/expressions/arrays/elements_prettier_ignore_member/input.svelte new file mode 100644 index 000000000..5f07bd3d0 --- /dev/null +++ b/tests/fixtures/typescript/expressions/arrays/elements_prettier_ignore_member/input.svelte @@ -0,0 +1,78 @@ + diff --git a/tests/fixtures/typescript/expressions/arrays/elements_prettier_ignore_member/unformatted_spaces.svelte b/tests/fixtures/typescript/expressions/arrays/elements_prettier_ignore_member/unformatted_spaces.svelte new file mode 100644 index 000000000..1e8eedd42 --- /dev/null +++ b/tests/fixtures/typescript/expressions/arrays/elements_prettier_ignore_member/unformatted_spaces.svelte @@ -0,0 +1,78 @@ + diff --git a/tests/fixtures/typescript/expressions/calls/args_prettier_ignore_member/expected.json b/tests/fixtures/typescript/expressions/calls/args_prettier_ignore_member/expected.json new file mode 100644 index 000000000..7791d39d6 --- /dev/null +++ b/tests/fixtures/typescript/expressions/calls/args_prettier_ignore_member/expected.json @@ -0,0 +1,2893 @@ +{ + "css": null, + "js": [], + "start": 0, + "end": 1952, + "type": "Root", + "fragment": { + "type": "Fragment", + "nodes": [] + }, + "options": null, + "comments": [ + { + "type": "Line", + "value": " an own-line directive in an argument gap freezes only the following argument;", + "start": 20, + "end": 100, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 81 + } + } + }, + { + "type": "Line", + "value": " the list stays broken one argument per line", + "start": 102, + "end": 148, + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 47 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 168, + "end": 186, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " before the first argument: freezes that argument (Rule A — first like every)", + "start": 218, + "end": 297, + "loc": { + "start": { + "line": 11, + "column": 1 + }, + "end": { + "line": 11, + "column": 80 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 305, + "end": 323, + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " an own-line block comment behaves identically — placement keys the freeze, not the spelling", + "start": 355, + "end": 449, + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 95 + } + } + }, + { + "type": "Block", + "value": " prettier-ignore ", + "start": 457, + "end": 478, + "loc": { + "start": { + "line": 20, + "column": 2 + }, + "end": { + "line": 20, + "column": 23 + } + } + }, + { + "type": "Line", + "value": " a lone argument freezes too, and never hugs: a hug would pull the directive off its line", + "start": 510, + "end": 601, + "loc": { + "start": { + "line": 25, + "column": 1 + }, + "end": { + "line": 25, + "column": 92 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 609, + "end": 627, + "loc": { + "start": { + "line": 27, + "column": 2 + }, + "end": { + "line": 27, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " two arrow arguments take the always-expand layout", + "start": 647, + "end": 699, + "loc": { + "start": { + "line": 31, + "column": 1 + }, + "end": { + "line": 31, + "column": 53 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 707, + "end": 725, + "loc": { + "start": { + "line": 33, + "column": 2 + }, + "end": { + "line": 33, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " a callback-bearing argument takes the function-composition layout", + "start": 759, + "end": 827, + "loc": { + "start": { + "line": 38, + "column": 1 + }, + "end": { + "line": 38, + "column": 69 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 835, + "end": 853, + "loc": { + "start": { + "line": 40, + "column": 2 + }, + "end": { + "line": 40, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " an argument with multiline content takes the forced-expansion layout", + "start": 890, + "end": 961, + "loc": { + "start": { + "line": 45, + "column": 1 + }, + "end": { + "line": 45, + "column": 72 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 969, + "end": 987, + "loc": { + "start": { + "line": 47, + "column": 2 + }, + "end": { + "line": 47, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " a spread rides inside the frozen slice", + "start": 1017, + "end": 1058, + "loc": { + "start": { + "line": 53, + "column": 1 + }, + "end": { + "line": 53, + "column": 42 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 1066, + "end": 1084, + "loc": { + "start": { + "line": 55, + "column": 2 + }, + "end": { + "line": 55, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " an assignment argument keeps its clarity parens around the frozen slice", + "start": 1111, + "end": 1185, + "loc": { + "start": { + "line": 60, + "column": 1 + }, + "end": { + "line": 60, + "column": 75 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 1193, + "end": 1211, + "loc": { + "start": { + "line": 62, + "column": 2 + }, + "end": { + "line": 62, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " an author blank line beside a frozen argument is preserved", + "start": 1239, + "end": 1300, + "loc": { + "start": { + "line": 67, + "column": 1 + }, + "end": { + "line": 67, + "column": 62 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 1314, + "end": 1332, + "loc": { + "start": { + "line": 71, + "column": 2 + }, + "end": { + "line": 71, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " a multi-line frozen argument keeps its verbatim layout; the `,` is parent-owned", + "start": 1352, + "end": 1434, + "loc": { + "start": { + "line": 75, + "column": 1 + }, + "end": { + "line": 75, + "column": 83 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 1447, + "end": 1465, + "loc": { + "start": { + "line": 78, + "column": 2 + }, + "end": { + "line": 78, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " a block comment glued before a frozen argument is OWNED by it — it rides inside", + "start": 1505, + "end": 1587, + "loc": { + "start": { + "line": 86, + "column": 1 + }, + "end": { + "line": 86, + "column": 83 + } + } + }, + { + "type": "Line", + "value": " the argument's own doc, which the frozen slice replaces, so the freeze claims it", + "start": 1589, + "end": 1672, + "loc": { + "start": { + "line": 87, + "column": 1 + }, + "end": { + "line": 87, + "column": 84 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 1680, + "end": 1698, + "loc": { + "start": { + "line": 89, + "column": 2 + }, + "end": { + "line": 89, + "column": 20 + } + } + }, + { + "type": "Block", + "value": " c ", + "start": 1701, + "end": 1708, + "loc": { + "start": { + "line": 90, + "column": 2 + }, + "end": { + "line": 90, + "column": 9 + } + } + }, + { + "type": "Line", + "value": " a sequence expression prints its own grouping parens, and they are not part of its", + "start": 1731, + "end": 1816, + "loc": { + "start": { + "line": 94, + "column": 1 + }, + "end": { + "line": 94, + "column": 86 + } + } + }, + { + "type": "Line", + "value": " node span — the frozen slice re-synthesizes them or the call changes arity", + "start": 1818, + "end": 1895, + "loc": { + "start": { + "line": 95, + "column": 1 + }, + "end": { + "line": 95, + "column": 78 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 1903, + "end": 1921, + "loc": { + "start": { + "line": 97, + "column": 2 + }, + "end": { + "line": 97, + "column": 20 + } + } + } + ], + "instance": { + "type": "Script", + "start": 0, + "end": 1951, + "context": "default", + "content": { + "type": "Program", + "start": 18, + "end": 1942, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 101, + "column": 9 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 150, + "end": 215, + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 9, + "column": 3 + } + }, + "expression": { + "type": "CallExpression", + "start": 150, + "end": 214, + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 9, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 150, + "end": 152, + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "name": "fn" + }, + "arguments": [ + { + "type": "ObjectExpression", + "start": 156, + "end": 164, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "properties": [ + { + "type": "Property", + "start": 158, + "end": 162, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 8 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 158, + "end": 159, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 5 + } + }, + "name": "a" + }, + "value": { + "type": "Literal", + "start": 161, + "end": 162, + "loc": { + "start": { + "line": 5, + "column": 7 + }, + "end": { + "line": 5, + "column": 8 + } + }, + "value": 1, + "raw": "1" + }, + "kind": "init" + } + ] + }, + { + "type": "ObjectExpression", + "start": 189, + "end": 199, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 12 + } + }, + "properties": [ + { + "type": "Property", + "start": 191, + "end": 197, + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 10 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 191, + "end": 192, + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 5 + } + }, + "name": "b" + }, + "value": { + "type": "Literal", + "start": 196, + "end": 197, + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 7, + "column": 10 + } + }, + "value": 2, + "raw": "2" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 168, + "end": 186 + } + ] + }, + { + "type": "ObjectExpression", + "start": 203, + "end": 211, + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 10 + } + }, + "properties": [ + { + "type": "Property", + "start": 205, + "end": 209, + "loc": { + "start": { + "line": 8, + "column": 4 + }, + "end": { + "line": 8, + "column": 8 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 205, + "end": 206, + "loc": { + "start": { + "line": 8, + "column": 4 + }, + "end": { + "line": 8, + "column": 5 + } + }, + "name": "c" + }, + "value": { + "type": "Literal", + "start": 208, + "end": 209, + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 8 + } + }, + "value": 3, + "raw": "3" + }, + "kind": "init" + } + ] + } + ], + "optional": false + }, + "leadingComments": [ + { + "type": "Line", + "value": " an own-line directive in an argument gap freezes only the following argument;", + "start": 20, + "end": 100 + }, + { + "type": "Line", + "value": " the list stays broken one argument per line", + "start": 102, + "end": 148 + } + ] + }, + { + "type": "ExpressionStatement", + "start": 299, + "end": 352, + "loc": { + "start": { + "line": 12, + "column": 1 + }, + "end": { + "line": 16, + "column": 3 + } + }, + "expression": { + "type": "CallExpression", + "start": 299, + "end": 351, + "loc": { + "start": { + "line": 12, + "column": 1 + }, + "end": { + "line": 16, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 299, + "end": 301, + "loc": { + "start": { + "line": 12, + "column": 1 + }, + "end": { + "line": 12, + "column": 3 + } + }, + "name": "fn" + }, + "arguments": [ + { + "type": "ObjectExpression", + "start": 326, + "end": 336, + "loc": { + "start": { + "line": 14, + "column": 2 + }, + "end": { + "line": 14, + "column": 12 + } + }, + "properties": [ + { + "type": "Property", + "start": 328, + "end": 334, + "loc": { + "start": { + "line": 14, + "column": 4 + }, + "end": { + "line": 14, + "column": 10 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 328, + "end": 329, + "loc": { + "start": { + "line": 14, + "column": 4 + }, + "end": { + "line": 14, + "column": 5 + } + }, + "name": "a" + }, + "value": { + "type": "Literal", + "start": 333, + "end": 334, + "loc": { + "start": { + "line": 14, + "column": 9 + }, + "end": { + "line": 14, + "column": 10 + } + }, + "value": 1, + "raw": "1" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 305, + "end": 323 + } + ] + }, + { + "type": "ObjectExpression", + "start": 340, + "end": 348, + "loc": { + "start": { + "line": 15, + "column": 2 + }, + "end": { + "line": 15, + "column": 10 + } + }, + "properties": [ + { + "type": "Property", + "start": 342, + "end": 346, + "loc": { + "start": { + "line": 15, + "column": 4 + }, + "end": { + "line": 15, + "column": 8 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 342, + "end": 343, + "loc": { + "start": { + "line": 15, + "column": 4 + }, + "end": { + "line": 15, + "column": 5 + } + }, + "name": "b" + }, + "value": { + "type": "Literal", + "start": 345, + "end": 346, + "loc": { + "start": { + "line": 15, + "column": 7 + }, + "end": { + "line": 15, + "column": 8 + } + }, + "value": 2, + "raw": "2" + }, + "kind": "init" + } + ] + } + ], + "optional": false + }, + "leadingComments": [ + { + "type": "Line", + "value": " before the first argument: freezes that argument (Rule A — first like every)", + "start": 218, + "end": 297 + } + ] + }, + { + "type": "ExpressionStatement", + "start": 451, + "end": 507, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 23, + "column": 3 + } + }, + "expression": { + "type": "CallExpression", + "start": 451, + "end": 506, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 23, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 451, + "end": 453, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 3 + } + }, + "name": "fn" + }, + "arguments": [ + { + "type": "ObjectExpression", + "start": 481, + "end": 491, + "loc": { + "start": { + "line": 21, + "column": 2 + }, + "end": { + "line": 21, + "column": 12 + } + }, + "properties": [ + { + "type": "Property", + "start": 483, + "end": 489, + "loc": { + "start": { + "line": 21, + "column": 4 + }, + "end": { + "line": 21, + "column": 10 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 483, + "end": 484, + "loc": { + "start": { + "line": 21, + "column": 4 + }, + "end": { + "line": 21, + "column": 5 + } + }, + "name": "a" + }, + "value": { + "type": "Literal", + "start": 488, + "end": 489, + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 21, + "column": 10 + } + }, + "value": 1, + "raw": "1" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Block", + "value": " prettier-ignore ", + "start": 457, + "end": 478 + } + ] + }, + { + "type": "ObjectExpression", + "start": 495, + "end": 503, + "loc": { + "start": { + "line": 22, + "column": 2 + }, + "end": { + "line": 22, + "column": 10 + } + }, + "properties": [ + { + "type": "Property", + "start": 497, + "end": 501, + "loc": { + "start": { + "line": 22, + "column": 4 + }, + "end": { + "line": 22, + "column": 8 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 497, + "end": 498, + "loc": { + "start": { + "line": 22, + "column": 4 + }, + "end": { + "line": 22, + "column": 5 + } + }, + "name": "b" + }, + "value": { + "type": "Literal", + "start": 500, + "end": 501, + "loc": { + "start": { + "line": 22, + "column": 7 + }, + "end": { + "line": 22, + "column": 8 + } + }, + "value": 2, + "raw": "2" + }, + "kind": "init" + } + ] + } + ], + "optional": false + }, + "leadingComments": [ + { + "type": "Line", + "value": " an own-line block comment behaves identically — placement keys the freeze, not the spelling", + "start": 355, + "end": 449 + } + ] + }, + { + "type": "ExpressionStatement", + "start": 603, + "end": 644, + "loc": { + "start": { + "line": 26, + "column": 1 + }, + "end": { + "line": 29, + "column": 3 + } + }, + "expression": { + "type": "CallExpression", + "start": 603, + "end": 643, + "loc": { + "start": { + "line": 26, + "column": 1 + }, + "end": { + "line": 29, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 603, + "end": 605, + "loc": { + "start": { + "line": 26, + "column": 1 + }, + "end": { + "line": 26, + "column": 3 + } + }, + "name": "fn" + }, + "arguments": [ + { + "type": "ObjectExpression", + "start": 630, + "end": 640, + "loc": { + "start": { + "line": 28, + "column": 2 + }, + "end": { + "line": 28, + "column": 12 + } + }, + "properties": [ + { + "type": "Property", + "start": 632, + "end": 638, + "loc": { + "start": { + "line": 28, + "column": 4 + }, + "end": { + "line": 28, + "column": 10 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 632, + "end": 633, + "loc": { + "start": { + "line": 28, + "column": 4 + }, + "end": { + "line": 28, + "column": 5 + } + }, + "name": "a" + }, + "value": { + "type": "Literal", + "start": 637, + "end": 638, + "loc": { + "start": { + "line": 28, + "column": 9 + }, + "end": { + "line": 28, + "column": 10 + } + }, + "value": 1, + "raw": "1" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 609, + "end": 627 + } + ] + } + ], + "optional": false + }, + "leadingComments": [ + { + "type": "Line", + "value": " a lone argument freezes too, and never hugs: a hug would pull the directive off its line", + "start": 510, + "end": 601 + } + ] + }, + { + "type": "ExpressionStatement", + "start": 701, + "end": 756, + "loc": { + "start": { + "line": 32, + "column": 1 + }, + "end": { + "line": 36, + "column": 3 + } + }, + "expression": { + "type": "CallExpression", + "start": 701, + "end": 755, + "loc": { + "start": { + "line": 32, + "column": 1 + }, + "end": { + "line": 36, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 701, + "end": 703, + "loc": { + "start": { + "line": 32, + "column": 1 + }, + "end": { + "line": 32, + "column": 3 + } + }, + "name": "fn" + }, + "arguments": [ + { + "type": "ArrowFunctionExpression", + "start": 728, + "end": 741, + "loc": { + "start": { + "line": 34, + "column": 2 + }, + "end": { + "line": 34, + "column": 15 + } + }, + "id": null, + "expression": true, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BinaryExpression", + "start": 734, + "end": 741, + "loc": { + "start": { + "line": 34, + "column": 8 + }, + "end": { + "line": 34, + "column": 15 + } + }, + "left": { + "type": "Identifier", + "start": 734, + "end": 735, + "loc": { + "start": { + "line": 34, + "column": 8 + }, + "end": { + "line": 34, + "column": 9 + } + }, + "name": "a" + }, + "operator": "+", + "right": { + "type": "Identifier", + "start": 740, + "end": 741, + "loc": { + "start": { + "line": 34, + "column": 14 + }, + "end": { + "line": 34, + "column": 15 + } + }, + "name": "b" + } + }, + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 707, + "end": 725 + } + ] + }, + { + "type": "ArrowFunctionExpression", + "start": 745, + "end": 752, + "loc": { + "start": { + "line": 35, + "column": 2 + }, + "end": { + "line": 35, + "column": 9 + } + }, + "id": null, + "expression": true, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "Identifier", + "start": 751, + "end": 752, + "loc": { + "start": { + "line": 35, + "column": 8 + }, + "end": { + "line": 35, + "column": 9 + } + }, + "name": "c" + } + } + ], + "optional": false + }, + "leadingComments": [ + { + "type": "Line", + "value": " two arrow arguments take the always-expand layout", + "start": 647, + "end": 699 + } + ] + }, + { + "type": "ExpressionStatement", + "start": 829, + "end": 887, + "loc": { + "start": { + "line": 39, + "column": 1 + }, + "end": { + "line": 43, + "column": 3 + } + }, + "expression": { + "type": "CallExpression", + "start": 829, + "end": 886, + "loc": { + "start": { + "line": 39, + "column": 1 + }, + "end": { + "line": 43, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 829, + "end": 831, + "loc": { + "start": { + "line": 39, + "column": 1 + }, + "end": { + "line": 39, + "column": 3 + } + }, + "name": "fn" + }, + "arguments": [ + { + "type": "CallExpression", + "start": 856, + "end": 878, + "loc": { + "start": { + "line": 41, + "column": 2 + }, + "end": { + "line": 41, + "column": 24 + } + }, + "callee": { + "type": "MemberExpression", + "start": 856, + "end": 863, + "loc": { + "start": { + "line": 41, + "column": 2 + }, + "end": { + "line": 41, + "column": 9 + } + }, + "object": { + "type": "Identifier", + "start": 856, + "end": 859, + "loc": { + "start": { + "line": 41, + "column": 2 + }, + "end": { + "line": 41, + "column": 5 + } + }, + "name": "arr" + }, + "property": { + "type": "Identifier", + "start": 860, + "end": 863, + "loc": { + "start": { + "line": 41, + "column": 6 + }, + "end": { + "line": 41, + "column": 9 + } + }, + "name": "map" + }, + "computed": false, + "optional": false + }, + "arguments": [ + { + "type": "ArrowFunctionExpression", + "start": 864, + "end": 877, + "loc": { + "start": { + "line": 41, + "column": 10 + }, + "end": { + "line": 41, + "column": 23 + } + }, + "id": null, + "expression": true, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 865, + "end": 866, + "loc": { + "start": { + "line": 41, + "column": 11 + }, + "end": { + "line": 41, + "column": 12 + } + }, + "name": "x" + } + ], + "body": { + "type": "BinaryExpression", + "start": 871, + "end": 877, + "loc": { + "start": { + "line": 41, + "column": 17 + }, + "end": { + "line": 41, + "column": 23 + } + }, + "left": { + "type": "Identifier", + "start": 871, + "end": 872, + "loc": { + "start": { + "line": 41, + "column": 17 + }, + "end": { + "line": 41, + "column": 18 + } + }, + "name": "x" + }, + "operator": "+", + "right": { + "type": "Literal", + "start": 876, + "end": 877, + "loc": { + "start": { + "line": 41, + "column": 22 + }, + "end": { + "line": 41, + "column": 23 + } + }, + "value": 1, + "raw": "1" + } + } + } + ], + "optional": false, + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 835, + "end": 853 + } + ] + }, + { + "type": "Identifier", + "start": 882, + "end": 883, + "loc": { + "start": { + "line": 42, + "column": 2 + }, + "end": { + "line": 42, + "column": 3 + } + }, + "name": "b" + } + ], + "optional": false + }, + "leadingComments": [ + { + "type": "Line", + "value": " a callback-bearing argument takes the function-composition layout", + "start": 759, + "end": 827 + } + ] + }, + { + "type": "ExpressionStatement", + "start": 963, + "end": 1014, + "loc": { + "start": { + "line": 46, + "column": 1 + }, + "end": { + "line": 51, + "column": 3 + } + }, + "expression": { + "type": "CallExpression", + "start": 963, + "end": 1013, + "loc": { + "start": { + "line": 46, + "column": 1 + }, + "end": { + "line": 51, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 963, + "end": 965, + "loc": { + "start": { + "line": 46, + "column": 1 + }, + "end": { + "line": 46, + "column": 3 + } + }, + "name": "fn" + }, + "arguments": [ + { + "type": "ObjectExpression", + "start": 990, + "end": 1000, + "loc": { + "start": { + "line": 48, + "column": 2 + }, + "end": { + "line": 48, + "column": 12 + } + }, + "properties": [ + { + "type": "Property", + "start": 992, + "end": 998, + "loc": { + "start": { + "line": 48, + "column": 4 + }, + "end": { + "line": 48, + "column": 10 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 992, + "end": 993, + "loc": { + "start": { + "line": 48, + "column": 4 + }, + "end": { + "line": 48, + "column": 5 + } + }, + "name": "a" + }, + "value": { + "type": "Literal", + "start": 997, + "end": 998, + "loc": { + "start": { + "line": 48, + "column": 9 + }, + "end": { + "line": 48, + "column": 10 + } + }, + "value": 1, + "raw": "1" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 969, + "end": 987 + } + ] + }, + { + "type": "Literal", + "start": 1004, + "end": 1010, + "loc": { + "start": { + "line": 49, + "column": 2 + }, + "end": { + "line": 50, + "column": 2 + } + }, + "value": "ab", + "raw": "'a\\\nb'" + } + ], + "optional": false + }, + "leadingComments": [ + { + "type": "Line", + "value": " an argument with multiline content takes the forced-expansion layout", + "start": 890, + "end": 961 + } + ] + }, + { + "type": "ExpressionStatement", + "start": 1060, + "end": 1108, + "loc": { + "start": { + "line": 54, + "column": 1 + }, + "end": { + "line": 58, + "column": 3 + } + }, + "expression": { + "type": "CallExpression", + "start": 1060, + "end": 1107, + "loc": { + "start": { + "line": 54, + "column": 1 + }, + "end": { + "line": 58, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 1060, + "end": 1062, + "loc": { + "start": { + "line": 54, + "column": 1 + }, + "end": { + "line": 54, + "column": 3 + } + }, + "name": "fn" + }, + "arguments": [ + { + "type": "SpreadElement", + "start": 1087, + "end": 1099, + "loc": { + "start": { + "line": 56, + "column": 2 + }, + "end": { + "line": 56, + "column": 14 + } + }, + "argument": { + "type": "MemberExpression", + "start": 1092, + "end": 1099, + "loc": { + "start": { + "line": 56, + "column": 7 + }, + "end": { + "line": 56, + "column": 14 + } + }, + "object": { + "type": "Identifier", + "start": 1092, + "end": 1093, + "loc": { + "start": { + "line": 56, + "column": 7 + }, + "end": { + "line": 56, + "column": 8 + } + }, + "name": "a" + }, + "property": { + "type": "Identifier", + "start": 1098, + "end": 1099, + "loc": { + "start": { + "line": 56, + "column": 13 + }, + "end": { + "line": 56, + "column": 14 + } + }, + "name": "b" + }, + "computed": false, + "optional": false + }, + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 1066, + "end": 1084 + } + ] + }, + { + "type": "Identifier", + "start": 1103, + "end": 1104, + "loc": { + "start": { + "line": 57, + "column": 2 + }, + "end": { + "line": 57, + "column": 3 + } + }, + "name": "c" + } + ], + "optional": false + }, + "leadingComments": [ + { + "type": "Line", + "value": " a spread rides inside the frozen slice", + "start": 1017, + "end": 1058 + } + ] + }, + { + "type": "ExpressionStatement", + "start": 1187, + "end": 1236, + "loc": { + "start": { + "line": 61, + "column": 1 + }, + "end": { + "line": 65, + "column": 3 + } + }, + "expression": { + "type": "CallExpression", + "start": 1187, + "end": 1235, + "loc": { + "start": { + "line": 61, + "column": 1 + }, + "end": { + "line": 65, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 1187, + "end": 1189, + "loc": { + "start": { + "line": 61, + "column": 1 + }, + "end": { + "line": 61, + "column": 3 + } + }, + "name": "fn" + }, + "arguments": [ + { + "type": "AssignmentExpression", + "start": 1215, + "end": 1226, + "loc": { + "start": { + "line": 63, + "column": 3 + }, + "end": { + "line": 63, + "column": 14 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 1215, + "end": 1216, + "loc": { + "start": { + "line": 63, + "column": 3 + }, + "end": { + "line": 63, + "column": 4 + } + }, + "name": "a" + }, + "right": { + "type": "BinaryExpression", + "start": 1219, + "end": 1226, + "loc": { + "start": { + "line": 63, + "column": 7 + }, + "end": { + "line": 63, + "column": 14 + } + }, + "left": { + "type": "Identifier", + "start": 1219, + "end": 1220, + "loc": { + "start": { + "line": 63, + "column": 7 + }, + "end": { + "line": 63, + "column": 8 + } + }, + "name": "b" + }, + "operator": "+", + "right": { + "type": "Identifier", + "start": 1225, + "end": 1226, + "loc": { + "start": { + "line": 63, + "column": 13 + }, + "end": { + "line": 63, + "column": 14 + } + }, + "name": "c" + } + }, + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 1193, + "end": 1211 + } + ] + }, + { + "type": "Identifier", + "start": 1231, + "end": 1232, + "loc": { + "start": { + "line": 64, + "column": 2 + }, + "end": { + "line": 64, + "column": 3 + } + }, + "name": "d" + } + ], + "optional": false + }, + "leadingComments": [ + { + "type": "Line", + "value": " an assignment argument keeps its clarity parens around the frozen slice", + "start": 1111, + "end": 1185 + } + ] + }, + { + "type": "ExpressionStatement", + "start": 1302, + "end": 1349, + "loc": { + "start": { + "line": 68, + "column": 1 + }, + "end": { + "line": 73, + "column": 3 + } + }, + "expression": { + "type": "CallExpression", + "start": 1302, + "end": 1348, + "loc": { + "start": { + "line": 68, + "column": 1 + }, + "end": { + "line": 73, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 1302, + "end": 1304, + "loc": { + "start": { + "line": 68, + "column": 1 + }, + "end": { + "line": 68, + "column": 3 + } + }, + "name": "fn" + }, + "arguments": [ + { + "type": "Identifier", + "start": 1308, + "end": 1309, + "loc": { + "start": { + "line": 69, + "column": 2 + }, + "end": { + "line": 69, + "column": 3 + } + }, + "name": "a" + }, + { + "type": "ObjectExpression", + "start": 1335, + "end": 1345, + "loc": { + "start": { + "line": 72, + "column": 2 + }, + "end": { + "line": 72, + "column": 12 + } + }, + "properties": [ + { + "type": "Property", + "start": 1337, + "end": 1343, + "loc": { + "start": { + "line": 72, + "column": 4 + }, + "end": { + "line": 72, + "column": 10 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 1337, + "end": 1338, + "loc": { + "start": { + "line": 72, + "column": 4 + }, + "end": { + "line": 72, + "column": 5 + } + }, + "name": "b" + }, + "value": { + "type": "Literal", + "start": 1342, + "end": 1343, + "loc": { + "start": { + "line": 72, + "column": 9 + }, + "end": { + "line": 72, + "column": 10 + } + }, + "value": 2, + "raw": "2" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 1314, + "end": 1332 + } + ] + } + ], + "optional": false + }, + "leadingComments": [ + { + "type": "Line", + "value": " an author blank line beside a frozen argument is preserved", + "start": 1239, + "end": 1300 + } + ] + }, + { + "type": "ExpressionStatement", + "start": 1436, + "end": 1502, + "loc": { + "start": { + "line": 76, + "column": 1 + }, + "end": { + "line": 84, + "column": 3 + } + }, + "expression": { + "type": "CallExpression", + "start": 1436, + "end": 1501, + "loc": { + "start": { + "line": 76, + "column": 1 + }, + "end": { + "line": 84, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 1436, + "end": 1438, + "loc": { + "start": { + "line": 76, + "column": 1 + }, + "end": { + "line": 76, + "column": 3 + } + }, + "name": "fn" + }, + "arguments": [ + { + "type": "Identifier", + "start": 1442, + "end": 1443, + "loc": { + "start": { + "line": 77, + "column": 2 + }, + "end": { + "line": 77, + "column": 3 + } + }, + "name": "a" + }, + { + "type": "ObjectExpression", + "start": 1468, + "end": 1493, + "loc": { + "start": { + "line": 79, + "column": 2 + }, + "end": { + "line": 82, + "column": 3 + } + }, + "properties": [ + { + "type": "Property", + "start": 1473, + "end": 1479, + "loc": { + "start": { + "line": 80, + "column": 3 + }, + "end": { + "line": 80, + "column": 9 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 1473, + "end": 1474, + "loc": { + "start": { + "line": 80, + "column": 3 + }, + "end": { + "line": 80, + "column": 4 + } + }, + "name": "b" + }, + "value": { + "type": "Literal", + "start": 1478, + "end": 1479, + "loc": { + "start": { + "line": 80, + "column": 8 + }, + "end": { + "line": 80, + "column": 9 + } + }, + "value": 2, + "raw": "2" + }, + "kind": "init" + }, + { + "type": "Property", + "start": 1485, + "end": 1489, + "loc": { + "start": { + "line": 81, + "column": 4 + }, + "end": { + "line": 81, + "column": 8 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 1485, + "end": 1486, + "loc": { + "start": { + "line": 81, + "column": 4 + }, + "end": { + "line": 81, + "column": 5 + } + }, + "name": "c" + }, + "value": { + "type": "Literal", + "start": 1488, + "end": 1489, + "loc": { + "start": { + "line": 81, + "column": 7 + }, + "end": { + "line": 81, + "column": 8 + } + }, + "value": 3, + "raw": "3" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 1447, + "end": 1465 + } + ] + }, + { + "type": "Identifier", + "start": 1497, + "end": 1498, + "loc": { + "start": { + "line": 83, + "column": 2 + }, + "end": { + "line": 83, + "column": 3 + } + }, + "name": "d" + } + ], + "optional": false + }, + "leadingComments": [ + { + "type": "Line", + "value": " a multi-line frozen argument keeps its verbatim layout; the `,` is parent-owned", + "start": 1352, + "end": 1434 + } + ] + }, + { + "type": "ExpressionStatement", + "start": 1674, + "end": 1728, + "loc": { + "start": { + "line": 88, + "column": 1 + }, + "end": { + "line": 92, + "column": 3 + } + }, + "expression": { + "type": "CallExpression", + "start": 1674, + "end": 1727, + "loc": { + "start": { + "line": 88, + "column": 1 + }, + "end": { + "line": 92, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 1674, + "end": 1676, + "loc": { + "start": { + "line": 88, + "column": 1 + }, + "end": { + "line": 88, + "column": 3 + } + }, + "name": "fn" + }, + "arguments": [ + { + "type": "ObjectExpression", + "start": 1709, + "end": 1719, + "loc": { + "start": { + "line": 90, + "column": 10 + }, + "end": { + "line": 90, + "column": 20 + } + }, + "properties": [ + { + "type": "Property", + "start": 1711, + "end": 1717, + "loc": { + "start": { + "line": 90, + "column": 12 + }, + "end": { + "line": 90, + "column": 18 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 1711, + "end": 1712, + "loc": { + "start": { + "line": 90, + "column": 12 + }, + "end": { + "line": 90, + "column": 13 + } + }, + "name": "a" + }, + "value": { + "type": "Literal", + "start": 1716, + "end": 1717, + "loc": { + "start": { + "line": 90, + "column": 17 + }, + "end": { + "line": 90, + "column": 18 + } + }, + "value": 1, + "raw": "1" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 1680, + "end": 1698 + }, + { + "type": "Block", + "value": " c ", + "start": 1701, + "end": 1708 + } + ] + }, + { + "type": "Identifier", + "start": 1723, + "end": 1724, + "loc": { + "start": { + "line": 91, + "column": 2 + }, + "end": { + "line": 91, + "column": 3 + } + }, + "name": "b" + } + ], + "optional": false + }, + "leadingComments": [ + { + "type": "Line", + "value": " a block comment glued before a frozen argument is OWNED by it — it rides inside", + "start": 1505, + "end": 1587 + }, + { + "type": "Line", + "value": " the argument's own doc, which the frozen slice replaces, so the freeze claims it", + "start": 1589, + "end": 1672 + } + ] + }, + { + "type": "ExpressionStatement", + "start": 1897, + "end": 1941, + "loc": { + "start": { + "line": 96, + "column": 1 + }, + "end": { + "line": 100, + "column": 3 + } + }, + "expression": { + "type": "CallExpression", + "start": 1897, + "end": 1940, + "loc": { + "start": { + "line": 96, + "column": 1 + }, + "end": { + "line": 100, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 1897, + "end": 1899, + "loc": { + "start": { + "line": 96, + "column": 1 + }, + "end": { + "line": 96, + "column": 3 + } + }, + "name": "fn" + }, + "arguments": [ + { + "type": "SequenceExpression", + "start": 1925, + "end": 1931, + "loc": { + "start": { + "line": 98, + "column": 3 + }, + "end": { + "line": 98, + "column": 9 + } + }, + "expressions": [ + { + "type": "Literal", + "start": 1925, + "end": 1926, + "loc": { + "start": { + "line": 98, + "column": 3 + }, + "end": { + "line": 98, + "column": 4 + } + }, + "value": 0, + "raw": "0" + }, + { + "type": "Literal", + "start": 1930, + "end": 1931, + "loc": { + "start": { + "line": 98, + "column": 8 + }, + "end": { + "line": 98, + "column": 9 + } + }, + "value": 1, + "raw": "1" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 1903, + "end": 1921 + } + ] + }, + { + "type": "Identifier", + "start": 1936, + "end": 1937, + "loc": { + "start": { + "line": 99, + "column": 2 + }, + "end": { + "line": 99, + "column": 3 + } + }, + "name": "b" + } + ], + "optional": false + }, + "leadingComments": [ + { + "type": "Line", + "value": " a sequence expression prints its own grouping parens, and they are not part of its", + "start": 1731, + "end": 1816 + }, + { + "type": "Line", + "value": " node span — the frozen slice re-synthesizes them or the call changes arity", + "start": 1818, + "end": 1895 + } + ] + } + ], + "sourceType": "module" + }, + "attributes": [ + { + "type": "Attribute", + "start": 8, + "end": 17, + "name": "lang", + "name_loc": { + "start": { + "line": 1, + "column": 8, + "character": 8 + }, + "end": { + "line": 1, + "column": 12, + "character": 12 + } + }, + "value": [ + { + "start": 14, + "end": 16, + "type": "Text", + "raw": "ts", + "data": "ts" + } + ] + } + ] + } +} diff --git a/tests/fixtures/typescript/expressions/calls/args_prettier_ignore_member/input.svelte b/tests/fixtures/typescript/expressions/calls/args_prettier_ignore_member/input.svelte new file mode 100644 index 000000000..722a4ffe7 --- /dev/null +++ b/tests/fixtures/typescript/expressions/calls/args_prettier_ignore_member/input.svelte @@ -0,0 +1,101 @@ + diff --git a/tests/fixtures/typescript/expressions/calls/args_prettier_ignore_member/unformatted_spaces.svelte b/tests/fixtures/typescript/expressions/calls/args_prettier_ignore_member/unformatted_spaces.svelte new file mode 100644 index 000000000..22526a2cb --- /dev/null +++ b/tests/fixtures/typescript/expressions/calls/args_prettier_ignore_member/unformatted_spaces.svelte @@ -0,0 +1,101 @@ + diff --git a/tests/fixtures/typescript/expressions/calls/chained/args_prettier_ignore_member/expected.json b/tests/fixtures/typescript/expressions/calls/chained/args_prettier_ignore_member/expected.json new file mode 100644 index 000000000..5e9fa16d9 --- /dev/null +++ b/tests/fixtures/typescript/expressions/calls/chained/args_prettier_ignore_member/expected.json @@ -0,0 +1,1305 @@ +{ + "css": null, + "js": [], + "start": 0, + "end": 566, + "type": "Root", + "fragment": { + "type": "Fragment", + "nodes": [] + }, + "options": null, + "comments": [ + { + "type": "Line", + "value": " a member-chain call's arguments take the chain's forced-expansion layout", + "start": 20, + "end": 95, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 76 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 117, + "end": 135, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " an inter-argument directive in a chain call", + "start": 157, + "end": 203, + "loc": { + "start": { + "line": 8, + "column": 1 + }, + "end": { + "line": 8, + "column": 47 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 237, + "end": 255, + "loc": { + "start": { + "line": 11, + "column": 2 + }, + "end": { + "line": 11, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " a curried call — the second argument list is a chain call too", + "start": 277, + "end": 341, + "loc": { + "start": { + "line": 15, + "column": 1 + }, + "end": { + "line": 15, + "column": 65 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 351, + "end": 369, + "loc": { + "start": { + "line": 17, + "column": 2 + }, + "end": { + "line": 17, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " a broken chain keeps the frozen argument verbatim", + "start": 412, + "end": 464, + "loc": { + "start": { + "line": 24, + "column": 1 + }, + "end": { + "line": 24, + "column": 53 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 506, + "end": 524, + "loc": { + "start": { + "line": 28, + "column": 3 + }, + "end": { + "line": 28, + "column": 21 + } + } + } + ], + "instance": { + "type": "Script", + "start": 0, + "end": 565, + "context": "default", + "content": { + "type": "Program", + "start": 18, + "end": 556, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 32, + "column": 9 + } + }, + "body": [ + { + "type": "VariableDeclaration", + "start": 97, + "end": 154, + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 6, + "column": 5 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 103, + "end": 153, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 6, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 103, + "end": 104, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "name": "a" + }, + "init": { + "type": "MemberExpression", + "start": 107, + "end": 153, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 6, + "column": 4 + } + }, + "object": { + "type": "CallExpression", + "start": 107, + "end": 151, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "callee": { + "type": "MemberExpression", + "start": 107, + "end": 113, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "object": { + "type": "Identifier", + "start": 107, + "end": 110, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "name": "obj" + }, + "property": { + "type": "Identifier", + "start": 111, + "end": 113, + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "name": "fn" + }, + "computed": false, + "optional": false + }, + "arguments": [ + { + "type": "ObjectExpression", + "start": 138, + "end": 148, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 12 + } + }, + "properties": [ + { + "type": "Property", + "start": 140, + "end": 146, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 140, + "end": 141, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 5 + } + }, + "name": "a" + }, + "value": { + "type": "Literal", + "start": 145, + "end": 146, + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "value": 1, + "raw": "1" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 117, + "end": 135 + } + ] + } + ], + "optional": false + }, + "property": { + "type": "Identifier", + "start": 152, + "end": 153, + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 4 + } + }, + "name": "b" + }, + "computed": false, + "optional": false + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "Line", + "value": " a member-chain call's arguments take the chain's forced-expansion layout", + "start": 20, + "end": 95 + } + ] + }, + { + "type": "VariableDeclaration", + "start": 205, + "end": 274, + "loc": { + "start": { + "line": 9, + "column": 1 + }, + "end": { + "line": 13, + "column": 5 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 211, + "end": 273, + "loc": { + "start": { + "line": 9, + "column": 7 + }, + "end": { + "line": 13, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 211, + "end": 212, + "loc": { + "start": { + "line": 9, + "column": 7 + }, + "end": { + "line": 9, + "column": 8 + } + }, + "name": "b" + }, + "init": { + "type": "MemberExpression", + "start": 215, + "end": 273, + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 13, + "column": 4 + } + }, + "object": { + "type": "CallExpression", + "start": 215, + "end": 271, + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 13, + "column": 2 + } + }, + "callee": { + "type": "MemberExpression", + "start": 215, + "end": 221, + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 9, + "column": 17 + } + }, + "object": { + "type": "Identifier", + "start": 215, + "end": 218, + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 9, + "column": 14 + } + }, + "name": "obj" + }, + "property": { + "type": "Identifier", + "start": 219, + "end": 221, + "loc": { + "start": { + "line": 9, + "column": 15 + }, + "end": { + "line": 9, + "column": 17 + } + }, + "name": "fn" + }, + "computed": false, + "optional": false + }, + "arguments": [ + { + "type": "ObjectExpression", + "start": 225, + "end": 233, + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 10, + "column": 10 + } + }, + "properties": [ + { + "type": "Property", + "start": 227, + "end": 231, + "loc": { + "start": { + "line": 10, + "column": 4 + }, + "end": { + "line": 10, + "column": 8 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 227, + "end": 228, + "loc": { + "start": { + "line": 10, + "column": 4 + }, + "end": { + "line": 10, + "column": 5 + } + }, + "name": "a" + }, + "value": { + "type": "Literal", + "start": 230, + "end": 231, + "loc": { + "start": { + "line": 10, + "column": 7 + }, + "end": { + "line": 10, + "column": 8 + } + }, + "value": 1, + "raw": "1" + }, + "kind": "init" + } + ] + }, + { + "type": "ObjectExpression", + "start": 258, + "end": 268, + "loc": { + "start": { + "line": 12, + "column": 2 + }, + "end": { + "line": 12, + "column": 12 + } + }, + "properties": [ + { + "type": "Property", + "start": 260, + "end": 266, + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 10 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 260, + "end": 261, + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 5 + } + }, + "name": "b" + }, + "value": { + "type": "Literal", + "start": 265, + "end": 266, + "loc": { + "start": { + "line": 12, + "column": 9 + }, + "end": { + "line": 12, + "column": 10 + } + }, + "value": 2, + "raw": "2" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 237, + "end": 255 + } + ] + } + ], + "optional": false + }, + "property": { + "type": "Identifier", + "start": 272, + "end": 273, + "loc": { + "start": { + "line": 13, + "column": 3 + }, + "end": { + "line": 13, + "column": 4 + } + }, + "name": "c" + }, + "computed": false, + "optional": false + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "Line", + "value": " an inter-argument directive in a chain call", + "start": 157, + "end": 203 + } + ] + }, + { + "type": "ExpressionStatement", + "start": 343, + "end": 409, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 22, + "column": 3 + } + }, + "expression": { + "type": "CallExpression", + "start": 343, + "end": 408, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 22, + "column": 2 + } + }, + "callee": { + "type": "CallExpression", + "start": 343, + "end": 347, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 5 + } + }, + "callee": { + "type": "Identifier", + "start": 343, + "end": 345, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 3 + } + }, + "name": "fn" + }, + "arguments": [], + "optional": false + }, + "arguments": [ + { + "type": "ObjectExpression", + "start": 372, + "end": 382, + "loc": { + "start": { + "line": 18, + "column": 2 + }, + "end": { + "line": 18, + "column": 12 + } + }, + "properties": [ + { + "type": "Property", + "start": 374, + "end": 380, + "loc": { + "start": { + "line": 18, + "column": 4 + }, + "end": { + "line": 18, + "column": 10 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 374, + "end": 375, + "loc": { + "start": { + "line": 18, + "column": 4 + }, + "end": { + "line": 18, + "column": 5 + } + }, + "name": "a" + }, + "value": { + "type": "Literal", + "start": 379, + "end": 380, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 10 + } + }, + "value": 1, + "raw": "1" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 351, + "end": 369 + } + ] + }, + { + "type": "ArrowFunctionExpression", + "start": 386, + "end": 405, + "loc": { + "start": { + "line": 19, + "column": 2 + }, + "end": { + "line": 21, + "column": 3 + } + }, + "id": null, + "expression": false, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 392, + "end": 405, + "loc": { + "start": { + "line": 19, + "column": 8 + }, + "end": { + "line": 21, + "column": 3 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 397, + "end": 401, + "loc": { + "start": { + "line": 20, + "column": 3 + }, + "end": { + "line": 20, + "column": 7 + } + }, + "expression": { + "type": "CallExpression", + "start": 397, + "end": 400, + "loc": { + "start": { + "line": 20, + "column": 3 + }, + "end": { + "line": 20, + "column": 6 + } + }, + "callee": { + "type": "Identifier", + "start": 397, + "end": 398, + "loc": { + "start": { + "line": 20, + "column": 3 + }, + "end": { + "line": 20, + "column": 4 + } + }, + "name": "b" + }, + "arguments": [], + "optional": false + } + } + ] + } + } + ], + "optional": false + }, + "leadingComments": [ + { + "type": "Line", + "value": " a curried call — the second argument list is a chain call too", + "start": 277, + "end": 341 + } + ] + }, + { + "type": "VariableDeclaration", + "start": 466, + "end": 555, + "loc": { + "start": { + "line": 25, + "column": 1 + }, + "end": { + "line": 31, + "column": 12 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 472, + "end": 554, + "loc": { + "start": { + "line": 25, + "column": 7 + }, + "end": { + "line": 31, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 472, + "end": 473, + "loc": { + "start": { + "line": 25, + "column": 7 + }, + "end": { + "line": 25, + "column": 8 + } + }, + "name": "c" + }, + "init": { + "type": "CallExpression", + "start": 476, + "end": 554, + "loc": { + "start": { + "line": 25, + "column": 11 + }, + "end": { + "line": 31, + "column": 11 + } + }, + "callee": { + "type": "MemberExpression", + "start": 476, + "end": 551, + "loc": { + "start": { + "line": 25, + "column": 11 + }, + "end": { + "line": 31, + "column": 8 + } + }, + "object": { + "type": "CallExpression", + "start": 476, + "end": 542, + "loc": { + "start": { + "line": 25, + "column": 11 + }, + "end": { + "line": 30, + "column": 3 + } + }, + "callee": { + "type": "MemberExpression", + "start": 476, + "end": 501, + "loc": { + "start": { + "line": 25, + "column": 11 + }, + "end": { + "line": 27, + "column": 9 + } + }, + "object": { + "type": "CallExpression", + "start": 476, + "end": 491, + "loc": { + "start": { + "line": 25, + "column": 11 + }, + "end": { + "line": 26, + "column": 11 + } + }, + "callee": { + "type": "MemberExpression", + "start": 476, + "end": 488, + "loc": { + "start": { + "line": 25, + "column": 11 + }, + "end": { + "line": 26, + "column": 8 + } + }, + "object": { + "type": "Identifier", + "start": 476, + "end": 479, + "loc": { + "start": { + "line": 25, + "column": 11 + }, + "end": { + "line": 25, + "column": 14 + } + }, + "name": "obj" + }, + "property": { + "type": "Identifier", + "start": 483, + "end": 488, + "loc": { + "start": { + "line": 26, + "column": 3 + }, + "end": { + "line": 26, + "column": 8 + } + }, + "name": "first" + }, + "computed": false, + "optional": false + }, + "arguments": [ + { + "type": "Literal", + "start": 489, + "end": 490, + "loc": { + "start": { + "line": 26, + "column": 9 + }, + "end": { + "line": 26, + "column": 10 + } + }, + "value": 1, + "raw": "1" + } + ], + "optional": false + }, + "property": { + "type": "Identifier", + "start": 495, + "end": 501, + "loc": { + "start": { + "line": 27, + "column": 3 + }, + "end": { + "line": 27, + "column": 9 + } + }, + "name": "second" + }, + "computed": false, + "optional": false + }, + "arguments": [ + { + "type": "ObjectExpression", + "start": 528, + "end": 538, + "loc": { + "start": { + "line": 29, + "column": 3 + }, + "end": { + "line": 29, + "column": 13 + } + }, + "properties": [ + { + "type": "Property", + "start": 530, + "end": 536, + "loc": { + "start": { + "line": 29, + "column": 5 + }, + "end": { + "line": 29, + "column": 11 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 530, + "end": 531, + "loc": { + "start": { + "line": 29, + "column": 5 + }, + "end": { + "line": 29, + "column": 6 + } + }, + "name": "a" + }, + "value": { + "type": "Literal", + "start": 535, + "end": 536, + "loc": { + "start": { + "line": 29, + "column": 10 + }, + "end": { + "line": 29, + "column": 11 + } + }, + "value": 1, + "raw": "1" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 506, + "end": 524 + } + ] + } + ], + "optional": false + }, + "property": { + "type": "Identifier", + "start": 546, + "end": 551, + "loc": { + "start": { + "line": 31, + "column": 3 + }, + "end": { + "line": 31, + "column": 8 + } + }, + "name": "third" + }, + "computed": false, + "optional": false + }, + "arguments": [ + { + "type": "Literal", + "start": 552, + "end": 553, + "loc": { + "start": { + "line": 31, + "column": 9 + }, + "end": { + "line": 31, + "column": 10 + } + }, + "value": 3, + "raw": "3" + } + ], + "optional": false + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "Line", + "value": " a broken chain keeps the frozen argument verbatim", + "start": 412, + "end": 464 + } + ] + } + ], + "sourceType": "module" + }, + "attributes": [ + { + "type": "Attribute", + "start": 8, + "end": 17, + "name": "lang", + "name_loc": { + "start": { + "line": 1, + "column": 8, + "character": 8 + }, + "end": { + "line": 1, + "column": 12, + "character": 12 + } + }, + "value": [ + { + "start": 14, + "end": 16, + "type": "Text", + "raw": "ts", + "data": "ts" + } + ] + } + ] + } +} diff --git a/tests/fixtures/typescript/expressions/calls/chained/args_prettier_ignore_member/input.svelte b/tests/fixtures/typescript/expressions/calls/chained/args_prettier_ignore_member/input.svelte new file mode 100644 index 000000000..13da104b1 --- /dev/null +++ b/tests/fixtures/typescript/expressions/calls/chained/args_prettier_ignore_member/input.svelte @@ -0,0 +1,32 @@ + diff --git a/tests/fixtures/typescript/expressions/calls/chained/args_prettier_ignore_member/unformatted_spaces.svelte b/tests/fixtures/typescript/expressions/calls/chained/args_prettier_ignore_member/unformatted_spaces.svelte new file mode 100644 index 000000000..ba1c34802 --- /dev/null +++ b/tests/fixtures/typescript/expressions/calls/chained/args_prettier_ignore_member/unformatted_spaces.svelte @@ -0,0 +1,32 @@ + diff --git a/tests/fixtures/typescript/expressions/calls/import_args_prettier_ignore_member/expected.json b/tests/fixtures/typescript/expressions/calls/import_args_prettier_ignore_member/expected.json new file mode 100644 index 000000000..3a4e2b40b --- /dev/null +++ b/tests/fixtures/typescript/expressions/calls/import_args_prettier_ignore_member/expected.json @@ -0,0 +1,911 @@ +{ + "css": null, + "js": [], + "start": 0, + "end": 562, + "type": "Root", + "fragment": { + "type": "Fragment", + "nodes": [] + }, + "options": null, + "comments": [ + { + "type": "Line", + "value": " an own-line directive before the source argument freezes it", + "start": 20, + "end": 82, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 63 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 104, + "end": 122, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " with an options argument too", + "start": 146, + "end": 177, + "loc": { + "start": { + "line": 8, + "column": 1 + }, + "end": { + "line": 8, + "column": 32 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 199, + "end": 217, + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 10, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " an own-line directive in the source→options gap freezes the options argument", + "start": 249, + "end": 328, + "loc": { + "start": { + "line": 15, + "column": 1 + }, + "end": { + "line": 15, + "column": 80 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 359, + "end": 377, + "loc": { + "start": { + "line": 18, + "column": 2 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " an own-line block spelling freezes identically", + "start": 415, + "end": 464, + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 22, + "column": 50 + } + } + }, + { + "type": "Block", + "value": " prettier-ignore ", + "start": 495, + "end": 516, + "loc": { + "start": { + "line": 25, + "column": 2 + }, + "end": { + "line": 25, + "column": 23 + } + } + } + ], + "instance": { + "type": "Script", + "start": 0, + "end": 561, + "context": "default", + "content": { + "type": "Program", + "start": 18, + "end": 552, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 28, + "column": 9 + } + }, + "body": [ + { + "type": "VariableDeclaration", + "start": 84, + "end": 143, + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 90, + "end": 142, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "id": { + "type": "Identifier", + "start": 90, + "end": 91, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "name": "a" + }, + "init": { + "type": "ImportExpression", + "start": 94, + "end": 142, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "source": { + "type": "BinaryExpression", + "start": 125, + "end": 139, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 16 + } + }, + "left": { + "type": "Identifier", + "start": 125, + "end": 129, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 6 + } + }, + "name": "base" + }, + "operator": "+", + "right": { + "type": "Literal", + "start": 134, + "end": 139, + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 16 + } + }, + "value": "./a", + "raw": "'./a'" + }, + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 104, + "end": 122 + } + ] + } + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "Line", + "value": " an own-line directive before the source argument freezes it", + "start": 20, + "end": 82 + } + ] + }, + { + "type": "VariableDeclaration", + "start": 179, + "end": 246, + "loc": { + "start": { + "line": 9, + "column": 1 + }, + "end": { + "line": 13, + "column": 3 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 185, + "end": 245, + "loc": { + "start": { + "line": 9, + "column": 7 + }, + "end": { + "line": 13, + "column": 2 + } + }, + "id": { + "type": "Identifier", + "start": 185, + "end": 186, + "loc": { + "start": { + "line": 9, + "column": 7 + }, + "end": { + "line": 9, + "column": 8 + } + }, + "name": "b" + }, + "init": { + "type": "ImportExpression", + "start": 189, + "end": 245, + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 13, + "column": 2 + } + }, + "source": { + "type": "BinaryExpression", + "start": 220, + "end": 234, + "loc": { + "start": { + "line": 11, + "column": 2 + }, + "end": { + "line": 11, + "column": 16 + } + }, + "left": { + "type": "Identifier", + "start": 220, + "end": 224, + "loc": { + "start": { + "line": 11, + "column": 2 + }, + "end": { + "line": 11, + "column": 6 + } + }, + "name": "base" + }, + "operator": "+", + "right": { + "type": "Literal", + "start": 229, + "end": 234, + "loc": { + "start": { + "line": 11, + "column": 11 + }, + "end": { + "line": 11, + "column": 16 + } + }, + "value": "./a", + "raw": "'./a'" + }, + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 199, + "end": 217 + } + ] + }, + "arguments": [ + { + "type": "Identifier", + "start": 238, + "end": 242, + "loc": { + "start": { + "line": 12, + "column": 2 + }, + "end": { + "line": 12, + "column": 6 + } + }, + "name": "opts" + } + ] + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "Line", + "value": " with an options argument too", + "start": 146, + "end": 177 + } + ] + }, + { + "type": "VariableDeclaration", + "start": 330, + "end": 412, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 20, + "column": 3 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 336, + "end": 411, + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 20, + "column": 2 + } + }, + "id": { + "type": "Identifier", + "start": 336, + "end": 337, + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + }, + "name": "c" + }, + "init": { + "type": "ImportExpression", + "start": 340, + "end": 411, + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 20, + "column": 2 + } + }, + "source": { + "type": "Literal", + "start": 350, + "end": 355, + "loc": { + "start": { + "line": 17, + "column": 2 + }, + "end": { + "line": 17, + "column": 7 + } + }, + "value": "./a", + "raw": "'./a'" + }, + "arguments": [ + { + "type": "ObjectExpression", + "start": 380, + "end": 408, + "loc": { + "start": { + "line": 19, + "column": 2 + }, + "end": { + "line": 19, + "column": 30 + } + }, + "properties": [ + { + "type": "Property", + "start": 382, + "end": 406, + "loc": { + "start": { + "line": 19, + "column": 4 + }, + "end": { + "line": 19, + "column": 28 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 382, + "end": 386, + "loc": { + "start": { + "line": 19, + "column": 4 + }, + "end": { + "line": 19, + "column": 8 + } + }, + "name": "with" + }, + "value": { + "type": "ObjectExpression", + "start": 388, + "end": 406, + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 28 + } + }, + "properties": [ + { + "type": "Property", + "start": 390, + "end": 404, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 26 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 390, + "end": 394, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 16 + } + }, + "name": "type" + }, + "value": { + "type": "Literal", + "start": 398, + "end": 404, + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 26 + } + }, + "value": "json", + "raw": "'json'" + }, + "kind": "init" + } + ] + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 359, + "end": 377 + } + ] + } + ] + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "Line", + "value": " an own-line directive in the source→options gap freezes the options argument", + "start": 249, + "end": 328 + } + ] + }, + { + "type": "VariableDeclaration", + "start": 466, + "end": 551, + "loc": { + "start": { + "line": 23, + "column": 1 + }, + "end": { + "line": 27, + "column": 3 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 472, + "end": 550, + "loc": { + "start": { + "line": 23, + "column": 7 + }, + "end": { + "line": 27, + "column": 2 + } + }, + "id": { + "type": "Identifier", + "start": 472, + "end": 473, + "loc": { + "start": { + "line": 23, + "column": 7 + }, + "end": { + "line": 23, + "column": 8 + } + }, + "name": "d" + }, + "init": { + "type": "ImportExpression", + "start": 476, + "end": 550, + "loc": { + "start": { + "line": 23, + "column": 11 + }, + "end": { + "line": 27, + "column": 2 + } + }, + "source": { + "type": "Literal", + "start": 486, + "end": 491, + "loc": { + "start": { + "line": 24, + "column": 2 + }, + "end": { + "line": 24, + "column": 7 + } + }, + "value": "./a", + "raw": "'./a'" + }, + "arguments": [ + { + "type": "ObjectExpression", + "start": 519, + "end": 547, + "loc": { + "start": { + "line": 26, + "column": 2 + }, + "end": { + "line": 26, + "column": 30 + } + }, + "properties": [ + { + "type": "Property", + "start": 521, + "end": 545, + "loc": { + "start": { + "line": 26, + "column": 4 + }, + "end": { + "line": 26, + "column": 28 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 521, + "end": 525, + "loc": { + "start": { + "line": 26, + "column": 4 + }, + "end": { + "line": 26, + "column": 8 + } + }, + "name": "with" + }, + "value": { + "type": "ObjectExpression", + "start": 527, + "end": 545, + "loc": { + "start": { + "line": 26, + "column": 10 + }, + "end": { + "line": 26, + "column": 28 + } + }, + "properties": [ + { + "type": "Property", + "start": 529, + "end": 543, + "loc": { + "start": { + "line": 26, + "column": 12 + }, + "end": { + "line": 26, + "column": 26 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 529, + "end": 533, + "loc": { + "start": { + "line": 26, + "column": 12 + }, + "end": { + "line": 26, + "column": 16 + } + }, + "name": "type" + }, + "value": { + "type": "Literal", + "start": 537, + "end": 543, + "loc": { + "start": { + "line": 26, + "column": 20 + }, + "end": { + "line": 26, + "column": 26 + } + }, + "value": "json", + "raw": "'json'" + }, + "kind": "init" + } + ] + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Block", + "value": " prettier-ignore ", + "start": 495, + "end": 516 + } + ] + } + ] + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "Line", + "value": " an own-line block spelling freezes identically", + "start": 415, + "end": 464 + } + ] + } + ], + "sourceType": "module" + }, + "attributes": [ + { + "type": "Attribute", + "start": 8, + "end": 17, + "name": "lang", + "name_loc": { + "start": { + "line": 1, + "column": 8, + "character": 8 + }, + "end": { + "line": 1, + "column": 12, + "character": 12 + } + }, + "value": [ + { + "start": 14, + "end": 16, + "type": "Text", + "raw": "ts", + "data": "ts" + } + ] + } + ] + } +} diff --git a/tests/fixtures/typescript/expressions/calls/import_args_prettier_ignore_member/input.svelte b/tests/fixtures/typescript/expressions/calls/import_args_prettier_ignore_member/input.svelte new file mode 100644 index 000000000..9859c8fa3 --- /dev/null +++ b/tests/fixtures/typescript/expressions/calls/import_args_prettier_ignore_member/input.svelte @@ -0,0 +1,28 @@ + diff --git a/tests/fixtures/typescript/expressions/calls/import_args_prettier_ignore_member/unformatted_spaces.svelte b/tests/fixtures/typescript/expressions/calls/import_args_prettier_ignore_member/unformatted_spaces.svelte new file mode 100644 index 000000000..eff161675 --- /dev/null +++ b/tests/fixtures/typescript/expressions/calls/import_args_prettier_ignore_member/unformatted_spaces.svelte @@ -0,0 +1,28 @@ + diff --git a/tests/fixtures/typescript/expressions/calls/test_call_arg_comment_prettier_divergence/README.md b/tests/fixtures/typescript/expressions/calls/test_call_arg_comment_prettier_divergence/README.md new file mode 100644 index 000000000..c5d458cb7 --- /dev/null +++ b/tests/fixtures/typescript/expressions/calls/test_call_arg_comment_prettier_divergence/README.md @@ -0,0 +1,55 @@ +# test_call_arg_comment_prettier_divergence + +A test call (`it` / `test` / `describe` and friends) prints its arguments on one +flat line, however long they get. That layout has no argument-gap comment +emitter, so a comment in the leading gap (`it(⏎// c⏎'text', …)`) or an +inter-argument gap has nowhere to go. tsv gives up the flat layout for such a +call: it expands like any other call and every comment keeps the line the author +wrote it on. Prettier keeps the flat layout and relocates the comment onto the +`(` line (leading gap) or past the previous argument (inter-argument gap). + +tsv: the call expands, each comment stays on its own line +Prettier: the flat layout is kept and the comment is relocated onto a code line + +``` +// tsv // prettier +it( it(// c + // c 'text', () => { + 'text', a(); + () => { }); + a(); + } +); +``` + +## Reason + +Two independent reasons, either sufficient: + +1. **Content loss.** The flat layout emits only the argument docs joined with + `", "` plus a trailing-comment suffix after the last argument — the + hazard-4 shape from + [comments.md](../../../../../../docs/comments.md) (an alternate-layout + container builder that never runs a gap lookup). Every leading and + inter-argument gap comment was **dropped**. A layout that cannot print a + comment must not be selected for a document that has one. +2. **Comment position.** Prettier's relocated forms move a comment across a + syntactic boundary onto a code line, and its own second pass then keeps + drifting: an inter-argument comment migrates **into the callback body** + (`it('text', () => { // c`) on pass 2 and onto its own line inside that body + on pass 3 — the comment's association changes from "leads the callback + argument" to "first statement of the callback". `audit_signature.txt` pins the + chain. tsv's expanded form is a one-pass fixed point. + +A **glued** block comment is owned by the argument it precedes and rides inside +that argument's doc, so the flat layout can print it — that case keeps the flat +layout and matches prettier (a case in this fixture). Likewise a comment +trailing the whole call, which the flat layout emits itself. The gate is +therefore keyed on comments *to emit* in the gaps, the axis that answers +"would this comment be dropped here?". + +A format-ignore directive alone on its line in a gap freezes the following +argument here as everywhere else (Rule A) — see +[args_prettier_ignore_member](../args_prettier_ignore_member/). + +See [conformance_prettier.md](../../../../../../docs/conformance_prettier.md) §Comment relocation. diff --git a/tests/fixtures/typescript/expressions/calls/test_call_arg_comment_prettier_divergence/audit_signature.txt b/tests/fixtures/typescript/expressions/calls/test_call_arg_comment_prettier_divergence/audit_signature.txt new file mode 100644 index 000000000..78513bd62 --- /dev/null +++ b/tests/fixtures/typescript/expressions/calls/test_call_arg_comment_prettier_divergence/audit_signature.txt @@ -0,0 +1,86 @@ +# Auto-generated prettier chain signature. Do not edit manually. +# Regenerate: deno task fixtures:update:formatted +# +# Each %%PASS=N%% section is exactly prettier^N(output_prettier.). +# This file exists when prettier is non-idempotent on output_prettier.* — it pins +# the full chain so the audit recognizes the case and the validator catches drift. +# See docs/fixture_overview.md (rule F4) and crates/tsv_debug/src/fixtures/audit_signature.rs. + +%%PASS=2%% + + +%%PASS=3 (fixed point)%% + diff --git a/tests/fixtures/typescript/expressions/calls/test_call_arg_comment_prettier_divergence/expected.json b/tests/fixtures/typescript/expressions/calls/test_call_arg_comment_prettier_divergence/expected.json new file mode 100644 index 000000000..4bd50d10d --- /dev/null +++ b/tests/fixtures/typescript/expressions/calls/test_call_arg_comment_prettier_divergence/expected.json @@ -0,0 +1,1325 @@ +{ + "css": null, + "js": [], + "start": 0, + "end": 950, + "type": "Root", + "fragment": { + "type": "Fragment", + "nodes": [] + }, + "options": null, + "comments": [ + { + "type": "Line", + "value": " a test call's flat one-line layout has no argument-gap comment emitter, so a", + "start": 20, + "end": 99, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 80 + } + } + }, + { + "type": "Line", + "value": " comment in the leading or an inter-argument gap gives up that layout and the", + "start": 101, + "end": 180, + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 80 + } + } + }, + { + "type": "Line", + "value": " call expands like any other — tsv keeps the comment on its own line where", + "start": 182, + "end": 258, + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 77 + } + } + }, + { + "type": "Line", + "value": " prettier relocates it onto the `(` (or the previous argument's) line", + "start": 260, + "end": 331, + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 72 + } + } + }, + { + "type": "Line", + "value": " c", + "start": 339, + "end": 343, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 6 + } + } + }, + { + "type": "Line", + "value": " c", + "start": 398, + "end": 402, + "loc": { + "start": { + "line": 16, + "column": 2 + }, + "end": { + "line": 16, + "column": 6 + } + } + }, + { + "type": "Line", + "value": " the block spelling behaves the same", + "start": 431, + "end": 469, + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 22, + "column": 39 + } + } + }, + { + "type": "Block", + "value": " c ", + "start": 483, + "end": 490, + "loc": { + "start": { + "line": 24, + "column": 2 + }, + "end": { + "line": 24, + "column": 9 + } + } + }, + { + "type": "Line", + "value": " a directive alone on its line freezes the following argument here too", + "start": 529, + "end": 601, + "loc": { + "start": { + "line": 31, + "column": 1 + }, + "end": { + "line": 31, + "column": 73 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 611, + "end": 629, + "loc": { + "start": { + "line": 33, + "column": 2 + }, + "end": { + "line": 33, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " a glued block comment is owned by its argument and rides inside its doc, so the", + "start": 670, + "end": 752, + "loc": { + "start": { + "line": 40, + "column": 1 + }, + "end": { + "line": 40, + "column": 83 + } + } + }, + { + "type": "Line", + "value": " flat layout survives", + "start": 754, + "end": 777, + "loc": { + "start": { + "line": 41, + "column": 1 + }, + "end": { + "line": 41, + "column": 24 + } + } + }, + { + "type": "Block", + "value": " c ", + "start": 790, + "end": 797, + "loc": { + "start": { + "line": 42, + "column": 12 + }, + "end": { + "line": 42, + "column": 19 + } + } + }, + { + "type": "Line", + "value": " a trailing comment after the last argument is emitted by the flat layout itself", + "start": 820, + "end": 902, + "loc": { + "start": { + "line": 46, + "column": 1 + }, + "end": { + "line": 46, + "column": 83 + } + } + }, + { + "type": "Line", + "value": " c", + "start": 935, + "end": 939, + "loc": { + "start": { + "line": 49, + "column": 5 + }, + "end": { + "line": 49, + "column": 9 + } + } + } + ], + "instance": { + "type": "Script", + "start": 0, + "end": 949, + "context": "default", + "content": { + "type": "Program", + "start": 18, + "end": 940, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 50, + "column": 9 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 333, + "end": 379, + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 12, + "column": 3 + } + }, + "expression": { + "type": "CallExpression", + "start": 333, + "end": 378, + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 12, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 333, + "end": 335, + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "name": "it" + }, + "arguments": [ + { + "type": "Literal", + "start": 346, + "end": 352, + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 8 + } + }, + "value": "text", + "raw": "'text'", + "leadingComments": [ + { + "type": "Line", + "value": " c", + "start": 339, + "end": 343 + } + ] + }, + { + "type": "ArrowFunctionExpression", + "start": 356, + "end": 375, + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 11, + "column": 3 + } + }, + "id": null, + "expression": false, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 362, + "end": 375, + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 11, + "column": 3 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 367, + "end": 371, + "loc": { + "start": { + "line": 10, + "column": 3 + }, + "end": { + "line": 10, + "column": 7 + } + }, + "expression": { + "type": "CallExpression", + "start": 367, + "end": 370, + "loc": { + "start": { + "line": 10, + "column": 3 + }, + "end": { + "line": 10, + "column": 6 + } + }, + "callee": { + "type": "Identifier", + "start": 367, + "end": 368, + "loc": { + "start": { + "line": 10, + "column": 3 + }, + "end": { + "line": 10, + "column": 4 + } + }, + "name": "a" + }, + "arguments": [], + "optional": false + } + } + ] + } + } + ], + "optional": false + }, + "leadingComments": [ + { + "type": "Line", + "value": " a test call's flat one-line layout has no argument-gap comment emitter, so a", + "start": 20, + "end": 99 + }, + { + "type": "Line", + "value": " comment in the leading or an inter-argument gap gives up that layout and the", + "start": 101, + "end": 180 + }, + { + "type": "Line", + "value": " call expands like any other — tsv keeps the comment on its own line where", + "start": 182, + "end": 258 + }, + { + "type": "Line", + "value": " prettier relocates it onto the `(` (or the previous argument's) line", + "start": 260, + "end": 331 + } + ] + }, + { + "type": "ExpressionStatement", + "start": 382, + "end": 428, + "loc": { + "start": { + "line": 14, + "column": 1 + }, + "end": { + "line": 20, + "column": 3 + } + }, + "expression": { + "type": "CallExpression", + "start": 382, + "end": 427, + "loc": { + "start": { + "line": 14, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 382, + "end": 384, + "loc": { + "start": { + "line": 14, + "column": 1 + }, + "end": { + "line": 14, + "column": 3 + } + }, + "name": "it" + }, + "arguments": [ + { + "type": "Literal", + "start": 388, + "end": 394, + "loc": { + "start": { + "line": 15, + "column": 2 + }, + "end": { + "line": 15, + "column": 8 + } + }, + "value": "text", + "raw": "'text'" + }, + { + "type": "ArrowFunctionExpression", + "start": 405, + "end": 424, + "loc": { + "start": { + "line": 17, + "column": 2 + }, + "end": { + "line": 19, + "column": 3 + } + }, + "id": null, + "expression": false, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 411, + "end": 424, + "loc": { + "start": { + "line": 17, + "column": 8 + }, + "end": { + "line": 19, + "column": 3 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 416, + "end": 420, + "loc": { + "start": { + "line": 18, + "column": 3 + }, + "end": { + "line": 18, + "column": 7 + } + }, + "expression": { + "type": "CallExpression", + "start": 416, + "end": 419, + "loc": { + "start": { + "line": 18, + "column": 3 + }, + "end": { + "line": 18, + "column": 6 + } + }, + "callee": { + "type": "Identifier", + "start": 416, + "end": 417, + "loc": { + "start": { + "line": 18, + "column": 3 + }, + "end": { + "line": 18, + "column": 4 + } + }, + "name": "a" + }, + "arguments": [], + "optional": false + } + } + ] + }, + "leadingComments": [ + { + "type": "Line", + "value": " c", + "start": 398, + "end": 402 + } + ] + } + ], + "optional": false + } + }, + { + "type": "ExpressionStatement", + "start": 471, + "end": 526, + "loc": { + "start": { + "line": 23, + "column": 1 + }, + "end": { + "line": 29, + "column": 3 + } + }, + "expression": { + "type": "CallExpression", + "start": 471, + "end": 525, + "loc": { + "start": { + "line": 23, + "column": 1 + }, + "end": { + "line": 29, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 471, + "end": 479, + "loc": { + "start": { + "line": 23, + "column": 1 + }, + "end": { + "line": 23, + "column": 9 + } + }, + "name": "describe" + }, + "arguments": [ + { + "type": "Literal", + "start": 493, + "end": 499, + "loc": { + "start": { + "line": 25, + "column": 2 + }, + "end": { + "line": 25, + "column": 8 + } + }, + "value": "text", + "raw": "'text'", + "leadingComments": [ + { + "type": "Block", + "value": " c ", + "start": 483, + "end": 490 + } + ] + }, + { + "type": "ArrowFunctionExpression", + "start": 503, + "end": 522, + "loc": { + "start": { + "line": 26, + "column": 2 + }, + "end": { + "line": 28, + "column": 3 + } + }, + "id": null, + "expression": false, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 509, + "end": 522, + "loc": { + "start": { + "line": 26, + "column": 8 + }, + "end": { + "line": 28, + "column": 3 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 514, + "end": 518, + "loc": { + "start": { + "line": 27, + "column": 3 + }, + "end": { + "line": 27, + "column": 7 + } + }, + "expression": { + "type": "CallExpression", + "start": 514, + "end": 517, + "loc": { + "start": { + "line": 27, + "column": 3 + }, + "end": { + "line": 27, + "column": 6 + } + }, + "callee": { + "type": "Identifier", + "start": 514, + "end": 515, + "loc": { + "start": { + "line": 27, + "column": 3 + }, + "end": { + "line": 27, + "column": 4 + } + }, + "name": "a" + }, + "arguments": [], + "optional": false + } + } + ] + } + } + ], + "optional": false + }, + "leadingComments": [ + { + "type": "Line", + "value": " the block spelling behaves the same", + "start": 431, + "end": 469 + } + ] + }, + { + "type": "ExpressionStatement", + "start": 603, + "end": 667, + "loc": { + "start": { + "line": 32, + "column": 1 + }, + "end": { + "line": 38, + "column": 3 + } + }, + "expression": { + "type": "CallExpression", + "start": 603, + "end": 666, + "loc": { + "start": { + "line": 32, + "column": 1 + }, + "end": { + "line": 38, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 603, + "end": 607, + "loc": { + "start": { + "line": 32, + "column": 1 + }, + "end": { + "line": 32, + "column": 5 + } + }, + "name": "test" + }, + "arguments": [ + { + "type": "Literal", + "start": 632, + "end": 640, + "loc": { + "start": { + "line": 34, + "column": 2 + }, + "end": { + "line": 34, + "column": 10 + } + }, + "value": "te xt", + "raw": "'te xt'", + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 611, + "end": 629 + } + ] + }, + { + "type": "ArrowFunctionExpression", + "start": 644, + "end": 663, + "loc": { + "start": { + "line": 35, + "column": 2 + }, + "end": { + "line": 37, + "column": 3 + } + }, + "id": null, + "expression": false, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 650, + "end": 663, + "loc": { + "start": { + "line": 35, + "column": 8 + }, + "end": { + "line": 37, + "column": 3 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 655, + "end": 659, + "loc": { + "start": { + "line": 36, + "column": 3 + }, + "end": { + "line": 36, + "column": 7 + } + }, + "expression": { + "type": "CallExpression", + "start": 655, + "end": 658, + "loc": { + "start": { + "line": 36, + "column": 3 + }, + "end": { + "line": 36, + "column": 6 + } + }, + "callee": { + "type": "Identifier", + "start": 655, + "end": 656, + "loc": { + "start": { + "line": 36, + "column": 3 + }, + "end": { + "line": 36, + "column": 4 + } + }, + "name": "a" + }, + "arguments": [], + "optional": false + } + } + ] + } + } + ], + "optional": false + }, + "leadingComments": [ + { + "type": "Line", + "value": " a directive alone on its line freezes the following argument here too", + "start": 529, + "end": 601 + } + ] + }, + { + "type": "ExpressionStatement", + "start": 779, + "end": 817, + "loc": { + "start": { + "line": 42, + "column": 1 + }, + "end": { + "line": 44, + "column": 4 + } + }, + "expression": { + "type": "CallExpression", + "start": 779, + "end": 816, + "loc": { + "start": { + "line": 42, + "column": 1 + }, + "end": { + "line": 44, + "column": 3 + } + }, + "callee": { + "type": "Identifier", + "start": 779, + "end": 781, + "loc": { + "start": { + "line": 42, + "column": 1 + }, + "end": { + "line": 42, + "column": 3 + } + }, + "name": "it" + }, + "arguments": [ + { + "type": "Literal", + "start": 782, + "end": 788, + "loc": { + "start": { + "line": 42, + "column": 4 + }, + "end": { + "line": 42, + "column": 10 + } + }, + "value": "text", + "raw": "'text'", + "trailingComments": [ + { + "type": "Block", + "value": " c ", + "start": 790, + "end": 797 + } + ] + }, + { + "type": "ArrowFunctionExpression", + "start": 798, + "end": 815, + "loc": { + "start": { + "line": 42, + "column": 20 + }, + "end": { + "line": 44, + "column": 2 + } + }, + "id": null, + "expression": false, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 804, + "end": 815, + "loc": { + "start": { + "line": 42, + "column": 26 + }, + "end": { + "line": 44, + "column": 2 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 808, + "end": 812, + "loc": { + "start": { + "line": 43, + "column": 2 + }, + "end": { + "line": 43, + "column": 6 + } + }, + "expression": { + "type": "CallExpression", + "start": 808, + "end": 811, + "loc": { + "start": { + "line": 43, + "column": 2 + }, + "end": { + "line": 43, + "column": 5 + } + }, + "callee": { + "type": "Identifier", + "start": 808, + "end": 809, + "loc": { + "start": { + "line": 43, + "column": 2 + }, + "end": { + "line": 43, + "column": 3 + } + }, + "name": "a" + }, + "arguments": [], + "optional": false + } + } + ] + } + } + ], + "optional": false + }, + "leadingComments": [ + { + "type": "Line", + "value": " a glued block comment is owned by its argument and rides inside its doc, so the", + "start": 670, + "end": 752 + }, + { + "type": "Line", + "value": " flat layout survives", + "start": 754, + "end": 777 + } + ] + }, + { + "type": "ExpressionStatement", + "start": 904, + "end": 934, + "loc": { + "start": { + "line": 47, + "column": 1 + }, + "end": { + "line": 49, + "column": 4 + } + }, + "expression": { + "type": "CallExpression", + "start": 904, + "end": 933, + "loc": { + "start": { + "line": 47, + "column": 1 + }, + "end": { + "line": 49, + "column": 3 + } + }, + "callee": { + "type": "Identifier", + "start": 904, + "end": 906, + "loc": { + "start": { + "line": 47, + "column": 1 + }, + "end": { + "line": 47, + "column": 3 + } + }, + "name": "it" + }, + "arguments": [ + { + "type": "Literal", + "start": 907, + "end": 913, + "loc": { + "start": { + "line": 47, + "column": 4 + }, + "end": { + "line": 47, + "column": 10 + } + }, + "value": "text", + "raw": "'text'" + }, + { + "type": "ArrowFunctionExpression", + "start": 915, + "end": 932, + "loc": { + "start": { + "line": 47, + "column": 12 + }, + "end": { + "line": 49, + "column": 2 + } + }, + "id": null, + "expression": false, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 921, + "end": 932, + "loc": { + "start": { + "line": 47, + "column": 18 + }, + "end": { + "line": 49, + "column": 2 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 925, + "end": 929, + "loc": { + "start": { + "line": 48, + "column": 2 + }, + "end": { + "line": 48, + "column": 6 + } + }, + "expression": { + "type": "CallExpression", + "start": 925, + "end": 928, + "loc": { + "start": { + "line": 48, + "column": 2 + }, + "end": { + "line": 48, + "column": 5 + } + }, + "callee": { + "type": "Identifier", + "start": 925, + "end": 926, + "loc": { + "start": { + "line": 48, + "column": 2 + }, + "end": { + "line": 48, + "column": 3 + } + }, + "name": "a" + }, + "arguments": [], + "optional": false + } + } + ] + } + } + ], + "optional": false + }, + "leadingComments": [ + { + "type": "Line", + "value": " a trailing comment after the last argument is emitted by the flat layout itself", + "start": 820, + "end": 902 + } + ], + "trailingComments": [ + { + "type": "Line", + "value": " c", + "start": 935, + "end": 939 + } + ] + } + ], + "sourceType": "module" + }, + "attributes": [ + { + "type": "Attribute", + "start": 8, + "end": 17, + "name": "lang", + "name_loc": { + "start": { + "line": 1, + "column": 8, + "character": 8 + }, + "end": { + "line": 1, + "column": 12, + "character": 12 + } + }, + "value": [ + { + "start": 14, + "end": 16, + "type": "Text", + "raw": "ts", + "data": "ts" + } + ] + } + ] + } +} diff --git a/tests/fixtures/typescript/expressions/calls/test_call_arg_comment_prettier_divergence/input.svelte b/tests/fixtures/typescript/expressions/calls/test_call_arg_comment_prettier_divergence/input.svelte new file mode 100644 index 000000000..d36b38ac7 --- /dev/null +++ b/tests/fixtures/typescript/expressions/calls/test_call_arg_comment_prettier_divergence/input.svelte @@ -0,0 +1,50 @@ + diff --git a/tests/fixtures/typescript/expressions/calls/test_call_arg_comment_prettier_divergence/output_prettier.svelte b/tests/fixtures/typescript/expressions/calls/test_call_arg_comment_prettier_divergence/output_prettier.svelte new file mode 100644 index 000000000..74ec07ce9 --- /dev/null +++ b/tests/fixtures/typescript/expressions/calls/test_call_arg_comment_prettier_divergence/output_prettier.svelte @@ -0,0 +1,38 @@ + diff --git a/tests/fixtures/typescript/expressions/calls/test_call_arg_comment_prettier_divergence/unformatted_ours_spaces.svelte b/tests/fixtures/typescript/expressions/calls/test_call_arg_comment_prettier_divergence/unformatted_ours_spaces.svelte new file mode 100644 index 000000000..7c585e541 --- /dev/null +++ b/tests/fixtures/typescript/expressions/calls/test_call_arg_comment_prettier_divergence/unformatted_ours_spaces.svelte @@ -0,0 +1,50 @@ + diff --git a/tests/fixtures/typescript/expressions/new/args_prettier_ignore_member/expected.json b/tests/fixtures/typescript/expressions/new/args_prettier_ignore_member/expected.json new file mode 100644 index 000000000..06c2e4d66 --- /dev/null +++ b/tests/fixtures/typescript/expressions/new/args_prettier_ignore_member/expected.json @@ -0,0 +1,2596 @@ +{ + "css": null, + "js": [], + "start": 0, + "end": 1505, + "type": "Root", + "fragment": { + "type": "Fragment", + "nodes": [] + }, + "options": null, + "comments": [ + { + "type": "Line", + "value": " an own-line directive in a `new` argument gap freezes only the following argument", + "start": 20, + "end": 104, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 85 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 127, + "end": 145, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " before the first argument", + "start": 177, + "end": 205, + "loc": { + "start": { + "line": 10, + "column": 1 + }, + "end": { + "line": 10, + "column": 29 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 216, + "end": 234, + "loc": { + "start": { + "line": 12, + "column": 2 + }, + "end": { + "line": 12, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " a lone huggable argument freezes and expands instead of hugging", + "start": 266, + "end": 332, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 67 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 343, + "end": 361, + "loc": { + "start": { + "line": 19, + "column": 2 + }, + "end": { + "line": 19, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 390, + "end": 408, + "loc": { + "start": { + "line": 24, + "column": 2 + }, + "end": { + "line": 24, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 435, + "end": 453, + "loc": { + "start": { + "line": 29, + "column": 2 + }, + "end": { + "line": 29, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " a lone arrow argument", + "start": 494, + "end": 518, + "loc": { + "start": { + "line": 35, + "column": 1 + }, + "end": { + "line": 35, + "column": 25 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 529, + "end": 547, + "loc": { + "start": { + "line": 37, + "column": 2 + }, + "end": { + "line": 37, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " an author blank line beside a frozen argument is preserved", + "start": 570, + "end": 631, + "loc": { + "start": { + "line": 41, + "column": 1 + }, + "end": { + "line": 41, + "column": 62 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 648, + "end": 666, + "loc": { + "start": { + "line": 45, + "column": 2 + }, + "end": { + "line": 45, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " an own-line block spelling freezes identically", + "start": 686, + "end": 735, + "loc": { + "start": { + "line": 49, + "column": 1 + }, + "end": { + "line": 49, + "column": 50 + } + } + }, + { + "type": "Block", + "value": " prettier-ignore ", + "start": 746, + "end": 767, + "loc": { + "start": { + "line": 51, + "column": 2 + }, + "end": { + "line": 51, + "column": 23 + } + } + }, + { + "type": "Line", + "value": " a block comment glued before a frozen argument is owned by it and stays put", + "start": 799, + "end": 877, + "loc": { + "start": { + "line": 56, + "column": 1 + }, + "end": { + "line": 56, + "column": 79 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 888, + "end": 906, + "loc": { + "start": { + "line": 58, + "column": 2 + }, + "end": { + "line": 58, + "column": 20 + } + } + }, + { + "type": "Block", + "value": " c ", + "start": 909, + "end": 916, + "loc": { + "start": { + "line": 59, + "column": 2 + }, + "end": { + "line": 59, + "column": 9 + } + } + }, + { + "type": "Line", + "value": " an ordinary comment leading the same run keeps the directive on its own line, so", + "start": 955, + "end": 1038, + "loc": { + "start": { + "line": 64, + "column": 1 + }, + "end": { + "line": 64, + "column": 84 + } + } + }, + { + "type": "Line", + "value": " the freeze survives the next pass; the variant authors that comment on the `(` line", + "start": 1040, + "end": 1126, + "loc": { + "start": { + "line": 65, + "column": 1 + }, + "end": { + "line": 65, + "column": 87 + } + } + }, + { + "type": "Line", + "value": " c", + "start": 1137, + "end": 1141, + "loc": { + "start": { + "line": 67, + "column": 2 + }, + "end": { + "line": 67, + "column": 6 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 1144, + "end": 1162, + "loc": { + "start": { + "line": 68, + "column": 2 + }, + "end": { + "line": 68, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " a frozen FIRST argument followed by an author blank line — the blank-line layout", + "start": 1194, + "end": 1277, + "loc": { + "start": { + "line": 73, + "column": 1 + }, + "end": { + "line": 73, + "column": 84 + } + } + }, + { + "type": "Line", + "value": " owns the leading gap here", + "start": 1279, + "end": 1307, + "loc": { + "start": { + "line": 74, + "column": 1 + }, + "end": { + "line": 74, + "column": 29 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 1318, + "end": 1336, + "loc": { + "start": { + "line": 76, + "column": 2 + }, + "end": { + "line": 76, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " a sequence argument keeps its own grouping parens around the frozen slice", + "start": 1369, + "end": 1445, + "loc": { + "start": { + "line": 82, + "column": 1 + }, + "end": { + "line": 82, + "column": 77 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 1456, + "end": 1474, + "loc": { + "start": { + "line": 84, + "column": 2 + }, + "end": { + "line": 84, + "column": 20 + } + } + } + ], + "instance": { + "type": "Script", + "start": 0, + "end": 1504, + "context": "default", + "content": { + "type": "Program", + "start": 18, + "end": 1495, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 88, + "column": 9 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 106, + "end": 174, + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 8, + "column": 3 + } + }, + "expression": { + "type": "NewExpression", + "start": 106, + "end": 173, + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 8, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 110, + "end": 111, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "name": "A" + }, + "arguments": [ + { + "type": "ObjectExpression", + "start": 115, + "end": 123, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 10 + } + }, + "properties": [ + { + "type": "Property", + "start": 117, + "end": 121, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 8 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 117, + "end": 118, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 5 + } + }, + "name": "a" + }, + "value": { + "type": "Literal", + "start": 120, + "end": 121, + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 8 + } + }, + "value": 1, + "raw": "1" + }, + "kind": "init" + } + ] + }, + { + "type": "ObjectExpression", + "start": 148, + "end": 158, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 12 + } + }, + "properties": [ + { + "type": "Property", + "start": 150, + "end": 156, + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 10 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 150, + "end": 151, + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 5 + } + }, + "name": "b" + }, + "value": { + "type": "Literal", + "start": 155, + "end": 156, + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 6, + "column": 10 + } + }, + "value": 2, + "raw": "2" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 127, + "end": 145 + } + ] + }, + { + "type": "ObjectExpression", + "start": 162, + "end": 170, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 10 + } + }, + "properties": [ + { + "type": "Property", + "start": 164, + "end": 168, + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 8 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 164, + "end": 165, + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 5 + } + }, + "name": "c" + }, + "value": { + "type": "Literal", + "start": 167, + "end": 168, + "loc": { + "start": { + "line": 7, + "column": 7 + }, + "end": { + "line": 7, + "column": 8 + } + }, + "value": 3, + "raw": "3" + }, + "kind": "init" + } + ] + } + ] + }, + "leadingComments": [ + { + "type": "Line", + "value": " an own-line directive in a `new` argument gap freezes only the following argument", + "start": 20, + "end": 104 + } + ] + }, + { + "type": "ExpressionStatement", + "start": 207, + "end": 263, + "loc": { + "start": { + "line": 11, + "column": 1 + }, + "end": { + "line": 15, + "column": 3 + } + }, + "expression": { + "type": "NewExpression", + "start": 207, + "end": 262, + "loc": { + "start": { + "line": 11, + "column": 1 + }, + "end": { + "line": 15, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 211, + "end": 212, + "loc": { + "start": { + "line": 11, + "column": 5 + }, + "end": { + "line": 11, + "column": 6 + } + }, + "name": "A" + }, + "arguments": [ + { + "type": "ObjectExpression", + "start": 237, + "end": 247, + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 12 + } + }, + "properties": [ + { + "type": "Property", + "start": 239, + "end": 245, + "loc": { + "start": { + "line": 13, + "column": 4 + }, + "end": { + "line": 13, + "column": 10 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 239, + "end": 240, + "loc": { + "start": { + "line": 13, + "column": 4 + }, + "end": { + "line": 13, + "column": 5 + } + }, + "name": "a" + }, + "value": { + "type": "Literal", + "start": 244, + "end": 245, + "loc": { + "start": { + "line": 13, + "column": 9 + }, + "end": { + "line": 13, + "column": 10 + } + }, + "value": 1, + "raw": "1" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 216, + "end": 234 + } + ] + }, + { + "type": "ObjectExpression", + "start": 251, + "end": 259, + "loc": { + "start": { + "line": 14, + "column": 2 + }, + "end": { + "line": 14, + "column": 10 + } + }, + "properties": [ + { + "type": "Property", + "start": 253, + "end": 257, + "loc": { + "start": { + "line": 14, + "column": 4 + }, + "end": { + "line": 14, + "column": 8 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 253, + "end": 254, + "loc": { + "start": { + "line": 14, + "column": 4 + }, + "end": { + "line": 14, + "column": 5 + } + }, + "name": "b" + }, + "value": { + "type": "Literal", + "start": 256, + "end": 257, + "loc": { + "start": { + "line": 14, + "column": 7 + }, + "end": { + "line": 14, + "column": 8 + } + }, + "value": 2, + "raw": "2" + }, + "kind": "init" + } + ] + } + ] + }, + "leadingComments": [ + { + "type": "Line", + "value": " before the first argument", + "start": 177, + "end": 205 + } + ] + }, + { + "type": "ExpressionStatement", + "start": 334, + "end": 378, + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 21, + "column": 3 + } + }, + "expression": { + "type": "NewExpression", + "start": 334, + "end": 377, + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 338, + "end": 339, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 6 + } + }, + "name": "A" + }, + "arguments": [ + { + "type": "ObjectExpression", + "start": 364, + "end": 374, + "loc": { + "start": { + "line": 20, + "column": 2 + }, + "end": { + "line": 20, + "column": 12 + } + }, + "properties": [ + { + "type": "Property", + "start": 366, + "end": 372, + "loc": { + "start": { + "line": 20, + "column": 4 + }, + "end": { + "line": 20, + "column": 10 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 366, + "end": 367, + "loc": { + "start": { + "line": 20, + "column": 4 + }, + "end": { + "line": 20, + "column": 5 + } + }, + "name": "a" + }, + "value": { + "type": "Literal", + "start": 371, + "end": 372, + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 20, + "column": 10 + } + }, + "value": 1, + "raw": "1" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 343, + "end": 361 + } + ] + } + ] + }, + "leadingComments": [ + { + "type": "Line", + "value": " a lone huggable argument freezes and expands instead of hugging", + "start": 266, + "end": 332 + } + ] + }, + { + "type": "ExpressionStatement", + "start": 381, + "end": 423, + "loc": { + "start": { + "line": 23, + "column": 1 + }, + "end": { + "line": 26, + "column": 3 + } + }, + "expression": { + "type": "NewExpression", + "start": 381, + "end": 422, + "loc": { + "start": { + "line": 23, + "column": 1 + }, + "end": { + "line": 26, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 385, + "end": 386, + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 6 + } + }, + "name": "A" + }, + "arguments": [ + { + "type": "ArrayExpression", + "start": 411, + "end": 419, + "loc": { + "start": { + "line": 25, + "column": 2 + }, + "end": { + "line": 25, + "column": 10 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 412, + "end": 413, + "loc": { + "start": { + "line": 25, + "column": 3 + }, + "end": { + "line": 25, + "column": 4 + } + }, + "name": "a" + }, + { + "type": "Identifier", + "start": 417, + "end": 418, + "loc": { + "start": { + "line": 25, + "column": 8 + }, + "end": { + "line": 25, + "column": 9 + } + }, + "name": "b" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 390, + "end": 408 + } + ] + } + ] + } + }, + { + "type": "ExpressionStatement", + "start": 426, + "end": 491, + "loc": { + "start": { + "line": 28, + "column": 1 + }, + "end": { + "line": 33, + "column": 3 + } + }, + "expression": { + "type": "NewExpression", + "start": 426, + "end": 490, + "loc": { + "start": { + "line": 28, + "column": 1 + }, + "end": { + "line": 33, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 430, + "end": 431, + "loc": { + "start": { + "line": 28, + "column": 5 + }, + "end": { + "line": 28, + "column": 6 + } + }, + "name": "A" + }, + "arguments": [ + { + "type": "FunctionExpression", + "start": 456, + "end": 487, + "loc": { + "start": { + "line": 30, + "column": 2 + }, + "end": { + "line": 32, + "column": 3 + } + }, + "id": null, + "expression": false, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 468, + "end": 487, + "loc": { + "start": { + "line": 30, + "column": 14 + }, + "end": { + "line": 32, + "column": 3 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 473, + "end": 483, + "loc": { + "start": { + "line": 31, + "column": 3 + }, + "end": { + "line": 31, + "column": 13 + } + }, + "expression": { + "type": "CallExpression", + "start": 473, + "end": 482, + "loc": { + "start": { + "line": 31, + "column": 3 + }, + "end": { + "line": 31, + "column": 12 + } + }, + "callee": { + "type": "Identifier", + "start": 473, + "end": 474, + "loc": { + "start": { + "line": 31, + "column": 3 + }, + "end": { + "line": 31, + "column": 4 + } + }, + "name": "a" + }, + "arguments": [ + { + "type": "Literal", + "start": 475, + "end": 476, + "loc": { + "start": { + "line": 31, + "column": 5 + }, + "end": { + "line": 31, + "column": 6 + } + }, + "value": 1, + "raw": "1" + }, + { + "type": "Literal", + "start": 480, + "end": 481, + "loc": { + "start": { + "line": 31, + "column": 10 + }, + "end": { + "line": 31, + "column": 11 + } + }, + "value": 2, + "raw": "2" + } + ], + "optional": false + } + } + ] + }, + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 435, + "end": 453 + } + ] + } + ] + } + }, + { + "type": "ExpressionStatement", + "start": 520, + "end": 567, + "loc": { + "start": { + "line": 36, + "column": 1 + }, + "end": { + "line": 39, + "column": 3 + } + }, + "expression": { + "type": "NewExpression", + "start": 520, + "end": 566, + "loc": { + "start": { + "line": 36, + "column": 1 + }, + "end": { + "line": 39, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 524, + "end": 525, + "loc": { + "start": { + "line": 36, + "column": 5 + }, + "end": { + "line": 36, + "column": 6 + } + }, + "name": "A" + }, + "arguments": [ + { + "type": "ArrowFunctionExpression", + "start": 550, + "end": 563, + "loc": { + "start": { + "line": 38, + "column": 2 + }, + "end": { + "line": 38, + "column": 15 + } + }, + "id": null, + "expression": true, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BinaryExpression", + "start": 556, + "end": 563, + "loc": { + "start": { + "line": 38, + "column": 8 + }, + "end": { + "line": 38, + "column": 15 + } + }, + "left": { + "type": "Identifier", + "start": 556, + "end": 557, + "loc": { + "start": { + "line": 38, + "column": 8 + }, + "end": { + "line": 38, + "column": 9 + } + }, + "name": "a" + }, + "operator": "+", + "right": { + "type": "Identifier", + "start": 562, + "end": 563, + "loc": { + "start": { + "line": 38, + "column": 14 + }, + "end": { + "line": 38, + "column": 15 + } + }, + "name": "b" + } + }, + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 529, + "end": 547 + } + ] + } + ] + }, + "leadingComments": [ + { + "type": "Line", + "value": " a lone arrow argument", + "start": 494, + "end": 518 + } + ] + }, + { + "type": "ExpressionStatement", + "start": 633, + "end": 683, + "loc": { + "start": { + "line": 42, + "column": 1 + }, + "end": { + "line": 47, + "column": 3 + } + }, + "expression": { + "type": "NewExpression", + "start": 633, + "end": 682, + "loc": { + "start": { + "line": 42, + "column": 1 + }, + "end": { + "line": 47, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 637, + "end": 638, + "loc": { + "start": { + "line": 42, + "column": 5 + }, + "end": { + "line": 42, + "column": 6 + } + }, + "name": "A" + }, + "arguments": [ + { + "type": "Identifier", + "start": 642, + "end": 643, + "loc": { + "start": { + "line": 43, + "column": 2 + }, + "end": { + "line": 43, + "column": 3 + } + }, + "name": "a" + }, + { + "type": "ObjectExpression", + "start": 669, + "end": 679, + "loc": { + "start": { + "line": 46, + "column": 2 + }, + "end": { + "line": 46, + "column": 12 + } + }, + "properties": [ + { + "type": "Property", + "start": 671, + "end": 677, + "loc": { + "start": { + "line": 46, + "column": 4 + }, + "end": { + "line": 46, + "column": 10 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 671, + "end": 672, + "loc": { + "start": { + "line": 46, + "column": 4 + }, + "end": { + "line": 46, + "column": 5 + } + }, + "name": "b" + }, + "value": { + "type": "Literal", + "start": 676, + "end": 677, + "loc": { + "start": { + "line": 46, + "column": 9 + }, + "end": { + "line": 46, + "column": 10 + } + }, + "value": 2, + "raw": "2" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 648, + "end": 666 + } + ] + } + ] + }, + "leadingComments": [ + { + "type": "Line", + "value": " an author blank line beside a frozen argument is preserved", + "start": 570, + "end": 631 + } + ] + }, + { + "type": "ExpressionStatement", + "start": 737, + "end": 796, + "loc": { + "start": { + "line": 50, + "column": 1 + }, + "end": { + "line": 54, + "column": 3 + } + }, + "expression": { + "type": "NewExpression", + "start": 737, + "end": 795, + "loc": { + "start": { + "line": 50, + "column": 1 + }, + "end": { + "line": 54, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 741, + "end": 742, + "loc": { + "start": { + "line": 50, + "column": 5 + }, + "end": { + "line": 50, + "column": 6 + } + }, + "name": "A" + }, + "arguments": [ + { + "type": "ObjectExpression", + "start": 770, + "end": 780, + "loc": { + "start": { + "line": 52, + "column": 2 + }, + "end": { + "line": 52, + "column": 12 + } + }, + "properties": [ + { + "type": "Property", + "start": 772, + "end": 778, + "loc": { + "start": { + "line": 52, + "column": 4 + }, + "end": { + "line": 52, + "column": 10 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 772, + "end": 773, + "loc": { + "start": { + "line": 52, + "column": 4 + }, + "end": { + "line": 52, + "column": 5 + } + }, + "name": "a" + }, + "value": { + "type": "Literal", + "start": 777, + "end": 778, + "loc": { + "start": { + "line": 52, + "column": 9 + }, + "end": { + "line": 52, + "column": 10 + } + }, + "value": 1, + "raw": "1" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Block", + "value": " prettier-ignore ", + "start": 746, + "end": 767 + } + ] + }, + { + "type": "ObjectExpression", + "start": 784, + "end": 792, + "loc": { + "start": { + "line": 53, + "column": 2 + }, + "end": { + "line": 53, + "column": 10 + } + }, + "properties": [ + { + "type": "Property", + "start": 786, + "end": 790, + "loc": { + "start": { + "line": 53, + "column": 4 + }, + "end": { + "line": 53, + "column": 8 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 786, + "end": 787, + "loc": { + "start": { + "line": 53, + "column": 4 + }, + "end": { + "line": 53, + "column": 5 + } + }, + "name": "b" + }, + "value": { + "type": "Literal", + "start": 789, + "end": 790, + "loc": { + "start": { + "line": 53, + "column": 7 + }, + "end": { + "line": 53, + "column": 8 + } + }, + "value": 2, + "raw": "2" + }, + "kind": "init" + } + ] + } + ] + }, + "leadingComments": [ + { + "type": "Line", + "value": " an own-line block spelling freezes identically", + "start": 686, + "end": 735 + } + ] + }, + { + "type": "ExpressionStatement", + "start": 879, + "end": 952, + "loc": { + "start": { + "line": 57, + "column": 1 + }, + "end": { + "line": 62, + "column": 3 + } + }, + "expression": { + "type": "NewExpression", + "start": 879, + "end": 951, + "loc": { + "start": { + "line": 57, + "column": 1 + }, + "end": { + "line": 62, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 883, + "end": 884, + "loc": { + "start": { + "line": 57, + "column": 5 + }, + "end": { + "line": 57, + "column": 6 + } + }, + "name": "A" + }, + "arguments": [ + { + "type": "FunctionExpression", + "start": 917, + "end": 948, + "loc": { + "start": { + "line": 59, + "column": 10 + }, + "end": { + "line": 61, + "column": 3 + } + }, + "id": null, + "expression": false, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 929, + "end": 948, + "loc": { + "start": { + "line": 59, + "column": 22 + }, + "end": { + "line": 61, + "column": 3 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 934, + "end": 944, + "loc": { + "start": { + "line": 60, + "column": 3 + }, + "end": { + "line": 60, + "column": 13 + } + }, + "expression": { + "type": "CallExpression", + "start": 934, + "end": 943, + "loc": { + "start": { + "line": 60, + "column": 3 + }, + "end": { + "line": 60, + "column": 12 + } + }, + "callee": { + "type": "Identifier", + "start": 934, + "end": 935, + "loc": { + "start": { + "line": 60, + "column": 3 + }, + "end": { + "line": 60, + "column": 4 + } + }, + "name": "a" + }, + "arguments": [ + { + "type": "Literal", + "start": 936, + "end": 937, + "loc": { + "start": { + "line": 60, + "column": 5 + }, + "end": { + "line": 60, + "column": 6 + } + }, + "value": 1, + "raw": "1" + }, + { + "type": "Literal", + "start": 941, + "end": 942, + "loc": { + "start": { + "line": 60, + "column": 10 + }, + "end": { + "line": 60, + "column": 11 + } + }, + "value": 2, + "raw": "2" + } + ], + "optional": false + } + } + ] + }, + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 888, + "end": 906 + }, + { + "type": "Block", + "value": " c ", + "start": 909, + "end": 916 + } + ] + } + ] + }, + "leadingComments": [ + { + "type": "Line", + "value": " a block comment glued before a frozen argument is owned by it and stays put", + "start": 799, + "end": 877 + } + ] + }, + { + "type": "ExpressionStatement", + "start": 1128, + "end": 1191, + "loc": { + "start": { + "line": 66, + "column": 1 + }, + "end": { + "line": 71, + "column": 3 + } + }, + "expression": { + "type": "NewExpression", + "start": 1128, + "end": 1190, + "loc": { + "start": { + "line": 66, + "column": 1 + }, + "end": { + "line": 71, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 1132, + "end": 1133, + "loc": { + "start": { + "line": 66, + "column": 5 + }, + "end": { + "line": 66, + "column": 6 + } + }, + "name": "A" + }, + "arguments": [ + { + "type": "ObjectExpression", + "start": 1165, + "end": 1175, + "loc": { + "start": { + "line": 69, + "column": 2 + }, + "end": { + "line": 69, + "column": 12 + } + }, + "properties": [ + { + "type": "Property", + "start": 1167, + "end": 1173, + "loc": { + "start": { + "line": 69, + "column": 4 + }, + "end": { + "line": 69, + "column": 10 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 1167, + "end": 1168, + "loc": { + "start": { + "line": 69, + "column": 4 + }, + "end": { + "line": 69, + "column": 5 + } + }, + "name": "a" + }, + "value": { + "type": "Literal", + "start": 1172, + "end": 1173, + "loc": { + "start": { + "line": 69, + "column": 9 + }, + "end": { + "line": 69, + "column": 10 + } + }, + "value": 1, + "raw": "1" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " c", + "start": 1137, + "end": 1141 + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 1144, + "end": 1162 + } + ] + }, + { + "type": "ObjectExpression", + "start": 1179, + "end": 1187, + "loc": { + "start": { + "line": 70, + "column": 2 + }, + "end": { + "line": 70, + "column": 10 + } + }, + "properties": [ + { + "type": "Property", + "start": 1181, + "end": 1185, + "loc": { + "start": { + "line": 70, + "column": 4 + }, + "end": { + "line": 70, + "column": 8 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 1181, + "end": 1182, + "loc": { + "start": { + "line": 70, + "column": 4 + }, + "end": { + "line": 70, + "column": 5 + } + }, + "name": "b" + }, + "value": { + "type": "Literal", + "start": 1184, + "end": 1185, + "loc": { + "start": { + "line": 70, + "column": 7 + }, + "end": { + "line": 70, + "column": 8 + } + }, + "value": 2, + "raw": "2" + }, + "kind": "init" + } + ] + } + ] + }, + "leadingComments": [ + { + "type": "Line", + "value": " an ordinary comment leading the same run keeps the directive on its own line, so", + "start": 955, + "end": 1038 + }, + { + "type": "Line", + "value": " the freeze survives the next pass; the variant authors that comment on the `(` line", + "start": 1040, + "end": 1126 + } + ] + }, + { + "type": "ExpressionStatement", + "start": 1309, + "end": 1366, + "loc": { + "start": { + "line": 75, + "column": 1 + }, + "end": { + "line": 80, + "column": 3 + } + }, + "expression": { + "type": "NewExpression", + "start": 1309, + "end": 1365, + "loc": { + "start": { + "line": 75, + "column": 1 + }, + "end": { + "line": 80, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 1313, + "end": 1314, + "loc": { + "start": { + "line": 75, + "column": 5 + }, + "end": { + "line": 75, + "column": 6 + } + }, + "name": "A" + }, + "arguments": [ + { + "type": "ObjectExpression", + "start": 1339, + "end": 1349, + "loc": { + "start": { + "line": 77, + "column": 2 + }, + "end": { + "line": 77, + "column": 12 + } + }, + "properties": [ + { + "type": "Property", + "start": 1341, + "end": 1347, + "loc": { + "start": { + "line": 77, + "column": 4 + }, + "end": { + "line": 77, + "column": 10 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 1341, + "end": 1342, + "loc": { + "start": { + "line": 77, + "column": 4 + }, + "end": { + "line": 77, + "column": 5 + } + }, + "name": "a" + }, + "value": { + "type": "Literal", + "start": 1346, + "end": 1347, + "loc": { + "start": { + "line": 77, + "column": 9 + }, + "end": { + "line": 77, + "column": 10 + } + }, + "value": 1, + "raw": "1" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 1318, + "end": 1336 + } + ] + }, + { + "type": "ObjectExpression", + "start": 1354, + "end": 1362, + "loc": { + "start": { + "line": 79, + "column": 2 + }, + "end": { + "line": 79, + "column": 10 + } + }, + "properties": [ + { + "type": "Property", + "start": 1356, + "end": 1360, + "loc": { + "start": { + "line": 79, + "column": 4 + }, + "end": { + "line": 79, + "column": 8 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 1356, + "end": 1357, + "loc": { + "start": { + "line": 79, + "column": 4 + }, + "end": { + "line": 79, + "column": 5 + } + }, + "name": "b" + }, + "value": { + "type": "Literal", + "start": 1359, + "end": 1360, + "loc": { + "start": { + "line": 79, + "column": 7 + }, + "end": { + "line": 79, + "column": 8 + } + }, + "value": 2, + "raw": "2" + }, + "kind": "init" + } + ] + } + ] + }, + "leadingComments": [ + { + "type": "Line", + "value": " a frozen FIRST argument followed by an author blank line — the blank-line layout", + "start": 1194, + "end": 1277 + }, + { + "type": "Line", + "value": " owns the leading gap here", + "start": 1279, + "end": 1307 + } + ] + }, + { + "type": "ExpressionStatement", + "start": 1447, + "end": 1494, + "loc": { + "start": { + "line": 83, + "column": 1 + }, + "end": { + "line": 87, + "column": 3 + } + }, + "expression": { + "type": "NewExpression", + "start": 1447, + "end": 1493, + "loc": { + "start": { + "line": 83, + "column": 1 + }, + "end": { + "line": 87, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 1451, + "end": 1452, + "loc": { + "start": { + "line": 83, + "column": 5 + }, + "end": { + "line": 83, + "column": 6 + } + }, + "name": "A" + }, + "arguments": [ + { + "type": "SequenceExpression", + "start": 1478, + "end": 1484, + "loc": { + "start": { + "line": 85, + "column": 3 + }, + "end": { + "line": 85, + "column": 9 + } + }, + "expressions": [ + { + "type": "Literal", + "start": 1478, + "end": 1479, + "loc": { + "start": { + "line": 85, + "column": 3 + }, + "end": { + "line": 85, + "column": 4 + } + }, + "value": 0, + "raw": "0" + }, + { + "type": "Literal", + "start": 1483, + "end": 1484, + "loc": { + "start": { + "line": 85, + "column": 8 + }, + "end": { + "line": 85, + "column": 9 + } + }, + "value": 1, + "raw": "1" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 1456, + "end": 1474 + } + ] + }, + { + "type": "Identifier", + "start": 1489, + "end": 1490, + "loc": { + "start": { + "line": 86, + "column": 2 + }, + "end": { + "line": 86, + "column": 3 + } + }, + "name": "b" + } + ] + }, + "leadingComments": [ + { + "type": "Line", + "value": " a sequence argument keeps its own grouping parens around the frozen slice", + "start": 1369, + "end": 1445 + } + ] + } + ], + "sourceType": "module" + }, + "attributes": [ + { + "type": "Attribute", + "start": 8, + "end": 17, + "name": "lang", + "name_loc": { + "start": { + "line": 1, + "column": 8, + "character": 8 + }, + "end": { + "line": 1, + "column": 12, + "character": 12 + } + }, + "value": [ + { + "start": 14, + "end": 16, + "type": "Text", + "raw": "ts", + "data": "ts" + } + ] + } + ] + } +} diff --git a/tests/fixtures/typescript/expressions/new/args_prettier_ignore_member/input.svelte b/tests/fixtures/typescript/expressions/new/args_prettier_ignore_member/input.svelte new file mode 100644 index 000000000..6be96e707 --- /dev/null +++ b/tests/fixtures/typescript/expressions/new/args_prettier_ignore_member/input.svelte @@ -0,0 +1,88 @@ + diff --git a/tests/fixtures/typescript/expressions/new/args_prettier_ignore_member/unformatted_spaces.svelte b/tests/fixtures/typescript/expressions/new/args_prettier_ignore_member/unformatted_spaces.svelte new file mode 100644 index 000000000..1d93ebad8 --- /dev/null +++ b/tests/fixtures/typescript/expressions/new/args_prettier_ignore_member/unformatted_spaces.svelte @@ -0,0 +1,87 @@ + diff --git a/tests/fixtures/typescript/expressions/new/blank_line_between_args/expected.json b/tests/fixtures/typescript/expressions/new/blank_line_between_args/expected.json index 1b8ee1194..4d5a28869 100644 --- a/tests/fixtures/typescript/expressions/new/blank_line_between_args/expected.json +++ b/tests/fixtures/typescript/expressions/new/blank_line_between_args/expected.json @@ -2,7 +2,7 @@ "css": null, "js": [], "start": 0, - "end": 390, + "end": 604, "type": "Root", "fragment": { "type": "Fragment", @@ -105,24 +105,72 @@ "column": 37 } } + }, + { + "type": "Line", + "value": " Leading comment before the FIRST arg, with a blank line after it: the blank-line", + "start": 382, + "end": 465, + "loc": { + "start": { + "line": 32, + "column": 1 + }, + "end": { + "line": 32, + "column": 84 + } + } + }, + { + "type": "Line", + "value": " layout must emit the `(`→first-argument gap itself or the comment is dropped", + "start": 467, + "end": 546, + "loc": { + "start": { + "line": 33, + "column": 1 + }, + "end": { + "line": 33, + "column": 80 + } + } + }, + { + "type": "Line", + "value": " comment", + "start": 569, + "end": 579, + "loc": { + "start": { + "line": 35, + "column": 2 + }, + "end": { + "line": 35, + "column": 12 + } + } } ], "instance": { "type": "Script", "start": 0, - "end": 389, + "end": 603, "context": "default", "content": { "type": "Program", "start": 8, - "end": 380, + "end": 594, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 31, + "line": 40, "column": 9 } }, @@ -646,6 +694,142 @@ "end": 340 } ] + }, + { + "type": "VariableDeclaration", + "start": 548, + "end": 593, + "loc": { + "start": { + "line": 34, + "column": 1 + }, + "end": { + "line": 39, + "column": 3 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 554, + "end": 592, + "loc": { + "start": { + "line": 34, + "column": 7 + }, + "end": { + "line": 39, + "column": 2 + } + }, + "id": { + "type": "Identifier", + "start": 554, + "end": 555, + "loc": { + "start": { + "line": 34, + "column": 7 + }, + "end": { + "line": 34, + "column": 8 + } + }, + "name": "e" + }, + "init": { + "type": "NewExpression", + "start": 558, + "end": 592, + "loc": { + "start": { + "line": 34, + "column": 11 + }, + "end": { + "line": 39, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 562, + "end": 565, + "loc": { + "start": { + "line": 34, + "column": 15 + }, + "end": { + "line": 34, + "column": 18 + } + }, + "name": "Foo" + }, + "arguments": [ + { + "type": "Identifier", + "start": 582, + "end": 583, + "loc": { + "start": { + "line": 36, + "column": 2 + }, + "end": { + "line": 36, + "column": 3 + } + }, + "name": "x", + "leadingComments": [ + { + "type": "Line", + "value": " comment", + "start": 569, + "end": 579 + } + ] + }, + { + "type": "Identifier", + "start": 588, + "end": 589, + "loc": { + "start": { + "line": 38, + "column": 2 + }, + "end": { + "line": 38, + "column": 3 + } + }, + "name": "y" + } + ] + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "Line", + "value": " Leading comment before the FIRST arg, with a blank line after it: the blank-line", + "start": 382, + "end": 465 + }, + { + "type": "Line", + "value": " layout must emit the `(`→first-argument gap itself or the comment is dropped", + "start": 467, + "end": 546 + } + ] } ], "sourceType": "module" diff --git a/tests/fixtures/typescript/expressions/new/blank_line_between_args/input.svelte b/tests/fixtures/typescript/expressions/new/blank_line_between_args/input.svelte index d12c47ca4..3ffde4cb2 100644 --- a/tests/fixtures/typescript/expressions/new/blank_line_between_args/input.svelte +++ b/tests/fixtures/typescript/expressions/new/blank_line_between_args/input.svelte @@ -28,4 +28,13 @@ z ); + + // Leading comment before the FIRST arg, with a blank line after it: the blank-line + // layout must emit the `(`→first-argument gap itself or the comment is dropped + const e = new Foo( + // comment + x, + + y + ); diff --git a/tests/fixtures/typescript/expressions/new/blank_line_between_args/unformatted_compact.svelte b/tests/fixtures/typescript/expressions/new/blank_line_between_args/unformatted_compact.svelte index 44415b01f..3ff604d37 100644 --- a/tests/fixtures/typescript/expressions/new/blank_line_between_args/unformatted_compact.svelte +++ b/tests/fixtures/typescript/expressions/new/blank_line_between_args/unformatted_compact.svelte @@ -20,4 +20,12 @@ const d = new Foo(x, y, z); + +// Leading comment before the FIRST arg, with a blank line after it: the blank-line +// layout must emit the `(`→first-argument gap itself or the comment is dropped +const e = new Foo( +// comment +x, + +y); diff --git a/tests/fixtures/typescript/expressions/new/sole_arg_own_line_comment/expected.json b/tests/fixtures/typescript/expressions/new/sole_arg_own_line_comment/expected.json new file mode 100644 index 000000000..1bf36b675 --- /dev/null +++ b/tests/fixtures/typescript/expressions/new/sole_arg_own_line_comment/expected.json @@ -0,0 +1,1005 @@ +{ + "css": null, + "js": [], + "start": 0, + "end": 525, + "type": "Root", + "fragment": { + "type": "Fragment", + "nodes": [] + }, + "options": null, + "comments": [ + { + "type": "Line", + "value": " a lone huggable argument with an own-line leading comment expands instead of", + "start": 20, + "end": 99, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 80 + } + } + }, + { + "type": "Line", + "value": " hugging — the hug has no gap emitter, so the comment would be dropped", + "start": 101, + "end": 173, + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 73 + } + } + }, + { + "type": "Line", + "value": " c", + "start": 184, + "end": 188, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 6 + } + } + }, + { + "type": "Line", + "value": " c", + "start": 215, + "end": 219, + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 10, + "column": 6 + } + } + }, + { + "type": "Line", + "value": " c", + "start": 244, + "end": 248, + "loc": { + "start": { + "line": 15, + "column": 2 + }, + "end": { + "line": 15, + "column": 6 + } + } + }, + { + "type": "Line", + "value": " an own-line block comment behaves the same", + "start": 283, + "end": 328, + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 46 + } + } + }, + { + "type": "Block", + "value": " c ", + "start": 339, + "end": 346, + "loc": { + "start": { + "line": 23, + "column": 2 + }, + "end": { + "line": 23, + "column": 9 + } + } + }, + { + "type": "Line", + "value": " a glued block comment is owned by the argument and rides inside its doc, so the", + "start": 364, + "end": 446, + "loc": { + "start": { + "line": 27, + "column": 1 + }, + "end": { + "line": 27, + "column": 83 + } + } + }, + { + "type": "Line", + "value": " hug survives", + "start": 448, + "end": 463, + "loc": { + "start": { + "line": 28, + "column": 1 + }, + "end": { + "line": 28, + "column": 16 + } + } + }, + { + "type": "Block", + "value": " c ", + "start": 471, + "end": 478, + "loc": { + "start": { + "line": 29, + "column": 7 + }, + "end": { + "line": 29, + "column": 14 + } + } + }, + { + "type": "Block", + "value": " c ", + "start": 498, + "end": 505, + "loc": { + "start": { + "line": 31, + "column": 7 + }, + "end": { + "line": 31, + "column": 14 + } + } + } + ], + "instance": { + "type": "Script", + "start": 0, + "end": 524, + "context": "default", + "content": { + "type": "Program", + "start": 18, + "end": 515, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 32, + "column": 9 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 175, + "end": 203, + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 7, + "column": 3 + } + }, + "expression": { + "type": "NewExpression", + "start": 175, + "end": 202, + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 7, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 179, + "end": 180, + "loc": { + "start": { + "line": 4, + "column": 5 + }, + "end": { + "line": 4, + "column": 6 + } + }, + "name": "A" + }, + "arguments": [ + { + "type": "ObjectExpression", + "start": 191, + "end": 199, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 10 + } + }, + "properties": [ + { + "type": "Property", + "start": 193, + "end": 197, + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 8 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 193, + "end": 194, + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 5 + } + }, + "name": "a" + }, + "value": { + "type": "Literal", + "start": 196, + "end": 197, + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 8 + } + }, + "value": 1, + "raw": "1" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " c", + "start": 184, + "end": 188 + } + ] + } + ] + }, + "leadingComments": [ + { + "type": "Line", + "value": " a lone huggable argument with an own-line leading comment expands instead of", + "start": 20, + "end": 99 + }, + { + "type": "Line", + "value": " hugging — the hug has no gap emitter, so the comment would be dropped", + "start": 101, + "end": 173 + } + ] + }, + { + "type": "ExpressionStatement", + "start": 206, + "end": 232, + "loc": { + "start": { + "line": 9, + "column": 1 + }, + "end": { + "line": 12, + "column": 3 + } + }, + "expression": { + "type": "NewExpression", + "start": 206, + "end": 231, + "loc": { + "start": { + "line": 9, + "column": 1 + }, + "end": { + "line": 12, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 210, + "end": 211, + "loc": { + "start": { + "line": 9, + "column": 5 + }, + "end": { + "line": 9, + "column": 6 + } + }, + "name": "A" + }, + "arguments": [ + { + "type": "ArrayExpression", + "start": 222, + "end": 228, + "loc": { + "start": { + "line": 11, + "column": 2 + }, + "end": { + "line": 11, + "column": 8 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 223, + "end": 224, + "loc": { + "start": { + "line": 11, + "column": 3 + }, + "end": { + "line": 11, + "column": 4 + } + }, + "name": "a" + }, + { + "type": "Identifier", + "start": 226, + "end": 227, + "loc": { + "start": { + "line": 11, + "column": 6 + }, + "end": { + "line": 11, + "column": 7 + } + }, + "name": "b" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " c", + "start": 215, + "end": 219 + } + ] + } + ] + } + }, + { + "type": "ExpressionStatement", + "start": 235, + "end": 280, + "loc": { + "start": { + "line": 14, + "column": 1 + }, + "end": { + "line": 19, + "column": 3 + } + }, + "expression": { + "type": "NewExpression", + "start": 235, + "end": 279, + "loc": { + "start": { + "line": 14, + "column": 1 + }, + "end": { + "line": 19, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 239, + "end": 240, + "loc": { + "start": { + "line": 14, + "column": 5 + }, + "end": { + "line": 14, + "column": 6 + } + }, + "name": "A" + }, + "arguments": [ + { + "type": "FunctionExpression", + "start": 251, + "end": 276, + "loc": { + "start": { + "line": 16, + "column": 2 + }, + "end": { + "line": 18, + "column": 3 + } + }, + "id": null, + "expression": false, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 263, + "end": 276, + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 18, + "column": 3 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 268, + "end": 272, + "loc": { + "start": { + "line": 17, + "column": 3 + }, + "end": { + "line": 17, + "column": 7 + } + }, + "expression": { + "type": "CallExpression", + "start": 268, + "end": 271, + "loc": { + "start": { + "line": 17, + "column": 3 + }, + "end": { + "line": 17, + "column": 6 + } + }, + "callee": { + "type": "Identifier", + "start": 268, + "end": 269, + "loc": { + "start": { + "line": 17, + "column": 3 + }, + "end": { + "line": 17, + "column": 4 + } + }, + "name": "a" + }, + "arguments": [], + "optional": false + } + } + ] + }, + "leadingComments": [ + { + "type": "Line", + "value": " c", + "start": 244, + "end": 248 + } + ] + } + ] + } + }, + { + "type": "ExpressionStatement", + "start": 330, + "end": 361, + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 25, + "column": 3 + } + }, + "expression": { + "type": "NewExpression", + "start": 330, + "end": 360, + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 25, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 334, + "end": 335, + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 6 + } + }, + "name": "A" + }, + "arguments": [ + { + "type": "ObjectExpression", + "start": 349, + "end": 357, + "loc": { + "start": { + "line": 24, + "column": 2 + }, + "end": { + "line": 24, + "column": 10 + } + }, + "properties": [ + { + "type": "Property", + "start": 351, + "end": 355, + "loc": { + "start": { + "line": 24, + "column": 4 + }, + "end": { + "line": 24, + "column": 8 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 351, + "end": 352, + "loc": { + "start": { + "line": 24, + "column": 4 + }, + "end": { + "line": 24, + "column": 5 + } + }, + "name": "a" + }, + "value": { + "type": "Literal", + "start": 354, + "end": 355, + "loc": { + "start": { + "line": 24, + "column": 7 + }, + "end": { + "line": 24, + "column": 8 + } + }, + "value": 1, + "raw": "1" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Block", + "value": " c ", + "start": 339, + "end": 346 + } + ] + } + ] + }, + "leadingComments": [ + { + "type": "Line", + "value": " an own-line block comment behaves the same", + "start": 283, + "end": 328 + } + ] + }, + { + "type": "ExpressionStatement", + "start": 465, + "end": 489, + "loc": { + "start": { + "line": 29, + "column": 1 + }, + "end": { + "line": 29, + "column": 25 + } + }, + "expression": { + "type": "NewExpression", + "start": 465, + "end": 488, + "loc": { + "start": { + "line": 29, + "column": 1 + }, + "end": { + "line": 29, + "column": 24 + } + }, + "callee": { + "type": "Identifier", + "start": 469, + "end": 470, + "loc": { + "start": { + "line": 29, + "column": 5 + }, + "end": { + "line": 29, + "column": 6 + } + }, + "name": "A" + }, + "arguments": [ + { + "type": "ObjectExpression", + "start": 479, + "end": 487, + "loc": { + "start": { + "line": 29, + "column": 15 + }, + "end": { + "line": 29, + "column": 23 + } + }, + "properties": [ + { + "type": "Property", + "start": 481, + "end": 485, + "loc": { + "start": { + "line": 29, + "column": 17 + }, + "end": { + "line": 29, + "column": 21 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 481, + "end": 482, + "loc": { + "start": { + "line": 29, + "column": 17 + }, + "end": { + "line": 29, + "column": 18 + } + }, + "name": "a" + }, + "value": { + "type": "Literal", + "start": 484, + "end": 485, + "loc": { + "start": { + "line": 29, + "column": 20 + }, + "end": { + "line": 29, + "column": 21 + } + }, + "value": 1, + "raw": "1" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Block", + "value": " c ", + "start": 471, + "end": 478 + } + ] + } + ] + }, + "leadingComments": [ + { + "type": "Line", + "value": " a glued block comment is owned by the argument and rides inside its doc, so the", + "start": 364, + "end": 446 + }, + { + "type": "Line", + "value": " hug survives", + "start": 448, + "end": 463 + } + ] + }, + { + "type": "ExpressionStatement", + "start": 492, + "end": 514, + "loc": { + "start": { + "line": 31, + "column": 1 + }, + "end": { + "line": 31, + "column": 23 + } + }, + "expression": { + "type": "NewExpression", + "start": 492, + "end": 513, + "loc": { + "start": { + "line": 31, + "column": 1 + }, + "end": { + "line": 31, + "column": 22 + } + }, + "callee": { + "type": "Identifier", + "start": 496, + "end": 497, + "loc": { + "start": { + "line": 31, + "column": 5 + }, + "end": { + "line": 31, + "column": 6 + } + }, + "name": "A" + }, + "arguments": [ + { + "type": "ArrayExpression", + "start": 506, + "end": 512, + "loc": { + "start": { + "line": 31, + "column": 15 + }, + "end": { + "line": 31, + "column": 21 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 507, + "end": 508, + "loc": { + "start": { + "line": 31, + "column": 16 + }, + "end": { + "line": 31, + "column": 17 + } + }, + "name": "a" + }, + { + "type": "Identifier", + "start": 510, + "end": 511, + "loc": { + "start": { + "line": 31, + "column": 19 + }, + "end": { + "line": 31, + "column": 20 + } + }, + "name": "b" + } + ], + "leadingComments": [ + { + "type": "Block", + "value": " c ", + "start": 498, + "end": 505 + } + ] + } + ] + } + } + ], + "sourceType": "module" + }, + "attributes": [ + { + "type": "Attribute", + "start": 8, + "end": 17, + "name": "lang", + "name_loc": { + "start": { + "line": 1, + "column": 8, + "character": 8 + }, + "end": { + "line": 1, + "column": 12, + "character": 12 + } + }, + "value": [ + { + "start": 14, + "end": 16, + "type": "Text", + "raw": "ts", + "data": "ts" + } + ] + } + ] + } +} diff --git a/tests/fixtures/typescript/expressions/new/sole_arg_own_line_comment/input.svelte b/tests/fixtures/typescript/expressions/new/sole_arg_own_line_comment/input.svelte new file mode 100644 index 000000000..92f55f162 --- /dev/null +++ b/tests/fixtures/typescript/expressions/new/sole_arg_own_line_comment/input.svelte @@ -0,0 +1,32 @@ + diff --git a/tests/fixtures/typescript/expressions/new/sole_arg_own_line_comment/unformatted_spaces.svelte b/tests/fixtures/typescript/expressions/new/sole_arg_own_line_comment/unformatted_spaces.svelte new file mode 100644 index 000000000..9869058eb --- /dev/null +++ b/tests/fixtures/typescript/expressions/new/sole_arg_own_line_comment/unformatted_spaces.svelte @@ -0,0 +1,32 @@ + diff --git a/tests/fixtures/typescript/expressions/parenthesized/jsdoc_cast_prettier_ignore_interior/expected.json b/tests/fixtures/typescript/expressions/parenthesized/jsdoc_cast_prettier_ignore_interior/expected.json new file mode 100644 index 000000000..4a98b7697 --- /dev/null +++ b/tests/fixtures/typescript/expressions/parenthesized/jsdoc_cast_prettier_ignore_interior/expected.json @@ -0,0 +1,1161 @@ +{ + "css": null, + "js": [], + "start": 0, + "end": 927, + "type": "Root", + "fragment": { + "type": "Fragment", + "nodes": [] + }, + "options": null, + "comments": [ + { + "type": "Line", + "value": " a directive alone on its line inside a JSDoc cast's own parens freezes the cast's", + "start": 10, + "end": 94, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 85 + } + } + }, + { + "type": "Line", + "value": " inner expression — the cast's comment and parens print around the frozen slice", + "start": 96, + "end": 177, + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 82 + } + } + }, + { + "type": "Block", + "value": "* @type {T} ", + "start": 189, + "end": 205, + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 27 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 210, + "end": 228, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " the block spelling keeps its line here too: a glued directive is inert, so", + "start": 248, + "end": 325, + "loc": { + "start": { + "line": 9, + "column": 1 + }, + "end": { + "line": 9, + "column": 78 + } + } + }, + { + "type": "Line", + "value": " collapsing it inline would lose the freeze on the next pass", + "start": 327, + "end": 389, + "loc": { + "start": { + "line": 10, + "column": 1 + }, + "end": { + "line": 10, + "column": 63 + } + } + }, + { + "type": "Block", + "value": "* @type {T} ", + "start": 401, + "end": 417, + "loc": { + "start": { + "line": 11, + "column": 11 + }, + "end": { + "line": 11, + "column": 27 + } + } + }, + { + "type": "Block", + "value": " prettier-ignore ", + "start": 422, + "end": 443, + "loc": { + "start": { + "line": 12, + "column": 2 + }, + "end": { + "line": 12, + "column": 23 + } + } + }, + { + "type": "Line", + "value": " as a call argument — the position the ignore ledger keys this on", + "start": 463, + "end": 530, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 68 + } + } + }, + { + "type": "Block", + "value": "* @type {T} ", + "start": 546, + "end": 562, + "loc": { + "start": { + "line": 19, + "column": 2 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 568, + "end": 586, + "loc": { + "start": { + "line": 20, + "column": 3 + }, + "end": { + "line": 20, + "column": 21 + } + } + }, + { + "type": "Line", + "value": " an ordinary own-line comment in the same gap still collapses inline (no freeze,", + "start": 612, + "end": 694, + "loc": { + "start": { + "line": 25, + "column": 1 + }, + "end": { + "line": 25, + "column": 83 + } + } + }, + { + "type": "Line", + "value": " nothing to preserve)", + "start": 696, + "end": 719, + "loc": { + "start": { + "line": 26, + "column": 1 + }, + "end": { + "line": 26, + "column": 24 + } + } + }, + { + "type": "Block", + "value": "* @type {T} ", + "start": 731, + "end": 747, + "loc": { + "start": { + "line": 27, + "column": 11 + }, + "end": { + "line": 27, + "column": 27 + } + } + }, + { + "type": "Block", + "value": " c ", + "start": 749, + "end": 756, + "loc": { + "start": { + "line": 27, + "column": 29 + }, + "end": { + "line": 27, + "column": 36 + } + } + }, + { + "type": "Line", + "value": " a block comment glued before the inner is owned by it and stays put", + "start": 770, + "end": 840, + "loc": { + "start": { + "line": 29, + "column": 1 + }, + "end": { + "line": 29, + "column": 71 + } + } + }, + { + "type": "Block", + "value": "* @type {T} ", + "start": 852, + "end": 868, + "loc": { + "start": { + "line": 30, + "column": 11 + }, + "end": { + "line": 30, + "column": 27 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 873, + "end": 891, + "loc": { + "start": { + "line": 31, + "column": 2 + }, + "end": { + "line": 31, + "column": 20 + } + } + }, + { + "type": "Block", + "value": " c ", + "start": 894, + "end": 901, + "loc": { + "start": { + "line": 32, + "column": 2 + }, + "end": { + "line": 32, + "column": 9 + } + } + } + ], + "instance": { + "type": "Script", + "start": 0, + "end": 926, + "context": "default", + "content": { + "type": "Program", + "start": 8, + "end": 917, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 34, + "column": 9 + } + }, + "body": [ + { + "type": "VariableDeclaration", + "start": 179, + "end": 245, + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 7, + "column": 3 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 185, + "end": 244, + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 7, + "column": 2 + } + }, + "id": { + "type": "Identifier", + "start": 185, + "end": 186, + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 8 + } + }, + "name": "a" + }, + "init": { + "type": "CallExpression", + "start": 231, + "end": 241, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 12 + } + }, + "callee": { + "type": "Identifier", + "start": 231, + "end": 233, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 4 + } + }, + "name": "fn" + }, + "arguments": [ + { + "type": "Literal", + "start": 234, + "end": 235, + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 6 + } + }, + "value": 1, + "raw": "1" + }, + { + "type": "Literal", + "start": 239, + "end": 240, + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 11 + } + }, + "value": 2, + "raw": "2" + } + ], + "optional": false, + "leadingComments": [ + { + "type": "Block", + "value": "* @type {T} ", + "start": 189, + "end": 205 + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 210, + "end": 228 + } + ] + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "Line", + "value": " a directive alone on its line inside a JSDoc cast's own parens freezes the cast's", + "start": 10, + "end": 94 + }, + { + "type": "Line", + "value": " inner expression — the cast's comment and parens print around the frozen slice", + "start": 96, + "end": 177 + } + ] + }, + { + "type": "VariableDeclaration", + "start": 391, + "end": 460, + "loc": { + "start": { + "line": 11, + "column": 1 + }, + "end": { + "line": 14, + "column": 3 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 397, + "end": 459, + "loc": { + "start": { + "line": 11, + "column": 7 + }, + "end": { + "line": 14, + "column": 2 + } + }, + "id": { + "type": "Identifier", + "start": 397, + "end": 398, + "loc": { + "start": { + "line": 11, + "column": 7 + }, + "end": { + "line": 11, + "column": 8 + } + }, + "name": "b" + }, + "init": { + "type": "CallExpression", + "start": 446, + "end": 456, + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 12 + } + }, + "callee": { + "type": "Identifier", + "start": 446, + "end": 448, + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 4 + } + }, + "name": "fn" + }, + "arguments": [ + { + "type": "Literal", + "start": 449, + "end": 450, + "loc": { + "start": { + "line": 13, + "column": 5 + }, + "end": { + "line": 13, + "column": 6 + } + }, + "value": 1, + "raw": "1" + }, + { + "type": "Literal", + "start": 454, + "end": 455, + "loc": { + "start": { + "line": 13, + "column": 10 + }, + "end": { + "line": 13, + "column": 11 + } + }, + "value": 2, + "raw": "2" + } + ], + "optional": false, + "leadingComments": [ + { + "type": "Block", + "value": "* @type {T} ", + "start": 401, + "end": 417 + }, + { + "type": "Block", + "value": " prettier-ignore ", + "start": 422, + "end": 443 + } + ] + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "Line", + "value": " the block spelling keeps its line here too: a glued directive is inert, so", + "start": 248, + "end": 325 + }, + { + "type": "Line", + "value": " collapsing it inline would lose the freeze on the next pass", + "start": 327, + "end": 389 + } + ] + }, + { + "type": "ExpressionStatement", + "start": 532, + "end": 609, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 23, + "column": 3 + } + }, + "expression": { + "type": "CallExpression", + "start": 532, + "end": 608, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 23, + "column": 2 + } + }, + "callee": { + "type": "MemberExpression", + "start": 532, + "end": 535, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 4 + } + }, + "object": { + "type": "Identifier", + "start": 532, + "end": 533, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 2 + } + }, + "name": "c" + }, + "property": { + "type": "Identifier", + "start": 534, + "end": 535, + "loc": { + "start": { + "line": 17, + "column": 3 + }, + "end": { + "line": 17, + "column": 4 + } + }, + "name": "d" + }, + "computed": false, + "optional": false + }, + "arguments": [ + { + "type": "ArrayExpression", + "start": 539, + "end": 542, + "loc": { + "start": { + "line": 18, + "column": 2 + }, + "end": { + "line": 18, + "column": 5 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 540, + "end": 541, + "loc": { + "start": { + "line": 18, + "column": 3 + }, + "end": { + "line": 18, + "column": 4 + } + }, + "name": "e" + } + ] + }, + { + "type": "CallExpression", + "start": 590, + "end": 601, + "loc": { + "start": { + "line": 21, + "column": 3 + }, + "end": { + "line": 21, + "column": 14 + } + }, + "callee": { + "type": "MemberExpression", + "start": 590, + "end": 593, + "loc": { + "start": { + "line": 21, + "column": 3 + }, + "end": { + "line": 21, + "column": 6 + } + }, + "object": { + "type": "Identifier", + "start": 590, + "end": 591, + "loc": { + "start": { + "line": 21, + "column": 3 + }, + "end": { + "line": 21, + "column": 4 + } + }, + "name": "f" + }, + "property": { + "type": "Identifier", + "start": 592, + "end": 593, + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 21, + "column": 6 + } + }, + "name": "g" + }, + "computed": false, + "optional": false + }, + "arguments": [ + { + "type": "Literal", + "start": 594, + "end": 595, + "loc": { + "start": { + "line": 21, + "column": 7 + }, + "end": { + "line": 21, + "column": 8 + } + }, + "value": 1, + "raw": "1" + }, + { + "type": "Literal", + "start": 599, + "end": 600, + "loc": { + "start": { + "line": 21, + "column": 12 + }, + "end": { + "line": 21, + "column": 13 + } + }, + "value": 2, + "raw": "2" + } + ], + "optional": false, + "leadingComments": [ + { + "type": "Block", + "value": "* @type {T} ", + "start": 546, + "end": 562 + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 568, + "end": 586 + } + ] + } + ], + "optional": false + }, + "leadingComments": [ + { + "type": "Line", + "value": " as a call argument — the position the ignore ledger keys this on", + "start": 463, + "end": 530 + } + ] + }, + { + "type": "VariableDeclaration", + "start": 721, + "end": 767, + "loc": { + "start": { + "line": 27, + "column": 1 + }, + "end": { + "line": 27, + "column": 47 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 727, + "end": 766, + "loc": { + "start": { + "line": 27, + "column": 7 + }, + "end": { + "line": 27, + "column": 46 + } + }, + "id": { + "type": "Identifier", + "start": 727, + "end": 728, + "loc": { + "start": { + "line": 27, + "column": 7 + }, + "end": { + "line": 27, + "column": 8 + } + }, + "name": "h" + }, + "init": { + "type": "CallExpression", + "start": 757, + "end": 765, + "loc": { + "start": { + "line": 27, + "column": 37 + }, + "end": { + "line": 27, + "column": 45 + } + }, + "callee": { + "type": "Identifier", + "start": 757, + "end": 759, + "loc": { + "start": { + "line": 27, + "column": 37 + }, + "end": { + "line": 27, + "column": 39 + } + }, + "name": "fn" + }, + "arguments": [ + { + "type": "Literal", + "start": 760, + "end": 761, + "loc": { + "start": { + "line": 27, + "column": 40 + }, + "end": { + "line": 27, + "column": 41 + } + }, + "value": 1, + "raw": "1" + }, + { + "type": "Literal", + "start": 763, + "end": 764, + "loc": { + "start": { + "line": 27, + "column": 43 + }, + "end": { + "line": 27, + "column": 44 + } + }, + "value": 2, + "raw": "2" + } + ], + "optional": false, + "leadingComments": [ + { + "type": "Block", + "value": "* @type {T} ", + "start": 731, + "end": 747 + }, + { + "type": "Block", + "value": " c ", + "start": 749, + "end": 756 + } + ] + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "Line", + "value": " an ordinary own-line comment in the same gap still collapses inline (no freeze,", + "start": 612, + "end": 694 + }, + { + "type": "Line", + "value": " nothing to preserve)", + "start": 696, + "end": 719 + } + ] + }, + { + "type": "VariableDeclaration", + "start": 842, + "end": 916, + "loc": { + "start": { + "line": 30, + "column": 1 + }, + "end": { + "line": 33, + "column": 3 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 848, + "end": 915, + "loc": { + "start": { + "line": 30, + "column": 7 + }, + "end": { + "line": 33, + "column": 2 + } + }, + "id": { + "type": "Identifier", + "start": 848, + "end": 849, + "loc": { + "start": { + "line": 30, + "column": 7 + }, + "end": { + "line": 30, + "column": 8 + } + }, + "name": "i" + }, + "init": { + "type": "CallExpression", + "start": 902, + "end": 912, + "loc": { + "start": { + "line": 32, + "column": 10 + }, + "end": { + "line": 32, + "column": 20 + } + }, + "callee": { + "type": "Identifier", + "start": 902, + "end": 904, + "loc": { + "start": { + "line": 32, + "column": 10 + }, + "end": { + "line": 32, + "column": 12 + } + }, + "name": "fn" + }, + "arguments": [ + { + "type": "Literal", + "start": 905, + "end": 906, + "loc": { + "start": { + "line": 32, + "column": 13 + }, + "end": { + "line": 32, + "column": 14 + } + }, + "value": 1, + "raw": "1" + }, + { + "type": "Literal", + "start": 910, + "end": 911, + "loc": { + "start": { + "line": 32, + "column": 18 + }, + "end": { + "line": 32, + "column": 19 + } + }, + "value": 2, + "raw": "2" + } + ], + "optional": false, + "leadingComments": [ + { + "type": "Block", + "value": "* @type {T} ", + "start": 852, + "end": 868 + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 873, + "end": 891 + }, + { + "type": "Block", + "value": " c ", + "start": 894, + "end": 901 + } + ] + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "Line", + "value": " a block comment glued before the inner is owned by it and stays put", + "start": 770, + "end": 840 + } + ] + } + ], + "sourceType": "module" + }, + "attributes": [] + } +} diff --git a/tests/fixtures/typescript/expressions/parenthesized/jsdoc_cast_prettier_ignore_interior/input.svelte b/tests/fixtures/typescript/expressions/parenthesized/jsdoc_cast_prettier_ignore_interior/input.svelte new file mode 100644 index 000000000..3f0e3b58b --- /dev/null +++ b/tests/fixtures/typescript/expressions/parenthesized/jsdoc_cast_prettier_ignore_interior/input.svelte @@ -0,0 +1,34 @@ + diff --git a/tests/fixtures/typescript/expressions/parenthesized/jsdoc_cast_prettier_ignore_interior/unformatted_spaces.svelte b/tests/fixtures/typescript/expressions/parenthesized/jsdoc_cast_prettier_ignore_interior/unformatted_spaces.svelte new file mode 100644 index 000000000..cce6b59ec --- /dev/null +++ b/tests/fixtures/typescript/expressions/parenthesized/jsdoc_cast_prettier_ignore_interior/unformatted_spaces.svelte @@ -0,0 +1,34 @@ + diff --git a/tests/fixtures/typescript/expressions/patterns/prettier_ignore_element/expected.json b/tests/fixtures/typescript/expressions/patterns/prettier_ignore_element/expected.json new file mode 100644 index 000000000..b1c255578 --- /dev/null +++ b/tests/fixtures/typescript/expressions/patterns/prettier_ignore_element/expected.json @@ -0,0 +1,1311 @@ +{ + "css": null, + "js": [], + "start": 0, + "end": 745, + "type": "Root", + "fragment": { + "type": "Fragment", + "nodes": [] + }, + "options": null, + "comments": [ + { + "type": "Line", + "value": " an own-line directive in an array-pattern element gap freezes only that element", + "start": 20, + "end": 102, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 83 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 127, + "end": 145, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " before the first element", + "start": 178, + "end": 205, + "loc": { + "start": { + "line": 10, + "column": 1 + }, + "end": { + "line": 10, + "column": 28 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 217, + "end": 235, + "loc": { + "start": { + "line": 12, + "column": 2 + }, + "end": { + "line": 12, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " an own-line block comment behaves identically", + "start": 268, + "end": 316, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 49 + } + } + }, + { + "type": "Block", + "value": " prettier-ignore ", + "start": 328, + "end": 349, + "loc": { + "start": { + "line": 19, + "column": 2 + }, + "end": { + "line": 19, + "column": 23 + } + } + }, + { + "type": "Line", + "value": " a rest element rides inside the frozen slice", + "start": 382, + "end": 429, + "loc": { + "start": { + "line": 24, + "column": 1 + }, + "end": { + "line": 24, + "column": 48 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 447, + "end": 465, + "loc": { + "start": { + "line": 27, + "column": 2 + }, + "end": { + "line": 27, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " a destructuring parameter host", + "start": 490, + "end": 523, + "loc": { + "start": { + "line": 31, + "column": 1 + }, + "end": { + "line": 31, + "column": 34 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 541, + "end": 559, + "loc": { + "start": { + "line": 33, + "column": 2 + }, + "end": { + "line": 33, + "column": 20 + } + } + }, + { + "type": "Line", + "value": " a block comment glued before a frozen element is owned by it and stays put", + "start": 589, + "end": 666, + "loc": { + "start": { + "line": 38, + "column": 1 + }, + "end": { + "line": 38, + "column": 78 + } + } + }, + { + "type": "Line", + "value": " prettier-ignore", + "start": 678, + "end": 696, + "loc": { + "start": { + "line": 40, + "column": 2 + }, + "end": { + "line": 40, + "column": 20 + } + } + }, + { + "type": "Block", + "value": " c ", + "start": 699, + "end": 706, + "loc": { + "start": { + "line": 41, + "column": 2 + }, + "end": { + "line": 41, + "column": 9 + } + } + } + ], + "instance": { + "type": "Script", + "start": 0, + "end": 744, + "context": "default", + "content": { + "type": "Program", + "start": 18, + "end": 735, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 44, + "column": 9 + } + }, + "body": [ + { + "type": "VariableDeclaration", + "start": 104, + "end": 175, + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 8, + "column": 9 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 110, + "end": 174, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 8, + "column": 8 + } + }, + "id": { + "type": "ArrayPattern", + "start": 110, + "end": 168, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 8, + "column": 2 + } + }, + "elements": [ + { + "type": "ObjectPattern", + "start": 114, + "end": 123, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 11 + } + }, + "properties": [ + { + "type": "Property", + "start": 116, + "end": 121, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 9 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 116, + "end": 117, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 5 + } + }, + "name": "a" + }, + "value": { + "type": "Identifier", + "start": 119, + "end": 121, + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 9 + } + }, + "name": "a1" + }, + "kind": "init" + } + ] + }, + { + "type": "ObjectPattern", + "start": 148, + "end": 159, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 13 + } + }, + "properties": [ + { + "type": "Property", + "start": 150, + "end": 157, + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 11 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 150, + "end": 151, + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 5 + } + }, + "name": "b" + }, + "value": { + "type": "Identifier", + "start": 155, + "end": 157, + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 6, + "column": 11 + } + }, + "name": "b1" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 127, + "end": 145 + } + ] + }, + { + "type": "Identifier", + "start": 163, + "end": 165, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 4 + } + }, + "name": "c1" + } + ] + }, + "init": { + "type": "Identifier", + "start": 171, + "end": 174, + "loc": { + "start": { + "line": 8, + "column": 5 + }, + "end": { + "line": 8, + "column": 8 + } + }, + "name": "arr" + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "Line", + "value": " an own-line directive in an array-pattern element gap freezes only that element", + "start": 20, + "end": 102 + } + ] + }, + { + "type": "VariableDeclaration", + "start": 207, + "end": 265, + "loc": { + "start": { + "line": 11, + "column": 1 + }, + "end": { + "line": 15, + "column": 9 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 213, + "end": 264, + "loc": { + "start": { + "line": 11, + "column": 7 + }, + "end": { + "line": 15, + "column": 8 + } + }, + "id": { + "type": "ArrayPattern", + "start": 213, + "end": 258, + "loc": { + "start": { + "line": 11, + "column": 7 + }, + "end": { + "line": 15, + "column": 2 + } + }, + "elements": [ + { + "type": "ObjectPattern", + "start": 238, + "end": 249, + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 13 + } + }, + "properties": [ + { + "type": "Property", + "start": 240, + "end": 247, + "loc": { + "start": { + "line": 13, + "column": 4 + }, + "end": { + "line": 13, + "column": 11 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 240, + "end": 241, + "loc": { + "start": { + "line": 13, + "column": 4 + }, + "end": { + "line": 13, + "column": 5 + } + }, + "name": "a" + }, + "value": { + "type": "Identifier", + "start": 245, + "end": 247, + "loc": { + "start": { + "line": 13, + "column": 9 + }, + "end": { + "line": 13, + "column": 11 + } + }, + "name": "a2" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 217, + "end": 235 + } + ] + }, + { + "type": "Identifier", + "start": 253, + "end": 255, + "loc": { + "start": { + "line": 14, + "column": 2 + }, + "end": { + "line": 14, + "column": 4 + } + }, + "name": "b2" + } + ] + }, + "init": { + "type": "Identifier", + "start": 261, + "end": 264, + "loc": { + "start": { + "line": 15, + "column": 5 + }, + "end": { + "line": 15, + "column": 8 + } + }, + "name": "arr" + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "Line", + "value": " before the first element", + "start": 178, + "end": 205 + } + ] + }, + { + "type": "VariableDeclaration", + "start": 318, + "end": 379, + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 22, + "column": 9 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 324, + "end": 378, + "loc": { + "start": { + "line": 18, + "column": 7 + }, + "end": { + "line": 22, + "column": 8 + } + }, + "id": { + "type": "ArrayPattern", + "start": 324, + "end": 372, + "loc": { + "start": { + "line": 18, + "column": 7 + }, + "end": { + "line": 22, + "column": 2 + } + }, + "elements": [ + { + "type": "ObjectPattern", + "start": 352, + "end": 363, + "loc": { + "start": { + "line": 20, + "column": 2 + }, + "end": { + "line": 20, + "column": 13 + } + }, + "properties": [ + { + "type": "Property", + "start": 354, + "end": 361, + "loc": { + "start": { + "line": 20, + "column": 4 + }, + "end": { + "line": 20, + "column": 11 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 354, + "end": 355, + "loc": { + "start": { + "line": 20, + "column": 4 + }, + "end": { + "line": 20, + "column": 5 + } + }, + "name": "a" + }, + "value": { + "type": "Identifier", + "start": 359, + "end": 361, + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 20, + "column": 11 + } + }, + "name": "a3" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Block", + "value": " prettier-ignore ", + "start": 328, + "end": 349 + } + ] + }, + { + "type": "Identifier", + "start": 367, + "end": 369, + "loc": { + "start": { + "line": 21, + "column": 2 + }, + "end": { + "line": 21, + "column": 4 + } + }, + "name": "b3" + } + ] + }, + "init": { + "type": "Identifier", + "start": 375, + "end": 378, + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 8 + } + }, + "name": "arr" + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "Line", + "value": " an own-line block comment behaves identically", + "start": 268, + "end": 316 + } + ] + }, + { + "type": "VariableDeclaration", + "start": 431, + "end": 487, + "loc": { + "start": { + "line": 25, + "column": 1 + }, + "end": { + "line": 29, + "column": 9 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 437, + "end": 486, + "loc": { + "start": { + "line": 25, + "column": 7 + }, + "end": { + "line": 29, + "column": 8 + } + }, + "id": { + "type": "ArrayPattern", + "start": 437, + "end": 480, + "loc": { + "start": { + "line": 25, + "column": 7 + }, + "end": { + "line": 29, + "column": 2 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 441, + "end": 443, + "loc": { + "start": { + "line": 26, + "column": 2 + }, + "end": { + "line": 26, + "column": 4 + } + }, + "name": "a4" + }, + { + "type": "RestElement", + "start": 468, + "end": 477, + "loc": { + "start": { + "line": 28, + "column": 2 + }, + "end": { + "line": 28, + "column": 11 + } + }, + "argument": { + "type": "Identifier", + "start": 473, + "end": 477, + "loc": { + "start": { + "line": 28, + "column": 7 + }, + "end": { + "line": 28, + "column": 11 + } + }, + "name": "rest" + }, + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 447, + "end": 465 + } + ] + } + ] + }, + "init": { + "type": "Identifier", + "start": 483, + "end": 486, + "loc": { + "start": { + "line": 29, + "column": 5 + }, + "end": { + "line": 29, + "column": 8 + } + }, + "name": "arr" + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "Line", + "value": " a rest element rides inside the frozen slice", + "start": 382, + "end": 429 + } + ] + }, + { + "type": "FunctionDeclaration", + "start": 525, + "end": 586, + "loc": { + "start": { + "line": 32, + "column": 1 + }, + "end": { + "line": 36, + "column": 6 + } + }, + "id": { + "type": "Identifier", + "start": 534, + "end": 536, + "loc": { + "start": { + "line": 32, + "column": 10 + }, + "end": { + "line": 32, + "column": 12 + } + }, + "name": "fn" + }, + "expression": false, + "generator": false, + "async": false, + "params": [ + { + "type": "ArrayPattern", + "start": 537, + "end": 582, + "loc": { + "start": { + "line": 32, + "column": 13 + }, + "end": { + "line": 36, + "column": 2 + } + }, + "elements": [ + { + "type": "ObjectPattern", + "start": 562, + "end": 573, + "loc": { + "start": { + "line": 34, + "column": 2 + }, + "end": { + "line": 34, + "column": 13 + } + }, + "properties": [ + { + "type": "Property", + "start": 564, + "end": 571, + "loc": { + "start": { + "line": 34, + "column": 4 + }, + "end": { + "line": 34, + "column": 11 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 564, + "end": 565, + "loc": { + "start": { + "line": 34, + "column": 4 + }, + "end": { + "line": 34, + "column": 5 + } + }, + "name": "a" + }, + "value": { + "type": "Identifier", + "start": 569, + "end": 571, + "loc": { + "start": { + "line": 34, + "column": 9 + }, + "end": { + "line": 34, + "column": 11 + } + }, + "name": "a5" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 541, + "end": 559 + } + ] + }, + { + "type": "Identifier", + "start": 577, + "end": 579, + "loc": { + "start": { + "line": 35, + "column": 2 + }, + "end": { + "line": 35, + "column": 4 + } + }, + "name": "b5" + } + ] + } + ], + "body": { + "type": "BlockStatement", + "start": 584, + "end": 586, + "loc": { + "start": { + "line": 36, + "column": 4 + }, + "end": { + "line": 36, + "column": 6 + } + }, + "body": [] + }, + "leadingComments": [ + { + "type": "Line", + "value": " a destructuring parameter host", + "start": 490, + "end": 523 + } + ] + }, + { + "type": "VariableDeclaration", + "start": 668, + "end": 734, + "loc": { + "start": { + "line": 39, + "column": 1 + }, + "end": { + "line": 43, + "column": 9 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 674, + "end": 733, + "loc": { + "start": { + "line": 39, + "column": 7 + }, + "end": { + "line": 43, + "column": 8 + } + }, + "id": { + "type": "ArrayPattern", + "start": 674, + "end": 727, + "loc": { + "start": { + "line": 39, + "column": 7 + }, + "end": { + "line": 43, + "column": 2 + } + }, + "elements": [ + { + "type": "ObjectPattern", + "start": 707, + "end": 718, + "loc": { + "start": { + "line": 41, + "column": 10 + }, + "end": { + "line": 41, + "column": 21 + } + }, + "properties": [ + { + "type": "Property", + "start": 709, + "end": 716, + "loc": { + "start": { + "line": 41, + "column": 12 + }, + "end": { + "line": 41, + "column": 19 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 709, + "end": 710, + "loc": { + "start": { + "line": 41, + "column": 12 + }, + "end": { + "line": 41, + "column": 13 + } + }, + "name": "a" + }, + "value": { + "type": "Identifier", + "start": 714, + "end": 716, + "loc": { + "start": { + "line": 41, + "column": 17 + }, + "end": { + "line": 41, + "column": 19 + } + }, + "name": "a6" + }, + "kind": "init" + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " prettier-ignore", + "start": 678, + "end": 696 + }, + { + "type": "Block", + "value": " c ", + "start": 699, + "end": 706 + } + ] + }, + { + "type": "Identifier", + "start": 722, + "end": 724, + "loc": { + "start": { + "line": 42, + "column": 2 + }, + "end": { + "line": 42, + "column": 4 + } + }, + "name": "b6" + } + ] + }, + "init": { + "type": "Identifier", + "start": 730, + "end": 733, + "loc": { + "start": { + "line": 43, + "column": 5 + }, + "end": { + "line": 43, + "column": 8 + } + }, + "name": "arr" + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "Line", + "value": " a block comment glued before a frozen element is owned by it and stays put", + "start": 589, + "end": 666 + } + ] + } + ], + "sourceType": "module" + }, + "attributes": [ + { + "type": "Attribute", + "start": 8, + "end": 17, + "name": "lang", + "name_loc": { + "start": { + "line": 1, + "column": 8, + "character": 8 + }, + "end": { + "line": 1, + "column": 12, + "character": 12 + } + }, + "value": [ + { + "start": 14, + "end": 16, + "type": "Text", + "raw": "ts", + "data": "ts" + } + ] + } + ] + } +} diff --git a/tests/fixtures/typescript/expressions/patterns/prettier_ignore_element/input.svelte b/tests/fixtures/typescript/expressions/patterns/prettier_ignore_element/input.svelte new file mode 100644 index 000000000..54fb4a76a --- /dev/null +++ b/tests/fixtures/typescript/expressions/patterns/prettier_ignore_element/input.svelte @@ -0,0 +1,44 @@ + diff --git a/tests/fixtures/typescript/expressions/patterns/prettier_ignore_element/unformatted_spaces.svelte b/tests/fixtures/typescript/expressions/patterns/prettier_ignore_element/unformatted_spaces.svelte new file mode 100644 index 000000000..65320db27 --- /dev/null +++ b/tests/fixtures/typescript/expressions/patterns/prettier_ignore_element/unformatted_spaces.svelte @@ -0,0 +1,44 @@ +