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
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | const astUtil = require('./ast');
|
---|
4 |
|
---|
5 | /**
|
---|
6 | * Checks if the node is a React.createContext call
|
---|
7 | * @param {ASTNode} node - The AST node being checked.
|
---|
8 | * @returns {boolean} - True if node is a React.createContext call, false if not.
|
---|
9 | */
|
---|
10 | module.exports = function isCreateContext(node) {
|
---|
11 | if (
|
---|
12 | node.init
|
---|
13 | && node.init.callee
|
---|
14 | ) {
|
---|
15 | if (
|
---|
16 | astUtil.isCallExpression(node.init)
|
---|
17 | && node.init.callee.name === 'createContext'
|
---|
18 | ) {
|
---|
19 | return true;
|
---|
20 | }
|
---|
21 |
|
---|
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 | }
|
---|
29 | }
|
---|
30 |
|
---|
31 | if (
|
---|
32 | node.expression
|
---|
33 | && node.expression.type === 'AssignmentExpression'
|
---|
34 | && node.expression.operator === '='
|
---|
35 | && astUtil.isCallExpression(node.expression.right)
|
---|
36 | && node.expression.right.callee
|
---|
37 | ) {
|
---|
38 | const right = node.expression.right;
|
---|
39 |
|
---|
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 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | return false;
|
---|
54 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.