@lingo.dev/compiler 0.4.11 → 0.4.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/plugin/transform/process-file.cjs +14 -1
- package/build/plugin/transform/process-file.mjs +14 -1
- package/build/plugin/transform/process-file.mjs.map +1 -1
- package/build/react/server/ServerLingoProvider.d.cts +2 -2
- package/build/react/server/ServerLingoProvider.d.mts +2 -2
- package/build/react/shared/LingoProvider.d.cts +2 -2
- package/build/react/shared/LingoProvider.d.mts +2 -2
- package/package.json +2 -2
|
@@ -242,9 +242,21 @@ function processJSXElement(path, state) {
|
|
|
242
242
|
const entry = require_utils.createTranslationEntry("content", scope.text, { componentName: component.name }, state.filePath, path.node.loc?.start.line, path.node.loc?.start.column, overrides);
|
|
243
243
|
registerEntry(entry, state, component.name);
|
|
244
244
|
rewriteChildren(path, state, scope, entry.hash);
|
|
245
|
+
if (path.node.type === "JSXElement") path.get("openingElement").traverse(componentVisitors, { visitorState: state });
|
|
245
246
|
path.skip();
|
|
246
247
|
}
|
|
247
248
|
/**
|
|
249
|
+
* Is this node part of the value handed to a JSX attribute?
|
|
250
|
+
*
|
|
251
|
+
* Two visitors need the answer, and neither can get it from the node alone. A
|
|
252
|
+
* function sitting in a prop is a callback, not a component — `inferComponentName`
|
|
253
|
+
* only looks for a name and would happily accept `actions={function renderIt() { … }}`
|
|
254
|
+
* — and an `<html>` sitting in a prop is not the document root.
|
|
255
|
+
*/
|
|
256
|
+
function isInsidePropValue(path) {
|
|
257
|
+
return path.findParent((parent) => parent.isJSXAttribute()) !== null;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
248
260
|
* Inject dynamic locale attribute into <html> elements
|
|
249
261
|
* Transforms: <html> → <html lang={locale}>
|
|
250
262
|
*
|
|
@@ -294,6 +306,7 @@ function addTranslationImports(programPath, state) {
|
|
|
294
306
|
* Handle component function detection and state update
|
|
295
307
|
*/
|
|
296
308
|
function processComponentFunction(path, state) {
|
|
309
|
+
if (isInsidePropValue(path)) return;
|
|
297
310
|
if (!require_utils.isReactComponent(path)) {
|
|
298
311
|
path.skip();
|
|
299
312
|
require_logger.logger.debug(`Skipping non-React component: ${path.node.type}`);
|
|
@@ -332,7 +345,7 @@ const componentVisitors = {
|
|
|
332
345
|
},
|
|
333
346
|
JSXElement(path) {
|
|
334
347
|
translateAttributes(path.node, this.visitorState);
|
|
335
|
-
injectHtmlLangAttribute(path.node, this.visitorState);
|
|
348
|
+
if (!isInsidePropValue(path)) injectHtmlLangAttribute(path.node, this.visitorState);
|
|
336
349
|
if (shouldSkipTranslationForElement(path.node)) {
|
|
337
350
|
path.skip();
|
|
338
351
|
return;
|
|
@@ -240,9 +240,21 @@ function processJSXElement(path, state) {
|
|
|
240
240
|
const entry = createTranslationEntry("content", scope.text, { componentName: component.name }, state.filePath, path.node.loc?.start.line, path.node.loc?.start.column, overrides);
|
|
241
241
|
registerEntry(entry, state, component.name);
|
|
242
242
|
rewriteChildren(path, state, scope, entry.hash);
|
|
243
|
+
if (path.node.type === "JSXElement") path.get("openingElement").traverse(componentVisitors, { visitorState: state });
|
|
243
244
|
path.skip();
|
|
244
245
|
}
|
|
245
246
|
/**
|
|
247
|
+
* Is this node part of the value handed to a JSX attribute?
|
|
248
|
+
*
|
|
249
|
+
* Two visitors need the answer, and neither can get it from the node alone. A
|
|
250
|
+
* function sitting in a prop is a callback, not a component — `inferComponentName`
|
|
251
|
+
* only looks for a name and would happily accept `actions={function renderIt() { … }}`
|
|
252
|
+
* — and an `<html>` sitting in a prop is not the document root.
|
|
253
|
+
*/
|
|
254
|
+
function isInsidePropValue(path) {
|
|
255
|
+
return path.findParent((parent) => parent.isJSXAttribute()) !== null;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
246
258
|
* Inject dynamic locale attribute into <html> elements
|
|
247
259
|
* Transforms: <html> → <html lang={locale}>
|
|
248
260
|
*
|
|
@@ -292,6 +304,7 @@ function addTranslationImports(programPath, state) {
|
|
|
292
304
|
* Handle component function detection and state update
|
|
293
305
|
*/
|
|
294
306
|
function processComponentFunction(path, state) {
|
|
307
|
+
if (isInsidePropValue(path)) return;
|
|
295
308
|
if (!isReactComponent(path)) {
|
|
296
309
|
path.skip();
|
|
297
310
|
logger.debug(`Skipping non-React component: ${path.node.type}`);
|
|
@@ -330,7 +343,7 @@ const componentVisitors = {
|
|
|
330
343
|
},
|
|
331
344
|
JSXElement(path) {
|
|
332
345
|
translateAttributes(path.node, this.visitorState);
|
|
333
|
-
injectHtmlLangAttribute(path.node, this.visitorState);
|
|
346
|
+
if (!isInsidePropValue(path)) injectHtmlLangAttribute(path.node, this.visitorState);
|
|
334
347
|
if (shouldSkipTranslationForElement(path.node)) {
|
|
335
348
|
path.skip();
|
|
336
349
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-file.mjs","names":["variables: string[]","text","componentEntry: ComponentEntry","state: VisitorsInternalState"],"sources":["../../../src/plugin/transform/process-file.ts"],"sourcesContent":["/**\n * Keep mutations to the current node and children. Do not mutate program inserting imports when processing the component.\n * This should be done in the end.\n * The overall idea is that state is used for side effect tracking. When we exit relevant points, we check if we need to make extra changes at this level.\n * e.g. when we transform elements to insert translations, we record their hashes and add the translation hook call when leaving the component.\n */\nimport * as t from \"@babel/types\";\nimport type { NodePath, TraverseOptions } from \"@babel/traverse\";\nimport type { TranslationEntry } from \"../../types\";\nimport { logger } from \"../../utils/logger\";\nimport {\n comstructUnifiedImport,\n constructServerImport,\n constructTranslationCall,\n createTranslationEntry,\n escapeTextForICU,\n hasUseI18nDirective,\n inferComponentName,\n injectServerHook,\n injectUnifiedHook,\n isReactComponent,\n isVoidElement,\n normalizeWhitespace,\n} from \"./utils\";\nimport {\n type MetadataOutputState,\n processNextDynamicMetadata,\n processNextStaticMetadata,\n} from \"./metadata\";\nimport { traverse } from \"./babel-compat\";\nimport { processOverrideAttributes } from \"./parse-override\";\n\ntype ComponentEntry = {\n name: string;\n isAsync: boolean;\n};\n\n/**\n * State shared between all the visitors.\n */\nexport interface VisitorsInternalState {\n needsDirective: boolean;\n filePath: string;\n newEntries: TranslationEntry[];\n /** Stores component encountered up the tree at the current point, to avoid lookups. */\n componentsStack: ComponentEntry[];\n /** Map component names to their translation hashes */\n componentHashes: Map<string, string[]>;\n /** Track metadata functions that need translation */\n /** Track if we need the unified hook import */\n needsUnifiedImport: boolean;\n /** Track if we need the async API import */\n needsAsyncImport: boolean;\n /** Track which components need locale from hook (for <html> lang attribute) */\n componentsNeedingLocale: Set<string>;\n}\n\nfunction updateWithMetadataState(\n state: VisitorsInternalState,\n newState: MetadataOutputState,\n): VisitorsInternalState {\n state.newEntries = [...state.newEntries, ...newState.newEntries];\n state.needsAsyncImport = state.needsAsyncImport || newState.needsAsyncImport;\n return state;\n}\n\nconst SKIP_ATTRIBUTE = \"data-lingo-skip\";\n\n/**\n * Elements whose content should not be translated by default.\n * These are typically code-related or technical elements where translation\n * would break functionality or meaning.\n */\nconst NON_TRANSLATABLE_ELEMENTS = new Set([\n \"code\",\n \"pre\",\n \"script\",\n \"style\",\n \"kbd\",\n \"samp\",\n \"var\",\n]);\n\nconst TRANSLATABLE_ATTRIBUTES = new Set([\n \"title\",\n \"aria-label\",\n \"aria-description\",\n \"alt\",\n \"label\",\n \"description\",\n \"placeholder\",\n \"content\",\n \"subtitle\",\n]);\n\n/**\n * Check if a JSX element should skip translation based on:\n * 1. Element type (code, pre, script, style, etc.)\n * 2. translate=\"no\" attribute (HTML standard)\n * 3. data-lingo-skip attribute\n */\nfunction shouldSkipTranslationForElement(\n element: t.JSXElement | t.JSXFragment,\n): boolean {\n // We always translate fragments\n if (element.type === \"JSXFragment\") {\n return false;\n }\n const openingElement = element.openingElement;\n\n // Check element type\n if (openingElement.name.type === \"JSXIdentifier\") {\n if (NON_TRANSLATABLE_ELEMENTS.has(openingElement.name.name)) {\n return true;\n }\n }\n\n for (const attr of openingElement.attributes) {\n if (attr.type === \"JSXAttribute\" && attr.name.type === \"JSXIdentifier\") {\n // Check for translate=\"no\" (HTML standard)\n if (attr.name.name === \"translate\") {\n if (attr.value?.type === \"StringLiteral\" && attr.value.value === \"no\") {\n return true;\n }\n }\n\n if (attr.name.name === SKIP_ATTRIBUTE) {\n return true;\n }\n }\n }\n\n return false;\n}\n\n// Called even on the element which are not translatable.\nfunction translateAttributes(\n node: t.JSXElement,\n state: VisitorsInternalState,\n): void {\n const openingElement = node.openingElement;\n\n const component = state.componentsStack.at(-1);\n if (!component) return;\n\n for (const attr of openingElement.attributes) {\n if (\n attr.type === \"JSXAttribute\" &&\n attr.name.type === \"JSXIdentifier\" &&\n TRANSLATABLE_ATTRIBUTES.has(attr.name.name) &&\n attr.value?.type === \"StringLiteral\"\n ) {\n const text = normalizeWhitespace(attr.value.value);\n if (text.length == 0) continue;\n\n const entry = createTranslationEntry(\n \"attribute\",\n text,\n {\n attributeName: attr.name.name,\n componentName: component.name,\n },\n state.filePath,\n node.loc?.start.line,\n node.loc?.start.column,\n );\n registerEntry(entry, state, component.name);\n\n attr.value = constructTranslationCall(entry.hash, text);\n }\n }\n}\n\n/**\n * Check if a JSX element has mixed content that needs rich text translation\n * Mixed content = text nodes + expressions + nested JSX elements (excluding void elements)\n */\nfunction hasMixedContent(element: t.JSXElement | t.JSXFragment): boolean {\n const children = element.children;\n if (children.length === 0) return false;\n // 001\n // 221\n // 101\n // States:\n // 0 - no text or translatable nodes\n // 1 - text node\n // 2 - expression or translatable element\n // 3 - interrupted text node\n // 4 - mixed\n //\n let state = 0;\n\n for (const child of children) {\n if (child.type === \"JSXText\") {\n if (child.value.trim().length > 0) {\n switch (state) {\n case 0:\n state = 1;\n break;\n case 1:\n break;\n case 2:\n return true;\n case 3:\n return true;\n }\n }\n // Expressions require a substitution of the placeholder and are usually a part of the text so should be translated in one context\n } else if (child.type === \"JSXExpressionContainer\") {\n switch (state) {\n case 0:\n state = 2;\n break;\n case 1:\n return true;\n case 2:\n break;\n case 3:\n return true;\n }\n } else if (child.type === \"JSXElement\") {\n if (!isVoidElement(child)) {\n switch (state) {\n case 0:\n state = 2;\n break;\n case 1:\n return true;\n case 2:\n break;\n case 3:\n return true;\n }\n } else {\n switch (state) {\n case 0:\n break;\n case 1:\n state = 3;\n break;\n case 2:\n break;\n case 3:\n break;\n }\n }\n }\n }\n return false;\n}\n\n/**\n * Result of serializing JSX children to a translation string\n */\ninterface SerializedJSX {\n /** The serialized string with placeholders, e.g. \"Hello {name}, you have <strong0>{count}</strong0> messages\" */\n text: string;\n /** Variable identifiers extracted from expressions, e.g. [\"name\", \"count\"] */\n variables: string[];\n expressions: Map<string, t.Expression>;\n /** Component mappings for nested elements, e.g. { strong0: <strong>...</strong> } */\n components: Map<string, t.JSXElement>;\n}\n\n/**\n * Serialize JSX children to a translation string with placeholders\n */\nfunction serializeJSXChildren(\n children: Array<\n | t.JSXText\n | t.JSXExpressionContainer\n | t.JSXElement\n | t.JSXSpreadChild\n | t.JSXFragment\n >,\n state: VisitorsInternalState,\n): SerializedJSX {\n let text = \"\";\n const variables: string[] = [];\n const expressions = new Map<string, t.Expression>();\n const components = new Map<string, t.JSXElement>();\n const elementCounts = new Map<string, number>();\n\n for (const child of children) {\n if (child.type === \"JSXText\") {\n // Normalize whitespace within this text node\n let normalized = normalizeWhitespace(child.value);\n\n // If we have accumulated text and this node starts with whitespace,\n // ensure there's a space separator\n if (\n text.length > 0 &&\n child.value.match(/^\\s/) &&\n normalized.length > 0\n ) {\n if (!text.endsWith(\" \")) {\n normalized = ` ${normalized}`;\n }\n }\n\n // If this node ends with whitespace and has content, add trailing space\n if (normalized.length > 0 && child.value.match(/\\s$/)) {\n if (!text.endsWith(\" \")) {\n normalized = `${normalized} `;\n }\n }\n\n text += escapeTextForICU(normalized);\n } else if (child.type === \"JSXExpressionContainer\") {\n // Extract variable name from expression\n const expr = child.expression;\n if (expr.type === \"Identifier\") {\n text += `{${expr.name}}`;\n if (!variables.includes(expr.name)) {\n variables.push(expr.name);\n }\n } else if (expr.type === \"StringLiteral\") {\n // String literal (like {\" \"}) - include the literal text directly\n text += escapeTextForICU(expr.value);\n } else if (expr.type !== \"JSXEmptyExpression\") {\n const name = `expression${expressions.size}`;\n text += `{${name}}`;\n expressions.set(name, expr);\n }\n } else if (child.type === \"JSXElement\") {\n let shouldTranslate = true;\n // Skip void elements (they cannot have children and shouldn't be in rich text)\n if (isVoidElement(child)) {\n // Void elements are ignored in the translation string\n // They will remain in their original position in the JSX tree\n shouldTranslate = false;\n }\n\n // Skip elements that should not be translated (code, pre, etc.)\n // These elements remain in the JSX tree but are not included in translation\n if (shouldSkipTranslationForElement(child)) {\n shouldTranslate = false;\n }\n\n // Get element name\n const openingElement = child.openingElement;\n let elementName = \"\";\n if (openingElement.name.type === \"JSXIdentifier\") {\n elementName = openingElement.name.name;\n } else {\n // TODO (AleksandrSl 02/12/2025): What is this corner case?\n // I thought it may be a fragment, but it seems that fragment is a separate JSXFragment node.\n elementName = \"element\";\n }\n\n // Generate unique tag name with index\n const count = elementCounts.get(elementName) || 0;\n elementCounts.set(elementName, count + 1);\n const tagName = `${elementName}${count}`;\n\n translateAttributes(child, state);\n\n if (shouldTranslate) {\n // Recursively serialize nested content\n const nested = serializeJSXChildren(child.children, state);\n text += `<${tagName}>${nested.text}</${tagName}>`;\n\n // Merge nested variables\n for (const v of nested.variables) {\n if (!variables.includes(v)) {\n variables.push(v);\n }\n }\n\n // Merge nested component mappings with prefixes to avoid conflicts\n for (const [nestedTag, nestedElement] of nested.components) {\n components.set(`${tagName}_${nestedTag}`, nestedElement);\n }\n } else {\n // There is no support for self-closing tags in format js, so we should generate empty ones.\n text += `<${tagName}></${tagName}>`;\n child.extra = {\n ...child.extra,\n shouldTranslate: false,\n };\n }\n\n // Store component mapping\n components.set(tagName, child);\n }\n }\n\n return { text, variables, expressions, components };\n}\n\nfunction transformVoidElement(\n node: t.JSXElement,\n state: VisitorsInternalState,\n) {\n translateAttributes(node, state);\n}\n\ntype TranslationScope =\n | { kind: \"mixed\"; text: string; args: any }\n | { kind: \"text\"; text: string; textNodeIndex: number };\n\nfunction getTranslationScope(\n node: t.JSXElement | t.JSXFragment,\n state: VisitorsInternalState,\n): TranslationScope | null {\n if (hasMixedContent(node)) {\n const serialized = serializeJSXChildren(node.children, state);\n const text = serialized.text.trim();\n if (text.length === 0) return null;\n\n return {\n kind: \"mixed\",\n text,\n args: {\n variables: serialized.variables,\n expressions: serialized.expressions,\n components: serialized.components,\n },\n };\n }\n\n // Non-mixed: allow exactly one meaningful JSXText + optional void elements + whitespace\n const textNodeIndex = node.children.findIndex(\n (child) => child.type === \"JSXText\" && child.value.trim().length > 0,\n );\n if (textNodeIndex === -1) return null;\n\n const allowed = node.children.every(\n (child) =>\n child.type === \"JSXText\" ||\n (child.type === \"JSXElement\" && isVoidElement(child)),\n );\n if (!allowed) return null;\n\n const textNode = node.children[textNodeIndex] as t.JSXText;\n const text = normalizeWhitespace(textNode.value);\n if (text.length === 0) return null;\n\n return { kind: \"text\", text, textNodeIndex };\n}\n\nfunction registerEntry(\n entry: ReturnType<typeof createTranslationEntry>,\n state: VisitorsInternalState,\n componentName: string,\n) {\n state.newEntries.push(entry);\n\n const hashes = state.componentHashes.get(componentName) ?? [];\n hashes.push(entry.hash);\n state.componentHashes.set(componentName, hashes);\n}\n\nfunction rewriteChildren(\n path: NodePath<t.JSXElement | t.JSXFragment>,\n state: VisitorsInternalState,\n translationScope: TranslationScope,\n entryHash: string,\n) {\n if (translationScope.kind === \"mixed\") {\n path.node.children = [\n constructTranslationCall(\n entryHash,\n translationScope.text,\n translationScope.args,\n ),\n ];\n return;\n }\n\n const { textNodeIndex, text } = translationScope;\n\n path.node.children = path.node.children.map((child, index) => {\n if (index === textNodeIndex) {\n return constructTranslationCall(entryHash, text);\n }\n if (child.type === \"JSXElement\") {\n transformVoidElement(child, state);\n }\n return child;\n });\n}\n\nfunction processJSXElement(\n path: NodePath<t.JSXElement | t.JSXFragment>,\n state: VisitorsInternalState,\n): void {\n const component = state.componentsStack.at(-1);\n if (!component) return;\n\n const scope = getTranslationScope(path.node, state);\n if (!scope) return;\n\n const overrides = processOverrideAttributes(path);\n\n const entry = createTranslationEntry(\n \"content\",\n scope.text,\n { componentName: component.name },\n state.filePath,\n path.node.loc?.start.line,\n path.node.loc?.start.column,\n overrides,\n );\n\n registerEntry(entry, state, component.name);\n rewriteChildren(path, state, scope, entry.hash);\n\n path.skip();\n}\n\n/**\n * Inject dynamic locale attribute into <html> elements\n * Transforms: <html> → <html lang={locale}>\n *\n * Only injects if:\n * 1. Element is <html>\n * 2. No existing lang/language attribute\n * 3. We're inside a React component (has locale context)\n */\nfunction injectHtmlLangAttribute(\n node: t.JSXElement,\n state: VisitorsInternalState,\n): void {\n const openingElement = node.openingElement;\n\n if (\n openingElement.name.type !== \"JSXIdentifier\" ||\n openingElement.name.name !== \"html\"\n ) {\n return;\n }\n\n // Check if lang attribute already exists\n const hasLangAttr = openingElement.attributes.some((attr) => {\n return (\n attr.type === \"JSXAttribute\" &&\n attr.name.type === \"JSXIdentifier\" &&\n (attr.name.name === \"lang\" || attr.name.name === \"language\")\n );\n });\n\n if (hasLangAttr) {\n // Already has lang attribute, don't inject\n return;\n }\n\n // Check if we're inside a component (has access to locale context)\n const component = state.componentsStack.at(-1);\n if (!component) {\n // Not inside a component, can't inject locale\n return;\n }\n\n // Inject lang={locale} attribute\n // This creates: <html lang={locale}>\n const langAttr = t.jsxAttribute(\n t.jsxIdentifier(\"lang\"),\n t.jsxExpressionContainer(t.identifier(\"locale\")),\n );\n\n openingElement.attributes.push(langAttr);\n\n logger.debug(\n `Injected locale attribute into <html> element in component: ${component.name}`,\n );\n\n // Mark that this component needs locale destructured from the hook\n state.componentsNeedingLocale.add(component.name);\n}\n\n/**\n * Inject translation hook into a component when it's done processing\n * Called when popping component from stack\n */\nexport function injectTranslationHook(\n path: NodePath<\n t.FunctionDeclaration | t.FunctionExpression | t.ArrowFunctionExpression\n >,\n component: ComponentEntry,\n state: VisitorsInternalState,\n): void {\n const needsLocale = state.componentsNeedingLocale.has(component.name);\n const hashes = state.componentHashes.get(component.name);\n if ((!hashes || hashes.length === 0) && !needsLocale) {\n return; // No translations needed\n }\n\n if (component.isAsync) {\n // Async component uses getServerTranslations\n injectServerHook(path, hashes ?? [], needsLocale);\n state.needsAsyncImport = true;\n } else {\n // Non-async component uses unified hook (useTranslation)\n injectUnifiedHook(path, hashes ?? [], needsLocale);\n state.needsUnifiedImport = true;\n }\n}\n\n/**\n * Add translation imports at the top of the file\n * Called on Program exit after all components have been processed\n */\nfunction addTranslationImports(\n programPath: NodePath<t.Program>,\n state: VisitorsInternalState,\n): void {\n // A file can have both async and non-async components!\n if (state.needsAsyncImport) {\n programPath.node.body.unshift(constructServerImport());\n }\n if (state.needsUnifiedImport) {\n programPath.node.body.unshift(comstructUnifiedImport());\n }\n}\n\n/**\n * Handle component function detection and state update\n */\nfunction processComponentFunction(\n path: NodePath<\n t.FunctionDeclaration | t.FunctionExpression | t.ArrowFunctionExpression\n >,\n state: VisitorsInternalState,\n): void {\n if (!isReactComponent(path)) {\n path.skip();\n logger.debug(`Skipping non-React component: ${path.node.type}`);\n return;\n }\n\n const componentName = inferComponentName(path);\n if (!componentName) {\n path.skip();\n return;\n }\n\n // Store component info for later hook injection\n if (!state.componentHashes.has(componentName)) {\n state.componentHashes.set(componentName, []);\n }\n\n // Push component to stack with async info and path reference\n const componentEntry: ComponentEntry = {\n name: componentName,\n isAsync: path.node.async,\n };\n state.componentsStack.push(componentEntry);\n logger.debug(`Component ${JSON.stringify(componentEntry)} entered`);\n\n path.setData(\"componentName\", componentName);\n path.traverse(componentVisitors, { visitorState: state });\n const component = state.componentsStack.pop();\n if (component) {\n injectTranslationHook(path, component, state);\n }\n // We have already traversed the path's children so the main traverse can skip it.\n path.skip();\n}\n\nconst componentVisitors = {\n // 1. Handle nested components. FunctionDeclaration|FunctionExpression|ArrowFunctionExpression unfortunately doesn't give the correct type signature for the path.\n FunctionDeclaration(path: NodePath<t.FunctionDeclaration>) {\n processComponentFunction(path, this.visitorState);\n },\n ArrowFunctionExpression(path: NodePath<t.ArrowFunctionExpression>) {\n processComponentFunction(path, this.visitorState);\n },\n FunctionExpression(path: NodePath<t.FunctionExpression>) {\n processComponentFunction(path, this.visitorState);\n },\n // 2. Fragments are separate from other JSX elements. Both <> and <Fragment> are the same AST node type.\n JSXFragment(path: NodePath<t.JSXFragment>) {\n // No attributes to translate on the fragment, so we only check if it has mixed content. If it doesn't, go ahead and its children will be checked.\n // We also do not check for translation skip, because fragments are mostly used to make the bare text translatable.\n // But if we want to support <Fragment data-lingo-skip>Text</Fragment> we should do it here.\n processJSXElement(path, this.visitorState);\n },\n\n // Transform JSX elements with mixed content (text + expressions or nested elements)\n JSXElement(path: NodePath<t.JSXElement>) {\n translateAttributes(path.node, this.visitorState);\n\n // Inject locale attribute into <html> elements for Next.js\n injectHtmlLangAttribute(path.node, this.visitorState);\n\n if (shouldSkipTranslationForElement(path.node)) {\n path.skip();\n return;\n }\n processJSXElement(path, this.visitorState);\n },\n} satisfies TraverseOptions<{ visitorState: VisitorsInternalState }>;\n\nconst fileVisitors = {\n // Handle static metadata exports: export const metadata = { ... }\n ExportNamedDeclaration(path: NodePath<t.ExportNamedDeclaration>) {\n // Check if the export is a metadata export and converts it to a function\n const metadataState = processNextStaticMetadata(path, {\n filePath: this.visitorState.filePath,\n });\n\n if (metadataState) {\n updateWithMetadataState(this.visitorState, metadataState);\n }\n },\n\n // All component function types share the same handler\n FunctionDeclaration(path: NodePath<t.FunctionDeclaration>) {\n const metadataState = processNextDynamicMetadata(path, {\n filePath: this.visitorState.filePath,\n });\n if (metadataState) {\n updateWithMetadataState(this.visitorState, metadataState);\n }\n\n // Otherwise, handle as component\n processComponentFunction(path, this.visitorState);\n },\n\n // export const MyComponent = () => {}\n ArrowFunctionExpression(path: NodePath<t.ArrowFunctionExpression>) {\n processComponentFunction(path, this.visitorState);\n },\n\n // All these are considered function expressions\n // const myFunction = function() {\n // return 'hello';\n // };\n //\n // const myFunction2 = function namedFunc() {\n // return 'hello';\n // };\n //\n // setTimeout(function() {\n // console.log('hello');\n // }, 1000);\n // While\n // export default function() {}\n // is not\n FunctionExpression(path: NodePath<t.FunctionExpression>) {\n processComponentFunction(path, this.visitorState);\n },\n} satisfies TraverseOptions<{ visitorState: VisitorsInternalState }>;\n\n/**\n * Create Babel visitors for auto-translation (single-pass transformation)\n */\nconst programVisitor = {\n Program: {\n enter(path: NodePath<t.Program>) {\n // We do the check on the loader level, but since they could be false positive, accepting the files we don't need to process, we do the check here as well.\n if (this.visitorState.needsDirective && !hasUseI18nDirective(path)) {\n path.skip();\n return;\n }\n\n path.traverse(fileVisitors, {\n visitorState: this.visitorState,\n });\n },\n\n exit(path: NodePath<t.Program>) {\n if (\n this.visitorState.needsUnifiedImport ||\n this.visitorState.needsAsyncImport\n ) {\n addTranslationImports(path, this.visitorState);\n }\n },\n },\n} satisfies TraverseOptions<{ visitorState: VisitorsInternalState }>;\n\nexport function processFile(\n ast: t.Node,\n options: { relativeFilePath: string; needsDirective: boolean },\n) {\n const state: VisitorsInternalState = {\n needsDirective: options.needsDirective,\n filePath: options.relativeFilePath,\n newEntries: [],\n componentsStack: [],\n componentHashes: new Map<string, string[]>(),\n needsUnifiedImport: false,\n needsAsyncImport: false,\n componentsNeedingLocale: new Set<string>(),\n };\n\n traverse(ast, programVisitor, undefined, { visitorState: state });\n\n return state.newEntries;\n}\n"],"mappings":";;;;;;;;;;;;;;AAyDA,SAAS,wBACP,OACA,UACuB;AACvB,OAAM,aAAa,CAAC,GAAG,MAAM,YAAY,GAAG,SAAS,WAAW;AAChE,OAAM,mBAAmB,MAAM,oBAAoB,SAAS;AAC5D,QAAO;;AAGT,MAAM,iBAAiB;;;;;;AAOvB,MAAM,4BAA4B,IAAI,IAAI;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,MAAM,0BAA0B,IAAI,IAAI;CACtC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;;;;;;AAQF,SAAS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;;CAE7C;AAED,MAAM,eAAe;CAEnB,uBAAuB,MAA0C;EAE/D,MAAM,gBAAgB,0BAA0B,MAAM,EACpD,UAAU,KAAK,aAAa,UAC7B,CAAC;AAEF,MAAI,cACF,yBAAwB,KAAK,cAAc,cAAc;;CAK7D,oBAAoB,MAAuC;EACzD,MAAM,gBAAgB,2BAA2B,MAAM,EACrD,UAAU,KAAK,aAAa,UAC7B,CAAC;AACF,MAAI,cACF,yBAAwB,KAAK,cAAc,cAAc;AAI3D,2BAAyB,MAAM,KAAK,aAAa;;CAInD,wBAAwB,MAA2C;AACjE,2BAAyB,MAAM,KAAK,aAAa;;CAkBnD,mBAAmB,MAAsC;AACvD,2BAAyB,MAAM,KAAK,aAAa;;CAEpD;;;;AAKD,MAAM,iBAAiB,EACrB,SAAS;CACP,MAAM,MAA2B;AAE/B,MAAI,KAAK,aAAa,kBAAkB,CAAC,oBAAoB,KAAK,EAAE;AAClE,QAAK,MAAM;AACX;;AAGF,OAAK,SAAS,cAAc,EAC1B,cAAc,KAAK,cACpB,CAAC;;CAGJ,KAAK,MAA2B;AAC9B,MACE,KAAK,aAAa,sBAClB,KAAK,aAAa,iBAElB,uBAAsB,MAAM,KAAK,aAAa;;CAGnD,EACF;AAED,SAAgB,YACd,KACA,SACA;CACA,MAAMC,QAA+B;EACnC,gBAAgB,QAAQ;EACxB,UAAU,QAAQ;EAClB,YAAY,EAAE;EACd,iBAAiB,EAAE;EACnB,iCAAiB,IAAI,KAAuB;EAC5C,oBAAoB;EACpB,kBAAkB;EAClB,yCAAyB,IAAI,KAAa;EAC3C;AAED,UAAS,KAAK,gBAAgB,QAAW,EAAE,cAAc,OAAO,CAAC;AAEjE,QAAO,MAAM"}
|
|
1
|
+
{"version":3,"file":"process-file.mjs","names":["variables: string[]","text","componentEntry: ComponentEntry","state: VisitorsInternalState"],"sources":["../../../src/plugin/transform/process-file.ts"],"sourcesContent":["/**\n * Keep mutations to the current node and children. Do not mutate program inserting imports when processing the component.\n * This should be done in the end.\n * The overall idea is that state is used for side effect tracking. When we exit relevant points, we check if we need to make extra changes at this level.\n * e.g. when we transform elements to insert translations, we record their hashes and add the translation hook call when leaving the component.\n */\nimport * as t from \"@babel/types\";\nimport type { NodePath, TraverseOptions } from \"@babel/traverse\";\nimport type { TranslationEntry } from \"../../types\";\nimport { logger } from \"../../utils/logger\";\nimport {\n comstructUnifiedImport,\n constructServerImport,\n constructTranslationCall,\n createTranslationEntry,\n escapeTextForICU,\n hasUseI18nDirective,\n inferComponentName,\n injectServerHook,\n injectUnifiedHook,\n isReactComponent,\n isVoidElement,\n normalizeWhitespace,\n} from \"./utils\";\nimport {\n type MetadataOutputState,\n processNextDynamicMetadata,\n processNextStaticMetadata,\n} from \"./metadata\";\nimport { traverse } from \"./babel-compat\";\nimport { processOverrideAttributes } from \"./parse-override\";\n\ntype ComponentEntry = {\n name: string;\n isAsync: boolean;\n};\n\n/**\n * State shared between all the visitors.\n */\nexport interface VisitorsInternalState {\n needsDirective: boolean;\n filePath: string;\n newEntries: TranslationEntry[];\n /** Stores component encountered up the tree at the current point, to avoid lookups. */\n componentsStack: ComponentEntry[];\n /** Map component names to their translation hashes */\n componentHashes: Map<string, string[]>;\n /** Track metadata functions that need translation */\n /** Track if we need the unified hook import */\n needsUnifiedImport: boolean;\n /** Track if we need the async API import */\n needsAsyncImport: boolean;\n /** Track which components need locale from hook (for <html> lang attribute) */\n componentsNeedingLocale: Set<string>;\n}\n\nfunction updateWithMetadataState(\n state: VisitorsInternalState,\n newState: MetadataOutputState,\n): VisitorsInternalState {\n state.newEntries = [...state.newEntries, ...newState.newEntries];\n state.needsAsyncImport = state.needsAsyncImport || newState.needsAsyncImport;\n return state;\n}\n\nconst SKIP_ATTRIBUTE = \"data-lingo-skip\";\n\n/**\n * Elements whose content should not be translated by default.\n * These are typically code-related or technical elements where translation\n * would break functionality or meaning.\n */\nconst NON_TRANSLATABLE_ELEMENTS = new Set([\n \"code\",\n \"pre\",\n \"script\",\n \"style\",\n \"kbd\",\n \"samp\",\n \"var\",\n]);\n\nconst TRANSLATABLE_ATTRIBUTES = new Set([\n \"title\",\n \"aria-label\",\n \"aria-description\",\n \"alt\",\n \"label\",\n \"description\",\n \"placeholder\",\n \"content\",\n \"subtitle\",\n]);\n\n/**\n * Check if a JSX element should skip translation based on:\n * 1. Element type (code, pre, script, style, etc.)\n * 2. translate=\"no\" attribute (HTML standard)\n * 3. data-lingo-skip attribute\n */\nfunction shouldSkipTranslationForElement(\n element: t.JSXElement | t.JSXFragment,\n): boolean {\n // We always translate fragments\n if (element.type === \"JSXFragment\") {\n return false;\n }\n const openingElement = element.openingElement;\n\n // Check element type\n if (openingElement.name.type === \"JSXIdentifier\") {\n if (NON_TRANSLATABLE_ELEMENTS.has(openingElement.name.name)) {\n return true;\n }\n }\n\n for (const attr of openingElement.attributes) {\n if (attr.type === \"JSXAttribute\" && attr.name.type === \"JSXIdentifier\") {\n // Check for translate=\"no\" (HTML standard)\n if (attr.name.name === \"translate\") {\n if (attr.value?.type === \"StringLiteral\" && attr.value.value === \"no\") {\n return true;\n }\n }\n\n if (attr.name.name === SKIP_ATTRIBUTE) {\n return true;\n }\n }\n }\n\n return false;\n}\n\n// Called even on the element which are not translatable.\nfunction translateAttributes(\n node: t.JSXElement,\n state: VisitorsInternalState,\n): void {\n const openingElement = node.openingElement;\n\n const component = state.componentsStack.at(-1);\n if (!component) return;\n\n for (const attr of openingElement.attributes) {\n if (\n attr.type === \"JSXAttribute\" &&\n attr.name.type === \"JSXIdentifier\" &&\n TRANSLATABLE_ATTRIBUTES.has(attr.name.name) &&\n attr.value?.type === \"StringLiteral\"\n ) {\n const text = normalizeWhitespace(attr.value.value);\n if (text.length == 0) continue;\n\n const entry = createTranslationEntry(\n \"attribute\",\n text,\n {\n attributeName: attr.name.name,\n componentName: component.name,\n },\n state.filePath,\n node.loc?.start.line,\n node.loc?.start.column,\n );\n registerEntry(entry, state, component.name);\n\n attr.value = constructTranslationCall(entry.hash, text);\n }\n }\n}\n\n/**\n * Check if a JSX element has mixed content that needs rich text translation\n * Mixed content = text nodes + expressions + nested JSX elements (excluding void elements)\n */\nfunction hasMixedContent(element: t.JSXElement | t.JSXFragment): boolean {\n const children = element.children;\n if (children.length === 0) return false;\n // 001\n // 221\n // 101\n // States:\n // 0 - no text or translatable nodes\n // 1 - text node\n // 2 - expression or translatable element\n // 3 - interrupted text node\n // 4 - mixed\n //\n let state = 0;\n\n for (const child of children) {\n if (child.type === \"JSXText\") {\n if (child.value.trim().length > 0) {\n switch (state) {\n case 0:\n state = 1;\n break;\n case 1:\n break;\n case 2:\n return true;\n case 3:\n return true;\n }\n }\n // Expressions require a substitution of the placeholder and are usually a part of the text so should be translated in one context\n } else if (child.type === \"JSXExpressionContainer\") {\n switch (state) {\n case 0:\n state = 2;\n break;\n case 1:\n return true;\n case 2:\n break;\n case 3:\n return true;\n }\n } else if (child.type === \"JSXElement\") {\n if (!isVoidElement(child)) {\n switch (state) {\n case 0:\n state = 2;\n break;\n case 1:\n return true;\n case 2:\n break;\n case 3:\n return true;\n }\n } else {\n switch (state) {\n case 0:\n break;\n case 1:\n state = 3;\n break;\n case 2:\n break;\n case 3:\n break;\n }\n }\n }\n }\n return false;\n}\n\n/**\n * Result of serializing JSX children to a translation string\n */\ninterface SerializedJSX {\n /** The serialized string with placeholders, e.g. \"Hello {name}, you have <strong0>{count}</strong0> messages\" */\n text: string;\n /** Variable identifiers extracted from expressions, e.g. [\"name\", \"count\"] */\n variables: string[];\n expressions: Map<string, t.Expression>;\n /** Component mappings for nested elements, e.g. { strong0: <strong>...</strong> } */\n components: Map<string, t.JSXElement>;\n}\n\n/**\n * Serialize JSX children to a translation string with placeholders\n */\nfunction serializeJSXChildren(\n children: Array<\n | t.JSXText\n | t.JSXExpressionContainer\n | t.JSXElement\n | t.JSXSpreadChild\n | t.JSXFragment\n >,\n state: VisitorsInternalState,\n): SerializedJSX {\n let text = \"\";\n const variables: string[] = [];\n const expressions = new Map<string, t.Expression>();\n const components = new Map<string, t.JSXElement>();\n const elementCounts = new Map<string, number>();\n\n for (const child of children) {\n if (child.type === \"JSXText\") {\n // Normalize whitespace within this text node\n let normalized = normalizeWhitespace(child.value);\n\n // If we have accumulated text and this node starts with whitespace,\n // ensure there's a space separator\n if (\n text.length > 0 &&\n child.value.match(/^\\s/) &&\n normalized.length > 0\n ) {\n if (!text.endsWith(\" \")) {\n normalized = ` ${normalized}`;\n }\n }\n\n // If this node ends with whitespace and has content, add trailing space\n if (normalized.length > 0 && child.value.match(/\\s$/)) {\n if (!text.endsWith(\" \")) {\n normalized = `${normalized} `;\n }\n }\n\n text += escapeTextForICU(normalized);\n } else if (child.type === \"JSXExpressionContainer\") {\n // Extract variable name from expression\n const expr = child.expression;\n if (expr.type === \"Identifier\") {\n text += `{${expr.name}}`;\n if (!variables.includes(expr.name)) {\n variables.push(expr.name);\n }\n } else if (expr.type === \"StringLiteral\") {\n // String literal (like {\" \"}) - include the literal text directly\n text += escapeTextForICU(expr.value);\n } else if (expr.type !== \"JSXEmptyExpression\") {\n const name = `expression${expressions.size}`;\n text += `{${name}}`;\n expressions.set(name, expr);\n }\n } else if (child.type === \"JSXElement\") {\n let shouldTranslate = true;\n // Skip void elements (they cannot have children and shouldn't be in rich text)\n if (isVoidElement(child)) {\n // Void elements are ignored in the translation string\n // They will remain in their original position in the JSX tree\n shouldTranslate = false;\n }\n\n // Skip elements that should not be translated (code, pre, etc.)\n // These elements remain in the JSX tree but are not included in translation\n if (shouldSkipTranslationForElement(child)) {\n shouldTranslate = false;\n }\n\n // Get element name\n const openingElement = child.openingElement;\n let elementName = \"\";\n if (openingElement.name.type === \"JSXIdentifier\") {\n elementName = openingElement.name.name;\n } else {\n // TODO (AleksandrSl 02/12/2025): What is this corner case?\n // I thought it may be a fragment, but it seems that fragment is a separate JSXFragment node.\n elementName = \"element\";\n }\n\n // Generate unique tag name with index\n const count = elementCounts.get(elementName) || 0;\n elementCounts.set(elementName, count + 1);\n const tagName = `${elementName}${count}`;\n\n translateAttributes(child, state);\n\n if (shouldTranslate) {\n // Recursively serialize nested content\n const nested = serializeJSXChildren(child.children, state);\n text += `<${tagName}>${nested.text}</${tagName}>`;\n\n // Merge nested variables\n for (const v of nested.variables) {\n if (!variables.includes(v)) {\n variables.push(v);\n }\n }\n\n // Merge nested component mappings with prefixes to avoid conflicts\n for (const [nestedTag, nestedElement] of nested.components) {\n components.set(`${tagName}_${nestedTag}`, nestedElement);\n }\n } else {\n // There is no support for self-closing tags in format js, so we should generate empty ones.\n text += `<${tagName}></${tagName}>`;\n child.extra = {\n ...child.extra,\n shouldTranslate: false,\n };\n }\n\n // Store component mapping\n components.set(tagName, child);\n }\n }\n\n return { text, variables, expressions, components };\n}\n\nfunction transformVoidElement(\n node: t.JSXElement,\n state: VisitorsInternalState,\n) {\n translateAttributes(node, state);\n}\n\ntype TranslationScope =\n | { kind: \"mixed\"; text: string; args: any }\n | { kind: \"text\"; text: string; textNodeIndex: number };\n\nfunction getTranslationScope(\n node: t.JSXElement | t.JSXFragment,\n state: VisitorsInternalState,\n): TranslationScope | null {\n if (hasMixedContent(node)) {\n const serialized = serializeJSXChildren(node.children, state);\n const text = serialized.text.trim();\n if (text.length === 0) return null;\n\n return {\n kind: \"mixed\",\n text,\n args: {\n variables: serialized.variables,\n expressions: serialized.expressions,\n components: serialized.components,\n },\n };\n }\n\n // Non-mixed: allow exactly one meaningful JSXText + optional void elements + whitespace\n const textNodeIndex = node.children.findIndex(\n (child) => child.type === \"JSXText\" && child.value.trim().length > 0,\n );\n if (textNodeIndex === -1) return null;\n\n const allowed = node.children.every(\n (child) =>\n child.type === \"JSXText\" ||\n (child.type === \"JSXElement\" && isVoidElement(child)),\n );\n if (!allowed) return null;\n\n const textNode = node.children[textNodeIndex] as t.JSXText;\n const text = normalizeWhitespace(textNode.value);\n if (text.length === 0) return null;\n\n return { kind: \"text\", text, textNodeIndex };\n}\n\nfunction registerEntry(\n entry: ReturnType<typeof createTranslationEntry>,\n state: VisitorsInternalState,\n componentName: string,\n) {\n state.newEntries.push(entry);\n\n const hashes = state.componentHashes.get(componentName) ?? [];\n hashes.push(entry.hash);\n state.componentHashes.set(componentName, hashes);\n}\n\nfunction rewriteChildren(\n path: NodePath<t.JSXElement | t.JSXFragment>,\n state: VisitorsInternalState,\n translationScope: TranslationScope,\n entryHash: string,\n) {\n if (translationScope.kind === \"mixed\") {\n path.node.children = [\n constructTranslationCall(\n entryHash,\n translationScope.text,\n translationScope.args,\n ),\n ];\n return;\n }\n\n const { textNodeIndex, text } = translationScope;\n\n path.node.children = path.node.children.map((child, index) => {\n if (index === textNodeIndex) {\n return constructTranslationCall(entryHash, text);\n }\n if (child.type === \"JSXElement\") {\n transformVoidElement(child, state);\n }\n return child;\n });\n}\n\nfunction processJSXElement(\n path: NodePath<t.JSXElement | t.JSXFragment>,\n state: VisitorsInternalState,\n): void {\n const component = state.componentsStack.at(-1);\n if (!component) return;\n\n const scope = getTranslationScope(path.node, state);\n if (!scope) return;\n\n const overrides = processOverrideAttributes(path);\n\n const entry = createTranslationEntry(\n \"content\",\n scope.text,\n { componentName: component.name },\n state.filePath,\n path.node.loc?.start.line,\n path.node.loc?.start.column,\n overrides,\n );\n\n registerEntry(entry, state, component.name);\n rewriteChildren(path, state, scope, entry.hash);\n\n // `path.skip()` below prunes the whole subtree, `openingElement` included, so JSX\n // handed to this element through an attribute (`actions={<span>Text</span>}`) would\n // never be visited. Traverse the opening element first. Fragments have no attributes.\n if (path.node.type === \"JSXElement\") {\n path.get(\"openingElement\").traverse(componentVisitors, { visitorState: state });\n }\n\n path.skip();\n}\n\n/**\n * Is this node part of the value handed to a JSX attribute?\n *\n * Two visitors need the answer, and neither can get it from the node alone. A\n * function sitting in a prop is a callback, not a component — `inferComponentName`\n * only looks for a name and would happily accept `actions={function renderIt() { … }}`\n * — and an `<html>` sitting in a prop is not the document root.\n */\nfunction isInsidePropValue(path: NodePath): boolean {\n return path.findParent((parent) => parent.isJSXAttribute()) !== null;\n}\n\n/**\n * Inject dynamic locale attribute into <html> elements\n * Transforms: <html> → <html lang={locale}>\n *\n * Only injects if:\n * 1. Element is <html>\n * 2. No existing lang/language attribute\n * 3. We're inside a React component (has locale context)\n */\nfunction injectHtmlLangAttribute(\n node: t.JSXElement,\n state: VisitorsInternalState,\n): void {\n const openingElement = node.openingElement;\n\n if (\n openingElement.name.type !== \"JSXIdentifier\" ||\n openingElement.name.name !== \"html\"\n ) {\n return;\n }\n\n // Check if lang attribute already exists\n const hasLangAttr = openingElement.attributes.some((attr) => {\n return (\n attr.type === \"JSXAttribute\" &&\n attr.name.type === \"JSXIdentifier\" &&\n (attr.name.name === \"lang\" || attr.name.name === \"language\")\n );\n });\n\n if (hasLangAttr) {\n // Already has lang attribute, don't inject\n return;\n }\n\n // Check if we're inside a component (has access to locale context)\n const component = state.componentsStack.at(-1);\n if (!component) {\n // Not inside a component, can't inject locale\n return;\n }\n\n // Inject lang={locale} attribute\n // This creates: <html lang={locale}>\n const langAttr = t.jsxAttribute(\n t.jsxIdentifier(\"lang\"),\n t.jsxExpressionContainer(t.identifier(\"locale\")),\n );\n\n openingElement.attributes.push(langAttr);\n\n logger.debug(\n `Injected locale attribute into <html> element in component: ${component.name}`,\n );\n\n // Mark that this component needs locale destructured from the hook\n state.componentsNeedingLocale.add(component.name);\n}\n\n/**\n * Inject translation hook into a component when it's done processing\n * Called when popping component from stack\n */\nexport function injectTranslationHook(\n path: NodePath<\n t.FunctionDeclaration | t.FunctionExpression | t.ArrowFunctionExpression\n >,\n component: ComponentEntry,\n state: VisitorsInternalState,\n): void {\n const needsLocale = state.componentsNeedingLocale.has(component.name);\n const hashes = state.componentHashes.get(component.name);\n if ((!hashes || hashes.length === 0) && !needsLocale) {\n return; // No translations needed\n }\n\n if (component.isAsync) {\n // Async component uses getServerTranslations\n injectServerHook(path, hashes ?? [], needsLocale);\n state.needsAsyncImport = true;\n } else {\n // Non-async component uses unified hook (useTranslation)\n injectUnifiedHook(path, hashes ?? [], needsLocale);\n state.needsUnifiedImport = true;\n }\n}\n\n/**\n * Add translation imports at the top of the file\n * Called on Program exit after all components have been processed\n */\nfunction addTranslationImports(\n programPath: NodePath<t.Program>,\n state: VisitorsInternalState,\n): void {\n // A file can have both async and non-async components!\n if (state.needsAsyncImport) {\n programPath.node.body.unshift(constructServerImport());\n }\n if (state.needsUnifiedImport) {\n programPath.node.body.unshift(comstructUnifiedImport());\n }\n}\n\n/**\n * Handle component function detection and state update\n */\nfunction processComponentFunction(\n path: NodePath<\n t.FunctionDeclaration | t.FunctionExpression | t.ArrowFunctionExpression\n >,\n state: VisitorsInternalState,\n): void {\n // A function handed to a prop is a callback, however React-shaped it looks. Return\n // without skipping so its JSX is still reached by the ambient traversal and gets\n // registered against the enclosing component, whose `t` it closes over. Skipping\n // here instead would drop those strings, which is what used to happen to arrow\n // render props.\n if (isInsidePropValue(path)) return;\n\n if (!isReactComponent(path)) {\n path.skip();\n logger.debug(`Skipping non-React component: ${path.node.type}`);\n return;\n }\n\n const componentName = inferComponentName(path);\n if (!componentName) {\n path.skip();\n return;\n }\n\n // Store component info for later hook injection\n if (!state.componentHashes.has(componentName)) {\n state.componentHashes.set(componentName, []);\n }\n\n // Push component to stack with async info and path reference\n const componentEntry: ComponentEntry = {\n name: componentName,\n isAsync: path.node.async,\n };\n state.componentsStack.push(componentEntry);\n logger.debug(`Component ${JSON.stringify(componentEntry)} entered`);\n\n path.setData(\"componentName\", componentName);\n path.traverse(componentVisitors, { visitorState: state });\n const component = state.componentsStack.pop();\n if (component) {\n injectTranslationHook(path, component, state);\n }\n // We have already traversed the path's children so the main traverse can skip it.\n path.skip();\n}\n\nconst componentVisitors = {\n // 1. Handle nested components. FunctionDeclaration|FunctionExpression|ArrowFunctionExpression unfortunately doesn't give the correct type signature for the path.\n FunctionDeclaration(path: NodePath<t.FunctionDeclaration>) {\n processComponentFunction(path, this.visitorState);\n },\n ArrowFunctionExpression(path: NodePath<t.ArrowFunctionExpression>) {\n processComponentFunction(path, this.visitorState);\n },\n FunctionExpression(path: NodePath<t.FunctionExpression>) {\n processComponentFunction(path, this.visitorState);\n },\n // 2. Fragments are separate from other JSX elements. Both <> and <Fragment> are the same AST node type.\n JSXFragment(path: NodePath<t.JSXFragment>) {\n // No attributes to translate on the fragment, so we only check if it has mixed content. If it doesn't, go ahead and its children will be checked.\n // We also do not check for translation skip, because fragments are mostly used to make the bare text translatable.\n // But if we want to support <Fragment data-lingo-skip>Text</Fragment> we should do it here.\n processJSXElement(path, this.visitorState);\n },\n\n // Transform JSX elements with mixed content (text + expressions or nested elements)\n JSXElement(path: NodePath<t.JSXElement>) {\n translateAttributes(path.node, this.visitorState);\n\n // Inject locale attribute into <html> elements for Next.js\n // Only the document root gets the locale. An `<html>` handed to a prop is\n // somebody's example markup, not the page.\n if (!isInsidePropValue(path)) {\n injectHtmlLangAttribute(path.node, this.visitorState);\n }\n\n if (shouldSkipTranslationForElement(path.node)) {\n path.skip();\n return;\n }\n processJSXElement(path, this.visitorState);\n },\n} satisfies TraverseOptions<{ visitorState: VisitorsInternalState }>;\n\nconst fileVisitors = {\n // Handle static metadata exports: export const metadata = { ... }\n ExportNamedDeclaration(path: NodePath<t.ExportNamedDeclaration>) {\n // Check if the export is a metadata export and converts it to a function\n const metadataState = processNextStaticMetadata(path, {\n filePath: this.visitorState.filePath,\n });\n\n if (metadataState) {\n updateWithMetadataState(this.visitorState, metadataState);\n }\n },\n\n // All component function types share the same handler\n FunctionDeclaration(path: NodePath<t.FunctionDeclaration>) {\n const metadataState = processNextDynamicMetadata(path, {\n filePath: this.visitorState.filePath,\n });\n if (metadataState) {\n updateWithMetadataState(this.visitorState, metadataState);\n }\n\n // Otherwise, handle as component\n processComponentFunction(path, this.visitorState);\n },\n\n // export const MyComponent = () => {}\n ArrowFunctionExpression(path: NodePath<t.ArrowFunctionExpression>) {\n processComponentFunction(path, this.visitorState);\n },\n\n // All these are considered function expressions\n // const myFunction = function() {\n // return 'hello';\n // };\n //\n // const myFunction2 = function namedFunc() {\n // return 'hello';\n // };\n //\n // setTimeout(function() {\n // console.log('hello');\n // }, 1000);\n // While\n // export default function() {}\n // is not\n FunctionExpression(path: NodePath<t.FunctionExpression>) {\n processComponentFunction(path, this.visitorState);\n },\n} satisfies TraverseOptions<{ visitorState: VisitorsInternalState }>;\n\n/**\n * Create Babel visitors for auto-translation (single-pass transformation)\n */\nconst programVisitor = {\n Program: {\n enter(path: NodePath<t.Program>) {\n // We do the check on the loader level, but since they could be false positive, accepting the files we don't need to process, we do the check here as well.\n if (this.visitorState.needsDirective && !hasUseI18nDirective(path)) {\n path.skip();\n return;\n }\n\n path.traverse(fileVisitors, {\n visitorState: this.visitorState,\n });\n },\n\n exit(path: NodePath<t.Program>) {\n if (\n this.visitorState.needsUnifiedImport ||\n this.visitorState.needsAsyncImport\n ) {\n addTranslationImports(path, this.visitorState);\n }\n },\n },\n} satisfies TraverseOptions<{ visitorState: VisitorsInternalState }>;\n\nexport function processFile(\n ast: t.Node,\n options: { relativeFilePath: string; needsDirective: boolean },\n) {\n const state: VisitorsInternalState = {\n needsDirective: options.needsDirective,\n filePath: options.relativeFilePath,\n newEntries: [],\n componentsStack: [],\n componentHashes: new Map<string, string[]>(),\n needsUnifiedImport: false,\n needsAsyncImport: false,\n componentsNeedingLocale: new Set<string>(),\n };\n\n traverse(ast, programVisitor, undefined, { visitorState: state });\n\n return state.newEntries;\n}\n"],"mappings":";;;;;;;;;;;;;;AAyDA,SAAS,wBACP,OACA,UACuB;AACvB,OAAM,aAAa,CAAC,GAAG,MAAM,YAAY,GAAG,SAAS,WAAW;AAChE,OAAM,mBAAmB,MAAM,oBAAoB,SAAS;AAC5D,QAAO;;AAGT,MAAM,iBAAiB;;;;;;AAOvB,MAAM,4BAA4B,IAAI,IAAI;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,MAAM,0BAA0B,IAAI,IAAI;CACtC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;;;;;;AAQF,SAAS,gCACP,SACS;AAET,KA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ED,UAAS,KAAK,gBAAgB,QAAW,EAAE,cAAc,OAAO,CAAC;AAEjE,QAAO,MAAM"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { LingoProviderProps } from "../shared/LingoProvider.cjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as react_jsx_runtime1 from "react/jsx-runtime";
|
|
3
3
|
|
|
4
4
|
//#region src/react/server/ServerLingoProvider.d.ts
|
|
5
5
|
declare function LingoProvider({
|
|
6
6
|
initialLocale,
|
|
7
7
|
initialTranslations,
|
|
8
8
|
...rest
|
|
9
|
-
}: LingoProviderProps): Promise<
|
|
9
|
+
}: LingoProviderProps): Promise<react_jsx_runtime1.JSX.Element>;
|
|
10
10
|
//#endregion
|
|
11
11
|
export { LingoProvider };
|
|
12
12
|
//# sourceMappingURL=ServerLingoProvider.d.cts.map
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { LingoProviderProps } from "../shared/LingoProvider.mjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as react_jsx_runtime3 from "react/jsx-runtime";
|
|
3
3
|
|
|
4
4
|
//#region src/react/server/ServerLingoProvider.d.ts
|
|
5
5
|
declare function LingoProvider({
|
|
6
6
|
initialLocale,
|
|
7
7
|
initialTranslations,
|
|
8
8
|
...rest
|
|
9
|
-
}: LingoProviderProps): Promise<
|
|
9
|
+
}: LingoProviderProps): Promise<react_jsx_runtime3.JSX.Element>;
|
|
10
10
|
//#endregion
|
|
11
11
|
export { LingoProvider };
|
|
12
12
|
//# sourceMappingURL=ServerLingoProvider.d.mts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LocaleCode } from "lingo.dev/spec";
|
|
2
|
-
import * as
|
|
2
|
+
import * as react_jsx_runtime3 from "react/jsx-runtime";
|
|
3
3
|
import { PropsWithChildren } from "react";
|
|
4
4
|
|
|
5
5
|
//#region src/react/shared/LingoProvider.d.ts
|
|
@@ -70,7 +70,7 @@ declare function LingoProvider__Dev({
|
|
|
70
70
|
router,
|
|
71
71
|
devWidget,
|
|
72
72
|
children
|
|
73
|
-
}: LingoProviderProps):
|
|
73
|
+
}: LingoProviderProps): react_jsx_runtime3.JSX.Element;
|
|
74
74
|
//#endregion
|
|
75
75
|
export { LingoProvider, LingoProviderProps };
|
|
76
76
|
//# sourceMappingURL=LingoProvider.d.cts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PropsWithChildren } from "react";
|
|
2
|
-
import * as
|
|
2
|
+
import * as react_jsx_runtime1 from "react/jsx-runtime";
|
|
3
3
|
import { LocaleCode } from "lingo.dev/spec";
|
|
4
4
|
|
|
5
5
|
//#region src/react/shared/LingoProvider.d.ts
|
|
@@ -70,7 +70,7 @@ declare function LingoProvider__Dev({
|
|
|
70
70
|
router,
|
|
71
71
|
devWidget,
|
|
72
72
|
children
|
|
73
|
-
}: LingoProviderProps):
|
|
73
|
+
}: LingoProviderProps): react_jsx_runtime1.JSX.Element;
|
|
74
74
|
//#endregion
|
|
75
75
|
export { LingoProvider, LingoProviderProps };
|
|
76
76
|
//# sourceMappingURL=LingoProvider.d.mts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingo.dev/compiler",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.12",
|
|
4
4
|
"description": "Lingo.dev Compiler",
|
|
5
5
|
"private": false,
|
|
6
6
|
"repository": {
|
|
@@ -161,7 +161,7 @@
|
|
|
161
161
|
"posthog-node": "5.14.0",
|
|
162
162
|
"lmdb": "3.2.6",
|
|
163
163
|
"ws": "8.21.0",
|
|
164
|
-
"lingo.dev": "^0.138.
|
|
164
|
+
"lingo.dev": "^0.138.6"
|
|
165
165
|
},
|
|
166
166
|
"peerDependencies": {
|
|
167
167
|
"next": "^15.0.0 || ^16.0.4",
|