Skip to content

Commit 5d5b3d2

Browse files
committed
refactor(symbol): rename Symbol to BSONSymbol
BREAKING CHANGE: This was conflicting with the ES6 Symbol type
1 parent b0fda90 commit 5d5b3d2

File tree

7 files changed

+23
-15
lines changed

7 files changed

+23
-15
lines changed

Diff for: lib/bson.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const Double = require('./double');
77
const Timestamp = require('./timestamp');
88
const ObjectId = require('./objectid');
99
const BSONRegExp = require('./regexp');
10-
const Symbol = require('./symbol');
10+
const BSONSymbol = require('./symbol');
1111
const Int32 = require('./int_32');
1212
const Code = require('./code');
1313
const Decimal128 = require('./decimal128');
@@ -250,7 +250,7 @@ module.exports = {
250250
// wrapped types
251251
Code,
252252
Map,
253-
Symbol,
253+
BSONSymbol,
254254
DBRef,
255255
Binary,
256256
ObjectId,

Diff for: lib/parser/calculate_size.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const Long = require('../long');
55
const Double = require('../double');
66
const Timestamp = require('../timestamp');
77
const ObjectId = require('../objectid');
8-
const Symbol = require('../symbol');
8+
const BSONSymbol = require('../symbol');
99
const BSONRegExp = require('../regexp');
1010
const Code = require('../code');
1111
const Decimal128 = require('../decimal128');
@@ -146,7 +146,7 @@ function calculateElement(name, value, serializeFunctions, isArray, ignoreUndefi
146146
(name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + (value.position + 1 + 4 + 1)
147147
);
148148
}
149-
} else if (value instanceof Symbol || value['_bsontype'] === 'Symbol') {
149+
} else if (value instanceof BSONSymbol || value['_bsontype'] === 'Symbol') {
150150
return (
151151
(name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) +
152152
Buffer.byteLength(value.value, 'utf8') +

Diff for: lib/parser/serializer.js

+6
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@ function serializeBSONRegExp(buffer, key, value, index, isArray) {
251251
}
252252

253253
function serializeMinMax(buffer, key, value, index, isArray) {
254+
console.log({
255+
value,
256+
MinKey,
257+
isMinKey: value instanceof MinKey
258+
});
259+
254260
// Write the type of either min or max key
255261
if (value === null) {
256262
buffer[index++] = constants.BSON_DATA_NULL;

Diff for: lib/symbol.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* A class representation of the BSON Symbol type.
44
*/
5-
class Symbol {
5+
class BSONSymbol {
66
/**
77
* Create a Symbol type
88
*
@@ -54,9 +54,9 @@ class Symbol {
5454
* @ignore
5555
*/
5656
static fromExtendedJSON(doc) {
57-
return new Symbol(doc.$symbol);
57+
return new BSONSymbol(doc.$symbol);
5858
}
5959
}
6060

61-
Object.defineProperty(Symbol.prototype, '_bsontype', { value: 'Symbol' });
62-
module.exports = Symbol;
61+
Object.defineProperty(BSONSymbol.prototype, '_bsontype', { value: 'Symbol' });
62+
module.exports = BSONSymbol;

Diff for: test/node/bson_corpus_tests.js

+2
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ describe('BSON Corpus', function() {
177177
const dEJ = normalize(v.degenerate_extjson);
178178
const roundTrippedDEJ = nativeToCEJSON(jsonToNative(dEJ));
179179
expect(roundTrippedDEJ).to.equal(cEJ);
180+
180181
if (!v.lossy) {
181182
expect(nativeToBson(jsonToNative(dEJ))).to.deep.equal(cB);
182183
}
@@ -195,6 +196,7 @@ describe('BSON Corpus', function() {
195196
let rEJ = normalize(v.relaxed_extjson);
196197
// BSON -> native -> relaxed EJSON matches provided
197198
expect(nativeToREJSON(nativeFromCB)).to.equal(rEJ);
199+
198200
// relaxed EJSON -> native -> relaxed EJSON unchanged
199201
expect(nativeToREJSON(jsonToNative(rEJ))).to.equal(rEJ);
200202
}

Diff for: test/node/bson_test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const Binary = BSON.Binary;
99
const Timestamp = BSON.Timestamp;
1010
const Long = BSON.Long;
1111
const ObjectId = BSON.ObjectId;
12-
const Symbol = BSON.Symbol;
12+
const BSONSymbol = BSON.BSONSymbol;
1313
const DBRef = BSON.DBRef;
1414
const Decimal128 = BSON.Decimal128;
1515
const Int32 = BSON.Int32;
@@ -100,7 +100,7 @@ describe('BSON', function() {
100100
expect(_mongodb.Timestamp === Timestamp).to.be.ok;
101101
expect(_mongodb.Code === Code).to.be.ok;
102102
expect(_mongodb.DBRef === DBRef).to.be.ok;
103-
expect(_mongodb.Symbol === Symbol).to.be.ok;
103+
expect(_mongodb.BSONSymbol === BSONSymbol).to.be.ok;
104104
expect(_mongodb.MinKey === MinKey).to.be.ok;
105105
expect(_mongodb.MaxKey === MaxKey).to.be.ok;
106106
expect(_mongodb.Double === Double).to.be.ok;
@@ -1377,10 +1377,10 @@ describe('BSON', function() {
13771377
* @ignore
13781378
*/
13791379
it('Should Correctly Serialize and Deserialize Symbol', function(done) {
1380-
if (Symbol != null) {
1380+
if (BSONSymbol != null) {
13811381
// symbols are deprecated, so upgrade to strings... so I'm not sure
13821382
// we really need this test anymore...
1383-
//var doc = { b: [new Symbol('test')] };
1383+
//var doc = { b: [new BSONSymbol('test')] };
13841384

13851385
var doc = { b: ['test'] };
13861386
var serialized_data = BSON.serialize(doc);

Diff for: test/node/extended_json_tests.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const MaxKey = BSON.MaxKey;
1717
const MinKey = BSON.MinKey;
1818
const ObjectID = BSON.ObjectID;
1919
const BSONRegExp = BSON.BSONRegExp;
20-
const Symbol = BSON.Symbol;
20+
const BSONSymbol = BSON.BSONSymbol;
2121
const Timestamp = BSON.Timestamp;
2222

2323
describe('Extended JSON', function() {
@@ -43,7 +43,7 @@ describe('Extended JSON', function() {
4343
minKey: new MinKey(),
4444
objectId: ObjectID.createFromHexString('111111111111111111111111'),
4545
regexp: new BSONRegExp('hello world', 'i'),
46-
symbol: new Symbol('symbol'),
46+
symbol: new BSONSymbol('symbol'),
4747
timestamp: Timestamp.fromNumber(1000),
4848
int32Number: 300,
4949
doubleNumber: 200.2,
@@ -172,7 +172,7 @@ describe('Extended JSON', function() {
172172
minKey: new MinKey(),
173173
objectID: ObjectID.createFromHexString('111111111111111111111111'),
174174
bsonRegExp: new BSONRegExp('hello world', 'i'),
175-
symbol: new Symbol('symbol'),
175+
symbol: new BSONSymbol('symbol'),
176176
timestamp: new Timestamp()
177177
};
178178

0 commit comments

Comments
 (0)