@lingo.dev/_compiler 0.2.1 → 0.2.3

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.
Files changed (3) hide show
  1. package/build/index.cjs +177 -170
  2. package/build/index.mjs +187 -180
  3. package/package.json +1 -1
package/build/index.cjs CHANGED
@@ -4,7 +4,7 @@ var _unplugin = require('unplugin');
4
4
  // package.json
5
5
  var package_default = {
6
6
  name: "@lingo.dev/_compiler",
7
- version: "0.2.1",
7
+ version: "0.2.3",
8
8
  description: "Lingo.dev Compiler",
9
9
  private: false,
10
10
  publishConfig: {
@@ -117,7 +117,7 @@ var defaultParams = {
117
117
 
118
118
  // src/utils/index.ts
119
119
  var _traverse = require('@babel/traverse'); var _traverse2 = _interopRequireDefault(_traverse);
120
- var _types = require('@babel/types'); var t2 = _interopRequireWildcard(_types); var t = _interopRequireWildcard(_types); var t4 = _interopRequireWildcard(_types); var t3 = _interopRequireWildcard(_types); var t5 = _interopRequireWildcard(_types); var t8 = _interopRequireWildcard(_types); var t6 = _interopRequireWildcard(_types); var t7 = _interopRequireWildcard(_types); var t10 = _interopRequireWildcard(_types); var t9 = _interopRequireWildcard(_types); var t11 = _interopRequireWildcard(_types); var t12 = _interopRequireWildcard(_types); var t13 = _interopRequireWildcard(_types); var t14 = _interopRequireWildcard(_types); var t15 = _interopRequireWildcard(_types); var t16 = _interopRequireWildcard(_types); var t17 = _interopRequireWildcard(_types); var t21 = _interopRequireWildcard(_types); var t18 = _interopRequireWildcard(_types); var t19 = _interopRequireWildcard(_types); var t20 = _interopRequireWildcard(_types); var t22 = _interopRequireWildcard(_types); var t23 = _interopRequireWildcard(_types);
120
+ var _types = require('@babel/types'); var t2 = _interopRequireWildcard(_types); var t = _interopRequireWildcard(_types); var t4 = _interopRequireWildcard(_types); var t3 = _interopRequireWildcard(_types); var t5 = _interopRequireWildcard(_types); var t8 = _interopRequireWildcard(_types); var t6 = _interopRequireWildcard(_types); var t7 = _interopRequireWildcard(_types); var t10 = _interopRequireWildcard(_types); var t9 = _interopRequireWildcard(_types); var t11 = _interopRequireWildcard(_types); var t13 = _interopRequireWildcard(_types); var t12 = _interopRequireWildcard(_types); var t14 = _interopRequireWildcard(_types); var t15 = _interopRequireWildcard(_types); var t16 = _interopRequireWildcard(_types); var t17 = _interopRequireWildcard(_types); var t18 = _interopRequireWildcard(_types); var t22 = _interopRequireWildcard(_types); var t19 = _interopRequireWildcard(_types); var t20 = _interopRequireWildcard(_types); var t21 = _interopRequireWildcard(_types); var t23 = _interopRequireWildcard(_types); var t24 = _interopRequireWildcard(_types);
121
121
 
122
122
  // src/utils/jsx-attribute.ts
123
123
 
@@ -1767,6 +1767,38 @@ function collectCallExpressions(path7, importNames, result, functionName) {
1767
1767
 
1768
1768
  // src/rsc-dictionary-loader.ts
1769
1769
 
1770
+
1771
+ // src/_utils.ts
1772
+
1773
+ var getDictionaryPath = (params) => {
1774
+ const absolute = path.default.resolve(
1775
+ params.sourceRoot,
1776
+ params.lingoDir,
1777
+ LCP_DICTIONARY_FILE_NAME
1778
+ );
1779
+ const rel = path.default.relative(params.relativeFilePath, absolute);
1780
+ return rel.split(path.default.sep).join(path.default.posix.sep);
1781
+ };
1782
+
1783
+ // src/utils/create-locale-import-map.ts
1784
+
1785
+ function createLocaleImportMap(allLocales, dictionaryPath) {
1786
+ return t12.objectExpression(
1787
+ allLocales.map(
1788
+ (locale) => t12.objectProperty(
1789
+ t12.stringLiteral(locale),
1790
+ t12.arrowFunctionExpression(
1791
+ [],
1792
+ t12.callExpression(t12.identifier("import"), [
1793
+ t12.stringLiteral(`${dictionaryPath}?locale=${locale}`)
1794
+ ])
1795
+ )
1796
+ )
1797
+ )
1798
+ );
1799
+ }
1800
+
1801
+ // src/rsc-dictionary-loader.ts
1770
1802
  var rscDictionaryLoaderMutation = createCodeMutation((payload) => {
1771
1803
  const mode = getModuleExecutionMode(payload.ast, payload.params.rsc);
1772
1804
  if (mode === "client") {
@@ -1784,24 +1816,15 @@ var rscDictionaryLoaderMutation = createCodeMutation((payload) => {
1784
1816
  moduleName: "lingo.dev/react/rsc" /* ReactRSC */,
1785
1817
  exportedName: "loadDictionary_internal"
1786
1818
  });
1787
- if (t12.isIdentifier(invokation.callee)) {
1819
+ if (t13.isIdentifier(invokation.callee)) {
1788
1820
  invokation.callee.name = internalDictionaryLoader.importedName;
1789
1821
  }
1790
- const localeImportMap = t12.objectExpression(
1791
- allLocales.map(
1792
- (locale) => t12.objectProperty(
1793
- t12.identifier(locale),
1794
- t12.arrowFunctionExpression(
1795
- [],
1796
- t12.callExpression(t12.identifier("import"), [
1797
- t12.stringLiteral(
1798
- `@/${payload.params.lingoDir}/${LCP_DICTIONARY_FILE_NAME}?locale=${locale}`
1799
- )
1800
- ])
1801
- )
1802
- )
1803
- )
1804
- );
1822
+ const dictionaryPath = getDictionaryPath({
1823
+ sourceRoot: payload.params.sourceRoot,
1824
+ lingoDir: payload.params.lingoDir,
1825
+ relativeFilePath: payload.relativeFilePath
1826
+ });
1827
+ const localeImportMap = createLocaleImportMap(allLocales, dictionaryPath);
1805
1828
  invokation.arguments.push(localeImportMap);
1806
1829
  }
1807
1830
  return payload;
@@ -1827,24 +1850,15 @@ var reactRouterDictionaryLoaderMutation = createCodeMutation(
1827
1850
  moduleName: "lingo.dev/react/react-router" /* ReactRouter */,
1828
1851
  exportedName: "loadDictionary_internal"
1829
1852
  });
1830
- if (t13.isIdentifier(invokation.callee)) {
1853
+ if (t14.isIdentifier(invokation.callee)) {
1831
1854
  invokation.callee.name = internalDictionaryLoader.importedName;
1832
1855
  }
1833
- const localeImportMap = t13.objectExpression(
1834
- allLocales.map(
1835
- (locale) => t13.objectProperty(
1836
- t13.identifier(locale),
1837
- t13.arrowFunctionExpression(
1838
- [],
1839
- t13.callExpression(t13.identifier("import"), [
1840
- t13.stringLiteral(
1841
- `~/${payload.params.lingoDir}/${LCP_DICTIONARY_FILE_NAME}?locale=${locale}`
1842
- )
1843
- ])
1844
- )
1845
- )
1846
- )
1847
- );
1856
+ const dictionaryPath = getDictionaryPath({
1857
+ sourceRoot: payload.params.sourceRoot,
1858
+ lingoDir: payload.params.lingoDir,
1859
+ relativeFilePath: payload.relativeFilePath
1860
+ });
1861
+ const localeImportMap = createLocaleImportMap(allLocales, dictionaryPath);
1848
1862
  invokation.arguments.push(localeImportMap);
1849
1863
  }
1850
1864
  return payload;
@@ -1862,7 +1876,7 @@ function jsxFragmentMutation(payload) {
1862
1876
  ImportDeclaration(path7) {
1863
1877
  if (path7.node.source.value !== "react") return;
1864
1878
  for (const specifier of path7.node.specifiers) {
1865
- if (t14.isImportSpecifier(specifier) && t14.isIdentifier(specifier.imported) && specifier.imported.name === "Fragment") {
1879
+ if (t15.isImportSpecifier(specifier) && t15.isIdentifier(specifier.imported) && specifier.imported.name === "Fragment") {
1866
1880
  fragmentImportName = specifier.local.name;
1867
1881
  path7.stop();
1868
1882
  }
@@ -1879,9 +1893,9 @@ function jsxFragmentMutation(payload) {
1879
1893
  });
1880
1894
  fragmentImportName = result.importedName;
1881
1895
  }
1882
- const fragmentElement = t14.jsxElement(
1883
- t14.jsxOpeningElement(t14.jsxIdentifier(fragmentImportName), [], false),
1884
- t14.jsxClosingElement(t14.jsxIdentifier(fragmentImportName)),
1896
+ const fragmentElement = t15.jsxElement(
1897
+ t15.jsxOpeningElement(t15.jsxIdentifier(fragmentImportName), [], false),
1898
+ t15.jsxClosingElement(t15.jsxIdentifier(fragmentImportName)),
1885
1899
  path7.node.children,
1886
1900
  false
1887
1901
  );
@@ -1904,11 +1918,11 @@ var jsxHtmlLangMutation = createCodeMutation((payload) => {
1904
1918
  moduleName: packagePath,
1905
1919
  exportedName: "LingoHtmlComponent"
1906
1920
  });
1907
- path7.node.openingElement.name = t15.jsxIdentifier(
1921
+ path7.node.openingElement.name = t16.jsxIdentifier(
1908
1922
  lingoHtmlComponentImport.importedName
1909
1923
  );
1910
1924
  if (path7.node.closingElement) {
1911
- path7.node.closingElement.name = t15.jsxIdentifier(
1925
+ path7.node.closingElement.name = t16.jsxIdentifier(
1912
1926
  lingoHtmlComponentImport.importedName
1913
1927
  );
1914
1928
  }
@@ -1951,18 +1965,22 @@ function jsxAttributeScopesExportMutation(payload) {
1951
1965
  for (const [scope, attributes] of attributeScopes) {
1952
1966
  for (const attributeDefinition of attributes) {
1953
1967
  const [attribute, scopeKey] = attributeDefinition.split(":");
1954
- lcp.resetScope(payload.fileKey, scopeKey);
1968
+ lcp.resetScope(payload.relativeFilePath, scopeKey);
1955
1969
  const attributeValue = getJsxAttributeValue(scope, attribute);
1956
1970
  if (!attributeValue) {
1957
1971
  continue;
1958
1972
  }
1959
- lcp.setScopeType(payload.fileKey, scopeKey, "attribute");
1973
+ lcp.setScopeType(payload.relativeFilePath, scopeKey, "attribute");
1960
1974
  const hash = getJsxAttributeValueHash(String(attributeValue));
1961
- lcp.setScopeHash(payload.fileKey, scopeKey, hash);
1962
- lcp.setScopeContext(payload.fileKey, scopeKey, "");
1963
- lcp.setScopeSkip(payload.fileKey, scopeKey, false);
1964
- lcp.setScopeOverrides(payload.fileKey, scopeKey, {});
1965
- lcp.setScopeContent(payload.fileKey, scopeKey, String(attributeValue));
1975
+ lcp.setScopeHash(payload.relativeFilePath, scopeKey, hash);
1976
+ lcp.setScopeContext(payload.relativeFilePath, scopeKey, "");
1977
+ lcp.setScopeSkip(payload.relativeFilePath, scopeKey, false);
1978
+ lcp.setScopeOverrides(payload.relativeFilePath, scopeKey, {});
1979
+ lcp.setScopeContent(
1980
+ payload.relativeFilePath,
1981
+ scopeKey,
1982
+ String(attributeValue)
1983
+ );
1966
1984
  }
1967
1985
  }
1968
1986
  lcp.save();
@@ -1995,39 +2013,39 @@ function extractJsxContent(nodePath, replaceWhitespacePlaceholders = true) {
1995
2013
  return;
1996
2014
  }
1997
2015
  const expr = path7.node.expression;
1998
- if (t16.isCallExpression(expr)) {
2016
+ if (t17.isCallExpression(expr)) {
1999
2017
  let key = "";
2000
- if (t16.isIdentifier(expr.callee)) {
2018
+ if (t17.isIdentifier(expr.callee)) {
2001
2019
  key = `${expr.callee.name}`;
2002
- } else if (t16.isMemberExpression(expr.callee)) {
2020
+ } else if (t17.isMemberExpression(expr.callee)) {
2003
2021
  let firstCallee = expr.callee;
2004
- while (t16.isMemberExpression(firstCallee) && t16.isCallExpression(firstCallee.object)) {
2022
+ while (t17.isMemberExpression(firstCallee) && t17.isCallExpression(firstCallee.object)) {
2005
2023
  firstCallee = firstCallee.object.callee;
2006
2024
  }
2007
2025
  let current = firstCallee;
2008
2026
  const parts = [];
2009
- while (t16.isMemberExpression(current)) {
2010
- if (t16.isIdentifier(current.property)) {
2027
+ while (t17.isMemberExpression(current)) {
2028
+ if (t17.isIdentifier(current.property)) {
2011
2029
  parts.unshift(current.property.name);
2012
2030
  }
2013
2031
  current = current.object;
2014
2032
  }
2015
- if (t16.isIdentifier(current)) {
2033
+ if (t17.isIdentifier(current)) {
2016
2034
  parts.unshift(current.name);
2017
2035
  }
2018
- if (t16.isMemberExpression(firstCallee) && t16.isNewExpression(firstCallee.object) && t16.isIdentifier(firstCallee.object.callee)) {
2036
+ if (t17.isMemberExpression(firstCallee) && t17.isNewExpression(firstCallee.object) && t17.isIdentifier(firstCallee.object.callee)) {
2019
2037
  parts.unshift(firstCallee.object.callee.name);
2020
2038
  }
2021
2039
  key = parts.join(".");
2022
2040
  }
2023
2041
  chunks.push(`<function:${key}/>`);
2024
- } else if (t16.isIdentifier(expr)) {
2042
+ } else if (t17.isIdentifier(expr)) {
2025
2043
  chunks.push(`{${expr.name}}`);
2026
- } else if (t16.isMemberExpression(expr)) {
2044
+ } else if (t17.isMemberExpression(expr)) {
2027
2045
  let current = expr;
2028
2046
  const parts = [];
2029
- while (t16.isMemberExpression(current)) {
2030
- if (t16.isIdentifier(current.property)) {
2047
+ while (t17.isMemberExpression(current)) {
2048
+ if (t17.isIdentifier(current.property)) {
2031
2049
  if (current.computed) {
2032
2050
  parts.unshift(`[${current.property.name}]`);
2033
2051
  } else {
@@ -2036,7 +2054,7 @@ function extractJsxContent(nodePath, replaceWhitespacePlaceholders = true) {
2036
2054
  }
2037
2055
  current = current.object;
2038
2056
  }
2039
- if (t16.isIdentifier(current)) {
2057
+ if (t17.isIdentifier(current)) {
2040
2058
  parts.unshift(current.name);
2041
2059
  chunks.push(`{${parts.join(".").replaceAll(".[", "[")}}`);
2042
2060
  }
@@ -2057,12 +2075,12 @@ function extractJsxContent(nodePath, replaceWhitespacePlaceholders = true) {
2057
2075
  }
2058
2076
  var compilerProps = ["data-jsx-attribute-scope", "data-jsx-scope"];
2059
2077
  function isExpression2(nodePath) {
2060
- const isCompilerExpression = !_lodash2.default.isArray(nodePath.container) && t16.isJSXAttribute(nodePath.container) && t16.isJSXIdentifier(nodePath.container.name) && compilerProps.includes(nodePath.container.name.name);
2061
- return !isCompilerExpression && !t16.isJSXEmptyExpression(nodePath.node.expression);
2078
+ const isCompilerExpression = !_lodash2.default.isArray(nodePath.container) && t17.isJSXAttribute(nodePath.container) && t17.isJSXIdentifier(nodePath.container.name) && compilerProps.includes(nodePath.container.name.name);
2079
+ return !isCompilerExpression && !t17.isJSXEmptyExpression(nodePath.node.expression);
2062
2080
  }
2063
2081
  function isWhitespace(nodePath) {
2064
2082
  const expr = nodePath.node.expression;
2065
- return t16.isStringLiteral(expr) && expr.value === " ";
2083
+ return t17.isStringLiteral(expr) && expr.value === " ";
2066
2084
  }
2067
2085
  function normalizeJsxWhitespace(input) {
2068
2086
  const lines = input.split("\n");
@@ -2093,21 +2111,29 @@ function jsxScopesExportMutation(payload) {
2093
2111
  });
2094
2112
  for (const scope of scopes) {
2095
2113
  const scopeKey = getAstKey(scope);
2096
- lcp.resetScope(payload.fileKey, scopeKey);
2097
- lcp.setScopeType(payload.fileKey, scopeKey, "element");
2114
+ lcp.resetScope(payload.relativeFilePath, scopeKey);
2115
+ lcp.setScopeType(payload.relativeFilePath, scopeKey, "element");
2098
2116
  const hash = getJsxElementHash(scope);
2099
- lcp.setScopeHash(payload.fileKey, scopeKey, hash);
2117
+ lcp.setScopeHash(payload.relativeFilePath, scopeKey, hash);
2100
2118
  const context = getJsxAttributeValue(scope, "data-lingo-context");
2101
- lcp.setScopeContext(payload.fileKey, scopeKey, String(context || ""));
2119
+ lcp.setScopeContext(
2120
+ payload.relativeFilePath,
2121
+ scopeKey,
2122
+ String(context || "")
2123
+ );
2102
2124
  const skip = getJsxAttributeValue(scope, "data-lingo-skip");
2103
- lcp.setScopeSkip(payload.fileKey, scopeKey, Boolean(skip || false));
2125
+ lcp.setScopeSkip(
2126
+ payload.relativeFilePath,
2127
+ scopeKey,
2128
+ Boolean(skip || false)
2129
+ );
2104
2130
  const attributesMap = getJsxAttributesMap(scope);
2105
2131
  const overrides = _lodash2.default.chain(attributesMap).entries().filter(
2106
2132
  ([attributeKey]) => attributeKey.startsWith("data-lingo-override-")
2107
2133
  ).map(([k, v]) => [k.split("data-lingo-override-")[1], v]).filter(([k]) => !!k).filter(([, v]) => !!v).fromPairs().value();
2108
- lcp.setScopeOverrides(payload.fileKey, scopeKey, overrides);
2134
+ lcp.setScopeOverrides(payload.relativeFilePath, scopeKey, overrides);
2109
2135
  const content = extractJsxContent(scope);
2110
- lcp.setScopeContent(payload.fileKey, scopeKey, content);
2136
+ lcp.setScopeContent(payload.relativeFilePath, scopeKey, content);
2111
2137
  }
2112
2138
  lcp.save();
2113
2139
  return payload;
@@ -2129,34 +2155,34 @@ var lingoJsxAttributeScopeInjectMutation = createCodeMutation(
2129
2155
  if (!originalJsxElementName) {
2130
2156
  continue;
2131
2157
  }
2132
- jsxScope.node.openingElement.name = t17.jsxIdentifier(
2158
+ jsxScope.node.openingElement.name = t18.jsxIdentifier(
2133
2159
  lingoComponentImport.importedName
2134
2160
  );
2135
2161
  if (jsxScope.node.closingElement) {
2136
- jsxScope.node.closingElement.name = t17.jsxIdentifier(
2162
+ jsxScope.node.closingElement.name = t18.jsxIdentifier(
2137
2163
  lingoComponentImport.importedName
2138
2164
  );
2139
2165
  }
2140
- const as = /^[A-Z]/.test(originalJsxElementName) ? t17.jsxExpressionContainer(t17.identifier(originalJsxElementName)) : t17.stringLiteral(originalJsxElementName);
2166
+ const as = /^[A-Z]/.test(originalJsxElementName) ? t18.jsxExpressionContainer(t18.identifier(originalJsxElementName)) : t18.stringLiteral(originalJsxElementName);
2141
2167
  jsxScope.node.openingElement.attributes.push(
2142
- t17.jsxAttribute(t17.jsxIdentifier("$attrAs"), as)
2168
+ t18.jsxAttribute(t18.jsxIdentifier("$attrAs"), as)
2143
2169
  );
2144
2170
  jsxScope.node.openingElement.attributes.push(
2145
- t17.jsxAttribute(
2146
- t17.jsxIdentifier("$fileKey"),
2147
- t17.stringLiteral(payload.fileKey)
2171
+ t18.jsxAttribute(
2172
+ t18.jsxIdentifier("$fileKey"),
2173
+ t18.stringLiteral(payload.relativeFilePath)
2148
2174
  )
2149
2175
  );
2150
2176
  jsxScope.node.openingElement.attributes.push(
2151
- t17.jsxAttribute(
2152
- t17.jsxIdentifier("$attributes"),
2153
- t17.jsxExpressionContainer(
2154
- t17.objectExpression(
2177
+ t18.jsxAttribute(
2178
+ t18.jsxIdentifier("$attributes"),
2179
+ t18.jsxExpressionContainer(
2180
+ t18.objectExpression(
2155
2181
  attributes.map((attributeDefinition) => {
2156
2182
  const [attribute, key = ""] = attributeDefinition.split(":");
2157
- return t17.objectProperty(
2158
- t17.stringLiteral(attribute),
2159
- t17.stringLiteral(key)
2183
+ return t18.objectProperty(
2184
+ t18.stringLiteral(attribute),
2185
+ t18.stringLiteral(key)
2160
2186
  );
2161
2187
  })
2162
2188
  )
@@ -2169,14 +2195,14 @@ var lingoJsxAttributeScopeInjectMutation = createCodeMutation(
2169
2195
  moduleName: "lingo.dev/react/rsc" /* ReactRSC */
2170
2196
  });
2171
2197
  jsxScope.node.openingElement.attributes.push(
2172
- t17.jsxAttribute(
2173
- t17.jsxIdentifier("$loadDictionary"),
2174
- t17.jsxExpressionContainer(
2175
- t17.arrowFunctionExpression(
2176
- [t17.identifier("locale")],
2177
- t17.callExpression(
2178
- t17.identifier(loadDictionaryImport.importedName),
2179
- [t17.identifier("locale")]
2198
+ t18.jsxAttribute(
2199
+ t18.jsxIdentifier("$loadDictionary"),
2200
+ t18.jsxExpressionContainer(
2201
+ t18.arrowFunctionExpression(
2202
+ [t18.identifier("locale")],
2203
+ t18.callExpression(
2204
+ t18.identifier(loadDictionaryImport.importedName),
2205
+ [t18.identifier("locale")]
2180
2206
  )
2181
2207
  )
2182
2208
  )
@@ -2200,13 +2226,13 @@ var getJsxVariables = (nodePath) => {
2200
2226
  path7.skip();
2201
2227
  },
2202
2228
  JSXExpressionContainer(path7) {
2203
- if (t18.isIdentifier(path7.node.expression)) {
2229
+ if (t19.isIdentifier(path7.node.expression)) {
2204
2230
  variables.add(path7.node.expression.name);
2205
- } else if (t18.isMemberExpression(path7.node.expression)) {
2231
+ } else if (t19.isMemberExpression(path7.node.expression)) {
2206
2232
  let current = path7.node.expression;
2207
2233
  const parts = [];
2208
- while (t18.isMemberExpression(current)) {
2209
- if (t18.isIdentifier(current.property)) {
2234
+ while (t19.isMemberExpression(current)) {
2235
+ if (t19.isIdentifier(current.property)) {
2210
2236
  if (current.computed) {
2211
2237
  parts.unshift(`[${current.property.name}]`);
2212
2238
  } else {
@@ -2215,7 +2241,7 @@ var getJsxVariables = (nodePath) => {
2215
2241
  }
2216
2242
  current = current.object;
2217
2243
  }
2218
- if (t18.isIdentifier(current)) {
2244
+ if (t19.isIdentifier(current)) {
2219
2245
  parts.unshift(current.name);
2220
2246
  variables.add(parts.join(".").replaceAll(".[", "["));
2221
2247
  }
@@ -2224,9 +2250,9 @@ var getJsxVariables = (nodePath) => {
2224
2250
  }
2225
2251
  });
2226
2252
  const properties = Array.from(variables).map(
2227
- (name) => t18.objectProperty(t18.stringLiteral(name), t18.identifier(name))
2253
+ (name) => t19.objectProperty(t19.stringLiteral(name), t19.identifier(name))
2228
2254
  );
2229
- const result = t18.objectExpression(properties);
2255
+ const result = t19.objectExpression(properties);
2230
2256
  return result;
2231
2257
  };
2232
2258
 
@@ -2240,27 +2266,27 @@ var getJsxFunctions = (nodePath) => {
2240
2266
  path7.skip();
2241
2267
  },
2242
2268
  JSXExpressionContainer(path7) {
2243
- if (t19.isCallExpression(path7.node.expression)) {
2269
+ if (t20.isCallExpression(path7.node.expression)) {
2244
2270
  let key = "";
2245
- if (t19.isIdentifier(path7.node.expression.callee)) {
2271
+ if (t20.isIdentifier(path7.node.expression.callee)) {
2246
2272
  key = `${path7.node.expression.callee.name}`;
2247
- } else if (t19.isMemberExpression(path7.node.expression.callee)) {
2273
+ } else if (t20.isMemberExpression(path7.node.expression.callee)) {
2248
2274
  let firstCallee = path7.node.expression.callee;
2249
- while (t19.isMemberExpression(firstCallee) && t19.isCallExpression(firstCallee.object)) {
2275
+ while (t20.isMemberExpression(firstCallee) && t20.isCallExpression(firstCallee.object)) {
2250
2276
  firstCallee = firstCallee.object.callee;
2251
2277
  }
2252
2278
  let current = firstCallee;
2253
2279
  const parts = [];
2254
- while (t19.isMemberExpression(current)) {
2255
- if (t19.isIdentifier(current.property)) {
2280
+ while (t20.isMemberExpression(current)) {
2281
+ if (t20.isIdentifier(current.property)) {
2256
2282
  parts.unshift(current.property.name);
2257
2283
  }
2258
2284
  current = current.object;
2259
2285
  }
2260
- if (t19.isIdentifier(current)) {
2286
+ if (t20.isIdentifier(current)) {
2261
2287
  parts.unshift(current.name);
2262
2288
  }
2263
- if (t19.isMemberExpression(firstCallee) && t19.isNewExpression(firstCallee.object) && t19.isIdentifier(firstCallee.object.callee)) {
2289
+ if (t20.isMemberExpression(firstCallee) && t20.isNewExpression(firstCallee.object) && t20.isIdentifier(firstCallee.object.callee)) {
2264
2290
  parts.unshift(firstCallee.object.callee.name);
2265
2291
  }
2266
2292
  key = parts.join(".");
@@ -2273,9 +2299,9 @@ var getJsxFunctions = (nodePath) => {
2273
2299
  }
2274
2300
  });
2275
2301
  const properties = Array.from(functions.entries()).map(
2276
- ([name, callExpr]) => t19.objectProperty(t19.stringLiteral(name), t19.arrayExpression(callExpr))
2302
+ ([name, callExpr]) => t20.objectProperty(t20.stringLiteral(name), t20.arrayExpression(callExpr))
2277
2303
  );
2278
- return t19.objectExpression(properties);
2304
+ return t20.objectExpression(properties);
2279
2305
  };
2280
2306
 
2281
2307
  // src/utils/jsx-expressions.ts
@@ -2288,13 +2314,13 @@ var getJsxExpressions = (nodePath) => {
2288
2314
  },
2289
2315
  JSXExpressionContainer(path7) {
2290
2316
  const expr = path7.node.expression;
2291
- if (!t20.isJSXEmptyExpression(expr) && !t20.isIdentifier(expr) && !t20.isMemberExpression(expr) && !t20.isCallExpression(expr) && !(t20.isStringLiteral(expr) && expr.value === " ")) {
2317
+ if (!t21.isJSXEmptyExpression(expr) && !t21.isIdentifier(expr) && !t21.isMemberExpression(expr) && !t21.isCallExpression(expr) && !(t21.isStringLiteral(expr) && expr.value === " ")) {
2292
2318
  expressions.push(expr);
2293
2319
  }
2294
2320
  path7.skip();
2295
2321
  }
2296
2322
  });
2297
- return t20.arrayExpression(expressions);
2323
+ return t21.arrayExpression(expressions);
2298
2324
  };
2299
2325
 
2300
2326
  // src/jsx-scope-inject.ts
@@ -2316,53 +2342,53 @@ var lingoJsxScopeInjectMutation = createCodeMutation((payload) => {
2316
2342
  continue;
2317
2343
  }
2318
2344
  const originalAttributes = jsxScope.node.openingElement.attributes.slice();
2319
- const as = /^[A-Z]/.test(originalJsxElementName) ? t21.jsxExpressionContainer(t21.identifier(originalJsxElementName)) : t21.stringLiteral(originalJsxElementName);
2320
- originalAttributes.push(t21.jsxAttribute(t21.jsxIdentifier("$as"), as));
2345
+ const as = /^[A-Z]/.test(originalJsxElementName) ? t22.jsxExpressionContainer(t22.identifier(originalJsxElementName)) : t22.stringLiteral(originalJsxElementName);
2346
+ originalAttributes.push(t22.jsxAttribute(t22.jsxIdentifier("$as"), as));
2321
2347
  originalAttributes.push(
2322
- t21.jsxAttribute(
2323
- t21.jsxIdentifier("$fileKey"),
2324
- t21.stringLiteral(payload.fileKey)
2348
+ t22.jsxAttribute(
2349
+ t22.jsxIdentifier("$fileKey"),
2350
+ t22.stringLiteral(payload.relativeFilePath)
2325
2351
  )
2326
2352
  );
2327
2353
  originalAttributes.push(
2328
- t21.jsxAttribute(
2329
- t21.jsxIdentifier("$entryKey"),
2330
- t21.stringLiteral(getJsxScopeAttribute(jsxScope))
2354
+ t22.jsxAttribute(
2355
+ t22.jsxIdentifier("$entryKey"),
2356
+ t22.stringLiteral(getJsxScopeAttribute(jsxScope))
2331
2357
  )
2332
2358
  );
2333
2359
  const $variables = getJsxVariables(jsxScope);
2334
2360
  if ($variables.properties.length > 0) {
2335
2361
  originalAttributes.push(
2336
- t21.jsxAttribute(
2337
- t21.jsxIdentifier("$variables"),
2338
- t21.jsxExpressionContainer($variables)
2362
+ t22.jsxAttribute(
2363
+ t22.jsxIdentifier("$variables"),
2364
+ t22.jsxExpressionContainer($variables)
2339
2365
  )
2340
2366
  );
2341
2367
  }
2342
2368
  const $elements = getNestedJsxElements(jsxScope);
2343
2369
  if ($elements.elements.length > 0) {
2344
2370
  originalAttributes.push(
2345
- t21.jsxAttribute(
2346
- t21.jsxIdentifier("$elements"),
2347
- t21.jsxExpressionContainer($elements)
2371
+ t22.jsxAttribute(
2372
+ t22.jsxIdentifier("$elements"),
2373
+ t22.jsxExpressionContainer($elements)
2348
2374
  )
2349
2375
  );
2350
2376
  }
2351
2377
  const $functions = getJsxFunctions(jsxScope);
2352
2378
  if ($functions.properties.length > 0) {
2353
2379
  originalAttributes.push(
2354
- t21.jsxAttribute(
2355
- t21.jsxIdentifier("$functions"),
2356
- t21.jsxExpressionContainer($functions)
2380
+ t22.jsxAttribute(
2381
+ t22.jsxIdentifier("$functions"),
2382
+ t22.jsxExpressionContainer($functions)
2357
2383
  )
2358
2384
  );
2359
2385
  }
2360
2386
  const $expressions = getJsxExpressions(jsxScope);
2361
2387
  if ($expressions.elements.length > 0) {
2362
2388
  originalAttributes.push(
2363
- t21.jsxAttribute(
2364
- t21.jsxIdentifier("$expressions"),
2365
- t21.jsxExpressionContainer($expressions)
2389
+ t22.jsxAttribute(
2390
+ t22.jsxIdentifier("$expressions"),
2391
+ t22.jsxExpressionContainer($expressions)
2366
2392
  )
2367
2393
  );
2368
2394
  }
@@ -2372,23 +2398,23 @@ var lingoJsxScopeInjectMutation = createCodeMutation((payload) => {
2372
2398
  moduleName: "lingo.dev/react/rsc" /* ReactRSC */
2373
2399
  });
2374
2400
  originalAttributes.push(
2375
- t21.jsxAttribute(
2376
- t21.jsxIdentifier("$loadDictionary"),
2377
- t21.jsxExpressionContainer(
2378
- t21.arrowFunctionExpression(
2379
- [t21.identifier("locale")],
2380
- t21.callExpression(
2381
- t21.identifier(loadDictionaryImport.importedName),
2382
- [t21.identifier("locale")]
2401
+ t22.jsxAttribute(
2402
+ t22.jsxIdentifier("$loadDictionary"),
2403
+ t22.jsxExpressionContainer(
2404
+ t22.arrowFunctionExpression(
2405
+ [t22.identifier("locale")],
2406
+ t22.callExpression(
2407
+ t22.identifier(loadDictionaryImport.importedName),
2408
+ [t22.identifier("locale")]
2383
2409
  )
2384
2410
  )
2385
2411
  )
2386
2412
  )
2387
2413
  );
2388
2414
  }
2389
- const newNode = t21.jsxElement(
2390
- t21.jsxOpeningElement(
2391
- t21.jsxIdentifier(lingoComponentImport.importedName),
2415
+ const newNode = t22.jsxElement(
2416
+ t22.jsxOpeningElement(
2417
+ t22.jsxIdentifier(lingoComponentImport.importedName),
2392
2418
  originalAttributes,
2393
2419
  true
2394
2420
  // selfClosing
@@ -2419,7 +2445,7 @@ var jsxRemoveAttributesMutation = createCodeMutation(
2419
2445
  JSXElement(path7) {
2420
2446
  const openingElement = path7.node.openingElement;
2421
2447
  openingElement.attributes = openingElement.attributes.filter((attr) => {
2422
- const removeAttr = t22.isJSXAttribute(attr) && t22.isJSXIdentifier(attr.name) && ATTRIBUTES_TO_REMOVE.includes(attr.name.name);
2448
+ const removeAttr = t23.isJSXAttribute(attr) && t23.isJSXIdentifier(attr.name) && ATTRIBUTES_TO_REMOVE.includes(attr.name.name);
2423
2449
  return !removeAttr;
2424
2450
  });
2425
2451
  }
@@ -2432,17 +2458,7 @@ var jsxRemoveAttributesMutation = createCodeMutation(
2432
2458
 
2433
2459
  // src/client-dictionary-loader.ts
2434
2460
 
2435
-
2436
2461
  var clientDictionaryLoaderMutation = createCodeMutation((payload) => {
2437
- const lingoDir = path.default.resolve(
2438
- process.cwd(),
2439
- payload.params.sourceRoot,
2440
- payload.params.lingoDir
2441
- );
2442
- const currentDir = path.default.dirname(
2443
- path.default.resolve(process.cwd(), payload.params.sourceRoot, payload.fileKey)
2444
- );
2445
- const relativeLingoPath = path.default.relative(currentDir, lingoDir);
2446
2462
  const invokations = findInvokations(payload.ast, {
2447
2463
  moduleName: "lingo.dev/react/client" /* ReactClient */,
2448
2464
  functionName: "loadDictionary"
@@ -2455,24 +2471,15 @@ var clientDictionaryLoaderMutation = createCodeMutation((payload) => {
2455
2471
  moduleName: "lingo.dev/react/client" /* ReactClient */,
2456
2472
  exportedName: "loadDictionary_internal"
2457
2473
  });
2458
- if (t23.isIdentifier(invokation.callee)) {
2474
+ if (t24.isIdentifier(invokation.callee)) {
2459
2475
  invokation.callee.name = internalDictionaryLoader.importedName;
2460
2476
  }
2461
- const localeImportMap = t23.objectExpression(
2462
- allLocales.map(
2463
- (locale) => t23.objectProperty(
2464
- t23.identifier(locale),
2465
- t23.arrowFunctionExpression(
2466
- [],
2467
- t23.callExpression(t23.identifier("import"), [
2468
- t23.stringLiteral(
2469
- `./${relativeLingoPath}/${LCP_DICTIONARY_FILE_NAME}?locale=${locale}`
2470
- )
2471
- ])
2472
- )
2473
- )
2474
- )
2475
- );
2477
+ const dictionaryPath = getDictionaryPath({
2478
+ sourceRoot: payload.params.sourceRoot,
2479
+ lingoDir: payload.params.lingoDir,
2480
+ relativeFilePath: payload.relativeFilePath
2481
+ });
2482
+ const localeImportMap = createLocaleImportMap(allLocales, dictionaryPath);
2476
2483
  invokation.arguments.push(localeImportMap);
2477
2484
  }
2478
2485
  return payload;
@@ -2552,7 +2559,7 @@ var unplugin = _unplugin.createUnplugin.call(void 0,
2552
2559
  const result = _lodash2.default.chain({
2553
2560
  code,
2554
2561
  params,
2555
- fileKey: path.default.relative(path.default.resolve(process.cwd(), params.sourceRoot), id).split(path.default.sep).join("/")
2562
+ relativeFilePath: path.default.relative(path.default.resolve(process.cwd(), params.sourceRoot), id).split(path.default.sep).join("/")
2556
2563
  // Always normalize for consistent dictionaries
2557
2564
  }).thru(createPayload).thru(
2558
2565
  composeMutations(