From c6939d3fcaf70ad5c12ef55ef2a8939bacd611ba Mon Sep 17 00:00:00 2001 From: Austin Sanders Date: Wed, 27 Jun 2018 15:11:29 -0700 Subject: [PATCH 1/2] Adds use strict. Fixes canjs/canjs#4217 --- all.js | 1 + base/base.js | 1 + build.js | 1 + cache-requests/cache-requests.js | 1 + can-connect.js | 1 + can/base-map/base-map.js | 1 + .../constructor-hydrate.js | 1 + can/map/make-real-time-super-model.js | 1 + can/map/test-real-time-super-model.js | 1 + can/merge/merge.js | 1 + can/ref/ref.js | 1 + can/super-map/super-map.js | 1 + can/tag/tag.js | 1 + connect.js | 1 + constructor/callbacks-once/callbacks-once.js | 1 + constructor/constructor.js | 2 + constructor/store/store.js | 1 + data/callbacks-cache/callbacks-cache.js | 1 + data/callbacks/callbacks.js | 1 + data/combine-requests/combine-requests.js | 1 + data/localstorage-cache/localstorage-cache.js | 1 + data/memory-cache/memory-cache.js | 1 + data/parse/parse.js | 7 +-- data/url/url.js | 45 ++++++++++--------- data/worker/demo/todo_connection.js | 1 + data/worker/worker.js | 1 + docs/hooks.js | 1 + fall-through-cache/fall-through-cache.js | 1 + helpers/clone-data.js | 1 + helpers/deferred.js | 1 + helpers/deparam.js | 1 + helpers/get-id-props.js | 1 + helpers/get-index-by-id.js | 1 + helpers/get-items.js | 1 + helpers/id-merge.js | 1 + helpers/map-deep-merge.js | 1 + helpers/overwrite.js | 1 + helpers/poly-weak-set.js | 1 + helpers/remove-element.js | 1 + helpers/set-add.js | 1 + helpers/sorted-set-json.js | 1 + helpers/validate.js | 1 + helpers/weak-reference-map.js | 1 + helpers/weak-reference-set.js | 1 + real-time/real-time.js | 1 + service-worker/service-worker-main.js | 1 + service-worker/service-worker.js | 1 + test-helpers.js | 1 + 48 files changed, 74 insertions(+), 25 deletions(-) diff --git a/all.js b/all.js index 9f12b529..c797caa4 100644 --- a/all.js +++ b/all.js @@ -1,3 +1,4 @@ +"use strict"; var connect = require("./can-connect"); connect.cacheRequests = require("./cache-requests/cache-requests"); diff --git a/base/base.js b/base/base.js index 938c68b5..794126a8 100644 --- a/base/base.js +++ b/base/base.js @@ -1,3 +1,4 @@ +"use strict"; var connect = require("can-connect/connect"); /** * @module can-connect/base/base base diff --git a/build.js b/build.js index c75557ae..922a2558 100644 --- a/build.js +++ b/build.js @@ -1,3 +1,4 @@ +"use strict"; var stealTools = require("steal-tools"); var path = require("path"); var fs = require("fs"); diff --git a/cache-requests/cache-requests.js b/cache-requests/cache-requests.js index befb45a2..e3c796c1 100644 --- a/cache-requests/cache-requests.js +++ b/cache-requests/cache-requests.js @@ -1,3 +1,4 @@ +"use strict"; var connect = require("can-connect"); var getItems = require("can-connect/helpers/get-items"); var canSet = require("can-set"); diff --git a/can-connect.js b/can-connect.js index e3f23c95..500f6bca 100644 --- a/can-connect.js +++ b/can-connect.js @@ -1,3 +1,4 @@ +"use strict"; var connect = require("can-connect/connect"); var base = require("can-connect/base/base"); var ns = require("can-namespace"); diff --git a/can/base-map/base-map.js b/can/base-map/base-map.js index 61043000..003abb51 100644 --- a/can/base-map/base-map.js +++ b/can/base-map/base-map.js @@ -1,3 +1,4 @@ +"use strict"; var connect = require("can-connect"); var constructor = require("../../constructor/constructor"); diff --git a/can/constructor-hydrate/constructor-hydrate.js b/can/constructor-hydrate/constructor-hydrate.js index c7196833..e63a4b14 100644 --- a/can/constructor-hydrate/constructor-hydrate.js +++ b/can/constructor-hydrate/constructor-hydrate.js @@ -1,3 +1,4 @@ +"use strict"; /** * @module {connect.Behavior} can-connect/can/constructor-hydrate/constructor-hydrate constructor-hydrate * @parent can-connect.behaviors diff --git a/can/map/make-real-time-super-model.js b/can/map/make-real-time-super-model.js index ea7e7b45..5e600e81 100644 --- a/can/map/make-real-time-super-model.js +++ b/can/map/make-real-time-super-model.js @@ -1,3 +1,4 @@ +"use strict"; var constructor = require("can-connect/constructor/"); var canMap = require("can-connect/can/map/"); //var canRef = require("can-connect/can/ref/"); diff --git a/can/map/test-real-time-super-model.js b/can/map/test-real-time-super-model.js index 2667f025..e34708f4 100644 --- a/can/map/test-real-time-super-model.js +++ b/can/map/test-real-time-super-model.js @@ -1,3 +1,4 @@ +"use strict"; var QUnit = require("steal-qunit"); var canLog = require("can-util/js/log/log"); diff --git a/can/merge/merge.js b/can/merge/merge.js index 769c1130..4139568e 100644 --- a/can/merge/merge.js +++ b/can/merge/merge.js @@ -1,3 +1,4 @@ +"use strict"; var smartMerge = require('can-connect/helpers/map-deep-merge'); var connectMap = require('can-connect/can/map/map'); var canBatch = require('can-event/batch/batch'); diff --git a/can/ref/ref.js b/can/ref/ref.js index 6b1a1759..ae870b89 100644 --- a/can/ref/ref.js +++ b/can/ref/ref.js @@ -1,3 +1,4 @@ +"use strict"; /** * @module {connect.Behavior} can-connect/can/ref/ref can/ref * @parent can-connect.behaviors diff --git a/can/super-map/super-map.js b/can/super-map/super-map.js index a9f22e08..5cf5a3f5 100644 --- a/can/super-map/super-map.js +++ b/can/super-map/super-map.js @@ -1,3 +1,4 @@ +"use strict"; var connect = require("can-connect"); var constructor = require("../../constructor/constructor"); diff --git a/can/tag/tag.js b/can/tag/tag.js index 1b0eed2c..5342269a 100644 --- a/can/tag/tag.js +++ b/can/tag/tag.js @@ -1,3 +1,4 @@ +"use strict"; /** * @module can-connect/can/tag/tag * @parent can-connect.modules diff --git a/connect.js b/connect.js index b9f29b99..20b30803 100644 --- a/connect.js +++ b/connect.js @@ -1,3 +1,4 @@ +"use strict"; var assign = require("can-util/js/assign/assign"); /** * diff --git a/constructor/callbacks-once/callbacks-once.js b/constructor/callbacks-once/callbacks-once.js index e0eae4b5..702851f7 100644 --- a/constructor/callbacks-once/callbacks-once.js +++ b/constructor/callbacks-once/callbacks-once.js @@ -1,3 +1,4 @@ +"use strict"; /** * @module {function} can-connect/constructor/callbacks-once/callbacks-once constructor/callbacks-once * @parent can-connect.behaviors diff --git a/constructor/constructor.js b/constructor/constructor.js index 4536a038..0f51d32e 100644 --- a/constructor/constructor.js +++ b/constructor/constructor.js @@ -1,5 +1,7 @@ +"use strict"; + /** * @module {connect.Behavior} can-connect/constructor/constructor constructor * @parent can-connect.behaviors diff --git a/constructor/store/store.js b/constructor/store/store.js index 1452aab2..2b7f5e7c 100644 --- a/constructor/store/store.js +++ b/constructor/store/store.js @@ -1,3 +1,4 @@ +"use strict"; /** * @module {connect.Behavior} can-connect/constructor/store/store constructor/store * @parent can-connect.behaviors diff --git a/data/callbacks-cache/callbacks-cache.js b/data/callbacks-cache/callbacks-cache.js index b604bd46..ae4f3290 100644 --- a/data/callbacks-cache/callbacks-cache.js +++ b/data/callbacks-cache/callbacks-cache.js @@ -1,3 +1,4 @@ +"use strict"; /** * @module can-connect/data/callbacks-cache/callbacks-cache data/callbacks-cache * @parent can-connect.behaviors diff --git a/data/callbacks/callbacks.js b/data/callbacks/callbacks.js index c260a47e..ce055c85 100644 --- a/data/callbacks/callbacks.js +++ b/data/callbacks/callbacks.js @@ -1,3 +1,4 @@ +"use strict"; /** * @module can-connect/data/callbacks/callbacks data/callbacks * @parent can-connect.behaviors diff --git a/data/combine-requests/combine-requests.js b/data/combine-requests/combine-requests.js index 312d339d..9a902006 100644 --- a/data/combine-requests/combine-requests.js +++ b/data/combine-requests/combine-requests.js @@ -1,3 +1,4 @@ +"use strict"; var connect = require("can-connect"); var canSet = require("can-set"); var getItems = require("can-connect/helpers/get-items"); diff --git a/data/localstorage-cache/localstorage-cache.js b/data/localstorage-cache/localstorage-cache.js index aa517961..05703568 100644 --- a/data/localstorage-cache/localstorage-cache.js +++ b/data/localstorage-cache/localstorage-cache.js @@ -1,3 +1,4 @@ +"use strict"; /** * @module can-connect/data/localstorage-cache/localstorage-cache localstorage-cache * @parent can-connect.behaviors diff --git a/data/memory-cache/memory-cache.js b/data/memory-cache/memory-cache.js index 8aafc0bc..c4af37da 100644 --- a/data/memory-cache/memory-cache.js +++ b/data/memory-cache/memory-cache.js @@ -1,3 +1,4 @@ +"use strict"; /** * @module can-connect/data/memory-cache/memory-cache memory-cache * @parent can-connect.behaviors diff --git a/data/parse/parse.js b/data/parse/parse.js index 75b3f297..81038aec 100644 --- a/data/parse/parse.js +++ b/data/parse/parse.js @@ -1,3 +1,4 @@ +"use strict"; /** * @module {connect.Behavior} can-connect/data/parse/parse * @parent can-connect.behaviors @@ -53,9 +54,9 @@ * ``` * */ - var connect = require("can-connect"); - var each = require("can-util/js/each/each"); - var getObject = require("can-util/js/get/get"); +var connect = require("can-connect"); +var each = require("can-util/js/each/each"); +var getObject = require("can-util/js/get/get"); module.exports = connect.behavior("data/parse",function(baseConnection){ diff --git a/data/url/url.js b/data/url/url.js index 71bd4a31..5aa24dba 100644 --- a/data/url/url.js +++ b/data/url/url.js @@ -1,3 +1,4 @@ +"use strict"; /** * @module {connect.Behavior} can-connect/data/url/url data/url * @parent can-connect.behaviors @@ -211,28 +212,28 @@ var urlBehavior = connect.behavior("data/url", function(baseConnection) { */ - /** - * @property {function} can-connect/data/url/url.ajax ajax - * @parent can-connect/data/url/url.option - * - * Specify the ajax functionality that should be used to make the request. - * - * @option {function} Provides an alternate function to be used to make - * ajax requests. By default [can-util/dom/ajax/ajax] provides the ajax - * functionality. jQuery's ajax method can be substituted as follows: - * - * ```js - * connect([ - * require("can-connect/data/url/url") - * ],{ - * url: "/things", - * ajax: $.ajax - * }); - * ``` - * - * @param {Object} settings Configuration options for the AJAX request. - * @return {Promise} A Promise that resolves to the data. - */ +/** + * @property {function} can-connect/data/url/url.ajax ajax + * @parent can-connect/data/url/url.option + * + * Specify the ajax functionality that should be used to make the request. + * + * @option {function} Provides an alternate function to be used to make + * ajax requests. By default [can-util/dom/ajax/ajax] provides the ajax + * functionality. jQuery's ajax method can be substituted as follows: + * + * ```js + * connect([ + * require("can-connect/data/url/url") + * ],{ + * url: "/things", + * ajax: $.ajax + * }); + * ``` + * + * @param {Object} settings Configuration options for the AJAX request. + * @return {Promise} A Promise that resolves to the data. + */ // ## methodMetaData // Metadata on different methods that is passed to makeAjax diff --git a/data/worker/demo/todo_connection.js b/data/worker/demo/todo_connection.js index 4e640533..0fa96d96 100644 --- a/data/worker/demo/todo_connection.js +++ b/data/worker/demo/todo_connection.js @@ -1,3 +1,4 @@ +"use strict"; var connect = require("can-connect"); var fixture = require("can-fixture"); diff --git a/data/worker/worker.js b/data/worker/worker.js index 9def32ee..d62c30f4 100644 --- a/data/worker/worker.js +++ b/data/worker/worker.js @@ -1,3 +1,4 @@ +"use strict"; var connect = require("can-connect"); var makeDeferred = require("can-connect/helpers/deferred"); var canLog = require("can-util/js/log/log"); diff --git a/docs/hooks.js b/docs/hooks.js index 07b57301..ab5e1ce2 100644 --- a/docs/hooks.js +++ b/docs/hooks.js @@ -1,3 +1,4 @@ +"use strict"; var hooks = { // CRUD stuff /** diff --git a/fall-through-cache/fall-through-cache.js b/fall-through-cache/fall-through-cache.js index 96184b16..18fadd2c 100644 --- a/fall-through-cache/fall-through-cache.js +++ b/fall-through-cache/fall-through-cache.js @@ -1,3 +1,4 @@ +"use strict"; /** * @module can-connect/fall-through-cache/fall-through-cache fall-through-cache * @parent can-connect.behaviors diff --git a/helpers/clone-data.js b/helpers/clone-data.js index 1fcc6409..d0664fd3 100644 --- a/helpers/clone-data.js +++ b/helpers/clone-data.js @@ -1,3 +1,4 @@ +"use strict"; var deepAssign = require("can-util/js/deep-assign/deep-assign"); module.exports = function(data) { diff --git a/helpers/deferred.js b/helpers/deferred.js index a021b1b1..90522318 100644 --- a/helpers/deferred.js +++ b/helpers/deferred.js @@ -1,4 +1,5 @@ +"use strict"; module.exports = function(){ var def = {}; def.promise = new Promise(function(resolve, reject){ diff --git a/helpers/deparam.js b/helpers/deparam.js index 929e45fe..ce8e032c 100644 --- a/helpers/deparam.js +++ b/helpers/deparam.js @@ -1,3 +1,4 @@ +"use strict"; var digitTest = /^\d+$/, keyBreaker = /([^\[\]]+)|(\[\])/g, paramTest = /([^?#]*)(#.*)?$/, diff --git a/helpers/get-id-props.js b/helpers/get-id-props.js index 03e17ba4..81e1075d 100644 --- a/helpers/get-id-props.js +++ b/helpers/get-id-props.js @@ -1,3 +1,4 @@ +"use strict"; module.exports = function(connection) { var ids = [], algebra = connection.algebra; diff --git a/helpers/get-index-by-id.js b/helpers/get-index-by-id.js index 0c608f6f..2d869b9d 100644 --- a/helpers/get-index-by-id.js +++ b/helpers/get-index-by-id.js @@ -1,3 +1,4 @@ +"use strict"; /*jshint eqeqeq: false */ module.exports = function(connection, props, items){ var id = connection.id(props); diff --git a/helpers/get-items.js b/helpers/get-items.js index d9a95847..d7a7564e 100644 --- a/helpers/get-items.js +++ b/helpers/get-items.js @@ -1,3 +1,4 @@ +"use strict"; module.exports = function(data){ if(Array.isArray(data)) { return data; diff --git a/helpers/id-merge.js b/helpers/id-merge.js index 9acff774..429ea1a5 100644 --- a/helpers/id-merge.js +++ b/helpers/id-merge.js @@ -1,3 +1,4 @@ +"use strict"; var map = [].map; module.exports = function(list, update, id, make){ diff --git a/helpers/map-deep-merge.js b/helpers/map-deep-merge.js index 779d0113..85c10474 100644 --- a/helpers/map-deep-merge.js +++ b/helpers/map-deep-merge.js @@ -1,3 +1,4 @@ +"use strict"; // TODO: This implementation deeply depends on `can-define/map/` and `can-define/list/`. // Track the issue `https://github.com/canjs/canjs/issues/2931` to figure out how to apply smartMerge // to regular objects and arrays. diff --git a/helpers/overwrite.js b/helpers/overwrite.js index 1df53187..eb6a9e02 100644 --- a/helpers/overwrite.js +++ b/helpers/overwrite.js @@ -1,3 +1,4 @@ +"use strict"; module.exports = function(d, s, id){ for(var prop in d) { if(d.hasOwnProperty(prop) && !(prop.substr(0,2) === '__') && prop !== id && !(prop in s)) { diff --git a/helpers/poly-weak-set.js b/helpers/poly-weak-set.js index 8dc4a02f..4005a808 100644 --- a/helpers/poly-weak-set.js +++ b/helpers/poly-weak-set.js @@ -1,3 +1,4 @@ +"use strict"; var assign = require("can-util/js/assign/assign"); var PolyWeakSet = function(getKey){ diff --git a/helpers/remove-element.js b/helpers/remove-element.js index ac8d7c33..0a08dd77 100644 --- a/helpers/remove-element.js +++ b/helpers/remove-element.js @@ -1,3 +1,4 @@ +"use strict"; var observer = new MutationObserver( function(mutations){ var mutation; for(var i = 0; i < mutations.length; i++) { diff --git a/helpers/set-add.js b/helpers/set-add.js index 681deab1..12366c9a 100644 --- a/helpers/set-add.js +++ b/helpers/set-add.js @@ -1,3 +1,4 @@ +"use strict"; var canSet = require("can-set"); // This helper is used to add something to a set of data. // if the set algebra doesn't know where to put it, we add it at the end. diff --git a/helpers/sorted-set-json.js b/helpers/sorted-set-json.js index f2ac5060..6e1719a1 100644 --- a/helpers/sorted-set-json.js +++ b/helpers/sorted-set-json.js @@ -1,3 +1,4 @@ +"use strict"; var forEach = [].forEach; var keys = Object.keys; diff --git a/helpers/validate.js b/helpers/validate.js index b3e1891a..76ad0f16 100644 --- a/helpers/validate.js +++ b/helpers/validate.js @@ -1,3 +1,4 @@ +"use strict"; // return wrapped can-connect behavior mixin that validates interface of the input behavior being extended // deprecate this and use can-validate-interface decorator once available diff --git a/helpers/weak-reference-map.js b/helpers/weak-reference-map.js index 36c6ce1e..cd1b6e5f 100644 --- a/helpers/weak-reference-map.js +++ b/helpers/weak-reference-map.js @@ -1,3 +1,4 @@ +"use strict"; var assign = require("can-util/js/assign/assign"); /** diff --git a/helpers/weak-reference-set.js b/helpers/weak-reference-set.js index 25a5e5e9..2432ba77 100644 --- a/helpers/weak-reference-set.js +++ b/helpers/weak-reference-set.js @@ -1,3 +1,4 @@ +"use strict"; var assign = require("can-util/js/assign/assign"); diff --git a/real-time/real-time.js b/real-time/real-time.js index 06df957d..4d08049e 100644 --- a/real-time/real-time.js +++ b/real-time/real-time.js @@ -1,3 +1,4 @@ +"use strict"; /** * @module can-connect/real-time/real-time real-time * @parent can-connect.behaviors diff --git a/service-worker/service-worker-main.js b/service-worker/service-worker-main.js index 958aee7e..32f8bac9 100644 --- a/service-worker/service-worker-main.js +++ b/service-worker/service-worker-main.js @@ -1,3 +1,4 @@ +"use strict"; console.log("WORKER - LISTENING"); addEventListener("message", function(ev){ diff --git a/service-worker/service-worker.js b/service-worker/service-worker.js index 33c5bf2c..d91a52c5 100644 --- a/service-worker/service-worker.js +++ b/service-worker/service-worker.js @@ -1,4 +1,5 @@ +"use strict"; var connect = require("can-connect"); var makeDeferred = require("can-connect/helpers/deferred"); var canLog = require("can-util/js/log/log"); diff --git a/test-helpers.js b/test-helpers.js index 9e1a746e..4b5e8e65 100644 --- a/test-helpers.js +++ b/test-helpers.js @@ -1,3 +1,4 @@ +"use strict"; module.exports = { makeStateChecker: function(QUnit, names){ From 8d8cda2b15a9ea6ba28f1727c8d2d1d468eee730 Mon Sep 17 00:00:00 2001 From: Austin Sanders Date: Tue, 3 Jul 2018 12:29:04 -0700 Subject: [PATCH 2/2] added Object.defineProperty to connect.js:73, fixed this context in localstorage-cache.js:405 --- connect.js | 4 +++- data/localstorage-cache/localstorage-cache.js | 2 +- data/localstorage-cache/localstorage-cache_test.js | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/connect.js b/connect.js index 20b30803..56c5e00e 100644 --- a/connect.js +++ b/connect.js @@ -70,7 +70,9 @@ connect.behavior = function(name, behavior){ var behaviorMixin = function(base){ // basically Object.create var Behavior = function(){}; - Behavior.name = name; + Object.defineProperty(Behavior, "name", { + value: name + }); Behavior.prototype = base; var newBehavior = new Behavior(); // allows behaviors to be a simple object, not always a function diff --git a/data/localstorage-cache/localstorage-cache.js b/data/localstorage-cache/localstorage-cache.js index 05703568..dea1136b 100644 --- a/data/localstorage-cache/localstorage-cache.js +++ b/data/localstorage-cache/localstorage-cache.js @@ -402,7 +402,7 @@ module.exports = connect.behavior("data/localstorage-cache",function(baseConnect // Get the data for the old set we can union with. return this.getListData(setDatum.set).then(function(setData){ // update the old set to the new set - self.updateSet(setDatum, canSet.getUnion(setDatum.set, set, getItems(setData), items, this.algebra), union); + self.updateSet(setDatum, canSet.getUnion(setDatum.set, set, getItems(setData), items, self.algebra), union); }); } } diff --git a/data/localstorage-cache/localstorage-cache_test.js b/data/localstorage-cache/localstorage-cache_test.js index 3f31faa9..a6dfbd5f 100644 --- a/data/localstorage-cache/localstorage-cache_test.js +++ b/data/localstorage-cache/localstorage-cache_test.js @@ -332,6 +332,7 @@ QUnit.asyncTest("pagination loses the bigger set (#126)", function(){ QUnit.start(); }); }).catch(function(e){ + console.log(e); QUnit.ok(false, "something broke"); QUnit.start(); });