File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import { createLingoConfig } from "../utils/config-factory";
1010import { logger } from "../utils/logger" ;
1111import type { PartialLingoConfig } from "../types" ;
1212import { lingoUnplugin } from "./unplugin" ;
13+ import { useI18nRegex } from "./transform/use-i18n" ;
1314
1415export type LingoNextPluginOptions = PartialLingoConfig ;
1516
@@ -87,8 +88,7 @@ function buildLingoConfig(
8788 // This is more efficient than checking in the loader itself
8889 if ( lingoConfig . useDirective ) {
8990 lingoRuleConfig . condition = {
90- content :
91- / ^ \s * (?: [ " ' ] u s e (?: s t r i c t | c l i e n t | s e r v e r ) [ " ' ] \s * ; ? \s * ) * [ " ' ] u s e i 1 8 n [ " ' ] \s * ; ? / m,
91+ content : useI18nRegex ,
9292 } ;
9393 }
9494
Original file line number Diff line number Diff line change 1+ export const useI18n = "use i18n" ;
2+ export const useI18nRegex = new RegExp ( `["']${ useI18n } ["']` ) ;
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import type { NodePath } from "@babel/traverse";
33import type { VariableDeclaration } from "@babel/types" ;
44import * as t from "@babel/types" ;
55import { generateTranslationHash } from "../../utils/hash" ;
6+ import { useI18n } from "./use-i18n" ;
67
78type TranslationEntryByType = {
89 [ T in TranslationEntry as T [ "type" ] ] : T ;
@@ -104,7 +105,7 @@ export function inferComponentName(path: NodePath<any>): string | null {
104105export function hasUseI18nDirective ( program : NodePath < t . Program > ) : boolean {
105106 const directives = program . node . directives || [ ] ;
106107 return directives . some (
107- ( directive : t . Directive ) => directive . value . value === "use i18n" ,
108+ ( directive : t . Directive ) => directive . value . value === useI18n ,
108109 ) ;
109110}
110111
Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ import type { LingoConfig } from "../types";
22import { loadMetadata , saveMetadata , upsertEntries } from "../metadata/manager" ;
33import { shouldTransformFile , transformComponent } from "./transform" ;
44import { logger } from "../utils/logger" ;
5- import { hasI18nDirective } from "../utils/directive-check" ;
65
76/**
87 * Turbopack/Webpack loader for automatic translation
@@ -26,17 +25,12 @@ export default async function lingoCompilerTurbopackLoader(
2625 try {
2726 const config : LingoConfig = this . getOptions ( ) ;
2827
28+ // TODO (AleksandrSl 07/12/2025): Remove too I think
2929 // Check if this file should be transformed
3030 if ( ! shouldTransformFile ( this . resourcePath , config ) ) {
3131 return callback ( null , source ) ;
3232 }
3333
34- // Fast path: if useDirective is enabled, check for directive before parsing
35- // This avoids expensive Babel parsing for files without "use i18n"
36- if ( config . useDirective && ! hasI18nDirective ( source ) ) {
37- return callback ( null , source ) ;
38- }
39-
4034 // Transform the component
4135 const result = transformComponent ( {
4236 code : source ,
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ import { saveMetadataWithEntries } from "../metadata/manager";
2323import { createLingoConfig } from "../utils/config-factory" ;
2424import { logger } from "../utils/logger" ;
2525import { getCacheDir } from "../utils/path-helpers" ;
26+ import { useI18nRegex } from "./transform/use-i18n" ;
2627
2728export type LingoPluginOptions = PartialLingoConfig ;
2829
@@ -84,9 +85,7 @@ export const cacheDir = ${JSON.stringify(cacheDir)};`;
8485 } ,
8586 // If useDirective is enabled, only process files with "use i18n"
8687 // This is more efficient than checking in the handler
87- code : config . useDirective
88- ? / ^ \s * (?: [ " ' ] u s e (?: s t r i c t | c l i e n t | s e r v e r ) [ " ' ] \s * ; ? \s * ) * [ " ' ] u s e i 1 8 n [ " ' ] \s * ; ? / m
89- : undefined ,
88+ code : config . useDirective ? useI18nRegex : undefined ,
9089 } ,
9190 handler : async ( code , id ) => {
9291 try {
You can’t perform that action at this time.
0 commit comments