Skip to content

Commit

Permalink
Fix type constant names [fix]
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Sep 9, 2023
1 parent f3c648f commit 61ee545
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 43 deletions.
2 changes: 1 addition & 1 deletion lib/serialize/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const {isSymbol, isNumber} = require('is-it-type'),
const {createDependency} = require('./records.js'),
{GLOBAL, MODULE, VALUE, GETTER, SETTER, PROTO, EVAL, COMMON_JS} = require('../shared/constants.js'),
{isJsIdentifier, firstMapKey} = require('./utils.js'),
{GLOBAL: GLOBAL_TYPE} = require('./types.js');
{GLOBAL_TYPE} = require('./types.js');

Check failure on line 17 in lib/serialize/globals.js

View workflow job for this annotation

GitHub Actions / lint

'GLOBAL_TYPE' is assigned a value but never used

Check failure on line 17 in lib/serialize/globals.js

View workflow job for this annotation

GitHub Actions / lint

'GLOBAL_TYPE' is assigned a value but never used

// Exports

Expand Down
39 changes: 23 additions & 16 deletions lib/serialize/primitives.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ const t = require('@babel/types');

// Imports
const {
STRING, BOOLEAN, NUMBER, BIGINT, NULL, UNDEFINED, NEGATIVE, registerSerializer
STRING_TYPE,
BOOLEAN_TYPE,
NUMBER_TYPE,
BIGINT_TYPE,
NULL_TYPE,
UNDEFINED_TYPE,
NEGATIVE_TYPE,
registerSerializer
} = require('./types.js');

