hermes-transform 0.23.0 → 0.24.0
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.
|
@@ -12,10 +12,16 @@ exports.isValidModuleDeclarationParent = isValidModuleDeclarationParent;
|
|
|
12
12
|
* LICENSE file in the root directory of this source tree.
|
|
13
13
|
*
|
|
14
14
|
*
|
|
15
|
-
* @
|
|
15
|
+
* @noformat
|
|
16
16
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
function isModuleDeclaration(node)
|
|
18
|
+
/*: node is (
|
|
19
|
+
| ImportDeclaration
|
|
20
|
+
| ExportNamedDeclaration
|
|
21
|
+
| ExportDefaultDeclaration
|
|
22
|
+
| ExportAllDeclaration
|
|
23
|
+
) */
|
|
24
|
+
{
|
|
19
25
|
return node.type === 'ImportDeclaration' || node.type === 'ExportNamedDeclaration' || node.type === 'ExportDefaultDeclaration' || node.type === 'ExportAllDeclaration';
|
|
20
26
|
}
|
|
21
27
|
|
|
@@ -5,14 +5,34 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
* @flow strict-local
|
|
8
|
-
* @
|
|
8
|
+
* @noformat
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import type {
|
|
11
|
+
import type {
|
|
12
|
+
ESNode,
|
|
13
|
+
// Used in flow comments
|
|
14
|
+
// eslint-disable-next-line no-unused-vars
|
|
15
|
+
ExportAllDeclaration,
|
|
16
|
+
// Used in flow comments
|
|
17
|
+
// eslint-disable-next-line no-unused-vars
|
|
18
|
+
ExportDefaultDeclaration,
|
|
19
|
+
// Used in flow comments
|
|
20
|
+
// eslint-disable-next-line no-unused-vars
|
|
21
|
+
ExportNamedDeclaration,
|
|
22
|
+
// Used in flow comments
|
|
23
|
+
// eslint-disable-next-line no-unused-vars
|
|
24
|
+
ImportDeclaration,
|
|
25
|
+
ModuleDeclaration,
|
|
26
|
+
Statement,
|
|
27
|
+
} from 'hermes-estree';
|
|
12
28
|
import type {DetachedNode} from '../../../detachedNode';
|
|
13
29
|
|
|
14
|
-
|
|
15
|
-
|
|
30
|
+
function isModuleDeclaration(node: ESNode) /*: node is (
|
|
31
|
+
| ImportDeclaration
|
|
32
|
+
| ExportNamedDeclaration
|
|
33
|
+
| ExportDefaultDeclaration
|
|
34
|
+
| ExportAllDeclaration
|
|
35
|
+
) */ {
|
|
16
36
|
return (
|
|
17
37
|
node.type === 'ImportDeclaration' ||
|
|
18
38
|
node.type === 'ExportNamedDeclaration' ||
|
package/dist/transform/print.js
CHANGED
|
@@ -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; //
|
|
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
|
-
//
|
|
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.
|
|
3
|
+
"version": "0.24.0",
|
|
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.
|
|
16
|
-
"hermes-estree": "0.
|
|
17
|
-
"hermes-parser": "0.
|
|
15
|
+
"hermes-eslint": "0.24.0",
|
|
16
|
+
"hermes-estree": "0.24.0",
|
|
17
|
+
"hermes-parser": "0.24.0",
|
|
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.
|
|
22
|
+
"prettier-plugin-hermes-parser": "0.24.0"
|
|
23
23
|
},
|
|
24
24
|
"files": [
|
|
25
25
|
"dist",
|