hermes-transform 0.23.0 → 0.23.1

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.
@@ -29,9 +29,24 @@ const cacheBase = Math.random();
29
29
 
30
30
  async function print(ast, originalCode, prettierOptions = {}, visitorKeys) {
31
31
  // $FlowExpectedError[incompatible-type] This is now safe to access.
32
- const program = ast; // Fix up the AST to match what prettier expects.
32
+ const program = ast; // If the AST body is empty, we can skip the cost of prettier by returning a static string of the contents.
33
+
34
+ if (program.body.length === 0) {
35
+ var _program$docblock;
36
+
37
+ // If the program had a docblock comment, we need to create the string manually.
38
+ const docblockComment = (_program$docblock = program.docblock) == null ? void 0 : _program$docblock.comment;
39
+
40
+ if (docblockComment != null) {
41
+ return '/*' + docblockComment.value + '*/\n';
42
+ }
43
+
44
+ return '';
45
+ } // Cleanup the comments from the AST and generate the "orginal" code needed for prettier.
46
+
47
+
48
+ const codeForPrinting = (0, _comments.mutateESTreeASTCommentsForPrettier)(program, originalCode); // Fix up the AST to match what prettier expects.
33
49
 
34
- const codeForPrinting = (0, _comments.mutateESTreeASTCommentsForPrettier)(program, originalCode);
35
50
  (0, _hermesParser.mutateESTreeASTForPrettier)(program, visitorKeys);
36
51
 
37
52
  switch (getPrettierMajorVersion()) {
@@ -30,11 +30,24 @@ export async function print(
30
30
  // $FlowExpectedError[incompatible-type] This is now safe to access.
31
31
  const program: Program = ast;
32
32
 
33
- // Fix up the AST to match what prettier expects.
33
+ // If the AST body is empty, we can skip the cost of prettier by returning a static string of the contents.
34
+ if (program.body.length === 0) {
35
+ // If the program had a docblock comment, we need to create the string manually.
36
+ const docblockComment = program.docblock?.comment;
37
+ if (docblockComment != null) {
38
+ return '/*' + docblockComment.value + '*/\n';
39
+ }
40
+
41
+ return '';
42
+ }
43
+
44
+ // Cleanup the comments from the AST and generate the "orginal" code needed for prettier.
34
45
  const codeForPrinting = mutateESTreeASTCommentsForPrettier(
35
46
  program,
36
47
  originalCode,
37
48
  );
49
+
50
+ // Fix up the AST to match what prettier expects.
38
51
  mutateESTreeASTForPrettier(program, visitorKeys);
39
52
 
40
53
  switch (getPrettierMajorVersion()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hermes-transform",
3
- "version": "0.23.0",
3
+ "version": "0.23.1",
4
4
  "description": "Tools built on top of Hermes-ESTree to enable codebase transformation",
5
5
  "main": "dist/index.js",
6
6
  "license": "MIT",
@@ -12,14 +12,14 @@
12
12
  "@babel/code-frame": "^7.16.0",
13
13
  "esquery": "^1.4.0",
14
14
  "flow-enums-runtime": "^0.0.6",
15
- "hermes-eslint": "0.23.0",
16
- "hermes-estree": "0.23.0",
17
- "hermes-parser": "0.23.0",
15
+ "hermes-eslint": "0.23.1",
16
+ "hermes-estree": "0.23.1",
17
+ "hermes-parser": "0.23.1",
18
18
  "string-width": "4.2.3"
19
19
  },
20
20
  "peerDependencies": {
21
21
  "prettier": "^3.0.0 || ^2.7.1",
22
- "prettier-plugin-hermes-parser": "0.23.0"
22
+ "prettier-plugin-hermes-parser": "0.23.1"
23
23
  },
24
24
  "files": [
25
25
  "dist",