Skip to content

Commit

Permalink
fix some ambiguous this
Browse files Browse the repository at this point in the history
  • Loading branch information
rsek committed Jan 17, 2024
1 parent cb128cd commit 360df52
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ declare class ObjectGlobber<TTuple extends Array<PropertyKey> = Array<PropertyKe
includeArrays: boolean;
}): unknown[];
/** Is this value an object with recursable keys? */
static isWalkable(value: unknown, includeArrays?: boolean): boolean;
static isWalkable(value: unknown, includeArrays?: boolean): value is object;
/** Is the value valid as an object property key? */
static isPropertyKey(key: unknown): key is PropertyKey;
/**
Expand Down
22 changes: 11 additions & 11 deletions pkg/nodejs/@datasworn/core/dist/ObjectGlobPath/ObjectGlobber.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ class ObjectGlobber extends Array {
const nextPath = keys.slice(1);
// console.log('next:', nextKey, nextPath)
if (nextPath.length === 0)
return this.getKeyMatches(from, nextKey, { includeArrays, matchTest });
const matches = this.getKeyMatches(from, nextKey, {
return _a.getKeyMatches(from, nextKey, { includeArrays, matchTest });
const matches = _a.getKeyMatches(from, nextKey, {
includeArrays
});
const results = [];
for (const match of matches) {
results.push(...this.getMatches(match, nextPath, {
results.push(..._a.getMatches(match, nextPath, {
matchTest,
includeArrays
}));
Expand All @@ -124,7 +124,7 @@ class ObjectGlobber extends Array {
static getKeyMatches(from, matchKey, { forEachMatch, matchTest, includeArrays = false } = {
includeArrays: false
}) {
if (!this.isPropertyKey(matchKey))
if (!_a.isPropertyKey(matchKey))
throw new Error(`Expected a number, string, or symbol key, but got ${typeof matchKey}`);
const results = [];
const hasMatchTest = typeof matchTest === 'function';
Expand All @@ -134,8 +134,8 @@ class ObjectGlobber extends Array {
}
function iterateGlobstarMatch(key, value, results) {
iterateWildcardMatch(key, value, results);
if (this.isWalkable(value, includeArrays)) {
results.push(...this.getKeyMatches(value, matchKey, {
if (_a.isWalkable(value, includeArrays)) {
results.push(..._a.getKeyMatches(value, matchKey, {
matchTest,
includeArrays
}));
Expand Down Expand Up @@ -205,7 +205,7 @@ class ObjectGlobber extends Array {
if (typeof forEach === 'function')
forEach(from, path);
const [currentKey, ...nextPath] = path;
if (!this.isPropertyKey(currentKey))
if (!_a.isPropertyKey(currentKey))
throw new Error(`Expected a number, string, or symbol key, but got ${typeof currentKey}`);
if (typeof from !== 'object')
throw new Error(`Expected an object but got ${typeof from}`);
Expand All @@ -232,9 +232,9 @@ class ObjectGlobber extends Array {
static getObjectPaths(object, includeArrays = false, currentPath = new _a()) {
const results = [];
if (object instanceof Map)
results.push(...__classPrivateFieldGet(this, _a, "m", _ObjectGlobber_getMapPaths).call(this, object, includeArrays, currentPath));
results.push(...__classPrivateFieldGet(_a, _a, "m", _ObjectGlobber_getMapPaths).call(_a, object, includeArrays, currentPath));
else
results.push(...__classPrivateFieldGet(this, _a, "m", _ObjectGlobber_getPlainObjectPaths).call(this, object, includeArrays, currentPath));
results.push(...__classPrivateFieldGet(_a, _a, "m", _ObjectGlobber_getPlainObjectPaths).call(_a, object, includeArrays, currentPath));
return results;
}
/** Replace a wildcard/globstar string with a Symbol */
Expand Down Expand Up @@ -272,7 +272,7 @@ _a = ObjectGlobber, _ObjectGlobber_getPlainObjectPaths = function _ObjectGlobber
if (!includeArrays && Array.isArray(nextObject))
continue;
const nextPath = new _a(...currentPath, k);
results.push(nextPath, ...this.getObjectPaths(nextObject, includeArrays, nextPath));
results.push(nextPath, ..._a.getObjectPaths(nextObject, includeArrays, nextPath));
}
return results;
}, _ObjectGlobber_getMapPaths = function _ObjectGlobber_getMapPaths(object, includeArrays = false, currentPath = new _a()) {
Expand All @@ -285,7 +285,7 @@ _a = ObjectGlobber, _ObjectGlobber_getPlainObjectPaths = function _ObjectGlobber
if (!includeArrays && Array.isArray(nextObject))
continue;
const nextPath = new _a(...currentPath, k);
results.push(nextPath, ...this.getObjectPaths(nextObject, includeArrays, nextPath));
results.push(nextPath, ..._a.getObjectPaths(nextObject, includeArrays, nextPath));
}
return results;
};
Expand Down
1 change: 1 addition & 0 deletions src/pkg-core/Id/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ const testParse = [
]

