hermes-parser 0.36.0 → 0.37.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/HermesAST.js.flow +2 -2
- package/dist/HermesASTAdapter.js +1 -1
- package/dist/HermesParser.js +1 -1
- package/dist/HermesParserDecodeUTF8String.js +1 -1
- package/dist/HermesParserDeserializer.js +1 -1
- package/dist/HermesParserDeserializer.js.flow +8 -8
- package/dist/HermesParserNodeDeserializers.js +1 -1
- package/dist/HermesParserNodeDeserializers.js.flow +1 -1
- package/dist/HermesParserWASM.js +1 -1
- package/dist/HermesParserWASM.js.flow +6 -6
- package/dist/HermesToESTreeAdapter.js +3 -2
- package/dist/HermesToESTreeAdapter.js.flow +4 -3
- package/dist/ParserOptions.js +5 -3
- package/dist/ParserOptions.js.flow +5 -5
- package/dist/babel/TransformESTreeToBabel.js +4 -3
- package/dist/babel/TransformESTreeToBabel.js.flow +101 -100
- package/dist/estree/StripFlowTypes.js +1 -1
- package/dist/estree/StripFlowTypesForBabel.js +1 -1
- package/dist/estree/TransformComponentSyntax.js +1 -1
- package/dist/estree/TransformComponentSyntax.js.flow +3 -3
- package/dist/estree/TransformEnumSyntax.js +1 -1
- package/dist/estree/TransformEnumSyntax.js.flow +1 -1
- package/dist/estree/TransformMatchSyntax.js +11 -2
- package/dist/estree/TransformMatchSyntax.js.flow +10 -9
- package/dist/estree/TransformRecordSyntax.js +1 -1
- package/dist/generated/ESTreeVisitorKeys.js +1 -1
- package/dist/generated/ESTreeVisitorKeys.js.flow +1 -1
- package/dist/generated/ParserVisitorKeys.js +1 -1
- package/dist/generated/ParserVisitorKeys.js.flow +2 -2
- package/dist/getModuleDocblock.js +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.flow +5 -5
- package/dist/src/HermesASTAdapter.js +1 -1
- package/dist/src/HermesParser.js +1 -1
- package/dist/src/HermesParserDecodeUTF8String.js +1 -1
- package/dist/src/HermesParserDeserializer.js +1 -1
- package/dist/src/HermesParserNodeDeserializers.js +1 -1
- package/dist/src/HermesToESTreeAdapter.js +3 -2
- package/dist/src/ParserOptions.js +5 -3
- package/dist/src/babel/TransformESTreeToBabel.js +4 -3
- package/dist/src/estree/StripFlowTypes.js +1 -1
- package/dist/src/estree/StripFlowTypesForBabel.js +1 -1
- package/dist/src/estree/TransformComponentSyntax.js +1 -1
- package/dist/src/estree/TransformEnumSyntax.js +1 -1
- package/dist/src/estree/TransformMatchSyntax.js +11 -2
- package/dist/src/estree/TransformRecordSyntax.js +1 -1
- package/dist/src/generated/ESTreeVisitorKeys.js +1 -1
- package/dist/src/generated/ParserVisitorKeys.js +1 -1
- package/dist/src/getModuleDocblock.js +1 -1
- package/dist/src/index.js +4 -3
- package/dist/src/transform/SimpleTransform.js +10 -1
- package/dist/src/transform/astArrayMutationHelpers.js +1 -1
- package/dist/src/transform/astNodeMutationHelpers.js +4 -3
- package/dist/src/traverse/SimpleTraverser.js +4 -2
- package/dist/src/traverse/getVisitorKeys.js +5 -3
- package/dist/src/utils/Builders.js +2 -3
- package/dist/src/utils/GenID.js +1 -1
- package/dist/src/utils/createSyntaxError.js +1 -1
- package/dist/src/utils/isReservedWord.js +1 -1
- package/dist/src/utils/mutateESTreeASTForPrettier.js +1 -1
- package/dist/transform/SimpleTransform.js +10 -1
- package/dist/transform/SimpleTransform.js.flow +6 -7
- package/dist/transform/astArrayMutationHelpers.js +1 -1
- package/dist/transform/astArrayMutationHelpers.js.flow +8 -8
- package/dist/transform/astNodeMutationHelpers.js +4 -3
- package/dist/transform/astNodeMutationHelpers.js.flow +12 -6
- package/dist/traverse/SimpleTraverser.js +4 -2
- package/dist/traverse/SimpleTraverser.js.flow +4 -4
- package/dist/traverse/getVisitorKeys.js +5 -3
- package/dist/traverse/getVisitorKeys.js.flow +5 -3
- package/dist/utils/Builders.js +2 -3
- package/dist/utils/Builders.js.flow +6 -6
- package/dist/utils/GenID.js +1 -1
- package/dist/utils/GenID.js.flow +2 -2
- package/dist/utils/createSyntaxError.js +1 -1
- package/dist/utils/isReservedWord.js +1 -1
- package/dist/utils/mutateESTreeASTForPrettier.js +1 -1
- package/dist/utils/mutateESTreeASTForPrettier.js.flow +1 -1
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
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.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* strict
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
@@ -135,9 +135,10 @@ function getOptions(options = { ...DEFAULTS
|
|
|
135
135
|
options.tokens = options.tokens === true;
|
|
136
136
|
options.allowReturnOutsideFunction = options.allowReturnOutsideFunction === true;
|
|
137
137
|
return options;
|
|
138
|
-
}
|
|
139
|
-
|
|
138
|
+
} // eslint-disable-next-line no-redeclare
|
|
140
139
|
// eslint-disable-next-line no-redeclare
|
|
140
|
+
|
|
141
|
+
|
|
141
142
|
function parse(code, opts) {
|
|
142
143
|
var _options$transformOpt, _options$transformOpt2;
|
|
143
144
|
|
package/dist/index.js.flow
CHANGED
|
@@ -25,8 +25,8 @@ import * as StripFlowTypesForBabel from './estree/StripFlowTypesForBabel';
|
|
|
25
25
|
import * as TransformESTreeToBabel from './babel/TransformESTreeToBabel';
|
|
26
26
|
import * as StripFlowTypes from './estree/StripFlowTypes';
|
|
27
27
|
|
|
28
|
-
const DEFAULTS = {
|
|
29
|
-
flow:
|
|
28
|
+
const DEFAULTS: {flow: 'detect'} = {
|
|
29
|
+
flow: 'detect',
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
function getOptions(options?: ParserOptions = {...DEFAULTS}) {
|
|
@@ -72,14 +72,14 @@ function getOptions(options?: ParserOptions = {...DEFAULTS}) {
|
|
|
72
72
|
|
|
73
73
|
declare function parse(
|
|
74
74
|
code: string,
|
|
75
|
-
opts:
|
|
75
|
+
opts: Readonly<{...ParserOptions, babel: true}>,
|
|
76
76
|
): BabelFile;
|
|
77
77
|
// eslint-disable-next-line no-redeclare
|
|
78
78
|
declare function parse(
|
|
79
79
|
code: string,
|
|
80
80
|
opts?:
|
|
81
|
-
|
|
|
82
|
-
|
|
|
81
|
+
| Readonly<{...ParserOptions, babel?: false | void}>
|
|
82
|
+
| Readonly<{...ParserOptions, babel: false}>,
|
|
83
83
|
): ESTreeProgram;
|
|
84
84
|
|
|
85
85
|
// eslint-disable-next-line no-redeclare
|
package/dist/src/HermesParser.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
/* eslint no-undef: 'error', no-unused-vars: ['error', {vars: "local"}], no-redeclare: 'error' */
|
|
20
20
|
|
|
21
|
-
/* global
|
|
21
|
+
/* global NonNullable, Partial, Readonly, ReadonlyArray, $FlowFixMe */
|
|
22
22
|
'use strict';
|
|
23
23
|
|
|
24
24
|
function deserializeEmpty() {
|
|
@@ -17,9 +17,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
17
17
|
* This source code is licensed under the MIT license found in the
|
|
18
18
|
* LICENSE file in the root directory of this source tree.
|
|
19
19
|
*
|
|
20
|
-
*
|
|
20
|
+
* strict
|
|
21
21
|
* @format
|
|
22
22
|
*/
|
|
23
|
+
// eslint-disable-next-line no-unused-vars
|
|
23
24
|
class HermesToESTreeAdapter extends _HermesASTAdapter.default {
|
|
24
25
|
constructor(options, code) {
|
|
25
26
|
super(options);
|
|
@@ -185,7 +186,7 @@ class HermesToESTreeAdapter extends _HermesASTAdapter.default {
|
|
|
185
186
|
|
|
186
187
|
try {
|
|
187
188
|
value = new RegExp(pattern, flags);
|
|
188
|
-
} catch
|
|
189
|
+
} catch {
|
|
189
190
|
value = null;
|
|
190
191
|
}
|
|
191
192
|
|
|
@@ -11,8 +11,10 @@ exports.ParserOptionsKeys = void 0;
|
|
|
11
11
|
* This source code is licensed under the MIT license found in the
|
|
12
12
|
* LICENSE file in the root directory of this source tree.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
* @
|
|
14
|
+
* strict
|
|
15
|
+
* @noformat
|
|
16
16
|
*/
|
|
17
|
-
const ParserOptionsKeys
|
|
17
|
+
const ParserOptionsKeys
|
|
18
|
+
/*: ReadonlySet<keyof ParserOptions> */
|
|
19
|
+
= new Set(['allowReturnOutsideFunction', 'babel', 'flow', 'enableExperimentalComponentSyntax', 'enableExperimentalFlowMatchSyntax', 'enableExperimentalFlowRecordSyntax', 'reactRuntimeTarget', 'sourceFilename', 'sourceType', 'tokens', 'transformOptions']);
|
|
18
20
|
exports.ParserOptionsKeys = ParserOptionsKeys;
|
|
@@ -4,7 +4,7 @@
|
|
|
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.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* strict
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
@@ -277,14 +277,15 @@ function mapProperty(node) {
|
|
|
277
277
|
|
|
278
278
|
return newNode;
|
|
279
279
|
} // Non-method property nodes should be renamed to ObjectProperty
|
|
280
|
+
// $FlowExpectedError[incompatible-type]
|
|
280
281
|
|
|
281
282
|
|
|
283
|
+
const propertyValue = value;
|
|
282
284
|
return {
|
|
283
285
|
type: 'ObjectProperty',
|
|
284
286
|
computed: node.computed,
|
|
285
287
|
key: node.key,
|
|
286
|
-
|
|
287
|
-
value: node.value,
|
|
288
|
+
value: propertyValue,
|
|
288
289
|
method: node.method,
|
|
289
290
|
shorthand: node.shorthand,
|
|
290
291
|
loc: node.loc,
|
|
@@ -4,7 +4,7 @@
|
|
|
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.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* strict
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
@@ -48,6 +48,14 @@ function genIdent() {
|
|
|
48
48
|
* location of to be tested against, or location to be extracted to a binding.
|
|
49
49
|
*/
|
|
50
50
|
|
|
51
|
+
/**
|
|
52
|
+
* The conditional aspect of a match pattern for a single location.
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* A binding introduced by a match pattern.
|
|
57
|
+
*/
|
|
58
|
+
|
|
51
59
|
|
|
52
60
|
function objKeyToString(node) {
|
|
53
61
|
switch (node.type) {
|
|
@@ -368,7 +376,8 @@ function analyzePattern(pattern, key, seenBindingNames) {
|
|
|
368
376
|
conditions,
|
|
369
377
|
bindings
|
|
370
378
|
} = analyzePattern(asPattern, key, seenBindingNames);
|
|
371
|
-
const
|
|
379
|
+
const constKind = 'const';
|
|
380
|
+
const [id, kind] = target.type === 'MatchBindingPattern' ? [target.id, target.kind] : [target, constKind];
|
|
372
381
|
checkDuplicateBindingName(seenBindingNames, pattern, id.name);
|
|
373
382
|
checkBindingKind(pattern, kind);
|
|
374
383
|
const binding = {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
/* eslint no-undef: 'error', no-unused-vars: ['error', {vars: "local"}], no-redeclare: 'error' */
|
|
20
20
|
|
|
21
|
-
/* global
|
|
21
|
+
/* global NonNullable, Partial, Readonly, ReadonlyArray, $FlowFixMe */
|
|
22
22
|
'use strict';
|
|
23
23
|
|
|
24
24
|
module.exports = {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
/* eslint no-undef: 'error', no-unused-vars: ['error', {vars: "local"}], no-redeclare: 'error' */
|
|
20
20
|
|
|
21
|
-
/* global
|
|
21
|
+
/* global NonNullable, Partial, Readonly, ReadonlyArray, $FlowFixMe */
|
|
22
22
|
'use strict';
|
|
23
23
|
|
|
24
24
|
Object.defineProperty(exports, "__esModule", {
|
package/dist/src/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
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.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* strict
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
@@ -135,9 +135,10 @@ function getOptions(options = { ...DEFAULTS
|
|
|
135
135
|
options.tokens = options.tokens === true;
|
|
136
136
|
options.allowReturnOutsideFunction = options.allowReturnOutsideFunction === true;
|
|
137
137
|
return options;
|
|
138
|
-
}
|
|
139
|
-
|
|
138
|
+
} // eslint-disable-next-line no-redeclare
|
|
140
139
|
// eslint-disable-next-line no-redeclare
|
|
140
|
+
|
|
141
|
+
|
|
141
142
|
function parse(code, opts) {
|
|
142
143
|
var _options$transformOpt, _options$transformOpt2;
|
|
143
144
|
|
|
@@ -4,7 +4,7 @@
|
|
|
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.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* strict
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
@@ -18,6 +18,15 @@ var _SimpleTraverser = require("../traverse/SimpleTraverser");
|
|
|
18
18
|
|
|
19
19
|
var _astNodeMutationHelpers = require("./astNodeMutationHelpers");
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Transform callback
|
|
23
|
+
* @param node The node we are visiting
|
|
24
|
+
* @returns
|
|
25
|
+
* - return input node, signals no changes were made will continue to the next node.
|
|
26
|
+
* - return new node, the old node will be replaced in the AST. The new node and its
|
|
27
|
+
* children are then traversed.
|
|
28
|
+
* - return null, signals the node should be deleted from the AST.
|
|
29
|
+
*/
|
|
21
30
|
function setParentPointer(node, parent) {
|
|
22
31
|
if (parent != null) {
|
|
23
32
|
if (Array.isArray(node)) {
|
|
@@ -4,7 +4,7 @@
|
|
|
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.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* strict
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
@@ -42,10 +42,11 @@ function getParentKey(target, parent, visitorKeys) {
|
|
|
42
42
|
key
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
-
} else if (Array.isArray(
|
|
45
|
+
} else if (Array.isArray( // $FlowExpectedError[prop-missing]
|
|
46
|
+
parent[key])) {
|
|
46
47
|
for (let i = 0; i < parent[key].length; i += 1) {
|
|
47
48
|
// $FlowExpectedError[invalid-tuple-index]
|
|
48
|
-
const current = parent[key][i];
|
|
49
|
+
const current = parent[key][i]; // $FlowFixMe[invalid-compare]
|
|
49
50
|
|
|
50
51
|
if (current === target) {
|
|
51
52
|
return {
|
|
@@ -4,7 +4,7 @@
|
|
|
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.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* strict
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
@@ -80,7 +80,9 @@ class SimpleTraverser {
|
|
|
80
80
|
const keys = (0, _getVisitorKeys.getVisitorKeys)(node, options.visitorKeys);
|
|
81
81
|
|
|
82
82
|
for (const key of keys) {
|
|
83
|
-
const
|
|
83
|
+
const lookupKey = key;
|
|
84
|
+
const childAny = node[lookupKey];
|
|
85
|
+
const child = childAny;
|
|
84
86
|
|
|
85
87
|
if (Array.isArray(child)) {
|
|
86
88
|
for (let j = 0; j < child.length; ++j) {
|
|
@@ -4,7 +4,7 @@
|
|
|
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.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* strict
|
|
8
8
|
* @noformat
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
@@ -20,12 +20,14 @@ var _ESTreeVisitorKeys = _interopRequireDefault(require("../generated/ESTreeVisi
|
|
|
20
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
21
|
|
|
22
22
|
function isNode(thing)
|
|
23
|
-
/*: implies thing is {
|
|
23
|
+
/*: implies thing is {readonly [string]: unknown} */
|
|
24
24
|
{
|
|
25
25
|
return typeof thing === 'object' && thing != null && typeof thing.type === 'string';
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
function getVisitorKeys(node, visitorKeys)
|
|
28
|
+
function getVisitorKeys(node, visitorKeys)
|
|
29
|
+
/*: ReadonlyArray<keyof T> */
|
|
30
|
+
{
|
|
29
31
|
const keys = (visitorKeys != null ? visitorKeys : _ESTreeVisitorKeys.default)[node.type];
|
|
30
32
|
|
|
31
33
|
if (keys == null) {
|
|
@@ -4,10 +4,10 @@
|
|
|
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.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* strict
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
|
-
'use strict';
|
|
10
|
+
'use strict'; // Rely on the mapper to fix up parent relationships.
|
|
11
11
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", {
|
|
13
13
|
value: true
|
|
@@ -26,7 +26,6 @@ exports.stringLiteral = stringLiteral;
|
|
|
26
26
|
exports.throwStatement = throwStatement;
|
|
27
27
|
exports.typeofExpression = typeofExpression;
|
|
28
28
|
exports.variableDeclaration = variableDeclaration;
|
|
29
|
-
// Rely on the mapper to fix up parent relationships.
|
|
30
29
|
const EMPTY_PARENT = null;
|
|
31
30
|
exports.EMPTY_PARENT = EMPTY_PARENT;
|
|
32
31
|
|
package/dist/src/utils/GenID.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
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.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* strict
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
@@ -18,6 +18,15 @@ var _SimpleTraverser = require("../traverse/SimpleTraverser");
|
|
|
18
18
|
|
|
19
19
|
var _astNodeMutationHelpers = require("./astNodeMutationHelpers");
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Transform callback
|
|
23
|
+
* @param node The node we are visiting
|
|
24
|
+
* @returns
|
|
25
|
+
* - return input node, signals no changes were made will continue to the next node.
|
|
26
|
+
* - return new node, the old node will be replaced in the AST. The new node and its
|
|
27
|
+
* children are then traversed.
|
|
28
|
+
* - return null, signals the node should be deleted from the AST.
|
|
29
|
+
*/
|
|
21
30
|
function setParentPointer(node, parent) {
|
|
22
31
|
if (parent != null) {
|
|
23
32
|
if (Array.isArray(node)) {
|
|
@@ -31,9 +31,9 @@ import {
|
|
|
31
31
|
*/
|
|
32
32
|
export type TransformCallback = (
|
|
33
33
|
node: ESNode,
|
|
34
|
-
) => ESNode |
|
|
34
|
+
) => ESNode | ReadonlyArray<ESNode> | null;
|
|
35
35
|
|
|
36
|
-
export type TransformOptions =
|
|
36
|
+
export type TransformOptions = Readonly<{
|
|
37
37
|
/** The callback function which is called on entering each node. */
|
|
38
38
|
transform: TransformCallback,
|
|
39
39
|
|
|
@@ -42,7 +42,7 @@ export type TransformOptions = $ReadOnly<{
|
|
|
42
42
|
}>;
|
|
43
43
|
|
|
44
44
|
function setParentPointer(
|
|
45
|
-
node: ESNode |
|
|
45
|
+
node: ESNode | ReadonlyArray<ESNode>,
|
|
46
46
|
parent: ?ESNode,
|
|
47
47
|
): void {
|
|
48
48
|
if (parent != null) {
|
|
@@ -75,11 +75,10 @@ export class SimpleTransform {
|
|
|
75
75
|
// Ensure the parent pointers are correctly set before entering the node.
|
|
76
76
|
setParentPointer(node, parent);
|
|
77
77
|
|
|
78
|
-
const resultNode: ESNode |
|
|
78
|
+
const resultNode: ESNode | ReadonlyArray<ESNode> | null =
|
|
79
79
|
options.transform(node);
|
|
80
80
|
if (resultNode !== node) {
|
|
81
|
-
let traversedResultNode: ESNode |
|
|
82
|
-
null;
|
|
81
|
+
let traversedResultNode: ESNode | ReadonlyArray<ESNode> | null = null;
|
|
83
82
|
|
|
84
83
|
if (resultNode != null) {
|
|
85
84
|
// Ensure the new node has the correct parent pointers before recursing again.
|
|
@@ -159,7 +158,7 @@ export class SimpleTransform {
|
|
|
159
158
|
* @return Either the orginal node if the properties matched the existing node or a new node with
|
|
160
159
|
* the new properties.
|
|
161
160
|
*/
|
|
162
|
-
static nodeWith<T
|
|
161
|
+
static nodeWith<T extends ESNode>(
|
|
163
162
|
node: T,
|
|
164
163
|
overrideProps: Partial<T>,
|
|
165
164
|
visitorKeys?: VisitorKeysType,
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
function assertArrayBounds<T>(array:
|
|
11
|
+
function assertArrayBounds<T>(array: ReadonlyArray<T>, index: number): void {
|
|
12
12
|
if (index < 0 || index >= array.length) {
|
|
13
13
|
throw new Error(
|
|
14
14
|
`Invalid Mutation: Tried to mutate an elements array with an out of bounds index. Index: ${index}, Array Size: ${array.length}`,
|
|
@@ -17,8 +17,8 @@ function assertArrayBounds<T>(array: $ReadOnlyArray<T>, index: number): void {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export function arrayIsEqual(
|
|
20
|
-
a1:
|
|
21
|
-
a2:
|
|
20
|
+
a1: ReadonlyArray<unknown>,
|
|
21
|
+
a2: ReadonlyArray<unknown>,
|
|
22
22
|
): boolean {
|
|
23
23
|
if (a1 === a2) {
|
|
24
24
|
return true;
|
|
@@ -38,9 +38,9 @@ export function arrayIsEqual(
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
export function insertInArray<T>(
|
|
41
|
-
array:
|
|
41
|
+
array: ReadonlyArray<T>,
|
|
42
42
|
index: number,
|
|
43
|
-
elements:
|
|
43
|
+
elements: ReadonlyArray<T>,
|
|
44
44
|
): Array<T> {
|
|
45
45
|
if (index === array.length) {
|
|
46
46
|
// Support the insert at end of array case.
|
|
@@ -51,7 +51,7 @@ export function insertInArray<T>(
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
export function removeFromArray<T>(
|
|
54
|
-
array:
|
|
54
|
+
array: ReadonlyArray<T>,
|
|
55
55
|
index: number,
|
|
56
56
|
): Array<T> {
|
|
57
57
|
assertArrayBounds(array, index);
|
|
@@ -59,9 +59,9 @@ export function removeFromArray<T>(
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
export function replaceInArray<T>(
|
|
62
|
-
array:
|
|
62
|
+
array: ReadonlyArray<T>,
|
|
63
63
|
index: number,
|
|
64
|
-
elements:
|
|
64
|
+
elements: ReadonlyArray<T>,
|
|
65
65
|
): Array<T> {
|
|
66
66
|
assertArrayBounds(array, index);
|
|
67
67
|
return array
|
|
@@ -4,7 +4,7 @@
|
|
|
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.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* strict
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
@@ -42,10 +42,11 @@ function getParentKey(target, parent, visitorKeys) {
|
|
|
42
42
|
key
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
-
} else if (Array.isArray(
|
|
45
|
+
} else if (Array.isArray( // $FlowExpectedError[prop-missing]
|
|
46
|
+
parent[key])) {
|
|
46
47
|
for (let i = 0; i < parent[key].length; i += 1) {
|
|
47
48
|
// $FlowExpectedError[invalid-tuple-index]
|
|
48
|
-
const current = parent[key][i];
|
|
49
|
+
const current = parent[key][i]; // $FlowFixMe[invalid-compare]
|
|
49
50
|
|
|
50
51
|
if (current === target) {
|
|
51
52
|
return {
|