diff --git a/lib/serialize/globals.js b/lib/serialize/globals.js index d3cd8cca..96230617 100644 --- a/lib/serialize/globals.js +++ b/lib/serialize/globals.js @@ -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'); // Exports diff --git a/lib/serialize/primitives.js b/lib/serialize/primitives.js index c7e9f305..73b37135 100644 --- a/lib/serialize/primitives.js +++ b/lib/serialize/primitives.js @@ -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 @@ -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; } /** @@ -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; } /** @@ -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; } /** @@ -112,7 +119,7 @@ function traceBigInt(val, record) { function serializeNull() { return t.nullLiteral(); } -registerSerializer(NULL, serializeNull); +registerSerializer(NULL_TYPE, serializeNull); /** * Serialize `undefined`. @@ -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. @@ -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. @@ -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. @@ -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`. @@ -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`. @@ -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); diff --git a/lib/serialize/records.js b/lib/serialize/records.js index 6380513f..7e827067 100644 --- a/lib/serialize/records.js +++ b/lib/serialize/records.js @@ -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 @@ -35,7 +35,7 @@ module.exports = { function createRecord(name) { return { name, - type: NONE, + type: NO_TYPE, varNode: undefined, serializer: undefined, props: undefined, diff --git a/lib/serialize/types.js b/lib/serialize/types.js index 89859f7d..6f110adc 100644 --- a/lib/serialize/types.js +++ b/lib/serialize/types.js @@ -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 };