for (const id of testParse) console.log(id.toString(), id.toPath().join('.'))

30 changes: 18 additions & 12 deletions src/pkg-core/ObjectGlobPath/ObjectGlobber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,17 @@ class ObjectGlobber<
// console.log('next:', nextKey, nextPath)

if (nextPath.length === 0)
return this.getKeyMatches(from, nextKey, { includeArrays, matchTest })
return ObjectGlobber.getKeyMatches(from, nextKey, { includeArrays, matchTest })

const matches = this.getKeyMatches(from, nextKey, {
const matches = ObjectGlobber.getKeyMatches(from, nextKey, {
includeArrays
})

const results: unknown[] = []

for (const match of matches) {
results.push(
...this.getMatches(match as object, nextPath, {
...ObjectGlobber.getMatches(match as object, nextPath, {
matchTest,
includeArrays
})
Expand All @@ -185,7 +185,7 @@ class ObjectGlobber<
includeArrays: false
}
): unknown[] {
if (!this.isPropertyKey(matchKey))
if (!ObjectGlobber.isPropertyKey(matchKey))
throw new Error(
`Expected a number, string, or symbol key, but got ${typeof matchKey}`
)
Expand All @@ -207,9 +207,9 @@ class ObjectGlobber<
results: unknown[]
) {
iterateWildcardMatch(key, value, results)
if (this.isWalkable(value, includeArrays)) {
if (ObjectGlobber.isWalkable(value, includeArrays)) {
results.push(
...this.getKeyMatches(value, matchKey, {
...ObjectGlobber.getKeyMatches(value, matchKey, {
matchTest,
includeArrays
})
Expand Down Expand Up @@ -266,7 +266,7 @@ class ObjectGlobber<
}

/** Is this value an object with recursable keys? */
static isWalkable(value: unknown, includeArrays = false) {
static isWalkable(value: unknown, includeArrays = false): value is object {
if (!includeArrays && Array.isArray(value)) return false

return typeof value === 'object' && !Object.is(value, null)
Expand Down Expand Up @@ -304,7 +304,7 @@ class ObjectGlobber<

const [currentKey, ...nextPath] = path

if (!this.isPropertyKey(currentKey))
if (!ObjectGlobber.isPropertyKey(currentKey))
throw new Error(
`Expected a number, string, or symbol key, but got ${typeof currentKey}`
)
Expand Down Expand Up @@ -339,10 +339,16 @@ class ObjectGlobber<
const results: Array<ObjectGlobber> = []

if (object instanceof Map)
results.push(...this.#getMapPaths(object, includeArrays, currentPath))
results.push(
...ObjectGlobber.#getMapPaths(object, includeArrays, currentPath)
)
else
results.push(
...this.#getPlainObjectPaths(object, includeArrays, currentPath)
...ObjectGlobber.#getPlainObjectPaths(
object,
includeArrays,
currentPath
)
)

return results
Expand All @@ -366,7 +372,7 @@ class ObjectGlobber<

results.push(
nextPath,
...this.getObjectPaths(nextObject, includeArrays, nextPath)
...ObjectGlobber.getObjectPaths(nextObject, includeArrays, nextPath)
)
}

Expand All @@ -389,7 +395,7 @@ class ObjectGlobber<

results.push(
nextPath,
...this.getObjectPaths(nextObject, includeArrays, nextPath)
...ObjectGlobber.getObjectPaths(nextObject, includeArrays, nextPath)
)
}

Expand Down

0 comments on commit 360df52

Please sign in to comment.