Skip to content

Commit cbdfc01

Browse files
Merge pull request #26794 from samlanning/fix-equalownproperties
Housekeeping: Fix equalOwnProperties
2 parents 8f8e616 + 2c41d8b commit cbdfc01

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

Diff for: src/compiler/core.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,7 @@ namespace ts {
12721272
if (!left || !right) return false;
12731273
for (const key in left) {
12741274
if (hasOwnProperty.call(left, key)) {
1275-
if (!hasOwnProperty.call(right, key) === undefined) return false;
1275+
if (!hasOwnProperty.call(right, key)) return false;
12761276
if (!equalityComparer(left[key], right[key])) return false;
12771277
}
12781278
}

Diff for: src/testRunner/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"unittests/cancellableLanguageServiceOperations.ts",
4747
"unittests/commandLineParsing.ts",
4848
"unittests/compileOnSave.ts",
49+
"unittests/compilerCore.ts",
4950
"unittests/configurationExtension.ts",
5051
"unittests/convertCompilerOptionsFromJson.ts",
5152
"unittests/convertToAsyncFunction.ts",

Diff for: src/testRunner/unittests/compilerCore.ts

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace ts {
2+
describe("compilerCore", () => {
3+
describe("equalOwnProperties", () => {
4+
it("correctly equates objects", () => {
5+
assert.isTrue(equalOwnProperties({}, {}));
6+
assert.isTrue(equalOwnProperties({ a: 1 }, { a: 1 }));
7+
assert.isTrue(equalOwnProperties({ a: 1, b: 2 }, { b: 2, a: 1 }));
8+
});
9+
it("correctly identifies unmatched objects", () => {
10+
assert.isFalse(equalOwnProperties({}, { a: 1 }), "missing left property");
11+
assert.isFalse(equalOwnProperties({ a: 1 }, {}), "missing right property");
12+
assert.isFalse(equalOwnProperties({ a: 1 }, { a: 2 }), "differing property");
13+
});
14+
it("correctly identifies undefined vs hasOwnProperty", () => {
15+
assert.isFalse(equalOwnProperties({}, { a: undefined }), "missing left property");
16+
assert.isFalse(equalOwnProperties({ a: undefined }, {}), "missing right property");
17+
});
18+
it("truthiness", () => {
19+
const trythyTest = (l: any, r: any) => !!l === !!r;
20+
assert.isFalse(equalOwnProperties({}, { a: 1 }, trythyTest), "missing left truthy property");
21+
assert.isFalse(equalOwnProperties({}, { a: 0 }, trythyTest), "missing left falsey property");
22+
assert.isFalse(equalOwnProperties({ a: 1 }, {}, trythyTest), "missing right truthy property");
23+
assert.isFalse(equalOwnProperties({ a: 0 }, {}, trythyTest), "missing right falsey property");
24+
assert.isTrue(equalOwnProperties({ a: 1 }, { a: "foo" }, trythyTest), "valid equality");
25+
});
26+
it("all equal", () => {
27+
assert.isFalse(equalOwnProperties({}, { a: 1 }, () => true), "missing left property");
28+
assert.isFalse(equalOwnProperties({ a: 1 }, {}, () => true), "missing right property");
29+
assert.isTrue(equalOwnProperties({ a: 1 }, { a: 2 }, () => true), "valid equality");
30+
});
31+
});
32+
});
33+
}

0 commit comments

Comments
 (0)