hermes-transform 0.12.0 → 0.13.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.
|
@@ -1544,8 +1544,7 @@ function PropertyDefinition(props) {
|
|
|
1544
1544
|
declare: props.declare,
|
|
1545
1545
|
optional: props.optional,
|
|
1546
1546
|
variance: (0, _detachedNode.asDetachedNodeForCodeGen)(props.variance),
|
|
1547
|
-
typeAnnotation: (0, _detachedNode.asDetachedNodeForCodeGen)(props.typeAnnotation)
|
|
1548
|
-
tsModifiers: (0, _detachedNode.asDetachedNodeForCodeGen)(props.tsModifiers)
|
|
1547
|
+
typeAnnotation: (0, _detachedNode.asDetachedNodeForCodeGen)(props.typeAnnotation)
|
|
1549
1548
|
});
|
|
1550
1549
|
(0, _detachedNode.setParentPointersInDirectChildren)(node);
|
|
1551
1550
|
return node;
|
|
@@ -893,7 +893,6 @@ export type PropertyDefinitionProps = {
|
|
|
893
893
|
+typeAnnotation?: ?MaybeDetachedNode<
|
|
894
894
|
PropertyDefinitionType['typeAnnotation'],
|
|
895
895
|
>,
|
|
896
|
-
+tsModifiers?: ?MaybeDetachedNode<PropertyDefinitionType['tsModifiers']>,
|
|
897
896
|
};
|
|
898
897
|
|
|
899
898
|
export type QualifiedTypeIdentifierProps = {
|
|
@@ -2641,7 +2640,6 @@ export function PropertyDefinition(props: {
|
|
|
2641
2640
|
optional: props.optional,
|
|
2642
2641
|
variance: asDetachedNodeForCodeGen(props.variance),
|
|
2643
2642
|
typeAnnotation: asDetachedNodeForCodeGen(props.typeAnnotation),
|
|
2644
|
-
tsModifiers: asDetachedNodeForCodeGen(props.tsModifiers),
|
|
2645
2643
|
});
|
|
2646
2644
|
setParentPointersInDirectChildren(node);
|
|
2647
2645
|
return node;
|
package/dist/transform/print.js
CHANGED
|
@@ -24,6 +24,8 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
24
24
|
|
|
25
25
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
26
26
|
|
|
27
|
+
let cache = 1;
|
|
28
|
+
|
|
27
29
|
async function print(ast, originalCode, prettierOptions = {}, visitorKeys) {
|
|
28
30
|
// $FlowExpectedError[incompatible-type] This is now safe to access.
|
|
29
31
|
const program = ast; // The docblock comment is never attached to any AST nodes, since its technically
|
|
@@ -75,13 +77,37 @@ async function print(ast, originalCode, prettierOptions = {}, visitorKeys) {
|
|
|
75
77
|
|
|
76
78
|
case '2':
|
|
77
79
|
{
|
|
80
|
+
var _hermesPlugin$parsers;
|
|
81
|
+
|
|
82
|
+
const hermesPlugin = require('prettier-plugin-hermes-parser');
|
|
83
|
+
|
|
84
|
+
const hermesParser = (_hermesPlugin$parsers = hermesPlugin.parsers) == null ? void 0 : _hermesPlugin$parsers.hermes;
|
|
85
|
+
|
|
86
|
+
if (hermesParser == null) {
|
|
87
|
+
throw new Error('Hermes parser plugin not found');
|
|
88
|
+
}
|
|
89
|
+
|
|
78
90
|
return prettier.format(originalCode, // $FlowExpectedError[incompatible-exact] - we don't want to create a dependency on the prettier types
|
|
79
91
|
{ ...prettierOptions,
|
|
92
|
+
parser: 'hermes',
|
|
93
|
+
requirePragma: false,
|
|
94
|
+
plugins: [// $FlowExpectedError[incompatible-call] Cache value is not expected but needed in this case.
|
|
95
|
+
{
|
|
96
|
+
parsers: {
|
|
97
|
+
hermes: { ...hermesParser,
|
|
98
|
+
// Prettier caches the plugin, by making this key always unique we ensure the new `parse`
|
|
99
|
+
// function with the correct AST is always called.
|
|
100
|
+
cache: cache++,
|
|
80
101
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
102
|
+
// Provide the passed AST to prettier
|
|
103
|
+
parse() {
|
|
104
|
+
return program;
|
|
105
|
+
}
|
|
84
106
|
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
printers: hermesPlugin.printers
|
|
110
|
+
}]
|
|
85
111
|
});
|
|
86
112
|
}
|
|
87
113
|
|
|
@@ -21,6 +21,8 @@ import {
|
|
|
21
21
|
} from './comments/comments';
|
|
22
22
|
import type {VisitorKeysType} from 'hermes-parser';
|
|
23
23
|
|
|
24
|
+
let cache = 1;
|
|
25
|
+
|
|
24
26
|
export async function print(
|
|
25
27
|
ast: MaybeDetachedNode<Program>,
|
|
26
28
|
originalCode: string,
|
|
@@ -79,14 +81,39 @@ export async function print(
|
|
|
79
81
|
);
|
|
80
82
|
}
|
|
81
83
|
case '2': {
|
|
84
|
+
const hermesPlugin = require('prettier-plugin-hermes-parser');
|
|
85
|
+
const hermesParser = hermesPlugin.parsers?.hermes;
|
|
86
|
+
if (hermesParser == null) {
|
|
87
|
+
throw new Error('Hermes parser plugin not found');
|
|
88
|
+
}
|
|
89
|
+
|
|
82
90
|
return prettier.format(
|
|
83
91
|
originalCode,
|
|
84
92
|
// $FlowExpectedError[incompatible-exact] - we don't want to create a dependency on the prettier types
|
|
85
93
|
{
|
|
86
94
|
...prettierOptions,
|
|
87
|
-
parser
|
|
88
|
-
|
|
89
|
-
|
|
95
|
+
parser: 'hermes',
|
|
96
|
+
requirePragma: false,
|
|
97
|
+
plugins: [
|
|
98
|
+
// $FlowExpectedError[incompatible-call] Cache value is not expected but needed in this case.
|
|
99
|
+
{
|
|
100
|
+
parsers: {
|
|
101
|
+
hermes: {
|
|
102
|
+
...hermesParser,
|
|
103
|
+
|
|
104
|
+
// Prettier caches the plugin, by making this key always unique we ensure the new `parse`
|
|
105
|
+
// function with the correct AST is always called.
|
|
106
|
+
cache: cache++,
|
|
107
|
+
|
|
108
|
+
// Provide the passed AST to prettier
|
|
109
|
+
parse() {
|
|
110
|
+
return program;
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
printers: hermesPlugin.printers,
|
|
115
|
+
},
|
|
116
|
+
],
|
|
90
117
|
},
|
|
91
118
|
);
|
|
92
119
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hermes-transform",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.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,9 +12,9 @@
|
|
|
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.13.0",
|
|
16
|
+
"hermes-estree": "0.13.0",
|
|
17
|
+
"hermes-parser": "0.13.0"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
20
|
"prettier": "^3.0.0 || ^2.7.1"
|