This repository was archived by the owner on Jan 2, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +32
-14
lines changed Expand file tree Collapse file tree 3 files changed +32
-14
lines changed Original file line number Diff line number Diff line change 1
1
(ns foo )
2
2
3
- (js/console.log " hello" )
4
- (js/console.log (+ 1 2 3 ))
3
+ (def log js /console.log )
5
4
6
- (let [x (do (js/console.log " in do" )
7
- 12 )]
8
- (js/console.log " x + 1 =" (inc x)))
5
+ (log " hello" )
6
+ (log (+ 1 2 3 ))
7
+
8
+ (let [y (let [x (do (log " in do" )
9
+ 12 )]
10
+ (log " x + 1 =" (inc x))
11
+ (+ x 13 ))]
12
+ (log " y =" y))
Original file line number Diff line number Diff line change 1
- console . log ( "hello" ) ;
2
- console . log ( ( 1 + 2 + 3 ) ) ;
3
- ( function ( ) { const x = ( function ( ) { console . log ( "in do" ) ;
1
+ const log = console . log ;
2
+ ;
3
+ log ( "hello" ) ;
4
+ log ( ( 1 + 2 + 3 ) ) ;
5
+ ( function ( ) { const y = ( function ( ) { const x = ( function ( ) { log ( "in do" ) ;
4
6
return 12 ; } ) ( ) ;
5
- return ( function ( ) { return console . log ( "x + 1 =" , ( x + 1 ) ) ; } ) ( ) ; } ) ( ) ;
7
+ return ( function ( ) { log ( "x + 1 =" , ( x + 1 ) ) ;
8
+ return ( x + 13 ) ; } ) ( ) ; } ) ( ) ;
9
+ return ( function ( ) { return log ( "y =" , y ) ; } ) ( ) ; } ) ( ) ;
Original file line number Diff line number Diff line change 73
73
(str (name expr)))
74
74
75
75
(defmethod emit clojure.lang.Symbol [expr]
76
- (when-not (valid-symbol? (str expr))
77
- (#' throwf " %s is not a valid javascript symbol" expr))
78
- (str expr))
76
+ (let [expr (if (and (qualified-symbol? expr)
77
+ (= " js" (namespace expr)))
78
+ (name expr)
79
+ expr)]
80
+ (when-not (valid-symbol? (str expr))
81
+ (#' throwf " %s is not a valid javascript symbol" expr))
82
+ (str expr)))
79
83
80
84
(defmethod emit java.util.regex.Pattern [expr]
81
85
(str \/ expr \/))
87
91
'return 'delete 'new 'do 'aget 'while 'doseq
88
92
'str 'inc! 'dec! 'dec 'inc 'defined? 'and 'or
89
93
'? 'try 'break
90
- 'await 'const 'defn 'let 'ns]))
94
+ 'await 'const 'defn 'let 'ns 'def ]))
91
95
92
96
(def prefix-unary-operators (set ['!]))
93
97
138
142
(partition 2 more))
139
143
(repeat statement-separator))))
140
144
141
- (defmethod emit-special ' const [_type [const & more] ]
145
+ (defn emit-const [more]
142
146
(apply str (interleave (map (fn [[name expr]]
143
147
(str " const " (emit name) " = " (emit expr)))
144
148
(partition 2 more))
145
149
(repeat statement-separator))))
146
150
151
+ (defmethod emit-special 'const [_type [_const & more]]
152
+ (emit-const more))
153
+
154
+ (defmethod emit-special 'def [_type [_const & more]]
155
+ (emit-const more))
156
+
147
157
(declare emit-do )
148
158
149
159
(defn wrap-await [s]
You can’t perform that action at this time.
0 commit comments