hermes-transform 0.29.1 → 0.31.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.
- package/dist/generated/node-types.js +4 -0
- package/dist/generated/node-types.js.flow +8 -0
- package/dist/src/generated/node-types.js +4 -0
- package/dist/src/transform/parse.js +1 -1
- package/dist/src/transform/print.js +14 -81
- package/dist/src/transform/transform.js +1 -1
- package/dist/transform/parse.js +1 -1
- package/dist/transform/parse.js.flow +1 -1
- package/dist/transform/print.js +14 -81
- package/dist/transform/print.js.flow +19 -83
- package/dist/transform/transform.js +1 -1
- package/dist/transform/transform.js.flow +1 -1
- package/package.json +5 -6
|
@@ -788,6 +788,8 @@ function DeclareOpaqueType(props) {
|
|
|
788
788
|
id: (0, _detachedNode.asDetachedNodeForCodeGen)(props.id),
|
|
789
789
|
typeParameters: (0, _detachedNode.asDetachedNodeForCodeGen)(props.typeParameters),
|
|
790
790
|
impltype: (0, _detachedNode.asDetachedNodeForCodeGen)(props.impltype),
|
|
791
|
+
lowerBound: (0, _detachedNode.asDetachedNodeForCodeGen)(props.lowerBound),
|
|
792
|
+
upperBound: (0, _detachedNode.asDetachedNodeForCodeGen)(props.upperBound),
|
|
791
793
|
supertype: (0, _detachedNode.asDetachedNodeForCodeGen)(props.supertype)
|
|
792
794
|
});
|
|
793
795
|
(0, _detachedNode.setParentPointersInDirectChildren)(node);
|
|
@@ -1763,6 +1765,8 @@ function OpaqueType(props) {
|
|
|
1763
1765
|
id: (0, _detachedNode.asDetachedNodeForCodeGen)(props.id),
|
|
1764
1766
|
typeParameters: (0, _detachedNode.asDetachedNodeForCodeGen)(props.typeParameters),
|
|
1765
1767
|
impltype: (0, _detachedNode.asDetachedNodeForCodeGen)(props.impltype),
|
|
1768
|
+
lowerBound: (0, _detachedNode.asDetachedNodeForCodeGen)(props.lowerBound),
|
|
1769
|
+
upperBound: (0, _detachedNode.asDetachedNodeForCodeGen)(props.upperBound),
|
|
1766
1770
|
supertype: (0, _detachedNode.asDetachedNodeForCodeGen)(props.supertype)
|
|
1767
1771
|
});
|
|
1768
1772
|
(0, _detachedNode.setParentPointersInDirectChildren)(node);
|
|
@@ -444,6 +444,8 @@ export type DeclareOpaqueTypeProps = {
|
|
|
444
444
|
+id: MaybeDetachedNode<DeclareOpaqueTypeType['id']>,
|
|
445
445
|
+typeParameters?: ?MaybeDetachedNode<DeclareOpaqueTypeType['typeParameters']>,
|
|
446
446
|
+impltype?: ?MaybeDetachedNode<DeclareOpaqueTypeType['impltype']>,
|
|
447
|
+
+lowerBound?: ?MaybeDetachedNode<DeclareOpaqueTypeType['lowerBound']>,
|
|
448
|
+
+upperBound?: ?MaybeDetachedNode<DeclareOpaqueTypeType['upperBound']>,
|
|
447
449
|
+supertype?: ?MaybeDetachedNode<DeclareOpaqueTypeType['supertype']>,
|
|
448
450
|
};
|
|
449
451
|
|
|
@@ -1013,6 +1015,8 @@ export type OpaqueTypeProps = {
|
|
|
1013
1015
|
+id: MaybeDetachedNode<OpaqueTypeType['id']>,
|
|
1014
1016
|
+typeParameters?: ?MaybeDetachedNode<OpaqueTypeType['typeParameters']>,
|
|
1015
1017
|
+impltype: MaybeDetachedNode<OpaqueTypeType['impltype']>,
|
|
1018
|
+
+lowerBound?: ?MaybeDetachedNode<OpaqueTypeType['lowerBound']>,
|
|
1019
|
+
+upperBound?: ?MaybeDetachedNode<OpaqueTypeType['upperBound']>,
|
|
1016
1020
|
+supertype?: ?MaybeDetachedNode<OpaqueTypeType['supertype']>,
|
|
1017
1021
|
};
|
|
1018
1022
|
|
|
@@ -1820,6 +1824,8 @@ export function DeclareOpaqueType(props: {
|
|
|
1820
1824
|
id: asDetachedNodeForCodeGen(props.id),
|
|
1821
1825
|
typeParameters: asDetachedNodeForCodeGen(props.typeParameters),
|
|
1822
1826
|
impltype: asDetachedNodeForCodeGen(props.impltype),
|
|
1827
|
+
lowerBound: asDetachedNodeForCodeGen(props.lowerBound),
|
|
1828
|
+
upperBound: asDetachedNodeForCodeGen(props.upperBound),
|
|
1823
1829
|
supertype: asDetachedNodeForCodeGen(props.supertype),
|
|
1824
1830
|
},
|
|
1825
1831
|
);
|
|
@@ -3222,6 +3228,8 @@ export function OpaqueType(props: {
|
|
|
3222
3228
|
id: asDetachedNodeForCodeGen(props.id),
|
|
3223
3229
|
typeParameters: asDetachedNodeForCodeGen(props.typeParameters),
|
|
3224
3230
|
impltype: asDetachedNodeForCodeGen(props.impltype),
|
|
3231
|
+
lowerBound: asDetachedNodeForCodeGen(props.lowerBound),
|
|
3232
|
+
upperBound: asDetachedNodeForCodeGen(props.upperBound),
|
|
3225
3233
|
supertype: asDetachedNodeForCodeGen(props.supertype),
|
|
3226
3234
|
});
|
|
3227
3235
|
setParentPointersInDirectChildren((node: $FlowFixMe));
|
|
@@ -788,6 +788,8 @@ function DeclareOpaqueType(props) {
|
|
|
788
788
|
id: (0, _detachedNode.asDetachedNodeForCodeGen)(props.id),
|
|
789
789
|
typeParameters: (0, _detachedNode.asDetachedNodeForCodeGen)(props.typeParameters),
|
|
790
790
|
impltype: (0, _detachedNode.asDetachedNodeForCodeGen)(props.impltype),
|
|
791
|
+
lowerBound: (0, _detachedNode.asDetachedNodeForCodeGen)(props.lowerBound),
|
|
792
|
+
upperBound: (0, _detachedNode.asDetachedNodeForCodeGen)(props.upperBound),
|
|
791
793
|
supertype: (0, _detachedNode.asDetachedNodeForCodeGen)(props.supertype)
|
|
792
794
|
});
|
|
793
795
|
(0, _detachedNode.setParentPointersInDirectChildren)(node);
|
|
@@ -1763,6 +1765,8 @@ function OpaqueType(props) {
|
|
|
1763
1765
|
id: (0, _detachedNode.asDetachedNodeForCodeGen)(props.id),
|
|
1764
1766
|
typeParameters: (0, _detachedNode.asDetachedNodeForCodeGen)(props.typeParameters),
|
|
1765
1767
|
impltype: (0, _detachedNode.asDetachedNodeForCodeGen)(props.impltype),
|
|
1768
|
+
lowerBound: (0, _detachedNode.asDetachedNodeForCodeGen)(props.lowerBound),
|
|
1769
|
+
upperBound: (0, _detachedNode.asDetachedNodeForCodeGen)(props.upperBound),
|
|
1766
1770
|
supertype: (0, _detachedNode.asDetachedNodeForCodeGen)(props.supertype)
|
|
1767
1771
|
});
|
|
1768
1772
|
(0, _detachedNode.setParentPointersInDirectChildren)(node);
|
|
@@ -24,9 +24,6 @@ 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
|
-
const cacheBase = Math.random();
|
|
29
|
-
|
|
30
27
|
async function print(ast, originalCode, prettierOptions = {}, visitorKeys) {
|
|
31
28
|
// $FlowExpectedError[incompatible-type] This is now safe to access.
|
|
32
29
|
const program = ast; // If the AST body is empty, we can skip the cost of prettier by returning a static string of the contents.
|
|
@@ -47,88 +44,24 @@ async function print(ast, originalCode, prettierOptions = {}, visitorKeys) {
|
|
|
47
44
|
|
|
48
45
|
const codeForPrinting = (0, _comments.mutateESTreeASTCommentsForPrettier)(program, originalCode); // Fix up the AST to match what prettier expects.
|
|
49
46
|
|
|
50
|
-
(0, _hermesParser.mutateESTreeASTForPrettier)(program, visitorKeys);
|
|
51
|
-
|
|
52
|
-
switch (getPrettierMajorVersion()) {
|
|
53
|
-
case '3':
|
|
54
|
-
{
|
|
55
|
-
// Lazy require this module as it only exists in prettier v3.
|
|
56
|
-
const prettierFlowPlugin = require('prettier/plugins/flow');
|
|
57
|
-
|
|
58
|
-
return prettier.format(codeForPrinting, // $FlowExpectedError[incompatible-exact] - we don't want to create a dependency on the prettier types
|
|
59
|
-
{ ...prettierOptions,
|
|
60
|
-
parser: 'flow',
|
|
61
|
-
requirePragma: false,
|
|
62
|
-
plugins: [{
|
|
63
|
-
parsers: {
|
|
64
|
-
flow: { ...prettierFlowPlugin.parsers.flow,
|
|
65
|
-
|
|
66
|
-
parse() {
|
|
67
|
-
return program;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}]
|
|
73
|
-
});
|
|
74
|
-
}
|
|
47
|
+
(0, _hermesParser.mutateESTreeASTForPrettier)(program, visitorKeys); // Lazy require this module as it only exists in prettier v3.
|
|
75
48
|
|
|
76
|
-
|
|
77
|
-
{
|
|
78
|
-
var _hermesPlugin$parsers;
|
|
49
|
+
const prettierFlowPlugin = require('prettier/plugins/flow');
|
|
79
50
|
|
|
80
|
-
|
|
51
|
+
return prettier.format(codeForPrinting, // $FlowExpectedError[incompatible-exact] - we don't want to create a dependency on the prettier types
|
|
52
|
+
{ ...prettierOptions,
|
|
53
|
+
parser: 'flow',
|
|
54
|
+
requirePragma: false,
|
|
55
|
+
plugins: [{
|
|
56
|
+
parsers: {
|
|
57
|
+
flow: { ...prettierFlowPlugin.parsers.flow,
|
|
81
58
|
|
|
82
|
-
|
|
59
|
+
parse() {
|
|
60
|
+
return program;
|
|
61
|
+
}
|
|
83
62
|
|
|
84
|
-
if (hermesParser == null) {
|
|
85
|
-
throw new Error('Hermes parser plugin not found');
|
|
86
63
|
}
|
|
87
|
-
|
|
88
|
-
return prettier.format(codeForPrinting, // $FlowExpectedError[incompatible-exact] - we don't want to create a dependency on the prettier types
|
|
89
|
-
{ ...prettierOptions,
|
|
90
|
-
parser: 'hermes',
|
|
91
|
-
requirePragma: false,
|
|
92
|
-
plugins: [// $FlowExpectedError[incompatible-call] Cache value is not expected but needed in this case.
|
|
93
|
-
{
|
|
94
|
-
parsers: {
|
|
95
|
-
hermes: { ...hermesParser,
|
|
96
|
-
// Prettier caches the plugin, by making this key always unique we ensure the new `parse`
|
|
97
|
-
// function with the correct AST is always called.
|
|
98
|
-
cache: `${cacheBase}-${cache++}`,
|
|
99
|
-
|
|
100
|
-
// Provide the passed AST to prettier
|
|
101
|
-
parse() {
|
|
102
|
-
return program;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
printers: hermesPlugin.printers
|
|
108
|
-
}]
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
case 'UNSUPPORTED':
|
|
113
|
-
default:
|
|
114
|
-
{
|
|
115
|
-
throw new Error(`Unknown or unsupported prettier version of "${prettier.version}". Only major versions 3 or 2 of prettier are supported.`);
|
|
116
64
|
}
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function getPrettierMajorVersion() {
|
|
121
|
-
const {
|
|
122
|
-
version
|
|
123
|
-
} = prettier;
|
|
124
|
-
|
|
125
|
-
if (version.startsWith('3.')) {
|
|
126
|
-
return '3';
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (version.startsWith('2.')) {
|
|
130
|
-
return '2';
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
return 'UNSUPPORTED';
|
|
65
|
+
}]
|
|
66
|
+
});
|
|
134
67
|
}
|
|
@@ -21,7 +21,7 @@ var _parse = require("./parse");
|
|
|
21
21
|
var _print = require("./print");
|
|
22
22
|
|
|
23
23
|
async function transform(originalCode, visitors, prettierOptions = {}) {
|
|
24
|
-
const parseResult =
|
|
24
|
+
const parseResult = (0, _parse.parse)(originalCode);
|
|
25
25
|
const {
|
|
26
26
|
ast,
|
|
27
27
|
astWasMutated,
|
package/dist/transform/parse.js
CHANGED
|
@@ -22,7 +22,7 @@ export type ParseResult = {
|
|
|
22
22
|
code: string,
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
export
|
|
25
|
+
export function parse(code: string): ParseResult {
|
|
26
26
|
const {ast, scopeManager} = parseForESLint(code, {
|
|
27
27
|
sourceType: 'module',
|
|
28
28
|
enableExperimentalComponentSyntax: true,
|
package/dist/transform/print.js
CHANGED
|
@@ -24,9 +24,6 @@ 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
|
-
const cacheBase = Math.random();
|
|
29
|
-
|
|
30
27
|
async function print(ast, originalCode, prettierOptions = {}, visitorKeys) {
|
|
31
28
|
// $FlowExpectedError[incompatible-type] This is now safe to access.
|
|
32
29
|
const program = ast; // If the AST body is empty, we can skip the cost of prettier by returning a static string of the contents.
|
|
@@ -47,88 +44,24 @@ async function print(ast, originalCode, prettierOptions = {}, visitorKeys) {
|
|
|
47
44
|
|
|
48
45
|
const codeForPrinting = (0, _comments.mutateESTreeASTCommentsForPrettier)(program, originalCode); // Fix up the AST to match what prettier expects.
|
|
49
46
|
|
|
50
|
-
(0, _hermesParser.mutateESTreeASTForPrettier)(program, visitorKeys);
|
|
51
|
-
|
|
52
|
-
switch (getPrettierMajorVersion()) {
|
|
53
|
-
case '3':
|
|
54
|
-
{
|
|
55
|
-
// Lazy require this module as it only exists in prettier v3.
|
|
56
|
-
const prettierFlowPlugin = require('prettier/plugins/flow');
|
|
57
|
-
|
|
58
|
-
return prettier.format(codeForPrinting, // $FlowExpectedError[incompatible-exact] - we don't want to create a dependency on the prettier types
|
|
59
|
-
{ ...prettierOptions,
|
|
60
|
-
parser: 'flow',
|
|
61
|
-
requirePragma: false,
|
|
62
|
-
plugins: [{
|
|
63
|
-
parsers: {
|
|
64
|
-
flow: { ...prettierFlowPlugin.parsers.flow,
|
|
65
|
-
|
|
66
|
-
parse() {
|
|
67
|
-
return program;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}]
|
|
73
|
-
});
|
|
74
|
-
}
|
|
47
|
+
(0, _hermesParser.mutateESTreeASTForPrettier)(program, visitorKeys); // Lazy require this module as it only exists in prettier v3.
|
|
75
48
|
|
|
76
|
-
|
|
77
|
-
{
|
|
78
|
-
var _hermesPlugin$parsers;
|
|
49
|
+
const prettierFlowPlugin = require('prettier/plugins/flow');
|
|
79
50
|
|
|
80
|
-
|
|
51
|
+
return prettier.format(codeForPrinting, // $FlowExpectedError[incompatible-exact] - we don't want to create a dependency on the prettier types
|
|
52
|
+
{ ...prettierOptions,
|
|
53
|
+
parser: 'flow',
|
|
54
|
+
requirePragma: false,
|
|
55
|
+
plugins: [{
|
|
56
|
+
parsers: {
|
|
57
|
+
flow: { ...prettierFlowPlugin.parsers.flow,
|
|
81
58
|
|
|
82
|
-
|
|
59
|
+
parse() {
|
|
60
|
+
return program;
|
|
61
|
+
}
|
|
83
62
|
|
|
84
|
-
if (hermesParser == null) {
|
|
85
|
-
throw new Error('Hermes parser plugin not found');
|
|
86
63
|
}
|
|
87
|
-
|
|
88
|
-
return prettier.format(codeForPrinting, // $FlowExpectedError[incompatible-exact] - we don't want to create a dependency on the prettier types
|
|
89
|
-
{ ...prettierOptions,
|
|
90
|
-
parser: 'hermes',
|
|
91
|
-
requirePragma: false,
|
|
92
|
-
plugins: [// $FlowExpectedError[incompatible-call] Cache value is not expected but needed in this case.
|
|
93
|
-
{
|
|
94
|
-
parsers: {
|
|
95
|
-
hermes: { ...hermesParser,
|
|
96
|
-
// Prettier caches the plugin, by making this key always unique we ensure the new `parse`
|
|
97
|
-
// function with the correct AST is always called.
|
|
98
|
-
cache: `${cacheBase}-${cache++}`,
|
|
99
|
-
|
|
100
|
-
// Provide the passed AST to prettier
|
|
101
|
-
parse() {
|
|
102
|
-
return program;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
printers: hermesPlugin.printers
|
|
108
|
-
}]
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
case 'UNSUPPORTED':
|
|
113
|
-
default:
|
|
114
|
-
{
|
|
115
|
-
throw new Error(`Unknown or unsupported prettier version of "${prettier.version}". Only major versions 3 or 2 of prettier are supported.`);
|
|
116
64
|
}
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function getPrettierMajorVersion() {
|
|
121
|
-
const {
|
|
122
|
-
version
|
|
123
|
-
} = prettier;
|
|
124
|
-
|
|
125
|
-
if (version.startsWith('3.')) {
|
|
126
|
-
return '3';
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (version.startsWith('2.')) {
|
|
130
|
-
return '2';
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
return 'UNSUPPORTED';
|
|
65
|
+
}]
|
|
66
|
+
});
|
|
134
67
|
}
|
|
@@ -18,9 +18,6 @@ import * as prettier from 'prettier';
|
|
|
18
18
|
import {mutateESTreeASTCommentsForPrettier} from './comments/comments';
|
|
19
19
|
import type {VisitorKeysType} from 'hermes-parser';
|
|
20
20
|
|
|
21
|
-
let cache = 1;
|
|
22
|
-
const cacheBase = Math.random();
|
|
23
|
-
|
|
24
21
|
export async function print(
|
|
25
22
|
ast: MaybeDetachedNode<Program>,
|
|
26
23
|
originalCode: string,
|
|
@@ -50,88 +47,27 @@ export async function print(
|
|
|
50
47
|
// Fix up the AST to match what prettier expects.
|
|
51
48
|
mutateESTreeASTForPrettier(program, visitorKeys);
|
|
52
49
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
requirePragma: false,
|
|
64
|
-
plugins: [
|
|
65
|
-
{
|
|
66
|
-
parsers: {
|
|
67
|
-
flow: {
|
|
68
|
-
...prettierFlowPlugin.parsers.flow,
|
|
69
|
-
parse() {
|
|
70
|
-
return program;
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
],
|
|
76
|
-
},
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
case '2': {
|
|
80
|
-
const hermesPlugin = require('prettier-plugin-hermes-parser');
|
|
81
|
-
const hermesParser = hermesPlugin.parsers?.hermes;
|
|
82
|
-
if (hermesParser == null) {
|
|
83
|
-
throw new Error('Hermes parser plugin not found');
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return prettier.format(
|
|
87
|
-
codeForPrinting,
|
|
88
|
-
// $FlowExpectedError[incompatible-exact] - we don't want to create a dependency on the prettier types
|
|
50
|
+
// Lazy require this module as it only exists in prettier v3.
|
|
51
|
+
const prettierFlowPlugin = require('prettier/plugins/flow');
|
|
52
|
+
return prettier.format(
|
|
53
|
+
codeForPrinting,
|
|
54
|
+
// $FlowExpectedError[incompatible-exact] - we don't want to create a dependency on the prettier types
|
|
55
|
+
{
|
|
56
|
+
...prettierOptions,
|
|
57
|
+
parser: 'flow',
|
|
58
|
+
requirePragma: false,
|
|
59
|
+
plugins: [
|
|
89
60
|
{
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
{
|
|
96
|
-
parsers: {
|
|
97
|
-
hermes: {
|
|
98
|
-
...hermesParser,
|
|
99
|
-
|
|
100
|
-
// Prettier caches the plugin, by making this key always unique we ensure the new `parse`
|
|
101
|
-
// function with the correct AST is always called.
|
|
102
|
-
cache: `${cacheBase}-${cache++}`,
|
|
103
|
-
|
|
104
|
-
// Provide the passed AST to prettier
|
|
105
|
-
parse() {
|
|
106
|
-
return program;
|
|
107
|
-
},
|
|
108
|
-
},
|
|
61
|
+
parsers: {
|
|
62
|
+
flow: {
|
|
63
|
+
...prettierFlowPlugin.parsers.flow,
|
|
64
|
+
parse() {
|
|
65
|
+
return program;
|
|
109
66
|
},
|
|
110
|
-
printers: hermesPlugin.printers,
|
|
111
67
|
},
|
|
112
|
-
|
|
68
|
+
},
|
|
113
69
|
},
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
default: {
|
|
118
|
-
throw new Error(
|
|
119
|
-
`Unknown or unsupported prettier version of "${prettier.version}". Only major versions 3 or 2 of prettier are supported.`,
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function getPrettierMajorVersion(): '3' | '2' | 'UNSUPPORTED' {
|
|
126
|
-
const {version} = prettier;
|
|
127
|
-
|
|
128
|
-
if (version.startsWith('3.')) {
|
|
129
|
-
return '3';
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if (version.startsWith('2.')) {
|
|
133
|
-
return '2';
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return 'UNSUPPORTED';
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
);
|
|
137
73
|
}
|
|
@@ -21,7 +21,7 @@ var _parse = require("./parse");
|
|
|
21
21
|
var _print = require("./print");
|
|
22
22
|
|
|
23
23
|
async function transform(originalCode, visitors, prettierOptions = {}) {
|
|
24
|
-
const parseResult =
|
|
24
|
+
const parseResult = (0, _parse.parse)(originalCode);
|
|
25
25
|
const {
|
|
26
26
|
ast,
|
|
27
27
|
astWasMutated,
|
|
@@ -24,7 +24,7 @@ export async function transform(
|
|
|
24
24
|
visitors: TransformVisitor,
|
|
25
25
|
prettierOptions: {...} = {},
|
|
26
26
|
): Promise<string> {
|
|
27
|
-
const parseResult =
|
|
27
|
+
const parseResult = parse(originalCode);
|
|
28
28
|
|
|
29
29
|
const {ast, astWasMutated, mutatedCode} = transformAST(parseResult, visitors);
|
|
30
30
|
if (!astWasMutated) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hermes-transform",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.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,13 @@
|
|
|
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.31.0",
|
|
16
|
+
"hermes-estree": "0.31.0",
|
|
17
|
+
"hermes-parser": "0.31.0",
|
|
18
18
|
"string-width": "4.2.3"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
|
-
"prettier": "^3.0.0
|
|
22
|
-
"prettier-plugin-hermes-parser": "0.29.1"
|
|
21
|
+
"prettier": "^3.0.0"
|
|
23
22
|
},
|
|
24
23
|
"files": [
|
|
25
24
|
"dist",
|