Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save remitbri/ef0ad6ae5f89ecc86dbba269ba1bc97e to your computer and use it in GitHub Desktop.
Save remitbri/ef0ad6ae5f89ecc86dbba269ba1bc97e to your computer and use it in GitHub Desktop.

@rescript/react 0.13.1 deprecates the usage of ReactDOM.Style.make. Depending on your codebase, the refacto may be important. Here's a method to help you migrate:

1 - Install Comby

2 - Download the config.toml config file to, say, the root of your repo

3 - Run comby -config conf.toml -f .res -matcher .re -i -d src (if your rescript codebase is in the src directory)

4 - Correct manually the type error(s). It's likely there are instances where the compiler doesn't have enough context to detect for example that the record {color: black} is of type JsxDOMStyle.t

5 - Run rescript format -all for good measure

[pattern-1]
match = "let :[name] = ReactDOM.Style.make(:[args])"
rewrite = "let :[name]: JsxDOMStyle.t = ReactDOM.Style.make(:[args])"
[pattern-2]
match = "ReactDOM.Style.make(:[args])"
rewrite = "ReactDOM.Style.make({:[args]})"
rule = '''
where
rewrite :[args] {
"~:[[mmm]]?,"
-> "~:[mmm]=?:[mmm],"
},
rewrite :[args] {
"~:[[mmm]],"
-> "~:[mmm]=:[mmm],"
}
'''
[pattern-3]
match = "ReactDOM.Style.make(:[args])"
rewrite = "ReactDOM.Style.make(:[args])"
rule = '''
where
rewrite :[args] {
"~:[[k]]=:[v],"
-> ":[k]: :[v],"
}
'''
[pattern-4]
match = "ReactDOM.Style.make(:[args])"
rewrite = "ReactDOM.Style.make(:[args])"
rule = '''
where
rewrite :[args] {
""
-> "{}"
}
'''
[pattern-5]
match = "ReactDOM.Style.make(:[args])"
rewrite = ":[args]"
rule = '''
where
rewrite :[args] {
":[~,\s*\(\)]"
-> ""
}
'''
[pattern-6]
match = "style={{:[args]}}"
rewrite = "style={:[args]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment