Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcf6e681

Browse files
committed
Added CSS modules because I could lol
1 parent78c602b commitcf6e681

File tree

6 files changed

+227
-0
lines changed

6 files changed

+227
-0
lines changed

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _test.js
88
_test.d.ts
99
_test.re
1010
_test.graphql
11+
_test.css
1112
.merlin
1213
lib/retyped_node.js
1314
lib/bs

‎bindings/csstree.re‎

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
moduleInternal= {
2+
moduleType= {
3+
letanPlusB="AnPlusB";
4+
letatrule="Atrule";
5+
letatrulePrelude="AtrulePrelude";
6+
letattributeSelector="AttributeSelector";
7+
letblock="Block";
8+
letbrackets="Brackets";
9+
letcdc="CDC";
10+
letcdo="CDO";
11+
letclassSelector="ClassSelector";
12+
letcombinator="Combinator";
13+
letcomment="Comment";
14+
letdeclaration="Declaration";
15+
letdeclarationList="DeclarationList";
16+
letdimension="Dimension";
17+
letfunction_="Function";
18+
lethexColor="HexColor";
19+
letidentifier="Identifier";
20+
letidSelector="IdSelector";
21+
letmediaFeature="MediaFeature";
22+
letmediaQuery="MediaQuery";
23+
letmediaQueryList="MediaQueryList";
24+
letnth="Nth";
25+
letnumber="Number";
26+
letoperator="Operator";
27+
letparentheses="Parentheses";
28+
letpercentage="Percentage";
29+
letpseudoClassSelector="PseudoClassSelector";
30+
letpseudoElementSelector="PseudoElementSelector";
31+
letratio="Ratio";
32+
letraw="Raw";
33+
letrule="Rule";
34+
letselector="Selector";
35+
letselectorList="SelectorList";
36+
letstring="String";
37+
letstyleSheet="StyleSheet";
38+
lettypeSelector="TypeSelector";
39+
letunicodeRange="UnicodeRange";
40+
leturl="Url";
41+
letvalue="Value";
42+
letwhiteSpace="WhiteSpace";
43+
};
44+
typenode= {. "type":string};
45+
typeast;
46+
[@bs.module"css-tree"]externalparse:string =>ast="";
47+
[@bs.module"css-tree"]externaltoPlainObject:ast =>node="";
48+
};
49+
50+
typepoint= {
51+
offset:int,
52+
line:int,
53+
column:int
54+
};
55+
56+
typeloc= {
57+
source:string,
58+
start:point,
59+
end_:point
60+
};
61+
62+
typestyleSheet= {
63+
loc:option(loc),
64+
children:array(node)
65+
}
66+
andrule= {
67+
loc:option(loc),
68+
prelude:node,
69+
block:node
70+
}
71+
and selectorList = {
72+
loc: option(loc),
73+
children: array(node)
74+
}
75+
and selector= {
76+
loc: option(loc),
77+
children: array(node)
78+
}
79+
and classSelector= {
80+
loc: option(loc),
81+
name: string
82+
}
83+
and node=
84+
|StyleSheet(styleSheet)
85+
|Rule(rule)
86+
|SelectorList(selectorList)
87+
|Selector(selector)
88+
|ClassSelector(classSelector)
89+
|Unknown(string);
90+
91+
moduleDecoder= {
92+
letpoint= json=>
93+
Json.Decode.{
94+
offset: json|> field("offset", int),
95+
line: json|> field("line", int),
96+
column: json|> field("column", int)
97+
};
98+
letloc= json=>
99+
Json.Decode.{
100+
source: json|> field("source", string),
101+
start: json|> field("start", point),
102+
end_: json|> field("end", point)
103+
};
104+
externalnodeToJson:Internal.node =>Js.Json.t="%identity";
105+
letrecdecoders=[
106+
(Internal.Type.styleSheet, styleSheet),
107+
(Internal.Type.rule, rule),
108+
(Internal.Type.selectorList, selectorList),
109+
(Internal.Type.selector, selector),
110+
(Internal.Type.classSelector, classSelector)
111+
]
112+
andnode= json=> {
113+
letkind= json|>Json.Decode.field("type",Json.Decode.string);
114+
letdecoder=
115+
try (List.assoc(kind, decoders)) {
116+
|_=> unknown
117+
};
118+
decoder(json);
119+
}
120+
andstyleSheet= json=>
121+
StyleSheet(
122+
Json.Decode.{
123+
children: json|> field("children", array(node)),
124+
loc: json|> optional(field("loc", loc))
125+
}
126+
)
127+
andrule= json=>
128+
Rule(
129+
Json.Decode.{
130+
loc: json|> optional(field("loc", loc)),
131+
prelude: json|> field("prelude", node),
132+
block: json|> field("block", node)
133+
}
134+
)
135+
andselectorList= json=>
136+
SelectorList(
137+
Json.Decode.{
138+
loc: json|> optional(field("loc", loc)),
139+
children: json|> field("children", array(node))
140+
}
141+
)
142+
andselector= json=>
143+
Selector(
144+
Json.Decode.{
145+
loc: json|> optional(field("loc", loc)),
146+
children: json|> field("children", array(node))
147+
}
148+
)
149+
andclassSelector= json=>
150+
ClassSelector(
151+
Json.Decode.{
152+
loc: json|> optional(field("loc", loc)),
153+
name: json|> field("name", string)
154+
}
155+
)
156+
andunknown= json=> {
157+
letkind=Json.Decode.field("type",Json.Decode.string, json);
158+
Unknown(kind);
159+
};
160+
letdecode= cssNode=> {
161+
letjson= nodeToJson(cssNode);
162+
node(json);
163+
};
164+
};
165+
166+
letparse= (_fileName:string, source:string)=> {
167+
letast=Internal.parse(source);
168+
letastObj=Internal.toPlainObject(ast);
169+
Decoder.decode(astObj);
170+
};

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"@glennsl/bs-json":"^1.1.2",
3232
"babel-code-frame":"^6.26.0",
3333
"chalk":"^2.1.0",
34+
"css-tree":"^1.0.0-alpha.28",
3435
"graphql":"^0.13.2",
3536
"meow":"^3.7.0",
3637
"reason":"^3.0.0",

