-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
normalize-jsx.ts
63 lines (58 loc) · 1.61 KB
/
normalize-jsx.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* @file Utilities - normalizeJsx
* @module tsconfig-utils/utils/normalizeJsx
*/
import { JsxEmit } from '@flex-development/tsconfig-types'
import { cast, type Optional } from '@flex-development/tutils'
import ts from 'typescript'
/**
* Converts the given `option` into a **programmatic** [`jsx`][1] value.
*
* TypeScript programs expect a {@linkcode ts.JsxEmit} value.
*
* If the `option` is already programmatic, it will be returned unmodified. If
* it cannot be converted, `undefined` will be returned instead.
*
* [1]: https://www.typescriptlang.org/tsconfig#jsx
*
* @param {unknown} option - Option to evaluate
* @return {Optional<ts.JsxEmit>} `ts.JsxEmit` value or `undefined`
*/
const normalizeJsx = (option: unknown): Optional<ts.JsxEmit> => {
/**
* TypeScript program compiler option value, if any.
*
* @var {Optional<ts.JsxEmit>} ret
*/
let ret: Optional<ts.JsxEmit>
// normalize user compiler option
switch (cast<JsxEmit | ts.JsxEmit>(option)) {
case ts.JsxEmit.None:
ret = ts.JsxEmit.None
break
case JsxEmit.Preserve:
case ts.JsxEmit.Preserve:
ret = ts.JsxEmit.Preserve
break
case JsxEmit.React:
case ts.JsxEmit.React:
ret = ts.JsxEmit.React
break
case JsxEmit.ReactJSX:
case ts.JsxEmit.ReactJSX:
ret = ts.JsxEmit.ReactJSX
break
case JsxEmit.ReactJSXDev:
case ts.JsxEmit.ReactJSXDev:
ret = ts.JsxEmit.ReactJSXDev
break
case JsxEmit.ReactNative:
case ts.JsxEmit.ReactNative:
ret = ts.JsxEmit.ReactNative
break
default:
break
}
return ret
}
export default normalizeJsx