Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

breaking: drop modulo syntax #1814

Merged
merged 1 commit into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Loading