Skip to content

Commit

Permalink
chore: Object.prototype.hasOwnProperty.call -> Object.hasOwn
Browse files Browse the repository at this point in the history
  • Loading branch information
hegemonic committed Jan 9, 2023
1 parent 9b07314 commit 333522a
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 70 deletions.
4 changes: 1 addition & 3 deletions packages/jsdoc-core/lib/name.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
const _ = require('lodash');
const escape = require('escape-string-regexp');

const hasOwnProp = Object.prototype.hasOwnProperty;

/**
* Longnames that have a special meaning in JSDoc.
*
Expand Down Expand Up @@ -443,7 +441,7 @@ exports.longnamesToTree = (longnames, doclets) => {
currentParent = currentParent.children;
}

if (!hasOwnProp.call(currentParent, chunk)) {
if (!Object.hasOwn(currentParent, chunk)) {
currentParent[chunk] = nameInfo[currentLongname];
}

Expand Down
3 changes: 1 addition & 2 deletions packages/jsdoc-util/lib/bus.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const EventEmitter = require('events').EventEmitter;
const { default: ow } = require('ow');

let cache = {};
const hasOwnProp = Object.prototype.hasOwnProperty;

/**
* An event bus that works the same way as a standard Node.js event emitter, with a few key
Expand Down Expand Up @@ -52,7 +51,7 @@ class EventBus extends EventEmitter {

const shouldCache = _.isBoolean(opts.cache) ? opts.cache : true;

if (hasOwnProp.call(cache, id) && shouldCache) {
if (Object.hasOwn(cache, id) && shouldCache) {
return cache[id];
}

Expand Down
24 changes: 11 additions & 13 deletions packages/jsdoc/lib/jsdoc/augment.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ const jsdoc = {
doclet: require('jsdoc/doclet'),
};

const hasOwnProp = Object.prototype.hasOwnProperty;

function mapDependencies(index, propertyName) {
const dependencies = {};
let doc;
Expand All @@ -39,7 +37,7 @@ function mapDependencies(index, propertyName) {
doc = doclets[i];
if (kinds.includes(doc.kind)) {
dependencies[indexName] = {};
if (hasOwnProp.call(doc, propertyName)) {
if (Object.hasOwn(doc, propertyName)) {
len = doc[propertyName].length;
for (let j = 0; j < len; j++) {
dependencies[indexName][doc[propertyName][j]] = true;
Expand Down Expand Up @@ -172,7 +170,7 @@ function updateAddedDoclets(doclet, additions, indexes) {
* @return {void}
*/
function updateDocumentedDoclets(doclet, documented) {
if (!hasOwnProp.call(documented, doclet.longname)) {
if (!Object.hasOwn(documented, doclet.longname)) {
documented[doclet.longname] = [];
}

Expand All @@ -190,7 +188,7 @@ function updateDocumentedDoclets(doclet, documented) {
*/
function updateMemberofDoclets(doclet, memberof) {
if (doclet.memberof) {
if (!hasOwnProp.call(memberof, doclet.memberof)) {
if (!Object.hasOwn(memberof, doclet.memberof)) {
memberof[doclet.memberof] = [];
}

Expand Down Expand Up @@ -261,7 +259,7 @@ function getInheritedAdditions(doclets, docs, { documented, memberof }) {

// We don't want to fold in properties from the child doclet if it had an
// `@inheritdoc` tag.
if (hasOwnProp.call(childDoclet, 'inheritdoc')) {
if (Object.hasOwn(childDoclet, 'inheritdoc')) {
childDoclet = {};
}

Expand All @@ -280,15 +278,15 @@ function getInheritedAdditions(doclets, docs, { documented, memberof }) {
// Indicate what the descendant is overriding. (We only care about the closest
// ancestor. For classes A > B > C, if B#a overrides A#a, and C#a inherits B#a,
// we don't want the doclet for C#a to say that it overrides A#a.)
if (hasOwnProp.call(docs.index.longname, member.longname)) {
if (Object.hasOwn(docs.index.longname, member.longname)) {
member.overrides = parentDoclet.longname;
} else {
delete member.overrides;
}

// Add the ancestor's docs unless the descendant overrides the ancestor AND
// documents the override.
if (!hasOwnProp.call(documented, member.longname)) {
if (!Object.hasOwn(documented, member.longname)) {
updateAddedDoclets(member, additions, additionIndexes);
updateDocumentedDoclets(member, documented);
updateMemberofDoclets(member, memberof);
Expand Down Expand Up @@ -414,7 +412,7 @@ function updateImplements(implDoclets, implementedLongname) {
}

implDoclets.forEach((implDoclet) => {
if (!hasOwnProp.call(implDoclet, 'implements')) {
if (!Object.hasOwn(implDoclet, 'implements')) {
implDoclet.implements = [];
}

Expand Down Expand Up @@ -465,7 +463,7 @@ function getImplementedAdditions(implDoclets, allDoclets, { documented, memberof

// We don't want to fold in properties from the child doclet if it had an
// `@inheritdoc` tag.
if (hasOwnProp.call(childDoclet, 'inheritdoc')) {
if (Object.hasOwn(childDoclet, 'inheritdoc')) {
childDoclet = {};
}

Expand All @@ -475,13 +473,13 @@ function getImplementedAdditions(implDoclets, allDoclets, { documented, memberof
updateImplements(implementationDoclet, parentDoclet.longname);

// If there's no implementation, move along.
implExists = hasOwnProp.call(allDoclets.index.longname, implementationDoclet.longname);
implExists = Object.hasOwn(allDoclets.index.longname, implementationDoclet.longname);
if (!implExists) {
continue;
}

// Add the interface's docs unless the implementation is already documented.
if (!hasOwnProp.call(commentedDoclets, implementationDoclet.longname)) {
if (!Object.hasOwn(commentedDoclets, implementationDoclet.longname)) {
updateAddedDoclets(implementationDoclet, additions, additionIndexes);
updateDocumentedDoclets(implementationDoclet, commentedDoclets);
updateMemberofDoclets(implementationDoclet, memberof);
Expand Down Expand Up @@ -536,7 +534,7 @@ function augment(doclets, propertyName, docletFinder, jsdocDeps) {
additions.forEach((addition) => {
const longname = addition.longname;

if (!hasOwnProp.call(index, longname)) {
if (!Object.hasOwn(index, longname)) {
index[longname] = [];
}
index[longname].push(addition);
Expand Down
8 changes: 2 additions & 6 deletions packages/jsdoc/lib/jsdoc/doclet.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,14 +353,10 @@ function copyMostProperties(primary, secondary, target, exclude) {
*/
function copySpecificProperties(primary, secondary, target, include) {
include.forEach((property) => {
if (
{}.hasOwnProperty.call(primary, property) &&
primary[property] &&
primary[property].length
) {
if (Object.hasOwn(primary, property) && primary[property] && primary[property].length) {
target[property] = _.cloneDeep(primary[property]);
} else if (
{}.hasOwnProperty.call(secondary, property) &&
Object.hasOwn(secondary, property) &&
secondary[property] &&
secondary[property].length
) {
Expand Down
16 changes: 7 additions & 9 deletions packages/jsdoc/lib/jsdoc/src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ const { getBasename, LONGNAMES, SCOPE, toParts } = require('@jsdoc/core').name;
const { Visitor } = require('jsdoc/src/visitor');
const { Walker } = require('jsdoc/src/walker');

const hasOwnProp = Object.prototype.hasOwnProperty;

/* eslint-disable no-script-url */
// Prefix for JavaScript strings that were provided in lieu of a filename.
const SCHEMA = 'javascript:';
Expand All @@ -38,7 +36,7 @@ class DocletCache {
}

get(itemName) {
if (!hasOwnProp.call(this._doclets, itemName)) {
if (!Object.hasOwn(this._doclets, itemName)) {
return null;
}

Expand All @@ -47,7 +45,7 @@ class DocletCache {
}

put(itemName, value) {
if (!hasOwnProp.call(this._doclets, itemName)) {
if (!Object.hasOwn(this._doclets, itemName)) {
this._doclets[itemName] = [];
}

Expand Down Expand Up @@ -76,7 +74,7 @@ function definedInScope(doclet, basename) {
Boolean(doclet.meta) &&
Boolean(doclet.meta.vars) &&
Boolean(basename) &&
hasOwnProp.call(doclet.meta.vars, basename)
Object.hasOwn(doclet.meta.vars, basename)
);
}

Expand Down Expand Up @@ -221,29 +219,29 @@ class Parser extends EventEmitter {
this._resultBuffer.push(doclet);

// track all doclets by longname
if (!hasOwnProp.call(index.longname, doclet.longname)) {
if (!Object.hasOwn(index.longname, doclet.longname)) {
index.longname[doclet.longname] = [];
}
index.longname[doclet.longname].push(doclet);

// track all doclets that have a memberof by memberof
if (doclet.memberof) {
if (!hasOwnProp.call(index.memberof, doclet.memberof)) {
if (!Object.hasOwn(index.memberof, doclet.memberof)) {
index.memberof[doclet.memberof] = [];
}
index.memberof[doclet.memberof].push(doclet);
}

// track longnames of documented symbols
if (!doclet.undocumented) {
if (!hasOwnProp.call(index.documented, doclet.longname)) {
if (!Object.hasOwn(index.documented, doclet.longname)) {
index.documented[doclet.longname] = [];
}
index.documented[doclet.longname].push(doclet);
}

// track doclets with a `borrowed` property
if (hasOwnProp.call(doclet, 'borrowed')) {
if (Object.hasOwn(doclet, 'borrowed')) {
index.borrowed.push(doclet);
}
}
Expand Down
6 changes: 2 additions & 4 deletions packages/jsdoc/lib/jsdoc/tag/dictionary.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
const definitions = require('jsdoc/tag/dictionary/definitions');
const { log } = require('@jsdoc/util');

const hasOwnProp = Object.prototype.hasOwnProperty;

const DEFINITIONS = {
closure: 'closureTags',
jsdoc: 'jsdocTags',
Expand Down Expand Up @@ -159,7 +157,7 @@ class Dictionary {
lookup(title) {
title = this.normalize(title);

if (hasOwnProp.call(this._tags, title)) {
if (Object.hasOwn(this._tags, title)) {
return this._tags[title];
}

Expand All @@ -177,7 +175,7 @@ class Dictionary {
normalize(title) {
const canonicalName = title.toLowerCase();

if (hasOwnProp.call(this._tagSynonyms, canonicalName)) {
if (Object.hasOwn(this._tagSynonyms, canonicalName)) {
return this._tagSynonyms[canonicalName];
}

Expand Down
12 changes: 5 additions & 7 deletions packages/jsdoc/lib/jsdoc/util/templateHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ const { inline } = require('@jsdoc/tag');
const { log } = require('@jsdoc/util');
const { longnamesToTree, SCOPE, SCOPE_TO_PUNC, toParts } = require('@jsdoc/core').name;

const hasOwnProp = Object.prototype.hasOwnProperty;

const MODULE_NAMESPACE = 'module:';

const files = {};
Expand Down Expand Up @@ -92,7 +90,7 @@ function makeUniqueFilename(filename, str) {

// append enough underscores to make the filename unique
while (nonUnique) {
if (hasOwnProp.call(files, key)) {
if (Object.hasOwn(files, key)) {
filename += '_';
key = filename.toLowerCase();
} else {
Expand Down Expand Up @@ -152,7 +150,7 @@ const getUniqueFilename = (exports.getUniqueFilename = (str, dependencies) => {
function getFilename(longname, dependencies) {
let fileUrl;

if (hasOwnProp.call(longnameToUrl, longname)) {
if (Object.hasOwn(longnameToUrl, longname)) {
fileUrl = longnameToUrl[longname];
} else {
fileUrl = getUniqueFilename(longname, dependencies);
Expand Down Expand Up @@ -191,7 +189,7 @@ function makeUniqueId(filename, id) {

// append enough underscores to make the identifier unique
while (nonUnique) {
if (hasOwnProp.call(ids, filename) && hasOwnProp.call(ids[filename], key)) {
if (Object.hasOwn(ids, filename) && Object.hasOwn(ids[filename], key)) {
id += '_';
key = id.toLowerCase();
} else {
Expand All @@ -211,7 +209,7 @@ function makeUniqueId(filename, id) {
* @private
*/
function getId(longname, id) {
if (hasOwnProp.call(longnameToId, longname)) {
if (Object.hasOwn(longnameToId, longname)) {
id = longnameToId[longname];
} else if (!id) {
// no ID required
Expand Down Expand Up @@ -342,7 +340,7 @@ function buildLink(longname, linkText, options) {

return stringifyType(parsedType, options.cssClass, options.linkMap);
} else {
fileUrl = hasOwnProp.call(options.linkMap, longname) ? options.linkMap[longname] : '';
fileUrl = Object.hasOwn(options.linkMap, longname) ? options.linkMap[longname] : '';
text = linkText || (options.shortenName ? getShortName(longname) : longname);
}

Expand Down
7 changes: 3 additions & 4 deletions packages/jsdoc/templates/default/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const template = require('jsdoc/template');
const htmlsafe = helper.htmlsafe;
const linkto = helper.linkto;
const resolveAuthorLinks = helper.resolveAuthorLinks;
const hasOwnProp = Object.prototype.hasOwnProperty;

const FONT_NAMES = [
'OpenSans-Bold',
Expand Down Expand Up @@ -342,9 +341,9 @@ function buildMemberNav(items, itemHeading, itemsSeen, linktoFn, dependencies) {
items.forEach((item) => {
let displayName;

if (!hasOwnProp.call(item, 'longname')) {
if (!Object.hasOwn(item, 'longname')) {
itemsNav += `<li>${linktoFn('', item.name)}</li>`;
} else if (!hasOwnProp.call(itemsSeen, item.longname)) {
} else if (!Object.hasOwn(itemsSeen, item.longname)) {
if (config.templates.default.useLongnameInNav) {
displayName = item.longname;
} else {
Expand Down Expand Up @@ -401,7 +400,7 @@ function buildNav(members, dependencies) {
globalNav = '';

members.globals.forEach(({ kind, longname, name }) => {
if (kind !== 'typedef' && !hasOwnProp.call(seen, longname)) {
if (kind !== 'typedef' && !Object.hasOwn(seen, longname)) {
globalNav += `<li>${linkto(longname, name)}</li>`;
}
seen[longname] = true;
Expand Down
Loading

0 comments on commit 333522a

Please sign in to comment.