chore(marshal): Increase similarity between encodeTo{CapData,Smallcaps}
MODIFY
packages/marshal/src/encodeToCapData.js
packages/marshal/src/encodeToCapData.js
@@ -134,30 +134,26 @@ export const makeEncodeToCapData = ({
// JSON, and some must be encoded as [QCLASS] composites.
const passStyle = passStyleOf(passable);
switch (passStyle) {
- case 'null': {
- return null;
+ case 'null':
+ case 'boolean':
+ case 'string': {
+ // pass through to JSON
+ return passable;
}
case 'undefined': {
return { [QCLASS]: 'undefined' };
}
- case 'string':
- case 'boolean': {
- return passable;
- }
case 'number': {
+ // Special-case numbers with no digit-based representation.
if (Number.isNaN(passable)) {
return { [QCLASS]: 'NaN' };
- }
- if (is(passable, -0)) {
- return 0;
- }
- if (passable === Infinity) {
+ } else if (passable === Infinity) {
return { [QCLASS]: 'Infinity' };
- }
- if (passable === -Infinity) {
+ } else if (passable === -Infinity) {
return { [QCLASS]: '-Infinity' };
}
- return passable;
+ // Pass through everything else, replacing -0 with 0.
+ return is(passable, -0) ? 0 : passable;
}
case 'bigint': {
return {

MODIFY
packages/marshal/src/encodeToSmallcaps.js
packages/marshal/src/encodeToSmallcaps.js
@@ -177,37 +177,30 @@ export const makeEncodeToSmallcaps = ({
// All other strings pass through to JSON
return passable;
}
- case 'symbol': {
- // At the smallcaps level, we prefix symbol names with `%`.
- // By "symbol name", we mean according to `nameForPassableSymbol`
- // which does some further escaping. See comment on that function.
- assertPassableSymbol(passable);
- const name = /** @type {string} */ (nameForPassableSymbol(passable));
- return `%${name}`;
- }
case 'undefined': {
return '#undefined';
}
case 'number': {
+ // Special-case numbers with no digit-based representation.
if (Number.isNaN(passable)) {
return '#NaN';
- }
- if (is(passable, -0)) {
- return 0;
- }
- if (passable === Infinity) {
+ } else if (passable === Infinity) {
return '#Infinity';
- }
- if (passable === -Infinity) {
+ } else if (passable === -Infinity) {
return '#-Infinity';
}
- // All other numbers pass through to JSON
- return passable;
+ // Pass through everything else, replacing -0 with 0.
+ return is(passable, -0) ? 0 : passable;
}
case 'bigint': {
const str = String(passable);
return passable < 0n ? str : `+${str}`;
}
+ case 'symbol': {
+ assertPassableSymbol(passable);
+ const name = /** @type {string} */ (nameForPassableSymbol(passable));
+ return `%${name}`;
+ }
case 'copyRecord': {
// Currently copyRecord allows only string keys so this will
// work. If we allow sortable symbol keys, this will need to

chore(marshal): Increase similarity between encodeTo{CapData,Smallcaps}