hermes-transform 0.30.0 → 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/src/transform/print.js +14 -81
- package/dist/transform/print.js +14 -81
- package/dist/transform/print.js.flow +19 -83
- package/package.json +5 -6
|
@@ -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
|
}
|
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
|
}
|
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.30.0"
|
|
21
|
+
"prettier": "^3.0.0"
|
|
23
22
|
},
|
|
24
23
|
"files": [
|
|
25
24
|
"dist",
|