Skip to content

Commit

Permalink
refactor: Object.prototype.hasOwnProperty.call -> Object.hasOwn
Browse files Browse the repository at this point in the history
  • Loading branch information
sverweij committed Oct 5, 2024
1 parent 3fe36bc commit d0a4fa5
Show file tree
Hide file tree
Showing 18 changed files with 44 additions and 52 deletions.
2 changes: 1 addition & 1 deletion dist/cli/normalize.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions dist/parse/scxml/index.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/render/dot/index.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions dist/render/smcat/index.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dist/state-machine-model.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<meta name="google-site-verification" content="K0j5zueKp7lYKMR7WihmcTJbLpHxBOpaXZEI_s0nHTw" />
<link rel="canonical" href="https://state-machine-cat.js.org">
<script nonce="known-inline-script">let LOG = false;</script>
<script src="smcat-online-interpreter.min.js" type="module" defer integrity="sha512-LzV4WdQWscs9/euUna1KrfMGbrC9/7qaQzosyb+1mY0xpyzCJd7v6X+cq2IlMnd3wSKspbGDTScrkkFxWSZXVg=="></script>
<script src="smcat-online-interpreter.min.js" type="module" defer integrity="sha512-jW00R6aQpO/8HlgIBHby+zWnUNKDEBCKgZmQDMy7sWZAnnQ+0+OKOQs5Besk+eRZh+MO9AaM1Rd1nMm3j0SiqQ=="></script>
<script defer src="https://code.getmdl.io/1.3.0/material.min.js" async></script>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-DCPVBY7NNV"></script>
<script nonce="known-inline-script">
Expand Down
2 changes: 1 addition & 1 deletion docs/inpage.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
src="state-machine-cat-inpage.min.js"
type="module"
defer
integrity="sha512-8B26LbBRLk2NRwfL3RmG2iZ6KIVMQUyHyK4fedzMLuHfubc01DjK5VC4k0ms+jVoP6exjqHpdeu8zYeM/T0j0Q=="
integrity="sha512-YYgQmVg4m0xE8e7kXnumFlKAXEnr3pKqygJA9EF5Qqs1bwFY4s7tBTwUg29Hh5+wAhyf6fok2kBpFhc8w55GBg=="
></script>
<style>
body { font-family: sans-serif; margin: 0 auto; max-width: 799px;
Expand Down
6 changes: 3 additions & 3 deletions docs/smcat-online-interpreter.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/smcat-online-interpreter.min.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/state-machine-cat-inpage.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/state-machine-cat-inpage.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/cli/normalize.mts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function determineParameter(
pOptions: ILooseCLIRenderOptions,
pParameter: string,
): string {
return Object.prototype.hasOwnProperty.call(pOptions, pParameter)
return Object.hasOwn(pOptions, pParameter)
? // @ts-expect-error tsc complains we can't index pOptions with a thing of type string - however: we can
pOptions[pParameter]
: // @ts-expect-error tsc complains we can't index pOptions with a thing of type string - however: we can
Expand Down
4 changes: 1 addition & 3 deletions src/parse/scxml/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,7 @@ function reduceTransition(pState) {
*/
function extractTransitions(pStates) {
return pStates
.filter((pState) =>
Object.prototype.hasOwnProperty.call(pState, "transition"),
)
.filter((pState) => Object.hasOwn(pState, "transition"))
.reduce((pAllTransitions, pThisState) => {
const lTransitionAsArray = castArray(pThisState.transition);
return pAllTransitions.concat(
Expand Down
2 changes: 1 addition & 1 deletion src/render/dot/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import utl from "./utl.mjs";
*/
function addExternalSelfTransitions(pStateMachineModel) {
return (pState) => {
if (Object.prototype.hasOwnProperty.call(pState, "statemachine")) {
if (Object.hasOwn(pState, "statemachine")) {
pState.nestedExternalSelfTransitions = pStateMachineModel
.findExternalSelfTransitions(pState.name)
.map((pTransition) => pTransition.name);
Expand Down
16 changes: 8 additions & 8 deletions src/render/smcat/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ function flattenActions(pState: IExtendedState): IFlattenedActionsState {
/* eslint complexity:0 */
function flagExtendedStateAttributes(pState: IExtendedState): IExtendedState {
if (
Object.prototype.hasOwnProperty.call(pState, "label") ||
Object.prototype.hasOwnProperty.call(pState, "typeExplicitlySet") ||
Object.prototype.hasOwnProperty.call(pState, "color") ||
Object.prototype.hasOwnProperty.call(pState, "active") ||
Object.prototype.hasOwnProperty.call(pState, "class")
Object.hasOwn(pState, "label") ||
Object.hasOwn(pState, "typeExplicitlySet") ||
Object.hasOwn(pState, "color") ||
Object.hasOwn(pState, "active") ||
Object.hasOwn(pState, "class")
) {
// note & fixme: mutating a parameter here
pState.hasExtendedAttributes = true;
Expand Down Expand Up @@ -83,9 +83,9 @@ function flagExtendedTransitionAttributes(
pTransition: IExtendedTransition,
): IExtendedTransition {
if (
Object.prototype.hasOwnProperty.call(pTransition, "type") ||
Object.prototype.hasOwnProperty.call(pTransition, "color") ||
Object.prototype.hasOwnProperty.call(pTransition, "class")
Object.hasOwn(pTransition, "type") ||
Object.hasOwn(pTransition, "color") ||
Object.hasOwn(pTransition, "class")
) {
pTransition.hasExtendedAttributes = true;
}
Expand Down
8 changes: 5 additions & 3 deletions src/state-machine-model.mts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ function flattenStates(pStates: IState[], pHasParent = false): any[] {
pStates
.filter((pState) => Boolean(pState.statemachine))
.forEach((pState) => {
if (Object.prototype.hasOwnProperty.call(pState.statemachine, "states")) {
// @ts-expect-error ts2345 - typescript doesn't detect that one line above we
// ensure pState.statemachine is not undefined
if (Object.hasOwn(pState.statemachine, "states")) {
lReturnValue = lReturnValue.concat(
// @ts-expect-error TS doesn't detect that after the call in the filter
// the .statemachine is guaranteed to exist
Expand All @@ -35,12 +37,12 @@ function flattenTransitions(pStateMachine: IStateMachine): ITransition[] {
/** @type {import("../types/state-machine-cat").ITransition[]} */
let lTransitions: ITransition[] = [];

if (Object.prototype.hasOwnProperty.call(pStateMachine, "transitions")) {
if (Object.hasOwn(pStateMachine, "transitions")) {
// @ts-expect-error TS doesn't detect that after the call in the if the
// .transitions is guaranteed to exist
lTransitions = pStateMachine.transitions;
}
if (Object.prototype.hasOwnProperty.call(pStateMachine, "states")) {
if (Object.hasOwn(pStateMachine, "states")) {
pStateMachine.states
.filter((pState) => Boolean(pState.statemachine))
.forEach((pState) => {
Expand Down
5 changes: 1 addition & 4 deletions test/parse/smcat-parser.spec.mts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ const syntaxErrors = requireJSON("./20-no-transitions-errors.json")

describe("#parse() - happy day ASTs -", () => {
programASTPairs.forEach((pPair) => {
if (
Object.prototype.hasOwnProperty.call(pPair, "pending") &&
pPair.pending
) {
if (Object.hasOwn(pPair, "pending") && pPair.pending) {
/* eslint mocha/no-skipped-tests: off */
xit(pPair.title);
} else {
Expand Down
5 changes: 1 addition & 4 deletions test/render/smcat.spec.mts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ const programASTPairs = requireJSON("../parse/00-no-transitions.json")

describe("#parse(convert) - happy day ASTs - ", () => {
programASTPairs.forEach((pPair) => {
if (
Object.prototype.hasOwnProperty.call(pPair, "pending") &&
pPair.pending
) {
if (Object.hasOwn(pPair, "pending") && pPair.pending) {
/* eslint mocha/no-skipped-tests: off */
xit(pPair.title);
} else {
Expand Down

0 comments on commit d0a4fa5

Please sign in to comment.