@@ -9,12 +9,12 @@ export function inspectProcessTailwindFeaturesReturnContext(content: string) {
9
9
FunctionDeclaration ( p ) {
10
10
const n = p . node
11
11
if ( n . id ?. name === 'processTailwindFeatures' ) {
12
- if ( n . body . body . length === 1 && n . body . body [ 0 ] . type === 'ReturnStatement' ) {
12
+ if ( n . body . body . length === 1 && t . isReturnStatement ( n . body . body [ 0 ] ) ) {
13
13
const rts = n . body . body [ 0 ]
14
14
if ( t . isFunctionExpression ( rts . argument ) ) {
15
15
const body = rts . argument . body . body
16
16
const lastStatement = body [ body . length - 1 ]
17
- hasPatched = lastStatement . type === 'ReturnStatement' && lastStatement . argument ?. type === 'Identifier' && lastStatement . argument . name === 'context'
17
+ hasPatched = t . isReturnStatement ( lastStatement ) && t . isIdentifier ( lastStatement . argument ) && lastStatement . argument . name === 'context'
18
18
if ( ! hasPatched ) {
19
19
// return context;
20
20
const rts = t . returnStatement ( t . identifier ( 'context' ) )
@@ -41,28 +41,30 @@ export function inspectPostcssPlugin(content: string) {
41
41
traverse ( ast , {
42
42
Program ( p ) {
43
43
const n = p . node
44
+ // find module.exports = function tailwindcss(configOrPath)
44
45
const idx = n . body . findIndex ( ( x ) => {
45
46
return (
46
- x . type === 'ExpressionStatement' &&
47
- x . expression . type === 'AssignmentExpression' &&
48
- x . expression . left . type === 'MemberExpression' &&
49
- x . expression . right . type === 'FunctionExpression' &&
47
+ t . isExpressionStatement ( x ) &&
48
+ t . isAssignmentExpression ( x . expression ) &&
49
+ t . isMemberExpression ( x . expression . left ) &&
50
+ t . isFunctionExpression ( x . expression . right ) &&
50
51
x . expression . right . id ?. name === 'tailwindcss'
51
52
)
52
53
} )
54
+
53
55
if ( idx > - 1 ) {
54
56
const prevStatement = n . body [ idx - 1 ]
55
57
const lastStatement = n . body [ n . body . length - 1 ]
56
58
const hasPatchedCondition0 =
57
59
prevStatement &&
58
- prevStatement . type === 'VariableDeclaration' &&
60
+ t . isVariableDeclaration ( prevStatement ) &&
59
61
prevStatement . declarations . length === 1 &&
60
- prevStatement . declarations [ 0 ] . id . type === 'Identifier' &&
62
+ t . isIdentifier ( prevStatement . declarations [ 0 ] . id ) &&
61
63
prevStatement . declarations [ 0 ] . id . name === variableName
62
64
const hasPatchedCondition1 =
63
- lastStatement . type === 'ExpressionStatement' &&
64
- lastStatement . expression . type === 'AssignmentExpression' &&
65
- lastStatement . expression . right . type === 'Identifier' &&
65
+ t . isExpressionStatement ( lastStatement ) &&
66
+ t . isAssignmentExpression ( lastStatement . expression ) &&
67
+ t . isIdentifier ( lastStatement . expression . right ) &&
66
68
lastStatement . expression . right . name === variableName
67
69
68
70
hasPatched = hasPatchedCondition0 || hasPatchedCondition1
@@ -93,26 +95,26 @@ export function inspectPostcssPlugin(content: string) {
93
95
}
94
96
const n = p . node
95
97
if ( n . id ?. name === 'tailwindcss' ) {
96
- if ( n . body . body . length === 1 && n . body . body [ 0 ] . type === 'ReturnStatement' ) {
98
+ if ( n . body . body . length === 1 && t . isReturnStatement ( n . body . body [ 0 ] ) ) {
97
99
const returnStatement = n . body . body [ 0 ]
98
- if ( returnStatement . argument ?. type === 'ObjectExpression' && returnStatement . argument . properties . length === 2 ) {
100
+ if ( t . isObjectExpression ( returnStatement . argument ) && returnStatement . argument . properties . length === 2 ) {
99
101
const properties = returnStatement . argument . properties
100
- if ( properties [ 0 ] . type === 'ObjectProperty' && properties [ 1 ] . type === 'ObjectProperty' ) {
101
- const keyMatched = properties [ 0 ] . key . type === 'Identifier' && properties [ 0 ] . key . name === 'postcssPlugin'
102
- const pluginsMatched = properties [ 1 ] . key . type === 'Identifier' && properties [ 1 ] . key . name === 'plugins'
102
+ if ( t . isObjectProperty ( properties [ 0 ] ) && t . isObjectProperty ( properties [ 1 ] ) ) {
103
+ const keyMatched = t . isIdentifier ( properties [ 0 ] . key ) && properties [ 0 ] . key . name === 'postcssPlugin'
104
+ const pluginsMatched = t . isIdentifier ( properties [ 1 ] . key ) && properties [ 1 ] . key . name === 'plugins'
103
105
if (
104
106
pluginsMatched &&
105
107
keyMatched &&
106
- properties [ 1 ] . value . type === 'CallExpression' &&
107
- properties [ 1 ] . value . callee . type === 'MemberExpression' &&
108
- properties [ 1 ] . value . callee . object . type === 'ArrayExpression'
108
+ t . isCallExpression ( properties [ 1 ] . value ) &&
109
+ t . isMemberExpression ( properties [ 1 ] . value . callee ) &&
110
+ t . isArrayExpression ( properties [ 1 ] . value . callee . object )
109
111
) {
110
112
const pluginsCode = properties [ 1 ] . value . callee . object . elements
111
- if ( pluginsCode [ 1 ] && pluginsCode [ 1 ] . type === 'FunctionExpression' ) {
113
+ if ( pluginsCode [ 1 ] && t . isFunctionExpression ( pluginsCode [ 1 ] ) ) {
112
114
const targetBlockStatement = pluginsCode [ 1 ] . body
113
115
114
116
const lastStatement = targetBlockStatement . body [ targetBlockStatement . body . length - 1 ]
115
- if ( lastStatement . type === 'ExpressionStatement' ) {
117
+ if ( t . isExpressionStatement ( lastStatement ) ) {
116
118
// contextRef.value.push((0, _processTailwindFeatures.default)(context)(root, result));
117
119
const newExpressionStatement = t . expressionStatement (
118
120
t . callExpression (
@@ -128,14 +130,14 @@ export function inspectPostcssPlugin(content: string) {
128
130
targetBlockStatement . body [ targetBlockStatement . body . length - 1 ] = newExpressionStatement
129
131
}
130
132
131
- const ifIdx = targetBlockStatement . body . findIndex ( ( x ) => x . type === 'IfStatement' )
133
+ const ifIdx = targetBlockStatement . body . findIndex ( ( x ) => t . isIfStatement ( x ) )
132
134
if ( ifIdx > - 1 ) {
133
135
const ifRoot = < t . IfStatement > targetBlockStatement . body [ ifIdx ]
134
- if ( ifRoot . consequent . type === 'BlockStatement' && ifRoot . consequent . body [ 1 ] && ifRoot . consequent . body [ 1 ] . type === 'ForOfStatement' ) {
136
+ if ( t . isBlockStatement ( ifRoot . consequent ) && ifRoot . consequent . body [ 1 ] && t . isForOfStatement ( ifRoot . consequent . body [ 1 ] ) ) {
135
137
const forOf : t . ForOfStatement = ifRoot . consequent . body [ 1 ]
136
- if ( forOf . body . type === 'BlockStatement' && forOf . body . body . length === 1 && forOf . body . body [ 0 ] . type === 'IfStatement' ) {
138
+ if ( t . isBlockStatement ( forOf . body ) && forOf . body . body . length === 1 && t . isIfStatement ( forOf . body . body [ 0 ] ) ) {
137
139
const if2 : t . IfStatement = forOf . body . body [ 0 ]
138
- if ( if2 . consequent . type === 'BlockStatement' && if2 . consequent . body . length === 1 && if2 . consequent . body [ 0 ] . type === 'ExpressionStatement' ) {
140
+ if ( t . isBlockStatement ( if2 . consequent ) && if2 . consequent . body . length === 1 && t . isExpressionStatement ( if2 . consequent . body [ 0 ] ) ) {
139
141
const target = if2 . consequent . body [ 0 ]
140
142
// contextRef.value.push((0, _processTailwindFeatures.default)(context)(root1, result));
141
143
const newExpressionStatement = t . expressionStatement (
0 commit comments