Skip to content

Commit

Permalink
Bug 1869678 - Use more idiomatic code patterns for better type infere…
Browse files Browse the repository at this point in the history
…nce r=robwu

These fall under 5 main categories:

 1) Declare and/or initialize all class fiels in the constructor.
    (general good practise)

 2) Use real getters and redefineGetter instead of defineLazyGetter.
    (also keeps related code closer together)

 3) When subclassing, don't override class fields with getters (or vice versa).
    microsoft/TypeScript#33509

 4) Declare and assign object literals at the same time, not separatelly.
    (don't use `let foo;` at the top of the file, use `var foo = {`)

 5) Don't re-use local variables unnecesarily with different types.
    (general good practise, local variables are "free")

Differential Revision: https://phabricator.services.mozilla.com/D196386

UltraBlame original commit: 8e768446e17cc306729e3b0f705b0285c69321cf
  • Loading branch information
marco-c committed Jan 1, 2024
1 parent e29e1d8 commit d2c4b0c
Show file tree
Hide file tree
Showing 20 changed files with 2,015 additions and 1,416 deletions.
109 changes: 108 additions & 1 deletion toolkit/components/extensions/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,13 @@ console
/
No
using
variables
things
before
they
'
re
defined
.
"
no
-
Expand All @@ -406,9 +410,112 @@ before
define
"
:
[
"
error
"
{
allowNamedExports
:
true
classes
:
true
/
/
The
next
two
being
false
allows
idiomatic
patterns
which
are
more
/
/
type
-
inference
friendly
.
Functions
are
hoisted
so
this
is
safe
.
functions
:
false
/
/
This
flag
is
only
meaningful
for
var
declarations
.
/
/
When
false
it
still
disallows
use
-
before
-
define
in
the
same
scope
.
/
/
Since
we
only
allow
var
at
the
global
scope
this
is
no
worse
than
/
/
how
we
currently
declare
an
uninitialized
let
at
the
top
of
file
.
variables
:
false
}
]
/
/
Disallow
Expand Down
11 changes: 7 additions & 4 deletions toolkit/components/extensions/ConduitsParent.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3114,7 +3114,8 @@ this
)
;
}
sender
let
remote
=
Hub
.
Expand All @@ -3128,10 +3129,10 @@ sender
if
(
!
sender
remote
|
|
sender
remote
.
actor
!
Expand Down Expand Up @@ -3173,7 +3174,7 @@ Hub
.
recvConduitClosed
(
sender
remote
)
;
}
Expand Down Expand Up @@ -3224,6 +3225,8 @@ actor
this
query
sender
:
remote
}
)
;
Expand Down
Loading

0 comments on commit d2c4b0c

Please sign in to comment.