-
Notifications
You must be signed in to change notification settings - Fork 645
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for
const
type parameters
Summary: Add support for `const` type parameters. Reviewed By: panagosg7 Differential Revision: D67406406 fbshipit-source-id: ee1b0d9238ab1b7cfa3f2d862c3b2115a591e10b
- Loading branch information
1 parent
e28fd47
commit 3dc760e
Showing
2 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
tools/hermes-parser/js/prettier-plugin-hermes-parser/__tests__/const-type-param-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/** | ||
* 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. | ||
* | ||
* @flow strict-local | ||
* @format | ||
*/ | ||
|
||
// $FlowExpectedError[cannot-resolve-module] | ||
import prettierConfig from '../../.prettierrc.json'; | ||
|
||
import * as prettier from 'prettier'; | ||
|
||
function format(code: string) { | ||
const options = { | ||
...prettierConfig, | ||
parser: 'hermes', | ||
requirePragma: false, | ||
plugins: [require('../src/index.js')], | ||
}; | ||
return prettier.format(code, options); | ||
} | ||
|
||
describe(`'const' type parameters`, () => { | ||
test('type', async () => { | ||
expect( | ||
format(` | ||
type T<const X> = X; | ||
`), | ||
).toMatchInlineSnapshot(` | ||
"type T<const X> = X; | ||
" | ||
`); | ||
}); | ||
|
||
test('function: basic', async () => { | ||
expect( | ||
format(` | ||
function f<const T>(): void {} | ||
`), | ||
).toMatchInlineSnapshot(` | ||
"function f<const T>(): void {} | ||
" | ||
`); | ||
}); | ||
|
||
test('function: with variance', async () => { | ||
expect( | ||
format(` | ||
function f<const +T>(): void {} | ||
`), | ||
).toMatchInlineSnapshot(` | ||
"function f<const +T>(): void {} | ||
" | ||
`); | ||
}); | ||
|
||
test('arrow: basic', async () => { | ||
expect( | ||
format(` | ||
<const T>(x: T) => {} | ||
`), | ||
).toMatchInlineSnapshot(` | ||
"<const T>(x: T) => {}; | ||
" | ||
`); | ||
}); | ||
|
||
test('arrow: with variance', async () => { | ||
expect( | ||
format(` | ||
<const +T>(x: T) => {} | ||
`), | ||
).toMatchInlineSnapshot(` | ||
"<const +T>(x: T) => {}; | ||
" | ||
`); | ||
}); | ||
|
||
test('class: basic', async () => { | ||
expect( | ||
format(` | ||
class C<const T>{} | ||
`), | ||
).toMatchInlineSnapshot(` | ||
"class C<const T> {} | ||
" | ||
`); | ||
}); | ||
|
||
test('class: with variance', async () => { | ||
expect( | ||
format(` | ||
class C<const T>{} | ||
`), | ||
).toMatchInlineSnapshot(` | ||
"class C<const T> {} | ||
" | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters