@formatjs/cli 6.14.3 → 6.14.5
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/bin/formatjs +2 -2
- package/bin/{gts_extractor-DbRF6KL4.js → gts_extractor-CEZNDfvc.js} +2 -2
- package/bin/{gts_extractor-DbRF6KL4.js.map → gts_extractor-CEZNDfvc.js.map} +1 -1
- package/bin/{parse_script-BLH7yZ7h.js → parse_script-Dh6HQV8l.js} +56 -45
- package/bin/{parse_script-BLH7yZ7h.js.map → parse_script-Dh6HQV8l.js.map} +1 -1
- package/package.json +2 -2
package/bin/formatjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { fileURLToPath as _furl } from "node:url";
|
|
3
3
|
import { dirname as _dname } from "node:path";
|
|
4
4
|
_dname(_furl(import.meta.url));
|
|
5
|
-
import { _ as __exportAll, a as warn, c as require_json_stable_stringify, d as isPluralElement, f as isSelectElement, g as __commonJSMin, h as parse, i as getStdinAsString, l as TYPE, m as isTagElement, n as interpolateName, o as writeStderr, p as isStructurallySame, r as debug, s as writeStdout, t as parseScript, u as isLiteralElement, v as __require, y as __toESM } from "./parse_script-
|
|
5
|
+
import { _ as __exportAll, a as warn, c as require_json_stable_stringify, d as isPluralElement, f as isSelectElement, g as __commonJSMin, h as parse, i as getStdinAsString, l as TYPE, m as isTagElement, n as interpolateName, o as writeStderr, p as isStructurallySame, r as debug, s as writeStdout, t as parseScript, u as isLiteralElement, v as __require, y as __toESM } from "./parse_script-Dh6HQV8l.js";
|
|
6
6
|
import { basename, join, resolve } from "path";
|
|
7
7
|
import { readFileSync } from "fs";
|
|
8
8
|
import { readFile } from "fs/promises";
|
|
@@ -11444,7 +11444,7 @@ async function processFile(source, fn, { idInterpolationPattern, ...opts }) {
|
|
|
11444
11444
|
parseFile(source, fn, opts);
|
|
11445
11445
|
} else if (fn.endsWith(".gts") || fn.endsWith(".gjs")) {
|
|
11446
11446
|
debug("Processing %s as gts/gjs file", fn);
|
|
11447
|
-
const { parseFile } = await import("./gts_extractor-
|
|
11447
|
+
const { parseFile } = await import("./gts_extractor-CEZNDfvc.js");
|
|
11448
11448
|
parseFile(source, fn, opts);
|
|
11449
11449
|
} else {
|
|
11450
11450
|
debug("Processing %s using typescript extractor", fn);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { fileURLToPath as _furl } from "node:url";
|
|
2
2
|
import { dirname as _dname } from "node:path";
|
|
3
3
|
_dname(_furl(import.meta.url));
|
|
4
|
-
import { t as parseScript } from "./parse_script-
|
|
4
|
+
import { t as parseScript } from "./parse_script-Dh6HQV8l.js";
|
|
5
5
|
import { parseFile as parseFile$1 } from "./hbs_extractor-BBhVhSg0.js";
|
|
6
6
|
import { Preprocessor } from "content-tag";
|
|
7
7
|
//#region packages/cli-lib/gts_extractor.ts
|
|
@@ -14,4 +14,4 @@ function parseFile(source, fileName, options) {
|
|
|
14
14
|
//#endregion
|
|
15
15
|
export { parseFile };
|
|
16
16
|
|
|
17
|
-
//# sourceMappingURL=gts_extractor-
|
|
17
|
+
//# sourceMappingURL=gts_extractor-CEZNDfvc.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gts_extractor-
|
|
1
|
+
{"version":3,"file":"gts_extractor-CEZNDfvc.js","names":[],"sources":["../gts_extractor.ts"],"sourcesContent":["import {Preprocessor} from 'content-tag'\nimport {parseFile as parseHbsFile} from '#packages/cli-lib/hbs_extractor.js'\nimport {parseScript} from '#packages/cli-lib/parse_script.js'\nlet p = new Preprocessor()\n\nexport function parseFile(\n source: string,\n fileName: string,\n options: any\n): void {\n const scriptParseFn = parseScript(options, fileName)\n const transformedSource = p.process(source, {filename: fileName})\n\n scriptParseFn(transformedSource.code)\n\n // extract template from transformed source to then run through hbs processor\n const parseResult = p.parse(source, {filename: fileName})\n\n for (let parsed of parseResult) {\n parseHbsFile(parsed.contents, fileName, options)\n }\n}\n"],"mappings":";;;;;;;AAGA,IAAI,IAAI,IAAI,cAAc;AAE1B,SAAgB,UACd,QACA,UACA,SACM;AACgB,aAAY,SAAS,SAAS,CAC1B,EAAE,QAAQ,QAAQ,EAAC,UAAU,UAAS,CAAC,CAEjC,KAAK;CAGrC,MAAM,cAAc,EAAE,MAAM,QAAQ,EAAC,UAAU,UAAS,CAAC;AAEzD,MAAK,IAAI,UAAU,YACjB,aAAa,OAAO,UAAU,UAAU,QAAQ"}
|
|
@@ -151818,7 +151818,8 @@ function isSingularMessageDecl(ts, node, additionalComponentNames) {
|
|
|
151818
151818
|
return compNames.has(fnName);
|
|
151819
151819
|
}
|
|
151820
151820
|
function evaluateStringConcat(ts, node) {
|
|
151821
|
-
const
|
|
151821
|
+
const right = unwrapTransparentTypeScriptExpression(ts, node.right);
|
|
151822
|
+
const left = unwrapTransparentTypeScriptExpression(ts, node.left);
|
|
151822
151823
|
if (!ts.isStringLiteral(right)) return ["", false];
|
|
151823
151824
|
if (ts.isStringLiteral(left)) return [left.text + right.text, true];
|
|
151824
151825
|
if (ts.isBinaryExpression(left)) {
|
|
@@ -151827,6 +151828,15 @@ function evaluateStringConcat(ts, node) {
|
|
|
151827
151828
|
}
|
|
151828
151829
|
return ["", false];
|
|
151829
151830
|
}
|
|
151831
|
+
function unwrapTransparentTypeScriptExpression(ts, node) {
|
|
151832
|
+
let current = node;
|
|
151833
|
+
while (ts.isAsExpression(current) || ts.isSatisfiesExpression(current) || ts.isNonNullExpression(current) || ts.isTypeAssertionExpression(current)) current = current.expression;
|
|
151834
|
+
return current;
|
|
151835
|
+
}
|
|
151836
|
+
function unwrapObjectLiteralExpression(ts, node) {
|
|
151837
|
+
const expression = unwrapTransparentTypeScriptExpression(ts, node);
|
|
151838
|
+
return ts.isObjectLiteralExpression(expression) ? expression : void 0;
|
|
151839
|
+
}
|
|
151830
151840
|
function extractMessageDescriptor(ts, node, { overrideIdFn, extractSourceLocation, preserveWhitespace, flatten, throws = true, onMsgError }, sf) {
|
|
151831
151841
|
let extractionError = null;
|
|
151832
151842
|
function handleError(errorMsg, errorNode) {
|
|
@@ -151849,31 +151859,32 @@ function extractMessageDescriptor(ts, node, { overrideIdFn, extractSourceLocatio
|
|
|
151849
151859
|
const { name } = prop;
|
|
151850
151860
|
const initializer = ts.isPropertyAssignment(prop) || ts.isJsxAttribute(prop) ? prop.initializer : void 0;
|
|
151851
151861
|
if (name && ts.isIdentifier(name) && initializer) {
|
|
151852
|
-
|
|
151862
|
+
const value = ts.isPropertyAssignment(prop) ? unwrapTransparentTypeScriptExpression(ts, prop.initializer) : initializer;
|
|
151863
|
+
if (ts.isStringLiteral(value)) switch (name.text) {
|
|
151853
151864
|
case "id":
|
|
151854
|
-
msg.id =
|
|
151865
|
+
msg.id = value.text;
|
|
151855
151866
|
break;
|
|
151856
151867
|
case "defaultMessage":
|
|
151857
|
-
msg.defaultMessage =
|
|
151868
|
+
msg.defaultMessage = value.text;
|
|
151858
151869
|
break;
|
|
151859
151870
|
case "description":
|
|
151860
|
-
msg.description =
|
|
151871
|
+
msg.description = value.text;
|
|
151861
151872
|
break;
|
|
151862
151873
|
}
|
|
151863
|
-
else if (ts.isNoSubstitutionTemplateLiteral(
|
|
151874
|
+
else if (ts.isNoSubstitutionTemplateLiteral(value)) switch (name.text) {
|
|
151864
151875
|
case "id":
|
|
151865
|
-
msg.id =
|
|
151876
|
+
msg.id = value.text;
|
|
151866
151877
|
break;
|
|
151867
151878
|
case "defaultMessage":
|
|
151868
|
-
msg.defaultMessage =
|
|
151879
|
+
msg.defaultMessage = value.text;
|
|
151869
151880
|
break;
|
|
151870
151881
|
case "description":
|
|
151871
|
-
msg.description =
|
|
151882
|
+
msg.description = value.text;
|
|
151872
151883
|
break;
|
|
151873
151884
|
}
|
|
151874
|
-
else if (ts.isTaggedTemplateExpression(
|
|
151885
|
+
else if (ts.isTaggedTemplateExpression(value)) {
|
|
151875
151886
|
if (!(name.text === "id" || name.text === "defaultMessage" || name.text === "description")) return;
|
|
151876
|
-
const { template } =
|
|
151887
|
+
const { template } = value;
|
|
151877
151888
|
if (!ts.isNoSubstitutionTemplateLiteral(template)) {
|
|
151878
151889
|
handleError("[FormatJS] Tagged template expression must be no substitution", prop);
|
|
151879
151890
|
return;
|
|
@@ -151889,35 +151900,34 @@ function extractMessageDescriptor(ts, node, { overrideIdFn, extractSourceLocatio
|
|
|
151889
151900
|
msg.description = template.text;
|
|
151890
151901
|
break;
|
|
151891
151902
|
}
|
|
151892
|
-
} else if (ts.isJsxExpression(
|
|
151893
|
-
|
|
151903
|
+
} else if (ts.isJsxExpression(value) && value.expression) {
|
|
151904
|
+
const expression = unwrapTransparentTypeScriptExpression(ts, value.expression);
|
|
151905
|
+
if (ts.isStringLiteral(expression)) switch (name.text) {
|
|
151894
151906
|
case "id":
|
|
151895
|
-
msg.id =
|
|
151907
|
+
msg.id = expression.text;
|
|
151896
151908
|
break;
|
|
151897
151909
|
case "defaultMessage":
|
|
151898
|
-
msg.defaultMessage =
|
|
151910
|
+
msg.defaultMessage = expression.text;
|
|
151899
151911
|
break;
|
|
151900
151912
|
case "description":
|
|
151901
|
-
msg.description =
|
|
151913
|
+
msg.description = expression.text;
|
|
151902
151914
|
break;
|
|
151903
151915
|
}
|
|
151904
|
-
else if (ts.isObjectLiteralExpression(
|
|
151905
|
-
else if (ts.isNoSubstitutionTemplateLiteral(
|
|
151906
|
-
|
|
151907
|
-
|
|
151908
|
-
|
|
151909
|
-
|
|
151910
|
-
|
|
151911
|
-
|
|
151912
|
-
|
|
151913
|
-
|
|
151914
|
-
|
|
151915
|
-
|
|
151916
|
-
|
|
151917
|
-
}
|
|
151918
|
-
} else if (ts.isTaggedTemplateExpression(initializer.expression)) {
|
|
151916
|
+
else if (ts.isObjectLiteralExpression(expression) && name.text === "description") msg.description = objectLiteralExpressionToObj(ts, expression);
|
|
151917
|
+
else if (ts.isNoSubstitutionTemplateLiteral(expression)) switch (name.text) {
|
|
151918
|
+
case "id":
|
|
151919
|
+
msg.id = expression.text;
|
|
151920
|
+
break;
|
|
151921
|
+
case "defaultMessage":
|
|
151922
|
+
msg.defaultMessage = expression.text;
|
|
151923
|
+
break;
|
|
151924
|
+
case "description":
|
|
151925
|
+
msg.description = expression.text;
|
|
151926
|
+
break;
|
|
151927
|
+
}
|
|
151928
|
+
else if (ts.isTaggedTemplateExpression(expression)) {
|
|
151919
151929
|
if (!(name.text === "id" || name.text === "defaultMessage" || name.text === "description")) return;
|
|
151920
|
-
const {
|
|
151930
|
+
const { template } = expression;
|
|
151921
151931
|
if (!ts.isNoSubstitutionTemplateLiteral(template)) {
|
|
151922
151932
|
handleError("[FormatJS] Tagged template expression must be no substitution", prop);
|
|
151923
151933
|
return;
|
|
@@ -151933,8 +151943,7 @@ function extractMessageDescriptor(ts, node, { overrideIdFn, extractSourceLocatio
|
|
|
151933
151943
|
msg.description = template.text;
|
|
151934
151944
|
break;
|
|
151935
151945
|
}
|
|
151936
|
-
} else if (ts.isBinaryExpression(
|
|
151937
|
-
const { expression } = initializer;
|
|
151946
|
+
} else if (ts.isBinaryExpression(expression)) {
|
|
151938
151947
|
const [result, isStatic] = evaluateStringConcat(ts, expression);
|
|
151939
151948
|
if (isStatic) switch (name.text) {
|
|
151940
151949
|
case "id":
|
|
@@ -151955,8 +151964,8 @@ function extractMessageDescriptor(ts, node, { overrideIdFn, extractSourceLocatio
|
|
|
151955
151964
|
handleError(`[FormatJS] \`${name.text}\` must be a string literal to be extracted.`, prop);
|
|
151956
151965
|
return;
|
|
151957
151966
|
}
|
|
151958
|
-
} else if (ts.isBinaryExpression(
|
|
151959
|
-
const [result, isStatic] = evaluateStringConcat(ts,
|
|
151967
|
+
} else if (ts.isBinaryExpression(value)) {
|
|
151968
|
+
const [result, isStatic] = evaluateStringConcat(ts, value);
|
|
151960
151969
|
if (isStatic) switch (name.text) {
|
|
151961
151970
|
case "id":
|
|
151962
151971
|
msg.id = result;
|
|
@@ -151972,7 +151981,7 @@ function extractMessageDescriptor(ts, node, { overrideIdFn, extractSourceLocatio
|
|
|
151972
151981
|
handleError(`[FormatJS] \`${name.text}\` must be a string literal or statically evaluable expression to be extracted.`, prop);
|
|
151973
151982
|
return;
|
|
151974
151983
|
}
|
|
151975
|
-
} else if (ts.isObjectLiteralExpression(
|
|
151984
|
+
} else if (ts.isObjectLiteralExpression(value) && name.text === "description") msg.description = objectLiteralExpressionToObj(ts, value);
|
|
151976
151985
|
else if (MESSAGE_DESC_KEYS.includes(name.text) && name.text !== "description") {
|
|
151977
151986
|
handleError(`[FormatJS] \`${name.text}\` must be a string literal to be extracted.`, prop);
|
|
151978
151987
|
return;
|
|
@@ -152056,12 +152065,13 @@ function extractMessagesFromCallExpression(ts, factory, node, opts, sf) {
|
|
|
152056
152065
|
const { onMsgExtracted, additionalFunctionNames } = opts;
|
|
152057
152066
|
if (isMultipleMessageDecl(ts, node)) {
|
|
152058
152067
|
const [arg, ...restArgs] = node.arguments;
|
|
152059
|
-
|
|
152060
|
-
if (ts.isObjectLiteralExpression(arg)) descriptorsObj = arg;
|
|
152061
|
-
else if (ts.isAsExpression(arg) && ts.isObjectLiteralExpression(arg.expression)) descriptorsObj = arg.expression;
|
|
152068
|
+
const descriptorsObj = unwrapObjectLiteralExpression(ts, arg);
|
|
152062
152069
|
if (descriptorsObj) {
|
|
152063
152070
|
const properties = descriptorsObj.properties;
|
|
152064
|
-
const msgs = properties.filter((prop) => ts.isPropertyAssignment(prop)).map((prop) =>
|
|
152071
|
+
const msgs = properties.filter((prop) => ts.isPropertyAssignment(prop)).map((prop) => {
|
|
152072
|
+
const descriptor = unwrapObjectLiteralExpression(ts, prop.initializer);
|
|
152073
|
+
return descriptor && extractMessageDescriptor(ts, descriptor, opts, sf);
|
|
152074
|
+
}).filter((msg) => !!msg);
|
|
152065
152075
|
if (!msgs.length) return node;
|
|
152066
152076
|
debug("Multiple messages extracted from \"%s\": %s", sf.fileName, msgs);
|
|
152067
152077
|
if (typeof onMsgExtracted === "function") onMsgExtracted(sf.fileName, msgs);
|
|
@@ -152077,12 +152087,13 @@ function extractMessagesFromCallExpression(ts, factory, node, opts, sf) {
|
|
|
152077
152087
|
}
|
|
152078
152088
|
} else if (isSingularMessageDecl(ts, node, opts.additionalComponentNames || []) || isMemberMethodFormatMessageCall(ts, node, additionalFunctionNames || [])) {
|
|
152079
152089
|
const [descriptorsObj, ...restArgs] = node.arguments;
|
|
152080
|
-
|
|
152081
|
-
|
|
152090
|
+
const descriptor = unwrapObjectLiteralExpression(ts, descriptorsObj);
|
|
152091
|
+
if (descriptor) {
|
|
152092
|
+
const msg = extractMessageDescriptor(ts, descriptor, opts, sf);
|
|
152082
152093
|
if (!msg) return node;
|
|
152083
152094
|
debug("Message extracted from \"%s\": %s", sf.fileName, msg);
|
|
152084
152095
|
if (typeof onMsgExtracted === "function") onMsgExtracted(sf.fileName, [msg]);
|
|
152085
|
-
return factory.updateCallExpression(node, node.expression, node.typeArguments, [setAttributesInObject(ts, factory,
|
|
152096
|
+
return factory.updateCallExpression(node, node.expression, node.typeArguments, [setAttributesInObject(ts, factory, descriptor, {
|
|
152086
152097
|
defaultMessage: opts.removeDefaultMessage ? void 0 : msg.defaultMessage,
|
|
152087
152098
|
id: msg.id
|
|
152088
152099
|
}, opts.ast), ...restArgs]);
|
|
@@ -152167,4 +152178,4 @@ ${e.message || ""}`;
|
|
|
152167
152178
|
//#endregion
|
|
152168
152179
|
export { __exportAll as _, warn as a, require_json_stable_stringify as c, isPluralElement$2 as d, isSelectElement$2 as f, __commonJSMin as g, parse as h, getStdinAsString as i, TYPE$2 as l, isTagElement$2 as m, interpolateName as n, writeStderr as o, isStructurallySame as p, debug$1 as r, writeStdout as s, parseScript as t, isLiteralElement$1 as u, __require as v, __toESM as y };
|
|
152169
152180
|
|
|
152170
|
-
//# sourceMappingURL=parse_script-
|
|
152181
|
+
//# sourceMappingURL=parse_script-Dh6HQV8l.js.map
|