|
1033 | 1033 | "Given a foreign js property list, return a resolved js property list and the |
1034 | 1034 | extern var info" |
1035 | 1035 | ([pre externs] |
1036 | | - (resolve-extern pre externs externs {:resolved [] :info nil})) |
| 1036 | + (resolve-extern pre externs externs {:resolved []})) |
1037 | 1037 | ([pre externs top ret] |
1038 | 1038 | (cond |
1039 | 1039 | (empty? pre) ret |
|
1044 | 1044 | (not me) nil |
1045 | 1045 | :else |
1046 | 1046 | (let [[x' externs'] me |
1047 | | - info' (meta x')] |
| 1047 | + info' (meta x') |
| 1048 | + ret (cond-> ret |
| 1049 | + ;; we only care about var info for the last property |
| 1050 | + ;; also if we already added it, don't override it |
| 1051 | + ;; because we're now resolving type information |
| 1052 | + ;; not instance information anymore |
| 1053 | + ;; i.e. [console] -> [Console] but :tag is Console _not_ Function vs. |
| 1054 | + ;; [console log] -> [Console prototype log] where :tag is Function |
| 1055 | + (and (empty? (next pre)) |
| 1056 | + (not (contains? ret :info))) |
| 1057 | + (assoc :info info'))] |
1048 | 1058 | (if (and (:ctor info') (= 'Function (:tag info'))) |
1049 | 1059 | (or |
1050 | 1060 | ;; then check for "static" property |
1051 | 1061 | (resolve-extern (next pre) externs' top |
1052 | | - (-> ret |
1053 | | - (update :resolved conj x) |
1054 | | - (assoc :info info'))) |
1055 | | - |
1056 | | - ;; first look for a property on the prototype |
1057 | | - (resolve-extern (into '[prototype] (next pre)) externs' top |
1058 | | - (-> ret |
1059 | | - (update :resolved conj x) |
1060 | | - (assoc :info nil))) |
1061 | | - |
1062 | | - ;; finally check the super class if there is one |
1063 | | - (when-let [super (:super info')] |
1064 | | - (resolve-extern (into [super] (next pre)) externs top |
1065 | | - (-> ret |
1066 | | - (assoc :resolved []) |
1067 | | - (assoc :info nil))))) |
| 1062 | + (update ret :resolved conj x)) |
| 1063 | + |
| 1064 | + ;; first look for a property on the prototype |
| 1065 | + (resolve-extern (into '[prototype] (next pre)) externs' top |
| 1066 | + (update ret :resolved conj x)) |
| 1067 | + |
| 1068 | + ;; finally check the super class if there is one |
| 1069 | + (when-let [super (:super info')] |
| 1070 | + (resolve-extern (into [super] (next pre)) externs top |
| 1071 | + (assoc ret :resolved [])))) |
1068 | 1072 |
|
1069 | 1073 | (or |
1070 | 1074 | ;; If the tag isn't Function or undefined, |
1071 | 1075 | ;; try to resolve it similar to the super case above |
1072 | 1076 | (let [tag (:tag info')] |
1073 | 1077 | (when (and tag (not (contains? '#{Function undefined} tag))) |
1074 | 1078 | (resolve-extern (into [tag] (next pre)) externs top |
1075 | | - (-> ret |
1076 | | - (assoc :resolved []) |
1077 | | - (assoc :info nil))))) |
| 1079 | + (assoc ret :resolved [])))) |
1078 | 1080 |
|
1079 | 1081 | ;; assume static property |
1080 | 1082 | (recur (next pre) externs' top |
1081 | | - (-> ret |
1082 | | - (update :resolved conj x) |
1083 | | - (assoc :info info'))))))))))) |
| 1083 | + (update ret :resolved conj x)))))))))) |
1084 | 1084 |
|
1085 | 1085 | (defn has-extern?* |
1086 | 1086 | [pre externs] |
|
1101 | 1101 | ([pre tag-type externs] |
1102 | 1102 | (js-tag pre tag-type externs externs)) |
1103 | 1103 | ([pre tag-type externs top] |
1104 | | - (when-let [[p externs' :as me] (find externs (first pre))] |
1105 | | - (let [tag (-> p meta tag-type)] |
1106 | | - (if (= (count pre) 1) |
1107 | | - (when tag (symbol "js" (str (alias->type tag tag)))) |
1108 | | - (or (js-tag (next pre) tag-type externs' top) |
1109 | | - (js-tag (into '[prototype] (next pre)) tag-type (get top tag) top))))))) |
| 1104 | + (when-let [tag (get-in (resolve-extern pre externs) [:info tag-type])] |
| 1105 | + (symbol "js" (str (alias->type tag tag)))))) |
1110 | 1106 |
|
1111 | 1107 | (defn dotted-symbol? [sym] |
1112 | 1108 | (let [s (str sym)] |
|
0 commit comments