|
138 | 138 | :ns-var-clash true
|
139 | 139 | :extend-type-invalid-method-shape true
|
140 | 140 | :unsupported-js-module-type true
|
141 |
| - :unsupported-preprocess-value true}) |
| 141 | + :unsupported-preprocess-value true |
| 142 | + :js-shadowed-by-local true}) |
142 | 143 |
|
143 | 144 | (def js-reserved
|
144 | 145 | #{"arguments" "abstract" "boolean" "break" "byte" "case"
|
|
409 | 410 | (str "Unsupported preprocess value " preprocess " for foreign library "
|
410 | 411 | file "."))
|
411 | 412 |
|
| 413 | +(defmethod error-message :js-shadowed-by-local |
| 414 | + [warning-type {:keys [name]}] |
| 415 | + (str name " is shadowed by a local")) |
| 416 | + |
412 | 417 | (defn default-warning-handler [warning-type env extra]
|
413 | 418 | (when (warning-type *cljs-warnings*)
|
414 | 419 | (when-let [s (error-message warning-type extra)]
|
|
740 | 745 | warnings about unresolved vars."
|
741 | 746 | ([env sym] (resolve-var env sym nil))
|
742 | 747 | ([env sym confirm]
|
| 748 | + (let [locals (:locals env)] |
743 | 749 | (if #?(:clj (= "js" (namespace sym))
|
744 | 750 | :cljs (identical? "js" (namespace sym)))
|
745 |
| - {:name sym :ns 'js} |
746 |
| - (let [s (str sym) |
747 |
| - lcls (:locals env) |
748 |
| - lb (get lcls sym)] |
| 751 | + (do |
| 752 | + (when (contains? locals (-> sym name symbol)) |
| 753 | + (warning :js-shadowed-by-local env {:name sym})) |
| 754 | + {:name sym :ns 'js}) |
| 755 | + (let [s (str sym) |
| 756 | + lb (get locals sym)] |
749 | 757 | (cond
|
750 | 758 | (not (nil? lb)) lb
|
751 | 759 |
|
|
771 | 779 | (let [idx (.indexOf s ".")
|
772 | 780 | prefix (symbol (subs s 0 idx))
|
773 | 781 | suffix (subs s (inc idx))
|
774 |
| - lb (get lcls prefix)] |
| 782 | + lb (get locals prefix)] |
775 | 783 | (if-not (nil? lb)
|
776 | 784 | {:name (symbol (str (:name lb)) suffix)}
|
777 | 785 | (let [cur-ns (-> env :ns :name)
|
|
816 | 824 | (confirm env full-ns sym))
|
817 | 825 | (merge (gets @env/*compiler* ::namespaces full-ns :defs sym)
|
818 | 826 | {:name (symbol (str full-ns) (str sym))
|
819 |
| - :ns full-ns}))))))) |
| 827 | + :ns full-ns})))))))) |
820 | 828 |
|
821 | 829 | (defn resolve-existing-var
|
822 | 830 | "Given env, an analysis environment, and sym, a symbol, resolve an existing var.
|
|
0 commit comments