Skip to content

Commit

Permalink
breaking: drop modulo interpolation syntax (#1814)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon committed Apr 20, 2024
1 parent ac5c33e commit 5e882ce
Show file tree
Hide file tree
Showing 28 changed files with 548 additions and 1,443 deletions.
19 changes: 0 additions & 19 deletions e2e/formatting/ruby.spec.ts

This file was deleted.

57 changes: 0 additions & 57 deletions examples/composition/formatting/ruby.html

This file was deleted.

47 changes: 0 additions & 47 deletions examples/legacy/formatting/ruby.html

This file was deleted.

52 changes: 0 additions & 52 deletions examples/petite/formatting/ruby.html

This file was deleted.

25 changes: 1 addition & 24 deletions packages/core-base/src/compilation.ts
@@ -1,7 +1,6 @@
import { warn, format, isObject, isBoolean, isString } from '@intlify/shared'
import {
baseCompile as baseCompileCore,
CompileWarnCodes,
defaultOnError,
detectHtmlTag
} from '@intlify/message-compiler'
Expand All @@ -12,8 +11,7 @@ import type {
CompileOptions,
CompileError,
CompilerResult,
ResourceNode,
CompileWarn
ResourceNode
} from '@intlify/message-compiler'
import type { MessageFunction, MessageFunctions } from './runtime'
import type { MessageCompilerContext } from './context'
Expand All @@ -29,17 +27,6 @@ function checkHtmlMessage(source: string, warnHtmlMessage?: boolean): void {
const defaultOnCacheKey = (message: string): string => message
let compileCache: unknown = Object.create(null)

function onCompileWarn(_warn: CompileWarn): void {
if (_warn.code === CompileWarnCodes.USE_MODULO_SYNTAX) {
warn(
`The use of named interpolation with modulo syntax is deprecated. ` +
`It will be removed in v10.\n` +
`reference: https://vue-i18n.intlify.dev/guide/essentials/syntax#rails-i18n-format \n` +
`(message compiler warning message: ${_warn.message})`
)
}
}

export function clearCompileCache(): void {
compileCache = Object.create(null)
}
Expand Down Expand Up @@ -77,11 +64,6 @@ export const compileToFunction = <
throw createCoreError(CoreErrorCodes.NOT_SUPPORT_NON_STRING_MESSAGE)
}

// set onWarn
if (__DEV__) {
context.onWarn = onCompileWarn
}

if (__RUNTIME__) {
__DEV__ &&
warn(
Expand Down Expand Up @@ -125,11 +107,6 @@ export function compile<
message: MessageSource,
context: MessageCompilerContext
): MessageFunction<Message> {
// set onWarn
if (__DEV__) {
context.onWarn = onCompileWarn
}

if (
(__ESM_BROWSER__ ||
__NODE_JS__ ||
Expand Down
2 changes: 1 addition & 1 deletion packages/core-base/src/context.ts
Expand Up @@ -145,7 +145,7 @@ export type PostTranslationHandler<Message = string> = (
*/
export type MessageCompilerContext = Pick<
CompileOptions,
'onError' | 'onCacheKey' | 'onWarn'
'onError' | 'onCacheKey'
> & {
/**
* Whether to allow the use locale messages of HTML formatting.
Expand Down
19 changes: 9 additions & 10 deletions packages/core-base/src/warnings.ts
@@ -1,18 +1,17 @@
import { format, incrementer } from '@intlify/shared'
import { CompileWarnCodes } from '@intlify/message-compiler'

const code = CompileWarnCodes.__EXTEND_POINT__
const code = 1
const inc = incrementer(code)

export const CoreWarnCodes = {
NOT_FOUND_KEY: code, // 2
FALLBACK_TO_TRANSLATE: inc(), // 3
CANNOT_FORMAT_NUMBER: inc(), // 4
FALLBACK_TO_NUMBER_FORMAT: inc(), // 5
CANNOT_FORMAT_DATE: inc(), // 6
FALLBACK_TO_DATE_FORMAT: inc(), // 7
EXPERIMENTAL_CUSTOM_MESSAGE_COMPILER: inc(), // 8
__EXTEND_POINT__: inc() // 9
NOT_FOUND_KEY: code, // 1
FALLBACK_TO_TRANSLATE: inc(), // 2
CANNOT_FORMAT_NUMBER: inc(), // 3
FALLBACK_TO_NUMBER_FORMAT: inc(), // 4
CANNOT_FORMAT_DATE: inc(), // 5
FALLBACK_TO_DATE_FORMAT: inc(), // 6
EXPERIMENTAL_CUSTOM_MESSAGE_COMPILER: inc(), // 7
__EXTEND_POINT__: inc() // 8
} as const

export type CoreWarnCodes = (typeof CoreWarnCodes)[keyof typeof CoreWarnCodes]
Expand Down
24 changes: 0 additions & 24 deletions packages/core-base/test/compilation.test.ts
Expand Up @@ -60,19 +60,6 @@ describe('compileToFunction', () => {
})
expect(occured).toBe(true)
})

test('modulo syntax warning', () => {
const mockWarn = vi.spyOn(shared, 'warn')
mockWarn.mockImplementation(() => {})

compileToFunction('hello %{name}!', {
...DEFAULT_CONTEXT
})
expect(mockWarn).toHaveBeenCalledTimes(1)
expect(mockWarn.mock.calls[0][0]).includes(
`The use of named interpolation with modulo syntax is deprecated. It will be removed in v10.`
)
})
})

describe('compile', () => {
Expand Down Expand Up @@ -132,15 +119,4 @@ describe('compile', () => {
})
expect(occured).toBe(true)
})

test('modulo syntax warning', () => {
const mockWarn = vi.spyOn(shared, 'warn')
mockWarn.mockImplementation(() => {})

compile('%{msg} world!', DEFAULT_CONTEXT)
expect(mockWarn).toHaveBeenCalledTimes(1)
expect(mockWarn.mock.calls[0][0]).includes(
`The use of named interpolation with modulo syntax is deprecated. It will be removed in v10.`
)
})
})
2 changes: 1 addition & 1 deletion packages/core-base/test/warnings.test.ts
@@ -1,5 +1,5 @@
import { CoreWarnCodes } from '../src/warnings'

test('CoreWarnCodes', () => {
expect(CoreWarnCodes.NOT_FOUND_KEY).toBe(2)
expect(CoreWarnCodes.NOT_FOUND_KEY).toBe(1)
})
1 change: 0 additions & 1 deletion packages/message-compiler/src/index.ts
@@ -1,7 +1,6 @@
export * from './location'
export * from './nodes'
export * from './options'
export * from './warnings'
export * from './errors'
export * from './helpers'
export * from './parser'
Expand Down
5 changes: 0 additions & 5 deletions packages/message-compiler/src/options.ts
@@ -1,7 +1,5 @@
import type { CompileError } from './errors'
import type { CompileWarn } from './warnings'

export type CompileWarnHandler = (warn: CompileWarn) => void
export type CompileErrorHandler = (error: CompileError) => void
export type CacheKeyHandler = (source: string) => string

Expand All @@ -13,12 +11,10 @@ export interface TokenizeOptions {
export interface ParserOptions {
location?: boolean // default true
onCacheKey?: (source: string) => string
onWarn?: CompileWarnHandler
onError?: CompileErrorHandler
}

export interface TransformOptions {
onWarn?: CompileWarnHandler
onError?: CompileErrorHandler
}

Expand All @@ -27,7 +23,6 @@ export interface CodeGenOptions {
mode?: 'normal' | 'arrow' // default normal
breakLineCode?: '\n' | ';' // default newline
needIndent?: boolean // default true
onWarn?: CompileWarnHandler
onError?: CompileErrorHandler
// Generate source map?
// - Default: false
Expand Down

0 comments on commit 5e882ce

Please sign in to comment.