-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
fix: Add objectParser for ObjectTypeAnnotation (e.g. PARSE_SERVER_AUTH_PROVIDERS) #9912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: alpha
Are you sure you want to change the base?
Changes from 10 commits
996205b
81b88f1
d794856
c72fff6
69875a2
8224a93
55e2001
7ddc932
cca3608
8d9e578
b35f5d5
8ea3f4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -155,8 +155,10 @@ function mapperFor(elt, t) { | |
| return wrap(t.identifier('objectParser')); | ||
| } else if (t.isBooleanTypeAnnotation(elt)) { | ||
| return wrap(t.identifier('booleanParser')); | ||
| } else if (t.isObjectTypeAnnotation(elt)) { | ||
| return wrap(t.identifier('objectParser')); | ||
| } else if (t.isGenericTypeAnnotation(elt)) { | ||
| const type = elt.typeAnnotation.id.name; | ||
| const type = elt.id.name; | ||
| if (type == 'Adapter') { | ||
| return wrap(t.identifier('moduleOrObjectParser')); | ||
| } | ||
|
|
@@ -372,12 +374,18 @@ This code has been generated by resources/buildConfigDefinitions.js | |
| Do not edit manually, but update Options/index.js | ||
| `; | ||
|
|
||
| const babel = require('@babel/core'); | ||
| const res = babel.transformFileSync('./src/Options/index.js', { | ||
| plugins: [plugin, '@babel/transform-flow-strip-types'], | ||
| babelrc: false, | ||
| auxiliaryCommentBefore, | ||
| sourceMaps: false, | ||
| }); | ||
| require('fs').writeFileSync('./src/Options/Definitions.js', res.code + '\n'); | ||
| require('fs').writeFileSync('./src/Options/docs.js', docs); | ||
| // Only run the transformation when executed directly, not when imported by tests | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the reason for this change?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mattia1208 friendly ping
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mtrezza for me it wasn’t necessary, it was requested by coderabbitai. |
||
| if (require.main === module) { | ||
| const babel = require('@babel/core'); | ||
| const res = babel.transformFileSync('./src/Options/index.js', { | ||
| plugins: [plugin, '@babel/transform-flow-strip-types'], | ||
| babelrc: false, | ||
| auxiliaryCommentBefore, | ||
| sourceMaps: false, | ||
| }); | ||
| require('fs').writeFileSync('./src/Options/Definitions.js', res.code + '\n'); | ||
| require('fs').writeFileSync('./src/Options/docs.js', docs); | ||
| } | ||
|
|
||
| // Export mapperFor for testing | ||
| module.exports = { mapperFor }; | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| const t = require('@babel/types'); | ||
| const { mapperFor } = require('../resources/buildConfigDefinitions'); | ||
|
|
||
| describe('buildConfigDefinitions', () => { | ||
| describe('mapperFor', () => { | ||
| it('should return objectParser for ObjectTypeAnnotation', () => { | ||
| const mockElement = { | ||
| type: 'ObjectTypeAnnotation', | ||
| }; | ||
|
|
||
| const result = mapperFor(mockElement, t); | ||
|
|
||
| expect(t.isMemberExpression(result)).toBe(true); | ||
| expect(result.object.name).toBe('parsers'); | ||
| expect(result.property.name).toBe('objectParser'); | ||
| }); | ||
|
|
||
| it('should return objectParser for AnyTypeAnnotation', () => { | ||
| const mockElement = { | ||
| type: 'AnyTypeAnnotation', | ||
| }; | ||
|
|
||
| const result = mapperFor(mockElement, t); | ||
|
|
||
| expect(t.isMemberExpression(result)).toBe(true); | ||
| expect(result.object.name).toBe('parsers'); | ||
| expect(result.property.name).toBe('objectParser'); | ||
| }); | ||
|
|
||
| it('should return arrayParser for ArrayTypeAnnotation', () => { | ||
| const mockElement = { | ||
| type: 'ArrayTypeAnnotation', | ||
| }; | ||
|
|
||
| const result = mapperFor(mockElement, t); | ||
|
|
||
| expect(t.isMemberExpression(result)).toBe(true); | ||
| expect(result.object.name).toBe('parsers'); | ||
| expect(result.property.name).toBe('arrayParser'); | ||
| }); | ||
|
|
||
| it('should return booleanParser for BooleanTypeAnnotation', () => { | ||
| const mockElement = { | ||
| type: 'BooleanTypeAnnotation', | ||
| }; | ||
|
|
||
| const result = mapperFor(mockElement, t); | ||
|
|
||
| expect(t.isMemberExpression(result)).toBe(true); | ||
| expect(result.object.name).toBe('parsers'); | ||
| expect(result.property.name).toBe('booleanParser'); | ||
| }); | ||
|
|
||
| it('should return numberParser call expression for NumberTypeAnnotation', () => { | ||
| const mockElement = { | ||
| type: 'NumberTypeAnnotation', | ||
| name: 'testNumber', | ||
| }; | ||
|
|
||
| const result = mapperFor(mockElement, t); | ||
|
|
||
| expect(t.isCallExpression(result)).toBe(true); | ||
| expect(result.callee.property.name).toBe('numberParser'); | ||
| expect(result.arguments[0].value).toBe('testNumber'); | ||
| }); | ||
|
|
||
| it('should return moduleOrObjectParser for Adapter GenericTypeAnnotation', () => { | ||
| const mockElement = { | ||
| type: 'GenericTypeAnnotation', | ||
| id: { | ||
| name: 'Adapter', | ||
| }, | ||
| }; | ||
|
|
||
| const result = mapperFor(mockElement, t); | ||
|
|
||
| expect(t.isMemberExpression(result)).toBe(true); | ||
| expect(result.object.name).toBe('parsers'); | ||
| expect(result.property.name).toBe('moduleOrObjectParser'); | ||
| }); | ||
|
|
||
| it('should return numberOrBooleanParser for NumberOrBoolean GenericTypeAnnotation', () => { | ||
| const mockElement = { | ||
| type: 'GenericTypeAnnotation', | ||
| id: { | ||
| name: 'NumberOrBoolean', | ||
| }, | ||
| }; | ||
|
|
||
| const result = mapperFor(mockElement, t); | ||
|
|
||
| expect(t.isMemberExpression(result)).toBe(true); | ||
| expect(result.object.name).toBe('parsers'); | ||
| expect(result.property.name).toBe('numberOrBooleanParser'); | ||
| }); | ||
|
|
||
| it('should return numberOrStringParser call expression for NumberOrString GenericTypeAnnotation', () => { | ||
| const mockElement = { | ||
| type: 'GenericTypeAnnotation', | ||
| name: 'testString', | ||
| id: { | ||
| name: 'NumberOrString', | ||
| }, | ||
| }; | ||
|
|
||
| const result = mapperFor(mockElement, t); | ||
|
|
||
| expect(t.isCallExpression(result)).toBe(true); | ||
| expect(result.callee.property.name).toBe('numberOrStringParser'); | ||
| expect(result.arguments[0].value).toBe('testString'); | ||
| }); | ||
|
|
||
| it('should return arrayParser for StringOrStringArray GenericTypeAnnotation', () => { | ||
| const mockElement = { | ||
| type: 'GenericTypeAnnotation', | ||
| id: { | ||
| name: 'StringOrStringArray', | ||
| }, | ||
| }; | ||
|
|
||
| const result = mapperFor(mockElement, t); | ||
|
|
||
| expect(t.isMemberExpression(result)).toBe(true); | ||
| expect(result.object.name).toBe('parsers'); | ||
| expect(result.property.name).toBe('arrayParser'); | ||
| }); | ||
|
|
||
| it('should return objectParser for unknown GenericTypeAnnotation', () => { | ||
| const mockElement = { | ||
| type: 'GenericTypeAnnotation', | ||
| id: { | ||
| name: 'UnknownType', | ||
| }, | ||
| }; | ||
|
|
||
| const result = mapperFor(mockElement, t); | ||
|
|
||
| expect(t.isMemberExpression(result)).toBe(true); | ||
| expect(result.object.name).toBe('parsers'); | ||
| expect(result.property.name).toBe('objectParser'); | ||
| }); | ||
| }); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.