‎src/compiler.re‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ module Stage = {
3131
|"graphql"=>[
3232
Graphql.parse(name, source)|>GraphqlBsType.graphqlAstToBsTypeAst
3333
]
34+
|"css"=>[
35+
Csstree.parse(name, source)|>CssBsType.cssAstToBsTypeAst(name)
36+
]
3437
|_=>[]
3538
};
3639
};

‎src/cssBsType.re‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
letselectorChildrenToBsTypeAst=
2+
fun
3+
|Csstree.ClassSelector(classSelector)=>[
4+
BsTypeAst.VarDecl(classSelector.name,BsTypeAst.String)
5+
]
6+
|_=>[];
7+
8+
letselectorToBsTypeAst=
9+
fun
10+
|Csstree.Selector(selector)=>
11+
selector.children
12+
|>Array.to_list
13+
|>List.map(selectorChildrenToBsTypeAst)
14+
|>List.flatten
15+
|_=>[];
16+
17+
letselectorListToBsTypeAst=
18+
fun
19+
|Csstree.SelectorList(selectorList)=>
20+
selectorList.children
21+
|>Array.to_list
22+
|>List.map(selectorToBsTypeAst)
23+
|>List.flatten
24+
|_=>[];
25+
26+
letruleToBsTypeAst=
27+
fun
28+
|Csstree.Rule(rule)=> selectorListToBsTypeAst(rule.prelude)
29+
|_=>[];
30+
31+
letcssAstToBsTypeAst= fileName=>
32+
fun
33+
|Csstree.StyleSheet(sheet)=>
34+
BsTypeAst.ModuleDecl(
35+
fileName,
36+
sheet.children
37+
|>Array.to_list
38+
|>List.map(ruleToBsTypeAst)
39+
|>List.flatten
40+
)
41+
|_=>BsTypeAst.Noop;

‎yarn.lock‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,13 @@ crypto-browserify@^3.0.0:
11891189
randombytes "^2.0.0"
11901190
randomfill "^1.0.3"
11911191

1192+
css-tree@^1.0.0-alpha.28:
1193+
version "1.0.0-alpha.28"
1194+
resolved "https://registry.yarnpkg.com/css-tree/-/css-tree-1.0.0-alpha.28.tgz#8e8968190d886c9477bc8d61e96f61af3f7ffa7f"
1195+
dependencies:
1196+
mdn-data "~1.1.0"
1197+
source-map "^0.5.3"
1198+
11921199
cssom@0.3.x, "cssom@>= 0.3.2 < 0.4.0":
11931200
version "0.3.2"
11941201
resolved "https://registry.yarnpkg.com/cssom/-/cssom-0.3.2.tgz#b8036170c79f07a90ff2f16e22284027a243848b"
@@ -2617,6 +2624,10 @@ md5.js@^1.3.4:
26172624
hash-base "^3.0.0"
26182625
inherits "^2.0.1"
26192626

2627+
mdn-data@~1.1.0:
2628+
version "1.1.0"
2629+
resolved "https://registry.yarnpkg.com/mdn-data/-/mdn-data-1.1.0.tgz#a7056319da95a2d0881267d7263075042eb061e2"
2630+
26202631
mem@^1.1.0:
26212632
version "1.1.0"
26222633
resolved "https://registry.yarnpkg.com/mem/-/mem-1.1.0.tgz#5edd52b485ca1d900fe64895505399a0dfa45f76"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp