File tree Expand file tree Collapse file tree 3 files changed +34
-3
lines changed Expand file tree Collapse file tree 3 files changed +34
-3
lines changed Original file line number Diff line number Diff line change 3558
3558
[argc method-params]
3559
3559
(boolean (some #{argc} (map count method-params))))
3560
3560
3561
+ (defn- record-tag?
3562
+ [tag]
3563
+ (boolean (and (symbol? tag)
3564
+ (some? (namespace tag))
3565
+ (get-in @env/*compiler* [::namespaces (symbol (namespace tag)) :defs (symbol (name tag)) :record ]))))
3566
+
3567
+ (defn- record-basis
3568
+ [tag]
3569
+ (let [positional-factory (symbol (str " ->" (name tag)))
3570
+ fields (first (get-in @env/*compiler* [::namespaces (symbol (namespace tag)) :defs positional-factory :method-params ]))]
3571
+ (into #{} fields)))
3572
+
3573
+ (defn- record-with-field?
3574
+ [tag field]
3575
+ (and (record-tag? tag)
3576
+ (contains? (record-basis tag) field)))
3577
+
3561
3578
(defn parse-invoke*
3562
3579
[env [f & args :as form]]
3563
3580
(let [enve (assoc env :context :expr )
3611
3628
~@(if bind-args? arg-syms args)))))
3612
3629
(let [ana-expr #(analyze enve %)
3613
3630
argexprs (mapv ana-expr args)]
3614
- {:env env :op :invoke :form form :fn fexpr :args argexprs
3615
- :children [:fn :args ]}))))
3631
+ (if (and (and (keyword? f)
3632
+ (nil? (namespace f)))
3633
+ (== 1 (count args))
3634
+ (record-with-field? (:tag (first argexprs)) (symbol (name f))))
3635
+ (let [field-access-form (list* (symbol (str " .-" (name f))) args)]
3636
+ (analyze env field-access-form))
3637
+ {:env env :op :invoke :form form :fn fexpr :args argexprs
3638
+ :children [:fn :args ]})))))
3616
3639
3617
3640
(defn parse-invoke
3618
3641
[env form]
Original file line number Diff line number Diff line change 34
34
(declare ^{:arglists '([a b])} declared-fn )
35
35
36
36
(declared-fn 1 2 )
37
+
38
+ (defrecord Foo [foo-field-a foo-field-b])
39
+
40
+ (def foo-record (->Foo 1 2 ))
41
+
42
+ (:foo-field-a foo-record)
Original file line number Diff line number Diff line change 281
281
(is (re-find #"(?m)^.*var .*=.*inv_arg1.cljs.core.IFn._invoke.arity.0 \? .*$"
282
282
content))
283
283
; ; CLJS-1871: A declare hinted with :arglists meta should result in static dispatch
284
- (is (str/includes? content " cljs.invoke_test.declared_fn(" )))))
284
+ (is (str/includes? content " cljs.invoke_test.declared_fn(" ))
285
+ ; ; CLJS-2950: Direct field access for keyword lookup on records
286
+ (is (str/includes? content " cljs.invoke_test.foo_record.foo_field_a;" )))))
285
287
#_(test-vars [#'test-optimized-invoke-emit])
286
288
287
289
; ; CLJS-1225
You can’t perform that action at this time.
0 commit comments