js2coffee
Version:
JavaScript to CoffeeScript compiler
51 lines (38 loc) • 1.02 kB
text/coffeescript
TransformerBase = require('./base')
###
# Mangles the AST with various CoffeeScript tweaks.
###
module.exports = class extends TransformerBase
BinaryExpression: (node) ->
###
# Updates equals to their CoffeeScript equivalents.
###
updateEquals: (node) ->
dict =
'===': '=='
'!==': '!='
op = node.operator
if dict[op] then node.operator = dict[op]
node
escapeEqualsForCompatibility: (node) ->
isIncompatible =
node.operator is '==' or
node.operator is '!='
if @options.compat and isIncompatible
else
node
###
# Fire warnings when '==' is used
###
warnAboutEquals: (node) ->
op = node.operator
replacements = { '==': '===', '!=': '!==' }
if op is '==' or op is '!='
repl = replacements[op]
"use '#{repl}' instead"
node