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 52b12318..e3c8e203 100644 --- a/crates/tsv_debug/src/cli/commands/gap_audit_known.txt +++ b/crates/tsv_debug/src/cli/commands/gap_audit_known.txt @@ -227,6 +227,7 @@ DROPPED :⟨⟩{ annotation,block,jsdoc_cast,multiline DROPPED :⟨⟩␣ annotation,block,jsdoc_cast,multiline DROPPED ;#⟨⟩IDENT annotation,block,jsdoc_cast,line,multiline DROPPED ;}⟨⟩} annotation,block,jsdoc_cast,line,multiline +DROPPED <&⟨⟩␣ line DROPPED <-⟨⟩NUM annotation,block,jsdoc_cast,line,multiline DROPPED <⟨⟩IDENT annotation,block,jsdoc_cast,multiline DROPPED <⟨⟩const annotation,block,jsdoc_cast,multiline diff --git a/crates/tsv_ts/src/parser/expression_type_args.rs b/crates/tsv_ts/src/parser/expression_type_args.rs index 118820f3..12400df0 100644 --- a/crates/tsv_ts/src/parser/expression_type_args.rs +++ b/crates/tsv_ts/src/parser/expression_type_args.rs @@ -84,6 +84,14 @@ impl<'a, 'arena> Parser<'a, 'arena> { // whole literal to its follow-token. b'0'..=b'9' | b'-' => scan_for_closing_angle_bracket(bytes, pos), + // A leading `|`/`&` on the first union/intersection member + // (`f<| A | B>()`, `f<& A & B>()`) — the form prettier itself emits + // whenever such a type argument breaks across lines. Neither byte can + // start an expression, so a `<` followed by one is never a comparison; + // the closing-`>` + follow-token scan still runs, as in every other arm, + // so an unterminated `<` stays unclaimed. + b'|' | b'&' => scan_for_closing_angle_bracket(bytes, pos), + // Not a recognized type argument start _ => false, } diff --git a/crates/tsv_ts/src/printer/types/composite.rs b/crates/tsv_ts/src/printer/types/composite.rs index ca47ad7e..aa60ae5f 100644 --- a/crates/tsv_ts/src/printer/types/composite.rs +++ b/crates/tsv_ts/src/printer/types/composite.rs @@ -10,9 +10,8 @@ use super::super::comments_to_emit_in_range; use super::helpers::{ - should_hug_union_type, type_needs_parens_for_array_element, - type_needs_parens_for_conditional_check, type_needs_parens_for_conditional_extends, - unwrap_parenthesized, + type_needs_parens_for_array_element, type_needs_parens_for_conditional_check, + type_needs_parens_for_conditional_extends, unwrap_parenthesized, }; use super::{CommentSpacing, Printer}; use crate::ast::internal::{ @@ -199,7 +198,10 @@ impl<'a> Printer<'a> { fn build_conditional_check_doc(&self, check: &TSType<'_>) -> DocId { let d = self.d(); match self.unwrap_redundant_parens(check) { - TSType::Union(u) if !should_hug_union_type(u) => { + // `union_prints_hugged`, not the bare syntactic `union_hug_shape`: a comment + // that makes the printer expand the members must make this gate hang too, or + // `extends` keeps its operand glued while they explode below it. + TSType::Union(u) if !self.union_prints_hugged(u) => { let union_doc = self.build_union_type_doc(u); d.group(d.indent(d.concat(&[d.softline(), union_doc]))) } @@ -269,7 +271,10 @@ impl<'a> Printer<'a> { } }; match self.unwrap_redundant_parens(branch_type) { - TSType::Union(u) if !should_hug_union_type(u) => { + // `union_prints_hugged`, not the bare syntactic `union_hug_shape` — see + // `build_conditional_check_doc`; here a bare ask left the members one indent + // level short of prettier's. + TSType::Union(u) if !self.union_prints_hugged(u) => { // `build_union_type_doc` already returns `group(members)` (the bare // `printed`); the branch supplies only one `indent`, so the member // group breaks its continuations one level past the operator. @@ -768,13 +773,15 @@ impl<'a> Printer<'a> { match self.unwrap_redundant_parens(type_ann) { TSType::Union(u) => { let type_doc = self.build_union_type_doc(u); - // A hugging union (`{ ... } | null`) without forcing line comments - // keeps its inline `: ` since the object owns its own expansion; - // everything else hangs after `:` so it breaks to leading `| ` - // instead of gluing (line comments between members force multiline). - if should_hug_union_type(u) - && !self.union_has_line_comments_between_members(u) - { + // A hugging union (`{ ... } | null`) keeps its inline `: ` since the + // object owns its own expansion; everything else hangs after `:` so + // it breaks to leading `| ` instead of gluing. `union_prints_hugged` + // owns that question whole — this site used to pair the bare + // syntactic shape with its own NARROWER comment scan (line comments + // between members only), which let a block comment between members, + // or a line comment in the leading `|`→first-member gap, read as + // "hug" while the printer expanded them. + if self.union_prints_hugged(u) { body_parts.push(d.text(" ")); body_parts.push(type_doc); } else { diff --git a/crates/tsv_ts/src/printer/types/function_types.rs b/crates/tsv_ts/src/printer/types/function_types.rs index 529ca90c..0adf9191 100644 --- a/crates/tsv_ts/src/printer/types/function_types.rs +++ b/crates/tsv_ts/src/printer/types/function_types.rs @@ -190,7 +190,7 @@ impl<'a> Printer<'a> { // NOT hugged (the sanctioned `return_type_generic_union` print-width // family), and a member/gap comment disqualifies the hug — those fall // through to the break-after-operator layout that matches prettier there. - if self.union_return_hugs(value_type, u, arrow_end, type_start) { + if self.union_return_hugs(value_type, arrow_end, type_start) { return joined(d.text(arrow_sp), type_doc); } let hung = match comments_doc { diff --git a/crates/tsv_ts/src/printer/types/helpers.rs b/crates/tsv_ts/src/printer/types/helpers.rs index bab76678..123cdfa5 100644 --- a/crates/tsv_ts/src/printer/types/helpers.rs +++ b/crates/tsv_ts/src/printer/types/helpers.rs @@ -96,18 +96,25 @@ pub fn is_simple_type_arg(ty: &TSType<'_>) -> bool { || matches!(unwrapped, TSType::TypeReference(r) if r.type_arguments.is_none()) } -/// Prettier's `shouldHugUnionType` criterion for a single type argument: a union with -/// exactly one brace-delimited member and only void-like siblings (`{…} | null`, -/// `null | {…}`, `{…} | void`), per [`should_hug_union_type`]. Such a union inlines -/// atomically — the object member carries its own group and breaks block-style inside -/// the hugged `<…>`, so the `<…>` itself never needs a break point. Parenthesized -/// wrappers are unwrapped first. The single source of truth shared by the -/// call/`new`/instantiation type-argument builder and the type-position builder so the -/// two agree by construction. Prettier ref: `shouldHugType` → `shouldHugUnionType`. -pub fn is_hugging_union_type_arg(ty: &TSType<'_>) -> bool { - matches!(unwrap_parenthesized(ty), TSType::Union(u) - if should_hug_union_type(u) - && u.types.iter().any(|t| matches!(t, TSType::TypeLiteral(_) | TSType::Mapped(_)))) +/// Whether any union member is **brace-delimited** (`TypeLiteral`/`Mapped`) — the extra +/// narrowing a *type-argument* hug requires on top of [`union_hug_shape`]: the object +/// member carries its own group and breaks block-style inside the hugged `<…>`, so the +/// `<…>` itself never needs a break point. +/// +/// **Deliberately stricter than** prettier's `isObjectLikeType`, which also accepts a bare +/// `TSTypeReference`: excluding it is the sanctioned `return_type_generic_union` print-width +/// family (a `Promise<…> | null` argument keeps its break point). Don't widen it to match +/// prettier. +/// +/// Sole caller is +/// [`Printer::type_arg_union_prints_hugged`](super::super::Printer::type_arg_union_prints_hugged) +/// — this is one *clause* of that gate, never the gate. It is safe to ask bare (unlike +/// [`union_hug_shape`], it makes no claim to answer "does this hug?"). +pub(super) fn union_has_brace_member(union: &TSUnionType<'_>) -> bool { + union + .types + .iter() + .any(|t| matches!(t, TSType::TypeLiteral(_) | TSType::Mapped(_))) } /// Find the `TSParenthesizedType` that directly wraps `ts_type`'s underlying type, @@ -142,15 +149,27 @@ pub fn is_huggable_type(ts_type: &TSType<'_>) -> bool { matches!(ts_type, TSType::TypeLiteral(_) | TSType::Mapped(_)) } -/// Check if a union type should be "hugged" — formatted as `A | B | C` inline -/// even when it breaks, rather than using the multi-line `| A\n| B\n| C` format. +/// The **syntactic shape** a hugging union must have — exactly one object-like +/// member (`TSTypeLiteral` or `TSTypeReference`) with only void siblings (`void`, +/// `null`), e.g. `{ name: string; value: number } | null`. /// -/// Matches Prettier's `shouldHugUnionType`: hugs when there's exactly one -/// object-like type (TSTypeLiteral or TSTypeReference) and all other members -/// are void types (void, null). +/// ⚠️ **Necessary, never sufficient — do not use this as a layout gate.** This is +/// Prettier's `shouldHugUnionType` (`utilities/union-type-print.js`) **minus its +/// first clause**, `types.some((n) => hasComment(n))`. That clause needs the +/// comment table, which a free function has no access to; it lives in +/// [`Printer::union_prints_hugged`](super::super::Printer::union_prints_hugged), +/// which pairs this shape with the comment checks and is the single source of +/// truth for *whether the hug actually happens*. /// -/// Example: `{ name: string; value: number } | null` stays hugged. -pub fn should_hug_union_type(union: &TSUnionType<'_>) -> bool { +/// A layout gate that asks this predicate alone re-derives the hug with a subset +/// of the rule, so it answers "hug" for a union the printer then expands: the +/// keyword keeps its operand glued while the members explode below it +/// (`type A = Foo<| {…} /* c */⏎| null>`). That is a bug class, not a hypothetical +/// — five gates asked it bare. Every caller must pair it with `union_prints_hugged` +/// (see [`Self::union_return_hugs`](super::super::Printer::union_return_hugs) and +/// [`Printer::type_arg_union_prints_hugged`](super::super::Printer::type_arg_union_prints_hugged) +/// for the two shapes that do). +pub(super) fn union_hug_shape(union: &TSUnionType<'_>) -> bool { // Find exactly one object-like type let mut object_idx = None; for (i, t) in union.types.iter().enumerate() { diff --git a/crates/tsv_ts/src/printer/types/type_annotation.rs b/crates/tsv_ts/src/printer/types/type_annotation.rs index f92171e0..cabbdd27 100644 --- a/crates/tsv_ts/src/printer/types/type_annotation.rs +++ b/crates/tsv_ts/src/printer/types/type_annotation.rs @@ -264,7 +264,7 @@ impl<'a> Printer<'a> { // `return_type_generic_union` print-width family, handled by the // `union_prints_hugged` branch below), and any comment that makes the printer // decline the hug disqualifies it here too. - if self.union_return_hugs(value_type, u, colon_end, value_type_start) { + if self.union_return_hugs(value_type, colon_end, value_type_start) { return match comments_doc { Some(c) => d.concat(&[d.text(": "), c, type_doc]), None => d.concat(&[d.text(": "), type_doc]), diff --git a/crates/tsv_ts/src/printer/types/type_arguments.rs b/crates/tsv_ts/src/printer/types/type_arguments.rs index 1cc64f0c..3ba81675 100644 --- a/crates/tsv_ts/src/printer/types/type_arguments.rs +++ b/crates/tsv_ts/src/printer/types/type_arguments.rs @@ -1,7 +1,7 @@ // Type-argument instantiation (``) rendering use super::Printer; -use super::helpers::{is_hugging_union_type_arg, is_simple_type_arg, unwrap_parenthesized}; +use super::helpers::{is_simple_type_arg, unwrap_parenthesized}; use crate::ast::internal::{self, TSType}; use smallvec::smallvec; use tsv_lang::doc::DocBuf; @@ -31,7 +31,7 @@ impl<'a> Printer<'a> { /// carries its own group and still breaks block-style within the hugged `<…>`. /// /// Assumes `args.params.len() == 1`; the caller gates on its own single-arg inline - /// predicate (`is_simple_type_arg`, `is_hugging_union_type_arg`, a huggable object, + /// predicate (`is_simple_type_arg`, `union_type_arg_hug_shape`, a huggable object, /// or always-inline). Own-line and line comments are routed to the multiline path /// before this runs, so only inline block comments remain to preserve here. Shared by /// the type-position builder and the call/`new`/instantiation builder. @@ -171,7 +171,7 @@ impl<'a> Printer<'a> { let unwrapped = unwrap_parenthesized(&args.params[0]); let is_huggable = is_simple_type_arg(&args.params[0]) || matches!(unwrapped, TSType::TypeLiteral(_) | TSType::Mapped(_)) - || is_hugging_union_type_arg(&args.params[0]); + || self.type_arg_union_prints_hugged(&args.params[0]); if is_huggable { return self.build_single_type_arg_inline(args, has_comments); } diff --git a/crates/tsv_ts/src/printer/types/type_params.rs b/crates/tsv_ts/src/printer/types/type_params.rs index dbbc77df..b7b0be9d 100644 --- a/crates/tsv_ts/src/printer/types/type_params.rs +++ b/crates/tsv_ts/src/printer/types/type_params.rs @@ -4,7 +4,7 @@ // - Type parameter declarations: `` // - Type parameter instantiation (type arguments): `` -use super::helpers::{is_hugging_union_type_arg, is_simple_type_arg}; +use super::helpers::is_simple_type_arg; use super::{CommentFilter, CommentSpacing, Printer}; use crate::ast::internal::{self, TSType, TSTypeParameter, TSTypeParameterDeclaration}; use crate::printer::layout::fluid_after_operator; @@ -555,7 +555,7 @@ impl<'a> Printer<'a> { // A single *simple* or *hugged-union* type argument inlines atomically: no // group, no softlines. Simple = keyword, literal, `this`, or a bare type // reference (`is_simple_type_arg`); hugged union = `{…} | null` / `null | {…}` - // (`is_hugging_union_type_arg`), whose object member carries its own group and + // (`union_type_arg_hug_shape`), whose object member carries its own group and // breaks block-style inside the hugged `<…>` rather than breaking the `<…>` onto // its own lines. Matches Prettier's `shouldInline`/`shouldHugType` and tsv's own // type-position builder (`build_type_arguments_doc_wrapping`), via the shared @@ -567,7 +567,8 @@ impl<'a> Printer<'a> { // remain — the shared `build_single_type_arg_inline` preserves them. (The single // brace-delimited object/mapped type is handled by the curly-hug case above.) if inst.params.len() == 1 - && (is_simple_type_arg(&inst.params[0]) || is_hugging_union_type_arg(&inst.params[0])) + && (is_simple_type_arg(&inst.params[0]) + || self.type_arg_union_prints_hugged(&inst.params[0])) { return self.build_single_type_arg_inline(inst, has_comments); } diff --git a/crates/tsv_ts/src/printer/types/union_intersection.rs b/crates/tsv_ts/src/printer/types/union_intersection.rs index 67bce48e..df6939f0 100644 --- a/crates/tsv_ts/src/printer/types/union_intersection.rs +++ b/crates/tsv_ts/src/printer/types/union_intersection.rs @@ -8,8 +8,9 @@ use super::super::comments_to_emit_in_range; use super::helpers::{ find_separator_position, intersection_has_expanding_first_type, - intersection_has_huggable_last_type, is_huggable_type, is_hugging_union_type_arg, - should_hug_union_type, type_needs_parens_in_union_or_intersection, unwrap_parenthesized, + intersection_has_huggable_last_type, is_huggable_type, + type_needs_parens_in_union_or_intersection, union_has_brace_member, union_hug_shape, + unwrap_parenthesized, }; use super::{CommentFilter, CommentSpacing, Printer}; use crate::ast::internal::{TSIntersectionType, TSParenthesizedType, TSType, TSUnionType}; @@ -400,7 +401,7 @@ impl<'a> Printer<'a> { let TSType::Union(union) = ty else { return None; }; - // `union_prints_hugged`, not the bare syntactic `should_hug_union_type`: this + // `union_prints_hugged`, not the bare syntactic `union_hug_shape`: this // must agree with the layout `build_union_type_doc` will actually take. A comment // can make it decline the hug and expand, and then the keyword has to break like // any other non-hugging union — asking the syntactic form alone keeps `as ` glued @@ -680,8 +681,8 @@ impl<'a> Printer<'a> { /// (`build_type_annotation_doc_with_wrapping`), so the two arms can't drift (the /// drift is exactly what let the hug miss those contexts before). /// - /// Requires a brace member with only void siblings (`is_hugging_union_type_arg` — - /// a `TypeLiteral`/`Mapped`; excludes the `Promise<…> | null` `TSTypeReference` + /// Requires the brace-member shape (`union_has_brace_member` — a + /// `TypeLiteral`/`Mapped`; excludes the `Promise<…> | null` `TSTypeReference` /// print-width family). A comment prettier's `shouldHugUnionType` would bail on — /// between two members, or in the operator→union gap `[gap_start, gap_end]` — /// disqualifies the hug; an *inside-object* comment (`{ /* c */ … }`) does not. @@ -689,31 +690,42 @@ impl<'a> Printer<'a> { pub(crate) fn union_return_hugs( &self, value_type: &TSType<'_>, - union: &TSUnionType<'_>, gap_start: u32, gap_end: u32, ) -> bool { - // Two questions, each asked of the one predicate that owns it. The **brace** - // narrowing is this site's own (`is_hugging_union_type_arg` — a - // `Promise<…> | null` `TSTypeReference` member is excluded, the sanctioned - // `return_type_generic_union` print-width family), and so is the `:`→union gap. - // But whether the union HUGS AT ALL belongs to [`Self::union_prints_hugged`] and - // is not re-derived here: this gate used to spell out its own subset of that - // predicate's comment checks and missed the leading `|`→first-member line + // The `:`→union gap is this site's own question; the hug itself is not + // re-derived here but delegated (via `type_arg_union_prints_hugged`) to + // [`Self::union_prints_hugged`]. This gate used to spell out its own subset of + // that predicate's comment checks and missed the leading `|`→first-member line // comment, so a comment that made the printer decline the hug still read as // "hug" here and kept `: ` glued while the members exploded below it. - is_hugging_union_type_arg(value_type) - && self.union_prints_hugged(union) + self.type_arg_union_prints_hugged(value_type) && !self.has_comments_to_emit_between(gap_start, gap_end) } + /// Whether a **type argument** actually prints hugged — [`Self::union_prints_hugged`] + /// (which owns the whole hug question, shape *and* comments) narrowed by + /// [`union_has_brace_member`] (the type-argument-only extra clause). + /// + /// The single gate every type-argument position asks, so none of them has to + /// remember that a shape predicate is only half the question. Asking a bare shape + /// instead inlines the argument atomically while the printer expands its members, + /// gluing the `<` to a dangling `|` (`Foo<| {…} /* c */⏎| null>`) — which is exactly + /// what `type_arguments.rs` and `type_params.rs` both did. + pub(crate) fn type_arg_union_prints_hugged(&self, ty: &TSType<'_>) -> bool { + // `union_prints_hugged` subsumes `union_hug_shape`, so the shape is not re-tested + // here — the brace clause is the only thing this position adds. + matches!(unwrap_parenthesized(ty), TSType::Union(u) + if self.union_prints_hugged(u) && union_has_brace_member(u)) + } + /// Whether [`Self::build_union_type_doc`] will actually take its **hug** path — /// the inline `{ … } | null` form where the object member owns its own expansion. /// /// The single source of truth for that question, because two places must agree on /// it: the union printer (which lays the members out) and the type-alias RHS /// (`build_type_alias_doc`, which decides whether to break after `=`). Asking the - /// bare syntactic [`should_hug_union_type`] at the alias while the printer declines + /// bare syntactic [`union_hug_shape`] at the alias while the printer declines /// the hug for a comment splits them — the alias keeps `= ` while the union expands, /// yielding `type A = | // c⏎{ a: 1 }⏎| null` where a non-hugging union of the same /// shape correctly breaks after the `=`. @@ -743,7 +755,7 @@ impl<'a> Printer<'a> { /// pairwise scan would report "no comments" for an owned one, hugging a union whose /// members the printer expands. pub(crate) fn union_prints_hugged(&self, union: &TSUnionType<'_>) -> bool { - if !should_hug_union_type(union) { + if !union_hug_shape(union) { return false; } // Zero-comment fast path — an **on-page** question, since it short-circuits the @@ -781,24 +793,6 @@ impl<'a> Printer<'a> { .any(|pair| self.has_comments_to_emit_between(pair[0].span().end, pair[1].span().start)) } - /// Check if a union type has line comments between any consecutive members. - /// - /// Used by callers (e.g., mapped types) to decide whether the union needs - /// extra indentation wrapping, and internally to force multiline formatting. - pub(crate) fn union_has_line_comments_between_members(&self, union: &TSUnionType<'_>) -> bool { - // Zero-comment window gate (as in `union_has_comments_between_members`): every - // pairwise range lies within the union span, so no comment inside the union - // means every pairwise scan below is provably false — skip them on the common - // comment-free `A | B | C`. - if !self.has_comments_to_emit_between(union.span.start, union.span.end) { - return false; - } - union - .types - .windows(2) - .any(|pair| self.has_line_comments_between(pair[0].span().end, pair[1].span().start)) - } - /// True when an **own-line comment** sits between two consecutive members — /// a line comment (which can never be inline), or a block comment with a /// newline before it (`| 'x'⏎/* c */⏎| 'y'`), on either side of the `|`. @@ -807,9 +801,8 @@ impl<'a> Printer<'a> { /// (`union-type.js`), forcing the whole union group to break /// one-member-per-line. A *same-line* block comment (`a /* c */ | b`) does /// not count — it stays inline, matching `union_intersection_parens_comment`. - /// Subsumes the between-members case of `union_has_line_comments_between_members` - /// (a line comment is always own-line here) and additionally catches own-line - /// *block* comments, which the default (groupable) path would otherwise keep flat. + /// Catches own-line *block* comments too, which the default (groupable) path would + /// otherwise keep flat. fn union_has_own_line_member_comment(&self, union: &TSUnionType<'_>) -> bool { // Zero-comment window gate (see `union_has_comments_between_members`): every // pairwise range lies within the union span, so no comment inside the union diff --git a/tests/fixtures/typescript/types/type_argument_leading_operator/expected.json b/tests/fixtures/typescript/types/type_argument_leading_operator/expected.json new file mode 100644 index 00000000..7032ce52 --- /dev/null +++ b/tests/fixtures/typescript/types/type_argument_leading_operator/expected.json @@ -0,0 +1,1199 @@ +{ + "css": null, + "js": [], + "start": 0, + "end": 340, + "type": "Root", + "fragment": { + "type": "Fragment", + "nodes": [] + }, + "options": null, + "comments": [ + { + "type": "Line", + "value": " A redundant leading `|` or `&` on a type argument is stripped, in expression", + "start": 20, + "end": 99, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 80 + } + } + }, + { + "type": "Line", + "value": " position (`fn<...>()`, `new Foo<...>()`) as well as type position.", + "start": 101, + "end": 170, + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 70 + } + } + } + ], + "instance": { + "type": "Script", + "start": 0, + "end": 339, + "context": "default", + "content": { + "type": "Program", + "start": 18, + "end": 330, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 11, + "column": 9 + } + }, + "body": [ + { + "type": "TSTypeAliasDeclaration", + "start": 172, + "end": 188, + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 17 + } + }, + "id": { + "type": "Identifier", + "start": 177, + "end": 178, + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 7 + } + }, + "name": "A" + }, + "typeAnnotation": { + "type": "TSTypeReference", + "start": 181, + "end": 187, + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 4, + "column": 16 + } + }, + "typeName": { + "type": "Identifier", + "start": 181, + "end": 184, + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 4, + "column": 13 + } + }, + "name": "Foo" + }, + "typeArguments": { + "type": "TSTypeParameterInstantiation", + "start": 184, + "end": 187, + "loc": { + "start": { + "line": 4, + "column": 13 + }, + "end": { + "line": 4, + "column": 16 + } + }, + "params": [ + { + "type": "TSTypeReference", + "start": 185, + "end": 186, + "loc": { + "start": { + "line": 4, + "column": 14 + }, + "end": { + "line": 4, + "column": 15 + } + }, + "typeName": { + "type": "Identifier", + "start": 185, + "end": 186, + "loc": { + "start": { + "line": 4, + "column": 14 + }, + "end": { + "line": 4, + "column": 15 + } + }, + "name": "T" + } + } + ] + } + }, + "leadingComments": [ + { + "type": "Line", + "value": " A redundant leading `|` or `&` on a type argument is stripped, in expression", + "start": 20, + "end": 99 + }, + { + "type": "Line", + "value": " position (`fn<...>()`, `new Foo<...>()`) as well as type position.", + "start": 101, + "end": 170 + } + ] + }, + { + "type": "TSTypeAliasDeclaration", + "start": 190, + "end": 210, + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 21 + } + }, + "id": { + "type": "Identifier", + "start": 195, + "end": 196, + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 7 + } + }, + "name": "B" + }, + "typeAnnotation": { + "type": "TSTypeReference", + "start": 199, + "end": 209, + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 20 + } + }, + "typeName": { + "type": "Identifier", + "start": 199, + "end": 202, + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 13 + } + }, + "name": "Foo" + }, + "typeArguments": { + "type": "TSTypeParameterInstantiation", + "start": 202, + "end": 209, + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 20 + } + }, + "params": [ + { + "type": "TSUnionType", + "start": 203, + "end": 208, + "loc": { + "start": { + "line": 5, + "column": 14 + }, + "end": { + "line": 5, + "column": 19 + } + }, + "types": [ + { + "type": "TSTypeReference", + "start": 203, + "end": 204, + "loc": { + "start": { + "line": 5, + "column": 14 + }, + "end": { + "line": 5, + "column": 15 + } + }, + "typeName": { + "type": "Identifier", + "start": 203, + "end": 204, + "loc": { + "start": { + "line": 5, + "column": 14 + }, + "end": { + "line": 5, + "column": 15 + } + }, + "name": "T" + } + }, + { + "type": "TSTypeReference", + "start": 207, + "end": 208, + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 19 + } + }, + "typeName": { + "type": "Identifier", + "start": 207, + "end": 208, + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 19 + } + }, + "name": "U" + } + } + ] + } + ] + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "start": 212, + "end": 232, + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 21 + } + }, + "id": { + "type": "Identifier", + "start": 217, + "end": 218, + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 6, + "column": 7 + } + }, + "name": "C" + }, + "typeAnnotation": { + "type": "TSTypeReference", + "start": 221, + "end": 231, + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 20 + } + }, + "typeName": { + "type": "Identifier", + "start": 221, + "end": 224, + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 13 + } + }, + "name": "Foo" + }, + "typeArguments": { + "type": "TSTypeParameterInstantiation", + "start": 224, + "end": 231, + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 20 + } + }, + "params": [ + { + "type": "TSIntersectionType", + "start": 225, + "end": 230, + "loc": { + "start": { + "line": 6, + "column": 14 + }, + "end": { + "line": 6, + "column": 19 + } + }, + "types": [ + { + "type": "TSTypeReference", + "start": 225, + "end": 226, + "loc": { + "start": { + "line": 6, + "column": 14 + }, + "end": { + "line": 6, + "column": 15 + } + }, + "typeName": { + "type": "Identifier", + "start": 225, + "end": 226, + "loc": { + "start": { + "line": 6, + "column": 14 + }, + "end": { + "line": 6, + "column": 15 + } + }, + "name": "T" + } + }, + { + "type": "TSTypeReference", + "start": 229, + "end": 230, + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 6, + "column": 19 + } + }, + "typeName": { + "type": "Identifier", + "start": 229, + "end": 230, + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 6, + "column": 19 + } + }, + "name": "U" + } + } + ] + } + ] + } + } + }, + { + "type": "VariableDeclaration", + "start": 234, + "end": 252, + "loc": { + "start": { + "line": 7, + "column": 1 + }, + "end": { + "line": 7, + "column": 19 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 240, + "end": 251, + "loc": { + "start": { + "line": 7, + "column": 7 + }, + "end": { + "line": 7, + "column": 18 + } + }, + "id": { + "type": "Identifier", + "start": 240, + "end": 241, + "loc": { + "start": { + "line": 7, + "column": 7 + }, + "end": { + "line": 7, + "column": 8 + } + }, + "name": "a" + }, + "init": { + "type": "CallExpression", + "start": 244, + "end": 251, + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 7, + "column": 18 + } + }, + "callee": { + "type": "Identifier", + "start": 244, + "end": 246, + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 7, + "column": 13 + } + }, + "name": "fn" + }, + "arguments": [], + "typeArguments": { + "type": "TSTypeParameterInstantiation", + "start": 246, + "end": 249, + "loc": { + "start": { + "line": 7, + "column": 13 + }, + "end": { + "line": 7, + "column": 16 + } + }, + "params": [ + { + "type": "TSTypeReference", + "start": 247, + "end": 248, + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 7, + "column": 15 + } + }, + "typeName": { + "type": "Identifier", + "start": 247, + "end": 248, + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 7, + "column": 15 + } + }, + "name": "T" + } + } + ] + } + } + } + ], + "kind": "const" + }, + { + "type": "VariableDeclaration", + "start": 254, + "end": 276, + "loc": { + "start": { + "line": 8, + "column": 1 + }, + "end": { + "line": 8, + "column": 23 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 260, + "end": 275, + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 22 + } + }, + "id": { + "type": "Identifier", + "start": 260, + "end": 261, + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 8 + } + }, + "name": "b" + }, + "init": { + "type": "CallExpression", + "start": 264, + "end": 275, + "loc": { + "start": { + "line": 8, + "column": 11 + }, + "end": { + "line": 8, + "column": 22 + } + }, + "callee": { + "type": "Identifier", + "start": 264, + "end": 266, + "loc": { + "start": { + "line": 8, + "column": 11 + }, + "end": { + "line": 8, + "column": 13 + } + }, + "name": "fn" + }, + "arguments": [], + "typeArguments": { + "type": "TSTypeParameterInstantiation", + "start": 266, + "end": 273, + "loc": { + "start": { + "line": 8, + "column": 13 + }, + "end": { + "line": 8, + "column": 20 + } + }, + "params": [ + { + "type": "TSUnionType", + "start": 267, + "end": 272, + "loc": { + "start": { + "line": 8, + "column": 14 + }, + "end": { + "line": 8, + "column": 19 + } + }, + "types": [ + { + "type": "TSTypeReference", + "start": 267, + "end": 268, + "loc": { + "start": { + "line": 8, + "column": 14 + }, + "end": { + "line": 8, + "column": 15 + } + }, + "typeName": { + "type": "Identifier", + "start": 267, + "end": 268, + "loc": { + "start": { + "line": 8, + "column": 14 + }, + "end": { + "line": 8, + "column": 15 + } + }, + "name": "T" + } + }, + { + "type": "TSTypeReference", + "start": 271, + "end": 272, + "loc": { + "start": { + "line": 8, + "column": 18 + }, + "end": { + "line": 8, + "column": 19 + } + }, + "typeName": { + "type": "Identifier", + "start": 271, + "end": 272, + "loc": { + "start": { + "line": 8, + "column": 18 + }, + "end": { + "line": 8, + "column": 19 + } + }, + "name": "U" + } + } + ] + } + ] + } + } + } + ], + "kind": "const" + }, + { + "type": "VariableDeclaration", + "start": 278, + "end": 305, + "loc": { + "start": { + "line": 9, + "column": 1 + }, + "end": { + "line": 9, + "column": 28 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 284, + "end": 304, + "loc": { + "start": { + "line": 9, + "column": 7 + }, + "end": { + "line": 9, + "column": 27 + } + }, + "id": { + "type": "Identifier", + "start": 284, + "end": 285, + "loc": { + "start": { + "line": 9, + "column": 7 + }, + "end": { + "line": 9, + "column": 8 + } + }, + "name": "c" + }, + "init": { + "type": "NewExpression", + "start": 288, + "end": 304, + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 9, + "column": 27 + } + }, + "callee": { + "type": "Identifier", + "start": 292, + "end": 295, + "loc": { + "start": { + "line": 9, + "column": 15 + }, + "end": { + "line": 9, + "column": 18 + } + }, + "name": "Foo" + }, + "typeArguments": { + "type": "TSTypeParameterInstantiation", + "start": 295, + "end": 302, + "loc": { + "start": { + "line": 9, + "column": 18 + }, + "end": { + "line": 9, + "column": 25 + } + }, + "params": [ + { + "type": "TSUnionType", + "start": 296, + "end": 301, + "loc": { + "start": { + "line": 9, + "column": 19 + }, + "end": { + "line": 9, + "column": 24 + } + }, + "types": [ + { + "type": "TSTypeReference", + "start": 296, + "end": 297, + "loc": { + "start": { + "line": 9, + "column": 19 + }, + "end": { + "line": 9, + "column": 20 + } + }, + "typeName": { + "type": "Identifier", + "start": 296, + "end": 297, + "loc": { + "start": { + "line": 9, + "column": 19 + }, + "end": { + "line": 9, + "column": 20 + } + }, + "name": "T" + } + }, + { + "type": "TSTypeReference", + "start": 300, + "end": 301, + "loc": { + "start": { + "line": 9, + "column": 23 + }, + "end": { + "line": 9, + "column": 24 + } + }, + "typeName": { + "type": "Identifier", + "start": 300, + "end": 301, + "loc": { + "start": { + "line": 9, + "column": 23 + }, + "end": { + "line": 9, + "column": 24 + } + }, + "name": "U" + } + } + ] + } + ] + }, + "arguments": [] + } + } + ], + "kind": "const" + }, + { + "type": "VariableDeclaration", + "start": 307, + "end": 329, + "loc": { + "start": { + "line": 10, + "column": 1 + }, + "end": { + "line": 10, + "column": 23 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 313, + "end": 328, + "loc": { + "start": { + "line": 10, + "column": 7 + }, + "end": { + "line": 10, + "column": 22 + } + }, + "id": { + "type": "Identifier", + "start": 313, + "end": 314, + "loc": { + "start": { + "line": 10, + "column": 7 + }, + "end": { + "line": 10, + "column": 8 + } + }, + "name": "d" + }, + "init": { + "type": "CallExpression", + "start": 317, + "end": 328, + "loc": { + "start": { + "line": 10, + "column": 11 + }, + "end": { + "line": 10, + "column": 22 + } + }, + "callee": { + "type": "Identifier", + "start": 317, + "end": 319, + "loc": { + "start": { + "line": 10, + "column": 11 + }, + "end": { + "line": 10, + "column": 13 + } + }, + "name": "fn" + }, + "arguments": [], + "typeArguments": { + "type": "TSTypeParameterInstantiation", + "start": 319, + "end": 326, + "loc": { + "start": { + "line": 10, + "column": 13 + }, + "end": { + "line": 10, + "column": 20 + } + }, + "params": [ + { + "type": "TSIntersectionType", + "start": 320, + "end": 325, + "loc": { + "start": { + "line": 10, + "column": 14 + }, + "end": { + "line": 10, + "column": 19 + } + }, + "types": [ + { + "type": "TSTypeReference", + "start": 320, + "end": 321, + "loc": { + "start": { + "line": 10, + "column": 14 + }, + "end": { + "line": 10, + "column": 15 + } + }, + "typeName": { + "type": "Identifier", + "start": 320, + "end": 321, + "loc": { + "start": { + "line": 10, + "column": 14 + }, + "end": { + "line": 10, + "column": 15 + } + }, + "name": "T" + } + }, + { + "type": "TSTypeReference", + "start": 324, + "end": 325, + "loc": { + "start": { + "line": 10, + "column": 18 + }, + "end": { + "line": 10, + "column": 19 + } + }, + "typeName": { + "type": "Identifier", + "start": 324, + "end": 325, + "loc": { + "start": { + "line": 10, + "column": 18 + }, + "end": { + "line": 10, + "column": 19 + } + }, + "name": "U" + } + } + ] + } + ] + } + } + } + ], + "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/typescript/types/type_argument_leading_operator/input.svelte b/tests/fixtures/typescript/types/type_argument_leading_operator/input.svelte new file mode 100644 index 00000000..1eaccf36 --- /dev/null +++ b/tests/fixtures/typescript/types/type_argument_leading_operator/input.svelte @@ -0,0 +1,11 @@ + diff --git a/tests/fixtures/typescript/types/type_argument_leading_operator/unformatted_leading_operator.svelte b/tests/fixtures/typescript/types/type_argument_leading_operator/unformatted_leading_operator.svelte new file mode 100644 index 00000000..c8909a11 --- /dev/null +++ b/tests/fixtures/typescript/types/type_argument_leading_operator/unformatted_leading_operator.svelte @@ -0,0 +1,11 @@ + diff --git a/tests/fixtures/typescript/types/type_argument_union_comment_long/expected.json b/tests/fixtures/typescript/types/type_argument_union_comment_long/expected.json new file mode 100644 index 00000000..5d5f8fd8 --- /dev/null +++ b/tests/fixtures/typescript/types/type_argument_union_comment_long/expected.json @@ -0,0 +1,1165 @@ +{ + "css": null, + "js": [], + "start": 0, + "end": 840, + "type": "Root", + "fragment": { + "type": "Fragment", + "nodes": [] + }, + "options": null, + "comments": [ + { + "type": "Line", + "value": " A comment between the union members disqualifies the hug, so the type argument", + "start": 20, + "end": 101, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 82 + } + } + }, + { + "type": "Line", + "value": " is no longer inlined atomically and the `<...>` breaks at the boundary.", + "start": 103, + "end": 177, + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 75 + } + } + }, + { + "type": "Line", + "value": " type position - 100 chars, stays inline", + "start": 180, + "end": 222, + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 43 + } + } + }, + { + "type": "Block", + "value": " c ", + "start": 306, + "end": 313, + "loc": { + "start": { + "line": 6, + "column": 83 + }, + "end": { + "line": 6, + "column": 90 + } + } + }, + { + "type": "Line", + "value": " type position - 101 chars, `<...>` breaks with the union inline", + "start": 325, + "end": 391, + "loc": { + "start": { + "line": 8, + "column": 1 + }, + "end": { + "line": 8, + "column": 67 + } + } + }, + { + "type": "Block", + "value": " c ", + "start": 479, + "end": 486, + "loc": { + "start": { + "line": 10, + "column": 72 + }, + "end": { + "line": 10, + "column": 79 + } + } + }, + { + "type": "Line", + "value": " expression position - 100 chars, stays inline", + "start": 500, + "end": 548, + "loc": { + "start": { + "line": 13, + "column": 1 + }, + "end": { + "line": 13, + "column": 49 + } + } + }, + { + "type": "Block", + "value": " c ", + "start": 630, + "end": 637, + "loc": { + "start": { + "line": 14, + "column": 81 + }, + "end": { + "line": 14, + "column": 88 + } + } + }, + { + "type": "Line", + "value": " expression position - 101 chars, `<...>` breaks with the union inline", + "start": 651, + "end": 723, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 73 + } + } + }, + { + "type": "Block", + "value": " c ", + "start": 809, + "end": 816, + "loc": { + "start": { + "line": 18, + "column": 70 + }, + "end": { + "line": 18, + "column": 77 + } + } + } + ], + "instance": { + "type": "Script", + "start": 0, + "end": 839, + "context": "default", + "content": { + "type": "Program", + "start": 18, + "end": 830, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 20, + "column": 9 + } + }, + "body": [ + { + "type": "TSTypeAliasDeclaration", + "start": 224, + "end": 322, + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 99 + } + }, + "id": { + "type": "Identifier", + "start": 229, + "end": 230, + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 6, + "column": 7 + } + }, + "name": "C" + }, + "typeAnnotation": { + "type": "TSTypeReference", + "start": 233, + "end": 321, + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 98 + } + }, + "typeName": { + "type": "Identifier", + "start": 233, + "end": 236, + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 13 + } + }, + "name": "Foo" + }, + "typeArguments": { + "type": "TSTypeParameterInstantiation", + "start": 236, + "end": 321, + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 98 + } + }, + "params": [ + { + "type": "TSUnionType", + "start": 237, + "end": 320, + "loc": { + "start": { + "line": 6, + "column": 14 + }, + "end": { + "line": 6, + "column": 97 + } + }, + "types": [ + { + "type": "TSTypeLiteral", + "start": 237, + "end": 305, + "loc": { + "start": { + "line": 6, + "column": 14 + }, + "end": { + "line": 6, + "column": 82 + } + }, + "members": [ + { + "type": "TSPropertySignature", + "start": 239, + "end": 303, + "loc": { + "start": { + "line": 6, + "column": 16 + }, + "end": { + "line": 6, + "column": 80 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 239, + "end": 240, + "loc": { + "start": { + "line": 6, + "column": 16 + }, + "end": { + "line": 6, + "column": 17 + } + }, + "name": "a" + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 240, + "end": 303, + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 80 + } + }, + "typeAnnotation": { + "type": "TSTypeReference", + "start": 242, + "end": 303, + "loc": { + "start": { + "line": 6, + "column": 19 + }, + "end": { + "line": 6, + "column": 80 + } + }, + "typeName": { + "type": "Identifier", + "start": 242, + "end": 303, + "loc": { + "start": { + "line": 6, + "column": 19 + }, + "end": { + "line": 6, + "column": 80 + } + }, + "name": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + } + } + } + } + ], + "trailingComments": [ + { + "type": "Block", + "value": " c ", + "start": 306, + "end": 313 + } + ] + }, + { + "type": "TSNullKeyword", + "start": 316, + "end": 320, + "loc": { + "start": { + "line": 6, + "column": 93 + }, + "end": { + "line": 6, + "column": 97 + } + } + } + ] + } + ] + } + }, + "leadingComments": [ + { + "type": "Line", + "value": " A comment between the union members disqualifies the hug, so the type argument", + "start": 20, + "end": 101 + }, + { + "type": "Line", + "value": " is no longer inlined atomically and the `<...>` breaks at the boundary.", + "start": 103, + "end": 177 + }, + { + "type": "Line", + "value": " type position - 100 chars, stays inline", + "start": 180, + "end": 222 + } + ] + }, + { + "type": "TSTypeAliasDeclaration", + "start": 393, + "end": 497, + "loc": { + "start": { + "line": 9, + "column": 1 + }, + "end": { + "line": 11, + "column": 3 + } + }, + "id": { + "type": "Identifier", + "start": 398, + "end": 399, + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 7 + } + }, + "name": "D" + }, + "typeAnnotation": { + "type": "TSTypeReference", + "start": 402, + "end": 496, + "loc": { + "start": { + "line": 9, + "column": 10 + }, + "end": { + "line": 11, + "column": 2 + } + }, + "typeName": { + "type": "Identifier", + "start": 402, + "end": 405, + "loc": { + "start": { + "line": 9, + "column": 10 + }, + "end": { + "line": 9, + "column": 13 + } + }, + "name": "Foo" + }, + "typeArguments": { + "type": "TSTypeParameterInstantiation", + "start": 405, + "end": 496, + "loc": { + "start": { + "line": 9, + "column": 13 + }, + "end": { + "line": 11, + "column": 2 + } + }, + "params": [ + { + "type": "TSUnionType", + "start": 409, + "end": 493, + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 10, + "column": 86 + } + }, + "types": [ + { + "type": "TSTypeLiteral", + "start": 409, + "end": 478, + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 10, + "column": 71 + } + }, + "members": [ + { + "type": "TSPropertySignature", + "start": 411, + "end": 476, + "loc": { + "start": { + "line": 10, + "column": 4 + }, + "end": { + "line": 10, + "column": 69 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 411, + "end": 412, + "loc": { + "start": { + "line": 10, + "column": 4 + }, + "end": { + "line": 10, + "column": 5 + } + }, + "name": "a" + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 412, + "end": 476, + "loc": { + "start": { + "line": 10, + "column": 5 + }, + "end": { + "line": 10, + "column": 69 + } + }, + "typeAnnotation": { + "type": "TSTypeReference", + "start": 414, + "end": 476, + "loc": { + "start": { + "line": 10, + "column": 7 + }, + "end": { + "line": 10, + "column": 69 + } + }, + "typeName": { + "type": "Identifier", + "start": 414, + "end": 476, + "loc": { + "start": { + "line": 10, + "column": 7 + }, + "end": { + "line": 10, + "column": 69 + } + }, + "name": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + } + } + } + } + ], + "trailingComments": [ + { + "type": "Block", + "value": " c ", + "start": 479, + "end": 486 + } + ] + }, + { + "type": "TSNullKeyword", + "start": 489, + "end": 493, + "loc": { + "start": { + "line": 10, + "column": 82 + }, + "end": { + "line": 10, + "column": 86 + } + } + } + ] + } + ] + } + }, + "leadingComments": [ + { + "type": "Line", + "value": " type position - 101 chars, `<...>` breaks with the union inline", + "start": 325, + "end": 391 + } + ] + }, + { + "type": "VariableDeclaration", + "start": 550, + "end": 648, + "loc": { + "start": { + "line": 14, + "column": 1 + }, + "end": { + "line": 14, + "column": 99 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 556, + "end": 647, + "loc": { + "start": { + "line": 14, + "column": 7 + }, + "end": { + "line": 14, + "column": 98 + } + }, + "id": { + "type": "Identifier", + "start": 556, + "end": 557, + "loc": { + "start": { + "line": 14, + "column": 7 + }, + "end": { + "line": 14, + "column": 8 + } + }, + "name": "a" + }, + "init": { + "type": "CallExpression", + "start": 560, + "end": 647, + "loc": { + "start": { + "line": 14, + "column": 11 + }, + "end": { + "line": 14, + "column": 98 + } + }, + "callee": { + "type": "Identifier", + "start": 560, + "end": 562, + "loc": { + "start": { + "line": 14, + "column": 11 + }, + "end": { + "line": 14, + "column": 13 + } + }, + "name": "fn" + }, + "arguments": [], + "typeArguments": { + "type": "TSTypeParameterInstantiation", + "start": 562, + "end": 645, + "loc": { + "start": { + "line": 14, + "column": 13 + }, + "end": { + "line": 14, + "column": 96 + } + }, + "params": [ + { + "type": "TSUnionType", + "start": 563, + "end": 644, + "loc": { + "start": { + "line": 14, + "column": 14 + }, + "end": { + "line": 14, + "column": 95 + } + }, + "types": [ + { + "type": "TSTypeLiteral", + "start": 563, + "end": 629, + "loc": { + "start": { + "line": 14, + "column": 14 + }, + "end": { + "line": 14, + "column": 80 + } + }, + "members": [ + { + "type": "TSPropertySignature", + "start": 565, + "end": 627, + "loc": { + "start": { + "line": 14, + "column": 16 + }, + "end": { + "line": 14, + "column": 78 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 565, + "end": 566, + "loc": { + "start": { + "line": 14, + "column": 16 + }, + "end": { + "line": 14, + "column": 17 + } + }, + "name": "a" + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 566, + "end": 627, + "loc": { + "start": { + "line": 14, + "column": 17 + }, + "end": { + "line": 14, + "column": 78 + } + }, + "typeAnnotation": { + "type": "TSTypeReference", + "start": 568, + "end": 627, + "loc": { + "start": { + "line": 14, + "column": 19 + }, + "end": { + "line": 14, + "column": 78 + } + }, + "typeName": { + "type": "Identifier", + "start": 568, + "end": 627, + "loc": { + "start": { + "line": 14, + "column": 19 + }, + "end": { + "line": 14, + "column": 78 + } + }, + "name": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + } + } + } + } + ], + "trailingComments": [ + { + "type": "Block", + "value": " c ", + "start": 630, + "end": 637 + } + ] + }, + { + "type": "TSNullKeyword", + "start": 640, + "end": 644, + "loc": { + "start": { + "line": 14, + "column": 91 + }, + "end": { + "line": 14, + "column": 95 + } + } + } + ] + } + ] + } + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "Line", + "value": " expression position - 100 chars, stays inline", + "start": 500, + "end": 548 + } + ] + }, + { + "type": "VariableDeclaration", + "start": 725, + "end": 829, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 19, + "column": 5 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 731, + "end": 828, + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 19, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 731, + "end": 732, + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 8 + } + }, + "name": "b" + }, + "init": { + "type": "CallExpression", + "start": 735, + "end": 828, + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 19, + "column": 4 + } + }, + "callee": { + "type": "Identifier", + "start": 735, + "end": 737, + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 13 + } + }, + "name": "fn" + }, + "arguments": [], + "typeArguments": { + "type": "TSTypeParameterInstantiation", + "start": 737, + "end": 826, + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 19, + "column": 2 + } + }, + "params": [ + { + "type": "TSUnionType", + "start": 741, + "end": 823, + "loc": { + "start": { + "line": 18, + "column": 2 + }, + "end": { + "line": 18, + "column": 84 + } + }, + "types": [ + { + "type": "TSTypeLiteral", + "start": 741, + "end": 808, + "loc": { + "start": { + "line": 18, + "column": 2 + }, + "end": { + "line": 18, + "column": 69 + } + }, + "members": [ + { + "type": "TSPropertySignature", + "start": 743, + "end": 806, + "loc": { + "start": { + "line": 18, + "column": 4 + }, + "end": { + "line": 18, + "column": 67 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 743, + "end": 744, + "loc": { + "start": { + "line": 18, + "column": 4 + }, + "end": { + "line": 18, + "column": 5 + } + }, + "name": "a" + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 744, + "end": 806, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 67 + } + }, + "typeAnnotation": { + "type": "TSTypeReference", + "start": 746, + "end": 806, + "loc": { + "start": { + "line": 18, + "column": 7 + }, + "end": { + "line": 18, + "column": 67 + } + }, + "typeName": { + "type": "Identifier", + "start": 746, + "end": 806, + "loc": { + "start": { + "line": 18, + "column": 7 + }, + "end": { + "line": 18, + "column": 67 + } + }, + "name": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + } + } + } + } + ], + "trailingComments": [ + { + "type": "Block", + "value": " c ", + "start": 809, + "end": 816 + } + ] + }, + { + "type": "TSNullKeyword", + "start": 819, + "end": 823, + "loc": { + "start": { + "line": 18, + "column": 80 + }, + "end": { + "line": 18, + "column": 84 + } + } + } + ] + } + ] + } + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "Line", + "value": " expression position - 101 chars, `<...>` breaks with the union inline", + "start": 651, + "end": 723 + } + ] + } + ], + "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/types/type_argument_union_comment_long/input.svelte b/tests/fixtures/typescript/types/type_argument_union_comment_long/input.svelte new file mode 100644 index 00000000..75855741 --- /dev/null +++ b/tests/fixtures/typescript/types/type_argument_union_comment_long/input.svelte @@ -0,0 +1,20 @@ + diff --git a/tests/fixtures/typescript/types/union_hug_leading_line_comment_prettier_divergence/README.md b/tests/fixtures/typescript/types/union_hug_leading_line_comment_prettier_divergence/README.md index adb03612..3e4539f8 100644 --- a/tests/fixtures/typescript/types/union_hug_leading_line_comment_prettier_divergence/README.md +++ b/tests/fixtures/typescript/types/union_hug_leading_line_comment_prettier_divergence/README.md @@ -25,10 +25,23 @@ answer had drifted: - `:` — an annotation (`d`), via `union_return_hugs` - `=>` — a function-type return (`E`), same gate - `as` — a cast (`f`), via `build_union_hanging_indent_doc` - -`g`/`H`/`i` are the controls: the same three positions with nothing to disqualify the hug, so -it still happens and the keyword stays glued. A **block** comment in the gap (`C`) also stays -hugged and inline — it renders fine there, nothing is lost, and prettier agrees. +- a mapped-type value (`G`) +- a conditional check (`H`) and branch (`I`) +- a type argument, in type (`J`) and expression (`k`) position + +⚠️ **This list is load-bearing, and it has been wrong before.** It once named only the first +four, which read as "the vein is closed" — while the last five asked the bare syntactic +predicate and mangled every one of them. An enumeration that trails the code is worse than +none: it is what stops the next reader from probing. If you add a position that can hold a +union, add it here, and probe it against prettier rather than trusting this list. + +`l`/`M`/`n` are the controls: the same positions with nothing to disqualify the hug, so it +still happens and the keyword stays glued. A **block** comment in the gap (`C`) also stays +hugged and inline — it renders fine there, nothing is lost, and prettier agrees. The +*between-members* block comment — the other clause that declines the hug, and the one the +narrower duplicate scan used to miss — is pinned by +[union_hug_member_block_comment](../union_hug_member_block_comment/), which fully matches +prettier (no alignment is involved, so it is not a divergence). ## The divergence diff --git a/tests/fixtures/typescript/types/union_hug_leading_line_comment_prettier_divergence/expected.json b/tests/fixtures/typescript/types/union_hug_leading_line_comment_prettier_divergence/expected.json index 3ee0a163..6353b18e 100644 --- a/tests/fixtures/typescript/types/union_hug_leading_line_comment_prettier_divergence/expected.json +++ b/tests/fixtures/typescript/types/union_hug_leading_line_comment_prettier_divergence/expected.json @@ -2,7 +2,7 @@ "css": null, "js": [], "start": 0, - "end": 774, + "end": 1067, "type": "Root", "fragment": { "type": "Fragment", @@ -186,18 +186,98 @@ } } }, + { + "type": "Line", + "value": " c", + "start": 636, + "end": 640, + "loc": { + "start": { + "line": 36, + "column": 5 + }, + "end": { + "line": 36, + "column": 9 + } + } + }, + { + "type": "Line", + "value": " c", + "start": 684, + "end": 688, + "loc": { + "start": { + "line": 42, + "column": 4 + }, + "end": { + "line": 42, + "column": 8 + } + } + }, + { + "type": "Line", + "value": " c", + "start": 762, + "end": 766, + "loc": { + "start": { + "line": 49, + "column": 6 + }, + "end": { + "line": 49, + "column": 10 + } + } + }, + { + "type": "Line", + "value": " c", + "start": 817, + "end": 821, + "loc": { + "start": { + "line": 55, + "column": 4 + }, + "end": { + "line": 55, + "column": 8 + } + } + }, + { + "type": "Line", + "value": " c", + "start": 867, + "end": 871, + "loc": { + "start": { + "line": 61, + "column": 4 + }, + "end": { + "line": 61, + "column": 8 + } + } + }, { "type": "Line", "value": " The same positions still hug when nothing disqualifies it.", - "start": 608, - "end": 669, + "start": 901, + "end": 962, "loc": { "start": { - "line": 34, + "line": 66, "column": 1 }, "end": { - "line": 34, + "line": 66, "column": 62 } } @@ -206,19 +286,19 @@ "instance": { "type": "Script", "start": 0, - "end": 773, + "end": 1066, "context": "default", "content": { "type": "Program", "start": 18, - "end": 764, + "end": 1057, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 38, + "line": 70, "column": 9 } }, @@ -1313,321 +1393,1553 @@ "kind": "const" }, { - "type": "VariableDeclaration", - "start": 671, - "end": 694, + "type": "TSTypeAliasDeclaration", + "start": 608, + "end": 668, "loc": { "start": { - "line": 35, + "line": 34, "column": 1 }, "end": { - "line": 35, - "column": 24 + "line": 39, + "column": 3 } }, - "declarations": [ - { - "type": "VariableDeclarator", - "start": 675, - "end": 693, + "id": { + "type": "Identifier", + "start": 613, + "end": 614, + "loc": { + "start": { + "line": 34, + "column": 6 + }, + "end": { + "line": 34, + "column": 7 + } + }, + "name": "G" + }, + "typeAnnotation": { + "type": "TSMappedType", + "start": 617, + "end": 667, + "loc": { + "start": { + "line": 34, + "column": 10 + }, + "end": { + "line": 39, + "column": 2 + } + }, + "typeParameter": { + "type": "TSTypeParameter", + "start": 622, + "end": 628, "loc": { "start": { "line": 35, - "column": 5 + "column": 3 }, "end": { "line": 35, - "column": 23 + "column": 9 } }, - "id": { - "type": "Identifier", - "start": 675, - "end": 693, + "name": "K", + "constraint": { + "type": "TSTypeReference", + "start": 627, + "end": 628, "loc": { "start": { "line": 35, - "column": 5 + "column": 8 }, "end": { "line": 35, - "column": 23 + "column": 9 } }, - "name": "g", - "typeAnnotation": { - "type": "TSTypeAnnotation", - "start": 676, - "end": 693, + "typeName": { + "type": "Identifier", + "start": 627, + "end": 628, "loc": { "start": { "line": 35, - "column": 6 + "column": 8 }, "end": { "line": 35, - "column": 23 + "column": 9 } }, - "typeAnnotation": { - "type": "TSUnionType", - "start": 678, - "end": 693, - "loc": { - "start": { - "line": 35, - "column": 8 - }, - "end": { - "line": 35, - "column": 23 - } + "name": "T" + } + } + }, + "nameType": null, + "typeAnnotation": { + "type": "TSUnionType", + "start": 634, + "end": 663, + "loc": { + "start": { + "line": 36, + "column": 3 + }, + "end": { + "line": 38, + "column": 9 + } + }, + "types": [ + { + "type": "TSTypeLiteral", + "start": 645, + "end": 653, + "loc": { + "start": { + "line": 37, + "column": 4 }, - "types": [ - { - "type": "TSTypeLiteral", - "start": 678, - "end": 686, + "end": { + "line": 37, + "column": 12 + } + }, + "members": [ + { + "type": "TSPropertySignature", + "start": 647, + "end": 651, + "loc": { + "start": { + "line": 37, + "column": 6 + }, + "end": { + "line": 37, + "column": 10 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 647, + "end": 648, "loc": { "start": { - "line": 35, - "column": 8 + "line": 37, + "column": 6 }, "end": { - "line": 35, - "column": 16 + "line": 37, + "column": 7 } }, - "members": [ - { - "type": "TSPropertySignature", - "start": 680, - "end": 684, + "name": "a" + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 648, + "end": 651, + "loc": { + "start": { + "line": 37, + "column": 7 + }, + "end": { + "line": 37, + "column": 10 + } + }, + "typeAnnotation": { + "type": "TSLiteralType", + "start": 650, + "end": 651, + "loc": { + "start": { + "line": 37, + "column": 9 + }, + "end": { + "line": 37, + "column": 10 + } + }, + "literal": { + "type": "Literal", + "start": 650, + "end": 651, "loc": { "start": { - "line": 35, - "column": 10 + "line": 37, + "column": 9 }, "end": { - "line": 35, - "column": 14 + "line": 37, + "column": 10 } }, - "computed": false, - "key": { - "type": "Identifier", - "start": 680, - "end": 681, - "loc": { - "start": { - "line": 35, - "column": 10 - }, - "end": { - "line": 35, - "column": 11 - } - }, - "name": "a" - }, - "typeAnnotation": { - "type": "TSTypeAnnotation", - "start": 681, - "end": 684, - "loc": { - "start": { - "line": 35, - "column": 11 - }, - "end": { - "line": 35, - "column": 14 - } - }, - "typeAnnotation": { - "type": "TSLiteralType", - "start": 683, - "end": 684, - "loc": { - "start": { - "line": 35, - "column": 13 - }, - "end": { - "line": 35, - "column": 14 - } - }, - "literal": { - "type": "Literal", - "start": 683, - "end": 684, - "loc": { - "start": { - "line": 35, - "column": 13 - }, - "end": { - "line": 35, - "column": 14 - } - }, - "value": 1, - "raw": "1" - } - } - } - } - ] - }, - { - "type": "TSNullKeyword", - "start": 689, - "end": 693, - "loc": { - "start": { - "line": 35, - "column": 19 - }, - "end": { - "line": 35, - "column": 23 + "value": 1, + "raw": "1" } } } - ] + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " c", + "start": 636, + "end": 640 + } + ] + }, + { + "type": "TSNullKeyword", + "start": 659, + "end": 663, + "loc": { + "start": { + "line": 38, + "column": 5 + }, + "end": { + "line": 38, + "column": 9 + } } } - }, - "init": null - } - ], - "kind": "let", - "leadingComments": [ - { - "type": "Line", - "value": " The same positions still hug when nothing disqualifies it.", - "start": 608, - "end": 669 + ] } - ] + } }, { "type": "TSTypeAliasDeclaration", - "start": 696, - "end": 727, + "start": 671, + "end": 732, "loc": { "start": { - "line": 36, + "line": 41, "column": 1 }, "end": { - "line": 36, - "column": 32 + "line": 46, + "column": 6 } }, "id": { "type": "Identifier", - "start": 701, - "end": 702, + "start": 676, + "end": 677, "loc": { "start": { - "line": 36, + "line": 41, "column": 6 }, "end": { - "line": 36, + "line": 41, "column": 7 } }, "name": "H" }, "typeAnnotation": { - "type": "TSFunctionType", - "start": 705, - "end": 726, + "type": "TSConditionalType", + "start": 682, + "end": 731, "loc": { "start": { - "line": 36, - "column": 10 + "line": 42, + "column": 2 }, "end": { - "line": 36, - "column": 31 + "line": 46, + "column": 5 + } + }, + "checkType": { + "type": "TSUnionType", + "start": 682, + "end": 709, + "loc": { + "start": { + "line": 42, + "column": 2 + }, + "end": { + "line": 44, + "column": 8 + } + }, + "types": [ + { + "type": "TSTypeLiteral", + "start": 692, + "end": 700, + "loc": { + "start": { + "line": 43, + "column": 3 + }, + "end": { + "line": 43, + "column": 11 + } + }, + "members": [ + { + "type": "TSPropertySignature", + "start": 694, + "end": 698, + "loc": { + "start": { + "line": 43, + "column": 5 + }, + "end": { + "line": 43, + "column": 9 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 694, + "end": 695, + "loc": { + "start": { + "line": 43, + "column": 5 + }, + "end": { + "line": 43, + "column": 6 + } + }, + "name": "a" + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 695, + "end": 698, + "loc": { + "start": { + "line": 43, + "column": 6 + }, + "end": { + "line": 43, + "column": 9 + } + }, + "typeAnnotation": { + "type": "TSLiteralType", + "start": 697, + "end": 698, + "loc": { + "start": { + "line": 43, + "column": 8 + }, + "end": { + "line": 43, + "column": 9 + } + }, + "literal": { + "type": "Literal", + "start": 697, + "end": 698, + "loc": { + "start": { + "line": 43, + "column": 8 + }, + "end": { + "line": 43, + "column": 9 + } + }, + "value": 1, + "raw": "1" + } + } + } + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " c", + "start": 684, + "end": 688 + } + ] + }, + { + "type": "TSNullKeyword", + "start": 705, + "end": 709, + "loc": { + "start": { + "line": 44, + "column": 4 + }, + "end": { + "line": 44, + "column": 8 + } + } + } + ] + }, + "extendsType": { + "type": "TSTypeReference", + "start": 718, + "end": 719, + "loc": { + "start": { + "line": 44, + "column": 17 + }, + "end": { + "line": 44, + "column": 18 + } + }, + "typeName": { + "type": "Identifier", + "start": 718, + "end": 719, + "loc": { + "start": { + "line": 44, + "column": 17 + }, + "end": { + "line": 44, + "column": 18 + } + }, + "name": "U" + } + }, + "trueType": { + "type": "TSLiteralType", + "start": 724, + "end": 725, + "loc": { + "start": { + "line": 45, + "column": 4 + }, + "end": { + "line": 45, + "column": 5 + } + }, + "literal": { + "type": "Literal", + "start": 724, + "end": 725, + "loc": { + "start": { + "line": 45, + "column": 4 + }, + "end": { + "line": 45, + "column": 5 + } + }, + "value": 1, + "raw": "1" + } + }, + "falseType": { + "type": "TSLiteralType", + "start": 730, + "end": 731, + "loc": { + "start": { + "line": 46, + "column": 4 + }, + "end": { + "line": 46, + "column": 5 + } + }, + "literal": { + "type": "Literal", + "start": 730, + "end": 731, + "loc": { + "start": { + "line": 46, + "column": 4 + }, + "end": { + "line": 46, + "column": 5 + } + }, + "value": 2, + "raw": "2" + } + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "start": 735, + "end": 796, + "loc": { + "start": { + "line": 48, + "column": 1 + }, + "end": { + "line": 52, + "column": 6 + } + }, + "id": { + "type": "Identifier", + "start": 740, + "end": 741, + "loc": { + "start": { + "line": 48, + "column": 6 + }, + "end": { + "line": 48, + "column": 7 + } + }, + "name": "I" + }, + "typeAnnotation": { + "type": "TSConditionalType", + "start": 744, + "end": 795, + "loc": { + "start": { + "line": 48, + "column": 10 + }, + "end": { + "line": 52, + "column": 5 + } + }, + "checkType": { + "type": "TSTypeReference", + "start": 744, + "end": 745, + "loc": { + "start": { + "line": 48, + "column": 10 + }, + "end": { + "line": 48, + "column": 11 + } + }, + "typeName": { + "type": "Identifier", + "start": 744, + "end": 745, + "loc": { + "start": { + "line": 48, + "column": 10 + }, + "end": { + "line": 48, + "column": 11 + } + }, + "name": "T" + } + }, + "extendsType": { + "type": "TSTypeReference", + "start": 754, + "end": 755, + "loc": { + "start": { + "line": 48, + "column": 20 + }, + "end": { + "line": 48, + "column": 21 + } + }, + "typeName": { + "type": "Identifier", + "start": 754, + "end": 755, + "loc": { + "start": { + "line": 48, + "column": 20 + }, + "end": { + "line": 48, + "column": 21 + } + }, + "name": "U" + } + }, + "trueType": { + "type": "TSUnionType", + "start": 760, + "end": 789, + "loc": { + "start": { + "line": 49, + "column": 4 + }, + "end": { + "line": 51, + "column": 9 + } + }, + "types": [ + { + "type": "TSTypeLiteral", + "start": 771, + "end": 779, + "loc": { + "start": { + "line": 50, + "column": 4 + }, + "end": { + "line": 50, + "column": 12 + } + }, + "members": [ + { + "type": "TSPropertySignature", + "start": 773, + "end": 777, + "loc": { + "start": { + "line": 50, + "column": 6 + }, + "end": { + "line": 50, + "column": 10 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 773, + "end": 774, + "loc": { + "start": { + "line": 50, + "column": 6 + }, + "end": { + "line": 50, + "column": 7 + } + }, + "name": "a" + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 774, + "end": 777, + "loc": { + "start": { + "line": 50, + "column": 7 + }, + "end": { + "line": 50, + "column": 10 + } + }, + "typeAnnotation": { + "type": "TSLiteralType", + "start": 776, + "end": 777, + "loc": { + "start": { + "line": 50, + "column": 9 + }, + "end": { + "line": 50, + "column": 10 + } + }, + "literal": { + "type": "Literal", + "start": 776, + "end": 777, + "loc": { + "start": { + "line": 50, + "column": 9 + }, + "end": { + "line": 50, + "column": 10 + } + }, + "value": 1, + "raw": "1" + } + } + } + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " c", + "start": 762, + "end": 766 + } + ] + }, + { + "type": "TSNullKeyword", + "start": 785, + "end": 789, + "loc": { + "start": { + "line": 51, + "column": 5 + }, + "end": { + "line": 51, + "column": 9 + } + } + } + ] + }, + "falseType": { + "type": "TSLiteralType", + "start": 794, + "end": 795, + "loc": { + "start": { + "line": 52, + "column": 4 + }, + "end": { + "line": 52, + "column": 5 + } + }, + "literal": { + "type": "Literal", + "start": 794, + "end": 795, + "loc": { + "start": { + "line": 52, + "column": 4 + }, + "end": { + "line": 52, + "column": 5 + } + }, + "value": 2, + "raw": "2" + } + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "start": 799, + "end": 846, + "loc": { + "start": { + "line": 54, + "column": 1 + }, + "end": { + "line": 58, + "column": 3 + } + }, + "id": { + "type": "Identifier", + "start": 804, + "end": 805, + "loc": { + "start": { + "line": 54, + "column": 6 + }, + "end": { + "line": 54, + "column": 7 + } + }, + "name": "J" + }, + "typeAnnotation": { + "type": "TSTypeReference", + "start": 808, + "end": 845, + "loc": { + "start": { + "line": 54, + "column": 10 + }, + "end": { + "line": 58, + "column": 2 + } + }, + "typeName": { + "type": "Identifier", + "start": 808, + "end": 811, + "loc": { + "start": { + "line": 54, + "column": 10 + }, + "end": { + "line": 54, + "column": 13 + } + }, + "name": "Foo" + }, + "typeArguments": { + "type": "TSTypeParameterInstantiation", + "start": 811, + "end": 845, + "loc": { + "start": { + "line": 54, + "column": 13 + }, + "end": { + "line": 58, + "column": 2 + } + }, + "params": [ + { + "type": "TSUnionType", + "start": 815, + "end": 842, + "loc": { + "start": { + "line": 55, + "column": 2 + }, + "end": { + "line": 57, + "column": 8 + } + }, + "types": [ + { + "type": "TSTypeLiteral", + "start": 825, + "end": 833, + "loc": { + "start": { + "line": 56, + "column": 3 + }, + "end": { + "line": 56, + "column": 11 + } + }, + "members": [ + { + "type": "TSPropertySignature", + "start": 827, + "end": 831, + "loc": { + "start": { + "line": 56, + "column": 5 + }, + "end": { + "line": 56, + "column": 9 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 827, + "end": 828, + "loc": { + "start": { + "line": 56, + "column": 5 + }, + "end": { + "line": 56, + "column": 6 + } + }, + "name": "a" + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 828, + "end": 831, + "loc": { + "start": { + "line": 56, + "column": 6 + }, + "end": { + "line": 56, + "column": 9 + } + }, + "typeAnnotation": { + "type": "TSLiteralType", + "start": 830, + "end": 831, + "loc": { + "start": { + "line": 56, + "column": 8 + }, + "end": { + "line": 56, + "column": 9 + } + }, + "literal": { + "type": "Literal", + "start": 830, + "end": 831, + "loc": { + "start": { + "line": 56, + "column": 8 + }, + "end": { + "line": 56, + "column": 9 + } + }, + "value": 1, + "raw": "1" + } + } + } + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " c", + "start": 817, + "end": 821 + } + ] + }, + { + "type": "TSNullKeyword", + "start": 838, + "end": 842, + "loc": { + "start": { + "line": 57, + "column": 4 + }, + "end": { + "line": 57, + "column": 8 + } + } + } + ] + } + ] + } + } + }, + { + "type": "VariableDeclaration", + "start": 849, + "end": 898, + "loc": { + "start": { + "line": 60, + "column": 1 + }, + "end": { + "line": 64, + "column": 5 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 855, + "end": 897, + "loc": { + "start": { + "line": 60, + "column": 7 + }, + "end": { + "line": 64, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 855, + "end": 856, + "loc": { + "start": { + "line": 60, + "column": 7 + }, + "end": { + "line": 60, + "column": 8 + } + }, + "name": "k" + }, + "init": { + "type": "CallExpression", + "start": 859, + "end": 897, + "loc": { + "start": { + "line": 60, + "column": 11 + }, + "end": { + "line": 64, + "column": 4 + } + }, + "callee": { + "type": "Identifier", + "start": 859, + "end": 861, + "loc": { + "start": { + "line": 60, + "column": 11 + }, + "end": { + "line": 60, + "column": 13 + } + }, + "name": "fn" + }, + "arguments": [], + "typeArguments": { + "type": "TSTypeParameterInstantiation", + "start": 861, + "end": 895, + "loc": { + "start": { + "line": 60, + "column": 13 + }, + "end": { + "line": 64, + "column": 2 + } + }, + "params": [ + { + "type": "TSUnionType", + "start": 865, + "end": 892, + "loc": { + "start": { + "line": 61, + "column": 2 + }, + "end": { + "line": 63, + "column": 8 + } + }, + "types": [ + { + "type": "TSTypeLiteral", + "start": 875, + "end": 883, + "loc": { + "start": { + "line": 62, + "column": 3 + }, + "end": { + "line": 62, + "column": 11 + } + }, + "members": [ + { + "type": "TSPropertySignature", + "start": 877, + "end": 881, + "loc": { + "start": { + "line": 62, + "column": 5 + }, + "end": { + "line": 62, + "column": 9 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 877, + "end": 878, + "loc": { + "start": { + "line": 62, + "column": 5 + }, + "end": { + "line": 62, + "column": 6 + } + }, + "name": "a" + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 878, + "end": 881, + "loc": { + "start": { + "line": 62, + "column": 6 + }, + "end": { + "line": 62, + "column": 9 + } + }, + "typeAnnotation": { + "type": "TSLiteralType", + "start": 880, + "end": 881, + "loc": { + "start": { + "line": 62, + "column": 8 + }, + "end": { + "line": 62, + "column": 9 + } + }, + "literal": { + "type": "Literal", + "start": 880, + "end": 881, + "loc": { + "start": { + "line": 62, + "column": 8 + }, + "end": { + "line": 62, + "column": 9 + } + }, + "value": 1, + "raw": "1" + } + } + } + } + ], + "leadingComments": [ + { + "type": "Line", + "value": " c", + "start": 867, + "end": 871 + } + ] + }, + { + "type": "TSNullKeyword", + "start": 888, + "end": 892, + "loc": { + "start": { + "line": 63, + "column": 4 + }, + "end": { + "line": 63, + "column": 8 + } + } + } + ] + } + ] + } + } + } + ], + "kind": "const" + }, + { + "type": "VariableDeclaration", + "start": 964, + "end": 987, + "loc": { + "start": { + "line": 67, + "column": 1 + }, + "end": { + "line": 67, + "column": 24 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 968, + "end": 986, + "loc": { + "start": { + "line": 67, + "column": 5 + }, + "end": { + "line": 67, + "column": 23 + } + }, + "id": { + "type": "Identifier", + "start": 968, + "end": 986, + "loc": { + "start": { + "line": 67, + "column": 5 + }, + "end": { + "line": 67, + "column": 23 + } + }, + "name": "l", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 969, + "end": 986, + "loc": { + "start": { + "line": 67, + "column": 6 + }, + "end": { + "line": 67, + "column": 23 + } + }, + "typeAnnotation": { + "type": "TSUnionType", + "start": 971, + "end": 986, + "loc": { + "start": { + "line": 67, + "column": 8 + }, + "end": { + "line": 67, + "column": 23 + } + }, + "types": [ + { + "type": "TSTypeLiteral", + "start": 971, + "end": 979, + "loc": { + "start": { + "line": 67, + "column": 8 + }, + "end": { + "line": 67, + "column": 16 + } + }, + "members": [ + { + "type": "TSPropertySignature", + "start": 973, + "end": 977, + "loc": { + "start": { + "line": 67, + "column": 10 + }, + "end": { + "line": 67, + "column": 14 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 973, + "end": 974, + "loc": { + "start": { + "line": 67, + "column": 10 + }, + "end": { + "line": 67, + "column": 11 + } + }, + "name": "a" + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 974, + "end": 977, + "loc": { + "start": { + "line": 67, + "column": 11 + }, + "end": { + "line": 67, + "column": 14 + } + }, + "typeAnnotation": { + "type": "TSLiteralType", + "start": 976, + "end": 977, + "loc": { + "start": { + "line": 67, + "column": 13 + }, + "end": { + "line": 67, + "column": 14 + } + }, + "literal": { + "type": "Literal", + "start": 976, + "end": 977, + "loc": { + "start": { + "line": 67, + "column": 13 + }, + "end": { + "line": 67, + "column": 14 + } + }, + "value": 1, + "raw": "1" + } + } + } + } + ] + }, + { + "type": "TSNullKeyword", + "start": 982, + "end": 986, + "loc": { + "start": { + "line": 67, + "column": 19 + }, + "end": { + "line": 67, + "column": 23 + } + } + } + ] + } + } + }, + "init": null + } + ], + "kind": "let", + "leadingComments": [ + { + "type": "Line", + "value": " The same positions still hug when nothing disqualifies it.", + "start": 901, + "end": 962 + } + ] + }, + { + "type": "TSTypeAliasDeclaration", + "start": 989, + "end": 1020, + "loc": { + "start": { + "line": 68, + "column": 1 + }, + "end": { + "line": 68, + "column": 32 + } + }, + "id": { + "type": "Identifier", + "start": 994, + "end": 995, + "loc": { + "start": { + "line": 68, + "column": 6 + }, + "end": { + "line": 68, + "column": 7 + } + }, + "name": "M" + }, + "typeAnnotation": { + "type": "TSFunctionType", + "start": 998, + "end": 1019, + "loc": { + "start": { + "line": 68, + "column": 10 + }, + "end": { + "line": 68, + "column": 31 } }, "parameters": [], "typeAnnotation": { "type": "TSTypeAnnotation", - "start": 708, - "end": 726, + "start": 1001, + "end": 1019, "loc": { "start": { - "line": 36, + "line": 68, "column": 13 }, "end": { - "line": 36, + "line": 68, "column": 31 } }, "typeAnnotation": { "type": "TSUnionType", - "start": 711, - "end": 726, + "start": 1004, + "end": 1019, "loc": { "start": { - "line": 36, + "line": 68, "column": 16 }, "end": { - "line": 36, + "line": 68, "column": 31 } }, "types": [ { "type": "TSTypeLiteral", - "start": 711, - "end": 719, + "start": 1004, + "end": 1012, "loc": { "start": { - "line": 36, + "line": 68, "column": 16 }, "end": { - "line": 36, + "line": 68, "column": 24 } }, "members": [ { "type": "TSPropertySignature", - "start": 713, - "end": 717, + "start": 1006, + "end": 1010, "loc": { "start": { - "line": 36, + "line": 68, "column": 18 }, "end": { - "line": 36, + "line": 68, "column": 22 } }, "computed": false, "key": { "type": "Identifier", - "start": 713, - "end": 714, + "start": 1006, + "end": 1007, "loc": { "start": { - "line": 36, + "line": 68, "column": 18 }, "end": { - "line": 36, + "line": 68, "column": 19 } }, @@ -1635,43 +2947,43 @@ }, "typeAnnotation": { "type": "TSTypeAnnotation", - "start": 714, - "end": 717, + "start": 1007, + "end": 1010, "loc": { "start": { - "line": 36, + "line": 68, "column": 19 }, "end": { - "line": 36, + "line": 68, "column": 22 } }, "typeAnnotation": { "type": "TSLiteralType", - "start": 716, - "end": 717, + "start": 1009, + "end": 1010, "loc": { "start": { - "line": 36, + "line": 68, "column": 21 }, "end": { - "line": 36, + "line": 68, "column": 22 } }, "literal": { "type": "Literal", - "start": 716, - "end": 717, + "start": 1009, + "end": 1010, "loc": { "start": { - "line": 36, + "line": 68, "column": 21 }, "end": { - "line": 36, + "line": 68, "column": 22 } }, @@ -1685,15 +2997,15 @@ }, { "type": "TSNullKeyword", - "start": 722, - "end": 726, + "start": 1015, + "end": 1019, "loc": { "start": { - "line": 36, + "line": 68, "column": 27 }, "end": { - "line": 36, + "line": 68, "column": 31 } } @@ -1705,74 +3017,74 @@ }, { "type": "VariableDeclaration", - "start": 729, - "end": 763, + "start": 1022, + "end": 1056, "loc": { "start": { - "line": 37, + "line": 69, "column": 1 }, "end": { - "line": 37, + "line": 69, "column": 35 } }, "declarations": [ { "type": "VariableDeclarator", - "start": 735, - "end": 762, + "start": 1028, + "end": 1055, "loc": { "start": { - "line": 37, + "line": 69, "column": 7 }, "end": { - "line": 37, + "line": 69, "column": 34 } }, "id": { "type": "Identifier", - "start": 735, - "end": 736, + "start": 1028, + "end": 1029, "loc": { "start": { - "line": 37, + "line": 69, "column": 7 }, "end": { - "line": 37, + "line": 69, "column": 8 } }, - "name": "i" + "name": "n" }, "init": { "type": "TSAsExpression", - "start": 739, - "end": 762, + "start": 1032, + "end": 1055, "loc": { "start": { - "line": 37, + "line": 69, "column": 11 }, "end": { - "line": 37, + "line": 69, "column": 34 } }, "expression": { "type": "Identifier", - "start": 739, - "end": 743, + "start": 1032, + "end": 1036, "loc": { "start": { - "line": 37, + "line": 69, "column": 11 }, "end": { - "line": 37, + "line": 69, "column": 15 } }, @@ -1780,60 +3092,60 @@ }, "typeAnnotation": { "type": "TSUnionType", - "start": 747, - "end": 762, + "start": 1040, + "end": 1055, "loc": { "start": { - "line": 37, + "line": 69, "column": 19 }, "end": { - "line": 37, + "line": 69, "column": 34 } }, "types": [ { "type": "TSTypeLiteral", - "start": 747, - "end": 755, + "start": 1040, + "end": 1048, "loc": { "start": { - "line": 37, + "line": 69, "column": 19 }, "end": { - "line": 37, + "line": 69, "column": 27 } }, "members": [ { "type": "TSPropertySignature", - "start": 749, - "end": 753, + "start": 1042, + "end": 1046, "loc": { "start": { - "line": 37, + "line": 69, "column": 21 }, "end": { - "line": 37, + "line": 69, "column": 25 } }, "computed": false, "key": { "type": "Identifier", - "start": 749, - "end": 750, + "start": 1042, + "end": 1043, "loc": { "start": { - "line": 37, + "line": 69, "column": 21 }, "end": { - "line": 37, + "line": 69, "column": 22 } }, @@ -1841,43 +3153,43 @@ }, "typeAnnotation": { "type": "TSTypeAnnotation", - "start": 750, - "end": 753, + "start": 1043, + "end": 1046, "loc": { "start": { - "line": 37, + "line": 69, "column": 22 }, "end": { - "line": 37, + "line": 69, "column": 25 } }, "typeAnnotation": { "type": "TSLiteralType", - "start": 752, - "end": 753, + "start": 1045, + "end": 1046, "loc": { "start": { - "line": 37, + "line": 69, "column": 24 }, "end": { - "line": 37, + "line": 69, "column": 25 } }, "literal": { "type": "Literal", - "start": 752, - "end": 753, + "start": 1045, + "end": 1046, "loc": { "start": { - "line": 37, + "line": 69, "column": 24 }, "end": { - "line": 37, + "line": 69, "column": 25 } }, @@ -1891,15 +3203,15 @@ }, { "type": "TSNullKeyword", - "start": 758, - "end": 762, + "start": 1051, + "end": 1055, "loc": { "start": { - "line": 37, + "line": 69, "column": 30 }, "end": { - "line": 37, + "line": 69, "column": 34 } } diff --git a/tests/fixtures/typescript/types/union_hug_leading_line_comment_prettier_divergence/input.svelte b/tests/fixtures/typescript/types/union_hug_leading_line_comment_prettier_divergence/input.svelte index a6d9c98e..2238e07d 100644 --- a/tests/fixtures/typescript/types/union_hug_leading_line_comment_prettier_divergence/input.svelte +++ b/tests/fixtures/typescript/types/union_hug_leading_line_comment_prettier_divergence/input.svelte @@ -31,8 +31,40 @@ { a: 1 } | null; + type G = { + [K in T]: + | // c + { a: 1 } + | null; + }; + + type H = + | // c + { a: 1 } + | null extends U + ? 1 + : 2; + + type I = T extends U + ? | // c + { a: 1 } + | null + : 2; + + type J = Foo< + | // c + { a: 1 } + | null + >; + + const k = fn< + | // c + { a: 1 } + | null + >(); + // The same positions still hug when nothing disqualifies it. - let g: { a: 1 } | null; - type H = () => { a: 1 } | null; - const i = expr as { a: 1 } | null; + let l: { a: 1 } | null; + type M = () => { a: 1 } | null; + const n = expr as { a: 1 } | null; diff --git a/tests/fixtures/typescript/types/union_hug_leading_line_comment_prettier_divergence/output_prettier.svelte b/tests/fixtures/typescript/types/union_hug_leading_line_comment_prettier_divergence/output_prettier.svelte index 95f92f8c..42b036d3 100644 --- a/tests/fixtures/typescript/types/union_hug_leading_line_comment_prettier_divergence/output_prettier.svelte +++ b/tests/fixtures/typescript/types/union_hug_leading_line_comment_prettier_divergence/output_prettier.svelte @@ -31,8 +31,40 @@ { a: 1 } | null; + type G = { + [K in T]: + | // c + { a: 1 } + | null; + }; + + type H = + | // c + { a: 1 } + | null extends U + ? 1 + : 2; + + type I = T extends U + ? | // c + { a: 1 } + | null + : 2; + + type J = Foo< + | // c + { a: 1 } + | null + >; + + const k = fn< + | // c + { a: 1 } + | null + >(); + // The same positions still hug when nothing disqualifies it. - let g: { a: 1 } | null; - type H = () => { a: 1 } | null; - const i = expr as { a: 1 } | null; + let l: { a: 1 } | null; + type M = () => { a: 1 } | null; + const n = expr as { a: 1 } | null; diff --git a/tests/fixtures/typescript/types/union_hug_member_block_comment/expected.json b/tests/fixtures/typescript/types/union_hug_member_block_comment/expected.json new file mode 100644 index 00000000..122b5faa --- /dev/null +++ b/tests/fixtures/typescript/types/union_hug_member_block_comment/expected.json @@ -0,0 +1,2607 @@ +{ + "css": null, + "js": [], + "start": 0, + "end": 928, + "type": "Root", + "fragment": { + "type": "Fragment", + "nodes": [] + }, + "options": null, + "comments": [ + { + "type": "Line", + "value": " An own-line block comment between members disqualifies the union hug, so each", + "start": 20, + "end": 100, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 81 + } + } + }, + { + "type": "Line", + "value": " position that can hold a union breaks after its keyword instead of gluing.", + "start": 102, + "end": 179, + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 78 + } + } + }, + { + "type": "Line", + "value": " `=` - the type-alias RHS", + "start": 182, + "end": 209, + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 28 + } + } + }, + { + "type": "Block", + "value": " c ", + "start": 235, + "end": 242, + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 9 + } + } + }, + { + "type": "Line", + "value": " `:` - an annotation", + "start": 255, + "end": 277, + "loc": { + "start": { + "line": 11, + "column": 1 + }, + "end": { + "line": 11, + "column": 23 + } + } + }, + { + "type": "Block", + "value": " c ", + "start": 301, + "end": 308, + "loc": { + "start": { + "line": 14, + "column": 2 + }, + "end": { + "line": 14, + "column": 9 + } + } + }, + { + "type": "Line", + "value": " a mapped-type value", + "start": 321, + "end": 343, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 23 + } + } + }, + { + "type": "Block", + "value": " c ", + "start": 385, + "end": 392, + "loc": { + "start": { + "line": 21, + "column": 3 + }, + "end": { + "line": 21, + "column": 10 + } + } + }, + { + "type": "Line", + "value": " a conditional check", + "start": 410, + "end": 432, + "loc": { + "start": { + "line": 25, + "column": 1 + }, + "end": { + "line": 25, + "column": 23 + } + } + }, + { + "type": "Block", + "value": " c ", + "start": 458, + "end": 465, + "loc": { + "start": { + "line": 28, + "column": 2 + }, + "end": { + "line": 28, + "column": 9 + } + } + }, + { + "type": "Line", + "value": " a conditional branch", + "start": 500, + "end": 523, + "loc": { + "start": { + "line": 33, + "column": 1 + }, + "end": { + "line": 33, + "column": 24 + } + } + }, + { + "type": "Block", + "value": " c ", + "start": 564, + "end": 571, + "loc": { + "start": { + "line": 36, + "column": 3 + }, + "end": { + "line": 36, + "column": 10 + } + } + }, + { + "type": "Line", + "value": " a type argument", + "start": 591, + "end": 609, + "loc": { + "start": { + "line": 40, + "column": 1 + }, + "end": { + "line": 40, + "column": 19 + } + } + }, + { + "type": "Block", + "value": " c ", + "start": 640, + "end": 647, + "loc": { + "start": { + "line": 43, + "column": 2 + }, + "end": { + "line": 43, + "column": 9 + } + } + }, + { + "type": "Line", + "value": " a type argument in expression position", + "start": 663, + "end": 704, + "loc": { + "start": { + "line": 47, + "column": 1 + }, + "end": { + "line": 47, + "column": 42 + } + } + }, + { + "type": "Block", + "value": " c ", + "start": 735, + "end": 742, + "loc": { + "start": { + "line": 50, + "column": 2 + }, + "end": { + "line": 50, + "column": 9 + } + } + }, + { + "type": "Line", + "value": " Controls - nothing disqualifies the hug, so it still happens.", + "start": 760, + "end": 824, + "loc": { + "start": { + "line": 54, + "column": 1 + }, + "end": { + "line": 54, + "column": 65 + } + } + } + ], + "instance": { + "type": "Script", + "start": 0, + "end": 927, + "context": "default", + "content": { + "type": "Program", + "start": 18, + "end": 918, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 58, + "column": 9 + } + }, + "body": [ + { + "type": "TSTypeAliasDeclaration", + "start": 211, + "end": 252, + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 9, + "column": 9 + } + }, + "id": { + "type": "Identifier", + "start": 216, + "end": 217, + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 6, + "column": 7 + } + }, + "name": "A" + }, + "typeAnnotation": { + "type": "TSUnionType", + "start": 222, + "end": 251, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 9, + "column": 8 + } + }, + "types": [ + { + "type": "TSTypeLiteral", + "start": 224, + "end": 232, + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 12 + } + }, + "members": [ + { + "type": "TSPropertySignature", + "start": 226, + "end": 230, + "loc": { + "start": { + "line": 7, + "column": 6 + }, + "end": { + "line": 7, + "column": 10 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 226, + "end": 227, + "loc": { + "start": { + "line": 7, + "column": 6 + }, + "end": { + "line": 7, + "column": 7 + } + }, + "name": "a" + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 227, + "end": 230, + "loc": { + "start": { + "line": 7, + "column": 7 + }, + "end": { + "line": 7, + "column": 10 + } + }, + "typeAnnotation": { + "type": "TSLiteralType", + "start": 229, + "end": 230, + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 7, + "column": 10 + } + }, + "literal": { + "type": "Literal", + "start": 229, + "end": 230, + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 7, + "column": 10 + } + }, + "value": 1, + "raw": "1" + } + } + } + } + ] + }, + { + "type": "TSNullKeyword", + "start": 247, + "end": 251, + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 8 + } + }, + "leadingComments": [ + { + "type": "Block", + "value": " c ", + "start": 235, + "end": 242 + } + ] + } + ] + }, + "leadingComments": [ + { + "type": "Line", + "value": " An own-line block comment between members disqualifies the union hug, so each", + "start": 20, + "end": 100 + }, + { + "type": "Line", + "value": " position that can hold a union breaks after its keyword instead of gluing.", + "start": 102, + "end": 179 + }, + { + "type": "Line", + "value": " `=` - the type-alias RHS", + "start": 182, + "end": 209 + } + ] + }, + { + "type": "VariableDeclaration", + "start": 279, + "end": 318, + "loc": { + "start": { + "line": 12, + "column": 1 + }, + "end": { + "line": 15, + "column": 9 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 283, + "end": 317, + "loc": { + "start": { + "line": 12, + "column": 5 + }, + "end": { + "line": 15, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 283, + "end": 317, + "loc": { + "start": { + "line": 12, + "column": 5 + }, + "end": { + "line": 15, + "column": 8 + } + }, + "name": "b", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 284, + "end": 317, + "loc": { + "start": { + "line": 12, + "column": 6 + }, + "end": { + "line": 15, + "column": 8 + } + }, + "typeAnnotation": { + "type": "TSUnionType", + "start": 288, + "end": 317, + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 15, + "column": 8 + } + }, + "types": [ + { + "type": "TSTypeLiteral", + "start": 290, + "end": 298, + "loc": { + "start": { + "line": 13, + "column": 4 + }, + "end": { + "line": 13, + "column": 12 + } + }, + "members": [ + { + "type": "TSPropertySignature", + "start": 292, + "end": 296, + "loc": { + "start": { + "line": 13, + "column": 6 + }, + "end": { + "line": 13, + "column": 10 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 292, + "end": 293, + "loc": { + "start": { + "line": 13, + "column": 6 + }, + "end": { + "line": 13, + "column": 7 + } + }, + "name": "a" + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 293, + "end": 296, + "loc": { + "start": { + "line": 13, + "column": 7 + }, + "end": { + "line": 13, + "column": 10 + } + }, + "typeAnnotation": { + "type": "TSLiteralType", + "start": 295, + "end": 296, + "loc": { + "start": { + "line": 13, + "column": 9 + }, + "end": { + "line": 13, + "column": 10 + } + }, + "literal": { + "type": "Literal", + "start": 295, + "end": 296, + "loc": { + "start": { + "line": 13, + "column": 9 + }, + "end": { + "line": 13, + "column": 10 + } + }, + "value": 1, + "raw": "1" + } + } + } + } + ] + }, + { + "type": "TSNullKeyword", + "start": 313, + "end": 317, + "loc": { + "start": { + "line": 15, + "column": 4 + }, + "end": { + "line": 15, + "column": 8 + } + }, + "leadingComments": [ + { + "type": "Block", + "value": " c ", + "start": 301, + "end": 308 + } + ] + } + ] + } + } + }, + "init": null + } + ], + "kind": "let", + "leadingComments": [ + { + "type": "Line", + "value": " `:` - an annotation", + "start": 255, + "end": 277 + } + ] + }, + { + "type": "TSTypeAliasDeclaration", + "start": 345, + "end": 407, + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 23, + "column": 3 + } + }, + "id": { + "type": "Identifier", + "start": 350, + "end": 351, + "loc": { + "start": { + "line": 18, + "column": 6 + }, + "end": { + "line": 18, + "column": 7 + } + }, + "name": "C" + }, + "typeAnnotation": { + "type": "TSMappedType", + "start": 354, + "end": 406, + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 23, + "column": 2 + } + }, + "typeParameter": { + "type": "TSTypeParameter", + "start": 359, + "end": 365, + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 19, + "column": 9 + } + }, + "name": "K", + "constraint": { + "type": "TSTypeReference", + "start": 364, + "end": 365, + "loc": { + "start": { + "line": 19, + "column": 8 + }, + "end": { + "line": 19, + "column": 9 + } + }, + "typeName": { + "type": "Identifier", + "start": 364, + "end": 365, + "loc": { + "start": { + "line": 19, + "column": 8 + }, + "end": { + "line": 19, + "column": 9 + } + }, + "name": "T" + } + } + }, + "nameType": null, + "typeAnnotation": { + "type": "TSUnionType", + "start": 371, + "end": 402, + "loc": { + "start": { + "line": 20, + "column": 3 + }, + "end": { + "line": 22, + "column": 9 + } + }, + "types": [ + { + "type": "TSTypeLiteral", + "start": 373, + "end": 381, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 13 + } + }, + "members": [ + { + "type": "TSPropertySignature", + "start": 375, + "end": 379, + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 11 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 375, + "end": 376, + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 8 + } + }, + "name": "a" + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 376, + "end": 379, + "loc": { + "start": { + "line": 20, + "column": 8 + }, + "end": { + "line": 20, + "column": 11 + } + }, + "typeAnnotation": { + "type": "TSLiteralType", + "start": 378, + "end": 379, + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 11 + } + }, + "literal": { + "type": "Literal", + "start": 378, + "end": 379, + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 11 + } + }, + "value": 1, + "raw": "1" + } + } + } + } + ] + }, + { + "type": "TSNullKeyword", + "start": 398, + "end": 402, + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 9 + } + }, + "leadingComments": [ + { + "type": "Block", + "value": " c ", + "start": 385, + "end": 392 + } + ] + } + ] + } + }, + "leadingComments": [ + { + "type": "Line", + "value": " a mapped-type value", + "start": 321, + "end": 343 + } + ] + }, + { + "type": "TSTypeAliasDeclaration", + "start": 434, + "end": 497, + "loc": { + "start": { + "line": 26, + "column": 1 + }, + "end": { + "line": 31, + "column": 6 + } + }, + "id": { + "type": "Identifier", + "start": 439, + "end": 440, + "loc": { + "start": { + "line": 26, + "column": 6 + }, + "end": { + "line": 26, + "column": 7 + } + }, + "name": "D" + }, + "typeAnnotation": { + "type": "TSConditionalType", + "start": 445, + "end": 496, + "loc": { + "start": { + "line": 27, + "column": 2 + }, + "end": { + "line": 31, + "column": 5 + } + }, + "checkType": { + "type": "TSUnionType", + "start": 445, + "end": 474, + "loc": { + "start": { + "line": 27, + "column": 2 + }, + "end": { + "line": 29, + "column": 8 + } + }, + "types": [ + { + "type": "TSTypeLiteral", + "start": 447, + "end": 455, + "loc": { + "start": { + "line": 27, + "column": 4 + }, + "end": { + "line": 27, + "column": 12 + } + }, + "members": [ + { + "type": "TSPropertySignature", + "start": 449, + "end": 453, + "loc": { + "start": { + "line": 27, + "column": 6 + }, + "end": { + "line": 27, + "column": 10 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 449, + "end": 450, + "loc": { + "start": { + "line": 27, + "column": 6 + }, + "end": { + "line": 27, + "column": 7 + } + }, + "name": "a" + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 450, + "end": 453, + "loc": { + "start": { + "line": 27, + "column": 7 + }, + "end": { + "line": 27, + "column": 10 + } + }, + "typeAnnotation": { + "type": "TSLiteralType", + "start": 452, + "end": 453, + "loc": { + "start": { + "line": 27, + "column": 9 + }, + "end": { + "line": 27, + "column": 10 + } + }, + "literal": { + "type": "Literal", + "start": 452, + "end": 453, + "loc": { + "start": { + "line": 27, + "column": 9 + }, + "end": { + "line": 27, + "column": 10 + } + }, + "value": 1, + "raw": "1" + } + } + } + } + ] + }, + { + "type": "TSNullKeyword", + "start": 470, + "end": 474, + "loc": { + "start": { + "line": 29, + "column": 4 + }, + "end": { + "line": 29, + "column": 8 + } + }, + "leadingComments": [ + { + "type": "Block", + "value": " c ", + "start": 458, + "end": 465 + } + ] + } + ] + }, + "extendsType": { + "type": "TSTypeReference", + "start": 483, + "end": 484, + "loc": { + "start": { + "line": 29, + "column": 17 + }, + "end": { + "line": 29, + "column": 18 + } + }, + "typeName": { + "type": "Identifier", + "start": 483, + "end": 484, + "loc": { + "start": { + "line": 29, + "column": 17 + }, + "end": { + "line": 29, + "column": 18 + } + }, + "name": "U" + } + }, + "trueType": { + "type": "TSLiteralType", + "start": 489, + "end": 490, + "loc": { + "start": { + "line": 30, + "column": 4 + }, + "end": { + "line": 30, + "column": 5 + } + }, + "literal": { + "type": "Literal", + "start": 489, + "end": 490, + "loc": { + "start": { + "line": 30, + "column": 4 + }, + "end": { + "line": 30, + "column": 5 + } + }, + "value": 1, + "raw": "1" + } + }, + "falseType": { + "type": "TSLiteralType", + "start": 495, + "end": 496, + "loc": { + "start": { + "line": 31, + "column": 4 + }, + "end": { + "line": 31, + "column": 5 + } + }, + "literal": { + "type": "Literal", + "start": 495, + "end": 496, + "loc": { + "start": { + "line": 31, + "column": 4 + }, + "end": { + "line": 31, + "column": 5 + } + }, + "value": 2, + "raw": "2" + } + } + }, + "leadingComments": [ + { + "type": "Line", + "value": " a conditional check", + "start": 410, + "end": 432 + } + ] + }, + { + "type": "TSTypeAliasDeclaration", + "start": 525, + "end": 588, + "loc": { + "start": { + "line": 34, + "column": 1 + }, + "end": { + "line": 38, + "column": 6 + } + }, + "id": { + "type": "Identifier", + "start": 530, + "end": 531, + "loc": { + "start": { + "line": 34, + "column": 6 + }, + "end": { + "line": 34, + "column": 7 + } + }, + "name": "E" + }, + "typeAnnotation": { + "type": "TSConditionalType", + "start": 534, + "end": 587, + "loc": { + "start": { + "line": 34, + "column": 10 + }, + "end": { + "line": 38, + "column": 5 + } + }, + "checkType": { + "type": "TSTypeReference", + "start": 534, + "end": 535, + "loc": { + "start": { + "line": 34, + "column": 10 + }, + "end": { + "line": 34, + "column": 11 + } + }, + "typeName": { + "type": "Identifier", + "start": 534, + "end": 535, + "loc": { + "start": { + "line": 34, + "column": 10 + }, + "end": { + "line": 34, + "column": 11 + } + }, + "name": "T" + } + }, + "extendsType": { + "type": "TSTypeReference", + "start": 544, + "end": 545, + "loc": { + "start": { + "line": 34, + "column": 20 + }, + "end": { + "line": 34, + "column": 21 + } + }, + "typeName": { + "type": "Identifier", + "start": 544, + "end": 545, + "loc": { + "start": { + "line": 34, + "column": 20 + }, + "end": { + "line": 34, + "column": 21 + } + }, + "name": "U" + } + }, + "trueType": { + "type": "TSUnionType", + "start": 550, + "end": 581, + "loc": { + "start": { + "line": 35, + "column": 4 + }, + "end": { + "line": 37, + "column": 9 + } + }, + "types": [ + { + "type": "TSTypeLiteral", + "start": 552, + "end": 560, + "loc": { + "start": { + "line": 35, + "column": 6 + }, + "end": { + "line": 35, + "column": 14 + } + }, + "members": [ + { + "type": "TSPropertySignature", + "start": 554, + "end": 558, + "loc": { + "start": { + "line": 35, + "column": 8 + }, + "end": { + "line": 35, + "column": 12 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 554, + "end": 555, + "loc": { + "start": { + "line": 35, + "column": 8 + }, + "end": { + "line": 35, + "column": 9 + } + }, + "name": "a" + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 555, + "end": 558, + "loc": { + "start": { + "line": 35, + "column": 9 + }, + "end": { + "line": 35, + "column": 12 + } + }, + "typeAnnotation": { + "type": "TSLiteralType", + "start": 557, + "end": 558, + "loc": { + "start": { + "line": 35, + "column": 11 + }, + "end": { + "line": 35, + "column": 12 + } + }, + "literal": { + "type": "Literal", + "start": 557, + "end": 558, + "loc": { + "start": { + "line": 35, + "column": 11 + }, + "end": { + "line": 35, + "column": 12 + } + }, + "value": 1, + "raw": "1" + } + } + } + } + ] + }, + { + "type": "TSNullKeyword", + "start": 577, + "end": 581, + "loc": { + "start": { + "line": 37, + "column": 5 + }, + "end": { + "line": 37, + "column": 9 + } + }, + "leadingComments": [ + { + "type": "Block", + "value": " c ", + "start": 564, + "end": 571 + } + ] + } + ] + }, + "falseType": { + "type": "TSLiteralType", + "start": 586, + "end": 587, + "loc": { + "start": { + "line": 38, + "column": 4 + }, + "end": { + "line": 38, + "column": 5 + } + }, + "literal": { + "type": "Literal", + "start": 586, + "end": 587, + "loc": { + "start": { + "line": 38, + "column": 4 + }, + "end": { + "line": 38, + "column": 5 + } + }, + "value": 2, + "raw": "2" + } + } + }, + "leadingComments": [ + { + "type": "Line", + "value": " a conditional branch", + "start": 500, + "end": 523 + } + ] + }, + { + "type": "TSTypeAliasDeclaration", + "start": 611, + "end": 660, + "loc": { + "start": { + "line": 41, + "column": 1 + }, + "end": { + "line": 45, + "column": 3 + } + }, + "id": { + "type": "Identifier", + "start": 616, + "end": 617, + "loc": { + "start": { + "line": 41, + "column": 6 + }, + "end": { + "line": 41, + "column": 7 + } + }, + "name": "F" + }, + "typeAnnotation": { + "type": "TSTypeReference", + "start": 620, + "end": 659, + "loc": { + "start": { + "line": 41, + "column": 10 + }, + "end": { + "line": 45, + "column": 2 + } + }, + "typeName": { + "type": "Identifier", + "start": 620, + "end": 623, + "loc": { + "start": { + "line": 41, + "column": 10 + }, + "end": { + "line": 41, + "column": 13 + } + }, + "name": "Foo" + }, + "typeArguments": { + "type": "TSTypeParameterInstantiation", + "start": 623, + "end": 659, + "loc": { + "start": { + "line": 41, + "column": 13 + }, + "end": { + "line": 45, + "column": 2 + } + }, + "params": [ + { + "type": "TSUnionType", + "start": 627, + "end": 656, + "loc": { + "start": { + "line": 42, + "column": 2 + }, + "end": { + "line": 44, + "column": 8 + } + }, + "types": [ + { + "type": "TSTypeLiteral", + "start": 629, + "end": 637, + "loc": { + "start": { + "line": 42, + "column": 4 + }, + "end": { + "line": 42, + "column": 12 + } + }, + "members": [ + { + "type": "TSPropertySignature", + "start": 631, + "end": 635, + "loc": { + "start": { + "line": 42, + "column": 6 + }, + "end": { + "line": 42, + "column": 10 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 631, + "end": 632, + "loc": { + "start": { + "line": 42, + "column": 6 + }, + "end": { + "line": 42, + "column": 7 + } + }, + "name": "a" + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 632, + "end": 635, + "loc": { + "start": { + "line": 42, + "column": 7 + }, + "end": { + "line": 42, + "column": 10 + } + }, + "typeAnnotation": { + "type": "TSLiteralType", + "start": 634, + "end": 635, + "loc": { + "start": { + "line": 42, + "column": 9 + }, + "end": { + "line": 42, + "column": 10 + } + }, + "literal": { + "type": "Literal", + "start": 634, + "end": 635, + "loc": { + "start": { + "line": 42, + "column": 9 + }, + "end": { + "line": 42, + "column": 10 + } + }, + "value": 1, + "raw": "1" + } + } + } + } + ] + }, + { + "type": "TSNullKeyword", + "start": 652, + "end": 656, + "loc": { + "start": { + "line": 44, + "column": 4 + }, + "end": { + "line": 44, + "column": 8 + } + }, + "leadingComments": [ + { + "type": "Block", + "value": " c ", + "start": 640, + "end": 647 + } + ] + } + ] + } + ] + } + }, + "leadingComments": [ + { + "type": "Line", + "value": " a type argument", + "start": 591, + "end": 609 + } + ] + }, + { + "type": "VariableDeclaration", + "start": 706, + "end": 757, + "loc": { + "start": { + "line": 48, + "column": 1 + }, + "end": { + "line": 52, + "column": 5 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 712, + "end": 756, + "loc": { + "start": { + "line": 48, + "column": 7 + }, + "end": { + "line": 52, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 712, + "end": 713, + "loc": { + "start": { + "line": 48, + "column": 7 + }, + "end": { + "line": 48, + "column": 8 + } + }, + "name": "g" + }, + "init": { + "type": "CallExpression", + "start": 716, + "end": 756, + "loc": { + "start": { + "line": 48, + "column": 11 + }, + "end": { + "line": 52, + "column": 4 + } + }, + "callee": { + "type": "Identifier", + "start": 716, + "end": 718, + "loc": { + "start": { + "line": 48, + "column": 11 + }, + "end": { + "line": 48, + "column": 13 + } + }, + "name": "fn" + }, + "arguments": [], + "typeArguments": { + "type": "TSTypeParameterInstantiation", + "start": 718, + "end": 754, + "loc": { + "start": { + "line": 48, + "column": 13 + }, + "end": { + "line": 52, + "column": 2 + } + }, + "params": [ + { + "type": "TSUnionType", + "start": 722, + "end": 751, + "loc": { + "start": { + "line": 49, + "column": 2 + }, + "end": { + "line": 51, + "column": 8 + } + }, + "types": [ + { + "type": "TSTypeLiteral", + "start": 724, + "end": 732, + "loc": { + "start": { + "line": 49, + "column": 4 + }, + "end": { + "line": 49, + "column": 12 + } + }, + "members": [ + { + "type": "TSPropertySignature", + "start": 726, + "end": 730, + "loc": { + "start": { + "line": 49, + "column": 6 + }, + "end": { + "line": 49, + "column": 10 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 726, + "end": 727, + "loc": { + "start": { + "line": 49, + "column": 6 + }, + "end": { + "line": 49, + "column": 7 + } + }, + "name": "a" + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 727, + "end": 730, + "loc": { + "start": { + "line": 49, + "column": 7 + }, + "end": { + "line": 49, + "column": 10 + } + }, + "typeAnnotation": { + "type": "TSLiteralType", + "start": 729, + "end": 730, + "loc": { + "start": { + "line": 49, + "column": 9 + }, + "end": { + "line": 49, + "column": 10 + } + }, + "literal": { + "type": "Literal", + "start": 729, + "end": 730, + "loc": { + "start": { + "line": 49, + "column": 9 + }, + "end": { + "line": 49, + "column": 10 + } + }, + "value": 1, + "raw": "1" + } + } + } + } + ] + }, + { + "type": "TSNullKeyword", + "start": 747, + "end": 751, + "loc": { + "start": { + "line": 51, + "column": 4 + }, + "end": { + "line": 51, + "column": 8 + } + }, + "leadingComments": [ + { + "type": "Block", + "value": " c ", + "start": 735, + "end": 742 + } + ] + } + ] + } + ] + } + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "Line", + "value": " a type argument in expression position", + "start": 663, + "end": 704 + } + ] + }, + { + "type": "TSTypeAliasDeclaration", + "start": 826, + "end": 851, + "loc": { + "start": { + "line": 55, + "column": 1 + }, + "end": { + "line": 55, + "column": 26 + } + }, + "id": { + "type": "Identifier", + "start": 831, + "end": 832, + "loc": { + "start": { + "line": 55, + "column": 6 + }, + "end": { + "line": 55, + "column": 7 + } + }, + "name": "H" + }, + "typeAnnotation": { + "type": "TSUnionType", + "start": 835, + "end": 850, + "loc": { + "start": { + "line": 55, + "column": 10 + }, + "end": { + "line": 55, + "column": 25 + } + }, + "types": [ + { + "type": "TSTypeLiteral", + "start": 835, + "end": 843, + "loc": { + "start": { + "line": 55, + "column": 10 + }, + "end": { + "line": 55, + "column": 18 + } + }, + "members": [ + { + "type": "TSPropertySignature", + "start": 837, + "end": 841, + "loc": { + "start": { + "line": 55, + "column": 12 + }, + "end": { + "line": 55, + "column": 16 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 837, + "end": 838, + "loc": { + "start": { + "line": 55, + "column": 12 + }, + "end": { + "line": 55, + "column": 13 + } + }, + "name": "a" + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 838, + "end": 841, + "loc": { + "start": { + "line": 55, + "column": 13 + }, + "end": { + "line": 55, + "column": 16 + } + }, + "typeAnnotation": { + "type": "TSLiteralType", + "start": 840, + "end": 841, + "loc": { + "start": { + "line": 55, + "column": 15 + }, + "end": { + "line": 55, + "column": 16 + } + }, + "literal": { + "type": "Literal", + "start": 840, + "end": 841, + "loc": { + "start": { + "line": 55, + "column": 15 + }, + "end": { + "line": 55, + "column": 16 + } + }, + "value": 1, + "raw": "1" + } + } + } + } + ] + }, + { + "type": "TSNullKeyword", + "start": 846, + "end": 850, + "loc": { + "start": { + "line": 55, + "column": 21 + }, + "end": { + "line": 55, + "column": 25 + } + } + } + ] + }, + "leadingComments": [ + { + "type": "Line", + "value": " Controls - nothing disqualifies the hug, so it still happens.", + "start": 760, + "end": 824 + } + ] + }, + { + "type": "TSTypeAliasDeclaration", + "start": 853, + "end": 883, + "loc": { + "start": { + "line": 56, + "column": 1 + }, + "end": { + "line": 56, + "column": 31 + } + }, + "id": { + "type": "Identifier", + "start": 858, + "end": 859, + "loc": { + "start": { + "line": 56, + "column": 6 + }, + "end": { + "line": 56, + "column": 7 + } + }, + "name": "I" + }, + "typeAnnotation": { + "type": "TSTypeReference", + "start": 862, + "end": 882, + "loc": { + "start": { + "line": 56, + "column": 10 + }, + "end": { + "line": 56, + "column": 30 + } + }, + "typeName": { + "type": "Identifier", + "start": 862, + "end": 865, + "loc": { + "start": { + "line": 56, + "column": 10 + }, + "end": { + "line": 56, + "column": 13 + } + }, + "name": "Foo" + }, + "typeArguments": { + "type": "TSTypeParameterInstantiation", + "start": 865, + "end": 882, + "loc": { + "start": { + "line": 56, + "column": 13 + }, + "end": { + "line": 56, + "column": 30 + } + }, + "params": [ + { + "type": "TSUnionType", + "start": 866, + "end": 881, + "loc": { + "start": { + "line": 56, + "column": 14 + }, + "end": { + "line": 56, + "column": 29 + } + }, + "types": [ + { + "type": "TSTypeLiteral", + "start": 866, + "end": 874, + "loc": { + "start": { + "line": 56, + "column": 14 + }, + "end": { + "line": 56, + "column": 22 + } + }, + "members": [ + { + "type": "TSPropertySignature", + "start": 868, + "end": 872, + "loc": { + "start": { + "line": 56, + "column": 16 + }, + "end": { + "line": 56, + "column": 20 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 868, + "end": 869, + "loc": { + "start": { + "line": 56, + "column": 16 + }, + "end": { + "line": 56, + "column": 17 + } + }, + "name": "a" + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 869, + "end": 872, + "loc": { + "start": { + "line": 56, + "column": 17 + }, + "end": { + "line": 56, + "column": 20 + } + }, + "typeAnnotation": { + "type": "TSLiteralType", + "start": 871, + "end": 872, + "loc": { + "start": { + "line": 56, + "column": 19 + }, + "end": { + "line": 56, + "column": 20 + } + }, + "literal": { + "type": "Literal", + "start": 871, + "end": 872, + "loc": { + "start": { + "line": 56, + "column": 19 + }, + "end": { + "line": 56, + "column": 20 + } + }, + "value": 1, + "raw": "1" + } + } + } + } + ] + }, + { + "type": "TSNullKeyword", + "start": 877, + "end": 881, + "loc": { + "start": { + "line": 56, + "column": 25 + }, + "end": { + "line": 56, + "column": 29 + } + } + } + ] + } + ] + } + } + }, + { + "type": "VariableDeclaration", + "start": 885, + "end": 917, + "loc": { + "start": { + "line": 57, + "column": 1 + }, + "end": { + "line": 57, + "column": 33 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 891, + "end": 916, + "loc": { + "start": { + "line": 57, + "column": 7 + }, + "end": { + "line": 57, + "column": 32 + } + }, + "id": { + "type": "Identifier", + "start": 891, + "end": 892, + "loc": { + "start": { + "line": 57, + "column": 7 + }, + "end": { + "line": 57, + "column": 8 + } + }, + "name": "j" + }, + "init": { + "type": "CallExpression", + "start": 895, + "end": 916, + "loc": { + "start": { + "line": 57, + "column": 11 + }, + "end": { + "line": 57, + "column": 32 + } + }, + "callee": { + "type": "Identifier", + "start": 895, + "end": 897, + "loc": { + "start": { + "line": 57, + "column": 11 + }, + "end": { + "line": 57, + "column": 13 + } + }, + "name": "fn" + }, + "arguments": [], + "typeArguments": { + "type": "TSTypeParameterInstantiation", + "start": 897, + "end": 914, + "loc": { + "start": { + "line": 57, + "column": 13 + }, + "end": { + "line": 57, + "column": 30 + } + }, + "params": [ + { + "type": "TSUnionType", + "start": 898, + "end": 913, + "loc": { + "start": { + "line": 57, + "column": 14 + }, + "end": { + "line": 57, + "column": 29 + } + }, + "types": [ + { + "type": "TSTypeLiteral", + "start": 898, + "end": 906, + "loc": { + "start": { + "line": 57, + "column": 14 + }, + "end": { + "line": 57, + "column": 22 + } + }, + "members": [ + { + "type": "TSPropertySignature", + "start": 900, + "end": 904, + "loc": { + "start": { + "line": 57, + "column": 16 + }, + "end": { + "line": 57, + "column": 20 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 900, + "end": 901, + "loc": { + "start": { + "line": 57, + "column": 16 + }, + "end": { + "line": 57, + "column": 17 + } + }, + "name": "a" + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 901, + "end": 904, + "loc": { + "start": { + "line": 57, + "column": 17 + }, + "end": { + "line": 57, + "column": 20 + } + }, + "typeAnnotation": { + "type": "TSLiteralType", + "start": 903, + "end": 904, + "loc": { + "start": { + "line": 57, + "column": 19 + }, + "end": { + "line": 57, + "column": 20 + } + }, + "literal": { + "type": "Literal", + "start": 903, + "end": 904, + "loc": { + "start": { + "line": 57, + "column": 19 + }, + "end": { + "line": 57, + "column": 20 + } + }, + "value": 1, + "raw": "1" + } + } + } + } + ] + }, + { + "type": "TSNullKeyword", + "start": 909, + "end": 913, + "loc": { + "start": { + "line": 57, + "column": 25 + }, + "end": { + "line": 57, + "column": 29 + } + } + } + ] + } + ] + } + } + } + ], + "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/typescript/types/union_hug_member_block_comment/input.svelte b/tests/fixtures/typescript/types/union_hug_member_block_comment/input.svelte new file mode 100644 index 00000000..3d247f4b --- /dev/null +++ b/tests/fixtures/typescript/types/union_hug_member_block_comment/input.svelte @@ -0,0 +1,58 @@ +