@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.
- package/build/index.cjs +177 -170
- package/build/index.mjs +187 -180
- package/package.json +1 -1
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.
|
|
7
|
+
version: "0.2.3",
|
|
8
8
|
description: "Lingo.dev Compiler",
|
|
9
9
|
private: false,
|
|
10
10
|
publishConfig: {
|
|
@@ -1766,7 +1766,39 @@ function collectCallExpressions(path7, importNames, result, functionName) {
|
|
|
1766
1766
|
}
|
|
1767
1767
|
|
|
1768
1768
|
// src/rsc-dictionary-loader.ts
|
|
1769
|
+
import * as t13 from "@babel/types";
|
|
1770
|
+
|
|
1771
|
+
// src/_utils.ts
|
|
1772
|
+
import path5 from "path";
|
|
1773
|
+
var getDictionaryPath = (params) => {
|
|
1774
|
+
const absolute = path5.resolve(
|
|
1775
|
+
params.sourceRoot,
|
|
1776
|
+
params.lingoDir,
|
|
1777
|
+
LCP_DICTIONARY_FILE_NAME
|
|
1778
|
+
);
|
|
1779
|
+
const rel = path5.relative(params.relativeFilePath, absolute);
|
|
1780
|
+
return rel.split(path5.sep).join(path5.posix.sep);
|
|
1781
|
+
};
|
|
1782
|
+
|
|
1783
|
+
// src/utils/create-locale-import-map.ts
|
|
1769
1784
|
import * as t12 from "@babel/types";
|
|
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,31 +1816,22 @@ var rscDictionaryLoaderMutation = createCodeMutation((payload) => {
|
|
|
1784
1816
|
moduleName: "lingo.dev/react/rsc" /* ReactRSC */,
|
|
1785
1817
|
exportedName: "loadDictionary_internal"
|
|
1786
1818
|
});
|
|
1787
|
-
if (
|
|
1819
|
+
if (t13.isIdentifier(invokation.callee)) {
|
|
1788
1820
|
invokation.callee.name = internalDictionaryLoader.importedName;
|
|
1789
1821
|
}
|
|
1790
|
-
const
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
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;
|
|
1808
1831
|
});
|
|
1809
1832
|
|
|
1810
1833
|
// src/react-router-dictionary-loader.ts
|
|
1811
|
-
import * as
|
|
1834
|
+
import * as t14 from "@babel/types";
|
|
1812
1835
|
var reactRouterDictionaryLoaderMutation = createCodeMutation(
|
|
1813
1836
|
(payload) => {
|
|
1814
1837
|
const mode = getModuleExecutionMode(payload.ast, payload.params.rsc);
|
|
@@ -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 (
|
|
1853
|
+
if (t14.isIdentifier(invokation.callee)) {
|
|
1831
1854
|
invokation.callee.name = internalDictionaryLoader.importedName;
|
|
1832
1855
|
}
|
|
1833
|
-
const
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
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;
|
|
@@ -1853,7 +1867,7 @@ var reactRouterDictionaryLoaderMutation = createCodeMutation(
|
|
|
1853
1867
|
|
|
1854
1868
|
// src/jsx-fragment.ts
|
|
1855
1869
|
import traverse7 from "@babel/traverse";
|
|
1856
|
-
import * as
|
|
1870
|
+
import * as t15 from "@babel/types";
|
|
1857
1871
|
function jsxFragmentMutation(payload) {
|
|
1858
1872
|
const { ast } = payload;
|
|
1859
1873
|
let foundFragments = false;
|
|
@@ -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 (
|
|
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 =
|
|
1883
|
-
|
|
1884
|
-
|
|
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
|
);
|
|
@@ -1893,7 +1907,7 @@ function jsxFragmentMutation(payload) {
|
|
|
1893
1907
|
|
|
1894
1908
|
// src/jsx-html-lang.ts
|
|
1895
1909
|
import traverse8 from "@babel/traverse";
|
|
1896
|
-
import * as
|
|
1910
|
+
import * as t16 from "@babel/types";
|
|
1897
1911
|
var jsxHtmlLangMutation = createCodeMutation((payload) => {
|
|
1898
1912
|
traverse8(payload.ast, {
|
|
1899
1913
|
JSXElement: (path7) => {
|
|
@@ -1904,11 +1918,11 @@ var jsxHtmlLangMutation = createCodeMutation((payload) => {
|
|
|
1904
1918
|
moduleName: packagePath,
|
|
1905
1919
|
exportedName: "LingoHtmlComponent"
|
|
1906
1920
|
});
|
|
1907
|
-
path7.node.openingElement.name =
|
|
1921
|
+
path7.node.openingElement.name = t16.jsxIdentifier(
|
|
1908
1922
|
lingoHtmlComponentImport.importedName
|
|
1909
1923
|
);
|
|
1910
1924
|
if (path7.node.closingElement) {
|
|
1911
|
-
path7.node.closingElement.name =
|
|
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.
|
|
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.
|
|
1973
|
+
lcp.setScopeType(payload.relativeFilePath, scopeKey, "attribute");
|
|
1960
1974
|
const hash = getJsxAttributeValueHash(String(attributeValue));
|
|
1961
|
-
lcp.setScopeHash(payload.
|
|
1962
|
-
lcp.setScopeContext(payload.
|
|
1963
|
-
lcp.setScopeSkip(payload.
|
|
1964
|
-
lcp.setScopeOverrides(payload.
|
|
1965
|
-
lcp.setScopeContent(
|
|
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();
|
|
@@ -1973,7 +1991,7 @@ function jsxAttributeScopesExportMutation(payload) {
|
|
|
1973
1991
|
import _10 from "lodash";
|
|
1974
1992
|
|
|
1975
1993
|
// src/utils/jsx-content.ts
|
|
1976
|
-
import * as
|
|
1994
|
+
import * as t17 from "@babel/types";
|
|
1977
1995
|
import _9 from "lodash";
|
|
1978
1996
|
var WHITESPACE_PLACEHOLDER = "[lingo-whitespace-placeholder]";
|
|
1979
1997
|
function extractJsxContent(nodePath, replaceWhitespacePlaceholders = true) {
|
|
@@ -1995,39 +2013,39 @@ function extractJsxContent(nodePath, replaceWhitespacePlaceholders = true) {
|
|
|
1995
2013
|
return;
|
|
1996
2014
|
}
|
|
1997
2015
|
const expr = path7.node.expression;
|
|
1998
|
-
if (
|
|
2016
|
+
if (t17.isCallExpression(expr)) {
|
|
1999
2017
|
let key = "";
|
|
2000
|
-
if (
|
|
2018
|
+
if (t17.isIdentifier(expr.callee)) {
|
|
2001
2019
|
key = `${expr.callee.name}`;
|
|
2002
|
-
} else if (
|
|
2020
|
+
} else if (t17.isMemberExpression(expr.callee)) {
|
|
2003
2021
|
let firstCallee = expr.callee;
|
|
2004
|
-
while (
|
|
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 (
|
|
2010
|
-
if (
|
|
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 (
|
|
2033
|
+
if (t17.isIdentifier(current)) {
|
|
2016
2034
|
parts.unshift(current.name);
|
|
2017
2035
|
}
|
|
2018
|
-
if (
|
|
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 (
|
|
2042
|
+
} else if (t17.isIdentifier(expr)) {
|
|
2025
2043
|
chunks.push(`{${expr.name}}`);
|
|
2026
|
-
} else if (
|
|
2044
|
+
} else if (t17.isMemberExpression(expr)) {
|
|
2027
2045
|
let current = expr;
|
|
2028
2046
|
const parts = [];
|
|
2029
|
-
while (
|
|
2030
|
-
if (
|
|
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 (
|
|
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 = !_9.isArray(nodePath.container) &&
|
|
2061
|
-
return !isCompilerExpression && !
|
|
2078
|
+
const isCompilerExpression = !_9.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
|
|
2083
|
+
return t17.isStringLiteral(expr) && expr.value === " ";
|
|
2066
2084
|
}
|
|
2067
2085
|
function normalizeJsxWhitespace(input) {
|
|
2068
2086
|
const lines = input.split("\n");
|
|
@@ -2093,28 +2111,36 @@ function jsxScopesExportMutation(payload) {
|
|
|
2093
2111
|
});
|
|
2094
2112
|
for (const scope of scopes) {
|
|
2095
2113
|
const scopeKey = getAstKey(scope);
|
|
2096
|
-
lcp.resetScope(payload.
|
|
2097
|
-
lcp.setScopeType(payload.
|
|
2114
|
+
lcp.resetScope(payload.relativeFilePath, scopeKey);
|
|
2115
|
+
lcp.setScopeType(payload.relativeFilePath, scopeKey, "element");
|
|
2098
2116
|
const hash = getJsxElementHash(scope);
|
|
2099
|
-
lcp.setScopeHash(payload.
|
|
2117
|
+
lcp.setScopeHash(payload.relativeFilePath, scopeKey, hash);
|
|
2100
2118
|
const context = getJsxAttributeValue(scope, "data-lingo-context");
|
|
2101
|
-
lcp.setScopeContext(
|
|
2119
|
+
lcp.setScopeContext(
|
|
2120
|
+
payload.relativeFilePath,
|
|
2121
|
+
scopeKey,
|
|
2122
|
+
String(context || "")
|
|
2123
|
+
);
|
|
2102
2124
|
const skip = getJsxAttributeValue(scope, "data-lingo-skip");
|
|
2103
|
-
lcp.setScopeSkip(
|
|
2125
|
+
lcp.setScopeSkip(
|
|
2126
|
+
payload.relativeFilePath,
|
|
2127
|
+
scopeKey,
|
|
2128
|
+
Boolean(skip || false)
|
|
2129
|
+
);
|
|
2104
2130
|
const attributesMap = getJsxAttributesMap(scope);
|
|
2105
2131
|
const overrides = _10.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.
|
|
2134
|
+
lcp.setScopeOverrides(payload.relativeFilePath, scopeKey, overrides);
|
|
2109
2135
|
const content = extractJsxContent(scope);
|
|
2110
|
-
lcp.setScopeContent(payload.
|
|
2136
|
+
lcp.setScopeContent(payload.relativeFilePath, scopeKey, content);
|
|
2111
2137
|
}
|
|
2112
2138
|
lcp.save();
|
|
2113
2139
|
return payload;
|
|
2114
2140
|
}
|
|
2115
2141
|
|
|
2116
2142
|
// src/jsx-attribute-scope-inject.ts
|
|
2117
|
-
import * as
|
|
2143
|
+
import * as t18 from "@babel/types";
|
|
2118
2144
|
var lingoJsxAttributeScopeInjectMutation = createCodeMutation(
|
|
2119
2145
|
(payload) => {
|
|
2120
2146
|
const mode = getModuleExecutionMode(payload.ast, payload.params.rsc);
|
|
@@ -2129,34 +2155,34 @@ var lingoJsxAttributeScopeInjectMutation = createCodeMutation(
|
|
|
2129
2155
|
if (!originalJsxElementName) {
|
|
2130
2156
|
continue;
|
|
2131
2157
|
}
|
|
2132
|
-
jsxScope.node.openingElement.name =
|
|
2158
|
+
jsxScope.node.openingElement.name = t18.jsxIdentifier(
|
|
2133
2159
|
lingoComponentImport.importedName
|
|
2134
2160
|
);
|
|
2135
2161
|
if (jsxScope.node.closingElement) {
|
|
2136
|
-
jsxScope.node.closingElement.name =
|
|
2162
|
+
jsxScope.node.closingElement.name = t18.jsxIdentifier(
|
|
2137
2163
|
lingoComponentImport.importedName
|
|
2138
2164
|
);
|
|
2139
2165
|
}
|
|
2140
|
-
const as = /^[A-Z]/.test(originalJsxElementName) ?
|
|
2166
|
+
const as = /^[A-Z]/.test(originalJsxElementName) ? t18.jsxExpressionContainer(t18.identifier(originalJsxElementName)) : t18.stringLiteral(originalJsxElementName);
|
|
2141
2167
|
jsxScope.node.openingElement.attributes.push(
|
|
2142
|
-
|
|
2168
|
+
t18.jsxAttribute(t18.jsxIdentifier("$attrAs"), as)
|
|
2143
2169
|
);
|
|
2144
2170
|
jsxScope.node.openingElement.attributes.push(
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2171
|
+
t18.jsxAttribute(
|
|
2172
|
+
t18.jsxIdentifier("$fileKey"),
|
|
2173
|
+
t18.stringLiteral(payload.relativeFilePath)
|
|
2148
2174
|
)
|
|
2149
2175
|
);
|
|
2150
2176
|
jsxScope.node.openingElement.attributes.push(
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
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
|
|
2158
|
-
|
|
2159
|
-
|
|
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
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
[
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
[
|
|
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
|
)
|
|
@@ -2189,10 +2215,10 @@ var lingoJsxAttributeScopeInjectMutation = createCodeMutation(
|
|
|
2189
2215
|
);
|
|
2190
2216
|
|
|
2191
2217
|
// src/jsx-scope-inject.ts
|
|
2192
|
-
import * as
|
|
2218
|
+
import * as t22 from "@babel/types";
|
|
2193
2219
|
|
|
2194
2220
|
// src/utils/jsx-variables.ts
|
|
2195
|
-
import * as
|
|
2221
|
+
import * as t19 from "@babel/types";
|
|
2196
2222
|
var getJsxVariables = (nodePath) => {
|
|
2197
2223
|
const variables = /* @__PURE__ */ new Set();
|
|
2198
2224
|
nodePath.traverse({
|
|
@@ -2200,13 +2226,13 @@ var getJsxVariables = (nodePath) => {
|
|
|
2200
2226
|
path7.skip();
|
|
2201
2227
|
},
|
|
2202
2228
|
JSXExpressionContainer(path7) {
|
|
2203
|
-
if (
|
|
2229
|
+
if (t19.isIdentifier(path7.node.expression)) {
|
|
2204
2230
|
variables.add(path7.node.expression.name);
|
|
2205
|
-
} else if (
|
|
2231
|
+
} else if (t19.isMemberExpression(path7.node.expression)) {
|
|
2206
2232
|
let current = path7.node.expression;
|
|
2207
2233
|
const parts = [];
|
|
2208
|
-
while (
|
|
2209
|
-
if (
|
|
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 (
|
|
2244
|
+
if (t19.isIdentifier(current)) {
|
|
2219
2245
|
parts.unshift(current.name);
|
|
2220
2246
|
variables.add(parts.join(".").replaceAll(".[", "["));
|
|
2221
2247
|
}
|
|
@@ -2224,14 +2250,14 @@ var getJsxVariables = (nodePath) => {
|
|
|
2224
2250
|
}
|
|
2225
2251
|
});
|
|
2226
2252
|
const properties = Array.from(variables).map(
|
|
2227
|
-
(name) =>
|
|
2253
|
+
(name) => t19.objectProperty(t19.stringLiteral(name), t19.identifier(name))
|
|
2228
2254
|
);
|
|
2229
|
-
const result =
|
|
2255
|
+
const result = t19.objectExpression(properties);
|
|
2230
2256
|
return result;
|
|
2231
2257
|
};
|
|
2232
2258
|
|
|
2233
2259
|
// src/utils/jsx-functions.ts
|
|
2234
|
-
import * as
|
|
2260
|
+
import * as t20 from "@babel/types";
|
|
2235
2261
|
var getJsxFunctions = (nodePath) => {
|
|
2236
2262
|
const functions = /* @__PURE__ */ new Map();
|
|
2237
2263
|
let fnCounter = 0;
|
|
@@ -2240,27 +2266,27 @@ var getJsxFunctions = (nodePath) => {
|
|
|
2240
2266
|
path7.skip();
|
|
2241
2267
|
},
|
|
2242
2268
|
JSXExpressionContainer(path7) {
|
|
2243
|
-
if (
|
|
2269
|
+
if (t20.isCallExpression(path7.node.expression)) {
|
|
2244
2270
|
let key = "";
|
|
2245
|
-
if (
|
|
2271
|
+
if (t20.isIdentifier(path7.node.expression.callee)) {
|
|
2246
2272
|
key = `${path7.node.expression.callee.name}`;
|
|
2247
|
-
} else if (
|
|
2273
|
+
} else if (t20.isMemberExpression(path7.node.expression.callee)) {
|
|
2248
2274
|
let firstCallee = path7.node.expression.callee;
|
|
2249
|
-
while (
|
|
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 (
|
|
2255
|
-
if (
|
|
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 (
|
|
2286
|
+
if (t20.isIdentifier(current)) {
|
|
2261
2287
|
parts.unshift(current.name);
|
|
2262
2288
|
}
|
|
2263
|
-
if (
|
|
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,13 +2299,13 @@ var getJsxFunctions = (nodePath) => {
|
|
|
2273
2299
|
}
|
|
2274
2300
|
});
|
|
2275
2301
|
const properties = Array.from(functions.entries()).map(
|
|
2276
|
-
([name, callExpr]) =>
|
|
2302
|
+
([name, callExpr]) => t20.objectProperty(t20.stringLiteral(name), t20.arrayExpression(callExpr))
|
|
2277
2303
|
);
|
|
2278
|
-
return
|
|
2304
|
+
return t20.objectExpression(properties);
|
|
2279
2305
|
};
|
|
2280
2306
|
|
|
2281
2307
|
// src/utils/jsx-expressions.ts
|
|
2282
|
-
import * as
|
|
2308
|
+
import * as t21 from "@babel/types";
|
|
2283
2309
|
var getJsxExpressions = (nodePath) => {
|
|
2284
2310
|
const expressions = [];
|
|
2285
2311
|
nodePath.traverse({
|
|
@@ -2288,13 +2314,13 @@ var getJsxExpressions = (nodePath) => {
|
|
|
2288
2314
|
},
|
|
2289
2315
|
JSXExpressionContainer(path7) {
|
|
2290
2316
|
const expr = path7.node.expression;
|
|
2291
|
-
if (!
|
|
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
|
|
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) ?
|
|
2320
|
-
originalAttributes.push(
|
|
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
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2348
|
+
t22.jsxAttribute(
|
|
2349
|
+
t22.jsxIdentifier("$fileKey"),
|
|
2350
|
+
t22.stringLiteral(payload.relativeFilePath)
|
|
2325
2351
|
)
|
|
2326
2352
|
);
|
|
2327
2353
|
originalAttributes.push(
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
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
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
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
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
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
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
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
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
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
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
[
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
[
|
|
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 =
|
|
2390
|
-
|
|
2391
|
-
|
|
2415
|
+
const newNode = t22.jsxElement(
|
|
2416
|
+
t22.jsxOpeningElement(
|
|
2417
|
+
t22.jsxIdentifier(lingoComponentImport.importedName),
|
|
2392
2418
|
originalAttributes,
|
|
2393
2419
|
true
|
|
2394
2420
|
// selfClosing
|
|
@@ -2406,7 +2432,7 @@ var lingoJsxScopeInjectMutation = createCodeMutation((payload) => {
|
|
|
2406
2432
|
});
|
|
2407
2433
|
|
|
2408
2434
|
// src/jsx-remove-attributes.ts
|
|
2409
|
-
import * as
|
|
2435
|
+
import * as t23 from "@babel/types";
|
|
2410
2436
|
import traverse9 from "@babel/traverse";
|
|
2411
2437
|
var jsxRemoveAttributesMutation = createCodeMutation(
|
|
2412
2438
|
(payload) => {
|
|
@@ -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 =
|
|
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
|
}
|
|
@@ -2431,18 +2457,8 @@ var jsxRemoveAttributesMutation = createCodeMutation(
|
|
|
2431
2457
|
);
|
|
2432
2458
|
|
|
2433
2459
|
// src/client-dictionary-loader.ts
|
|
2434
|
-
import
|
|
2435
|
-
import * as t23 from "@babel/types";
|
|
2460
|
+
import * as t24 from "@babel/types";
|
|
2436
2461
|
var clientDictionaryLoaderMutation = createCodeMutation((payload) => {
|
|
2437
|
-
const lingoDir = path5.resolve(
|
|
2438
|
-
process.cwd(),
|
|
2439
|
-
payload.params.sourceRoot,
|
|
2440
|
-
payload.params.lingoDir
|
|
2441
|
-
);
|
|
2442
|
-
const currentDir = path5.dirname(
|
|
2443
|
-
path5.resolve(process.cwd(), payload.params.sourceRoot, payload.fileKey)
|
|
2444
|
-
);
|
|
2445
|
-
const relativeLingoPath = path5.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 (
|
|
2474
|
+
if (t24.isIdentifier(invokation.callee)) {
|
|
2459
2475
|
invokation.callee.name = internalDictionaryLoader.importedName;
|
|
2460
2476
|
}
|
|
2461
|
-
const
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
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 = createUnplugin(
|
|
|
2552
2559
|
const result = _11.chain({
|
|
2553
2560
|
code,
|
|
2554
2561
|
params,
|
|
2555
|
-
|
|
2562
|
+
relativeFilePath: path6.relative(path6.resolve(process.cwd(), params.sourceRoot), id).split(path6.sep).join("/")
|
|
2556
2563
|
// Always normalize for consistent dictionaries
|
|
2557
2564
|
}).thru(createPayload).thru(
|
|
2558
2565
|
composeMutations(
|