| 1 |
import { declare } from "@babel/helper-plugin-utils"; |
| 2 |
import syntaxOptionalChaining from "@babel/plugin-syntax-optional-chaining"; |
| 3 |
import { transform } from "./transform"; |
| 4 |
import type { NodePath } from "@babel/traverse"; |
| 5 |
import type * as t from "@babel/types"; |
| 6 |
|
| 7 |
export interface Options { |
| 8 |
loose?: boolean; |
| 9 |
} |
| 10 |
export default declare((api, options: Options) => { |
| 11 |
api.assertVersion(7); |
| 12 |
|
| 13 |
const { loose = false } = options; |
| 14 |
const noDocumentAll = api.assumption("noDocumentAll") ?? loose; |
| 15 |
const pureGetters = api.assumption("pureGetters") ?? loose; |
| 16 |
|
| 17 |
return { |
| 18 |
name: "proposal-optional-chaining", |
| 19 |
inherits: syntaxOptionalChaining.default, |
| 20 |
|
| 21 |
visitor: { |
| 22 |
"OptionalCallExpression|OptionalMemberExpression"( |
| 23 |
path: NodePath<t.OptionalCallExpression | t.OptionalMemberExpression>, |
| 24 |
) { |
| 25 |
transform(path, { noDocumentAll, pureGetters }); |
| 26 |
}, |
| 27 |
}, |
| 28 |
}; |
| 29 |
}); |
| 30 |
|
| 31 |
export { transform }; |