@formatjs/ts-transformer 3.9.8 → 3.9.11

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/LICENSE.md CHANGED
File without changes
package/README.md CHANGED
File without changes
package/index.d.ts CHANGED
File without changes
package/index.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/ts-transformer/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,wBAAwB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,wBAAwB,CAAA"}
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
4
- (0, tslib_1.__exportStar)(require("./src/transform"), exports);
5
- (0, tslib_1.__exportStar)(require("./src/types"), exports);
6
- (0, tslib_1.__exportStar)(require("./src/interpolate-name"), exports);
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./src/transform"), exports);
5
+ tslib_1.__exportStar(require("./src/types"), exports);
6
+ tslib_1.__exportStar(require("./src/interpolate-name"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formatjs/ts-transformer",
3
- "version": "3.9.8",
3
+ "version": "3.9.11",
4
4
  "description": "TS Compiler transformer for formatjs",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -17,7 +17,7 @@
17
17
  "react-intl"
18
18
  ],
19
19
  "dependencies": {
20
- "@formatjs/icu-messageformat-parser": "2.1.3",
20
+ "@formatjs/icu-messageformat-parser": "2.1.6",
21
21
  "@types/json-stable-stringify": "^1.0.32",
22
22
  "@types/node": "14 || 16 || 17",
23
23
  "chalk": "^4.0.0",
@@ -26,7 +26,7 @@
26
26
  "typescript": "^4.5"
27
27
  },
28
28
  "peerDependencies": {
29
- "ts-jest": "27"
29
+ "ts-jest": "27 || 28"
30
30
  },
31
31
  "peerDependenciesMeta": {
32
32
  "ts-jest": {
@@ -39,4 +39,4 @@
39
39
  "url": "https://github.com/formatjs/formatjs/issues"
40
40
  },
41
41
  "homepage": "https://github.com/formatjs/formatjs#readme"
42
- }
42
+ }
File without changes
@@ -1 +1 @@
1
- {"version":3,"file":"console_utils.d.ts","sourceRoot":"","sources":["../../../../../../packages/ts-transformer/src/console_utils.ts"],"names":[],"mappings":"AAeA,wBAAsB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,iBAM1D;AAED,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAG1D;AAED,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAG3D"}
1
+ {"version":3,"file":"console_utils.d.ts","sourceRoot":"","sources":["console_utils.ts"],"names":[],"mappings":"AAeA,wBAAsB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,iBAM1D;AAED,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAG1D;AAED,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAG3D"}
@@ -1,49 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.error = exports.warn = exports.debug = void 0;
4
- var tslib_1 = require("tslib");
5
- var chalk_1 = require("chalk");
6
- var util_1 = require("util");
7
- var LEVEL_COLORS = {
4
+ const chalk_1 = require("chalk");
5
+ const util_1 = require("util");
6
+ const LEVEL_COLORS = {
8
7
  debug: chalk_1.green,
9
8
  warn: chalk_1.yellow,
10
9
  error: chalk_1.red,
11
10
  };
12
11
  function label(level, message) {
13
- return "[@formatjs/ts-transformer] [".concat(LEVEL_COLORS[level](level.toUpperCase()), "] ").concat(message);
12
+ return `[@formatjs/ts-transformer] [${LEVEL_COLORS[level](level.toUpperCase())}] ${message}`;
14
13
  }
15
- function debug(message) {
16
- var args = [];
17
- for (var _i = 1; _i < arguments.length; _i++) {
18
- args[_i - 1] = arguments[_i];
14
+ async function debug(message, ...args) {
15
+ if (process.env.LOG_LEVEL !== 'debug') {
16
+ return;
19
17
  }
20
- return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
21
- return (0, tslib_1.__generator)(this, function (_a) {
22
- if (process.env.LOG_LEVEL !== 'debug') {
23
- return [2 /*return*/];
24
- }
25
- console.error(util_1.format.apply(void 0, (0, tslib_1.__spreadArray)([label('debug', message)], args, false)));
26
- console.error('\n');
27
- return [2 /*return*/];
28
- });
29
- });
18
+ console.error((0, util_1.format)(label('debug', message), ...args));
19
+ console.error('\n');
30
20
  }
31
21
  exports.debug = debug;
32
- function warn(message) {
33
- var args = [];
34
- for (var _i = 1; _i < arguments.length; _i++) {
35
- args[_i - 1] = arguments[_i];
36
- }
37
- console.error(util_1.format.apply(void 0, (0, tslib_1.__spreadArray)([label('warn', message)], args, false)));
22
+ function warn(message, ...args) {
23
+ console.error((0, util_1.format)(label('warn', message), ...args));
38
24
  console.error('\n');
39
25
  }
40
26
  exports.warn = warn;
41
- function error(message) {
42
- var args = [];
43
- for (var _i = 1; _i < arguments.length; _i++) {
44
- args[_i - 1] = arguments[_i];
45
- }
46
- console.error(util_1.format.apply(void 0, (0, tslib_1.__spreadArray)([label('error', message)], args, false)));
27
+ function error(message, ...args) {
28
+ console.error((0, util_1.format)(label('error', message), ...args));
47
29
  console.error('\n');
48
30
  }
49
31
  exports.error = error;
File without changes
@@ -1 +1 @@
1
- {"version":3,"file":"interpolate-name.d.ts","sourceRoot":"","sources":["../../../../../../packages/ts-transformer/src/interpolate-name.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,aAAa;IAC5B,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,OAAO,CAAC,EAAE;QACR,qBAAqB,CACnB,IAAI,EAAE,aAAa,EACnB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,GAAG,MAAM,EACrB,OAAO,EAAE,OAAO,GACf,MAAM,CAAA;KACV,CAAA;CACF;AAED,MAAM,WAAW,OAAO;IACtB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,oBAAY,MAAM,GAAG,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,KAAK,MAAM,CAAA;AAa9E,wBAAgB,eAAe,CAC7B,aAAa,EAAE,aAAa,EAC5B,IAAI,EAAE,MAAM,GAAG,MAAM,EACrB,OAAO,EAAE,OAAO,UA6GjB"}
1
+ {"version":3,"file":"interpolate-name.d.ts","sourceRoot":"","sources":["interpolate-name.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,aAAa;IAC5B,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,OAAO,CAAC,EAAE;QACR,qBAAqB,CACnB,IAAI,EAAE,aAAa,EACnB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,GAAG,MAAM,EACrB,OAAO,EAAE,OAAO,GACf,MAAM,CAAA;KACV,CAAA;CACF;AAED,MAAM,WAAW,OAAO;IACtB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,oBAAY,MAAM,GAAG,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,KAAK,MAAM,CAAA;AAa9E,wBAAgB,eAAe,CAC7B,aAAa,EAAE,aAAa,EAC5B,IAAI,EAAE,MAAM,GAAG,MAAM,EACrB,OAAO,EAAE,OAAO,UA6GjB"}
@@ -1,37 +1,34 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.interpolateName = void 0;
4
- var tslib_1 = require("tslib");
5
- var path = (0, tslib_1.__importStar)(require("path"));
6
- var crypto_1 = require("crypto");
7
- function getHashDigest(content, hashType, digestType, length) {
8
- if (hashType === void 0) { hashType = 'md5'; }
9
- if (digestType === void 0) { digestType = 'hex'; }
10
- if (length === void 0) { length = 9999; }
11
- var hasher = (0, crypto_1.createHash)(hashType);
4
+ const tslib_1 = require("tslib");
5
+ const path = tslib_1.__importStar(require("path"));
6
+ const crypto_1 = require("crypto");
7
+ function getHashDigest(content, hashType = 'md5', digestType = 'hex', length = 9999) {
8
+ const hasher = (0, crypto_1.createHash)(hashType);
12
9
  hasher.update(content);
13
10
  return hasher.digest(digestType).slice(0, length);
14
11
  }
15
12
  function interpolateName(loaderContext, name, options) {
16
- var filename;
17
- var hasQuery = loaderContext.resourceQuery && loaderContext.resourceQuery.length > 1;
13
+ let filename;
14
+ const hasQuery = loaderContext.resourceQuery && loaderContext.resourceQuery.length > 1;
18
15
  if (typeof name === 'function') {
19
16
  filename = name(loaderContext.resourcePath, hasQuery ? loaderContext.resourceQuery : undefined);
20
17
  }
21
18
  else {
22
19
  filename = name || '[hash].[ext]';
23
20
  }
24
- var context = options.context;
25
- var content = options.content;
26
- var regExp = options.regExp;
27
- var ext = 'bin';
28
- var basename = 'file';
29
- var directory = '';
30
- var folder = '';
31
- var query = '';
21
+ const context = options.context;
22
+ const content = options.content;
23
+ const regExp = options.regExp;
24
+ let ext = 'bin';
25
+ let basename = 'file';
26
+ let directory = '';
27
+ let folder = '';
28
+ let query = '';
32
29
  if (loaderContext.resourcePath) {
33
- var parsed = path.parse(loaderContext.resourcePath);
34
- var resourcePath = loaderContext.resourcePath;
30
+ const parsed = path.parse(loaderContext.resourcePath);
31
+ let resourcePath = loaderContext.resourcePath;
35
32
  if (parsed.ext) {
36
33
  ext = parsed.ext.slice(1);
37
34
  }
@@ -58,31 +55,29 @@ function interpolateName(loaderContext, name, options) {
58
55
  }
59
56
  if (loaderContext.resourceQuery && loaderContext.resourceQuery.length > 1) {
60
57
  query = loaderContext.resourceQuery;
61
- var hashIdx = query.indexOf('#');
58
+ const hashIdx = query.indexOf('#');
62
59
  if (hashIdx >= 0) {
63
60
  query = query.slice(0, hashIdx);
64
61
  }
65
62
  }
66
- var url = filename;
63
+ let url = filename;
67
64
  if (content) {
68
65
  // Match hash template
69
66
  url = url
70
67
  // `hash` and `contenthash` are same in `loader-utils` context
71
68
  // let's keep `hash` for backward compatibility
72
- .replace(/\[(?:([^:\]]+):)?(?:hash|contenthash)(?::([a-z]+\d*))?(?::(\d+))?\]/gi, function (_, hashType, digestType, maxLength) {
73
- return getHashDigest(content, hashType, digestType, parseInt(maxLength, 10));
74
- });
69
+ .replace(/\[(?:([^:\]]+):)?(?:hash|contenthash)(?::([a-z]+\d*))?(?::(\d+))?\]/gi, (_, hashType, digestType, maxLength) => getHashDigest(content, hashType, digestType, parseInt(maxLength, 10)));
75
70
  }
76
71
  url = url
77
- .replace(/\[ext\]/gi, function () { return ext; })
78
- .replace(/\[name\]/gi, function () { return basename; })
79
- .replace(/\[path\]/gi, function () { return directory; })
80
- .replace(/\[folder\]/gi, function () { return folder; })
81
- .replace(/\[query\]/gi, function () { return query; });
72
+ .replace(/\[ext\]/gi, () => ext)
73
+ .replace(/\[name\]/gi, () => basename)
74
+ .replace(/\[path\]/gi, () => directory)
75
+ .replace(/\[folder\]/gi, () => folder)
76
+ .replace(/\[query\]/gi, () => query);
82
77
  if (regExp && loaderContext.resourcePath) {
83
- var match = loaderContext.resourcePath.match(new RegExp(regExp));
78
+ const match = loaderContext.resourcePath.match(new RegExp(regExp));
84
79
  match &&
85
- match.forEach(function (matched, i) {
80
+ match.forEach((matched, i) => {
86
81
  url = url.replace(new RegExp('\\[' + i + '\\]', 'ig'), matched);
87
82
  });
88
83
  }
File without changes
@@ -1 +1 @@
1
- {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../../../../packages/ts-transformer/src/transform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,YAAY,CAAA;AACxC,OAAO,EAAC,iBAAiB,EAAC,MAAM,SAAS,CAAA;AAKzC,oBAAY,SAAS,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB,EAAE,KAAK,IAAI,CAAA;AAC7E,oBAAY,aAAa,GAAG,CAC1B,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KACzB,IAAI,CAAA;AAET,oBAAY,iBAAiB,GAAG,CAC9B,EAAE,CAAC,EAAE,iBAAiB,CAAC,IAAI,CAAC,EAC5B,cAAc,CAAC,EAAE,iBAAiB,CAAC,gBAAgB,CAAC,EACpD,WAAW,CAAC,EAAE,iBAAiB,CAAC,aAAa,CAAC,EAC9C,QAAQ,CAAC,EAAE,MAAM,KACd,MAAM,CAAA;AAQX,aAAK,UAAU,GAAG,OAAO,UAAU,CAAA;AA2FnC,MAAM,WAAW,IAAI;IACnB;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;;;OAKG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAA;IAC/B;;OAEG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B;;;OAGG;IACH,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAA;IACnC;;;;OAIG;IACH,uBAAuB,CAAC,EAAE,MAAM,EAAE,CAAA;IAClC;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,SAAS,CAAA;IAC1B;;;OAGG;IACH,eAAe,CAAC,EAAE,aAAa,CAAA;IAC/B;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,iBAAiB,GAAG,MAAM,CAAA;IACzC;;;OAGG;IACH,GAAG,CAAC,EAAE,OAAO,CAAA;IACb;;OAEG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B;AAmiBD,wBAAgB,eAAe,CAAC,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,wDA6BzD;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,wDAEnC"}
1
+ {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["transform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,YAAY,CAAA;AACxC,OAAO,EAAC,iBAAiB,EAAC,MAAM,SAAS,CAAA;AAKzC,oBAAY,SAAS,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB,EAAE,KAAK,IAAI,CAAA;AAC7E,oBAAY,aAAa,GAAG,CAC1B,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KACzB,IAAI,CAAA;AAET,oBAAY,iBAAiB,GAAG,CAC9B,EAAE,CAAC,EAAE,iBAAiB,CAAC,IAAI,CAAC,EAC5B,cAAc,CAAC,EAAE,iBAAiB,CAAC,gBAAgB,CAAC,EACpD,WAAW,CAAC,EAAE,iBAAiB,CAAC,aAAa,CAAC,EAC9C,QAAQ,CAAC,EAAE,MAAM,KACd,MAAM,CAAA;AAQX,aAAK,UAAU,GAAG,OAAO,UAAU,CAAA;AA2FnC,MAAM,WAAW,IAAI;IACnB;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;;;OAKG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAA;IAC/B;;OAEG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B;;;OAGG;IACH,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAA;IACnC;;;;OAIG;IACH,uBAAuB,CAAC,EAAE,MAAM,EAAE,CAAA;IAClC;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,SAAS,CAAA;IAC1B;;;OAGG;IACH,eAAe,CAAC,EAAE,aAAa,CAAA;IAC/B;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,iBAAiB,GAAG,MAAM,CAAA;IACzC;;;OAGG;IACH,GAAG,CAAC,EAAE,OAAO,CAAA;IACb;;OAEG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B;AAmiBD,wBAAgB,eAAe,CAAC,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,wDA6BzD;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,wDAEnC"}
package/src/transform.js CHANGED
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transform = exports.transformWithTs = void 0;
4
- var tslib_1 = require("tslib");
5
- var typescript = (0, tslib_1.__importStar)(require("typescript"));
6
- var interpolate_name_1 = require("./interpolate-name");
7
- var icu_messageformat_parser_1 = require("@formatjs/icu-messageformat-parser");
8
- var console_utils_1 = require("./console_utils");
9
- var json_stable_stringify_1 = (0, tslib_1.__importDefault)(require("json-stable-stringify"));
10
- var MESSAGE_DESC_KEYS = [
4
+ const tslib_1 = require("tslib");
5
+ const typescript = tslib_1.__importStar(require("typescript"));
6
+ const interpolate_name_1 = require("./interpolate-name");
7
+ const icu_messageformat_parser_1 = require("@formatjs/icu-messageformat-parser");
8
+ const console_utils_1 = require("./console_utils");
9
+ const json_stable_stringify_1 = tslib_1.__importDefault(require("json-stable-stringify"));
10
+ const MESSAGE_DESC_KEYS = [
11
11
  'id',
12
12
  'defaultMessage',
13
13
  'description',
@@ -25,7 +25,7 @@ function primitiveToTSNode(factory, v) {
25
25
  }
26
26
  function isValidIdentifier(k) {
27
27
  try {
28
- new Function("return {".concat(k, ":1}"));
28
+ new Function(`return {${k}:1}`);
29
29
  return true;
30
30
  }
31
31
  catch (e) {
@@ -36,24 +36,18 @@ function objToTSNode(factory, obj) {
36
36
  if (typeof obj === 'object' && !obj) {
37
37
  return factory.createNull();
38
38
  }
39
- var props = Object.entries(obj)
40
- .filter(function (_a) {
41
- var _ = _a[0], v = _a[1];
42
- return typeof v !== 'undefined';
43
- })
44
- .map(function (_a) {
45
- var k = _a[0], v = _a[1];
46
- return factory.createPropertyAssignment(isValidIdentifier(k) ? k : factory.createStringLiteral(k), primitiveToTSNode(factory, v) ||
47
- (Array.isArray(v)
48
- ? factory.createArrayLiteralExpression(v
49
- .filter(function (n) { return typeof n !== 'undefined'; })
50
- .map(function (n) { return objToTSNode(factory, n); }))
51
- : objToTSNode(factory, v)));
52
- });
39
+ const props = Object.entries(obj)
40
+ .filter(([_, v]) => typeof v !== 'undefined')
41
+ .map(([k, v]) => factory.createPropertyAssignment(isValidIdentifier(k) ? k : factory.createStringLiteral(k), primitiveToTSNode(factory, v) ||
42
+ (Array.isArray(v)
43
+ ? factory.createArrayLiteralExpression(v
44
+ .filter(n => typeof n !== 'undefined')
45
+ .map(n => objToTSNode(factory, n)))
46
+ : objToTSNode(factory, v))));
53
47
  return factory.createObjectLiteralExpression(props);
54
48
  }
55
49
  function messageASTToTSNode(factory, ast) {
56
- return factory.createArrayLiteralExpression(ast.map(function (el) { return objToTSNode(factory, el); }));
50
+ return factory.createArrayLiteralExpression(ast.map(el => objToTSNode(factory, el)));
57
51
  }
58
52
  function literalToObj(ts, n) {
59
53
  if (ts.isNumericLiteral(n)) {
@@ -70,7 +64,7 @@ function literalToObj(ts, n) {
70
64
  }
71
65
  }
72
66
  function objectLiteralExpressionToObj(ts, obj) {
73
- return obj.properties.reduce(function (all, prop) {
67
+ return obj.properties.reduce((all, prop) => {
74
68
  if (ts.isPropertyAssignment(prop) && prop.name) {
75
69
  if (ts.isIdentifier(prop.name)) {
76
70
  all[prop.name.escapedText.toString()] = literalToObj(ts, prop.initializer);
@@ -82,22 +76,23 @@ function objectLiteralExpressionToObj(ts, obj) {
82
76
  return all;
83
77
  }, {});
84
78
  }
85
- var DEFAULT_OPTS = {
86
- onMsgExtracted: function () { return undefined; },
87
- onMetaExtracted: function () { return undefined; },
79
+ const DEFAULT_OPTS = {
80
+ onMsgExtracted: () => undefined,
81
+ onMetaExtracted: () => undefined,
88
82
  };
89
83
  function isMultipleMessageDecl(ts, node) {
90
84
  return (ts.isIdentifier(node.expression) &&
91
85
  node.expression.text === 'defineMessages');
92
86
  }
93
87
  function isSingularMessageDecl(ts, node, additionalComponentNames) {
94
- var compNames = new Set((0, tslib_1.__spreadArray)([
88
+ const compNames = new Set([
95
89
  'FormattedMessage',
96
90
  'defineMessage',
97
91
  'formatMessage',
98
- '$formatMessage'
99
- ], additionalComponentNames, true));
100
- var fnName = '';
92
+ '$formatMessage',
93
+ ...additionalComponentNames,
94
+ ]);
95
+ let fnName = '';
101
96
  if (ts.isCallExpression(node) && ts.isIdentifier(node.expression)) {
102
97
  fnName = node.expression.text;
103
98
  }
@@ -111,7 +106,7 @@ function isSingularMessageDecl(ts, node, additionalComponentNames) {
111
106
  return compNames.has(fnName);
112
107
  }
113
108
  function evaluateStringConcat(ts, node) {
114
- var right = node.right, left = node.left;
109
+ const { right, left } = node;
115
110
  if (!ts.isStringLiteral(right)) {
116
111
  return ['', false];
117
112
  }
@@ -119,27 +114,26 @@ function evaluateStringConcat(ts, node) {
119
114
  return [left.text + right.text, true];
120
115
  }
121
116
  if (ts.isBinaryExpression(left)) {
122
- var _a = evaluateStringConcat(ts, left), result = _a[0], isStatic = _a[1];
117
+ const [result, isStatic] = evaluateStringConcat(ts, left);
123
118
  return [result + right.text, isStatic];
124
119
  }
125
120
  return ['', false];
126
121
  }
127
- function extractMessageDescriptor(ts, node, _a, sf) {
128
- var overrideIdFn = _a.overrideIdFn, extractSourceLocation = _a.extractSourceLocation, preserveWhitespace = _a.preserveWhitespace;
129
- var properties = undefined;
122
+ function extractMessageDescriptor(ts, node, { overrideIdFn, extractSourceLocation, preserveWhitespace }, sf) {
123
+ let properties = undefined;
130
124
  if (ts.isObjectLiteralExpression(node)) {
131
125
  properties = node.properties;
132
126
  }
133
127
  else if (ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) {
134
128
  properties = node.attributes.properties;
135
129
  }
136
- var msg = { id: '' };
130
+ const msg = { id: '' };
137
131
  if (!properties) {
138
132
  return;
139
133
  }
140
- properties.forEach(function (prop) {
141
- var name = prop.name;
142
- var initializer = ts.isPropertyAssignment(prop) || ts.isJsxAttribute(prop)
134
+ properties.forEach(prop => {
135
+ const { name } = prop;
136
+ const initializer = ts.isPropertyAssignment(prop) || ts.isJsxAttribute(prop)
143
137
  ? prop.initializer
144
138
  : undefined;
145
139
  if (name && ts.isIdentifier(name) && initializer) {
@@ -193,7 +187,7 @@ function extractMessageDescriptor(ts, node, _a, sf) {
193
187
  }
194
188
  // <FormattedMessage foo={`bar`} />
195
189
  else if (ts.isNoSubstitutionTemplateLiteral(initializer.expression)) {
196
- var expression = initializer.expression;
190
+ const { expression } = initializer;
197
191
  switch (name.text) {
198
192
  case 'id':
199
193
  msg.id = expression.text;
@@ -208,8 +202,8 @@ function extractMessageDescriptor(ts, node, _a, sf) {
208
202
  }
209
203
  // <FormattedMessage foo={'bar' + 'baz'} />
210
204
  else if (ts.isBinaryExpression(initializer.expression)) {
211
- var expression = initializer.expression;
212
- var _a = evaluateStringConcat(ts, expression), result = _a[0], isStatic = _a[1];
205
+ const { expression } = initializer;
206
+ const [result, isStatic] = evaluateStringConcat(ts, expression);
213
207
  if (isStatic) {
214
208
  switch (name.text) {
215
209
  case 'id':
@@ -227,7 +221,7 @@ function extractMessageDescriptor(ts, node, _a, sf) {
227
221
  }
228
222
  // {defaultMessage: 'asd' + bar'}
229
223
  else if (ts.isBinaryExpression(initializer)) {
230
- var _b = evaluateStringConcat(ts, initializer), result = _b[0], isStatic = _b[1];
224
+ const [result, isStatic] = evaluateStringConcat(ts, initializer);
231
225
  if (isStatic) {
232
226
  switch (name.text) {
233
227
  case 'id':
@@ -262,9 +256,9 @@ function extractMessageDescriptor(ts, node, _a, sf) {
262
256
  if (!msg.id) {
263
257
  msg.id = (0, interpolate_name_1.interpolateName)({ resourcePath: sf.fileName }, overrideIdFn, {
264
258
  content: msg.description
265
- ? "".concat(msg.defaultMessage, "#").concat(typeof msg.description === 'string'
259
+ ? `${msg.defaultMessage}#${typeof msg.description === 'string'
266
260
  ? msg.description
267
- : (0, json_stable_stringify_1.default)(msg.description))
261
+ : (0, json_stable_stringify_1.default)(msg.description)}`
268
262
  : msg.defaultMessage,
269
263
  });
270
264
  }
@@ -275,7 +269,12 @@ function extractMessageDescriptor(ts, node, _a, sf) {
275
269
  }
276
270
  }
277
271
  if (extractSourceLocation) {
278
- return (0, tslib_1.__assign)((0, tslib_1.__assign)({}, msg), { file: sf.fileName, start: node.pos, end: node.end });
272
+ return {
273
+ ...msg,
274
+ file: sf.fileName,
275
+ start: node.pos,
276
+ end: node.end,
277
+ };
279
278
  }
280
279
  return msg;
281
280
  }
@@ -285,11 +284,12 @@ function extractMessageDescriptor(ts, node, _a, sf) {
285
284
  * @param sf
286
285
  */
287
286
  function isMemberMethodFormatMessageCall(ts, node, additionalFunctionNames) {
288
- var fnNames = new Set((0, tslib_1.__spreadArray)([
287
+ const fnNames = new Set([
289
288
  'formatMessage',
290
- '$formatMessage'
291
- ], additionalFunctionNames, true));
292
- var method = node.expression;
289
+ '$formatMessage',
290
+ ...additionalFunctionNames,
291
+ ]);
292
+ const method = node.expression;
293
293
  // Handle foo.formatMessage()
294
294
  if (ts.isPropertyAccessExpression(method)) {
295
295
  return fnNames.has(method.name.text);
@@ -298,18 +298,18 @@ function isMemberMethodFormatMessageCall(ts, node, additionalFunctionNames) {
298
298
  return ts.isIdentifier(method) && fnNames.has(method.text);
299
299
  }
300
300
  function extractMessageFromJsxComponent(ts, factory, node, opts, sf) {
301
- var onMsgExtracted = opts.onMsgExtracted;
301
+ const { onMsgExtracted } = opts;
302
302
  if (!isSingularMessageDecl(ts, node, opts.additionalComponentNames || [])) {
303
303
  return node;
304
304
  }
305
- var msg = extractMessageDescriptor(ts, node, opts, sf);
305
+ const msg = extractMessageDescriptor(ts, node, opts, sf);
306
306
  if (!msg) {
307
307
  return node;
308
308
  }
309
309
  if (typeof onMsgExtracted === 'function') {
310
310
  onMsgExtracted(sf.fileName, [msg]);
311
311
  }
312
- var newProps = generateNewProperties(ts, factory, node.attributes, {
312
+ const newProps = generateNewProperties(ts, factory, node.attributes, {
313
313
  defaultMessage: opts.removeDefaultMessage
314
314
  ? undefined
315
315
  : msg.defaultMessage,
@@ -321,17 +321,17 @@ function extractMessageFromJsxComponent(ts, factory, node, opts, sf) {
321
321
  return factory.updateJsxSelfClosingElement(node, node.tagName, node.typeArguments, factory.createJsxAttributes(newProps));
322
322
  }
323
323
  function setAttributesInObject(ts, factory, node, msg, ast) {
324
- var newProps = (0, tslib_1.__spreadArray)([
325
- factory.createPropertyAssignment('id', factory.createStringLiteral(msg.id))
326
- ], (msg.defaultMessage
327
- ? [
328
- factory.createPropertyAssignment('defaultMessage', ast
329
- ? messageASTToTSNode(factory, (0, icu_messageformat_parser_1.parse)(msg.defaultMessage))
330
- : factory.createStringLiteral(msg.defaultMessage)),
331
- ]
332
- : []), true);
333
- for (var _i = 0, _a = node.properties; _i < _a.length; _i++) {
334
- var prop = _a[_i];
324
+ const newProps = [
325
+ factory.createPropertyAssignment('id', factory.createStringLiteral(msg.id)),
326
+ ...(msg.defaultMessage
327
+ ? [
328
+ factory.createPropertyAssignment('defaultMessage', ast
329
+ ? messageASTToTSNode(factory, (0, icu_messageformat_parser_1.parse)(msg.defaultMessage))
330
+ : factory.createStringLiteral(msg.defaultMessage)),
331
+ ]
332
+ : []),
333
+ ];
334
+ for (const prop of node.properties) {
335
335
  if (ts.isPropertyAssignment(prop) &&
336
336
  ts.isIdentifier(prop.name) &&
337
337
  MESSAGE_DESC_KEYS.includes(prop.name.text)) {
@@ -344,17 +344,17 @@ function setAttributesInObject(ts, factory, node, msg, ast) {
344
344
  return factory.createObjectLiteralExpression(factory.createNodeArray(newProps));
345
345
  }
346
346
  function generateNewProperties(ts, factory, node, msg, ast) {
347
- var newProps = (0, tslib_1.__spreadArray)([
348
- factory.createJsxAttribute(factory.createIdentifier('id'), factory.createStringLiteral(msg.id))
349
- ], (msg.defaultMessage
350
- ? [
351
- factory.createJsxAttribute(factory.createIdentifier('defaultMessage'), ast
352
- ? factory.createJsxExpression(undefined, messageASTToTSNode(factory, (0, icu_messageformat_parser_1.parse)(msg.defaultMessage)))
353
- : factory.createStringLiteral(msg.defaultMessage)),
354
- ]
355
- : []), true);
356
- for (var _i = 0, _a = node.properties; _i < _a.length; _i++) {
357
- var prop = _a[_i];
347
+ const newProps = [
348
+ factory.createJsxAttribute(factory.createIdentifier('id'), factory.createStringLiteral(msg.id)),
349
+ ...(msg.defaultMessage
350
+ ? [
351
+ factory.createJsxAttribute(factory.createIdentifier('defaultMessage'), ast
352
+ ? factory.createJsxExpression(undefined, messageASTToTSNode(factory, (0, icu_messageformat_parser_1.parse)(msg.defaultMessage)))
353
+ : factory.createStringLiteral(msg.defaultMessage)),
354
+ ]
355
+ : []),
356
+ ];
357
+ for (const prop of node.properties) {
358
358
  if (ts.isJsxAttribute(prop) &&
359
359
  ts.isIdentifier(prop.name) &&
360
360
  MESSAGE_DESC_KEYS.includes(prop.name.text)) {
@@ -367,10 +367,10 @@ function generateNewProperties(ts, factory, node, msg, ast) {
367
367
  return newProps;
368
368
  }
369
369
  function extractMessagesFromCallExpression(ts, factory, node, opts, sf) {
370
- var onMsgExtracted = opts.onMsgExtracted, additionalFunctionNames = opts.additionalFunctionNames;
370
+ const { onMsgExtracted, additionalFunctionNames } = opts;
371
371
  if (isMultipleMessageDecl(ts, node)) {
372
- var _a = node.arguments, arg = _a[0], restArgs = _a.slice(1);
373
- var descriptorsObj = void 0;
372
+ const [arg, ...restArgs] = node.arguments;
373
+ let descriptorsObj;
374
374
  if (ts.isObjectLiteralExpression(arg)) {
375
375
  descriptorsObj = arg;
376
376
  }
@@ -379,24 +379,20 @@ function extractMessagesFromCallExpression(ts, factory, node, opts, sf) {
379
379
  descriptorsObj = arg.expression;
380
380
  }
381
381
  if (descriptorsObj) {
382
- var properties = descriptorsObj.properties;
383
- var msgs_1 = properties
384
- .filter(function (prop) {
385
- return ts.isPropertyAssignment(prop);
386
- })
387
- .map(function (prop) {
388
- return ts.isObjectLiteralExpression(prop.initializer) &&
389
- extractMessageDescriptor(ts, prop.initializer, opts, sf);
390
- })
391
- .filter(function (msg) { return !!msg; });
392
- if (!msgs_1.length) {
382
+ const properties = descriptorsObj.properties;
383
+ const msgs = properties
384
+ .filter((prop) => ts.isPropertyAssignment(prop))
385
+ .map(prop => ts.isObjectLiteralExpression(prop.initializer) &&
386
+ extractMessageDescriptor(ts, prop.initializer, opts, sf))
387
+ .filter((msg) => !!msg);
388
+ if (!msgs.length) {
393
389
  return node;
394
390
  }
395
- (0, console_utils_1.debug)('Multiple messages extracted from "%s": %s', sf.fileName, msgs_1);
391
+ (0, console_utils_1.debug)('Multiple messages extracted from "%s": %s', sf.fileName, msgs);
396
392
  if (typeof onMsgExtracted === 'function') {
397
- onMsgExtracted(sf.fileName, msgs_1);
393
+ onMsgExtracted(sf.fileName, msgs);
398
394
  }
399
- var clonedProperties = factory.createNodeArray(properties.map(function (prop, i) {
395
+ const clonedProperties = factory.createNodeArray(properties.map((prop, i) => {
400
396
  if (!ts.isPropertyAssignment(prop) ||
401
397
  !ts.isObjectLiteralExpression(prop.initializer)) {
402
398
  return prop;
@@ -404,19 +400,19 @@ function extractMessagesFromCallExpression(ts, factory, node, opts, sf) {
404
400
  return factory.createPropertyAssignment(prop.name, setAttributesInObject(ts, factory, prop.initializer, {
405
401
  defaultMessage: opts.removeDefaultMessage
406
402
  ? undefined
407
- : msgs_1[i].defaultMessage,
408
- id: msgs_1[i] ? msgs_1[i].id : '',
403
+ : msgs[i].defaultMessage,
404
+ id: msgs[i] ? msgs[i].id : '',
409
405
  }, opts.ast));
410
406
  }));
411
- var clonedDescriptorsObj = factory.createObjectLiteralExpression(clonedProperties);
412
- return factory.updateCallExpression(node, node.expression, node.typeArguments, (0, tslib_1.__spreadArray)([clonedDescriptorsObj], restArgs, true));
407
+ const clonedDescriptorsObj = factory.createObjectLiteralExpression(clonedProperties);
408
+ return factory.updateCallExpression(node, node.expression, node.typeArguments, [clonedDescriptorsObj, ...restArgs]);
413
409
  }
414
410
  }
415
411
  else if (isSingularMessageDecl(ts, node, opts.additionalComponentNames || []) ||
416
412
  isMemberMethodFormatMessageCall(ts, node, additionalFunctionNames || [])) {
417
- var _b = node.arguments, descriptorsObj = _b[0], restArgs = _b.slice(1);
413
+ const [descriptorsObj, ...restArgs] = node.arguments;
418
414
  if (ts.isObjectLiteralExpression(descriptorsObj)) {
419
- var msg = extractMessageDescriptor(ts, descriptorsObj, opts, sf);
415
+ const msg = extractMessageDescriptor(ts, descriptorsObj, opts, sf);
420
416
  if (!msg) {
421
417
  return node;
422
418
  }
@@ -424,22 +420,23 @@ function extractMessagesFromCallExpression(ts, factory, node, opts, sf) {
424
420
  if (typeof onMsgExtracted === 'function') {
425
421
  onMsgExtracted(sf.fileName, [msg]);
426
422
  }
427
- return factory.updateCallExpression(node, node.expression, node.typeArguments, (0, tslib_1.__spreadArray)([
423
+ return factory.updateCallExpression(node, node.expression, node.typeArguments, [
428
424
  setAttributesInObject(ts, factory, descriptorsObj, {
429
425
  defaultMessage: opts.removeDefaultMessage
430
426
  ? undefined
431
427
  : msg.defaultMessage,
432
428
  id: msg.id,
433
- }, opts.ast)
434
- ], restArgs, true));
429
+ }, opts.ast),
430
+ ...restArgs,
431
+ ]);
435
432
  }
436
433
  }
437
434
  return node;
438
435
  }
439
- var PRAGMA_REGEX = /^\/\/ @([^\s]*) (.*)$/m;
436
+ const PRAGMA_REGEX = /^\/\/ @([^\s]*) (.*)$/m;
440
437
  function getVisitor(ts, ctx, sf, opts) {
441
- var visitor = function (node) {
442
- var newNode = ts.isCallExpression(node)
438
+ const visitor = (node) => {
439
+ const newNode = ts.isCallExpression(node)
443
440
  ? extractMessagesFromCallExpression(ts, ctx.factory, node, opts, sf)
444
441
  : ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)
445
442
  ? extractMessageFromJsxComponent(ts, ctx.factory, node, opts, sf)
@@ -449,20 +446,19 @@ function getVisitor(ts, ctx, sf, opts) {
449
446
  return visitor;
450
447
  }
451
448
  function transformWithTs(ts, opts) {
452
- opts = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, DEFAULT_OPTS), opts);
449
+ opts = { ...DEFAULT_OPTS, ...opts };
453
450
  (0, console_utils_1.debug)('Transforming options', opts);
454
- var transformFn = function (ctx) {
455
- return function (sf) {
456
- var pragmaResult = PRAGMA_REGEX.exec(sf.text);
451
+ const transformFn = ctx => {
452
+ return (sf) => {
453
+ const pragmaResult = PRAGMA_REGEX.exec(sf.text);
457
454
  if (pragmaResult) {
458
455
  (0, console_utils_1.debug)('Pragma found', pragmaResult);
459
- var pragma = pragmaResult[1], kvString = pragmaResult[2];
456
+ const [, pragma, kvString] = pragmaResult;
460
457
  if (pragma === opts.pragma) {
461
- var kvs = kvString.split(' ');
462
- var result = {};
463
- for (var _i = 0, kvs_1 = kvs; _i < kvs_1.length; _i++) {
464
- var kv = kvs_1[_i];
465
- var _a = kv.split(':'), k = _a[0], v = _a[1];
458
+ const kvs = kvString.split(' ');
459
+ const result = {};
460
+ for (const kv of kvs) {
461
+ const [k, v] = kv.split(':');
466
462
  result[k] = v;
467
463
  }
468
464
  (0, console_utils_1.debug)('Pragma extracted', result);
package/src/types.d.ts CHANGED
File without changes
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../packages/ts-transformer/src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAA;IACV,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,QAAQ;IACvB,CAAC,GAAG,EAAE,MAAM,GAAG,iBAAiB,CAAA;CACjC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAA;IACV,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,QAAQ;IACvB,CAAC,GAAG,EAAE,MAAM,GAAG,iBAAiB,CAAA;CACjC"}
package/src/types.js CHANGED
File without changes
@@ -1,5 +1,5 @@
1
1
  import { Opts } from '.';
2
- import type { TsCompilerInstance } from 'ts-jest/dist/types';
2
+ import type { TsCompilerInstance } from 'ts-jest';
3
3
  export declare const name = "@formatjs/ts-transformer";
4
4
  export declare const version = "2.10.1";
5
5
  export declare function factory(compilerInstance: TsCompilerInstance, opts: Opts): import("typescript").TransformerFactory<import("typescript").SourceFile>;
@@ -1 +1 @@
1
- {"version":3,"file":"ts-jest-integration.d.ts","sourceRoot":"","sources":["../../../../../packages/ts-transformer/ts-jest-integration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,IAAI,EAAC,MAAM,GAAG,CAAA;AACvC,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,oBAAoB,CAAA;AAE1D,eAAO,MAAM,IAAI,6BAA6B,CAAA;AAC9C,eAAO,MAAM,OAAO,WAAW,CAAA;AAE/B,wBAAgB,OAAO,CAAC,gBAAgB,EAAE,kBAAkB,EAAE,IAAI,EAAE,IAAI,4EAEvE"}
1
+ {"version":3,"file":"ts-jest-integration.d.ts","sourceRoot":"","sources":["ts-jest-integration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,IAAI,EAAC,MAAM,GAAG,CAAA;AACvC,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,SAAS,CAAA;AAE/C,eAAO,MAAM,IAAI,6BAA6B,CAAA;AAC9C,eAAO,MAAM,OAAO,WAAW,CAAA;AAE/B,wBAAgB,OAAO,CAAC,gBAAgB,EAAE,kBAAkB,EAAE,IAAI,EAAE,IAAI,4EAEvE"}
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.factory = exports.version = exports.name = void 0;
4
- var _1 = require(".");
4
+ const _1 = require(".");
5
5
  exports.name = '@formatjs/ts-transformer';
6
6
  exports.version = '2.10.1';
7
7
  function factory(compilerInstance, opts) {