Skip to content

Housekeeping: Fix equalOwnProperties #26794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ namespace ts {
if (!left || !right) return false;
for (const key in left) {
if (hasOwnProperty.call(left, key)) {
if (!hasOwnProperty.call(right, key) === undefined) return false;
if (!hasOwnProperty.call(right, key)) return false;
if (!equalityComparer(left[key], right[key])) return false;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/testRunner/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"unittests/cancellableLanguageServiceOperations.ts",
"unittests/commandLineParsing.ts",
"unittests/compileOnSave.ts",
"unittests/compilerCore.ts",
"unittests/configurationExtension.ts",
"unittests/convertCompilerOptionsFromJson.ts",
"unittests/convertToAsyncFunction.ts",
Expand Down
33 changes: 33 additions & 0 deletions src/testRunner/unittests/compilerCore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace ts {
describe("compilerCore", () => {
describe("equalOwnProperties", () => {
it("correctly equates objects", () => {
assert.isTrue(equalOwnProperties({}, {}));
assert.isTrue(equalOwnProperties({ a: 1 }, { a: 1 }));
assert.isTrue(equalOwnProperties({ a: 1, b: 2 }, { b: 2, a: 1 }));
});
it("correctly identifies unmatched objects", () => {
assert.isFalse(equalOwnProperties({}, { a: 1 }), "missing left property");
assert.isFalse(equalOwnProperties({ a: 1 }, {}), "missing right property");
assert.isFalse(equalOwnProperties({ a: 1 }, { a: 2 }), "differing property");
});
it("correctly identifies undefined vs hasOwnProperty", () => {
assert.isFalse(equalOwnProperties({}, { a: undefined }), "missing left property");
assert.isFalse(equalOwnProperties({ a: undefined }, {}), "missing right property");
});
it("truthiness", () => {
const trythyTest = (l: any, r: any) => !!l === !!r;
assert.isFalse(equalOwnProperties({}, { a: 1 }, trythyTest), "missing left truthy property");
assert.isFalse(equalOwnProperties({}, { a: 0 }, trythyTest), "missing left falsey property");
assert.isFalse(equalOwnProperties({ a: 1 }, {}, trythyTest), "missing right truthy property");
assert.isFalse(equalOwnProperties({ a: 0 }, {}, trythyTest), "missing right falsey property");
assert.isTrue(equalOwnProperties({ a: 1 }, { a: "foo" }, trythyTest), "valid equality");
});
it("all equal", () => {
assert.isFalse(equalOwnProperties({}, { a: 1 }, () => true), "missing left property");
assert.isFalse(equalOwnProperties({ a: 1 }, {}, () => true), "missing right property");
assert.isTrue(equalOwnProperties({ a: 1 }, { a: 2 }, () => true), "valid equality");
});
});
});
}