@lingo.dev/_compiler 0.2.2 → 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 +127 -142
- package/build/index.mjs +138 -153
- 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.
|
|
7
|
+
version: "0.2.3",
|
|
8
8
|
description: "Lingo.dev Compiler",
|
|
9
9
|
private: false,
|
|
10
10
|
publishConfig: {
|
|
@@ -117,7 +117,7 @@ var defaultParams = {
|
|
|
117
117
|
|
|
118
118
|
// src/utils/index.ts
|
|
119
119
|
var _traverse = require('@babel/traverse'); var _traverse2 = _interopRequireDefault(_traverse);
|
|
120
|
-
var _types = require('@babel/types'); var t2 = _interopRequireWildcard(_types); var t = _interopRequireWildcard(_types); var t4 = _interopRequireWildcard(_types); var t3 = _interopRequireWildcard(_types); var t5 = _interopRequireWildcard(_types); var t8 = _interopRequireWildcard(_types); var t6 = _interopRequireWildcard(_types); var t7 = _interopRequireWildcard(_types); var t10 = _interopRequireWildcard(_types); var t9 = _interopRequireWildcard(_types); var t11 = _interopRequireWildcard(_types); var
|
|
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
|
|
|
@@ -1771,12 +1771,33 @@ function collectCallExpressions(path7, importNames, result, functionName) {
|
|
|
1771
1771
|
// src/_utils.ts
|
|
1772
1772
|
|
|
1773
1773
|
var getDictionaryPath = (params) => {
|
|
1774
|
-
|
|
1775
|
-
params.
|
|
1776
|
-
|
|
1774
|
+
const absolute = path.default.resolve(
|
|
1775
|
+
params.sourceRoot,
|
|
1776
|
+
params.lingoDir,
|
|
1777
|
+
LCP_DICTIONARY_FILE_NAME
|
|
1777
1778
|
);
|
|
1779
|
+
const rel = path.default.relative(params.relativeFilePath, absolute);
|
|
1780
|
+
return rel.split(path.default.sep).join(path.default.posix.sep);
|
|
1778
1781
|
};
|
|
1779
1782
|
|
|
1783
|
+
// src/utils/create-locale-import-map.ts
|
|
1784
|
+
|
|
1785
|
+
function createLocaleImportMap(allLocales, dictionaryPath) {
|
|
1786
|
+
return t12.objectExpression(
|
|
1787
|
+
allLocales.map(
|
|
1788
|
+
(locale) => t12.objectProperty(
|
|
1789
|
+
t12.stringLiteral(locale),
|
|
1790
|
+
t12.arrowFunctionExpression(
|
|
1791
|
+
[],
|
|
1792
|
+
t12.callExpression(t12.identifier("import"), [
|
|
1793
|
+
t12.stringLiteral(`${dictionaryPath}?locale=${locale}`)
|
|
1794
|
+
])
|
|
1795
|
+
)
|
|
1796
|
+
)
|
|
1797
|
+
)
|
|
1798
|
+
);
|
|
1799
|
+
}
|
|
1800
|
+
|
|
1780
1801
|
// src/rsc-dictionary-loader.ts
|
|
1781
1802
|
var rscDictionaryLoaderMutation = createCodeMutation((payload) => {
|
|
1782
1803
|
const mode = getModuleExecutionMode(payload.ast, payload.params.rsc);
|
|
@@ -1795,7 +1816,7 @@ var rscDictionaryLoaderMutation = createCodeMutation((payload) => {
|
|
|
1795
1816
|
moduleName: "lingo.dev/react/rsc" /* ReactRSC */,
|
|
1796
1817
|
exportedName: "loadDictionary_internal"
|
|
1797
1818
|
});
|
|
1798
|
-
if (
|
|
1819
|
+
if (t13.isIdentifier(invokation.callee)) {
|
|
1799
1820
|
invokation.callee.name = internalDictionaryLoader.importedName;
|
|
1800
1821
|
}
|
|
1801
1822
|
const dictionaryPath = getDictionaryPath({
|
|
@@ -1803,19 +1824,7 @@ var rscDictionaryLoaderMutation = createCodeMutation((payload) => {
|
|
|
1803
1824
|
lingoDir: payload.params.lingoDir,
|
|
1804
1825
|
relativeFilePath: payload.relativeFilePath
|
|
1805
1826
|
});
|
|
1806
|
-
const localeImportMap =
|
|
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
|
-
);
|
|
1827
|
+
const localeImportMap = createLocaleImportMap(allLocales, dictionaryPath);
|
|
1819
1828
|
invokation.arguments.push(localeImportMap);
|
|
1820
1829
|
}
|
|
1821
1830
|
return payload;
|
|
@@ -1841,7 +1850,7 @@ var reactRouterDictionaryLoaderMutation = createCodeMutation(
|
|
|
1841
1850
|
moduleName: "lingo.dev/react/react-router" /* ReactRouter */,
|
|
1842
1851
|
exportedName: "loadDictionary_internal"
|
|
1843
1852
|
});
|
|
1844
|
-
if (
|
|
1853
|
+
if (t14.isIdentifier(invokation.callee)) {
|
|
1845
1854
|
invokation.callee.name = internalDictionaryLoader.importedName;
|
|
1846
1855
|
}
|
|
1847
1856
|
const dictionaryPath = getDictionaryPath({
|
|
@@ -1849,19 +1858,7 @@ var reactRouterDictionaryLoaderMutation = createCodeMutation(
|
|
|
1849
1858
|
lingoDir: payload.params.lingoDir,
|
|
1850
1859
|
relativeFilePath: payload.relativeFilePath
|
|
1851
1860
|
});
|
|
1852
|
-
const localeImportMap =
|
|
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
|
-
);
|
|
1861
|
+
const localeImportMap = createLocaleImportMap(allLocales, dictionaryPath);
|
|
1865
1862
|
invokation.arguments.push(localeImportMap);
|
|
1866
1863
|
}
|
|
1867
1864
|
return payload;
|
|
@@ -1879,7 +1876,7 @@ function jsxFragmentMutation(payload) {
|
|
|
1879
1876
|
ImportDeclaration(path7) {
|
|
1880
1877
|
if (path7.node.source.value !== "react") return;
|
|
1881
1878
|
for (const specifier of path7.node.specifiers) {
|
|
1882
|
-
if (
|
|
1879
|
+
if (t15.isImportSpecifier(specifier) && t15.isIdentifier(specifier.imported) && specifier.imported.name === "Fragment") {
|
|
1883
1880
|
fragmentImportName = specifier.local.name;
|
|
1884
1881
|
path7.stop();
|
|
1885
1882
|
}
|
|
@@ -1896,9 +1893,9 @@ function jsxFragmentMutation(payload) {
|
|
|
1896
1893
|
});
|
|
1897
1894
|
fragmentImportName = result.importedName;
|
|
1898
1895
|
}
|
|
1899
|
-
const fragmentElement =
|
|
1900
|
-
|
|
1901
|
-
|
|
1896
|
+
const fragmentElement = t15.jsxElement(
|
|
1897
|
+
t15.jsxOpeningElement(t15.jsxIdentifier(fragmentImportName), [], false),
|
|
1898
|
+
t15.jsxClosingElement(t15.jsxIdentifier(fragmentImportName)),
|
|
1902
1899
|
path7.node.children,
|
|
1903
1900
|
false
|
|
1904
1901
|
);
|
|
@@ -1921,11 +1918,11 @@ var jsxHtmlLangMutation = createCodeMutation((payload) => {
|
|
|
1921
1918
|
moduleName: packagePath,
|
|
1922
1919
|
exportedName: "LingoHtmlComponent"
|
|
1923
1920
|
});
|
|
1924
|
-
path7.node.openingElement.name =
|
|
1921
|
+
path7.node.openingElement.name = t16.jsxIdentifier(
|
|
1925
1922
|
lingoHtmlComponentImport.importedName
|
|
1926
1923
|
);
|
|
1927
1924
|
if (path7.node.closingElement) {
|
|
1928
|
-
path7.node.closingElement.name =
|
|
1925
|
+
path7.node.closingElement.name = t16.jsxIdentifier(
|
|
1929
1926
|
lingoHtmlComponentImport.importedName
|
|
1930
1927
|
);
|
|
1931
1928
|
}
|
|
@@ -2016,39 +2013,39 @@ function extractJsxContent(nodePath, replaceWhitespacePlaceholders = true) {
|
|
|
2016
2013
|
return;
|
|
2017
2014
|
}
|
|
2018
2015
|
const expr = path7.node.expression;
|
|
2019
|
-
if (
|
|
2016
|
+
if (t17.isCallExpression(expr)) {
|
|
2020
2017
|
let key = "";
|
|
2021
|
-
if (
|
|
2018
|
+
if (t17.isIdentifier(expr.callee)) {
|
|
2022
2019
|
key = `${expr.callee.name}`;
|
|
2023
|
-
} else if (
|
|
2020
|
+
} else if (t17.isMemberExpression(expr.callee)) {
|
|
2024
2021
|
let firstCallee = expr.callee;
|
|
2025
|
-
while (
|
|
2022
|
+
while (t17.isMemberExpression(firstCallee) && t17.isCallExpression(firstCallee.object)) {
|
|
2026
2023
|
firstCallee = firstCallee.object.callee;
|
|
2027
2024
|
}
|
|
2028
2025
|
let current = firstCallee;
|
|
2029
2026
|
const parts = [];
|
|
2030
|
-
while (
|
|
2031
|
-
if (
|
|
2027
|
+
while (t17.isMemberExpression(current)) {
|
|
2028
|
+
if (t17.isIdentifier(current.property)) {
|
|
2032
2029
|
parts.unshift(current.property.name);
|
|
2033
2030
|
}
|
|
2034
2031
|
current = current.object;
|
|
2035
2032
|
}
|
|
2036
|
-
if (
|
|
2033
|
+
if (t17.isIdentifier(current)) {
|
|
2037
2034
|
parts.unshift(current.name);
|
|
2038
2035
|
}
|
|
2039
|
-
if (
|
|
2036
|
+
if (t17.isMemberExpression(firstCallee) && t17.isNewExpression(firstCallee.object) && t17.isIdentifier(firstCallee.object.callee)) {
|
|
2040
2037
|
parts.unshift(firstCallee.object.callee.name);
|
|
2041
2038
|
}
|
|
2042
2039
|
key = parts.join(".");
|
|
2043
2040
|
}
|
|
2044
2041
|
chunks.push(`<function:${key}/>`);
|
|
2045
|
-
} else if (
|
|
2042
|
+
} else if (t17.isIdentifier(expr)) {
|
|
2046
2043
|
chunks.push(`{${expr.name}}`);
|
|
2047
|
-
} else if (
|
|
2044
|
+
} else if (t17.isMemberExpression(expr)) {
|
|
2048
2045
|
let current = expr;
|
|
2049
2046
|
const parts = [];
|
|
2050
|
-
while (
|
|
2051
|
-
if (
|
|
2047
|
+
while (t17.isMemberExpression(current)) {
|
|
2048
|
+
if (t17.isIdentifier(current.property)) {
|
|
2052
2049
|
if (current.computed) {
|
|
2053
2050
|
parts.unshift(`[${current.property.name}]`);
|
|
2054
2051
|
} else {
|
|
@@ -2057,7 +2054,7 @@ function extractJsxContent(nodePath, replaceWhitespacePlaceholders = true) {
|
|
|
2057
2054
|
}
|
|
2058
2055
|
current = current.object;
|
|
2059
2056
|
}
|
|
2060
|
-
if (
|
|
2057
|
+
if (t17.isIdentifier(current)) {
|
|
2061
2058
|
parts.unshift(current.name);
|
|
2062
2059
|
chunks.push(`{${parts.join(".").replaceAll(".[", "[")}}`);
|
|
2063
2060
|
}
|
|
@@ -2078,12 +2075,12 @@ function extractJsxContent(nodePath, replaceWhitespacePlaceholders = true) {
|
|
|
2078
2075
|
}
|
|
2079
2076
|
var compilerProps = ["data-jsx-attribute-scope", "data-jsx-scope"];
|
|
2080
2077
|
function isExpression2(nodePath) {
|
|
2081
|
-
const isCompilerExpression = !_lodash2.default.isArray(nodePath.container) &&
|
|
2082
|
-
return !isCompilerExpression && !
|
|
2078
|
+
const isCompilerExpression = !_lodash2.default.isArray(nodePath.container) && t17.isJSXAttribute(nodePath.container) && t17.isJSXIdentifier(nodePath.container.name) && compilerProps.includes(nodePath.container.name.name);
|
|
2079
|
+
return !isCompilerExpression && !t17.isJSXEmptyExpression(nodePath.node.expression);
|
|
2083
2080
|
}
|
|
2084
2081
|
function isWhitespace(nodePath) {
|
|
2085
2082
|
const expr = nodePath.node.expression;
|
|
2086
|
-
return
|
|
2083
|
+
return t17.isStringLiteral(expr) && expr.value === " ";
|
|
2087
2084
|
}
|
|
2088
2085
|
function normalizeJsxWhitespace(input) {
|
|
2089
2086
|
const lines = input.split("\n");
|
|
@@ -2158,34 +2155,34 @@ var lingoJsxAttributeScopeInjectMutation = createCodeMutation(
|
|
|
2158
2155
|
if (!originalJsxElementName) {
|
|
2159
2156
|
continue;
|
|
2160
2157
|
}
|
|
2161
|
-
jsxScope.node.openingElement.name =
|
|
2158
|
+
jsxScope.node.openingElement.name = t18.jsxIdentifier(
|
|
2162
2159
|
lingoComponentImport.importedName
|
|
2163
2160
|
);
|
|
2164
2161
|
if (jsxScope.node.closingElement) {
|
|
2165
|
-
jsxScope.node.closingElement.name =
|
|
2162
|
+
jsxScope.node.closingElement.name = t18.jsxIdentifier(
|
|
2166
2163
|
lingoComponentImport.importedName
|
|
2167
2164
|
);
|
|
2168
2165
|
}
|
|
2169
|
-
const as = /^[A-Z]/.test(originalJsxElementName) ?
|
|
2166
|
+
const as = /^[A-Z]/.test(originalJsxElementName) ? t18.jsxExpressionContainer(t18.identifier(originalJsxElementName)) : t18.stringLiteral(originalJsxElementName);
|
|
2170
2167
|
jsxScope.node.openingElement.attributes.push(
|
|
2171
|
-
|
|
2168
|
+
t18.jsxAttribute(t18.jsxIdentifier("$attrAs"), as)
|
|
2172
2169
|
);
|
|
2173
2170
|
jsxScope.node.openingElement.attributes.push(
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2171
|
+
t18.jsxAttribute(
|
|
2172
|
+
t18.jsxIdentifier("$fileKey"),
|
|
2173
|
+
t18.stringLiteral(payload.relativeFilePath)
|
|
2177
2174
|
)
|
|
2178
2175
|
);
|
|
2179
2176
|
jsxScope.node.openingElement.attributes.push(
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2177
|
+
t18.jsxAttribute(
|
|
2178
|
+
t18.jsxIdentifier("$attributes"),
|
|
2179
|
+
t18.jsxExpressionContainer(
|
|
2180
|
+
t18.objectExpression(
|
|
2184
2181
|
attributes.map((attributeDefinition) => {
|
|
2185
2182
|
const [attribute, key = ""] = attributeDefinition.split(":");
|
|
2186
|
-
return
|
|
2187
|
-
|
|
2188
|
-
|
|
2183
|
+
return t18.objectProperty(
|
|
2184
|
+
t18.stringLiteral(attribute),
|
|
2185
|
+
t18.stringLiteral(key)
|
|
2189
2186
|
);
|
|
2190
2187
|
})
|
|
2191
2188
|
)
|
|
@@ -2198,14 +2195,14 @@ var lingoJsxAttributeScopeInjectMutation = createCodeMutation(
|
|
|
2198
2195
|
moduleName: "lingo.dev/react/rsc" /* ReactRSC */
|
|
2199
2196
|
});
|
|
2200
2197
|
jsxScope.node.openingElement.attributes.push(
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
[
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
[
|
|
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")]
|
|
2209
2206
|
)
|
|
2210
2207
|
)
|
|
2211
2208
|
)
|
|
@@ -2229,13 +2226,13 @@ var getJsxVariables = (nodePath) => {
|
|
|
2229
2226
|
path7.skip();
|
|
2230
2227
|
},
|
|
2231
2228
|
JSXExpressionContainer(path7) {
|
|
2232
|
-
if (
|
|
2229
|
+
if (t19.isIdentifier(path7.node.expression)) {
|
|
2233
2230
|
variables.add(path7.node.expression.name);
|
|
2234
|
-
} else if (
|
|
2231
|
+
} else if (t19.isMemberExpression(path7.node.expression)) {
|
|
2235
2232
|
let current = path7.node.expression;
|
|
2236
2233
|
const parts = [];
|
|
2237
|
-
while (
|
|
2238
|
-
if (
|
|
2234
|
+
while (t19.isMemberExpression(current)) {
|
|
2235
|
+
if (t19.isIdentifier(current.property)) {
|
|
2239
2236
|
if (current.computed) {
|
|
2240
2237
|
parts.unshift(`[${current.property.name}]`);
|
|
2241
2238
|
} else {
|
|
@@ -2244,7 +2241,7 @@ var getJsxVariables = (nodePath) => {
|
|
|
2244
2241
|
}
|
|
2245
2242
|
current = current.object;
|
|
2246
2243
|
}
|
|
2247
|
-
if (
|
|
2244
|
+
if (t19.isIdentifier(current)) {
|
|
2248
2245
|
parts.unshift(current.name);
|
|
2249
2246
|
variables.add(parts.join(".").replaceAll(".[", "["));
|
|
2250
2247
|
}
|
|
@@ -2253,9 +2250,9 @@ var getJsxVariables = (nodePath) => {
|
|
|
2253
2250
|
}
|
|
2254
2251
|
});
|
|
2255
2252
|
const properties = Array.from(variables).map(
|
|
2256
|
-
(name) =>
|
|
2253
|
+
(name) => t19.objectProperty(t19.stringLiteral(name), t19.identifier(name))
|
|
2257
2254
|
);
|
|
2258
|
-
const result =
|
|
2255
|
+
const result = t19.objectExpression(properties);
|
|
2259
2256
|
return result;
|
|
2260
2257
|
};
|
|
2261
2258
|
|
|
@@ -2269,27 +2266,27 @@ var getJsxFunctions = (nodePath) => {
|
|
|
2269
2266
|
path7.skip();
|
|
2270
2267
|
},
|
|
2271
2268
|
JSXExpressionContainer(path7) {
|
|
2272
|
-
if (
|
|
2269
|
+
if (t20.isCallExpression(path7.node.expression)) {
|
|
2273
2270
|
let key = "";
|
|
2274
|
-
if (
|
|
2271
|
+
if (t20.isIdentifier(path7.node.expression.callee)) {
|
|
2275
2272
|
key = `${path7.node.expression.callee.name}`;
|
|
2276
|
-
} else if (
|
|
2273
|
+
} else if (t20.isMemberExpression(path7.node.expression.callee)) {
|
|
2277
2274
|
let firstCallee = path7.node.expression.callee;
|
|
2278
|
-
while (
|
|
2275
|
+
while (t20.isMemberExpression(firstCallee) && t20.isCallExpression(firstCallee.object)) {
|
|
2279
2276
|
firstCallee = firstCallee.object.callee;
|
|
2280
2277
|
}
|
|
2281
2278
|
let current = firstCallee;
|
|
2282
2279
|
const parts = [];
|
|
2283
|
-
while (
|
|
2284
|
-
if (
|
|
2280
|
+
while (t20.isMemberExpression(current)) {
|
|
2281
|
+
if (t20.isIdentifier(current.property)) {
|
|
2285
2282
|
parts.unshift(current.property.name);
|
|
2286
2283
|
}
|
|
2287
2284
|
current = current.object;
|
|
2288
2285
|
}
|
|
2289
|
-
if (
|
|
2286
|
+
if (t20.isIdentifier(current)) {
|
|
2290
2287
|
parts.unshift(current.name);
|
|
2291
2288
|
}
|
|
2292
|
-
if (
|
|
2289
|
+
if (t20.isMemberExpression(firstCallee) && t20.isNewExpression(firstCallee.object) && t20.isIdentifier(firstCallee.object.callee)) {
|
|
2293
2290
|
parts.unshift(firstCallee.object.callee.name);
|
|
2294
2291
|
}
|
|
2295
2292
|
key = parts.join(".");
|
|
@@ -2302,9 +2299,9 @@ var getJsxFunctions = (nodePath) => {
|
|
|
2302
2299
|
}
|
|
2303
2300
|
});
|
|
2304
2301
|
const properties = Array.from(functions.entries()).map(
|
|
2305
|
-
([name, callExpr]) =>
|
|
2302
|
+
([name, callExpr]) => t20.objectProperty(t20.stringLiteral(name), t20.arrayExpression(callExpr))
|
|
2306
2303
|
);
|
|
2307
|
-
return
|
|
2304
|
+
return t20.objectExpression(properties);
|
|
2308
2305
|
};
|
|
2309
2306
|
|
|
2310
2307
|
// src/utils/jsx-expressions.ts
|
|
@@ -2317,13 +2314,13 @@ var getJsxExpressions = (nodePath) => {
|
|
|
2317
2314
|
},
|
|
2318
2315
|
JSXExpressionContainer(path7) {
|
|
2319
2316
|
const expr = path7.node.expression;
|
|
2320
|
-
if (!
|
|
2317
|
+
if (!t21.isJSXEmptyExpression(expr) && !t21.isIdentifier(expr) && !t21.isMemberExpression(expr) && !t21.isCallExpression(expr) && !(t21.isStringLiteral(expr) && expr.value === " ")) {
|
|
2321
2318
|
expressions.push(expr);
|
|
2322
2319
|
}
|
|
2323
2320
|
path7.skip();
|
|
2324
2321
|
}
|
|
2325
2322
|
});
|
|
2326
|
-
return
|
|
2323
|
+
return t21.arrayExpression(expressions);
|
|
2327
2324
|
};
|
|
2328
2325
|
|
|
2329
2326
|
// src/jsx-scope-inject.ts
|
|
@@ -2345,53 +2342,53 @@ var lingoJsxScopeInjectMutation = createCodeMutation((payload) => {
|
|
|
2345
2342
|
continue;
|
|
2346
2343
|
}
|
|
2347
2344
|
const originalAttributes = jsxScope.node.openingElement.attributes.slice();
|
|
2348
|
-
const as = /^[A-Z]/.test(originalJsxElementName) ?
|
|
2349
|
-
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));
|
|
2350
2347
|
originalAttributes.push(
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2348
|
+
t22.jsxAttribute(
|
|
2349
|
+
t22.jsxIdentifier("$fileKey"),
|
|
2350
|
+
t22.stringLiteral(payload.relativeFilePath)
|
|
2354
2351
|
)
|
|
2355
2352
|
);
|
|
2356
2353
|
originalAttributes.push(
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2354
|
+
t22.jsxAttribute(
|
|
2355
|
+
t22.jsxIdentifier("$entryKey"),
|
|
2356
|
+
t22.stringLiteral(getJsxScopeAttribute(jsxScope))
|
|
2360
2357
|
)
|
|
2361
2358
|
);
|
|
2362
2359
|
const $variables = getJsxVariables(jsxScope);
|
|
2363
2360
|
if ($variables.properties.length > 0) {
|
|
2364
2361
|
originalAttributes.push(
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2362
|
+
t22.jsxAttribute(
|
|
2363
|
+
t22.jsxIdentifier("$variables"),
|
|
2364
|
+
t22.jsxExpressionContainer($variables)
|
|
2368
2365
|
)
|
|
2369
2366
|
);
|
|
2370
2367
|
}
|
|
2371
2368
|
const $elements = getNestedJsxElements(jsxScope);
|
|
2372
2369
|
if ($elements.elements.length > 0) {
|
|
2373
2370
|
originalAttributes.push(
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2371
|
+
t22.jsxAttribute(
|
|
2372
|
+
t22.jsxIdentifier("$elements"),
|
|
2373
|
+
t22.jsxExpressionContainer($elements)
|
|
2377
2374
|
)
|
|
2378
2375
|
);
|
|
2379
2376
|
}
|
|
2380
2377
|
const $functions = getJsxFunctions(jsxScope);
|
|
2381
2378
|
if ($functions.properties.length > 0) {
|
|
2382
2379
|
originalAttributes.push(
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2380
|
+
t22.jsxAttribute(
|
|
2381
|
+
t22.jsxIdentifier("$functions"),
|
|
2382
|
+
t22.jsxExpressionContainer($functions)
|
|
2386
2383
|
)
|
|
2387
2384
|
);
|
|
2388
2385
|
}
|
|
2389
2386
|
const $expressions = getJsxExpressions(jsxScope);
|
|
2390
2387
|
if ($expressions.elements.length > 0) {
|
|
2391
2388
|
originalAttributes.push(
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2389
|
+
t22.jsxAttribute(
|
|
2390
|
+
t22.jsxIdentifier("$expressions"),
|
|
2391
|
+
t22.jsxExpressionContainer($expressions)
|
|
2395
2392
|
)
|
|
2396
2393
|
);
|
|
2397
2394
|
}
|
|
@@ -2401,23 +2398,23 @@ var lingoJsxScopeInjectMutation = createCodeMutation((payload) => {
|
|
|
2401
2398
|
moduleName: "lingo.dev/react/rsc" /* ReactRSC */
|
|
2402
2399
|
});
|
|
2403
2400
|
originalAttributes.push(
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
[
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
[
|
|
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")]
|
|
2412
2409
|
)
|
|
2413
2410
|
)
|
|
2414
2411
|
)
|
|
2415
2412
|
)
|
|
2416
2413
|
);
|
|
2417
2414
|
}
|
|
2418
|
-
const newNode =
|
|
2419
|
-
|
|
2420
|
-
|
|
2415
|
+
const newNode = t22.jsxElement(
|
|
2416
|
+
t22.jsxOpeningElement(
|
|
2417
|
+
t22.jsxIdentifier(lingoComponentImport.importedName),
|
|
2421
2418
|
originalAttributes,
|
|
2422
2419
|
true
|
|
2423
2420
|
// selfClosing
|
|
@@ -2448,7 +2445,7 @@ var jsxRemoveAttributesMutation = createCodeMutation(
|
|
|
2448
2445
|
JSXElement(path7) {
|
|
2449
2446
|
const openingElement = path7.node.openingElement;
|
|
2450
2447
|
openingElement.attributes = openingElement.attributes.filter((attr) => {
|
|
2451
|
-
const removeAttr =
|
|
2448
|
+
const removeAttr = t23.isJSXAttribute(attr) && t23.isJSXIdentifier(attr.name) && ATTRIBUTES_TO_REMOVE.includes(attr.name.name);
|
|
2452
2449
|
return !removeAttr;
|
|
2453
2450
|
});
|
|
2454
2451
|
}
|
|
@@ -2474,7 +2471,7 @@ var clientDictionaryLoaderMutation = createCodeMutation((payload) => {
|
|
|
2474
2471
|
moduleName: "lingo.dev/react/client" /* ReactClient */,
|
|
2475
2472
|
exportedName: "loadDictionary_internal"
|
|
2476
2473
|
});
|
|
2477
|
-
if (
|
|
2474
|
+
if (t24.isIdentifier(invokation.callee)) {
|
|
2478
2475
|
invokation.callee.name = internalDictionaryLoader.importedName;
|
|
2479
2476
|
}
|
|
2480
2477
|
const dictionaryPath = getDictionaryPath({
|
|
@@ -2482,19 +2479,7 @@ var clientDictionaryLoaderMutation = createCodeMutation((payload) => {
|
|
|
2482
2479
|
lingoDir: payload.params.lingoDir,
|
|
2483
2480
|
relativeFilePath: payload.relativeFilePath
|
|
2484
2481
|
});
|
|
2485
|
-
const localeImportMap =
|
|
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
|
-
);
|
|
2482
|
+
const localeImportMap = createLocaleImportMap(allLocales, dictionaryPath);
|
|
2498
2483
|
invokation.arguments.push(localeImportMap);
|
|
2499
2484
|
}
|
|
2500
2485
|
return payload;
|
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,17 +1766,38 @@ function collectCallExpressions(path7, importNames, result, functionName) {
|
|
|
1766
1766
|
}
|
|
1767
1767
|
|
|
1768
1768
|
// src/rsc-dictionary-loader.ts
|
|
1769
|
-
import * as
|
|
1769
|
+
import * as t13 from "@babel/types";
|
|
1770
1770
|
|
|
1771
1771
|
// src/_utils.ts
|
|
1772
1772
|
import path5 from "path";
|
|
1773
1773
|
var getDictionaryPath = (params) => {
|
|
1774
|
-
|
|
1775
|
-
params.
|
|
1776
|
-
|
|
1774
|
+
const absolute = path5.resolve(
|
|
1775
|
+
params.sourceRoot,
|
|
1776
|
+
params.lingoDir,
|
|
1777
|
+
LCP_DICTIONARY_FILE_NAME
|
|
1777
1778
|
);
|
|
1779
|
+
const rel = path5.relative(params.relativeFilePath, absolute);
|
|
1780
|
+
return rel.split(path5.sep).join(path5.posix.sep);
|
|
1778
1781
|
};
|
|
1779
1782
|
|
|
1783
|
+
// src/utils/create-locale-import-map.ts
|
|
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
|
+
|
|
1780
1801
|
// src/rsc-dictionary-loader.ts
|
|
1781
1802
|
var rscDictionaryLoaderMutation = createCodeMutation((payload) => {
|
|
1782
1803
|
const mode = getModuleExecutionMode(payload.ast, payload.params.rsc);
|
|
@@ -1795,7 +1816,7 @@ var rscDictionaryLoaderMutation = createCodeMutation((payload) => {
|
|
|
1795
1816
|
moduleName: "lingo.dev/react/rsc" /* ReactRSC */,
|
|
1796
1817
|
exportedName: "loadDictionary_internal"
|
|
1797
1818
|
});
|
|
1798
|
-
if (
|
|
1819
|
+
if (t13.isIdentifier(invokation.callee)) {
|
|
1799
1820
|
invokation.callee.name = internalDictionaryLoader.importedName;
|
|
1800
1821
|
}
|
|
1801
1822
|
const dictionaryPath = getDictionaryPath({
|
|
@@ -1803,26 +1824,14 @@ var rscDictionaryLoaderMutation = createCodeMutation((payload) => {
|
|
|
1803
1824
|
lingoDir: payload.params.lingoDir,
|
|
1804
1825
|
relativeFilePath: payload.relativeFilePath
|
|
1805
1826
|
});
|
|
1806
|
-
const localeImportMap =
|
|
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
|
-
);
|
|
1827
|
+
const localeImportMap = createLocaleImportMap(allLocales, dictionaryPath);
|
|
1819
1828
|
invokation.arguments.push(localeImportMap);
|
|
1820
1829
|
}
|
|
1821
1830
|
return payload;
|
|
1822
1831
|
});
|
|
1823
1832
|
|
|
1824
1833
|
// src/react-router-dictionary-loader.ts
|
|
1825
|
-
import * as
|
|
1834
|
+
import * as t14 from "@babel/types";
|
|
1826
1835
|
var reactRouterDictionaryLoaderMutation = createCodeMutation(
|
|
1827
1836
|
(payload) => {
|
|
1828
1837
|
const mode = getModuleExecutionMode(payload.ast, payload.params.rsc);
|
|
@@ -1841,7 +1850,7 @@ var reactRouterDictionaryLoaderMutation = createCodeMutation(
|
|
|
1841
1850
|
moduleName: "lingo.dev/react/react-router" /* ReactRouter */,
|
|
1842
1851
|
exportedName: "loadDictionary_internal"
|
|
1843
1852
|
});
|
|
1844
|
-
if (
|
|
1853
|
+
if (t14.isIdentifier(invokation.callee)) {
|
|
1845
1854
|
invokation.callee.name = internalDictionaryLoader.importedName;
|
|
1846
1855
|
}
|
|
1847
1856
|
const dictionaryPath = getDictionaryPath({
|
|
@@ -1849,19 +1858,7 @@ var reactRouterDictionaryLoaderMutation = createCodeMutation(
|
|
|
1849
1858
|
lingoDir: payload.params.lingoDir,
|
|
1850
1859
|
relativeFilePath: payload.relativeFilePath
|
|
1851
1860
|
});
|
|
1852
|
-
const localeImportMap =
|
|
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
|
-
);
|
|
1861
|
+
const localeImportMap = createLocaleImportMap(allLocales, dictionaryPath);
|
|
1865
1862
|
invokation.arguments.push(localeImportMap);
|
|
1866
1863
|
}
|
|
1867
1864
|
return payload;
|
|
@@ -1870,7 +1867,7 @@ var reactRouterDictionaryLoaderMutation = createCodeMutation(
|
|
|
1870
1867
|
|
|
1871
1868
|
// src/jsx-fragment.ts
|
|
1872
1869
|
import traverse7 from "@babel/traverse";
|
|
1873
|
-
import * as
|
|
1870
|
+
import * as t15 from "@babel/types";
|
|
1874
1871
|
function jsxFragmentMutation(payload) {
|
|
1875
1872
|
const { ast } = payload;
|
|
1876
1873
|
let foundFragments = false;
|
|
@@ -1879,7 +1876,7 @@ function jsxFragmentMutation(payload) {
|
|
|
1879
1876
|
ImportDeclaration(path7) {
|
|
1880
1877
|
if (path7.node.source.value !== "react") return;
|
|
1881
1878
|
for (const specifier of path7.node.specifiers) {
|
|
1882
|
-
if (
|
|
1879
|
+
if (t15.isImportSpecifier(specifier) && t15.isIdentifier(specifier.imported) && specifier.imported.name === "Fragment") {
|
|
1883
1880
|
fragmentImportName = specifier.local.name;
|
|
1884
1881
|
path7.stop();
|
|
1885
1882
|
}
|
|
@@ -1896,9 +1893,9 @@ function jsxFragmentMutation(payload) {
|
|
|
1896
1893
|
});
|
|
1897
1894
|
fragmentImportName = result.importedName;
|
|
1898
1895
|
}
|
|
1899
|
-
const fragmentElement =
|
|
1900
|
-
|
|
1901
|
-
|
|
1896
|
+
const fragmentElement = t15.jsxElement(
|
|
1897
|
+
t15.jsxOpeningElement(t15.jsxIdentifier(fragmentImportName), [], false),
|
|
1898
|
+
t15.jsxClosingElement(t15.jsxIdentifier(fragmentImportName)),
|
|
1902
1899
|
path7.node.children,
|
|
1903
1900
|
false
|
|
1904
1901
|
);
|
|
@@ -1910,7 +1907,7 @@ function jsxFragmentMutation(payload) {
|
|
|
1910
1907
|
|
|
1911
1908
|
// src/jsx-html-lang.ts
|
|
1912
1909
|
import traverse8 from "@babel/traverse";
|
|
1913
|
-
import * as
|
|
1910
|
+
import * as t16 from "@babel/types";
|
|
1914
1911
|
var jsxHtmlLangMutation = createCodeMutation((payload) => {
|
|
1915
1912
|
traverse8(payload.ast, {
|
|
1916
1913
|
JSXElement: (path7) => {
|
|
@@ -1921,11 +1918,11 @@ var jsxHtmlLangMutation = createCodeMutation((payload) => {
|
|
|
1921
1918
|
moduleName: packagePath,
|
|
1922
1919
|
exportedName: "LingoHtmlComponent"
|
|
1923
1920
|
});
|
|
1924
|
-
path7.node.openingElement.name =
|
|
1921
|
+
path7.node.openingElement.name = t16.jsxIdentifier(
|
|
1925
1922
|
lingoHtmlComponentImport.importedName
|
|
1926
1923
|
);
|
|
1927
1924
|
if (path7.node.closingElement) {
|
|
1928
|
-
path7.node.closingElement.name =
|
|
1925
|
+
path7.node.closingElement.name = t16.jsxIdentifier(
|
|
1929
1926
|
lingoHtmlComponentImport.importedName
|
|
1930
1927
|
);
|
|
1931
1928
|
}
|
|
@@ -1994,7 +1991,7 @@ function jsxAttributeScopesExportMutation(payload) {
|
|
|
1994
1991
|
import _10 from "lodash";
|
|
1995
1992
|
|
|
1996
1993
|
// src/utils/jsx-content.ts
|
|
1997
|
-
import * as
|
|
1994
|
+
import * as t17 from "@babel/types";
|
|
1998
1995
|
import _9 from "lodash";
|
|
1999
1996
|
var WHITESPACE_PLACEHOLDER = "[lingo-whitespace-placeholder]";
|
|
2000
1997
|
function extractJsxContent(nodePath, replaceWhitespacePlaceholders = true) {
|
|
@@ -2016,39 +2013,39 @@ function extractJsxContent(nodePath, replaceWhitespacePlaceholders = true) {
|
|
|
2016
2013
|
return;
|
|
2017
2014
|
}
|
|
2018
2015
|
const expr = path7.node.expression;
|
|
2019
|
-
if (
|
|
2016
|
+
if (t17.isCallExpression(expr)) {
|
|
2020
2017
|
let key = "";
|
|
2021
|
-
if (
|
|
2018
|
+
if (t17.isIdentifier(expr.callee)) {
|
|
2022
2019
|
key = `${expr.callee.name}`;
|
|
2023
|
-
} else if (
|
|
2020
|
+
} else if (t17.isMemberExpression(expr.callee)) {
|
|
2024
2021
|
let firstCallee = expr.callee;
|
|
2025
|
-
while (
|
|
2022
|
+
while (t17.isMemberExpression(firstCallee) && t17.isCallExpression(firstCallee.object)) {
|
|
2026
2023
|
firstCallee = firstCallee.object.callee;
|
|
2027
2024
|
}
|
|
2028
2025
|
let current = firstCallee;
|
|
2029
2026
|
const parts = [];
|
|
2030
|
-
while (
|
|
2031
|
-
if (
|
|
2027
|
+
while (t17.isMemberExpression(current)) {
|
|
2028
|
+
if (t17.isIdentifier(current.property)) {
|
|
2032
2029
|
parts.unshift(current.property.name);
|
|
2033
2030
|
}
|
|
2034
2031
|
current = current.object;
|
|
2035
2032
|
}
|
|
2036
|
-
if (
|
|
2033
|
+
if (t17.isIdentifier(current)) {
|
|
2037
2034
|
parts.unshift(current.name);
|
|
2038
2035
|
}
|
|
2039
|
-
if (
|
|
2036
|
+
if (t17.isMemberExpression(firstCallee) && t17.isNewExpression(firstCallee.object) && t17.isIdentifier(firstCallee.object.callee)) {
|
|
2040
2037
|
parts.unshift(firstCallee.object.callee.name);
|
|
2041
2038
|
}
|
|
2042
2039
|
key = parts.join(".");
|
|
2043
2040
|
}
|
|
2044
2041
|
chunks.push(`<function:${key}/>`);
|
|
2045
|
-
} else if (
|
|
2042
|
+
} else if (t17.isIdentifier(expr)) {
|
|
2046
2043
|
chunks.push(`{${expr.name}}`);
|
|
2047
|
-
} else if (
|
|
2044
|
+
} else if (t17.isMemberExpression(expr)) {
|
|
2048
2045
|
let current = expr;
|
|
2049
2046
|
const parts = [];
|
|
2050
|
-
while (
|
|
2051
|
-
if (
|
|
2047
|
+
while (t17.isMemberExpression(current)) {
|
|
2048
|
+
if (t17.isIdentifier(current.property)) {
|
|
2052
2049
|
if (current.computed) {
|
|
2053
2050
|
parts.unshift(`[${current.property.name}]`);
|
|
2054
2051
|
} else {
|
|
@@ -2057,7 +2054,7 @@ function extractJsxContent(nodePath, replaceWhitespacePlaceholders = true) {
|
|
|
2057
2054
|
}
|
|
2058
2055
|
current = current.object;
|
|
2059
2056
|
}
|
|
2060
|
-
if (
|
|
2057
|
+
if (t17.isIdentifier(current)) {
|
|
2061
2058
|
parts.unshift(current.name);
|
|
2062
2059
|
chunks.push(`{${parts.join(".").replaceAll(".[", "[")}}`);
|
|
2063
2060
|
}
|
|
@@ -2078,12 +2075,12 @@ function extractJsxContent(nodePath, replaceWhitespacePlaceholders = true) {
|
|
|
2078
2075
|
}
|
|
2079
2076
|
var compilerProps = ["data-jsx-attribute-scope", "data-jsx-scope"];
|
|
2080
2077
|
function isExpression2(nodePath) {
|
|
2081
|
-
const isCompilerExpression = !_9.isArray(nodePath.container) &&
|
|
2082
|
-
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);
|
|
2083
2080
|
}
|
|
2084
2081
|
function isWhitespace(nodePath) {
|
|
2085
2082
|
const expr = nodePath.node.expression;
|
|
2086
|
-
return
|
|
2083
|
+
return t17.isStringLiteral(expr) && expr.value === " ";
|
|
2087
2084
|
}
|
|
2088
2085
|
function normalizeJsxWhitespace(input) {
|
|
2089
2086
|
const lines = input.split("\n");
|
|
@@ -2143,7 +2140,7 @@ function jsxScopesExportMutation(payload) {
|
|
|
2143
2140
|
}
|
|
2144
2141
|
|
|
2145
2142
|
// src/jsx-attribute-scope-inject.ts
|
|
2146
|
-
import * as
|
|
2143
|
+
import * as t18 from "@babel/types";
|
|
2147
2144
|
var lingoJsxAttributeScopeInjectMutation = createCodeMutation(
|
|
2148
2145
|
(payload) => {
|
|
2149
2146
|
const mode = getModuleExecutionMode(payload.ast, payload.params.rsc);
|
|
@@ -2158,34 +2155,34 @@ var lingoJsxAttributeScopeInjectMutation = createCodeMutation(
|
|
|
2158
2155
|
if (!originalJsxElementName) {
|
|
2159
2156
|
continue;
|
|
2160
2157
|
}
|
|
2161
|
-
jsxScope.node.openingElement.name =
|
|
2158
|
+
jsxScope.node.openingElement.name = t18.jsxIdentifier(
|
|
2162
2159
|
lingoComponentImport.importedName
|
|
2163
2160
|
);
|
|
2164
2161
|
if (jsxScope.node.closingElement) {
|
|
2165
|
-
jsxScope.node.closingElement.name =
|
|
2162
|
+
jsxScope.node.closingElement.name = t18.jsxIdentifier(
|
|
2166
2163
|
lingoComponentImport.importedName
|
|
2167
2164
|
);
|
|
2168
2165
|
}
|
|
2169
|
-
const as = /^[A-Z]/.test(originalJsxElementName) ?
|
|
2166
|
+
const as = /^[A-Z]/.test(originalJsxElementName) ? t18.jsxExpressionContainer(t18.identifier(originalJsxElementName)) : t18.stringLiteral(originalJsxElementName);
|
|
2170
2167
|
jsxScope.node.openingElement.attributes.push(
|
|
2171
|
-
|
|
2168
|
+
t18.jsxAttribute(t18.jsxIdentifier("$attrAs"), as)
|
|
2172
2169
|
);
|
|
2173
2170
|
jsxScope.node.openingElement.attributes.push(
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2171
|
+
t18.jsxAttribute(
|
|
2172
|
+
t18.jsxIdentifier("$fileKey"),
|
|
2173
|
+
t18.stringLiteral(payload.relativeFilePath)
|
|
2177
2174
|
)
|
|
2178
2175
|
);
|
|
2179
2176
|
jsxScope.node.openingElement.attributes.push(
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2177
|
+
t18.jsxAttribute(
|
|
2178
|
+
t18.jsxIdentifier("$attributes"),
|
|
2179
|
+
t18.jsxExpressionContainer(
|
|
2180
|
+
t18.objectExpression(
|
|
2184
2181
|
attributes.map((attributeDefinition) => {
|
|
2185
2182
|
const [attribute, key = ""] = attributeDefinition.split(":");
|
|
2186
|
-
return
|
|
2187
|
-
|
|
2188
|
-
|
|
2183
|
+
return t18.objectProperty(
|
|
2184
|
+
t18.stringLiteral(attribute),
|
|
2185
|
+
t18.stringLiteral(key)
|
|
2189
2186
|
);
|
|
2190
2187
|
})
|
|
2191
2188
|
)
|
|
@@ -2198,14 +2195,14 @@ var lingoJsxAttributeScopeInjectMutation = createCodeMutation(
|
|
|
2198
2195
|
moduleName: "lingo.dev/react/rsc" /* ReactRSC */
|
|
2199
2196
|
});
|
|
2200
2197
|
jsxScope.node.openingElement.attributes.push(
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
[
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
[
|
|
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")]
|
|
2209
2206
|
)
|
|
2210
2207
|
)
|
|
2211
2208
|
)
|
|
@@ -2218,10 +2215,10 @@ var lingoJsxAttributeScopeInjectMutation = createCodeMutation(
|
|
|
2218
2215
|
);
|
|
2219
2216
|
|
|
2220
2217
|
// src/jsx-scope-inject.ts
|
|
2221
|
-
import * as
|
|
2218
|
+
import * as t22 from "@babel/types";
|
|
2222
2219
|
|
|
2223
2220
|
// src/utils/jsx-variables.ts
|
|
2224
|
-
import * as
|
|
2221
|
+
import * as t19 from "@babel/types";
|
|
2225
2222
|
var getJsxVariables = (nodePath) => {
|
|
2226
2223
|
const variables = /* @__PURE__ */ new Set();
|
|
2227
2224
|
nodePath.traverse({
|
|
@@ -2229,13 +2226,13 @@ var getJsxVariables = (nodePath) => {
|
|
|
2229
2226
|
path7.skip();
|
|
2230
2227
|
},
|
|
2231
2228
|
JSXExpressionContainer(path7) {
|
|
2232
|
-
if (
|
|
2229
|
+
if (t19.isIdentifier(path7.node.expression)) {
|
|
2233
2230
|
variables.add(path7.node.expression.name);
|
|
2234
|
-
} else if (
|
|
2231
|
+
} else if (t19.isMemberExpression(path7.node.expression)) {
|
|
2235
2232
|
let current = path7.node.expression;
|
|
2236
2233
|
const parts = [];
|
|
2237
|
-
while (
|
|
2238
|
-
if (
|
|
2234
|
+
while (t19.isMemberExpression(current)) {
|
|
2235
|
+
if (t19.isIdentifier(current.property)) {
|
|
2239
2236
|
if (current.computed) {
|
|
2240
2237
|
parts.unshift(`[${current.property.name}]`);
|
|
2241
2238
|
} else {
|
|
@@ -2244,7 +2241,7 @@ var getJsxVariables = (nodePath) => {
|
|
|
2244
2241
|
}
|
|
2245
2242
|
current = current.object;
|
|
2246
2243
|
}
|
|
2247
|
-
if (
|
|
2244
|
+
if (t19.isIdentifier(current)) {
|
|
2248
2245
|
parts.unshift(current.name);
|
|
2249
2246
|
variables.add(parts.join(".").replaceAll(".[", "["));
|
|
2250
2247
|
}
|
|
@@ -2253,14 +2250,14 @@ var getJsxVariables = (nodePath) => {
|
|
|
2253
2250
|
}
|
|
2254
2251
|
});
|
|
2255
2252
|
const properties = Array.from(variables).map(
|
|
2256
|
-
(name) =>
|
|
2253
|
+
(name) => t19.objectProperty(t19.stringLiteral(name), t19.identifier(name))
|
|
2257
2254
|
);
|
|
2258
|
-
const result =
|
|
2255
|
+
const result = t19.objectExpression(properties);
|
|
2259
2256
|
return result;
|
|
2260
2257
|
};
|
|
2261
2258
|
|
|
2262
2259
|
// src/utils/jsx-functions.ts
|
|
2263
|
-
import * as
|
|
2260
|
+
import * as t20 from "@babel/types";
|
|
2264
2261
|
var getJsxFunctions = (nodePath) => {
|
|
2265
2262
|
const functions = /* @__PURE__ */ new Map();
|
|
2266
2263
|
let fnCounter = 0;
|
|
@@ -2269,27 +2266,27 @@ var getJsxFunctions = (nodePath) => {
|
|
|
2269
2266
|
path7.skip();
|
|
2270
2267
|
},
|
|
2271
2268
|
JSXExpressionContainer(path7) {
|
|
2272
|
-
if (
|
|
2269
|
+
if (t20.isCallExpression(path7.node.expression)) {
|
|
2273
2270
|
let key = "";
|
|
2274
|
-
if (
|
|
2271
|
+
if (t20.isIdentifier(path7.node.expression.callee)) {
|
|
2275
2272
|
key = `${path7.node.expression.callee.name}`;
|
|
2276
|
-
} else if (
|
|
2273
|
+
} else if (t20.isMemberExpression(path7.node.expression.callee)) {
|
|
2277
2274
|
let firstCallee = path7.node.expression.callee;
|
|
2278
|
-
while (
|
|
2275
|
+
while (t20.isMemberExpression(firstCallee) && t20.isCallExpression(firstCallee.object)) {
|
|
2279
2276
|
firstCallee = firstCallee.object.callee;
|
|
2280
2277
|
}
|
|
2281
2278
|
let current = firstCallee;
|
|
2282
2279
|
const parts = [];
|
|
2283
|
-
while (
|
|
2284
|
-
if (
|
|
2280
|
+
while (t20.isMemberExpression(current)) {
|
|
2281
|
+
if (t20.isIdentifier(current.property)) {
|
|
2285
2282
|
parts.unshift(current.property.name);
|
|
2286
2283
|
}
|
|
2287
2284
|
current = current.object;
|
|
2288
2285
|
}
|
|
2289
|
-
if (
|
|
2286
|
+
if (t20.isIdentifier(current)) {
|
|
2290
2287
|
parts.unshift(current.name);
|
|
2291
2288
|
}
|
|
2292
|
-
if (
|
|
2289
|
+
if (t20.isMemberExpression(firstCallee) && t20.isNewExpression(firstCallee.object) && t20.isIdentifier(firstCallee.object.callee)) {
|
|
2293
2290
|
parts.unshift(firstCallee.object.callee.name);
|
|
2294
2291
|
}
|
|
2295
2292
|
key = parts.join(".");
|
|
@@ -2302,13 +2299,13 @@ var getJsxFunctions = (nodePath) => {
|
|
|
2302
2299
|
}
|
|
2303
2300
|
});
|
|
2304
2301
|
const properties = Array.from(functions.entries()).map(
|
|
2305
|
-
([name, callExpr]) =>
|
|
2302
|
+
([name, callExpr]) => t20.objectProperty(t20.stringLiteral(name), t20.arrayExpression(callExpr))
|
|
2306
2303
|
);
|
|
2307
|
-
return
|
|
2304
|
+
return t20.objectExpression(properties);
|
|
2308
2305
|
};
|
|
2309
2306
|
|
|
2310
2307
|
// src/utils/jsx-expressions.ts
|
|
2311
|
-
import * as
|
|
2308
|
+
import * as t21 from "@babel/types";
|
|
2312
2309
|
var getJsxExpressions = (nodePath) => {
|
|
2313
2310
|
const expressions = [];
|
|
2314
2311
|
nodePath.traverse({
|
|
@@ -2317,13 +2314,13 @@ var getJsxExpressions = (nodePath) => {
|
|
|
2317
2314
|
},
|
|
2318
2315
|
JSXExpressionContainer(path7) {
|
|
2319
2316
|
const expr = path7.node.expression;
|
|
2320
|
-
if (!
|
|
2317
|
+
if (!t21.isJSXEmptyExpression(expr) && !t21.isIdentifier(expr) && !t21.isMemberExpression(expr) && !t21.isCallExpression(expr) && !(t21.isStringLiteral(expr) && expr.value === " ")) {
|
|
2321
2318
|
expressions.push(expr);
|
|
2322
2319
|
}
|
|
2323
2320
|
path7.skip();
|
|
2324
2321
|
}
|
|
2325
2322
|
});
|
|
2326
|
-
return
|
|
2323
|
+
return t21.arrayExpression(expressions);
|
|
2327
2324
|
};
|
|
2328
2325
|
|
|
2329
2326
|
// src/jsx-scope-inject.ts
|
|
@@ -2345,53 +2342,53 @@ var lingoJsxScopeInjectMutation = createCodeMutation((payload) => {
|
|
|
2345
2342
|
continue;
|
|
2346
2343
|
}
|
|
2347
2344
|
const originalAttributes = jsxScope.node.openingElement.attributes.slice();
|
|
2348
|
-
const as = /^[A-Z]/.test(originalJsxElementName) ?
|
|
2349
|
-
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));
|
|
2350
2347
|
originalAttributes.push(
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2348
|
+
t22.jsxAttribute(
|
|
2349
|
+
t22.jsxIdentifier("$fileKey"),
|
|
2350
|
+
t22.stringLiteral(payload.relativeFilePath)
|
|
2354
2351
|
)
|
|
2355
2352
|
);
|
|
2356
2353
|
originalAttributes.push(
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2354
|
+
t22.jsxAttribute(
|
|
2355
|
+
t22.jsxIdentifier("$entryKey"),
|
|
2356
|
+
t22.stringLiteral(getJsxScopeAttribute(jsxScope))
|
|
2360
2357
|
)
|
|
2361
2358
|
);
|
|
2362
2359
|
const $variables = getJsxVariables(jsxScope);
|
|
2363
2360
|
if ($variables.properties.length > 0) {
|
|
2364
2361
|
originalAttributes.push(
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2362
|
+
t22.jsxAttribute(
|
|
2363
|
+
t22.jsxIdentifier("$variables"),
|
|
2364
|
+
t22.jsxExpressionContainer($variables)
|
|
2368
2365
|
)
|
|
2369
2366
|
);
|
|
2370
2367
|
}
|
|
2371
2368
|
const $elements = getNestedJsxElements(jsxScope);
|
|
2372
2369
|
if ($elements.elements.length > 0) {
|
|
2373
2370
|
originalAttributes.push(
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2371
|
+
t22.jsxAttribute(
|
|
2372
|
+
t22.jsxIdentifier("$elements"),
|
|
2373
|
+
t22.jsxExpressionContainer($elements)
|
|
2377
2374
|
)
|
|
2378
2375
|
);
|
|
2379
2376
|
}
|
|
2380
2377
|
const $functions = getJsxFunctions(jsxScope);
|
|
2381
2378
|
if ($functions.properties.length > 0) {
|
|
2382
2379
|
originalAttributes.push(
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2380
|
+
t22.jsxAttribute(
|
|
2381
|
+
t22.jsxIdentifier("$functions"),
|
|
2382
|
+
t22.jsxExpressionContainer($functions)
|
|
2386
2383
|
)
|
|
2387
2384
|
);
|
|
2388
2385
|
}
|
|
2389
2386
|
const $expressions = getJsxExpressions(jsxScope);
|
|
2390
2387
|
if ($expressions.elements.length > 0) {
|
|
2391
2388
|
originalAttributes.push(
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2389
|
+
t22.jsxAttribute(
|
|
2390
|
+
t22.jsxIdentifier("$expressions"),
|
|
2391
|
+
t22.jsxExpressionContainer($expressions)
|
|
2395
2392
|
)
|
|
2396
2393
|
);
|
|
2397
2394
|
}
|
|
@@ -2401,23 +2398,23 @@ var lingoJsxScopeInjectMutation = createCodeMutation((payload) => {
|
|
|
2401
2398
|
moduleName: "lingo.dev/react/rsc" /* ReactRSC */
|
|
2402
2399
|
});
|
|
2403
2400
|
originalAttributes.push(
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
[
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
[
|
|
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")]
|
|
2412
2409
|
)
|
|
2413
2410
|
)
|
|
2414
2411
|
)
|
|
2415
2412
|
)
|
|
2416
2413
|
);
|
|
2417
2414
|
}
|
|
2418
|
-
const newNode =
|
|
2419
|
-
|
|
2420
|
-
|
|
2415
|
+
const newNode = t22.jsxElement(
|
|
2416
|
+
t22.jsxOpeningElement(
|
|
2417
|
+
t22.jsxIdentifier(lingoComponentImport.importedName),
|
|
2421
2418
|
originalAttributes,
|
|
2422
2419
|
true
|
|
2423
2420
|
// selfClosing
|
|
@@ -2435,7 +2432,7 @@ var lingoJsxScopeInjectMutation = createCodeMutation((payload) => {
|
|
|
2435
2432
|
});
|
|
2436
2433
|
|
|
2437
2434
|
// src/jsx-remove-attributes.ts
|
|
2438
|
-
import * as
|
|
2435
|
+
import * as t23 from "@babel/types";
|
|
2439
2436
|
import traverse9 from "@babel/traverse";
|
|
2440
2437
|
var jsxRemoveAttributesMutation = createCodeMutation(
|
|
2441
2438
|
(payload) => {
|
|
@@ -2448,7 +2445,7 @@ var jsxRemoveAttributesMutation = createCodeMutation(
|
|
|
2448
2445
|
JSXElement(path7) {
|
|
2449
2446
|
const openingElement = path7.node.openingElement;
|
|
2450
2447
|
openingElement.attributes = openingElement.attributes.filter((attr) => {
|
|
2451
|
-
const removeAttr =
|
|
2448
|
+
const removeAttr = t23.isJSXAttribute(attr) && t23.isJSXIdentifier(attr.name) && ATTRIBUTES_TO_REMOVE.includes(attr.name.name);
|
|
2452
2449
|
return !removeAttr;
|
|
2453
2450
|
});
|
|
2454
2451
|
}
|
|
@@ -2460,7 +2457,7 @@ var jsxRemoveAttributesMutation = createCodeMutation(
|
|
|
2460
2457
|
);
|
|
2461
2458
|
|
|
2462
2459
|
// src/client-dictionary-loader.ts
|
|
2463
|
-
import * as
|
|
2460
|
+
import * as t24 from "@babel/types";
|
|
2464
2461
|
var clientDictionaryLoaderMutation = createCodeMutation((payload) => {
|
|
2465
2462
|
const invokations = findInvokations(payload.ast, {
|
|
2466
2463
|
moduleName: "lingo.dev/react/client" /* ReactClient */,
|
|
@@ -2474,7 +2471,7 @@ var clientDictionaryLoaderMutation = createCodeMutation((payload) => {
|
|
|
2474
2471
|
moduleName: "lingo.dev/react/client" /* ReactClient */,
|
|
2475
2472
|
exportedName: "loadDictionary_internal"
|
|
2476
2473
|
});
|
|
2477
|
-
if (
|
|
2474
|
+
if (t24.isIdentifier(invokation.callee)) {
|
|
2478
2475
|
invokation.callee.name = internalDictionaryLoader.importedName;
|
|
2479
2476
|
}
|
|
2480
2477
|
const dictionaryPath = getDictionaryPath({
|
|
@@ -2482,19 +2479,7 @@ var clientDictionaryLoaderMutation = createCodeMutation((payload) => {
|
|
|
2482
2479
|
lingoDir: payload.params.lingoDir,
|
|
2483
2480
|
relativeFilePath: payload.relativeFilePath
|
|
2484
2481
|
});
|
|
2485
|
-
const localeImportMap =
|
|
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
|
-
);
|
|
2482
|
+
const localeImportMap = createLocaleImportMap(allLocales, dictionaryPath);
|
|
2498
2483
|
invokation.arguments.push(localeImportMap);
|
|
2499
2484
|
}
|
|
2500
2485
|
return payload;
|