main
Last change
on this file since 0c6b92a was 0c6b92a, checked in by stefan toskovski <stefantoska84@…>, 5 weeks ago |
Pred finalna verzija
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
[0c6b92a] | 3 | const astUtil = require('./ast');
|
---|
| 4 |
|
---|
[d565449] | 5 | /**
|
---|
| 6 | * Checks if the node is a React.createContext call
|
---|
| 7 | * @param {ASTNode} node - The AST node being checked.
|
---|
[0c6b92a] | 8 | * @returns {boolean} - True if node is a React.createContext call, false if not.
|
---|
[d565449] | 9 | */
|
---|
| 10 | module.exports = function isCreateContext(node) {
|
---|
| 11 | if (
|
---|
| 12 | node.init
|
---|
| 13 | && node.init.callee
|
---|
| 14 | ) {
|
---|
[0c6b92a] | 15 | if (
|
---|
| 16 | astUtil.isCallExpression(node.init)
|
---|
| 17 | && node.init.callee.name === 'createContext'
|
---|
| 18 | ) {
|
---|
| 19 | return true;
|
---|
| 20 | }
|
---|
[d565449] | 21 |
|
---|
[0c6b92a] | 22 | if (
|
---|
| 23 | node.init.callee.type === 'MemberExpression'
|
---|
| 24 | && node.init.callee.property
|
---|
| 25 | && node.init.callee.property.name === 'createContext'
|
---|
| 26 | ) {
|
---|
| 27 | return true;
|
---|
| 28 | }
|
---|
[d565449] | 29 | }
|
---|
| 30 |
|
---|
| 31 | if (
|
---|
| 32 | node.expression
|
---|
| 33 | && node.expression.type === 'AssignmentExpression'
|
---|
| 34 | && node.expression.operator === '='
|
---|
[0c6b92a] | 35 | && astUtil.isCallExpression(node.expression.right)
|
---|
[d565449] | 36 | && node.expression.right.callee
|
---|
| 37 | ) {
|
---|
[0c6b92a] | 38 | const right = node.expression.right;
|
---|
[d565449] | 39 |
|
---|
[0c6b92a] | 40 | if (right.callee.name === 'createContext') {
|
---|
| 41 | return true;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | if (
|
---|
| 45 | right.callee.type === 'MemberExpression'
|
---|
| 46 | && right.callee.property
|
---|
| 47 | && right.callee.property.name === 'createContext'
|
---|
| 48 | ) {
|
---|
| 49 | return true;
|
---|
| 50 | }
|
---|
[d565449] | 51 | }
|
---|
| 52 |
|
---|
| 53 | return false;
|
---|
| 54 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.