@lingo.dev/_compiler 0.2.2 → 0.2.4

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 +150 -160
  2. package/build/index.mjs +161 -171
  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.2",
7
+ version: "0.2.4",
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
 
@@ -204,7 +204,7 @@ function findExistingImport(ast, exportedName, moduleName) {
204
204
  let result = null;
205
205
  _traverse2.default.call(void 0, ast, {
206
206
  ImportDeclaration(path7) {
207
- if (path7.node.source.value !== moduleName) {
207
+ if (!moduleName.includes(path7.node.source.value)) {
208
208
  return;
209
209
  }
210
210
  for (const specifier of path7.node.specifiers) {
@@ -244,14 +244,14 @@ function createImportDeclaration(ast, localName, exportedName, moduleName) {
244
244
  t2.identifier(exportedName)
245
245
  );
246
246
  const existingImport = path7.get("body").find(
247
- (nodePath) => t2.isImportDeclaration(nodePath.node) && nodePath.node.source.value === moduleName
247
+ (nodePath) => t2.isImportDeclaration(nodePath.node) && moduleName.includes(nodePath.node.source.value)
248
248
  );
249
249
  if (existingImport && t2.isImportDeclaration(existingImport.node)) {
250
250
  existingImport.node.specifiers.push(importSpecifier2);
251
251
  } else {
252
252
  const importDeclaration2 = t2.importDeclaration(
253
253
  [importSpecifier2],
254
- t2.stringLiteral(moduleName)
254
+ t2.stringLiteral(moduleName[0])
255
255
  );
256
256
  const lastImportIndex = findLastImportIndex(path7);
257
257
  path7.node.body.splice(lastImportIndex + 1, 0, importDeclaration2);
@@ -345,6 +345,11 @@ function getNestedJsxElements(nodePath) {
345
345
  }
346
346
 
347
347
  // src/_const.ts
348
+ var ModuleId = {
349
+ ReactClient: ["lingo.dev/react/client", "lingo.dev/react-client"],
350
+ ReactRSC: ["lingo.dev/react/rsc", "lingo.dev/react-rsc"],
351
+ ReactRouter: ["lingo.dev/react/react-router", "lingo.dev/react-router"]
352
+ };
348
353
  var LCP_DICTIONARY_FILE_NAME = "dictionary.js";
349
354
 
350
355
  // src/jsx-provider.ts
@@ -357,11 +362,11 @@ var jsxProviderMutation = createCodeMutation((payload) => {
357
362
  return;
358
363
  }
359
364
  const lingoProviderImport = getOrCreateImport(payload.ast, {
360
- moduleName: "lingo.dev/react/rsc" /* ReactRSC */,
365
+ moduleName: ModuleId.ReactRSC,
361
366
  exportedName: "LingoProvider"
362
367
  });
363
368
  const loadDictionaryImport = getOrCreateImport(payload.ast, {
364
- moduleName: "lingo.dev/react/rsc" /* ReactRSC */,
369
+ moduleName: ModuleId.ReactRSC,
365
370
  exportedName: "loadDictionary"
366
371
  });
367
372
  const loadDictionaryArrow = t4.arrowFunctionExpression(
@@ -1731,7 +1736,7 @@ function findInvokations(ast, params) {
1731
1736
  const result = [];
1732
1737
  _traverse2.default.call(void 0, ast, {
1733
1738
  ImportDeclaration(path7) {
1734
- if (path7.node.source.value !== params.moduleName) return;
1739
+ if (!params.moduleName.includes(path7.node.source.value)) return;
1735
1740
  const importNames = /* @__PURE__ */ new Map();
1736
1741
  const specifiers = path7.node.specifiers;
1737
1742
  specifiers.forEach((specifier) => {
@@ -1771,12 +1776,33 @@ function collectCallExpressions(path7, importNames, result, functionName) {
1771
1776
  // src/_utils.ts
1772
1777
 
1773
1778
  var getDictionaryPath = (params) => {
1774
- return path.default.relative(
1775
- params.relativeFilePath,
1776
- path.default.resolve(params.sourceRoot, params.lingoDir, LCP_DICTIONARY_FILE_NAME)
1779
+ const absolute = path.default.resolve(
1780
+ params.sourceRoot,
1781
+ params.lingoDir,
1782
+ LCP_DICTIONARY_FILE_NAME
1777
1783
  );
1784
+ const rel = path.default.relative(params.relativeFilePath, absolute);
1785
+ return rel.split(path.default.sep).join(path.default.posix.sep);
1778
1786
  };
1779
1787
 
1788
+ // src/utils/create-locale-import-map.ts
1789
+
1790
+ function createLocaleImportMap(allLocales, dictionaryPath) {
1791
+ return t12.objectExpression(
1792
+ allLocales.map(
1793
+ (locale) => t12.objectProperty(
1794
+ t12.stringLiteral(locale),
1795
+ t12.arrowFunctionExpression(
1796
+ [],
1797
+ t12.callExpression(t12.identifier("import"), [
1798
+ t12.stringLiteral(`${dictionaryPath}?locale=${locale}`)
1799
+ ])
1800
+ )
1801
+ )
1802
+ )
1803
+ );
1804
+ }
1805
+
1780
1806
  // src/rsc-dictionary-loader.ts
1781
1807
  var rscDictionaryLoaderMutation = createCodeMutation((payload) => {
1782
1808
  const mode = getModuleExecutionMode(payload.ast, payload.params.rsc);
@@ -1784,7 +1810,7 @@ var rscDictionaryLoaderMutation = createCodeMutation((payload) => {
1784
1810
  return payload;
1785
1811
  }
1786
1812
  const invokations = findInvokations(payload.ast, {
1787
- moduleName: "lingo.dev/react/rsc" /* ReactRSC */,
1813
+ moduleName: ModuleId.ReactRSC,
1788
1814
  functionName: "loadDictionary"
1789
1815
  });
1790
1816
  const allLocales = Array.from(
@@ -1792,10 +1818,10 @@ var rscDictionaryLoaderMutation = createCodeMutation((payload) => {
1792
1818
  );
1793
1819
  for (const invokation of invokations) {
1794
1820
  const internalDictionaryLoader = getOrCreateImport(payload.ast, {
1795
- moduleName: "lingo.dev/react/rsc" /* ReactRSC */,
1821
+ moduleName: ModuleId.ReactRSC,
1796
1822
  exportedName: "loadDictionary_internal"
1797
1823
  });
1798
- if (t12.isIdentifier(invokation.callee)) {
1824
+ if (t13.isIdentifier(invokation.callee)) {
1799
1825
  invokation.callee.name = internalDictionaryLoader.importedName;
1800
1826
  }
1801
1827
  const dictionaryPath = getDictionaryPath({
@@ -1803,19 +1829,7 @@ var rscDictionaryLoaderMutation = createCodeMutation((payload) => {
1803
1829
  lingoDir: payload.params.lingoDir,
1804
1830
  relativeFilePath: payload.relativeFilePath
1805
1831
  });
1806
- const localeImportMap = t12.objectExpression(
1807
- allLocales.map(
1808
- (locale) => t12.objectProperty(
1809
- t12.identifier(locale),
1810
- t12.arrowFunctionExpression(
1811
- [],
1812
- t12.callExpression(t12.identifier("import"), [
1813
- t12.stringLiteral(`${dictionaryPath}?locale=${locale}`)
1814
- ])
1815
- )
1816
- )
1817
- )
1818
- );
1832
+ const localeImportMap = createLocaleImportMap(allLocales, dictionaryPath);
1819
1833
  invokation.arguments.push(localeImportMap);
1820
1834
  }
1821
1835
  return payload;
@@ -1830,7 +1844,7 @@ var reactRouterDictionaryLoaderMutation = createCodeMutation(
1830
1844
  return payload;
1831
1845
  }
1832
1846
  const invokations = findInvokations(payload.ast, {
1833
- moduleName: "lingo.dev/react/react-router" /* ReactRouter */,
1847
+ moduleName: ModuleId.ReactRouter,
1834
1848
  functionName: "loadDictionary"
1835
1849
  });
1836
1850
  const allLocales = Array.from(
@@ -1838,10 +1852,10 @@ var reactRouterDictionaryLoaderMutation = createCodeMutation(
1838
1852
  );
1839
1853
  for (const invokation of invokations) {
1840
1854
  const internalDictionaryLoader = getOrCreateImport(payload.ast, {
1841
- moduleName: "lingo.dev/react/react-router" /* ReactRouter */,
1855
+ moduleName: ModuleId.ReactRouter,
1842
1856
  exportedName: "loadDictionary_internal"
1843
1857
  });
1844
- if (t13.isIdentifier(invokation.callee)) {
1858
+ if (t14.isIdentifier(invokation.callee)) {
1845
1859
  invokation.callee.name = internalDictionaryLoader.importedName;
1846
1860
  }
1847
1861
  const dictionaryPath = getDictionaryPath({
@@ -1849,19 +1863,7 @@ var reactRouterDictionaryLoaderMutation = createCodeMutation(
1849
1863
  lingoDir: payload.params.lingoDir,
1850
1864
  relativeFilePath: payload.relativeFilePath
1851
1865
  });
1852
- const localeImportMap = t13.objectExpression(
1853
- allLocales.map(
1854
- (locale) => t13.objectProperty(
1855
- t13.identifier(locale),
1856
- t13.arrowFunctionExpression(
1857
- [],
1858
- t13.callExpression(t13.identifier("import"), [
1859
- t13.stringLiteral(`${dictionaryPath}?locale=${locale}`)
1860
- ])
1861
- )
1862
- )
1863
- )
1864
- );
1866
+ const localeImportMap = createLocaleImportMap(allLocales, dictionaryPath);
1865
1867
  invokation.arguments.push(localeImportMap);
1866
1868
  }
1867
1869
  return payload;
@@ -1879,7 +1881,7 @@ function jsxFragmentMutation(payload) {
1879
1881
  ImportDeclaration(path7) {
1880
1882
  if (path7.node.source.value !== "react") return;
1881
1883
  for (const specifier of path7.node.specifiers) {
1882
- if (t14.isImportSpecifier(specifier) && t14.isIdentifier(specifier.imported) && specifier.imported.name === "Fragment") {
1884
+ if (t15.isImportSpecifier(specifier) && t15.isIdentifier(specifier.imported) && specifier.imported.name === "Fragment") {
1883
1885
  fragmentImportName = specifier.local.name;
1884
1886
  path7.stop();
1885
1887
  }
@@ -1892,13 +1894,13 @@ function jsxFragmentMutation(payload) {
1892
1894
  if (!fragmentImportName) {
1893
1895
  const result = getOrCreateImport(ast, {
1894
1896
  exportedName: "Fragment",
1895
- moduleName: "react"
1897
+ moduleName: ["react"]
1896
1898
  });
1897
1899
  fragmentImportName = result.importedName;
1898
1900
  }
1899
- const fragmentElement = t14.jsxElement(
1900
- t14.jsxOpeningElement(t14.jsxIdentifier(fragmentImportName), [], false),
1901
- t14.jsxClosingElement(t14.jsxIdentifier(fragmentImportName)),
1901
+ const fragmentElement = t15.jsxElement(
1902
+ t15.jsxOpeningElement(t15.jsxIdentifier(fragmentImportName), [], false),
1903
+ t15.jsxClosingElement(t15.jsxIdentifier(fragmentImportName)),
1902
1904
  path7.node.children,
1903
1905
  false
1904
1906
  );
@@ -1916,16 +1918,16 @@ var jsxHtmlLangMutation = createCodeMutation((payload) => {
1916
1918
  JSXElement: (path7) => {
1917
1919
  if (_optionalChain([getJsxElementName, 'call', _48 => _48(path7), 'optionalAccess', _49 => _49.toLowerCase, 'call', _50 => _50()]) === "html") {
1918
1920
  const mode = getModuleExecutionMode(payload.ast, payload.params.rsc);
1919
- const packagePath = mode === "client" ? "lingo.dev/react/client" /* ReactClient */ : "lingo.dev/react/rsc" /* ReactRSC */;
1921
+ const packagePath = mode === "client" ? ModuleId.ReactClient : ModuleId.ReactRSC;
1920
1922
  const lingoHtmlComponentImport = getOrCreateImport(payload.ast, {
1921
1923
  moduleName: packagePath,
1922
1924
  exportedName: "LingoHtmlComponent"
1923
1925
  });
1924
- path7.node.openingElement.name = t15.jsxIdentifier(
1926
+ path7.node.openingElement.name = t16.jsxIdentifier(
1925
1927
  lingoHtmlComponentImport.importedName
1926
1928
  );
1927
1929
  if (path7.node.closingElement) {
1928
- path7.node.closingElement.name = t15.jsxIdentifier(
1930
+ path7.node.closingElement.name = t16.jsxIdentifier(
1929
1931
  lingoHtmlComponentImport.importedName
1930
1932
  );
1931
1933
  }
@@ -2016,39 +2018,39 @@ function extractJsxContent(nodePath, replaceWhitespacePlaceholders = true) {
2016
2018
  return;
2017
2019
  }
2018
2020
  const expr = path7.node.expression;
2019
- if (t16.isCallExpression(expr)) {
2021
+ if (t17.isCallExpression(expr)) {
2020
2022
  let key = "";
2021
- if (t16.isIdentifier(expr.callee)) {
2023
+ if (t17.isIdentifier(expr.callee)) {
2022
2024
  key = `${expr.callee.name}`;
2023
- } else if (t16.isMemberExpression(expr.callee)) {
2025
+ } else if (t17.isMemberExpression(expr.callee)) {
2024
2026
  let firstCallee = expr.callee;
2025
- while (t16.isMemberExpression(firstCallee) && t16.isCallExpression(firstCallee.object)) {
2027
+ while (t17.isMemberExpression(firstCallee) && t17.isCallExpression(firstCallee.object)) {
2026
2028
  firstCallee = firstCallee.object.callee;
2027
2029
  }
2028
2030
  let current = firstCallee;
2029
2031
  const parts = [];
2030
- while (t16.isMemberExpression(current)) {
2031
- if (t16.isIdentifier(current.property)) {
2032
+ while (t17.isMemberExpression(current)) {
2033
+ if (t17.isIdentifier(current.property)) {
2032
2034
  parts.unshift(current.property.name);
2033
2035
  }
2034
2036
  current = current.object;
2035
2037
  }
2036
- if (t16.isIdentifier(current)) {
2038
+ if (t17.isIdentifier(current)) {
2037
2039
  parts.unshift(current.name);
2038
2040
  }
2039
- if (t16.isMemberExpression(firstCallee) && t16.isNewExpression(firstCallee.object) && t16.isIdentifier(firstCallee.object.callee)) {
2041
+ if (t17.isMemberExpression(firstCallee) && t17.isNewExpression(firstCallee.object) && t17.isIdentifier(firstCallee.object.callee)) {
2040
2042
  parts.unshift(firstCallee.object.callee.name);
2041
2043
  }
2042
2044
  key = parts.join(".");
2043
2045
  }
2044
2046
  chunks.push(`<function:${key}/>`);
2045
- } else if (t16.isIdentifier(expr)) {
2047
+ } else if (t17.isIdentifier(expr)) {
2046
2048
  chunks.push(`{${expr.name}}`);
2047
- } else if (t16.isMemberExpression(expr)) {
2049
+ } else if (t17.isMemberExpression(expr)) {
2048
2050
  let current = expr;
2049
2051
  const parts = [];
2050
- while (t16.isMemberExpression(current)) {
2051
- if (t16.isIdentifier(current.property)) {
2052
+ while (t17.isMemberExpression(current)) {
2053
+ if (t17.isIdentifier(current.property)) {
2052
2054
  if (current.computed) {
2053
2055
  parts.unshift(`[${current.property.name}]`);
2054
2056
  } else {
@@ -2057,7 +2059,7 @@ function extractJsxContent(nodePath, replaceWhitespacePlaceholders = true) {
2057
2059
  }
2058
2060
  current = current.object;
2059
2061
  }
2060
- if (t16.isIdentifier(current)) {
2062
+ if (t17.isIdentifier(current)) {
2061
2063
  parts.unshift(current.name);
2062
2064
  chunks.push(`{${parts.join(".").replaceAll(".[", "[")}}`);
2063
2065
  }
@@ -2078,12 +2080,12 @@ function extractJsxContent(nodePath, replaceWhitespacePlaceholders = true) {
2078
2080
  }
2079
2081
  var compilerProps = ["data-jsx-attribute-scope", "data-jsx-scope"];
2080
2082
  function isExpression2(nodePath) {
2081
- const isCompilerExpression = !_lodash2.default.isArray(nodePath.container) && t16.isJSXAttribute(nodePath.container) && t16.isJSXIdentifier(nodePath.container.name) && compilerProps.includes(nodePath.container.name.name);
2082
- return !isCompilerExpression && !t16.isJSXEmptyExpression(nodePath.node.expression);
2083
+ const isCompilerExpression = !_lodash2.default.isArray(nodePath.container) && t17.isJSXAttribute(nodePath.container) && t17.isJSXIdentifier(nodePath.container.name) && compilerProps.includes(nodePath.container.name.name);
2084
+ return !isCompilerExpression && !t17.isJSXEmptyExpression(nodePath.node.expression);
2083
2085
  }
2084
2086
  function isWhitespace(nodePath) {
2085
2087
  const expr = nodePath.node.expression;
2086
- return t16.isStringLiteral(expr) && expr.value === " ";
2088
+ return t17.isStringLiteral(expr) && expr.value === " ";
2087
2089
  }
2088
2090
  function normalizeJsxWhitespace(input) {
2089
2091
  const lines = input.split("\n");
@@ -2149,7 +2151,7 @@ var lingoJsxAttributeScopeInjectMutation = createCodeMutation(
2149
2151
  const mode = getModuleExecutionMode(payload.ast, payload.params.rsc);
2150
2152
  const jsxAttributeScopes = collectJsxAttributeScopes(payload.ast);
2151
2153
  for (const [jsxScope, attributes] of jsxAttributeScopes) {
2152
- const packagePath = mode === "client" ? "lingo.dev/react/client" /* ReactClient */ : "lingo.dev/react/rsc" /* ReactRSC */;
2154
+ const packagePath = mode === "client" ? ModuleId.ReactClient : ModuleId.ReactRSC;
2153
2155
  const lingoComponentImport = getOrCreateImport(payload.ast, {
2154
2156
  moduleName: packagePath,
2155
2157
  exportedName: "LingoAttributeComponent"
@@ -2158,34 +2160,34 @@ var lingoJsxAttributeScopeInjectMutation = createCodeMutation(
2158
2160
  if (!originalJsxElementName) {
2159
2161
  continue;
2160
2162
  }
2161
- jsxScope.node.openingElement.name = t17.jsxIdentifier(
2163
+ jsxScope.node.openingElement.name = t18.jsxIdentifier(
2162
2164
  lingoComponentImport.importedName
2163
2165
  );
2164
2166
  if (jsxScope.node.closingElement) {
2165
- jsxScope.node.closingElement.name = t17.jsxIdentifier(
2167
+ jsxScope.node.closingElement.name = t18.jsxIdentifier(
2166
2168
  lingoComponentImport.importedName
2167
2169
  );
2168
2170
  }
2169
- const as = /^[A-Z]/.test(originalJsxElementName) ? t17.jsxExpressionContainer(t17.identifier(originalJsxElementName)) : t17.stringLiteral(originalJsxElementName);
2171
+ const as = /^[A-Z]/.test(originalJsxElementName) ? t18.jsxExpressionContainer(t18.identifier(originalJsxElementName)) : t18.stringLiteral(originalJsxElementName);
2170
2172
  jsxScope.node.openingElement.attributes.push(
2171
- t17.jsxAttribute(t17.jsxIdentifier("$attrAs"), as)
2173
+ t18.jsxAttribute(t18.jsxIdentifier("$attrAs"), as)
2172
2174
  );
2173
2175
  jsxScope.node.openingElement.attributes.push(
2174
- t17.jsxAttribute(
2175
- t17.jsxIdentifier("$fileKey"),
2176
- t17.stringLiteral(payload.relativeFilePath)
2176
+ t18.jsxAttribute(
2177
+ t18.jsxIdentifier("$fileKey"),
2178
+ t18.stringLiteral(payload.relativeFilePath)
2177
2179
  )
2178
2180
  );
2179
2181
  jsxScope.node.openingElement.attributes.push(
2180
- t17.jsxAttribute(
2181
- t17.jsxIdentifier("$attributes"),
2182
- t17.jsxExpressionContainer(
2183
- t17.objectExpression(
2182
+ t18.jsxAttribute(
2183
+ t18.jsxIdentifier("$attributes"),
2184
+ t18.jsxExpressionContainer(
2185
+ t18.objectExpression(
2184
2186
  attributes.map((attributeDefinition) => {
2185
2187
  const [attribute, key = ""] = attributeDefinition.split(":");
2186
- return t17.objectProperty(
2187
- t17.stringLiteral(attribute),
2188
- t17.stringLiteral(key)
2188
+ return t18.objectProperty(
2189
+ t18.stringLiteral(attribute),
2190
+ t18.stringLiteral(key)
2189
2191
  );
2190
2192
  })
2191
2193
  )
@@ -2195,17 +2197,17 @@ var lingoJsxAttributeScopeInjectMutation = createCodeMutation(
2195
2197
  if (mode === "server") {
2196
2198
  const loadDictionaryImport = getOrCreateImport(payload.ast, {
2197
2199
  exportedName: "loadDictionary",
2198
- moduleName: "lingo.dev/react/rsc" /* ReactRSC */
2200
+ moduleName: ModuleId.ReactRSC
2199
2201
  });
2200
2202
  jsxScope.node.openingElement.attributes.push(
2201
- t17.jsxAttribute(
2202
- t17.jsxIdentifier("$loadDictionary"),
2203
- t17.jsxExpressionContainer(
2204
- t17.arrowFunctionExpression(
2205
- [t17.identifier("locale")],
2206
- t17.callExpression(
2207
- t17.identifier(loadDictionaryImport.importedName),
2208
- [t17.identifier("locale")]
2203
+ t18.jsxAttribute(
2204
+ t18.jsxIdentifier("$loadDictionary"),
2205
+ t18.jsxExpressionContainer(
2206
+ t18.arrowFunctionExpression(
2207
+ [t18.identifier("locale")],
2208
+ t18.callExpression(
2209
+ t18.identifier(loadDictionaryImport.importedName),
2210
+ [t18.identifier("locale")]
2209
2211
  )
2210
2212
  )
2211
2213
  )
@@ -2229,13 +2231,13 @@ var getJsxVariables = (nodePath) => {
2229
2231
  path7.skip();
2230
2232
  },
2231
2233
  JSXExpressionContainer(path7) {
2232
- if (t18.isIdentifier(path7.node.expression)) {
2234
+ if (t19.isIdentifier(path7.node.expression)) {
2233
2235
  variables.add(path7.node.expression.name);
2234
- } else if (t18.isMemberExpression(path7.node.expression)) {
2236
+ } else if (t19.isMemberExpression(path7.node.expression)) {
2235
2237
  let current = path7.node.expression;
2236
2238
  const parts = [];
2237
- while (t18.isMemberExpression(current)) {
2238
- if (t18.isIdentifier(current.property)) {
2239
+ while (t19.isMemberExpression(current)) {
2240
+ if (t19.isIdentifier(current.property)) {
2239
2241
  if (current.computed) {
2240
2242
  parts.unshift(`[${current.property.name}]`);
2241
2243
  } else {
@@ -2244,7 +2246,7 @@ var getJsxVariables = (nodePath) => {
2244
2246
  }
2245
2247
  current = current.object;
2246
2248
  }
2247
- if (t18.isIdentifier(current)) {
2249
+ if (t19.isIdentifier(current)) {
2248
2250
  parts.unshift(current.name);
2249
2251
  variables.add(parts.join(".").replaceAll(".[", "["));
2250
2252
  }
@@ -2253,9 +2255,9 @@ var getJsxVariables = (nodePath) => {
2253
2255
  }
2254
2256
  });
2255
2257
  const properties = Array.from(variables).map(
2256
- (name) => t18.objectProperty(t18.stringLiteral(name), t18.identifier(name))
2258
+ (name) => t19.objectProperty(t19.stringLiteral(name), t19.identifier(name))
2257
2259
  );
2258
- const result = t18.objectExpression(properties);
2260
+ const result = t19.objectExpression(properties);
2259
2261
  return result;
2260
2262
  };
2261
2263
 
@@ -2269,27 +2271,27 @@ var getJsxFunctions = (nodePath) => {
2269
2271
  path7.skip();
2270
2272
  },
2271
2273
  JSXExpressionContainer(path7) {
2272
- if (t19.isCallExpression(path7.node.expression)) {
2274
+ if (t20.isCallExpression(path7.node.expression)) {
2273
2275
  let key = "";
2274
- if (t19.isIdentifier(path7.node.expression.callee)) {
2276
+ if (t20.isIdentifier(path7.node.expression.callee)) {
2275
2277
  key = `${path7.node.expression.callee.name}`;
2276
- } else if (t19.isMemberExpression(path7.node.expression.callee)) {
2278
+ } else if (t20.isMemberExpression(path7.node.expression.callee)) {
2277
2279
  let firstCallee = path7.node.expression.callee;
2278
- while (t19.isMemberExpression(firstCallee) && t19.isCallExpression(firstCallee.object)) {
2280
+ while (t20.isMemberExpression(firstCallee) && t20.isCallExpression(firstCallee.object)) {
2279
2281
  firstCallee = firstCallee.object.callee;
2280
2282
  }
2281
2283
  let current = firstCallee;
2282
2284
  const parts = [];
2283
- while (t19.isMemberExpression(current)) {
2284
- if (t19.isIdentifier(current.property)) {
2285
+ while (t20.isMemberExpression(current)) {
2286
+ if (t20.isIdentifier(current.property)) {
2285
2287
  parts.unshift(current.property.name);
2286
2288
  }
2287
2289
  current = current.object;
2288
2290
  }
2289
- if (t19.isIdentifier(current)) {
2291
+ if (t20.isIdentifier(current)) {
2290
2292
  parts.unshift(current.name);
2291
2293
  }
2292
- if (t19.isMemberExpression(firstCallee) && t19.isNewExpression(firstCallee.object) && t19.isIdentifier(firstCallee.object.callee)) {
2294
+ if (t20.isMemberExpression(firstCallee) && t20.isNewExpression(firstCallee.object) && t20.isIdentifier(firstCallee.object.callee)) {
2293
2295
  parts.unshift(firstCallee.object.callee.name);
2294
2296
  }
2295
2297
  key = parts.join(".");
@@ -2302,9 +2304,9 @@ var getJsxFunctions = (nodePath) => {
2302
2304
  }
2303
2305
  });
2304
2306
  const properties = Array.from(functions.entries()).map(
2305
- ([name, callExpr]) => t19.objectProperty(t19.stringLiteral(name), t19.arrayExpression(callExpr))
2307
+ ([name, callExpr]) => t20.objectProperty(t20.stringLiteral(name), t20.arrayExpression(callExpr))
2306
2308
  );
2307
- return t19.objectExpression(properties);
2309
+ return t20.objectExpression(properties);
2308
2310
  };
2309
2311
 
2310
2312
  // src/utils/jsx-expressions.ts
@@ -2317,13 +2319,13 @@ var getJsxExpressions = (nodePath) => {
2317
2319
  },
2318
2320
  JSXExpressionContainer(path7) {
2319
2321
  const expr = path7.node.expression;
2320
- if (!t20.isJSXEmptyExpression(expr) && !t20.isIdentifier(expr) && !t20.isMemberExpression(expr) && !t20.isCallExpression(expr) && !(t20.isStringLiteral(expr) && expr.value === " ")) {
2322
+ if (!t21.isJSXEmptyExpression(expr) && !t21.isIdentifier(expr) && !t21.isMemberExpression(expr) && !t21.isCallExpression(expr) && !(t21.isStringLiteral(expr) && expr.value === " ")) {
2321
2323
  expressions.push(expr);
2322
2324
  }
2323
2325
  path7.skip();
2324
2326
  }
2325
2327
  });
2326
- return t20.arrayExpression(expressions);
2328
+ return t21.arrayExpression(expressions);
2327
2329
  };
2328
2330
 
2329
2331
  // src/jsx-scope-inject.ts
@@ -2335,7 +2337,7 @@ var lingoJsxScopeInjectMutation = createCodeMutation((payload) => {
2335
2337
  if (skip) {
2336
2338
  continue;
2337
2339
  }
2338
- const packagePath = mode === "client" ? "lingo.dev/react/client" /* ReactClient */ : "lingo.dev/react/rsc" /* ReactRSC */;
2340
+ const packagePath = mode === "client" ? ModuleId.ReactClient : ModuleId.ReactRSC;
2339
2341
  const lingoComponentImport = getOrCreateImport(payload.ast, {
2340
2342
  moduleName: packagePath,
2341
2343
  exportedName: "LingoComponent"
@@ -2345,79 +2347,79 @@ var lingoJsxScopeInjectMutation = createCodeMutation((payload) => {
2345
2347
  continue;
2346
2348
  }
2347
2349
  const originalAttributes = jsxScope.node.openingElement.attributes.slice();
2348
- const as = /^[A-Z]/.test(originalJsxElementName) ? t21.jsxExpressionContainer(t21.identifier(originalJsxElementName)) : t21.stringLiteral(originalJsxElementName);
2349
- originalAttributes.push(t21.jsxAttribute(t21.jsxIdentifier("$as"), as));
2350
+ const as = /^[A-Z]/.test(originalJsxElementName) ? t22.jsxExpressionContainer(t22.identifier(originalJsxElementName)) : t22.stringLiteral(originalJsxElementName);
2351
+ originalAttributes.push(t22.jsxAttribute(t22.jsxIdentifier("$as"), as));
2350
2352
  originalAttributes.push(
2351
- t21.jsxAttribute(
2352
- t21.jsxIdentifier("$fileKey"),
2353
- t21.stringLiteral(payload.relativeFilePath)
2353
+ t22.jsxAttribute(
2354
+ t22.jsxIdentifier("$fileKey"),
2355
+ t22.stringLiteral(payload.relativeFilePath)
2354
2356
  )
2355
2357
  );
2356
2358
  originalAttributes.push(
2357
- t21.jsxAttribute(
2358
- t21.jsxIdentifier("$entryKey"),
2359
- t21.stringLiteral(getJsxScopeAttribute(jsxScope))
2359
+ t22.jsxAttribute(
2360
+ t22.jsxIdentifier("$entryKey"),
2361
+ t22.stringLiteral(getJsxScopeAttribute(jsxScope))
2360
2362
  )
2361
2363
  );
2362
2364
  const $variables = getJsxVariables(jsxScope);
2363
2365
  if ($variables.properties.length > 0) {
2364
2366
  originalAttributes.push(
2365
- t21.jsxAttribute(
2366
- t21.jsxIdentifier("$variables"),
2367
- t21.jsxExpressionContainer($variables)
2367
+ t22.jsxAttribute(
2368
+ t22.jsxIdentifier("$variables"),
2369
+ t22.jsxExpressionContainer($variables)
2368
2370
  )
2369
2371
  );
2370
2372
  }
2371
2373
  const $elements = getNestedJsxElements(jsxScope);
2372
2374
  if ($elements.elements.length > 0) {
2373
2375
  originalAttributes.push(
2374
- t21.jsxAttribute(
2375
- t21.jsxIdentifier("$elements"),
2376
- t21.jsxExpressionContainer($elements)
2376
+ t22.jsxAttribute(
2377
+ t22.jsxIdentifier("$elements"),
2378
+ t22.jsxExpressionContainer($elements)
2377
2379
  )
2378
2380
  );
2379
2381
  }
2380
2382
  const $functions = getJsxFunctions(jsxScope);
2381
2383
  if ($functions.properties.length > 0) {
2382
2384
  originalAttributes.push(
2383
- t21.jsxAttribute(
2384
- t21.jsxIdentifier("$functions"),
2385
- t21.jsxExpressionContainer($functions)
2385
+ t22.jsxAttribute(
2386
+ t22.jsxIdentifier("$functions"),
2387
+ t22.jsxExpressionContainer($functions)
2386
2388
  )
2387
2389
  );
2388
2390
  }
2389
2391
  const $expressions = getJsxExpressions(jsxScope);
2390
2392
  if ($expressions.elements.length > 0) {
2391
2393
  originalAttributes.push(
2392
- t21.jsxAttribute(
2393
- t21.jsxIdentifier("$expressions"),
2394
- t21.jsxExpressionContainer($expressions)
2394
+ t22.jsxAttribute(
2395
+ t22.jsxIdentifier("$expressions"),
2396
+ t22.jsxExpressionContainer($expressions)
2395
2397
  )
2396
2398
  );
2397
2399
  }
2398
2400
  if (mode === "server") {
2399
2401
  const loadDictionaryImport = getOrCreateImport(payload.ast, {
2400
2402
  exportedName: "loadDictionary",
2401
- moduleName: "lingo.dev/react/rsc" /* ReactRSC */
2403
+ moduleName: ModuleId.ReactRSC
2402
2404
  });
2403
2405
  originalAttributes.push(
2404
- t21.jsxAttribute(
2405
- t21.jsxIdentifier("$loadDictionary"),
2406
- t21.jsxExpressionContainer(
2407
- t21.arrowFunctionExpression(
2408
- [t21.identifier("locale")],
2409
- t21.callExpression(
2410
- t21.identifier(loadDictionaryImport.importedName),
2411
- [t21.identifier("locale")]
2406
+ t22.jsxAttribute(
2407
+ t22.jsxIdentifier("$loadDictionary"),
2408
+ t22.jsxExpressionContainer(
2409
+ t22.arrowFunctionExpression(
2410
+ [t22.identifier("locale")],
2411
+ t22.callExpression(
2412
+ t22.identifier(loadDictionaryImport.importedName),
2413
+ [t22.identifier("locale")]
2412
2414
  )
2413
2415
  )
2414
2416
  )
2415
2417
  )
2416
2418
  );
2417
2419
  }
2418
- const newNode = t21.jsxElement(
2419
- t21.jsxOpeningElement(
2420
- t21.jsxIdentifier(lingoComponentImport.importedName),
2420
+ const newNode = t22.jsxElement(
2421
+ t22.jsxOpeningElement(
2422
+ t22.jsxIdentifier(lingoComponentImport.importedName),
2421
2423
  originalAttributes,
2422
2424
  true
2423
2425
  // selfClosing
@@ -2448,7 +2450,7 @@ var jsxRemoveAttributesMutation = createCodeMutation(
2448
2450
  JSXElement(path7) {
2449
2451
  const openingElement = path7.node.openingElement;
2450
2452
  openingElement.attributes = openingElement.attributes.filter((attr) => {
2451
- const removeAttr = t22.isJSXAttribute(attr) && t22.isJSXIdentifier(attr.name) && ATTRIBUTES_TO_REMOVE.includes(attr.name.name);
2453
+ const removeAttr = t23.isJSXAttribute(attr) && t23.isJSXIdentifier(attr.name) && ATTRIBUTES_TO_REMOVE.includes(attr.name.name);
2452
2454
  return !removeAttr;
2453
2455
  });
2454
2456
  }
@@ -2463,7 +2465,7 @@ var jsxRemoveAttributesMutation = createCodeMutation(
2463
2465
 
2464
2466
  var clientDictionaryLoaderMutation = createCodeMutation((payload) => {
2465
2467
  const invokations = findInvokations(payload.ast, {
2466
- moduleName: "lingo.dev/react/client" /* ReactClient */,
2468
+ moduleName: ModuleId.ReactClient,
2467
2469
  functionName: "loadDictionary"
2468
2470
  });
2469
2471
  const allLocales = Array.from(
@@ -2471,10 +2473,10 @@ var clientDictionaryLoaderMutation = createCodeMutation((payload) => {
2471
2473
  );
2472
2474
  for (const invokation of invokations) {
2473
2475
  const internalDictionaryLoader = getOrCreateImport(payload.ast, {
2474
- moduleName: "lingo.dev/react/client" /* ReactClient */,
2476
+ moduleName: ModuleId.ReactClient,
2475
2477
  exportedName: "loadDictionary_internal"
2476
2478
  });
2477
- if (t23.isIdentifier(invokation.callee)) {
2479
+ if (t24.isIdentifier(invokation.callee)) {
2478
2480
  invokation.callee.name = internalDictionaryLoader.importedName;
2479
2481
  }
2480
2482
  const dictionaryPath = getDictionaryPath({
@@ -2482,19 +2484,7 @@ var clientDictionaryLoaderMutation = createCodeMutation((payload) => {
2482
2484
  lingoDir: payload.params.lingoDir,
2483
2485
  relativeFilePath: payload.relativeFilePath
2484
2486
  });
2485
- const localeImportMap = t23.objectExpression(
2486
- allLocales.map(
2487
- (locale) => t23.objectProperty(
2488
- t23.identifier(locale),
2489
- t23.arrowFunctionExpression(
2490
- [],
2491
- t23.callExpression(t23.identifier("import"), [
2492
- t23.stringLiteral(`${dictionaryPath}?locale=${locale}`)
2493
- ])
2494
- )
2495
- )
2496
- )
2497
- );
2487
+ const localeImportMap = createLocaleImportMap(allLocales, dictionaryPath);
2498
2488
  invokation.arguments.push(localeImportMap);
2499
2489
  }
2500
2490
  return payload;