react-native-tscodegen
Advanced tools
Comparing version 0.71.1 to 0.72.0
@@ -5,3 +5,17 @@ { | ||
{ | ||
"date": "Wed, 30 Nov 2022 20:39:41 GMT", | ||
"date": "Tue, 13 Dec 2022 22:32:22 GMT", | ||
"tag": "react-native-tscodegen_v0.72.0", | ||
"version": "0.72.0", | ||
"comments": { | ||
"minor": [ | ||
{ | ||
"comment": "Catch up facebook/react-native/packages/react-native-codegen on 2022-12-13", | ||
"author": "53799235+ZihanChen-MSFT@users.noreply.github.com", | ||
"commit": "0957c81dab95936028784aeabd6100d78d34c296" | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"date": "Wed, 30 Nov 2022 20:39:50 GMT", | ||
"tag": "react-native-tscodegen_v0.71.1", | ||
@@ -8,0 +22,0 @@ "version": "0.71.1", |
# Change Log - react-native-tscodegen | ||
This log was last generated on Wed, 30 Nov 2022 20:39:41 GMT and should not be manually modified. | ||
This log was last generated on Tue, 13 Dec 2022 22:32:22 GMT and should not be manually modified. | ||
## 0.72.0 | ||
Tue, 13 Dec 2022 22:32:22 GMT | ||
### Minor changes | ||
- Catch up facebook/react-native/packages/react-native-codegen on 2022-12-13 (53799235+ZihanChen-MSFT@users.noreply.github.com) | ||
## 0.71.1 | ||
Wed, 30 Nov 2022 20:39:41 GMT | ||
Wed, 30 Nov 2022 20:39:50 GMT | ||
@@ -8,0 +14,0 @@ ### Patches |
@@ -129,3 +129,3 @@ export declare type PlatformType = 'iOS' | 'android'; | ||
readonly spec: NativeModuleSpec; | ||
readonly moduleNames: readonly string[]; | ||
readonly moduleName: string; | ||
readonly excludedPlatforms?: readonly PlatformType[]; | ||
@@ -177,2 +177,3 @@ } | ||
readonly type: 'PromiseTypeAnnotation'; | ||
readonly elementType?: Nullable<NativeModuleBaseTypeAnnotation>; | ||
} | ||
@@ -179,0 +180,0 @@ export declare type UnionTypeAnnotationMemberType = 'NumberTypeAnnotation' | 'ObjectTypeAnnotation' | 'StringTypeAnnotation'; |
@@ -63,3 +63,3 @@ /** | ||
}, | ||
moduleNames: ['Calculator'] | ||
moduleName: 'Calculator' | ||
} | ||
@@ -66,0 +66,0 @@ } |
@@ -180,7 +180,7 @@ /** | ||
case 'PointPrimitive': | ||
imports.add('#include <react/renderer/graphics/Geometry.h>'); | ||
imports.add('#include <react/renderer/graphics/Point.h>'); | ||
return; | ||
case 'EdgeInsetsPrimitive': | ||
imports.add('#include <react/renderer/graphics/Geometry.h>'); | ||
imports.add('#include <react/renderer/graphics/RectangleEdges.h>'); | ||
return; | ||
@@ -187,0 +187,0 @@ |
@@ -217,3 +217,3 @@ /** | ||
properties = nativeModule.spec.properties, | ||
moduleNames = nativeModule.moduleNames; | ||
moduleName = nativeModule.moduleName; | ||
const resolveAlias = createAliasResolver(aliases); | ||
@@ -224,4 +224,3 @@ const hostFunctions = properties.map(property => serializePropertyIntoHostFunction(hasteModuleName, property, resolveAlias)); | ||
hostFunctions, | ||
// TODO: What happens when there are more than one NativeModule requires? | ||
moduleName: moduleNames[0], | ||
moduleName, | ||
methods: properties.map(({ | ||
@@ -228,0 +227,0 @@ name: propertyName, |
@@ -294,5 +294,3 @@ /** | ||
properties = _nativeModules$hasteM.spec.properties, | ||
_nativeModules$hasteM2 = _slicedToArray(_nativeModules$hasteM.moduleNames, 1), | ||
moduleName = _nativeModules$hasteM2[0]; | ||
moduleName = _nativeModules$hasteM.moduleName; | ||
const resolveAlias = createAliasResolver(aliases); | ||
@@ -299,0 +297,0 @@ const structs = createStructs(moduleName, aliases, resolveAlias); |
@@ -30,2 +30,3 @@ /** | ||
className = config.className, | ||
jsName = config.jsName, | ||
methods = config.methods, | ||
@@ -50,2 +51,4 @@ imports = config.imports; | ||
public abstract class ${className} extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule { | ||
public static final String NAME = "${jsName}"; | ||
public ${className}(ReactApplicationContext reactContext) { | ||
@@ -55,2 +58,7 @@ super(reactContext); | ||
@Override | ||
public @Nonnull String getName() { | ||
return NAME; | ||
} | ||
${methods} | ||
@@ -450,2 +458,3 @@ } | ||
excludedPlatforms = _nativeModules$hasteM.excludedPlatforms, | ||
moduleName = _nativeModules$hasteM.moduleName, | ||
properties = _nativeModules$hasteM.spec.properties; | ||
@@ -460,3 +469,3 @@ | ||
const imports = new Set([// Always required. | ||
'com.facebook.react.bridge.ReactApplicationContext', 'com.facebook.react.bridge.ReactContextBaseJavaModule', 'com.facebook.react.bridge.ReactMethod', 'com.facebook.react.bridge.ReactModuleWithSpec', 'com.facebook.react.turbomodule.core.interfaces.TurboModule', 'com.facebook.proguard.annotations.DoNotStrip']); | ||
'com.facebook.react.bridge.ReactApplicationContext', 'com.facebook.react.bridge.ReactContextBaseJavaModule', 'com.facebook.react.bridge.ReactMethod', 'com.facebook.react.bridge.ReactModuleWithSpec', 'com.facebook.react.turbomodule.core.interfaces.TurboModule', 'com.facebook.proguard.annotations.DoNotStrip', 'javax.annotation.Nonnull']); | ||
const methods = properties.map(method => { | ||
@@ -501,2 +510,3 @@ if (method.name === 'getConstants') { | ||
className, | ||
jsName: moduleName, | ||
methods: methods.filter(Boolean).join('\n\n'), | ||
@@ -503,0 +513,0 @@ imports: Array.from(imports).sort().map(p => `import ${p};`).join('\n') |
@@ -451,4 +451,3 @@ /** | ||
}); | ||
}).join('\n'); // $FlowFixMe[missing-type-arg] | ||
}).join('\n'); | ||
const moduleLookups = Object.keys(nativeModules).filter(hasteModuleName => { | ||
@@ -458,6 +457,4 @@ const module = nativeModules[hasteModuleName]; | ||
}).sort((a, b) => { | ||
const moduleA = nativeModules[a]; | ||
const moduleB = nativeModules[b]; | ||
const nameA = moduleA.moduleNames[0]; | ||
const nameB = moduleB.moduleNames[0]; | ||
const nameA = nativeModules[a].moduleName; | ||
const nameB = nativeModules[b].moduleName; | ||
@@ -471,9 +468,6 @@ if (nameA < nameB) { | ||
return 0; | ||
}).flatMap(hasteModuleName => { | ||
const moduleNames = nativeModules[hasteModuleName].moduleNames; | ||
return moduleNames.map(moduleName => ({ | ||
moduleName, | ||
hasteModuleName | ||
})); | ||
}); | ||
}).map(hasteModuleName => ({ | ||
moduleName: nativeModules[hasteModuleName].moduleName, | ||
hasteModuleName | ||
})); | ||
const fileName = `${libraryName}-generated.cpp`; | ||
@@ -480,0 +474,0 @@ const replacedTemplate = FileTemplate({ |
@@ -59,50 +59,2 @@ /** | ||
`; | ||
}; // Note: this Android.mk template includes dependencies for both NativeModule and components. | ||
const AndroidMkTemplate = ({ | ||
libraryName | ||
}) => { | ||
return `# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
LOCAL_PATH := $(call my-dir) | ||
include $(CLEAR_VARS) | ||
LOCAL_MODULE := react_codegen_${libraryName} | ||
LOCAL_C_INCLUDES := $(LOCAL_PATH) | ||
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) $(wildcard $(LOCAL_PATH)/react/renderer/components/${libraryName}/*.cpp) | ||
LOCAL_SRC_FILES := $(subst $(LOCAL_PATH)/,,$(LOCAL_SRC_FILES)) | ||
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) $(LOCAL_PATH)/react/renderer/components/${libraryName} | ||
LOCAL_SHARED_LIBRARIES := libfbjni \ | ||
libfolly_runtime \ | ||
libglog \ | ||
libjsi \ | ||
libreact_codegen_rncore \ | ||
libreact_debug \ | ||
libreact_nativemodule_core \ | ||
libreact_render_core \ | ||
libreact_render_debug \ | ||
libreact_render_graphics \ | ||
libreact_render_imagemanager \ | ||
libreact_render_mapbuffer \ | ||
librrc_image \ | ||
librrc_view \ | ||
libturbomodulejsijni \ | ||
libyoga | ||
LOCAL_CFLAGS := \\ | ||
-DLOG_TAG=\\"ReactNative\\" | ||
LOCAL_CFLAGS += -fexceptions -frtti -std=c++17 -Wall | ||
include $(BUILD_SHARED_LIBRARY) | ||
`; | ||
}; // Note: this CMakeLists.txt template includes dependencies for both NativeModule and components. | ||
@@ -177,6 +129,4 @@ | ||
}); | ||
return new Map([[`jni/${fileName}`, replacedTemplate], ['jni/Android.mk', AndroidMkTemplate({ | ||
return new Map([[`jni/${fileName}`, replacedTemplate], ['jni/CMakeLists.txt', CMakeListsTemplate({ | ||
libraryName: libraryName | ||
})], ['jni/CMakeLists.txt', CMakeListsTemplate({ | ||
libraryName: libraryName | ||
})]]); | ||
@@ -183,0 +133,0 @@ } |
@@ -24,3 +24,4 @@ /** | ||
throwIfUntypedModule = _require.throwIfUntypedModule, | ||
throwIfUnsupportedFunctionParamTypeAnnotationParserError = _require.throwIfUnsupportedFunctionParamTypeAnnotationParserError; | ||
throwIfUnsupportedFunctionParamTypeAnnotationParserError = _require.throwIfUnsupportedFunctionParamTypeAnnotationParserError, | ||
throwIfArrayElementTypeAnnotationIsUnsupported = _require.throwIfArrayElementTypeAnnotationIsUnsupported; | ||
@@ -443,2 +444,29 @@ const _require2 = require('../errors'), | ||
}); | ||
}); | ||
describe('throwIfArrayElementTypeAnnotationIsUnsupported', () => { | ||
const _require5 = require('../errors.js'), | ||
UnsupportedArrayElementTypeAnnotationParserError = _require5.UnsupportedArrayElementTypeAnnotationParserError; | ||
const moduleName = 'moduleName'; | ||
const language = 'Flow'; | ||
it('throws the error if it is the type is void type annotation', () => { | ||
expect(() => { | ||
throwIfArrayElementTypeAnnotationIsUnsupported(moduleName, undefined, 'Array', 'VoidTypeAnnotation', language); | ||
}).toThrow(UnsupportedArrayElementTypeAnnotationParserError); | ||
}); | ||
it('throws the error if it is the type is promise type annotation', () => { | ||
expect(() => { | ||
throwIfArrayElementTypeAnnotationIsUnsupported(moduleName, undefined, 'Array', 'PromiseTypeAnnotation', language); | ||
}).toThrow(UnsupportedArrayElementTypeAnnotationParserError); | ||
}); | ||
it('throws the error if it is the type is function type annotation', () => { | ||
expect(() => { | ||
throwIfArrayElementTypeAnnotationIsUnsupported(moduleName, undefined, 'Array', 'FunctionTypeAnnotation', language); | ||
}).toThrow(UnsupportedArrayElementTypeAnnotationParserError); | ||
}); | ||
it('does not throw the error if the type is NativeModuleTypeAnnotation', () => { | ||
expect(() => { | ||
throwIfArrayElementTypeAnnotationIsUnsupported(moduleName, undefined, 'Array', 'StringTypeAnnotation', language); | ||
}).not.toThrow(UnsupportedArrayElementTypeAnnotationParserError); | ||
}); | ||
}); |
@@ -19,6 +19,5 @@ /** | ||
import { assertGenericTypeAnnotationHasExactlyOneTypeParameter, isObjectProperty, parseObjectProperty, wrapNullable, unwrapNullable, emitUnionTypeAnnotation } from '../parsers-commons'; | ||
import { assertGenericTypeAnnotationHasExactlyOneTypeParameter, isObjectProperty, parseObjectProperty, wrapNullable, unwrapNullable } from '../parsers-commons'; | ||
const _require = require('../errors'), | ||
UnsupportedUnionTypeAnnotationParserError = _require.UnsupportedUnionTypeAnnotationParserError, | ||
UnsupportedObjectPropertyTypeAnnotationParserError = _require.UnsupportedObjectPropertyTypeAnnotationParserError; | ||
@@ -28,5 +27,3 @@ | ||
import { TypeScriptParser } from '../typescript/parser'; | ||
import { FlowParser } from '../flow/parser'; | ||
const parser = new MockedParser(); | ||
const flowParser = new FlowParser(); | ||
const typeScriptParser = new TypeScriptParser(); | ||
@@ -68,2 +65,3 @@ | ||
it('returns original type annotation', () => { | ||
// $FlowFixMe[incompatible-call] | ||
const result = unwrapNullable({ | ||
@@ -165,10 +163,4 @@ type: 'NullableTypeAnnotation', | ||
}); | ||
it("returns 'true' if 'property.type' is 'ObjectTypeIndexer'", () => { | ||
it("returns 'false' if 'property.type' is not 'ObjectTypeProperty'", () => { | ||
const result = isObjectProperty(_objectSpread({ | ||
type: 'ObjectTypeIndexer' | ||
}, propertyStub), language); | ||
expect(result).toEqual(true); | ||
}); | ||
it("returns 'false' if 'property.type' is not 'ObjectTypeProperty' or 'ObjectTypeIndexer'", () => { | ||
const result = isObjectProperty(_objectSpread({ | ||
type: 'notObjectTypeProperty' | ||
@@ -187,10 +179,4 @@ }, propertyStub), language); | ||
}); | ||
it("returns 'true' if 'property.type' is 'TSIndexSignature'", () => { | ||
it("returns 'false' if 'property.type' is not 'TSPropertySignature'", () => { | ||
const result = isObjectProperty(_objectSpread({ | ||
type: 'TSIndexSignature' | ||
}, propertyStub), language); | ||
expect(result).toEqual(true); | ||
}); | ||
it("returns 'false' if 'property.type' is not 'TSPropertySignature' or 'TSIndexSignature'", () => { | ||
const result = isObjectProperty(_objectSpread({ | ||
type: 'notTSPropertySignature' | ||
@@ -215,3 +201,3 @@ }, propertyStub), language); | ||
const language = 'Flow'; | ||
it("throws an 'UnsupportedObjectPropertyTypeAnnotationParserError' error if 'property.type' is not 'ObjectTypeProperty' or 'ObjectTypeIndexer'.", () => { | ||
it("throws an 'UnsupportedObjectPropertyTypeAnnotationParserError' error if 'property.type' is not 'ObjectTypeProperty'.", () => { | ||
const property = { | ||
@@ -232,3 +218,3 @@ type: 'notObjectTypeProperty', | ||
const language = 'TypeScript'; | ||
it("throws an 'UnsupportedObjectPropertyTypeAnnotationParserError' error if 'property.type' is not 'TSPropertySignature' or 'TSIndexSignature'.", () => { | ||
it("throws an 'UnsupportedObjectPropertyTypeAnnotationParserError' error if 'property.type' is not 'TSPropertySignature'.", () => { | ||
const property = { | ||
@@ -245,310 +231,3 @@ type: 'notTSPropertySignature', | ||
}); | ||
it("returns a 'NativeModuleBaseTypeAnnotation' object with 'typeAnnotation.type' equal to 'GenericObjectTypeAnnotation', if 'property.type' is 'TSIndexSignature'.", () => { | ||
const property = { | ||
type: 'TSIndexSignature', | ||
typeAnnotation: { | ||
type: 'TSIndexSignature', | ||
typeAnnotation: 'TSIndexSignature' | ||
}, | ||
key: { | ||
name: 'testKeyName' | ||
}, | ||
value: 'wrongValue', | ||
name: 'wrongName', | ||
parameters: [{ | ||
name: 'testName' | ||
}] | ||
}; | ||
const result = parseObjectProperty(property, moduleName, types, aliasMap, tryParse, cxxOnly, nullable, typeScriptTranslateTypeAnnotation, typeScriptParser); | ||
const expected = { | ||
name: 'testName', | ||
optional: false, | ||
typeAnnotation: wrapNullable(nullable, { | ||
type: 'GenericObjectTypeAnnotation' | ||
}) | ||
}; | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
}); | ||
describe('emitUnionTypeAnnotation', () => { | ||
const hasteModuleName = 'SampleTurboModule'; | ||
describe('when language is flow', () => { | ||
describe('when members type is numeric', () => { | ||
const typeAnnotation = { | ||
type: 'UnionTypeAnnotation', | ||
types: [{ | ||
type: 'NumberLiteralTypeAnnotation' | ||
}, { | ||
type: 'NumberLiteralTypeAnnotation' | ||
}] | ||
}; | ||
describe('when nullable is true', () => { | ||
it('returns nullable type annotation', () => { | ||
const result = emitUnionTypeAnnotation(true, hasteModuleName, typeAnnotation, flowParser); | ||
const expected = { | ||
type: 'NullableTypeAnnotation', | ||
typeAnnotation: { | ||
type: 'UnionTypeAnnotation', | ||
memberType: 'NumberTypeAnnotation' | ||
} | ||
}; | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
describe('when nullable is false', () => { | ||
it('returns non nullable type annotation', () => { | ||
const result = emitUnionTypeAnnotation(false, hasteModuleName, typeAnnotation, flowParser); | ||
const expected = { | ||
type: 'UnionTypeAnnotation', | ||
memberType: 'NumberTypeAnnotation' | ||
}; | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
}); | ||
describe('when members type is string', () => { | ||
const typeAnnotation = { | ||
type: 'UnionTypeAnnotation', | ||
types: [{ | ||
type: 'StringLiteralTypeAnnotation' | ||
}, { | ||
type: 'StringLiteralTypeAnnotation' | ||
}] | ||
}; | ||
describe('when nullable is true', () => { | ||
it('returns nullable type annotation', () => { | ||
const result = emitUnionTypeAnnotation(true, hasteModuleName, typeAnnotation, flowParser); | ||
const expected = { | ||
type: 'NullableTypeAnnotation', | ||
typeAnnotation: { | ||
type: 'UnionTypeAnnotation', | ||
memberType: 'StringTypeAnnotation' | ||
} | ||
}; | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
describe('when nullable is false', () => { | ||
it('returns non nullable type annotation', () => { | ||
const result = emitUnionTypeAnnotation(false, hasteModuleName, typeAnnotation, flowParser); | ||
const expected = { | ||
type: 'UnionTypeAnnotation', | ||
memberType: 'StringTypeAnnotation' | ||
}; | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
}); | ||
describe('when members type is object', () => { | ||
const typeAnnotation = { | ||
type: 'UnionTypeAnnotation', | ||
types: [{ | ||
type: 'ObjectTypeAnnotation' | ||
}, { | ||
type: 'ObjectTypeAnnotation' | ||
}] | ||
}; | ||
describe('when nullable is true', () => { | ||
it('returns nullable type annotation', () => { | ||
const result = emitUnionTypeAnnotation(true, hasteModuleName, typeAnnotation, flowParser); | ||
const expected = { | ||
type: 'NullableTypeAnnotation', | ||
typeAnnotation: { | ||
type: 'UnionTypeAnnotation', | ||
memberType: 'ObjectTypeAnnotation' | ||
} | ||
}; | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
describe('when nullable is false', () => { | ||
it('returns non nullable type annotation', () => { | ||
const result = emitUnionTypeAnnotation(false, hasteModuleName, typeAnnotation, flowParser); | ||
const expected = { | ||
type: 'UnionTypeAnnotation', | ||
memberType: 'ObjectTypeAnnotation' | ||
}; | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
}); | ||
describe('when members type is mixed', () => { | ||
const typeAnnotation = { | ||
type: 'UnionTypeAnnotation', | ||
types: [{ | ||
type: 'NumberLiteralTypeAnnotation' | ||
}, { | ||
type: 'StringLiteralTypeAnnotation' | ||
}, { | ||
type: 'ObjectTypeAnnotation' | ||
}] | ||
}; | ||
const unionTypes = ['NumberTypeAnnotation', 'StringTypeAnnotation', 'ObjectTypeAnnotation']; | ||
describe('when nullable is true', () => { | ||
it('throws an excpetion', () => { | ||
const expected = new UnsupportedUnionTypeAnnotationParserError(hasteModuleName, typeAnnotation, unionTypes, flowParser.language()); | ||
expect(() => { | ||
emitUnionTypeAnnotation(true, hasteModuleName, typeAnnotation, flowParser); | ||
}).toThrow(expected); | ||
}); | ||
}); | ||
describe('when nullable is false', () => { | ||
it('throws an excpetion', () => { | ||
const expected = new UnsupportedUnionTypeAnnotationParserError(hasteModuleName, typeAnnotation, unionTypes, flowParser.language()); | ||
expect(() => { | ||
emitUnionTypeAnnotation(false, hasteModuleName, typeAnnotation, flowParser); | ||
}).toThrow(expected); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('when language is typescript', () => { | ||
describe('when members type is numeric', () => { | ||
const typeAnnotation = { | ||
type: 'TSUnionType', | ||
types: [{ | ||
type: 'TSLiteralType', | ||
literal: { | ||
type: 'NumericLiteral' | ||
} | ||
}, { | ||
type: 'TSLiteralType', | ||
literal: { | ||
type: 'NumericLiteral' | ||
} | ||
}] | ||
}; | ||
describe('when nullable is true', () => { | ||
it('returns nullable type annotation', () => { | ||
const result = emitUnionTypeAnnotation(true, hasteModuleName, typeAnnotation, typeScriptParser); | ||
const expected = { | ||
type: 'NullableTypeAnnotation', | ||
typeAnnotation: { | ||
type: 'UnionTypeAnnotation', | ||
memberType: 'NumberTypeAnnotation' | ||
} | ||
}; | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
describe('when nullable is false', () => { | ||
it('returns non nullable type annotation', () => { | ||
const result = emitUnionTypeAnnotation(false, hasteModuleName, typeAnnotation, typeScriptParser); | ||
const expected = { | ||
type: 'UnionTypeAnnotation', | ||
memberType: 'NumberTypeAnnotation' | ||
}; | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
}); | ||
describe('when members type is string', () => { | ||
const typeAnnotation = { | ||
type: 'TSUnionType', | ||
types: [{ | ||
type: 'TSLiteralType', | ||
literal: { | ||
type: 'StringLiteral' | ||
} | ||
}, { | ||
type: 'TSLiteralType', | ||
literal: { | ||
type: 'StringLiteral' | ||
} | ||
}] | ||
}; | ||
describe('when nullable is true', () => { | ||
it('returns nullable type annotation', () => { | ||
const result = emitUnionTypeAnnotation(true, hasteModuleName, typeAnnotation, typeScriptParser); | ||
const expected = { | ||
type: 'NullableTypeAnnotation', | ||
typeAnnotation: { | ||
type: 'UnionTypeAnnotation', | ||
memberType: 'StringTypeAnnotation' | ||
} | ||
}; | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
describe('when nullable is false', () => { | ||
it('returns non nullable type annotation', () => { | ||
const result = emitUnionTypeAnnotation(false, hasteModuleName, typeAnnotation, typeScriptParser); | ||
const expected = { | ||
type: 'UnionTypeAnnotation', | ||
memberType: 'StringTypeAnnotation' | ||
}; | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
}); | ||
describe('when members type is object', () => { | ||
const typeAnnotation = { | ||
type: 'TSUnionType', | ||
types: [{ | ||
type: 'TSLiteralType' | ||
}, { | ||
type: 'TSLiteralType' | ||
}] | ||
}; | ||
describe('when nullable is true', () => { | ||
it('returns nullable type annotation', () => { | ||
const result = emitUnionTypeAnnotation(true, hasteModuleName, typeAnnotation, typeScriptParser); | ||
const expected = { | ||
type: 'NullableTypeAnnotation', | ||
typeAnnotation: { | ||
type: 'UnionTypeAnnotation', | ||
memberType: 'ObjectTypeAnnotation' | ||
} | ||
}; | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
describe('when nullable is false', () => { | ||
it('returns non nullable type annotation', () => { | ||
const result = emitUnionTypeAnnotation(false, hasteModuleName, typeAnnotation, typeScriptParser); | ||
const expected = { | ||
type: 'UnionTypeAnnotation', | ||
memberType: 'ObjectTypeAnnotation' | ||
}; | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
}); | ||
describe('when members type is mixed', () => { | ||
const typeAnnotation = { | ||
type: 'TSUnionType', | ||
types: [{ | ||
type: 'TSLiteralType', | ||
literal: { | ||
type: 'NumericLiteral' | ||
} | ||
}, { | ||
type: 'TSLiteralType', | ||
literal: { | ||
type: 'StringLiteral' | ||
} | ||
}, { | ||
type: 'TSLiteralType' | ||
}] | ||
}; | ||
const unionTypes = ['NumberTypeAnnotation', 'StringTypeAnnotation', 'ObjectTypeAnnotation']; | ||
describe('when nullable is true', () => { | ||
it('throws an excpetion', () => { | ||
const expected = new UnsupportedUnionTypeAnnotationParserError(hasteModuleName, typeAnnotation, unionTypes, typeScriptParser.language()); | ||
expect(() => { | ||
emitUnionTypeAnnotation(true, hasteModuleName, typeAnnotation, typeScriptParser); | ||
}).toThrow(expected); | ||
}); | ||
}); | ||
describe('when nullable is false', () => { | ||
it('throws an excpetion', () => { | ||
const expected = new UnsupportedUnionTypeAnnotationParserError(hasteModuleName, typeAnnotation, unionTypes, typeScriptParser.language()); | ||
expect(() => { | ||
emitUnionTypeAnnotation(false, hasteModuleName, typeAnnotation, typeScriptParser); | ||
}).toThrow(expected); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -14,2 +14,3 @@ /** | ||
const _require = require('../parsers-primitives.js'), | ||
emitArrayType = _require.emitArrayType, | ||
emitBoolean = _require.emitBoolean, | ||
@@ -26,7 +27,23 @@ emitDouble = _require.emitDouble, | ||
emitStringish = _require.emitStringish, | ||
emitMixedTypeAnnotation = _require.emitMixedTypeAnnotation, | ||
emitMixed = _require.emitMixed, | ||
typeAliasResolution = _require.typeAliasResolution; | ||
import { MockedParser } from '../parserMock'; | ||
const _require2 = require('../parserMock'), | ||
MockedParser = _require2.MockedParser; | ||
const _require3 = require('../parsers-primitives'), | ||
emitUnion = _require3.emitUnion; | ||
const _require4 = require('../errors'), | ||
UnsupportedUnionTypeAnnotationParserError = _require4.UnsupportedUnionTypeAnnotationParserError; | ||
const _require5 = require('../flow/parser'), | ||
FlowParser = _require5.FlowParser; | ||
const _require6 = require('../typescript/parser'), | ||
TypeScriptParser = _require6.TypeScriptParser; | ||
const parser = new MockedParser(); | ||
const flowParser = new FlowParser(); | ||
const typeScriptParser = new TypeScriptParser(); | ||
describe('emitBoolean', () => { | ||
@@ -287,2 +304,20 @@ describe('when nullable is true', () => { | ||
const moduleName = 'testModuleName'; | ||
function emitPromiseForUnitTest(typeAnnotation, nullable) { | ||
return emitPromise(moduleName, typeAnnotation, parser, nullable, // mock translateTypeAnnotation function | ||
/* types: TypeDeclarationMap */ | ||
{}, | ||
/* aliasMap: {...NativeModuleAliasMap} */ | ||
{}, | ||
/* tryParse: ParserErrorCapturer */ | ||
function (_) { | ||
return null; | ||
}, | ||
/* cxxOnly: boolean */ | ||
false, | ||
/* the translateTypeAnnotation function */ | ||
(_, elementType) => elementType); | ||
} | ||
describe("when typeAnnotation doesn't have exactly one typeParameter", () => { | ||
@@ -300,3 +335,3 @@ const typeAnnotation = { | ||
const nullable = false; | ||
expect(() => emitPromise(moduleName, typeAnnotation, parser, nullable)).toThrow(); | ||
expect(() => emitPromiseForUnitTest(typeAnnotation, nullable)).toThrow(); | ||
}); | ||
@@ -317,7 +352,8 @@ }); | ||
it('returns nullable type annotation', () => { | ||
const result = emitPromise(moduleName, typeAnnotation, parser, nullable); | ||
const result = emitPromiseForUnitTest(typeAnnotation, nullable); | ||
const expected = { | ||
type: 'NullableTypeAnnotation', | ||
typeAnnotation: { | ||
type: 'PromiseTypeAnnotation' | ||
type: 'PromiseTypeAnnotation', | ||
elementType: 1 | ||
} | ||
@@ -331,5 +367,6 @@ }; | ||
it('returns non nullable type annotation', () => { | ||
const result = emitPromise(moduleName, typeAnnotation, parser, nullable); | ||
const result = emitPromiseForUnitTest(typeAnnotation, nullable); | ||
const expected = { | ||
type: 'PromiseTypeAnnotation' | ||
type: 'PromiseTypeAnnotation', | ||
elementType: 1 | ||
}; | ||
@@ -387,6 +424,6 @@ expect(result).toEqual(expected); | ||
}); | ||
describe('emitMixedTypeAnnotation', () => { | ||
describe('emitMixed', () => { | ||
describe('when nullable is true', () => { | ||
it('returns nullable type annotation', () => { | ||
const result = emitMixedTypeAnnotation(true); | ||
const result = emitMixed(true); | ||
const expected = { | ||
@@ -403,3 +440,3 @@ type: 'NullableTypeAnnotation', | ||
it('returns non nullable type annotation', () => { | ||
const result = emitMixedTypeAnnotation(false); | ||
const result = emitMixed(false); | ||
const expected = { | ||
@@ -411,2 +448,350 @@ type: 'MixedTypeAnnotation' | ||
}); | ||
}); | ||
describe('emitUnion', () => { | ||
const hasteModuleName = 'SampleTurboModule'; | ||
describe('when language is flow', () => { | ||
describe('when members type is numeric', () => { | ||
const typeAnnotation = { | ||
type: 'UnionTypeAnnotation', | ||
types: [{ | ||
type: 'NumberLiteralTypeAnnotation' | ||
}, { | ||
type: 'NumberLiteralTypeAnnotation' | ||
}] | ||
}; | ||
describe('when nullable is true', () => { | ||
it('returns nullable type annotation', () => { | ||
const result = emitUnion(true, hasteModuleName, typeAnnotation, flowParser); | ||
const expected = { | ||
type: 'NullableTypeAnnotation', | ||
typeAnnotation: { | ||
type: 'UnionTypeAnnotation', | ||
memberType: 'NumberTypeAnnotation' | ||
} | ||
}; | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
describe('when nullable is false', () => { | ||
it('returns non nullable type annotation', () => { | ||
const result = emitUnion(false, hasteModuleName, typeAnnotation, flowParser); | ||
const expected = { | ||
type: 'UnionTypeAnnotation', | ||
memberType: 'NumberTypeAnnotation' | ||
}; | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
}); | ||
describe('when members type is string', () => { | ||
const typeAnnotation = { | ||
type: 'UnionTypeAnnotation', | ||
types: [{ | ||
type: 'StringLiteralTypeAnnotation' | ||
}, { | ||
type: 'StringLiteralTypeAnnotation' | ||
}] | ||
}; | ||
describe('when nullable is true', () => { | ||
it('returns nullable type annotation', () => { | ||
const result = emitUnion(true, hasteModuleName, typeAnnotation, flowParser); | ||
const expected = { | ||
type: 'NullableTypeAnnotation', | ||
typeAnnotation: { | ||
type: 'UnionTypeAnnotation', | ||
memberType: 'StringTypeAnnotation' | ||
} | ||
}; | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
describe('when nullable is false', () => { | ||
it('returns non nullable type annotation', () => { | ||
const result = emitUnion(false, hasteModuleName, typeAnnotation, flowParser); | ||
const expected = { | ||
type: 'UnionTypeAnnotation', | ||
memberType: 'StringTypeAnnotation' | ||
}; | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
}); | ||
describe('when members type is object', () => { | ||
const typeAnnotation = { | ||
type: 'UnionTypeAnnotation', | ||
types: [{ | ||
type: 'ObjectTypeAnnotation' | ||
}, { | ||
type: 'ObjectTypeAnnotation' | ||
}] | ||
}; | ||
describe('when nullable is true', () => { | ||
it('returns nullable type annotation', () => { | ||
const result = emitUnion(true, hasteModuleName, typeAnnotation, flowParser); | ||
const expected = { | ||
type: 'NullableTypeAnnotation', | ||
typeAnnotation: { | ||
type: 'UnionTypeAnnotation', | ||
memberType: 'ObjectTypeAnnotation' | ||
} | ||
}; | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
describe('when nullable is false', () => { | ||
it('returns non nullable type annotation', () => { | ||
const result = emitUnion(false, hasteModuleName, typeAnnotation, flowParser); | ||
const expected = { | ||
type: 'UnionTypeAnnotation', | ||
memberType: 'ObjectTypeAnnotation' | ||
}; | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
}); | ||
describe('when members type is mixed', () => { | ||
const typeAnnotation = { | ||
type: 'UnionTypeAnnotation', | ||
types: [{ | ||
type: 'NumberLiteralTypeAnnotation' | ||
}, { | ||
type: 'StringLiteralTypeAnnotation' | ||
}, { | ||
type: 'ObjectTypeAnnotation' | ||
}] | ||
}; | ||
const unionTypes = ['NumberTypeAnnotation', 'StringTypeAnnotation', 'ObjectTypeAnnotation']; | ||
describe('when nullable is true', () => { | ||
it('throws an excpetion', () => { | ||
const expected = new UnsupportedUnionTypeAnnotationParserError(hasteModuleName, typeAnnotation, unionTypes, flowParser.language()); | ||
expect(() => { | ||
emitUnion(true, hasteModuleName, typeAnnotation, flowParser); | ||
}).toThrow(expected); | ||
}); | ||
}); | ||
describe('when nullable is false', () => { | ||
it('throws an excpetion', () => { | ||
const expected = new UnsupportedUnionTypeAnnotationParserError(hasteModuleName, typeAnnotation, unionTypes, flowParser.language()); | ||
expect(() => { | ||
emitUnion(false, hasteModuleName, typeAnnotation, flowParser); | ||
}).toThrow(expected); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('when language is typescript', () => { | ||
describe('when members type is numeric', () => { | ||
const typeAnnotation = { | ||
type: 'TSUnionType', | ||
types: [{ | ||
type: 'TSLiteralType', | ||
literal: { | ||
type: 'NumericLiteral' | ||
} | ||
}, { | ||
type: 'TSLiteralType', | ||
literal: { | ||
type: 'NumericLiteral' | ||
} | ||
}] | ||
}; | ||
describe('when nullable is true', () => { | ||
it('returns nullable type annotation', () => { | ||
const result = emitUnion(true, hasteModuleName, typeAnnotation, typeScriptParser); | ||
const expected = { | ||
type: 'NullableTypeAnnotation', | ||
typeAnnotation: { | ||
type: 'UnionTypeAnnotation', | ||
memberType: 'NumberTypeAnnotation' | ||
} | ||
}; | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
describe('when nullable is false', () => { | ||
it('returns non nullable type annotation', () => { | ||
const result = emitUnion(false, hasteModuleName, typeAnnotation, typeScriptParser); | ||
const expected = { | ||
type: 'UnionTypeAnnotation', | ||
memberType: 'NumberTypeAnnotation' | ||
}; | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
}); | ||
describe('when members type is string', () => { | ||
const typeAnnotation = { | ||
type: 'TSUnionType', | ||
types: [{ | ||
type: 'TSLiteralType', | ||
literal: { | ||
type: 'StringLiteral' | ||
} | ||
}, { | ||
type: 'TSLiteralType', | ||
literal: { | ||
type: 'StringLiteral' | ||
} | ||
}] | ||
}; | ||
describe('when nullable is true', () => { | ||
it('returns nullable type annotation', () => { | ||
const result = emitUnion(true, hasteModuleName, typeAnnotation, typeScriptParser); | ||
const expected = { | ||
type: 'NullableTypeAnnotation', | ||
typeAnnotation: { | ||
type: 'UnionTypeAnnotation', | ||
memberType: 'StringTypeAnnotation' | ||
} | ||
}; | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
describe('when nullable is false', () => { | ||
it('returns non nullable type annotation', () => { | ||
const result = emitUnion(false, hasteModuleName, typeAnnotation, typeScriptParser); | ||
const expected = { | ||
type: 'UnionTypeAnnotation', | ||
memberType: 'StringTypeAnnotation' | ||
}; | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
}); | ||
describe('when members type is object', () => { | ||
const typeAnnotation = { | ||
type: 'TSUnionType', | ||
types: [{ | ||
type: 'TSLiteralType' | ||
}, { | ||
type: 'TSLiteralType' | ||
}] | ||
}; | ||
describe('when nullable is true', () => { | ||
it('returns nullable type annotation', () => { | ||
const result = emitUnion(true, hasteModuleName, typeAnnotation, typeScriptParser); | ||
const expected = { | ||
type: 'NullableTypeAnnotation', | ||
typeAnnotation: { | ||
type: 'UnionTypeAnnotation', | ||
memberType: 'ObjectTypeAnnotation' | ||
} | ||
}; | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
describe('when nullable is false', () => { | ||
it('returns non nullable type annotation', () => { | ||
const result = emitUnion(false, hasteModuleName, typeAnnotation, typeScriptParser); | ||
const expected = { | ||
type: 'UnionTypeAnnotation', | ||
memberType: 'ObjectTypeAnnotation' | ||
}; | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
}); | ||
describe('when members type is mixed', () => { | ||
const typeAnnotation = { | ||
type: 'TSUnionType', | ||
types: [{ | ||
type: 'TSLiteralType', | ||
literal: { | ||
type: 'NumericLiteral' | ||
} | ||
}, { | ||
type: 'TSLiteralType', | ||
literal: { | ||
type: 'StringLiteral' | ||
} | ||
}, { | ||
type: 'TSLiteralType' | ||
}] | ||
}; | ||
const unionTypes = ['NumberTypeAnnotation', 'StringTypeAnnotation', 'ObjectTypeAnnotation']; | ||
describe('when nullable is true', () => { | ||
it('throws an excpetion', () => { | ||
const expected = new UnsupportedUnionTypeAnnotationParserError(hasteModuleName, typeAnnotation, unionTypes, typeScriptParser.language()); | ||
expect(() => { | ||
emitUnion(true, hasteModuleName, typeAnnotation, typeScriptParser); | ||
}).toThrow(expected); | ||
}); | ||
}); | ||
describe('when nullable is false', () => { | ||
it('throws an excpetion', () => { | ||
const expected = new UnsupportedUnionTypeAnnotationParserError(hasteModuleName, typeAnnotation, unionTypes, typeScriptParser.language()); | ||
expect(() => { | ||
emitUnion(false, hasteModuleName, typeAnnotation, typeScriptParser); | ||
}).toThrow(expected); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('emitArrayType', () => { | ||
const hasteModuleName = 'SampleTurboModule'; | ||
function emitArrayTypeForUnitTest(typeAnnotation, nullable) { | ||
return emitArrayType(hasteModuleName, typeAnnotation, parser, | ||
/* types: TypeDeclarationMap */ | ||
{}, | ||
/* aliasMap: {...NativeModuleAliasMap} */ | ||
{}, | ||
/* cxxOnly: boolean */ | ||
false, nullable, | ||
/* the translateTypeAnnotation function */ | ||
(_, elementType) => elementType); | ||
} | ||
describe("when typeAnnotation doesn't have exactly one typeParameter", () => { | ||
const nullable = false; | ||
const typeAnnotation = { | ||
typeParameters: { | ||
params: [1, 2], | ||
type: 'TypeParameterInstantiation' | ||
}, | ||
id: { | ||
name: 'typeAnnotationName' | ||
} | ||
}; | ||
it('throws an IncorrectlyParameterizedGenericParserError error', () => { | ||
expect(() => emitArrayTypeForUnitTest(typeAnnotation, nullable)).toThrow(); | ||
}); | ||
}); | ||
describe('when typeAnnotation has exactly one typeParameter', () => { | ||
const typeAnnotation = { | ||
typeParameters: { | ||
params: [1], | ||
type: 'TypeParameterInstantiation' | ||
}, | ||
id: { | ||
name: 'typeAnnotationName' | ||
} | ||
}; | ||
describe('when nullable is true', () => { | ||
const nullable = true; | ||
it('returns nullable type annotation', () => { | ||
const result = emitArrayTypeForUnitTest(typeAnnotation, nullable); | ||
const expected = { | ||
type: 'NullableTypeAnnotation', | ||
typeAnnotation: { | ||
type: 'ArrayTypeAnnotation', | ||
elementType: 1 | ||
} | ||
}; | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
describe('when nullable is false', () => { | ||
const nullable = false; | ||
it('returns non nullable type annotation', () => { | ||
const result = emitArrayTypeForUnitTest(typeAnnotation, nullable); | ||
const expected = { | ||
type: 'ArrayTypeAnnotation', | ||
elementType: 1 | ||
}; | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -34,22 +34,2 @@ /** | ||
}); | ||
describe('when propertyOrIndex is ObjectTypeIndexer', () => { | ||
it('returns indexer name', () => { | ||
const indexer = { | ||
type: 'ObjectTypeIndexer', | ||
id: { | ||
name: 'indexerName' | ||
} | ||
}; | ||
const expected = 'indexerName'; | ||
expect(parser.getKeyName(indexer, hasteModuleName)).toEqual(expected); | ||
}); | ||
it('returns `key` if indexer has no name', () => { | ||
const indexer = { | ||
type: 'ObjectTypeIndexer', | ||
id: {} | ||
}; | ||
const expected = 'key'; | ||
expect(parser.getKeyName(indexer, hasteModuleName)).toEqual(expected); | ||
}); | ||
}); | ||
describe('when propertyOrIndex is not ObjectTypeProperty or ObjectTypeIndexer', () => { | ||
@@ -95,14 +75,2 @@ it('throw UnsupportedObjectPropertyTypeAnnotationParserError', () => { | ||
}); | ||
describe('when propertyOrIndex is TSIndexSignature', () => { | ||
it('returns indexer name', () => { | ||
const indexer = { | ||
type: 'TSIndexSignature', | ||
parameters: [{ | ||
name: 'indexerName' | ||
}] | ||
}; | ||
const expected = 'indexerName'; | ||
expect(parser.getKeyName(indexer, hasteModuleName)).toEqual(expected); | ||
}); | ||
}); | ||
describe('when propertyOrIndex is not TSPropertySignature or TSIndexSignature', () => { | ||
@@ -109,0 +77,0 @@ it('throw UnsupportedObjectPropertyTypeAnnotationParserError', () => { |
@@ -21,13 +21,16 @@ /** | ||
const _require = require('../utils.js'), | ||
extractNativeModuleName = _require.extractNativeModuleName, | ||
createParserErrorCapturer = _require.createParserErrorCapturer, | ||
verifyPlatforms = _require.verifyPlatforms, | ||
visit = _require.visit, | ||
buildSchemaFromConfigType = _require.buildSchemaFromConfigType, | ||
isModuleRegistryCall = _require.isModuleRegistryCall; | ||
const _require = require('../parserMock'), | ||
MockedParser = _require.MockedParser; | ||
const _require2 = require('../errors'), | ||
ParserError = _require2.ParserError; | ||
const _require2 = require('../utils.js'), | ||
extractNativeModuleName = _require2.extractNativeModuleName, | ||
createParserErrorCapturer = _require2.createParserErrorCapturer, | ||
verifyPlatforms = _require2.verifyPlatforms, | ||
visit = _require2.visit, | ||
buildSchemaFromConfigType = _require2.buildSchemaFromConfigType, | ||
isModuleRegistryCall = _require2.isModuleRegistryCall; | ||
const _require3 = require('../errors'), | ||
ParserError = _require3.ParserError; | ||
beforeEach(() => { | ||
@@ -143,9 +146,9 @@ jest.clearAllMocks(); | ||
it('exclude android given an iOS only module', () => { | ||
let result = verifyPlatforms('NativeSampleTurboModule', ['SampleTurboModuleIOS']); | ||
let result = verifyPlatforms('NativeSampleTurboModule', 'SampleTurboModuleIOS'); | ||
expect(result.cxxOnly).toBe(false); | ||
expect(result.excludedPlatforms).toEqual(['android']); | ||
result = verifyPlatforms('NativeSampleTurboModuleIOS', ['SampleTurboModule']); | ||
result = verifyPlatforms('NativeSampleTurboModuleIOS', 'SampleTurboModule'); | ||
expect(result.cxxOnly).toBe(false); | ||
expect(result.excludedPlatforms).toEqual(['android']); | ||
result = verifyPlatforms('NativeSampleTurboModuleIOS', ['SampleTurboModuleIOS']); | ||
result = verifyPlatforms('NativeSampleTurboModuleIOS', 'SampleTurboModuleIOS'); | ||
expect(result.cxxOnly).toBe(false); | ||
@@ -155,9 +158,9 @@ expect(result.excludedPlatforms).toEqual(['android']); | ||
it('exclude iOS given an android only module', () => { | ||
let result = verifyPlatforms('NativeSampleTurboModule', ['SampleTurboModuleAndroid']); | ||
let result = verifyPlatforms('NativeSampleTurboModule', 'SampleTurboModuleAndroid'); | ||
expect(result.cxxOnly).toBe(false); | ||
expect(result.excludedPlatforms).toEqual(['iOS']); | ||
result = verifyPlatforms('NativeSampleTurboModuleAndroid', ['SampleTurboModule']); | ||
result = verifyPlatforms('NativeSampleTurboModuleAndroid', 'SampleTurboModule'); | ||
expect(result.cxxOnly).toBe(false); | ||
expect(result.excludedPlatforms).toEqual(['iOS']); | ||
result = verifyPlatforms('NativeSampleTurboModuleAndroid', ['SampleTurboModuleAndroid']); | ||
result = verifyPlatforms('NativeSampleTurboModuleAndroid', 'SampleTurboModuleAndroid'); | ||
expect(result.cxxOnly).toBe(false); | ||
@@ -167,9 +170,9 @@ expect(result.excludedPlatforms).toEqual(['iOS']); | ||
it('exclude iOS and android given a Cxx only module', () => { | ||
let result = verifyPlatforms('NativeSampleTurboModule', ['SampleTurboModuleCxx']); | ||
let result = verifyPlatforms('NativeSampleTurboModule', 'SampleTurboModuleCxx'); | ||
expect(result.cxxOnly).toBe(true); | ||
expect(result.excludedPlatforms).toEqual(['iOS', 'android']); | ||
result = verifyPlatforms('NativeSampleTurboModuleCxx', ['SampleTurboModule']); | ||
result = verifyPlatforms('NativeSampleTurboModuleCxx', 'SampleTurboModule'); | ||
expect(result.cxxOnly).toBe(true); | ||
expect(result.excludedPlatforms).toEqual(['iOS', 'android']); | ||
result = verifyPlatforms('NativeSampleTurboModuleCxx', ['SampleTurboModuleCxx']); | ||
result = verifyPlatforms('NativeSampleTurboModuleCxx', 'SampleTurboModuleCxx'); | ||
expect(result.cxxOnly).toBe(true); | ||
@@ -272,2 +275,3 @@ expect(result.excludedPlatforms).toEqual(['iOS', 'android']); | ||
describe('buildSchemaFromConfigType', () => { | ||
const parser = new MockedParser(); | ||
const astMock = { | ||
@@ -305,10 +309,10 @@ type: 'Program', | ||
}, | ||
moduleNames: [] | ||
moduleName: '' | ||
}; | ||
const wrapComponentSchemaMock = jest.fn(); | ||
const buildComponentSchemaMock = jest.fn(() => componentSchemaMock); | ||
const buildComponentSchemaMock = jest.fn(_ => componentSchemaMock); | ||
const wrapModuleSchemaMock = jest.spyOn(require('../parsers-commons'), 'wrapModuleSchema'); | ||
const buildModuleSchemaMock = jest.fn(() => moduleSchemaMock); | ||
const buildModuleSchemaMock = jest.fn((_0, _1, _2, _3) => moduleSchemaMock); | ||
const buildSchemaFromConfigTypeHelper = (configType, filename) => buildSchemaFromConfigType(configType, filename, astMock, wrapComponentSchemaMock, buildComponentSchemaMock, buildModuleSchemaMock); | ||
const buildSchemaFromConfigTypeHelper = (configType, filename) => buildSchemaFromConfigType(configType, filename, astMock, wrapComponentSchemaMock, buildComponentSchemaMock, buildModuleSchemaMock, parser); | ||
@@ -366,3 +370,3 @@ describe('when configType is none', () => { | ||
expect(buildModuleSchemaMock).toHaveBeenCalledTimes(1); | ||
expect(buildModuleSchemaMock).toHaveBeenCalledWith('filename', astMock, expect.any(Function)); | ||
expect(buildModuleSchemaMock).toHaveBeenCalledWith('filename', astMock, expect.any(Function), parser); | ||
expect(wrapModuleSchemaMock).toHaveBeenCalledTimes(1); | ||
@@ -369,0 +373,0 @@ expect(wrapModuleSchemaMock).toHaveBeenCalledWith(moduleSchemaMock, 'filename'); |
@@ -20,3 +20,3 @@ /** | ||
const flowExtraCases = []; | ||
const flowExtraCases = ['PROMISE_WITH_COMMONLY_USED_TYPES']; | ||
@@ -23,0 +23,0 @@ const tsFixtures = require('../../typescript/modules/__test_fixtures__/fixtures.js'); |
@@ -12,3 +12,3 @@ /** | ||
const _require = require('./errors.js'), | ||
const _require = require('./errors'), | ||
MisnamedModuleInterfaceParserError = _require.MisnamedModuleInterfaceParserError, | ||
@@ -25,3 +25,4 @@ UnsupportedFunctionReturnTypeAnnotationParserError = _require.UnsupportedFunctionReturnTypeAnnotationParserError, | ||
MoreThanOneModuleInterfaceParserError = _require.MoreThanOneModuleInterfaceParserError, | ||
UnsupportedFunctionParamTypeAnnotationParserError = _require.UnsupportedFunctionParamTypeAnnotationParserError; | ||
UnsupportedFunctionParamTypeAnnotationParserError = _require.UnsupportedFunctionParamTypeAnnotationParserError, | ||
UnsupportedArrayElementTypeAnnotationParserError = _require.UnsupportedArrayElementTypeAnnotationParserError; | ||
@@ -74,5 +75,5 @@ function throwIfModuleInterfaceIsMisnamed(nativeModuleName, moduleSpecId, parserType) { | ||
function throwIfUntypedModule(typeArguments, hasteModuleName, callExpression, methodName, $moduleName, language) { | ||
function throwIfUntypedModule(typeArguments, hasteModuleName, callExpression, methodName, moduleName, language) { | ||
if (typeArguments == null) { | ||
throw new UntypedModuleRegistryCallParserError(hasteModuleName, callExpression, methodName, $moduleName, language); | ||
throw new UntypedModuleRegistryCallParserError(hasteModuleName, callExpression, methodName, moduleName, language); | ||
} | ||
@@ -110,2 +111,17 @@ } | ||
function throwIfArrayElementTypeAnnotationIsUnsupported(hasteModuleName, flowElementType, flowArrayType, type, language) { | ||
const TypeMap = { | ||
FunctionTypeAnnotation: 'FunctionTypeAnnotation', | ||
VoidTypeAnnotation: 'void', | ||
PromiseTypeAnnotation: 'Promise', | ||
// TODO: Added as a work-around for now until TupleTypeAnnotation are fully supported in both flow and TS | ||
// Right now they are partially treated as UnionTypeAnnotation | ||
UnionTypeAnnotation: 'UnionTypeAnnotation' | ||
}; | ||
if (type in TypeMap) { | ||
throw new UnsupportedArrayElementTypeAnnotationParserError(hasteModuleName, flowElementType, flowArrayType, TypeMap[type], language); | ||
} | ||
} | ||
module.exports = { | ||
@@ -123,3 +139,4 @@ throwIfModuleInterfaceIsMisnamed, | ||
throwIfMoreThanOneModuleInterfaceParserError, | ||
throwIfUnsupportedFunctionParamTypeAnnotationParserError | ||
throwIfUnsupportedFunctionParamTypeAnnotationParserError, | ||
throwIfArrayElementTypeAnnotationIsUnsupported | ||
}; |
@@ -7,3 +7,3 @@ /** | ||
* | ||
* | ||
* strict | ||
* @format | ||
@@ -14,4 +14,5 @@ */ | ||
const _require = require('../utils.js'), | ||
getValueFromTypes = _require.getValueFromTypes; | ||
getValueFromTypes = _require.getValueFromTypes; // $FlowFixMe[unclear-type] there's no flowtype for ASTs | ||
function buildCommandSchema(property, types) { | ||
@@ -18,0 +19,0 @@ const name = property.key.name; |
@@ -7,3 +7,3 @@ /** | ||
* | ||
* strict-local | ||
* strict | ||
* @format | ||
@@ -10,0 +10,0 @@ */ |
@@ -7,3 +7,3 @@ /** | ||
* | ||
* strict-local | ||
* strict | ||
* @format | ||
@@ -10,0 +10,0 @@ */ |
@@ -7,3 +7,3 @@ /** | ||
* | ||
* strict-local | ||
* strict | ||
* @format | ||
@@ -10,0 +10,0 @@ */ |
@@ -7,3 +7,3 @@ /** | ||
* | ||
* strict-local | ||
* strict | ||
* @format | ||
@@ -10,0 +10,0 @@ */ |
@@ -7,3 +7,3 @@ /** | ||
* | ||
* strict-local | ||
* strict | ||
* @format | ||
@@ -10,0 +10,0 @@ */ |
@@ -7,3 +7,3 @@ /** | ||
* | ||
* strict-local | ||
* strict | ||
* @format | ||
@@ -10,0 +10,0 @@ */ |
@@ -7,74 +7,29 @@ /** | ||
* | ||
* strict-local | ||
* strict | ||
* @format | ||
*/ | ||
'use strict'; // $FlowFixMe[untyped-import] there's no flowtype flow-parser | ||
'use strict'; | ||
const flowParser = require('flow-parser'); | ||
const fs = require('fs'); | ||
const _require = require('../utils'), | ||
buildSchemaFromConfigType = _require.buildSchemaFromConfigType, | ||
getConfigType = _require.getConfigType, | ||
isModuleRegistryCall = _require.isModuleRegistryCall; | ||
const _require = require('./buildSchema'), | ||
buildSchema = _require.buildSchema; | ||
const _require2 = require('./components'), | ||
buildComponentSchema = _require2.buildComponentSchema; | ||
const _require2 = require('./parser'), | ||
FlowParser = _require2.FlowParser; | ||
const _require3 = require('./components/schema'), | ||
wrapComponentSchema = _require3.wrapComponentSchema; | ||
const parser = new FlowParser(); | ||
const _require4 = require('./modules'), | ||
buildModuleSchema = _require4.buildModuleSchema; | ||
function Visitor(infoMap) { | ||
return { | ||
CallExpression(node) { | ||
if (node.callee.type === 'Identifier' && node.callee.name === 'codegenNativeComponent') { | ||
infoMap.isComponent = true; | ||
} | ||
if (isModuleRegistryCall(node)) { | ||
infoMap.isModule = true; | ||
} | ||
}, | ||
InterfaceExtends(node) { | ||
if (node.id.name === 'TurboModule') { | ||
infoMap.isModule = true; | ||
} | ||
} | ||
}; | ||
} | ||
function buildSchema(contents, filename) { | ||
// Early return for non-Spec JavaScript files | ||
if (!contents.includes('codegenNativeComponent') && !contents.includes('TurboModule')) { | ||
return { | ||
modules: {} | ||
}; | ||
} | ||
const ast = flowParser.parse(contents, { | ||
enums: true | ||
}); | ||
const configType = getConfigType(ast, Visitor); | ||
return buildSchemaFromConfigType(configType, filename, ast, wrapComponentSchema, buildComponentSchema, buildModuleSchema); | ||
} | ||
function parseModuleFixture(filename) { | ||
const contents = fs.readFileSync(filename, 'utf8'); | ||
return buildSchema(contents, 'path/NativeSampleTurboModule.js'); | ||
return buildSchema(contents, 'path/NativeSampleTurboModule.js', parser); | ||
} | ||
function parseString(contents, filename) { | ||
return buildSchema(contents, filename); | ||
return buildSchema(contents, filename, parser); | ||
} | ||
module.exports = { | ||
buildSchema, | ||
parseModuleFixture, | ||
parseString | ||
}; |
@@ -7,3 +7,3 @@ /** | ||
* | ||
* strict-local | ||
* strict | ||
* @format | ||
@@ -27,106 +27,54 @@ */ | ||
const _require = require('../../parsers-utils'), | ||
nullGuard = _require.nullGuard; | ||
const _require = require('../../utils'), | ||
visit = _require.visit, | ||
isModuleRegistryCall = _require.isModuleRegistryCall, | ||
verifyPlatforms = _require.verifyPlatforms; | ||
const _require2 = require('../../utils'), | ||
visit = _require2.visit, | ||
verifyPlatforms = _require2.verifyPlatforms, | ||
isModuleRegistryCall = _require2.isModuleRegistryCall; | ||
const _require2 = require('../utils'), | ||
resolveTypeAnnotation = _require2.resolveTypeAnnotation, | ||
getTypes = _require2.getTypes; | ||
const _require3 = require('../utils.js'), | ||
resolveTypeAnnotation = _require3.resolveTypeAnnotation, | ||
getTypes = _require3.getTypes; | ||
const _require3 = require('../../parsers-commons'), | ||
unwrapNullable = _require3.unwrapNullable, | ||
wrapNullable = _require3.wrapNullable, | ||
assertGenericTypeAnnotationHasExactlyOneTypeParameter = _require3.assertGenericTypeAnnotationHasExactlyOneTypeParameter, | ||
parseObjectProperty = _require3.parseObjectProperty, | ||
translateDefault = _require3.translateDefault, | ||
buildPropertySchema = _require3.buildPropertySchema; | ||
const _require4 = require('../../parsers-commons'), | ||
unwrapNullable = _require4.unwrapNullable, | ||
wrapNullable = _require4.wrapNullable, | ||
assertGenericTypeAnnotationHasExactlyOneTypeParameter = _require4.assertGenericTypeAnnotationHasExactlyOneTypeParameter, | ||
parseObjectProperty = _require4.parseObjectProperty, | ||
emitUnionTypeAnnotation = _require4.emitUnionTypeAnnotation, | ||
translateDefault = _require4.translateDefault, | ||
translateFunctionTypeAnnotation = _require4.translateFunctionTypeAnnotation; | ||
const _require4 = require('../../parsers-primitives'), | ||
emitArrayType = _require4.emitArrayType, | ||
emitBoolean = _require4.emitBoolean, | ||
emitDouble = _require4.emitDouble, | ||
emitFloat = _require4.emitFloat, | ||
emitFunction = _require4.emitFunction, | ||
emitNumber = _require4.emitNumber, | ||
emitInt32 = _require4.emitInt32, | ||
emitObject = _require4.emitObject, | ||
emitPromise = _require4.emitPromise, | ||
emitRootTag = _require4.emitRootTag, | ||
emitVoid = _require4.emitVoid, | ||
emitString = _require4.emitString, | ||
emitStringish = _require4.emitStringish, | ||
emitMixed = _require4.emitMixed, | ||
emitUnion = _require4.emitUnion, | ||
typeAliasResolution = _require4.typeAliasResolution, | ||
translateArrayTypeAnnotation = _require4.translateArrayTypeAnnotation; | ||
const _require5 = require('../../parsers-primitives'), | ||
emitBoolean = _require5.emitBoolean, | ||
emitDouble = _require5.emitDouble, | ||
emitFloat = _require5.emitFloat, | ||
emitFunction = _require5.emitFunction, | ||
emitNumber = _require5.emitNumber, | ||
emitInt32 = _require5.emitInt32, | ||
emitObject = _require5.emitObject, | ||
emitPromise = _require5.emitPromise, | ||
emitRootTag = _require5.emitRootTag, | ||
emitVoid = _require5.emitVoid, | ||
emitString = _require5.emitString, | ||
emitStringish = _require5.emitStringish, | ||
emitMixedTypeAnnotation = _require5.emitMixedTypeAnnotation, | ||
typeAliasResolution = _require5.typeAliasResolution; | ||
const _require5 = require('../../errors'), | ||
UnsupportedTypeAnnotationParserError = _require5.UnsupportedTypeAnnotationParserError, | ||
IncorrectModuleRegistryCallArgumentTypeParserError = _require5.IncorrectModuleRegistryCallArgumentTypeParserError; | ||
const _require6 = require('../../errors.js'), | ||
UnsupportedArrayElementTypeAnnotationParserError = _require6.UnsupportedArrayElementTypeAnnotationParserError, | ||
UnsupportedTypeAnnotationParserError = _require6.UnsupportedTypeAnnotationParserError, | ||
IncorrectModuleRegistryCallArgumentTypeParserError = _require6.IncorrectModuleRegistryCallArgumentTypeParserError; | ||
const _require6 = require('../../error-utils'), | ||
throwIfModuleInterfaceNotFound = _require6.throwIfModuleInterfaceNotFound, | ||
throwIfModuleInterfaceIsMisnamed = _require6.throwIfModuleInterfaceIsMisnamed, | ||
throwIfUnusedModuleInterfaceParserError = _require6.throwIfUnusedModuleInterfaceParserError, | ||
throwIfWrongNumberOfCallExpressionArgs = _require6.throwIfWrongNumberOfCallExpressionArgs, | ||
throwIfMoreThanOneModuleRegistryCalls = _require6.throwIfMoreThanOneModuleRegistryCalls, | ||
throwIfIncorrectModuleRegistryCallTypeParameterParserError = _require6.throwIfIncorrectModuleRegistryCallTypeParameterParserError, | ||
throwIfUntypedModule = _require6.throwIfUntypedModule, | ||
throwIfMoreThanOneModuleInterfaceParserError = _require6.throwIfMoreThanOneModuleInterfaceParserError; | ||
const _require7 = require('../../error-utils'), | ||
throwIfModuleInterfaceNotFound = _require7.throwIfModuleInterfaceNotFound, | ||
throwIfModuleInterfaceIsMisnamed = _require7.throwIfModuleInterfaceIsMisnamed, | ||
throwIfUnusedModuleInterfaceParserError = _require7.throwIfUnusedModuleInterfaceParserError, | ||
throwIfWrongNumberOfCallExpressionArgs = _require7.throwIfWrongNumberOfCallExpressionArgs, | ||
throwIfMoreThanOneModuleRegistryCalls = _require7.throwIfMoreThanOneModuleRegistryCalls, | ||
throwIfIncorrectModuleRegistryCallTypeParameterParserError = _require7.throwIfIncorrectModuleRegistryCallTypeParameterParserError, | ||
throwIfUntypedModule = _require7.throwIfUntypedModule, | ||
throwIfModuleTypeIsUnsupported = _require7.throwIfModuleTypeIsUnsupported, | ||
throwIfMoreThanOneModuleInterfaceParserError = _require7.throwIfMoreThanOneModuleInterfaceParserError; | ||
const _require8 = require('../parser.js'), | ||
FlowParser = _require8.FlowParser; | ||
const language = 'Flow'; | ||
const parser = new FlowParser(); | ||
function translateArrayTypeAnnotation(hasteModuleName, types, aliasMap, cxxOnly, flowArrayType, flowElementType, nullable) { | ||
try { | ||
/** | ||
* TODO(T72031674): Migrate all our NativeModule specs to not use | ||
* invalid Array ElementTypes. Then, make the elementType a required | ||
* parameter. | ||
*/ | ||
const _unwrapNullable = unwrapNullable(translateTypeAnnotation(hasteModuleName, flowElementType, types, aliasMap, | ||
/** | ||
* TODO(T72031674): Ensure that all ParsingErrors that are thrown | ||
* while parsing the array element don't get captured and collected. | ||
* Why? If we detect any parsing error while parsing the element, | ||
* we should default it to null down the line, here. This is | ||
* the correct behaviour until we migrate all our NativeModule specs | ||
* to be parseable. | ||
*/ | ||
nullGuard, cxxOnly)), | ||
_unwrapNullable2 = _slicedToArray(_unwrapNullable, 2), | ||
elementType = _unwrapNullable2[0], | ||
isElementTypeNullable = _unwrapNullable2[1]; | ||
if (elementType.type === 'VoidTypeAnnotation') { | ||
throw new UnsupportedArrayElementTypeAnnotationParserError(hasteModuleName, flowElementType, flowArrayType, 'void', language); | ||
} | ||
if (elementType.type === 'PromiseTypeAnnotation') { | ||
throw new UnsupportedArrayElementTypeAnnotationParserError(hasteModuleName, flowElementType, flowArrayType, 'Promise', language); | ||
} | ||
if (elementType.type === 'FunctionTypeAnnotation') { | ||
throw new UnsupportedArrayElementTypeAnnotationParserError(hasteModuleName, flowElementType, flowArrayType, 'FunctionTypeAnnotation', language); | ||
} | ||
const finalTypeAnnotation = { | ||
type: 'ArrayTypeAnnotation', | ||
elementType: wrapNullable(isElementTypeNullable, elementType) | ||
}; | ||
return wrapNullable(nullable, finalTypeAnnotation); | ||
} catch (ex) { | ||
return wrapNullable(nullable, { | ||
type: 'ArrayTypeAnnotation' | ||
}); | ||
} | ||
} | ||
function translateTypeAnnotation(hasteModuleName, | ||
@@ -136,3 +84,3 @@ /** | ||
*/ | ||
flowTypeAnnotation, types, aliasMap, tryParse, cxxOnly) { | ||
flowTypeAnnotation, types, aliasMap, tryParse, cxxOnly, parser) { | ||
const _resolveTypeAnnotatio = resolveTypeAnnotation(flowTypeAnnotation, types), | ||
@@ -154,3 +102,3 @@ nullable = _resolveTypeAnnotatio.nullable, | ||
{ | ||
return emitPromise(hasteModuleName, typeAnnotation, parser, nullable); | ||
return emitPromise(hasteModuleName, typeAnnotation, parser, nullable, types, aliasMap, tryParse, cxxOnly, translateTypeAnnotation); | ||
} | ||
@@ -161,4 +109,3 @@ | ||
{ | ||
assertGenericTypeAnnotationHasExactlyOneTypeParameter(hasteModuleName, typeAnnotation, parser); | ||
return translateArrayTypeAnnotation(hasteModuleName, types, aliasMap, cxxOnly, typeAnnotation.type, typeAnnotation.typeParameters.params[0], nullable); | ||
return emitArrayType(hasteModuleName, typeAnnotation, parser, types, aliasMap, cxxOnly, nullable, translateTypeAnnotation); | ||
} | ||
@@ -170,6 +117,6 @@ | ||
const _unwrapNullable3 = unwrapNullable(translateTypeAnnotation(hasteModuleName, typeAnnotation.typeParameters.params[0], types, aliasMap, tryParse, cxxOnly)), | ||
_unwrapNullable4 = _slicedToArray(_unwrapNullable3, 2), | ||
paramType = _unwrapNullable4[0], | ||
isParamNullable = _unwrapNullable4[1]; | ||
const _unwrapNullable = unwrapNullable(translateTypeAnnotation(hasteModuleName, typeAnnotation.typeParameters.params[0], types, aliasMap, tryParse, cxxOnly, parser)), | ||
_unwrapNullable2 = _slicedToArray(_unwrapNullable, 2), | ||
paramType = _unwrapNullable2[0], | ||
isParamNullable = _unwrapNullable2[1]; | ||
@@ -214,2 +161,16 @@ return wrapNullable(nullable || isParamNullable, paramType); | ||
{ | ||
// if there is any indexer, then it is a dictionary | ||
if (typeAnnotation.indexers) { | ||
const indexers = typeAnnotation.indexers.filter(member => member.type === 'ObjectTypeIndexer'); | ||
if (indexers.length > 0) { | ||
// check the property type to prevent developers from using unsupported types | ||
// the return value from `translateTypeAnnotation` is unused | ||
const propertyType = indexers[0].value; | ||
translateTypeAnnotation(hasteModuleName, propertyType, types, aliasMap, tryParse, cxxOnly, parser); // no need to do further checking | ||
return emitObject(nullable); | ||
} | ||
} | ||
const objectTypeAnnotation = { | ||
@@ -249,3 +210,3 @@ type: 'ObjectTypeAnnotation', | ||
{ | ||
return emitFunction(nullable, hasteModuleName, typeAnnotation, types, aliasMap, tryParse, cxxOnly, translateTypeAnnotation, language); | ||
return emitFunction(nullable, hasteModuleName, typeAnnotation, types, aliasMap, tryParse, cxxOnly, translateTypeAnnotation, parser); | ||
} | ||
@@ -255,11 +216,21 @@ | ||
{ | ||
return emitUnionTypeAnnotation(nullable, hasteModuleName, typeAnnotation, parser); | ||
return emitUnion(nullable, hasteModuleName, typeAnnotation, parser); | ||
} | ||
case 'StringLiteralTypeAnnotation': | ||
{ | ||
// 'a' is a special case for 'a' | 'b' but the type name is different | ||
return wrapNullable(nullable, { | ||
type: 'UnionTypeAnnotation', | ||
memberType: 'StringTypeAnnotation' | ||
}); | ||
} | ||
case 'MixedTypeAnnotation': | ||
{ | ||
if (cxxOnly) { | ||
return emitMixedTypeAnnotation(nullable); | ||
} // Fallthrough | ||
return emitMixed(nullable); | ||
} else { | ||
return emitObject(nullable); | ||
} | ||
} | ||
@@ -274,24 +245,2 @@ | ||
function buildPropertySchema(hasteModuleName, // TODO(T71778680): This is an ObjectTypeProperty containing either: | ||
// - a FunctionTypeAnnotation or GenericTypeAnnotation | ||
// - a NullableTypeAnnoation containing a FunctionTypeAnnotation or GenericTypeAnnotation | ||
// Flow type this node | ||
property, types, aliasMap, tryParse, cxxOnly) { | ||
let nullable = false; | ||
let key = property.key, | ||
value = property.value; | ||
const methodName = key.name; | ||
var _resolveTypeAnnotatio2 = resolveTypeAnnotation(value, types); | ||
nullable = _resolveTypeAnnotatio2.nullable; | ||
value = _resolveTypeAnnotatio2.typeAnnotation; | ||
throwIfModuleTypeIsUnsupported(hasteModuleName, property.value, property.key.name, value.type, language); | ||
return { | ||
name: methodName, | ||
optional: property.optional, | ||
typeAnnotation: wrapNullable(nullable, translateFunctionTypeAnnotation(hasteModuleName, value, types, aliasMap, tryParse, cxxOnly, translateTypeAnnotation, language)) | ||
}; | ||
} | ||
function isModuleInterface(node) { | ||
@@ -305,3 +254,3 @@ return node.type === 'InterfaceDeclaration' && node.extends.length === 1 && node.extends[0].type === 'InterfaceExtends' && node.extends[0].id.name === 'TurboModule'; | ||
*/ | ||
ast, tryParse) { | ||
ast, tryParse, parser) { | ||
const types = getTypes(ast); | ||
@@ -315,5 +264,5 @@ const moduleSpecs = Object.values(types).filter(isModuleInterface); | ||
throwIfModuleInterfaceIsMisnamed(hasteModuleName, moduleSpec.id, language); // Parse Module Names | ||
throwIfModuleInterfaceIsMisnamed(hasteModuleName, moduleSpec.id, language); // Parse Module Name | ||
const moduleName = tryParse(() => { | ||
const moduleName = (() => { | ||
const callExpressions = []; | ||
@@ -344,4 +293,3 @@ visit(ast, { | ||
return $moduleName; | ||
}); | ||
const moduleNames = moduleName == null ? [] : [moduleName]; // Some module names use platform suffix to indicate platform-exclusive modules. | ||
})(); // Some module names use platform suffix to indicate platform-exclusive modules. | ||
// Eventually this should be made explicit in the Flow type itself. | ||
@@ -351,3 +299,4 @@ // Also check the hasteModuleName for platform suffix. | ||
const _verifyPlatforms = verifyPlatforms(hasteModuleName, moduleNames), | ||
const _verifyPlatforms = verifyPlatforms(hasteModuleName, moduleName), | ||
cxxOnly = _verifyPlatforms.cxxOnly, | ||
@@ -361,3 +310,3 @@ excludedPlatforms = _verifyPlatforms.excludedPlatforms; // $FlowFixMe[missing-type-arg] | ||
aliasMap: aliasMap, | ||
propertyShape: buildPropertySchema(hasteModuleName, property, types, aliasMap, tryParse, cxxOnly) | ||
propertyShape: buildPropertySchema(hasteModuleName, property, types, aliasMap, tryParse, cxxOnly, resolveTypeAnnotation, translateTypeAnnotation, parser) | ||
})); | ||
@@ -367,14 +316,12 @@ }).filter(Boolean).reduce((moduleSchema, { | ||
propertyShape | ||
}) => { | ||
return { | ||
type: 'NativeModule', | ||
aliases: _objectSpread({}, moduleSchema.aliases, {}, aliasMap), | ||
spec: { | ||
properties: [...moduleSchema.spec.properties, propertyShape] | ||
}, | ||
moduleNames: moduleSchema.moduleNames, | ||
excludedPlatforms: moduleSchema.excludedPlatforms | ||
}; | ||
}, { | ||
}) => ({ | ||
type: 'NativeModule', | ||
aliases: _objectSpread({}, moduleSchema.aliases, {}, aliasMap), | ||
spec: { | ||
properties: [...moduleSchema.spec.properties, propertyShape] | ||
}, | ||
moduleName: moduleSchema.moduleName, | ||
excludedPlatforms: moduleSchema.excludedPlatforms | ||
}), { | ||
type: 'NativeModule', | ||
aliases: {}, | ||
@@ -384,3 +331,3 @@ spec: { | ||
}, | ||
moduleNames: moduleNames, | ||
moduleName, | ||
excludedPlatforms: excludedPlatforms.length !== 0 ? [...excludedPlatforms] : undefined | ||
@@ -387,0 +334,0 @@ }); |
@@ -14,5 +14,10 @@ /** | ||
const _require = require('../errors'), | ||
UnsupportedObjectPropertyTypeAnnotationParserError = _require.UnsupportedObjectPropertyTypeAnnotationParserError; | ||
const _require = require('./buildSchema'), | ||
buildSchema = _require.buildSchema; | ||
const fs = require('fs'); | ||
const _require2 = require('../errors'), | ||
UnsupportedObjectPropertyTypeAnnotationParserError = _require2.UnsupportedObjectPropertyTypeAnnotationParserError; | ||
class FlowParser { | ||
@@ -23,16 +28,12 @@ constructor() { | ||
getKeyName(propertyOrIndex, hasteModuleName) { | ||
var _ref, _propertyOrIndex$id; | ||
isProperty(property) { | ||
return property.type === 'ObjectTypeProperty'; | ||
} | ||
switch (propertyOrIndex.type) { | ||
case 'ObjectTypeProperty': | ||
return propertyOrIndex.key.name; | ||
getKeyName(property, hasteModuleName) { | ||
if (!this.isProperty(property)) { | ||
throw new UnsupportedObjectPropertyTypeAnnotationParserError(hasteModuleName, property, property.type, this.language()); | ||
} | ||
case 'ObjectTypeIndexer': | ||
// flow index name is optional | ||
return (_ref = (_propertyOrIndex$id = propertyOrIndex.id) === null || _propertyOrIndex$id === void 0 ? void 0 : _propertyOrIndex$id.name) !== null && _ref !== void 0 ? _ref : 'key'; | ||
default: | ||
throw new UnsupportedObjectPropertyTypeAnnotationParserError(hasteModuleName, propertyOrIndex, propertyOrIndex.type, this.language()); | ||
} | ||
return property.key.name; | ||
} | ||
@@ -68,2 +69,7 @@ | ||
parseFile(filename) { | ||
const contents = fs.readFileSync(filename, 'utf8'); | ||
return buildSchema(contents, filename, this); | ||
} | ||
} | ||
@@ -70,0 +76,0 @@ |
@@ -7,3 +7,3 @@ /** | ||
* | ||
* strict-local | ||
* strict | ||
* @format | ||
@@ -10,0 +10,0 @@ */ |
@@ -22,16 +22,12 @@ /** | ||
getKeyName(propertyOrIndex, hasteModuleName) { | ||
var _ref, _propertyOrIndex$id; | ||
isProperty(property) { | ||
return property.type === 'ObjectTypeProperty'; | ||
} | ||
switch (propertyOrIndex.type) { | ||
case 'ObjectTypeProperty': | ||
return propertyOrIndex.key.name; | ||
getKeyName(property, hasteModuleName) { | ||
if (!this.isProperty(property)) { | ||
throw new UnsupportedObjectPropertyTypeAnnotationParserError(hasteModuleName, property, property.type, this.language()); | ||
} | ||
case 'ObjectTypeIndexer': | ||
// flow index name is optional | ||
return (_ref = (_propertyOrIndex$id = propertyOrIndex.id) === null || _propertyOrIndex$id === void 0 ? void 0 : _propertyOrIndex$id.name) !== null && _ref !== void 0 ? _ref : 'key'; | ||
default: | ||
throw new UnsupportedObjectPropertyTypeAnnotationParserError(hasteModuleName, propertyOrIndex, propertyOrIndex.type, this.language()); | ||
} | ||
return property.key.name; | ||
} | ||
@@ -63,2 +59,20 @@ | ||
parseFile(filename) { | ||
return { | ||
modules: { | ||
StringPropNativeComponentView: { | ||
type: 'Component', | ||
components: { | ||
StringPropNativeComponentView: { | ||
extendsProps: [], | ||
events: [], | ||
props: [], | ||
commands: [] | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
} |
@@ -23,3 +23,4 @@ /** | ||
throwIfUnsupportedFunctionParamTypeAnnotationParserError = _require.throwIfUnsupportedFunctionParamTypeAnnotationParserError, | ||
throwIfUnsupportedFunctionReturnTypeAnnotationParserError = _require.throwIfUnsupportedFunctionReturnTypeAnnotationParserError; | ||
throwIfUnsupportedFunctionReturnTypeAnnotationParserError = _require.throwIfUnsupportedFunctionReturnTypeAnnotationParserError, | ||
throwIfModuleTypeIsUnsupported = _require.throwIfModuleTypeIsUnsupported; | ||
@@ -31,4 +32,2 @@ const _require2 = require('./errors'), | ||
UnsupportedGenericParserError = _require2.UnsupportedGenericParserError, | ||
UnsupportedObjectPropertyTypeAnnotationParserError = _require2.UnsupportedObjectPropertyTypeAnnotationParserError, | ||
UnsupportedUnionTypeAnnotationParserError = _require2.UnsupportedUnionTypeAnnotationParserError, | ||
UnnamedFunctionParamParserError = _require2.UnnamedFunctionParamParserError; | ||
@@ -85,6 +84,6 @@ | ||
case 'Flow': | ||
return property.type === 'ObjectTypeProperty' || property.type === 'ObjectTypeIndexer'; | ||
return property.type === 'ObjectTypeProperty'; | ||
case 'TypeScript': | ||
return property.type === 'TSPropertySignature' || property.type === 'TSIndexSignature'; | ||
return property.type === 'TSPropertySignature'; | ||
@@ -98,24 +97,8 @@ default: | ||
const language = parser.language(); | ||
if (!isObjectProperty(property, language)) { | ||
throw new UnsupportedObjectPropertyTypeAnnotationParserError(hasteModuleName, property, property.type, language); | ||
} | ||
const name = parser.getKeyName(property, hasteModuleName); | ||
const _property$optional = property.optional, | ||
optional = _property$optional === void 0 ? false : _property$optional; | ||
const name = parser.getKeyName(property, hasteModuleName); | ||
const languageTypeAnnotation = language === 'TypeScript' ? property.typeAnnotation.typeAnnotation : property.value; | ||
if (property.type === 'ObjectTypeIndexer' || property.type === 'TSIndexSignature') { | ||
return { | ||
name, | ||
optional, | ||
typeAnnotation: wrapNullable(nullable, { | ||
type: 'GenericObjectTypeAnnotation' | ||
}) //TODO: use `emitObject` for typeAnnotation | ||
}; | ||
} | ||
const _unwrapNullable = unwrapNullable(translateTypeAnnotation(hasteModuleName, languageTypeAnnotation, types, aliasMap, tryParse, cxxOnly)), | ||
const _unwrapNullable = unwrapNullable(translateTypeAnnotation(hasteModuleName, languageTypeAnnotation, types, aliasMap, tryParse, cxxOnly, parser)), | ||
_unwrapNullable2 = _slicedToArray(_unwrapNullable, 2), | ||
@@ -136,15 +119,2 @@ propertyTypeAnnotation = _unwrapNullable2[0], | ||
function emitUnionTypeAnnotation(nullable, hasteModuleName, typeAnnotation, parser) { | ||
const unionTypes = parser.remapUnionTypeAnnotationMemberNames(typeAnnotation.types); // Only support unionTypes of the same kind | ||
if (unionTypes.length > 1) { | ||
throw new UnsupportedUnionTypeAnnotationParserError(hasteModuleName, typeAnnotation, unionTypes, parser.language()); | ||
} | ||
return wrapNullable(nullable, { | ||
type: 'UnionTypeAnnotation', | ||
memberType: unionTypes[0] | ||
}); | ||
} | ||
function translateDefault(hasteModuleName, typeAnnotation, types, nullable, parser) { | ||
@@ -191,14 +161,14 @@ const maybeEnumDeclaration = types[parser.nameForGenericTypeAnnotation(typeAnnotation)]; | ||
// TODO(T71778680): This is a FunctionTypeAnnotation. Type this. | ||
typeAnnotation, types, aliasMap, tryParse, cxxOnly, translateTypeAnnotation, language) { | ||
typeAnnotation, types, aliasMap, tryParse, cxxOnly, translateTypeAnnotation, parser) { | ||
const params = []; | ||
for (const param of getTypeAnnotationParameters(typeAnnotation, language)) { | ||
for (const param of getTypeAnnotationParameters(typeAnnotation, parser.language())) { | ||
const parsedParam = tryParse(() => { | ||
if (getFunctionNameFromParameter(param, language) == null) { | ||
throw new UnnamedFunctionParamParserError(param, hasteModuleName, language); | ||
if (getFunctionNameFromParameter(param, parser.language()) == null) { | ||
throw new UnnamedFunctionParamParserError(param, hasteModuleName, parser.language()); | ||
} | ||
const paramName = getParameterName(param, language); | ||
const paramName = getParameterName(param, parser.language()); | ||
const _unwrapNullable3 = unwrapNullable(translateTypeAnnotation(hasteModuleName, getParameterTypeAnnotation(param, language), types, aliasMap, tryParse, cxxOnly)), | ||
const _unwrapNullable3 = unwrapNullable(translateTypeAnnotation(hasteModuleName, getParameterTypeAnnotation(param, parser.language()), types, aliasMap, tryParse, cxxOnly, parser)), | ||
_unwrapNullable4 = _slicedToArray(_unwrapNullable3, 2), | ||
@@ -224,3 +194,3 @@ paramTypeAnnotation = _unwrapNullable4[0], | ||
const _unwrapNullable5 = unwrapNullable(translateTypeAnnotation(hasteModuleName, getTypeAnnotationReturnType(typeAnnotation, language), types, aliasMap, tryParse, cxxOnly)), | ||
const _unwrapNullable5 = unwrapNullable(translateTypeAnnotation(hasteModuleName, getTypeAnnotationReturnType(typeAnnotation, parser.language()), types, aliasMap, tryParse, cxxOnly, parser)), | ||
_unwrapNullable6 = _slicedToArray(_unwrapNullable5, 2), | ||
@@ -230,3 +200,3 @@ returnTypeAnnotation = _unwrapNullable6[0], | ||
throwIfUnsupportedFunctionReturnTypeAnnotationParserError(hasteModuleName, typeAnnotation, 'FunctionTypeAnnotation', language, cxxOnly, returnTypeAnnotation.type); | ||
throwIfUnsupportedFunctionReturnTypeAnnotationParserError(hasteModuleName, typeAnnotation, 'FunctionTypeAnnotation', parser.language(), cxxOnly, returnTypeAnnotation.type); | ||
return { | ||
@@ -239,2 +209,29 @@ type: 'FunctionTypeAnnotation', | ||
function buildPropertySchema(hasteModuleName, // TODO(T108222691): [TS] Use flow-types for @babel/parser | ||
// TODO(T71778680): [Flow] This is an ObjectTypeProperty containing either: | ||
// - a FunctionTypeAnnotation or GenericTypeAnnotation | ||
// - a NullableTypeAnnoation containing a FunctionTypeAnnotation or GenericTypeAnnotation | ||
// Flow type this node | ||
property, types, aliasMap, tryParse, cxxOnly, resolveTypeAnnotation, translateTypeAnnotation, parser) { | ||
let nullable = false; | ||
let key = property.key, | ||
value = property.value; | ||
const methodName = key.name; | ||
if (parser.language() === 'TypeScript') { | ||
value = property.type === 'TSMethodSignature' ? property : property.typeAnnotation; | ||
} | ||
var _resolveTypeAnnotatio = resolveTypeAnnotation(value, types); | ||
nullable = _resolveTypeAnnotatio.nullable; | ||
value = _resolveTypeAnnotatio.typeAnnotation; | ||
throwIfModuleTypeIsUnsupported(hasteModuleName, property.value, key.name, value.type, parser.language()); | ||
return { | ||
name: methodName, | ||
optional: Boolean(property.optional), | ||
typeAnnotation: wrapNullable(nullable, translateFunctionTypeAnnotation(hasteModuleName, value, types, aliasMap, tryParse, cxxOnly, translateTypeAnnotation, parser)) | ||
}; | ||
} | ||
module.exports = { | ||
@@ -247,5 +244,5 @@ wrapModuleSchema, | ||
parseObjectProperty, | ||
emitUnionTypeAnnotation, | ||
translateDefault, | ||
translateFunctionTypeAnnotation | ||
translateFunctionTypeAnnotation, | ||
buildPropertySchema | ||
}; |
@@ -12,7 +12,25 @@ /** | ||
const _require = require('./parsers-commons'), | ||
assertGenericTypeAnnotationHasExactlyOneTypeParameter = _require.assertGenericTypeAnnotationHasExactlyOneTypeParameter, | ||
wrapNullable = _require.wrapNullable, | ||
translateFunctionTypeAnnotation = _require.translateFunctionTypeAnnotation; | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } | ||
function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
const _require = require('./errors'), | ||
UnsupportedUnionTypeAnnotationParserError = _require.UnsupportedUnionTypeAnnotationParserError; | ||
const _require2 = require('./error-utils'), | ||
throwIfArrayElementTypeAnnotationIsUnsupported = _require2.throwIfArrayElementTypeAnnotationIsUnsupported; | ||
const _require3 = require('./parsers-utils'), | ||
nullGuard = _require3.nullGuard; | ||
const _require4 = require('./parsers-commons'), | ||
assertGenericTypeAnnotationHasExactlyOneTypeParameter = _require4.assertGenericTypeAnnotationHasExactlyOneTypeParameter, | ||
wrapNullable = _require4.wrapNullable, | ||
unwrapNullable = _require4.unwrapNullable, | ||
translateFunctionTypeAnnotation = _require4.translateFunctionTypeAnnotation; | ||
function emitBoolean(nullable) { | ||
@@ -61,8 +79,8 @@ return wrapNullable(nullable, { | ||
function emitFunction(nullable, hasteModuleName, typeAnnotation, types, aliasMap, tryParse, cxxOnly, translateTypeAnnotation, language) { | ||
const translateFunctionTypeAnnotationValue = translateFunctionTypeAnnotation(hasteModuleName, typeAnnotation, types, aliasMap, tryParse, cxxOnly, translateTypeAnnotation, language); | ||
function emitFunction(nullable, hasteModuleName, typeAnnotation, types, aliasMap, tryParse, cxxOnly, translateTypeAnnotation, parser) { | ||
const translateFunctionTypeAnnotationValue = translateFunctionTypeAnnotation(hasteModuleName, typeAnnotation, types, aliasMap, tryParse, cxxOnly, translateTypeAnnotation, parser); | ||
return wrapNullable(nullable, translateFunctionTypeAnnotationValue); | ||
} | ||
function emitMixedTypeAnnotation(nullable) { | ||
function emitMixed(nullable) { | ||
return wrapNullable(nullable, { | ||
@@ -125,7 +143,22 @@ type: 'MixedTypeAnnotation' | ||
function emitPromise(hasteModuleName, typeAnnotation, parser, nullable) { | ||
function emitPromise(hasteModuleName, typeAnnotation, parser, nullable, types, aliasMap, tryParse, cxxOnly, translateTypeAnnotation) { | ||
assertGenericTypeAnnotationHasExactlyOneTypeParameter(hasteModuleName, typeAnnotation, parser); | ||
return wrapNullable(nullable, { | ||
type: 'PromiseTypeAnnotation' | ||
}); | ||
const elementType = typeAnnotation.typeParameters.params[0]; | ||
if (elementType.type === 'ExistsTypeAnnotation' || elementType.type === 'EmptyTypeAnnotation') { | ||
return wrapNullable(nullable, { | ||
type: 'PromiseTypeAnnotation' | ||
}); | ||
} else { | ||
try { | ||
return wrapNullable(nullable, { | ||
type: 'PromiseTypeAnnotation', | ||
elementType: translateTypeAnnotation(hasteModuleName, typeAnnotation.typeParameters.params[0], types, aliasMap, tryParse, cxxOnly, parser) | ||
}); | ||
} catch { | ||
return wrapNullable(nullable, { | ||
type: 'PromiseTypeAnnotation' | ||
}); | ||
} | ||
} | ||
} | ||
@@ -145,3 +178,56 @@ | ||
function emitUnion(nullable, hasteModuleName, typeAnnotation, parser) { | ||
const unionTypes = parser.remapUnionTypeAnnotationMemberNames(typeAnnotation.types); // Only support unionTypes of the same kind | ||
if (unionTypes.length > 1) { | ||
throw new UnsupportedUnionTypeAnnotationParserError(hasteModuleName, typeAnnotation, unionTypes, parser.language()); | ||
} | ||
return wrapNullable(nullable, { | ||
type: 'UnionTypeAnnotation', | ||
memberType: unionTypes[0] | ||
}); | ||
} | ||
function translateArrayTypeAnnotation(hasteModuleName, types, aliasMap, cxxOnly, arrayType, elementType, nullable, translateTypeAnnotation, parser) { | ||
try { | ||
/** | ||
* TODO(T72031674): Migrate all our NativeModule specs to not use | ||
* invalid Array ElementTypes. Then, make the elementType a required | ||
* parameter. | ||
*/ | ||
const _unwrapNullable = unwrapNullable(translateTypeAnnotation(hasteModuleName, elementType, types, aliasMap, | ||
/** | ||
* TODO(T72031674): Ensure that all ParsingErrors that are thrown | ||
* while parsing the array element don't get captured and collected. | ||
* Why? If we detect any parsing error while parsing the element, | ||
* we should default it to null down the line, here. This is | ||
* the correct behaviour until we migrate all our NativeModule specs | ||
* to be parseable. | ||
*/ | ||
nullGuard, cxxOnly, parser)), | ||
_unwrapNullable2 = _slicedToArray(_unwrapNullable, 2), | ||
_elementType = _unwrapNullable2[0], | ||
isElementTypeNullable = _unwrapNullable2[1]; | ||
throwIfArrayElementTypeAnnotationIsUnsupported(hasteModuleName, elementType, arrayType, _elementType.type, parser.language()); | ||
return wrapNullable(nullable, { | ||
type: 'ArrayTypeAnnotation', | ||
// $FlowFixMe[incompatible-call] | ||
elementType: wrapNullable(isElementTypeNullable, _elementType) | ||
}); | ||
} catch (ex) { | ||
return wrapNullable(nullable, { | ||
type: 'ArrayTypeAnnotation' | ||
}); | ||
} | ||
} | ||
function emitArrayType(hasteModuleName, typeAnnotation, parser, types, aliasMap, cxxOnly, nullable, translateTypeAnnotation) { | ||
assertGenericTypeAnnotationHasExactlyOneTypeParameter(hasteModuleName, typeAnnotation, parser); | ||
return translateArrayTypeAnnotation(hasteModuleName, types, aliasMap, cxxOnly, typeAnnotation.type, typeAnnotation.typeParameters.params[0], nullable, translateTypeAnnotation, parser); | ||
} | ||
module.exports = { | ||
emitArrayType, | ||
emitBoolean, | ||
@@ -159,4 +245,6 @@ emitDouble, | ||
emitStringish, | ||
emitMixedTypeAnnotation, | ||
typeAliasResolution | ||
emitMixed, | ||
emitUnion, | ||
typeAliasResolution, | ||
translateArrayTypeAnnotation | ||
}; |
@@ -13,7 +13,5 @@ /** | ||
const TypeScriptParser = require('../../index.js'); | ||
const _require = require('../../parser'), | ||
TypeScriptParser = _require.TypeScriptParser; | ||
const _require = require('../../../utils.js'), | ||
parseFile = _require.parseFile; | ||
const fixtures = require('../__test_fixtures__/fixtures.js'); | ||
@@ -35,6 +33,7 @@ | ||
})); | ||
const parser = new TypeScriptParser(); | ||
describe('RN Codegen TypeScript Parser', () => { | ||
Object.keys(fixtures).sort().forEach(fixtureName => { | ||
it(`can generate fixture ${fixtureName}`, () => { | ||
const schema = parseFile(fixtureName, TypeScriptParser.buildSchema); | ||
const schema = parser.parseFile(fixtureName); | ||
const serializedSchema = JSON.stringify(schema, null, 2).replace(/"/g, "'"); | ||
@@ -47,3 +46,3 @@ expect(serializedSchema).toMatchSnapshot(); | ||
expect(() => { | ||
parseFile(fixtureName, TypeScriptParser.buildSchema); | ||
parser.parseFile(fixtureName); | ||
}).toThrowErrorMatchingSnapshot(); | ||
@@ -50,0 +49,0 @@ }); |
@@ -7,3 +7,3 @@ /** | ||
* | ||
* | ||
* strict | ||
* @format | ||
@@ -14,4 +14,5 @@ */ | ||
const _require = require('../parseTopLevelType'), | ||
parseTopLevelType = _require.parseTopLevelType; | ||
parseTopLevelType = _require.parseTopLevelType; // $FlowFixMe[unclear-type] there's no flowtype for ASTs | ||
function buildCommandSchemaInternal(name, optional, parameters, types) { | ||
@@ -18,0 +19,0 @@ var _firstParam$typeAnnot, _firstParam$typeAnnot2; |
@@ -7,3 +7,3 @@ /** | ||
* | ||
* strict-local | ||
* strict | ||
* @format | ||
@@ -10,0 +10,0 @@ */ |
@@ -7,3 +7,3 @@ /** | ||
* | ||
* strict-local | ||
* strict | ||
* @format | ||
@@ -10,0 +10,0 @@ */ |
@@ -7,3 +7,3 @@ /** | ||
* | ||
* strict-local | ||
* strict | ||
* @format | ||
@@ -10,0 +10,0 @@ */ |
@@ -7,3 +7,3 @@ /** | ||
* | ||
* strict-local | ||
* strict | ||
* @format | ||
@@ -10,0 +10,0 @@ */ |
@@ -7,3 +7,3 @@ /** | ||
* | ||
* strict-local | ||
* strict | ||
* @format | ||
@@ -10,0 +10,0 @@ */ |
@@ -7,3 +7,3 @@ /** | ||
* | ||
* strict-local | ||
* strict | ||
* @format | ||
@@ -10,0 +10,0 @@ */ |
@@ -7,3 +7,3 @@ /** | ||
* | ||
* | ||
* strict | ||
* @format | ||
@@ -13,70 +13,24 @@ */ | ||
const babelParser = require('@babel/parser'); | ||
const fs = require('fs'); | ||
const _require = require('../utils'), | ||
buildSchemaFromConfigType = _require.buildSchemaFromConfigType, | ||
getConfigType = _require.getConfigType, | ||
isModuleRegistryCall = _require.isModuleRegistryCall; | ||
const _require = require('./buildSchema'), | ||
buildSchema = _require.buildSchema; | ||
const _require2 = require('./components'), | ||
buildComponentSchema = _require2.buildComponentSchema; | ||
const _require2 = require('./parser'), | ||
TypeScriptParser = _require2.TypeScriptParser; | ||
const _require3 = require('./components/schema'), | ||
wrapComponentSchema = _require3.wrapComponentSchema; | ||
const parser = new TypeScriptParser(); | ||
const _require4 = require('./modules'), | ||
buildModuleSchema = _require4.buildModuleSchema; | ||
function Visitor(infoMap) { | ||
return { | ||
CallExpression(node) { | ||
if (node.callee.type === 'Identifier' && node.callee.name === 'codegenNativeComponent') { | ||
infoMap.isComponent = true; | ||
} | ||
if (isModuleRegistryCall(node)) { | ||
infoMap.isModule = true; | ||
} | ||
}, | ||
TSInterfaceDeclaration(node) { | ||
if (Array.isArray(node.extends) && node.extends.some(extension => extension.expression.name === 'TurboModule')) { | ||
infoMap.isModule = true; | ||
} | ||
} | ||
}; | ||
} | ||
function buildSchema(contents, filename) { | ||
// Early return for non-Spec JavaScript files | ||
if (!contents.includes('codegenNativeComponent') && !contents.includes('TurboModule')) { | ||
return { | ||
modules: {} | ||
}; | ||
} | ||
const ast = babelParser.parse(contents, { | ||
sourceType: 'module', | ||
plugins: ['typescript'] | ||
}).program; | ||
const configType = getConfigType(ast, Visitor); | ||
return buildSchemaFromConfigType(configType, filename, ast, wrapComponentSchema, buildComponentSchema, buildModuleSchema); | ||
} | ||
function parseModuleFixture(filename) { | ||
const contents = fs.readFileSync(filename, 'utf8'); | ||
return buildSchema(contents, 'path/NativeSampleTurboModule.ts'); | ||
return buildSchema(contents, 'path/NativeSampleTurboModule.ts', parser); | ||
} | ||
function parseString(contents, filename) { | ||
return buildSchema(contents, filename); | ||
return buildSchema(contents, filename, parser); | ||
} | ||
module.exports = { | ||
buildSchema, | ||
parseModuleFixture, | ||
parseString | ||
}; |
@@ -7,3 +7,3 @@ /** | ||
* | ||
* strict-local | ||
* strict | ||
* @format | ||
@@ -27,115 +27,52 @@ */ | ||
const _require = require('../../parsers-utils'), | ||
nullGuard = _require.nullGuard; | ||
const _require = require('../../utils'), | ||
visit = _require.visit, | ||
isModuleRegistryCall = _require.isModuleRegistryCall, | ||
verifyPlatforms = _require.verifyPlatforms; | ||
const _require2 = require('../../utils'), | ||
visit = _require2.visit, | ||
isModuleRegistryCall = _require2.isModuleRegistryCall; | ||
const _require2 = require('../utils'), | ||
resolveTypeAnnotation = _require2.resolveTypeAnnotation, | ||
getTypes = _require2.getTypes; | ||
const _require3 = require('../utils.js'), | ||
resolveTypeAnnotation = _require3.resolveTypeAnnotation, | ||
getTypes = _require3.getTypes; | ||
const _require3 = require('../../parsers-commons'), | ||
parseObjectProperty = _require3.parseObjectProperty, | ||
translateDefault = _require3.translateDefault, | ||
buildPropertySchema = _require3.buildPropertySchema; | ||
const _require4 = require('../../parsers-commons'), | ||
unwrapNullable = _require4.unwrapNullable, | ||
wrapNullable = _require4.wrapNullable, | ||
assertGenericTypeAnnotationHasExactlyOneTypeParameter = _require4.assertGenericTypeAnnotationHasExactlyOneTypeParameter, | ||
parseObjectProperty = _require4.parseObjectProperty, | ||
emitUnionTypeAnnotation = _require4.emitUnionTypeAnnotation, | ||
translateDefault = _require4.translateDefault, | ||
translateFunctionTypeAnnotation = _require4.translateFunctionTypeAnnotation; | ||
const _require4 = require('../../parsers-primitives'), | ||
emitArrayType = _require4.emitArrayType, | ||
emitBoolean = _require4.emitBoolean, | ||
emitDouble = _require4.emitDouble, | ||
emitFloat = _require4.emitFloat, | ||
emitFunction = _require4.emitFunction, | ||
emitNumber = _require4.emitNumber, | ||
emitInt32 = _require4.emitInt32, | ||
emitObject = _require4.emitObject, | ||
emitPromise = _require4.emitPromise, | ||
emitRootTag = _require4.emitRootTag, | ||
emitVoid = _require4.emitVoid, | ||
emitString = _require4.emitString, | ||
emitStringish = _require4.emitStringish, | ||
emitMixed = _require4.emitMixed, | ||
emitUnion = _require4.emitUnion, | ||
typeAliasResolution = _require4.typeAliasResolution, | ||
translateArrayTypeAnnotation = _require4.translateArrayTypeAnnotation; | ||
const _require5 = require('../../parsers-primitives'), | ||
emitBoolean = _require5.emitBoolean, | ||
emitDouble = _require5.emitDouble, | ||
emitFloat = _require5.emitFloat, | ||
emitFunction = _require5.emitFunction, | ||
emitNumber = _require5.emitNumber, | ||
emitInt32 = _require5.emitInt32, | ||
emitObject = _require5.emitObject, | ||
emitPromise = _require5.emitPromise, | ||
emitRootTag = _require5.emitRootTag, | ||
emitVoid = _require5.emitVoid, | ||
emitString = _require5.emitString, | ||
emitStringish = _require5.emitStringish, | ||
emitMixedTypeAnnotation = _require5.emitMixedTypeAnnotation, | ||
typeAliasResolution = _require5.typeAliasResolution; | ||
const _require5 = require('../../errors'), | ||
UnsupportedGenericParserError = _require5.UnsupportedGenericParserError, | ||
UnsupportedTypeAnnotationParserError = _require5.UnsupportedTypeAnnotationParserError, | ||
IncorrectModuleRegistryCallArgumentTypeParserError = _require5.IncorrectModuleRegistryCallArgumentTypeParserError; | ||
const _require6 = require('../../errors.js'), | ||
UnsupportedArrayElementTypeAnnotationParserError = _require6.UnsupportedArrayElementTypeAnnotationParserError, | ||
UnsupportedGenericParserError = _require6.UnsupportedGenericParserError, | ||
UnsupportedTypeAnnotationParserError = _require6.UnsupportedTypeAnnotationParserError, | ||
IncorrectModuleRegistryCallArgumentTypeParserError = _require6.IncorrectModuleRegistryCallArgumentTypeParserError; | ||
const _require6 = require('../../error-utils'), | ||
throwIfUntypedModule = _require6.throwIfUntypedModule, | ||
throwIfUnusedModuleInterfaceParserError = _require6.throwIfUnusedModuleInterfaceParserError, | ||
throwIfModuleInterfaceNotFound = _require6.throwIfModuleInterfaceNotFound, | ||
throwIfModuleInterfaceIsMisnamed = _require6.throwIfModuleInterfaceIsMisnamed, | ||
throwIfWrongNumberOfCallExpressionArgs = _require6.throwIfWrongNumberOfCallExpressionArgs, | ||
throwIfMoreThanOneModuleRegistryCalls = _require6.throwIfMoreThanOneModuleRegistryCalls, | ||
throwIfMoreThanOneModuleInterfaceParserError = _require6.throwIfMoreThanOneModuleInterfaceParserError, | ||
throwIfIncorrectModuleRegistryCallTypeParameterParserError = _require6.throwIfIncorrectModuleRegistryCallTypeParameterParserError; | ||
const _require7 = require('../../utils'), | ||
verifyPlatforms = _require7.verifyPlatforms; | ||
const _require8 = require('../../error-utils'), | ||
throwIfUntypedModule = _require8.throwIfUntypedModule, | ||
throwIfModuleTypeIsUnsupported = _require8.throwIfModuleTypeIsUnsupported, | ||
throwIfUnusedModuleInterfaceParserError = _require8.throwIfUnusedModuleInterfaceParserError, | ||
throwIfModuleInterfaceNotFound = _require8.throwIfModuleInterfaceNotFound, | ||
throwIfModuleInterfaceIsMisnamed = _require8.throwIfModuleInterfaceIsMisnamed, | ||
throwIfWrongNumberOfCallExpressionArgs = _require8.throwIfWrongNumberOfCallExpressionArgs, | ||
throwIfMoreThanOneModuleRegistryCalls = _require8.throwIfMoreThanOneModuleRegistryCalls, | ||
throwIfMoreThanOneModuleInterfaceParserError = _require8.throwIfMoreThanOneModuleInterfaceParserError, | ||
throwIfIncorrectModuleRegistryCallTypeParameterParserError = _require8.throwIfIncorrectModuleRegistryCallTypeParameterParserError; | ||
const _require9 = require('../parser'), | ||
TypeScriptParser = _require9.TypeScriptParser; | ||
const language = 'TypeScript'; | ||
const parser = new TypeScriptParser(); | ||
function translateArrayTypeAnnotation(hasteModuleName, types, aliasMap, cxxOnly, tsArrayType, tsElementType, nullable) { | ||
try { | ||
/** | ||
* TODO(T72031674): Migrate all our NativeModule specs to not use | ||
* invalid Array ElementTypes. Then, make the elementType a required | ||
* parameter. | ||
*/ | ||
const _unwrapNullable = unwrapNullable(translateTypeAnnotation(hasteModuleName, tsElementType, types, aliasMap, | ||
/** | ||
* TODO(T72031674): Ensure that all ParsingErrors that are thrown | ||
* while parsing the array element don't get captured and collected. | ||
* Why? If we detect any parsing error while parsing the element, | ||
* we should default it to null down the line, here. This is | ||
* the correct behaviour until we migrate all our NativeModule specs | ||
* to be parseable. | ||
*/ | ||
nullGuard, cxxOnly)), | ||
_unwrapNullable2 = _slicedToArray(_unwrapNullable, 2), | ||
elementType = _unwrapNullable2[0], | ||
isElementTypeNullable = _unwrapNullable2[1]; | ||
if (elementType.type === 'VoidTypeAnnotation') { | ||
throw new UnsupportedArrayElementTypeAnnotationParserError(hasteModuleName, tsElementType, tsArrayType, 'void', language); | ||
} | ||
if (elementType.type === 'PromiseTypeAnnotation') { | ||
throw new UnsupportedArrayElementTypeAnnotationParserError(hasteModuleName, tsElementType, tsArrayType, 'Promise', language); | ||
} | ||
if (elementType.type === 'FunctionTypeAnnotation') { | ||
throw new UnsupportedArrayElementTypeAnnotationParserError(hasteModuleName, tsElementType, tsArrayType, 'FunctionTypeAnnotation', language); | ||
} // TODO: Added as a work-around for now until TupleTypeAnnotation are fully supported in both flow and TS | ||
// Right now they are partially treated as UnionTypeAnnotation | ||
if (elementType.type === 'UnionTypeAnnotation') { | ||
throw new UnsupportedArrayElementTypeAnnotationParserError(hasteModuleName, tsElementType, tsArrayType, 'UnionTypeAnnotation', language); | ||
} | ||
const finalTypeAnnotation = { | ||
type: 'ArrayTypeAnnotation', | ||
elementType: wrapNullable(isElementTypeNullable, elementType) | ||
}; | ||
return wrapNullable(nullable, finalTypeAnnotation); | ||
} catch (ex) { | ||
return wrapNullable(nullable, { | ||
type: 'ArrayTypeAnnotation' | ||
}); | ||
} | ||
} | ||
function translateTypeAnnotation(hasteModuleName, | ||
@@ -145,3 +82,3 @@ /** | ||
*/ | ||
typeScriptTypeAnnotation, types, aliasMap, tryParse, cxxOnly) { | ||
typeScriptTypeAnnotation, types, aliasMap, tryParse, cxxOnly, parser) { | ||
const _resolveTypeAnnotatio = resolveTypeAnnotation(typeScriptTypeAnnotation, types), | ||
@@ -155,3 +92,3 @@ nullable = _resolveTypeAnnotatio.nullable, | ||
{ | ||
return translateArrayTypeAnnotation(hasteModuleName, types, aliasMap, cxxOnly, 'Array', typeAnnotation.elementType, nullable); | ||
return translateArrayTypeAnnotation(hasteModuleName, types, aliasMap, cxxOnly, 'Array', typeAnnotation.elementType, nullable, translateTypeAnnotation, parser); | ||
} | ||
@@ -162,3 +99,3 @@ | ||
if (typeAnnotation.operator === 'readonly' && typeAnnotation.typeAnnotation.type === 'TSArrayType') { | ||
return translateArrayTypeAnnotation(hasteModuleName, types, aliasMap, cxxOnly, 'ReadonlyArray', typeAnnotation.typeAnnotation.elementType, nullable); | ||
return translateArrayTypeAnnotation(hasteModuleName, types, aliasMap, cxxOnly, 'ReadonlyArray', typeAnnotation.typeAnnotation.elementType, nullable, translateTypeAnnotation, parser); | ||
} else { | ||
@@ -179,3 +116,3 @@ throw new UnsupportedGenericParserError(hasteModuleName, typeAnnotation, parser); | ||
{ | ||
return emitPromise(hasteModuleName, typeAnnotation, parser, nullable); | ||
return emitPromise(hasteModuleName, typeAnnotation, parser, nullable, types, aliasMap, tryParse, cxxOnly, translateTypeAnnotation); | ||
} | ||
@@ -186,4 +123,3 @@ | ||
{ | ||
assertGenericTypeAnnotationHasExactlyOneTypeParameter(hasteModuleName, typeAnnotation, parser); | ||
return translateArrayTypeAnnotation(hasteModuleName, types, aliasMap, cxxOnly, typeAnnotation.type, typeAnnotation.typeParameters.params[0], nullable); | ||
return emitArrayType(hasteModuleName, typeAnnotation, parser, types, aliasMap, cxxOnly, nullable, translateTypeAnnotation); | ||
} | ||
@@ -226,2 +162,16 @@ | ||
{ | ||
// if there is TSIndexSignature, then it is a dictionary | ||
if (typeAnnotation.members) { | ||
const indexSignatures = typeAnnotation.members.filter(member => member.type === 'TSIndexSignature'); | ||
if (indexSignatures.length > 0) { | ||
// check the property type to prevent developers from using unsupported types | ||
// the return value from `translateTypeAnnotation` is unused | ||
const propertyType = indexSignatures[0].typeAnnotation; | ||
translateTypeAnnotation(hasteModuleName, propertyType, types, aliasMap, tryParse, cxxOnly, parser); // no need to do further checking | ||
return emitObject(nullable); | ||
} | ||
} | ||
const objectTypeAnnotation = { | ||
@@ -261,3 +211,3 @@ type: 'ObjectTypeAnnotation', | ||
{ | ||
return emitFunction(nullable, hasteModuleName, typeAnnotation, types, aliasMap, tryParse, cxxOnly, translateTypeAnnotation, language); | ||
return emitFunction(nullable, hasteModuleName, typeAnnotation, types, aliasMap, tryParse, cxxOnly, translateTypeAnnotation, parser); | ||
} | ||
@@ -267,3 +217,3 @@ | ||
{ | ||
return emitUnionTypeAnnotation(nullable, hasteModuleName, typeAnnotation, parser); | ||
return emitUnion(nullable, hasteModuleName, typeAnnotation, parser); | ||
} | ||
@@ -274,3 +224,3 @@ | ||
if (cxxOnly) { | ||
return emitMixedTypeAnnotation(nullable); | ||
return emitMixed(nullable); | ||
} // Fallthrough | ||
@@ -287,25 +237,8 @@ | ||
function buildPropertySchema(hasteModuleName, // TODO(T108222691): Use flow-types for @babel/parser | ||
property, types, aliasMap, tryParse, cxxOnly) { | ||
let nullable = false; | ||
let key = property.key; | ||
let value = property.type === 'TSMethodSignature' ? property : property.typeAnnotation; | ||
const methodName = key.name; | ||
function isModuleInterface(node) { | ||
var _node$extends; | ||
var _resolveTypeAnnotatio2 = resolveTypeAnnotation(value, types); | ||
nullable = _resolveTypeAnnotatio2.nullable; | ||
value = _resolveTypeAnnotatio2.typeAnnotation; | ||
throwIfModuleTypeIsUnsupported(hasteModuleName, property.value, property.key.name, value.type, language); | ||
return { | ||
name: methodName, | ||
optional: Boolean(property.optional), | ||
typeAnnotation: wrapNullable(nullable, translateFunctionTypeAnnotation(hasteModuleName, value, types, aliasMap, tryParse, cxxOnly, translateTypeAnnotation, language)) | ||
}; | ||
return node.type === 'TSInterfaceDeclaration' && ((_node$extends = node.extends) === null || _node$extends === void 0 ? void 0 : _node$extends.length) === 1 && node.extends[0].type === 'TSExpressionWithTypeArguments' && node.extends[0].expression.name === 'TurboModule'; | ||
} | ||
function isModuleInterface(node) { | ||
return node.type === 'TSInterfaceDeclaration' && node.extends.length === 1 && node.extends[0].type === 'TSExpressionWithTypeArguments' && node.extends[0].expression.name === 'TurboModule'; | ||
} | ||
function buildModuleSchema(hasteModuleName, | ||
@@ -315,3 +248,3 @@ /** | ||
*/ | ||
ast, tryParse) { | ||
ast, tryParse, parser) { | ||
const types = getTypes(ast); | ||
@@ -325,5 +258,5 @@ const moduleSpecs = Object.values(types).filter(isModuleInterface); | ||
throwIfModuleInterfaceIsMisnamed(hasteModuleName, moduleSpec.id, language); // Parse Module Names | ||
throwIfModuleInterfaceIsMisnamed(hasteModuleName, moduleSpec.id, language); // Parse Module Name | ||
const moduleName = tryParse(() => { | ||
const moduleName = (() => { | ||
const callExpressions = []; | ||
@@ -354,4 +287,3 @@ visit(ast, { | ||
return $moduleName; | ||
}); | ||
const moduleNames = moduleName == null ? [] : [moduleName]; // Some module names use platform suffix to indicate platform-exclusive modules. | ||
})(); // Some module names use platform suffix to indicate platform-exclusive modules. | ||
// Eventually this should be made explicit in the Flow type itself. | ||
@@ -361,3 +293,4 @@ // Also check the hasteModuleName for platform suffix. | ||
const _verifyPlatforms = verifyPlatforms(hasteModuleName, moduleNames), | ||
const _verifyPlatforms = verifyPlatforms(hasteModuleName, moduleName), | ||
cxxOnly = _verifyPlatforms.cxxOnly, | ||
@@ -371,3 +304,3 @@ excludedPlatforms = _verifyPlatforms.excludedPlatforms; // $FlowFixMe[missing-type-arg] | ||
aliasMap: aliasMap, | ||
propertyShape: buildPropertySchema(hasteModuleName, property, types, aliasMap, tryParse, cxxOnly) | ||
propertyShape: buildPropertySchema(hasteModuleName, property, types, aliasMap, tryParse, cxxOnly, resolveTypeAnnotation, translateTypeAnnotation, parser) | ||
})); | ||
@@ -384,3 +317,3 @@ }).filter(Boolean).reduce((moduleSchema, { | ||
}, | ||
moduleNames: moduleSchema.moduleNames, | ||
moduleName: moduleSchema.moduleName, | ||
excludedPlatforms: moduleSchema.excludedPlatforms | ||
@@ -394,3 +327,3 @@ }; | ||
}, | ||
moduleNames: moduleNames, | ||
moduleName: moduleName, | ||
excludedPlatforms: excludedPlatforms.length !== 0 ? [...excludedPlatforms] : undefined | ||
@@ -397,0 +330,0 @@ }); |
@@ -14,5 +14,10 @@ /** | ||
const _require = require('../errors'), | ||
UnsupportedObjectPropertyTypeAnnotationParserError = _require.UnsupportedObjectPropertyTypeAnnotationParserError; | ||
const _require = require('./buildSchema'), | ||
buildSchema = _require.buildSchema; | ||
const fs = require('fs'); | ||
const _require2 = require('../errors'), | ||
UnsupportedObjectPropertyTypeAnnotationParserError = _require2.UnsupportedObjectPropertyTypeAnnotationParserError; | ||
class TypeScriptParser { | ||
@@ -23,13 +28,12 @@ constructor() { | ||
getKeyName(propertyOrIndex, hasteModuleName) { | ||
switch (propertyOrIndex.type) { | ||
case 'TSPropertySignature': | ||
return propertyOrIndex.key.name; | ||
isProperty(property) { | ||
return property.type === 'TSPropertySignature'; | ||
} | ||
case 'TSIndexSignature': | ||
return propertyOrIndex.parameters[0].name; | ||
getKeyName(property, hasteModuleName) { | ||
if (!this.isProperty(property)) { | ||
throw new UnsupportedObjectPropertyTypeAnnotationParserError(hasteModuleName, property, property.type, this.language()); | ||
} | ||
default: | ||
throw new UnsupportedObjectPropertyTypeAnnotationParserError(hasteModuleName, propertyOrIndex, propertyOrIndex.type, this.language()); | ||
} | ||
return property.key.name; | ||
} | ||
@@ -69,2 +73,7 @@ | ||
parseFile(filename) { | ||
const contents = fs.readFileSync(filename, 'utf8'); | ||
return buildSchema(contents, filename, this); | ||
} | ||
} | ||
@@ -71,0 +80,0 @@ |
@@ -7,3 +7,3 @@ /** | ||
* | ||
* strict-local | ||
* strict | ||
* @format | ||
@@ -10,0 +10,0 @@ */ |
@@ -7,3 +7,3 @@ /** | ||
* | ||
* strict-local | ||
* strict | ||
* @format | ||
@@ -10,0 +10,0 @@ */ |
@@ -26,4 +26,2 @@ /** | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
@@ -58,6 +56,6 @@ | ||
function verifyPlatforms(hasteModuleName, moduleNames) { | ||
function verifyPlatforms(hasteModuleName, moduleName) { | ||
let cxxOnly = false; | ||
const excludedPlatforms = new Set(); | ||
const namesToValidate = [...moduleNames, hasteModuleName]; | ||
const namesToValidate = [moduleName, hasteModuleName]; | ||
namesToValidate.forEach(name => { | ||
@@ -85,7 +83,2 @@ if (name.endsWith('Android')) { | ||
}; | ||
} | ||
function parseFile(filename, callback) { | ||
const contents = fs.readFileSync(filename, 'utf8'); | ||
return callback(contents, filename); | ||
} // TODO(T108222691): Use flow-types for @babel/parser | ||
@@ -115,3 +108,3 @@ | ||
function buildSchemaFromConfigType(configType, filename, ast, wrapComponentSchema, buildComponentSchema, buildModuleSchema) { | ||
function buildSchemaFromConfigType(configType, filename, ast, wrapComponentSchema, buildComponentSchema, buildModuleSchema, parser) { | ||
switch (configType) { | ||
@@ -136,3 +129,3 @@ case 'component': | ||
const schema = tryParse(() => buildModuleSchema(nativeModuleName, ast, tryParse)); | ||
const schema = tryParse(() => buildModuleSchema(nativeModuleName, ast, tryParse, parser)); | ||
@@ -218,3 +211,2 @@ if (parsingErrors.length > 0) { | ||
verifyPlatforms, | ||
parseFile, | ||
visit, | ||
@@ -221,0 +213,0 @@ buildSchemaFromConfigType, |
{ | ||
"name": "react-native-tscodegen", | ||
"version": "0.71.1", | ||
"version": "0.72.0", | ||
"description": "TypeScript Code Generation for React Native Turbo Module", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
648895
104
16061
7