-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
97 lines (79 loc) · 2.36 KB
/
index.js
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
const d = require('./directives');
const p = require('./directives/prefix');
const Directive = require('./directives/enum');
const { hasDirective, hasPartialDirective } = require('./utils');
function directiveParser(_, opts) {
if (opts.prefix && opts.prefix !== p.defaultPrefix) {
if (/^(\$|[a-z])+$/.test(opts.prefix)) {
p.setPrefix(opts.prefix);
} else {
throw new SyntaxError(
'Prefix option for Babel plugin react-jsx-directives' +
'should consist of one or more lowercase characters (including `$` character)'
);
}
}
if (typeof opts.prefixSeparation !== 'undefined' && opts.prefixSeparation !== p.defaultPrefixSeparation) {
p.setPrefixSeparation(!!opts.prefixSeparation);
}
return {
name: 'react-jsx-directives',
visitor: {
JSXElement(path, state) {
if (hasDirective(path.node, Directive.IF)) {
d.transformIfDirective(path, state);
return;
}
if (hasDirective(path.node, Directive.FOR)) {
d.transformForDirective(path, state);
return;
}
if (hasDirective(path.node, Directive.SWITCH)) {
d.transformSwitchDirective(path, state);
return;
}
if (hasDirective(path.node, Directive.CLASS)) {
d.transformClassDirective(path, state);
return;
}
if (hasPartialDirective(path.node, Directive.CLASS)) {
d.transformPartialClassDirective(path, state);
return;
}
if (hasPartialDirective(path.node, Directive.STYLE)) {
d.transformPartialStyleDirective(path, state);
return;
}
if (hasDirective(path.node, Directive.PARAMS)) {
d.transformParamsDirective(path, state);
return;
}
if (hasDirective(path.node, Directive.DYNAMIC_PROP)) {
d.transformDynamicPropDirective(path, state);
return;
}
if (hasDirective(path.node, Directive.DYNAMIC_EVENT)) {
d.transformDynamicEventDirective(path, state);
return;
}
if (hasDirective(path.node, Directive.SHOW)) {
d.transformShowDirective(path, state);
return;
}
if (hasDirective(path.node, Directive.HIDE)) {
d.transformHideDirective(path, state);
return;
}
if (hasDirective(path.node, Directive.HIDDEN)) {
d.transformHiddenDirective(path, state);
return;
}
if (hasDirective(path.node, Directive.MODEL)) {
d.transformModelDirective(path, state);
return;
}
}
}
};
}
module.exports = directiveParser;