mirror of
https://github.com/cupcakearmy/svelte-i18n.git
synced 2024-09-28 15:14:45 +02:00
Refactor type imports to use type modifier
This commit is contained in:
parent
abbd396128
commit
739d784c16
@ -1,4 +1,4 @@
|
|||||||
import {
|
import type {
|
||||||
Node,
|
Node,
|
||||||
ObjectExpression,
|
ObjectExpression,
|
||||||
ImportDeclaration,
|
ImportDeclaration,
|
||||||
@ -8,13 +8,13 @@ import {
|
|||||||
Literal,
|
Literal,
|
||||||
} from 'estree';
|
} from 'estree';
|
||||||
import { walk } from 'estree-walker';
|
import { walk } from 'estree-walker';
|
||||||
import { Ast } from 'svelte/types/compiler/interfaces';
|
import type { Ast } from 'svelte/types/compiler/interfaces';
|
||||||
import { parse } from 'svelte/compiler';
|
import { parse } from 'svelte/compiler';
|
||||||
import dlv from 'dlv';
|
import dlv from 'dlv';
|
||||||
|
|
||||||
import { deepSet } from './includes/deepSet';
|
import { deepSet } from './includes/deepSet';
|
||||||
import { getObjFromExpression } from './includes/getObjFromExpression';
|
import { getObjFromExpression } from './includes/getObjFromExpression';
|
||||||
import { Message } from './types';
|
import type { Message } from './types';
|
||||||
|
|
||||||
const LIB_NAME = 'svelte-i18n';
|
const LIB_NAME = 'svelte-i18n';
|
||||||
const DEFINE_MESSAGES_METHOD_NAME = 'defineMessages';
|
const DEFINE_MESSAGES_METHOD_NAME = 'defineMessages';
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { ObjectExpression, Property, Identifier } from 'estree';
|
import type { ObjectExpression, Property, Identifier } from 'estree';
|
||||||
|
|
||||||
import { Message } from '../types';
|
import type { Message } from '../types';
|
||||||
|
|
||||||
export function getObjFromExpression(exprNode: ObjectExpression) {
|
export function getObjFromExpression(exprNode: ObjectExpression) {
|
||||||
return exprNode.properties.reduce<Message>((acc, prop: Property) => {
|
return exprNode.properties.reduce<Message>((acc, prop: Property) => {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { ConfigureOptions } from './types';
|
import type { ConfigureOptions } from './types';
|
||||||
import { $locale } from './stores/locale';
|
import { $locale } from './stores/locale';
|
||||||
|
|
||||||
interface Formats {
|
interface Formats {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import IntlMessageFormat from 'intl-messageformat';
|
import IntlMessageFormat from 'intl-messageformat';
|
||||||
|
|
||||||
import { MemoizedIntlFormatter } from '../types';
|
import type { MemoizedIntlFormatter } from '../types';
|
||||||
import { getCurrentLocale } from '../stores/locale';
|
import { getCurrentLocale } from '../stores/locale';
|
||||||
import { getOptions } from '../configs';
|
import { getOptions } from '../configs';
|
||||||
import { monadicMemoize } from './memoize';
|
import { monadicMemoize } from './memoize';
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { MessagesLoader } from '../types';
|
import type { MessagesLoader } from '../types';
|
||||||
import {
|
import {
|
||||||
hasLocaleDictionary,
|
hasLocaleDictionary,
|
||||||
$dictionary,
|
$dictionary,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { MessageObject } from './types';
|
import type { MessageObject } from './types';
|
||||||
import { getCurrentLocale, $locale } from './stores/locale';
|
import { getCurrentLocale, $locale } from './stores/locale';
|
||||||
import { getOptions, init } from './configs';
|
import { getOptions, init } from './configs';
|
||||||
import { flush, registerLocaleLoader } from './includes/loaderQueue';
|
import { flush, registerLocaleLoader } from './includes/loaderQueue';
|
||||||
|
@ -2,7 +2,7 @@ import { writable, derived } from 'svelte/store';
|
|||||||
import deepmerge from 'deepmerge';
|
import deepmerge from 'deepmerge';
|
||||||
import dlv from 'dlv';
|
import dlv from 'dlv';
|
||||||
|
|
||||||
import { LocaleDictionary, LocalesDictionary } from '../types/index';
|
import type { LocaleDictionary, LocalesDictionary } from '../types/index';
|
||||||
import { getFallbackOf } from './locale';
|
import { getFallbackOf } from './locale';
|
||||||
|
|
||||||
let dictionary: LocalesDictionary;
|
let dictionary: LocalesDictionary;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { derived } from 'svelte/store';
|
import { derived } from 'svelte/store';
|
||||||
|
|
||||||
import {
|
import type {
|
||||||
MessageFormatter,
|
MessageFormatter,
|
||||||
MessageObject,
|
MessageObject,
|
||||||
TimeFormatter,
|
TimeFormatter,
|
||||||
|
@ -49,7 +49,7 @@ export type NumberFormatter = (
|
|||||||
options?: IntlFormatterOptions<Intl.NumberFormatOptions>,
|
options?: IntlFormatterOptions<Intl.NumberFormatOptions>,
|
||||||
) => string;
|
) => string;
|
||||||
|
|
||||||
export type JSONGetter = <T extends any>(id: string, locale?: string) => T;
|
export type JSONGetter = <T>(id: string, locale?: string) => T;
|
||||||
|
|
||||||
type IntlFormatterOptions<T> = T & {
|
type IntlFormatterOptions<T> = T & {
|
||||||
format?: string;
|
format?: string;
|
||||||
|
@ -30,7 +30,7 @@ test('gets a message from the fallback dictionary', () => {
|
|||||||
expect(lookup('field', 'en-US')).toBe('name');
|
expect(lookup('field', 'en-US')).toBe('name');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('gets an array ', () => {
|
test('gets an array', () => {
|
||||||
addMessages('en', {
|
addMessages('en', {
|
||||||
careers: [
|
careers: [
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { get } from 'svelte/store';
|
import { get } from 'svelte/store';
|
||||||
|
|
||||||
import {
|
import type {
|
||||||
JSONGetter,
|
JSONGetter,
|
||||||
MessageFormatter,
|
MessageFormatter,
|
||||||
TimeFormatter,
|
TimeFormatter,
|
||||||
|
Loading…
Reference in New Issue
Block a user