// Exports
Expand Down Expand Up @@ -46,24 +53,24 @@ function tracePrimitive(val, type, record) {

function traceNull(record) {
record.name = 'null';
return NULL;
return NULL_TYPE;
}

function traceUndefined(record) {
record.name = 'undefined';
return UNDEFINED;
return UNDEFINED_TYPE;
}

function traceString(val, record) {
record.extra = {val};
record.name = val;
return STRING;
return STRING_TYPE;
}

function traceBoolean(val, record) {
record.extra = {val};
record.name = `${val}`;
return BOOLEAN;
return BOOLEAN_TYPE;
}

/**
Expand All @@ -78,12 +85,12 @@ function traceNumber(val, record) {
if (val < 0 || Object.is(val, -0)) {
record.name = `minus${-val}`;
record.extra = {positive: this.traceDependency(-val, record)};
return NEGATIVE;
return NEGATIVE_TYPE;
}

record.extra = {val};
record.name = `n${val}`;
return NUMBER;
return NUMBER_TYPE;
}

/**
Expand All @@ -97,12 +104,12 @@ function traceBigInt(val, record) {
if (val < 0) {
record.name = `minusb${-val}`;
record.extra = {positive: this.traceDependency(-val, record)};
return NEGATIVE;
return NEGATIVE_TYPE;
}

record.extra = {val};
record.name = `b${val}`;
return BIGINT;
return BIGINT_TYPE;
}

/**
Expand All @@ -112,7 +119,7 @@ function traceBigInt(val, record) {
function serializeNull() {
return t.nullLiteral();
}
registerSerializer(NULL, serializeNull);
registerSerializer(NULL_TYPE, serializeNull);

/**
* Serialize `undefined`.
Expand All @@ -121,7 +128,7 @@ registerSerializer(NULL, serializeNull);
function serializeUndefined() {
return t.unaryExpression('void', t.numericLiteral(0));
}
registerSerializer(UNDEFINED, serializeUndefined);
registerSerializer(UNDEFINED_TYPE, serializeUndefined);

/**
* Serialize string.
Expand All @@ -133,7 +140,7 @@ registerSerializer(UNDEFINED, serializeUndefined);
function serializeString(record) {
return t.stringLiteral(record.extra.val);
}
registerSerializer(STRING, serializeString);
registerSerializer(STRING_TYPE, serializeString);

/**
* Serialize boolean.
Expand All @@ -145,7 +152,7 @@ registerSerializer(STRING, serializeString);
function serializeBoolean(record) {
return t.booleanLiteral(record.extra.val);
}
registerSerializer(BOOLEAN, serializeBoolean);
registerSerializer(BOOLEAN_TYPE, serializeBoolean);

/**
* Serialize number.
Expand All @@ -160,7 +167,7 @@ function serializeNumber(record) {
if (val > 0 || Object.is(val, 0)) return t.numericLiteral(val);
return t.unaryExpression('-', t.numericLiteral(-val));
}
registerSerializer(NUMBER, serializeNumber);
registerSerializer(NUMBER_TYPE, serializeNumber);

/**
* Serialize `BigInt`.
Expand All @@ -174,7 +181,7 @@ function serializeBigInt(record) {
if (val >= 0) return t.bigIntLiteral(bigIntToString.call(val));
return t.unaryExpression('-', t.bigIntLiteral(bigIntToString.call(-val)));
}
registerSerializer(BIGINT, serializeBigInt);
registerSerializer(BIGINT_TYPE, serializeBigInt);

/**
* Serialize negative number / `BigInt`.
Expand All @@ -187,4 +194,4 @@ registerSerializer(BIGINT, serializeBigInt);
function serializeNegative(record) {
return t.unaryExpression('-', this.serializeValue(record.extra.positive));
}
registerSerializer(NEGATIVE, serializeNegative);
registerSerializer(NEGATIVE_TYPE, serializeNegative);
4 changes: 2 additions & 2 deletions lib/serialize/records.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const upperFirst = require('lodash/upperFirst');

// Imports
const {deleteItem} = require('./utils.js'),
{NONE} = require('./types.js');
{NO_TYPE} = require('./types.js');

// Exports

Expand All @@ -35,7 +35,7 @@ module.exports = {
function createRecord(name) {
return {
name,
type: NONE,
type: NO_TYPE,
varNode: undefined,
serializer: undefined,
props: undefined,
Expand Down
48 changes: 24 additions & 24 deletions lib/serialize/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,35 @@
// Exports

/* eslint-disable no-bitwise */
const NONE = 0,
PRIMITIVE = 8,
STRING = PRIMITIVE | 0,
BOOLEAN = PRIMITIVE | 1,
NUMBER = PRIMITIVE | 2,
BIGINT = PRIMITIVE | 3,
NULL = PRIMITIVE | 4,
UNDEFINED = PRIMITIVE | 5,
NEGATIVE = PRIMITIVE | 6, // TODO: Should this be a primitive?
FUNCTION = 16,
METHOD = FUNCTION | 1,
GLOBAL = 32;
const NO_TYPE = 0,
PRIMITIVE_TYPE = 8,
STRING_TYPE = PRIMITIVE_TYPE | 0,
BOOLEAN_TYPE = PRIMITIVE_TYPE | 1,
NUMBER_TYPE = PRIMITIVE_TYPE | 2,
BIGINT_TYPE = PRIMITIVE_TYPE | 3,
NULL_TYPE = PRIMITIVE_TYPE | 4,
UNDEFINED_TYPE = PRIMITIVE_TYPE | 5,
NEGATIVE_TYPE = PRIMITIVE_TYPE | 6, // TODO: Should this be a primitive?
FUNCTION_TYPE = 16,
METHOD_TYPE = FUNCTION_TYPE | 1,
GLOBAL_TYPE = 32;
/* eslint-enable no-bitwise */

const SERIALIZERS = [];

module.exports = {
NONE,
PRIMITIVE,
STRING,
BOOLEAN,
NUMBER,
BIGINT,
NULL,
UNDEFINED,
NEGATIVE,
FUNCTION,
METHOD,
GLOBAL,
NO_TYPE,
PRIMITIVE_TYPE,
STRING_TYPE,
BOOLEAN_TYPE,
NUMBER_TYPE,
BIGINT_TYPE,
NULL_TYPE,
UNDEFINED_TYPE,
NEGATIVE_TYPE,
FUNCTION_TYPE,
METHOD_TYPE,
GLOBAL_TYPE,
SERIALIZERS,
registerSerializer
};
Expand Down

0 comments on commit 61ee545

Please sign in to comment.