Skip to content

Commit

Permalink
refactor: verbatimModuleSyntax option
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon committed Jan 7, 2025
1 parent 453f50b commit 255ae03
Show file tree
Hide file tree
Showing 26 changed files with 107 additions and 89 deletions.
2 changes: 1 addition & 1 deletion packages/core-base/src/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
} from '@intlify/shared'
import { isMessageAST } from './compilation'
import {
CoreContext,
getAdditionalMeta,
handleMissing,
isAlmostSameLocale,
Expand All @@ -36,6 +35,7 @@ import { CoreWarnCodes, getWarnMessage } from './warnings'
import type { AdditionalPayloads } from '@intlify/devtools-types'
import type { CompileError, ResourceNode } from '@intlify/message-compiler'
import type {
CoreContext,
CoreInternalContext,
DefineCoreLocaleMessage,
LocaleMessages,
Expand Down
6 changes: 3 additions & 3 deletions packages/core-base/test/context.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
createCoreContext,
import { createCoreContext } from '../src'

import type {
DateTimeFormat,
Locale,
LocaleDetector,
NumberFormat,
PickupFallbackLocales
} from '../src'

import type { MyDatetimeScehma, MyNumberSchema, ResourceSchema } from './schema'

// loose options
Expand Down
8 changes: 5 additions & 3 deletions packages/core-base/test/fallbacker.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { createCoreContext as context, CoreContext } from '../src/context'
import { createCoreContext as context } from '../src/context'
import { CoreErrorCodes, errorMessages } from '../src/errors'
import {
fallbackWithLocaleChain,
fallbackWithSimple,
resolveLocale
} from '../src/fallbacker'
import { errorMessages, CoreErrorCodes } from '../src/errors'
import { LocaleDetector } from '@intlify/core-base'

import type { LocaleDetector } from '@intlify/core-base'
import type { CoreContext } from '../src/context'

describe('fallbackWithSimple', () => {
let ctx: CoreContext<string>
Expand Down
3 changes: 2 additions & 1 deletion packages/core-base/test/issues.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { NodeTypes } from '@intlify/message-compiler'
import { format } from '../src/format'
import { createMessageContext as context } from '../src/runtime'

import { NodeTypes, ResourceNode } from '@intlify/message-compiler'
import type { ResourceNode } from '@intlify/message-compiler'

describe('CVE-2024-52809', () => {
function attackGetter() {
Expand Down
16 changes: 9 additions & 7 deletions packages/core-base/test/number.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@ vi.mock('../src/intl', async () => {
}
})

import { createCoreContext as context, NOT_REOSLVED } from '../src/context'
import { number } from '../src/number'
import { CoreErrorCodes, errorMessages } from '../src/errors'
import { compile } from '../src/compilation'
import {
registerMessageCompiler,
registerLocaleFallbacker
createCoreContext as context,
NOT_REOSLVED,
registerLocaleFallbacker,
registerMessageCompiler
} from '../src/context'
import { compile } from '../src/compilation'
import { CoreErrorCodes, errorMessages } from '../src/errors'
import { fallbackWithLocaleChain } from '../src/fallbacker'
import { NumberFormats } from '../src/types/index'
import { number } from '../src/number'

import type { NumberFormats } from '../src/types/index'

type MyNumberSchema = {
currency: {} // loose schema
Expand Down
2 changes: 1 addition & 1 deletion packages/core-base/test/runtime.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MessageType } from '../src/runtime'
import type { MessageType } from '../src/runtime'

/**
* Message Type
Expand Down
6 changes: 4 additions & 2 deletions packages/format-explorer/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { execaSync } from 'execa'
import path from 'node:path'
import { URL } from 'node:url'
import { defineConfig } from 'vite'

const commit = execaSync('git', ['rev-parse', 'HEAD']).stdout.slice(0, 7)
console.log('commit', commit)

const __dirname = path.dirname(new URL(import.meta.url).pathname)

// https://vitejs.dev/config/
export default defineConfig({
const config = defineConfig({
define: {
__COMMIT__: JSON.stringify(commit),
__BROWSER__: false
Expand All @@ -25,3 +25,5 @@ export default defineConfig({
},
plugins: [vue()]
})

export default config
2 changes: 1 addition & 1 deletion packages/message-compiler/src/nodes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SourceLocation } from './location'
import type { SourceLocation } from './location'

export const enum NodeTypes {
Resource, // 0
Expand Down
3 changes: 1 addition & 2 deletions packages/vue-i18n-core/src/components/base.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Composer } from '../composer'

import type { Locale } from '@intlify/core-base'
import type { Composer } from '../composer'
import type { I18nScope } from '../i18n'

export type ComponentI18nScope = Exclude<I18nScope, 'local'>
Expand Down
14 changes: 9 additions & 5 deletions packages/vue-i18n-core/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
export { BaseFormatProps, ComponentI18nScope } from './base'
export { DatetimeFormat, DatetimeFormatProps, I18nD } from './DatetimeFormat'
export { FormattableProps } from './formatRenderer'
export { I18nN, NumberFormat, NumberFormatProps } from './NumberFormat'
export { I18nT, Translation, TranslationProps } from './Translation'
export { DatetimeFormat, I18nD } from './DatetimeFormat'
export { I18nN, NumberFormat } from './NumberFormat'
export { I18nT, Translation } from './Translation'

export type { BaseFormatProps, ComponentI18nScope } from './base'
export type { DatetimeFormatProps } from './DatetimeFormat'
export type { FormattableProps } from './formatRenderer'
export type { NumberFormatProps } from './NumberFormat'
export type { TranslationProps } from './Translation'
2 changes: 1 addition & 1 deletion packages/vue-i18n-core/src/composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import {
DEFAULT_LOCALE,
MISSING_RESOLVE_VALUE,
MessageFunction,
NOT_REOSLVED,
clearDateTimeFormat,
clearNumberFormat,
Expand Down Expand Up @@ -80,6 +79,7 @@ import type {
LocaleMessages,
LocaleParams,
MessageCompiler,
MessageFunction,
MessageFunctions,
MessageProcessor,
MessageResolver,
Expand Down
8 changes: 3 additions & 5 deletions packages/vue-i18n-core/src/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import {
isObject,
isString
} from '@intlify/shared'
import {
ComponentTreeNode,
Hooks,
setupDevtoolsPlugin
} from '@vue/devtools-api'
import { setupDevtoolsPlugin } from '@vue/devtools-api'

import type {
VueDevToolsIDs,
Expand All @@ -19,9 +15,11 @@ import type {
} from '@intlify/devtools-types'
import type {
ComponentStateBase,
ComponentTreeNode,
CustomInspectorState,
DevtoolsPluginApi,
HookPayloads,
Hooks,
InspectedComponentData
} from '@vue/devtools-api'
import type { App, ComponentInternalInstance } from 'vue'
Expand Down
8 changes: 6 additions & 2 deletions packages/vue-i18n-core/src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
warnOnce
} from '@intlify/shared'
import {
InjectionKey,
effectScope,
getCurrentInstance,
inject,
Expand Down Expand Up @@ -42,7 +41,12 @@ import type {
VueDevToolsEmitter,
VueDevToolsEmitterEvents
} from '@intlify/devtools-types'
import type { App, ComponentInternalInstance, EffectScope } from 'vue'
import type {
App,
ComponentInternalInstance,
EffectScope,
InjectionKey
} from 'vue'
import type {
Composer,
ComposerInternalOptions,
Expand Down
3 changes: 2 additions & 1 deletion packages/vue-i18n-core/src/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
isRegExp,
isString
} from '@intlify/shared'
import { createComposer, DefineLocaleMessage } from './composer'
import { createComposer } from './composer'
import { DisableEmitter, EnableEmitter } from './symbols'

import type {
Expand Down Expand Up @@ -55,6 +55,7 @@ import type {
DefaultLocaleMessageSchema,
DefaultNumberFormatSchema,
DefineDateTimeFormat,
DefineLocaleMessage,
DefineNumberFormat,
MissingHandler,
VueMessageType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import {
registerMessageResolver,
resolveValue
} from '@intlify/core-base'
import { defineComponent, h, SetupContext, VNodeChild } from 'vue'
import { defineComponent, h } from 'vue'
import { createI18n } from '../../src/index'
import { mount } from '../helper'

import type { SetupContext, VNodeChild } from 'vue'
import type { IntlDateTimeFormats } from '../../src/index'

const datetimeFormats: IntlDateTimeFormats = {
Expand Down
3 changes: 2 additions & 1 deletion packages/vue-i18n-core/test/components/NumberFormat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import {
registerMessageResolver,
resolveValue
} from '@intlify/core-base'
import { defineComponent, h, SetupContext, VNodeChild } from 'vue'
import { defineComponent, h } from 'vue'
import { createI18n } from '../../src/index'
import { mount } from '../helper'

import type { SetupContext, VNodeChild } from 'vue'
import type { IntlNumberFormats } from '../../src/index'

const numberFormats: IntlNumberFormats = {
Expand Down
11 changes: 2 additions & 9 deletions packages/vue-i18n-core/test/components/Translation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,12 @@ import {
registerMessageResolver,
resolveValue
} from '@intlify/core-base'
import {
defineComponent,
h,
nextTick,
ref,
SetupContext,
VNodeChild
} from 'vue'
import { defineComponent, h, nextTick, ref } from 'vue'
import { createI18n, useI18n } from '../../src/index'
import { mount } from '../helper'

import type { Path, PathValue } from '@intlify/core-base'
import type { Ref } from 'vue'
import type { Ref, SetupContext, VNodeChild } from 'vue'

const messages = {
en: {
Expand Down
39 changes: 21 additions & 18 deletions packages/vue-i18n-core/test/composer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,44 @@

// utils
import * as shared from '@intlify/shared'
import { pluralRules as _pluralRules } from './helper'
vi.mock('@intlify/shared', async () => {
const actual = await vi.importActual<object>('@intlify/shared')
return {
...actual,
warn: vi.fn()
}
})
import { pluralRules as _pluralRules } from './helper'

import {
createComposer,
MissingHandler,
ComposerOptions,
VueMessageType
} from '../src/composer'
compile,
fallbackWithLocaleChain,
registerLocaleFallbacker,
registerMessageCompiler,
registerMessageResolver,
resolveValue
} from '@intlify/core-base'
import { createVNode, nextTick, Text, watch, watchEffect } from 'vue'
import { createComposer } from '../src/composer'
import {
TranslateVNodeSymbol,
DatetimePartsSymbol,
NumberPartsSymbol,
DatetimePartsSymbol
TranslateVNodeSymbol
} from '../src/symbols'
import { getWarnMessage, I18nWarnCodes } from '../src/warnings'
import { watch, watchEffect, nextTick, Text, createVNode } from 'vue'
import {

import type {
Locale,
compile,
registerMessageCompiler,
resolveValue,
registerMessageResolver,
fallbackWithLocaleChain,
registerLocaleFallbacker,
MessageContext,
MessageFunction,
Path,
PathValue,
MessageFunction
PathValue
} from '@intlify/core-base'
import type {
ComposerOptions,
MissingHandler,
VueMessageType
} from '../src/composer'

beforeEach(() => {
registerMessageCompiler(compile)
Expand Down
24 changes: 13 additions & 11 deletions packages/vue-i18n-core/test/helper.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import { assign, isBoolean, isPlainObject } from '@intlify/shared'
import { compile } from '@vue/compiler-dom'
import * as runtimeDom from 'vue'
import {
createApp,
defineComponent,
h,
ComponentPublicInstance,
reactive,
nextTick,
ComponentObjectPropsOptions,
App,
VNode,
shallowRef,
onErrorCaptured,
ComponentOptions
reactive,
shallowRef
} from 'vue'
import { compile } from '@vue/compiler-dom'
import * as runtimeDom from 'vue'
import { isBoolean, isPlainObject, assign } from '@intlify/shared'
import { I18n } from '../src/i18n'

import type {
App,
ComponentObjectPropsOptions,
ComponentOptions,
ComponentPublicInstance,
VNode
} from 'vue'
import type { I18n } from '../src/i18n'
import type { I18nPluginOptions } from '../src/plugin/types'

export interface MountOptions {
Expand Down
5 changes: 2 additions & 3 deletions packages/vue-i18n-core/test/i18n.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,20 @@ import {
} from '@intlify/core-base'
import { createEmitter } from '@intlify/shared'
import {
ComponentOptions,
defineComponent,
defineCustomElement,
getCurrentInstance,
h,
nextTick,
ref
} from 'vue'
import { Composer } from '../src/composer'
import { errorMessages, I18nErrorCodes } from '../src/errors'
import { createI18n, useI18n } from '../src/i18n'
import { pluralRules as _pluralRules, mount, randStr } from './helper'

import type { IntlifyDevToolsEmitterHooks } from '@intlify/devtools-types'
import type { App } from 'vue'
import type { App, ComponentOptions } from 'vue'
import type { Composer } from '../src/composer'
import type { I18n } from '../src/i18n'
import type { VueI18n } from '../src/legacy'
/* eslint-disable @typescript-eslint/no-explicit-any */
Expand Down
Loading

0 comments on commit 255ae03

Please sign in to comment.