Skip to content

Commit

Permalink
traceDependency
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Sep 9, 2023
1 parent faa9472 commit ffbb79b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/serialize/primitives.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function traceNumber(val, record) {
// `Object.is()` required to differentiate between 0 and -0
if (val < 0 || Object.is(val, -0)) {
record.name = `minus${-val}`;
record.extra = {positive: this.traceDependency(-val, record)};
record.extra = {positive: this.traceDependency(-val, null, null, record)};
return NEGATIVE_TYPE;
}

Expand All @@ -103,7 +103,7 @@ function traceNumber(val, record) {
function traceBigInt(val, record) {
if (val < 0) {
record.name = `minusb${-val}`;
record.extra = {positive: this.traceDependency(-val, record)};
record.extra = {positive: this.traceDependency(-val, null, null, record)};
return NEGATIVE_TYPE;
}

Expand Down
15 changes: 15 additions & 0 deletions lib/serialize/trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,21 @@ module.exports = {
*/
getTraceStack() {
return ` ${this.traceStack.join('\n ')}`;
},

/**
* Trace dependency of record.
* @param {*} val - Value which is dependency
* @param {string} [name] - Name for var. Does not need to be valid JS identifier.
* Can be omitted for globals.
* @param {string} [traceStackEntry] - Trace stack entry for debugging. Can be omitted for globals.
* @param {Object} dependent - Record for dependent
* @returns {Object} - Record
*/
traceDependency(val, name, traceStackEntry, dependent) {
const record = this.traceValue(val, name, traceStackEntry);
createDependency(dependent, record);
return record;
}
};

Expand Down

0 comments on commit ffbb79b

Please sign in to comment.