ClojureScript

Warn on reference to js/foo shadowed by local binding

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Trivial Trivial
  • Resolution: Completed
  • Affects Version/s: 1.9.76
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Environment:
    OS X

Description

When a local binding shadows a JS global, and an attempt is made to access said global with js/foo, it would be nice to get a warning indicating that the global is inaccessible.

Example:

(defn simple-repro []
  (let [location (str js/location.pathname)]
    location))

Per discussion in Clojurians Slack, this is the same issue as http://dev.clojure.org/jira/browse/CLJS-833.

The previous issue was closed because the suggested solution was inadequate, but per discussion it seems appropriate to provide a warning so it is less surprising.

Activity

Hide
Dan Johansson added a comment -

Testing this on ClojureScript 1.10.439 only gives me warnings in the letfn case

cljs.user=> (letfn [(parseInt [s] (js/parseInt s))] (parseInt "123"))
WARNING: js/parseInt is shadowed by a local at line 1 <cljs repl>
RangeError: Maximum call stack size exceeded

cljs.user=> (let [parseInt (fn [s] (js/parseInt s))] (parseInt "123"))
RangeError: Maximum call stack size exceeded

Show
Dan Johansson added a comment - Testing this on ClojureScript 1.10.439 only gives me warnings in the letfn case cljs.user=> (letfn [(parseInt [s] (js/parseInt s))] (parseInt "123")) WARNING: js/parseInt is shadowed by a local at line 1 <cljs repl> RangeError: Maximum call stack size exceeded cljs.user=> (let [parseInt (fn [s] (js/parseInt s))] (parseInt "123")) RangeError: Maximum call stack size exceeded

People

Vote (1)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: