@lingo.dev/_compiler 0.2.3 → 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.
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.3",
7
+ version: "0.2.4",
8
8
  description: "Lingo.dev Compiler",
9
9
  private: false,
10
10
  publishConfig: {
@@ -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) => {
@@ -1805,7 +1810,7 @@ var rscDictionaryLoaderMutation = createCodeMutation((payload) => {
1805
1810
  return payload;
1806
1811
  }
1807
1812
  const invokations = findInvokations(payload.ast, {
1808
- moduleName: "lingo.dev/react/rsc" /* ReactRSC */,
1813
+ moduleName: ModuleId.ReactRSC,
1809
1814
  functionName: "loadDictionary"
1810
1815
  });
1811
1816
  const allLocales = Array.from(
@@ -1813,7 +1818,7 @@ var rscDictionaryLoaderMutation = createCodeMutation((payload) => {
1813
1818
  );
1814
1819
  for (const invokation of invokations) {
1815
1820
  const internalDictionaryLoader = getOrCreateImport(payload.ast, {
1816
- moduleName: "lingo.dev/react/rsc" /* ReactRSC */,
1821
+ moduleName: ModuleId.ReactRSC,
1817
1822
  exportedName: "loadDictionary_internal"
1818
1823
  });
1819
1824
  if (t13.isIdentifier(invokation.callee)) {
@@ -1839,7 +1844,7 @@ var reactRouterDictionaryLoaderMutation = createCodeMutation(
1839
1844
  return payload;
1840
1845
  }
1841
1846
  const invokations = findInvokations(payload.ast, {
1842
- moduleName: "lingo.dev/react/react-router" /* ReactRouter */,
1847
+ moduleName: ModuleId.ReactRouter,
1843
1848
  functionName: "loadDictionary"
1844
1849
  });
1845
1850
  const allLocales = Array.from(
@@ -1847,7 +1852,7 @@ var reactRouterDictionaryLoaderMutation = createCodeMutation(
1847
1852
  );
1848
1853
  for (const invokation of invokations) {
1849
1854
  const internalDictionaryLoader = getOrCreateImport(payload.ast, {
1850
- moduleName: "lingo.dev/react/react-router" /* ReactRouter */,
1855
+ moduleName: ModuleId.ReactRouter,
1851
1856
  exportedName: "loadDictionary_internal"
1852
1857
  });
1853
1858
  if (t14.isIdentifier(invokation.callee)) {
@@ -1889,7 +1894,7 @@ function jsxFragmentMutation(payload) {
1889
1894
  if (!fragmentImportName) {
1890
1895
  const result = getOrCreateImport(ast, {
1891
1896
  exportedName: "Fragment",
1892
- moduleName: "react"
1897
+ moduleName: ["react"]
1893
1898
  });
1894
1899
  fragmentImportName = result.importedName;
1895
1900
  }
@@ -1913,7 +1918,7 @@ var jsxHtmlLangMutation = createCodeMutation((payload) => {
1913
1918
  JSXElement: (path7) => {
1914
1919
  if (_optionalChain([getJsxElementName, 'call', _48 => _48(path7), 'optionalAccess', _49 => _49.toLowerCase, 'call', _50 => _50()]) === "html") {
1915
1920
  const mode = getModuleExecutionMode(payload.ast, payload.params.rsc);
1916
- const packagePath = mode === "client" ? "lingo.dev/react/client" /* ReactClient */ : "lingo.dev/react/rsc" /* ReactRSC */;
1921
+ const packagePath = mode === "client" ? ModuleId.ReactClient : ModuleId.ReactRSC;
1917
1922
  const lingoHtmlComponentImport = getOrCreateImport(payload.ast, {
1918
1923
  moduleName: packagePath,
1919
1924
  exportedName: "LingoHtmlComponent"
@@ -2146,7 +2151,7 @@ var lingoJsxAttributeScopeInjectMutation = createCodeMutation(
2146
2151
  const mode = getModuleExecutionMode(payload.ast, payload.params.rsc);
2147
2152
  const jsxAttributeScopes = collectJsxAttributeScopes(payload.ast);
2148
2153
  for (const [jsxScope, attributes] of jsxAttributeScopes) {
2149
- const packagePath = mode === "client" ? "lingo.dev/react/client" /* ReactClient */ : "lingo.dev/react/rsc" /* ReactRSC */;
2154
+ const packagePath = mode === "client" ? ModuleId.ReactClient : ModuleId.ReactRSC;
2150
2155
  const lingoComponentImport = getOrCreateImport(payload.ast, {
2151
2156
  moduleName: packagePath,
2152
2157
  exportedName: "LingoAttributeComponent"
@@ -2192,7 +2197,7 @@ var lingoJsxAttributeScopeInjectMutation = createCodeMutation(
2192
2197
  if (mode === "server") {
2193
2198
  const loadDictionaryImport = getOrCreateImport(payload.ast, {
2194
2199
  exportedName: "loadDictionary",
2195
- moduleName: "lingo.dev/react/rsc" /* ReactRSC */
2200
+ moduleName: ModuleId.ReactRSC
2196
2201
  });
2197
2202
  jsxScope.node.openingElement.attributes.push(
2198
2203
  t18.jsxAttribute(
@@ -2332,7 +2337,7 @@ var lingoJsxScopeInjectMutation = createCodeMutation((payload) => {
2332
2337
  if (skip) {
2333
2338
  continue;
2334
2339
  }
2335
- const packagePath = mode === "client" ? "lingo.dev/react/client" /* ReactClient */ : "lingo.dev/react/rsc" /* ReactRSC */;
2340
+ const packagePath = mode === "client" ? ModuleId.ReactClient : ModuleId.ReactRSC;
2336
2341
  const lingoComponentImport = getOrCreateImport(payload.ast, {
2337
2342
  moduleName: packagePath,
2338
2343
  exportedName: "LingoComponent"
@@ -2395,7 +2400,7 @@ var lingoJsxScopeInjectMutation = createCodeMutation((payload) => {
2395
2400
  if (mode === "server") {
2396
2401
  const loadDictionaryImport = getOrCreateImport(payload.ast, {
2397
2402
  exportedName: "loadDictionary",
2398
- moduleName: "lingo.dev/react/rsc" /* ReactRSC */
2403
+ moduleName: ModuleId.ReactRSC
2399
2404
  });
2400
2405
  originalAttributes.push(
2401
2406
  t22.jsxAttribute(
@@ -2460,7 +2465,7 @@ var jsxRemoveAttributesMutation = createCodeMutation(
2460
2465
 
2461
2466
  var clientDictionaryLoaderMutation = createCodeMutation((payload) => {
2462
2467
  const invokations = findInvokations(payload.ast, {
2463
- moduleName: "lingo.dev/react/client" /* ReactClient */,
2468
+ moduleName: ModuleId.ReactClient,
2464
2469
  functionName: "loadDictionary"
2465
2470
  });
2466
2471
  const allLocales = Array.from(
@@ -2468,7 +2473,7 @@ var clientDictionaryLoaderMutation = createCodeMutation((payload) => {
2468
2473
  );
2469
2474
  for (const invokation of invokations) {
2470
2475
  const internalDictionaryLoader = getOrCreateImport(payload.ast, {
2471
- moduleName: "lingo.dev/react/client" /* ReactClient */,
2476
+ moduleName: ModuleId.ReactClient,
2472
2477
  exportedName: "loadDictionary_internal"
2473
2478
  });
2474
2479
  if (t24.isIdentifier(invokation.callee)) {
package/build/index.mjs CHANGED
@@ -4,7 +4,7 @@ import { createUnplugin } from "unplugin";
4
4
  // package.json
5
5
  var package_default = {
6
6
  name: "@lingo.dev/_compiler",
7
- version: "0.2.3",
7
+ version: "0.2.4",
8
8
  description: "Lingo.dev Compiler",
9
9
  private: false,
10
10
  publishConfig: {
@@ -204,7 +204,7 @@ function findExistingImport(ast, exportedName, moduleName) {
204
204
  let result = null;
205
205
  traverse(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
  traverse6(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) => {
@@ -1805,7 +1810,7 @@ var rscDictionaryLoaderMutation = createCodeMutation((payload) => {
1805
1810
  return payload;
1806
1811
  }
1807
1812
  const invokations = findInvokations(payload.ast, {
1808
- moduleName: "lingo.dev/react/rsc" /* ReactRSC */,
1813
+ moduleName: ModuleId.ReactRSC,
1809
1814
  functionName: "loadDictionary"
1810
1815
  });
1811
1816
  const allLocales = Array.from(
@@ -1813,7 +1818,7 @@ var rscDictionaryLoaderMutation = createCodeMutation((payload) => {
1813
1818
  );
1814
1819
  for (const invokation of invokations) {
1815
1820
  const internalDictionaryLoader = getOrCreateImport(payload.ast, {
1816
- moduleName: "lingo.dev/react/rsc" /* ReactRSC */,
1821
+ moduleName: ModuleId.ReactRSC,
1817
1822
  exportedName: "loadDictionary_internal"
1818
1823
  });
1819
1824
  if (t13.isIdentifier(invokation.callee)) {
@@ -1839,7 +1844,7 @@ var reactRouterDictionaryLoaderMutation = createCodeMutation(
1839
1844
  return payload;
1840
1845
  }
1841
1846
  const invokations = findInvokations(payload.ast, {
1842
- moduleName: "lingo.dev/react/react-router" /* ReactRouter */,
1847
+ moduleName: ModuleId.ReactRouter,
1843
1848
  functionName: "loadDictionary"
1844
1849
  });
1845
1850
  const allLocales = Array.from(
@@ -1847,7 +1852,7 @@ var reactRouterDictionaryLoaderMutation = createCodeMutation(
1847
1852
  );
1848
1853
  for (const invokation of invokations) {
1849
1854
  const internalDictionaryLoader = getOrCreateImport(payload.ast, {
1850
- moduleName: "lingo.dev/react/react-router" /* ReactRouter */,
1855
+ moduleName: ModuleId.ReactRouter,
1851
1856
  exportedName: "loadDictionary_internal"
1852
1857
  });
1853
1858
  if (t14.isIdentifier(invokation.callee)) {
@@ -1889,7 +1894,7 @@ function jsxFragmentMutation(payload) {
1889
1894
  if (!fragmentImportName) {
1890
1895
  const result = getOrCreateImport(ast, {
1891
1896
  exportedName: "Fragment",
1892
- moduleName: "react"
1897
+ moduleName: ["react"]
1893
1898
  });
1894
1899
  fragmentImportName = result.importedName;
1895
1900
  }
@@ -1913,7 +1918,7 @@ var jsxHtmlLangMutation = createCodeMutation((payload) => {
1913
1918
  JSXElement: (path7) => {
1914
1919
  if (getJsxElementName(path7)?.toLowerCase() === "html") {
1915
1920
  const mode = getModuleExecutionMode(payload.ast, payload.params.rsc);
1916
- const packagePath = mode === "client" ? "lingo.dev/react/client" /* ReactClient */ : "lingo.dev/react/rsc" /* ReactRSC */;
1921
+ const packagePath = mode === "client" ? ModuleId.ReactClient : ModuleId.ReactRSC;
1917
1922
  const lingoHtmlComponentImport = getOrCreateImport(payload.ast, {
1918
1923
  moduleName: packagePath,
1919
1924
  exportedName: "LingoHtmlComponent"
@@ -2146,7 +2151,7 @@ var lingoJsxAttributeScopeInjectMutation = createCodeMutation(
2146
2151
  const mode = getModuleExecutionMode(payload.ast, payload.params.rsc);
2147
2152
  const jsxAttributeScopes = collectJsxAttributeScopes(payload.ast);
2148
2153
  for (const [jsxScope, attributes] of jsxAttributeScopes) {
2149
- const packagePath = mode === "client" ? "lingo.dev/react/client" /* ReactClient */ : "lingo.dev/react/rsc" /* ReactRSC */;
2154
+ const packagePath = mode === "client" ? ModuleId.ReactClient : ModuleId.ReactRSC;
2150
2155
  const lingoComponentImport = getOrCreateImport(payload.ast, {
2151
2156
  moduleName: packagePath,
2152
2157
  exportedName: "LingoAttributeComponent"
@@ -2192,7 +2197,7 @@ var lingoJsxAttributeScopeInjectMutation = createCodeMutation(
2192
2197
  if (mode === "server") {
2193
2198
  const loadDictionaryImport = getOrCreateImport(payload.ast, {
2194
2199
  exportedName: "loadDictionary",
2195
- moduleName: "lingo.dev/react/rsc" /* ReactRSC */
2200
+ moduleName: ModuleId.ReactRSC
2196
2201
  });
2197
2202
  jsxScope.node.openingElement.attributes.push(
2198
2203
  t18.jsxAttribute(
@@ -2332,7 +2337,7 @@ var lingoJsxScopeInjectMutation = createCodeMutation((payload) => {
2332
2337
  if (skip) {
2333
2338
  continue;
2334
2339
  }
2335
- const packagePath = mode === "client" ? "lingo.dev/react/client" /* ReactClient */ : "lingo.dev/react/rsc" /* ReactRSC */;
2340
+ const packagePath = mode === "client" ? ModuleId.ReactClient : ModuleId.ReactRSC;
2336
2341
  const lingoComponentImport = getOrCreateImport(payload.ast, {
2337
2342
  moduleName: packagePath,
2338
2343
  exportedName: "LingoComponent"
@@ -2395,7 +2400,7 @@ var lingoJsxScopeInjectMutation = createCodeMutation((payload) => {
2395
2400
  if (mode === "server") {
2396
2401
  const loadDictionaryImport = getOrCreateImport(payload.ast, {
2397
2402
  exportedName: "loadDictionary",
2398
- moduleName: "lingo.dev/react/rsc" /* ReactRSC */
2403
+ moduleName: ModuleId.ReactRSC
2399
2404
  });
2400
2405
  originalAttributes.push(
2401
2406
  t22.jsxAttribute(
@@ -2460,7 +2465,7 @@ var jsxRemoveAttributesMutation = createCodeMutation(
2460
2465
  import * as t24 from "@babel/types";
2461
2466
  var clientDictionaryLoaderMutation = createCodeMutation((payload) => {
2462
2467
  const invokations = findInvokations(payload.ast, {
2463
- moduleName: "lingo.dev/react/client" /* ReactClient */,
2468
+ moduleName: ModuleId.ReactClient,
2464
2469
  functionName: "loadDictionary"
2465
2470
  });
2466
2471
  const allLocales = Array.from(
@@ -2468,7 +2473,7 @@ var clientDictionaryLoaderMutation = createCodeMutation((payload) => {
2468
2473
  );
2469
2474
  for (const invokation of invokations) {
2470
2475
  const internalDictionaryLoader = getOrCreateImport(payload.ast, {
2471
- moduleName: "lingo.dev/react/client" /* ReactClient */,
2476
+ moduleName: ModuleId.ReactClient,
2472
2477
  exportedName: "loadDictionary_internal"
2473
2478
  });
2474
2479
  if (t24.isIdentifier(invokation.callee)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingo.dev/_compiler",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Lingo.dev Compiler",
5
5
  "private": false,
6
6
  "publishConfig": {