@lingo.dev/_compiler 0.1.1 → 0.1.2

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.1.1",
7
+ version: "0.1.2",
8
8
  description: "Lingo.dev Compiler",
9
9
  private: false,
10
10
  publishConfig: {
@@ -43,7 +43,7 @@ var package_default = {
43
43
  "@ai-sdk/groq": "^1.2.3",
44
44
  "@babel/generator": "^7.26.5",
45
45
  "@babel/parser": "^7.26.7",
46
- "@babel/traverse": "^7.26.7",
46
+ "@babel/traverse": "^7.27.4",
47
47
  "@babel/types": "^7.26.7",
48
48
  ai: "^4.2.10",
49
49
  dedent: "^1.6.0",
@@ -350,7 +350,7 @@ var LCP_DICTIONARY_FILE_NAME = "dictionary.js";
350
350
  var jsxProviderMutation = createCodeMutation((payload) => {
351
351
  _traverse2.default.call(void 0, payload.ast, {
352
352
  JSXElement: (path6) => {
353
- if (_optionalChain([getJsxElementName, 'call', _13 => _13(path6), 'optionalAccess', _14 => _14.toLowerCase, 'call', _15 => _15()]) === "html") {
353
+ if (_optionalChain([getJsxElementName, 'call', _12 => _12(path6), 'optionalAccess', _13 => _13.toLowerCase, 'call', _14 => _14()]) === "html") {
354
354
  const mode = getModuleExecutionMode(payload.ast, payload.params.rsc);
355
355
  if (mode === "client") {
356
356
  return;
@@ -423,7 +423,7 @@ function getAstKey(nodePath) {
423
423
  while (current) {
424
424
  keyChunks.push(current.key);
425
425
  current = current.parentPath;
426
- if (t6.isProgram(_optionalChain([current, 'optionalAccess', _16 => _16.node]))) {
426
+ if (t6.isProgram(_optionalChain([current, 'optionalAccess', _15 => _15.node]))) {
427
427
  break;
428
428
  }
429
429
  }
@@ -693,10 +693,10 @@ var LCP = class _LCP {
693
693
  return this._setScopeField(fileKey, scopeKey, "content", content);
694
694
  }
695
695
  toJSON() {
696
- const files = _lodash2.default.call(void 0, _optionalChain([this, 'access', _17 => _17.data, 'optionalAccess', _18 => _18.files])).mapValues((file, fileName) => {
696
+ const files = _lodash2.default.call(void 0, _optionalChain([this, 'access', _16 => _16.data, 'optionalAccess', _17 => _17.files])).mapValues((file, fileName) => {
697
697
  return {
698
698
  ...file,
699
- scopes: _lodash2.default.call(void 0, _optionalChain([file, 'optionalAccess', _19 => _19.scopes])).toPairs().sortBy([0]).fromPairs().value()
699
+ scopes: _lodash2.default.call(void 0, _optionalChain([file, 'optionalAccess', _18 => _18.scopes])).toPairs().sortBy([0]).fromPairs().value()
700
700
  };
701
701
  }).toPairs().sortBy([0]).fromPairs().value();
702
702
  return { ...this.data, files };
@@ -831,7 +831,7 @@ var LCPCache = class {
831
831
  const config2 = await prettier.resolveConfig(cachePath);
832
832
  const prettierOptions = {
833
833
  ..._nullishCoalesce(config2, () => ( {})),
834
- parser: _optionalChain([config2, 'optionalAccess', _20 => _20.parser]) ? config2.parser : "typescript"
834
+ parser: _optionalChain([config2, 'optionalAccess', _19 => _19.parser]) ? config2.parser : "typescript"
835
835
  };
836
836
  return await prettier.format(cachedContent, prettierOptions);
837
837
  } catch (error) {
@@ -895,7 +895,7 @@ function getLocaleModel(localeModels, sourceLocale, targetLocale) {
895
895
  ];
896
896
  const modelKey = localeKeys.find((key) => localeModels.hasOwnProperty(key));
897
897
  if (modelKey) {
898
- const [provider, model] = _optionalChain([localeModels, 'access', _21 => _21[modelKey], 'optionalAccess', _22 => _22.split, 'call', _23 => _23(":")]);
898
+ const [provider, model] = _optionalChain([localeModels, 'access', _20 => _20[modelKey], 'optionalAccess', _21 => _21.split, 'call', _22 => _22(":")]);
899
899
  if (provider && model) {
900
900
  return { provider, model };
901
901
  }
@@ -908,7 +908,7 @@ var prompt_default = (args) => {
908
908
  return getUserSystemPrompt(args) || getBuiltInSystemPrompt(args);
909
909
  };
910
910
  function getUserSystemPrompt(args) {
911
- const userPrompt = _optionalChain([args, 'access', _24 => _24.prompt, 'optionalAccess', _25 => _25.trim, 'call', _26 => _26(), 'optionalAccess', _27 => _27.replace, 'call', _28 => _28("{SOURCE_LOCALE}", args.sourceLocale), 'optionalAccess', _29 => _29.replace, 'call', _30 => _30("{TARGET_LOCALE}", args.targetLocale)]);
911
+ const userPrompt = _optionalChain([args, 'access', _23 => _23.prompt, 'optionalAccess', _24 => _24.trim, 'call', _25 => _25(), 'optionalAccess', _26 => _26.replace, 'call', _27 => _27("{SOURCE_LOCALE}", args.sourceLocale), 'optionalAccess', _28 => _28.replace, 'call', _29 => _29("{TARGET_LOCALE}", args.targetLocale)]);
912
912
  if (userPrompt) {
913
913
  console.log("\u2728 Compiler is using user-defined prompt.");
914
914
  return userPrompt;
@@ -1515,12 +1515,12 @@ var LCPServer = (_class = class {
1515
1515
  const files = _lodash2.default.call(void 0, fileNames).map((fileName) => {
1516
1516
  const sourceFile = _lodash2.default.get(sourceDictionary.files, fileName);
1517
1517
  const targetFile = _lodash2.default.get(targetDictionary.files, fileName);
1518
- const entries = removeEmptyEntries ? _lodash2.default.pickBy(_optionalChain([sourceFile, 'optionalAccess', _31 => _31.entries]), (value) => value.trim().length > 0) : _optionalChain([sourceFile, 'optionalAccess', _32 => _32.entries]);
1518
+ const entries = removeEmptyEntries ? _lodash2.default.pickBy(_optionalChain([sourceFile, 'optionalAccess', _30 => _30.entries]), (value) => value.trim().length > 0) : _optionalChain([sourceFile, 'optionalAccess', _31 => _31.entries]);
1519
1519
  return [
1520
1520
  fileName,
1521
1521
  {
1522
1522
  ...targetFile,
1523
- entries: _lodash2.default.merge(_optionalChain([targetFile, 'optionalAccess', _33 => _33.entries]), entries)
1523
+ entries: _lodash2.default.merge(_optionalChain([targetFile, 'optionalAccess', _32 => _32.entries]), entries)
1524
1524
  }
1525
1525
  ];
1526
1526
  }).fromPairs().value();
@@ -1712,7 +1712,7 @@ function jsxFragmentMutation(payload) {
1712
1712
  var jsxHtmlLangMutation = createCodeMutation((payload) => {
1713
1713
  _traverse2.default.call(void 0, payload.ast, {
1714
1714
  JSXElement: (path6) => {
1715
- if (_optionalChain([getJsxElementName, 'call', _34 => _34(path6), 'optionalAccess', _35 => _35.toLowerCase, 'call', _36 => _36()]) === "html") {
1715
+ if (_optionalChain([getJsxElementName, 'call', _33 => _33(path6), 'optionalAccess', _34 => _34.toLowerCase, 'call', _35 => _35()]) === "html") {
1716
1716
  const mode = getModuleExecutionMode(payload.ast, payload.params.rsc);
1717
1717
  const packagePath = mode === "client" ? "lingo.dev/react/client" /* ReactClient */ : "lingo.dev/react/rsc" /* ReactRSC */;
1718
1718
  const lingoHtmlComponentImport = getOrCreateImport(payload.ast, {
@@ -2006,7 +2006,6 @@ var lingoJsxAttributeScopeInjectMutation = createCodeMutation(
2006
2006
  // src/jsx-scope-inject.ts
2007
2007
 
2008
2008
 
2009
-
2010
2009
  // src/utils/jsx-variables.ts
2011
2010
 
2012
2011
  var getJsxVariables = (nodePath) => {
@@ -2127,66 +2126,55 @@ var lingoJsxScopeInjectMutation = createCodeMutation((payload) => {
2127
2126
  moduleName: packagePath,
2128
2127
  exportedName: "LingoComponent"
2129
2128
  });
2130
- const originalJsxScope = _lodash2.default.cloneDeep(jsxScope);
2131
2129
  const originalJsxElementName = getJsxElementName(jsxScope);
2132
2130
  if (!originalJsxElementName) {
2133
2131
  continue;
2134
2132
  }
2135
- jsxScope.node.openingElement.name = t21.jsxIdentifier(
2136
- lingoComponentImport.importedName
2137
- );
2138
- if (jsxScope.node.closingElement) {
2139
- jsxScope.node.closingElement = null;
2140
- jsxScope.node.children = [];
2141
- jsxScope.node.selfClosing = true;
2142
- jsxScope.node.openingElement.selfClosing = true;
2143
- }
2133
+ const originalAttributes = jsxScope.node.openingElement.attributes.slice();
2144
2134
  const as = /^[A-Z]/.test(originalJsxElementName) ? t21.jsxExpressionContainer(t21.identifier(originalJsxElementName)) : t21.stringLiteral(originalJsxElementName);
2145
- jsxScope.node.openingElement.attributes.push(
2146
- t21.jsxAttribute(t21.jsxIdentifier("$as"), as)
2147
- );
2148
- jsxScope.node.openingElement.attributes.push(
2135
+ originalAttributes.push(t21.jsxAttribute(t21.jsxIdentifier("$as"), as));
2136
+ originalAttributes.push(
2149
2137
  t21.jsxAttribute(
2150
2138
  t21.jsxIdentifier("$fileKey"),
2151
2139
  t21.stringLiteral(payload.fileKey)
2152
2140
  )
2153
2141
  );
2154
- jsxScope.node.openingElement.attributes.push(
2142
+ originalAttributes.push(
2155
2143
  t21.jsxAttribute(
2156
2144
  t21.jsxIdentifier("$entryKey"),
2157
2145
  t21.stringLiteral(getJsxScopeAttribute(jsxScope))
2158
2146
  )
2159
2147
  );
2160
- const $variables = getJsxVariables(originalJsxScope);
2148
+ const $variables = getJsxVariables(jsxScope);
2161
2149
  if ($variables.properties.length > 0) {
2162
- jsxScope.node.openingElement.attributes.push(
2150
+ originalAttributes.push(
2163
2151
  t21.jsxAttribute(
2164
2152
  t21.jsxIdentifier("$variables"),
2165
2153
  t21.jsxExpressionContainer($variables)
2166
2154
  )
2167
2155
  );
2168
2156
  }
2169
- const $elements = getNestedJsxElements(originalJsxScope);
2157
+ const $elements = getNestedJsxElements(jsxScope);
2170
2158
  if ($elements.elements.length > 0) {
2171
- jsxScope.node.openingElement.attributes.push(
2159
+ originalAttributes.push(
2172
2160
  t21.jsxAttribute(
2173
2161
  t21.jsxIdentifier("$elements"),
2174
2162
  t21.jsxExpressionContainer($elements)
2175
2163
  )
2176
2164
  );
2177
2165
  }
2178
- const $functions = getJsxFunctions(originalJsxScope);
2166
+ const $functions = getJsxFunctions(jsxScope);
2179
2167
  if ($functions.properties.length > 0) {
2180
- jsxScope.node.openingElement.attributes.push(
2168
+ originalAttributes.push(
2181
2169
  t21.jsxAttribute(
2182
2170
  t21.jsxIdentifier("$functions"),
2183
2171
  t21.jsxExpressionContainer($functions)
2184
2172
  )
2185
2173
  );
2186
2174
  }
2187
- const $expressions = getJsxExpressions(originalJsxScope);
2175
+ const $expressions = getJsxExpressions(jsxScope);
2188
2176
  if ($expressions.elements.length > 0) {
2189
- jsxScope.node.openingElement.attributes.push(
2177
+ originalAttributes.push(
2190
2178
  t21.jsxAttribute(
2191
2179
  t21.jsxIdentifier("$expressions"),
2192
2180
  t21.jsxExpressionContainer($expressions)
@@ -2198,7 +2186,7 @@ var lingoJsxScopeInjectMutation = createCodeMutation((payload) => {
2198
2186
  exportedName: "loadDictionary",
2199
2187
  moduleName: "lingo.dev/react/rsc" /* ReactRSC */
2200
2188
  });
2201
- jsxScope.node.openingElement.attributes.push(
2189
+ originalAttributes.push(
2202
2190
  t21.jsxAttribute(
2203
2191
  t21.jsxIdentifier("$loadDictionary"),
2204
2192
  t21.jsxExpressionContainer(
@@ -2213,6 +2201,21 @@ var lingoJsxScopeInjectMutation = createCodeMutation((payload) => {
2213
2201
  )
2214
2202
  );
2215
2203
  }
2204
+ const newNode = t21.jsxElement(
2205
+ t21.jsxOpeningElement(
2206
+ t21.jsxIdentifier(lingoComponentImport.importedName),
2207
+ originalAttributes,
2208
+ true
2209
+ // selfClosing
2210
+ ),
2211
+ null,
2212
+ // no closing element
2213
+ [],
2214
+ // no children
2215
+ true
2216
+ // selfClosing
2217
+ );
2218
+ jsxScope.replaceWith(newNode);
2216
2219
  }
2217
2220
  return payload;
2218
2221
  });
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.1.1",
7
+ version: "0.1.2",
8
8
  description: "Lingo.dev Compiler",
9
9
  private: false,
10
10
  publishConfig: {
@@ -43,7 +43,7 @@ var package_default = {
43
43
  "@ai-sdk/groq": "^1.2.3",
44
44
  "@babel/generator": "^7.26.5",
45
45
  "@babel/parser": "^7.26.7",
46
- "@babel/traverse": "^7.26.7",
46
+ "@babel/traverse": "^7.27.4",
47
47
  "@babel/types": "^7.26.7",
48
48
  ai: "^4.2.10",
49
49
  dedent: "^1.6.0",
@@ -60,7 +60,7 @@ var package_default = {
60
60
  };
61
61
 
62
62
  // src/index.ts
63
- import _12 from "lodash";
63
+ import _11 from "lodash";
64
64
  import dedent2 from "dedent";
65
65
 
66
66
  // src/_base.ts
@@ -2005,7 +2005,6 @@ var lingoJsxAttributeScopeInjectMutation = createCodeMutation(
2005
2005
 
2006
2006
  // src/jsx-scope-inject.ts
2007
2007
  import * as t21 from "@babel/types";
2008
- import _11 from "lodash";
2009
2008
 
2010
2009
  // src/utils/jsx-variables.ts
2011
2010
  import * as t18 from "@babel/types";
@@ -2127,66 +2126,55 @@ var lingoJsxScopeInjectMutation = createCodeMutation((payload) => {
2127
2126
  moduleName: packagePath,
2128
2127
  exportedName: "LingoComponent"
2129
2128
  });
2130
- const originalJsxScope = _11.cloneDeep(jsxScope);
2131
2129
  const originalJsxElementName = getJsxElementName(jsxScope);
2132
2130
  if (!originalJsxElementName) {
2133
2131
  continue;
2134
2132
  }
2135
- jsxScope.node.openingElement.name = t21.jsxIdentifier(
2136
- lingoComponentImport.importedName
2137
- );
2138
- if (jsxScope.node.closingElement) {
2139
- jsxScope.node.closingElement = null;
2140
- jsxScope.node.children = [];
2141
- jsxScope.node.selfClosing = true;
2142
- jsxScope.node.openingElement.selfClosing = true;
2143
- }
2133
+ const originalAttributes = jsxScope.node.openingElement.attributes.slice();
2144
2134
  const as = /^[A-Z]/.test(originalJsxElementName) ? t21.jsxExpressionContainer(t21.identifier(originalJsxElementName)) : t21.stringLiteral(originalJsxElementName);
2145
- jsxScope.node.openingElement.attributes.push(
2146
- t21.jsxAttribute(t21.jsxIdentifier("$as"), as)
2147
- );
2148
- jsxScope.node.openingElement.attributes.push(
2135
+ originalAttributes.push(t21.jsxAttribute(t21.jsxIdentifier("$as"), as));
2136
+ originalAttributes.push(
2149
2137
  t21.jsxAttribute(
2150
2138
  t21.jsxIdentifier("$fileKey"),
2151
2139
  t21.stringLiteral(payload.fileKey)
2152
2140
  )
2153
2141
  );
2154
- jsxScope.node.openingElement.attributes.push(
2142
+ originalAttributes.push(
2155
2143
  t21.jsxAttribute(
2156
2144
  t21.jsxIdentifier("$entryKey"),
2157
2145
  t21.stringLiteral(getJsxScopeAttribute(jsxScope))
2158
2146
  )
2159
2147
  );
2160
- const $variables = getJsxVariables(originalJsxScope);
2148
+ const $variables = getJsxVariables(jsxScope);
2161
2149
  if ($variables.properties.length > 0) {
2162
- jsxScope.node.openingElement.attributes.push(
2150
+ originalAttributes.push(
2163
2151
  t21.jsxAttribute(
2164
2152
  t21.jsxIdentifier("$variables"),
2165
2153
  t21.jsxExpressionContainer($variables)
2166
2154
  )
2167
2155
  );
2168
2156
  }
2169
- const $elements = getNestedJsxElements(originalJsxScope);
2157
+ const $elements = getNestedJsxElements(jsxScope);
2170
2158
  if ($elements.elements.length > 0) {
2171
- jsxScope.node.openingElement.attributes.push(
2159
+ originalAttributes.push(
2172
2160
  t21.jsxAttribute(
2173
2161
  t21.jsxIdentifier("$elements"),
2174
2162
  t21.jsxExpressionContainer($elements)
2175
2163
  )
2176
2164
  );
2177
2165
  }
2178
- const $functions = getJsxFunctions(originalJsxScope);
2166
+ const $functions = getJsxFunctions(jsxScope);
2179
2167
  if ($functions.properties.length > 0) {
2180
- jsxScope.node.openingElement.attributes.push(
2168
+ originalAttributes.push(
2181
2169
  t21.jsxAttribute(
2182
2170
  t21.jsxIdentifier("$functions"),
2183
2171
  t21.jsxExpressionContainer($functions)
2184
2172
  )
2185
2173
  );
2186
2174
  }
2187
- const $expressions = getJsxExpressions(originalJsxScope);
2175
+ const $expressions = getJsxExpressions(jsxScope);
2188
2176
  if ($expressions.elements.length > 0) {
2189
- jsxScope.node.openingElement.attributes.push(
2177
+ originalAttributes.push(
2190
2178
  t21.jsxAttribute(
2191
2179
  t21.jsxIdentifier("$expressions"),
2192
2180
  t21.jsxExpressionContainer($expressions)
@@ -2198,7 +2186,7 @@ var lingoJsxScopeInjectMutation = createCodeMutation((payload) => {
2198
2186
  exportedName: "loadDictionary",
2199
2187
  moduleName: "lingo.dev/react/rsc" /* ReactRSC */
2200
2188
  });
2201
- jsxScope.node.openingElement.attributes.push(
2189
+ originalAttributes.push(
2202
2190
  t21.jsxAttribute(
2203
2191
  t21.jsxIdentifier("$loadDictionary"),
2204
2192
  t21.jsxExpressionContainer(
@@ -2213,6 +2201,21 @@ var lingoJsxScopeInjectMutation = createCodeMutation((payload) => {
2213
2201
  )
2214
2202
  );
2215
2203
  }
2204
+ const newNode = t21.jsxElement(
2205
+ t21.jsxOpeningElement(
2206
+ t21.jsxIdentifier(lingoComponentImport.importedName),
2207
+ originalAttributes,
2208
+ true
2209
+ // selfClosing
2210
+ ),
2211
+ null,
2212
+ // no closing element
2213
+ [],
2214
+ // no children
2215
+ true
2216
+ // selfClosing
2217
+ );
2218
+ jsxScope.replaceWith(newNode);
2216
2219
  }
2217
2220
  return payload;
2218
2221
  });
@@ -2297,7 +2300,7 @@ var unplugin = createUnplugin(
2297
2300
  if (!isRunningInCIOrDocker()) {
2298
2301
  validateGroqKeyDetails();
2299
2302
  }
2300
- const params = _12.defaults(_params, defaultParams);
2303
+ const params = _11.defaults(_params, defaultParams);
2301
2304
  const invalidLocales = getInvalidLocales(
2302
2305
  params.models,
2303
2306
  params.sourceLocale,
@@ -2349,7 +2352,7 @@ var unplugin = createUnplugin(
2349
2352
  enforce: "pre",
2350
2353
  transform(code, id) {
2351
2354
  try {
2352
- const result = _12.chain({
2355
+ const result = _11.chain({
2353
2356
  code,
2354
2357
  params,
2355
2358
  fileKey: path5.relative(
@@ -2398,7 +2401,7 @@ var src_default = {
2398
2401
  webpack: (config2, { isServer }) => {
2399
2402
  config2.plugins.push(
2400
2403
  unplugin.webpack(
2401
- _12.merge({}, defaultParams, { rsc: true }, compilerParams)
2404
+ _11.merge({}, defaultParams, { rsc: true }, compilerParams)
2402
2405
  )
2403
2406
  );
2404
2407
  return config2;
@@ -2406,7 +2409,7 @@ var src_default = {
2406
2409
  }),
2407
2410
  vite: (compilerParams) => (config2) => {
2408
2411
  config2.plugins.push(
2409
- unplugin.vite(_12.merge({}, defaultParams, { rsc: false }, compilerParams))
2412
+ unplugin.vite(_11.merge({}, defaultParams, { rsc: false }, compilerParams))
2410
2413
  );
2411
2414
  return config2;
2412
2415
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingo.dev/_compiler",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Lingo.dev Compiler",
5
5
  "private": false,
6
6
  "publishConfig": {
@@ -32,7 +32,7 @@
32
32
  "@ai-sdk/groq": "^1.2.3",
33
33
  "@babel/generator": "^7.26.5",
34
34
  "@babel/parser": "^7.26.7",
35
- "@babel/traverse": "^7.26.7",
35
+ "@babel/traverse": "^7.27.4",
36
36
  "@babel/types": "^7.26.7",
37
37
  "ai": "^4.2.10",
38
38
  "dedent": "^1.6.0",