hermes-transform 0.5.0 → 0.8.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/LICENSE +1 -1
- package/dist/detachedNode.js +25 -49
- package/dist/detachedNode.js.flow +3 -3
- package/dist/generated/TransformCloneSignatures.js.flow +1728 -9
- package/dist/generated/TransformReplaceSignatures.js.flow +921 -780
- package/dist/generated/node-types.js +1099 -1156
- package/dist/generated/node-types.js.flow +77 -125
- package/dist/generated/special-case-node-types.js +106 -85
- package/dist/generated/special-case-node-types.js.flow +28 -2
- package/dist/getVisitorKeys.js +4 -6
- package/dist/getVisitorKeys.js.flow +1 -1
- package/dist/index.js +13 -18
- package/dist/index.js.flow +8 -2
- package/dist/transform/Errors.js +8 -116
- package/dist/transform/Errors.js.flow +1 -1
- package/dist/transform/MutationContext.js +54 -67
- package/dist/transform/MutationContext.js.flow +4 -3
- package/dist/transform/TransformContext.js +100 -58
- package/dist/transform/TransformContext.js.flow +277 -141
- package/dist/transform/comments/comments.js +127 -40
- package/dist/transform/comments/comments.js.flow +106 -29
- package/dist/transform/comments/prettier/common/util.js +46 -47
- package/dist/transform/comments/prettier/common/util.js.flow +1 -1
- package/dist/transform/comments/prettier/language-js/comments.js +199 -216
- package/dist/transform/comments/prettier/language-js/comments.js.flow +1 -1
- package/dist/transform/comments/prettier/language-js/loc.js +10 -9
- package/dist/transform/comments/prettier/language-js/loc.js.flow +1 -1
- package/dist/transform/comments/prettier/language-js/printer-estree.js +7 -6
- package/dist/transform/comments/prettier/language-js/printer-estree.js.flow +1 -1
- package/dist/transform/comments/prettier/language-js/utils.js +18 -30
- package/dist/transform/comments/prettier/language-js/utils.js.flow +1 -1
- package/dist/transform/comments/prettier/main/comments.js +225 -298
- package/dist/transform/comments/prettier/main/comments.js.flow +1 -1
- package/dist/transform/comments/prettier/utils/get-last.js +2 -4
- package/dist/transform/comments/prettier/utils/get-last.js.flow +1 -1
- package/dist/transform/getTransformedAST.js +81 -104
- package/dist/transform/getTransformedAST.js.flow +18 -13
- package/dist/transform/mutations/AddComments.js +43 -0
- package/dist/transform/mutations/AddComments.js.flow +50 -0
- package/dist/transform/mutations/CloneCommentsTo.js +16 -24
- package/dist/transform/mutations/CloneCommentsTo.js.flow +2 -3
- package/dist/transform/mutations/InsertStatement.js +28 -30
- package/dist/transform/mutations/InsertStatement.js.flow +7 -2
- package/dist/transform/mutations/RemoveComment.js +25 -43
- package/dist/transform/mutations/RemoveComment.js.flow +1 -1
- package/dist/transform/mutations/RemoveNode.js +192 -0
- package/dist/transform/mutations/RemoveNode.js.flow +290 -0
- package/dist/transform/mutations/RemoveStatement.js +7 -9
- package/dist/transform/mutations/RemoveStatement.js.flow +1 -1
- package/dist/transform/mutations/ReplaceNode.js +36 -44
- package/dist/transform/mutations/ReplaceNode.js.flow +1 -1
- package/dist/transform/mutations/ReplaceStatementWithMany.js +11 -13
- package/dist/transform/mutations/ReplaceStatementWithMany.js.flow +1 -1
- package/dist/transform/mutations/utils/arrayUtils.js +16 -14
- package/dist/transform/mutations/utils/arrayUtils.js.flow +16 -1
- package/dist/transform/mutations/utils/getStatementParent.js +23 -28
- package/dist/transform/mutations/utils/getStatementParent.js.flow +2 -2
- package/dist/transform/mutations/utils/isValidModuleDeclarationParent.js +7 -24
- package/dist/transform/mutations/utils/isValidModuleDeclarationParent.js.flow +1 -1
- package/dist/transform/transform.js +58 -30
- package/dist/transform/transform.js.flow +51 -13
- package/dist/traverse/NodeEventGenerator.js +91 -165
- package/dist/traverse/NodeEventGenerator.js.flow +1 -1
- package/dist/traverse/SafeEmitter.js +20 -38
- package/dist/traverse/SafeEmitter.js.flow +1 -1
- package/dist/traverse/SimpleTraverser.js +67 -98
- package/dist/traverse/SimpleTraverser.js.flow +4 -1
- package/dist/traverse/esquery.js +6 -6
- package/dist/traverse/esquery.js.flow +1 -1
- package/dist/traverse/traverse.js +64 -52
- package/dist/traverse/traverse.js.flow +63 -10
- package/package.json +5 -3
- package/dist/transform/mutations/AddLeadingComments.js +0 -47
- package/dist/transform/mutations/AddLeadingComments.js.flow +0 -49
- package/dist/transform/mutations/AddTrailingComments.js +0 -47
- package/dist/transform/mutations/AddTrailingComments.js.flow +0 -49
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -20,6 +20,7 @@ import type {
|
|
|
20
20
|
RegExpLiteral as RegExpLiteralType,
|
|
21
21
|
TemplateElement as TemplateElementType,
|
|
22
22
|
Identifier as IdentifierType,
|
|
23
|
+
BigIntLiteral as BigIntLiteralType,
|
|
23
24
|
BooleanLiteral as BooleanLiteralType,
|
|
24
25
|
NumericLiteral as NumericLiteralType,
|
|
25
26
|
NullLiteral as NullLiteralType,
|
|
@@ -144,6 +145,31 @@ export function Identifier({
|
|
|
144
145
|
// Literals require a "raw" which is added by the estree transform, not hermes.
|
|
145
146
|
//
|
|
146
147
|
|
|
148
|
+
export type BigIntLiteralProps = {
|
|
149
|
+
+value: $FlowFixMe /* bigint | null */,
|
|
150
|
+
/**
|
|
151
|
+
* Only set this if you want to use a source-code representation like 1_1n, etc.
|
|
152
|
+
* By default "raw" will just be the exact number you've given.
|
|
153
|
+
*/
|
|
154
|
+
+raw?: NumericLiteralType['raw'],
|
|
155
|
+
};
|
|
156
|
+
export function BigIntLiteral({
|
|
157
|
+
parent,
|
|
158
|
+
...props
|
|
159
|
+
}: {
|
|
160
|
+
...$ReadOnly<BigIntLiteralProps>,
|
|
161
|
+
+parent?: ESNode,
|
|
162
|
+
}): DetachedNode<BigIntLiteralType> {
|
|
163
|
+
const node = detachedProps<BigIntLiteralType>(parent, {
|
|
164
|
+
type: 'Literal',
|
|
165
|
+
...props,
|
|
166
|
+
raw: props.raw ?? `${props.value}n`,
|
|
167
|
+
bigint: `${props.value}`,
|
|
168
|
+
});
|
|
169
|
+
setParentPointersInDirectChildren(node);
|
|
170
|
+
return node;
|
|
171
|
+
}
|
|
172
|
+
|
|
147
173
|
export type BooleanLiteralProps = {
|
|
148
174
|
+value: BooleanLiteralType['value'],
|
|
149
175
|
};
|
|
@@ -164,7 +190,7 @@ export function BooleanLiteral({
|
|
|
164
190
|
export type NumericLiteralProps = {
|
|
165
191
|
+value: NumericLiteralType['value'],
|
|
166
192
|
/**
|
|
167
|
-
* Only set this if you want to use a source-code representation like 1e100, 0x11, etc.
|
|
193
|
+
* Only set this if you want to use a source-code representation like 1e100, 0x11, 1_1, etc.
|
|
168
194
|
* By default "raw" will just be the exact number you've given.
|
|
169
195
|
*/
|
|
170
196
|
+raw?: NumericLiteralType['raw'],
|
package/dist/getVisitorKeys.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -17,17 +17,15 @@ exports.isNode = isNode;
|
|
|
17
17
|
|
|
18
18
|
var _hermesEslint = require("hermes-eslint");
|
|
19
19
|
|
|
20
|
-
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
21
|
-
|
|
22
20
|
function isNode(thing) {
|
|
23
|
-
return
|
|
21
|
+
return typeof thing === 'object' && thing != null && typeof thing.type === 'string';
|
|
24
22
|
}
|
|
25
23
|
|
|
26
24
|
function getVisitorKeys(node) {
|
|
27
|
-
|
|
25
|
+
const keys = _hermesEslint.VisitorKeys[node.type];
|
|
28
26
|
|
|
29
27
|
if (keys == null) {
|
|
30
|
-
throw new Error(
|
|
28
|
+
throw new Error(`No visitor keys found for node type "${node.type}".`);
|
|
31
29
|
} // $FlowExpectedError[prop-missing]
|
|
32
30
|
|
|
33
31
|
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -9,33 +9,28 @@
|
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
|
-
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
13
|
-
|
|
14
12
|
Object.defineProperty(exports, "__esModule", {
|
|
15
13
|
value: true
|
|
16
14
|
});
|
|
17
|
-
exports.t = void 0;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
Object.defineProperty(exports, "traverse", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
get: function get() {
|
|
27
|
-
return _traverse.traverse;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
15
|
+
exports.traverseWithContext = exports.traverse = exports.transform = exports.t = exports.SimpleTraverser = void 0;
|
|
16
|
+
|
|
17
|
+
var _SimpleTraverser = require("./traverse/SimpleTraverser");
|
|
18
|
+
|
|
19
|
+
exports.SimpleTraverser = _SimpleTraverser.SimpleTraverser;
|
|
30
20
|
|
|
31
21
|
var _traverse = require("./traverse/traverse");
|
|
32
22
|
|
|
23
|
+
exports.traverse = _traverse.traverse;
|
|
24
|
+
exports.traverseWithContext = _traverse.traverseWithContext;
|
|
25
|
+
|
|
33
26
|
var _transform = require("./transform/transform");
|
|
34
27
|
|
|
28
|
+
exports.transform = _transform.transform;
|
|
29
|
+
|
|
35
30
|
var _t = _interopRequireWildcard(require("./generated/node-types"));
|
|
36
31
|
|
|
37
32
|
exports.t = _t;
|
|
38
33
|
|
|
39
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function
|
|
34
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
40
35
|
|
|
41
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null ||
|
|
36
|
+
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; }
|
package/dist/index.js.flow
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -10,6 +10,12 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
export {
|
|
13
|
+
export type {TraversalContextBase, Visitor} from './traverse/traverse';
|
|
14
|
+
export type {TransformVisitor} from './transform/transform';
|
|
15
|
+
export type {TransformContext} from './transform/TransformContext';
|
|
16
|
+
export type {DetachedNode} from './detachedNode';
|
|
17
|
+
|
|
18
|
+
export {SimpleTraverser} from './traverse/SimpleTraverser';
|
|
19
|
+
export {traverse, traverseWithContext} from './traverse/traverse';
|
|
14
20
|
export {transform} from './transform/transform';
|
|
15
21
|
export * as t from './generated/node-types';
|
package/dist/transform/Errors.js
CHANGED
|
@@ -1,36 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
6
|
exports.UnexpectedTransformationState = exports.NodeIsMutatedError = exports.NodeIsDeletedError = exports.InvalidStatementError = exports.InvalidReplacementError = exports.InvalidRemovalError = exports.InvalidInsertionError = void 0;
|
|
9
7
|
|
|
10
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
11
|
-
|
|
12
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
13
|
-
|
|
14
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
15
|
-
|
|
16
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
17
|
-
|
|
18
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
19
|
-
|
|
20
|
-
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
|
|
21
|
-
|
|
22
|
-
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
|
|
23
|
-
|
|
24
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
25
|
-
|
|
26
|
-
function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
|
|
27
|
-
|
|
28
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
29
|
-
|
|
30
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
31
|
-
|
|
32
8
|
/**
|
|
33
|
-
* Copyright (c)
|
|
9
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
34
10
|
*
|
|
35
11
|
* This source code is licensed under the MIT license found in the
|
|
36
12
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -38,114 +14,30 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
38
14
|
*
|
|
39
15
|
* @format
|
|
40
16
|
*/
|
|
41
|
-
|
|
42
|
-
_inherits(NodeIsDeletedError, _Error);
|
|
43
|
-
|
|
44
|
-
var _super = _createSuper(NodeIsDeletedError);
|
|
45
|
-
|
|
46
|
-
function NodeIsDeletedError() {
|
|
47
|
-
_classCallCheck(this, NodeIsDeletedError);
|
|
48
|
-
|
|
49
|
-
return _super.apply(this, arguments);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return NodeIsDeletedError;
|
|
53
|
-
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
17
|
+
class NodeIsDeletedError extends Error {}
|
|
54
18
|
|
|
55
19
|
exports.NodeIsDeletedError = NodeIsDeletedError;
|
|
56
20
|
|
|
57
|
-
|
|
58
|
-
_inherits(NodeIsMutatedError, _Error2);
|
|
59
|
-
|
|
60
|
-
var _super2 = _createSuper(NodeIsMutatedError);
|
|
61
|
-
|
|
62
|
-
function NodeIsMutatedError() {
|
|
63
|
-
_classCallCheck(this, NodeIsMutatedError);
|
|
64
|
-
|
|
65
|
-
return _super2.apply(this, arguments);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return NodeIsMutatedError;
|
|
69
|
-
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
21
|
+
class NodeIsMutatedError extends Error {}
|
|
70
22
|
|
|
71
23
|
exports.NodeIsMutatedError = NodeIsMutatedError;
|
|
72
24
|
|
|
73
|
-
|
|
74
|
-
_inherits(InvalidInsertionError, _Error3);
|
|
75
|
-
|
|
76
|
-
var _super3 = _createSuper(InvalidInsertionError);
|
|
77
|
-
|
|
78
|
-
function InvalidInsertionError() {
|
|
79
|
-
_classCallCheck(this, InvalidInsertionError);
|
|
80
|
-
|
|
81
|
-
return _super3.apply(this, arguments);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return InvalidInsertionError;
|
|
85
|
-
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
25
|
+
class InvalidInsertionError extends Error {}
|
|
86
26
|
|
|
87
27
|
exports.InvalidInsertionError = InvalidInsertionError;
|
|
88
28
|
|
|
89
|
-
|
|
90
|
-
_inherits(UnexpectedTransformationState, _Error4);
|
|
91
|
-
|
|
92
|
-
var _super4 = _createSuper(UnexpectedTransformationState);
|
|
93
|
-
|
|
94
|
-
function UnexpectedTransformationState() {
|
|
95
|
-
_classCallCheck(this, UnexpectedTransformationState);
|
|
96
|
-
|
|
97
|
-
return _super4.apply(this, arguments);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return UnexpectedTransformationState;
|
|
101
|
-
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
29
|
+
class UnexpectedTransformationState extends Error {}
|
|
102
30
|
|
|
103
31
|
exports.UnexpectedTransformationState = UnexpectedTransformationState;
|
|
104
32
|
|
|
105
|
-
|
|
106
|
-
_inherits(InvalidStatementError, _Error5);
|
|
107
|
-
|
|
108
|
-
var _super5 = _createSuper(InvalidStatementError);
|
|
109
|
-
|
|
110
|
-
function InvalidStatementError() {
|
|
111
|
-
_classCallCheck(this, InvalidStatementError);
|
|
112
|
-
|
|
113
|
-
return _super5.apply(this, arguments);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return InvalidStatementError;
|
|
117
|
-
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
33
|
+
class InvalidStatementError extends Error {}
|
|
118
34
|
|
|
119
35
|
exports.InvalidStatementError = InvalidStatementError;
|
|
120
36
|
|
|
121
|
-
|
|
122
|
-
_inherits(InvalidRemovalError, _Error6);
|
|
123
|
-
|
|
124
|
-
var _super6 = _createSuper(InvalidRemovalError);
|
|
125
|
-
|
|
126
|
-
function InvalidRemovalError() {
|
|
127
|
-
_classCallCheck(this, InvalidRemovalError);
|
|
128
|
-
|
|
129
|
-
return _super6.apply(this, arguments);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return InvalidRemovalError;
|
|
133
|
-
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
37
|
+
class InvalidRemovalError extends Error {}
|
|
134
38
|
|
|
135
39
|
exports.InvalidRemovalError = InvalidRemovalError;
|
|
136
40
|
|
|
137
|
-
|
|
138
|
-
_inherits(InvalidReplacementError, _Error7);
|
|
139
|
-
|
|
140
|
-
var _super7 = _createSuper(InvalidReplacementError);
|
|
141
|
-
|
|
142
|
-
function InvalidReplacementError() {
|
|
143
|
-
_classCallCheck(this, InvalidReplacementError);
|
|
144
|
-
|
|
145
|
-
return _super7.apply(this, arguments);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return InvalidReplacementError;
|
|
149
|
-
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
41
|
+
class InvalidReplacementError extends Error {}
|
|
150
42
|
|
|
151
43
|
exports.InvalidReplacementError = InvalidReplacementError;
|
|
@@ -9,86 +9,73 @@ var _Errors = require("./Errors");
|
|
|
9
9
|
|
|
10
10
|
var _comments = require("./comments/comments");
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
14
|
+
*
|
|
15
|
+
* This source code is licensed under the MIT license found in the
|
|
16
|
+
* LICENSE file in the root directory of this source tree.
|
|
17
|
+
*
|
|
18
|
+
*
|
|
19
|
+
* @format
|
|
20
|
+
*/
|
|
21
|
+
class MutationContext {
|
|
21
22
|
// TODO - do we care about this? Arrays are pretty safe to concurrently mutate
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
constructor(code) {
|
|
24
|
+
this._deletedNodes = new Set();
|
|
25
|
+
this._mutatedKeys = new Map();
|
|
26
|
+
this._mutatedArrays = new Map();
|
|
27
|
+
this.code = void 0;
|
|
28
|
+
this.code = code;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Marks a node and its entire subtree as deleted.
|
|
32
|
+
*/
|
|
24
33
|
|
|
25
|
-
_defineProperty(this, "_deletedNodes", new Set());
|
|
26
34
|
|
|
27
|
-
|
|
35
|
+
markDeletion(node) {
|
|
36
|
+
this._deletedNodes.add(node);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Marks the key of the node as having been mutated.
|
|
40
|
+
*/
|
|
28
41
|
|
|
29
|
-
_defineProperty(this, "_mutatedArrays", new Map());
|
|
30
42
|
|
|
31
|
-
|
|
43
|
+
markMutation(node, key) {
|
|
44
|
+
var _map$get$add, _map$get;
|
|
32
45
|
|
|
33
|
-
this.
|
|
46
|
+
this.assertNotDeleted(node, `Attempted to mutate a \`${node.type}.${key}\` on a deleted node.`);
|
|
47
|
+
this.assertNotMutated(node, key, `Attempted to mutate a \`${node.type}.${key}\` when it has already been mutated.`);
|
|
48
|
+
const map = Array.isArray( // $FlowExpectedError[prop-missing]
|
|
49
|
+
node[key]) ? this._mutatedArrays : this._mutatedKeys;
|
|
50
|
+
map.set(node, (_map$get$add = (_map$get = map.get(node)) == null ? void 0 : _map$get.add(key)) != null ? _map$get$add : new Set([key]));
|
|
34
51
|
}
|
|
35
52
|
/**
|
|
36
|
-
*
|
|
53
|
+
* Throws if the node has been deleted
|
|
37
54
|
*/
|
|
38
55
|
|
|
39
56
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
this._deletedNodes.add(node);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Marks the key of the node as having been mutated.
|
|
47
|
-
*/
|
|
48
|
-
|
|
49
|
-
}, {
|
|
50
|
-
key: "markMutation",
|
|
51
|
-
value: function markMutation(node, key) {
|
|
52
|
-
var _map$get$add, _map$get;
|
|
53
|
-
|
|
54
|
-
this.assertNotDeleted(node, "Attempted to mutate a `".concat(node.type, ".").concat(key, "` on a deleted node."));
|
|
55
|
-
this.assertNotMutated(node, key, "Attempted to mutate a `".concat(node.type, ".").concat(key, "` when it has already been mutated."));
|
|
56
|
-
var map = Array.isArray( // $FlowExpectedError[prop-missing]
|
|
57
|
-
node[key]) ? this._mutatedArrays : this._mutatedKeys;
|
|
58
|
-
map.set(node, (_map$get$add = (_map$get = map.get(node)) === null || _map$get === void 0 ? void 0 : _map$get.add(key)) !== null && _map$get$add !== void 0 ? _map$get$add : new Set([key]));
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Throws if the node has been deleted
|
|
62
|
-
*/
|
|
63
|
-
|
|
64
|
-
}, {
|
|
65
|
-
key: "assertNotDeleted",
|
|
66
|
-
value: function assertNotDeleted(node, message) {
|
|
67
|
-
if (this._deletedNodes.has(node)) {
|
|
68
|
-
throw new _Errors.NodeIsDeletedError(message);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Throws if the key of the node has been mutated
|
|
73
|
-
*/
|
|
74
|
-
|
|
75
|
-
}, {
|
|
76
|
-
key: "assertNotMutated",
|
|
77
|
-
value: function assertNotMutated(node, key, message) {
|
|
78
|
-
var _this$_mutatedKeys$ge;
|
|
79
|
-
|
|
80
|
-
if (((_this$_mutatedKeys$ge = this._mutatedKeys.get(node)) === null || _this$_mutatedKeys$ge === void 0 ? void 0 : _this$_mutatedKeys$ge.has(key)) === true) {
|
|
81
|
-
throw new _Errors.NodeIsMutatedError(message);
|
|
82
|
-
}
|
|
57
|
+
assertNotDeleted(node, message) {
|
|
58
|
+
if (this._deletedNodes.has(node)) {
|
|
59
|
+
throw new _Errors.NodeIsDeletedError(message);
|
|
83
60
|
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Throws if the key of the node has been mutated
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
assertNotMutated(node, key, message) {
|
|
68
|
+
var _this$_mutatedKeys$ge;
|
|
69
|
+
|
|
70
|
+
if (((_this$_mutatedKeys$ge = this._mutatedKeys.get(node)) == null ? void 0 : _this$_mutatedKeys$ge.has(key)) === true) {
|
|
71
|
+
throw new _Errors.NodeIsMutatedError(message);
|
|
88
72
|
}
|
|
89
|
-
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
appendCommentToSource(comment, placement) {
|
|
76
|
+
this.code = (0, _comments.appendCommentToSource)(this.code, comment, placement);
|
|
77
|
+
}
|
|
90
78
|
|
|
91
|
-
|
|
92
|
-
}();
|
|
79
|
+
}
|
|
93
80
|
|
|
94
81
|
exports.MutationContext = MutationContext;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
+
import type {CommentPlacement} from './comments/comments';
|
|
11
12
|
import type {Comment, ESNode} from 'hermes-estree';
|
|
12
13
|
|
|
13
14
|
import {NodeIsDeletedError, NodeIsMutatedError} from './Errors';
|
|
@@ -74,7 +75,7 @@ export class MutationContext {
|
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
77
|
|
|
77
|
-
appendCommentToSource(comment: Comment): void {
|
|
78
|
-
this.code = appendCommentToSource(this.code, comment);
|
|
78
|
+
appendCommentToSource(comment: Comment, placement: CommentPlacement): void {
|
|
79
|
+
this.code = appendCommentToSource(this.code, comment, placement);
|
|
79
80
|
}
|
|
80
81
|
}
|