Skip to content

Commit

Permalink
Revert special refs map
Browse files Browse the repository at this point in the history
  • Loading branch information
lxsmnsyc committed Nov 14, 2023
1 parent b3fbdb5 commit c538439
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
4 changes: 2 additions & 2 deletions packages/seroval/src/core/parser-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { SerovalNodeType } from './constants';
import type { Plugin, PluginAccessOptions, SerovalMode } from './plugin';
import { hasReferenceID } from './reference';
import type { SpecialReference } from './special-reference';
import { getSpecialReferenceSource } from './special-reference';
import { SPECIAL_REFS } from './special-reference';
import type {
SerovalIndexedValueNode, SerovalReferenceNode, SerovalSpecialReferenceNode,
} from './types';
Expand Down Expand Up @@ -68,7 +68,7 @@ export abstract class BaseParserContext implements PluginAccessOptions {
current: SpecialReference,
): SerovalIndexedValueNode | SerovalReferenceNode | SerovalSpecialReferenceNode {
const ref = this.getReference(
getSpecialReferenceSource(this.features, current),
SPECIAL_REFS[current],
);
if (typeof ref === 'number') {
return {
Expand Down
20 changes: 5 additions & 15 deletions packages/seroval/src/core/special-reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,11 @@ export const enum SpecialReference {
SymbolIterator = 2,
}

const SENTINEL_REF = {};
const ITERATOR_REF = {};

export function getSpecialReferenceSource(features: number, ref: SpecialReference): unknown {
switch (ref) {
case SpecialReference.Sentinel:
return SENTINEL_REF;
case SpecialReference.Iterator:
return ITERATOR_REF;
case SpecialReference.SymbolIterator:
return Symbol.iterator;
default:
throw new Error('unknown special reference ' + ref);
}
}
export const SPECIAL_REFS: Record<SpecialReference, unknown> = {
[SpecialReference.Sentinel]: {},
[SpecialReference.Iterator]: {},
[SpecialReference.SymbolIterator]: Symbol.iterator,
};

export function getSpecialReferenceValue(features: number, ref: SpecialReference): string {
switch (ref) {
Expand Down

0 comments on commit c538439

Please sign in to comment.