flow-parser 0.320.0 → 0.322.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/README.md +14 -26
- package/{oxidized/oxidized-src → dist}/FlowParser.js +3 -53
- package/{oxidized/oxidized-src → dist}/FlowParserDeserializer.js +3 -41
- package/{oxidized → dist}/FlowParserNodeDeserializers.js +0 -7
- package/{oxidized → dist}/FlowParserWASM.js +1 -1
- package/{oxidized/oxidized-src → dist}/HermesParserDecodeUTF8String.js +0 -9
- package/dist/ParserOptions.js +7 -0
- package/{oxidized → dist}/babel/TransformESTreeToBabel.js +9 -157
- package/{oxidized → dist}/estree/StripFlowTypes.js +0 -26
- package/{oxidized/oxidized-src → dist}/estree/StripFlowTypesForBabel.js +0 -24
- package/{oxidized/oxidized-src → dist}/estree/TransformComponentSyntax.js +0 -87
- package/{oxidized/oxidized-src → dist}/estree/TransformEnumSyntax.js +0 -12
- package/{oxidized/oxidized-src → dist}/estree/TransformMatchSyntax.js +3 -99
- package/{oxidized → dist}/estree/TransformRecordSyntax.js +3 -31
- package/{oxidized → dist}/getModuleDocblock.js +0 -21
- package/{oxidized → dist}/index.js +25 -99
- package/{oxidized → dist}/transform/SimpleTransform.js +0 -21
- package/{oxidized → dist}/transform/astArrayMutationHelpers.js +0 -9
- package/{oxidized/oxidized-src → dist}/transform/astNodeMutationHelpers.js +4 -26
- package/{oxidized/oxidized-src → dist}/transform/print/comments/comments.js +2 -51
- package/{oxidized → dist}/transform/print/comments/prettier/common/util.js +0 -49
- package/{oxidized → dist}/transform/print/comments/prettier/language-js/comments.js +0 -111
- package/{oxidized/oxidized-src → dist}/transform/print/comments/prettier/language-js/loc.js +0 -6
- package/{oxidized/oxidized-src → dist}/transform/print/comments/prettier/language-js/printer-estree.js +0 -3
- package/{oxidized/oxidized-src → dist}/transform/print/comments/prettier/language-js/utils.js +0 -20
- package/{oxidized/oxidized-src → dist}/transform/print/comments/prettier/main/comments.js +2 -63
- package/{oxidized/oxidized-src → dist}/transform/print/comments/prettier/utils/get-last.js +0 -1
- package/{oxidized → dist}/transform/print/print.js +6 -22
- package/{oxidized/oxidized-src → dist}/traverse/SimpleTraverser.js +2 -22
- package/{oxidized/oxidized-src → dist}/traverse/getVisitorKeys.js +3 -9
- package/{oxidized/oxidized-src → dist}/utils/Builders.js +1 -17
- package/{oxidized → dist}/utils/GenID.js +0 -7
- package/{oxidized/oxidized-src → dist}/utils/createSyntaxError.js +0 -1
- package/{oxidized → dist}/utils/isReservedWord.js +0 -2
- package/{oxidized → dist}/utils/mutateESTreeASTForPrettier.js +6 -21
- package/package.json +6 -7
- package/flow_parser.js +0 -14585
- package/oxidized/FlowParser.js +0 -249
- package/oxidized/FlowParserDeserializer.js +0 -209
- package/oxidized/HermesParserDecodeUTF8String.js +0 -45
- package/oxidized/ParserOptions.js +0 -8
- package/oxidized/estree/StripFlowTypesForBabel.js +0 -191
- package/oxidized/estree/TransformComponentSyntax.js +0 -764
- package/oxidized/estree/TransformEnumSyntax.js +0 -92
- package/oxidized/estree/TransformMatchSyntax.js +0 -990
- package/oxidized/oxidized-src/FlowParserNodeDeserializers.js +0 -1781
- package/oxidized/oxidized-src/ParserOptions.js +0 -8
- package/oxidized/oxidized-src/babel/TransformESTreeToBabel.js +0 -1063
- package/oxidized/oxidized-src/estree/StripFlowTypes.js +0 -158
- package/oxidized/oxidized-src/estree/TransformRecordSyntax.js +0 -283
- package/oxidized/oxidized-src/generated/ESTreeVisitorKeys.js +0 -234
- package/oxidized/oxidized-src/getModuleDocblock.js +0 -87
- package/oxidized/oxidized-src/index.js +0 -220
- package/oxidized/oxidized-src/transform/SimpleTransform.js +0 -95
- package/oxidized/oxidized-src/transform/astArrayMutationHelpers.js +0 -52
- package/oxidized/oxidized-src/transform/print/comments/prettier/common/util.js +0 -235
- package/oxidized/oxidized-src/transform/print/comments/prettier/language-js/comments.js +0 -663
- package/oxidized/oxidized-src/transform/print/print.js +0 -68
- package/oxidized/oxidized-src/utils/GenID.js +0 -37
- package/oxidized/oxidized-src/utils/isReservedWord.js +0 -53
- package/oxidized/oxidized-src/utils/mutateESTreeASTForPrettier.js +0 -85
- package/oxidized/transform/astNodeMutationHelpers.js +0 -142
- package/oxidized/transform/print/comments/comments.js +0 -245
- package/oxidized/transform/print/comments/prettier/language-js/loc.js +0 -30
- package/oxidized/transform/print/comments/prettier/language-js/printer-estree.js +0 -23
- package/oxidized/transform/print/comments/prettier/language-js/utils.js +0 -89
- package/oxidized/transform/print/comments/prettier/main/comments.js +0 -374
- package/oxidized/transform/print/comments/prettier/utils/get-last.js +0 -5
- package/oxidized/transform/print/detachedNodeTypes.js +0 -1
- package/oxidized/traverse/SimpleTraverser.js +0 -90
- package/oxidized/traverse/getVisitorKeys.js +0 -29
- package/oxidized/utils/Builders.js +0 -181
- package/oxidized/utils/createSyntaxError.js +0 -15
- /package/{oxidized → dist}/FlowParser.js.flow +0 -0
- /package/{oxidized → dist}/FlowParserDeserializer.js.flow +0 -0
- /package/{oxidized → dist}/FlowParserNodeDeserializers.js.flow +0 -0
- /package/{oxidized → dist}/FlowParserWASM.js.flow +0 -0
- /package/{oxidized → dist}/HermesAST.js.flow +0 -0
- /package/{oxidized → dist}/HermesParserDecodeUTF8String.js.flow +0 -0
- /package/{oxidized → dist}/ParserOptions.js.flow +0 -0
- /package/{oxidized → dist}/babel/TransformESTreeToBabel.js.flow +0 -0
- /package/{oxidized → dist}/estree/StripFlowTypes.js.flow +0 -0
- /package/{oxidized → dist}/estree/StripFlowTypesForBabel.js.flow +0 -0
- /package/{oxidized → dist}/estree/TransformComponentSyntax.js.flow +0 -0
- /package/{oxidized → dist}/estree/TransformEnumSyntax.js.flow +0 -0
- /package/{oxidized → dist}/estree/TransformMatchSyntax.js.flow +0 -0
- /package/{oxidized → dist}/estree/TransformRecordSyntax.js.flow +0 -0
- /package/{oxidized → dist}/generated/ESTreeVisitorKeys.js +0 -0
- /package/{oxidized → dist}/generated/ESTreeVisitorKeys.js.flow +0 -0
- /package/{oxidized → dist}/getModuleDocblock.js.flow +0 -0
- /package/{oxidized → dist}/index.js.flow +0 -0
- /package/{oxidized → dist}/transform/SimpleTransform.js.flow +0 -0
- /package/{oxidized → dist}/transform/astArrayMutationHelpers.js.flow +0 -0
- /package/{oxidized → dist}/transform/astNodeMutationHelpers.js.flow +0 -0
- /package/{oxidized → dist}/transform/print/comments/comments.js.flow +0 -0
- /package/{oxidized/oxidized-src → dist}/transform/print/detachedNodeTypes.js +0 -0
- /package/{oxidized → dist}/transform/print/detachedNodeTypes.js.flow +0 -0
- /package/{oxidized → dist}/transform/print/print.js.flow +0 -0
- /package/{oxidized → dist}/traverse/SimpleTraverser.js.flow +0 -0
- /package/{oxidized → dist}/traverse/getVisitorKeys.js.flow +0 -0
- /package/{oxidized → dist}/utils/Builders.js.flow +0 -0
- /package/{oxidized → dist}/utils/GenID.js.flow +0 -0
- /package/{oxidized → dist}/utils/createSyntaxError.js.flow +0 -0
- /package/{oxidized → dist}/utils/isReservedWord.js.flow +0 -0
- /package/{oxidized → dist}/utils/mutateESTreeASTForPrettier.js.flow +0 -0
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getModuleDocblock = getModuleDocblock;
|
|
7
|
-
exports.parseDocblockString = parseDocblockString;
|
|
8
|
-
const DIRECTIVE_REGEX = /^\s*@([a-zA-Z0-9_-]+)( +.+)?$/;
|
|
9
|
-
|
|
10
|
-
function parseDocblockString(docblock) {
|
|
11
|
-
const directiveLines = docblock.split('\n').map(line => line.trimStart().replace(/^\* ?/, '').trim()).filter(line => line.startsWith('@'));
|
|
12
|
-
const directives = Object.create(null);
|
|
13
|
-
|
|
14
|
-
for (const line of directiveLines) {
|
|
15
|
-
var _match$;
|
|
16
|
-
|
|
17
|
-
const match = DIRECTIVE_REGEX.exec(line);
|
|
18
|
-
|
|
19
|
-
if (match == null) {
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const name = match[1];
|
|
24
|
-
const value = ((_match$ = match[2]) != null ? _match$ : '').trim();
|
|
25
|
-
|
|
26
|
-
if (directives[name]) {
|
|
27
|
-
directives[name].push(value);
|
|
28
|
-
} else {
|
|
29
|
-
directives[name] = [value];
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return directives;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function getModuleDocblock(hermesProgram) {
|
|
37
|
-
const docblockNode = (() => {
|
|
38
|
-
if (hermesProgram.type !== 'Program') {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const program = hermesProgram;
|
|
43
|
-
|
|
44
|
-
if (program.comments.length === 0) {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const firstComment = (() => {
|
|
49
|
-
const first = program.comments[0];
|
|
50
|
-
|
|
51
|
-
if (first.type === 'Block') {
|
|
52
|
-
return first;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (program.comments.length === 1) {
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const second = program.comments[1];
|
|
60
|
-
|
|
61
|
-
if (first.type === 'Line' && first.range[0] === 0 && second.type === 'Block') {
|
|
62
|
-
return second;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return null;
|
|
66
|
-
})();
|
|
67
|
-
|
|
68
|
-
if (firstComment == null) {
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (program.body.length > 0 && program.body[0].range[0] < firstComment.range[0]) {
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return firstComment;
|
|
77
|
-
})();
|
|
78
|
-
|
|
79
|
-
if (docblockNode == null) {
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return {
|
|
84
|
-
directives: parseDocblockString(docblockNode.value),
|
|
85
|
-
comment: docblockNode
|
|
86
|
-
};
|
|
87
|
-
}
|
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _exportNames = {
|
|
7
|
-
parse: true,
|
|
8
|
-
mutateESTreeASTForPrettier: true,
|
|
9
|
-
Transforms: true,
|
|
10
|
-
FlowVisitorKeys: true,
|
|
11
|
-
astArrayMutationHelpers: true,
|
|
12
|
-
astNodeMutationHelpers: true
|
|
13
|
-
};
|
|
14
|
-
exports.mutateESTreeASTForPrettier = exports.astNodeMutationHelpers = exports.astArrayMutationHelpers = exports.Transforms = void 0;
|
|
15
|
-
exports.parse = parse;
|
|
16
|
-
|
|
17
|
-
var FlowParser = _interopRequireWildcard(require("./FlowParser"));
|
|
18
|
-
|
|
19
|
-
var _ESTreeVisitorKeys = _interopRequireDefault(require("./generated/ESTreeVisitorKeys"));
|
|
20
|
-
|
|
21
|
-
exports.FlowVisitorKeys = _ESTreeVisitorKeys.default;
|
|
22
|
-
|
|
23
|
-
var TransformComponentSyntax = _interopRequireWildcard(require("./estree/TransformComponentSyntax"));
|
|
24
|
-
|
|
25
|
-
var TransformEnumSyntax = _interopRequireWildcard(require("./estree/TransformEnumSyntax"));
|
|
26
|
-
|
|
27
|
-
var TransformMatchSyntax = _interopRequireWildcard(require("./estree/TransformMatchSyntax"));
|
|
28
|
-
|
|
29
|
-
var TransformRecordSyntax = _interopRequireWildcard(require("./estree/TransformRecordSyntax"));
|
|
30
|
-
|
|
31
|
-
var StripFlowTypesForBabel = _interopRequireWildcard(require("./estree/StripFlowTypesForBabel"));
|
|
32
|
-
|
|
33
|
-
var TransformESTreeToBabel = _interopRequireWildcard(require("./babel/TransformESTreeToBabel"));
|
|
34
|
-
|
|
35
|
-
var StripFlowTypes = _interopRequireWildcard(require("./estree/StripFlowTypes"));
|
|
36
|
-
|
|
37
|
-
var _ParserOptions = require("./ParserOptions");
|
|
38
|
-
|
|
39
|
-
Object.keys(_ParserOptions).forEach(function (key) {
|
|
40
|
-
if (key === "default" || key === "__esModule") return;
|
|
41
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
42
|
-
if (key in exports && exports[key] === _ParserOptions[key]) return;
|
|
43
|
-
exports[key] = _ParserOptions[key];
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
var _SimpleTraverser = require("./traverse/SimpleTraverser");
|
|
47
|
-
|
|
48
|
-
Object.keys(_SimpleTraverser).forEach(function (key) {
|
|
49
|
-
if (key === "default" || key === "__esModule") return;
|
|
50
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
51
|
-
if (key in exports && exports[key] === _SimpleTraverser[key]) return;
|
|
52
|
-
exports[key] = _SimpleTraverser[key];
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
var _SimpleTransform = require("./transform/SimpleTransform");
|
|
56
|
-
|
|
57
|
-
Object.keys(_SimpleTransform).forEach(function (key) {
|
|
58
|
-
if (key === "default" || key === "__esModule") return;
|
|
59
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
60
|
-
if (key in exports && exports[key] === _SimpleTransform[key]) return;
|
|
61
|
-
exports[key] = _SimpleTransform[key];
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
var _getVisitorKeys = require("./traverse/getVisitorKeys");
|
|
65
|
-
|
|
66
|
-
Object.keys(_getVisitorKeys).forEach(function (key) {
|
|
67
|
-
if (key === "default" || key === "__esModule") return;
|
|
68
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
69
|
-
if (key in exports && exports[key] === _getVisitorKeys[key]) return;
|
|
70
|
-
exports[key] = _getVisitorKeys[key];
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
var _astArrayMutationHelpers = _interopRequireWildcard(require("./transform/astArrayMutationHelpers"));
|
|
74
|
-
|
|
75
|
-
exports.astArrayMutationHelpers = _astArrayMutationHelpers;
|
|
76
|
-
|
|
77
|
-
var _astNodeMutationHelpers = _interopRequireWildcard(require("./transform/astNodeMutationHelpers"));
|
|
78
|
-
|
|
79
|
-
exports.astNodeMutationHelpers = _astNodeMutationHelpers;
|
|
80
|
-
|
|
81
|
-
var _mutateESTreeASTForPrettier = _interopRequireDefault(require("./utils/mutateESTreeASTForPrettier"));
|
|
82
|
-
|
|
83
|
-
exports.mutateESTreeASTForPrettier = _mutateESTreeASTForPrettier.default;
|
|
84
|
-
|
|
85
|
-
function _interopRequireDefault(obj) {
|
|
86
|
-
return obj && obj.__esModule ? obj : {
|
|
87
|
-
default: obj
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function _getRequireWildcardCache(nodeInterop) {
|
|
92
|
-
if (typeof WeakMap !== "function") return null;
|
|
93
|
-
var cacheBabelInterop = new WeakMap();
|
|
94
|
-
var cacheNodeInterop = new WeakMap();
|
|
95
|
-
return (_getRequireWildcardCache = function (nodeInterop) {
|
|
96
|
-
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
97
|
-
})(nodeInterop);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function _interopRequireWildcard(obj, nodeInterop) {
|
|
101
|
-
if (!nodeInterop && obj && obj.__esModule) {
|
|
102
|
-
return obj;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
106
|
-
return {
|
|
107
|
-
default: obj
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
var cache = _getRequireWildcardCache(nodeInterop);
|
|
112
|
-
|
|
113
|
-
if (cache && cache.has(obj)) {
|
|
114
|
-
return cache.get(obj);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
var newObj = {};
|
|
118
|
-
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
119
|
-
|
|
120
|
-
for (var key in obj) {
|
|
121
|
-
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
122
|
-
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
123
|
-
|
|
124
|
-
if (desc && (desc.get || desc.set)) {
|
|
125
|
-
Object.defineProperty(newObj, key, desc);
|
|
126
|
-
} else {
|
|
127
|
-
newObj[key] = obj[key];
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
newObj.default = obj;
|
|
133
|
-
|
|
134
|
-
if (cache) {
|
|
135
|
-
cache.set(obj, newObj);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return newObj;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const DEFAULTS = {
|
|
142
|
-
flow: 'detect'
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
function getOptions(opts) {
|
|
146
|
-
const options = { ...DEFAULTS,
|
|
147
|
-
...(opts != null ? opts : {})
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
if (options.flow !== 'all' && options.flow !== 'detect') {
|
|
151
|
-
throw new Error('flow option must be "all" or "detect"');
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (options.sourceType === 'unambiguous') {
|
|
155
|
-
delete options.sourceType;
|
|
156
|
-
} else if (options.sourceType != null && options.sourceType !== 'script' && options.sourceType !== 'module') {
|
|
157
|
-
throw new Error('sourceType option must be "script", "module", or "unambiguous" if set');
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (options.enableExperimentalComponentSyntax == null) {
|
|
161
|
-
options.enableExperimentalComponentSyntax = true;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (options.enableExperimentalFlowMatchSyntax == null) {
|
|
165
|
-
options.enableExperimentalFlowMatchSyntax = true;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (options.enableExperimentalFlowRecordSyntax == null) {
|
|
169
|
-
options.enableExperimentalFlowRecordSyntax = true;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
options.enableRecords = options.enableExperimentalFlowRecordSyntax;
|
|
173
|
-
|
|
174
|
-
if (options.enableEnums == null) {
|
|
175
|
-
options.enableEnums = true;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
if (options.enableExperimentalDecorators == null) {
|
|
179
|
-
options.enableExperimentalDecorators = true;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
options.tokens = options.tokens === true;
|
|
183
|
-
options.allowReturnOutsideFunction = options.allowReturnOutsideFunction === true;
|
|
184
|
-
return options;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
function parse(code, opts) {
|
|
188
|
-
var _options$transformOpt, _options$transformOpt2;
|
|
189
|
-
|
|
190
|
-
const options = getOptions(opts);
|
|
191
|
-
|
|
192
|
-
if (options.flow === 'all') {
|
|
193
|
-
options.enableTypes = true;
|
|
194
|
-
} else {
|
|
195
|
-
options.enableTypesPragmaDetection = true;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
const estreeAST = FlowParser.parse(code, options);
|
|
199
|
-
|
|
200
|
-
if (options.babel !== true) {
|
|
201
|
-
return estreeAST;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
const loweredESTreeAST = [(_options$transformOpt = options.transformOptions) != null && (_options$transformOpt2 = _options$transformOpt.TransformEnumSyntax) != null && _options$transformOpt2.enable ? TransformEnumSyntax.transformProgram : null, TransformMatchSyntax.transformProgram, TransformComponentSyntax.transformProgram, TransformRecordSyntax.transformProgram, StripFlowTypesForBabel.transformProgram].reduce((ast, transform) => {
|
|
205
|
-
var _transform;
|
|
206
|
-
|
|
207
|
-
return (_transform = transform == null ? void 0 : transform(ast, options)) != null ? _transform : ast;
|
|
208
|
-
}, estreeAST);
|
|
209
|
-
return TransformESTreeToBabel.transformProgram(loweredESTreeAST, options);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
const Transforms = {
|
|
213
|
-
transformEnumSyntax: TransformEnumSyntax.transformProgram,
|
|
214
|
-
transformMatchSyntax: TransformMatchSyntax.transformProgram,
|
|
215
|
-
transformComponentSyntax: TransformComponentSyntax.transformProgram,
|
|
216
|
-
transformRecordSyntax: TransformRecordSyntax.transformProgram,
|
|
217
|
-
stripFlowTypesForBabel: StripFlowTypesForBabel.transformProgram,
|
|
218
|
-
stripFlowTypes: StripFlowTypes.transformProgram
|
|
219
|
-
};
|
|
220
|
-
exports.Transforms = Transforms;
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.SimpleTransform = void 0;
|
|
7
|
-
|
|
8
|
-
var _SimpleTraverser = require("../traverse/SimpleTraverser");
|
|
9
|
-
|
|
10
|
-
var _astNodeMutationHelpers = require("./astNodeMutationHelpers");
|
|
11
|
-
|
|
12
|
-
function setParentPointer(node, parent) {
|
|
13
|
-
if (parent != null) {
|
|
14
|
-
if (Array.isArray(node)) {
|
|
15
|
-
for (const item of node) {
|
|
16
|
-
item.parent = parent;
|
|
17
|
-
}
|
|
18
|
-
} else {
|
|
19
|
-
node.parent = parent;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
class SimpleTransform {
|
|
25
|
-
transform(rootNode, options) {
|
|
26
|
-
let resultRootNode = rootNode;
|
|
27
|
-
|
|
28
|
-
_SimpleTraverser.SimpleTraverser.traverse(rootNode, {
|
|
29
|
-
enter: (node, parent) => {
|
|
30
|
-
setParentPointer(node, parent);
|
|
31
|
-
const resultNode = options.transform(node);
|
|
32
|
-
|
|
33
|
-
if (resultNode !== node) {
|
|
34
|
-
let traversedResultNode = null;
|
|
35
|
-
|
|
36
|
-
if (resultNode != null) {
|
|
37
|
-
setParentPointer(resultNode, parent);
|
|
38
|
-
|
|
39
|
-
if (Array.isArray(resultNode)) {
|
|
40
|
-
traversedResultNode = resultNode.map(item => this.transform(item, options)).filter(item => item != null);
|
|
41
|
-
} else {
|
|
42
|
-
traversedResultNode = this.transform(resultNode, options);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (parent == null) {
|
|
47
|
-
if (node !== rootNode) {
|
|
48
|
-
throw new Error('SimpleTransform infra error: Parent not set on non root node, this should not be possible');
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (Array.isArray(traversedResultNode)) {
|
|
52
|
-
throw new Error('SimpleTransform: invalid array result for root node');
|
|
53
|
-
} else {
|
|
54
|
-
resultRootNode = traversedResultNode;
|
|
55
|
-
}
|
|
56
|
-
} else if (traversedResultNode == null) {
|
|
57
|
-
(0, _astNodeMutationHelpers.removeNodeOnParent)(node, parent, options.visitorKeys);
|
|
58
|
-
} else {
|
|
59
|
-
(0, _astNodeMutationHelpers.replaceNodeOnParent)(node, parent, traversedResultNode, options.visitorKeys);
|
|
60
|
-
setParentPointer(traversedResultNode, parent);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
throw _SimpleTraverser.SimpleTraverser.Skip;
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
|
|
67
|
-
leave(_node) {},
|
|
68
|
-
|
|
69
|
-
visitorKeys: options.visitorKeys
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
return resultRootNode;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
static transform(node, options) {
|
|
76
|
-
return new SimpleTransform().transform(node, options);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
static transformProgram(program, options) {
|
|
80
|
-
const result = SimpleTransform.transform(program, options);
|
|
81
|
-
|
|
82
|
-
if ((result == null ? void 0 : result.type) === 'Program') {
|
|
83
|
-
return result;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
throw new Error('SimpleTransform.transformProgram: Expected program node.');
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
static nodeWith(node, overrideProps, visitorKeys) {
|
|
90
|
-
return (0, _astNodeMutationHelpers.nodeWith)(node, overrideProps, visitorKeys);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
exports.SimpleTransform = SimpleTransform;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.arrayIsEqual = arrayIsEqual;
|
|
7
|
-
exports.insertInArray = insertInArray;
|
|
8
|
-
exports.removeFromArray = removeFromArray;
|
|
9
|
-
exports.replaceInArray = replaceInArray;
|
|
10
|
-
|
|
11
|
-
function assertArrayBounds(array, index) {
|
|
12
|
-
if (index < 0 || index >= array.length) {
|
|
13
|
-
throw new Error(`Invalid Mutation: Tried to mutate an elements array with an out of bounds index. Index: ${index}, Array Size: ${array.length}`);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function arrayIsEqual(a1, a2) {
|
|
18
|
-
if (a1 === a2) {
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (a1.length !== a2.length) {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
for (let i = 0; i < a1.length; i++) {
|
|
27
|
-
if (a1[i] !== a2[i]) {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function insertInArray(array, index, elements) {
|
|
36
|
-
if (index === array.length) {
|
|
37
|
-
return array.concat(elements);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
assertArrayBounds(array, index);
|
|
41
|
-
return array.slice(0, index).concat(elements).concat(array.slice(index));
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function removeFromArray(array, index) {
|
|
45
|
-
assertArrayBounds(array, index);
|
|
46
|
-
return [...array.slice(0, index), ...array.slice(index + 1)];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function replaceInArray(array, index, elements) {
|
|
50
|
-
assertArrayBounds(array, index);
|
|
51
|
-
return array.slice(0, index).concat(elements).concat(array.slice(index + 1));
|
|
52
|
-
}
|
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const stringWidth = require('string-width');
|
|
4
|
-
|
|
5
|
-
const getLast = require('../utils/get-last.js');
|
|
6
|
-
|
|
7
|
-
const notAsciiRegex = /[^\x20-\x7F]/;
|
|
8
|
-
|
|
9
|
-
function skip(chars) {
|
|
10
|
-
return (text, index, opts) => {
|
|
11
|
-
const backwards = opts && opts.backwards;
|
|
12
|
-
|
|
13
|
-
if (index === false) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const {
|
|
18
|
-
length
|
|
19
|
-
} = text;
|
|
20
|
-
let cursor = index;
|
|
21
|
-
|
|
22
|
-
while (cursor >= 0 && cursor < length) {
|
|
23
|
-
const c = text.charAt(cursor);
|
|
24
|
-
|
|
25
|
-
if (chars instanceof RegExp) {
|
|
26
|
-
if (!chars.test(c)) {
|
|
27
|
-
return cursor;
|
|
28
|
-
}
|
|
29
|
-
} else if (!chars.includes(c)) {
|
|
30
|
-
return cursor;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
backwards ? cursor-- : cursor++;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (cursor === -1 || cursor === length) {
|
|
37
|
-
return cursor;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return false;
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const skipWhitespace = skip(/\s/);
|
|
45
|
-
const skipSpaces = skip(' \t');
|
|
46
|
-
const skipToLineEnd = skip(',; \t');
|
|
47
|
-
const skipEverythingButNewLine = skip(/[^\n\r]/);
|
|
48
|
-
|
|
49
|
-
function skipInlineComment(text, index) {
|
|
50
|
-
if (index === false) {
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (text.charAt(index) === '/' && text.charAt(index + 1) === '*') {
|
|
55
|
-
for (let i = index + 2; i < text.length; ++i) {
|
|
56
|
-
if (text.charAt(i) === '*' && text.charAt(i + 1) === '/') {
|
|
57
|
-
return i + 2;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return index;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function skipTrailingComment(text, index) {
|
|
66
|
-
if (index === false) {
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (text.charAt(index) === '/' && text.charAt(index + 1) === '/') {
|
|
71
|
-
return skipEverythingButNewLine(text, index);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return index;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function skipNewline(text, index, opts) {
|
|
78
|
-
const backwards = opts && opts.backwards;
|
|
79
|
-
|
|
80
|
-
if (index === false) {
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const atIndex = text.charAt(index);
|
|
85
|
-
|
|
86
|
-
if (backwards) {
|
|
87
|
-
if (text.charAt(index - 1) === '\r' && atIndex === '\n') {
|
|
88
|
-
return index - 2;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (atIndex === '\n' || atIndex === '\r' || atIndex === '\u2028' || atIndex === '\u2029') {
|
|
92
|
-
return index - 1;
|
|
93
|
-
}
|
|
94
|
-
} else {
|
|
95
|
-
if (atIndex === '\r' && text.charAt(index + 1) === '\n') {
|
|
96
|
-
return index + 2;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (atIndex === '\n' || atIndex === '\r' || atIndex === '\u2028' || atIndex === '\u2029') {
|
|
100
|
-
return index + 1;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return index;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function hasNewline(text, index, opts = {}) {
|
|
108
|
-
const idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
|
|
109
|
-
const idx2 = skipNewline(text, idx, opts);
|
|
110
|
-
return idx !== idx2;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function hasNewlineInRange(text, start, end) {
|
|
114
|
-
for (let i = start; i < end; ++i) {
|
|
115
|
-
if (text.charAt(i) === '\n') {
|
|
116
|
-
return true;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function isNextLineEmptyAfterIndex(text, index) {
|
|
124
|
-
let oldIdx = null;
|
|
125
|
-
let idx = index;
|
|
126
|
-
|
|
127
|
-
while (idx !== oldIdx) {
|
|
128
|
-
oldIdx = idx;
|
|
129
|
-
idx = skipToLineEnd(text, idx);
|
|
130
|
-
idx = skipInlineComment(text, idx);
|
|
131
|
-
idx = skipSpaces(text, idx);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
idx = skipTrailingComment(text, idx);
|
|
135
|
-
idx = skipNewline(text, idx);
|
|
136
|
-
return idx !== false && hasNewline(text, idx);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, idx) {
|
|
140
|
-
let oldIdx = null;
|
|
141
|
-
let nextIdx = idx;
|
|
142
|
-
|
|
143
|
-
while (nextIdx !== oldIdx) {
|
|
144
|
-
oldIdx = nextIdx;
|
|
145
|
-
nextIdx = skipSpaces(text, nextIdx);
|
|
146
|
-
nextIdx = skipInlineComment(text, nextIdx);
|
|
147
|
-
nextIdx = skipTrailingComment(text, nextIdx);
|
|
148
|
-
nextIdx = skipNewline(text, nextIdx);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return nextIdx;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd) {
|
|
155
|
-
return getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, locEnd(node));
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function getNextNonSpaceNonCommentCharacter(text, node, locEnd) {
|
|
159
|
-
return text.charAt(getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd));
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function getStringWidth(text) {
|
|
163
|
-
if (!text) {
|
|
164
|
-
return 0;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (!notAsciiRegex.test(text)) {
|
|
168
|
-
return text.length;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
return stringWidth(text);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
function addCommentHelper(node, comment) {
|
|
175
|
-
const comments = node.comments || (node.comments = []);
|
|
176
|
-
comments.push(comment);
|
|
177
|
-
comment.printed = false;
|
|
178
|
-
comment.nodeDescription = describeNodeForDebugging(node);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function addLeadingComment(node, comment) {
|
|
182
|
-
comment.leading = true;
|
|
183
|
-
comment.trailing = false;
|
|
184
|
-
addCommentHelper(node, comment);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
function addDanglingComment(node, comment, marker) {
|
|
188
|
-
comment.leading = false;
|
|
189
|
-
comment.trailing = false;
|
|
190
|
-
|
|
191
|
-
if (marker) {
|
|
192
|
-
comment.marker = marker;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
addCommentHelper(node, comment);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
function addTrailingComment(node, comment) {
|
|
199
|
-
comment.leading = false;
|
|
200
|
-
comment.trailing = true;
|
|
201
|
-
addCommentHelper(node, comment);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
function isNonEmptyArray(object) {
|
|
205
|
-
return Array.isArray(object) && object.length > 0;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
function describeNodeForDebugging(node) {
|
|
209
|
-
const nodeType = node.type || node.kind || '(unknown type)';
|
|
210
|
-
let nodeName = String(node.name || node.id && (typeof node.id === 'object' ? node.id.name : node.id) || node.key && (typeof node.key === 'object' ? node.key.name : node.key) || node.value && (typeof node.value === 'object' ? '' : String(node.value)) || node.operator || '');
|
|
211
|
-
|
|
212
|
-
if (nodeName.length > 20) {
|
|
213
|
-
nodeName = nodeName.slice(0, 19) + '…';
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
return nodeType + (nodeName ? ' ' + nodeName : '');
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
module.exports = {
|
|
220
|
-
getStringWidth,
|
|
221
|
-
getLast,
|
|
222
|
-
getNextNonSpaceNonCommentCharacterIndexWithStartIndex,
|
|
223
|
-
getNextNonSpaceNonCommentCharacterIndex,
|
|
224
|
-
getNextNonSpaceNonCommentCharacter,
|
|
225
|
-
skipWhitespace,
|
|
226
|
-
skipSpaces,
|
|
227
|
-
skipNewline,
|
|
228
|
-
isNextLineEmptyAfterIndex,
|
|
229
|
-
hasNewline,
|
|
230
|
-
hasNewlineInRange,
|
|
231
|
-
addLeadingComment,
|
|
232
|
-
addDanglingComment,
|
|
233
|
-
addTrailingComment,
|
|
234
|
-
isNonEmptyArray
|
|
235
|
-
};
|