From 0f19f34cd7ff186df856477c65eb8717073a096c Mon Sep 17 00:00:00 2001 From: Ole Martin Handeland Date: Mon, 14 Dec 2020 16:14:41 +0100 Subject: [PATCH] Using Frequency directly and getting rid of the getnlp hack This prevents problems with circular imports. I still get 14 warnings about circular imports in rollup (regardless of using the main commonjs plugin or the alternate one), but at least the emitted code seems to work fine in both now. --- src/nlp/index.ts | 13 +++++++------ src/rrule.ts | 23 +++++------------------ 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/nlp/index.ts b/src/nlp/index.ts index f18da328..2837583e 100644 --- a/src/nlp/index.ts +++ b/src/nlp/index.ts @@ -1,6 +1,7 @@ import ToText, { DateFormatter, GetText } from './totext' import parseText from './parsetext' import RRule from '../index' +import { Frequency } from '../types' import ENGLISH, { Language } from './i18n' /*! @@ -108,12 +109,12 @@ const common = [ ] ToText.IMPLEMENTED = [] -ToText.IMPLEMENTED[RRule.HOURLY] = common -ToText.IMPLEMENTED[RRule.MINUTELY] = common -ToText.IMPLEMENTED[RRule.DAILY] = ['byhour'].concat(common) -ToText.IMPLEMENTED[RRule.WEEKLY] = common -ToText.IMPLEMENTED[RRule.MONTHLY] = common -ToText.IMPLEMENTED[RRule.YEARLY] = ['byweekno', 'byyearday'].concat(common) +ToText.IMPLEMENTED[Frequency.HOURLY] = common +ToText.IMPLEMENTED[Frequency.MINUTELY] = common +ToText.IMPLEMENTED[Frequency.DAILY] = ['byhour'].concat(common) +ToText.IMPLEMENTED[Frequency.WEEKLY] = common +ToText.IMPLEMENTED[Frequency.MONTHLY] = common +ToText.IMPLEMENTED[Frequency.YEARLY] = ['byweekno', 'byyearday'].concat(common) // ============================================================================= // Export diff --git a/src/rrule.ts b/src/rrule.ts index ccbac06c..db337cd5 100644 --- a/src/rrule.ts +++ b/src/rrule.ts @@ -3,7 +3,7 @@ import dateutil from './dateutil' import IterResult, { IterArgs } from './iterresult' import CallbackIterResult from './callbackiterresult' import { Language } from './nlp/i18n' -import { Nlp } from './nlp/index' +import { fromText, parseText, toText, isFullyConvertible } from './nlp/index' import { DateFormatter, GetText } from './nlp/totext' import { ParsedOptions, Options, Frequency, QueryMethods, QueryMethodTypes, IterResultType } from './types' import { parseOptions, initializeOptions } from './parseoptions' @@ -13,19 +13,6 @@ import { Cache, CacheKeys } from './cache' import { Weekday } from './weekday' import { iter } from './iter/index' -interface GetNlp { - _nlp: Nlp - (): Nlp -} - -const getnlp: GetNlp = function () { - // Lazy, runtime import to avoid circular refs. - if (!getnlp._nlp) { - getnlp._nlp = require('./nlp') - } - return getnlp._nlp -} as GetNlp - // ============================================================================= // RRule // ============================================================================= @@ -114,11 +101,11 @@ export default class RRule implements QueryMethods { } static parseText (text: string, language?: Language) { - return getnlp().parseText(text, language) + return parseText(text, language) } static fromText (text: string, language?: Language) { - return getnlp().fromText(text, language) + return fromText(text, language) } static parseString = parseString @@ -256,11 +243,11 @@ export default class RRule implements QueryMethods { * to text. */ toText (gettext?: GetText, language?: Language, dateFormatter?: DateFormatter) { - return getnlp().toText(this, gettext, language, dateFormatter) + return toText(this, gettext, language, dateFormatter) } isFullyConvertibleToText () { - return getnlp().isFullyConvertible(this) + return isFullyConvertible(this) } /**