@react-native/codegen 0.74.0-nightly-20231107-bc68794c6 → 0.74.0-nightly-20231108-05d92bf2a
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/lib/parsers/flow/parseFlowAndThrowErrors.js +105 -0
- package/lib/parsers/flow/parseFlowAndThrowErrors.js.flow +41 -0
- package/lib/parsers/flow/parser.js +5 -5
- package/lib/parsers/flow/parser.js.flow +3 -6
- package/lib/parsers/parser.js.flow +3 -1
- package/lib/parsers/parserMock.js +9 -9
- package/lib/parsers/parserMock.js.flow +3 -6
- package/lib/parsers/parsers-commons.js +1 -1
- package/lib/parsers/parsers-commons.js.flow +1 -1
- package/lib/parsers/typescript/parser.js +1 -1
- package/lib/parsers/typescript/parser.js.flow +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
function ownKeys(object, enumerableOnly) {
|
|
14
|
+
var keys = Object.keys(object);
|
|
15
|
+
if (Object.getOwnPropertySymbols) {
|
|
16
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
17
|
+
enumerableOnly &&
|
|
18
|
+
(symbols = symbols.filter(function (sym) {
|
|
19
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
20
|
+
})),
|
|
21
|
+
keys.push.apply(keys, symbols);
|
|
22
|
+
}
|
|
23
|
+
return keys;
|
|
24
|
+
}
|
|
25
|
+
function _objectSpread(target) {
|
|
26
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
27
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
|
28
|
+
i % 2
|
|
29
|
+
? ownKeys(Object(source), !0).forEach(function (key) {
|
|
30
|
+
_defineProperty(target, key, source[key]);
|
|
31
|
+
})
|
|
32
|
+
: Object.getOwnPropertyDescriptors
|
|
33
|
+
? Object.defineProperties(
|
|
34
|
+
target,
|
|
35
|
+
Object.getOwnPropertyDescriptors(source),
|
|
36
|
+
)
|
|
37
|
+
: ownKeys(Object(source)).forEach(function (key) {
|
|
38
|
+
Object.defineProperty(
|
|
39
|
+
target,
|
|
40
|
+
key,
|
|
41
|
+
Object.getOwnPropertyDescriptor(source, key),
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return target;
|
|
46
|
+
}
|
|
47
|
+
function _defineProperty(obj, key, value) {
|
|
48
|
+
key = _toPropertyKey(key);
|
|
49
|
+
if (key in obj) {
|
|
50
|
+
Object.defineProperty(obj, key, {
|
|
51
|
+
value: value,
|
|
52
|
+
enumerable: true,
|
|
53
|
+
configurable: true,
|
|
54
|
+
writable: true,
|
|
55
|
+
});
|
|
56
|
+
} else {
|
|
57
|
+
obj[key] = value;
|
|
58
|
+
}
|
|
59
|
+
return obj;
|
|
60
|
+
}
|
|
61
|
+
function _toPropertyKey(arg) {
|
|
62
|
+
var key = _toPrimitive(arg, 'string');
|
|
63
|
+
return typeof key === 'symbol' ? key : String(key);
|
|
64
|
+
}
|
|
65
|
+
function _toPrimitive(input, hint) {
|
|
66
|
+
if (typeof input !== 'object' || input === null) return input;
|
|
67
|
+
var prim = input[Symbol.toPrimitive];
|
|
68
|
+
if (prim !== undefined) {
|
|
69
|
+
var res = prim.call(input, hint || 'default');
|
|
70
|
+
if (typeof res !== 'object') return res;
|
|
71
|
+
throw new TypeError('@@toPrimitive must return a primitive value.');
|
|
72
|
+
}
|
|
73
|
+
return (hint === 'string' ? String : Number)(input);
|
|
74
|
+
}
|
|
75
|
+
const hermesParser = require('hermes-parser');
|
|
76
|
+
function parseFlowAndThrowErrors(code, options = {}) {
|
|
77
|
+
let ast;
|
|
78
|
+
try {
|
|
79
|
+
ast = hermesParser.parse(
|
|
80
|
+
code,
|
|
81
|
+
_objectSpread(
|
|
82
|
+
{
|
|
83
|
+
// Produce an ESTree-compliant AST
|
|
84
|
+
babel: false,
|
|
85
|
+
// Parse Flow without a pragma
|
|
86
|
+
flow: 'all',
|
|
87
|
+
},
|
|
88
|
+
options.filename != null
|
|
89
|
+
? {
|
|
90
|
+
sourceFilename: options.filename,
|
|
91
|
+
}
|
|
92
|
+
: {},
|
|
93
|
+
),
|
|
94
|
+
);
|
|
95
|
+
} catch (e) {
|
|
96
|
+
if (options.filename != null) {
|
|
97
|
+
e.message = `Syntax error in ${options.filename}: ${e.message}`;
|
|
98
|
+
}
|
|
99
|
+
throw e;
|
|
100
|
+
}
|
|
101
|
+
return ast;
|
|
102
|
+
}
|
|
103
|
+
module.exports = {
|
|
104
|
+
parseFlowAndThrowErrors,
|
|
105
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
import type {Program as ESTreeProgram} from 'hermes-estree';
|
|
14
|
+
|
|
15
|
+
const hermesParser = require('hermes-parser');
|
|
16
|
+
|
|
17
|
+
function parseFlowAndThrowErrors(
|
|
18
|
+
code: string,
|
|
19
|
+
options: $ReadOnly<{filename?: ?string}> = {},
|
|
20
|
+
): ESTreeProgram {
|
|
21
|
+
let ast;
|
|
22
|
+
try {
|
|
23
|
+
ast = hermesParser.parse(code, {
|
|
24
|
+
// Produce an ESTree-compliant AST
|
|
25
|
+
babel: false,
|
|
26
|
+
// Parse Flow without a pragma
|
|
27
|
+
flow: 'all',
|
|
28
|
+
...(options.filename != null ? {sourceFilename: options.filename} : {}),
|
|
29
|
+
});
|
|
30
|
+
} catch (e) {
|
|
31
|
+
if (options.filename != null) {
|
|
32
|
+
e.message = `Syntax error in ${options.filename}: ${e.message}`;
|
|
33
|
+
}
|
|
34
|
+
throw e;
|
|
35
|
+
}
|
|
36
|
+
return ast;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
module.exports = {
|
|
40
|
+
parseFlowAndThrowErrors,
|
|
41
|
+
};
|
|
@@ -58,8 +58,8 @@ const _require6 = require('./components/componentsUtils'),
|
|
|
58
58
|
getTypeAnnotation = _require6.getTypeAnnotation;
|
|
59
59
|
const _require7 = require('./modules'),
|
|
60
60
|
flowTranslateTypeAnnotation = _require7.flowTranslateTypeAnnotation;
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
const _require8 = require('./parseFlowAndThrowErrors'),
|
|
62
|
+
parseFlowAndThrowErrors = _require8.parseFlowAndThrowErrors;
|
|
63
63
|
const fs = require('fs');
|
|
64
64
|
const invariant = require('invariant');
|
|
65
65
|
class FlowParser {
|
|
@@ -145,9 +145,9 @@ class FlowParser {
|
|
|
145
145
|
const contents = fs.readFileSync(filename, 'utf8');
|
|
146
146
|
return this.parseString(contents, 'path/NativeSampleTurboModule.js');
|
|
147
147
|
}
|
|
148
|
-
getAst(contents) {
|
|
149
|
-
return
|
|
150
|
-
|
|
148
|
+
getAst(contents, filename) {
|
|
149
|
+
return parseFlowAndThrowErrors(contents, {
|
|
150
|
+
filename,
|
|
151
151
|
});
|
|
152
152
|
}
|
|
153
153
|
getFunctionTypeAnnotationParameters(functionTypeAnnotation) {
|
|
@@ -55,8 +55,7 @@ const {
|
|
|
55
55
|
getTypeAnnotation,
|
|
56
56
|
} = require('./components/componentsUtils');
|
|
57
57
|
const {flowTranslateTypeAnnotation} = require('./modules');
|
|
58
|
-
|
|
59
|
-
const flowParser = require('flow-parser');
|
|
58
|
+
const {parseFlowAndThrowErrors} = require('./parseFlowAndThrowErrors');
|
|
60
59
|
const fs = require('fs');
|
|
61
60
|
const invariant = require('invariant');
|
|
62
61
|
|
|
@@ -143,10 +142,8 @@ class FlowParser implements Parser {
|
|
|
143
142
|
return this.parseString(contents, 'path/NativeSampleTurboModule.js');
|
|
144
143
|
}
|
|
145
144
|
|
|
146
|
-
getAst(contents: string): $FlowFixMe {
|
|
147
|
-
return
|
|
148
|
-
enums: true,
|
|
149
|
-
});
|
|
145
|
+
getAst(contents: string, filename?: ?string): $FlowFixMe {
|
|
146
|
+
return parseFlowAndThrowErrors(contents, {filename});
|
|
150
147
|
}
|
|
151
148
|
|
|
152
149
|
getFunctionTypeAnnotationParameters(
|
|
@@ -169,9 +169,11 @@ export interface Parser {
|
|
|
169
169
|
/**
|
|
170
170
|
* Given the content of a file, it returns an AST.
|
|
171
171
|
* @parameter contents: the content of the file.
|
|
172
|
+
* @parameter filename: the name of the file, if available.
|
|
173
|
+
* @throws if there is a syntax error.
|
|
172
174
|
* @returns: the AST of the file.
|
|
173
175
|
*/
|
|
174
|
-
getAst(contents: string): $FlowFixMe;
|
|
176
|
+
getAst(contents: string, filename?: ?string): $FlowFixMe;
|
|
175
177
|
|
|
176
178
|
/**
|
|
177
179
|
* Given a FunctionTypeAnnotation, it returns an array of its parameters.
|
|
@@ -42,12 +42,12 @@ import invariant from 'invariant';
|
|
|
42
42
|
const _require = require('./errors'),
|
|
43
43
|
UnsupportedObjectPropertyTypeAnnotationParserError =
|
|
44
44
|
_require.UnsupportedObjectPropertyTypeAnnotationParserError;
|
|
45
|
-
const _require2 = require('./
|
|
46
|
-
|
|
47
|
-
const _require3 = require('./
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
const _require2 = require('./flow/parseFlowAndThrowErrors'),
|
|
46
|
+
parseFlowAndThrowErrors = _require2.parseFlowAndThrowErrors;
|
|
47
|
+
const _require3 = require('./parsers-commons'),
|
|
48
|
+
buildPropSchema = _require3.buildPropSchema;
|
|
49
|
+
const _require4 = require('./typescript/components/componentsUtils'),
|
|
50
|
+
flattenProperties = _require4.flattenProperties;
|
|
51
51
|
const schemaMock = {
|
|
52
52
|
modules: {
|
|
53
53
|
StringPropNativeComponentView: {
|
|
@@ -125,9 +125,9 @@ export class MockedParser {
|
|
|
125
125
|
parseModuleFixture(filename) {
|
|
126
126
|
return schemaMock;
|
|
127
127
|
}
|
|
128
|
-
getAst(contents) {
|
|
129
|
-
return
|
|
130
|
-
|
|
128
|
+
getAst(contents, filename) {
|
|
129
|
+
return parseFlowAndThrowErrors(contents, {
|
|
130
|
+
filename,
|
|
131
131
|
});
|
|
132
132
|
}
|
|
133
133
|
getFunctionTypeAnnotationParameters(functionTypeAnnotation) {
|
|
@@ -42,10 +42,9 @@ import invariant from 'invariant';
|
|
|
42
42
|
const {
|
|
43
43
|
UnsupportedObjectPropertyTypeAnnotationParserError,
|
|
44
44
|
} = require('./errors');
|
|
45
|
+
const {parseFlowAndThrowErrors} = require('./flow/parseFlowAndThrowErrors');
|
|
45
46
|
const {buildPropSchema} = require('./parsers-commons');
|
|
46
47
|
const {flattenProperties} = require('./typescript/components/componentsUtils');
|
|
47
|
-
// $FlowFixMe[untyped-import] there's no flowtype flow-parser
|
|
48
|
-
const flowParser = require('flow-parser');
|
|
49
48
|
|
|
50
49
|
type ExtendsForProp = null | {
|
|
51
50
|
type: 'ReactNativeBuiltInType',
|
|
@@ -122,10 +121,8 @@ export class MockedParser implements Parser {
|
|
|
122
121
|
return schemaMock;
|
|
123
122
|
}
|
|
124
123
|
|
|
125
|
-
getAst(contents: string): $FlowFixMe {
|
|
126
|
-
return
|
|
127
|
-
enums: true,
|
|
128
|
-
});
|
|
124
|
+
getAst(contents: string, filename?: ?string): $FlowFixMe {
|
|
125
|
+
return parseFlowAndThrowErrors(contents, {filename});
|
|
129
126
|
}
|
|
130
127
|
|
|
131
128
|
getFunctionTypeAnnotationParameters(
|
|
@@ -147,7 +147,7 @@ class TypeScriptParser {
|
|
|
147
147
|
const contents = fs.readFileSync(filename, 'utf8');
|
|
148
148
|
return this.parseString(contents, 'path/NativeSampleTurboModule.ts');
|
|
149
149
|
}
|
|
150
|
-
getAst(contents) {
|
|
150
|
+
getAst(contents, filename) {
|
|
151
151
|
return babelParser.parse(contents, {
|
|
152
152
|
sourceType: 'module',
|
|
153
153
|
plugins: ['typescript'],
|
|
@@ -142,7 +142,7 @@ class TypeScriptParser implements Parser {
|
|
|
142
142
|
return this.parseString(contents, 'path/NativeSampleTurboModule.ts');
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
getAst(contents: string): $FlowFixMe {
|
|
145
|
+
getAst(contents: string, filename?: ?string): $FlowFixMe {
|
|
146
146
|
return babelParser.parse(contents, {
|
|
147
147
|
sourceType: 'module',
|
|
148
148
|
plugins: ['typescript'],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-native/codegen",
|
|
3
|
-
"version": "0.74.0-nightly-
|
|
3
|
+
"version": "0.74.0-nightly-20231108-05d92bf2a",
|
|
4
4
|
"description": "Code generation tools for React Native",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@babel/parser": "^7.20.0",
|
|
33
|
-
"
|
|
33
|
+
"hermes-parser": "0.17.1",
|
|
34
34
|
"jscodeshift": "^0.14.0",
|
|
35
35
|
"nullthrows": "^1.1.1"
|
|
36
36
|
},
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"@babel/preset-env": "^7.20.0",
|
|
48
48
|
"chalk": "^4.0.0",
|
|
49
49
|
"glob": "^7.1.1",
|
|
50
|
+
"hermes-estree": "0.17.1",
|
|
50
51
|
"invariant": "^2.2.4",
|
|
51
52
|
"micromatch": "^4.0.4",
|
|
52
53
|
"mkdirp": "^0.5.1",
|