Skip to content

Commit 6223938

Browse files
committed
Remove extra line
1 parent 6fbd649 commit 6223938

6 files changed

+25
-24
lines changed

compiler-core/src/javascript.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ impl<'a> Generator<'a> {
362362

363363
let mut definitions = constructors
364364
.iter()
365-
.map(|constructor| self.record_definition(constructor, name, constructor_publicity))
365+
.map(|constructor| self.variant_definition(constructor, name, constructor_publicity))
366366
.collect_vec();
367367

368368
// Generate getters for fields shared between variants
@@ -380,23 +380,23 @@ impl<'a> Generator<'a> {
380380
definitions
381381
}
382382

383-
fn record_definition(
383+
fn variant_definition(
384384
&self,
385385
constructor: &'a TypedRecordConstructor,
386386
type_name: &'a str,
387387
publicity: Publicity,
388388
) -> Document<'a> {
389-
let class_definition = self.record_class_definition(constructor, publicity);
389+
let class_definition = self.variant_class_definition(constructor, publicity);
390390

391391
// If the custom type is private or opaque, we don't need to generate API
392392
// functions for it.
393393
if publicity.is_private() {
394394
return class_definition;
395395
}
396396

397-
let constructor_definition = self.record_constructor_definition(constructor, type_name);
398-
let variant_check_definition = self.record_check_definition(constructor, type_name);
399-
let fields_definition = self.record_fields_definition(constructor, type_name);
397+
let constructor_definition = self.variant_constructor_definition(constructor, type_name);
398+
let variant_check_definition = self.variant_check_definition(constructor, type_name);
399+
let fields_definition = self.variant_fields_definition(constructor, type_name);
400400

401401
docvec![
402402
class_definition,
@@ -408,7 +408,7 @@ impl<'a> Generator<'a> {
408408
]
409409
}
410410

411-
fn record_constructor_definition(
411+
fn variant_constructor_definition(
412412
&self,
413413
constructor: &'a TypedRecordConstructor,
414414
type_name: &'a str,
@@ -445,7 +445,7 @@ impl<'a> Generator<'a> {
445445
]
446446
}
447447

448-
fn record_check_definition(
448+
fn variant_check_definition(
449449
&self,
450450
constructor: &'a TypedRecordConstructor,
451451
type_name: &'a str,
@@ -468,7 +468,7 @@ impl<'a> Generator<'a> {
468468
]
469469
}
470470

471-
fn record_fields_definition(
471+
fn variant_fields_definition(
472472
&self,
473473
constructor: &'a TypedRecordConstructor,
474474
type_name: &'a str,
@@ -528,27 +528,23 @@ impl<'a> Generator<'a> {
528528
type_name: &'a str,
529529
shared_accessors: &HashMap<EcoString, RecordAccessor>,
530530
) -> Document<'a> {
531-
let mut functions = Vec::new();
532-
533-
for field in shared_accessors.keys().sorted() {
531+
let accessors = shared_accessors.keys().sorted().map(|field| {
534532
let function_name = eco_format!("{type_name}${field}");
535533

536534
let contents =
537535
docvec![break_("", " "), "value.", maybe_escape_property(field), ";"].group();
538536

539-
functions.push(docvec![
540-
line(),
537+
docvec![
541538
"export const ",
542539
function_name,
543540
" = (value) =>",
544541
contents.nest(INDENT),
545-
]);
546-
}
547-
548-
concat(functions)
542+
]
543+
});
544+
concat(Itertools::intersperse(accessors, line()))
549545
}
550546

551-
fn record_class_definition(
547+
fn variant_class_definition(
552548
&self,
553549
constructor: &'a TypedRecordConstructor,
554550
publicity: Publicity,

compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__constructors_get_their_own_jsdoc.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
source: compiler-core/src/javascript/tests/custom_types.rs
3+
assertion_line: 678
34
expression: "\npub type Wibble {\n /// Wibbling!!\n Wibble(field: Int)\n\n /// Wobbling!!\n Wobble(field: Int)\n}\n"
5+
snapshot_kind: text
46
---
57
----- SOURCE CODE
68

@@ -44,5 +46,4 @@ export const Wibble$isWobble = (value) => value instanceof Wobble;
4446
export const Wibble$Wobble$field = (value) => value.field;
4547
export const Wibble$Wobble$0 = (value) => value.field;
4648

47-
4849
export const Wibble$field = (value) => value.field;

compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__records__record_accessor_multiple_variants.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
source: compiler-core/src/javascript/tests/records.rs
3+
assertion_line: 18
34
expression: "\npub type Person {\n Teacher(name: String, title: String)\n Student(name: String, age: Int)\n}\npub fn get_name(person: Person) { person.name }"
5+
snapshot_kind: text
46
---
57
----- SOURCE CODE
68

@@ -41,7 +43,6 @@ export const Person$Student$0 = (value) => value.name;
4143
export const Person$Student$age = (value) => value.age;
4244
export const Person$Student$1 = (value) => value.age;
4345

44-
4546
export const Person$name = (value) => value.name;
4647

4748
export function get_name(person) {

compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__records__record_accessor_multiple_variants_parameterised_types.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
source: compiler-core/src/javascript/tests/records.rs
3+
assertion_line: 61
34
expression: "\npub type Person {\n Teacher(name: String, age: List(Int), title: String)\n Student(name: String, age: List(Int))\n}\npub fn get_name(person: Person) { person.name }\npub fn get_age(person: Person) { person.age }"
5+
snapshot_kind: text
46
---
57
----- SOURCE CODE
68

@@ -46,7 +48,6 @@ export const Person$Student$0 = (value) => value.name;
4648
export const Person$Student$age = (value) => value.age;
4749
export const Person$Student$1 = (value) => value.age;
4850

49-
5051
export const Person$age = (value) => value.age;
5152
export const Person$name = (value) => value.name;
5253

compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__records__record_accessor_multiple_variants_positions_other_than_first.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
source: compiler-core/src/javascript/tests/records.rs
3+
assertion_line: 32
34
expression: "\npub type Person {\n Teacher(name: String, age: Int, title: String)\n Student(name: String, age: Int)\n}\npub fn get_name(person: Person) { person.name }\npub fn get_age(person: Person) { person.age }"
5+
snapshot_kind: text
46
---
57
----- SOURCE CODE
68

@@ -46,7 +48,6 @@ export const Person$Student$0 = (value) => value.name;
4648
export const Person$Student$age = (value) => value.age;
4749
export const Person$Student$1 = (value) => value.age;
4850

49-
5051
export const Person$age = (value) => value.age;
5152
export const Person$name = (value) => value.name;
5253

compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__records__record_accessor_multiple_with_first_position_different_types.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
source: compiler-core/src/javascript/tests/records.rs
3+
assertion_line: 47
34
expression: "\npub type Person {\n Teacher(name: Nil, age: Int)\n Student(name: String, age: Int)\n}\npub fn get_age(person: Person) { person.age }"
5+
snapshot_kind: text
46
---
57
----- SOURCE CODE
68

@@ -41,7 +43,6 @@ export const Person$Student$0 = (value) => value.name;
4143
export const Person$Student$age = (value) => value.age;
4244
export const Person$Student$1 = (value) => value.age;
4345

44-
4546
export const Person$age = (value) => value.age;
4647

4748
export function get_age(person) {

0 commit comments

Comments
 (0)