diff --git a/packages/ember-application/lib/system/application-instance.js b/packages/ember-application/lib/system/application-instance.js index b850ea9ef68..76c835802ba 100644 --- a/packages/ember-application/lib/system/application-instance.js +++ b/packages/ember-application/lib/system/application-instance.js @@ -176,7 +176,7 @@ const ApplicationInstance = EngineInstance.extend({ @private */ startRouting() { - var router = get(this, 'router'); + let router = get(this, 'router'); router.startRouting(); this._didSetupRouter = true; }, @@ -194,7 +194,7 @@ const ApplicationInstance = EngineInstance.extend({ if (this._didSetupRouter) { return; } this._didSetupRouter = true; - var router = get(this, 'router'); + let router = get(this, 'router'); router.setupRouter(); }, @@ -206,7 +206,7 @@ const ApplicationInstance = EngineInstance.extend({ @private */ handleURL(url) { - var router = get(this, 'router'); + let router = get(this, 'router'); this.setupRouter(); return router.handleURL(url); @@ -216,11 +216,11 @@ const ApplicationInstance = EngineInstance.extend({ @private */ setupEventDispatcher() { - var dispatcher = this.lookup('event_dispatcher:main'); - var applicationCustomEvents = get(this.application, 'customEvents'); - var instanceCustomEvents = get(this, 'customEvents'); + let dispatcher = this.lookup('event_dispatcher:main'); + let applicationCustomEvents = get(this.application, 'customEvents'); + let instanceCustomEvents = get(this, 'customEvents'); - var customEvents = assign({}, applicationCustomEvents, instanceCustomEvents); + let customEvents = assign({}, applicationCustomEvents, instanceCustomEvents); dispatcher.setup(customEvents, this.rootElement); return dispatcher; @@ -482,7 +482,7 @@ Object.defineProperty(ApplicationInstance.prototype, 'container', { configurable: true, enumerable: false, get() { - var instance = this; + let instance = this; return { lookup() { deprecate( diff --git a/packages/ember-application/lib/system/application.js b/packages/ember-application/lib/system/application.js index d7999f261b0..42cf6e270e7 100644 --- a/packages/ember-application/lib/system/application.js +++ b/packages/ember-application/lib/system/application.js @@ -31,7 +31,7 @@ import RSVP from 'ember-runtime/ext/rsvp'; import Engine, { GLIMMER } from './engine'; import require from 'require'; -var librariesRegistered = false; +let librariesRegistered = false; let warnedAboutLegacyViewAddon = false; let warnedAboutLegacyControllerAddon = false; @@ -103,7 +103,7 @@ export function _resetLegacyAddonWarnings() { names by setting the application's `customEvents` property: ```javascript - var App = Ember.Application.create({ + let App = Ember.Application.create({ customEvents: { // add support for the paste event paste: 'paste' @@ -116,7 +116,7 @@ export function _resetLegacyAddonWarnings() { property: ```javascript - var App = Ember.Application.create({ + let App = Ember.Application.create({ customEvents: { // prevent listeners for mouseenter/mouseleave events mouseenter: null, @@ -134,7 +134,7 @@ export function _resetLegacyAddonWarnings() { should be delegated, set your application's `rootElement` property: ```javascript - var App = Ember.Application.create({ + let App = Ember.Application.create({ rootElement: '#ember-app' }); ``` @@ -177,7 +177,7 @@ export function _resetLegacyAddonWarnings() { the `LOG_TRANSITIONS_INTERNAL` flag: ```javascript - var App = Ember.Application.create({ + let App = Ember.Application.create({ LOG_TRANSITIONS: true, // basic logging of successful transitions LOG_TRANSITIONS_INTERNAL: true // detailed logging of all routing steps }); @@ -253,7 +253,7 @@ const Application = Engine.extend({ To add new events to be listened to: ```javascript - var App = Ember.Application.create({ + let App = Ember.Application.create({ customEvents: { // add support for the paste event paste: 'paste' @@ -264,7 +264,7 @@ const Application = Engine.extend({ To prevent default events from being listened to: ```javascript - var App = Ember.Application.create({ + let App = Ember.Application.create({ customEvents: { // remove support for mouseenter / mouseleave events mouseenter: null, @@ -299,7 +299,7 @@ const Application = Engine.extend({ classes. ```javascript - var App = Ember.Application.create({ + let App = Ember.Application.create({ ... }); @@ -499,7 +499,7 @@ const Application = Engine.extend({ Example: ```javascript - var App = Ember.Application.create(); + let App = Ember.Application.create(); App.deferReadiness(); @@ -623,7 +623,7 @@ const Application = Engine.extend({ Typical Example: ```javascript - var App; + let App; run(function() { App = Ember.Application.create(); @@ -651,7 +651,7 @@ const Application = Engine.extend({ to the app becoming ready. ```javascript - var App; + let App; run(function() { App = Ember.Application.create(); @@ -686,7 +686,7 @@ const Application = Engine.extend({ create new \`Ember.ApplicationInstance\`s and dispose them via their \`destroy()\` method instead.`, this._globalsMode && this.autoboot); - var instance = this.__deprecatedInstance__; + let instance = this.__deprecatedInstance__; this._readinessDeferrals = 1; this._bootPromise = null; @@ -1026,10 +1026,10 @@ Application.reopenClass({ commonSetupRegistry(registry); if (options[GLIMMER]) { - var glimmerSetupRegistry = require('ember-glimmer/setup-registry').setupApplicationRegistry; + let glimmerSetupRegistry = require('ember-glimmer/setup-registry').setupApplicationRegistry; glimmerSetupRegistry(registry); } else { - var htmlbarsSetupRegistry = require('ember-htmlbars/setup-registry').setupApplicationRegistry; + let htmlbarsSetupRegistry = require('ember-htmlbars/setup-registry').setupApplicationRegistry; htmlbarsSetupRegistry(registry); } @@ -1067,18 +1067,16 @@ function logLibraryVersions() { if (ENV.LOG_VERSION) { // we only need to see this once per Application#init ENV.LOG_VERSION = false; - var libs = libraries._registry; + let libs = libraries._registry; - var nameLengths = libs.map(function(item) { - return get(item, 'name.length'); - }); + let nameLengths = libs.map(item => get(item, 'name.length')); - var maxNameLength = Math.max.apply(this, nameLengths); + let maxNameLength = Math.max.apply(this, nameLengths); debug('-------------------------------'); - for (var i = 0; i < libs.length; i++) { - var lib = libs[i]; - var spaces = new Array(maxNameLength - lib.name.length + 1).join(' '); + for (let i = 0; i < libs.length; i++) { + let lib = libs[i]; + let spaces = new Array(maxNameLength - lib.name.length + 1).join(' '); debug([lib.name, spaces, ' : ', lib.version].join('')); } debug('-------------------------------'); diff --git a/packages/ember-application/lib/system/engine-instance.js b/packages/ember-application/lib/system/engine-instance.js index c82685ee000..99ba1ac87a6 100644 --- a/packages/ember-application/lib/system/engine-instance.js +++ b/packages/ember-application/lib/system/engine-instance.js @@ -175,16 +175,12 @@ if (isEnabled('ember-application-engines')) { 'event_dispatcher:main', P`-bucket-cache:main`, 'service:-routing' - ].forEach((key) => { - this.register(key, parent.resolveRegistration(key)); - }); + ].forEach(key => this.register(key, parent.resolveRegistration(key))); [ 'router:main', '-view-registry:main' - ].forEach((key) => { - this.register(key, parent.lookup(key), { instantiate: false }); - }); + ].forEach(key => this.register(key, parent.lookup(key), { instantiate: false })); } }); } diff --git a/packages/ember-application/lib/system/engine.js b/packages/ember-application/lib/system/engine.js index 8fb703f1c6f..17ec503b052 100644 --- a/packages/ember-application/lib/system/engine.js +++ b/packages/ember-application/lib/system/engine.js @@ -26,7 +26,7 @@ export const GLIMMER = symbol('GLIMMER'); function props(obj) { var properties = []; - for (var key in obj) { + for (let key in obj) { properties.push(key); } @@ -104,7 +104,7 @@ const Engine = Namespace.extend(RegistryProxy, { @return {Ember.Registry} the configured registry */ buildRegistry() { - var registry = this.__registry__ = this.constructor.buildRegistry(this, { + let registry = this.__registry__ = this.constructor.buildRegistry(this, { [GLIMMER]: this[GLIMMER] }); @@ -163,19 +163,17 @@ const Engine = Namespace.extend(RegistryProxy, { }, _runInitializer(bucketName, cb) { - var initializersByName = get(this.constructor, bucketName); - var initializers = props(initializersByName); - var graph = new DAG(); - var initializer; + let initializersByName = get(this.constructor, bucketName); + let initializers = props(initializersByName); + let graph = new DAG(); + let initializer; - for (var i = 0; i < initializers.length; i++) { + for (let i = 0; i < initializers.length; i++) { initializer = initializersByName[initializers[i]]; graph.addEdges(initializer.name, initializer, initializer.before, initializer.after); } - graph.topsort(function (vertex) { - cb(vertex.name, vertex.value); - }); + graph.topsort(vertex => cb(vertex.name, vertex.value)); } }); @@ -395,7 +393,7 @@ Engine.reopenClass({ @public */ buildRegistry(namespace, options = {}) { - var registry = new Registry({ + let registry = new Registry({ resolver: resolverFor(namespace) }); @@ -406,10 +404,10 @@ Engine.reopenClass({ commonSetupRegistry(registry); if (options[GLIMMER]) { - var glimmerSetupRegistry = require('ember-glimmer/setup-registry').setupEngineRegistry; + let glimmerSetupRegistry = require('ember-glimmer/setup-registry').setupEngineRegistry; glimmerSetupRegistry(registry); } else { - var htmlbarsSetupRegistry = require('ember-htmlbars/setup-registry').setupEngineRegistry; + let htmlbarsSetupRegistry = require('ember-htmlbars/setup-registry').setupEngineRegistry; htmlbarsSetupRegistry(registry); } @@ -466,7 +464,7 @@ function buildInitializerMethod(bucketName, humanName) { // prototypal inheritance. Without this, attempting to add initializers to the subclass would // pollute the parent class as well as other subclasses. if (this.superclass[bucketName] !== undefined && this.superclass[bucketName] === this[bucketName]) { - var attrs = {}; + let attrs = {}; attrs[bucketName] = Object.create(this[bucketName]); this.reopenClass(attrs); } @@ -503,8 +501,6 @@ function commonSetupRegistry(registry) { registry.injection('route', 'router', 'router:main'); - - // Register the routing service... registry.register('service:-routing', RoutingService); // Then inject the app router into it diff --git a/packages/ember-application/lib/system/resolver.js b/packages/ember-application/lib/system/resolver.js index 2209a7f77b0..fa05531f62b 100644 --- a/packages/ember-application/lib/system/resolver.js +++ b/packages/ember-application/lib/system/resolver.js @@ -69,7 +69,7 @@ export const Resolver = EmberObject.extend({ App = Ember.Application.create({ Resolver: Ember.DefaultResolver.extend({ resolveTemplate: function(parsedName) { - var resolvedTemplate = this._super(parsedName); + let resolvedTemplate = this._super(parsedName); if (resolvedTemplate) { return resolvedTemplate; } return Ember.TEMPLATES['not_found']; } @@ -212,7 +212,7 @@ export default EmberObject.extend({ }, _parseName(fullName) { - var [ + let [ type, fullNameWithoutType ] = fullName.split(':'); @@ -224,9 +224,9 @@ export default EmberObject.extend({ let dirname = lastSlashIndex !== -1 ? name.slice(0, lastSlashIndex) : null; if (type !== 'template' && lastSlashIndex !== -1) { - var parts = name.split('/'); + let parts = name.split('/'); name = parts[parts.length - 1]; - var namespaceName = capitalize(parts.slice(0, -1).join('.')); + let namespaceName = capitalize(parts.slice(0, -1).join('.')); root = Namespace.byName(namespaceName); assert( @@ -236,19 +236,19 @@ export default EmberObject.extend({ ); } - var resolveMethodName = fullNameWithoutType === 'main' ? 'Main' : classify(type); + let resolveMethodName = fullNameWithoutType === 'main' ? 'Main' : classify(type); if (!(name && type)) { throw new TypeError('Invalid fullName: `' + fullName + '`, must be of the form `type:name` '); } return { - fullName: fullName, - type: type, - fullNameWithoutType: fullNameWithoutType, + fullName, + type, + fullNameWithoutType, dirname, - name: name, - root: root, + name, + root, resolveMethodName: 'resolve' + resolveMethodName }; }, @@ -265,8 +265,8 @@ export default EmberObject.extend({ @public */ lookupDescription(fullName) { - var parsedName = this.parseName(fullName); - var description; + let parsedName = this.parseName(fullName); + let description; if (parsedName.type === 'template') { return 'template at ' + parsedName.fullNameWithoutType.replace(/\./g, '/'); @@ -311,7 +311,7 @@ export default EmberObject.extend({ @public */ resolveTemplate(parsedName) { - var templateName = parsedName.fullNameWithoutType.replace(/\./g, '/'); + let templateName = parsedName.fullNameWithoutType.replace(/\./g, '/'); return getTemplate(templateName) || getTemplate(decamelize(templateName)); }, @@ -367,10 +367,10 @@ export default EmberObject.extend({ @public */ resolveModel(parsedName) { - var className = classify(parsedName.name); - var factory = get(parsedName.root, className); + let className = classify(parsedName.name); + let factory = get(parsedName.root, className); - if (factory) { return factory; } + return factory; }, /** Look up the specified object (from parsedName) on the appropriate @@ -396,13 +396,13 @@ export default EmberObject.extend({ @public */ resolveOther(parsedName) { - var className = classify(parsedName.name) + classify(parsedName.type); - var factory = get(parsedName.root, className); - if (factory) { return factory; } + let className = classify(parsedName.name) + classify(parsedName.type); + let factory = get(parsedName.root, className); + return factory; }, resolveMain(parsedName) { - var className = classify(parsedName.type); + let className = classify(parsedName.type); return get(parsedName.root, className); }, @@ -413,7 +413,7 @@ export default EmberObject.extend({ @private */ _logLookup(found, parsedName) { - var symbol, padding; + let symbol, padding; if (found) { symbol = '[✓]'; diff --git a/packages/ember-application/tests/system/application_instance_test.js b/packages/ember-application/tests/system/application_instance_test.js index 623edf4b869..0b395d14615 100644 --- a/packages/ember-application/tests/system/application_instance_test.js +++ b/packages/ember-application/tests/system/application_instance_test.js @@ -7,14 +7,12 @@ import factory from 'container/tests/test-helpers/factory'; import isEnabled from 'ember-metal/features'; import { privatize as P } from 'container/registry'; -let app, appInstance; +let application, appInstance; QUnit.module('Ember.ApplicationInstance', { setup() { jQuery('#qunit-fixture').html('
BYE
'); - run(function() { - top.setOutletState(routerState); - }); + run(() => top.setOutletState(routerState)); // Replace whitespace for older IE equal(trim(top.$().text()), 'HIBYE'); @@ -45,7 +43,7 @@ QUnit.test('a top-level outlet should always be a view', function() { appInstance.register('view:toplevel', EmberView.extend({ elementId: 'top-level' })); - var routerState = withTemplate('BYE
'); runAppend(top); @@ -55,7 +53,7 @@ QUnit.test('a top-level outlet should always be a view', function() { }); QUnit.test('view should render the outlet when set before dom insertion', function() { - var routerState = withTemplate('BYE
'); top.setOutletState(routerState); runAppend(top); @@ -66,7 +64,7 @@ QUnit.test('view should render the outlet when set before dom insertion', functi QUnit.test('outlet should support an optional name', function() { - var routerState = withTemplate('BYE
'); - run(function() { - top.setOutletState(routerState); - }); + run(() => top.setOutletState(routerState)); // Replace whitespace for older IE equal(trim(top.$().text()), 'HIBYE'); }); QUnit.test('Outlets bind to the current view, not the current concrete view', function() { - var routerState = withTemplate('{{title}}
')); - var modelDidChange = 0; + let modelDidChange = 0; runAppend(view); equal(modelDidChange, 0, 'model observer did not fire'); }); @@ -170,19 +166,19 @@ QUnit.test('{{render}} helper should raise an error when a given controller name setTemplate('home', compile('BYE
')); - expectAssertion(function() { + expectAssertion(() => { runAppend(view); }, 'The controller name you supplied \'postss\' did not resolve to a controller.'); }); QUnit.test('{{render}} helper should render with given controller', function() { - var template = '{{render "home" controller="posts"}}'; - var Controller = EmberController.extend(); + let template = '{{render "home" controller="posts"}}'; + let Controller = EmberController.extend(); let model = {}; let controller = Controller.create({ [OWNER]: appInstance }); - var id = 0; + let id = 0; appInstance.register('controller:posts', EmberController.extend({ init() { @@ -217,7 +213,7 @@ QUnit.test('{{render}} helper should rerender with given controller', function() let controller = Controller.create({ [OWNER]: appInstance }); - var id = 0; + let id = 0; appInstance.register('controller:posts', EmberController.extend({ init() { @@ -250,8 +246,8 @@ QUnit.test('{{render}} helper should rerender with given controller', function() }); QUnit.test('{{render}} helper should render a template without a model only once', function() { - var template = 'BYE
')); - expectAssertion(function() { + expectAssertion(() => { runAppend(view); }, /\{\{render\}\} helper once/i); }); @@ -316,16 +312,16 @@ QUnit.test('{{render}} helper should render templates with models multiple times }); QUnit.test('{{render}} helper should not leak controllers', function() { - var template = 'BYE
')); - var liveRoutes = { + let liveRoutes = { render: { template: compile('BYE
')); - expectAssertion(function() { + expectAssertion(() => { runAppend(view); }, 'The first argument of {{render}} must be quoted, e.g. {{render "sidebar"}}.'); }); QUnit.test('throws an assertion if {{render}} is called with a literal for a model', function() { - var template = 'BYE
')); - expectAssertion(function() { + expectAssertion(() => { runAppend(view); }, 'The second argument of {{render}} must be a path, e.g. {{render "post" post}}.'); }); QUnit.test('{{render}} helper should not require view to provide its own template', function() { - var template = '{{render \'fish\'}}'; - var Controller = EmberController.extend(); - var controller = Controller.create({ + let template = '{{render \'fish\'}}'; + let Controller = EmberController.extend(); + let controller = Controller.create({ [OWNER]: appInstance }); diff --git a/packages/ember-htmlbars/tests/htmlbars_test.js b/packages/ember-htmlbars/tests/htmlbars_test.js index ffa54f95421..441629084aa 100644 --- a/packages/ember-htmlbars/tests/htmlbars_test.js +++ b/packages/ember-htmlbars/tests/htmlbars_test.js @@ -7,11 +7,11 @@ import assign from 'ember-metal/assign'; QUnit.module('ember-htmlbars: main'); QUnit.test('HTMLBars is present and can be executed', function() { - var template = compile('ohai'); + let template = compile('ohai'); - var env = assign({ dom: domHelper }, defaultEnv); + let env = assign({ dom: domHelper }, defaultEnv); - var output = template.render({}, env, { contextualElement: document.body }).fragment; + let output = template.render({}, env, { contextualElement: document.body }).fragment; equalHTML(output, 'ohai'); }); diff --git a/packages/ember-htmlbars/tests/integration/component_invocation_test.js b/packages/ember-htmlbars/tests/integration/component_invocation_test.js index 467eb2fdb47..30d12985788 100644 --- a/packages/ember-htmlbars/tests/integration/component_invocation_test.js +++ b/packages/ember-htmlbars/tests/integration/component_invocation_test.js @@ -5,7 +5,7 @@ import { runAppend, runDestroy } from 'ember-runtime/tests/utils'; import buildOwner from 'container/tests/test-helpers/build-owner'; import { OWNER } from 'container/owner'; -var owner, component; +let owner, component; function commonSetup() { owner = buildOwner(); @@ -33,13 +33,13 @@ QUnit.module('component - invocation', { QUnit.test('moduleName is available on _renderNode when a layout is present', function() { expect(1); - var layoutModuleName = 'my-app-name/templates/components/sample-component'; - var sampleComponentLayout = compile('Sample Component - {{yield}}', { + let layoutModuleName = 'my-app-name/templates/components/sample-component'; + let sampleComponentLayout = compile('Sample Component - {{yield}}', { moduleName: layoutModuleName }); owner.register('template:components/sample-component', sampleComponentLayout); owner.register('component:sample-component', Component.extend({ - didInsertElement: function() { + didInsertElement() { equal(this._renderNode.lastResult.template.meta.moduleName, layoutModuleName); } })); @@ -55,9 +55,9 @@ QUnit.test('moduleName is available on _renderNode when a layout is present', fu QUnit.test('moduleName is available on _renderNode when no layout is present', function() { expect(1); - var templateModuleName = 'my-app-name/templates/application'; + let templateModuleName = 'my-app-name/templates/application'; owner.register('component:sample-component', Component.extend({ - didInsertElement: function() { + didInsertElement() { equal(this._renderNode.lastResult.template.meta.moduleName, templateModuleName); } })); diff --git a/packages/ember-htmlbars/tests/integration/component_lifecycle_test.js b/packages/ember-htmlbars/tests/integration/component_lifecycle_test.js index 0cf019ba14b..d589c734fb9 100644 --- a/packages/ember-htmlbars/tests/integration/component_lifecycle_test.js +++ b/packages/ember-htmlbars/tests/integration/component_lifecycle_test.js @@ -7,8 +7,8 @@ import EmberView from 'ember-views/views/view'; import buildOwner from 'container/tests/test-helpers/build-owner'; import { OWNER } from 'container/owner'; -var owner, view; -var hooks; +let owner, view; +let hooks; let styles = [{ name: 'curly', @@ -69,7 +69,7 @@ styles.forEach(style => { } QUnit.test('lifecycle hooks are invoked in a predictable order', function() { - var components = {}; + let components = {}; function component(label) { return style.class.extend({ @@ -150,9 +150,7 @@ styles.forEach(style => { hooks = []; - run(function() { - components.bottom.rerender(); - }); + run(() => components.bottom.rerender()); deepEqual(hooks, [ hook('bottom', 'willUpdate'), hook('bottom', 'willRender'), @@ -161,9 +159,7 @@ styles.forEach(style => { hooks = []; - run(function() { - components.middle.rerender(); - }); + run(() => components.middle.rerender()); bottomAttrs = { oldAttrs: { website: 'tomdale.net' }, newAttrs: { website: 'tomdale.net' } }; @@ -181,9 +177,7 @@ styles.forEach(style => { hooks = []; - run(function() { - components.top.rerender(); - }); + run(() => components.top.rerender()); middleAttrs = { oldAttrs: { name: 'Tom Dale' }, newAttrs: { name: 'Tom Dale' } }; @@ -203,9 +197,7 @@ styles.forEach(style => { hooks = []; - run(function() { - view.set('twitter', '@hipstertomdale'); - }); + run(() => view.set('twitter', '@hipstertomdale')); // Because the `twitter` attr is only used by the topmost component, // and not passed down, we do not expect to see lifecycle hooks @@ -223,7 +215,7 @@ styles.forEach(style => { }); QUnit.test('passing values through attrs causes lifecycle hooks to fire if the attribute values have changed', function() { - var components = {}; + let components = {}; function component(label) { return style.class.extend({ @@ -304,9 +296,7 @@ styles.forEach(style => { hooks = []; - run(function() { - view.set('twitter', '@hipstertomdale'); - }); + run(() => view.set('twitter', '@hipstertomdale')); // Because the `twitter` attr is used by the all of the components, // the lifecycle hooks are invoked for all components. @@ -334,9 +324,7 @@ styles.forEach(style => { // In this case, because the attrs are passed down, all child components are invoked. - run(function() { - view.rerender(); - }); + run(() => view.rerender()); topAttrs = { oldAttrs: { twitter: '@hipstertomdale' }, newAttrs: { twitter: '@hipstertomdale' } }; middleAttrs = { oldAttrs: { twitterTop: '@hipstertomdale' }, newAttrs: { twitterTop: '@hipstertomdale' } }; @@ -377,9 +365,7 @@ styles.forEach(style => { assert.strictEqual(component.$().text(), '@tomdale'); - run(() => { - component.destroy(); - }); + run(() => component.destroy()); }); QUnit.test('DEPRECATED: didInitAttrs is deprecated', function(assert) { @@ -399,9 +385,7 @@ styles.forEach(style => { component = componentClass.create(); }, /\[DEPRECATED\] didInitAttrs called in <\(subclass of Ember.Component\)\:ember[\d+]+>\./); - run(() => { - component.destroy(); - }); + run(() => component.destroy()); }); QUnit.test('properties set during `init` are availabe in `didReceiveAttrs`', function(assert) { diff --git a/packages/ember-htmlbars/tests/streams/concat_test.js b/packages/ember-htmlbars/tests/streams/concat_test.js index e184b2603b5..6acfc84df34 100644 --- a/packages/ember-htmlbars/tests/streams/concat_test.js +++ b/packages/ember-htmlbars/tests/streams/concat_test.js @@ -24,9 +24,7 @@ QUnit.test('returns string if no streams were in the array', function(assert) { }); QUnit.test('returns a stream if a stream is in the array', function(assert) { - let stream = new Stream(function() { - return 'bar'; - }); + let stream = new Stream(() => 'bar'); let result = concat(['foo', stream, 'baz'], ' '); assert.ok(isStream(result), 'a stream is returned'); @@ -35,9 +33,7 @@ QUnit.test('returns a stream if a stream is in the array', function(assert) { QUnit.test('returns updated value upon input dirtied', function(assert) { let value = 'bar'; - let stream = new Stream(function() { - return value; - }); + let stream = new Stream(() => value); let result = concat(['foo', stream, 'baz'], ' '); result.activate(); @@ -50,9 +46,7 @@ QUnit.test('returns updated value upon input dirtied', function(assert) { }); QUnit.test('removes dependencies when unsubscribeDependencies is called', function(assert) { - let stream = new Stream(function() { - return 'bar'; - }); + let stream = new Stream(() => 'bar'); let result = concat(['foo', stream, 'baz'], ' '); result.activate(); diff --git a/packages/ember-htmlbars/tests/streams/key-stream-test.js b/packages/ember-htmlbars/tests/streams/key-stream-test.js index 9242908d238..5498f048bab 100644 --- a/packages/ember-htmlbars/tests/streams/key-stream-test.js +++ b/packages/ember-htmlbars/tests/streams/key-stream-test.js @@ -3,7 +3,7 @@ import { Stream } from 'ember-htmlbars/streams/stream'; import KeyStream from 'ember-htmlbars/streams/key-stream'; import { set } from 'ember-metal/property_set'; -var source, object, count; +let source, object, count; function incrementCount() { count++; @@ -14,9 +14,7 @@ QUnit.module('KeyStream', { count = 0; object = { name: 'mmun' }; - source = new Stream(function() { - return object; - }); + source = new Stream(() => object); }, teardown() { count = undefined; @@ -26,17 +24,17 @@ QUnit.module('KeyStream', { }); QUnit.test('can be instantiated manually', function() { - var nameStream = new KeyStream(source, 'name'); + let nameStream = new KeyStream(source, 'name'); equal(nameStream.value(), 'mmun', 'Stream value is correct'); }); QUnit.test('can be instantiated via `Stream.prototype.get`', function() { - var nameStream = source.get('name'); + let nameStream = source.get('name'); equal(nameStream.value(), 'mmun', 'Stream value is correct'); }); QUnit.test('is notified when the observed object\'s property is mutated', function() { - var nameStream = source.get('name'); + let nameStream = source.get('name'); nameStream.subscribe(incrementCount); equal(count, 0, 'Subscribers called correct number of times'); @@ -49,7 +47,7 @@ QUnit.test('is notified when the observed object\'s property is mutated', functi }); QUnit.test('is notified when the source stream\'s value changes to a new object', function() { - var nameStream = source.get('name'); + let nameStream = source.get('name'); nameStream.subscribe(incrementCount); equal(count, 0, 'Subscribers called correct number of times'); @@ -68,7 +66,7 @@ QUnit.test('is notified when the source stream\'s value changes to a new object' }); QUnit.test('is notified when the source stream\'s value changes to the same object', function() { - var nameStream = source.get('name'); + let nameStream = source.get('name'); nameStream.subscribe(incrementCount); equal(count, 0, 'Subscribers called correct number of times'); @@ -86,16 +84,14 @@ QUnit.test('is notified when the source stream\'s value changes to the same obje }); QUnit.test('is notified when setSource is called with a new stream whose value is a new object', function() { - var nameStream = source.get('name'); + let nameStream = source.get('name'); nameStream.subscribe(incrementCount); equal(count, 0, 'Subscribers called correct number of times'); equal(nameStream.value(), 'mmun', 'Stream value is correct'); object = { name: 'wycats' }; - nameStream.setSource(new Stream(function() { - return object; - })); + nameStream.setSource(new Stream(() => object)); equal(count, 1, 'Subscribers called correct number of times'); equal(nameStream.value(), 'wycats', 'Stream value is correct'); @@ -107,15 +103,13 @@ QUnit.test('is notified when setSource is called with a new stream whose value i }); QUnit.test('is notified when setSource is called with a new stream whose value is the same object', function() { - var nameStream = source.get('name'); + let nameStream = source.get('name'); nameStream.subscribe(incrementCount); equal(count, 0, 'Subscribers called correct number of times'); equal(nameStream.value(), 'mmun', 'Stream value is correct'); - nameStream.setSource(new Stream(function() { - return object; - })); + nameStream.setSource(new Stream(() => object)); equal(count, 1, 'Subscribers called correct number of times'); equal(nameStream.value(), 'mmun', 'Stream value is correct'); @@ -127,7 +121,7 @@ QUnit.test('is notified when setSource is called with a new stream whose value i }); QUnit.test('adds and removes key observers on activation and deactivation', function() { - var nameStream = source.get('name'); + let nameStream = source.get('name'); ok(!isWatching(object, 'name'), 'Key is not observered immediately after creation'); @@ -135,7 +129,7 @@ QUnit.test('adds and removes key observers on activation and deactivation', func ok(!isWatching(object, 'name'), 'Key is not observered after calling value with no subscribers'); - var firstCallback = function() {}; + let firstCallback = function() {}; nameStream.subscribe(firstCallback); ok(!isWatching(object, 'name'), 'Key is not observered immediately after first subscription'); @@ -144,7 +138,7 @@ QUnit.test('adds and removes key observers on activation and deactivation', func ok(isWatching(object, 'name'), 'Key is observered after activation'); - var secondCallback = function() {}; + let secondCallback = function() {}; nameStream.subscribe(secondCallback); ok(isWatching(object, 'name'), 'Key is still observered after second subscription is added'); @@ -159,8 +153,8 @@ QUnit.test('adds and removes key observers on activation and deactivation', func }); QUnit.test('removes key observers on destruction', function() { - var nameStream = source.get('name'); - nameStream.subscribe(function() {}); + let nameStream = source.get('name'); + nameStream.subscribe(() => {}); nameStream.value(); ok(isWatching(object, 'name'), '(Precondition) Key is observered after activation'); @@ -171,13 +165,13 @@ QUnit.test('removes key observers on destruction', function() { }); QUnit.test('manages key observers correctly when the object changes', function() { - var nameStream = source.get('name'); - nameStream.subscribe(function() {}); + let nameStream = source.get('name'); + nameStream.subscribe(() => {}); nameStream.value(); ok(isWatching(object, 'name'), '(Precondition) Key is observered after activation'); - var prevObject = object; + let prevObject = object; object = { name: 'wycats' }; source.notify(); diff --git a/packages/ember-htmlbars/tests/streams/proxy-stream-test.js b/packages/ember-htmlbars/tests/streams/proxy-stream-test.js index 0a3e0f022fd..7730b3f88c6 100644 --- a/packages/ember-htmlbars/tests/streams/proxy-stream-test.js +++ b/packages/ember-htmlbars/tests/streams/proxy-stream-test.js @@ -1,7 +1,7 @@ import BasicStream from 'ember-htmlbars/streams/stream'; import ProxyStream from 'ember-htmlbars/streams/proxy-stream'; -var source; +let source; QUnit.module('ProxyStream', { setup() { @@ -28,7 +28,7 @@ QUnit.module('ProxyStream', { }); QUnit.test('supports a stream argument', function() { - var stream = new ProxyStream(source); + let stream = new ProxyStream(source); equal(stream.value(), 'zlurp'); stream.setValue('blorg'); @@ -36,7 +36,7 @@ QUnit.test('supports a stream argument', function() { }); QUnit.test('supports a non-stream argument', function() { - var stream = new ProxyStream('zlurp'); + let stream = new ProxyStream('zlurp'); equal(stream.value(), 'zlurp'); stream.setValue('blorg'); diff --git a/packages/ember-htmlbars/tests/streams/should-display-test.js b/packages/ember-htmlbars/tests/streams/should-display-test.js index 715d3887c69..873fc4bc003 100644 --- a/packages/ember-htmlbars/tests/streams/should-display-test.js +++ b/packages/ember-htmlbars/tests/streams/should-display-test.js @@ -37,19 +37,19 @@ QUnit.test('predicate permutations', function() { falseFunction.isTruthy = true; equal(shouldDisplay(trueFunction), true, 'shouldDisplay(function.isTruthy = true)'); - var truthyObj = { }; + let truthyObj = { }; defineProperty(truthyObj, 'isTruthy', computed(() => true)); equal(shouldDisplay(truthyObj), true, 'shouldDisplay(obj.get("isTruthy") === true)'); - var falseyObj = { }; + let falseyObj = { }; defineProperty(falseyObj, 'isTruthy', computed(() => false)); equal(shouldDisplay(falseyObj), false, 'shouldDisplay(obj.get("isFalsey") === false)'); - var falsyArray = [1]; + let falsyArray = [1]; falsyArray.isTruthy = false; equal(shouldDisplay(falsyArray), false, '[1].isTruthy = false'); - var falseyCPArray = [1]; + let falseyCPArray = [1]; defineProperty(falseyCPArray, 'isTruthy', computed(() => false)); equal(shouldDisplay(falseyCPArray), false, 'shouldDisplay([1].get("isFalsey") === true'); }); diff --git a/packages/ember-htmlbars/tests/streams/stream-test.js b/packages/ember-htmlbars/tests/streams/stream-test.js index c164b56a1fd..141689d9ffe 100644 --- a/packages/ember-htmlbars/tests/streams/stream-test.js +++ b/packages/ember-htmlbars/tests/streams/stream-test.js @@ -2,7 +2,7 @@ import { Stream } from 'ember-htmlbars/streams/stream'; import ObjectProxy from 'ember-runtime/system/object_proxy'; import { get } from 'ember-metal/property_get'; -var stream, value, count; +let stream, value, count; function incrementCount() { count++; @@ -13,9 +13,7 @@ QUnit.module('Stream - Proxy compatibility', { count = 0; value = 'zlurp'; - stream = new Stream(function() { - return value; - }); + stream = new Stream(() => value); }, teardown() { value = undefined; diff --git a/packages/ember-htmlbars/tests/system/lookup-helper_test.js b/packages/ember-htmlbars/tests/system/lookup-helper_test.js index ed7bce4ac89..e8dbfcc06a3 100644 --- a/packages/ember-htmlbars/tests/system/lookup-helper_test.js +++ b/packages/ember-htmlbars/tests/system/lookup-helper_test.js @@ -24,27 +24,27 @@ function generateOwner() { QUnit.module('ember-htmlbars: lookupHelper hook'); QUnit.test('looks for helpers in the provided `env.helpers`', function() { - var env = generateEnv({ + let env = generateEnv({ 'flubarb'() { } }); - var actual = lookupHelper('flubarb', null, env); + let actual = lookupHelper('flubarb', null, env); equal(actual, env.helpers.flubarb, 'helpers are looked up on env'); }); QUnit.test('returns undefined if no container exists (and helper is not found in env)', function() { - var env = generateEnv(); - var view = {}; + let env = generateEnv(); + let view = {}; - var actual = findHelper('flubarb', view, env); + let actual = findHelper('flubarb', view, env); equal(actual, undefined, 'does not blow up if view does not have a container'); }); QUnit.test('does not lookup in the container if the name does not contain a dash (and helper is not found in env)', function() { - var env = generateEnv(); - var view = { + let env = generateEnv(); + let view = { container: { lookup() { ok(false, 'should not lookup in the container'); @@ -52,38 +52,38 @@ QUnit.test('does not lookup in the container if the name does not contain a dash } }; - var actual = findHelper('flubarb', view, env); + let actual = findHelper('flubarb', view, env); equal(actual, undefined, 'does not blow up if view does not have a container'); }); QUnit.test('does a lookup in the container if the name contains a dash (and helper is not found in env)', function() { let owner = generateOwner(); - var env = generateEnv(null, owner); - var view = { + let env = generateEnv(null, owner); + let view = { [OWNER]: owner }; - var someName = Helper.extend(); + let someName = Helper.extend(); owner.register('helper:some-name', someName); - var actual = lookupHelper('some-name', view, env); + let actual = lookupHelper('some-name', view, env); ok(someName.detect(actual), 'helper is an instance of the helper class'); }); QUnit.test('does a lookup in the container if the name is found in knownHelpers', function() { let owner = generateOwner(); - var env = generateEnv(null, owner); - var view = { + let env = generateEnv(null, owner); + let view = { [OWNER]: owner }; env.knownHelpers['t'] = true; - var t = Helper.extend(); + let t = Helper.extend(); owner.register('helper:t', t); - var actual = lookupHelper('t', view, env); + let actual = lookupHelper('t', view, env); ok(t.detect(actual), 'helper is an instance of the helper class'); }); @@ -91,18 +91,18 @@ QUnit.test('does a lookup in the container if the name is found in knownHelpers' QUnit.test('looks up a shorthand helper in the container', function() { expect(2); let owner = generateOwner(); - var env = generateEnv(null, owner); - var view = { + let env = generateEnv(null, owner); + let view = { [OWNER]: owner }; - var called; + let called; function someName() { called = true; } owner.register('helper:some-name', makeHelper(someName)); - var actual = lookupHelper('some-name', view, env); + let actual = lookupHelper('some-name', view, env); ok(actual.isHelperInstance, 'is a helper'); @@ -114,16 +114,16 @@ QUnit.test('looks up a shorthand helper in the container', function() { QUnit.test('fails with a useful error when resolving a function', function() { expect(1); let owner = generateOwner(); - var env = generateEnv(null, owner); - var view = { + let env = generateEnv(null, owner); + let view = { [OWNER]: owner }; function someName() {} owner.register('helper:some-name', someName); - var actual; - expectAssertion(function() { + let actual; + expectAssertion(() => { actual = lookupHelper('some-name', view, env); }, 'Expected to find an Ember.Helper with the name helper:some-name, but found an object of type function instead.'); }); diff --git a/packages/ember-htmlbars/tests/utils.js b/packages/ember-htmlbars/tests/utils.js index f31bbb08b4e..8067b0e8d4e 100644 --- a/packages/ember-htmlbars/tests/utils.js +++ b/packages/ember-htmlbars/tests/utils.js @@ -65,19 +65,19 @@ function buildAppInstance() { function resolverFor(namespace) { return { resolve(fullName) { - var nameParts = fullName.split(':'); - var type = nameParts[0]; - var name = nameParts[1]; + let nameParts = fullName.split(':'); + let type = nameParts[0]; + let name = nameParts[1]; if (type === 'template') { - var templateName = decamelize(name); + let templateName = decamelize(name); if (hasTemplate(templateName)) { return getTemplate(templateName); } } - var className = classify(name) + classify(type); - var factory = get(namespace, className); + let className = classify(name) + classify(type); + let factory = get(namespace, className); if (factory) { return factory; } } diff --git a/packages/ember-htmlbars/tests/utils/string_test.js b/packages/ember-htmlbars/tests/utils/string_test.js index f9a9287e650..4aa0f0e533f 100644 --- a/packages/ember-htmlbars/tests/utils/string_test.js +++ b/packages/ember-htmlbars/tests/utils/string_test.js @@ -4,20 +4,20 @@ import { htmlSafe } from 'ember-htmlbars/utils/string'; QUnit.module('ember-htmlbars: SafeString'); QUnit.test('htmlSafe should return an instance of SafeString', function() { - var safeString = htmlSafe('you need to be more bold'); + let safeString = htmlSafe('you need to be more bold'); ok(safeString instanceof SafeString, 'should be a SafeString'); }); QUnit.test('htmlSafe should return an empty string for null', function() { - var safeString = htmlSafe(null); + let safeString = htmlSafe(null); equal(safeString instanceof SafeString, true, 'should be a SafeString'); equal(safeString.toString(), '', 'should return an empty string'); }); QUnit.test('htmlSafe should return an empty string for undefined', function() { - var safeString = htmlSafe(); + let safeString = htmlSafe(); equal(safeString instanceof SafeString, true, 'should be a SafeString'); equal(safeString.toString(), '', 'should return an empty string'); diff --git a/packages/ember-metal/lib/alias.js b/packages/ember-metal/lib/alias.js index 0923b5463d2..508875670f7 100644 --- a/packages/ember-metal/lib/alias.js +++ b/packages/ember-metal/lib/alias.js @@ -44,14 +44,14 @@ AliasedProperty.prototype.didUnwatch = function(obj, keyName) { AliasedProperty.prototype.setup = function(obj, keyName) { assert(`Setting alias '${keyName}' on self`, this.altKey !== keyName); - var m = meta(obj); + let m = meta(obj); if (m.peekWatching(keyName)) { addDependentKeys(this, obj, keyName, m); } }; AliasedProperty.prototype.teardown = function(obj, keyName) { - var m = meta(obj); + let m = meta(obj); if (m.peekWatching(keyName)) { removeDependentKeys(this, obj, keyName, m); } diff --git a/packages/ember-metal/lib/cache.js b/packages/ember-metal/lib/cache.js index ff4e1eedcab..e169077ab84 100644 --- a/packages/ember-metal/lib/cache.js +++ b/packages/ember-metal/lib/cache.js @@ -10,7 +10,7 @@ function Cache(limit, func) { this.func = func; } -var UNDEFINED = function() {}; +function UNDEFINED() {} Cache.prototype = { set(key, value) { @@ -27,7 +27,7 @@ Cache.prototype = { }, get(key) { - var value = this.store[key]; + let value = this.store[key]; if (value === undefined) { this.misses ++; diff --git a/packages/ember-metal/lib/chains.js b/packages/ember-metal/lib/chains.js index 4c632e0f941..9e2655657f9 100644 --- a/packages/ember-metal/lib/chains.js +++ b/packages/ember-metal/lib/chains.js @@ -3,7 +3,7 @@ import { meta as metaFor, peekMeta } from 'ember-metal/meta'; import { watchKey, unwatchKey } from 'ember-metal/watch_key'; import EmptyObject from 'ember-metal/empty_object'; -var FIRST_KEY = /^([^\.]+)/; +const FIRST_KEY = /^([^\.]+)/; function firstKey(path) { return path.match(FIRST_KEY)[0]; @@ -37,7 +37,7 @@ ChainWatchers.prototype = { remove(key, node) { let nodes = this.chains[key]; if (nodes) { - for (var i = 0; i < nodes.length; i++) { + for (let i = 0; i < nodes.length; i++) { if (nodes[i] === node) { nodes.splice(i, 1); break; @@ -49,7 +49,7 @@ ChainWatchers.prototype = { has(key, node) { let nodes = this.chains[key]; if (nodes) { - for (var i = 0; i < nodes.length; i++) { + for (let i = 0; i < nodes.length; i++) { if (nodes[i] === node) { return true; } @@ -169,7 +169,7 @@ function lazyGet(obj, key) { return; } - var meta = peekMeta(obj); + let meta = peekMeta(obj); // check if object meant only to be a prototype if (meta && meta.proto === obj) { @@ -191,7 +191,7 @@ function lazyGet(obj, key) { ChainNode.prototype = { value() { if (this._value === undefined && this._watching) { - var obj = this._parent.value(); + let obj = this._parent.value(); this._value = lazyGet(obj, this._key); } return this._value; @@ -199,7 +199,7 @@ ChainNode.prototype = { destroy() { if (this._watching) { - var obj = this._object; + let obj = this._object; if (obj) { removeChainWatcher(obj, this._key, this); } @@ -209,9 +209,9 @@ ChainNode.prototype = { // copies a top level object only copy(obj) { - var ret = new ChainNode(null, null, obj); - var paths = this._paths; - var path; + let ret = new ChainNode(null, null, obj); + let paths = this._paths; + let path; for (path in paths) { // this check will also catch non-number vals. @@ -250,8 +250,8 @@ ChainNode.prototype = { }, chain(key, path) { - var chains = this._chains; - var node; + let chains = this._chains; + let node; if (chains === undefined) { chains = this._chains = new EmptyObject(); } else { @@ -273,13 +273,13 @@ ChainNode.prototype = { }, unchain(key, path) { - var chains = this._chains; - var node = chains[key]; + let chains = this._chains; + let node = chains[key]; // unchain rest of path first... if (path && path.length > 1) { - var nextKey = firstKey(path); - var nextPath = path.slice(nextKey.length + 1); + let nextKey = firstKey(path); + let nextPath = path.slice(nextKey.length + 1); node.unchain(nextKey, nextPath); } @@ -293,7 +293,7 @@ ChainNode.prototype = { notify(revalidate, affected) { if (revalidate && this._watching) { - var obj = this._parent.value(); + let obj = this._parent.value(); if (obj !== this._object) { removeChainWatcher(this._object, this._key, this); this._object = obj; @@ -303,10 +303,10 @@ ChainNode.prototype = { } // then notify chains... - var chains = this._chains; - var node; + let chains = this._chains; + let node; if (chains) { - for (var key in chains) { + for (let key in chains) { node = chains[key]; if (node !== undefined) { node.notify(revalidate, affected); diff --git a/packages/ember-metal/lib/computed.js b/packages/ember-metal/lib/computed.js index eb2b2ee2e94..aa2240c764c 100644 --- a/packages/ember-metal/lib/computed.js +++ b/packages/ember-metal/lib/computed.js @@ -160,7 +160,7 @@ function ComputedProperty(config, opts) { ComputedProperty.prototype = new Descriptor(); -var ComputedPropertyPrototype = ComputedProperty.prototype; +const ComputedPropertyPrototype = ComputedProperty.prototype; /** Call on a computed property to set it into non-cached mode. When in this @@ -246,9 +246,9 @@ ComputedPropertyPrototype.readOnly = function() { @public */ ComputedPropertyPrototype.property = function() { - var args; + let args = []; - var addArg = function(property) { + function addArg(property) { warn( `Dependent keys containing @each only work one level deep. ` + `You cannot use nested forms like todos.@each.owner.name or todos.@each.owner.@each.name. ` + @@ -257,10 +257,9 @@ ComputedPropertyPrototype.property = function() { { id: 'ember-metal.computed-deep-each' } ); args.push(property); - }; + } - args = []; - for (var i = 0; i < arguments.length; i++) { + for (let i = 0; i < arguments.length; i++) { expandProperties(arguments[i], addArg); } @@ -536,14 +535,14 @@ ComputedPropertyPrototype.teardown = function(obj, keyName) { @public */ export default function computed(func) { - var args; + let args; if (arguments.length > 1) { args = [].slice.call(arguments); func = args.pop(); } - var cp = new ComputedProperty(func); + let cp = new ComputedProperty(func); if (args) { cp.property.apply(cp, args); @@ -567,9 +566,9 @@ export default function computed(func) { @public */ function cacheFor(obj, key) { - var meta = peekMeta(obj); - var cache = meta && meta.source === obj && meta.readableCache(); - var ret = cache && cache[key]; + let meta = peekMeta(obj); + let cache = meta && meta.source === obj && meta.readableCache(); + let ret = cache && cache[key]; if (ret === UNDEFINED) { return undefined; @@ -586,7 +585,7 @@ cacheFor.set = function(cache, key, value) { }; cacheFor.get = function(cache, key) { - var ret = cache[key]; + let ret = cache[key]; if (ret === UNDEFINED) { return undefined; } diff --git a/packages/ember-metal/lib/dependent_keys.js b/packages/ember-metal/lib/dependent_keys.js index eff8e3ea606..3887caef9cc 100644 --- a/packages/ember-metal/lib/dependent_keys.js +++ b/packages/ember-metal/lib/dependent_keys.js @@ -19,8 +19,8 @@ import { export function addDependentKeys(desc, obj, keyName, meta) { // the descriptor has a list of dependent keys, so // add all of its dependent keys. - var idx, depKey; - var depKeys = desc._dependentKeys; + let idx, depKey; + let depKeys = desc._dependentKeys; if (!depKeys) { return; } @@ -37,14 +37,13 @@ export function addDependentKeys(desc, obj, keyName, meta) { export function removeDependentKeys(desc, obj, keyName, meta) { // the descriptor has a list of dependent keys, so // remove all of its dependent keys. - var depKeys = desc._dependentKeys; - var idx, depKey; + let depKeys = desc._dependentKeys; if (!depKeys) { return; } - for (idx = 0; idx < depKeys.length; idx++) { - depKey = depKeys[idx]; + for (let idx = 0; idx < depKeys.length; idx++) { + let depKey = depKeys[idx]; // Decrement the number of times depKey depends on keyName. meta.writeDeps(depKey, keyName, (meta.peekDeps(depKey, keyName) || 0) - 1); // Unwatch the depKey diff --git a/packages/ember-metal/lib/dictionary.js b/packages/ember-metal/lib/dictionary.js index 3de8b806b66..b4d878161ab 100644 --- a/packages/ember-metal/lib/dictionary.js +++ b/packages/ember-metal/lib/dictionary.js @@ -6,7 +6,7 @@ import EmptyObject from './empty_object'; // the cost of creation dramatically over a plain Object.create. And as this // only makes sense for long-lived dictionaries that aren't instantiated often. export default function makeDictionary(parent) { - var dict; + let dict; if (parent === null) { dict = new EmptyObject(); } else { diff --git a/packages/ember-metal/lib/empty_object.js b/packages/ember-metal/lib/empty_object.js index dbe6d6ddb35..5585df6fead 100644 --- a/packages/ember-metal/lib/empty_object.js +++ b/packages/ember-metal/lib/empty_object.js @@ -4,7 +4,7 @@ // and don't want your keys colliding with build-in methods on the // default object prototype. -var proto = Object.create(null, { +const proto = Object.create(null, { // without this, we will always still end up with (new // EmptyObject()).constructor === Object constructor: { diff --git a/packages/ember-metal/lib/error.js b/packages/ember-metal/lib/error.js index 508c3eafb2a..d9845d1fc09 100644 --- a/packages/ember-metal/lib/error.js +++ b/packages/ember-metal/lib/error.js @@ -1,4 +1,4 @@ -var errorProps = [ +const errorProps = [ 'description', 'fileName', 'lineNumber', @@ -18,7 +18,7 @@ var errorProps = [ @public */ export default function EmberError() { - var tmp = Error.apply(this, arguments); + let tmp = Error.apply(this, arguments); // Adds a `stack` property to the given error object that will yield the // stack trace at the time captureStackTrace was called. @@ -31,7 +31,7 @@ export default function EmberError() { Error.captureStackTrace(this, EmberError); } // Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work. - for (var idx = 0; idx < errorProps.length; idx++) { + for (let idx = 0; idx < errorProps.length; idx++) { this[errorProps[idx]] = tmp[errorProps[idx]]; } } diff --git a/packages/ember-metal/lib/events.js b/packages/ember-metal/lib/events.js index 0706dc5fcee..41f1bfc3fbf 100644 --- a/packages/ember-metal/lib/events.js +++ b/packages/ember-metal/lib/events.js @@ -33,11 +33,11 @@ import { ONCE, SUSPENDED } from 'ember-metal/meta_listeners'; */ function indexOf(array, target, method) { - var index = -1; + let index = -1; // hashes are added to the end of the event array // so it makes sense to start searching at the end // of the array and search in reverse - for (var i = array.length - 3 ; i >=0; i -= 3) { + for (let i = array.length - 3 ; i >=0; i -= 3) { if (target === array[i] && method === array[i + 1]) { index = i; break; @@ -47,16 +47,16 @@ function indexOf(array, target, method) { } export function accumulateListeners(obj, eventName, otherActions) { - var meta = peekMeta(obj); + let meta = peekMeta(obj); if (!meta) { return; } - var actions = meta.matchingListeners(eventName); - var newActions = []; + let actions = meta.matchingListeners(eventName); + let newActions = []; - for (var i = actions.length - 3; i >= 0; i -= 3) { - var target = actions[i]; - var method = actions[i + 1]; - var flags = actions[i + 2]; - var actionIndex = indexOf(otherActions, target, method); + for (let i = actions.length - 3; i >= 0; i -= 3) { + let target = actions[i]; + let method = actions[i + 1]; + let flags = actions[i + 2]; + let actionIndex = indexOf(otherActions, target, method); if (actionIndex === -1) { otherActions.push(target, method, flags); @@ -99,7 +99,7 @@ export function addListener(obj, eventName, target, method, once) { target = null; } - var flags = 0; + let flags = 0; if (once) { flags |= ONCE; } @@ -211,16 +211,16 @@ export function watchedEvents(obj) { */ export function sendEvent(obj, eventName, params, actions) { if (!actions) { - var meta = peekMeta(obj); + let meta = peekMeta(obj); actions = meta && meta.matchingListeners(eventName); } if (!actions || actions.length === 0) { return; } - for (var i = actions.length - 3; i >= 0; i -= 3) { // looping in reverse for once listeners - var target = actions[i]; - var method = actions[i + 1]; - var flags = actions[i + 2]; + for (let i = actions.length - 3; i >= 0; i -= 3) { // looping in reverse for once listeners + let target = actions[i]; + let method = actions[i + 1]; + let flags = actions[i + 2]; if (!method) { continue; } if (flags & SUSPENDED) { continue; } @@ -251,7 +251,7 @@ export function sendEvent(obj, eventName, params, actions) { @param {String} eventName */ export function hasListeners(obj, eventName) { - var meta = peekMeta(obj); + let meta = peekMeta(obj); if (!meta) { return false; } return meta.matchingListeners(eventName).length > 0; } @@ -264,15 +264,15 @@ export function hasListeners(obj, eventName) { @param {String} eventName */ export function listenersFor(obj, eventName) { - var ret = []; - var meta = peekMeta(obj); - var actions = meta && meta.matchingListeners(eventName); + let ret = []; + let meta = peekMeta(obj); + let actions = meta && meta.matchingListeners(eventName); if (!actions) { return ret; } - for (var i = 0; i < actions.length; i += 3) { - var target = actions[i]; - var method = actions[i + 1]; + for (let i = 0; i < actions.length; i += 3) { + let target = actions[i]; + let method = actions[i + 1]; ret.push([target, method]); } @@ -285,13 +285,13 @@ export function listenersFor(obj, eventName) { ``` javascript - var Job = Ember.Object.extend({ + let Job = Ember.Object.extend({ logCompleted: Ember.on('completed', function() { console.log('Job completed!'); }) }); - var job = Job.create(); + let job = Job.create(); Ember.sendEvent(job, 'completed'); // Logs 'Job completed!' ``` @@ -304,8 +304,8 @@ export function listenersFor(obj, eventName) { @public */ export function on(...args) { - var func = args.pop(); - var events = args; + let func = args.pop(); + let events = args; func.__ember_listens__ = events; return func; } diff --git a/packages/ember-metal/lib/expand_properties.js b/packages/ember-metal/lib/expand_properties.js index e2f1dd04d47..ce7fc6ce82a 100644 --- a/packages/ember-metal/lib/expand_properties.js +++ b/packages/ember-metal/lib/expand_properties.js @@ -5,8 +5,8 @@ import { assert } from 'ember-metal/debug'; @submodule ember-metal */ -var SPLIT_REGEX = /\{|\}/; -var END_WITH_EACH_REGEX = /\.@each$/; +const SPLIT_REGEX = /\{|\}/; +const END_WITH_EACH_REGEX = /\.@each$/; /** Expands `pattern`, invoking `callback` for each expansion. @@ -42,8 +42,8 @@ export default function expandProperties(pattern, callback) { pattern.indexOf(' ') === -1 ); - var parts = pattern.split(SPLIT_REGEX); - var properties = [parts]; + let parts = pattern.split(SPLIT_REGEX); + let properties = [parts]; for (let i = 0; i < parts.length; i++) { let part = parts[i]; @@ -58,11 +58,11 @@ export default function expandProperties(pattern, callback) { } function duplicateAndReplace(properties, currentParts, index) { - var all = []; + let all = []; properties.forEach((property) => { currentParts.forEach((part) => { - var current = property.slice(0); + let current = property.slice(0); current[index] = part; all.push(current); }); diff --git a/packages/ember-metal/lib/get_properties.js b/packages/ember-metal/lib/get_properties.js index 7a27080aaec..7b66b541342 100644 --- a/packages/ember-metal/lib/get_properties.js +++ b/packages/ember-metal/lib/get_properties.js @@ -24,9 +24,9 @@ import { get } from 'ember-metal/property_get'; @public */ export default function getProperties(obj) { - var ret = {}; - var propertyNames = arguments; - var i = 1; + let ret = {}; + let propertyNames = arguments; + let i = 1; if (arguments.length === 2 && Array.isArray(arguments[1])) { i = 0; diff --git a/packages/ember-metal/lib/index.js b/packages/ember-metal/lib/index.js index 70a36383f8f..f0529234850 100644 --- a/packages/ember-metal/lib/index.js +++ b/packages/ember-metal/lib/index.js @@ -161,7 +161,7 @@ import Backburner from 'backburner'; // END IMPORTS // BEGIN EXPORTS -var EmberInstrumentation = Ember.Instrumentation = {}; +const EmberInstrumentation = Ember.Instrumentation = {}; EmberInstrumentation.instrument = instrument; EmberInstrumentation.subscribe = instrumentationSubscribe; EmberInstrumentation.unsubscribe = instrumentationUnsubscribe; @@ -329,31 +329,31 @@ Ember.EXTEND_PROTOTYPES = ENV.EXTEND_PROTOTYPES; // BACKWARDS COMPAT ACCESSORS FOR ENV FLAGS Object.defineProperty(Ember, 'LOG_STACKTRACE_ON_DEPRECATION', { - get: () => ENV.LOG_STACKTRACE_ON_DEPRECATION, - set: value => ENV.LOG_STACKTRACE_ON_DEPRECATION = !!value, + get() { return ENV.LOG_STACKTRACE_ON_DEPRECATION; }, + set(value) { ENV.LOG_STACKTRACE_ON_DEPRECATION = !!value; }, enumerable: false }); Object.defineProperty(Ember, 'LOG_VERSION', { - get: () => ENV.LOG_VERSION, - set: value => ENV.LOG_VERSION = !!value, + get() { return ENV.LOG_VERSION; }, + set(value) { ENV.LOG_VERSION = !!value; }, enumerable: false }); Object.defineProperty(Ember, 'MODEL_FACTORY_INJECTIONS', { - get: () => ENV.MODEL_FACTORY_INJECTIONS, - set: value => ENV.MODEL_FACTORY_INJECTIONS = !!value, + get() { return ENV.MODEL_FACTORY_INJECTIONS; }, + set(value) { ENV.MODEL_FACTORY_INJECTIONS = !!value; }, enumerable: false }); Object.defineProperty(Ember, 'LOG_BINDINGS', { - get: () => ENV.LOG_BINDINGS, - set: value => ENV.LOG_BINDINGS = !!value, + get() { return ENV.LOG_BINDINGS; }, + set(value) { ENV.LOG_BINDINGS = !!value; }, enumerable: false }); Object.defineProperty(Ember, 'ENV', { - get: () => ENV, + get() { return ENV; }, enumerable: false }); @@ -363,8 +363,8 @@ Object.defineProperty(Ember, 'ENV', { @private */ Object.defineProperty(Ember, 'lookup', { - get: () => context.lookup, - set: value => context.lookup = value, + get() { return context.lookup; }, + set(value) { context.lookup = value; }, enumerable: false }); diff --git a/packages/ember-metal/lib/injected_property.js b/packages/ember-metal/lib/injected_property.js index 9b461c80695..bd5e07af65f 100644 --- a/packages/ember-metal/lib/injected_property.js +++ b/packages/ember-metal/lib/injected_property.js @@ -15,7 +15,7 @@ import { getOwner } from 'container/owner'; to the property's name @private */ -function InjectedProperty(type, name) { +export default function InjectedProperty(type, name) { this.type = type; this.name = name; @@ -24,7 +24,7 @@ function InjectedProperty(type, name) { } function injectedPropertyGet(keyName) { - var desc = this[keyName]; + let desc = this[keyName]; let owner = getOwner(this) || this.container; // fallback to `container` for backwards compat assert(`InjectedProperties should be defined with the Ember.inject computed property macros.`, desc && desc.isDescriptor && desc.type); @@ -35,15 +35,12 @@ function injectedPropertyGet(keyName) { InjectedProperty.prototype = Object.create(Descriptor.prototype); -var InjectedPropertyPrototype = InjectedProperty.prototype; -var ComputedPropertyPrototype = ComputedProperty.prototype; -var AliasedPropertyPrototype = AliasedProperty.prototype; +const InjectedPropertyPrototype = InjectedProperty.prototype; +const ComputedPropertyPrototype = ComputedProperty.prototype; +const AliasedPropertyPrototype = AliasedProperty.prototype; InjectedPropertyPrototype._super$Constructor = ComputedProperty; InjectedPropertyPrototype.get = ComputedPropertyPrototype.get; InjectedPropertyPrototype.readOnly = ComputedPropertyPrototype.readOnly; - InjectedPropertyPrototype.teardown = ComputedPropertyPrototype.teardown; - -export default InjectedProperty; diff --git a/packages/ember-metal/lib/instrumentation.js b/packages/ember-metal/lib/instrumentation.js index dab363afbc0..72c2ad95e2e 100644 --- a/packages/ember-metal/lib/instrumentation.js +++ b/packages/ember-metal/lib/instrumentation.js @@ -10,11 +10,11 @@ import isEnabled from 'ember-metal/features'; ```javascript Ember.subscribe("render", { - before: function(name, timestamp, payload) { + before(name, timestamp, payload) { }, - after: function(name, timestamp, payload) { + after(name, timestamp, payload) { } }); @@ -48,14 +48,14 @@ import isEnabled from 'ember-metal/features'; @static @private */ -export var subscribers = []; -var cache = {}; +export let subscribers = []; +let cache = {}; -var populateListeners = function(name) { - var listeners = []; - var subscriber; +function populateListeners(name) { + let listeners = []; + let subscriber; - for (var i = 0; i < subscribers.length; i++) { + for (let i = 0; i < subscribers.length; i++) { subscriber = subscribers[i]; if (subscriber.regex.test(name)) { listeners.push(subscriber.object); @@ -64,11 +64,11 @@ var populateListeners = function(name) { cache[name] = listeners; return listeners; -}; +} -var time = (function() { - var perf = 'undefined' !== typeof window ? window.performance || {} : {}; - var fn = perf.now || perf.mozNow || perf.webkitNow || perf.msNow || perf.oNow; +const time = (function() { + let perf = 'undefined' !== typeof window ? window.performance || {} : {}; + let fn = perf.now || perf.mozNow || perf.webkitNow || perf.msNow || perf.oNow; // fn.bind will be available in all the browsers that support the advanced window.performance... ;-) return fn ? fn.bind(perf) : () => { return +new Date(); @@ -96,8 +96,8 @@ export function instrument(name, _payload, callback, binding) { if (subscribers.length === 0) { return callback.call(binding); } - var payload = _payload || {}; - var finalizer = _instrumentStart(name, () => payload); + let payload = _payload || {}; + let finalizer = _instrumentStart(name, () => payload); if (finalizer) { return withFinalizer(callback, finalizer, payload, binding); @@ -106,13 +106,11 @@ export function instrument(name, _payload, callback, binding) { } } -var flaggedInstrument; +let flaggedInstrument; if (isEnabled('ember-improved-instrumentation')) { flaggedInstrument = instrument; } else { - flaggedInstrument = function(name, payload, callback) { - return callback(); - }; + flaggedInstrument = (name, payload, callback) => callback(); } export { flaggedInstrument }; @@ -131,7 +129,7 @@ function withFinalizer(callback, finalizer, payload, binding) { // private for now export function _instrumentStart(name, _payload) { - var listeners = cache[name]; + let listeners = cache[name]; if (!listeners) { listeners = populateListeners(name); @@ -141,26 +139,26 @@ export function _instrumentStart(name, _payload) { return; } - var payload = _payload(); + let payload = _payload(); - var STRUCTURED_PROFILE = ENV.STRUCTURED_PROFILE; - var timeName; + let STRUCTURED_PROFILE = ENV.STRUCTURED_PROFILE; + let timeName; if (STRUCTURED_PROFILE) { timeName = name + ': ' + payload.object; console.time(timeName); } - var beforeValues = new Array(listeners.length); - var i, listener; - var timestamp = time(); + let beforeValues = new Array(listeners.length); + let i, listener; + let timestamp = time(); for (i = 0; i < listeners.length; i++) { listener = listeners[i]; beforeValues[i] = listener.before(name, timestamp, payload); } return function _instrumentEnd() { - var i, listener; - var timestamp = time(); + let i, listener; + let timestamp = time(); for (i = 0; i < listeners.length; i++) { listener = listeners[i]; if (typeof listener.after === 'function') { @@ -187,11 +185,11 @@ export function _instrumentStart(name, _payload) { @private */ export function subscribe(pattern, object) { - var paths = pattern.split('.'); - var path; - var regex = []; + let paths = pattern.split('.'); + let path; + let regex = []; - for (var i = 0; i < paths.length; i++) { + for (let i = 0; i < paths.length; i++) { path = paths[i]; if (path === '*') { regex.push('[^\\.]*'); @@ -203,7 +201,7 @@ export function subscribe(pattern, object) { regex = regex.join('\\.'); regex = regex + '(\\..*)?'; - var subscriber = { + let subscriber = { pattern: pattern, regex: new RegExp('^' + regex + '$'), object: object @@ -225,9 +223,9 @@ export function subscribe(pattern, object) { @private */ export function unsubscribe(subscriber) { - var index; + let index; - for (var i = 0; i < subscribers.length; i++) { + for (let i = 0; i < subscribers.length; i++) { if (subscribers[i] === subscriber) { index = i; } diff --git a/packages/ember-metal/lib/is_empty.js b/packages/ember-metal/lib/is_empty.js index f86b8016da2..541b3a82fd9 100644 --- a/packages/ember-metal/lib/is_empty.js +++ b/packages/ember-metal/lib/is_empty.js @@ -27,8 +27,8 @@ import isNone from 'ember-metal/is_none'; @return {Boolean} @public */ -function isEmpty(obj) { - var none = isNone(obj); +export default function isEmpty(obj) { + let none = isNone(obj); if (none) { return none; } @@ -37,10 +37,10 @@ function isEmpty(obj) { return !obj.size; } - var objectType = typeof obj; + let objectType = typeof obj; if (objectType === 'object') { - var size = get(obj, 'size'); + let size = get(obj, 'size'); if (typeof size === 'number') { return !size; } @@ -51,7 +51,7 @@ function isEmpty(obj) { } if (objectType === 'object') { - var length = get(obj, 'length'); + let length = get(obj, 'length'); if (typeof length === 'number') { return !length; } @@ -59,5 +59,3 @@ function isEmpty(obj) { return false; } - -export default isEmpty; diff --git a/packages/ember-metal/lib/libraries.js b/packages/ember-metal/lib/libraries.js index 6fde99f8d09..56dabfd8302 100644 --- a/packages/ember-metal/lib/libraries.js +++ b/packages/ember-metal/lib/libraries.js @@ -19,10 +19,10 @@ Libraries.prototype = { constructor: Libraries, _getLibraryByName(name) { - var libs = this._registry; - var count = libs.length; + let libs = this._registry; + let count = libs.length; - for (var i = 0; i < count; i++) { + for (let i = 0; i < count; i++) { if (libs[i].name === name) { return libs[i]; } @@ -30,7 +30,7 @@ Libraries.prototype = { }, register(name, version, isCoreLibrary) { - var index = this._registry.length; + let index = this._registry.length; if (!this._getLibraryByName(name)) { if (isCoreLibrary) { @@ -47,8 +47,8 @@ Libraries.prototype = { }, deRegister(name) { - var lib = this._getLibraryByName(name); - var index; + let lib = this._getLibraryByName(name); + let index; if (lib) { index = this._registry.indexOf(lib); diff --git a/packages/ember-metal/lib/map.js b/packages/ember-metal/lib/map.js index 217140b8877..a165cb0c540 100644 --- a/packages/ember-metal/lib/map.js +++ b/packages/ember-metal/lib/map.js @@ -32,9 +32,9 @@ function missingNew(name) { } function copyNull(obj) { - var output = new EmptyObject(); + let output = new EmptyObject(); - for (var prop in obj) { + for (let prop in obj) { // hasOwnPropery is not needed because obj is new EmptyObject(); output[prop] = obj[prop]; } @@ -43,8 +43,8 @@ function copyNull(obj) { } function copyMap(original, newObject) { - var keys = original._keys.copy(); - var values = copyNull(original._values); + let keys = original._keys.copy(); + let values = copyNull(original._values); newObject._keys = keys; newObject._values = values; @@ -79,7 +79,7 @@ function OrderedSet() { @private */ OrderedSet.create = function() { - var Constructor = this; + let Constructor = this; return new Constructor(); }; @@ -104,9 +104,9 @@ OrderedSet.prototype = { @private */ add(obj, _guid) { - var guid = _guid || guidFor(obj); - var presenceSet = this.presenceSet; - var list = this.list; + let guid = _guid || guidFor(obj); + let presenceSet = this.presenceSet; + let list = this.list; if (presenceSet[guid] !== true) { presenceSet[guid] = true; @@ -125,13 +125,13 @@ OrderedSet.prototype = { @private */ delete(obj, _guid) { - var guid = _guid || guidFor(obj); - var presenceSet = this.presenceSet; - var list = this.list; + let guid = _guid || guidFor(obj); + let presenceSet = this.presenceSet; + let list = this.list; if (presenceSet[guid] === true) { delete presenceSet[guid]; - var index = list.indexOf(obj); + let index = list.indexOf(obj); if (index > -1) { list.splice(index, 1); } @@ -160,8 +160,8 @@ OrderedSet.prototype = { has(obj) { if (this.size === 0) { return false; } - var guid = guidFor(obj); - var presenceSet = this.presenceSet; + let guid = guidFor(obj); + let presenceSet = this.presenceSet; return presenceSet[guid] === true; }, @@ -179,15 +179,14 @@ OrderedSet.prototype = { if (this.size === 0) { return; } - var list = this.list; - var i; + let list = this.list; if (arguments.length === 2) { - for (i = 0; i < list.length; i++) { + for (let i = 0; i < list.length; i++) { fn.call(arguments[1], list[i]); } } else { - for (i = 0; i < list.length; i++) { + for (let i = 0; i < list.length; i++) { fn(list[i]); } } @@ -208,8 +207,8 @@ OrderedSet.prototype = { @private */ copy() { - var Constructor = this.constructor; - var set = new Constructor(); + let Constructor = this.constructor; + let set = new Constructor(); set._silenceRemoveDeprecation = this._silenceRemoveDeprecation; set.presenceSet = copyNull(this.presenceSet); @@ -257,7 +256,7 @@ function Map() { @private */ Map.create = function() { - var Constructor = this; + let Constructor = this; return new Constructor(); }; @@ -286,8 +285,8 @@ Map.prototype = { get(key) { if (this.size === 0) { return; } - var values = this._values; - var guid = guidFor(key); + let values = this._values; + let guid = guidFor(key); return values[guid]; }, @@ -303,12 +302,12 @@ Map.prototype = { @private */ set(key, value) { - var keys = this._keys; - var values = this._values; - var guid = guidFor(key); + let keys = this._keys; + let values = this._values; + let guid = guidFor(key); // ensure we don't store -0 - var k = key === -0 ? 0 : key; + let k = key === -0 ? 0 : key; keys.add(k, guid); @@ -332,9 +331,9 @@ Map.prototype = { if (this.size === 0) { return false; } // don't use ES6 "delete" because it will be annoying // to use in browsers that are not ES6 friendly; - var keys = this._keys; - var values = this._values; - var guid = guidFor(key); + let keys = this._keys; + let values = this._values; + let guid = guidFor(key); if (keys.delete(key, guid)) { delete values[guid]; @@ -377,18 +376,14 @@ Map.prototype = { if (this.size === 0) { return; } - var map = this; - var cb, thisArg; + let map = this; + let cb, thisArg; if (arguments.length === 2) { thisArg = arguments[1]; - cb = function(key) { - callback.call(thisArg, map.get(key), key, map); - }; + cb = key => callback.call(thisArg, map.get(key), key, map); } else { - cb = function(key) { - callback(map.get(key), key, map); - }; + cb = key => callback(map.get(key), key, map); } this._keys.forEach(cb); @@ -459,12 +454,12 @@ MapWithDefault.prototype._super$get = Map.prototype.get; @private */ MapWithDefault.prototype.get = function(key) { - var hasValue = this.has(key); + let hasValue = this.has(key); if (hasValue) { return this._super$get(key); } else { - var defaultValue = this.defaultValue(key); + let defaultValue = this.defaultValue(key); this.set(key, defaultValue); return defaultValue; } @@ -476,7 +471,7 @@ MapWithDefault.prototype.get = function(key) { @private */ MapWithDefault.prototype.copy = function() { - var Constructor = this.constructor; + let Constructor = this.constructor; return copyMap(this, new Constructor({ defaultValue: this.defaultValue })); diff --git a/packages/ember-metal/lib/merge.js b/packages/ember-metal/lib/merge.js index 2d806915c07..6637e3d2b4a 100644 --- a/packages/ember-metal/lib/merge.js +++ b/packages/ember-metal/lib/merge.js @@ -3,8 +3,8 @@ ```javascript Ember.merge({first: 'Tom'}, {last: 'Dale'}); // {first: 'Tom', last: 'Dale'} - var a = {first: 'Yehuda'}; - var b = {last: 'Katz'}; + let a = {first: 'Yehuda'}; + let b = {last: 'Katz'}; Ember.merge(a, b); // a == {first: 'Yehuda', last: 'Katz'}, b == {last: 'Katz'} ``` @@ -20,10 +20,10 @@ export default function merge(original, updates) { return original; } - var props = Object.keys(updates); - var prop; + let props = Object.keys(updates); + let prop; - for (var i = 0; i < props.length; i++) { + for (let i = 0; i < props.length; i++) { prop = props[i]; original[prop] = updates[prop]; } diff --git a/packages/ember-metal/lib/meta.js b/packages/ember-metal/lib/meta.js index 74aeca6e55d..9e2fcc387cd 100644 --- a/packages/ember-metal/lib/meta.js +++ b/packages/ember-metal/lib/meta.js @@ -305,7 +305,7 @@ export var META_DESC = { value: null }; -var EMBER_META_PROPERTY = { +const EMBER_META_PROPERTY = { name: META_FIELD, descriptor: META_DESC }; diff --git a/packages/ember-metal/lib/meta_listeners.js b/packages/ember-metal/lib/meta_listeners.js index 736dda52585..5b8ec74500e 100644 --- a/packages/ember-metal/lib/meta_listeners.js +++ b/packages/ember-metal/lib/meta_listeners.js @@ -11,10 +11,10 @@ */ /* listener flags */ -export var ONCE = 1; -export var SUSPENDED = 2; +export const ONCE = 1; +export const SUSPENDED = 2; -export var protoMethods = { +export const protoMethods = { addToListeners(eventName, target, method, flags) { if (!this._listeners) { diff --git a/packages/ember-metal/lib/mixin.js b/packages/ember-metal/lib/mixin.js index 65489a7a0eb..1e8f53fdc3f 100644 --- a/packages/ember-metal/lib/mixin.js +++ b/packages/ember-metal/lib/mixin.js @@ -37,8 +37,7 @@ import { function ROOT() {} ROOT.__hasSuper = false; -var REQUIRED; -var a_slice = [].slice; +const a_slice = [].slice; function isMethod(obj) { return 'function' === typeof obj && @@ -51,10 +50,10 @@ function isMethod(obj) { obj !== String; } -var CONTINUE = {}; +const CONTINUE = {}; function mixinProperties(mixinsMeta, mixin) { - var guid; + let guid; if (mixin instanceof Mixin) { guid = guidFor(mixin); @@ -67,7 +66,7 @@ function mixinProperties(mixinsMeta, mixin) { } function concatenatedMixinProperties(concatProp, props, values, base) { - var concats; + let concats; // reset before adding each new mixin to pickup concats from previous concats = values[concatProp] || base[concatProp]; @@ -79,7 +78,7 @@ function concatenatedMixinProperties(concatProp, props, values, base) { } function giveDescriptorSuper(meta, key, property, values, descs, base) { - var superProperty; + let superProperty; // Computed properties override methods, and do not call super to them if (values[key] === undefined) { @@ -90,8 +89,8 @@ function giveDescriptorSuper(meta, key, property, values, descs, base) { // If we didn't find the original descriptor in a parent mixin, find // it on the original object. if (!superProperty) { - var possibleDesc = base[key]; - var superDesc = (possibleDesc !== null && typeof possibleDesc === 'object' && possibleDesc.isDescriptor) ? possibleDesc : undefined; + let possibleDesc = base[key]; + let superDesc = (possibleDesc !== null && typeof possibleDesc === 'object' && possibleDesc.isDescriptor) ? possibleDesc : undefined; superProperty = superDesc; } @@ -117,7 +116,7 @@ function giveDescriptorSuper(meta, key, property, values, descs, base) { } function giveMethodSuper(obj, key, method, values, descs) { - var superMethod; + let superMethod; // Methods overwrite computed properties, and do not call super to them. if (descs[key] === undefined) { @@ -138,7 +137,7 @@ function giveMethodSuper(obj, key, method, values, descs) { } function applyConcatenatedProperties(obj, key, value, values) { - var baseValue = values[key] || obj[key]; + let baseValue = values[key] || obj[key]; if (baseValue) { if ('function' === typeof baseValue.concat) { @@ -156,7 +155,7 @@ function applyConcatenatedProperties(obj, key, value, values) { } function applyMergedProperties(obj, key, value, values) { - var baseValue = values[key] || obj[key]; + let baseValue = values[key] || obj[key]; runInDebug(function() { if (Array.isArray(value)) { // use conditional to avoid stringifying every time @@ -166,13 +165,13 @@ function applyMergedProperties(obj, key, value, values) { if (!baseValue) { return value; } - var newBase = assign({}, baseValue); - var hasFunction = false; + let newBase = assign({}, baseValue); + let hasFunction = false; - for (var prop in value) { + for (let prop in value) { if (!value.hasOwnProperty(prop)) { continue; } - var propValue = value[prop]; + let propValue = value[prop]; if (isMethod(propValue)) { // TODO: support for Computed Properties, etc? hasFunction = true; @@ -218,14 +217,14 @@ function addNormalizedProperty(base, key, value, meta, descs, values, concats, m } function mergeMixins(mixins, m, descs, values, base, keys) { - var currentMixin, props, key, concats, mergings, meta; + let currentMixin, props, key, concats, mergings, meta; function removeKeys(keyName) { delete descs[keyName]; delete values[keyName]; } - for (var i = 0; i < mixins.length; i++) { + for (let i = 0; i < mixins.length; i++) { currentMixin = mixins[i]; assert( `Expected hash or Mixin instance, got ${Object.prototype.toString.call(currentMixin)}`, @@ -256,7 +255,7 @@ function mergeMixins(mixins, m, descs, values, base, keys) { } } -var IS_BINDING = /^.+Binding$/; +let IS_BINDING = /^.+Binding$/; function detectBinding(obj, key, value, m) { if (IS_BINDING.test(key)) { @@ -289,9 +288,9 @@ function finishPartial(obj, m) { } function followAlias(obj, desc, m, descs, values) { - var altKey = desc.methodName; - var value; - var possibleDesc; + let altKey = desc.methodName; + let value; + let possibleDesc; if (descs[altKey] || values[altKey]) { value = values[altKey]; desc = descs[altKey]; @@ -307,17 +306,17 @@ function followAlias(obj, desc, m, descs, values) { } function updateObserversAndListeners(obj, key, observerOrListener, pathsKey, updateMethod) { - var paths = observerOrListener[pathsKey]; + let paths = observerOrListener[pathsKey]; if (paths) { - for (var i = 0; i < paths.length; i++) { + for (let i = 0; i < paths.length; i++) { updateMethod(obj, paths[i], null, key); } } } function replaceObserversAndListeners(obj, key, observerOrListener) { - var prev = obj[key]; + let prev = obj[key]; if ('function' === typeof prev) { updateObserversAndListeners(obj, key, prev, '__ember_observesBefore__', _removeBeforeObserver); @@ -333,11 +332,11 @@ function replaceObserversAndListeners(obj, key, observerOrListener) { } function applyMixin(obj, mixins, partial) { - var descs = {}; - var values = {}; - var m = metaFor(obj); - var keys = []; - var key, value, desc; + let descs = {}; + let values = {}; + let m = metaFor(obj); + let keys = []; + let key, value, desc; obj._super = ROOT; @@ -350,7 +349,7 @@ function applyMixin(obj, mixins, partial) { // * Copying `toString` in broken browsers mergeMixins(mixins, m, descs, values, obj, keys); - for (var i = 0; i < keys.length; i++) { + for (let i = 0; i < keys.length; i++) { key = keys[i]; if (key === 'constructor' || !values.hasOwnProperty(key)) { continue; } @@ -360,7 +359,7 @@ function applyMixin(obj, mixins, partial) { if (desc === REQUIRED) { continue; } while (desc && desc instanceof Alias) { - var followed = followAlias(obj, desc, m, descs, values); + let followed = followAlias(obj, desc, m, descs, values); desc = followed.desc; value = followed.value; } @@ -452,13 +451,13 @@ export const NAME_KEY = GUID_KEY + '_name'; export default function Mixin(args, properties) { this.properties = properties; - var length = args && args.length; + let length = args && args.length; if (length > 0) { - var m = new Array(length); + let m = new Array(length); - for (var i = 0; i < length; i++) { - var x = args[i]; + for (let i = 0; i < length; i++) { + let x = args[i]; if (x instanceof Mixin) { m[i] = x; } else { @@ -480,7 +479,7 @@ export default function Mixin(args, properties) { Mixin._apply = applyMixin; Mixin.applyPartial = function(obj) { - var args = a_slice.call(arguments, 1); + let args = a_slice.call(arguments, 1); return applyMixin(obj, args, true); }; @@ -505,12 +504,11 @@ export function clearUnprocessedMixins() { Mixin.create = function(...args) { // ES6TODO: this relies on a global state? unprocessedFlag = true; - var M = this; + let M = this; return new M(args, undefined); }; -var MixinPrototype = Mixin.prototype; - +let MixinPrototype = Mixin.prototype; /** @method reopen @@ -518,7 +516,7 @@ var MixinPrototype = Mixin.prototype; @private */ MixinPrototype.reopen = function() { - var currentMixin; + let currentMixin; if (this.properties) { currentMixin = new Mixin(undefined, this.properties); @@ -528,8 +526,8 @@ MixinPrototype.reopen = function() { this.mixins = []; } - var mixins = this.mixins; - var idx; + let mixins = this.mixins; + let idx; for (idx = 0; idx < arguments.length; idx++) { currentMixin = arguments[idx]; @@ -566,14 +564,14 @@ MixinPrototype.applyPartial = function(obj) { MixinPrototype.toString = Object.toString; function _detect(curMixin, targetMixin, seen) { - var guid = guidFor(curMixin); + let guid = guidFor(curMixin); if (seen[guid]) { return false; } seen[guid] = true; if (curMixin === targetMixin) { return true; } - var mixins = curMixin.mixins; - var loc = mixins ? mixins.length : 0; + let mixins = curMixin.mixins; + let loc = mixins ? mixins.length : 0; while (--loc >= 0) { if (_detect(mixins[loc], targetMixin, seen)) { return true; } } @@ -589,13 +587,13 @@ function _detect(curMixin, targetMixin, seen) { MixinPrototype.detect = function(obj) { if (!obj) { return false; } if (obj instanceof Mixin) { return _detect(obj, this, {}); } - var m = peekMeta(obj); + let m = peekMeta(obj); if (!m) { return false; } return !!m.peekMixins(guidFor(this)); }; MixinPrototype.without = function(...args) { - var ret = new Mixin([this]); + let ret = new Mixin([this]); ret._without = args; return ret; }; @@ -605,9 +603,9 @@ function _keys(ret, mixin, seen) { seen[guidFor(mixin)] = true; if (mixin.properties) { - var props = Object.keys(mixin.properties); - for (var i = 0; i < props.length; i++) { - var key = props[i]; + let props = Object.keys(mixin.properties); + for (let i = 0; i < props.length; i++) { + let key = props[i]; ret[key] = true; } } else if (mixin.mixins) { @@ -616,11 +614,11 @@ function _keys(ret, mixin, seen) { } MixinPrototype.keys = function() { - var keys = {}; - var seen = {}; + let keys = {}; + let seen = {}; _keys(keys, this, seen); - var ret = Object.keys(keys); + let ret = Object.keys(keys); return ret; }; @@ -629,8 +627,8 @@ debugSeal(MixinPrototype); // returns the mixins currently applied to the specified object // TODO: Make Ember.mixin Mixin.mixins = function(obj) { - var m = peekMeta(obj); - var ret = []; + let m = peekMeta(obj); + let ret = []; if (!m) { return ret; } m.forEachMixins((key, currentMixin) => { @@ -641,7 +639,7 @@ Mixin.mixins = function(obj) { return ret; }; -REQUIRED = new Descriptor(); +const REQUIRED = new Descriptor(); REQUIRED.toString = function() { return '(Required Property)'; }; /** @@ -678,7 +676,7 @@ Alias.prototype = new Descriptor(); moniker: Ember.aliasMethod('name') }); - var goodGuy = App.Person.create(); + let goodGuy = App.Person.create(); goodGuy.name(); // 'Tomhuda Katzdale' goodGuy.moniker(); // 'Tomhuda Katzdale' @@ -719,13 +717,13 @@ export function aliasMethod(methodName) { @public */ export function observer(...args) { - var func = args.slice(-1)[0]; - var paths; + let func = args.slice(-1)[0]; + let paths; - var addWatchedProperty = function(path) { + let addWatchedProperty = function(path) { paths.push(path); }; - var _paths = args.slice(0, -1); + let _paths = args.slice(0, -1); if (typeof func !== 'function') { // revert to old, soft-deprecated argument ordering @@ -737,7 +735,7 @@ export function observer(...args) { paths = []; - for (var i = 0; i < _paths.length; ++i) { + for (let i = 0; i < _paths.length; ++i) { expandProperties(_paths[i], addWatchedProperty); } @@ -777,8 +775,8 @@ export function observer(...args) { export function _immediateObserver() { deprecate('Usage of `Ember.immediateObserver` is deprecated, use `Ember.observer` instead.', false, { id: 'ember-metal.immediate-observer', until: '3.0.0' }); - for (var i = 0; i < arguments.length; i++) { - var arg = arguments[i]; + for (let i = 0; i < arguments.length; i++) { + let arg = arguments[i]; assert( 'Immediate observers must observe internal properties only, not properties on other objects.', typeof arg !== 'string' || arg.indexOf('.') === -1 @@ -805,7 +803,7 @@ export function _immediateObserver() { valueDidChange: Ember.observer('content.value', function(obj, keyName) { // only run if updating a value already in the DOM if (this.get('state') === 'inDOM') { - var color = obj.get(keyName) > this.changingFrom ? 'green' : 'red'; + let color = obj.get(keyName) > this.changingFrom ? 'green' : 'red'; // logic } }), @@ -829,12 +827,12 @@ export function _immediateObserver() { @private */ export function _beforeObserver(...args) { - var func = args.slice(-1)[0]; - var paths; + let func = args.slice(-1)[0]; + let paths; - var addWatchedProperty = function(path) { paths.push(path); }; + let addWatchedProperty = function(path) { paths.push(path); }; - var _paths = args.slice(0, -1); + let _paths = args.slice(0, -1); if (typeof func !== 'function') { // revert to old, soft-deprecated argument ordering @@ -845,7 +843,7 @@ export function _beforeObserver(...args) { paths = []; - for (var i = 0; i < _paths.length; ++i) { + for (let i = 0; i < _paths.length; ++i) { expandProperties(_paths[i], addWatchedProperty); } diff --git a/packages/ember-metal/lib/observer.js b/packages/ember-metal/lib/observer.js index fe56218fec2..9efec41d466 100644 --- a/packages/ember-metal/lib/observer.js +++ b/packages/ember-metal/lib/observer.js @@ -13,8 +13,8 @@ import { @module ember-metal */ -var AFTER_OBSERVERS = ':change'; -var BEFORE_OBSERVERS = ':before'; +const AFTER_OBSERVERS = ':change'; +const BEFORE_OBSERVERS = ':before'; function changeEvent(keyName) { return keyName + AFTER_OBSERVERS; @@ -86,7 +86,7 @@ export function _suspendObserver(obj, path, target, method, callback) { } export function _suspendObservers(obj, paths, target, method, callback) { - var events = paths.map(changeEvent); + let events = paths.map(changeEvent); return suspendListeners(obj, events, target, method, callback); } diff --git a/packages/ember-metal/lib/observer_set.js b/packages/ember-metal/lib/observer_set.js index a59b5dbea5b..a3ebcc555d2 100644 --- a/packages/ember-metal/lib/observer_set.js +++ b/packages/ember-metal/lib/observer_set.js @@ -19,18 +19,17 @@ import { sendEvent } from 'ember-metal/events'; ... ] */ -export default ObserverSet; -function ObserverSet() { +export default function ObserverSet() { this.clear(); } ObserverSet.prototype.add = function(sender, keyName, eventName) { - var observerSet = this.observerSet; - var observers = this.observers; - var senderGuid = guidFor(sender); - var keySet = observerSet[senderGuid]; - var index; + let observerSet = this.observerSet; + let observers = this.observers; + let senderGuid = guidFor(sender); + let keySet = observerSet[senderGuid]; + let index; if (!keySet) { observerSet[senderGuid] = keySet = {}; @@ -49,8 +48,8 @@ ObserverSet.prototype.add = function(sender, keyName, eventName) { }; ObserverSet.prototype.flush = function() { - var observers = this.observers; - var i, observer, sender; + let observers = this.observers; + let i, observer, sender; this.clear(); for (i = 0; i < observers.length; ++i) { observer = observers[i]; @@ -64,4 +63,3 @@ ObserverSet.prototype.clear = function() { this.observerSet = {}; this.observers = []; }; - diff --git a/packages/ember-metal/lib/path_cache.js b/packages/ember-metal/lib/path_cache.js index 3679f7cad32..ddd723f972e 100644 --- a/packages/ember-metal/lib/path_cache.js +++ b/packages/ember-metal/lib/path_cache.js @@ -1,27 +1,16 @@ import Cache from 'ember-metal/cache'; -var IS_GLOBAL = /^[A-Z$]/; -var IS_GLOBAL_PATH = /^[A-Z$].*[\.]/; -var HAS_THIS = 'this.'; +const IS_GLOBAL = /^[A-Z$]/; +const IS_GLOBAL_PATH = /^[A-Z$].*[\.]/; +const HAS_THIS = 'this.'; -var isGlobalCache = new Cache(1000, (key) => { - return IS_GLOBAL.test(key); -}); - -var isGlobalPathCache = new Cache(1000, (key) => { - return IS_GLOBAL_PATH.test(key); -}); - -var hasThisCache = new Cache(1000, (key) => { - return key.lastIndexOf(HAS_THIS, 0) === 0; -}); - -var firstDotIndexCache = new Cache(1000, (key) => { - return key.indexOf('.'); -}); +const isGlobalCache = new Cache(1000, key => IS_GLOBAL.test(key)); +const isGlobalPathCache = new Cache(1000, key => IS_GLOBAL_PATH.test(key)); +const hasThisCache = new Cache(1000, key => key.lastIndexOf(HAS_THIS, 0) === 0); +const firstDotIndexCache = new Cache(1000, key => key.indexOf('.')); -var firstKeyCache = new Cache(1000, (path) => { - var index = firstDotIndexCache.get(path); +const firstKeyCache = new Cache(1000, (path) => { + let index = firstDotIndexCache.get(path); if (index === -1) { return path; } else { @@ -29,14 +18,14 @@ var firstKeyCache = new Cache(1000, (path) => { } }); -var tailPathCache = new Cache(1000, (path) => { - var index = firstDotIndexCache.get(path); +const tailPathCache = new Cache(1000, (path) => { + let index = firstDotIndexCache.get(path); if (index !== -1) { return path.slice(index + 1); } }); -export var caches = { +export const caches = { isGlobalCache: isGlobalCache, isGlobalPathCache: isGlobalPathCache, hasThisCache: hasThisCache, diff --git a/packages/ember-metal/lib/properties.js b/packages/ember-metal/lib/properties.js index ca578bf40f6..e7d9d4b12b0 100644 --- a/packages/ember-metal/lib/properties.js +++ b/packages/ember-metal/lib/properties.js @@ -23,7 +23,7 @@ export function Descriptor() { const REDEFINE_SUPPORTED = (function () { // https://github.com/spalger/kibana/commit/b7e35e6737df585585332857a4c397dc206e7ff9 - var a = Object.create(Object.prototype, { + let a = Object.create(Object.prototype, { prop: { configurable: true, value: 1 @@ -70,7 +70,7 @@ export function INHERITING_GETTER_FUNCTION(name) { let val = meta && meta.readInheritedValue('values', name); if (val === UNDEFINED) { - var proto = Object.getPrototypeOf(this); + let proto = Object.getPrototypeOf(this); return proto && proto[name]; } else { return val; @@ -127,12 +127,12 @@ export function INHERITING_GETTER_FUNCTION(name) { become the explicit value of this property. */ export function defineProperty(obj, keyName, desc, data, meta) { - var possibleDesc, existingDesc, watching, value; + let possibleDesc, existingDesc, watching, value; if (!meta) { meta = metaFor(obj); } - var watchEntry = meta.peekWatching(keyName); + let watchEntry = meta.peekWatching(keyName); possibleDesc = obj[keyName]; existingDesc = (possibleDesc !== null && typeof possibleDesc === 'object' && possibleDesc.isDescriptor) ? possibleDesc : undefined; diff --git a/packages/ember-metal/lib/property_events.js b/packages/ember-metal/lib/property_events.js index 5f76f07d497..ebd6fa799dc 100644 --- a/packages/ember-metal/lib/property_events.js +++ b/packages/ember-metal/lib/property_events.js @@ -16,9 +16,9 @@ import symbol from 'ember-metal/symbol'; export let PROPERTY_DID_CHANGE = symbol('PROPERTY_DID_CHANGE'); -var beforeObserverSet = new ObserverSet(); -var observerSet = new ObserverSet(); -var deferred = 0; +const beforeObserverSet = new ObserverSet(); +const observerSet = new ObserverSet(); +let deferred = 0; // .......................................................... // PROPERTY CHANGES @@ -41,15 +41,15 @@ var deferred = 0; @private */ function propertyWillChange(obj, keyName) { - var m = peekMeta(obj); + let m = peekMeta(obj); if (m && !m.isInitialized(obj)) { return; } - var watching = m && m.peekWatching(keyName) > 0; - var possibleDesc = obj[keyName]; - var desc = (possibleDesc !== null && typeof possibleDesc === 'object' && possibleDesc.isDescriptor) ? possibleDesc : undefined; + let watching = m && m.peekWatching(keyName) > 0; + let possibleDesc = obj[keyName]; + let desc = (possibleDesc !== null && typeof possibleDesc === 'object' && possibleDesc.isDescriptor) ? possibleDesc : undefined; if (desc && desc.willChange) { desc.willChange(obj, keyName); @@ -79,15 +79,15 @@ function propertyWillChange(obj, keyName) { @private */ function propertyDidChange(obj, keyName) { - var m = peekMeta(obj); + let m = peekMeta(obj); if (m && !m.isInitialized(obj)) { return; } - var watching = m && m.peekWatching(keyName) > 0; - var possibleDesc = obj[keyName]; - var desc = (possibleDesc !== null && typeof possibleDesc === 'object' && possibleDesc.isDescriptor) ? possibleDesc : undefined; + let watching = m && m.peekWatching(keyName) > 0; + let possibleDesc = obj[keyName]; + let desc = (possibleDesc !== null && typeof possibleDesc === 'object' && possibleDesc.isDescriptor) ? possibleDesc : undefined; // shouldn't this mean that we're watching this key? if (desc && desc.didChange) { @@ -111,14 +111,14 @@ function propertyDidChange(obj, keyName) { } -var WILL_SEEN, DID_SEEN; +let WILL_SEEN, DID_SEEN; // called whenever a property is about to change to clear the cache of any dependent keys (and notify those properties of changes, etc...) function dependentKeysWillChange(obj, depKey, meta) { if (obj.isDestroying) { return; } if (meta && meta.hasDeps(depKey)) { - var seen = WILL_SEEN; - var top = !seen; + let seen = WILL_SEEN; + let top = !seen; if (top) { seen = WILL_SEEN = {}; @@ -137,8 +137,8 @@ function dependentKeysDidChange(obj, depKey, meta) { if (obj.isDestroying) { return; } if (meta && meta.hasDeps(depKey)) { - var seen = DID_SEEN; - var top = !seen; + let seen = DID_SEEN; + let top = !seen; if (top) { seen = DID_SEEN = {}; @@ -153,9 +153,9 @@ function dependentKeysDidChange(obj, depKey, meta) { } function iterDeps(method, obj, depKey, seen, meta) { - var possibleDesc, desc; - var guid = guidFor(obj); - var current = seen[guid]; + let possibleDesc, desc; + let guid = guidFor(obj); + let current = seen[guid]; if (!current) { current = seen[guid] = {}; @@ -251,8 +251,8 @@ function changeProperties(callback, binding) { function notifyBeforeObservers(obj, keyName) { if (obj.isDestroying) { return; } - var eventName = keyName + ':before'; - var listeners, added; + let eventName = keyName + ':before'; + let listeners, added; if (deferred) { listeners = beforeObserverSet.add(obj, keyName, eventName); added = accumulateListeners(obj, eventName, listeners); @@ -265,8 +265,8 @@ function notifyBeforeObservers(obj, keyName) { function notifyObservers(obj, keyName) { if (obj.isDestroying) { return; } - var eventName = keyName + ':change'; - var listeners; + let eventName = keyName + ':change'; + let listeners; if (deferred) { listeners = observerSet.add(obj, keyName, eventName); accumulateListeners(obj, eventName, listeners); diff --git a/packages/ember-metal/lib/property_get.js b/packages/ember-metal/lib/property_get.js index 37cac051195..8f7884fc31a 100644 --- a/packages/ember-metal/lib/property_get.js +++ b/packages/ember-metal/lib/property_get.js @@ -54,9 +54,9 @@ export function get(obj, keyName) { return obj; } - var value = obj[keyName]; - var desc = (value !== null && typeof value === 'object' && value.isDescriptor) ? value : undefined; - var ret; + let value = obj[keyName]; + let desc = (value !== null && typeof value === 'object' && value.isDescriptor) ? value : undefined; + let ret; if (desc === undefined && isPath(keyName)) { return _getPath(obj, keyName); @@ -120,7 +120,7 @@ function isGettable(obj) { @public */ export function getWithDefault(root, key, defaultValue) { - var value = get(root, key); + let value = get(root, key); if (value === undefined) { return defaultValue; } return value; diff --git a/packages/ember-metal/lib/property_set.js b/packages/ember-metal/lib/property_set.js index 830da339624..4453633b4bc 100644 --- a/packages/ember-metal/lib/property_set.js +++ b/packages/ember-metal/lib/property_set.js @@ -100,13 +100,11 @@ if (isEnabled('mandatory-setter')) { } function setPath(root, path, value, tolerant) { - var keyName; - // get the last part of the path - keyName = path.slice(path.lastIndexOf('.') + 1); + let keyName = path.slice(path.lastIndexOf('.') + 1); // get the first part of the part - path = (path === keyName) ? keyName : path.slice(0, path.length - (keyName.length + 1)); + path = (path === keyName) ? keyName : path.slice(0, path.length - (keyName.length + 1)); // unless the path is this, look up the first part to // get the root diff --git a/packages/ember-metal/lib/replace.js b/packages/ember-metal/lib/replace.js index b3aec54e5d8..5cb3bdb330f 100644 --- a/packages/ember-metal/lib/replace.js +++ b/packages/ember-metal/lib/replace.js @@ -1,13 +1,13 @@ -var splice = Array.prototype.splice; +let { splice } = Array.prototype; export function _replace(array, idx, amt, objects) { - var args = [].concat(objects); - var ret = []; + let args = [].concat(objects); + let ret = []; // https://code.google.com/p/chromium/issues/detail?id=56588 - var size = 60000; - var start = idx; - var ends = amt; - var count, chunk; + let size = 60000; + let start = idx; + let ends = amt; + let count, chunk; while (args.length) { count = ends > size ? size : ends; @@ -28,13 +28,13 @@ export function _replace(array, idx, amt, objects) { Replaces objects in an array with the passed objects. ```javascript - var array = [1,2,3]; + let array = [1,2,3]; Ember.EnumerableUtils.replace(array, 1, 2, [4, 5]); // [1, 4, 5] - var array = [1,2,3]; + let array = [1,2,3]; Ember.EnumerableUtils.replace(array, 1, 1, [4, 5]); // [1, 4, 5, 3] - var array = [1,2,3]; + let array = [1,2,3]; Ember.EnumerableUtils.replace(array, 10, 1, [4, 5]); // [1, 2, 3, 4, 5] ``` diff --git a/packages/ember-metal/lib/run_loop.js b/packages/ember-metal/lib/run_loop.js index 1bcf79d030e..076a25804d5 100644 --- a/packages/ember-metal/lib/run_loop.js +++ b/packages/ember-metal/lib/run_loop.js @@ -30,7 +30,7 @@ const onErrorTarget = { } }; -var backburner = new Backburner(['sync', 'actions', 'destroy'], { +const backburner = new Backburner(['sync', 'actions', 'destroy'], { GUID_KEY: GUID_KEY, sync: { before: beginPropertyChanges, @@ -171,11 +171,7 @@ run.join = function() { @since 1.4.0 @public */ -run.bind = function(...curried) { - return function(...args) { - return run.join(...curried.concat(args)); - }; -}; +run.bind = (...curried) => (...args) => run.join(...curried.concat(args)); run.backburner = backburner; run.currentRunLoop = null; @@ -499,43 +495,43 @@ run.next = function(...args) { `run.throttle()`. ```javascript - var runNext = run.next(myContext, function() { + let runNext = run.next(myContext, function() { // will not be executed }); run.cancel(runNext); - var runLater = run.later(myContext, function() { + let runLater = run.later(myContext, function() { // will not be executed }, 500); run.cancel(runLater); - var runScheduleOnce = run.scheduleOnce('afterRender', myContext, function() { + let runScheduleOnce = run.scheduleOnce('afterRender', myContext, function() { // will not be executed }); run.cancel(runScheduleOnce); - var runOnce = run.once(myContext, function() { + let runOnce = run.once(myContext, function() { // will not be executed }); run.cancel(runOnce); - var throttle = run.throttle(myContext, function() { + let throttle = run.throttle(myContext, function() { // will not be executed }, 1, false); run.cancel(throttle); - var debounce = run.debounce(myContext, function() { + let debounce = run.debounce(myContext, function() { // will not be executed }, 1); run.cancel(debounce); - var debounceImmediate = run.debounce(myContext, function() { + let debounceImmediate = run.debounce(myContext, function() { // will be executed since we passed in true (immediate) }, 100, true); @@ -568,7 +564,7 @@ run.cancel = function(timer) { console.log(this.name + ' ran.'); } - var myContext = { name: 'debounce' }; + let myContext = { name: 'debounce' }; run.debounce(myContext, whoRan, 150); @@ -591,7 +587,7 @@ run.cancel = function(timer) { console.log(this.name + ' ran.'); } - var myContext = { name: 'debounce' }; + let myContext = { name: 'debounce' }; run.debounce(myContext, whoRan, 150, true); @@ -634,7 +630,7 @@ run.debounce = function() { console.log(this.name + ' ran.'); } - var myContext = { name: 'throttle' }; + let myContext = { name: 'throttle' }; run.throttle(myContext, whoRan, 150); // whoRan is invoked with context myContext diff --git a/packages/ember-metal/lib/set_properties.js b/packages/ember-metal/lib/set_properties.js index 3deb7d11b16..cde89f33ae3 100644 --- a/packages/ember-metal/lib/set_properties.js +++ b/packages/ember-metal/lib/set_properties.js @@ -7,7 +7,7 @@ import { set } from 'ember-metal/property_set'; observers will be buffered. ```javascript - var anObject = Ember.Object.create(); + let anObject = Ember.Object.create(); anObject.setProperties({ firstName: 'Stanley', @@ -25,10 +25,10 @@ import { set } from 'ember-metal/property_set'; export default function setProperties(obj, properties) { if (!properties || typeof properties !== 'object') { return properties; } changeProperties(() => { - var props = Object.keys(properties); - var propertyName; + let props = Object.keys(properties); + let propertyName; - for (var i = 0; i < props.length; i++) { + for (let i = 0; i < props.length; i++) { propertyName = props[i]; set(obj, propertyName, properties[propertyName]); diff --git a/packages/ember-metal/lib/tags.js b/packages/ember-metal/lib/tags.js index 5b00d0a973d..eb8b7cab45a 100644 --- a/packages/ember-metal/lib/tags.js +++ b/packages/ember-metal/lib/tags.js @@ -37,7 +37,7 @@ function ensureRunloop() { if (hasGlimmer) { ({ DirtyableTag, CONSTANT_TAG, CURRENT_TAG } = require('glimmer-reference')); - makeTag = function() { return new DirtyableTag(); }; + makeTag = () => new DirtyableTag(); markObjectAsDirty = function(meta) { ensureRunloop(); diff --git a/packages/ember-metal/lib/utils.js b/packages/ember-metal/lib/utils.js index 3aa80fb5055..1ca8cfdbc93 100644 --- a/packages/ember-metal/lib/utils.js +++ b/packages/ember-metal/lib/utils.js @@ -13,7 +13,7 @@ @private @return {Number} the uuid */ -var _uuid = 0; +let _uuid = 0; /** Generates a universally unique identifier. This method @@ -35,11 +35,11 @@ export function uuid() { @type String @final */ -var GUID_PREFIX = 'ember'; +const GUID_PREFIX = 'ember'; // Used for guid generation... -var numberCache = []; -var stringCache = {}; +const numberCache = []; +const stringCache = {}; /** Strongly hint runtimes to intern the provided string. @@ -81,9 +81,9 @@ var stringCache = {}; @return {String} interned version of the provided string */ export function intern(str) { - var obj = {}; + let obj = {}; obj[str] = 1; - for (var key in obj) { + for (let key in obj) { if (key === str) { return key; } @@ -105,23 +105,23 @@ export function intern(str) { @type String @final */ -var GUID_KEY = intern('__ember' + (+ new Date())); +const GUID_KEY = intern('__ember' + (+ new Date())); -export var GUID_DESC = { +export let GUID_DESC = { writable: true, configurable: true, enumerable: false, value: null }; -var nullDescriptor = { +let nullDescriptor = { configurable: true, writable: true, enumerable: false, value: null }; -export var GUID_KEY_PROPERTY = { +export let GUID_KEY_PROPERTY = { name: GUID_KEY, descriptor: nullDescriptor }; @@ -148,7 +148,7 @@ export function generateGuid(obj, prefix) { prefix = GUID_PREFIX; } - var ret = (prefix + uuid()); + let ret = (prefix + uuid()); if (obj) { if (obj[GUID_KEY] === null) { obj[GUID_KEY] = ret; @@ -192,8 +192,8 @@ export function guidFor(obj) { return '(null)'; } - var ret; - var type = typeof obj; + let ret; + let type = typeof obj; // Don't allow prototype changes to String etc. to change the guidFor switch (type) { @@ -298,9 +298,9 @@ export function wrap(func, superFunc) { function _wrap(func, superFunc) { function superWrapper() { - var orig = this._super; + let orig = this._super; this._super = superFunc; - var ret = func.apply(this, arguments); + let ret = func.apply(this, arguments); this._super = orig; return ret; } @@ -317,7 +317,7 @@ function _wrap(func, superFunc) { Checks to see if the `methodName` exists on the `obj`. ```javascript - var foo = { bar: function() { return 'bar'; }, baz: null }; + let foo = { bar: function() { return 'bar'; }, baz: null }; Ember.canInvoke(foo, 'bar'); // true Ember.canInvoke(foo, 'baz'); // false @@ -340,7 +340,7 @@ function canInvoke(obj, methodName) { and if it does, invokes it with the arguments passed. ```javascript - var d = new Date('03/15/2013'); + let d = new Date('03/15/2013'); Ember.tryInvoke(d, 'getTime'); // 1363320000000 Ember.tryInvoke(d, 'setFullYear', [2014]); // 1394856000000 @@ -365,7 +365,7 @@ export function tryInvoke(obj, methodName, args) { // TYPING & ARRAY MESSAGING // -var objectToString = Object.prototype.toString; +const objectToString = Object.prototype.toString; /** Forces the passed object to be part of an array. If the object is already @@ -379,7 +379,7 @@ var objectToString = Object.prototype.toString; Ember.makeArray('lindsay'); // ['lindsay'] Ember.makeArray([1, 2, 42]); // [1, 2, 42] - var controller = Ember.ArrayProxy.create({ content: [] }); + let controller = Ember.ArrayProxy.create({ content: [] }); Ember.makeArray(controller) === controller; // true ``` @@ -420,7 +420,7 @@ export function inspect(obj) { return '[' + obj + ']'; } // for non objects - var type = typeof obj; + let type = typeof obj; if (type !== 'object' && type !== 'symbol') { return '' + obj; } @@ -430,9 +430,9 @@ export function inspect(obj) { } // Object.prototype.toString === {}.toString - var v; - var ret = []; - for (var key in obj) { + let v; + let ret = []; + for (let key in obj) { if (obj.hasOwnProperty(key)) { v = obj[key]; if (v === 'toString') { continue; } // ignore useless items @@ -455,7 +455,7 @@ export function inspect(obj) { @private */ export function applyStr(t, m, a) { - var l = a && a.length; + let l = a && a.length; if (!a || !l) { return t[m](); } switch (l) { case 1: return t[m](a[0]); @@ -497,5 +497,3 @@ export { makeArray, canInvoke }; - - diff --git a/packages/ember-metal/lib/watch_key.js b/packages/ember-metal/lib/watch_key.js index 13f5e3f5612..a49df591c49 100644 --- a/packages/ember-metal/lib/watch_key.js +++ b/packages/ember-metal/lib/watch_key.js @@ -12,14 +12,14 @@ import { lookupDescriptor } from 'ember-metal/utils'; let handleMandatorySetter; export function watchKey(obj, keyName, meta) { - var m = meta || metaFor(obj); + let m = meta || metaFor(obj); // activate watching first time if (!m.peekWatching(keyName)) { m.writeWatching(keyName, 1); - var possibleDesc = obj[keyName]; - var desc = (possibleDesc !== null && + let possibleDesc = obj[keyName]; + let desc = (possibleDesc !== null && typeof possibleDesc === 'object' && possibleDesc.isDescriptor) ? possibleDesc : undefined; if (desc && desc.willWatch) { desc.willWatch(obj, keyName); } @@ -52,11 +52,11 @@ if (isEnabled('mandatory-setter')) { // ember strip this entire block out handleMandatorySetter = function handleMandatorySetter(m, obj, keyName) { let descriptor = lookupDescriptor(obj, keyName); - var configurable = descriptor ? descriptor.configurable : true; - var isWritable = descriptor ? descriptor.writable : true; - var hasValue = descriptor ? 'value' in descriptor : true; - var possibleDesc = descriptor && descriptor.value; - var isDescriptor = possibleDesc !== null && + let configurable = descriptor ? descriptor.configurable : true; + let isWritable = descriptor ? descriptor.writable : true; + let hasValue = descriptor ? 'value' in descriptor : true; + let possibleDesc = descriptor && descriptor.value; + let isDescriptor = possibleDesc !== null && typeof possibleDesc === 'object' && possibleDesc.isDescriptor; @@ -86,13 +86,13 @@ if (isEnabled('mandatory-setter')) { import { UNDEFINED } from './meta'; export function unwatchKey(obj, keyName, meta) { - var m = meta || metaFor(obj); + let m = meta || metaFor(obj); let count = m.peekWatching(keyName); if (count === 1) { m.writeWatching(keyName, 0); - var possibleDesc = obj[keyName]; - var desc = (possibleDesc !== null && + let possibleDesc = obj[keyName]; + let desc = (possibleDesc !== null && typeof possibleDesc === 'object' && possibleDesc.isDescriptor) ? possibleDesc : undefined; diff --git a/packages/ember-metal/lib/watch_path.js b/packages/ember-metal/lib/watch_path.js index 57903b4aac8..6e7c64dfedb 100644 --- a/packages/ember-metal/lib/watch_path.js +++ b/packages/ember-metal/lib/watch_path.js @@ -15,7 +15,7 @@ export function makeChainNode(obj) { } export function watchPath(obj, keyPath, meta) { - var m = meta || metaFor(obj); + let m = meta || metaFor(obj); let counter = m.peekWatching(keyPath) || 0; if (!counter) { // activate watching first time m.writeWatching(keyPath, 1); @@ -26,7 +26,7 @@ export function watchPath(obj, keyPath, meta) { } export function unwatchPath(obj, keyPath, meta) { - var m = meta || metaFor(obj); + let m = meta || metaFor(obj); let counter = m.peekWatching(keyPath) || 0; if (counter === 1) { diff --git a/packages/ember-metal/lib/watching.js b/packages/ember-metal/lib/watching.js index 5bb60f86a2e..b43d13ec853 100644 --- a/packages/ember-metal/lib/watching.js +++ b/packages/ember-metal/lib/watching.js @@ -45,12 +45,12 @@ function watch(obj, _keyPath, m) { export { watch }; export function isWatching(obj, key) { - var meta = peekMeta(obj); + let meta = peekMeta(obj); return (meta && meta.peekWatching(key)) > 0; } export function watcherCount(obj, key) { - var meta = peekMeta(obj); + let meta = peekMeta(obj); return (meta && meta.peekWatching(key)) || 0; } @@ -62,7 +62,7 @@ export function unwatch(obj, _keyPath, m) { } } -var NODE_STACK = []; +const NODE_STACK = []; /** Tears down the meta on an object so that it can be garbage collected. @@ -75,8 +75,8 @@ var NODE_STACK = []; @private */ export function destroy(obj) { - var meta = peekMeta(obj); - var node, nodes, key, nodeObject; + let meta = peekMeta(obj); + let node, nodes, key, nodeObject; if (meta) { deleteMeta(obj); diff --git a/packages/ember-metal/tests/accessors/get_path_test.js b/packages/ember-metal/tests/accessors/get_path_test.js index 19df6d3f2be..5c349014433 100644 --- a/packages/ember-metal/tests/accessors/get_path_test.js +++ b/packages/ember-metal/tests/accessors/get_path_test.js @@ -1,7 +1,7 @@ import { get } from 'ember-metal/property_get'; -var obj; -var moduleOpts = { +let obj; +const moduleOpts = { setup() { obj = { foo: { diff --git a/packages/ember-metal/tests/accessors/get_properties_test.js b/packages/ember-metal/tests/accessors/get_properties_test.js index 86149c7b480..e354d79acd4 100644 --- a/packages/ember-metal/tests/accessors/get_properties_test.js +++ b/packages/ember-metal/tests/accessors/get_properties_test.js @@ -3,7 +3,7 @@ import getProperties from 'ember-metal/get_properties'; QUnit.module('Ember.getProperties'); QUnit.test('can retrieve a hash of properties from an object via an argument list or array of property names', function() { - var obj = { + let obj = { firstName: 'Steve', lastName: 'Jobs', companyName: 'Apple, Inc.' diff --git a/packages/ember-metal/tests/accessors/get_test.js b/packages/ember-metal/tests/accessors/get_test.js index f628f9b9a4c..773137859d5 100644 --- a/packages/ember-metal/tests/accessors/get_test.js +++ b/packages/ember-metal/tests/accessors/get_test.js @@ -12,7 +12,7 @@ import { addObserver } from 'ember-metal/observer'; QUnit.module('Ember.get'); QUnit.test('should get arbitrary properties on an object', function() { - var obj = { + let obj = { string: 'string', number: 23, boolTrue: true, @@ -20,7 +20,7 @@ QUnit.test('should get arbitrary properties on an object', function() { nullValue: null }; - for (var key in obj) { + for (let key in obj) { if (!obj.hasOwnProperty(key)) { continue; } @@ -29,8 +29,8 @@ QUnit.test('should get arbitrary properties on an object', function() { }); QUnit.test('should not access a property more than once', function() { - var count = 0; - var obj = { + let count = 0; + let obj = { get id() { return ++count; } }; @@ -40,7 +40,7 @@ QUnit.test('should not access a property more than once', function() { }); testBoth('should call unknownProperty on watched values if the value is undefined', function(get, set) { - var obj = { + let obj = { count: 0, unknownProperty(key) { equal(key, 'foo', 'should pass key'); @@ -49,7 +49,7 @@ testBoth('should call unknownProperty on watched values if the value is undefine } }; - var count = 0; + let count = 0; addObserver(obj, 'foo', function() { count++; }); @@ -100,22 +100,12 @@ QUnit.test('warn on attempts to get a property path of null', function() { }); QUnit.test('warn on attempts to use get with an unsupported property path', function() { - var obj = {}; - expectAssertion(function() { - get(obj, null); - }, /The key provided to get must be a string, you passed null/); - expectAssertion(function() { - get(obj, NaN); - }, /The key provided to get must be a string, you passed NaN/); - expectAssertion(function() { - get(obj, undefined); - }, /The key provided to get must be a string, you passed undefined/); - expectAssertion(function() { - get(obj, false); - }, /The key provided to get must be a string, you passed false/); - expectAssertion(function() { - get(obj, 42); - }, /The key provided to get must be a string, you passed 42/); + let obj = {}; + expectAssertion(() => get(obj, null), /The key provided to get must be a string, you passed null/); + expectAssertion(() => get(obj, NaN), /The key provided to get must be a string, you passed NaN/); + expectAssertion(() => get(obj, undefined), /The key provided to get must be a string, you passed undefined/); + expectAssertion(() => get(obj, false), /The key provided to get must be a string, you passed false/); + expectAssertion(() => get(obj, 42), /The key provided to get must be a string, you passed 42/); }); // .......................................................... @@ -123,15 +113,13 @@ QUnit.test('warn on attempts to use get with an unsupported property path', func // QUnit.test('(regression) watched properties on unmodified inherited objects should still return their original value', function() { - var MyMixin = Mixin.create({ + let MyMixin = Mixin.create({ someProperty: 'foo', - propertyDidChange: observer('someProperty', function() { - // NOTHING TO DO - }) + propertyDidChange: observer('someProperty', () => {}) }); - var baseObject = MyMixin.apply({}); - var theRealObject = Object.create(baseObject); + let baseObject = MyMixin.apply({}); + let theRealObject = Object.create(baseObject); equal(get(theRealObject, 'someProperty'), 'foo', 'should return the set value, not false'); }); @@ -139,7 +127,7 @@ QUnit.test('(regression) watched properties on unmodified inherited objects shou QUnit.module('Ember.getWithDefault'); QUnit.test('should get arbitrary properties on an object', function() { - var obj = { + let obj = { string: 'string', number: 23, boolTrue: true, @@ -147,7 +135,7 @@ QUnit.test('should get arbitrary properties on an object', function() { nullValue: null }; - for (var key in obj) { + for (let key in obj) { if (!obj.hasOwnProperty(key)) { continue; } @@ -163,7 +151,7 @@ QUnit.test('should get arbitrary properties on an object', function() { }); QUnit.test('should call unknownProperty if defined and value is undefined', function() { - var obj = { + let obj = { count: 0, unknownProperty(key) { equal(key, 'foo', 'should pass key'); @@ -177,7 +165,7 @@ QUnit.test('should call unknownProperty if defined and value is undefined', func }); testBoth('if unknownProperty is present, it is called', function(get, set) { - var obj = { + let obj = { count: 0, unknownProperty(key) { if (key === 'foo') { @@ -188,10 +176,8 @@ testBoth('if unknownProperty is present, it is called', function(get, set) { } }; - var count = 0; - addObserver(obj, 'foo', function() { - count++; - }); + let count = 0; + addObserver(obj, 'foo', () => count++); equal(getWithDefault(obj, 'foo', 'fail'), 'FOO', 'should return value from unknownProperty'); equal(getWithDefault(obj, 'bar', 'default'), 'default', 'should convert undefined from unknownProperty into default'); @@ -202,15 +188,13 @@ testBoth('if unknownProperty is present, it is called', function(get, set) { // QUnit.test('(regression) watched properties on unmodified inherited objects should still return their original value', function() { - var MyMixin = Mixin.create({ + let MyMixin = Mixin.create({ someProperty: 'foo', - propertyDidChange: observer('someProperty', function() { - // NOTHING TO DO - }) + propertyDidChange: observer('someProperty', () => { /* nothing to do */}) }); - var baseObject = MyMixin.apply({}); - var theRealObject = Object.create(baseObject); + let baseObject = MyMixin.apply({}); + let theRealObject = Object.create(baseObject); equal(getWithDefault(theRealObject, 'someProperty', 'fail'), 'foo', 'should return the set value, not false'); }); diff --git a/packages/ember-metal/tests/accessors/mandatory_setters_test.js b/packages/ember-metal/tests/accessors/mandatory_setters_test.js index cf7144e7dfd..fc14da9bb0f 100644 --- a/packages/ember-metal/tests/accessors/mandatory_setters_test.js +++ b/packages/ember-metal/tests/accessors/mandatory_setters_test.js @@ -20,7 +20,7 @@ function hasMetaValue(object, property) { if (isEnabled('mandatory-setter')) { QUnit.test('does not assert if property is not being watched', function() { - var obj = { + let obj = { someProp: null, toString() { return 'custom-object'; @@ -34,7 +34,7 @@ if (isEnabled('mandatory-setter')) { QUnit.test('should not setup mandatory-setter if property is not writable', function() { expect(6); - var obj = { }; + let obj = { }; Object.defineProperty(obj, 'a', { value: true }); Object.defineProperty(obj, 'b', { value: false }); @@ -61,7 +61,7 @@ if (isEnabled('mandatory-setter')) { QUnit.test('should not teardown non mandatory-setter descriptor', function() { expect(1); - var obj = { get a() { return 'hi'; } }; + let obj = { get a() { return 'hi'; } }; watch(obj, 'a'); unwatch(obj, 'a'); @@ -72,7 +72,7 @@ if (isEnabled('mandatory-setter')) { QUnit.test('should not confuse non descriptor watched gets', function() { expect(2); - var obj = { get a() { return 'hi'; } }; + let obj = { get a() { return 'hi'; } }; watch(obj, 'a'); equal(get(obj, 'a'), 'hi'); @@ -82,7 +82,7 @@ if (isEnabled('mandatory-setter')) { QUnit.test('should not setup mandatory-setter if setter is already setup on property', function() { expect(2); - var obj = { someProp: null }; + let obj = { someProp: null }; Object.defineProperty(obj, 'someProp', { get() { @@ -130,7 +130,7 @@ if (isEnabled('mandatory-setter')) { } }); - var obj = new Foo(); + let obj = new Foo(); watch(obj, 'someProp'); ok(!hasMandatorySetter(obj, 'someProp'), 'mandatory-setter should not be installed'); @@ -157,7 +157,7 @@ if (isEnabled('mandatory-setter')) { Bar.prototype = Object.create(Foo.prototype); Bar.prototype.constructor = Bar; - var obj = new Bar(); + let obj = new Bar(); watch(obj, 'someProp'); ok(!hasMandatorySetter(obj, 'someProp'), 'mandatory-setter should not be installed'); @@ -188,7 +188,7 @@ if (isEnabled('mandatory-setter')) { Qux.prototype = Object.create(Bar.prototype); Qux.prototype.constructor = Qux; - var obj = new Qux(); + let obj = new Qux(); watch(obj, 'someProp'); ok(!hasMandatorySetter(obj, 'someProp'), 'mandatory-setter should not be installed'); @@ -197,7 +197,7 @@ if (isEnabled('mandatory-setter')) { }); QUnit.test('should assert if set without Ember.set when property is being watched', function() { - var obj = { + let obj = { someProp: null, toString() { return 'custom-object'; @@ -212,7 +212,7 @@ if (isEnabled('mandatory-setter')) { }); QUnit.test('should not assert if set with Ember.set when property is being watched', function() { - var obj = { + let obj = { someProp: null, toString() { return 'custom-object'; @@ -226,7 +226,7 @@ if (isEnabled('mandatory-setter')) { }); QUnit.test('does not setup mandatory-setter if non-configurable', function() { - var obj = { + let obj = { someProp: null, toString() { return 'custom-object'; @@ -244,7 +244,7 @@ if (isEnabled('mandatory-setter')) { }); QUnit.test('ensure after watch the property is restored (and the value is no-longer stored in meta) [non-enumerable]', function() { - var obj = { + let obj = { someProp: null, toString() { return 'custom-object'; @@ -296,7 +296,7 @@ if (isEnabled('mandatory-setter')) { }); QUnit.test('ensure after watch the property is restored (and the value is no-longer stored in meta) [enumerable]', function() { - var obj = { + let obj = { someProp: null, toString() { return 'custom-object'; @@ -349,14 +349,14 @@ if (isEnabled('mandatory-setter')) { QUnit.test('sets up mandatory-setter if property comes from prototype', function() { expect(2); - var obj = { + let obj = { someProp: null, toString() { return 'custom-object'; } }; - var obj2 = Object.create(obj); + let obj2 = Object.create(obj); watch(obj2, 'someProp'); @@ -371,7 +371,7 @@ if (isEnabled('mandatory-setter')) { function Parent() {} Parent.prototype.food = 'chips'; - var child = new Parent(); + let child = new Parent(); equal(child.food , 'chips'); diff --git a/packages/ember-metal/tests/accessors/set_path_test.js b/packages/ember-metal/tests/accessors/set_path_test.js index fa32cc09de8..cfaa5fd17a0 100644 --- a/packages/ember-metal/tests/accessors/set_path_test.js +++ b/packages/ember-metal/tests/accessors/set_path_test.js @@ -5,7 +5,7 @@ import { get } from 'ember-metal/property_get'; let originalLookup = context.lookup; let lookup; -var obj; +let obj; function commonSetup() { context.lookup = lookup = {}; obj = { @@ -58,7 +58,7 @@ QUnit.module('set with path - deprecated', { }); QUnit.test('[obj, bla.bla] gives a proper exception message', function() { - var exceptionMessage = 'Property set failed: object in path \"bla\" could not be found or was destroyed.'; + let exceptionMessage = 'Property set failed: object in path \"bla\" could not be found or was destroyed.'; try { set(obj, 'bla.bla', 'BAM'); } catch(ex) { @@ -67,9 +67,7 @@ QUnit.test('[obj, bla.bla] gives a proper exception message', function() { }); QUnit.test('[obj, foo.baz.bat] -> EXCEPTION', function() { - throws(function() { - set(obj, 'foo.baz.bat', 'BAM'); - }, Error); + throws(() => set(obj, 'foo.baz.bat', 'BAM')); }); QUnit.test('[obj, foo.baz.bat] -> EXCEPTION', function() { diff --git a/packages/ember-metal/tests/accessors/set_test.js b/packages/ember-metal/tests/accessors/set_test.js index a87e993e1de..491ed79c862 100644 --- a/packages/ember-metal/tests/accessors/set_test.js +++ b/packages/ember-metal/tests/accessors/set_test.js @@ -4,7 +4,7 @@ import { set } from 'ember-metal/property_set'; QUnit.module('set'); QUnit.test('should set arbitrary properties on an object', function() { - var obj = { + let obj = { string: 'string', number: 23, boolTrue: true, @@ -13,11 +13,11 @@ QUnit.test('should set arbitrary properties on an object', function() { undefinedValue: undefined }; - var newObj = { + let newObj = { undefinedValue: 'emberjs' }; - for (var key in obj) { + for (let key in obj) { if (!obj.hasOwnProperty(key)) { continue; } @@ -28,7 +28,7 @@ QUnit.test('should set arbitrary properties on an object', function() { }); QUnit.test('should call setUnknownProperty if defined and value is undefined', function() { - var obj = { + let obj = { count: 0, unknownProperty(key, value) { @@ -48,40 +48,24 @@ QUnit.test('should call setUnknownProperty if defined and value is undefined', f }); QUnit.test('warn on attempts to call set with undefined as object', function() { - expectAssertion(function() { - set(undefined, 'aProperty', 'BAM'); - }, /Cannot call set with 'aProperty' on an undefined object./); + expectAssertion(() => set(undefined, 'aProperty', 'BAM'), /Cannot call set with 'aProperty' on an undefined object./); }); QUnit.test('warn on attempts to call set with null as object', function() { - expectAssertion(function() { - set(null, 'aProperty', 'BAM'); - }, /Cannot call set with 'aProperty' on an undefined object./); + expectAssertion(() => set(null, 'aProperty', 'BAM'), /Cannot call set with 'aProperty' on an undefined object./); }); QUnit.test('warn on attempts to use set with an unsupported property path', function() { - var obj = {}; - expectAssertion(function() { - set(obj, null, 42); - }, /The key provided to set must be a string, you passed null/); - expectAssertion(function() { - set(obj, NaN, 42); - }, /The key provided to set must be a string, you passed NaN/); - expectAssertion(function() { - set(obj, undefined, 42); - }, /The key provided to set must be a string, you passed undefined/); - expectAssertion(function() { - set(obj, false, 42); - }, /The key provided to set must be a string, you passed false/); - expectAssertion(function() { - set(obj, 42, 42); - }, /The key provided to set must be a string, you passed 42/); + let obj = {}; + expectAssertion(() => set(obj, null, 42), /The key provided to set must be a string, you passed null/); + expectAssertion(() => set(obj, NaN, 42), /The key provided to set must be a string, you passed NaN/); + expectAssertion(() => set(obj, undefined, 42), /The key provided to set must be a string, you passed undefined/); + expectAssertion(() => set(obj, false, 42), /The key provided to set must be a string, you passed false/); + expectAssertion(() => set(obj, 42, 42), /The key provided to set must be a string, you passed 42/); }); QUnit.test('warn on attempts of calling set on a destroyed object', function() { let obj = { isDestroyed: true }; - expectAssertion(function() { - set(obj, 'favoriteFood', 'hot dogs'); - }, 'calling set on destroyed object: [object Object].favoriteFood = hot dogs'); + expectAssertion(() => set(obj, 'favoriteFood', 'hot dogs'), 'calling set on destroyed object: [object Object].favoriteFood = hot dogs'); }); diff --git a/packages/ember-metal/tests/alias_test.js b/packages/ember-metal/tests/alias_test.js index 062eaf609be..6e900648363 100644 --- a/packages/ember-metal/tests/alias_test.js +++ b/packages/ember-metal/tests/alias_test.js @@ -6,7 +6,7 @@ import { meta } from 'ember-metal/meta'; import { isWatching } from 'ember-metal/watching'; import { addObserver, removeObserver } from 'ember-metal/observer'; -var obj, count; +let obj, count; QUnit.module('ember-metal/alias', { setup() { @@ -35,7 +35,7 @@ QUnit.test('should proxy set to alt key', function() { QUnit.test('basic lifecycle', function() { defineProperty(obj, 'bar', alias('foo.faz')); - var m = meta(obj); + let m = meta(obj); addObserver(obj, 'bar', incrementCount); equal(m.peekDeps('foo.faz', 'bar'), 1); removeObserver(obj, 'bar', incrementCount); @@ -43,7 +43,7 @@ QUnit.test('basic lifecycle', function() { }); QUnit.test('old dependent keys should not trigger property changes', function() { - var obj1 = Object.create(null); + let obj1 = Object.create(null); defineProperty(obj1, 'foo', null, null); defineProperty(obj1, 'bar', alias('foo')); defineProperty(obj1, 'baz', alias('foo')); @@ -60,13 +60,13 @@ QUnit.test('old dependent keys should not trigger property changes', function() }); QUnit.test('overridden dependent keys should not trigger property changes', function() { - var obj1 = Object.create(null); + let obj1 = Object.create(null); defineProperty(obj1, 'foo', null, null); defineProperty(obj1, 'bar', alias('foo')); defineProperty(obj1, 'baz', alias('foo')); addObserver(obj1, 'baz', incrementCount); - var obj2 = Object.create(obj1); + let obj2 = Object.create(obj1); defineProperty(obj2, 'baz', alias('bar')); // override baz set(obj2, 'foo', 'FOO'); @@ -95,7 +95,5 @@ QUnit.test('immediately sets up dependencies if already being watched', function }); QUnit.test('setting alias on self should fail assertion', function() { - expectAssertion(function() { - defineProperty(obj, 'bar', alias('bar')); - }, 'Setting alias \'bar\' on self'); + expectAssertion(() => defineProperty(obj, 'bar', alias('bar')), 'Setting alias \'bar\' on self'); }); diff --git a/packages/ember-metal/tests/assign_test.js b/packages/ember-metal/tests/assign_test.js index dece1a6f1c0..5a632e768cd 100644 --- a/packages/ember-metal/tests/assign_test.js +++ b/packages/ember-metal/tests/assign_test.js @@ -3,10 +3,10 @@ import assign from 'ember-metal/assign'; QUnit.module('Ember.assign'); QUnit.test('Ember.assign', function() { - var a = { a: 1 }; - var b = { b: 2 }; - var c = { c: 3 }; - var a2 = { a: 4 }; + let a = { a: 1 }; + let b = { b: 2 }; + let c = { c: 3 }; + let a2 = { a: 4 }; assign(a, b, c, a2); diff --git a/packages/ember-metal/tests/binding/connect_test.js b/packages/ember-metal/tests/binding/connect_test.js index b56288ac679..dfdff96a265 100644 --- a/packages/ember-metal/tests/binding/connect_test.js +++ b/packages/ember-metal/tests/binding/connect_test.js @@ -10,7 +10,7 @@ import { get } from 'ember-metal/property_get'; function performTest(binding, a, b, get, set, connect) { if (connect === undefined) { - connect = function() {binding.connect(a);}; + connect = () => binding.connect(a); } ok(!run.currentRunLoop, 'performTest should not have a currentRunLoop'); @@ -24,18 +24,14 @@ function performTest(binding, a, b, get, set, connect) { equal(get(b, 'bar'), 'BAR', 'b should have changed'); // // make sure changes sync both ways - run(function () { - set(b, 'bar', 'BAZZ'); - }); + run(() => set(b, 'bar', 'BAZZ')); equal(get(a, 'foo'), 'BAZZ', 'a should have changed'); - run(function () { - set(a, 'foo', 'BARF'); - }); + run(() => set(a, 'foo', 'BARF')); equal(get(b, 'bar'), 'BARF', 'a should have changed'); } -var originalLookup, lookup, GlobalB; +let originalLookup, lookup, GlobalB; QUnit.module('Ember.Binding', { setup() { @@ -49,10 +45,10 @@ QUnit.module('Ember.Binding', { }); testBoth('Connecting a binding between two properties', function(get, set) { - var a = { foo: 'FOO', bar: 'BAR' }; + let a = { foo: 'FOO', bar: 'BAR' }; // a.bar -> a.foo - var binding = new Binding('foo', 'bar'); + let binding = new Binding('foo', 'bar'); let deprecationMessage = '`Ember.Binding` is deprecated. Consider using an' + ' `alias` computed property instead.'; @@ -62,12 +58,11 @@ testBoth('Connecting a binding between two properties', function(get, set) { }, deprecationMessage); }); -testBoth('Connecting a oneWay binding raises a deprecation', - function(get, set) { - var a = { foo: 'FOO', bar: 'BAR' }; +testBoth('Connecting a oneWay binding raises a deprecation', function(get, set) { + let a = { foo: 'FOO', bar: 'BAR' }; // a.bar -> a.foo - var binding = new Binding('foo', 'bar').oneWay(); + let binding = new Binding('foo', 'bar').oneWay(); let deprecationMessage = '`Ember.Binding` is deprecated. Since you' + ' are using a `oneWay` binding consider using a `readOnly` computed' + @@ -77,11 +72,11 @@ testBoth('Connecting a oneWay binding raises a deprecation', }); testBoth('Connecting a binding between two objects', function(get, set) { - var b = { bar: 'BAR' }; - var a = { foo: 'FOO', b: b }; + let b = { bar: 'BAR' }; + let a = { foo: 'FOO', b: b }; // b.bar -> a.foo - var binding = new Binding('foo', 'b.bar'); + let binding = new Binding('foo', 'b.bar'); let deprecationMessage = '`Ember.Binding` is deprecated. Consider using an' + ' `alias` computed property instead.'; @@ -92,15 +87,15 @@ testBoth('Connecting a binding between two objects', function(get, set) { }); testBoth('Connecting a binding to path', function(get, set) { - var a = { foo: 'FOO' }; + let a = { foo: 'FOO' }; lookup['GlobalB'] = GlobalB = { b: { bar: 'BAR' } }; - var b = get(GlobalB, 'b'); + let b = get(GlobalB, 'b'); // globalB.b.bar -> a.foo - var binding = new Binding('foo', 'GlobalB.b.bar'); + let binding = new Binding('foo', 'GlobalB.b.bar'); let deprecationMessage = '`Ember.Binding` is deprecated. Since you' + ' are binding to a global consider using a service instead.'; @@ -112,25 +107,23 @@ testBoth('Connecting a binding to path', function(get, set) { // make sure modifications update b = { bar: 'BIFF' }; - run(function() { - set(GlobalB, 'b', b); - }); + run(() => set(GlobalB, 'b', b)); equal(get(a, 'foo'), 'BIFF', 'a should have changed'); }); testBoth('Calling connect more than once', function(get, set) { - var b = { bar: 'BAR' }; - var a = { foo: 'FOO', b: b }; + let b = { bar: 'BAR' }; + let a = { foo: 'FOO', b: b }; // b.bar -> a.foo - var binding = new Binding('foo', 'b.bar'); + let binding = new Binding('foo', 'b.bar'); let deprecationMessage = '`Ember.Binding` is deprecated. Consider using an' + ' `alias` computed property instead.'; expectDeprecation(() => { - performTest(binding, a, b, get, set, function () { + performTest(binding, a, b, get, set, () => { binding.connect(a); binding.connect(a); }); @@ -138,16 +131,16 @@ testBoth('Calling connect more than once', function(get, set) { }); QUnit.test('inherited bindings should sync on create', function() { - var a; - run(function () { - var A = function() { + let a; + run(() => { + function A() { bind(this, 'foo', 'bar.baz'); - }; + } let deprecationMessage = '`Ember.Binding` is deprecated. Consider using an' + ' `alias` computed property instead.'; - expectDeprecation(() => { a = new A(); }, deprecationMessage); + expectDeprecation(() => a = new A(), deprecationMessage); set(a, 'bar', { baz: 'BAZ' }); }); diff --git a/packages/ember-metal/tests/binding/sync_test.js b/packages/ember-metal/tests/binding/sync_test.js index adb04149fad..860e3d33d0d 100644 --- a/packages/ember-metal/tests/binding/sync_test.js +++ b/packages/ember-metal/tests/binding/sync_test.js @@ -11,19 +11,19 @@ import { propertyWillChange, propertyDidChange } from 'ember-metal/property_even QUnit.module('system/binding/sync_test.js'); testBoth('bindings should not sync twice in a single run loop', function(get, set) { - var a, b, setValue; - var setCalled = 0; - var getCalled = 0; + let a, b, setValue; + let setCalled = 0; + let getCalled = 0; - run(function() { + run(() => { a = {}; defineProperty(a, 'foo', computed({ - get: function(key) { + get(key) { getCalled++; return setValue; }, - set: function(key, value) { + set(key, value) { setCalled++; propertyWillChange(this, key); setValue = value; @@ -39,15 +39,13 @@ testBoth('bindings should not sync twice in a single run loop', function(get, se let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + ' using an `alias` computed property instead.'; - expectDeprecation(() => { - bind(b, 'foo', 'a.foo'); - }, deprecationMessage); + expectDeprecation(() => bind(b, 'foo', 'a.foo'), deprecationMessage); }); // reset after initial binding synchronization getCalled = 0; - run(function() { + run(() => { set(a, 'foo', 'trollface'); }); @@ -57,10 +55,10 @@ testBoth('bindings should not sync twice in a single run loop', function(get, se }); testBoth('bindings should not infinite loop if computed properties return objects', function(get, set) { - var a, b; - var getCalled = 0; + let a, b; + let getCalled = 0; - run(function() { + run(() => { a = {}; defineProperty(a, 'foo', computed(function() { @@ -78,9 +76,7 @@ testBoth('bindings should not infinite loop if computed properties return object let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + ' using an `alias` computed property instead.'; - expectDeprecation(() => { - bind(b, 'foo', 'a.foo'); - }, deprecationMessage); + expectDeprecation(() => bind(b, 'foo', 'a.foo'), deprecationMessage); }); deepEqual(get(b, 'foo'), ['foo', 'bar'], 'the binding should sync'); @@ -88,9 +84,9 @@ testBoth('bindings should not infinite loop if computed properties return object }); testBoth('bindings should do the right thing when observers trigger bindings in the opposite direction', function(get, set) { - var a, b, c; + let a, b, c; - run(function() { + run(() => { a = { foo: 'trololol' }; @@ -102,9 +98,7 @@ testBoth('bindings should do the right thing when observers trigger bindings in let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + ' using an `alias` computed property instead.'; - expectDeprecation(() => { - bind(b, 'foo', 'a.foo'); - }, deprecationMessage); + expectDeprecation(() => bind(b, 'foo', 'a.foo'), deprecationMessage); c = { a: a @@ -115,21 +109,17 @@ testBoth('bindings should do the right thing when observers trigger bindings in }, deprecationMessage); }); - addObserver(b, 'foo', function() { - set(c, 'foo', 'what is going on'); - }); + addObserver(b, 'foo', () => set(c, 'foo', 'what is going on')); - run(function() { - set(a, 'foo', 'trollface'); - }); + run(() => set(a, 'foo', 'trollface')); equal(get(a, 'foo'), 'what is going on'); }); testBoth('bindings should not try to sync destroyed objects', function(get, set) { - var a, b; + let a, b; - run(function() { + run(() => { a = { foo: 'trololol' }; @@ -141,18 +131,16 @@ testBoth('bindings should not try to sync destroyed objects', function(get, set) let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + ' using an `alias` computed property instead.'; - expectDeprecation(() => { - bind(b, 'foo', 'a.foo'); - }, deprecationMessage); + expectDeprecation(() => bind(b, 'foo', 'a.foo'), deprecationMessage); }); - run(function() { + run(() => { set(a, 'foo', 'trollface'); set(b, 'isDestroyed', true); ok(true, 'should not raise'); }); - run(function() { + run(() => { a = { foo: 'trololol' }; @@ -164,12 +152,10 @@ testBoth('bindings should not try to sync destroyed objects', function(get, set) let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + ' using an `alias` computed property instead.'; - expectDeprecation(() => { - bind(b, 'foo', 'a.foo'); - }, deprecationMessage); + expectDeprecation(() => bind(b, 'foo', 'a.foo'), deprecationMessage); }); - run(function() { + run(() => { set(b, 'foo', 'trollface'); set(a, 'isDestroyed', true); ok(true, 'should not raise'); diff --git a/packages/ember-metal/tests/cache_test.js b/packages/ember-metal/tests/cache_test.js index 53ec4af9e02..17c502dd1a2 100644 --- a/packages/ember-metal/tests/cache_test.js +++ b/packages/ember-metal/tests/cache_test.js @@ -3,9 +3,7 @@ import Cache from 'ember-metal/cache'; QUnit.module('Cache'); QUnit.test('basic', function() { - var cache = new Cache(100, function(key) { - return key.toUpperCase(); - }); + let cache = new Cache(100, key => key.toUpperCase()); equal(cache.get('foo'), 'FOO'); equal(cache.get('bar'), 'BAR'); @@ -13,8 +11,8 @@ QUnit.test('basic', function() { }); QUnit.test('caches computation correctly', function() { - var count = 0; - var cache = new Cache(100, function(key) { + let count = 0; + let cache = new Cache(100, key => { count++; return key.toUpperCase(); }); @@ -31,15 +29,13 @@ QUnit.test('caches computation correctly', function() { }); QUnit.test('handles undefined value correctly', function() { - var cache = new Cache(100, function(key) {}); + let cache = new Cache(100, (key) => { }); equal(cache.get('foo'), undefined); }); QUnit.test('continues working after reaching cache limit', function() { - var cache = new Cache(3, function(key) { - return key.toUpperCase(); - }); + let cache = new Cache(3, key => key.toUpperCase()); cache.get('a'); cache.get('b'); diff --git a/packages/ember-metal/tests/chains_test.js b/packages/ember-metal/tests/chains_test.js index 7e637e13424..5258bbc5c90 100644 --- a/packages/ember-metal/tests/chains_test.js +++ b/packages/ember-metal/tests/chains_test.js @@ -11,17 +11,17 @@ QUnit.module('Chains'); QUnit.test('finishChains should properly copy chains from prototypes to instances', function() { function didChange() {} - var obj = {}; + let obj = {}; addObserver(obj, 'foo.bar', null, didChange); - var childObj = Object.create(obj); + let childObj = Object.create(obj); finishChains(childObj); ok(peekMeta(obj) !== peekMeta(childObj).readableChains(), 'The chains object is copied'); }); QUnit.test('observer and CP chains', function() { - var obj = { }; + let obj = { }; defineProperty(obj, 'foo', computed('qux.[]', function() { })); defineProperty(obj, 'qux', computed(function() { })); @@ -45,7 +45,6 @@ QUnit.test('observer and CP chains', function() { observer CP(foo, 'qux.[]') */ - // invalidate qux propertyDidChange(obj, 'qux'); diff --git a/packages/ember-metal/tests/computed_test.js b/packages/ember-metal/tests/computed_test.js index 0fb4c92456c..d989132226c 100644 --- a/packages/ember-metal/tests/computed_test.js +++ b/packages/ember-metal/tests/computed_test.js @@ -18,7 +18,7 @@ import { _addBeforeObserver } from 'ember-metal/observer'; -var obj, count; +let obj, count; QUnit.module('computed'); @@ -50,8 +50,8 @@ QUnit.test('computed properties defined with an object only allow `get` and `set QUnit.test('defining computed property should invoke property on get', function() { - var obj = {}; - var count = 0; + let obj = {}; + let count = 0; defineProperty(obj, 'foo', computed(function(key) { count++; return 'computed ' + key; @@ -62,11 +62,11 @@ QUnit.test('defining computed property should invoke property on get', function( }); QUnit.test('defining computed property should invoke property on set', function() { - var obj = {}; - var count = 0; + let obj = {}; + let count = 0; defineProperty(obj, 'foo', computed({ - get: function(key) { return this['__' + key]; }, - set: function(key, value) { + get(key) { return this['__' + key]; }, + set(key, value) { count++; this['__' + key] = 'computed ' + value; return this['__' + key]; @@ -79,7 +79,7 @@ QUnit.test('defining computed property should invoke property on set', function( }); QUnit.test('defining a computed property with a dependent key ending with @each is expanded to []', function() { - var cp = computed('blazo.@each', function() { }); + let cp = computed('blazo.@each', function() { }); deepEqual(cp._dependentKeys, ['blazo.[]']); @@ -110,15 +110,15 @@ QUnit.test('defining a computed property with a dependent key more than one leve }, warning); }); -var objA, objB; +let objA, objB; QUnit.module('computed should inherit through prototype', { setup() { objA = { __foo: 'FOO' }; defineProperty(objA, 'foo', computed({ - get: function(key) { + get(key) { return this['__' + key]; }, - set: function(key, value) { + set(key, value) { this['__' + key] = 'computed ' + value; return this['__' + key]; } @@ -154,10 +154,10 @@ QUnit.module('redefining computed property to normal', { setup() { objA = { __foo: 'FOO' }; defineProperty(objA, 'foo', computed({ - get: function(key) { + get(key) { return this['__' + key]; }, - set: function(key, value) { + set(key, value) { this['__' + key] = 'computed ' + value; return this['__' + key]; } @@ -193,10 +193,10 @@ QUnit.module('redefining computed property to another property', { setup() { objA = { __foo: 'FOO' }; defineProperty(objA, 'foo', computed({ - get: function(key) { + get(key) { return this['__' + key]; }, - set: function(key, value) { + set(key, value) { this['__' + key] = 'A ' + value; return this['__' + key]; } @@ -205,8 +205,8 @@ QUnit.module('redefining computed property to another property', { objB = Object.create(objA); objB.__foo = 'FOO'; defineProperty(objB, 'foo', computed({ - get: function(key) { return this['__' + key]; }, - set: function(key, value) { + get(key) { return this['__' + key]; }, + set(key, value) { this['__' + key] = 'B ' + value; return this['__' + key]; } @@ -238,14 +238,14 @@ testBoth('using get() and set()', function(get, set) { QUnit.module('computed - metadata'); QUnit.test('can set metadata on a computed property', function() { - var computedProperty = computed(function() { }); + let computedProperty = computed(function() { }); computedProperty.meta({ key: 'keyValue' }); equal(computedProperty.meta().key, 'keyValue', 'saves passed meta hash to the _meta property'); }); QUnit.test('meta should return an empty hash if no meta is set', function() { - var computedProperty = computed(function() { }); + let computedProperty = computed(function() { }); deepEqual(computedProperty.meta(), {}, 'returned value is an empty hash'); }); @@ -257,7 +257,7 @@ QUnit.module('computed - cacheable', { setup() { obj = {}; count = 0; - var func = function(key, value) { + let func = function(key, value) { count++; return 'bar ' + count; }; @@ -285,7 +285,7 @@ testBoth('modifying a cacheable property should update cache', function(get, set }); testBoth('inherited property should not pick up cache', function(get, set) { - var objB = Object.create(obj); + let objB = Object.create(obj); equal(get(obj, 'foo'), 'bar 1', 'obj first get'); equal(get(objB, 'foo'), 'bar 2', 'objB first get'); @@ -319,15 +319,15 @@ testBoth('cacheFor should return falsy cached values', function(get, set) { }); testBoth('setting a cached computed property passes the old value as the third argument', function(get, set) { - var obj = { + let obj = { foo: 0 }; - var receivedOldValue; + let receivedOldValue; defineProperty(obj, 'plusOne', computed({ - get: function() {}, - set: function(key, value, oldValue) { + get() {}, + set(key, value, oldValue) { receivedOldValue = oldValue; return value; } }).property('foo') @@ -351,7 +351,7 @@ QUnit.module('computed - dependentkey', { setup() { obj = { bar: 'baz' }; count = 0; - var getterAndSetter = function(key, value) { + let getterAndSetter = function(key, value) { count++; get(this, 'bar'); return 'bar ' + count; @@ -392,7 +392,7 @@ testBoth('local dependent key should invalidate cache', function(get, set) { }); testBoth('should invalidate multiple nested dependent keys', function(get, set) { - var count = 0; + let count = 0; defineProperty(obj, 'bar', computed(function() { count++; get(this, 'baz'); @@ -417,7 +417,7 @@ testBoth('should invalidate multiple nested dependent keys', function(get, set) }); testBoth('circular keys should not blow up', function(get, set) { - var func = function(key, value) { + let func = function(key, value) { count++; return 'bar ' + count; }; @@ -495,8 +495,8 @@ testBoth('throws assertion if brace expansion notation has spaces', function (ge // -var func; -var moduleOpts = { +let func; +let moduleOpts = { setup() { obj = { foo: { @@ -579,7 +579,7 @@ testBoth('chained dependent keys should evaluate computed properties lazily', fu QUnit.module('computed - improved cp syntax'); QUnit.test('setter and getters are passed using an object', function() { - var testObj = EmberObject.extend({ + let testObj = EmberObject.extend({ a: '1', b: '2', aInt: computed('a', { @@ -604,7 +604,7 @@ QUnit.test('setter and getters are passed using an object', function() { }); QUnit.test('setter can be omited', function() { - var testObj = EmberObject.extend({ + let testObj = EmberObject.extend({ a: '1', b: '2', aInt: computed('a', { @@ -622,7 +622,7 @@ QUnit.test('setter can be omited', function() { }); QUnit.test('the return value of the setter gets cached', function() { - var testObj = EmberObject.extend({ + let testObj = EmberObject.extend({ a: '1', sampleCP: computed('a', { get(keyName) { @@ -646,11 +646,11 @@ QUnit.test('the return value of the setter gets cached', function() { QUnit.module('computed edge cases'); QUnit.test('adding a computed property should show up in key iteration', function() { - var obj = {}; + let obj = {}; defineProperty(obj, 'foo', computed(function() {})); - var found = []; - for (var key in obj) { + let found = []; + for (let key in obj) { found.push(key); } ok(found.indexOf('foo')>=0, 'should find computed property in iteration found=' + found); @@ -658,12 +658,12 @@ QUnit.test('adding a computed property should show up in key iteration', functio }); testBoth('when setting a value after it had been retrieved empty don\'t pass function UNDEFINED as oldValue', function(get, set) { - var obj = {}; - var oldValueIsNoFunction = true; + let obj = {}; + let oldValueIsNoFunction = true; defineProperty(obj, 'foo', computed({ - get: function() { }, - set: function(key, value, oldValue) { + get() { }, + set(key, value, oldValue) { if (typeof oldValue === 'function') { oldValueIsNoFunction = false; } @@ -680,26 +680,26 @@ testBoth('when setting a value after it had been retrieved empty don\'t pass fun QUnit.module('computed - setter'); testBoth('setting a watched computed property', function(get, set) { - var obj = { + let obj = { firstName: 'Yehuda', lastName: 'Katz' }; defineProperty(obj, 'fullName', computed({ - get: function() { return get(this, 'firstName') + ' ' + get(this, 'lastName'); }, - set: function(key, value) { - var values = value.split(' '); + get() { return get(this, 'firstName') + ' ' + get(this, 'lastName'); }, + set(key, value) { + let values = value.split(' '); set(this, 'firstName', values[0]); set(this, 'lastName', values[1]); return value; } }).property('firstName', 'lastName') ); - var fullNameWillChange = 0; - var fullNameDidChange = 0; - var firstNameWillChange = 0; - var firstNameDidChange = 0; - var lastNameWillChange = 0; - var lastNameDidChange = 0; + let fullNameWillChange = 0; + let fullNameDidChange = 0; + let firstNameWillChange = 0; + let firstNameDidChange = 0; + let lastNameWillChange = 0; + let lastNameDidChange = 0; _addBeforeObserver(obj, 'fullName', function () { fullNameWillChange++; }); @@ -738,19 +738,19 @@ testBoth('setting a watched computed property', function(get, set) { }); testBoth('setting a cached computed property that modifies the value you give it', function(get, set) { - var obj = { + let obj = { foo: 0 }; defineProperty(obj, 'plusOne', computed({ - get: function(key) { return get(this, 'foo') + 1; }, - set: function(key, value) { + get(key) { return get(this, 'foo') + 1; }, + set(key, value) { set(this, 'foo', value); return value + 1; } }).property('foo') ); - var plusOneWillChange = 0; - var plusOneDidChange = 0; + let plusOneWillChange = 0; + let plusOneDidChange = 0; _addBeforeObserver(obj, 'plusOne', function () { plusOneWillChange++; }); @@ -777,16 +777,14 @@ testBoth('setting a cached computed property that modifies the value you give it QUnit.module('computed - default setter'); testBoth('when setting a value on a computed property that doesn\'t handle sets', function(get, set) { - var obj = {}; - var observerFired = false; + let obj = {}; + let observerFired = false; defineProperty(obj, 'foo', computed(function() { return 'foo'; })); - addObserver(obj, 'foo', null, function() { - observerFired = true; - }); + addObserver(obj, 'foo', null, () => observerFired = true); set(obj, 'foo', 'bar'); @@ -798,23 +796,23 @@ testBoth('when setting a value on a computed property that doesn\'t handle sets' QUnit.module('computed - readOnly'); QUnit.test('is chainable', function() { - var cp = computed(function() {}).readOnly(); + let cp = computed(function() {}).readOnly(); ok(cp instanceof Descriptor); ok(cp instanceof ComputedProperty); }); QUnit.test('throws assertion if called over a CP with a setter defined with the new syntax', function() { - expectAssertion(function() { + expectAssertion(() => { computed({ - get: function() { }, - set: function() { } + get() { }, + set() { } }).readOnly(); }, /Computed properties that define a setter using the new syntax cannot be read-only/); }); testBoth('protects against setting', function(get, set) { - var obj = { }; + let obj = { }; defineProperty(obj, 'bar', computed(function(key) { return 'barValue'; @@ -822,7 +820,7 @@ testBoth('protects against setting', function(get, set) { equal(get(obj, 'bar'), 'barValue'); - throws(function() { + throws(() => { set(obj, 'bar', 'newBar'); }, /Cannot set read\-only property "bar" on object:/ ); diff --git a/packages/ember-metal/tests/core/inspect_test.js b/packages/ember-metal/tests/core/inspect_test.js index 595a0444904..cd6ceb12ebf 100644 --- a/packages/ember-metal/tests/core/inspect_test.js +++ b/packages/ember-metal/tests/core/inspect_test.js @@ -33,7 +33,7 @@ QUnit.test('object', function() { }); QUnit.test('objects without a prototype', function() { - var prototypelessObj = Object.create(null); + let prototypelessObj = Object.create(null); equal(inspect({ foo: prototypelessObj }), '{foo: [object Object]}'); }); @@ -46,7 +46,7 @@ QUnit.test('regexp', function() { }); QUnit.test('date', function() { - var inspected = inspect(new Date('Sat Apr 30 2011 13:24:11')); + let inspected = inspect(new Date('Sat Apr 30 2011 13:24:11')); ok(inspected.match(/Sat Apr 30/), 'The inspected date has its date'); ok(inspected.match(/2011/), 'The inspected date has its year'); ok(inspected.match(/13:24:11/), 'The inspected date has its time'); diff --git a/packages/ember-metal/tests/error_test.js b/packages/ember-metal/tests/error_test.js index 9524f8bb743..cd7cdf9c5c8 100644 --- a/packages/ember-metal/tests/error_test.js +++ b/packages/ember-metal/tests/error_test.js @@ -3,9 +3,7 @@ import EmberError from 'ember-metal/error'; QUnit.module('Ember Error Throwing'); QUnit.test('new Ember.Error displays provided message', function() { - throws(function() { + throws(() => { throw new EmberError('A Message'); - }, function(e) { - return e.message === 'A Message'; - }, 'the assigned message was displayed'); + }, e => e.message === 'A Message', 'the assigned message was displayed'); }); diff --git a/packages/ember-metal/tests/events_test.js b/packages/ember-metal/tests/events_test.js index 567632c45a4..cd7998cdfde 100644 --- a/packages/ember-metal/tests/events_test.js +++ b/packages/ember-metal/tests/events_test.js @@ -15,9 +15,10 @@ import { QUnit.module('system/props/events_test'); QUnit.test('listener should receive event - removing should remove', function() { - var obj = {}; - var count = 0; - var F = function() { count++; }; + let obj = {}; + let count = 0; + + function F() { count++; } addListener(obj, 'event!', F); equal(count, 0, 'nothing yet'); @@ -33,13 +34,13 @@ QUnit.test('listener should receive event - removing should remove', function() }); QUnit.test('listeners should be inherited', function() { - var obj = {}; - var count = 0; - var F = function() { count++; }; + let obj = {}; + let count = 0; + let F = function() { count++; }; addListener(obj, 'event!', F); - var obj2 = Object.create(obj); + let obj2 = Object.create(obj); equal(count, 0, 'nothing yet'); @@ -58,9 +59,9 @@ QUnit.test('listeners should be inherited', function() { QUnit.test('adding a listener more than once should only invoke once', function() { - var obj = {}; - var count = 0; - var F = function() { count++; }; + let obj = {}; + let count = 0; + function F() { count++; } addListener(obj, 'event!', F); addListener(obj, 'event!', F); @@ -69,8 +70,8 @@ QUnit.test('adding a listener more than once should only invoke once', function( }); QUnit.test('adding a listener with a target should invoke with target', function() { - var obj = {}; - var target; + let obj = {}; + let target; target = { count: 0, @@ -83,8 +84,8 @@ QUnit.test('adding a listener with a target should invoke with target', function }); QUnit.test('suspending a listener should not invoke during callback', function() { - var obj = {}; - var target, otherTarget; + let obj = {}; + let target, otherTarget; target = { count: 0, @@ -119,8 +120,8 @@ QUnit.test('suspending a listener should not invoke during callback', function() }); QUnit.test('adding a listener with string method should lookup method on event delivery', function() { - var obj = {}; - var target; + let obj = {}; + let target; target = { count: 0, @@ -137,8 +138,8 @@ QUnit.test('adding a listener with string method should lookup method on event d }); QUnit.test('calling sendEvent with extra params should be passed to listeners', function() { - var obj = {}; - var params = null; + let obj = {}; + let params = null; addListener(obj, 'event!', function() { params = Array.prototype.slice.call(arguments); }); @@ -148,9 +149,10 @@ QUnit.test('calling sendEvent with extra params should be passed to listeners', }); QUnit.test('hasListeners tells you if there are listeners for a given event', function() { - var obj = {}; - var F = function() {}; - var F2 = function() {}; + let obj = {}; + + function F() {} + function F2() {} equal(hasListeners(obj, 'event!'), false, 'no listeners at first'); @@ -170,9 +172,9 @@ QUnit.test('hasListeners tells you if there are listeners for a given event', fu }); QUnit.test('calling removeListener without method should remove all listeners', function() { - var obj = {}; - var F = function() {}; - var F2 = function() {}; + let obj = {}; + function F() {} + function F2() {} equal(hasListeners(obj, 'event!'), false, 'no listeners at first'); @@ -186,8 +188,8 @@ QUnit.test('calling removeListener without method should remove all listeners', }); QUnit.test('while suspended, it should not be possible to add a duplicate listener', function() { - var obj = {}; - var target; + let obj = {}; + let target; target = { count: 0, @@ -218,8 +220,8 @@ QUnit.test('while suspended, it should not be possible to add a duplicate listen }); QUnit.test('a listener can be added as part of a mixin', function() { - var triggered = 0; - var MyMixin = Mixin.create({ + let triggered = 0; + let MyMixin = Mixin.create({ foo1: on('bar', function() { triggered++; }), @@ -229,7 +231,7 @@ QUnit.test('a listener can be added as part of a mixin', function() { }) }); - var obj = {}; + let obj = {}; MyMixin.apply(obj); sendEvent(obj, 'bar'); @@ -237,19 +239,19 @@ QUnit.test('a listener can be added as part of a mixin', function() { }); QUnit.test('a listener added as part of a mixin may be overridden', function() { - var triggered = 0; - var FirstMixin = Mixin.create({ + let triggered = 0; + let FirstMixin = Mixin.create({ foo: on('bar', function() { triggered++; }) }); - var SecondMixin = Mixin.create({ + let SecondMixin = Mixin.create({ foo: on('baz', function() { triggered++; }) }); - var obj = {}; + let obj = {}; FirstMixin.apply(obj); SecondMixin.apply(obj); @@ -261,7 +263,7 @@ QUnit.test('a listener added as part of a mixin may be overridden', function() { }); QUnit.test('DEPRECATED: adding didInitAttrs as a listener is deprecated', function() { - var obj = Component.create(); + let obj = Component.create(); expectDeprecation(() => { addListener(obj, 'didInitAttrs'); diff --git a/packages/ember-metal/tests/expand_properties_test.js b/packages/ember-metal/tests/expand_properties_test.js index 9b4adaadd24..a082e17fc9f 100644 --- a/packages/ember-metal/tests/expand_properties_test.js +++ b/packages/ember-metal/tests/expand_properties_test.js @@ -1,6 +1,6 @@ import expandProperties from 'ember-metal/expand_properties'; -var foundProperties = []; +let foundProperties = []; function addProperty(property) { foundProperties.push(property); @@ -36,7 +36,7 @@ QUnit.test('A property with only a brace expansion expands correctly', function( expandProperties('{a,b,c}', addProperty); - var expected = ['a', 'b', 'c']; + let expected = ['a', 'b', 'c']; deepEqual(expected.sort(), foundProperties.sort()); }); @@ -53,7 +53,7 @@ QUnit.test('A single brace expansion expands correctly', function() { expandProperties('a.{b,c,d}.e', addProperty); - var expected = ['a.b.e', 'a.c.e', 'a.d.e']; + let expected = ['a.b.e', 'a.c.e', 'a.d.e']; deepEqual(expected.sort(), foundProperties.sort()); }); @@ -62,7 +62,7 @@ QUnit.test('Multiple brace expansions work correctly', function() { expandProperties('{a,b,c}.d.{e,f}.g', addProperty); - var expected = ['a.d.e.g', 'a.d.f.g', 'b.d.e.g', 'b.d.f.g', 'c.d.e.g', 'c.d.f.g']; + let expected = ['a.d.e.g', 'a.d.f.g', 'b.d.e.g', 'b.d.f.g', 'c.d.e.g', 'c.d.f.g']; deepEqual(expected.sort(), foundProperties.sort()); }); @@ -71,14 +71,14 @@ QUnit.test('A property with only brace expansions expands correctly', function() expandProperties('{a,b,c}.{d}.{e,f}', addProperty); - var expected = ['a.d.e', 'a.d.f', 'b.d.e', 'b.d.f', 'c.d.e', 'c.d.f']; + let expected = ['a.d.e', 'a.d.f', 'b.d.e', 'b.d.f', 'c.d.e', 'c.d.f']; deepEqual(expected.sort(), foundProperties.sort()); }); QUnit.test('A pattern must be a string', function() { expect(1); - expectAssertion(function() { + expectAssertion(() => { expandProperties([], addProperty); }, /A computed property key must be a string/); }); @@ -86,7 +86,7 @@ QUnit.test('A pattern must be a string', function() { QUnit.test('A pattern must not contain a space', function() { expect(1); - expectAssertion(function() { + expectAssertion(() => { expandProperties('a, b', addProperty); }, /Brace expanded properties cannot contain spaces, e.g. "user.{firstName, lastName}" should be "user.{firstName,lastName}"/); }); diff --git a/packages/ember-metal/tests/injected_property_test.js b/packages/ember-metal/tests/injected_property_test.js index a91befcc01a..44d3704450f 100644 --- a/packages/ember-metal/tests/injected_property_test.js +++ b/packages/ember-metal/tests/injected_property_test.js @@ -14,7 +14,7 @@ QUnit.test('injected properties should be descriptors', function() { }); QUnit.test('injected properties should be overridable', function() { - var obj = {}; + let obj = {}; defineProperty(obj, 'foo', new InjectedProperty()); set(obj, 'foo', 'bar'); @@ -23,7 +23,7 @@ QUnit.test('injected properties should be overridable', function() { }); QUnit.test('getting on an object without an owner or container should fail assertion', function() { - var obj = {}; + let obj = {}; defineProperty(obj, 'foo', new InjectedProperty('type', 'name')); expectAssertion(function() { @@ -32,7 +32,7 @@ QUnit.test('getting on an object without an owner or container should fail asser }); QUnit.test('getting on an object without an owner but with a container should not fail', function() { - var obj = { + let obj = { container: { lookup(key) { ok(true, 'should call container.lookup'); @@ -49,7 +49,7 @@ QUnit.test('getting on an object without an owner but with a container should no QUnit.test('getting should return a lookup on the container', function() { expect(2); - var obj = {}; + let obj = {}; setOwner(obj, { lookup(key) { @@ -64,7 +64,7 @@ QUnit.test('getting should return a lookup on the container', function() { }); QUnit.test('omitting the lookup name should default to the property name', function() { - var obj = {}; + let obj = {}; setOwner(obj, { lookup(key) { diff --git a/packages/ember-metal/tests/instrumentation_test.js b/packages/ember-metal/tests/instrumentation_test.js index 229407a1db6..e232c2402aa 100644 --- a/packages/ember-metal/tests/instrumentation_test.js +++ b/packages/ember-metal/tests/instrumentation_test.js @@ -12,7 +12,7 @@ QUnit.module('Ember Instrumentation', { }); QUnit.test('execute block even if no listeners', function() { - var result = instrument('render', {}, function() { + let result = instrument('render', {}, function() { return 'hello'; }); equal(result, 'hello', 'called block'); @@ -21,8 +21,8 @@ QUnit.test('execute block even if no listeners', function() { QUnit.test('subscribing to a simple path receives the listener', function() { expect(12); - var sentPayload = {}; - var count = 0; + let sentPayload = {}; + let count = 0; subscribe('render', { before(name, timestamp, payload) { @@ -58,8 +58,8 @@ QUnit.test('subscribing to a simple path receives the listener', function() { QUnit.test('returning a value from the before callback passes it to the after callback', function() { expect(2); - var passthru1 = {}; - var passthru2 = {}; + let passthru1 = {}; + let passthru2 = {}; subscribe('render', { before(name, timestamp, payload) { @@ -98,7 +98,7 @@ QUnit.test('instrument with 2 args (name, callback) no payload', function() { QUnit.test('instrument with 3 args (name, callback, binding) no payload', function() { expect(2); - var binding = {}; + let binding = {}; subscribe('render', { before(name, timestamp, payload) { deepEqual(payload, {}); @@ -115,7 +115,7 @@ QUnit.test('instrument with 3 args (name, callback, binding) no payload', functi QUnit.test('instrument with 3 args (name, payload, callback) with payload', function() { expect(1); - var expectedPayload = { hi: 1 }; + let expectedPayload = { hi: 1 }; subscribe('render', { before(name, timestamp, payload) { deepEqual(payload, expectedPayload); @@ -129,8 +129,8 @@ QUnit.test('instrument with 3 args (name, payload, callback) with payload', func QUnit.test('instrument with 4 args (name, payload, callback, binding) with payload', function() { expect(2); - var expectedPayload = { hi: 1 }; - var binding = {}; + let expectedPayload = { hi: 1 }; + let binding = {}; subscribe('render', { before(name, timestamp, payload) { deepEqual(payload, expectedPayload); @@ -147,7 +147,7 @@ QUnit.test('instrument with 4 args (name, payload, callback, binding) with paylo QUnit.test('raising an exception in the instrumentation attaches it to the payload', function() { expect(2); - var error = new Error('Instrumentation'); + let error = new Error('Instrumentation'); subscribe('render', { before() {}, @@ -186,9 +186,9 @@ QUnit.test('it is possible to add a new subscriber after the first instrument', QUnit.test('it is possible to remove a subscriber', function() { expect(4); - var count = 0; + let count = 0; - var subscriber = subscribe('render', { + let subscriber = subscribe('render', { before() { equal(count, 0); ok(true, 'Before callback was called'); diff --git a/packages/ember-metal/tests/is_blank_test.js b/packages/ember-metal/tests/is_blank_test.js index e5cc9370389..5a609b6f4a0 100644 --- a/packages/ember-metal/tests/is_blank_test.js +++ b/packages/ember-metal/tests/is_blank_test.js @@ -3,9 +3,9 @@ import isBlank from 'ember-metal/is_blank'; QUnit.module('Ember.isBlank'); QUnit.test('Ember.isBlank', function() { - var string = 'string'; - var fn = function() {}; - var object = { length: 0 }; + let string = 'string'; + let fn = function() {}; + let object = { length: 0 }; equal(true, isBlank(null), 'for null'); equal(true, isBlank(undefined), 'for undefined'); diff --git a/packages/ember-metal/tests/is_empty_test.js b/packages/ember-metal/tests/is_empty_test.js index 8a2046ed633..58ba00a0237 100644 --- a/packages/ember-metal/tests/is_empty_test.js +++ b/packages/ember-metal/tests/is_empty_test.js @@ -7,9 +7,9 @@ import { QUnit.module('Ember.isEmpty'); QUnit.test('Ember.isEmpty', function() { - var string = 'string'; - var fn = function() {}; - var object = { length: 0 }; + let string = 'string'; + let fn = function() {}; + let object = { length: 0 }; equal(true, isEmpty(null), 'for null'); equal(true, isEmpty(undefined), 'for undefined'); @@ -27,14 +27,14 @@ QUnit.test('Ember.isEmpty', function() { }); QUnit.test('Ember.isEmpty Ember.Map', function() { - var map = new Map(); + let map = new Map(); equal(true, isEmpty(map), 'Empty map is empty'); map.set('foo', 'bar'); equal(false, isEmpty(map), 'Map is not empty'); }); QUnit.test('Ember.isEmpty Ember.OrderedSet', function() { - var orderedSet = new OrderedSet(); + let orderedSet = new OrderedSet(); equal(true, isEmpty(orderedSet), 'Empty ordered set is empty'); orderedSet.add('foo'); equal(false, isEmpty(orderedSet), 'Ordered set is not empty'); diff --git a/packages/ember-metal/tests/is_none_test.js b/packages/ember-metal/tests/is_none_test.js index 7f8498daf86..b962cc18103 100644 --- a/packages/ember-metal/tests/is_none_test.js +++ b/packages/ember-metal/tests/is_none_test.js @@ -3,8 +3,8 @@ import isNone from 'ember-metal/is_none'; QUnit.module('Ember.isNone'); QUnit.test('Ember.isNone', function() { - var string = 'string'; - var fn = function() {}; + let string = 'string'; + let fn = function() {}; equal(true, isNone(null), 'for null'); equal(true, isNone(undefined), 'for undefined'); diff --git a/packages/ember-metal/tests/is_present_test.js b/packages/ember-metal/tests/is_present_test.js index d68c70f702a..fd4d8a9fdac 100644 --- a/packages/ember-metal/tests/is_present_test.js +++ b/packages/ember-metal/tests/is_present_test.js @@ -3,9 +3,9 @@ import isPresent from 'ember-metal/is_present'; QUnit.module('Ember.isPresent'); QUnit.test('Ember.isPresent', function() { - var string = 'string'; - var fn = function() {}; - var object = { length: 0 }; + let string = 'string'; + let fn = function() {}; + let object = { length: 0 }; equal(false, isPresent(), 'for no params'); equal(false, isPresent(null), 'for null'); diff --git a/packages/ember-metal/tests/libraries_test.js b/packages/ember-metal/tests/libraries_test.js index 284b5bd78a5..5354968c860 100644 --- a/packages/ember-metal/tests/libraries_test.js +++ b/packages/ember-metal/tests/libraries_test.js @@ -3,7 +3,7 @@ import { getDebugFunction, setDebugFunction } from 'ember-metal/debug'; import isEnabled from 'ember-metal/features'; import { Libraries } from 'ember-metal/libraries'; -var libs, registry; +let libs, registry; let originalWarn = getDebugFunction('warn'); QUnit.module('Libraries registry', { diff --git a/packages/ember-metal/tests/main_test.js b/packages/ember-metal/tests/main_test.js index cfa2fad322a..d92830a4b05 100644 --- a/packages/ember-metal/tests/main_test.js +++ b/packages/ember-metal/tests/main_test.js @@ -1,12 +1,12 @@ import Ember from 'ember-metal'; // testing reexports // From sindresourhus/semver-regex https://github.com/sindresorhus/semver-regex/blob/795b05628d96597ebcbe6d31ef4a432858365582/index.js#L3 -var SEMVER_REGEX = /^\bv?(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)(?:-[\da-z\-]+(?:\.[\da-z\-]+)*)?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?\b$/; +const SEMVER_REGEX = /^\bv?(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)(?:-[\da-z\-]+(?:\.[\da-z\-]+)*)?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?\b$/; QUnit.module('ember-metal/core/main'); QUnit.test('Ember registers itself', function() { - var lib = Ember.libraries._registry[0]; + let lib = Ember.libraries._registry[0]; equal(lib.name, 'Ember'); equal(lib.version, Ember.VERSION); diff --git a/packages/ember-metal/tests/map_test.js b/packages/ember-metal/tests/map_test.js index e75c6c3cbee..93d2850d46d 100644 --- a/packages/ember-metal/tests/map_test.js +++ b/packages/ember-metal/tests/map_test.js @@ -4,8 +4,8 @@ import { OrderedSet } from 'ember-metal/map'; -var object, number, string, map, variety; -var varieties = [['Map', Map], ['MapWithDefault', MapWithDefault]]; +let object, number, string, map, variety; +const varieties = [['Map', Map], ['MapWithDefault', MapWithDefault]]; function testMap(nameAndFunc) { variety = nameAndFunc[0]; @@ -20,10 +20,10 @@ function testMap(nameAndFunc) { } }); - var mapHasLength = function(expected, theMap) { + let mapHasLength = function(expected, theMap) { theMap = theMap || map; - var length = 0; + let length = 0; theMap.forEach(function() { length++; }); @@ -31,10 +31,10 @@ function testMap(nameAndFunc) { equal(length, expected, 'map should contain ' + expected + ' items'); }; - var mapHasEntries = function(entries, theMap) { + let mapHasEntries = function(entries, theMap) { theMap = theMap || map; - for (var i = 0; i < entries.length; i++) { + for (let i = 0; i < entries.length; i++) { equal(theMap.get(entries[i][0]), entries[i][1]); equal(theMap.has(entries[i][0]), true); } @@ -42,7 +42,7 @@ function testMap(nameAndFunc) { mapHasLength(entries.length, theMap); }; - var unboundThis; + let unboundThis; (function() { unboundThis = this; @@ -146,7 +146,7 @@ function testMap(nameAndFunc) { map.set(number, 'winning'); map.set(string, 'winning'); - var map2 = map.copy(); + let map2 = map.copy(); map2.set(object, 'losing'); map2.set(number, 'losing'); @@ -170,7 +170,7 @@ function testMap(nameAndFunc) { map.set(number, 'winning'); map.set(string, 'winning'); - var map2 = map.copy(); + let map2 = map.copy(); map2.delete(object); map2.delete(number); @@ -202,7 +202,7 @@ function testMap(nameAndFunc) { equal(map.size, 2); //Check copy - var copy = map.copy(); + let copy = map.copy(); equal(copy.size, 2); //Remove a key twice @@ -250,16 +250,16 @@ function testMap(nameAndFunc) { map.set('b', 2); map.set('c', 3); - var iteration = 0; + let iteration = 0; - var expectations = [ + let expectations = [ { value: 1, key: 'a', context: unboundThis }, { value: 2, key: 'b', context: unboundThis }, { value: 3, key: 'c', context: unboundThis } ]; map.forEach(function(value, key, theMap) { - var expectation = expectations[iteration]; + let expectation = expectations[iteration]; equal(value, expectation.value, 'value should be correct'); equal(key, expectation.key, 'key should be correct'); @@ -277,16 +277,16 @@ function testMap(nameAndFunc) { map.set('b', 2); map.set('c', 3); - var iteration = 0; - var context = {}; - var expectations = [ + let iteration = 0; + let context = {}; + let expectations = [ { value: 1, key: 'a', context: context }, { value: 2, key: 'b', context: context }, { value: 3, key: 'c', context: context } ]; map.forEach(function(value, key, theMap) { - var expectation = expectations[iteration]; + let expectation = expectations[iteration]; equal(value, expectation.value, 'value should be correct'); equal(key, expectation.key, 'key should be correct'); @@ -304,9 +304,9 @@ function testMap(nameAndFunc) { map.set('b', 2); map.set('c', 3); - var iteration = 0; + let iteration = 0; - var expectations = [ + let expectations = [ { value: 1, key: 'a', context: unboundThis }, { value: 2, key: 'b', context: unboundThis } ]; @@ -316,7 +316,7 @@ function testMap(nameAndFunc) { map.delete('c'); } - var expectation = expectations[iteration]; + let expectation = expectations[iteration]; equal(value, expectation.value, 'value should be correct'); equal(key, expectation.key, 'key should be correct'); @@ -334,9 +334,9 @@ function testMap(nameAndFunc) { map.set('b', 2); map.set('c', 3); - var iteration = 0; + let iteration = 0; - var expectations = [ + let expectations = [ { value: 1, key: 'a', context: unboundThis }, { value: 2, key: 'b', context: unboundThis }, { value: 3, key: 'c', context: unboundThis }, @@ -348,7 +348,7 @@ function testMap(nameAndFunc) { map.set('d', 4); } - var expectation = expectations[iteration]; + let expectation = expectations[iteration]; equal(value, expectation.value, 'value should be correct'); equal(key, expectation.key, 'key should be correct'); @@ -362,7 +362,7 @@ function testMap(nameAndFunc) { }); QUnit.test('clear', function() { - var iterations = 0; + let iterations = 0; map.set('a', 1); map.set('b', 2); @@ -414,7 +414,7 @@ function testMap(nameAndFunc) { QUnit.test('NaN Boxed', function() { //jshint -W053 - var boxed = new Number(NaN); + let boxed = new Number(NaN); equal(map.has(boxed), false); map.set(boxed, 'not-a-number'); @@ -427,7 +427,7 @@ function testMap(nameAndFunc) { }); QUnit.test('0 value', function() { - var obj = {}; + let obj = {}; equal(map.has(obj), false); equal(map.size, 0); @@ -444,39 +444,39 @@ function testMap(nameAndFunc) { }); } -for (var i = 0; i < varieties.length; i++) { +for (let i = 0; i < varieties.length; i++) { testMap(varieties[i]); } QUnit.module('MapWithDefault - default values'); QUnit.test('Retrieving a value that has not been set returns and sets a default value', function() { - var map = MapWithDefault.create({ + let map = MapWithDefault.create({ defaultValue(key) { return [key]; } }); - var value = map.get('ohai'); + let value = map.get('ohai'); deepEqual(value, ['ohai']); strictEqual(value, map.get('ohai')); }); QUnit.test('Map.prototype.constructor', function() { - var map = new Map(); + let map = new Map(); equal(map.constructor, Map); }); QUnit.test('MapWithDefault.prototype.constructor', function() { - var map = new MapWithDefault({ + let map = new MapWithDefault({ defaultValue(key) { return key; } }); equal(map.constructor, MapWithDefault); }); QUnit.test('Copying a MapWithDefault copies the default value', function() { - var map = MapWithDefault.create({ + let map = MapWithDefault.create({ defaultValue(key) { return [key]; } @@ -485,7 +485,7 @@ QUnit.test('Copying a MapWithDefault copies the default value', function() { map.set('ohai', 1); map.get('bai'); - var map2 = map.copy(); + let map2 = map.copy(); equal(map2.get('ohai'), 1); deepEqual(map2.get('bai'), ['bai']); @@ -497,9 +497,7 @@ QUnit.test('Copying a MapWithDefault copies the default value', function() { deepEqual(map2.get('default'), ['default']); - map2.defaultValue = function(key) { - return ['tom is on', key]; - }; + map2.defaultValue = key => ['tom is on', key]; deepEqual(map2.get('drugs'), ['tom is on', 'drugs']); }); @@ -515,7 +513,7 @@ QUnit.module('OrderedSet', { }); QUnit.test('add returns the set', function() { - var obj = {}; + let obj = {}; equal(map.add(obj), map); equal(map.add(obj), map, 'when it is already in the set'); }); diff --git a/packages/ember-metal/tests/meta_test.js b/packages/ember-metal/tests/meta_test.js index a047c4dbcb2..9ba10a850df 100644 --- a/packages/ember-metal/tests/meta_test.js +++ b/packages/ember-metal/tests/meta_test.js @@ -5,7 +5,7 @@ import { QUnit.module('Ember.meta'); QUnit.test('should return the same hash for an object', function() { - var obj = {}; + let obj = {}; meta(obj).foo = 'bar'; @@ -13,7 +13,7 @@ QUnit.test('should return the same hash for an object', function() { }); QUnit.test('meta is not enumerable', function () { - var proto, obj, props, prop; + let proto, obj, props, prop; proto = { foo: 'bar' }; meta(proto); obj = Object.create(proto); diff --git a/packages/ember-metal/tests/mixin/alias_method_test.js b/packages/ember-metal/tests/mixin/alias_method_test.js index e0a90110a42..c68bfd32e25 100644 --- a/packages/ember-metal/tests/mixin/alias_method_test.js +++ b/packages/ember-metal/tests/mixin/alias_method_test.js @@ -13,63 +13,63 @@ function validateAliasMethod(obj) { } QUnit.test('methods of another name are aliased when the mixin is applied', function() { - var MyMixin = Mixin.create({ + let MyMixin = Mixin.create({ fooMethod() { return 'FOO'; }, barMethod: aliasMethod('fooMethod') }); - var obj = MyMixin.apply({}); + let obj = MyMixin.apply({}); validateAliasMethod(obj); }); QUnit.test('should follow aliasMethods all the way down', function() { - var MyMixin = Mixin.create({ + let MyMixin = Mixin.create({ bar: aliasMethod('foo'), // put first to break ordered iteration baz() { return 'baz'; }, foo: aliasMethod('baz') }); - var obj = MyMixin.apply({}); + let obj = MyMixin.apply({}); equal(get(obj, 'bar')(), 'baz', 'should have followed aliasMethods'); }); QUnit.test('should alias methods from other dependent mixins', function() { - var BaseMixin = Mixin.create({ + let BaseMixin = Mixin.create({ fooMethod() { return 'FOO'; } }); - var MyMixin = Mixin.create(BaseMixin, { + let MyMixin = Mixin.create(BaseMixin, { barMethod: aliasMethod('fooMethod') }); - var obj = MyMixin.apply({}); + let obj = MyMixin.apply({}); validateAliasMethod(obj); }); QUnit.test('should alias methods from other mixins applied at same time', function() { - var BaseMixin = Mixin.create({ + let BaseMixin = Mixin.create({ fooMethod() { return 'FOO'; } }); - var MyMixin = Mixin.create({ + let MyMixin = Mixin.create({ barMethod: aliasMethod('fooMethod') }); - var obj = mixin({}, BaseMixin, MyMixin); + let obj = mixin({}, BaseMixin, MyMixin); validateAliasMethod(obj); }); QUnit.test('should alias methods from mixins already applied on object', function() { - var BaseMixin = Mixin.create({ + let BaseMixin = Mixin.create({ quxMethod() { return 'qux'; } }); - var MyMixin = Mixin.create({ + let MyMixin = Mixin.create({ bar: aliasMethod('foo'), barMethod: aliasMethod('fooMethod') }); - var obj = { + let obj = { fooMethod() { return 'FOO'; } }; diff --git a/packages/ember-metal/tests/mixin/apply_test.js b/packages/ember-metal/tests/mixin/apply_test.js index b84d318df6a..f8ccc3e98b0 100644 --- a/packages/ember-metal/tests/mixin/apply_test.js +++ b/packages/ember-metal/tests/mixin/apply_test.js @@ -9,8 +9,8 @@ QUnit.module('Ember.Mixin.apply'); function K() {} QUnit.test('using apply() should apply properties', function() { - var MixinA = Mixin.create({ foo: 'FOO', baz: K }); - var obj = {}; + let MixinA = Mixin.create({ foo: 'FOO', baz: K }); + let obj = {}; mixin(obj, MixinA); equal(get(obj, 'foo'), 'FOO', 'should apply foo'); @@ -18,7 +18,7 @@ QUnit.test('using apply() should apply properties', function() { }); QUnit.test('applying anonymous properties', function() { - var obj = {}; + let obj = {}; mixin(obj, { foo: 'FOO', baz: K @@ -29,13 +29,11 @@ QUnit.test('applying anonymous properties', function() { }); QUnit.test('applying null values', function() { - expectAssertion(function() { - mixin({}, null); - }); + expectAssertion(() => mixin({}, null)); }); QUnit.test('applying a property with an undefined value', function() { - var obj = { tagName: '' }; + let obj = { tagName: '' }; mixin(obj, { tagName: undefined }); strictEqual(get(obj, 'tagName'), ''); diff --git a/packages/ember-metal/tests/mixin/computed_test.js b/packages/ember-metal/tests/mixin/computed_test.js index ddefadef44e..e8ca56474ba 100644 --- a/packages/ember-metal/tests/mixin/computed_test.js +++ b/packages/ember-metal/tests/mixin/computed_test.js @@ -9,8 +9,8 @@ function K() { return this; } QUnit.module('Mixin Computed Properties'); QUnit.test('overriding computed properties', function() { - var MixinA, MixinB, MixinC, MixinD; - var obj; + let MixinA, MixinB, MixinC, MixinD; + let obj; MixinA = Mixin.create({ aProp: computed(function() { @@ -59,23 +59,23 @@ QUnit.test('overriding computed properties', function() { }); QUnit.test('calling set on overridden computed properties', function() { - var SuperMixin, SubMixin; - var obj; + let SuperMixin, SubMixin; + let obj; - var superGetOccurred = false; - var superSetOccurred = false; + let superGetOccurred = false; + let superSetOccurred = false; SuperMixin = Mixin.create({ aProp: computed({ - get: function(key) { superGetOccurred = true; }, - set: function(key, value) { superSetOccurred = true; } + get(key) { superGetOccurred = true; }, + set(key, value) { superSetOccurred = true; } }) }); SubMixin = Mixin.create(SuperMixin, { aProp: computed({ - get: function(key) { return this._super(...arguments); }, - set: function(key, value) { return this._super(...arguments); } + get(key) { return this._super(...arguments); }, + set(key, value) { return this._super(...arguments); } }) }); @@ -98,25 +98,25 @@ QUnit.test('calling set on overridden computed properties', function() { }); QUnit.test('setter behavior works properly when overriding computed properties', function() { - var obj = {}; + let obj = {}; - var MixinA = Mixin.create({ + let MixinA = Mixin.create({ cpWithSetter2: computed(K), cpWithSetter3: computed(K), cpWithoutSetter: computed(K) }); - var cpWasCalled = false; + let cpWasCalled = false; - var MixinB = Mixin.create({ + let MixinB = Mixin.create({ cpWithSetter2: computed({ get: K, - set: function(k, v) { cpWasCalled = true; } + set(k, v) { cpWasCalled = true; } }), cpWithSetter3: computed({ get: K, - set: function(k, v) { cpWasCalled = true; } + set(k, v) { cpWasCalled = true; } }), cpWithoutSetter: computed(function(k) { diff --git a/packages/ember-metal/tests/mixin/concatenated_properties_test.js b/packages/ember-metal/tests/mixin/concatenated_properties_test.js index 7b50041ff09..ea082ff51ae 100644 --- a/packages/ember-metal/tests/mixin/concatenated_properties_test.js +++ b/packages/ember-metal/tests/mixin/concatenated_properties_test.js @@ -7,104 +7,104 @@ import { QUnit.module('Mixin concatenatedProperties'); QUnit.test('defining concatenated properties should concat future version', function() { - var MixinA = Mixin.create({ + let MixinA = Mixin.create({ concatenatedProperties: ['foo'], foo: ['a', 'b', 'c'] }); - var MixinB = Mixin.create({ + let MixinB = Mixin.create({ foo: ['d', 'e', 'f'] }); - var obj = mixin({}, MixinA, MixinB); + let obj = mixin({}, MixinA, MixinB); deepEqual(get(obj, 'foo'), ['a', 'b', 'c', 'd', 'e', 'f']); }); QUnit.test('defining concatenated properties should concat future version', function() { - var MixinA = Mixin.create({ + let MixinA = Mixin.create({ concatenatedProperties: null }); - var MixinB = Mixin.create({ + let MixinB = Mixin.create({ concatenatedProperties: null }); - var obj = mixin({}, MixinA, MixinB); + let obj = mixin({}, MixinA, MixinB); deepEqual(obj.concatenatedProperties, []); }); QUnit.test('concatenatedProperties should be concatenated', function() { - var MixinA = Mixin.create({ + let MixinA = Mixin.create({ concatenatedProperties: ['foo'], foo: ['a', 'b', 'c'] }); - var MixinB = Mixin.create({ + let MixinB = Mixin.create({ concatenatedProperties: 'bar', foo: ['d', 'e', 'f'], bar: [1, 2, 3] }); - var MixinC = Mixin.create({ + let MixinC = Mixin.create({ bar: [4, 5, 6] }); - var obj = mixin({}, MixinA, MixinB, MixinC); + let obj = mixin({}, MixinA, MixinB, MixinC); deepEqual(get(obj, 'concatenatedProperties'), ['foo', 'bar'], 'get concatenatedProperties'); deepEqual(get(obj, 'foo'), ['a', 'b', 'c', 'd', 'e', 'f'], 'get foo'); deepEqual(get(obj, 'bar'), [1, 2, 3, 4, 5, 6], 'get bar'); }); QUnit.test('adding a prop that is not an array should make array', function() { - var MixinA = Mixin.create({ + let MixinA = Mixin.create({ concatenatedProperties: ['foo'], foo: [1, 2, 3] }); - var MixinB = Mixin.create({ + let MixinB = Mixin.create({ foo: 4 }); - var obj = mixin({}, MixinA, MixinB); + let obj = mixin({}, MixinA, MixinB); deepEqual(get(obj, 'foo'), [1, 2, 3, 4]); }); QUnit.test('adding a prop that is not an array should make array', function() { - var MixinA = Mixin.create({ + let MixinA = Mixin.create({ concatenatedProperties: ['foo'], foo: 'bar' }); - var obj = mixin({}, MixinA); + let obj = mixin({}, MixinA); deepEqual(get(obj, 'foo'), ['bar']); }); QUnit.test('adding a non-concatenable property that already has a defined value should result in an array with both values', function() { - var mixinA = Mixin.create({ + let mixinA = Mixin.create({ foo: 1 }); - var mixinB = Mixin.create({ + let mixinB = Mixin.create({ concatenatedProperties: ['foo'], foo: 2 }); - var obj = mixin({}, mixinA, mixinB); + let obj = mixin({}, mixinA, mixinB); deepEqual(get(obj, 'foo'), [1, 2]); }); QUnit.test('adding a concatenable property that already has a defined value should result in a concatenated value', function() { - var mixinA = Mixin.create({ + let mixinA = Mixin.create({ foobar: 'foo' }); - var mixinB = Mixin.create({ + let mixinB = Mixin.create({ concatenatedProperties: ['foobar'], foobar: 'bar' }); - var obj = mixin({}, mixinA, mixinB); + let obj = mixin({}, mixinA, mixinB); equal(get(obj, 'foobar'), 'foobar'); }); diff --git a/packages/ember-metal/tests/mixin/detect_test.js b/packages/ember-metal/tests/mixin/detect_test.js index 5742e9dc34b..475e862b009 100644 --- a/packages/ember-metal/tests/mixin/detect_test.js +++ b/packages/ember-metal/tests/mixin/detect_test.js @@ -3,8 +3,8 @@ import { Mixin } from 'ember-metal/mixin'; QUnit.module('Mixin.detect'); QUnit.test('detect() finds a directly applied mixin', function() { - var MixinA = Mixin.create(); - var obj = {}; + let MixinA = Mixin.create(); + let obj = {}; equal(MixinA.detect(obj), false, 'MixinA.detect(obj) before apply()'); @@ -13,9 +13,9 @@ QUnit.test('detect() finds a directly applied mixin', function() { }); QUnit.test('detect() finds nested mixins', function() { - var MixinA = Mixin.create({}); - var MixinB = Mixin.create(MixinA); - var obj = {}; + let MixinA = Mixin.create({}); + let MixinB = Mixin.create(MixinA); + let obj = {}; equal(MixinA.detect(obj), false, 'MixinA.detect(obj) before apply()'); @@ -24,13 +24,13 @@ QUnit.test('detect() finds nested mixins', function() { }); QUnit.test('detect() finds mixins on other mixins', function() { - var MixinA = Mixin.create({}); - var MixinB = Mixin.create(MixinA); + let MixinA = Mixin.create({}); + let MixinB = Mixin.create(MixinA); equal(MixinA.detect(MixinB), true, 'MixinA is part of MixinB'); equal(MixinB.detect(MixinA), false, 'MixinB is not part of MixinA'); }); QUnit.test('detect handles null values', function() { - var MixinA = Mixin.create(); + let MixinA = Mixin.create(); equal(MixinA.detect(null), false); }); diff --git a/packages/ember-metal/tests/mixin/introspection_test.js b/packages/ember-metal/tests/mixin/introspection_test.js index a764695b9b5..ac39559f629 100644 --- a/packages/ember-metal/tests/mixin/introspection_test.js +++ b/packages/ember-metal/tests/mixin/introspection_test.js @@ -8,35 +8,30 @@ import { Mixin } from 'ember-metal/mixin'; -var PrivateProperty = Mixin.create({ +const PrivateProperty = Mixin.create({ _foo: '_FOO' }); - -var PublicProperty = Mixin.create({ +const PublicProperty = Mixin.create({ foo: 'FOO' }); - -var PrivateMethod = Mixin.create({ +const PrivateMethod = Mixin.create({ _fooMethod() {} }); - -var PublicMethod = Mixin.create({ +const PublicMethod = Mixin.create({ fooMethod() {} }); - -var BarProperties = Mixin.create({ +const BarProperties = Mixin.create({ _bar: '_BAR', bar: 'bar' }); - -var BarMethods = Mixin.create({ +const BarMethods = Mixin.create({ _barMethod() {}, barMethod() {} }); -var Combined = Mixin.create(BarProperties, BarMethods); +const Combined = Mixin.create(BarProperties, BarMethods); -var obj; +let obj; QUnit.module('Basic introspection', { setup() { @@ -47,7 +42,7 @@ QUnit.module('Basic introspection', { QUnit.test('Ember.mixins()', function() { function mapGuids(ary) { - return ary.map(function(x) { return guidFor(x); }); + return ary.map(x => guidFor(x)); } deepEqual(mapGuids(Mixin.mixins(obj)), mapGuids([PrivateProperty, PublicProperty, PrivateMethod, PublicMethod, Combined, BarProperties, BarMethods]), 'should return included mixins'); diff --git a/packages/ember-metal/tests/mixin/merged_properties_test.js b/packages/ember-metal/tests/mixin/merged_properties_test.js index efa0820103d..a720ddf1e64 100644 --- a/packages/ember-metal/tests/mixin/merged_properties_test.js +++ b/packages/ember-metal/tests/mixin/merged_properties_test.js @@ -5,87 +5,87 @@ import { mixin, Mixin } from 'ember-metal/mixin'; QUnit.module('Mixin mergedProperties'); QUnit.test('defining mergedProperties should merge future version', function() { - var MixinA = Mixin.create({ + let MixinA = Mixin.create({ mergedProperties: ['foo'], foo: { a: true, b: true, c: true } }); - var MixinB = Mixin.create({ + let MixinB = Mixin.create({ foo: { d: true, e: true, f: true } }); - var obj = mixin({}, MixinA, MixinB); + let obj = mixin({}, MixinA, MixinB); deepEqual(get(obj, 'foo'), { a: true, b: true, c: true, d: true, e: true, f: true }); }); QUnit.test('defining mergedProperties on future mixin should merged into past', function() { - var MixinA = Mixin.create({ + let MixinA = Mixin.create({ foo: { a: true, b: true, c: true } }); - var MixinB = Mixin.create({ + let MixinB = Mixin.create({ mergedProperties: ['foo'], foo: { d: true, e: true, f: true } }); - var obj = mixin({}, MixinA, MixinB); + let obj = mixin({}, MixinA, MixinB); deepEqual(get(obj, 'foo'), { a: true, b: true, c: true, d: true, e: true, f: true }); }); QUnit.test('defining mergedProperties with null properties should keep properties null', function() { - var MixinA = Mixin.create({ + let MixinA = Mixin.create({ mergedProperties: ['foo'], foo: null }); - var MixinB = Mixin.create({ + let MixinB = Mixin.create({ foo: null }); - var obj = mixin({}, MixinA, MixinB); + let obj = mixin({}, MixinA, MixinB); equal(get(obj, 'foo'), null); }); QUnit.test('mergedProperties\' properties can get overwritten', function() { - var MixinA = Mixin.create({ + let MixinA = Mixin.create({ mergedProperties: ['foo'], foo: { a: 1 } }); - var MixinB = Mixin.create({ + let MixinB = Mixin.create({ foo: { a: 2 } }); - var obj = mixin({}, MixinA, MixinB); + let obj = mixin({}, MixinA, MixinB); deepEqual(get(obj, 'foo'), { a: 2 }); }); QUnit.test('mergedProperties should be concatenated', function() { - var MixinA = Mixin.create({ + let MixinA = Mixin.create({ mergedProperties: ['foo'], foo: { a: true, b: true, c: true } }); - var MixinB = Mixin.create({ + let MixinB = Mixin.create({ mergedProperties: 'bar', foo: { d: true, e: true, f: true }, bar: { a: true, l: true } }); - var MixinC = Mixin.create({ + let MixinC = Mixin.create({ bar: { e: true, x: true } }); - var obj = mixin({}, MixinA, MixinB, MixinC); + let obj = mixin({}, MixinA, MixinB, MixinC); deepEqual(get(obj, 'mergedProperties'), ['foo', 'bar'], 'get mergedProperties'); deepEqual(get(obj, 'foo'), { a: true, b: true, c: true, d: true, e: true, f: true }, 'get foo'); deepEqual(get(obj, 'bar'), { a: true, l: true, e: true, x: true }, 'get bar'); }); QUnit.test('mergedProperties should exist even if not explicitly set on create', function() { - var AnObj = EmberObject.extend({ + let AnObj = EmberObject.extend({ mergedProperties: ['options'], options: { a: 'a', @@ -95,7 +95,7 @@ QUnit.test('mergedProperties should exist even if not explicitly set on create', } }); - var obj = AnObj.create({ + let obj = AnObj.create({ options: { a: 'A' } @@ -106,19 +106,19 @@ QUnit.test('mergedProperties should exist even if not explicitly set on create', }); QUnit.test('defining mergedProperties at create time should not modify the prototype', function() { - var AnObj = EmberObject.extend({ + let AnObj = EmberObject.extend({ mergedProperties: ['options'], options: { a: 1 } }); - var objA = AnObj.create({ + let objA = AnObj.create({ options: { a: 2 } }); - var objB = AnObj.create({ + let objB = AnObj.create({ options: { a: 3 } @@ -131,7 +131,7 @@ QUnit.test('defining mergedProperties at create time should not modify the proto QUnit.test('mergedProperties\' overwriting methods can call _super', function() { expect(4); - var MixinA = Mixin.create({ + let MixinA = Mixin.create({ mergedProperties: ['foo'], foo: { meth(a) { @@ -141,7 +141,7 @@ QUnit.test('mergedProperties\' overwriting methods can call _super', function() } }); - var MixinB = Mixin.create({ + let MixinB = Mixin.create({ foo: { meth(a) { ok(true, 'MixinB\'s `foo.meth` method called'); @@ -150,7 +150,7 @@ QUnit.test('mergedProperties\' overwriting methods can call _super', function() } }); - var MixinC = Mixin.create({ + let MixinC = Mixin.create({ foo: { meth(a) { ok(true, 'MixinC\'s `foo.meth` method called'); @@ -159,23 +159,23 @@ QUnit.test('mergedProperties\' overwriting methods can call _super', function() } }); - var obj = mixin({}, MixinA, MixinB, MixinC); + let obj = mixin({}, MixinA, MixinB, MixinC); equal(obj.foo.meth('WOOT'), 'WAT'); }); QUnit.test('Merging an Array should raise an error', function() { expect(1); - var MixinA = Mixin.create({ + let MixinA = Mixin.create({ mergedProperties: ['foo'], foo: { a: true, b: true, c: true } }); - var MixinB = Mixin.create({ + let MixinB = Mixin.create({ foo: ['a'] }); - expectAssertion(function() { + expectAssertion(() => { mixin({}, MixinA, MixinB); }, 'You passed in `["a"]` as the value for `foo` but `foo` cannot be an Array'); }); diff --git a/packages/ember-metal/tests/mixin/method_test.js b/packages/ember-metal/tests/mixin/method_test.js index 53b1f002d93..adea9d73915 100644 --- a/packages/ember-metal/tests/mixin/method_test.js +++ b/packages/ember-metal/tests/mixin/method_test.js @@ -6,7 +6,7 @@ import { QUnit.module('Mixin Methods'); QUnit.test('defining simple methods', function() { - var MixinA, obj, props; + let MixinA, obj, props; props = { publicMethod() { return 'publicMethod'; }, @@ -23,7 +23,7 @@ QUnit.test('defining simple methods', function() { }); QUnit.test('overriding public methods', function() { - var MixinA, MixinB, MixinD, MixinF, obj; + let MixinA, MixinB, MixinD, MixinF, obj; MixinA = Mixin.create({ publicMethod() { return 'A'; } @@ -61,22 +61,22 @@ QUnit.test('overriding public methods', function() { QUnit.test('overriding inherited objects', function() { - var cnt = 0; - var MixinA = Mixin.create({ + let cnt = 0; + let MixinA = Mixin.create({ foo() { cnt++; } }); - var MixinB = Mixin.create({ + let MixinB = Mixin.create({ foo() { this._super(...arguments); cnt++; } }); - var objA = {}; + let objA = {}; MixinA.apply(objA); - var objB = Object.create(objA); + let objB = Object.create(objA); MixinB.apply(objB); cnt = 0; @@ -89,24 +89,24 @@ QUnit.test('overriding inherited objects', function() { }); QUnit.test('Including the same mixin more than once will only run once', function() { - var cnt = 0; - var MixinA = Mixin.create({ + let cnt = 0; + let MixinA = Mixin.create({ foo() { cnt++; } }); - var MixinB = Mixin.create(MixinA, { + let MixinB = Mixin.create(MixinA, { foo() { this._super(...arguments); } }); - var MixinC = Mixin.create(MixinA, { + let MixinC = Mixin.create(MixinA, { foo() { this._super(...arguments); } }); - var MixinD = Mixin.create(MixinB, MixinC, MixinA, { + let MixinD = Mixin.create(MixinB, MixinC, MixinA, { foo() { this._super(...arguments); } }); - var obj = {}; + let obj = {}; MixinD.apply(obj); MixinA.apply(obj); // try to apply again.. @@ -117,13 +117,13 @@ QUnit.test('Including the same mixin more than once will only run once', functio }); QUnit.test('_super from a single mixin with no superclass does not error', function() { - var MixinA = Mixin.create({ + let MixinA = Mixin.create({ foo() { this._super(...arguments); } }); - var obj = {}; + let obj = {}; MixinA.apply(obj); obj.foo(); @@ -133,8 +133,8 @@ QUnit.test('_super from a single mixin with no superclass does not error', funct QUnit.test('_super from a first-of-two mixins with no superclass function does not error', function() { // _super was previously calling itself in the second assertion. // Use remaining count of calls to ensure it doesn't loop indefinitely. - var remaining = 3; - var MixinA = Mixin.create({ + let remaining = 3; + let MixinA = Mixin.create({ foo() { if (remaining-- > 0) { this._super(...arguments); @@ -142,11 +142,11 @@ QUnit.test('_super from a first-of-two mixins with no superclass function does n } }); - var MixinB = Mixin.create({ + let MixinB = Mixin.create({ foo() { this._super(...arguments); } }); - var obj = {}; + let obj = {}; MixinA.apply(obj); MixinB.apply(obj); @@ -162,11 +162,11 @@ QUnit.module('Method Conflicts'); QUnit.test('overriding toString', function() { - var MixinA = Mixin.create({ + let MixinA = Mixin.create({ toString() { return 'FOO'; } }); - var obj = {}; + let obj = {}; MixinA.apply(obj); equal(obj.toString(), 'FOO', 'should override toString w/o error'); @@ -182,26 +182,26 @@ QUnit.test('overriding toString', function() { QUnit.module('system/mixin/method_test BUGS'); QUnit.test('applying several mixins at once with sup already defined causes infinite loop', function() { - var cnt = 0; - var MixinA = Mixin.create({ + let cnt = 0; + let MixinA = Mixin.create({ foo() { cnt++; } }); - var MixinB = Mixin.create({ + let MixinB = Mixin.create({ foo() { this._super(...arguments); cnt++; } }); - var MixinC = Mixin.create({ + let MixinC = Mixin.create({ foo() { this._super(...arguments); cnt++; } }); - var obj = {}; + let obj = {}; mixin(obj, MixinA); // sup already exists mixin(obj, MixinB, MixinC); // must be more than one mixin diff --git a/packages/ember-metal/tests/mixin/observer_test.js b/packages/ember-metal/tests/mixin/observer_test.js index 84ad9013d00..651f54f9f18 100644 --- a/packages/ember-metal/tests/mixin/observer_test.js +++ b/packages/ember-metal/tests/mixin/observer_test.js @@ -9,7 +9,7 @@ import { isWatching } from 'ember-metal/watching'; QUnit.module('Mixin observer'); testBoth('global observer helper', function(get, set) { - var MyMixin = Mixin.create({ + let MyMixin = Mixin.create({ count: 0, @@ -19,7 +19,7 @@ testBoth('global observer helper', function(get, set) { }); - var obj = mixin({}, MyMixin); + let obj = mixin({}, MyMixin); equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); set(obj, 'bar', 'BAZ'); @@ -27,7 +27,7 @@ testBoth('global observer helper', function(get, set) { }); testBoth('global observer helper takes multiple params', function(get, set) { - var MyMixin = Mixin.create({ + let MyMixin = Mixin.create({ count: 0, @@ -37,7 +37,7 @@ testBoth('global observer helper takes multiple params', function(get, set) { }); - var obj = mixin({}, MyMixin); + let obj = mixin({}, MyMixin); equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); set(obj, 'bar', 'BAZ'); @@ -46,7 +46,7 @@ testBoth('global observer helper takes multiple params', function(get, set) { }); testBoth('replacing observer should remove old observer', function(get, set) { - var MyMixin = Mixin.create({ + let MyMixin = Mixin.create({ count: 0, @@ -56,13 +56,13 @@ testBoth('replacing observer should remove old observer', function(get, set) { }); - var Mixin2 = Mixin.create({ + let Mixin2 = Mixin.create({ foo: observer('baz', function() { set(this, 'count', get(this, 'count') + 10); }) }); - var obj = mixin({}, MyMixin, Mixin2); + let obj = mixin({}, MyMixin, Mixin2); equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); set(obj, 'bar', 'BAZ'); @@ -73,9 +73,9 @@ testBoth('replacing observer should remove old observer', function(get, set) { }); testBoth('observing chain with property before', function(get, set) { - var obj2 = { baz: 'baz' }; + let obj2 = { baz: 'baz' }; - var MyMixin = Mixin.create({ + let MyMixin = Mixin.create({ count: 0, bar: obj2, foo: observer('bar.baz', function() { @@ -83,7 +83,7 @@ testBoth('observing chain with property before', function(get, set) { }) }); - var obj = mixin({}, MyMixin); + let obj = mixin({}, MyMixin); equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); set(obj2, 'baz', 'BAZ'); @@ -91,9 +91,9 @@ testBoth('observing chain with property before', function(get, set) { }); testBoth('observing chain with property after', function(get, set) { - var obj2 = { baz: 'baz' }; + let obj2 = { baz: 'baz' }; - var MyMixin = Mixin.create({ + let MyMixin = Mixin.create({ count: 0, foo: observer('bar.baz', function() { set(this, 'count', get(this, 'count') + 1); @@ -101,7 +101,7 @@ testBoth('observing chain with property after', function(get, set) { bar: obj2 }); - var obj = mixin({}, MyMixin); + let obj = mixin({}, MyMixin); equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); set(obj2, 'baz', 'BAZ'); @@ -109,9 +109,9 @@ testBoth('observing chain with property after', function(get, set) { }); testBoth('observing chain with property in mixin applied later', function(get, set) { - var obj2 = { baz: 'baz' }; + let obj2 = { baz: 'baz' }; - var MyMixin = Mixin.create({ + let MyMixin = Mixin.create({ count: 0, foo: observer('bar.baz', function() { @@ -119,9 +119,9 @@ testBoth('observing chain with property in mixin applied later', function(get, s }) }); - var MyMixin2 = Mixin.create({ bar: obj2 }); + let MyMixin2 = Mixin.create({ bar: obj2 }); - var obj = mixin({}, MyMixin); + let obj = mixin({}, MyMixin); equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); MyMixin2.apply(obj); @@ -132,16 +132,16 @@ testBoth('observing chain with property in mixin applied later', function(get, s }); testBoth('observing chain with existing property', function(get, set) { - var obj2 = { baz: 'baz' }; + let obj2 = { baz: 'baz' }; - var MyMixin = Mixin.create({ + let MyMixin = Mixin.create({ count: 0, foo: observer('bar.baz', function() { set(this, 'count', get(this, 'count') + 1); }) }); - var obj = mixin({ bar: obj2 }, MyMixin); + let obj = mixin({ bar: obj2 }, MyMixin); equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); set(obj2, 'baz', 'BAZ'); @@ -149,17 +149,17 @@ testBoth('observing chain with existing property', function(get, set) { }); testBoth('observing chain with property in mixin before', function(get, set) { - var obj2 = { baz: 'baz' }; - var MyMixin2 = Mixin.create({ bar: obj2 }); + let obj2 = { baz: 'baz' }; + let MyMixin2 = Mixin.create({ bar: obj2 }); - var MyMixin = Mixin.create({ + let MyMixin = Mixin.create({ count: 0, foo: observer('bar.baz', function() { set(this, 'count', get(this, 'count') + 1); }) }); - var obj = mixin({}, MyMixin2, MyMixin); + let obj = mixin({}, MyMixin2, MyMixin); equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); set(obj2, 'baz', 'BAZ'); @@ -167,17 +167,17 @@ testBoth('observing chain with property in mixin before', function(get, set) { }); testBoth('observing chain with property in mixin after', function(get, set) { - var obj2 = { baz: 'baz' }; - var MyMixin2 = Mixin.create({ bar: obj2 }); + let obj2 = { baz: 'baz' }; + let MyMixin2 = Mixin.create({ bar: obj2 }); - var MyMixin = Mixin.create({ + let MyMixin = Mixin.create({ count: 0, foo: observer('bar.baz', function() { set(this, 'count', get(this, 'count') + 1); }) }); - var obj = mixin({}, MyMixin, MyMixin2); + let obj = mixin({}, MyMixin, MyMixin2); equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); set(obj2, 'baz', 'BAZ'); @@ -185,19 +185,19 @@ testBoth('observing chain with property in mixin after', function(get, set) { }); testBoth('observing chain with overriden property', function(get, set) { - var obj2 = { baz: 'baz' }; - var obj3 = { baz: 'foo' }; + let obj2 = { baz: 'baz' }; + let obj3 = { baz: 'foo' }; - var MyMixin2 = Mixin.create({ bar: obj3 }); + let MyMixin2 = Mixin.create({ bar: obj3 }); - var MyMixin = Mixin.create({ + let MyMixin = Mixin.create({ count: 0, foo: observer('bar.baz', function() { set(this, 'count', get(this, 'count') + 1); }) }); - var obj = mixin({ bar: obj2 }, MyMixin, MyMixin2); + let obj = mixin({ bar: obj2 }, MyMixin, MyMixin2); equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); equal(isWatching(obj2, 'baz'), false, 'should not be watching baz'); diff --git a/packages/ember-metal/tests/mixin/reopen_test.js b/packages/ember-metal/tests/mixin/reopen_test.js index b3884fbb816..814cd545895 100644 --- a/packages/ember-metal/tests/mixin/reopen_test.js +++ b/packages/ember-metal/tests/mixin/reopen_test.js @@ -6,9 +6,9 @@ import Mixin from 'ember-metal/mixin'; QUnit.module('Ember.Mixin#reopen'); QUnit.test('using reopen() to add more properties to a simple', function() { - var MixinA = Mixin.create({ foo: 'FOO', baz: 'BAZ' }); + let MixinA = Mixin.create({ foo: 'FOO', baz: 'BAZ' }); MixinA.reopen({ bar: 'BAR', foo: 'FOO2' }); - var obj = {}; + let obj = {}; MixinA.apply(obj); equal(get(obj, 'foo'), 'FOO2', 'mixin() should override'); @@ -17,7 +17,7 @@ QUnit.test('using reopen() to add more properties to a simple', function() { }); QUnit.test('using reopen() and calling _super where there is not a super function does not cause infinite recursion', function() { - var Taco = EmberObject.extend({ + let Taco = EmberObject.extend({ createBreakfast() { // There is no original createBreakfast function. // Calling the wrapped _super function here @@ -33,10 +33,10 @@ QUnit.test('using reopen() and calling _super where there is not a super functio } }); - var taco = Taco.create(); + let taco = Taco.create(); - var result; - run(function() { + let result; + run(() => { try { result = taco.createBreakfast(); } catch(e) { diff --git a/packages/ember-metal/tests/mixin/required_test.js b/packages/ember-metal/tests/mixin/required_test.js index c192627e233..f5638bacdea 100644 --- a/packages/ember-metal/tests/mixin/required_test.js +++ b/packages/ember-metal/tests/mixin/required_test.js @@ -5,11 +5,11 @@ import { } from 'ember-metal/mixin'; import { get } from 'ember-metal/property_get'; -var PartialMixin, FinalMixin, obj; +let PartialMixin, FinalMixin, obj; QUnit.module('Module.required', { setup() { - expectDeprecation(function() { + expectDeprecation(() => { PartialMixin = Mixin.create({ foo: required(), bar: 'BAR' diff --git a/packages/ember-metal/tests/mixin/without_test.js b/packages/ember-metal/tests/mixin/without_test.js index d29abdc56e7..349c7e4e2f7 100644 --- a/packages/ember-metal/tests/mixin/without_test.js +++ b/packages/ember-metal/tests/mixin/without_test.js @@ -1,14 +1,14 @@ import { Mixin } from 'ember-metal/mixin'; QUnit.test('without should create a new mixin excluding named properties', function() { - var MixinA = Mixin.create({ + let MixinA = Mixin.create({ foo: 'FOO', bar: 'BAR' }); - var MixinB = MixinA.without('bar'); + let MixinB = MixinA.without('bar'); - var obj = {}; + let obj = {}; MixinB.apply(obj); equal(obj.foo, 'FOO', 'should defined foo'); diff --git a/packages/ember-metal/tests/observer_test.js b/packages/ember-metal/tests/observer_test.js index 366e027e7e7..14294740b92 100644 --- a/packages/ember-metal/tests/observer_test.js +++ b/packages/ember-metal/tests/observer_test.js @@ -40,8 +40,8 @@ function K() {} QUnit.module('addObserver'); testBoth('observer should fire when property is modified', function(get, set) { - var obj = {}; - var count = 0; + let obj = {}; + let count = 0; addObserver(obj, 'foo', function() { equal(get(obj, 'foo'), 'bar', 'should invoke AFTER value changed'); @@ -53,14 +53,14 @@ testBoth('observer should fire when property is modified', function(get, set) { }); testBoth('observer should fire when dependent property is modified', function(get, set) { - var obj = { bar: 'bar' }; + let obj = { bar: 'bar' }; defineProperty(obj, 'foo', computed(function() { return get(this, 'bar').toUpperCase(); }).property('bar')); get(obj, 'foo'); - var count = 0; + let count = 0; addObserver(obj, 'foo', function() { equal(get(obj, 'foo'), 'BAZ', 'should have invoked after prop change'); count++; @@ -71,8 +71,8 @@ testBoth('observer should fire when dependent property is modified', function(ge }); testBoth('observer should continue to fire after dependent properties are accessed', function(get, set) { - var observerCount = 0; - var obj = {}; + let observerCount = 0; + let obj = {}; defineProperty(obj, 'prop', computed(function () { return Math.random(); })); defineProperty(obj, 'anotherProp', computed('prop', function () { return get(this, 'prop') + Math.random(); })); @@ -81,7 +81,7 @@ testBoth('observer should continue to fire after dependent properties are access get(obj, 'anotherProp'); - for (var i = 0; i < 10; i++) { + for (let i = 0; i < 10; i++) { propertyWillChange(obj, 'prop'); propertyDidChange(obj, 'prop'); } @@ -91,8 +91,8 @@ testBoth('observer should continue to fire after dependent properties are access if (ENV.EXTEND_PROTOTYPES.Function) { testBoth('observer added declaratively via brace expansion should fire when property changes', function (get, set) { - var obj = { }; - var count = 0; + let obj = { }; + let count = 0; mixin(obj, { observeFooAndBar: function () { @@ -111,8 +111,8 @@ if (ENV.EXTEND_PROTOTYPES.Function) { }); testBoth('observer specified declaratively via brace expansion should fire when dependent property changes', function (get, set) { - var obj = { baz: 'Initial' }; - var count = 0; + let obj = { baz: 'Initial' }; + let count = 0; defineProperty(obj, 'foo', computed(function() { return get(this, 'bar').toLowerCase(); @@ -139,8 +139,8 @@ if (ENV.EXTEND_PROTOTYPES.Function) { } testBoth('observers watching multiple properties via brace expansion should fire when the properties change', function (get, set) { - var obj = { }; - var count = 0; + let obj = { }; + let count = 0; mixin(obj, { observeFooAndBar: observer('{foo,bar}', function () { @@ -159,8 +159,8 @@ testBoth('observers watching multiple properties via brace expansion should fire }); testBoth('observers watching multiple properties via brace expansion should fire when dependent properties change', function (get, set) { - var obj = { baz: 'Initial' }; - var count = 0; + let obj = { baz: 'Initial' }; + let count = 0; defineProperty(obj, 'foo', computed(function() { return get(this, 'bar').toLowerCase(); @@ -186,9 +186,9 @@ testBoth('observers watching multiple properties via brace expansion should fire }); testBoth('nested observers should fire in order', function(get, set) { - var obj = { foo: 'foo', bar: 'bar' }; - var fooCount = 0; - var barCount = 0; + let obj = { foo: 'foo', bar: 'bar' }; + let fooCount = 0; + let barCount = 0; addObserver(obj, 'foo', function() { fooCount++; }); addObserver(obj, 'bar', function() { @@ -203,15 +203,15 @@ testBoth('nested observers should fire in order', function(get, set) { }); testBoth('removing an chain observer on change should not fail', function(get, set) { - var foo = { bar: 'bar' }; - var obj1 = { foo: foo }; - var obj2 = { foo: foo }; - var obj3 = { foo: foo }; - var obj4 = { foo: foo }; - var count1 = 0; - var count2 = 0; - var count3 = 0; - var count4 = 0; + let foo = { bar: 'bar' }; + let obj1 = { foo: foo }; + let obj2 = { foo: foo }; + let obj3 = { foo: foo }; + let obj4 = { foo: foo }; + let count1 = 0; + let count2 = 0; + let count3 = 0; + let count4 = 0; function observer1() { count1++; } function observer2() { count2++; } @@ -237,15 +237,15 @@ testBoth('removing an chain observer on change should not fail', function(get, s }); testBoth('removing an chain before observer on change should not fail', function(get, set) { - var foo = { bar: 'bar' }; - var obj1 = { foo: foo }; - var obj2 = { foo: foo }; - var obj3 = { foo: foo }; - var obj4 = { foo: foo }; - var count1 = 0; - var count2 = 0; - var count3 = 0; - var count4 = 0; + let foo = { bar: 'bar' }; + let obj1 = { foo: foo }; + let obj2 = { foo: foo }; + let obj3 = { foo: foo }; + let obj4 = { foo: foo }; + let count1 = 0; + let count2 = 0; + let count3 = 0; + let count4 = 0; function observer1() { count1++; } function observer2() { count2++; } @@ -271,8 +271,8 @@ testBoth('removing an chain before observer on change should not fail', function }); testBoth('suspending an observer should not fire during callback', function(get, set) { - var obj = {}; - var target, otherTarget; + let obj = {}; + let target, otherTarget; target = { values: [], @@ -308,8 +308,8 @@ testBoth('suspending an observer should not fire during callback', function(get, testBoth('suspending an observer should not defer change notifications during callback', function(get, set) { - var obj = {}; - var target, otherTarget; + let obj = {}; + let target, otherTarget; target = { values: [], @@ -346,8 +346,8 @@ testBoth('suspending an observer should not defer change notifications during ca }); testBoth('suspending observers should not fire during callback', function(get, set) { - var obj = {}; - var target, otherTarget; + let obj = {}; + let target, otherTarget; target = { values: [], @@ -383,8 +383,8 @@ testBoth('suspending observers should not fire during callback', function(get, s testBoth('suspending observers should not defer change notifications during callback', function(get, set) { - var obj = {}; - var target, otherTarget; + let obj = {}; + let target, otherTarget; target = { values: [], @@ -421,8 +421,8 @@ testBoth('suspending observers should not defer change notifications during call }); testBoth('deferring property change notifications', function(get, set) { - var obj = { foo: 'foo' }; - var fooCount = 0; + let obj = { foo: 'foo' }; + let fooCount = 0; addObserver(obj, 'foo', function() { fooCount++; }); @@ -435,9 +435,9 @@ testBoth('deferring property change notifications', function(get, set) { }); testBoth('deferring property change notifications safely despite exceptions', function(get, set) { - var obj = { foo: 'foo' }; - var fooCount = 0; - var exc = new Error('Something unexpected happened!'); + let obj = { foo: 'foo' }; + let fooCount = 0; + let exc = new Error('Something unexpected happened!'); expect(2); addObserver(obj, 'foo', function() { fooCount++; }); @@ -465,8 +465,8 @@ testBoth('deferring property change notifications safely despite exceptions', fu }); testBoth('deferring property change notifications will not defer before observers', function(get, set) { - var obj = { foo: 'foo' }; - var fooCount = 0; + let obj = { foo: 'foo' }; + let fooCount = 0; _addBeforeObserver(obj, 'foo', function() { fooCount++; }); @@ -480,8 +480,8 @@ testBoth('deferring property change notifications will not defer before observer }); testBoth('addObserver should propagate through prototype', function(get, set) { - var obj = { foo: 'foo', count: 0 }; - var obj2; + let obj = { foo: 'foo', count: 0 }; + let obj2; addObserver(obj, 'foo', function() { this.count++; }); obj2 = Object.create(obj); @@ -498,13 +498,13 @@ testBoth('addObserver should propagate through prototype', function(get, set) { }); testBoth('addObserver should respect targets with methods', function(get, set) { - var observed = { foo: 'foo' }; + let observed = { foo: 'foo' }; - var target1 = { + let target1 = { count: 0, didChange(obj, keyName) { - var value = get(obj, keyName); + let value = get(obj, keyName); equal(this, target1, 'should invoke with this'); equal(obj, observed, 'param1 should be observed object'); equal(keyName, 'foo', 'param2 should be keyName'); @@ -513,11 +513,11 @@ testBoth('addObserver should respect targets with methods', function(get, set) { } }; - var target2 = { + let target2 = { count: 0, didChange(obj, keyName) { - var value = get(obj, keyName); + let value = get(obj, keyName); equal(this, target2, 'should invoke with this'); equal(obj, observed, 'param1 should be observed object'); equal(keyName, 'foo', 'param2 should be keyName'); @@ -535,9 +535,9 @@ testBoth('addObserver should respect targets with methods', function(get, set) { }); testBoth('addObserver should allow multiple objects to observe a property', function(get, set) { - var observed = { foo: 'foo' }; + let observed = { foo: 'foo' }; - var target1 = { + let target1 = { count: 0, didChange(obj, keyName, value) { @@ -545,7 +545,7 @@ testBoth('addObserver should allow multiple objects to observe a property', func } }; - var target2 = { + let target2 = { count: 0, didChange(obj, keyName, value) { @@ -568,8 +568,8 @@ testBoth('addObserver should allow multiple objects to observe a property', func QUnit.module('removeObserver'); testBoth('removing observer should stop firing', function(get, set) { - var obj = {}; - var count = 0; + let obj = {}; + let count = 0; function F() { count++; } addObserver(obj, 'foo', F); @@ -583,9 +583,9 @@ testBoth('removing observer should stop firing', function(get, set) { }); testBoth('local observers can be removed', function(get, set) { - var barObserved = 0; + let barObserved = 0; - var MyMixin = Mixin.create({ + let MyMixin = Mixin.create({ foo1: observer('bar', function() { barObserved++; }), @@ -595,7 +595,7 @@ testBoth('local observers can be removed', function(get, set) { }) }); - var obj = {}; + let obj = {}; MyMixin.apply(obj); set(obj, 'bar', 'HI!'); @@ -610,9 +610,9 @@ testBoth('local observers can be removed', function(get, set) { }); testBoth('removeObserver should respect targets with methods', function(get, set) { - var observed = { foo: 'foo' }; + let observed = { foo: 'foo' }; - var target1 = { + let target1 = { count: 0, didChange() { @@ -620,7 +620,7 @@ testBoth('removeObserver should respect targets with methods', function(get, set } }; - var target2 = { + let target2 = { count: 0, didChange() { @@ -651,8 +651,8 @@ testBoth('removeObserver should respect targets with methods', function(get, set QUnit.module('_addBeforeObserver'); testBoth('observer should fire before a property is modified', function(get, set) { - var obj = { foo: 'foo' }; - var count = 0; + let obj = { foo: 'foo' }; + let count = 0; _addBeforeObserver(obj, 'foo', function() { equal(get(obj, 'foo'), 'foo', 'should invoke before value changed'); @@ -664,14 +664,14 @@ testBoth('observer should fire before a property is modified', function(get, set }); testBoth('observer should fire before dependent property is modified', function(get, set) { - var obj = { bar: 'bar' }; + let obj = { bar: 'bar' }; defineProperty(obj, 'foo', computed(function() { return get(this, 'bar').toUpperCase(); }).property('bar')); get(obj, 'foo'); - var count = 0; + let count = 0; _addBeforeObserver(obj, 'foo', function() { equal(get(obj, 'foo'), 'BAR', 'should have invoked after prop change'); count++; @@ -682,8 +682,8 @@ testBoth('observer should fire before dependent property is modified', function( }); testBoth('before observer watching multiple properties via brace expansion should fire when properties change', function (get, set) { - var obj = {}; - var count = 0; + let obj = {}; + let count = 0; mixin(obj, { fooAndBarWatcher: _beforeObserver('{foo,bar}', function () { @@ -702,8 +702,8 @@ testBoth('before observer watching multiple properties via brace expansion shoul }); testBoth('before observer watching multiple properties via brace expansion should fire when dependent property changes', function (get, set) { - var obj = { baz: 'Initial' }; - var count = 0; + let obj = { baz: 'Initial' }; + let count = 0; defineProperty(obj, 'foo', computed(function() { return get(this, 'bar').toLowerCase(); @@ -729,8 +729,8 @@ testBoth('before observer watching multiple properties via brace expansion shoul }); testBoth('_addBeforeObserver should propagate through prototype', function(get, set) { - var obj = { foo: 'foo', count: 0 }; - var obj2; + let obj = { foo: 'foo', count: 0 }; + let obj2; _addBeforeObserver(obj, 'foo', function() { this.count++; }); obj2 = Object.create(obj); @@ -746,13 +746,13 @@ testBoth('_addBeforeObserver should propagate through prototype', function(get, }); testBoth('_addBeforeObserver should respect targets with methods', function(get, set) { - var observed = { foo: 'foo' }; + let observed = { foo: 'foo' }; - var target1 = { + let target1 = { count: 0, willChange(obj, keyName) { - var value = get(obj, keyName); + let value = get(obj, keyName); equal(this, target1, 'should invoke with this'); equal(obj, observed, 'param1 should be observed object'); equal(keyName, 'foo', 'param2 should be keyName'); @@ -761,11 +761,11 @@ testBoth('_addBeforeObserver should respect targets with methods', function(get, } }; - var target2 = { + let target2 = { count: 0, willChange(obj, keyName) { - var value = get(obj, keyName); + let value = get(obj, keyName); equal(this, target2, 'should invoke with this'); equal(obj, observed, 'param1 should be observed object'); equal(keyName, 'foo', 'param2 should be keyName'); @@ -786,7 +786,7 @@ testBoth('_addBeforeObserver should respect targets with methods', function(get, // CHAINED OBSERVERS // -var obj, count; +let obj, count; QUnit.module('addObserver - dependentkey with chained properties', { setup() { @@ -823,7 +823,7 @@ testBoth('depending on a chain with a computed property', function (get, set) { return { foo: 'bar' }; })); - var changed = 0; + let changed = 0; addObserver(obj, 'computed.foo', function () { changed++; }); @@ -836,7 +836,7 @@ testBoth('depending on a chain with a computed property', function (get, set) { }); testBoth('depending on a simple chain', function(get, set) { - var val; + let val; addObserver(obj, 'foo.bar.baz.biff', function(target, key) { val = get(target, key); count++; @@ -862,7 +862,7 @@ testBoth('depending on a simple chain', function(get, set) { equal(val, 'BUZZ'); equal(count, 5); - var foo = get(obj, 'foo'); + let foo = get(obj, 'foo'); set(obj, 'foo', 'BOO'); equal(val, undefined); @@ -873,7 +873,7 @@ testBoth('depending on a simple chain', function(get, set) { }); testBoth('depending on a chain with a capitalized first key', function(get, set) { - var val; + let val; addObserver(obj, 'Capital.foo.bar.baz.biff', function(target, key) { val = get(obj, key); @@ -900,7 +900,7 @@ testBoth('depending on a chain with a capitalized first key', function(get, set) equal(val, 'BUZZ'); equal(count, 5); - var foo = get(obj, 'foo'); + let foo = get(obj, 'foo'); set(obj, 'Capital.foo', 'BOO'); equal(val, undefined); @@ -919,8 +919,8 @@ QUnit.module('_removeBeforeObserver'); QUnit.module('props/observer_test - setting identical values'); testBoth('setting simple prop should not trigger', function(get, set) { - var obj = { foo: 'bar' }; - var count = 0; + let obj = { foo: 'bar' }; + let count = 0; addObserver(obj, 'foo', function() { count++; }); @@ -938,14 +938,14 @@ testBoth('setting simple prop should not trigger', function(get, set) { // dependent key change (which triggers a cache expiration and recomputation), observers will // not be fired if the CP setter is called with the last set value. testBoth('setting a cached computed property whose value has changed should trigger', function(get, set) { - var obj = {}; + let obj = {}; defineProperty(obj, 'foo', computed({ get: function() { return get(this, 'baz'); }, set: function(key, value) { return value; } }).property('baz')); - var count = 0; + let count = 0; addObserver(obj, 'foo', function() { count++; }); @@ -967,9 +967,9 @@ QUnit.module('Ember.immediateObserver (Deprecated)'); testBoth('immediate observers should fire synchronously', function(get, set) { expectDeprecation(/Usage of `Ember.immediateObserver` is deprecated, use `Ember.observer` instead./); - var obj = {}; - var observerCalled = 0; - var mixin; + let obj = {}; + let observerCalled = 0; + let mixin; // explicitly create a run loop so we do not inadvertently // trigger deferred behavior @@ -1000,9 +1000,9 @@ testBoth('immediate observers should fire synchronously', function(get, set) { if (ENV.EXTEND_PROTOTYPES.Function) { testBoth('immediate observers added declaratively via brace expansion fire synchronously', function (get, set) { - var obj = {}; - var observerCalled = 0; - var mixin; + let obj = {}; + let observerCalled = 0; + let mixin; // explicitly create a run loop so we do not inadvertently // trigger deferred behavior @@ -1035,9 +1035,9 @@ if (ENV.EXTEND_PROTOTYPES.Function) { testBoth('immediate observers watching multiple properties via brace expansion fire synchronously', function (get, set) { expectDeprecation(/Usage of `Ember.immediateObserver` is deprecated, use `Ember.observer` instead./); - var obj = {}; - var observerCalled = 0; - var mixin; + let obj = {}; + let observerCalled = 0; + let mixin; // explicitly create a run loop so we do not inadvertently // trigger deferred behavior @@ -1075,7 +1075,7 @@ testBoth('immediate observers are for internal properties only', function(get, s QUnit.module('changeProperties'); testBoth('observers added/removed during changeProperties should do the right thing.', function(get, set) { - var obj = { + let obj = { foo: 0 }; function Observer() { @@ -1098,12 +1098,12 @@ testBoth('observers added/removed during changeProperties should do the right th this.didChangeCount++; } }; - var addedBeforeFirstChangeObserver = new Observer(); - var addedAfterFirstChangeObserver = new Observer(); - var addedAfterLastChangeObserver = new Observer(); - var removedBeforeFirstChangeObserver = new Observer(); - var removedBeforeLastChangeObserver = new Observer(); - var removedAfterLastChangeObserver = new Observer(); + let addedBeforeFirstChangeObserver = new Observer(); + let addedAfterFirstChangeObserver = new Observer(); + let addedAfterLastChangeObserver = new Observer(); + let removedBeforeFirstChangeObserver = new Observer(); + let removedBeforeLastChangeObserver = new Observer(); + let removedAfterLastChangeObserver = new Observer(); removedBeforeFirstChangeObserver.add(); removedBeforeLastChangeObserver.add(); removedAfterLastChangeObserver.add(); @@ -1150,7 +1150,7 @@ testBoth('should not leak properties on the prototype', function () { function Beer() { } Beer.prototype.type = 'ipa'; - var beer = new Beer(); + let beer = new Beer(); addObserver(beer, 'type', K); deepEqual(Object.keys(beer), []); @@ -1161,7 +1161,7 @@ testBoth('observing a non existent property', function (get, set) { function Beer() { } Beer.prototype.type = 'ipa'; - var beer = new Beer(); + let beer = new Beer(); addObserver(beer, 'brand', K); @@ -1177,7 +1177,7 @@ testBoth('with observers switched on and off', function (get, set) { function Beer() { } Beer.prototype.type = 'ipa'; - var beer = new Beer(); + let beer = new Beer(); addObserver(beer, 'type', K); removeObserver(beer, 'type', K); @@ -1189,7 +1189,7 @@ testBoth('observers switched on and off with setter in between', function (get, function Beer() { } Beer.prototype.type = 'ipa'; - var beer = new Beer(); + let beer = new Beer(); addObserver(beer, 'type', K); set(beer, 'type', 'ale'); @@ -1202,7 +1202,7 @@ testBoth('observer switched on and off and then setter', function (get, set) { function Beer() { } Beer.prototype.type = 'ipa'; - var beer = new Beer(); + let beer = new Beer(); addObserver(beer, 'type', K); removeObserver(beer, 'type', K); @@ -1214,22 +1214,22 @@ testBoth('observer switched on and off and then setter', function (get, set) { testBoth('observers switched on and off with setter in between (observed property is not shadowing)', function (get, set) { function Beer() { } - var beer = new Beer(); + let beer = new Beer(); set(beer, 'type', 'ale'); deepEqual(Object.keys(beer), ['type'], 'only set'); - var otherBeer = new Beer(); + let otherBeer = new Beer(); addObserver(otherBeer, 'type', K); set(otherBeer, 'type', 'ale'); deepEqual(Object.keys(otherBeer), ['type'], 'addObserver -> set'); - var yetAnotherBeer = new Beer(); + let yetAnotherBeer = new Beer(); addObserver(yetAnotherBeer, 'type', K); set(yetAnotherBeer, 'type', 'ale'); removeObserver(beer, 'type', K); deepEqual(Object.keys(yetAnotherBeer), ['type'], 'addObserver -> set -> removeObserver'); - var itsMyLastBeer = new Beer(); + let itsMyLastBeer = new Beer(); set(itsMyLastBeer, 'type', 'ale'); removeObserver(beer, 'type', K); deepEqual(Object.keys(itsMyLastBeer), ['type'], 'set -> removeObserver'); @@ -1239,22 +1239,22 @@ testBoth('observers switched on and off with setter in between (observed propert function Beer() { } Beer.prototype.type = 'ipa'; - var beer = new Beer(); + let beer = new Beer(); set(beer, 'type', 'ale'); deepEqual(Object.keys(beer), ['type'], 'after set'); - var otherBeer = new Beer(); + let otherBeer = new Beer(); addObserver(otherBeer, 'type', K); set(otherBeer, 'type', 'ale'); deepEqual(Object.keys(otherBeer), ['type'], 'addObserver -> set'); - var yetAnotherBeer = new Beer(); + let yetAnotherBeer = new Beer(); addObserver(yetAnotherBeer, 'type', K); set(yetAnotherBeer, 'type', 'ale'); removeObserver(beer, 'type', K); deepEqual(Object.keys(yetAnotherBeer), ['type'], 'addObserver -> set -> removeObserver'); - var itsMyLastBeer = new Beer(); + let itsMyLastBeer = new Beer(); set(itsMyLastBeer, 'type', 'ale'); removeObserver(beer, 'type', K); deepEqual(Object.keys(itsMyLastBeer), ['type'], 'set -> removeObserver'); diff --git a/packages/ember-metal/tests/performance_test.js b/packages/ember-metal/tests/performance_test.js index 0450cc7a938..245e8287e7a 100644 --- a/packages/ember-metal/tests/performance_test.js +++ b/packages/ember-metal/tests/performance_test.js @@ -19,9 +19,9 @@ import { addObserver } from 'ember-metal/observer'; QUnit.module('Computed Properties - Number of times evaluated'); QUnit.test('computed properties that depend on multiple properties should run only once per run loop', function() { - var obj = { a: 'a', b: 'b', c: 'c' }; - var cpCount = 0; - var obsCount = 0; + let obj = { a: 'a', b: 'b', c: 'c' }; + let cpCount = 0; + let obsCount = 0; defineProperty(obj, 'abc', computed(function(key) { cpCount++; @@ -49,9 +49,9 @@ QUnit.test('computed properties that depend on multiple properties should run on }); QUnit.test('computed properties are not executed if they are the last segment of an observer chain pain', function() { - var foo = { bar: { baz: { } } }; + let foo = { bar: { baz: { } } }; - var count = 0; + let count = 0; defineProperty(foo.bar.baz, 'bam', computed(function() { count++; diff --git a/packages/ember-metal/tests/properties_test.js b/packages/ember-metal/tests/properties_test.js index 15b2fa29bfb..87627acb3cc 100644 --- a/packages/ember-metal/tests/properties_test.js +++ b/packages/ember-metal/tests/properties_test.js @@ -5,7 +5,7 @@ import { deprecateProperty } from 'ember-metal/deprecate_property'; QUnit.module('Ember.defineProperty'); QUnit.test('toString', function() { - var obj = {}; + let obj = {}; defineProperty(obj, 'toString', undefined, function() { return 'FOO'; }); equal(obj.toString(), 'FOO', 'should replace toString'); }); @@ -13,7 +13,7 @@ QUnit.test('toString', function() { QUnit.test('for data properties, didDefineProperty hook should be called if implemented', function() { expect(2); - var obj = { + let obj = { didDefineProperty(obj, keyName, value) { equal(keyName, 'foo', 'key name should be foo'); equal(value, 'bar', 'value should be bar'); @@ -26,9 +26,9 @@ QUnit.test('for data properties, didDefineProperty hook should be called if impl QUnit.test('for computed properties, didDefineProperty hook should be called if implemented', function() { expect(2); - var computedProperty = computed(function() { return this; }); + let computedProperty = computed(function() { return this; }); - var obj = { + let obj = { didDefineProperty(obj, keyName, value) { equal(keyName, 'foo', 'key name should be foo'); strictEqual(value, computedProperty, 'value should be passed as computed property'); @@ -41,14 +41,14 @@ QUnit.test('for computed properties, didDefineProperty hook should be called if QUnit.test('for descriptor properties, didDefineProperty hook should be called if implemented', function() { expect(2); - var descriptor = { + let descriptor = { writable: true, configurable: false, enumerable: true, value: 42 }; - var obj = { + let obj = { didDefineProperty(obj, keyName, value) { equal(keyName, 'answer', 'key name should be answer'); strictEqual(value, descriptor, 'value should be passed as descriptor'); @@ -62,7 +62,7 @@ QUnit.module('Ember.deprecateProperty'); QUnit.test('enables access to deprecated property and returns the value of the new property', function() { expect(3); - var obj = { foo: 'bar' }; + let obj = { foo: 'bar' }; deprecateProperty(obj, 'baz', 'foo'); @@ -75,11 +75,11 @@ QUnit.test('enables access to deprecated property and returns the value of the n QUnit.test('deprecatedKey is not enumerable', function() { expect(2); - var obj = { foo: 'bar', blammo: 'whammy' }; + let obj = { foo: 'bar', blammo: 'whammy' }; deprecateProperty(obj, 'baz', 'foo'); - for (var prop in obj) { + for (let prop in obj) { if (obj.hasOwnProperty(prop)) { notEqual(prop, 'baz'); } @@ -88,7 +88,7 @@ QUnit.test('deprecatedKey is not enumerable', function() { QUnit.test('enables setter to deprecated property and updates the value of the new property', function() { expect(3); - var obj = { foo: 'bar' }; + let obj = { foo: 'bar' }; deprecateProperty(obj, 'baz', 'foo'); diff --git a/packages/ember-metal/tests/props_helper.js b/packages/ember-metal/tests/props_helper.js index ab08c9eb6ae..daf5e2743f3 100644 --- a/packages/ember-metal/tests/props_helper.js +++ b/packages/ember-metal/tests/props_helper.js @@ -1,9 +1,9 @@ import { ENV } from 'ember-environment'; -import {get as getFromEmberMetal, getWithDefault as getWithDefaultFromEmberMetal} from 'ember-metal/property_get'; -import {set as setFromEmberMetal} from 'ember-metal/property_set'; +import { get as getFromEmberMetal, getWithDefault as getWithDefaultFromEmberMetal } from 'ember-metal/property_get'; +import { set as setFromEmberMetal } from 'ember-metal/property_set'; // used by unit tests to test both accessor mode and non-accessor mode -var testBoth = function(testname, callback) { +export function testBoth(testname, callback) { function emberget(x, y) { return getFromEmberMetal(x, y); } function emberset(x, y, z) { return setFromEmberMetal(x, y, z); } function aget(x, y) { return x[y]; } @@ -20,9 +20,9 @@ var testBoth = function(testname, callback) { ok('SKIPPING ACCESSORS'); } }); -}; +} -var testWithDefault = function(testname, callback) { +export function testWithDefault(testname, callback) { function emberget(x, y) { return getFromEmberMetal(x, y); } function embergetwithdefault(x, y, z) { return getWithDefaultFromEmberMetal(x, y, z); } function getwithdefault(x, y, z) { return x.getWithDefault(y, z); } @@ -53,6 +53,4 @@ var testWithDefault = function(testname, callback) { ok('SKIPPING ACCESSORS'); } }); -}; - -export {testWithDefault, testBoth}; +} diff --git a/packages/ember-metal/tests/run_loop/add_queue_test.js b/packages/ember-metal/tests/run_loop/add_queue_test.js index 4f1c5cb9b20..cb20d5cd6d4 100644 --- a/packages/ember-metal/tests/run_loop/add_queue_test.js +++ b/packages/ember-metal/tests/run_loop/add_queue_test.js @@ -1,7 +1,7 @@ import run from 'ember-metal/run_loop'; -var originalQueues = run.queues; -var queues; +const originalQueues = run.queues; +let queues; QUnit.module('system/run_loop/add_queue_test', { setup() { diff --git a/packages/ember-metal/tests/run_loop/debounce_test.js b/packages/ember-metal/tests/run_loop/debounce_test.js index 1780403d1d4..c28b1dba8c6 100644 --- a/packages/ember-metal/tests/run_loop/debounce_test.js +++ b/packages/ember-metal/tests/run_loop/debounce_test.js @@ -1,7 +1,8 @@ import run from 'ember-metal/run_loop'; -var originalDebounce = run.backburner.debounce; -var wasCalled = false; +const originalDebounce = run.backburner.debounce; +let wasCalled = false; + QUnit.module('Ember.run.debounce', { setup() { run.backburner.debounce = function() { wasCalled = true; }; @@ -12,7 +13,7 @@ QUnit.module('Ember.run.debounce', { }); QUnit.test('Ember.run.debounce uses Backburner.debounce', function() { - run.debounce(function() {}); + run.debounce(() => {}); ok(wasCalled, 'Ember.run.debounce used'); }); diff --git a/packages/ember-metal/tests/run_loop/later_test.js b/packages/ember-metal/tests/run_loop/later_test.js index a62104d82cc..c880b99202c 100644 --- a/packages/ember-metal/tests/run_loop/later_test.js +++ b/packages/ember-metal/tests/run_loop/later_test.js @@ -1,14 +1,14 @@ import isNone from 'ember-metal/is_none'; import run from 'ember-metal/run_loop'; -var originalSetTimeout = window.setTimeout; -var originalDateValueOf = Date.prototype.valueOf; +const originalSetTimeout = window.setTimeout; +const originalDateValueOf = Date.prototype.valueOf; const originalPlatform = run.backburner._platform; function wait(callback, maxWaitCount) { maxWaitCount = isNone(maxWaitCount) ? 100 : maxWaitCount; - originalSetTimeout(function() { + originalSetTimeout(() => { if (maxWaitCount > 0 && (run.hasScheduledTimers() || run.currentRunLoop)) { wait(callback, maxWaitCount - 1); @@ -41,49 +41,49 @@ QUnit.module('run.later', { }); asyncTest('should invoke after specified period of time - function only', function() { - var invoked = false; + let invoked = false; - run(function() { - run.later(function() { invoked = true; }, 100); + run(() => { + run.later(() => invoked = true, 100); }); - wait(function() { + wait(() => { QUnit.start(); equal(invoked, true, 'should have invoked later item'); }); }); asyncTest('should invoke after specified period of time - target/method', function() { - var obj = { invoked: false }; + let obj = { invoked: false }; - run(function() { + run(() => { run.later(obj, function() { this.invoked = true; }, 100); }); - wait(function() { + wait(() => { QUnit.start(); equal(obj.invoked, true, 'should have invoked later item'); }); }); asyncTest('should invoke after specified period of time - target/method/args', function() { - var obj = { invoked: 0 }; + let obj = { invoked: 0 }; - run(function() { + run(() => { run.later(obj, function(amt) { this.invoked += amt; }, 10, 100); }); - wait(function() { + wait(() => { QUnit.start(); equal(obj.invoked, 10, 'should have invoked later item'); }); }); asyncTest('should always invoke within a separate runloop', function() { - var obj = { invoked: 0 }; - var firstRunLoop, secondRunLoop; + let obj = { invoked: 0 }; + let firstRunLoop, secondRunLoop; - run(function() { + run(() => { firstRunLoop = run.currentRunLoop; run.later(obj, function(amt) { @@ -98,7 +98,7 @@ asyncTest('should always invoke within a separate runloop', function() { ok(!run.currentRunLoop, 'shouldn\'t be in a run loop after flush'); equal(obj.invoked, 0, 'shouldn\'t have invoked later item yet'); - wait(function() { + wait(() => { QUnit.start(); equal(obj.invoked, 10, 'should have invoked later item'); ok(secondRunLoop, 'second run loop took place'); @@ -111,7 +111,7 @@ asyncTest('should always invoke within a separate runloop', function() { // See https://github.com/emberjs/ember.js/issues/3526 for more information. // asyncTest('callback order', function() { -// var array = []; +// let array = []; // function fn(val) { array.push(val); } // run(function() { @@ -136,14 +136,14 @@ asyncTest('should always invoke within a separate runloop', function() { // See https://github.com/emberjs/ember.js/issues/3522 for more information. // asyncTest('callbacks coalesce into same run loop if expiring at the same time', function() { -// var array = []; +// let array = []; // function fn(val) { array.push(run.currentRunLoop); } // run(function() { // // Force +new Date to return the same result while scheduling // // run.later timers. Otherwise: non-determinism! -// var now = +new Date(); +// let now = +new Date(); // Date.prototype.valueOf = function() { return now; }; // run.later(this, fn, 10); @@ -166,18 +166,18 @@ asyncTest('should always invoke within a separate runloop', function() { // }); asyncTest('inception calls to run.later should run callbacks in separate run loops', function() { - var runLoop, finished; + let runLoop, finished; - run(function() { + run(() => { runLoop = run.currentRunLoop; ok(runLoop); - run.later(function() { + run.later(() => { ok(run.currentRunLoop && run.currentRunLoop !== runLoop, 'first later callback has own run loop'); runLoop = run.currentRunLoop; - run.later(function() { + run.later(() => { ok(run.currentRunLoop && run.currentRunLoop !== runLoop, 'second later callback has own run loop'); finished = true; @@ -185,7 +185,7 @@ asyncTest('inception calls to run.later should run callbacks in separate run loo }, 40); }); - wait(function() { + wait(() => { QUnit.start(); ok(finished, 'all .later callbacks run'); }); @@ -198,10 +198,10 @@ asyncTest('setTimeout should never run with a negative wait', function() { // older browsers (IE <= 8) break with a negative wait, which // happens when an expired timer callback takes a while to run, // which is what we simulate here. - var newSetTimeoutUsed; + let newSetTimeoutUsed; run.backburner._platform = { setTimeout() { - var wait = arguments[arguments.length - 1]; + let wait = arguments[arguments.length - 1]; newSetTimeoutUsed = true; ok(!isNaN(wait) && wait >= 0, 'wait is a non-negative number'); @@ -209,9 +209,9 @@ asyncTest('setTimeout should never run with a negative wait', function() { } }; - var count = 0; - run(function() { - run.later(function() { + let count = 0; + run(() => { + run.later(() => { count++; // This will get run first. Waste some time. @@ -223,12 +223,12 @@ asyncTest('setTimeout should never run with a negative wait', function() { pauseUntil(+new Date() + 60); }, 1); - run.later(function() { + run.later(() => { equal(count, 1, 'callbacks called in order'); }, 50); }); - wait(function() { + wait(() => { QUnit.start(); ok(newSetTimeoutUsed, 'stub setTimeout was used'); }); diff --git a/packages/ember-metal/tests/run_loop/next_test.js b/packages/ember-metal/tests/run_loop/next_test.js index a12fef6a119..8c50fe62ede 100644 --- a/packages/ember-metal/tests/run_loop/next_test.js +++ b/packages/ember-metal/tests/run_loop/next_test.js @@ -3,29 +3,27 @@ import run from 'ember-metal/run_loop'; QUnit.module('run.next'); asyncTest('should invoke immediately on next timeout', function() { - var invoked = false; + let invoked = false; - run(function() { - run.next(function() { invoked = true; }); - }); + run(() => run.next(() => invoked = true)); equal(invoked, false, 'should not have invoked yet'); - setTimeout(function() { + setTimeout(() => { QUnit.start(); equal(invoked, true, 'should have invoked later item'); }, 20); }); asyncTest('callback should be called from within separate loop', function() { - var firstRunLoop, secondRunLoop; - run(function() { + let firstRunLoop, secondRunLoop; + run(() => { firstRunLoop = run.currentRunLoop; - run.next(function() { secondRunLoop = run.currentRunLoop; }); + run.next(() => secondRunLoop = run.currentRunLoop); }); - setTimeout(function() { + setTimeout(() => { QUnit.start(); ok(secondRunLoop, 'callback was called from within run loop'); ok(firstRunLoop && secondRunLoop !== firstRunLoop, 'two separate run loops were invoked'); @@ -33,14 +31,14 @@ asyncTest('callback should be called from within separate loop', function() { }); asyncTest('multiple calls to run.next share coalesce callbacks into same run loop', function() { - var firstRunLoop, secondRunLoop, thirdRunLoop; - run(function() { + let firstRunLoop, secondRunLoop, thirdRunLoop; + run(() => { firstRunLoop = run.currentRunLoop; - run.next(function() { secondRunLoop = run.currentRunLoop; }); - run.next(function() { thirdRunLoop = run.currentRunLoop; }); + run.next(() => secondRunLoop = run.currentRunLoop); + run.next(() => thirdRunLoop = run.currentRunLoop); }); - setTimeout(function() { + setTimeout(() => { QUnit.start(); ok(secondRunLoop && secondRunLoop === thirdRunLoop, 'callbacks coalesced into same run loop'); }, 20); diff --git a/packages/ember-metal/tests/run_loop/once_test.js b/packages/ember-metal/tests/run_loop/once_test.js index f6509e61fed..8adbdaf91ab 100644 --- a/packages/ember-metal/tests/run_loop/once_test.js +++ b/packages/ember-metal/tests/run_loop/once_test.js @@ -3,9 +3,9 @@ import run from 'ember-metal/run_loop'; QUnit.module('system/run_loop/once_test'); QUnit.test('calling invokeOnce more than once invokes only once', function() { - var count = 0; - run(function() { - var F = function() { count++; }; + let count = 0; + run(() => { + function F() { count++; } run.once(F); run.once(F); run.once(F); @@ -15,10 +15,10 @@ QUnit.test('calling invokeOnce more than once invokes only once', function() { }); QUnit.test('should differentiate based on target', function() { - var A = { count: 0 }; - var B = { count: 0 }; - run(function() { - var F = function() { this.count++; }; + let A = { count: 0 }; + let B = { count: 0 }; + run(() => { + function F() { this.count++; } run.once(A, F); run.once(B, F); run.once(A, F); @@ -31,10 +31,11 @@ QUnit.test('should differentiate based on target', function() { QUnit.test('should ignore other arguments - replacing previous ones', function() { - var A = { count: 0 }; - var B = { count: 0 }; - run(function() { - var F = function(amt) { this.count += amt; }; + let A = { count: 0 }; + let B = { count: 0 }; + + run(() => { + function F(amt) { this.count += amt; } run.once(A, F, 10); run.once(B, F, 20); run.once(A, F, 30); @@ -46,10 +47,8 @@ QUnit.test('should ignore other arguments - replacing previous ones', function() }); QUnit.test('should be inside of a runloop when running', function() { - run(function() { - run.once(function() { - ok(!!run.currentRunLoop, 'should have a runloop'); - }); + run(() => { + run.once(() => ok(!!run.currentRunLoop, 'should have a runloop')); }); }); diff --git a/packages/ember-metal/tests/run_loop/run_bind_test.js b/packages/ember-metal/tests/run_loop/run_bind_test.js index e48f0037033..cae45334e89 100644 --- a/packages/ember-metal/tests/run_loop/run_bind_test.js +++ b/packages/ember-metal/tests/run_loop/run_bind_test.js @@ -5,7 +5,7 @@ QUnit.module('system/run_loop/run_bind_test'); QUnit.test('Ember.run.bind builds a run-loop wrapped callback handler', function() { expect(3); - var obj = { + let obj = { value: 0, increment(increment) { ok(run.currentRunLoop, 'expected a run-loop'); @@ -13,7 +13,7 @@ QUnit.test('Ember.run.bind builds a run-loop wrapped callback handler', function } }; - var proxiedFunction = run.bind(obj, obj.increment, 1); + let proxiedFunction = run.bind(obj, obj.increment, 1); equal(proxiedFunction(), 1); equal(obj.value, 1); }); @@ -21,16 +21,16 @@ QUnit.test('Ember.run.bind builds a run-loop wrapped callback handler', function QUnit.test('Ember.run.bind keeps the async callback arguments', function() { expect(4); - var asyncCallback = function(increment, increment2, increment3) { + function asyncCallback(increment, increment2, increment3) { ok(run.currentRunLoop, 'expected a run-loop'); equal(increment, 1); equal(increment2, 2); equal(increment3, 3); - }; + } - var asyncFunction = function(fn) { + function asyncFunction(fn) { fn(2, 3); - }; + } asyncFunction(run.bind(asyncCallback, asyncCallback, 1)); }); diff --git a/packages/ember-metal/tests/run_loop/run_test.js b/packages/ember-metal/tests/run_loop/run_test.js index e4da70af3fe..20c8c8b37e2 100644 --- a/packages/ember-metal/tests/run_loop/run_test.js +++ b/packages/ember-metal/tests/run_loop/run_test.js @@ -3,13 +3,13 @@ import run from 'ember-metal/run_loop'; QUnit.module('system/run_loop/run_test'); QUnit.test('Ember.run invokes passed function, returning value', function() { - var obj = { + let obj = { foo() { return [this.bar, 'FOO']; }, bar: 'BAR', checkArgs(arg1, arg2) { return [arg1, this.bar, arg2]; } }; - equal(run(function() { return 'FOO'; }), 'FOO', 'pass function only'); + equal(run(() => 'FOO'), 'FOO', 'pass function only'); deepEqual(run(obj, obj.foo), ['BAR', 'FOO'], 'pass obj and obj.method'); deepEqual(run(obj, 'foo'), ['BAR', 'FOO'], 'pass obj and "method"'); deepEqual(run(obj, obj.checkArgs, 'hello', 'world'), ['hello', 'BAR', 'world'], 'pass obj, obj.method, and extra arguments'); diff --git a/packages/ember-metal/tests/run_loop/schedule_test.js b/packages/ember-metal/tests/run_loop/schedule_test.js index 87f53a4c4a3..f39dcf0b984 100644 --- a/packages/ember-metal/tests/run_loop/schedule_test.js +++ b/packages/ember-metal/tests/run_loop/schedule_test.js @@ -3,11 +3,11 @@ import run from 'ember-metal/run_loop'; QUnit.module('system/run_loop/schedule_test'); QUnit.test('scheduling item in queue should defer until finished', function() { - var cnt = 0; + let cnt = 0; - run(function() { - run.schedule('actions', function() { cnt++; }); - run.schedule('actions', function() { cnt++; }); + run(() => { + run.schedule('actions', () => cnt++); + run.schedule('actions', () => cnt++); equal(cnt, 0, 'should not run action yet'); }); @@ -15,14 +15,14 @@ QUnit.test('scheduling item in queue should defer until finished', function() { }); QUnit.test('nested runs should queue each phase independently', function() { - var cnt = 0; + let cnt = 0; - run(function() { - run.schedule('actions', function() { cnt++; }); + run(() => { + run.schedule('actions', () => cnt++); equal(cnt, 0, 'should not run action yet'); - run(function() { - run.schedule('actions', function() { cnt++; }); + run(() => { + run.schedule('actions', () => cnt++); }); equal(cnt, 1, 'should not run action yet'); }); @@ -31,31 +31,33 @@ QUnit.test('nested runs should queue each phase independently', function() { }); QUnit.test('prior queues should be flushed before moving on to next queue', function() { - var order = []; + let order = []; - run(function() { - var runLoop = run.currentRunLoop; + run(() => { + let runLoop = run.currentRunLoop; ok(runLoop, 'run loop present'); - run.schedule('sync', function() { + run.schedule('sync', () => { order.push('sync'); equal(runLoop, run.currentRunLoop, 'same run loop used'); }); - run.schedule('actions', function() { + + run.schedule('actions', () => { order.push('actions'); equal(runLoop, run.currentRunLoop, 'same run loop used'); - run.schedule('actions', function() { + run.schedule('actions', () => { order.push('actions'); equal(runLoop, run.currentRunLoop, 'same run loop used'); }); - run.schedule('sync', function() { + run.schedule('sync', () => { order.push('sync'); equal(runLoop, run.currentRunLoop, 'same run loop used'); }); }); - run.schedule('destroy', function() { + + run.schedule('destroy', () => { order.push('destroy'); equal(runLoop, run.currentRunLoop, 'same run loop used'); }); @@ -65,12 +67,8 @@ QUnit.test('prior queues should be flushed before moving on to next queue', func }); QUnit.test('makes sure it does not trigger an autorun during testing', function() { - expectAssertion(function() { - run.schedule('actions', function() {}); - }, /wrap any code with asynchronous side-effects in a run/); + expectAssertion(() => run.schedule('actions', () => {}), /wrap any code with asynchronous side-effects in a run/); // make sure not just the first violation is asserted. - expectAssertion(function() { - run.schedule('actions', function() {}); - }, /wrap any code with asynchronous side-effects in a run/); + expectAssertion(() => run.schedule('actions', () => {}), /wrap any code with asynchronous side-effects in a run/); }); diff --git a/packages/ember-metal/tests/run_loop/sync_test.js b/packages/ember-metal/tests/run_loop/sync_test.js index 188b41d02f2..b48fdf28004 100644 --- a/packages/ember-metal/tests/run_loop/sync_test.js +++ b/packages/ember-metal/tests/run_loop/sync_test.js @@ -3,9 +3,9 @@ import run from 'ember-metal/run_loop'; QUnit.module('system/run_loop/sync_test'); QUnit.test('sync() will immediately flush the sync queue only', function() { - var cnt = 0; + let cnt = 0; - run(function() { + run(() => { function cntup() { cnt++; } function syncfunc() { diff --git a/packages/ember-metal/tests/run_loop/unwind_test.js b/packages/ember-metal/tests/run_loop/unwind_test.js index e4a1a250a45..8b9bd07fdbb 100644 --- a/packages/ember-metal/tests/run_loop/unwind_test.js +++ b/packages/ember-metal/tests/run_loop/unwind_test.js @@ -4,10 +4,10 @@ import EmberError from 'ember-metal/error'; QUnit.module('system/run_loop/unwind_test'); QUnit.test('RunLoop unwinds despite unhandled exception', function() { - var initialRunLoop = run.currentRunLoop; + let initialRunLoop = run.currentRunLoop; - throws(function() { - run(function() { + throws(() => { + run(() => { run.schedule('actions', function() { throw new EmberError('boom!'); }); }); }, Error, 'boom!'); @@ -25,7 +25,7 @@ QUnit.test('RunLoop unwinds despite unhandled exception', function() { QUnit.test('run unwinds despite unhandled exception', function() { var initialRunLoop = run.currentRunLoop; - throws(function() { + throws(() => { run(function() { throw new EmberError('boom!'); }); diff --git a/packages/ember-metal/tests/utils/can_invoke_test.js b/packages/ember-metal/tests/utils/can_invoke_test.js index 6fb9fa94f98..5f4003f3fd0 100644 --- a/packages/ember-metal/tests/utils/can_invoke_test.js +++ b/packages/ember-metal/tests/utils/can_invoke_test.js @@ -1,6 +1,6 @@ import { canInvoke } from 'ember-metal/utils'; -var obj; +let obj; QUnit.module('Ember.canInvoke', { setup() { diff --git a/packages/ember-metal/tests/utils/generate_guid_test.js b/packages/ember-metal/tests/utils/generate_guid_test.js index 79a0ec86656..7a3057a15d4 100644 --- a/packages/ember-metal/tests/utils/generate_guid_test.js +++ b/packages/ember-metal/tests/utils/generate_guid_test.js @@ -3,7 +3,7 @@ import { generateGuid } from 'ember-metal/utils'; QUnit.module('Ember.generateGuid'); QUnit.test('Prefix', function() { - var a = {}; + let a = {}; ok(generateGuid(a, 'tyrell').indexOf('tyrell') > -1, 'guid can be prefixed'); }); diff --git a/packages/ember-metal/tests/utils/guid_for_test.js b/packages/ember-metal/tests/utils/guid_for_test.js index fa4d62b9a16..da9aceff417 100644 --- a/packages/ember-metal/tests/utils/guid_for_test.js +++ b/packages/ember-metal/tests/utils/guid_for_test.js @@ -4,22 +4,22 @@ import { QUnit.module('guidFor'); -var sameGuid = function(a, b, message) { +function sameGuid(a, b, message) { equal(guidFor(a), guidFor(b), message); -}; +} -var diffGuid = function(a, b, message) { +function diffGuid(a, b, message) { ok(guidFor(a) !== guidFor(b), message); -}; +} -var nanGuid = function(obj) { - var type = typeof obj; +function nanGuid(obj) { + let type = typeof obj; ok(isNaN(parseInt(guidFor(obj), 0)), 'guids for ' + type + 'don\'t parse to numbers'); -}; +} QUnit.test('Object', function() { - var a = {}; - var b = {}; + let a = {}; + let b = {}; sameGuid(a, a, 'same object always yields same guid'); diffGuid(a, b, 'different objects yield different guids'); @@ -27,9 +27,9 @@ QUnit.test('Object', function() { }); QUnit.test('strings', function() { - var a = 'string A'; - var aprime = 'string A'; - var b = 'String B'; + let a = 'string A'; + let aprime = 'string A'; + let b = 'String B'; sameGuid(a, a, 'same string always yields same guid'); sameGuid(a, aprime, 'identical strings always yield the same guid'); @@ -38,9 +38,9 @@ QUnit.test('strings', function() { }); QUnit.test('numbers', function() { - var a = 23; - var aprime = 23; - var b = 34; + let a = 23; + let aprime = 23; + let b = 34; sameGuid(a, a, 'same numbers always yields same guid'); sameGuid(a, aprime, 'identical numbers always yield the same guid'); @@ -49,9 +49,9 @@ QUnit.test('numbers', function() { }); QUnit.test('numbers', function() { - var a = true; - var aprime = true; - var b = false; + let a = true; + let aprime = true; + let b = false; sameGuid(a, a, 'same booleans always yields same guid'); sameGuid(a, aprime, 'identical booleans always yield the same guid'); @@ -61,9 +61,9 @@ QUnit.test('numbers', function() { }); QUnit.test('null and undefined', function() { - var a = null; - var aprime = null; - var b; + let a = null; + let aprime = null; + let b; sameGuid(a, a, 'null always returns the same guid'); sameGuid(b, b, 'undefined always returns the same guid'); @@ -74,9 +74,9 @@ QUnit.test('null and undefined', function() { }); QUnit.test('arrays', function() { - var a = ['a', 'b', 'c']; - var aprime = ['a', 'b', 'c']; - var b = ['1', '2', '3']; + let a = ['a', 'b', 'c']; + let aprime = ['a', 'b', 'c']; + let b = ['1', '2', '3']; sameGuid(a, a, 'same instance always yields same guid'); diffGuid(a, aprime, 'identical arrays always yield the same guid'); diff --git a/packages/ember-metal/tests/utils/try_invoke_test.js b/packages/ember-metal/tests/utils/try_invoke_test.js index 9e31733970a..55644636976 100644 --- a/packages/ember-metal/tests/utils/try_invoke_test.js +++ b/packages/ember-metal/tests/utils/try_invoke_test.js @@ -1,6 +1,6 @@ import { tryInvoke } from 'ember-metal/utils'; -var obj; +let obj; QUnit.module('Ember.tryInvoke', { setup() { diff --git a/packages/ember-metal/tests/watching/is_watching_test.js b/packages/ember-metal/tests/watching/is_watching_test.js index e49ce7c7373..f0020d8fba8 100644 --- a/packages/ember-metal/tests/watching/is_watching_test.js +++ b/packages/ember-metal/tests/watching/is_watching_test.js @@ -13,10 +13,9 @@ import { isWatching } from 'ember-metal/watching'; QUnit.module('isWatching'); -function testObserver(setup, teardown, key) { - var obj = {}; - var fn = function() {}; - key = key || 'foo'; +function testObserver(setup, teardown, key = 'key') { + let obj = {}; + function fn() {} equal(isWatching(obj, key), false, 'precond - isWatching is false by default'); setup(obj, key, fn); @@ -26,21 +25,17 @@ function testObserver(setup, teardown, key) { } QUnit.test('isWatching is true for regular local observers', function() { - testObserver(function(obj, key, fn) { + testObserver((obj, key, fn) => { Mixin.create({ didChange: observer(key, fn) }).apply(obj); - }, function(obj, key, fn) { - removeObserver(obj, key, obj, fn); - }); + }, (obj, key, fn) => removeObserver(obj, key, obj, fn)); }); QUnit.test('isWatching is true for nonlocal observers', function() { - testObserver(function(obj, key, fn) { + testObserver((obj, key, fn) => { addObserver(obj, key, obj, fn); - }, function(obj, key, fn) { - removeObserver(obj, key, obj, fn); - }); + }, (obj, key, fn) => removeObserver(obj, key, obj, fn)); }); QUnit.test('isWatching is true for chained observers', function() { @@ -52,30 +47,24 @@ QUnit.test('isWatching is true for chained observers', function() { }); QUnit.test('isWatching is true for computed properties', function() { - testObserver(function(obj, key, fn) { + testObserver((obj, key, fn) => { defineProperty(obj, 'computed', computed(fn).property(key)); get(obj, 'computed'); - }, function(obj, key, fn) { - defineProperty(obj, 'computed', null); - }); + }, (obj, key, fn) => defineProperty(obj, 'computed', null)); }); QUnit.test('isWatching is true for chained computed properties', function() { - testObserver(function(obj, key, fn) { + testObserver((obj, key, fn) => { defineProperty(obj, 'computed', computed(fn).property(key + '.bar')); get(obj, 'computed'); - }, function(obj, key, fn) { - defineProperty(obj, 'computed', null); - }); + }, (obj, key, fn) => defineProperty(obj, 'computed', null)); }); // can't watch length on Array - it is special... // But you should be able to watch a length property of an object QUnit.test('isWatching is true for \'length\' property on object', function() { - testObserver(function(obj, key, fn) { + testObserver((obj, key, fn) => { defineProperty(obj, 'length', null, '26.2 miles'); addObserver(obj, 'length', obj, fn); - }, function(obj, key, fn) { - removeObserver(obj, 'length', obj, fn); - }, 'length'); + }, (obj, key, fn) => removeObserver(obj, 'length', obj, fn), 'length'); }); diff --git a/packages/ember-metal/tests/watching/unwatch_test.js b/packages/ember-metal/tests/watching/unwatch_test.js index 94eb7d76c34..4ec9b41657a 100644 --- a/packages/ember-metal/tests/watching/unwatch_test.js +++ b/packages/ember-metal/tests/watching/unwatch_test.js @@ -8,7 +8,7 @@ import { addListener } from 'ember-metal/events'; import { computed } from 'ember-metal/computed'; import { set } from 'ember-metal/property_set'; -var willCount, didCount; +let willCount, didCount; QUnit.module('unwatch', { setup() { @@ -17,21 +17,18 @@ QUnit.module('unwatch', { }); function addListeners(obj, keyPath) { - addListener(obj, keyPath + ':before', function() { - willCount++; - }); - addListener(obj, keyPath + ':change', function() { - didCount++; - }); + addListener(obj, keyPath + ':before', () => willCount++); + addListener(obj, keyPath + ':change', () => didCount++); } testBoth('unwatching a computed property - regular get/set', function(get, set) { - var obj = {}; + let obj = {}; + defineProperty(obj, 'foo', computed({ - get: function() { + get() { return this.__foo; }, - set: function(keyName, value) { + set(keyName, value) { this.__foo = value; return this.__foo; } @@ -52,7 +49,7 @@ testBoth('unwatching a computed property - regular get/set', function(get, set) testBoth('unwatching a regular property - regular get/set', function(get, set) { - var obj = { foo: 'BIFF' }; + let obj = { foo: 'BIFF' }; addListeners(obj, 'foo'); watch(obj, 'foo'); @@ -68,7 +65,7 @@ testBoth('unwatching a regular property - regular get/set', function(get, set) { }); QUnit.test('unwatching should be nested', function() { - var obj = { foo: 'BIFF' }; + let obj = { foo: 'BIFF' }; addListeners(obj, 'foo'); watch(obj, 'foo'); @@ -91,7 +88,7 @@ QUnit.test('unwatching should be nested', function() { }); testBoth('unwatching "length" property on an object', function(get, set) { - var obj = { foo: 'RUN' }; + let obj = { foo: 'RUN' }; addListeners(obj, 'length'); // Can watch length when it is undefined @@ -109,7 +106,7 @@ testBoth('unwatching "length" property on an object', function(get, set) { }); testBoth('unwatching should not destroy non MANDATORY_SETTER descriptor', function(get, set) { - var obj = { get foo() { return 'RUN'; } }; + let obj = { get foo() { return 'RUN'; } }; equal(obj.foo, 'RUN', 'obj.foo'); watch(obj, 'foo'); diff --git a/packages/ember-metal/tests/watching/watch_test.js b/packages/ember-metal/tests/watching/watch_test.js index fa57fa27b6d..e81821466d9 100644 --- a/packages/ember-metal/tests/watching/watch_test.js +++ b/packages/ember-metal/tests/watching/watch_test.js @@ -12,7 +12,7 @@ import { destroy } from 'ember-metal/watching'; -var willCount, didCount, +let willCount, didCount, willKeys, didKeys, originalLookup, lookup; @@ -43,12 +43,12 @@ function addListeners(obj, keyPath) { } testBoth('watching a computed property', function(get, set) { - var obj = {}; + let obj = {}; defineProperty(obj, 'foo', computed({ - get: function() { + get() { return this.__foo; }, - set: function(keyName, value) { + set(keyName, value) { if (value !== undefined) { this.__foo = value; } @@ -64,7 +64,7 @@ testBoth('watching a computed property', function(get, set) { }); testBoth('watching a regular defined property', function(get, set) { - var obj = { foo: 'baz' }; + let obj = { foo: 'baz' }; addListeners(obj, 'foo'); watch(obj, 'foo'); @@ -79,7 +79,7 @@ testBoth('watching a regular defined property', function(get, set) { }); testBoth('watching a regular undefined property', function(get, set) { - var obj = { }; + let obj = { }; addListeners(obj, 'foo'); watch(obj, 'foo'); @@ -96,8 +96,8 @@ testBoth('watching a regular undefined property', function(get, set) { }); testBoth('watches should inherit', function(get, set) { - var obj = { foo: 'baz' }; - var objB = Object.create(obj); + let obj = { foo: 'baz' }; + let objB = Object.create(obj); addListeners(obj, 'foo'); watch(obj, 'foo'); @@ -110,7 +110,7 @@ testBoth('watches should inherit', function(get, set) { }); QUnit.test('watching an object THEN defining it should work also', function() { - var obj = {}; + let obj = {}; addListeners(obj, 'foo'); watch(obj, 'foo'); @@ -124,8 +124,8 @@ QUnit.test('watching an object THEN defining it should work also', function() { }); QUnit.test('watching a chain then defining the property', function () { - var obj = {}; - var foo = { bar: 'bar' }; + let obj = {}; + let foo = { bar: 'bar' }; addListeners(obj, 'foo.bar'); addListeners(foo, 'bar'); @@ -141,9 +141,9 @@ QUnit.test('watching a chain then defining the property', function () { }); QUnit.test('watching a chain then defining the nested property', function () { - var bar = {}; - var obj = { foo: bar }; - var baz = { baz: 'baz' }; + let bar = {}; + let obj = { foo: bar }; + let baz = { baz: 'baz' }; addListeners(obj, 'foo.bar.baz'); addListeners(baz, 'baz'); @@ -159,12 +159,12 @@ QUnit.test('watching a chain then defining the nested property', function () { }); testBoth('watching an object value then unwatching should restore old value', function(get, set) { - var obj = { foo: { bar: { baz: { biff: 'BIFF' } } } }; + let obj = { foo: { bar: { baz: { biff: 'BIFF' } } } }; addListeners(obj, 'foo.bar.baz.biff'); watch(obj, 'foo.bar.baz.biff'); - var foo = get(obj, 'foo'); + let foo = get(obj, 'foo'); equal(get(get(get(foo, 'bar'), 'baz'), 'biff'), 'BIFF', 'biff should exist'); unwatch(obj, 'foo.bar.baz.biff'); @@ -172,15 +172,15 @@ testBoth('watching an object value then unwatching should restore old value', fu }); QUnit.test('when watching another object, destroy should remove chain watchers from the other object', function() { - var objA = {}; - var objB = { foo: 'bar' }; + let objA = {}; + let objB = { foo: 'bar' }; objA.b = objB; addListeners(objA, 'b.foo'); watch(objA, 'b.foo'); - var meta_objB = meta(objB); - var chainNode = meta(objA).readableChains()._chains.b._chains.foo; + let meta_objB = meta(objB); + let chainNode = meta(objA).readableChains()._chains.b._chains.foo; equal(meta_objB.peekWatching('foo'), 1, 'should be watching foo'); equal(meta_objB.readableChainWatchers().has('foo', chainNode), true, 'should have chain watcher'); @@ -194,7 +194,7 @@ QUnit.test('when watching another object, destroy should remove chain watchers f // TESTS for length property testBoth('watching "length" property on an object', function(get, set) { - var obj = { length: '26.2 miles' }; + let obj = { length: '26.2 miles' }; addListeners(obj, 'length'); watch(obj, 'length'); @@ -209,7 +209,7 @@ testBoth('watching "length" property on an object', function(get, set) { }); testBoth('watching "length" property on an array', function(get, set) { - var arr = []; + let arr = []; addListeners(arr, 'length'); watch(arr, 'length'); @@ -224,8 +224,8 @@ testBoth('watching "length" property on an array', function(get, set) { }); testBoth('watch + ES5 getter', function(get) { - var parent = { b: 1 }; - var child = { + let parent = { b: 1 }; + let child = { get b() { return parent.b; } @@ -244,7 +244,7 @@ testBoth('watch + ES5 getter', function(get) { }); testBoth('watch + Ember.set + no-descriptor', function(get, set) { - var child = { }; + let child = { }; equal(child.b, undefined, 'child.b '); equal(get(child, 'b'), undefined, 'Ember.get(child, "b")'); diff --git a/packages/ember-metal/tests/weak_map_test.js b/packages/ember-metal/tests/weak_map_test.js index 1452e600488..d9d81db25a5 100644 --- a/packages/ember-metal/tests/weak_map_test.js +++ b/packages/ember-metal/tests/weak_map_test.js @@ -56,25 +56,11 @@ QUnit.test('invoking the WeakMap constructor with arguments is not supported at QUnit.test('that error is thrown when using a primitive key', function(assert) { let map = new WeakMap(); - expectAssertion(function() { - map.set('a', 1); - }, /Uncaught TypeError: Invalid value used as weak map key/); - - expectAssertion(function() { - map.set(1, 1); - }, /Uncaught TypeError: Invalid value used as weak map key/); - - expectAssertion(function() { - map.set(true, 1); - }, /Uncaught TypeError: Invalid value used as weak map key/); - - expectAssertion(function() { - map.set(null, 1); - }, /Uncaught TypeError: Invalid value used as weak map key/); - - expectAssertion(function() { - map.set(undefined, 1); - }, /Uncaught TypeError: Invalid value used as weak map key/); + expectAssertion(() => map.set('a', 1), /Uncaught TypeError: Invalid value used as weak map key/); + expectAssertion(() => map.set(1, 1), /Uncaught TypeError: Invalid value used as weak map key/); + expectAssertion(() => map.set(true, 1), /Uncaught TypeError: Invalid value used as weak map key/); + expectAssertion(() => map.set(null, 1), /Uncaught TypeError: Invalid value used as weak map key/); + expectAssertion(() => map.set(undefined, 1), /Uncaught TypeError: Invalid value used as weak map key/); }); QUnit.test('that .has and .delete work as expected', function(assert) { diff --git a/packages/ember-routing/lib/ext/controller.js b/packages/ember-routing/lib/ext/controller.js index 206645d7ea6..74c295b6a07 100644 --- a/packages/ember-routing/lib/ext/controller.js +++ b/packages/ember-routing/lib/ext/controller.js @@ -31,10 +31,10 @@ ControllerMixin.reopen({ @private */ _qpChanged(controller, _prop) { - var prop = _prop.substr(0, _prop.length - 3); + let prop = _prop.substr(0, _prop.length - 3); - var delegate = controller._qpDelegate; - var value = get(controller, prop); + let delegate = controller._qpDelegate; + let value = get(controller, prop); delegate(prop, value); }, @@ -112,8 +112,8 @@ ControllerMixin.reopen({ */ transitionToRoute() { // target may be either another controller or a router - var target = get(this, 'target'); - var method = target.transitionToRoute || target.transitionTo; + let target = get(this, 'target'); + let method = target.transitionToRoute || target.transitionTo; return method.apply(target, arguments); }, @@ -175,8 +175,8 @@ ControllerMixin.reopen({ */ replaceRoute() { // target may be either another controller or a router - var target = get(this, 'target'); - var method = target.replaceRoute || target.replaceWith; + let target = get(this, 'target'); + let method = target.replaceRoute || target.replaceWith; return method.apply(target, arguments); } }); diff --git a/packages/ember-routing/lib/location/api.js b/packages/ember-routing/lib/location/api.js index 6595b879cc0..667977c5866 100644 --- a/packages/ember-routing/lib/location/api.js +++ b/packages/ember-routing/lib/location/api.js @@ -166,10 +166,10 @@ export default { @private */ create(options) { - var implementation = options && options.implementation; + let implementation = options && options.implementation; assert('Ember.Location.create: you must specify a \'implementation\' option', !!implementation); - var implementationClass = this.implementations[implementation]; + let implementationClass = this.implementations[implementation]; assert(`Ember.Location.create: ${implementation} is not a valid implementation`, !!implementationClass); return implementationClass.create(...arguments); diff --git a/packages/ember-routing/lib/location/auto_location.js b/packages/ember-routing/lib/location/auto_location.js index 1451ce991b1..e2586909d68 100644 --- a/packages/ember-routing/lib/location/auto_location.js +++ b/packages/ember-routing/lib/location/auto_location.js @@ -115,12 +115,12 @@ export default EmberObject.extend({ @private */ detect() { - var rootURL = this.rootURL; + let rootURL = this.rootURL; assert('rootURL must end with a trailing forward slash e.g. "/app/"', rootURL.charAt(rootURL.length - 1) === '/'); - var implementation = detectImplementation({ + let implementation = detectImplementation({ location: this.location, history: this.history, userAgent: this.userAgent, @@ -134,7 +134,7 @@ export default EmberObject.extend({ implementation = 'none'; } - var concrete = getOwner(this).lookup(`location:${implementation}`); + let concrete = getOwner(this).lookup(`location:${implementation}`); set(concrete, 'rootURL', rootURL); assert(`Could not find location '${implementation}'.`, !!concrete); @@ -150,7 +150,7 @@ export default EmberObject.extend({ formatURL: delegateToConcreteImplementation('formatURL'), willDestroy() { - var concreteImplementation = get(this, 'concreteImplementation'); + let concreteImplementation = get(this, 'concreteImplementation'); if (concreteImplementation) { concreteImplementation.destroy(); @@ -160,7 +160,7 @@ export default EmberObject.extend({ function delegateToConcreteImplementation(methodName) { return function(...args) { - var concreteImplementation = get(this, 'concreteImplementation'); + let concreteImplementation = get(this, 'concreteImplementation'); assert('AutoLocation\'s detect() method should be called before calling any other hooks.', !!concreteImplementation); return tryInvoke(concreteImplementation, methodName, args); }; @@ -181,19 +181,19 @@ function delegateToConcreteImplementation(methodName) { */ function detectImplementation(options) { - var location = options.location; - var userAgent = options.userAgent; - var history = options.history; - var documentMode = options.documentMode; - var global = options.global; - var rootURL = options.rootURL; + let location = options.location; + let userAgent = options.userAgent; + let history = options.history; + let documentMode = options.documentMode; + let global = options.global; + let rootURL = options.rootURL; - var implementation = 'none'; - var cancelRouterSetup = false; - var currentPath = getFullPath(location); + let implementation = 'none'; + let cancelRouterSetup = false; + let currentPath = getFullPath(location); if (supportsHistory(userAgent, history)) { - var historyPath = getHistoryPath(rootURL, location); + let historyPath = getHistoryPath(rootURL, location); // If the browser supports history and we have a history path, we can use // the history location with no redirects. @@ -209,7 +209,7 @@ function detectImplementation(options) { } } } else if (supportsHashChange(documentMode, global)) { - var hashPath = getHashPath(rootURL, location); + let hashPath = getHashPath(rootURL, location); // Be sure we're using a hashed path, otherwise let's switch over it to so // we start off clean and consistent. We'll count an index path with no @@ -239,11 +239,11 @@ function detectImplementation(options) { starts off as a hashed URL) */ export function getHistoryPath(rootURL, location) { - var path = getPath(location); - var hash = getHash(location); - var query = getQuery(location); - var rootURLIndex = path.indexOf(rootURL); - var routeHash, hashParts; + let path = getPath(location); + let hash = getHash(location); + let query = getQuery(location); + let rootURLIndex = path.indexOf(rootURL); + let routeHash, hashParts; assert(`Path ${path} does not start with the provided rootURL ${rootURL}`, rootURLIndex === 0); @@ -284,9 +284,9 @@ export function getHistoryPath(rootURL, location) { @method _getHashPath */ export function getHashPath(rootURL, location) { - var path = rootURL; - var historyPath = getHistoryPath(rootURL, location); - var routePath = historyPath.substr(rootURL.length); + let path = rootURL; + let historyPath = getHistoryPath(rootURL, location); + let routePath = historyPath.substr(rootURL.length); if (routePath !== '') { if (routePath.charAt(0) !== '/') { diff --git a/packages/ember-routing/lib/location/hash_location.js b/packages/ember-routing/lib/location/hash_location.js index e13c614634a..240430e3098 100644 --- a/packages/ember-routing/lib/location/hash_location.js +++ b/packages/ember-routing/lib/location/hash_location.js @@ -51,8 +51,8 @@ export default EmberObject.extend({ @method getURL */ getURL() { - var originalPath = this.getHash().substr(1); - var outPath = originalPath; + let originalPath = this.getHash().substr(1); + let outPath = originalPath; if (outPath.charAt(0) !== '/') { outPath = '/'; @@ -106,11 +106,11 @@ export default EmberObject.extend({ @param callback {Function} */ onUpdateURL(callback) { - var guid = guidFor(this); + let guid = guidFor(this); jQuery(window).on(`hashchange.ember-location-${guid}`, () => { run(() => { - var path = this.getURL(); + let path = this.getURL(); if (get(this, 'lastSetURL') === path) { return; } set(this, 'lastSetURL', null); @@ -142,7 +142,7 @@ export default EmberObject.extend({ @method willDestroy */ willDestroy() { - var guid = guidFor(this); + let guid = guidFor(this); jQuery(window).off(`hashchange.ember-location-${guid}`); } diff --git a/packages/ember-routing/lib/location/history_location.js b/packages/ember-routing/lib/location/history_location.js index eb0ed1e8d69..ab886cac431 100644 --- a/packages/ember-routing/lib/location/history_location.js +++ b/packages/ember-routing/lib/location/history_location.js @@ -11,7 +11,7 @@ import jQuery from 'ember-views/system/jquery'; @submodule ember-routing */ -var popstateFired = false; +let popstateFired = false; /** Ember.HistoryLocation implements the location API using the browser's @@ -37,7 +37,7 @@ export default EmberObject.extend({ @method initState */ initState() { - var history = get(this, 'history') || window.history; + let history = get(this, 'history') || window.history; set(this, 'history', history); if (history && 'state' in history) { @@ -64,22 +64,22 @@ export default EmberObject.extend({ @return url {String} */ getURL() { - var location = get(this, 'location'); - var path = location.pathname; + let location = get(this, 'location'); + let path = location.pathname; - var rootURL = get(this, 'rootURL'); - var baseURL = get(this, 'baseURL'); + let rootURL = get(this, 'rootURL'); + let baseURL = get(this, 'baseURL'); // remove trailing slashes if they exists rootURL = rootURL.replace(/\/$/, ''); baseURL = baseURL.replace(/\/$/, ''); // remove baseURL and rootURL from start of path - var url = path + let url = path .replace(new RegExp('^' + baseURL), '') .replace(new RegExp('^' + rootURL), ''); - var search = location.search || ''; + let search = location.search || ''; url += search; url += this.getHash(); @@ -94,7 +94,7 @@ export default EmberObject.extend({ @param path {String} */ setURL(path) { - var state = this.getState(); + let state = this.getState(); path = this.formatURL(path); if (!state || state.path !== path) { @@ -111,7 +111,7 @@ export default EmberObject.extend({ @param path {String} */ replaceURL(path) { - var state = this.getState(); + let state = this.getState(); path = this.formatURL(path); if (!state || state.path !== path) { @@ -145,7 +145,7 @@ export default EmberObject.extend({ @param path {String} */ pushState(path) { - var state = { path: path }; + let state = { path: path }; get(this, 'history').pushState(state, null, path); @@ -163,7 +163,7 @@ export default EmberObject.extend({ @param path {String} */ replaceState(path) { - var state = { path: path }; + let state = { path: path }; get(this, 'history').replaceState(state, null, path); this._historyState = state; @@ -181,7 +181,7 @@ export default EmberObject.extend({ @param callback {Function} */ onUpdateURL(callback) { - var guid = guidFor(this); + let guid = guidFor(this); jQuery(window).on(`popstate.ember-location-${guid}`, (e) => { // Ignore initial page load popstate event in Chrome @@ -202,8 +202,8 @@ export default EmberObject.extend({ @return formatted url {String} */ formatURL(url) { - var rootURL = get(this, 'rootURL'); - var baseURL = get(this, 'baseURL'); + let rootURL = get(this, 'rootURL'); + let baseURL = get(this, 'baseURL'); if (url !== '') { // remove trailing slashes if they exists @@ -225,7 +225,7 @@ export default EmberObject.extend({ @method willDestroy */ willDestroy() { - var guid = guidFor(this); + let guid = guidFor(this); jQuery(window).off(`popstate.ember-location-${guid}`); }, diff --git a/packages/ember-routing/lib/services/routing.js b/packages/ember-routing/lib/services/routing.js index 036104787f5..bffc16cec90 100644 --- a/packages/ember-routing/lib/services/routing.js +++ b/packages/ember-routing/lib/services/routing.js @@ -38,9 +38,9 @@ export default Service.extend({ }, transitionTo(routeName, models, queryParams, shouldReplace) { - var router = get(this, 'router'); + let router = get(this, 'router'); - var transition = router._doTransition(routeName, models, queryParams); + let transition = router._doTransition(routeName, models, queryParams); if (shouldReplace) { transition.method('replace'); @@ -50,29 +50,29 @@ export default Service.extend({ }, normalizeQueryParams(routeName, models, queryParams) { - var router = get(this, 'router'); + let router = get(this, 'router'); router._prepareQueryParams(routeName, models, queryParams); }, generateURL(routeName, models, queryParams) { - var router = get(this, 'router'); + let router = get(this, 'router'); if (!router.router) { return; } - var visibleQueryParams = {}; + let visibleQueryParams = {}; assign(visibleQueryParams, queryParams); this.normalizeQueryParams(routeName, models, visibleQueryParams); - var args = routeArgs(routeName, models, visibleQueryParams); + let args = routeArgs(routeName, models, visibleQueryParams); return router.generate.apply(router, args); }, isActiveForRoute(contexts, queryParams, routeName, routerState, isCurrentWhenSpecified) { - var router = get(this, 'router'); + let router = get(this, 'router'); - var handlers = router.router.recognizer.handlersFor(routeName); - var leafName = handlers[handlers.length - 1].handler; - var maximumContexts = numberOfContextsAcceptedByHandler(routeName, handlers); + let handlers = router.router.recognizer.handlersFor(routeName); + let leafName = handlers[handlers.length - 1].handler; + let maximumContexts = numberOfContextsAcceptedByHandler(routeName, handlers); // NOTE: any ugliness in the calculation of activeness is largely // due to the fact that we support automatic normalizing of @@ -93,8 +93,8 @@ export default Service.extend({ }); function numberOfContextsAcceptedByHandler(handler, handlerInfos) { - var req = 0; - for (var i = 0; i < handlerInfos.length; i++) { + let req = 0; + for (let i = 0; i < handlerInfos.length; i++) { req = req + handlerInfos[i].names.length; if (handlerInfos[i].handler === handler) { break; diff --git a/packages/ember-routing/lib/system/cache.js b/packages/ember-routing/lib/system/cache.js index db999b429a0..c0a0ed6197a 100644 --- a/packages/ember-routing/lib/system/cache.js +++ b/packages/ember-routing/lib/system/cache.js @@ -8,23 +8,22 @@ export default EmberObject.extend({ return bucketKey in this.cache; }, stash(bucketKey, key, value) { - var bucket = this.cache[bucketKey]; + let bucket = this.cache[bucketKey]; if (!bucket) { bucket = this.cache[bucketKey] = {}; } bucket[key] = value; }, lookup(bucketKey, prop, defaultValue) { - var cache = this.cache; + let cache = this.cache; if (!(bucketKey in cache)) { return defaultValue; } - var bucket = cache[bucketKey]; + let bucket = cache[bucketKey]; if (prop in bucket) { return bucket[prop]; } else { return defaultValue; } - }, - cache: null + } }); diff --git a/packages/ember-routing/lib/system/dsl.js b/packages/ember-routing/lib/system/dsl.js index d1d5621a4bd..b1b9eb2db6e 100644 --- a/packages/ember-routing/lib/system/dsl.js +++ b/packages/ember-routing/lib/system/dsl.js @@ -22,7 +22,7 @@ export default DSL; DSL.prototype = { route(name, options, callback) { - var dummyErrorRoute = `/_unused_dummy_error_path_route_${name}/:error`; + let dummyErrorRoute = `/_unused_dummy_error_path_route_${name}/:error`; if (arguments.length === 2 && typeof options === 'function') { callback = options; options = {}; @@ -51,8 +51,8 @@ DSL.prototype = { } if (callback) { - var fullName = getFullName(this, name, options.resetNamespace); - var dsl = new DSL(fullName, this.options); + let fullName = getFullName(this, name, options.resetNamespace); + let dsl = new DSL(fullName, this.options); createRoute(dsl, 'loading'); createRoute(dsl, 'error', { path: dummyErrorRoute }); @@ -66,7 +66,7 @@ DSL.prototype = { }, push(url, name, callback) { - var parts = name.split('.'); + let parts = name.split('.'); if (url === '' || url === '/' || parts[parts.length - 1] === 'index') { this.explicitIndex = true; } this.matches.push([url, name, callback]); @@ -88,15 +88,15 @@ DSL.prototype = { }, generate() { - var dslMatches = this.matches; + let dslMatches = this.matches; if (!this.explicitIndex) { this.route('index', { path: '/' }); } - return function(match) { - for (var i = 0; i < dslMatches.length; i++) { - var dslMatch = dslMatches[i]; + return match => { + for (let i = 0; i < dslMatches.length; i++) { + let dslMatch = dslMatches[i]; match(dslMatch[0]).to(dslMatch[1], dslMatch[2]); } }; @@ -118,7 +118,7 @@ function getFullName(dsl, name, resetNamespace) { function createRoute(dsl, name, options, callback) { options = options || {}; - var fullName = getFullName(dsl, name, options.resetNamespace); + let fullName = getFullName(dsl, name, options.resetNamespace); if (typeof options.path !== 'string') { options.path = `/${name}`; @@ -128,7 +128,7 @@ function createRoute(dsl, name, options, callback) { } DSL.map = function(callback) { - var dsl = new DSL(); + let dsl = new DSL(); callback.call(dsl); return dsl; }; diff --git a/packages/ember-routing/lib/system/generate_controller.js b/packages/ember-routing/lib/system/generate_controller.js index 39e9728d1d5..79e4551598b 100644 --- a/packages/ember-routing/lib/system/generate_controller.js +++ b/packages/ember-routing/lib/system/generate_controller.js @@ -15,16 +15,14 @@ import { get } from 'ember-metal/property_get'; */ export function generateControllerFactory(owner, controllerName, context) { - var Factory, fullName; - - Factory = owner._lookupFactory('controller:basic').extend({ + let Factory = owner._lookupFactory('controller:basic').extend({ isGenerated: true, toString() { return `(generated ${controllerName} controller)`; } }); - fullName = `controller:${controllerName}`; + let fullName = `controller:${controllerName}`; owner.register(fullName, Factory); @@ -47,8 +45,8 @@ export function generateControllerFactory(owner, controllerName, context) { export default function generateController(owner, controllerName, context) { generateControllerFactory(owner, controllerName, context); - var fullName = `controller:${controllerName}`; - var instance = owner.lookup(fullName); + let fullName = `controller:${controllerName}`; + let instance = owner.lookup(fullName); if (get(instance, 'namespace.LOG_ACTIVE_GENERATION')) { info(`generated -> ${fullName}`, { fullName: fullName }); diff --git a/packages/ember-routing/lib/system/route.js b/packages/ember-routing/lib/system/route.js index fc7c422355a..cca2f3646d2 100644 --- a/packages/ember-routing/lib/system/route.js +++ b/packages/ember-routing/lib/system/route.js @@ -32,7 +32,7 @@ import { import { getOwner } from 'container/owner'; import isEmpty from 'ember-metal/is_empty'; import symbol from 'ember-metal/symbol'; -var slice = Array.prototype.slice; +const { slice } = Array.prototype; function K() { return this; } @@ -40,8 +40,8 @@ function defaultSerialize(model, params) { if (params.length < 1) { return; } if (!model) { return; } - var name = params[0]; - var object = {}; + let name = params[0]; + let object = {}; if (params.length === 1) { if (name in model) { @@ -82,7 +82,7 @@ export function hasDefaultSerialize(route) { @uses Ember.Evented @public */ -var Route = EmberObject.extend(ActionHandler, Evented, { +let Route = EmberObject.extend(ActionHandler, Evented, { /** Configuration hash for this route's queryParams. The possible configuration options and their defaults are as follows @@ -146,12 +146,12 @@ var Route = EmberObject.extend(ActionHandler, Evented, { @property _qp */ _qp: computed(function() { - var controllerProto, combinedQueryParameterConfiguration; + let controllerProto, combinedQueryParameterConfiguration; - var controllerName = this.controllerName || this.routeName; - var definedControllerClass = getOwner(this)._lookupFactory(`controller:${controllerName}`); - var queryParameterConfiguraton = get(this, 'queryParams'); - var hasRouterDefinedQueryParams = !!Object.keys(queryParameterConfiguraton).length; + let controllerName = this.controllerName || this.routeName; + let definedControllerClass = getOwner(this)._lookupFactory(`controller:${controllerName}`); + let queryParameterConfiguraton = get(this, 'queryParams'); + let hasRouterDefinedQueryParams = !!Object.keys(queryParameterConfiguraton).length; if (definedControllerClass) { // the developer has authored a controller class in their application for this route @@ -160,8 +160,8 @@ var Route = EmberObject.extend(ActionHandler, Evented, { // at least `{}` controllerProto = definedControllerClass.proto(); - var controllerDefinedQueryParameterConfiguration = get(controllerProto, 'queryParams'); - var normalizedControllerQueryParameterConfiguration = normalizeControllerQueryParams(controllerDefinedQueryParameterConfiguration); + let controllerDefinedQueryParameterConfiguration = get(controllerProto, 'queryParams'); + let normalizedControllerQueryParameterConfiguration = normalizeControllerQueryParams(controllerDefinedQueryParameterConfiguration); combinedQueryParameterConfiguration = mergeEachQueryParams(normalizedControllerQueryParameterConfiguration, queryParameterConfiguraton); if (isEnabled('ember-routing-route-configured-query-params')) { @@ -172,16 +172,16 @@ var Route = EmberObject.extend(ActionHandler, Evented, { } else if (hasRouterDefinedQueryParams) { // the developer has not defined a controller but *has* supplied route query params. // Generate a class for them so we can later insert default values - var generatedControllerClass = generateControllerFactory(getOwner(this), controllerName); + let generatedControllerClass = generateControllerFactory(getOwner(this), controllerName); controllerProto = generatedControllerClass.proto(); combinedQueryParameterConfiguration = queryParameterConfiguraton; } - var qps = []; - var map = {}; - var propertyNames = []; + let qps = []; + let map = {}; + let propertyNames = []; - for (var propName in combinedQueryParameterConfiguration) { + for (let propName in combinedQueryParameterConfiguration) { if (!combinedQueryParameterConfiguration.hasOwnProperty(propName)) { continue; } // to support the dubious feature of using unknownProperty @@ -191,7 +191,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, { continue; } - var desc = combinedQueryParameterConfiguration[propName]; + let desc = combinedQueryParameterConfiguration[propName]; if (isEnabled('ember-routing-route-configured-query-params')) { // apply default values to controllers @@ -206,25 +206,25 @@ var Route = EmberObject.extend(ActionHandler, Evented, { } } - var scope = desc.scope || 'model'; - var parts; + let scope = desc.scope || 'model'; + let parts; if (scope === 'controller') { parts = []; } - var urlKey = desc.as || this.serializeQueryParamKey(propName); - var defaultValue = get(controllerProto, propName); + let urlKey = desc.as || this.serializeQueryParamKey(propName); + let defaultValue = get(controllerProto, propName); if (Array.isArray(defaultValue)) { defaultValue = emberA(defaultValue.slice()); } - var type = desc.type || typeOf(defaultValue); + let type = desc.type || typeOf(defaultValue); - var defaultValueSerialized = this.serializeQueryParam(defaultValue, urlKey, type); - var scopedPropertyName = `${controllerName}:${propName}`; - var qp = { + let defaultValueSerialized = this.serializeQueryParam(defaultValue, urlKey, type); + let scopedPropertyName = `${controllerName}:${propName}`; + let qp = { undecoratedDefaultValue: get(controllerProto, propName), defaultValue: defaultValue, serializedDefaultValue: defaultValueSerialized, @@ -258,7 +258,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, { in the active route hierarchy. */ inactive: (prop, value) => { - var qp = map[prop]; + let qp = map[prop]; this._qpChanged(prop, value, qp); }, /* @@ -267,7 +267,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, { in the active route hierarchy. */ active: (prop, value) => { - var qp = map[prop]; + let qp = map[prop]; this._qpChanged(prop, value, qp); return this._activeQPChanged(map[prop], value); }, @@ -276,7 +276,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, { and the route is currently in the active route hierarchy. */ allowOverrides: (prop, value) => { - var qp = map[prop]; + let qp = map[prop]; this._qpChanged(prop, value, qp); return this._updatingQPChanged(map[prop]); } @@ -297,24 +297,24 @@ var Route = EmberObject.extend(ActionHandler, Evented, { @method _stashNames */ _stashNames(_handlerInfo, dynamicParent) { - var handlerInfo = _handlerInfo; + let handlerInfo = _handlerInfo; if (this._names) { return; } - var names = this._names = handlerInfo._names; + let names = this._names = handlerInfo._names; if (!names.length) { handlerInfo = dynamicParent; names = handlerInfo && handlerInfo._names || []; } - var qps = get(this, '_qp.qps'); + let qps = get(this, '_qp.qps'); - var namePaths = new Array(names.length); - for (var a = 0; a < names.length; ++a) { + let namePaths = new Array(names.length); + for (let a = 0; a < names.length; ++a) { namePaths[a] = `${handlerInfo.name}.${names[a]}`; } - for (var i = 0; i < qps.length; ++i) { - var qp = qps[i]; + for (let i = 0; i < qps.length; ++i) { + let qp = qps[i]; if (qp.scope === 'model') { qp.parts = namePaths; } @@ -328,7 +328,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, { @property _activeQPChanged */ _activeQPChanged(qp, value) { - var router = this.router; + let router = this.router; router._activeQPChanged(qp.scopedPropertyName, value); }, @@ -337,7 +337,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, { @method _updatingQPChanged */ _updatingQPChanged(qp) { - var router = this.router; + let router = this.router; router._updatingQPChanged(qp.urlKey); }, @@ -352,16 +352,16 @@ var Route = EmberObject.extend(ActionHandler, Evented, { @public */ paramsFor(name) { - var route = getOwner(this).lookup(`route:${name}`); + let route = getOwner(this).lookup(`route:${name}`); if (!route) { return {}; } - var transition = this.router.router.activeTransition; - var state = transition ? transition.state : this.router.router.state; + let transition = this.router.router.activeTransition; + let state = transition ? transition.state : this.router.router.state; - var params = {}; + let params = {}; assign(params, state.params[name]); assign(params, getQueryParamsFor(route, state)); @@ -476,7 +476,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, { @since 1.7.0 */ _reset(isExiting, transition) { - var controller = this.controller; + let controller = this.controller; controller._qpDelegate = get(this, '_qp.states.inactive'); this.resetController(controller, isExiting, transition); @@ -498,7 +498,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, { template. ```javascript - var PostsList = Ember.Route.extend({ + let PostsList = Ember.Route.extend({ templateName: 'posts/list' }); @@ -759,11 +759,11 @@ var Route = EmberObject.extend(ActionHandler, Evented, { @private */ queryParamsDidChange(changed, totalPresent, removed) { - var qpMap = get(this, '_qp').map; + let qpMap = get(this, '_qp').map; - var totalChanged = Object.keys(changed).concat(Object.keys(removed)); - for (var i = 0; i < totalChanged.length; ++i) { - var qp = qpMap[totalChanged[i]]; + let totalChanged = Object.keys(changed).concat(Object.keys(removed)); + for (let i = 0; i < totalChanged.length; ++i) { + let qp = qpMap[totalChanged[i]]; if (qp && get(this._optionsForQueryParam(qp), 'refreshModel') && this.router.currentState) { this.refresh(); } @@ -778,24 +778,24 @@ var Route = EmberObject.extend(ActionHandler, Evented, { // Transition object is absent for intermediate transitions. if (!transition) { return; } - var handlerInfos = transition.state.handlerInfos; - var router = this.router; - var qpMeta = router._queryParamsFor(handlerInfos[handlerInfos.length - 1].name); - var changes = router._qpUpdates; - var replaceUrl; + let handlerInfos = transition.state.handlerInfos; + let router = this.router; + let qpMeta = router._queryParamsFor(handlerInfos[handlerInfos.length - 1].name); + let changes = router._qpUpdates; + let replaceUrl; stashParamNames(router, handlerInfos); - for (var i = 0; i < qpMeta.qps.length; ++i) { - var qp = qpMeta.qps[i]; - var route = qp.route; - var controller = route.controller; - var presentKey = qp.urlKey in params && qp.urlKey; + for (let i = 0; i < qpMeta.qps.length; ++i) { + let qp = qpMeta.qps[i]; + let route = qp.route; + let controller = route.controller; + let presentKey = qp.urlKey in params && qp.urlKey; // Do a reverse lookup to see if the changed query // param URL key corresponds to a QP property on // this controller. - var value, svalue; + let value, svalue; if (changes && qp.urlKey in changes) { // Value updated in/before setupController value = get(controller, qp.prop); @@ -814,11 +814,11 @@ var Route = EmberObject.extend(ActionHandler, Evented, { controller._qpDelegate = get(route, '_qp.states.inactive'); - var thisQueryParamChanged = (svalue !== qp.serializedValue); + let thisQueryParamChanged = (svalue !== qp.serializedValue); if (thisQueryParamChanged) { if (transition.queryParamsOnly && replaceUrl !== false) { - var options = route._optionsForQueryParam(qp); - var replaceConfigValue = get(options, 'replace'); + let options = route._optionsForQueryParam(qp); + let replaceConfigValue = get(options, 'replace'); if (replaceConfigValue) { replaceUrl = true; } else if (replaceConfigValue === false) { @@ -833,7 +833,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, { // Stash current serialized value of controller. qp.serializedValue = svalue; - var thisQueryParamHasDefaultValue = (qp.serializedDefaultValue === svalue); + let thisQueryParamHasDefaultValue = (qp.serializedDefaultValue === svalue); if (!thisQueryParamHasDefaultValue) { finalParams.push({ value: svalue, @@ -848,8 +848,8 @@ var Route = EmberObject.extend(ActionHandler, Evented, { } qpMeta.qps.forEach(function(qp) { - var routeQpMeta = get(qp.route, '_qp'); - var finalizedController = qp.route.controller; + let routeQpMeta = get(qp.route, '_qp'); + let finalizedController = qp.route.controller; finalizedController._qpDelegate = get(routeQpMeta, 'states.active'); }); @@ -992,8 +992,8 @@ var Route = EmberObject.extend(ActionHandler, Evented, { App.IndexRoute = Ember.Route.extend({ actions: { moveToChocolateCereal: function() { - var cereal = { cerealId: 'ChocolateYumminess' }; - var breakfast = { breakfastId: 'CerealAndMilk' }; + let cereal = { cerealId: 'ChocolateYumminess' }; + let breakfast = { breakfastId: 'CerealAndMilk' }; this.transitionTo('cereal', breakfast, cereal); } @@ -1030,7 +1030,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, { @public */ transitionTo(name, context) { - var router = this.router; + let router = this.router; return router.transitionTo(...arguments); }, @@ -1052,7 +1052,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, { @public */ intermediateTransitionTo() { - var router = this.router; + let router = this.router; router.intermediateTransitionTo(...arguments); }, @@ -1114,7 +1114,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, { @public */ replaceWith() { - var router = this.router; + let router = this.router; return router.replaceWith(...arguments); }, @@ -1157,9 +1157,9 @@ var Route = EmberObject.extend(ActionHandler, Evented, { if ((this.router && this.router.router) || !isTesting()) { this.router.send(...args); } else { - var name = args[0]; + let name = args[0]; args = slice.call(args, 1); - var action = this.actions[name]; + let action = this.actions[name]; if (action) { return this.actions[name].apply(this, args); } @@ -1173,10 +1173,10 @@ var Route = EmberObject.extend(ActionHandler, Evented, { @method setup */ setup(context, transition) { - var controller; + let controller; - var controllerName = this.controllerName || this.routeName; - var definedController = this.controllerFor(controllerName, true); + let controllerName = this.controllerName || this.routeName; + let definedController = this.controllerFor(controllerName, true); if (!definedController) { controller = this.generateController(controllerName, context); @@ -1187,30 +1187,30 @@ var Route = EmberObject.extend(ActionHandler, Evented, { // Assign the route's controller so that it can more easily be // referenced in action handlers. Side effects. Side effects everywhere. if (!this.controller) { - var propNames = get(this, '_qp.propertyNames'); + let propNames = get(this, '_qp.propertyNames'); addQueryParamsObservers(controller, propNames); this.controller = controller; } - var queryParams = get(this, '_qp'); + let queryParams = get(this, '_qp'); - var states = queryParams.states; + let states = queryParams.states; if (transition) { // Update the model dep values used to calculate cache keys. stashParamNames(this.router, transition.state.handlerInfos); - var params = transition.params; - var allParams = queryParams.propertyNames; - var cache = this._bucketCache; + let params = transition.params; + let allParams = queryParams.propertyNames; + let cache = this._bucketCache; allParams.forEach(function(prop) { - var aQp = queryParams.map[prop]; + let aQp = queryParams.map[prop]; aQp.values = params; - var cacheKey = calculateCacheKey(aQp.prefix, aQp.parts, aQp.values); + let cacheKey = calculateCacheKey(aQp.prefix, aQp.parts, aQp.values); if (cache) { - var value = cache.lookup(cacheKey, prop, aQp.undecoratedDefaultValue); + let value = cache.lookup(cacheKey, prop, aQp.undecoratedDefaultValue); set(controller, prop, value); } }); @@ -1219,7 +1219,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, { controller._qpDelegate = states.allowOverrides; if (transition) { - var qpValues = getQueryParamsFor(this, transition.state); + let qpValues = getQueryParamsFor(this, transition.state); controller.setProperties(qpValues); } @@ -1238,10 +1238,10 @@ var Route = EmberObject.extend(ActionHandler, Evented, { _qpChanged(prop, value, qp) { if (!qp) { return; } - var cacheKey = calculateCacheKey(qp.prefix || '', qp.parts, qp.values); + let cacheKey = calculateCacheKey(qp.prefix || '', qp.parts, qp.values); // Update model-dep cache - var cache = this._bucketCache; + let cache = this._bucketCache; if (cache) { cache.stash(cacheKey, prop, value); } @@ -1294,7 +1294,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, { App.PostRoute = Ember.Route.extend({ beforeModel: function(transition) { if (!App.Post) { - var self = this; + let self = this; return Ember.$.getScript('post.js').then(null, function(e) { self.transitionTo('help'); @@ -1467,10 +1467,10 @@ var Route = EmberObject.extend(ActionHandler, Evented, { @public */ model(params, transition) { - var match, name, sawParams, value; - var queryParams = get(this, '_qp.map'); + let match, name, sawParams, value; + let queryParams = get(this, '_qp.map'); - for (var prop in params) { + for (let prop in params) { if (prop === 'queryParams' || (queryParams && prop in queryParams)) { continue; } @@ -1487,7 +1487,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, { } else if (!name) { if (transition.resolveIndex < 1) { return; } - var parentModel = transition.state.handlerInfos[transition.resolveIndex - 1].context; + let parentModel = transition.state.handlerInfos[transition.resolveIndex - 1].context; return parentModel; } @@ -1516,7 +1516,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, { @private */ findModel() { - var store = get(this, 'store'); + let store = get(this, 'store'); return store.find(...arguments); }, @@ -1535,13 +1535,13 @@ var Route = EmberObject.extend(ActionHandler, Evented, { @private */ store: computed(function() { - var owner = getOwner(this); - var routeName = this.routeName; - var namespace = get(this, 'router.namespace'); + let owner = getOwner(this); + let routeName = this.routeName; + let namespace = get(this, 'router.namespace'); return { find(name, value) { - var modelClass = owner._lookupFactory(`model:${name}`); + let modelClass = owner._lookupFactory(`model:${name}`); assert( `You used the dynamic segment ${name}_id in your route ${routeName}, but ${namespace}.${classify(name)} did not exist and you did not override your route's \`model\` hook.`, !!modelClass); @@ -1682,9 +1682,9 @@ var Route = EmberObject.extend(ActionHandler, Evented, { @public */ controllerFor(name, _skipAssert) { - var owner = getOwner(this); - var route = owner.lookup(`route:${name}`); - var controller; + let owner = getOwner(this); + let route = owner.lookup(`route:${name}`); + let controller; if (route && route.controllerName) { name = route.controllerName; @@ -1720,7 +1720,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, { @private */ generateController(name, model) { - var owner = getOwner(this); + let owner = getOwner(this); model = model || this.modelFor(name); @@ -1759,13 +1759,13 @@ var Route = EmberObject.extend(ActionHandler, Evented, { @public */ modelFor(name) { - var route = getOwner(this).lookup(`route:${name}`); - var transition = this.router ? this.router.router.activeTransition : null; + let route = getOwner(this).lookup(`route:${name}`); + let transition = this.router ? this.router.router.activeTransition : null; // If we are mid-transition, we want to try and look up // resolved parent contexts on the current transitionEvent. if (transition) { - var modelLookupName = (route && route.routeName) || name; + let modelLookupName = (route && route.routeName) || name; if (transition.resolvedModels.hasOwnProperty(modelLookupName)) { return transition.resolvedModels[modelLookupName]; } @@ -1787,7 +1787,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, { ```javascript App.PostsRoute = Ember.Route.extend({ renderTemplate: function(controller, model) { - var favController = this.controllerFor('favoritePost'); + let favController = this.controllerFor('favoritePost'); // Render the `favoritePost` template into // the outlet `posts`, and display the `favoritePost` @@ -1929,9 +1929,9 @@ var Route = EmberObject.extend(ActionHandler, Evented, { render(_name, options) { assert('The name in the given arguments is undefined', arguments.length > 0 ? !isNone(arguments[0]) : true); - var namePassed = typeof _name === 'string' && !!_name; - var isDefaultRender = arguments.length === 0 || isEmpty(arguments[0]); - var name; + let namePassed = typeof _name === 'string' && !!_name; + let isDefaultRender = arguments.length === 0 || isEmpty(arguments[0]); + let name; if (typeof _name === 'object' && !options) { name = this.routeName; @@ -1940,7 +1940,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, { name = _name; } - var renderOptions = buildRenderOptions(this, namePassed, isDefaultRender, name, options); + let renderOptions = buildRenderOptions(this, namePassed, isDefaultRender, name, options); this.connections.push(renderOptions); run.once(this.router, '_setOutlets'); }, @@ -1990,8 +1990,8 @@ var Route = EmberObject.extend(ActionHandler, Evented, { @public */ disconnectOutlet(options) { - var outletName; - var parentView; + let outletName; + let parentView; if (!options || typeof options === 'string') { outletName = options; } else { @@ -2005,7 +2005,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, { parentView = parentView && parentView.replace(/\//g, '.'); outletName = outletName || 'main'; this._disconnectOutlet(outletName, parentView); - for (var i = 0; i < this.router.router.currentHandlerInfos.length; i++) { + for (let i = 0; i < this.router.router.currentHandlerInfos.length; i++) { // This non-local state munging is sadly necessary to maintain // backward compatibility with our existing semantics, which allow // any route to disconnectOutlet things originally rendered by any @@ -2016,12 +2016,12 @@ var Route = EmberObject.extend(ActionHandler, Evented, { }, _disconnectOutlet(outletName, parentView) { - var parent = parentRoute(this); + let parent = parentRoute(this); if (parent && parentView === parent.routeName) { parentView = undefined; } - for (var i = 0; i < this.connections.length; i++) { - var connection = this.connections[i]; + for (let i = 0; i < this.connections.length; i++) { + let connection = this.connections[i]; if (connection.outlet === outletName && connection.into === parentView) { // This neuters the disconnected outlet such that it doesn't // render anything, but it leaves an entry in the outlet @@ -2067,16 +2067,16 @@ Route.reopenClass({ }); function parentRoute(route) { - var handlerInfo = handlerInfoFor(route, route.router.router.state.handlerInfos, -1); + let handlerInfo = handlerInfoFor(route, route.router.router.state.handlerInfos, -1); return handlerInfo && handlerInfo.handler; } function handlerInfoFor(route, handlerInfos, _offset) { if (!handlerInfos) { return; } - var offset = _offset || 0; - var current; - for (var i = 0; i < handlerInfos.length; i++) { + let offset = _offset || 0; + let current; + for (let i = 0; i < handlerInfos.length; i++) { current = handlerInfos[i].handler; if (current === route) { return handlerInfos[i + offset]; } } @@ -2154,29 +2154,29 @@ function getFullQueryParams(router, state) { state.fullQueryParams = {}; assign(state.fullQueryParams, state.queryParams); - var targetRouteName = state.handlerInfos[state.handlerInfos.length - 1].name; + let targetRouteName = state.handlerInfos[state.handlerInfos.length - 1].name; router._deserializeQueryParams(targetRouteName, state.fullQueryParams); return state.fullQueryParams; } function getQueryParamsFor(route, state) { state.queryParamsFor = state.queryParamsFor || {}; - var name = route.routeName; + let name = route.routeName; if (state.queryParamsFor[name]) { return state.queryParamsFor[name]; } - var fullQueryParams = getFullQueryParams(route.router, state); + let fullQueryParams = getFullQueryParams(route.router, state); - var params = state.queryParamsFor[name] = {}; + let params = state.queryParamsFor[name] = {}; // Copy over all the query params for this route/controller into params hash. - var qpMeta = get(route, '_qp'); - var qps = qpMeta.qps; - for (var i = 0; i < qps.length; ++i) { + let qpMeta = get(route, '_qp'); + let qps = qpMeta.qps; + for (let i = 0; i < qps.length; ++i) { // Put deserialized qp on params hash. - var qp = qps[i]; + let qp = qps[i]; - var qpValueWasPassedIn = (qp.prop in fullQueryParams); + let qpValueWasPassedIn = (qp.prop in fullQueryParams); params[qp.prop] = qpValueWasPassedIn ? fullQueryParams[qp.prop] : copyDefaultValue(qp.defaultValue); @@ -2198,8 +2198,8 @@ function copyDefaultValue(value) { the existing objects. */ function mergeEachQueryParams(controllerQP, routeQP) { - var keysAlreadyMergedOrSkippable; - var qps = {}; + let keysAlreadyMergedOrSkippable; + let qps = {}; if (isEnabled('ember-routing-route-configured-query-params')) { keysAlreadyMergedOrSkippable = {}; @@ -2214,10 +2214,10 @@ function mergeEachQueryParams(controllerQP, routeQP) { // first loop over all controller qps, merging them with any matching route qps // into a new empty object to avoid mutating. - for (var cqpName in controllerQP) { + for (let cqpName in controllerQP) { if (!controllerQP.hasOwnProperty(cqpName)) { continue; } - var newControllerParameterConfiguration = {}; + let newControllerParameterConfiguration = {}; assign(newControllerParameterConfiguration, controllerQP[cqpName]); assign(newControllerParameterConfiguration, routeQP[cqpName]); @@ -2229,10 +2229,10 @@ function mergeEachQueryParams(controllerQP, routeQP) { // loop over all route qps, skipping those that were merged in the first pass // because they also appear in controller qps - for (var rqpName in routeQP) { + for (let rqpName in routeQP) { if (!routeQP.hasOwnProperty(rqpName) || keysAlreadyMergedOrSkippable[rqpName]) { continue; } - var newRouteParameterConfiguration = {}; + let newRouteParameterConfiguration = {}; assign(newRouteParameterConfiguration, routeQP[rqpName], controllerQP[rqpName]); qps[rqpName] = newRouteParameterConfiguration; } diff --git a/packages/ember-routing/lib/system/router.js b/packages/ember-routing/lib/system/router.js index 86240f3f2e7..f5a1f4a39e0 100644 --- a/packages/ember-routing/lib/system/router.js +++ b/packages/ember-routing/lib/system/router.js @@ -35,7 +35,7 @@ import 'router/transition'; function K() { return this; } -var slice = [].slice; +const { slice } = Array.prototype; /** @@ -48,7 +48,7 @@ var slice = [].slice; @uses Ember.Evented @public */ -var EmberRouter = EmberObject.extend(Evented, { +const EmberRouter = EmberObject.extend(Evented, { /** The `location` property determines the type of URL's that your application will use. @@ -80,17 +80,17 @@ var EmberRouter = EmberObject.extend(Evented, { rootURL: '/', _initRouterJs() { - var router = this.router = new Router(); + let router = this.router = new Router(); router.triggerEvent = triggerEvent; router._triggerWillChangeContext = K; router._triggerWillLeave = K; - var dslCallbacks = this.constructor.dslCallbacks || [K]; - var dsl = this._buildDSL(); + let dslCallbacks = this.constructor.dslCallbacks || [K]; + let dsl = this._buildDSL(); dsl.route('application', { path: '/', resetNamespace: true, overrideNameAssertion: true }, function() { - for (var i = 0; i < dslCallbacks.length; i++) { + for (let i = 0; i < dslCallbacks.length; i++) { dslCallbacks[i].call(this); } }); @@ -171,13 +171,13 @@ var EmberRouter = EmberObject.extend(Evented, { @private */ startRouting() { - var initialURL = get(this, 'initialURL'); + let initialURL = get(this, 'initialURL'); if (this.setupRouter()) { if (typeof initialURL === 'undefined') { initialURL = get(this, 'location').getURL(); } - var initialTransition = this.handleURL(initialURL); + let initialTransition = this.handleURL(initialURL); if (initialTransition && initialTransition.error) { throw initialTransition.error; } @@ -188,8 +188,8 @@ var EmberRouter = EmberObject.extend(Evented, { this._initRouterJs(); this._setupLocation(); - var router = this.router; - var location = get(this, 'location'); + let router = this.router; + let location = get(this, 'location'); // Allow the Location class to cancel the router setup while it refreshes // the page @@ -216,7 +216,7 @@ var EmberRouter = EmberObject.extend(Evented, { you could use this hook. (Note: requires also including GA scripts, etc.) ```javascript - var Router = Ember.Router.extend({ + let Router = Ember.Router.extend({ location: config.locationType, didTransition: function() { @@ -252,21 +252,21 @@ var EmberRouter = EmberObject.extend(Evented, { }, _setOutlets() { - var handlerInfos = this.router.currentHandlerInfos; - var route; - var defaultParentState; - var liveRoutes = null; + let handlerInfos = this.router.currentHandlerInfos; + let route; + let defaultParentState; + let liveRoutes = null; if (!handlerInfos) { return; } - for (var i = 0; i < handlerInfos.length; i++) { + for (let i = 0; i < handlerInfos.length; i++) { route = handlerInfos[i].handler; - var connections = route.connections; - var ownState; - for (var j = 0; j < connections.length; j++) { - var appended = appendLiveRoute(liveRoutes, defaultParentState, connections[j]); + let connections = route.connections; + let ownState; + for (let j = 0; j < connections.length; j++) { + let appended = appendLiveRoute(liveRoutes, defaultParentState, connections[j]); liveRoutes = appended.liveRoutes; if (appended.ownState.render.name === route.routeName || appended.ownState.render.outlet === 'main') { ownState = appended.ownState; @@ -279,10 +279,10 @@ var EmberRouter = EmberObject.extend(Evented, { } if (!this._toplevelView) { let owner = getOwner(this); - var OutletView = owner._lookupFactory('view:-outlet'); + let OutletView = owner._lookupFactory('view:-outlet'); this._toplevelView = OutletView.create(); this._toplevelView.setOutletState(liveRoutes); - var instance = owner.lookup('-application-instance:main'); + let instance = owner.lookup('-application-instance:main'); instance.didCreateRootView(this._toplevelView); } else { this._toplevelView.setOutletState(liveRoutes); @@ -315,7 +315,7 @@ var EmberRouter = EmberObject.extend(Evented, { }, _doURLTransition(routerJsMethod, url) { - var transition = this.router[routerJsMethod](url || '/'); + let transition = this.router[routerJsMethod](url || '/'); didBeginTransition(transition, this); return transition; }, @@ -337,19 +337,19 @@ var EmberRouter = EmberObject.extend(Evented, { @public */ transitionTo(...args) { - var queryParams; + let queryParams; if (resemblesURL(args[0])) { return this._doURLTransition('transitionTo', args[0]); } - var possibleQueryParams = args[args.length - 1]; + let possibleQueryParams = args[args.length - 1]; if (possibleQueryParams && possibleQueryParams.hasOwnProperty('queryParams')) { queryParams = args.pop().queryParams; } else { queryParams = {}; } - var targetRouteName = args.shift(); + let targetRouteName = args.shift(); return this._doTransition(targetRouteName, args, queryParams); }, @@ -358,7 +358,7 @@ var EmberRouter = EmberObject.extend(Evented, { updatePaths(this); - var infos = this.router.currentHandlerInfos; + let infos = this.router.currentHandlerInfos; if (get(this, 'namespace').LOG_TRANSITIONS) { Logger.log(`Intermediate-transitioned into '${EmberRouter._routePath(infos)}'`); } @@ -369,7 +369,7 @@ var EmberRouter = EmberObject.extend(Evented, { }, generate() { - var url = this.router.generate(...arguments); + let url = this.router.generate(...arguments); return this.location.formatURL(url); }, @@ -382,7 +382,7 @@ var EmberRouter = EmberObject.extend(Evented, { @private */ isActive(routeName) { - var router = this.router; + let router = this.router; return router.isActive(...arguments); }, @@ -486,7 +486,7 @@ var EmberRouter = EmberObject.extend(Evented, { _connectActiveComponentNode(templateName, componentNode) { assert('cannot connect an activeView that already exists', !this._activeViews[templateName]); - var _activeViews = this._activeViews; + let _activeViews = this._activeViews; function disconnectActiveView() { delete _activeViews[templateName]; } @@ -496,18 +496,18 @@ var EmberRouter = EmberObject.extend(Evented, { }, _setupLocation() { - var location = get(this, 'location'); - var rootURL = get(this, 'rootURL'); + let location = get(this, 'location'); + let rootURL = get(this, 'rootURL'); let owner = getOwner(this); if ('string' === typeof location && owner) { - var resolvedLocation = owner.lookup(`location:${location}`); + let resolvedLocation = owner.lookup(`location:${location}`); if ('undefined' !== typeof resolvedLocation) { location = set(this, 'location', resolvedLocation); } else { // Allow for deprecated registration of custom location API's - var options = { + let options = { implementation: location }; @@ -536,13 +536,13 @@ var EmberRouter = EmberObject.extend(Evented, { }, _getHandlerFunction() { - var seen = new EmptyObject(); + let seen = new EmptyObject(); let owner = getOwner(this); - var DefaultRoute = owner._lookupFactory('route:basic'); + let DefaultRoute = owner._lookupFactory('route:basic'); return (name) => { - var routeName = 'route:' + name; - var handler = owner.lookup(routeName); + let routeName = 'route:' + name; + let handler = owner.lookup(routeName); if (seen[name]) { return handler; @@ -566,10 +566,10 @@ var EmberRouter = EmberObject.extend(Evented, { _getSerializerFunction() { return (name) => { - var serializer = this._serializeMethods[name]; + let serializer = this._serializeMethods[name]; if (!serializer) { - var handler = this.router.getHandler(name); + let handler = this.router.getHandler(name); deprecate( `Defining a serialize function on route '${name}' is deprecated. Instead, define it in the router's map as an option.`, @@ -585,8 +585,8 @@ var EmberRouter = EmberObject.extend(Evented, { }, _setupRouter(router, location) { - var lastURL; - var emberRouter = this; + let lastURL; + let emberRouter = this; router.getHandler = this._getHandlerFunction(); @@ -594,7 +594,7 @@ var EmberRouter = EmberObject.extend(Evented, { router.getSerializer = this._getSerializerFunction(); } - var doUpdateURL = function() { + let doUpdateURL = function() { location.setURL(lastURL); }; @@ -604,7 +604,7 @@ var EmberRouter = EmberObject.extend(Evented, { }; if (location.replaceURL) { - var doReplaceURL = function() { + let doReplaceURL = function() { location.replaceURL(lastURL); }; @@ -624,10 +624,10 @@ var EmberRouter = EmberObject.extend(Evented, { }, _serializeQueryParams(targetRouteName, queryParams) { - var groupedByUrlKey = {}; + let groupedByUrlKey = {}; forEachQueryParam(this, targetRouteName, queryParams, function(key, value, qp) { - var urlKey = qp.urlKey; + let urlKey = qp.urlKey; if (!groupedByUrlKey[urlKey]) { groupedByUrlKey[urlKey] = []; } @@ -638,10 +638,10 @@ var EmberRouter = EmberObject.extend(Evented, { delete queryParams[key]; }); - for (var key in groupedByUrlKey) { - var qps = groupedByUrlKey[key]; + for (let key in groupedByUrlKey) { + let qps = groupedByUrlKey[key]; assert(`You're not allowed to have more than one controller property map to the same query param key, but both \`${qps[0].qp.scopedPropertyName}\` and \`${qps[1] ? qps[1].qp.scopedPropertyName : ''}\` map to \`${qps[0].qp.urlKey}\`. You can fix this by mapping one of the controller properties to a different query param key via the \`as\` config option, e.g. \`${qps[0].qp.prop}: { as: \'other-${qps[0].qp.prop}\' }\``, qps.length <= 1); - var qp = qps[0].qp; + let qp = qps[0].qp; queryParams[qp.urlKey] = qp.route.serializeQueryParam(qps[0].value, qp.urlKey, qp.type); } }, @@ -654,9 +654,9 @@ var EmberRouter = EmberObject.extend(Evented, { }, _pruneDefaultQueryParamValues(targetRouteName, queryParams) { - var qps = this._queryParamsFor(targetRouteName); - for (var key in queryParams) { - var qp = qps.map[key]; + let qps = this._queryParamsFor(targetRouteName); + for (let key in queryParams) { + let qp = qps.map[key]; if (qp && qp.serializedDefaultValue === queryParams[key]) { delete queryParams[key]; } @@ -664,10 +664,10 @@ var EmberRouter = EmberObject.extend(Evented, { }, _doTransition(_targetRouteName, models, _queryParams) { - var targetRouteName = _targetRouteName || getActiveTargetName(this.router); + let targetRouteName = _targetRouteName || getActiveTargetName(this.router); assert(`The route ${targetRouteName} was not found`, targetRouteName && this.router.hasRoute(targetRouteName)); - var queryParams = {}; + let queryParams = {}; // merge in any queryParams from the active transition which could include // queryparams from the url on initial load. if (this.router.activeTransition) { @@ -677,8 +677,8 @@ var EmberRouter = EmberObject.extend(Evented, { assign(queryParams, _queryParams); this._prepareQueryParams(targetRouteName, models, queryParams); - var transitionArgs = routeArgs(targetRouteName, models, queryParams); - var transition = this.router.transitionTo.apply(this.router, transitionArgs); + let transitionArgs = routeArgs(targetRouteName, models, queryParams); + let transition = this.router.transitionTo.apply(this.router, transitionArgs); didBeginTransition(transition, this); @@ -702,20 +702,20 @@ var EmberRouter = EmberObject.extend(Evented, { return this._qpCache[leafRouteName]; } - var map = {}; - var qps = []; + let map = {}; + let qps = []; this._qpCache[leafRouteName] = { map: map, qps: qps }; - var routerjs = this.router; - var recogHandlerInfos = routerjs.recognizer.handlersFor(leafRouteName); + let routerjs = this.router; + let recogHandlerInfos = routerjs.recognizer.handlersFor(leafRouteName); - for (var i = 0; i < recogHandlerInfos.length; ++i) { - var recogHandler = recogHandlerInfos[i]; - var route = routerjs.getHandler(recogHandler.handler); - var qpMeta = get(route, '_qp'); + for (let i = 0; i < recogHandlerInfos.length; ++i) { + let recogHandler = recogHandlerInfos[i]; + let route = routerjs.getHandler(recogHandler.handler); + let qpMeta = get(route, '_qp'); if (!qpMeta) { continue; } @@ -730,19 +730,19 @@ var EmberRouter = EmberObject.extend(Evented, { }, _hydrateUnsuppliedQueryParams(leafRouteName, contexts, queryParams) { - var state = calculatePostTransitionState(this, leafRouteName, contexts); - var handlerInfos = state.handlerInfos; - var appCache = this._bucketCache; + let state = calculatePostTransitionState(this, leafRouteName, contexts); + let handlerInfos = state.handlerInfos; + let appCache = this._bucketCache; stashParamNames(this, handlerInfos); - for (var i = 0; i < handlerInfos.length; ++i) { - var route = handlerInfos[i].handler; - var qpMeta = get(route, '_qp'); + for (let i = 0; i < handlerInfos.length; ++i) { + let route = handlerInfos[i].handler; + let qpMeta = get(route, '_qp'); - for (var j = 0, qpLen = qpMeta.qps.length; j < qpLen; ++j) { - var qp = qpMeta.qps[j]; + for (let j = 0, qpLen = qpMeta.qps.length; j < qpLen; ++j) { + let qp = qpMeta.qps[j]; - var presentProp = qp.prop in queryParams && qp.prop || + let presentProp = qp.prop in queryParams && qp.prop || qp.scopedPropertyName in queryParams && qp.scopedPropertyName; if (presentProp) { @@ -751,7 +751,7 @@ var EmberRouter = EmberObject.extend(Evented, { delete queryParams[presentProp]; } } else { - var cacheKey = calculateCacheKey(qp.ctrl, qp.parts, state.params); + let cacheKey = calculateCacheKey(qp.ctrl, qp.parts, state.params); queryParams[qp.scopedPropertyName] = appCache.lookup(cacheKey, qp.prop, qp.defaultValue); } } @@ -814,11 +814,11 @@ var EmberRouter = EmberObject.extend(Evented, { @private */ function forEachRouteAbove(originRoute, transition, callback) { - var handlerInfos = transition.state.handlerInfos; - var originRouteFound = false; - var handlerInfo, route; + let handlerInfos = transition.state.handlerInfos; + let originRouteFound = false; + let handlerInfo, route; - for (var i = handlerInfos.length - 1; i >= 0; --i) { + for (let i = handlerInfos.length - 1; i >= 0; --i) { handlerInfo = handlerInfos[i]; route = handlerInfo.handler; @@ -838,7 +838,7 @@ function forEachRouteAbove(originRoute, transition, callback) { // These get invoked when an action bubbles above ApplicationRoute // and are not meant to be overridable. -var defaultActionHandlers = { +let defaultActionHandlers = { willResolveModel(transition, originRoute) { originRoute.router._scheduleLoadingEvent(transition, originRoute); @@ -846,10 +846,10 @@ var defaultActionHandlers = { error(error, transition, originRoute) { // Attempt to find an appropriate error substate to enter. - var router = originRoute.router; + let router = originRoute.router; - var tryTopLevel = forEachRouteAbove(originRoute, transition, function(route, childRoute) { - var childErrorRouteName = findChildRouteName(route, childRoute, 'error'); + let tryTopLevel = forEachRouteAbove(originRoute, transition, function(route, childRoute) { + let childErrorRouteName = findChildRouteName(route, childRoute, 'error'); if (childErrorRouteName) { router.intermediateTransitionTo(childErrorRouteName, error); return; @@ -870,10 +870,10 @@ var defaultActionHandlers = { loading(transition, originRoute) { // Attempt to find an appropriate loading substate to enter. - var router = originRoute.router; + let router = originRoute.router; - var tryTopLevel = forEachRouteAbove(originRoute, transition, function(route, childRoute) { - var childLoadingRouteName = findChildRouteName(route, childRoute, 'loading'); + let tryTopLevel = forEachRouteAbove(originRoute, transition, function(route, childRoute) { + let childLoadingRouteName = findChildRouteName(route, childRoute, 'loading'); if (childLoadingRouteName) { router.intermediateTransitionTo(childLoadingRouteName); @@ -897,8 +897,8 @@ var defaultActionHandlers = { }; function logError(_error, initialMessage) { - var errorArgs = []; - var error; + let errorArgs = []; + let error; if (_error && typeof _error === 'object' && typeof _error.errorThrown === 'object') { error = _error.errorThrown; } else { @@ -918,10 +918,10 @@ function logError(_error, initialMessage) { } function findChildRouteName(parentRoute, originatingChildRoute, name) { - var router = parentRoute.router; - var childName; - var targetChildRouteName = originatingChildRoute.routeName.split('.').pop(); - var namespace = parentRoute.routeName === 'application' ? '' : parentRoute.routeName + '.'; + let router = parentRoute.router; + let childName; + let targetChildRouteName = originatingChildRoute.routeName.split('.').pop(); + let namespace = parentRoute.routeName === 'application' ? '' : parentRoute.routeName + '.'; // First, try a named loading state, e.g. 'foo_loading' childName = namespace + targetChildRouteName + '_' + name; @@ -943,17 +943,17 @@ function routeHasBeenDefined(router, name) { } export function triggerEvent(handlerInfos, ignoreFailure, args) { - var name = args.shift(); + let name = args.shift(); if (!handlerInfos) { if (ignoreFailure) { return; } throw new EmberError(`Can't trigger action '${name}' because your app hasn't finished transitioning into its first route. To trigger an action on destination routes during a transition, you can call \`.send()\` on the \`Transition\` object passed to the \`model/beforeModel/afterModel\` hooks.`); } - var eventWasHandled = false; - var handlerInfo, handler; + let eventWasHandled = false; + let handlerInfo, handler; - for (var i = handlerInfos.length - 1; i >= 0; i--) { + for (let i = handlerInfos.length - 1; i >= 0; i--) { handlerInfo = handlerInfos[i]; handler = handlerInfo.handler; @@ -963,7 +963,7 @@ export function triggerEvent(handlerInfos, ignoreFailure, args) { } else { // Should only hit here if a non-bubbling error action is triggered on a route. if (name === 'error') { - var errorId = guidFor(args[0]); + let errorId = guidFor(args[0]); handler.router._markErrorAsHandled(errorId); } return; @@ -982,13 +982,13 @@ export function triggerEvent(handlerInfos, ignoreFailure, args) { } function calculatePostTransitionState(emberRouter, leafRouteName, contexts) { - var routerjs = emberRouter.router; - var state = routerjs.applyIntent(leafRouteName, contexts); - var handlerInfos = state.handlerInfos; - var params = state.params; + let routerjs = emberRouter.router; + let state = routerjs.applyIntent(leafRouteName, contexts); + let handlerInfos = state.handlerInfos; + let params = state.params; - for (var i = 0; i < handlerInfos.length; ++i) { - var handlerInfo = handlerInfos[i]; + for (let i = 0; i < handlerInfos.length; ++i) { + let handlerInfo = handlerInfos[i]; if (!handlerInfo.isResolved) { handlerInfo = handlerInfo.becomeResolved(null, handlerInfo.context); } @@ -1083,14 +1083,14 @@ EmberRouter.reopenClass({ }, _routePath(handlerInfos) { - var path = []; + let path = []; // We have to handle coalescing resource names that // are prefixed with their parent's names, e.g. // ['foo', 'foo.bar.baz'] => 'foo.bar.baz', not 'foo.foo.bar.baz' function intersectionMatches(a1, a2) { - for (var i = 0; i < a1.length; ++i) { + for (let i = 0; i < a1.length; ++i) { if (a1[i] !== a2[i]) { return false; } @@ -1098,8 +1098,8 @@ EmberRouter.reopenClass({ return true; } - var name, nameParts, oldNameParts; - for (var i = 1; i < handlerInfos.length; i++) { + let name, nameParts, oldNameParts; + for (let i = 1; i < handlerInfos.length; i++) { name = handlerInfos[i].name; nameParts = name.split('.'); oldNameParts = slice.call(path); @@ -1119,7 +1119,7 @@ EmberRouter.reopenClass({ }); function didBeginTransition(transition, router) { - var routerState = RouterState.create({ + let routerState = RouterState.create({ emberRouter: router, routerJs: router.router, routerJsState: transition.state @@ -1131,7 +1131,7 @@ function didBeginTransition(transition, router) { router.set('targetState', routerState); transition.promise = transition.catch(function(error) { - var errorId = guidFor(error); + let errorId = guidFor(error); if (router._isErrorHandled(errorId)) { router._clearHandledError(errorId); @@ -1146,12 +1146,12 @@ function resemblesURL(str) { } function forEachQueryParam(router, targetRouteName, queryParams, callback) { - var qpCache = router._queryParamsFor(targetRouteName); + let qpCache = router._queryParamsFor(targetRouteName); - for (var key in queryParams) { + for (let key in queryParams) { if (!queryParams.hasOwnProperty(key)) { continue; } - var value = queryParams[key]; - var qp = qpCache.map[key]; + let value = queryParams[key]; + let qp = qpCache.map[key]; if (qp) { callback(key, value, qp); @@ -1161,22 +1161,22 @@ function forEachQueryParam(router, targetRouteName, queryParams, callback) { function findLiveRoute(liveRoutes, name) { if (!liveRoutes) { return; } - var stack = [liveRoutes]; + let stack = [liveRoutes]; while (stack.length > 0) { - var test = stack.shift(); + let test = stack.shift(); if (test.render.name === name) { return test; } - var outlets = test.outlets; - for (var outletName in outlets) { + let outlets = test.outlets; + for (let outletName in outlets) { stack.push(outlets[outletName]); } } } function appendLiveRoute(liveRoutes, defaultParentState, renderOptions) { - var target; - var myState = { + let target; + let myState = { render: renderOptions, outlets: new EmptyObject() }; @@ -1226,7 +1226,7 @@ function appendOrphan(liveRoutes, into, myState) { function representEmptyRoute(liveRoutes, defaultParentState, route) { // the route didn't render anything - var alreadyAppended = findLiveRoute(liveRoutes, route.routeName); + let alreadyAppended = findLiveRoute(liveRoutes, route.routeName); if (alreadyAppended) { // But some other route has already rendered our default // template, so that becomes the default target for any diff --git a/packages/ember-routing/lib/system/router_state.js b/packages/ember-routing/lib/system/router_state.js index 5684747f07b..b06a9350b5a 100644 --- a/packages/ember-routing/lib/system/router_state.js +++ b/packages/ember-routing/lib/system/router_state.js @@ -2,21 +2,19 @@ import isEmpty from 'ember-metal/is_empty'; import EmberObject from 'ember-runtime/system/object'; import assign from 'ember-metal/assign'; -const keys = Object.keys; - -var RouterState = EmberObject.extend({ +export default EmberObject.extend({ emberRouter: null, routerJs: null, routerJsState: null, isActiveIntent(routeName, models, queryParams, queryParamsMustMatch) { - var state = this.routerJsState; + let state = this.routerJsState; if (!this.routerJs.isActiveIntent(routeName, models, null, state)) { return false; } - var emptyQueryParams = isEmpty(keys(queryParams)); + let emptyQueryParams = isEmpty(Object.keys(queryParams)); if (queryParamsMustMatch && !emptyQueryParams) { - var visibleQueryParams = {}; + let visibleQueryParams = {}; assign(visibleQueryParams, queryParams); this.emberRouter._prepareQueryParams(routeName, models, visibleQueryParams); @@ -28,7 +26,7 @@ var RouterState = EmberObject.extend({ }); function shallowEqual(a, b) { - var k; + let k; for (k in a) { if (a.hasOwnProperty(k) && a[k] !== b[k]) { return false; } } @@ -37,5 +35,3 @@ function shallowEqual(a, b) { } return true; } - -export default RouterState; diff --git a/packages/ember-routing/lib/utils.js b/packages/ember-routing/lib/utils.js index b7ca4747e97..df5aa910a05 100644 --- a/packages/ember-routing/lib/utils.js +++ b/packages/ember-routing/lib/utils.js @@ -1,8 +1,10 @@ import assign from 'ember-metal/assign'; import { get } from 'ember-metal/property_get'; +const ALL_PERIODS_REGEX = /\./g; + export function routeArgs(targetRouteName, models, queryParams) { - var args = []; + let args = []; if (typeof targetRouteName === 'string') { args.push('' + targetRouteName); } @@ -12,7 +14,7 @@ export function routeArgs(targetRouteName, models, queryParams) { } export function getActiveTargetName(router) { - var handlerInfos = router.activeTransition ? + let handlerInfos = router.activeTransition ? router.activeTransition.state.handlerInfos : router.state.handlerInfos; return handlerInfos[handlerInfos.length - 1].name; @@ -25,13 +27,13 @@ export function stashParamNames(router, handlerInfos) { // keeps separate a handlerInfo's list of parameter names depending // on whether a URL transition or named transition is happening. // Hopefully we can remove this in the future. - var targetRouteName = handlerInfos[handlerInfos.length - 1].name; - var recogHandlers = router.router.recognizer.handlersFor(targetRouteName); - var dynamicParent = null; + let targetRouteName = handlerInfos[handlerInfos.length - 1].name; + let recogHandlers = router.router.recognizer.handlersFor(targetRouteName); + let dynamicParent = null; - for (var i = 0; i < handlerInfos.length; ++i) { - var handlerInfo = handlerInfos[i]; - var names = recogHandlers[i].names; + for (let i = 0; i < handlerInfos.length; ++i) { + let handlerInfo = handlerInfos[i]; + let names = recogHandlers[i].names; if (names.length) { dynamicParent = handlerInfo; @@ -39,7 +41,7 @@ export function stashParamNames(router, handlerInfos) { handlerInfo._names = names; - var route = handlerInfo.handler; + let route = handlerInfo.handler; route._stashNames(handlerInfo, dynamicParent); } @@ -56,11 +58,11 @@ function _calculateCacheValuePrefix(prefix, part) { // given : prefix = site.article, part = site.article.id // - returns: site.article. (use get(values[site.article], 'id') to get the dynamic part - used below) - var prefixParts = prefix.split('.'); - var currPrefix = ''; + let prefixParts = prefix.split('.'); + let currPrefix = ''; - for (var i = 0; i < prefixParts.length; i++) { - var currPart = prefixParts.slice(0, i + 1).join('.'); + for (let i = 0; i < prefixParts.length; i++) { + let currPart = prefixParts.slice(0, i + 1).join('.'); if (part.indexOf(currPart) !== 0) { break; } @@ -74,15 +76,15 @@ function _calculateCacheValuePrefix(prefix, part) { Stolen from Controller */ export function calculateCacheKey(prefix, _parts, values) { - var parts = _parts || []; - var suffixes = ''; - for (var i = 0; i < parts.length; ++i) { - var part = parts[i]; - var cacheValuePrefix = _calculateCacheValuePrefix(prefix, part); - var value; + let parts = _parts || []; + let suffixes = ''; + for (let i = 0; i < parts.length; ++i) { + let part = parts[i]; + let cacheValuePrefix = _calculateCacheValuePrefix(prefix, part); + let value; if (values) { if (cacheValuePrefix && cacheValuePrefix in values) { - var partRemovedPrefix = (part.indexOf(cacheValuePrefix) === 0) ? part.substr(cacheValuePrefix.length + 1) : part; + let partRemovedPrefix = (part.indexOf(cacheValuePrefix) === 0) ? part.substr(cacheValuePrefix.length + 1) : part; value = get(values[cacheValuePrefix], partRemovedPrefix); } else { value = get(values, part); @@ -92,7 +94,6 @@ export function calculateCacheKey(prefix, _parts, values) { } return prefix + suffixes.replace(ALL_PERIODS_REGEX, '-'); } -var ALL_PERIODS_REGEX = /\./g; /* @@ -132,9 +133,9 @@ export function normalizeControllerQueryParams(queryParams) { return queryParams._qpMap; } - var qpMap = queryParams._qpMap = {}; + let qpMap = queryParams._qpMap = {}; - for (var i = 0; i < queryParams.length; ++i) { + for (let i = 0; i < queryParams.length; ++i) { accumulateQueryParamDescriptors(queryParams[i], qpMap); } @@ -142,18 +143,18 @@ export function normalizeControllerQueryParams(queryParams) { } function accumulateQueryParamDescriptors(_desc, accum) { - var desc = _desc; - var tmp; + let desc = _desc; + let tmp; if (typeof desc === 'string') { tmp = {}; tmp[desc] = { as: null }; desc = tmp; } - for (var key in desc) { + for (let key in desc) { if (!desc.hasOwnProperty(key)) { return; } - var singleDesc = desc[key]; + let singleDesc = desc[key]; if (typeof singleDesc === 'string') { singleDesc = { as: singleDesc }; } diff --git a/packages/ember-routing/tests/location/auto_location_test.js b/packages/ember-routing/tests/location/auto_location_test.js index bcbf5d63f6d..0001b5202b4 100644 --- a/packages/ember-routing/tests/location/auto_location_test.js +++ b/packages/ember-routing/tests/location/auto_location_test.js @@ -52,7 +52,7 @@ function createLocation(location, history) { return autolocation; } -var location; +let location; QUnit.module('Ember.AutoLocation', { teardown() { @@ -65,13 +65,13 @@ QUnit.module('Ember.AutoLocation', { QUnit.test('AutoLocation should return concrete implementation\'s value for `getURL`', function() { expect(1); - var browserLocation = mockBrowserLocation(); - var browserHistory = mockBrowserHistory(); + let browserLocation = mockBrowserLocation(); + let browserHistory = mockBrowserHistory(); location = createLocation(browserLocation, browserHistory); location.detect(); - var concreteImplementation = get(location, 'concreteImplementation'); + let concreteImplementation = get(location, 'concreteImplementation'); concreteImplementation.getURL = function() { return '/lincoln/park'; @@ -83,8 +83,8 @@ QUnit.test('AutoLocation should return concrete implementation\'s value for `get QUnit.test('AutoLocation should use a HistoryLocation instance when pushStates is supported', function() { expect(1); - var browserLocation = mockBrowserLocation(); - var browserHistory = mockBrowserHistory(); + let browserLocation = mockBrowserLocation(); + let browserHistory = mockBrowserHistory(); location = createLocation(browserLocation, browserHistory); location.detect(); @@ -95,7 +95,7 @@ QUnit.test('AutoLocation should use a HistoryLocation instance when pushStates i QUnit.test('AutoLocation should use a HashLocation instance when pushStates are not supported, but hashchange events are and the URL is already in the HashLocation format', function() { expect(1); - var browserLocation = mockBrowserLocation({ + let browserLocation = mockBrowserLocation({ hash: '#/testd' }); @@ -120,7 +120,7 @@ QUnit.test('AutoLocation should use a NoneLocation instance when neither history QUnit.test('AutoLocation should use an index path (i.e. \'/\') without any location.hash as OK for HashLocation', function() { expect(1); - var browserLocation = mockBrowserLocation({ + let browserLocation = mockBrowserLocation({ href: 'http://test.com/', pathname: '/', hash: '', @@ -143,7 +143,7 @@ QUnit.test('AutoLocation should use an index path (i.e. \'/\') without any locat QUnit.test('AutoLocation should transform the URL for hashchange-only browsers viewing a HistoryLocation-formatted path', function() { expect(3); - var browserLocation = mockBrowserLocation({ + let browserLocation = mockBrowserLocation({ hash: '', hostname: 'test.com', href: 'http://test.com/test', @@ -157,7 +157,7 @@ QUnit.test('AutoLocation should transform the URL for hashchange-only browsers v } }); - var location = createLocation(browserLocation); + let location = createLocation(browserLocation); location.global = { onhashchange() { } }; @@ -171,7 +171,7 @@ QUnit.test('AutoLocation should transform the URL for hashchange-only browsers v QUnit.test('AutoLocation should replace the URL for pushState-supported browsers viewing a HashLocation-formatted url', function() { expect(2); - var browserLocation = mockBrowserLocation({ + let browserLocation = mockBrowserLocation({ hash: '#/test', hostname: 'test.com', href: 'http://test.com/#/test', @@ -181,13 +181,13 @@ QUnit.test('AutoLocation should replace the URL for pushState-supported browsers search: '' }); - var browserHistory = mockBrowserHistory({ + let browserHistory = mockBrowserHistory({ replaceState(state, title, path) { equal(path, '/test', 'history.replaceState should be called with normalized HistoryLocation url'); } }); - var location = createLocation(browserLocation, browserHistory); + let location = createLocation(browserLocation, browserHistory); location.detect(); ok(get(location, 'concreteImplementation'), HistoryLocation); @@ -195,8 +195,8 @@ QUnit.test('AutoLocation should replace the URL for pushState-supported browsers QUnit.test('AutoLocation requires any rootURL given to end in a trailing forward slash', function() { expect(3); - var browserLocation = mockBrowserLocation(); - var expectedMsg = /rootURL must end with a trailing forward slash e.g. "\/app\/"/; + let browserLocation = mockBrowserLocation(); + let expectedMsg = /rootURL must end with a trailing forward slash e.g. "\/app\/"/; location = createLocation(browserLocation); location.rootURL = 'app'; @@ -219,24 +219,24 @@ QUnit.test('AutoLocation requires any rootURL given to end in a trailing forward QUnit.test('AutoLocation provides its rootURL to the concreteImplementation', function() { expect(1); - var browserLocation = mockBrowserLocation({ + let browserLocation = mockBrowserLocation({ pathname: '/some/subdir/derp' }); - var browserHistory = mockBrowserHistory(); + let browserHistory = mockBrowserHistory(); location = createLocation(browserLocation, browserHistory); location.rootURL = '/some/subdir/'; location.detect(); - var concreteLocation = get(location, 'concreteImplementation'); + let concreteLocation = get(location, 'concreteImplementation'); equal(location.rootURL, concreteLocation.rootURL); }); QUnit.test('getHistoryPath() should return a normalized, HistoryLocation-supported path', function() { expect(3); - var browserLocation = mockBrowserLocation({ + let browserLocation = mockBrowserLocation({ href: 'http://test.com/app/about?foo=bar#foo', pathname: '/app/about', search: '?foo=bar', @@ -265,7 +265,7 @@ QUnit.test('getHistoryPath() should return a normalized, HistoryLocation-support QUnit.test('getHashPath() should return a normalized, HashLocation-supported path', function() { expect(3); - var browserLocation = mockBrowserLocation({ + let browserLocation = mockBrowserLocation({ href: 'http://test.com/app/#/about?foo=bar#foo', pathname: '/app/', search: '', diff --git a/packages/ember-routing/tests/location/hash_location_test.js b/packages/ember-routing/tests/location/hash_location_test.js index 1eed7826b3b..107e323317e 100644 --- a/packages/ember-routing/tests/location/hash_location_test.js +++ b/packages/ember-routing/tests/location/hash_location_test.js @@ -4,7 +4,7 @@ import run from 'ember-metal/run_loop'; import HashLocation from 'ember-routing/location/hash_location'; import jQuery from 'ember-views/system/jquery'; -var HashTestLocation, location; +let HashTestLocation, location; function createLocation(options) { if (!options) { options = {}; } @@ -14,11 +14,11 @@ function createLocation(options) { function mockBrowserLocation(path) { // This is a neat trick to auto-magically extract the hostname from any // url by letting the browser do the work ;) - var tmp = document.createElement('a'); + let tmp = document.createElement('a'); tmp.href = path; - var protocol = (!tmp.protocol || tmp.protocol === ':') ? 'http' : tmp.protocol; - var pathname = (tmp.pathname.match(/^\//)) ? tmp.pathname : '/' + tmp.pathname; + let protocol = (!tmp.protocol || tmp.protocol === ':') ? 'http' : tmp.protocol; + let pathname = (tmp.pathname.match(/^\//)) ? tmp.pathname : '/' + tmp.pathname; return { hash: tmp.hash, @@ -124,7 +124,7 @@ QUnit.test('HashLocation.replaceURL() correctly replaces to the path with a page QUnit.test('HashLocation.onUpdateURL() registers a hashchange callback', function() { expect(3); - var oldInit = jQuery.fn.init; + let oldInit = jQuery.fn.init; jQuery.fn.init = function(element) { equal(element, window); @@ -142,7 +142,7 @@ QUnit.test('HashLocation.onUpdateURL() registers a hashchange callback', functio willDestroy() {} }); - var guid = guidFor(location); + let guid = guidFor(location); location.onUpdateURL(function () {}); @@ -157,7 +157,7 @@ QUnit.test('HashLocation.onUpdateURL callback executes as expected', function() _location: mockBrowserLocation('/#/foo/bar') }); - var callback = function (param) { + let callback = function (param) { equal(param, '/foo/bar', 'path is passed as param'); }; @@ -176,7 +176,7 @@ QUnit.test('HashLocation.onUpdateURL doesn\'t execute callback if lastSetURL === lastSetURL: '/foo/bar' }); - var callback = function (param) { + let callback = function (param) { ok(false, 'callback should not be called'); }; @@ -196,7 +196,7 @@ QUnit.test('HashLocation.formatURL() prepends a # to the provided string', funct QUnit.test('HashLocation.willDestroy() cleans up hashchange event listener', function() { expect(2); - var oldInit = jQuery.fn.init; + let oldInit = jQuery.fn.init; jQuery.fn.init = function(element) { equal(element, window); @@ -210,7 +210,7 @@ QUnit.test('HashLocation.willDestroy() cleans up hashchange event listener', fun createLocation(); - var guid = guidFor(location); + let guid = guidFor(location); location.willDestroy(); diff --git a/packages/ember-routing/tests/location/history_location_test.js b/packages/ember-routing/tests/location/history_location_test.js index ad36620196b..c518554252f 100644 --- a/packages/ember-routing/tests/location/history_location_test.js +++ b/packages/ember-routing/tests/location/history_location_test.js @@ -2,7 +2,7 @@ import { set } from 'ember-metal/property_set'; import run from 'ember-metal/run_loop'; import HistoryLocation from 'ember-routing/location/history_location'; -var FakeHistory, HistoryTestLocation, location; +let FakeHistory, HistoryTestLocation, location; function createLocation(options) { if (!options) { options = {}; } @@ -12,11 +12,11 @@ function createLocation(options) { function mockBrowserLocation(path) { // This is a neat trick to auto-magically extract the hostname from any // url by letting the browser do the work ;) - var tmp = document.createElement('a'); + let tmp = document.createElement('a'); tmp.href = path; - var protocol = (!tmp.protocol || tmp.protocol === ':') ? 'http' : tmp.protocol; - var pathname = (tmp.pathname.match(/^\//)) ? tmp.pathname : '/' + tmp.pathname; + let protocol = (!tmp.protocol || tmp.protocol === ':') ? 'http' : tmp.protocol; + let pathname = (tmp.pathname.match(/^\//)) ? tmp.pathname : '/' + tmp.pathname; return { hash: tmp.hash, @@ -51,7 +51,7 @@ QUnit.module('Ember.HistoryLocation', { }, teardown() { - run(function() { + run(() => { if (location) { location.destroy(); } }); } diff --git a/packages/ember-routing/tests/location/none_location_test.js b/packages/ember-routing/tests/location/none_location_test.js index 9f17a13863b..e09d50b1cf9 100644 --- a/packages/ember-routing/tests/location/none_location_test.js +++ b/packages/ember-routing/tests/location/none_location_test.js @@ -2,7 +2,7 @@ import { set } from 'ember-metal/property_set'; import run from 'ember-metal/run_loop'; import NoneLocation from 'ember-routing/location/none_location'; -var NoneTestLocation, location; +let NoneTestLocation, location; function createLocation(options) { if (!options) { options = {}; } @@ -15,7 +15,7 @@ QUnit.module('Ember.NoneLocation', { }, teardown() { - run(function() { + run(() => { if (location) { location.destroy(); } }); } diff --git a/packages/ember-routing/tests/location/util_test.js b/packages/ember-routing/tests/location/util_test.js index 6de1b20e2db..f0ebaf3caf6 100644 --- a/packages/ember-routing/tests/location/util_test.js +++ b/packages/ember-routing/tests/location/util_test.js @@ -27,9 +27,9 @@ QUnit.module('Location Utilities'); QUnit.test('replacePath cannot be used to redirect to a different origin', function() { expect(1); - var expectedURL; + let expectedURL; - var location = { + let location = { protocol: 'http:', hostname: 'emberjs.com', port: '1337', @@ -46,7 +46,7 @@ QUnit.test('replacePath cannot be used to redirect to a different origin', funct QUnit.test('getPath() should normalize location.pathname, making sure it always returns a leading slash', function() { expect(2); - var location = mockBrowserLocation({ pathname: 'test' }); + let location = mockBrowserLocation({ pathname: 'test' }); equal(getPath(location), '/test', 'When there is no leading slash, one is added.'); location = mockBrowserLocation({ pathname: '/test' }); @@ -56,14 +56,14 @@ QUnit.test('getPath() should normalize location.pathname, making sure it always QUnit.test('getQuery() should return location.search as-is', function() { expect(1); - var location = mockBrowserLocation({ search: '?foo=bar' }); + let location = mockBrowserLocation({ search: '?foo=bar' }); equal(getQuery(location), '?foo=bar'); }); QUnit.test('getFullPath() should return full pathname including query and hash', function() { expect(1); - var location = mockBrowserLocation({ + let location = mockBrowserLocation({ href: 'http://test.com/about?foo=bar#foo', pathname: '/about', search: '?foo=bar', @@ -121,7 +121,7 @@ QUnit.test("Feature-detecting the history API", function() { true, "returns true for Chrome (not stock browser) on Android 4.0.x" ); - + // Windows Phone UA and History API: https://github.com/Modernizr/Modernizr/issues/1471 equal( supportsHistory( diff --git a/packages/ember-routing/tests/system/controller_for_test.js b/packages/ember-routing/tests/system/controller_for_test.js index ec685079013..aa19f525f8a 100644 --- a/packages/ember-routing/tests/system/controller_for_test.js +++ b/packages/ember-routing/tests/system/controller_for_test.js @@ -11,7 +11,7 @@ import { } from 'ember-routing/system/generate_controller'; import buildOwner from 'container/tests/test-helpers/build-owner'; -var buildInstance = function(namespace) { +function buildInstance(namespace) { let owner = buildOwner(); owner.__registry__.resolver = resolverFor(namespace); @@ -22,27 +22,27 @@ var buildInstance = function(namespace) { owner.register('controller:basic', Controller, { instantiate: false }); return owner; -}; +} function resolverFor(namespace) { return { resolve(fullName) { - var nameParts = fullName.split(':'); - var type = nameParts[0]; - var name = nameParts[1]; + let nameParts = fullName.split(':'); + let type = nameParts[0]; + let name = nameParts[1]; if (name === 'basic') { name = ''; } - var className = classify(name) + classify(type); - var factory = get(namespace, className); + let className = classify(name) + classify(type); + let factory = get(namespace, className); if (factory) { return factory; } } }; } -var appInstance, appController, namespace; +let appInstance, appController, namespace; QUnit.module('Ember.controllerFor', { setup() { @@ -52,7 +52,7 @@ QUnit.module('Ember.controllerFor', { appController = appInstance.lookup('controller:app'); }, teardown() { - run(function () { + run(() => { appInstance.destroy(); namespace.destroy(); }); @@ -60,7 +60,7 @@ QUnit.module('Ember.controllerFor', { }); QUnit.test('controllerFor should lookup for registered controllers', function() { - var controller = controllerFor(appInstance, 'app'); + let controller = controllerFor(appInstance, 'app'); equal(appController, controller, 'should find app controller'); }); @@ -71,7 +71,7 @@ QUnit.module('Ember.generateController', { appInstance = buildInstance(namespace); }, teardown() { - run(function () { + run(() => { appInstance.destroy(); namespace.destroy(); }); @@ -84,14 +84,14 @@ QUnit.test('generateController and generateControllerFactory are properties on t }); QUnit.test('generateController should create Ember.Controller', function() { - var controller = generateController(appInstance, 'home'); + let controller = generateController(appInstance, 'home'); ok(controller instanceof Controller, 'should create controller'); }); QUnit.test('generateController should create App.Controller if provided', function() { - var controller; + let controller; namespace.Controller = Controller.extend(); controller = generateController(appInstance, 'home'); diff --git a/packages/ember-routing/tests/system/dsl_test.js b/packages/ember-routing/tests/system/dsl_test.js index 89ade6025f4..0e4e903cfd4 100644 --- a/packages/ember-routing/tests/system/dsl_test.js +++ b/packages/ember-routing/tests/system/dsl_test.js @@ -1,6 +1,6 @@ import EmberRouter from 'ember-routing/system/router'; -var Router; +let Router; QUnit.module('Ember Router DSL', { setup() { @@ -13,30 +13,30 @@ QUnit.module('Ember Router DSL', { QUnit.test('should fail when using a reserved route name', function() { expectDeprecation('this.resource() is deprecated. Use this.route(\'name\', { resetNamespace: true }, function () {}) instead.'); - var reservedNames = ['array', 'basic', 'object', 'application']; + let reservedNames = ['array', 'basic', 'object', 'application']; expect((reservedNames.length * 2) + 1); - reservedNames.forEach(function(reservedName) { - expectAssertion(function() { + reservedNames.forEach(reservedName => { + expectAssertion(() => { Router = EmberRouter.extend(); Router.map(function() { this.route(reservedName); }); - var router = Router.create(); + let router = Router.create(); router._initRouterJs(); }, '\'' + reservedName + '\' cannot be used as a route name.'); - expectAssertion(function() { + expectAssertion(() => { Router = EmberRouter.extend(); Router.map(function() { this.resource(reservedName); }); - var router = Router.create(); + let router = Router.create(); router._initRouterJs(); }, `'${reservedName}' cannot be used as a route name.`); }); @@ -53,7 +53,7 @@ QUnit.test('should reset namespace if nested with resource', function() { }); }); - var router = Router.create(); + let router = Router.create(); router._initRouterJs(); ok(router.router.recognizer.names['bleep'], 'nested resources do not contain parent name'); @@ -70,7 +70,7 @@ QUnit.test('should retain resource namespace if nested with routes', function() }); }); - var router = Router.create(); + let router = Router.create(); router._initRouterJs(); ok(router.router.recognizer.names['bleep'], 'parent name was used as base of nested routes'); @@ -83,7 +83,7 @@ QUnit.test('should add loading and error routes if _isRouterMapResult is true', this.route('blork'); }); - var router = Router.create({ + let router = Router.create({ _hasModuleBasedResolver() { return true; } }); @@ -99,7 +99,7 @@ QUnit.test('should not add loading and error routes if _isRouterMapResult is fal this.route('blork'); }); - var router = Router.create(); + let router = Router.create(); router._initRouterJs(false); ok(router.router.recognizer.names['blork'], 'main route was created'); diff --git a/packages/ember-routing/tests/system/route_test.js b/packages/ember-routing/tests/system/route_test.js index eb68c1a1ad3..2d7aa395b02 100644 --- a/packages/ember-routing/tests/system/route_test.js +++ b/packages/ember-routing/tests/system/route_test.js @@ -6,7 +6,7 @@ import inject from 'ember-runtime/inject'; import buildOwner from 'container/tests/test-helpers/build-owner'; import { setOwner } from 'container/owner'; -var route, routeOne, routeTwo, lookupHash; +let route, routeOne, routeTwo, lookupHash; function setup() { route = EmberRoute.create(); @@ -24,8 +24,8 @@ QUnit.module('Ember.Route', { QUnit.test('default store utilizes the container to acquire the model factory', function() { expect(4); - var Post = EmberObject.extend(); - var post = {}; + let Post = EmberObject.extend(); + let post = {}; Post.reopenClass({ find(id) { @@ -57,11 +57,11 @@ QUnit.test('\'store\' can be injected by data persistence frameworks', function( let owner = buildOwner(); - var post = { + let post = { id: 1 }; - var Store = EmberObject.extend({ + let Store = EmberObject.extend({ find(type, value) { ok(true, 'injected model was called'); equal(type, 'post', 'correct type was called'); @@ -86,7 +86,7 @@ QUnit.test('assert if \'store.find\' method is not found', function() { runDestroy(route); let owner = buildOwner(); - var Post = EmberObject.extend(); + let Post = EmberObject.extend(); owner.register('route:index', EmberRoute); owner.register('model:post', Post); @@ -149,7 +149,7 @@ QUnit.test('modelFor doesn\'t require the router', function() { QUnit.test('.send just calls an action if the router is absent', function() { expect(7); - var route = EmberRoute.extend({ + let route = EmberRoute.extend({ actions: { returnsTrue(foo, bar) { equal(foo, 1); @@ -172,7 +172,7 @@ QUnit.test('.send just calls an action if the router is absent', function() { QUnit.test('.send just calls an action if the routers internal router property is absent', function() { expect(7); - var route = EmberRoute.extend({ + let route = EmberRoute.extend({ router: { }, actions: { returnsTrue(foo, bar) { @@ -197,7 +197,7 @@ QUnit.test('.send just calls an action if the routers internal router property i QUnit.test('can access `actions` hash via `_actions` [DEPRECATED]', function() { expect(2); - var route = EmberRoute.extend({ + let route = EmberRoute.extend({ actions: { foo: function() { ok(true, 'called foo action'); @@ -249,19 +249,19 @@ QUnit.module('Ember.Route serialize', { }); QUnit.test('returns the models properties if params does not include *_id', function() { - var model = { id: 2, firstName: 'Ned', lastName: 'Ryerson' }; + let model = { id: 2, firstName: 'Ned', lastName: 'Ryerson' }; deepEqual(route.serialize(model, ['firstName', 'lastName']), { firstName: 'Ned', lastName: 'Ryerson' }, 'serialized correctly'); }); QUnit.test('returns model.id if params include *_id', function() { - var model = { id: 2 }; + let model = { id: 2 }; deepEqual(route.serialize(model, ['post_id']), { post_id: 2 }, 'serialized correctly'); }); QUnit.test('returns checks for existence of model.post_id before trying model.id', function() { - var model = { post_id: 3 }; + let model = { post_id: 3 }; deepEqual(route.serialize(model, ['post_id']), { post_id: 3 }, 'serialized correctly'); }); @@ -272,7 +272,7 @@ QUnit.test('returns undefined if model is not set', function() { QUnit.module('Ember.Route interaction', { setup() { - var owner = { + let owner = { lookup(fullName) { return lookupHash[fullName]; } @@ -297,7 +297,7 @@ QUnit.module('Ember.Route interaction', { }); QUnit.test('controllerFor uses route\'s controllerName if specified', function() { - var testController = {}; + let testController = {}; lookupHash['controller:test'] = testController; routeOne.controllerName = 'test'; @@ -316,8 +316,8 @@ QUnit.test('services can be injected into routes', function() { owner.register('service:auth', Service.extend()); - var appRoute = owner.lookup('route:application'); - var authService = owner.lookup('service:auth'); + let appRoute = owner.lookup('route:application'); + let authService = owner.lookup('service:auth'); equal(authService, appRoute.get('authService'), 'service.auth is injected'); }); diff --git a/packages/ember-routing/tests/system/router_test.js b/packages/ember-routing/tests/system/router_test.js index 942ad9ba010..736d9aa5990 100644 --- a/packages/ember-routing/tests/system/router_test.js +++ b/packages/ember-routing/tests/system/router_test.js @@ -7,11 +7,11 @@ import { runDestroy } from 'ember-runtime/tests/utils'; import buildOwner from 'container/tests/test-helpers/build-owner'; import { setOwner } from 'container/owner'; -var owner; +let owner; function createRouter(settings, options = {}) { - var CustomRouter = Router.extend(); - var router = CustomRouter.create(settings); + let CustomRouter = Router.extend(); + let router = CustomRouter.create(settings); if (!options.skipOwner) { setOwner(router, owner); @@ -47,13 +47,13 @@ QUnit.test('can create a router without an owner', function() { }); QUnit.test('should not create a router.js instance upon init', function() { - var router = createRouter(null, { disableSetup: true }); + let router = createRouter(null, { disableSetup: true }); ok(!router.router); }); QUnit.test('should not reify location until setupRouter is called', function() { - var router = createRouter(null, { disableSetup: true }); + let router = createRouter(null, { disableSetup: true }); equal(typeof router.location, 'string', 'location is specified as a string'); router.setupRouter(); @@ -62,8 +62,8 @@ QUnit.test('should not reify location until setupRouter is called', function() { }); QUnit.test('should destroy its location upon destroying the routers owner.', function() { - var router = createRouter(); - var location = router.get('location'); + let router = createRouter(); + let location = router.get('location'); runDestroy(owner); @@ -71,10 +71,10 @@ QUnit.test('should destroy its location upon destroying the routers owner.', fun }); QUnit.test('should instantiate its location with its `rootURL`', function() { - var router = createRouter({ + let router = createRouter({ rootURL: '/rootdir/' }); - var location = router.get('location'); + let location = router.get('location'); equal(location.get('rootURL'), '/rootdir/'); }); @@ -82,9 +82,9 @@ QUnit.test('should instantiate its location with its `rootURL`', function() { QUnit.test('replacePath should be called with the right path', function() { expect(1); - var location = owner.lookup('location:auto'); + let location = owner.lookup('location:auto'); - var browserLocation = { + let browserLocation = { href: 'http://test.com/rootdir/welcome', origin: 'http://test.com', pathname: '/rootdir/welcome', @@ -111,7 +111,7 @@ QUnit.test('Ember.Router._routePath should consume identical prefixes', function expect(8); function routePath(s1, s2, s3) { - var handlerInfos = Array.prototype.slice.call(arguments).map(function(s) { + let handlerInfos = Array.prototype.slice.call(arguments).map(function(s) { return { name: s }; }); handlerInfos.unshift({ name: 'ignored' }); @@ -135,8 +135,8 @@ QUnit.test('Ember.Router._routePath should consume identical prefixes', function QUnit.test('Router should cancel routing setup when the Location class says so via cancelRouterSetup', function() { expect(0); - var router; - var FakeLocation = { + let router; + let FakeLocation = { cancelRouterSetup: true, create() { return this; } }; @@ -157,7 +157,7 @@ QUnit.test('Router should cancel routing setup when the Location class says so v QUnit.test('AutoLocation should replace the url when it\'s not in the preferred format', function() { expect(1); - var location = owner.lookup('location:auto'); + let location = owner.lookup('location:auto'); location.location = { href: 'http://test.com/rootdir/welcome', @@ -183,7 +183,7 @@ QUnit.test('AutoLocation should replace the url when it\'s not in the preferred QUnit.test('Router#handleURL should remove any #hashes before doing URL transition', function() { expect(2); - var router = createRouter({ + let router = createRouter({ _doURLTransition(routerJsMethod, url) { equal(routerJsMethod, 'handleURL'); equal(url, '/foo/bar?time=morphin'); diff --git a/packages/ember-routing/tests/utils_test.js b/packages/ember-routing/tests/utils_test.js index 0e743404741..4fb77ab0f2b 100644 --- a/packages/ember-routing/tests/utils_test.js +++ b/packages/ember-routing/tests/utils_test.js @@ -6,18 +6,18 @@ import { QUnit.module('Routing query parameter utils - normalizeControllerQueryParams'); QUnit.test('returns the cached value if that has been previously set', function(assert) { - var cached = {}; - var params = ['foo']; + let cached = {}; + let params = ['foo']; params._qpMap = cached; - var normalized = normalizeControllerQueryParams(params); + let normalized = normalizeControllerQueryParams(params); equal(cached, normalized, 'cached value returned if previously set'); }); QUnit.test('converts array style into verbose object style', function(assert) { - var paramName = 'foo'; - var params = [paramName]; - var normalized = normalizeControllerQueryParams(params); + let paramName = 'foo'; + let params = [paramName]; + let normalized = normalizeControllerQueryParams(params); ok(normalized[paramName], 'turns the query param name into key'); equal(normalized[paramName].as, null, 'includes a blank alias in \'as\' key'); @@ -25,9 +25,9 @@ QUnit.test('converts array style into verbose object style', function(assert) { }); QUnit.test('converts object stlye [{foo: \'an_alias\'}]', function(assert) { - var paramName = 'foo'; - var params = [{ 'foo': 'an_alias' }]; - var normalized = normalizeControllerQueryParams(params); + let paramName = 'foo'; + let params = [{ 'foo': 'an_alias' }]; + let normalized = normalizeControllerQueryParams(params); ok(normalized[paramName], 'retains the query param name as key'); equal(normalized[paramName].as, 'an_alias', 'includes the provided alias in \'as\' key'); @@ -35,9 +35,9 @@ QUnit.test('converts object stlye [{foo: \'an_alias\'}]', function(assert) { }); QUnit.test('retains maximally verbose object stlye [{foo: {as: \'foo\'}}]', function(assert) { - var paramName = 'foo'; - var params = [{ 'foo': { as: 'an_alias' } }]; - var normalized = normalizeControllerQueryParams(params); + let paramName = 'foo'; + let params = [{ 'foo': { as: 'an_alias' } }]; + let normalized = normalizeControllerQueryParams(params); ok(normalized[paramName], 'retains the query param name as key'); equal(normalized[paramName].as, 'an_alias', 'includes the provided alias in \'as\' key'); diff --git a/packages/ember-runtime/lib/compare.js b/packages/ember-runtime/lib/compare.js index ac668e95935..827adf33b46 100644 --- a/packages/ember-runtime/lib/compare.js +++ b/packages/ember-runtime/lib/compare.js @@ -1,7 +1,7 @@ import { typeOf } from 'ember-runtime/utils'; import Comparable from 'ember-runtime/mixins/comparable'; -var TYPE_ORDER = { +const TYPE_ORDER = { 'undefined': 0, 'null': 1, 'boolean': 2, @@ -33,7 +33,7 @@ var TYPE_ORDER = { // `._________`-. `. `.___ // SSt `------'` function spaceship(a, b) { - var diff = a - b; + let diff = a - b; return (diff > 0) - (diff < 0); } @@ -83,8 +83,8 @@ export default function compare(v, w) { return 0; } - var type1 = typeOf(v); - var type2 = typeOf(w); + let type1 = typeOf(v); + let type2 = typeOf(w); if (Comparable) { if (type1 === 'instance' && Comparable.detect(v) && v.constructor.compare) { @@ -96,7 +96,7 @@ export default function compare(v, w) { } } - var res = spaceship(TYPE_ORDER[type1], TYPE_ORDER[type2]); + let res = spaceship(TYPE_ORDER[type1], TYPE_ORDER[type2]); if (res !== 0) { return res; @@ -112,12 +112,12 @@ export default function compare(v, w) { return spaceship(v.localeCompare(w), 0); case 'array': - var vLen = v.length; - var wLen = w.length; - var len = Math.min(vLen, wLen); + let vLen = v.length; + let wLen = w.length; + let len = Math.min(vLen, wLen); - for (var i = 0; i < len; i++) { - var r = compare(v[i], w[i]); + for (let i = 0; i < len; i++) { + let r = compare(v[i], w[i]); if (r !== 0) { return r; } diff --git a/packages/ember-runtime/lib/computed/computed_macros.js b/packages/ember-runtime/lib/computed/computed_macros.js index a01043cff6b..d7969f492ea 100644 --- a/packages/ember-runtime/lib/computed/computed_macros.js +++ b/packages/ember-runtime/lib/computed/computed_macros.js @@ -13,7 +13,7 @@ import expandProperties from 'ember-metal/expand_properties'; */ function expandPropertiesToArray(predicateName, properties) { - var expandedProperties = []; + let expandedProperties = []; function extractProperty(entry) { expandedProperties.push(entry); @@ -31,13 +31,13 @@ function expandPropertiesToArray(predicateName, properties) { function generateComputedWithPredicate(name, predicate) { return function(...properties) { - var expandedProperties = expandPropertiesToArray(name, properties); + let expandedProperties = expandPropertiesToArray(name, properties); - var computedFunc = computed(function() { - var lastIdx = expandedProperties.length - 1; + let computedFunc = computed(function() { + let lastIdx = expandedProperties.length - 1; - for (var i = 0; i < lastIdx; i++) { - var value = get(this, expandedProperties[i]); + for (let i = 0; i < lastIdx; i++) { + let value = get(this, expandedProperties[i]); if (!predicate(value)) { return value; } @@ -57,11 +57,11 @@ function generateComputedWithPredicate(name, predicate) { Example ```javascript - var ToDoList = Ember.Object.extend({ + let ToDoList = Ember.Object.extend({ isDone: Ember.computed.empty('todos') }); - var todoList = ToDoList.create({ + let todoList = ToDoList.create({ todos: ['Unit Test', 'Documentation', 'Release'] }); @@ -91,11 +91,11 @@ export function empty(dependentKey) { Example ```javascript - var Hamster = Ember.Object.extend({ + let Hamster = Ember.Object.extend({ hasStuff: Ember.computed.notEmpty('backpack') }); - var hamster = Hamster.create({ backpack: ['Food', 'Sleeping Bag', 'Tent'] }); + let hamster = Hamster.create({ backpack: ['Food', 'Sleeping Bag', 'Tent'] }); hamster.get('hasStuff'); // true hamster.get('backpack').clear(); // [] @@ -123,11 +123,11 @@ export function notEmpty(dependentKey) { Example ```javascript - var Hamster = Ember.Object.extend({ + let Hamster = Ember.Object.extend({ isHungry: Ember.computed.none('food') }); - var hamster = Hamster.create(); + let hamster = Hamster.create(); hamster.get('isHungry'); // true hamster.set('food', 'Banana'); @@ -156,11 +156,11 @@ export function none(dependentKey) { Example ```javascript - var User = Ember.Object.extend({ + let User = Ember.Object.extend({ isAnonymous: Ember.computed.not('loggedIn') }); - var user = User.create({loggedIn: false}); + let user = User.create({loggedIn: false}); user.get('isAnonymous'); // true user.set('loggedIn', true); @@ -185,11 +185,11 @@ export function not(dependentKey) { into a boolean value. ```javascript - var Hamster = Ember.Object.extend({ + let Hamster = Ember.Object.extend({ hasBananas: Ember.computed.bool('numBananas') }); - var hamster = Hamster.create(); + let hamster = Hamster.create(); hamster.get('hasBananas'); // false hamster.set('numBananas', 0); @@ -221,11 +221,11 @@ export function bool(dependentKey) { Example ```javascript - var User = Ember.Object.extend({ + let User = Ember.Object.extend({ hasValidEmail: Ember.computed.match('email', /^.+@.+\..+$/) }); - var user = User.create({loggedIn: false}); + let user = User.create({loggedIn: false}); user.get('hasValidEmail'); // false user.set('email', ''); @@ -244,7 +244,7 @@ export function bool(dependentKey) { */ export function match(dependentKey, regexp) { return computed(dependentKey, function() { - var value = get(this, dependentKey); + let value = get(this, dependentKey); return typeof value === 'string' ? regexp.test(value) : false; }); @@ -257,11 +257,11 @@ export function match(dependentKey, regexp) { Example ```javascript - var Hamster = Ember.Object.extend({ + let Hamster = Ember.Object.extend({ napTime: Ember.computed.equal('state', 'sleepy') }); - var hamster = Hamster.create(); + let hamster = Hamster.create(); hamster.get('napTime'); // false hamster.set('state', 'sleepy'); @@ -291,11 +291,11 @@ export function equal(dependentKey, value) { Example ```javascript - var Hamster = Ember.Object.extend({ + let Hamster = Ember.Object.extend({ hasTooManyBananas: Ember.computed.gt('numBananas', 10) }); - var hamster = Hamster.create(); + let hamster = Hamster.create(); hamster.get('hasTooManyBananas'); // false hamster.set('numBananas', 3); @@ -325,11 +325,11 @@ export function gt(dependentKey, value) { Example ```javascript - var Hamster = Ember.Object.extend({ + let Hamster = Ember.Object.extend({ hasTooManyBananas: Ember.computed.gte('numBananas', 10) }); - var hamster = Hamster.create(); + let hamster = Hamster.create(); hamster.get('hasTooManyBananas'); // false hamster.set('numBananas', 3); @@ -359,11 +359,11 @@ export function gte(dependentKey, value) { Example ```javascript - var Hamster = Ember.Object.extend({ + let Hamster = Ember.Object.extend({ needsMoreBananas: Ember.computed.lt('numBananas', 3) }); - var hamster = Hamster.create(); + let hamster = Hamster.create(); hamster.get('needsMoreBananas'); // true hamster.set('numBananas', 3); @@ -393,11 +393,11 @@ export function lt(dependentKey, value) { Example ```javascript - var Hamster = Ember.Object.extend({ + let Hamster = Ember.Object.extend({ needsMoreBananas: Ember.computed.lte('numBananas', 3) }); - var hamster = Hamster.create(); + let hamster = Hamster.create(); hamster.get('needsMoreBananas'); // true hamster.set('numBananas', 5); @@ -432,12 +432,12 @@ export function lte(dependentKey, value) { Example ```javascript - var Hamster = Ember.Object.extend({ + let Hamster = Ember.Object.extend({ readyForCamp: Ember.computed.and('hasTent', 'hasBackpack'), readyForHike: Ember.computed.and('hasWalkingStick', 'hasBackpack') }); - var tomster = Hamster.create(); + let tomster = Hamster.create(); tomster.get('readyForCamp'); // false tomster.set('hasTent', true); @@ -457,7 +457,7 @@ export function lte(dependentKey, value) { a logical `and` on the values of all the original values for properties. @public */ -export var and = generateComputedWithPredicate('and', function(value) { +export let and = generateComputedWithPredicate('and', function(value) { return value; }); @@ -473,12 +473,12 @@ export var and = generateComputedWithPredicate('and', function(value) { Example ```javascript - var Hamster = Ember.Object.extend({ + let Hamster = Ember.Object.extend({ readyForRain: Ember.computed.or('hasJacket', 'hasUmbrella'), readyForBeach: Ember.computed.or('{hasSunscreen,hasUmbrella}') }); - var tomster = Hamster.create(); + let tomster = Hamster.create(); tomster.get('readyForRain'); // undefined tomster.set('hasUmbrella', true); @@ -496,7 +496,7 @@ export var and = generateComputedWithPredicate('and', function(value) { a logical `or` on the values of all the original values for properties. @public */ -export var or = generateComputedWithPredicate('or', function(value) { +export let or = generateComputedWithPredicate('or', function(value) { return !value; }); @@ -506,12 +506,12 @@ export var or = generateComputedWithPredicate('or', function(value) { though they were called on the original property. ```javascript - var Person = Ember.Object.extend({ + let Person = Ember.Object.extend({ name: 'Alex Matchneer', nomen: Ember.computed.alias('name') }); - var alex = Person.create(); + let alex = Person.create(); alex.get('nomen'); // 'Alex Matchneer' alex.get('name'); // 'Alex Matchneer' @@ -538,13 +538,13 @@ export var or = generateComputedWithPredicate('or', function(value) { Example ```javascript - var User = Ember.Object.extend({ + let User = Ember.Object.extend({ firstName: null, lastName: null, nickName: Ember.computed.oneWay('firstName') }); - var teddy = User.create({ + let teddy = User.create({ firstName: 'Teddy', lastName: 'Zeenny' }); @@ -587,13 +587,13 @@ export function oneWay(dependentKey) { Example ```javascript - var User = Ember.Object.extend({ + let User = Ember.Object.extend({ firstName: null, lastName: null, nickName: Ember.computed.readOnly('firstName') }); - var teddy = User.create({ + let teddy = User.create({ firstName: 'Teddy', lastName: 'Zeenny' }); @@ -623,14 +623,14 @@ export function readOnly(dependentKey) { print a deprecation warning. ```javascript - var Hamster = Ember.Object.extend({ + let Hamster = Ember.Object.extend({ bananaCount: Ember.computed.deprecatingAlias('cavendishCount', { id: 'hamster.deprecate-banana', until: '3.0.0' }) }); - var hamster = Hamster.create(); + let hamster = Hamster.create(); hamster.set('bananaCount', 5); // Prints a deprecation warning. hamster.get('cavendishCount'); // 5 diff --git a/packages/ember-runtime/lib/computed/reduce_computed_macros.js b/packages/ember-runtime/lib/computed/reduce_computed_macros.js index 2d12a72e637..97615c983ca 100644 --- a/packages/ember-runtime/lib/computed/reduce_computed_macros.js +++ b/packages/ember-runtime/lib/computed/reduce_computed_macros.js @@ -32,7 +32,7 @@ function reduceMacro(dependentKey, callback, initialValue) { function arrayMacro(dependentKey, callback) { // This is a bit ugly - var propertyName; + let propertyName; if (/@each/.test(dependentKey)) { propertyName = dependentKey.replace(/\.@each.*$/, ''); } else { @@ -41,7 +41,7 @@ function arrayMacro(dependentKey, callback) { } return computed(dependentKey, function() { - var value = get(this, propertyName); + let value = get(this, propertyName); if (isArray(value)) { return emberA(callback.call(this, value)); } else { @@ -51,7 +51,7 @@ function arrayMacro(dependentKey, callback) { } function multiArrayMacro(dependentKeys, callback) { - var args = dependentKeys.map(key => `${key}.[]`); + let args = dependentKeys.map(key => `${key}.[]`); args.push(function() { return emberA(callback.call(this, dependentKeys)); @@ -81,12 +81,12 @@ export function sum(dependentKey) { array is empty. ```javascript - var Person = Ember.Object.extend({ + let Person = Ember.Object.extend({ childAges: Ember.computed.mapBy('children', 'age'), maxChildAge: Ember.computed.max('childAges') }); - var lordByron = Person.create({ children: [] }); + let lordByron = Person.create({ children: [] }); lordByron.get('maxChildAge'); // -Infinity lordByron.get('children').pushObject({ @@ -126,12 +126,12 @@ export function max(dependentKey) { array is empty. ```javascript - var Person = Ember.Object.extend({ + let Person = Ember.Object.extend({ childAges: Ember.computed.mapBy('children', 'age'), minChildAge: Ember.computed.min('childAges') }); - var lordByron = Person.create({ children: [] }); + let lordByron = Person.create({ children: [] }); lordByron.get('minChildAge'); // Infinity lordByron.get('children').pushObject({ @@ -179,13 +179,13 @@ export function min(dependentKey) { Example ```javascript - var Hamster = Ember.Object.extend({ + let Hamster = Ember.Object.extend({ excitingChores: Ember.computed.map('chores', function(chore, index) { return chore.toUpperCase() + '!'; }) }); - var hamster = Hamster.create({ + let hamster = Hamster.create({ chores: ['clean', 'write more unit tests'] }); @@ -209,11 +209,11 @@ export function map(dependentKey, callback) { Returns an array mapped to the specified key. ```javascript - var Person = Ember.Object.extend({ + let Person = Ember.Object.extend({ childAges: Ember.computed.mapBy('children', 'age') }); - var lordByron = Person.create({ children: [] }); + let lordByron = Person.create({ children: [] }); lordByron.get('childAges'); // [] lordByron.get('children').pushObject({ name: 'Augusta Ada Byron', age: 7 }); @@ -258,13 +258,13 @@ export function mapBy(dependentKey, propertyKey) { ``` ```javascript - var Hamster = Ember.Object.extend({ + let Hamster = Ember.Object.extend({ remainingChores: Ember.computed.filter('chores', function(chore, index, array) { return !chore.done; }) }); - var hamster = Hamster.create({ + let hamster = Hamster.create({ chores: [ { name: 'cook', done: true }, { name: 'clean', done: true }, @@ -292,11 +292,11 @@ export function filter(dependentKey, callback) { Filters the array by the property and value ```javascript - var Hamster = Ember.Object.extend({ + let Hamster = Ember.Object.extend({ remainingChores: Ember.computed.filterBy('chores', 'done', false) }); - var hamster = Hamster.create({ + let hamster = Hamster.create({ chores: [ { name: 'cook', done: true }, { name: 'clean', done: true }, @@ -316,16 +316,12 @@ export function filter(dependentKey, callback) { @public */ export function filterBy(dependentKey, propertyKey, value) { - var callback; + let callback; if (arguments.length === 2) { - callback = function(item) { - return get(item, propertyKey); - }; + callback = (item) => get(item, propertyKey); } else { - callback = function(item) { - return get(item, propertyKey) === value; - }; + callback = (item) => get(item, propertyKey) === value; } return filter(`${dependentKey}.@each.${propertyKey}`, callback); @@ -338,11 +334,11 @@ export function filterBy(dependentKey, propertyKey, value) { Example ```javascript - var Hamster = Ember.Object.extend({ + let Hamster = Ember.Object.extend({ uniqueFruits: Ember.computed.uniq('fruits') }); - var hamster = Hamster.create({ + let hamster = Hamster.create({ fruits: [ 'banana', 'grape', @@ -363,10 +359,10 @@ export function filterBy(dependentKey, propertyKey, value) { */ export function uniq(...args) { return multiArrayMacro(args, function(dependentKeys) { - var uniq = emberA(); + let uniq = emberA(); dependentKeys.forEach(dependentKey => { - var value = get(this, dependentKey); + let value = get(this, dependentKey); if (isArray(value)) { value.forEach(item => { if (uniq.indexOf(item) === -1) { @@ -385,10 +381,10 @@ export function uniq(...args) { elements from an array, with uniqueness determined by specific key. Example ```javascript - var Hamster = Ember.Object.extend({ + let Hamster = Ember.Object.extend({ uniqueFruits: Ember.computed.uniqBy('fruits', 'id') }); - var hamster = Hamster.create({ + let hamster = Hamster.create({ fruits: [ { id: 1, 'banana' }, { id: 2, 'grape' }, @@ -408,12 +404,12 @@ export function uniq(...args) { */ export function uniqBy(dependentKey, propertyKey) { return computed(`${dependentKey}.[]`, function() { - var uniq = emberA(); - var seen = new EmptyObject(); - var list = get(this, dependentKey); + let uniq = emberA(); + let seen = new EmptyObject(); + let list = get(this, dependentKey); if (isArray(list)) { list.forEach(item => { - var guid = guidFor(get(item, propertyKey)); + let guid = guidFor(get(item, propertyKey)); if (!(guid in seen)) { seen[guid] = true; uniq.push(item); @@ -434,7 +430,7 @@ export function uniqBy(dependentKey, propertyKey) { unique elements from the dependent array @public */ -export var union = uniq; +export let union = uniq; /** A computed property which returns a new array with all the duplicated @@ -443,7 +439,7 @@ export var union = uniq; Example ```javascript - var obj = Ember.Object.extend({ + let obj = Ember.Object.extend({ friendsInCommon: Ember.computed.intersect('adaFriends', 'charlesFriends') }).create({ adaFriends: ['Charles Babbage', 'John Hobhouse', 'William King', 'Mary Somerville'], @@ -462,17 +458,17 @@ export var union = uniq; */ export function intersect(...args) { return multiArrayMacro(args, function(dependentKeys) { - var arrays = dependentKeys.map(dependentKey => { - var array = get(this, dependentKey); + let arrays = dependentKeys.map(dependentKey => { + let array = get(this, dependentKey); return isArray(array) ? array : []; }); - var results = arrays.pop().filter(candidate => { - for (var i = 0; i < arrays.length; i++) { - var found = false; - var array = arrays[i]; - for (var j = 0; j < array.length; j++) { + let results = arrays.pop().filter(candidate => { + for (let i = 0; i < arrays.length; i++) { + let found = false; + let array = arrays[i]; + for (let j = 0; j < array.length; j++) { if (array[j] === candidate) { found = true; break; @@ -499,12 +495,12 @@ export function intersect(...args) { Example ```javascript - var Hamster = Ember.Object.extend({ + let Hamster = Ember.Object.extend({ likes: ['banana', 'grape', 'kale'], wants: Ember.computed.setDiff('likes', 'fruits') }); - var hamster = Hamster.create({ + let hamster = Hamster.create({ fruits: [ 'grape', 'kale', @@ -529,8 +525,8 @@ export function setDiff(setAProperty, setBProperty) { } return computed(`${setAProperty}.[]`, `${setBProperty}.[]`, function() { - var setA = this.get(setAProperty); - var setB = this.get(setBProperty); + let setA = this.get(setAProperty); + let setB = this.get(setBProperty); if (!isArray(setA)) { return emberA(); } if (!isArray(setB)) { return emberA(setA); } @@ -546,11 +542,11 @@ export function setDiff(setAProperty, setBProperty) { Example ```javascript - var Hamster = Ember.Object.extend({ + let Hamster = Ember.Object.extend({ clothes: Ember.computed.collect('hat', 'shirt') }); - var hamster = Hamster.create(); + let hamster = Hamster.create(); hamster.get('clothes'); // [null, null] hamster.set('hat', 'Camp Hat'); @@ -567,9 +563,9 @@ export function setDiff(setAProperty, setBProperty) { */ export function collect(...dependentKeys) { return multiArrayMacro(dependentKeys, function() { - var properties = getProperties(this, dependentKeys); - var res = emberA(); - for (var key in properties) { + let properties = getProperties(this, dependentKeys); + let res = emberA(); + for (let key in properties) { if (properties.hasOwnProperty(key)) { if (isNone(properties[key])) { res.push(null); @@ -606,7 +602,7 @@ export function collect(...dependentKeys) { Example ```javascript - var ToDoList = Ember.Object.extend({ + let ToDoList = Ember.Object.extend({ // using standard ascending sort todosSorting: ['name'], sortedTodos: Ember.computed.sort('todos', 'todosSorting'), @@ -627,7 +623,7 @@ export function collect(...dependentKeys) { }) }); - var todoList = ToDoList.create({todos: [ + let todoList = ToDoList.create({todos: [ { name: 'Unit Test', priority: 2 }, { name: 'Documentation', priority: 3 }, { name: 'Release', priority: 1 } @@ -686,9 +682,7 @@ function propertySort(itemsKey, sortPropertiesKey) { let activeObservers = activeObserversMap.get(this); if (activeObservers) { - activeObservers.forEach(args => { - removeObserver.apply(null, args); - }); + activeObservers.forEach(args => removeObserver.apply(null, args)); } function sortPropertyDidChange() { diff --git a/packages/ember-runtime/lib/controllers/controller.js b/packages/ember-runtime/lib/controllers/controller.js index 2764a40230f..2b0b2a52a36 100644 --- a/packages/ember-runtime/lib/controllers/controller.js +++ b/packages/ember-runtime/lib/controllers/controller.js @@ -16,7 +16,7 @@ import { deprecateUnderscoreActions } from 'ember-runtime/mixins/action_handler' @uses Ember.ControllerMixin @public */ -var Controller = EmberObject.extend(Mixin); +const Controller = EmberObject.extend(Mixin); deprecateUnderscoreActions(Controller); diff --git a/packages/ember-runtime/lib/copy.js b/packages/ember-runtime/lib/copy.js index f35b4e75bd5..48fb1cb8390 100644 --- a/packages/ember-runtime/lib/copy.js +++ b/packages/ember-runtime/lib/copy.js @@ -3,7 +3,7 @@ import EmberObject from 'ember-runtime/system/object'; import Copyable from 'ember-runtime/mixins/copyable'; function _copy(obj, deep, seen, copies) { - var ret, loc, key; + let ret, loc, key; // primitive data types are immutable, just return them. if (typeof obj !== 'object' || obj === null) { diff --git a/packages/ember-runtime/lib/ext/function.js b/packages/ember-runtime/lib/ext/function.js index 18d70590b73..51338d64ad3 100644 --- a/packages/ember-runtime/lib/ext/function.js +++ b/packages/ember-runtime/lib/ext/function.js @@ -29,7 +29,7 @@ if (ENV.EXTEND_PROTOTYPES.Function) { }.property() // Call this flag to mark the function as a property }); - var president = MyApp.President.create({ + let president = MyApp.President.create({ firstName: 'Barack', lastName: 'Obama' }); @@ -72,7 +72,7 @@ if (ENV.EXTEND_PROTOTYPES.Function) { @public */ FunctionPrototype.property = function () { - var ret = computed(this); + let ret = computed(this); // ComputedProperty.prototype.property expands properties; no need for us to // do so here. return ret.property(...arguments); @@ -114,7 +114,7 @@ if (ENV.EXTEND_PROTOTYPES.Function) { 'Immediate observers must observe internal properties only, ' + 'not properties on other objects.', function checkIsInternalProperty() { - for (var i = 0; i < arguments.length; i++) { + for (let i = 0; i < arguments.length; i++) { if (arguments[i].indexOf('.') !== -1) { return false; } @@ -182,7 +182,7 @@ if (ENV.EXTEND_PROTOTYPES.Function) { @public */ FunctionPrototype.on = function () { - var events = a_slice.call(arguments); + let events = a_slice.call(arguments); this.__ember_listens__ = events; return this; diff --git a/packages/ember-runtime/lib/inject.js b/packages/ember-runtime/lib/inject.js index a99882ee34a..373cb838ec2 100644 --- a/packages/ember-runtime/lib/inject.js +++ b/packages/ember-runtime/lib/inject.js @@ -14,7 +14,7 @@ export default function inject() { } // Dictionary of injection validations by type, added to by `createInjectionHelper` -var typeValidators = {}; +const typeValidators = {}; /** This method allows other Ember modules to register injection helpers for a @@ -47,20 +47,19 @@ export function createInjectionHelper(type, validator) { @param {Object} factory The factory object */ export function validatePropertyInjections(factory) { - var proto = factory.proto(); - var types = []; - var key, desc, validator, i; + let proto = factory.proto(); + let types = []; - for (key in proto) { - desc = proto[key]; + for (let key in proto) { + let desc = proto[key]; if (desc instanceof InjectedProperty && types.indexOf(desc.type) === -1) { types.push(desc.type); } } if (types.length) { - for (i = 0; i < types.length; i++) { - validator = typeValidators[types[i]]; + for (let i = 0; i < types.length; i++) { + let validator = typeValidators[types[i]]; if (typeof validator === 'function') { validator(factory); diff --git a/packages/ember-runtime/lib/mixins/-proxy.js b/packages/ember-runtime/lib/mixins/-proxy.js index 2a0d618cacd..a0b58fde6d6 100644 --- a/packages/ember-runtime/lib/mixins/-proxy.js +++ b/packages/ember-runtime/lib/mixins/-proxy.js @@ -29,13 +29,13 @@ export function isProxy(value) { } function contentPropertyWillChange(content, contentKey) { - var key = contentKey.slice(8); // remove "content." + let key = contentKey.slice(8); // remove "content." if (key in this) { return; } // if shadowed in proxy propertyWillChange(this, key); } function contentPropertyDidChange(content, contentKey) { - var key = contentKey.slice(8); // remove "content." + let key = contentKey.slice(8); // remove "content." if (key in this) { return; } // if shadowed in proxy propertyDidChange(this, key); } @@ -69,19 +69,19 @@ export default Mixin.create({ _debugContainerKey: null, willWatchProperty(key) { - var contentKey = 'content.' + key; + let contentKey = 'content.' + key; _addBeforeObserver(this, contentKey, null, contentPropertyWillChange); addObserver(this, contentKey, null, contentPropertyDidChange); }, didUnwatchProperty(key) { - var contentKey = 'content.' + key; + let contentKey = 'content.' + key; _removeBeforeObserver(this, contentKey, null, contentPropertyWillChange); removeObserver(this, contentKey, null, contentPropertyDidChange); }, unknownProperty(key) { - var content = get(this, 'content'); + let content = get(this, 'content'); if (content) { deprecate( `You attempted to access \`${key}\` from \`${this}\`, but object proxying is deprecated. Please use \`model.${key}\` instead.`, @@ -93,7 +93,7 @@ export default Mixin.create({ }, setUnknownProperty(key, value) { - var m = meta(this); + let m = meta(this); if (m.proto === this) { // if marked as prototype then just defineProperty // rather than delegate @@ -101,7 +101,7 @@ export default Mixin.create({ return value; } - var content = get(this, 'content'); + let content = get(this, 'content'); assert(`Cannot delegate set('${key}', ${value}) to the \'content\' property of object proxy ${this}: its 'content' is undefined.`, content); deprecate( @@ -111,5 +111,4 @@ export default Mixin.create({ ); return set(content, key, value); } - }); diff --git a/packages/ember-runtime/lib/mixins/action_handler.js b/packages/ember-runtime/lib/mixins/action_handler.js index ba538c3e402..6b20309619d 100644 --- a/packages/ember-runtime/lib/mixins/action_handler.js +++ b/packages/ember-runtime/lib/mixins/action_handler.js @@ -18,7 +18,7 @@ import { get } from 'ember-metal/property_get'; @namespace Ember @private */ -var ActionHandler = Mixin.create({ +const ActionHandler = Mixin.create({ mergedProperties: ['actions'], /** @@ -38,7 +38,7 @@ var ActionHandler = Mixin.create({ ```js App.CanDisplayBanner = Ember.Mixin.create({ actions: { - displayBanner: function(msg) { + displayBanner(msg) { // ... } } @@ -46,7 +46,7 @@ var ActionHandler = Mixin.create({ App.WelcomeRoute = Ember.Route.extend(App.CanDisplayBanner, { actions: { - playMusic: function() { + playMusic() { // ... } } @@ -66,7 +66,7 @@ var ActionHandler = Mixin.create({ ```js App.SongRoute = Ember.Route.extend({ actions: { - myAction: function() { + myAction() { this.controllerFor("song"); this.transitionTo("other.route"); ... @@ -84,7 +84,7 @@ var ActionHandler = Mixin.create({ ```js App.DebugRoute = Ember.Mixin.create({ actions: { - debugRouteInformation: function() { + debugRouteInformation() { console.debug("trololo"); } } @@ -92,7 +92,7 @@ var ActionHandler = Mixin.create({ App.AnnoyingDebugRoute = Ember.Route.extend(App.DebugRoute, { actions: { - debugRouteInformation: function() { + debugRouteInformation() { // also call the debugRouteInformation of mixed in App.DebugRoute this._super(...arguments); @@ -125,7 +125,7 @@ var ActionHandler = Mixin.create({ App.AlbumSongRoute = Ember.Route.extend({ actions: { - startPlaying: function() { + startPlaying() { // ... if (actionShouldAlsoBeTriggeredOnParentRoute) { @@ -157,10 +157,10 @@ var ActionHandler = Mixin.create({ ```js App.WelcomeRoute = Ember.Route.extend({ actions: { - playTheme: function() { + playTheme() { this.send('playMusic', 'theme.mp3'); }, - playMusic: function(track) { + playMusic(track) { // ... } } @@ -173,17 +173,16 @@ var ActionHandler = Mixin.create({ @public */ send(actionName, ...args) { - var target; + let target; if (this.actions && this.actions[actionName]) { - var shouldBubble = this.actions[actionName].apply(this, args) === true; + let shouldBubble = this.actions[actionName].apply(this, args) === true; if (!shouldBubble) { return; } } if (target = get(this, 'target')) { assert( - 'The `target` for ' + this + ' (' + target + - ') does not have a `send` method', + 'The `target` for ' + this + ' (' + target + ') does not have a `send` method', typeof target.send === 'function' ); target.send(...arguments); diff --git a/packages/ember-runtime/lib/mixins/array.js b/packages/ember-runtime/lib/mixins/array.js index 43fbbf40189..1b539910f62 100644 --- a/packages/ember-runtime/lib/mixins/array.js +++ b/packages/ember-runtime/lib/mixins/array.js @@ -34,9 +34,9 @@ import { deprecate } from 'ember-metal/debug'; import isEnabled from 'ember-metal/features'; function arrayObserversHelper(obj, target, opts, operation, notify) { - var willChange = (opts && opts.willChange) || 'arrayWillChange'; - var didChange = (opts && opts.didChange) || 'arrayDidChange'; - var hasObservers = get(obj, 'hasArrayObservers'); + let willChange = (opts && opts.willChange) || 'arrayWillChange'; + let didChange = (opts && opts.didChange) || 'arrayDidChange'; + let hasObservers = get(obj, 'hasArrayObservers'); if (hasObservers === notify) { propertyWillChange(obj, 'hasArrayObservers'); @@ -114,7 +114,7 @@ export function isEmberArray(obj) { @since Ember 0.9.0 @public */ -var ArrayMixin = Mixin.create(Enumerable, { +const ArrayMixin = Mixin.create(Enumerable, { [EMBER_ARRAY]: true, @@ -139,7 +139,7 @@ var ArrayMixin = Mixin.create(Enumerable, { yourself. ```javascript - var arr = ['a', 'b', 'c', 'd']; + let arr = ['a', 'b', 'c', 'd']; arr.objectAt(0); // 'a' arr.objectAt(3); // 'd' @@ -165,7 +165,7 @@ var ArrayMixin = Mixin.create(Enumerable, { This returns the objects at the specified indexes, using `objectAt`. ```javascript - var arr = ['a', 'b', 'c', 'd']; + let arr = ['a', 'b', 'c', 'd']; arr.objectsAt([0, 1, 2]); // ['a', 'b', 'c'] arr.objectsAt([2, 3, 4]); // ['c', 'd', undefined] @@ -234,7 +234,7 @@ var ArrayMixin = Mixin.create(Enumerable, { slice. ```javascript - var arr = ['red', 'green', 'blue']; + let arr = ['red', 'green', 'blue']; arr.slice(0); // ['red', 'green', 'blue'] arr.slice(0, 2); // ['red', 'green'] @@ -248,8 +248,8 @@ var ArrayMixin = Mixin.create(Enumerable, { @public */ slice(beginIndex, endIndex) { - var ret = Ember.A(); - var length = get(this, 'length'); + let ret = Ember.A(); + let length = get(this, 'length'); if (isNone(beginIndex)) { beginIndex = 0; @@ -281,7 +281,7 @@ var ArrayMixin = Mixin.create(Enumerable, { the end of the array. Returns -1 if no match is found. ```javascript - var arr = ['a', 'b', 'c', 'd', 'a']; + let arr = ['a', 'b', 'c', 'd', 'a']; arr.indexOf('a'); // 0 arr.indexOf('z'); // -1 @@ -298,8 +298,7 @@ var ArrayMixin = Mixin.create(Enumerable, { @public */ indexOf(object, startAt) { - var len = get(this, 'length'); - var idx; + let len = get(this, 'length'); if (startAt === undefined) { startAt = 0; @@ -309,7 +308,7 @@ var ArrayMixin = Mixin.create(Enumerable, { startAt += len; } - for (idx = startAt; idx < len; idx++) { + for (let idx = startAt; idx < len; idx++) { if (objectAt(this, idx) === object) { return idx; } @@ -325,7 +324,7 @@ var ArrayMixin = Mixin.create(Enumerable, { from the end of the array. Returns -1 if no match is found. ```javascript - var arr = ['a', 'b', 'c', 'd', 'a']; + let arr = ['a', 'b', 'c', 'd', 'a']; arr.lastIndexOf('a'); // 4 arr.lastIndexOf('z'); // -1 @@ -342,8 +341,7 @@ var ArrayMixin = Mixin.create(Enumerable, { @public */ lastIndexOf(object, startAt) { - var len = get(this, 'length'); - var idx; + let len = get(this, 'length'); if (startAt === undefined || startAt >= len) { startAt = len - 1; @@ -353,7 +351,7 @@ var ArrayMixin = Mixin.create(Enumerable, { startAt += len; } - for (idx = startAt; idx >= 0; idx--) { + for (let idx = startAt; idx >= 0; idx--) { if (objectAt(this, idx) === object) { return idx; } @@ -439,7 +437,7 @@ var ArrayMixin = Mixin.create(Enumerable, { @public */ arrayContentWillChange(startIdx, removeAmt, addAmt) { - var removing, lim; + let removing, lim; // if no args are passed assume everything changes if (startIdx === undefined) { @@ -466,7 +464,7 @@ var ArrayMixin = Mixin.create(Enumerable, { removing = []; lim = startIdx + removeAmt; - for (var idx = startIdx; idx < lim; idx++) { + for (let idx = startIdx; idx < lim; idx++) { removing.push(objectAt(this, idx)); } } else { @@ -494,8 +492,6 @@ var ArrayMixin = Mixin.create(Enumerable, { @public */ arrayContentDidChange(startIdx, removeAmt, addAmt) { - var adding, lim; - markObjectAsDirty(metaFor(this)); // if no args are passed assume everything changes @@ -512,11 +508,12 @@ var ArrayMixin = Mixin.create(Enumerable, { } } + let adding; if (startIdx >= 0 && addAmt >= 0 && get(this, 'hasEnumerableObservers')) { adding = []; - lim = startIdx + addAmt; + let lim = startIdx + addAmt; - for (var idx = startIdx; idx < lim; idx++) { + for (let idx = startIdx; idx < lim; idx++) { adding.push(objectAt(this, idx)); } } else { @@ -531,9 +528,9 @@ var ArrayMixin = Mixin.create(Enumerable, { sendEvent(this, '@array:change', [this, startIdx, removeAmt, addAmt]); - var length = get(this, 'length'); - var cachedFirst = cacheFor(this, 'firstObject'); - var cachedLast = cacheFor(this, 'lastObject'); + let length = get(this, 'length'); + let cachedFirst = cacheFor(this, 'firstObject'); + let cachedLast = cacheFor(this, 'lastObject'); if (objectAt(this, 0) !== cachedFirst) { propertyWillChange(this, 'firstObject'); @@ -609,8 +606,7 @@ if (isEnabled('ember-runtime-enumerable-includes')) { @public */ includes(obj, startAt) { - var len = get(this, 'length'); - var idx, currentObj; + let len = get(this, 'length'); if (startAt === undefined) { startAt = 0; @@ -620,8 +616,8 @@ if (isEnabled('ember-runtime-enumerable-includes')) { startAt += len; } - for (idx = startAt; idx < len; idx++) { - currentObj = objectAt(this, idx); + for (let idx = startAt; idx < len; idx++) { + let currentObj = objectAt(this, idx); // SameValueZero comparison (NaN !== NaN) if (obj === currentObj || (obj !== obj && currentObj !== currentObj)) { diff --git a/packages/ember-runtime/lib/mixins/container_proxy.js b/packages/ember-runtime/lib/mixins/container_proxy.js index cdf83fa2acf..9e9cd6689da 100644 --- a/packages/ember-runtime/lib/mixins/container_proxy.js +++ b/packages/ember-runtime/lib/mixins/container_proxy.js @@ -54,17 +54,17 @@ export default Mixin.create({ to all have their own locally scoped singletons. ```javascript - var registry = new Registry(); - var container = registry.container(); + let registry = new Registry(); + let container = registry.container(); registry.register('api:twitter', Twitter); - var twitter = container.lookup('api:twitter'); + let twitter = container.lookup('api:twitter'); twitter instanceof Twitter; // => true // by default the container will return singletons - var twitter2 = container.lookup('api:twitter'); + let twitter2 = container.lookup('api:twitter'); twitter2 instanceof Twitter; // => true twitter === twitter2; //=> true @@ -73,13 +73,13 @@ export default Mixin.create({ If singletons are not wanted an optional flag can be provided at lookup. ```javascript - var registry = new Registry(); - var container = registry.container(); + let registry = new Registry(); + let container = registry.container(); registry.register('api:twitter', Twitter); - var twitter = container.lookup('api:twitter', { singleton: false }); - var twitter2 = container.lookup('api:twitter', { singleton: false }); + let twitter = container.lookup('api:twitter', { singleton: false }); + let twitter2 = container.lookup('api:twitter', { singleton: false }); twitter === twitter2; //=> false ``` diff --git a/packages/ember-runtime/lib/mixins/controller_content_model_alias_deprecation.js b/packages/ember-runtime/lib/mixins/controller_content_model_alias_deprecation.js index 1034067fe30..7d915abde78 100644 --- a/packages/ember-runtime/lib/mixins/controller_content_model_alias_deprecation.js +++ b/packages/ember-runtime/lib/mixins/controller_content_model_alias_deprecation.js @@ -33,7 +33,7 @@ export default Mixin.create({ // there is another Mixin loaded first. this._super(...arguments); - var modelSpecified = !!props.model; + let modelSpecified = !!props.model; if (props.content && !modelSpecified) { props.model = props.content; diff --git a/packages/ember-runtime/lib/mixins/enumerable.js b/packages/ember-runtime/lib/mixins/enumerable.js index cc62215e7c0..666366c6be6 100644 --- a/packages/ember-runtime/lib/mixins/enumerable.js +++ b/packages/ember-runtime/lib/mixins/enumerable.js @@ -37,7 +37,7 @@ function emberA() { return (_emberA || (_emberA = require('ember-runtime/system/native_array').A))(); } -var contexts = []; +const contexts = []; function popCtx() { return contexts.length === 0 ? {} : contexts.pop(); @@ -49,10 +49,10 @@ function pushCtx(ctx) { } function iter(key, value) { - var valueProvided = arguments.length === 2; + let valueProvided = arguments.length === 2; function i(item) { - var cur = get(item, key); + let cur = get(item, key); return valueProvided ? value === cur : !!cur; } @@ -97,7 +97,7 @@ function iter(key, value) { @since Ember 0.9 @private */ -var Enumerable = Mixin.create({ +const Enumerable = Mixin.create({ /** __Required.__ You must implement this method to apply this mixin. @@ -148,10 +148,10 @@ var Enumerable = Mixin.create({ If your enumerable is empty, this method should return `undefined`. ```javascript - var arr = ['a', 'b', 'c']; + let arr = ['a', 'b', 'c']; arr.get('firstObject'); // 'a' - var arr = []; + let arr = []; arr.get('firstObject'); // undefined ``` @@ -166,8 +166,8 @@ var Enumerable = Mixin.create({ } // handle generic enumerables - var context = popCtx(); - var ret = this.nextObject(0, null, context); + let context = popCtx(); + let ret = this.nextObject(0, null, context); pushCtx(context); @@ -180,10 +180,10 @@ var Enumerable = Mixin.create({ If your enumerable is empty, this method should return `undefined`. ```javascript - var arr = ['a', 'b', 'c']; + let arr = ['a', 'b', 'c']; arr.get('lastObject'); // 'c' - var arr = []; + let arr = []; arr.get('lastObject'); // undefined ``` @@ -193,16 +193,16 @@ var Enumerable = Mixin.create({ @public */ lastObject: computed('[]', function() { - var len = get(this, 'length'); + let len = get(this, 'length'); if (len === 0) { return undefined; } - var context = popCtx(); - var idx = 0; - var last = null; - var cur; + let context = popCtx(); + let idx = 0; + let last = null; + let cur; do { last = cur; @@ -220,7 +220,7 @@ var Enumerable = Mixin.create({ is found. You may want to override this with a more efficient version. ```javascript - var arr = ['a', 'b', 'c']; + let arr = ['a', 'b', 'c']; arr.contains('a'); // true arr.contains('z'); // false @@ -240,9 +240,7 @@ var Enumerable = Mixin.create({ ); } - var found = this.find(function(item) { - return item === obj; - }); + let found = this.find(item => item === obj); return found !== undefined; }, @@ -278,16 +276,16 @@ var Enumerable = Mixin.create({ throw new TypeError(); } - var context = popCtx(); - var len = get(this, 'length'); - var last = null; + let context = popCtx(); + let len = get(this, 'length'); + let last = null; if (target === undefined) { target = null; } - for (var idx = 0; idx < len; idx++) { - var next = this.nextObject(idx, last, context); + for (let idx = 0; idx < len; idx++) { + let next = this.nextObject(idx, last, context); callback.call(target, next, idx, this); last = next; } @@ -321,9 +319,7 @@ var Enumerable = Mixin.create({ @public */ setEach(key, value) { - return this.forEach(function(item) { - set(item, key, value); - }); + return this.forEach(item => set(item, key, value)); }, /** @@ -354,11 +350,9 @@ var Enumerable = Mixin.create({ @public */ map(callback, target) { - var ret = emberA(); + let ret = emberA(); - this.forEach(function(x, idx, i) { - ret[idx] = callback.call(target, x, idx, i); - }); + this.forEach((x, idx, i) => ret[idx] = callback.call(target, x, idx, i)); return ret; }, @@ -373,9 +367,7 @@ var Enumerable = Mixin.create({ @public */ mapBy(key) { - return this.map(function(next) { - return get(next, key); - }); + return this.map(next => get(next, key)); }, /** @@ -408,7 +400,7 @@ var Enumerable = Mixin.create({ @public */ filter(callback, target) { - var ret = emberA(); + let ret = emberA(); this.forEach(function(x, idx, i) { if (callback.call(target, x, idx, i)) { @@ -479,15 +471,9 @@ var Enumerable = Mixin.create({ @public */ rejectBy(key, value) { - var exactValue = function(item) { - return get(item, key) === value; - }; - - var hasValue = function(item) { - return !!get(item, key); - }; - - var use = (arguments.length === 2 ? exactValue : hasValue); + let exactValue = item => get(item, key) === value; + let hasValue = item => !!get(item, key); + let use = (arguments.length === 2 ? exactValue : hasValue); return this.reject(use); }, @@ -522,18 +508,18 @@ var Enumerable = Mixin.create({ @public */ find(callback, target) { - var len = get(this, 'length'); + let len = get(this, 'length'); if (target === undefined) { target = null; } - var context = popCtx(); - var found = false; - var last = null; - var next, ret; + let context = popCtx(); + let found = false; + let last = null; + let next, ret; - for (var idx = 0; idx < len && !found; idx++) { + for (let idx = 0; idx < len && !found; idx++) { next = this.nextObject(idx, last, context); if (found = callback.call(target, next, idx, this)) { @@ -658,17 +644,17 @@ var Enumerable = Mixin.create({ @public */ any(callback, target) { - var len = get(this, 'length'); - var context = popCtx(); - var found = false; - var last = null; - var next, idx; + let len = get(this, 'length'); + let context = popCtx(); + let found = false; + let last = null; + let next; if (target === undefined) { target = null; } - for (idx = 0; idx < len && !found; idx++) { + for (let idx = 0; idx < len && !found; idx++) { next = this.nextObject(idx, last, context); found = callback.call(target, next, idx, this); last = next; @@ -734,7 +720,7 @@ var Enumerable = Mixin.create({ throw new TypeError(); } - var ret = initialValue; + let ret = initialValue; this.forEach(function(item, i) { ret = callback(ret, item, i, this, reducerProperty); @@ -755,10 +741,10 @@ var Enumerable = Mixin.create({ @public */ invoke(methodName, ...args) { - var ret = emberA(); + let ret = emberA(); this.forEach(function(x, idx) { - var method = x && x[methodName]; + let method = x && x[methodName]; if ('function' === typeof method) { ret[idx] = args ? method.apply(x, args) : x[methodName](); @@ -777,11 +763,9 @@ var Enumerable = Mixin.create({ @public */ toArray() { - var ret = emberA(); + let ret = emberA(); - this.forEach(function(o, idx) { - ret[idx] = o; - }); + this.forEach((o, idx) => ret[idx] = o); return ret; }, @@ -790,7 +774,7 @@ var Enumerable = Mixin.create({ Returns a copy of the array with all `null` and `undefined` elements removed. ```javascript - var arr = ['a', null, 'c', undefined]; + let arr = ['a', null, 'c', undefined]; arr.compact(); // ['a', 'c'] ``` @@ -799,9 +783,7 @@ var Enumerable = Mixin.create({ @public */ compact() { - return this.filter(function(value) { - return value != null; - }); + return this.filter(value => value != null); }, /** @@ -810,7 +792,7 @@ var Enumerable = Mixin.create({ If the receiver does not contain the value it returns the original enumerable. ```javascript - var arr = ['a', 'b', 'a', 'c']; + let arr = ['a', 'b', 'a', 'c']; arr.without('a'); // ['b', 'c'] ``` @@ -824,9 +806,9 @@ var Enumerable = Mixin.create({ return this; // nothing to do } - var ret = emberA(); + let ret = emberA(); - this.forEach(function(k) { + this.forEach(k => { if (k !== value) { ret[ret.length] = k; } @@ -840,7 +822,7 @@ var Enumerable = Mixin.create({ implementation returns an array regardless of the receiver type. ```javascript - var arr = ['a', 'a', 'b', 'b']; + let arr = ['a', 'a', 'b', 'b']; arr.uniq(); // ['a', 'b'] ``` @@ -851,9 +833,9 @@ var Enumerable = Mixin.create({ @public */ uniq() { - var ret = emberA(); + let ret = emberA(); - this.forEach((k) => { + this.forEach(k => { if (ret.indexOf(k) < 0) { ret.push(k); } @@ -894,9 +876,9 @@ var Enumerable = Mixin.create({ @private */ addEnumerableObserver(target, opts) { - var willChange = (opts && opts.willChange) || 'enumerableWillChange'; - var didChange = (opts && opts.didChange) || 'enumerableDidChange'; - var hasObservers = get(this, 'hasEnumerableObservers'); + let willChange = (opts && opts.willChange) || 'enumerableWillChange'; + let didChange = (opts && opts.didChange) || 'enumerableDidChange'; + let hasObservers = get(this, 'hasEnumerableObservers'); if (!hasObservers) { propertyWillChange(this, 'hasEnumerableObservers'); @@ -922,9 +904,9 @@ var Enumerable = Mixin.create({ @private */ removeEnumerableObserver(target, opts) { - var willChange = (opts && opts.willChange) || 'enumerableWillChange'; - var didChange = (opts && opts.didChange) || 'enumerableDidChange'; - var hasObservers = get(this, 'hasEnumerableObservers'); + let willChange = (opts && opts.willChange) || 'enumerableWillChange'; + let didChange = (opts && opts.didChange) || 'enumerableDidChange'; + let hasObservers = get(this, 'hasEnumerableObservers'); if (hasObservers) { propertyWillChange(this, 'hasEnumerableObservers'); @@ -967,7 +949,7 @@ var Enumerable = Mixin.create({ @private */ enumerableContentWillChange(removing, adding) { - var removeCnt, addCnt, hasDelta; + let removeCnt, addCnt, hasDelta; if ('number' === typeof removing) { removeCnt = removing; @@ -1022,7 +1004,7 @@ var Enumerable = Mixin.create({ @private */ enumerableContentDidChange(removing, adding) { - var removeCnt, addCnt, hasDelta; + let removeCnt, addCnt, hasDelta; if ('number' === typeof removing) { removeCnt = removing; @@ -1074,15 +1056,15 @@ var Enumerable = Mixin.create({ @public */ sortBy() { - var sortKeys = arguments; + let sortKeys = arguments; - return this.toArray().sort(function(a, b) { - for (var i = 0; i < sortKeys.length; i++) { - var key = sortKeys[i]; - var propA = get(a, key); - var propB = get(b, key); + return this.toArray().sort((a, b) => { + for (let i = 0; i < sortKeys.length; i++) { + let key = sortKeys[i]; + let propA = get(a, key); + let propB = get(b, key); // return 1 or -1 else continue to the next sortKey - var compareValue = compare(propA, propB); + let compareValue = compare(propA, propB); if (compareValue) { return compareValue; @@ -1101,7 +1083,7 @@ if (isEnabled('ember-runtime-computed-uniq-by')) { The default implementation returns an array regardless of the receiver type. ```javascript - var arr = [{ value: 'a' }, { value: 'a' }, { value: 'b' }, { value: 'b' }]; + let arr = [{ value: 'a' }, { value: 'a' }, { value: 'b' }, { value: 'b' }]; arr.uniqBy('value'); // [{ value: 'a' }, { value: 'b' }] ``` @@ -1111,11 +1093,11 @@ if (isEnabled('ember-runtime-computed-uniq-by')) { */ uniqBy(key) { - var ret = emberA(); - var seen = new EmptyObject(); + let ret = emberA(); + let seen = new EmptyObject(); this.forEach((item) => { - var guid = guidFor(get(item, key)); + let guid = guidFor(get(item, key)); if (!(guid in seen)) { seen[guid] = true; ret.push(item); @@ -1146,12 +1128,12 @@ if (isEnabled('ember-runtime-enumerable-includes')) { includes(obj) { assert('Enumerable#includes cannot accept a second argument "startAt" as enumerable items are unordered.', arguments.length === 1); - var len = get(this, 'length'); - var idx, next; - var last = null; - var found = false; + let len = get(this, 'length'); + let idx, next; + let last = null; + let found = false; - var context = popCtx(); + let context = popCtx(); for (idx = 0; idx < len && !found; idx++) { next = this.nextObject(idx, last, context); @@ -1172,9 +1154,9 @@ if (isEnabled('ember-runtime-enumerable-includes')) { return this; // nothing to do } - var ret = emberA(); + let ret = emberA(); - this.forEach(function(k) { + this.forEach(k => { // SameValueZero comparison (NaN !== NaN) if (!(k === value || k !== k && value !== value)) { ret[ret.length] = k; diff --git a/packages/ember-runtime/lib/mixins/mutable_array.js b/packages/ember-runtime/lib/mixins/mutable_array.js index 873f7c3ed32..efdba681fec 100644 --- a/packages/ember-runtime/lib/mixins/mutable_array.js +++ b/packages/ember-runtime/lib/mixins/mutable_array.js @@ -11,8 +11,8 @@ // CONSTANTS // -var OUT_OF_RANGE_EXCEPTION = 'Index out of range'; -var EMPTY = []; +const OUT_OF_RANGE_EXCEPTION = 'Index out of range'; +const EMPTY = []; // .......................................................... // HELPERS @@ -72,7 +72,7 @@ export default Mixin.create(EmberArray, MutableEnumerable, { want to reuse an existing array without having to recreate it. ```javascript - var colors = ['red', 'green', 'blue']; + let colors = ['red', 'green', 'blue']; color.length(); // 3 colors.clear(); // [] @@ -84,7 +84,7 @@ export default Mixin.create(EmberArray, MutableEnumerable, { @public */ clear() { - var len = get(this, 'length'); + let len = get(this, 'length'); if (len === 0) { return this; } @@ -98,7 +98,7 @@ export default Mixin.create(EmberArray, MutableEnumerable, { specified index. ```javascript - var colors = ['red', 'green', 'blue']; + let colors = ['red', 'green', 'blue']; colors.insertAt(2, 'yellow'); // ['red', 'green', 'yellow', 'blue'] colors.insertAt(5, 'orange'); // Error: Index out of range @@ -127,7 +127,7 @@ export default Mixin.create(EmberArray, MutableEnumerable, { length this method will throw an `OUT_OF_RANGE_EXCEPTION`. ```javascript - var colors = ['red', 'green', 'blue', 'yellow', 'orange']; + let colors = ['red', 'green', 'blue', 'yellow', 'orange']; colors.removeAt(0); // ['green', 'blue', 'yellow', 'orange'] colors.removeAt(2, 2); // ['green', 'blue'] @@ -162,7 +162,7 @@ export default Mixin.create(EmberArray, MutableEnumerable, { is KVO-compliant. ```javascript - var colors = ['red', 'green']; + let colors = ['red', 'green']; colors.pushObject('black'); // ['red', 'green', 'black'] colors.pushObject(['yellow']); // ['red', 'green', ['yellow']] @@ -183,7 +183,7 @@ export default Mixin.create(EmberArray, MutableEnumerable, { notifying observers of the change until all objects are added. ```javascript - var colors = ['red']; + let colors = ['red']; colors.pushObjects(['yellow', 'orange']); // ['red', 'yellow', 'orange'] ``` @@ -206,7 +206,7 @@ export default Mixin.create(EmberArray, MutableEnumerable, { it is KVO-compliant. ```javascript - var colors = ['red', 'green', 'blue']; + let colors = ['red', 'green', 'blue']; colors.popObject(); // 'blue' console.log(colors); // ['red', 'green'] @@ -217,12 +217,12 @@ export default Mixin.create(EmberArray, MutableEnumerable, { @public */ popObject() { - var len = get(this, 'length'); + let len = get(this, 'length'); if (len === 0) { return null; } - var ret = objectAt(this, len - 1); + let ret = objectAt(this, len - 1); this.removeAt(len - 1, 1); return ret; }, @@ -232,7 +232,7 @@ export default Mixin.create(EmberArray, MutableEnumerable, { like `shift()` but it is KVO-compliant. ```javascript - var colors = ['red', 'green', 'blue']; + let colors = ['red', 'green', 'blue']; colors.shiftObject(); // 'red' console.log(colors); // ['green', 'blue'] @@ -247,7 +247,7 @@ export default Mixin.create(EmberArray, MutableEnumerable, { return null; } - var ret = objectAt(this, 0); + let ret = objectAt(this, 0); this.removeAt(0); return ret; }, @@ -257,7 +257,7 @@ export default Mixin.create(EmberArray, MutableEnumerable, { KVO-compliant. ```javascript - var colors = ['red']; + let colors = ['red']; colors.unshiftObject('yellow'); // ['yellow', 'red'] colors.unshiftObject(['black']); // [['black'], 'yellow', 'red'] @@ -278,7 +278,7 @@ export default Mixin.create(EmberArray, MutableEnumerable, { observers until all objects have been added. ```javascript - var colors = ['red']; + let colors = ['red']; colors.unshiftObjects(['black', 'white']); // ['black', 'white', 'red'] colors.unshiftObjects('yellow'); // Type Error: 'undefined' is not a function @@ -303,12 +303,12 @@ export default Mixin.create(EmberArray, MutableEnumerable, { @public */ reverseObjects() { - var len = get(this, 'length'); + let len = get(this, 'length'); if (len === 0) { return this; } - var objects = this.toArray().reverse(); + let objects = this.toArray().reverse(); this.replace(0, len, objects); return this; }, @@ -318,7 +318,7 @@ export default Mixin.create(EmberArray, MutableEnumerable, { If argument is an empty array receiver will be cleared. ```javascript - var colors = ['red', 'green', 'blue']; + let colors = ['red', 'green', 'blue']; colors.setObjects(['black', 'white']); // ['black', 'white'] colors.setObjects([]); // [] @@ -335,7 +335,7 @@ export default Mixin.create(EmberArray, MutableEnumerable, { return this.clear(); } - var len = get(this, 'length'); + let len = get(this, 'length'); this.replace(0, len, objects); return this; }, @@ -348,7 +348,7 @@ export default Mixin.create(EmberArray, MutableEnumerable, { Remove all occurrences of an object in the array. ```javascript - var cities = ['Chicago', 'Berlin', 'Lima', 'Chicago']; + let cities = ['Chicago', 'Berlin', 'Lima', 'Chicago']; cities.removeObject('Chicago'); // ['Berlin', 'Lima'] cities.removeObject('Lima'); // ['Berlin'] @@ -361,9 +361,9 @@ export default Mixin.create(EmberArray, MutableEnumerable, { @public */ removeObject(obj) { - var loc = get(this, 'length') || 0; + let loc = get(this, 'length') || 0; while (--loc >= 0) { - var curObject = objectAt(this, loc); + let curObject = objectAt(this, loc); if (curObject === obj) { this.removeAt(loc); @@ -377,7 +377,7 @@ export default Mixin.create(EmberArray, MutableEnumerable, { present in the array. ```javascript - var cities = ['Chicago', 'Berlin']; + let cities = ['Chicago', 'Berlin']; cities.addObject('Lima'); // ['Chicago', 'Berlin', 'Lima'] cities.addObject('Berlin'); // ['Chicago', 'Berlin', 'Lima'] @@ -389,7 +389,7 @@ export default Mixin.create(EmberArray, MutableEnumerable, { @public */ addObject(obj) { - var included; + let included; if (isEnabled('ember-runtime-enumerable-includes')) { included = this.includes(obj); diff --git a/packages/ember-runtime/lib/mixins/mutable_enumerable.js b/packages/ember-runtime/lib/mixins/mutable_enumerable.js index 0af1242b12a..62625a06249 100644 --- a/packages/ember-runtime/lib/mixins/mutable_enumerable.js +++ b/packages/ember-runtime/lib/mixins/mutable_enumerable.js @@ -76,7 +76,7 @@ export default Mixin.create(Enumerable, { */ addObjects(objects) { beginPropertyChanges(this); - objects.forEach((obj) => this.addObject(obj)); + objects.forEach(obj => this.addObject(obj)); endPropertyChanges(this); return this; }, @@ -109,7 +109,7 @@ export default Mixin.create(Enumerable, { */ removeObjects(objects) { beginPropertyChanges(this); - for (var i = objects.length - 1; i >= 0; i--) { + for (let i = objects.length - 1; i >= 0; i--) { this.removeObject(objects[i]); } endPropertyChanges(this); diff --git a/packages/ember-runtime/lib/mixins/promise_proxy.js b/packages/ember-runtime/lib/mixins/promise_proxy.js index e7289f0f388..97715f0dbde 100644 --- a/packages/ember-runtime/lib/mixins/promise_proxy.js +++ b/packages/ember-runtime/lib/mixins/promise_proxy.js @@ -16,13 +16,13 @@ function tap(proxy, promise) { isRejected: false }); - return promise.then(function(value) { + return promise.then(value => { setProperties(proxy, { content: value, isFulfilled: true }); return value; - }, function(reason) { + }, reason => { setProperties(proxy, { reason: reason, isRejected: true @@ -35,9 +35,9 @@ function tap(proxy, promise) { A low level mixin making ObjectProxy promise-aware. ```javascript - var ObjectPromiseProxy = Ember.ObjectProxy.extend(Ember.PromiseProxyMixin); + let ObjectPromiseProxy = Ember.ObjectProxy.extend(Ember.PromiseProxyMixin); - var proxy = ObjectPromiseProxy.create({ + let proxy = ObjectPromiseProxy.create({ promise: $.getJSON('/some/remote/data.json') }); @@ -201,7 +201,7 @@ export default Mixin.create({ function promiseAlias(name) { return function () { - var promise = get(this, 'promise'); + let promise = get(this, 'promise'); return promise[name](...arguments); }; } diff --git a/packages/ember-runtime/lib/mixins/registry_proxy.js b/packages/ember-runtime/lib/mixins/registry_proxy.js index 6f80fc355d5..27c20487dd2 100644 --- a/packages/ember-runtime/lib/mixins/registry_proxy.js +++ b/packages/ember-runtime/lib/mixins/registry_proxy.js @@ -34,7 +34,7 @@ export default Mixin.create({ A simple example: ```javascript - var App = Ember.Application.create(); + let App = Ember.Application.create(); App.Orange = Ember.Object.extend(); App.register('fruit:favorite', App.Orange); @@ -47,8 +47,8 @@ export default Mixin.create({ An example of registering a controller with a non-standard name: ```javascript - var App = Ember.Application.create(); - var Session = Ember.Controller.extend(); + let App = Ember.Application.create(); + let Session = Ember.Controller.extend(); App.register('controller:session', Session); @@ -66,7 +66,7 @@ export default Mixin.create({ Some examples modifying that default behavior: ```javascript - var App = Ember.Application.create(); + let App = Ember.Application.create(); App.Person = Ember.Object.extend(); App.Orange = Ember.Object.extend(); @@ -91,8 +91,8 @@ export default Mixin.create({ Unregister a factory. ```javascript - var App = Ember.Application.create(); - var User = Ember.Object.extend(); + let App = Ember.Application.create(); + let User = Ember.Object.extend(); App.register('model:user', User); App.resolveRegistration('model:user').create() instanceof User //=> true @@ -163,8 +163,8 @@ export default Mixin.create({ Allow registering options for all factories of a type. ```javascript - var App = Ember.Application.create(); - var appInstance = App.buildInstance(); + let App = Ember.Application.create(); + let appInstance = App.buildInstance(); // if all of type `connection` must not be singletons appInstance.optionsForType('connection', { singleton: false }); @@ -172,13 +172,13 @@ export default Mixin.create({ appInstance.register('connection:twitter', TwitterConnection); appInstance.register('connection:facebook', FacebookConnection); - var twitter = appInstance.lookup('connection:twitter'); - var twitter2 = appInstance.lookup('connection:twitter'); + let twitter = appInstance.lookup('connection:twitter'); + let twitter2 = appInstance.lookup('connection:twitter'); twitter === twitter2; // => false - var facebook = appInstance.lookup('connection:facebook'); - var facebook2 = appInstance.lookup('connection:facebook'); + let facebook = appInstance.lookup('connection:facebook'); + let facebook2 = appInstance.lookup('connection:facebook'); facebook === facebook2; // => false ``` @@ -211,8 +211,8 @@ export default Mixin.create({ An example of providing a session object to all controllers: ```javascript - var App = Ember.Application.create(); - var Session = Ember.Object.extend({ isAuthenticated: false }); + let App = Ember.Application.create(); + let Session = Ember.Object.extend({ isAuthenticated: false }); // A factory must be registered before it can be injected App.register('session:main', Session); @@ -260,8 +260,8 @@ function registryAlias(name) { } export function buildFakeRegistryWithDeprecations(instance, typeForMessage) { - var fakeRegistry = {}; - var registryProps = { + let fakeRegistry = {}; + let registryProps = { resolve: 'resolveRegistration', register: 'register', unregister: 'unregister', @@ -274,7 +274,7 @@ export function buildFakeRegistryWithDeprecations(instance, typeForMessage) { injection: 'inject' }; - for (var deprecatedProperty in registryProps) { + for (let deprecatedProperty in registryProps) { fakeRegistry[deprecatedProperty] = buildFakeRegistryFunction(instance, typeForMessage, deprecatedProperty, registryProps[deprecatedProperty]); } diff --git a/packages/ember-runtime/lib/mixins/target_action_support.js b/packages/ember-runtime/lib/mixins/target_action_support.js index 8b8b41ec54a..7270670de44 100644 --- a/packages/ember-runtime/lib/mixins/target_action_support.js +++ b/packages/ember-runtime/lib/mixins/target_action_support.js @@ -24,7 +24,7 @@ view-aware defaults for target and actionContext. @extends Ember.Mixin @private */ -var TargetActionSupport = Mixin.create({ +export default Mixin.create({ target: null, action: null, actionContext: null, @@ -34,10 +34,10 @@ var TargetActionSupport = Mixin.create({ return this._targetObject; } - var target = get(this, 'target'); + let target = get(this, 'target'); if (typeof target === 'string') { - var value = get(this, target); + let value = get(this, target); if (value === undefined) { value = get(context.lookup, target); } @@ -48,17 +48,17 @@ var TargetActionSupport = Mixin.create({ } }), - actionContextObject: computed(function() { - var actionContext = get(this, 'actionContext'); + actionContextObject: computed('actionContext', function() { + let actionContext = get(this, 'actionContext'); if (typeof actionContext === 'string') { - var value = get(this, actionContext); + let value = get(this, actionContext); if (value === undefined) { value = get(context.lookup, actionContext); } return value; } else { return actionContext; } - }).property('actionContext'), + }), /** Send an `action` with an `actionContext` to a `target`. The action, actionContext @@ -69,7 +69,7 @@ var TargetActionSupport = Mixin.create({ target: Ember.computed.alias('controller'), action: 'save', actionContext: Ember.computed.alias('context'), - click: function() { + click() { this.triggerAction(); // Sends the `save` action, along with the current context // to the current controller } @@ -81,7 +81,7 @@ var TargetActionSupport = Mixin.create({ ```javascript App.SaveButtonView = Ember.View.extend(Ember.TargetActionSupport, { - click: function() { + click() { this.triggerAction({ action: 'save', target: this.get('controller'), @@ -99,7 +99,7 @@ var TargetActionSupport = Mixin.create({ ```javascript App.SaveButtonView = Ember.View.extend(Ember.TargetActionSupport, { target: Ember.computed.alias('controller'), - click: function() { + click() { this.triggerAction({ action: 'save' }); // Sends the `save` action, along with a reference to `this`, @@ -114,12 +114,12 @@ var TargetActionSupport = Mixin.create({ @private */ triggerAction(opts = {}) { - var action = opts.action || get(this, 'action'); - var target = opts.target || get(this, 'targetObject'); - var actionContext = opts.actionContext; + let action = opts.action || get(this, 'action'); + let target = opts.target || get(this, 'targetObject'); + let actionContext = opts.actionContext; function args(options, actionName) { - var ret = []; + let ret = []; if (actionName) { ret.push(actionName); } return ret.concat(options); @@ -130,7 +130,7 @@ var TargetActionSupport = Mixin.create({ } if (target && action) { - var ret; + let ret; if (target.send) { ret = target.send.apply(target, args(actionContext, action)); @@ -149,5 +149,3 @@ var TargetActionSupport = Mixin.create({ } } }); - -export default TargetActionSupport; diff --git a/packages/ember-runtime/lib/system/array_proxy.js b/packages/ember-runtime/lib/system/array_proxy.js index fa23ff76dbc..f1b78d2ed96 100644 --- a/packages/ember-runtime/lib/system/array_proxy.js +++ b/packages/ember-runtime/lib/system/array_proxy.js @@ -28,8 +28,8 @@ import { @submodule ember-runtime */ -var OUT_OF_RANGE_EXCEPTION = 'Index out of range'; -var EMPTY = []; +const OUT_OF_RANGE_EXCEPTION = 'Index out of range'; +const EMPTY = []; function K() { return this; } @@ -42,8 +42,8 @@ function K() { return this; } A simple example of usage: ```javascript - var pets = ['dog', 'cat', 'fish']; - var ap = Ember.ArrayProxy.create({ content: Ember.A(pets) }); + let pets = ['dog', 'cat', 'fish']; + let ap = Ember.ArrayProxy.create({ content: Ember.A(pets) }); ap.get('firstObject'); // 'dog' ap.set('content', ['amoeba', 'paramecium']); @@ -55,8 +55,8 @@ function K() { return this; } `objectAtContent`: ```javascript - var pets = ['dog', 'cat', 'fish']; - var ap = Ember.ArrayProxy.create({ + let pets = ['dog', 'cat', 'fish']; + let ap = Ember.ArrayProxy.create({ content: Ember.A(pets), objectAtContent: function(idx) { return this.get('content').objectAt(idx).toUpperCase(); @@ -72,7 +72,7 @@ function K() { return this; } @uses Ember.MutableArray @public */ -var ArrayProxy = EmberObject.extend(MutableArray, { +export default EmberObject.extend(MutableArray, { /** The content array. Must be an object that implements `Ember.Array` and/or @@ -141,7 +141,7 @@ var ArrayProxy = EmberObject.extend(MutableArray, { }), _teardownContent() { - var content = get(this, 'content'); + let content = get(this, 'content'); if (content) { removeArrayObserver(content, this, { @@ -184,7 +184,7 @@ var ArrayProxy = EmberObject.extend(MutableArray, { @method _contentDidChange */ _contentDidChange: observer('content', function() { - var content = get(this, 'content'); + let content = get(this, 'content'); assert('Can\'t set ArrayProxy\'s content to itself', content !== this); @@ -192,7 +192,7 @@ var ArrayProxy = EmberObject.extend(MutableArray, { }), _setupContent() { - var content = get(this, 'content'); + let content = get(this, 'content'); if (content) { assert(`ArrayProxy expects an Array or Ember.ArrayProxy, but you passed ${typeof content}`, isArray(content) || content.isDestroyed); @@ -205,8 +205,8 @@ var ArrayProxy = EmberObject.extend(MutableArray, { }, _arrangedContentWillChange: _beforeObserver('arrangedContent', function() { - var arrangedContent = get(this, 'arrangedContent'); - var len = arrangedContent ? get(arrangedContent, 'length') : 0; + let arrangedContent = get(this, 'arrangedContent'); + let len = arrangedContent ? get(arrangedContent, 'length') : 0; this.arrangedContentArrayWillChange(this, 0, len, undefined); this.arrangedContentWillChange(this); @@ -215,8 +215,8 @@ var ArrayProxy = EmberObject.extend(MutableArray, { }), _arrangedContentDidChange: observer('arrangedContent', function() { - var arrangedContent = get(this, 'arrangedContent'); - var len = arrangedContent ? get(arrangedContent, 'length') : 0; + let arrangedContent = get(this, 'arrangedContent'); + let len = arrangedContent ? get(arrangedContent, 'length') : 0; assert('Can\'t set ArrayProxy\'s content to itself', arrangedContent !== this); @@ -227,7 +227,7 @@ var ArrayProxy = EmberObject.extend(MutableArray, { }), _setupArrangedContent() { - var arrangedContent = get(this, 'arrangedContent'); + let arrangedContent = get(this, 'arrangedContent'); if (arrangedContent) { assert(`ArrayProxy expects an Array or Ember.ArrayProxy, but you passed ${typeof arrangedContent}`, @@ -241,7 +241,7 @@ var ArrayProxy = EmberObject.extend(MutableArray, { }, _teardownArrangedContent() { - var arrangedContent = get(this, 'arrangedContent'); + let arrangedContent = get(this, 'arrangedContent'); if (arrangedContent) { removeArrayObserver(arrangedContent, this, { @@ -259,13 +259,13 @@ var ArrayProxy = EmberObject.extend(MutableArray, { }, length: computed(function() { - var arrangedContent = get(this, 'arrangedContent'); + let arrangedContent = get(this, 'arrangedContent'); return arrangedContent ? get(arrangedContent, 'length') : 0; // No dependencies since Enumerable notifies length of change }), _replace(idx, amt, objects) { - var content = get(this, 'content'); + let content = get(this, 'content'); assert('The content property of ' + this.constructor + ' should be set before modifying it', content); if (content) { this.replaceContent(idx, amt, objects); @@ -301,10 +301,9 @@ var ArrayProxy = EmberObject.extend(MutableArray, { removeAt(start, len) { if ('number' === typeof start) { - var content = get(this, 'content'); - var arrangedContent = get(this, 'arrangedContent'); - var indices = []; - var i; + let content = get(this, 'content'); + let arrangedContent = get(this, 'arrangedContent'); + let indices = []; if ((start < 0) || (start >= get(this, 'length'))) { throw new EmberError(OUT_OF_RANGE_EXCEPTION); @@ -315,16 +314,16 @@ var ArrayProxy = EmberObject.extend(MutableArray, { } // Get a list of indices in original content to remove - for (i = start; i < start + len; i++) { + for (let i = start; i < start + len; i++) { // Use arrangedContent here so we avoid confusion with objects transformed by objectAtContent indices.push(content.indexOf(objectAt(arrangedContent, i))); } // Replace in reverse order since indices will change - indices.sort(function(a, b) { return b - a; }); + indices.sort((a, b) => b - a); beginPropertyChanges(); - for (i = 0; i < indices.length; i++) { + for (let i = 0; i < indices.length; i++) { this._replace(indices[i], 1, EMPTY); } endPropertyChanges(); @@ -351,7 +350,7 @@ var ArrayProxy = EmberObject.extend(MutableArray, { return this.clear(); } - var len = get(this, 'length'); + let len = get(this, 'length'); this._replace(0, len, objects); return this; }, @@ -367,7 +366,7 @@ var ArrayProxy = EmberObject.extend(MutableArray, { }, slice() { - var arr = this.toArray(); + let arr = this.toArray(); return arr.slice(...arguments); }, @@ -390,5 +389,3 @@ var ArrayProxy = EmberObject.extend(MutableArray, { this._teardownContent(); } }); - -export default ArrayProxy; diff --git a/packages/ember-runtime/lib/system/each_proxy.js b/packages/ember-runtime/lib/system/each_proxy.js index d95c0324818..58ff3c71511 100644 --- a/packages/ember-runtime/lib/system/each_proxy.js +++ b/packages/ember-runtime/lib/system/each_proxy.js @@ -20,7 +20,7 @@ import { objectAt } from 'ember-runtime/mixins/array'; @class EachProxy @private */ -function EachProxy(content) { +export default function EachProxy(content) { this._content = content; this._keys = undefined; this.__ember_meta__ = null; @@ -129,5 +129,3 @@ function removeObserverForContentKey(content, keyName, proxy, idx, loc) { } } } - -export default EachProxy; diff --git a/packages/ember-runtime/lib/system/lazy_load.js b/packages/ember-runtime/lib/system/lazy_load.js index 79aabdc78f9..604a7286e96 100644 --- a/packages/ember-runtime/lib/system/lazy_load.js +++ b/packages/ember-runtime/lib/system/lazy_load.js @@ -7,9 +7,9 @@ import { ENV, environment } from 'ember-environment'; @submodule ember-runtime */ -var loadHooks = ENV.EMBER_LOAD_HOOKS || {}; -var loaded = {}; -export var _loaded = loaded; +const loadHooks = ENV.EMBER_LOAD_HOOKS || {}; +const loaded = {}; +export let _loaded = loaded; /** Detects when a specific package of Ember (e.g. 'Ember.Application') @@ -31,7 +31,7 @@ export var _loaded = loaded; @private */ export function onLoad(name, callback) { - var object = loaded[name]; + let object = loaded[name]; loadHooks[name] = loadHooks[name] || []; loadHooks[name].push(callback); @@ -56,7 +56,7 @@ export function runLoadHooks(name, object) { let window = environment.window; if (window && typeof CustomEvent === 'function') { - var event = new CustomEvent(name, { detail: object, name: name }); + let event = new CustomEvent(name, { detail: object, name: name }); window.dispatchEvent(event); } diff --git a/packages/ember-runtime/lib/system/namespace.js b/packages/ember-runtime/lib/system/namespace.js index 00fbee32723..eb3b0bf248d 100644 --- a/packages/ember-runtime/lib/system/namespace.js +++ b/packages/ember-runtime/lib/system/namespace.js @@ -45,7 +45,7 @@ export function setSearchDisabled(flag) { @extends Ember.Object @public */ -var Namespace = EmberObject.extend({ +const Namespace = EmberObject.extend({ isNamespace: true, init() { @@ -54,7 +54,7 @@ var Namespace = EmberObject.extend({ }, toString() { - var name = get(this, 'name') || get(this, 'modulePrefix'); + let name = get(this, 'name') || get(this, 'modulePrefix'); if (name) { return name; } findNamespaces(); @@ -66,8 +66,8 @@ var Namespace = EmberObject.extend({ }, destroy() { - var namespaces = Namespace.NAMESPACES; - var toString = this.toString(); + let namespaces = Namespace.NAMESPACES; + let toString = this.toString(); if (toString) { context.lookup[toString] = undefined; @@ -94,19 +94,19 @@ Namespace.reopenClass({ } }); -var NAMESPACES_BY_ID = Namespace.NAMESPACES_BY_ID; +let NAMESPACES_BY_ID = Namespace.NAMESPACES_BY_ID; -var hasOwnProp = ({}).hasOwnProperty; +let hasOwnProp = ({}).hasOwnProperty; function processNamespace(paths, root, seen) { - var idx = paths.length; + let idx = paths.length; NAMESPACES_BY_ID[paths.join('.')] = root; // Loop over all of the keys in the namespace, looking for classes - for (var key in root) { + for (let key in root) { if (!hasOwnProp.call(root, key)) { continue; } - var obj = root[key]; + let obj = root[key]; // If we are processing the `Ember` namespace, for example, the // `paths` will start with `["Ember"]`. Every iteration through @@ -169,7 +169,7 @@ function findNamespaces() { } function superClassString(mixin) { - var superclass = mixin.superclass; + let superclass = mixin.superclass; if (superclass) { if (superclass[NAME_KEY]) { return superclass[NAME_KEY]; @@ -183,14 +183,14 @@ function classToString() { processAllNamespaces(); } - var ret; + let ret; if (this[NAME_KEY]) { ret = this[NAME_KEY]; } else if (this._toString) { ret = this._toString; } else { - var str = superClassString(this); + let str = superClassString(this); if (str) { ret = '(subclass of ' + str + ')'; } else { @@ -203,8 +203,8 @@ function classToString() { } function processAllNamespaces() { - var unprocessedNamespaces = !Namespace.PROCESSED; - var unprocessedMixins = hasUnprocessedMixins(); + let unprocessedNamespaces = !Namespace.PROCESSED; + let unprocessedMixins = hasUnprocessedMixins(); if (unprocessedNamespaces) { findNamespaces(); @@ -212,10 +212,10 @@ function processAllNamespaces() { } if (unprocessedNamespaces || unprocessedMixins) { - var namespaces = Namespace.NAMESPACES; - var namespace; + let namespaces = Namespace.NAMESPACES; + let namespace; - for (var i = 0; i < namespaces.length; i++) { + for (let i = 0; i < namespaces.length; i++) { namespace = namespaces[i]; processNamespace([namespace.toString()], namespace, {}); } @@ -225,7 +225,7 @@ function processAllNamespaces() { } function makeToString(ret) { - return function() { return ret; }; + return () => ret; } Mixin.prototype.toString = classToString; // ES6TODO: altering imported objects. SBB. diff --git a/packages/ember-runtime/lib/system/native_array.js b/packages/ember-runtime/lib/system/native_array.js index f45524f5e44..79d03cdf3ac 100644 --- a/packages/ember-runtime/lib/system/native_array.js +++ b/packages/ember-runtime/lib/system/native_array.js @@ -32,7 +32,7 @@ import copy from 'ember-runtime/copy'; @uses Ember.Copyable @public */ -var NativeArray = Mixin.create(MutableArray, Observable, Copyable, { +let NativeArray = Mixin.create(MutableArray, Observable, Copyable, { // because length is a built-in property we need to know to just get the // original property. @@ -57,7 +57,7 @@ var NativeArray = Mixin.create(MutableArray, Observable, Copyable, { // if we replaced exactly the same number of items, then pass only the // replaced range. Otherwise, pass the full remaining array length // since everything has shifted - var len = objects ? get(objects, 'length') : 0; + let len = objects ? get(objects, 'length') : 0; this.arrayContentWillChange(idx, amt, len); if (len === 0) { @@ -73,7 +73,7 @@ var NativeArray = Mixin.create(MutableArray, Observable, Copyable, { // If you ask for an unknown property, then try to collect the value // from member items. unknownProperty(key, value) { - var ret;// = this.reducedProperty(key, value); + let ret;// = this.reducedProperty(key, value); if (value !== undefined && ret === undefined) { ret = this[key] = value; } @@ -93,7 +93,7 @@ var NativeArray = Mixin.create(MutableArray, Observable, Copyable, { }); // Remove any methods implemented natively so we don't override them -var ignore = ['length']; +const ignore = ['length']; NativeArray.keys().forEach((methodName) => { if (Array.prototype[methodName]) { ignore.push(methodName); @@ -132,13 +132,13 @@ NativeArray = NativeArray.without.apply(NativeArray, ignore); @return {Ember.NativeArray} @public */ -var A; +let A; if (ENV.EXTEND_PROTOTYPES.Array) { NativeArray.apply(Array.prototype); - A = function (arr) { return arr || []; }; + A = arr => arr || []; } else { - A = function (arr) { + A = arr => { if (!arr) { arr = []; } return EmberArray.detect(arr) ? arr : NativeArray.apply(arr); }; diff --git a/packages/ember-runtime/lib/system/object.js b/packages/ember-runtime/lib/system/object.js index 83bf4b39dae..01c2356e404 100644 --- a/packages/ember-runtime/lib/system/object.js +++ b/packages/ember-runtime/lib/system/object.js @@ -17,9 +17,7 @@ import Observable from 'ember-runtime/mixins/observable'; @uses Ember.Observable @public */ -var EmberObject = CoreObject.extend(Observable); -EmberObject.toString = function() { - return 'Ember.Object'; -}; +const EmberObject = CoreObject.extend(Observable); +EmberObject.toString = () => 'Ember.Object'; export default EmberObject; diff --git a/packages/ember-runtime/lib/system/string.js b/packages/ember-runtime/lib/system/string.js index fff6f741c7a..dff32c15294 100644 --- a/packages/ember-runtime/lib/system/string.js +++ b/packages/ember-runtime/lib/system/string.js @@ -13,16 +13,16 @@ import { import Cache from 'ember-metal/cache'; -var STRING_DASHERIZE_REGEXP = (/[ _]/g); +const STRING_DASHERIZE_REGEXP = (/[ _]/g); -var STRING_DASHERIZE_CACHE = new Cache(1000, function(key) { +const STRING_DASHERIZE_CACHE = new Cache(1000, function(key) { return decamelize(key).replace(STRING_DASHERIZE_REGEXP, '-'); }); -var STRING_CAMELIZE_REGEXP_1 = (/(\-|\_|\.|\s)+(.)?/g); -var STRING_CAMELIZE_REGEXP_2 = (/(^|\/)([A-Z])/g); +const STRING_CAMELIZE_REGEXP_1 = (/(\-|\_|\.|\s)+(.)?/g); +const STRING_CAMELIZE_REGEXP_2 = (/(^|\/)([A-Z])/g); -var CAMELIZE_CACHE = new Cache(1000, function(key) { +const CAMELIZE_CACHE = new Cache(1000, function(key) { return key.replace(STRING_CAMELIZE_REGEXP_1, function(match, separator, chr) { return chr ? chr.toUpperCase() : ''; }).replace(STRING_CAMELIZE_REGEXP_2, function(match, separator, chr) { @@ -30,19 +30,19 @@ var CAMELIZE_CACHE = new Cache(1000, function(key) { }); }); -var STRING_CLASSIFY_REGEXP_1 = (/^(\-|_)+(.)?/); -var STRING_CLASSIFY_REGEXP_2 = (/(.)(\-|\_|\.|\s)+(.)?/g); -var STRING_CLASSIFY_REGEXP_3 = (/(^|\/|\.)([a-z])/g); +const STRING_CLASSIFY_REGEXP_1 = (/^(\-|_)+(.)?/); +const STRING_CLASSIFY_REGEXP_2 = (/(.)(\-|\_|\.|\s)+(.)?/g); +const STRING_CLASSIFY_REGEXP_3 = (/(^|\/|\.)([a-z])/g); -var CLASSIFY_CACHE = new Cache(1000, function(str) { - var replace1 = function(match, separator, chr) { +const CLASSIFY_CACHE = new Cache(1000, function(str) { + let replace1 = function(match, separator, chr) { return chr ? ('_' + chr.toUpperCase()) : ''; }; - var replace2 = function(match, initialChar, separator, chr) { + let replace2 = function(match, initialChar, separator, chr) { return initialChar + (chr ? chr.toUpperCase() : ''); }; - var parts = str.split('/'); - for (var i = 0; i < parts.length; i++) { + let parts = str.split('/'); + for (let i = 0; i < parts.length; i++) { parts[i] = parts[i] .replace(STRING_CLASSIFY_REGEXP_1, replace1) .replace(STRING_CLASSIFY_REGEXP_2, replace2); @@ -53,41 +53,41 @@ var CLASSIFY_CACHE = new Cache(1000, function(str) { }); }); -var STRING_UNDERSCORE_REGEXP_1 = (/([a-z\d])([A-Z]+)/g); -var STRING_UNDERSCORE_REGEXP_2 = (/\-|\s+/g); +const STRING_UNDERSCORE_REGEXP_1 = (/([a-z\d])([A-Z]+)/g); +const STRING_UNDERSCORE_REGEXP_2 = (/\-|\s+/g); -var UNDERSCORE_CACHE = new Cache(1000, function(str) { +const UNDERSCORE_CACHE = new Cache(1000, function(str) { return str.replace(STRING_UNDERSCORE_REGEXP_1, '$1_$2'). replace(STRING_UNDERSCORE_REGEXP_2, '_').toLowerCase(); }); -var STRING_CAPITALIZE_REGEXP = (/(^|\/)([a-z])/g); +const STRING_CAPITALIZE_REGEXP = (/(^|\/)([a-z])/g); -var CAPITALIZE_CACHE = new Cache(1000, function(str) { +const CAPITALIZE_CACHE = new Cache(1000, function(str) { return str.replace(STRING_CAPITALIZE_REGEXP, function(match, separator, chr) { return match.toUpperCase(); }); }); -var STRING_DECAMELIZE_REGEXP = (/([a-z\d])([A-Z])/g); +const STRING_DECAMELIZE_REGEXP = (/([a-z\d])([A-Z])/g); -var DECAMELIZE_CACHE = new Cache(1000, function(str) { +const DECAMELIZE_CACHE = new Cache(1000, function(str) { return str.replace(STRING_DECAMELIZE_REGEXP, '$1_$2').toLowerCase(); }); function _fmt(str, formats) { - var cachedFormats = formats; + let cachedFormats = formats; if (!isArray(cachedFormats) || arguments.length > 2) { cachedFormats = new Array(arguments.length - 1); - for (var i = 1; i < arguments.length; i++) { + for (let i = 1; i < arguments.length; i++) { cachedFormats[i - 1] = arguments[i]; } } // first, replace any ORDERED replacements. - var idx = 0; // the current index for non-numerical replacements + let idx = 0; // the current index for non-numerical replacements return str.replace(/%@([0-9]+)?/g, function(s, argIndex) { argIndex = (argIndex) ? parseInt(argIndex, 10) - 1 : idx++; s = cachedFormats[argIndex]; diff --git a/packages/ember-runtime/lib/utils.js b/packages/ember-runtime/lib/utils.js index b975ad16d6f..f4ddafea5dc 100644 --- a/packages/ember-runtime/lib/utils.js +++ b/packages/ember-runtime/lib/utils.js @@ -4,7 +4,7 @@ import EmberObject from 'ember-runtime/system/object'; // ........................................ // TYPING & ARRAY MESSAGING // -var TYPE_MAP = { +const TYPE_MAP = { '[object Boolean]': 'boolean', '[object Number]': 'number', '[object String]': 'string', @@ -15,7 +15,7 @@ var TYPE_MAP = { '[object Object]': 'object' }; -var toString = Object.prototype.toString; +const { toString } = Object.prototype; /** Returns true if the passed object is an array or Array-like. @@ -108,7 +108,7 @@ export function isArray(obj) { export function typeOf(item) { if (item === null) { return 'null'; } if (item === undefined) { return 'undefined'; } - var ret = TYPE_MAP[toString.call(item)] || 'object'; + let ret = TYPE_MAP[toString.call(item)] || 'object'; if (ret === 'function') { if (EmberObject.detect(item)) { diff --git a/packages/ember-runtime/tests/computed/computed_macros_test.js b/packages/ember-runtime/tests/computed/computed_macros_test.js index c879155ebca..39d2b4e014e 100644 --- a/packages/ember-runtime/tests/computed/computed_macros_test.js +++ b/packages/ember-runtime/tests/computed/computed_macros_test.js @@ -26,7 +26,7 @@ import { A as emberA } from 'ember-runtime/system/native_array'; QUnit.module('CP macros'); testBoth('Ember.computed.empty', function (get, set) { - var obj = EmberObject.extend({ + let obj = EmberObject.extend({ bestLannister: null, lannisters: null, @@ -47,7 +47,7 @@ testBoth('Ember.computed.empty', function (get, set) { }); testBoth('Ember.computed.notEmpty', function(get, set) { - var obj = EmberObject.extend({ + let obj = EmberObject.extend({ bestLannister: null, lannisters: null, @@ -68,7 +68,7 @@ testBoth('Ember.computed.notEmpty', function(get, set) { }); testBoth('computed.not', function(get, set) { - var obj = { foo: true }; + let obj = { foo: true }; defineProperty(obj, 'notFoo', not('foo')); equal(get(obj, 'notFoo'), false); @@ -78,7 +78,7 @@ testBoth('computed.not', function(get, set) { }); testBoth('computed.empty', function(get, set) { - var obj = { foo: [], bar: undefined, baz: null, quz: '' }; + let obj = { foo: [], bar: undefined, baz: null, quz: '' }; defineProperty(obj, 'fooEmpty', empty('foo')); defineProperty(obj, 'barEmpty', empty('bar')); defineProperty(obj, 'bazEmpty', empty('baz')); @@ -95,7 +95,7 @@ testBoth('computed.empty', function(get, set) { }); testBoth('computed.bool', function(get, set) { - var obj = { foo() {}, bar: 'asdf', baz: null, quz: false }; + let obj = { foo() {}, bar: 'asdf', baz: null, quz: false }; defineProperty(obj, 'fooBool', bool('foo')); defineProperty(obj, 'barBool', bool('bar')); defineProperty(obj, 'bazBool', bool('baz')); @@ -107,7 +107,7 @@ testBoth('computed.bool', function(get, set) { }); testBoth('computed.alias', function(get, set) { - var obj = { bar: 'asdf', baz: null, quz: false }; + let obj = { bar: 'asdf', baz: null, quz: false }; defineProperty(obj, 'bay', computed(function(key) { return 'apple'; })); @@ -136,8 +136,8 @@ testBoth('computed.alias', function(get, set) { }); testBoth('computed.alias set', function(get, set) { - var obj = {}; - var constantValue = 'always `a`'; + let obj = {}; + let constantValue = 'always `a`'; defineProperty(obj, 'original', computed({ get: function(key) { return constantValue; }, @@ -155,7 +155,7 @@ testBoth('computed.alias set', function(get, set) { }); testBoth('computed.match', function(get, set) { - var obj = { name: 'Paul' }; + let obj = { name: 'Paul' }; defineProperty(obj, 'isPaul', match('name', /Paul/)); equal(get(obj, 'isPaul'), true, 'is Paul'); @@ -166,7 +166,7 @@ testBoth('computed.match', function(get, set) { }); testBoth('computed.notEmpty', function(get, set) { - var obj = { items: [1] }; + let obj = { items: [1] }; defineProperty(obj, 'hasItems', notEmpty('items')); equal(get(obj, 'hasItems'), true, 'is not empty'); @@ -177,7 +177,7 @@ testBoth('computed.notEmpty', function(get, set) { }); testBoth('computed.equal', function(get, set) { - var obj = { name: 'Paul' }; + let obj = { name: 'Paul' }; defineProperty(obj, 'isPaul', computedEqual('name', 'Paul')); equal(get(obj, 'isPaul'), true, 'is Paul'); @@ -188,7 +188,7 @@ testBoth('computed.equal', function(get, set) { }); testBoth('computed.gt', function(get, set) { - var obj = { number: 2 }; + let obj = { number: 2 }; defineProperty(obj, 'isGreaterThenOne', gt('number', 1)); equal(get(obj, 'isGreaterThenOne'), true, 'is gt'); @@ -203,7 +203,7 @@ testBoth('computed.gt', function(get, set) { }); testBoth('computed.gte', function(get, set) { - var obj = { number: 2 }; + let obj = { number: 2 }; defineProperty(obj, 'isGreaterOrEqualThenOne', gte('number', 1)); equal(get(obj, 'isGreaterOrEqualThenOne'), true, 'is gte'); @@ -218,7 +218,7 @@ testBoth('computed.gte', function(get, set) { }); testBoth('computed.lt', function(get, set) { - var obj = { number: 0 }; + let obj = { number: 0 }; defineProperty(obj, 'isLesserThenOne', lt('number', 1)); equal(get(obj, 'isLesserThenOne'), true, 'is lt'); @@ -233,7 +233,7 @@ testBoth('computed.lt', function(get, set) { }); testBoth('computed.lte', function(get, set) { - var obj = { number: 0 }; + let obj = { number: 0 }; defineProperty(obj, 'isLesserOrEqualThenOne', lte('number', 1)); equal(get(obj, 'isLesserOrEqualThenOne'), true, 'is lte'); @@ -248,7 +248,7 @@ testBoth('computed.lte', function(get, set) { }); testBoth('computed.and two properties', function(get, set) { - var obj = { one: true, two: true }; + let obj = { one: true, two: true }; defineProperty(obj, 'oneAndTwo', and('one', 'two')); equal(get(obj, 'oneAndTwo'), true, 'one and two'); @@ -269,7 +269,7 @@ testBoth('computed.and two properties', function(get, set) { }); testBoth('computed.and three properties', function(get, set) { - var obj = { one: true, two: true, three: true }; + let obj = { one: true, two: true, three: true }; defineProperty(obj, 'oneTwoThree', and('one', 'two', 'three')); equal(get(obj, 'oneTwoThree'), true, 'one and two and three'); @@ -286,7 +286,7 @@ testBoth('computed.and three properties', function(get, set) { }); testBoth('computed.and expand properties', function(get, set) { - var obj = { one: true, two: true, three: true }; + let obj = { one: true, two: true, three: true }; defineProperty(obj, 'oneTwoThree', and('{one,two,three}')); equal(get(obj, 'oneTwoThree'), true, 'one and two and three'); @@ -303,7 +303,7 @@ testBoth('computed.and expand properties', function(get, set) { }); testBoth('computed.or two properties', function(get, set) { - var obj = { one: true, two: true }; + let obj = { one: true, two: true }; defineProperty(obj, 'oneOrTwo', or('one', 'two')); equal(get(obj, 'oneOrTwo'), true, 'one or two'); @@ -330,7 +330,7 @@ testBoth('computed.or two properties', function(get, set) { }); testBoth('computed.or three properties', function(get, set) { - var obj = { one: true, two: true, three: true }; + let obj = { one: true, two: true, three: true }; defineProperty(obj, 'oneTwoThree', or('one', 'two', 'three')); equal(get(obj, 'oneTwoThree'), true, 'one or two or three'); @@ -361,7 +361,7 @@ testBoth('computed.or three properties', function(get, set) { }); testBoth('computed.or expand properties', function(get, set) { - var obj = { one: true, two: true, three: true }; + let obj = { one: true, two: true, three: true }; defineProperty(obj, 'oneTwoThree', or('{one,two,three}')); equal(get(obj, 'oneTwoThree'), true, 'one or two or three'); @@ -392,7 +392,7 @@ testBoth('computed.or expand properties', function(get, set) { }); testBoth('computed.or and computed.and warn about dependent keys with spaces', function(get, set) { - var obj = { one: true, two: true }; + let obj = { one: true, two: true }; expectAssertion(function() { defineProperty(obj, 'oneOrTwo', or('one', 'two three')); }, /Dependent keys passed to Ember\.computed\.or\(\) can't have spaces\./); @@ -403,7 +403,7 @@ testBoth('computed.or and computed.and warn about dependent keys with spaces', f }); testBoth('computed.oneWay', function(get, set) { - var obj = { + let obj = { firstName: 'Teddy', lastName: 'Zeenny' }; @@ -427,7 +427,7 @@ testBoth('computed.oneWay', function(get, set) { }); testBoth('computed.readOnly', function(get, set) { - var obj = { + let obj = { firstName: 'Teddy', lastName: 'Zeenny' }; @@ -453,7 +453,7 @@ testBoth('computed.readOnly', function(get, set) { }); testBoth('computed.deprecatingAlias', function(get, set) { - var obj = { bar: 'asdf', baz: null, quz: false }; + let obj = { bar: 'asdf', baz: null, quz: false }; defineProperty(obj, 'bay', computed(function(key) { return 'apple'; })); diff --git a/packages/ember-runtime/tests/computed/reduce_computed_macros_test.js b/packages/ember-runtime/tests/computed/reduce_computed_macros_test.js index 243e10faec8..14af521fdb6 100644 --- a/packages/ember-runtime/tests/computed/reduce_computed_macros_test.js +++ b/packages/ember-runtime/tests/computed/reduce_computed_macros_test.js @@ -29,7 +29,7 @@ import { isArray } from 'ember-runtime/utils'; import { testBoth } from 'ember-metal/tests/props_helper'; import { A as emberA } from 'ember-runtime/system/native_array'; -var obj; +let obj; QUnit.module('map', { setup() { obj = EmberObject.extend({ @@ -74,7 +74,7 @@ QUnit.test('it maps simple properties', function() { }); QUnit.test('it maps simple unshifted properties', function() { - var array = emberA(); + let array = emberA(); obj = EmberObject.extend({ mapped: map('array', (item) => item.toUpperCase()) @@ -108,7 +108,7 @@ QUnit.test('it has the correct `this`', function() { }); QUnit.test('it passes the index to the callback', function() { - var array = ['a', 'b', 'c']; + let array = ['a', 'b', 'c']; obj = EmberObject.extend({ mapped: map('array', (item, index) => index) @@ -151,8 +151,8 @@ QUnit.test('it maps objects', function() { }); QUnit.test('it maps unshifted objects with property observers', function() { - var array = emberA(); - var cObj = { v: 'c' }; + let array = emberA(); + let cObj = { v: 'c' }; obj = EmberObject.extend({ mapped: map('array.@each.v', (item) => get(item, 'v').toUpperCase()) @@ -207,7 +207,7 @@ QUnit.test('it maps properties', function() { }); QUnit.test('it is observable', function() { - var calls = 0; + let calls = 0; deepEqual(obj.get('mapped'), [1, 3, 2, 1]); @@ -278,13 +278,13 @@ QUnit.test('it passes the array to the callback', function() { }); QUnit.test('it caches properly', function() { - var array = obj.get('array'); + let array = obj.get('array'); - var filtered = obj.get('filtered'); + let filtered = obj.get('filtered'); ok(filtered === obj.get('filtered')); array.addObject(11); - var newFiltered = obj.get('filtered'); + let newFiltered = obj.get('filtered'); ok(filtered !== newFiltered); @@ -292,7 +292,7 @@ QUnit.test('it caches properly', function() { }); QUnit.test('it updates as the array is modified', function() { - var array = obj.get('array'); + let array = obj.get('array'); deepEqual(obj.get('filtered'), [2, 4, 6, 8], 'precond - filtered array is initially correct'); @@ -309,7 +309,7 @@ QUnit.test('it updates as the array is modified', function() { }); QUnit.test('the dependent array can be cleared one at a time', function() { - var array = get(obj, 'array'); + let array = get(obj, 'array'); deepEqual(obj.get('filtered'), [2, 4, 6, 8], 'precond - filtered array is initially correct'); @@ -461,8 +461,8 @@ QUnit.test('properties values can be replaced', function() { }); QUnit.test('does not include duplicates', function() { - var array = obj.get('array'); - var array2 = obj.get('array2'); + let array = obj.get('array'); + let array2 = obj.get('array2'); deepEqual(obj.get('union').sort((x, y) => x - y), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], name + ' does not include duplicates'); @@ -484,7 +484,7 @@ QUnit.test('properties values can be replaced', function() { }); QUnit.test('has set-union semantics', function() { - var array = obj.get('array'); + let array = obj.get('array'); deepEqual(obj.get('union').sort((x, y) => x - y), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], name + ' is initially correct'); @@ -561,7 +561,7 @@ if (isEnabled('ember-runtime-computed-uniq-by')) { }); QUnit.test('it returns an empty array when computed on a non-array', function() { - var MyObject = EmberObject.extend({ + let MyObject = EmberObject.extend({ list: null, uniq: uniqBy('list', 'name') }); @@ -593,8 +593,8 @@ QUnit.test('intersect is readOnly', function() { }); QUnit.test('it has set-intersection semantics', function() { - var array2 = obj.get('array2'); - var array3 = obj.get('array3'); + let array2 = obj.get('array2'); + let array3 = obj.get('array3'); deepEqual(obj.get('intersection').sort((x, y) => x - y), [3, 5], 'intersection is initially correct'); @@ -662,8 +662,8 @@ QUnit.test('it throws an error if given fewer or more than two dependent propert QUnit.test('it has set-diff semantics', function() { - var array1 = obj.get('array'); - var array2 = obj.get('array2'); + let array1 = obj.get('array'); + let array2 = obj.get('array2'); deepEqual(obj.get('diff').sort((x, y) => x - y), [1, 2, 6, 7], 'set-diff is initially correct'); @@ -732,7 +732,7 @@ function commonSortTests() { }); QUnit.test('adding to the dependent array updates the sorted array', function() { - var items = obj.get('items'); + let items = obj.get('items'); deepEqual(obj.get('sortedItems').mapBy('fname'), [ 'Cersei', @@ -775,19 +775,19 @@ function commonSortTests() { QUnit.test('distinct items may be sort-equal, although their relative order will not be guaranteed', function() { // We recreate jaime and "Cersei" here only for test stability: we want // their guid-ordering to be deterministic - var jaimeInDisguise = { + let jaimeInDisguise = { fname: 'Cersei', lname: 'Lannister', age: 34 }; - var jaime = { + let jaime = { fname: 'Jaime', lname: 'Lannister', age: 34 }; - var items = obj.get('items'); + let items = obj.get('items'); items.replace(0, 1, jaime); items.replace(1, 1, jaimeInDisguise); @@ -819,18 +819,18 @@ function commonSortTests() { }); QUnit.test('guid sort-order fallback with a search proxy is not confused by non-search ObjectProxys', function() { - var tyrion = { + let tyrion = { fname: 'Tyrion', lname: 'Lannister' }; - var tyrionInDisguise = ObjectProxy.create({ + let tyrionInDisguise = ObjectProxy.create({ fname: 'Yollo', lname: '', content: tyrion }); - var items = obj.get('items'); + let items = obj.get('items'); items.pushObject(tyrion); @@ -883,7 +883,7 @@ QUnit.test('sort is readOnly', function() { commonSortTests(); QUnit.test('updating sort properties detaches observers for old sort properties', function() { - var objectToRemove = obj.get('items')[3]; + let objectToRemove = obj.get('items')[3]; deepEqual(obj.get('sortedItems').mapBy('fname'), [ 'Cersei', @@ -937,7 +937,7 @@ QUnit.test('updating sort properties updates the sorted array', function() { }); QUnit.test('updating sort properties invalidates the sorted array', function() { - var sortProps = obj.get('itemSorting'); + let sortProps = obj.get('itemSorting'); deepEqual(obj.get('sortedItems').mapBy('fname'), [ 'Cersei', @@ -1012,7 +1012,7 @@ QUnit.test('sort direction defaults to ascending (with sort property change)', f }); QUnit.test('updating an item\'s sort properties updates the sorted array', function() { - var tyrionInDisguise = obj.get('items')[1]; + let tyrionInDisguise = obj.get('items')[1]; deepEqual(obj.get('sortedItems').mapBy('fname'), [ 'Cersei', @@ -1032,7 +1032,7 @@ QUnit.test('updating an item\'s sort properties updates the sorted array', funct }); QUnit.test('updating several of an item\'s sort properties updated the sorted array', function() { - var sansaInDisguise = obj.get('items')[1]; + let sansaInDisguise = obj.get('items')[1]; deepEqual(obj.get('sortedItems').mapBy('fname'), [ 'Cersei', @@ -1055,17 +1055,17 @@ QUnit.test('updating several of an item\'s sort properties updated the sorted ar }); QUnit.test('updating an item\'s sort properties does not error when binary search does a self compare (#3273)', function() { - var jaime = { + let jaime = { name: 'Jaime', status: 1 }; - var cersei = { + let cersei = { name: 'Cersei', status: 2 }; - var obj = EmberObject.extend({ + let obj = EmberObject.extend({ sortProps: ['status'], sortedPeople: sort('people', 'sortProps') }).create({ @@ -1093,13 +1093,13 @@ QUnit.test('updating an item\'s sort properties does not error when binary searc }); QUnit.test('array observers do not leak', function() { - var daria = { name: 'Daria' }; - var jane = { name: 'Jane' }; + let daria = { name: 'Daria' }; + let jane = { name: 'Jane' }; - var sisters = [jane, daria]; + let sisters = [jane, daria]; - var sortProps = emberA(['name']); - var jaime = EmberObject.extend({ + let sortProps = emberA(['name']); + let jaime = EmberObject.extend({ sortedPeople: sort('sisters', 'sortProps'), sortProps }).create({ @@ -1120,19 +1120,19 @@ QUnit.test('array observers do not leak', function() { }); QUnit.test('property paths in sort properties update the sorted array', function () { - var jaime = { + let jaime = { relatedObj: { status: 1, firstName: 'Jaime', lastName: 'Lannister' } }; - var cersei = { + let cersei = { relatedObj: { status: 2, firstName: 'Cersei', lastName: 'Lannister' } }; - var sansa = EmberObject.create({ + let sansa = EmberObject.create({ relatedObj: { status: 3, firstName: 'Sansa', lastName: 'Stark' } }); - var obj = EmberObject.extend({ + let obj = EmberObject.extend({ sortProps: ['relatedObj.status'], sortedPeople: sort('people', 'sortProps') }).create({ @@ -1182,8 +1182,8 @@ QUnit.test('if the dependentKey is neither an array nor object, it will return a }); function sortByLnameFname(a, b) { - var lna = get(a, 'lname'); - var lnb = get(b, 'lname'); + let lna = get(a, 'lname'); + let lnb = get(b, 'lname'); if (lna !== lnb) { return lna > lnb ? 1 : -1; @@ -1193,8 +1193,8 @@ function sortByLnameFname(a, b) { } function sortByFnameAsc(a, b) { - var fna = get(a, 'fname'); - var fnb = get(b, 'fname'); + let fna = get(a, 'fname'); + let fnb = get(b, 'fname'); if (fna === fnb) { return 0; @@ -1221,7 +1221,7 @@ QUnit.module('sort - sort function', { }); QUnit.test('sort has correct `this`', function() { - var obj = EmberObject.extend({ + let obj = EmberObject.extend({ sortedItems: sort('items.@each.fname', function(a, b) { equal(this, obj, 'expected the object to be `this`'); return this.sortByLastName(a, b); @@ -1250,9 +1250,9 @@ QUnit.test('sort (with function) is readOnly', function() { commonSortTests(); QUnit.test('changing item properties specified via @each triggers a resort of the modified item', function() { - var items = get(obj, 'items'); + let items = get(obj, 'items'); - var tyrionInDisguise = items[1]; + let tyrionInDisguise = items[1]; deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted'); @@ -1262,8 +1262,8 @@ QUnit.test('changing item properties specified via @each triggers a resort of th }); QUnit.test('changing item properties not specified via @each does not trigger a resort', function() { - var items = obj.get('items'); - var cersei = items[1]; + let items = obj.get('items'); + let cersei = items[1]; deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted'); @@ -1302,7 +1302,7 @@ QUnit.test('sorts correctly as only one property changes', function() { deepEqual(obj.get('sortedItems').mapBy('name'), ['A', 'B', 'C', 'D'], 'final'); }); -var klass; +let klass; QUnit.module('sort - concurrency', { setup() { klass = EmberObject.extend({ @@ -1326,7 +1326,7 @@ QUnit.module('sort - concurrency', { }); QUnit.test('sorts correctly after mutation to the sort properties', function() { - var sorted = obj.get('sortedItems'); + let sorted = obj.get('sortedItems'); deepEqual(sorted.mapBy('name'), ['A', 'B', 'C', 'D'], 'initial'); set(obj.get('items')[1], 'count', 5); @@ -1347,7 +1347,7 @@ QUnit.test('sort correctly after mutation to the sort', function() { }); QUnit.test('sort correctly on multiple instances of the same class', function() { - var obj2 = klass.create({ + let obj2 = klass.create({ items: emberA([ { name: 'W', count: 23, thing: 4 }, { name: 'X', count: 24, thing: 3 }, @@ -1381,7 +1381,7 @@ QUnit.test('sort correctly on multiple instances of the same class', function() QUnit.test('sort correctly when multiple sorts are chained on the same instance of a class', function() { - var obj2 = klass.extend({ + let obj2 = klass.extend({ items: computed('sibling.sortedItems.[]', function() { return this.get('sibling.sortedItems'); }), @@ -1446,7 +1446,7 @@ QUnit.test('max is readOnly', function() { QUnit.test('max tracks the max number as objects are added', function() { equal(obj.get('max'), 3, 'precond - max is initially correct'); - var items = obj.get('items'); + let items = obj.get('items'); items.pushObject(5); @@ -1501,7 +1501,7 @@ QUnit.test('min tracks the min number as objects are added', function() { }); QUnit.test('min recomputes when the current min is removed', function() { - var items = obj.get('items'); + let items = obj.get('items'); equal(obj.get('min'), 1, 'precond - min is initially correct'); @@ -1539,7 +1539,7 @@ QUnit.module('Ember.arrayComputed - mixed sugar', { }); QUnit.test('filtering and sorting can be combined', function() { - var items = obj.get('items'); + let items = obj.get('items'); deepEqual(obj.get('sortedLannisters').mapBy('fname'), ['Cersei', 'Jaime'], 'precond - array is initially filtered and sorted'); @@ -1551,7 +1551,7 @@ QUnit.test('filtering and sorting can be combined', function() { }); QUnit.test('filtering, sorting and reduce (max) can be combined', function() { - var items = obj.get('items'); + let items = obj.get('items'); equal(16, obj.get('oldestStarkAge'), 'precond - end of chain is initially correct'); @@ -1569,14 +1569,14 @@ function todo(name, priority) { } function priorityComparator(todoA, todoB) { - var pa = parseInt(get(todoA, 'priority'), 10); - var pb = parseInt(get(todoB, 'priority'), 10); + let pa = parseInt(get(todoA, 'priority'), 10); + let pb = parseInt(get(todoB, 'priority'), 10); return pa - pb; } function evenPriorities(todo) { - var p = parseInt(get(todo, 'priority'), 10); + let p = parseInt(get(todo, 'priority'), 10); return p % 2 === 0; } @@ -1613,7 +1613,7 @@ QUnit.test('it can filter and sort when both depend on the same item property', deepEqual(obj.get('filtered').mapBy('name'), ['A', 'C', 'E', 'D'], 'filtered updated correctly'); }); -var userFnCalls; +let userFnCalls; QUnit.module('Chaining array and reduced CPs', { setup() { userFnCalls = 0; @@ -1638,7 +1638,7 @@ QUnit.module('Chaining array and reduced CPs', { QUnit.test('it computes interdependent array computed properties', function() { equal(obj.get('max'), 3, 'sanity - it properly computes the maximum value'); - var calls = 0; + let calls = 0; addObserver(obj, 'max', () => calls++); @@ -1696,7 +1696,7 @@ QUnit.test('updates when array is modified', function() { QUnit.module('collect'); testBoth('works', function(get, set) { - var obj = { one: 'foo', two: 'bar', three: null }; + let obj = { one: 'foo', two: 'bar', three: null }; defineProperty(obj, 'all', collect('one', 'two', 'three', 'four')); deepEqual(get(obj, 'all'), ['foo', 'bar', null, null], 'have all of them'); @@ -1705,7 +1705,7 @@ testBoth('works', function(get, set) { deepEqual(get(obj, 'all'), ['foo', 'bar', null, true], 'have all of them'); - var a = []; + let a = []; set(obj, 'one', 0); set(obj, 'three', a); diff --git a/packages/ember-runtime/tests/controllers/controller_test.js b/packages/ember-runtime/tests/controllers/controller_test.js index 41cf17dc4a9..24a6699b755 100644 --- a/packages/ember-runtime/tests/controllers/controller_test.js +++ b/packages/ember-runtime/tests/controllers/controller_test.js @@ -13,7 +13,7 @@ QUnit.module('Controller event handling'); QUnit.test('can access `actions` hash via `_actions` [DEPRECATED]', function() { expect(2); - var controller = Controller.extend({ + let controller = Controller.extend({ actions: { foo: function() { ok(true, 'called foo action'); @@ -28,20 +28,20 @@ QUnit.test('can access `actions` hash via `_actions` [DEPRECATED]', function() { QUnit.test('Action can be handled by a function on actions object', function() { expect(1); - var TestController = Controller.extend({ + let TestController = Controller.extend({ actions: { poke() { ok(true, 'poked'); } } }); - var controller = TestController.create(); + let controller = TestController.create(); controller.send('poke'); }); QUnit.test('A handled action can be bubbled to the target for continued processing', function() { expect(2); - var TestController = Controller.extend({ + let TestController = Controller.extend({ actions: { poke() { ok(true, 'poked 1'); @@ -50,7 +50,7 @@ QUnit.test('A handled action can be bubbled to the target for continued processi } }); - var controller = TestController.create({ + let controller = TestController.create({ target: Controller.extend({ actions: { poke() { @@ -65,7 +65,7 @@ QUnit.test('A handled action can be bubbled to the target for continued processi QUnit.test('Action can be handled by a superclass\' actions object', function() { expect(4); - var SuperController = Controller.extend({ + let SuperController = Controller.extend({ actions: { foo() { ok(true, 'foo'); @@ -76,7 +76,7 @@ QUnit.test('Action can be handled by a superclass\' actions object', function() } }); - var BarControllerMixin = Mixin.create({ + let BarControllerMixin = Mixin.create({ actions: { bar(msg) { equal(msg, 'HELLO'); @@ -85,7 +85,7 @@ QUnit.test('Action can be handled by a superclass\' actions object', function() } }); - var IndexController = SuperController.extend(BarControllerMixin, { + let IndexController = SuperController.extend(BarControllerMixin, { actions: { baz() { ok(true, 'baz'); @@ -93,7 +93,7 @@ QUnit.test('Action can be handled by a superclass\' actions object', function() } }); - var controller = IndexController.create({}); + let controller = IndexController.create({}); controller.send('foo'); controller.send('bar', 'HELLO'); controller.send('baz'); @@ -105,7 +105,7 @@ QUnit.module('Controller Content -> Model Alias'); QUnit.test('`model` is aliased as `content`', function() { expect(1); - var controller = Controller.extend({ + let controller = Controller.extend({ model: 'foo-bar' }).create(); @@ -114,7 +114,7 @@ QUnit.test('`model` is aliased as `content`', function() { QUnit.test('`content` is moved to `model` when `model` is unset', function() { expect(2); - var controller; + let controller; ignoreDeprecation(function() { controller = Controller.extend({ @@ -128,7 +128,7 @@ QUnit.test('`content` is moved to `model` when `model` is unset', function() { QUnit.test('specifying `content` (without `model` specified) results in deprecation', function() { expect(1); - var controller; + let controller; expectDeprecation(function() { controller = Controller.extend({ @@ -141,7 +141,7 @@ QUnit.test('specifying `content` (with `model` specified) does not result in dep expect(3); expectNoDeprecation(); - var controller = Controller.extend({ + let controller = Controller.extend({ content: 'foo-bar', model: 'blammo' }).create(); @@ -157,7 +157,7 @@ if (!EmberDev.runningProdBuild) { expectAssertion(function() { let owner = buildOwner(); - var AnObject = Object.extend({ + let AnObject = Object.extend({ foo: inject.controller('bar') }); @@ -177,8 +177,8 @@ QUnit.test('controllers can be injected into controllers', function() { owner.register('controller:posts', Controller.extend()); - var postController = owner.lookup('controller:post'); - var postsController = owner.lookup('controller:posts'); + let postController = owner.lookup('controller:post'); + let postsController = owner.lookup('controller:posts'); equal(postsController, postController.get('postsController'), 'controller.posts is injected'); }); @@ -192,8 +192,8 @@ QUnit.test('services can be injected into controllers', function() { owner.register('service:auth', Service.extend()); - var appController = owner.lookup('controller:application'); - var authService = owner.lookup('service:auth'); + let appController = owner.lookup('controller:application'); + let authService = owner.lookup('service:auth'); equal(authService, appController.get('authService'), 'service.auth is injected'); }); diff --git a/packages/ember-runtime/tests/core/compare_test.js b/packages/ember-runtime/tests/core/compare_test.js index 0f8a6bc4200..a1694066d0e 100644 --- a/packages/ember-runtime/tests/core/compare_test.js +++ b/packages/ember-runtime/tests/core/compare_test.js @@ -3,8 +3,8 @@ import EmberObject from 'ember-runtime/system/object'; import compare from 'ember-runtime/compare'; import Comparable from 'ember-runtime/mixins/comparable'; -var data = []; -var Comp = EmberObject.extend(Comparable); +let data = []; +let Comp = EmberObject.extend(Comparable); Comp.reopenClass({ compare(obj) { @@ -34,7 +34,7 @@ QUnit.module('Ember.compare()', { }); QUnit.test('ordering should work', function() { - var suspect, comparable, failureMessage, + let suspect, comparable, failureMessage, suspectIndex, comparableIndex; for (suspectIndex = 0; suspectIndex < data.length; suspectIndex++) { @@ -55,15 +55,15 @@ QUnit.test('ordering should work', function() { }); QUnit.test('comparables should return values in the range of -1, 0, 1', function() { - var negOne = Comp.create({ + let negOne = Comp.create({ val: -1 }); - var zero = Comp.create({ + let zero = Comp.create({ val: 0 }); - var one = Comp.create({ + let one = Comp.create({ val: 1 }); diff --git a/packages/ember-runtime/tests/core/copy_test.js b/packages/ember-runtime/tests/core/copy_test.js index 8165511ceb8..849e5ce5645 100644 --- a/packages/ember-runtime/tests/core/copy_test.js +++ b/packages/ember-runtime/tests/core/copy_test.js @@ -3,20 +3,20 @@ import copy from 'ember-runtime/copy'; QUnit.module('Ember Copy Method'); QUnit.test('Ember.copy null', function() { - var obj = { field: null }; + let obj = { field: null }; equal(copy(obj, true).field, null, 'null should still be null'); }); QUnit.test('Ember.copy date', function() { - var date = new Date(2014, 7, 22); - var dateCopy = copy(date); + let date = new Date(2014, 7, 22); + let dateCopy = copy(date); equal(date.getTime(), dateCopy.getTime(), 'dates should be equivalent'); }); QUnit.test('Ember.copy null prototype object', function() { - var obj = Object.create(null); + let obj = Object.create(null); obj.foo = 'bar'; @@ -24,8 +24,8 @@ QUnit.test('Ember.copy null prototype object', function() { }); QUnit.test('Ember.copy Array', function() { - var array = [1, null, new Date(2015, 9, 9), 'four']; - var arrayCopy = copy(array); + let array = [1, null, new Date(2015, 9, 9), 'four']; + let arrayCopy = copy(array); deepEqual(array, arrayCopy, 'array content cloned successfully in new array'); }); diff --git a/packages/ember-runtime/tests/core/isEqual_test.js b/packages/ember-runtime/tests/core/isEqual_test.js index bafd1e4235a..dfdf447c161 100644 --- a/packages/ember-runtime/tests/core/isEqual_test.js +++ b/packages/ember-runtime/tests/core/isEqual_test.js @@ -33,6 +33,6 @@ QUnit.test('array should be equal', function() { QUnit.test('first object implements isEqual should use it', function() { ok(isEqual({ isEqual() { return true; } }, null), 'should return true always'); - var obj = { isEqual() { return false; } }; + let obj = { isEqual() { return false; } }; equal(isEqual(obj, obj), false, 'should return false because isEqual returns false'); }); diff --git a/packages/ember-runtime/tests/core/is_array_test.js b/packages/ember-runtime/tests/core/is_array_test.js index cd703735cdd..66fd5d2ea01 100644 --- a/packages/ember-runtime/tests/core/is_array_test.js +++ b/packages/ember-runtime/tests/core/is_array_test.js @@ -4,17 +4,17 @@ import ArrayProxy from 'ember-runtime/system/array_proxy'; QUnit.module('Ember Type Checking'); -var global = this; +const global = this; QUnit.test('Ember.isArray', function() { - var numarray = [1, 2, 3]; - var number = 23; - var strarray = ['Hello', 'Hi']; - var string = 'Hello'; - var object = {}; - var length = { length: 12 }; - var fn = function() {}; - var arrayProxy = ArrayProxy.create({ content: emberA() }); + let numarray = [1, 2, 3]; + let number = 23; + let strarray = ['Hello', 'Hi']; + let string = 'Hello'; + let object = {}; + let length = { length: 12 }; + let fn = function() {}; + let arrayProxy = ArrayProxy.create({ content: emberA() }); equal(isArray(numarray), true, '[1,2,3]'); equal(isArray(number), false, '23'); diff --git a/packages/ember-runtime/tests/core/is_empty_test.js b/packages/ember-runtime/tests/core/is_empty_test.js index e7e906101bf..32c28cef697 100644 --- a/packages/ember-runtime/tests/core/is_empty_test.js +++ b/packages/ember-runtime/tests/core/is_empty_test.js @@ -5,7 +5,7 @@ import { A as emberA } from 'ember-runtime/system/native_array'; QUnit.module('Ember.isEmpty'); QUnit.test('Ember.isEmpty', function() { - var arrayProxy = ArrayProxy.create({ content: emberA() }); + let arrayProxy = ArrayProxy.create({ content: emberA() }); equal(true, isEmpty(arrayProxy), 'for an ArrayProxy that has empty content'); }); diff --git a/packages/ember-runtime/tests/core/type_of_test.js b/packages/ember-runtime/tests/core/type_of_test.js index 89e3782fb54..79da4df0aa4 100644 --- a/packages/ember-runtime/tests/core/type_of_test.js +++ b/packages/ember-runtime/tests/core/type_of_test.js @@ -4,17 +4,17 @@ import EmberObject from 'ember-runtime/system/object'; QUnit.module('Ember Type Checking'); QUnit.test('Ember.typeOf', function() { - var MockedDate = function() { }; + let MockedDate = function() { }; MockedDate.prototype = new Date(); - var mockedDate = new MockedDate(); - var date = new Date(); - var error = new Error('boum'); - var object = { a: 'b' }; - var a = null; - var arr = [1, 2, 3]; - var obj = {}; - var instance = EmberObject.create({ method() {} }); + let mockedDate = new MockedDate(); + let date = new Date(); + let error = new Error('boum'); + let object = { a: 'b' }; + let a = null; + let arr = [1, 2, 3]; + let obj = {}; + let instance = EmberObject.create({ method() {} }); equal(typeOf(), 'undefined', 'undefined'); equal(typeOf(null), 'null', 'null'); diff --git a/packages/ember-runtime/tests/ext/function_test.js b/packages/ember-runtime/tests/ext/function_test.js index 6a0b6782113..1b09fd6e054 100644 --- a/packages/ember-runtime/tests/ext/function_test.js +++ b/packages/ember-runtime/tests/ext/function_test.js @@ -12,7 +12,7 @@ testBoth('global observer helper takes multiple params', function(get, set) { return; } - var MyMixin = Mixin.create({ + let MyMixin = Mixin.create({ count: 0, @@ -22,7 +22,7 @@ testBoth('global observer helper takes multiple params', function(get, set) { }); - var obj = mixin({}, MyMixin); + let obj = mixin({}, MyMixin); equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); set(obj, 'bar', 'BAZ'); @@ -38,7 +38,7 @@ testBoth('sets up an event listener, and can trigger the function on multiple ev return; } - var MyMixin = Mixin.create({ + let MyMixin = Mixin.create({ count: 0, @@ -48,7 +48,7 @@ testBoth('sets up an event listener, and can trigger the function on multiple ev }); - var obj = mixin({}, Evented, MyMixin); + let obj = mixin({}, Evented, MyMixin); equal(get(obj, 'count'), 0, 'should not invoke listener immediately'); obj.trigger('bar'); @@ -62,7 +62,7 @@ testBoth('can be chained with observes', function(get, set) { return; } - var MyMixin = Mixin.create({ + let MyMixin = Mixin.create({ count: 0, bay: 'bay', @@ -71,7 +71,7 @@ testBoth('can be chained with observes', function(get, set) { }.observes('bay').on('bar') }); - var obj = mixin({}, Evented, MyMixin); + let obj = mixin({}, Evented, MyMixin); equal(get(obj, 'count'), 0, 'should not invoke listener immediately'); set(obj, 'bay', 'BAY'); @@ -87,7 +87,7 @@ testBoth('sets up a ComputedProperty', function(get, set) { return; } - var MyClass = EmberObject.extend({ + let MyClass = EmberObject.extend({ firstName: null, lastName: null, fullName: function() { @@ -95,7 +95,7 @@ testBoth('sets up a ComputedProperty', function(get, set) { }.property('firstName', 'lastName') }); - var obj = MyClass.create({ firstName: 'Fred', lastName: 'Flinstone' }); + let obj = MyClass.create({ firstName: 'Fred', lastName: 'Flinstone' }); equal(get(obj, 'fullName'), 'Fred Flinstone', 'should return the computed value'); set(obj, 'firstName', 'Wilma'); diff --git a/packages/ember-runtime/tests/ext/mixin_test.js b/packages/ember-runtime/tests/ext/mixin_test.js index a2d1775a1fc..86b076c76d2 100644 --- a/packages/ember-runtime/tests/ext/mixin_test.js +++ b/packages/ember-runtime/tests/ext/mixin_test.js @@ -7,13 +7,13 @@ import run from 'ember-metal/run_loop'; QUnit.module('system/mixin/binding_test'); QUnit.test('Defining a property ending in Binding should setup binding when applied', function() { - var MyMixin = Mixin.create({ + let MyMixin = Mixin.create({ fooBinding: 'bar.baz' }); - var obj = { bar: { baz: 'BIFF' } }; + let obj = { bar: { baz: 'BIFF' } }; - run(function() { + run(() => { let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + ' using an `alias` computed property instead.'; @@ -27,15 +27,13 @@ QUnit.test('Defining a property ending in Binding should setup binding when appl }); QUnit.test('Defining a property ending in Binding should apply to prototype children', function() { - var MyMixin, obj, obj2; - - run(function() { - MyMixin = Mixin.create({ + let MyMixin = run(() => { + return Mixin.create({ fooBinding: 'bar.baz' }); }); - obj = { bar: { baz: 'BIFF' } }; + let obj = { bar: { baz: 'BIFF' } }; run(function() { let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + @@ -47,11 +45,8 @@ QUnit.test('Defining a property ending in Binding should apply to prototype chil }); - obj2 = Object.create(obj); - run(function() { - set(get(obj2, 'bar'), 'baz', 'BARG'); - }); - + let obj2 = Object.create(obj); + run(() => set(get(obj2, 'bar'), 'baz', 'BARG')); ok(get(obj2, 'fooBinding') instanceof Binding, 'should be a binding object'); equal(get(obj2, 'foo'), 'BARG', 'binding should be created and synced'); diff --git a/packages/ember-runtime/tests/inject_test.js b/packages/ember-runtime/tests/inject_test.js index ea25190c37a..79750683376 100644 --- a/packages/ember-runtime/tests/inject_test.js +++ b/packages/ember-runtime/tests/inject_test.js @@ -11,7 +11,7 @@ import buildOwner from 'container/tests/test-helpers/build-owner'; QUnit.module('inject'); QUnit.test('calling `inject` directly should error', function() { - expectAssertion(function() { + expectAssertion(() => { inject('foo'); }, /Injected properties must be created through helpers/); }); @@ -28,7 +28,7 @@ if (!EmberDev.runningProdBuild) { let owner = buildOwner(); - var AnObject = Object.extend({ + let AnObject = Object.extend({ bar: inject.foo(), baz: inject.foo() }); @@ -39,20 +39,20 @@ if (!EmberDev.runningProdBuild) { QUnit.test('attempting to inject a nonexistent container key should error', function() { let owner = buildOwner(); - var AnObject = Object.extend({ + let AnObject = Object.extend({ foo: new InjectedProperty('bar', 'baz') }); owner.register('foo:main', AnObject); - throws(function() { + throws(() => { owner.lookup('foo:main'); }, /Attempting to inject an unknown injection: 'bar:baz'/); }); } QUnit.test('factories should return a list of lazy injection full names', function() { - var AnObject = Object.extend({ + let AnObject = Object.extend({ foo: new InjectedProperty('foo', 'bar'), bar: new InjectedProperty('quux') }); diff --git a/packages/ember-runtime/tests/legacy_1x/mixins/observable/chained_test.js b/packages/ember-runtime/tests/legacy_1x/mixins/observable/chained_test.js index 63948eb23f7..c25d8a67174 100644 --- a/packages/ember-runtime/tests/legacy_1x/mixins/observable/chained_test.js +++ b/packages/ember-runtime/tests/legacy_1x/mixins/observable/chained_test.js @@ -19,38 +19,38 @@ import { A as emberA } from 'ember-runtime/system/native_array'; QUnit.module('Ember.Observable - Observing with @each'); QUnit.test('chained observers on enumerable properties are triggered when the observed property of any item changes', function() { - var family = EmberObject.create({ momma: null }); - var momma = EmberObject.create({ children: [] }); + let family = EmberObject.create({ momma: null }); + let momma = EmberObject.create({ children: [] }); - var child1 = EmberObject.create({ name: 'Bartholomew' }); - var child2 = EmberObject.create({ name: 'Agnes' }); - var child3 = EmberObject.create({ name: 'Dan' }); - var child4 = EmberObject.create({ name: 'Nancy' }); + let child1 = EmberObject.create({ name: 'Bartholomew' }); + let child2 = EmberObject.create({ name: 'Agnes' }); + let child3 = EmberObject.create({ name: 'Dan' }); + let child4 = EmberObject.create({ name: 'Nancy' }); set(family, 'momma', momma); set(momma, 'children', emberA([child1, child2, child3])); - var observerFiredCount = 0; + let observerFiredCount = 0; addObserver(family, 'momma.children.@each.name', this, function() { observerFiredCount++; }); observerFiredCount = 0; - run(function() { get(momma, 'children').setEach('name', 'Juan'); }); + run(() => get(momma, 'children').setEach('name', 'Juan')); equal(observerFiredCount, 3, 'observer fired after changing child names'); observerFiredCount = 0; - run(function() { get(momma, 'children').pushObject(child4); }); + run(() => get(momma, 'children').pushObject(child4)); equal(observerFiredCount, 1, 'observer fired after adding a new item'); observerFiredCount = 0; - run(function() { set(child4, 'name', 'Herbert'); }); + run(() => set(child4, 'name', 'Herbert')); equal(observerFiredCount, 1, 'observer fired after changing property on new object'); set(momma, 'children', []); observerFiredCount = 0; - run(function() { set(child1, 'name', 'Hanna'); }); + run(() => set(child1, 'name', 'Hanna')); equal(observerFiredCount, 0, 'observer did not fire after removing changing property on a removed object'); }); diff --git a/packages/ember-runtime/tests/legacy_1x/mixins/observable/propertyChanges_test.js b/packages/ember-runtime/tests/legacy_1x/mixins/observable/propertyChanges_test.js index e8b874b2861..4618f55a736 100644 --- a/packages/ember-runtime/tests/legacy_1x/mixins/observable/propertyChanges_test.js +++ b/packages/ember-runtime/tests/legacy_1x/mixins/observable/propertyChanges_test.js @@ -22,10 +22,10 @@ import Observable from 'ember-runtime/mixins/observable'; import {computed} from 'ember-metal/computed'; import {observer} from 'ember-metal/mixin'; -var ObservableObject = EmberObject.extend(Observable); +const ObservableObject = EmberObject.extend(Observable); -var revMatches = false; -var ObjectA; +let revMatches = false; +let ObjectA; QUnit.module('object.propertyChanges', { setup() { @@ -117,7 +117,7 @@ QUnit.test('should notify that the property of an object has changed', function( }); QUnit.test('should invalidate function property cache when notifyPropertyChange is called', function() { - var a = ObservableObject.extend({ + let a = ObservableObject.extend({ b: computed({ get() { return this._b; }, set(key, value) { diff --git a/packages/ember-runtime/tests/legacy_1x/system/binding_test.js b/packages/ember-runtime/tests/legacy_1x/system/binding_test.js index 3bc64b5bb48..12a0425546c 100644 --- a/packages/ember-runtime/tests/legacy_1x/system/binding_test.js +++ b/packages/ember-runtime/tests/legacy_1x/system/binding_test.js @@ -45,7 +45,7 @@ import EmberObject from 'ember-runtime/system/object'; // ======================================================================== let TestNamespace, fromObject, toObject, binding, Bon1, bon2, root; // global variables -let originalLookup = context.lookup; +const originalLookup = context.lookup; let lookup; QUnit.module('basic object binding', { @@ -53,7 +53,7 @@ QUnit.module('basic object binding', { fromObject = EmberObject.create({ value: 'start' }); toObject = EmberObject.create({ value: 'end' }); root = { fromObject: fromObject, toObject: toObject }; - run(function () { + run(() => { let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + ' using an `alias` computed property instead.'; @@ -69,7 +69,7 @@ QUnit.test('binding should have synced on connect', function() { }); QUnit.test('fromObject change should propagate to toObject only after flush', function() { - run(function () { + run(() => { set(fromObject, 'value', 'change'); equal(get(toObject, 'value'), 'start'); }); @@ -77,7 +77,7 @@ QUnit.test('fromObject change should propagate to toObject only after flush', fu }); QUnit.test('toObject change should propagate to fromObject only after flush', function() { - run(function () { + run(() => { set(toObject, 'value', 'change'); equal(get(fromObject, 'value'), 'start'); }); @@ -104,7 +104,7 @@ QUnit.test('deferred observing during bindings', function() { callCount: 0 }); - var root = { fromObject: fromObject, toObject: toObject }; + let root = { fromObject: fromObject, toObject: toObject }; run(function () { let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + ' using an `alias` computed property instead.'; @@ -134,7 +134,7 @@ QUnit.test('binding disconnection actually works', function() { equal(get(toObject, 'value'), 'start'); }); -var first, second, third, binding1, binding2; // global variables +let first, second, third, binding1, binding2; // global variables // .......................................................... // chained binding @@ -224,11 +224,11 @@ QUnit.module('Custom Binding', { QUnit.test('two bindings to the same value should sync in the order they are initialized', function() { run.begin(); - var a = EmberObject.create({ + let a = EmberObject.create({ foo: 'bar' }); - var b = EmberObject.extend({ + let b = EmberObject.extend({ C: EmberObject.extend({ foo: 'bee', fooBinding: 'owner.foo' @@ -267,7 +267,7 @@ QUnit.module('propertyNameBinding with longhand', { context.lookup = lookup = {}; lookup['TestNamespace'] = TestNamespace = {}; - run(function () { + run(() => { TestNamespace.fromObject = EmberObject.create({ value: 'originalValue' }); @@ -292,29 +292,21 @@ QUnit.module('propertyNameBinding with longhand', { }); QUnit.test('works with full path', function() { - run(function () { - set(TestNamespace.fromObject, 'value', 'updatedValue'); - }); + run(() => set(TestNamespace.fromObject, 'value', 'updatedValue')); equal(get(TestNamespace.toObject, 'value'), 'updatedValue'); - run(function () { - set(TestNamespace.fromObject, 'value', 'newerValue'); - }); + run(() => set(TestNamespace.fromObject, 'value', 'newerValue')); equal(get(TestNamespace.toObject, 'value'), 'newerValue'); }); QUnit.test('works with local path', function() { - run(function () { - set(TestNamespace.toObject, 'localValue', 'updatedValue'); - }); + run(() => set(TestNamespace.toObject, 'localValue', 'updatedValue')); equal(get(TestNamespace.toObject, 'relative'), 'updatedValue'); - run(function () { - set(TestNamespace.toObject, 'localValue', 'newerValue'); - }); + run(() => set(TestNamespace.toObject, 'localValue', 'newerValue')); equal(get(TestNamespace.toObject, 'relative'), 'newerValue'); }); diff --git a/packages/ember-runtime/tests/legacy_1x/system/object/base_test.js b/packages/ember-runtime/tests/legacy_1x/system/object/base_test.js index fa829a1a737..023c2d623aa 100644 --- a/packages/ember-runtime/tests/legacy_1x/system/object/base_test.js +++ b/packages/ember-runtime/tests/legacy_1x/system/object/base_test.js @@ -24,7 +24,7 @@ import EmberObject from 'ember-runtime/system/object'; // EmberObject Base Tests // ======================================================================== -var obj, obj1, don; // global variables +let obj, obj1, don; // global variables QUnit.module('A new EmberObject instance', { diff --git a/packages/ember-runtime/tests/legacy_1x/system/object/bindings_test.js b/packages/ember-runtime/tests/legacy_1x/system/object/bindings_test.js index d6abe7c1e99..5fc3bd67712 100644 --- a/packages/ember-runtime/tests/legacy_1x/system/object/bindings_test.js +++ b/packages/ember-runtime/tests/legacy_1x/system/object/bindings_test.js @@ -25,8 +25,7 @@ let originalLookup = context.lookup; let testObject, fromObject, extraObject, TestObject; let TestNamespace, lookup; -var bindModuleOpts = { - +QUnit.module('bind() method', { setup() { context.lookup = lookup = {}; @@ -55,13 +54,10 @@ var bindModuleOpts = { testObject = fromObject = extraObject = null; context.lookup = originalLookup; } - -}; - -QUnit.module('bind() method', bindModuleOpts); +}); QUnit.test('bind(TestNamespace.fromObject.bar) should follow absolute path', function() { - run(function() { + run(() => { let deprecationMessage = '`Ember.Binding` is deprecated. Since you' + ' are binding to a global consider using a service instead.'; @@ -78,7 +74,7 @@ QUnit.test('bind(TestNamespace.fromObject.bar) should follow absolute path', fun }); QUnit.test('bind(.bar) should bind to relative path', function() { - run(function() { + run(() => { let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + ' using an `alias` computed property instead.'; @@ -94,8 +90,7 @@ QUnit.test('bind(.bar) should bind to relative path', function() { equal('changedValue', get(testObject, 'foo'), 'testObject.foo'); }); -var fooBindingModuleOpts = { - +QUnit.module('fooBinding method', { setup() { context.lookup = lookup = {}; @@ -125,14 +120,10 @@ var fooBindingModuleOpts = { TestObject = fromObject = extraObject = null; // delete TestNamespace; } - -}; - -QUnit.module('fooBinding method', fooBindingModuleOpts); - +}); QUnit.test('fooBinding: TestNamespace.fromObject.bar should follow absolute path', function() { - run(function() { + run(() => { let deprecationMessage = '`Ember.Binding` is deprecated. Since you' + ' are binding to a global consider using a service instead.'; @@ -151,7 +142,7 @@ QUnit.test('fooBinding: TestNamespace.fromObject.bar should follow absolute path }); QUnit.test('fooBinding: .bar should bind to relative path', function() { - run(function() { + run(() => { let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + ' using an `alias` computed property instead.'; @@ -170,7 +161,7 @@ QUnit.test('fooBinding: .bar should bind to relative path', function() { }); QUnit.test('fooBinding: should disconnect bindings when destroyed', function () { - run(function() { + run(() => { let deprecationMessage = '`Ember.Binding` is deprecated. Since you' + ' are binding to a global consider using a service instead.'; @@ -186,13 +177,9 @@ QUnit.test('fooBinding: should disconnect bindings when destroyed', function () equal(get(testObject, 'foo'), 'BAZ', 'binding should have synced'); - run(() => { - testObject.destroy(); - }); + run(() => testObject.destroy()); - run(function() { - set(TestNamespace.fromObject, 'bar', 'BIFF'); - }); + run(() => set(TestNamespace.fromObject, 'bar', 'BIFF')); ok(get(testObject, 'foo') !== 'bar', 'binding should not have synced'); }); diff --git a/packages/ember-runtime/tests/legacy_1x/system/object/concatenated_test.js b/packages/ember-runtime/tests/legacy_1x/system/object/concatenated_test.js index 1b34d91a726..a5d42c570ee 100644 --- a/packages/ember-runtime/tests/legacy_1x/system/object/concatenated_test.js +++ b/packages/ember-runtime/tests/legacy_1x/system/object/concatenated_test.js @@ -15,7 +15,7 @@ import EmberObject from 'ember-runtime/system/object'; function K() { return this; } -var klass; +let klass; QUnit.module('EmberObject Concatenated Properties', { setup() { @@ -28,24 +28,24 @@ QUnit.module('EmberObject Concatenated Properties', { }); QUnit.test('concatenates instances', function() { - var obj = klass.create({ + let obj = klass.create({ values: ['d', 'e', 'f'] }); - var values = get(obj, 'values'); - var expected = ['a', 'b', 'c', 'd', 'e', 'f']; + let values = get(obj, 'values'); + let expected = ['a', 'b', 'c', 'd', 'e', 'f']; deepEqual(values, expected, `should concatenate values property (expected: ${expected}, got: ${values})`); }); QUnit.test('concatenates subclasses', function() { - var subKlass = klass.extend({ + let subKlass = klass.extend({ values: ['d', 'e', 'f'] }); - var obj = subKlass.create(); + let obj = subKlass.create(); - var values = get(obj, 'values'); - var expected = ['a', 'b', 'c', 'd', 'e', 'f']; + let values = get(obj, 'values'); + let expected = ['a', 'b', 'c', 'd', 'e', 'f']; deepEqual(values, expected, `should concatenate values property (expected: ${expected}, got: ${values})`); }); @@ -54,51 +54,48 @@ QUnit.test('concatenates reopen', function() { klass.reopen({ values: ['d', 'e', 'f'] }); - var obj = klass.create(); + let obj = klass.create(); - var values = get(obj, 'values'); - var expected = ['a', 'b', 'c', 'd', 'e', 'f']; + let values = get(obj, 'values'); + let expected = ['a', 'b', 'c', 'd', 'e', 'f']; deepEqual(values, expected, `should concatenate values property (expected: ${expected}, got: ${values})`); }); QUnit.test('concatenates mixin', function() { - var mixin = { + let mixin = { values: ['d', 'e'] }; - var subKlass = klass.extend(mixin, { + let subKlass = klass.extend(mixin, { values: ['f'] }); - var obj = subKlass.create(); + let obj = subKlass.create(); - var values = get(obj, 'values'); - var expected = ['a', 'b', 'c', 'd', 'e', 'f']; + let values = get(obj, 'values'); + let expected = ['a', 'b', 'c', 'd', 'e', 'f']; deepEqual(values, expected, `should concatenate values property (expected: ${expected}, got: ${values})`); }); QUnit.test('concatenates reopen, subclass, and instance', function() { klass.reopen({ values: ['d'] }); - var subKlass = klass.extend({ values: ['e'] }); - var obj = subKlass.create({ values: ['f'] }); + let subKlass = klass.extend({ values: ['e'] }); + let obj = subKlass.create({ values: ['f'] }); - var values = get(obj, 'values'); - var expected = ['a', 'b', 'c', 'd', 'e', 'f']; + let values = get(obj, 'values'); + let expected = ['a', 'b', 'c', 'd', 'e', 'f']; deepEqual(values, expected, `should concatenate values property (expected: ${expected}, got: ${values})`); }); QUnit.test('concatenates subclasses when the values are functions', function() { - var subKlass = klass.extend({ + let subKlass = klass.extend({ functions: K }); - var obj = subKlass.create(); + let obj = subKlass.create(); - var values = get(obj, 'functions'); - var expected = [K, K]; + let values = get(obj, 'functions'); + let expected = [K, K]; deepEqual(values, expected, `should concatenate functions property (expected: ${expected}, got: ${values})`); }); - - - diff --git a/packages/ember-runtime/tests/legacy_1x/system/run_loop_test.js b/packages/ember-runtime/tests/legacy_1x/system/run_loop_test.js index 4c752b7dc80..2599a62efd7 100644 --- a/packages/ember-runtime/tests/legacy_1x/system/run_loop_test.js +++ b/packages/ember-runtime/tests/legacy_1x/system/run_loop_test.js @@ -18,7 +18,7 @@ import EmberObject from 'ember-runtime/system/object'; broken anyway. I don't think it ever even worked. */ -var MyApp, binding1, binding2; +let MyApp, binding1, binding2; QUnit.module('System:run_loop() - chained binding', { setup() { @@ -43,7 +43,7 @@ QUnit.module('System:run_loop() - chained binding', { }); QUnit.test('Should propagate bindings after the RunLoop completes (using Ember.RunLoop)', function() { - run(function () { + run(() => { let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + ' using an `alias` computed property instead.'; @@ -60,7 +60,7 @@ QUnit.test('Should propagate bindings after the RunLoop completes (using Ember.R }, deprecationMessage); }); - run(function () { + run(() => { // Based on the above binding if you change the output of MyApp.first // object it should change the all the variable of // MyApp.first,MyApp.second and MyApp.third object @@ -81,7 +81,7 @@ QUnit.test('Should propagate bindings after the RunLoop completes (using Ember.R }); QUnit.test('Should propagate bindings after the RunLoop completes', function() { - run(function () { + run(() => { let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + ' using an `alias` computed property instead.'; @@ -98,7 +98,7 @@ QUnit.test('Should propagate bindings after the RunLoop completes', function() { }, deprecationMessage); }); - run(function () { + run(() => { //Based on the above binding if you change the output of MyApp.first object it should //change the all the variable of MyApp.first,MyApp.second and MyApp.third object MyApp.first.set('output', 'change'); diff --git a/packages/ember-runtime/tests/mixins/array_test.js b/packages/ember-runtime/tests/mixins/array_test.js index fdd6d08175a..394501dd071 100644 --- a/packages/ember-runtime/tests/mixins/array_test.js +++ b/packages/ember-runtime/tests/mixins/array_test.js @@ -17,8 +17,7 @@ import { A as emberA } from 'ember-runtime/system/native_array'; Implement a basic fake mutable array. This validates that any non-native enumerable can impl this API. */ -var TestArray = EmberObject.extend(EmberArray, { - +const TestArray = EmberObject.extend(EmberArray, { _content: null, init(ary = []) { @@ -29,7 +28,7 @@ var TestArray = EmberObject.extend(EmberArray, { // arrays can be modified even if they don't implement MutableArray. The // MutableArray is just a standard API for mutation but not required. addObject(obj) { - var idx = this._content.length; + let idx = this._content.length; this.arrayContentWillChange(idx, 0, 1); this._content.push(obj); this.arrayContentDidChange(idx, 0, 1); @@ -72,15 +71,15 @@ ArrayTests.extend({ }).run(); QUnit.test('the return value of slice has Ember.Array applied', function() { - var x = EmberObject.extend(EmberArray).create({ + let x = EmberObject.extend(EmberArray).create({ length: 0 }); - var y = x.slice(1); + let y = x.slice(1); equal(EmberArray.detect(y), true, 'mixin should be applied'); }); QUnit.test('slice supports negative index arguments', function() { - var testArray = new TestArray([1, 2, 3, 4]); + let testArray = new TestArray([1, 2, 3, 4]); deepEqual(testArray.slice(-2), [3, 4], 'slice(-2)'); deepEqual(testArray.slice(-2, -1), [3], 'slice(-2, -1'); @@ -100,14 +99,13 @@ QUnit.test('slice supports negative index arguments', function() { // CONTENT DID CHANGE // -var DummyArray = EmberObject.extend(EmberArray, { +const DummyArray = EmberObject.extend(EmberArray, { nextObject() {}, length: 0, objectAt(idx) { return 'ITEM-' + idx; } }); -var obj, observer; - +let obj, observer; // .......................................................... // NOTIFY ARRAY OBSERVERS @@ -314,7 +312,7 @@ QUnit.test('removing enumerable observer should disable', function() { // @each // -var ary; +let ary; QUnit.module('EmberArray.@each support', { setup() { @@ -332,9 +330,9 @@ QUnit.module('EmberArray.@each support', { }); QUnit.test('adding an object should notify (@each.isDone)', function() { - var called = 0; + let called = 0; - var observerObject = EmberObject.create({ + let observerObject = EmberObject.create({ wasCalled() { called++; } @@ -351,9 +349,9 @@ QUnit.test('adding an object should notify (@each.isDone)', function() { }); QUnit.test('using @each to observe arrays that does not return objects raise error', function() { - var called = 0; + let called = 0; - var observerObject = EmberObject.create({ + let observerObject = EmberObject.create({ wasCalled() { called++; } @@ -367,7 +365,7 @@ QUnit.test('using @each to observe arrays that does not return objects raise err addObserver(ary, '@each.isDone', observerObject, 'wasCalled'); - expectAssertion(function() { + expectAssertion(() => { ary.addObject(EmberObject.create({ desc: 'foo', isDone: false @@ -383,13 +381,13 @@ QUnit.test('modifying the array should also indicate the isDone prop itself has // EachArray materialized but just want to know when the property has // changed. - var each = get(ary, '@each'); - var count = 0; + let each = get(ary, '@each'); + let count = 0; - addObserver(each, 'isDone', function() { count++; }); + addObserver(each, 'isDone', () => count++); count = 0; - var item = objectAt(ary, 2); + let item = objectAt(ary, 2); set(item, 'isDone', !get(item, 'isDone')); equal(count, 1, '@each.isDone should have notified'); }); @@ -401,7 +399,7 @@ QUnit.test('`objectAt` returns correct object', function() { }); testBoth('should be clear caches for computed properties that have dependent keys on arrays that are changed after object initialization', function(get, set) { - var obj = EmberObject.extend({ + let obj = EmberObject.extend({ init() { this._super(...arguments); set(this, 'resources', emberA()); @@ -420,18 +418,16 @@ testBoth('should be clear caches for computed properties that have dependent key }); testBoth('observers that contain @each in the path should fire only once the first time they are accessed', function(get, set) { - var count = 0; + let count = 0; - var obj = EmberObject.extend({ + let obj = EmberObject.extend({ init() { this._super(...arguments); // Observer does not fire on init set(this, 'resources', emberA()); }, - commonDidChange: emberObserver('resources.@each.common', function() { - count++; - }) + commonDidChange: emberObserver('resources.@each.common', () => count++) }).create(); // Observer fires second time when new object is added diff --git a/packages/ember-runtime/tests/mixins/comparable_test.js b/packages/ember-runtime/tests/mixins/comparable_test.js index 1b18c1b66b6..5cb2039236d 100644 --- a/packages/ember-runtime/tests/mixins/comparable_test.js +++ b/packages/ember-runtime/tests/mixins/comparable_test.js @@ -3,7 +3,7 @@ import EmberObject from 'ember-runtime/system/object'; import compare from 'ember-runtime/compare'; import Comparable from 'ember-runtime/mixins/comparable'; -var Rectangle = EmberObject.extend(Comparable, { +const Rectangle = EmberObject.extend(Comparable, { length: 0, width: 0, @@ -17,18 +17,13 @@ var Rectangle = EmberObject.extend(Comparable, { }); -var r1, r2; +let r1, r2; QUnit.module('Comparable', { - setup() { r1 = Rectangle.create({ length: 6, width: 12 }); r2 = Rectangle.create({ length: 6, width: 13 }); - }, - - teardown() { } - }); QUnit.test('should be comparable and return the correct result', function() { diff --git a/packages/ember-runtime/tests/mixins/copyable_test.js b/packages/ember-runtime/tests/mixins/copyable_test.js index 97c0f788606..be4b79b10bd 100644 --- a/packages/ember-runtime/tests/mixins/copyable_test.js +++ b/packages/ember-runtime/tests/mixins/copyable_test.js @@ -11,7 +11,7 @@ QUnit.module('Ember.Copyable.frozenCopy'); QUnit.test('should be deprecated', function() { expectDeprecation('`frozenCopy` is deprecated, use `Object.freeze` instead.'); - var Obj = EmberObject.extend(Freezable, Copyable, { + let Obj = EmberObject.extend(Freezable, Copyable, { copy() { return Obj.create(); } @@ -20,8 +20,7 @@ QUnit.test('should be deprecated', function() { Obj.create().frozenCopy(); }); -var CopyableObject = EmberObject.extend(Copyable, { - +const CopyableObject = EmberObject.extend(Copyable, { id: null, init() { @@ -30,7 +29,7 @@ var CopyableObject = EmberObject.extend(Copyable, { }, copy() { - var ret = new CopyableObject(); + let ret = new CopyableObject(); set(ret, 'id', get(this, 'id')); return ret; } diff --git a/packages/ember-runtime/tests/mixins/enumerable_test.js b/packages/ember-runtime/tests/mixins/enumerable_test.js index 37618f9a356..1bae861c124 100644 --- a/packages/ember-runtime/tests/mixins/enumerable_test.js +++ b/packages/ember-runtime/tests/mixins/enumerable_test.js @@ -10,13 +10,11 @@ import isEnabled from 'ember-metal/features'; function K() { return this; } - /* Implement a basic fake enumerable. This validates that any non-native enumerable can impl this API. */ -var TestEnumerable = EmberObject.extend(Enumerable, { - +const TestEnumerable = EmberObject.extend(Enumerable, { _content: null, init(ary = []) { @@ -48,7 +46,6 @@ var TestEnumerable = EmberObject.extend(Enumerable, { EnumerableTests.extend({ - name: 'Basic Enumerable', newObject(ary) { @@ -70,31 +67,31 @@ EnumerableTests.extend({ QUnit.module('Ember.Enumerable'); QUnit.test('should apply Ember.Array to return value of map', function() { - var x = EmberObject.extend(Enumerable).create(); - var y = x.map(K); + let x = EmberObject.extend(Enumerable).create(); + let y = x.map(K); equal(EmberArray.detect(y), true, 'should have mixin applied'); }); QUnit.test('should apply Ember.Array to return value of filter', function() { - var x = EmberObject.extend(Enumerable).create(); - var y = x.filter(K); + let x = EmberObject.extend(Enumerable).create(); + let y = x.filter(K); equal(EmberArray.detect(y), true, 'should have mixin applied'); }); QUnit.test('should apply Ember.Array to return value of invoke', function() { - var x = EmberObject.extend(Enumerable).create(); - var y = x.invoke(K); + let x = EmberObject.extend(Enumerable).create(); + let y = x.invoke(K); equal(EmberArray.detect(y), true, 'should have mixin applied'); }); QUnit.test('should apply Ember.Array to return value of toArray', function() { - var x = EmberObject.extend(Enumerable).create(); - var y = x.toArray(K); + let x = EmberObject.extend(Enumerable).create(); + let y = x.toArray(K); equal(EmberArray.detect(y), true, 'should have mixin applied'); }); QUnit.test('should apply Ember.Array to return value of without', function() { - var X = EmberObject.extend(Enumerable, { + let X = EmberObject.extend(Enumerable, { contains() { return true; } @@ -108,59 +105,57 @@ QUnit.test('should apply Ember.Array to return value of without', function() { }); } - var x = X.create(); - var y = x.without(K); + let x = X.create(); + let y = x.without(K); equal(EmberArray.detect(y), true, 'should have mixin applied'); }); QUnit.test('should apply Ember.Array to return value of uniq', function() { - var x = EmberObject.extend(Enumerable).create(); - var y = x.uniq(K); + let x = EmberObject.extend(Enumerable).create(); + let y = x.uniq(K); equal(EmberArray.detect(y), true, 'should have mixin applied'); }); QUnit.test('any', function() { - var kittens = emberA([{ + let kittens = emberA([{ color: 'white' }, { color: 'black' }, { color: 'white' }]); - var foundWhite = kittens.any(function(kitten) { return kitten.color === 'white'; }); - var foundWhite2 = kittens.isAny('color', 'white'); + let foundWhite = kittens.any(kitten => kitten.color === 'white'); + let foundWhite2 = kittens.isAny('color', 'white'); equal(foundWhite, true); equal(foundWhite2, true); }); QUnit.test('any with NaN', function() { - var numbers = emberA([1, 2, NaN, 4]); + let numbers = emberA([1, 2, NaN, 4]); - var hasNaN = numbers.any(function(n) { - return isNaN(n); - }); + let hasNaN = numbers.any(n => isNaN(n)); equal(hasNaN, true, 'works when matching NaN'); }); QUnit.test('every', function() { - var allColorsKittens = emberA([{ + let allColorsKittens = emberA([{ color: 'white' }, { color: 'black' }, { color: 'white' }]); - var allWhiteKittens = emberA([{ + let allWhiteKittens = emberA([{ color: 'white' }, { color: 'white' }, { color: 'white' }]); - var allWhite = false; - var whiteKittenPredicate = function(kitten) { return kitten.color === 'white'; }; + let allWhite = false; + let whiteKittenPredicate = function(kitten) { return kitten.color === 'white'; }; allWhite = allColorsKittens.every(whiteKittenPredicate); equal(allWhite, false); @@ -177,7 +172,7 @@ QUnit.test('every', function() { if (isEnabled('ember-runtime-enumerable-includes')) { QUnit.test('should throw an error passing a second argument to includes', function() { - var x = EmberObject.extend(Enumerable).create(); + let x = EmberObject.extend(Enumerable).create(); equal(x.includes('any'), false); expectAssertion(() => { @@ -190,12 +185,12 @@ if (isEnabled('ember-runtime-enumerable-includes')) { // CONTENT DID CHANGE // -var DummyEnum = EmberObject.extend(Enumerable, { +let DummyEnum = EmberObject.extend(Enumerable, { nextObject() {}, length: 0 }); -var obj, observer; +let obj, observer; // .......................................................... // NOTIFY ENUMERABLE PROPERTY @@ -204,7 +199,7 @@ var obj, observer; QUnit.module('mixins/enumerable/enumerableContentDidChange'); QUnit.test('should notify observers of []', function() { - var obj = EmberObject.extend(Enumerable, { + let obj = EmberObject.extend(Enumerable, { nextObject() {}, // avoid exceptions enumerablePropertyDidChange: emberObserver('[]', function() { @@ -252,8 +247,8 @@ QUnit.test('should notify observers when call with no params', function() { // API variation that included items only QUnit.test('should not notify when passed arrays of same length', function() { - var added = ['foo']; - var removed = ['bar']; + let added = ['foo']; + let removed = ['bar']; obj.enumerableContentWillChange(removed, added); equal(obj._after, 0); @@ -263,8 +258,8 @@ QUnit.test('should not notify when passed arrays of same length', function() { }); QUnit.test('should notify when passed arrays of different length', function() { - var added = ['foo']; - var removed = ['bar', 'baz']; + let added = ['foo']; + let removed = ['bar', 'baz']; obj.enumerableContentWillChange(removed, added); equal(obj._after, 0); @@ -290,7 +285,6 @@ QUnit.test('should notify when passed old index API with delta', function() { equal(obj._after, 1); }); - // .......................................................... // NOTIFY ENUMERABLE OBSERVER // @@ -332,8 +326,8 @@ QUnit.test('should notify enumerable observers when called with no params', func // API variation that included items only QUnit.test('should notify when called with same length items', function() { - var added = ['foo']; - var removed = ['bar']; + let added = ['foo']; + let removed = ['bar']; obj.enumerableContentWillChange(removed, added); deepEqual(observer._before, [obj, removed, added]); @@ -343,8 +337,8 @@ QUnit.test('should notify when called with same length items', function() { }); QUnit.test('should notify when called with diff length items', function() { - var added = ['foo', 'baz']; - var removed = ['bar']; + let added = ['foo', 'baz']; + let removed = ['bar']; obj.enumerableContentWillChange(removed, added); deepEqual(observer._before, [obj, removed, added]); diff --git a/packages/ember-runtime/tests/mixins/mutable_array_test.js b/packages/ember-runtime/tests/mixins/mutable_array_test.js index 973330b2172..2cf64ed1ef7 100644 --- a/packages/ember-runtime/tests/mixins/mutable_array_test.js +++ b/packages/ember-runtime/tests/mixins/mutable_array_test.js @@ -8,7 +8,7 @@ import { A as emberA } from 'ember-runtime/system/native_array'; Implement a basic fake mutable array. This validates that any non-native enumerable can impl this API. */ -var TestMutableArray = EmberObject.extend(MutableArray, { +const TestMutableArray = EmberObject.extend(MutableArray, { _content: null, @@ -17,9 +17,9 @@ var TestMutableArray = EmberObject.extend(MutableArray, { }, replace(idx, amt, objects) { - var args = objects ? objects.slice() : []; - var removeAmt = amt; - var addAmt = args.length; + let args = objects ? objects.slice() : []; + let removeAmt = amt; + let addAmt = args.length; this.arrayContentWillChange(idx, removeAmt, addAmt); diff --git a/packages/ember-runtime/tests/mixins/mutable_enumerable_test.js b/packages/ember-runtime/tests/mixins/mutable_enumerable_test.js index bd603bc9988..75e924d4ba4 100644 --- a/packages/ember-runtime/tests/mixins/mutable_enumerable_test.js +++ b/packages/ember-runtime/tests/mixins/mutable_enumerable_test.js @@ -8,8 +8,7 @@ import { get } from 'ember-metal/property_get'; Implement a basic fake mutable array. This validates that any non-native enumerable can impl this API. */ -var TestMutableEnumerable = EmberObject.extend(MutableEnumerable, { - +const TestMutableEnumerable = EmberObject.extend(MutableEnumerable, { _content: null, addObject(obj) { @@ -23,7 +22,7 @@ var TestMutableEnumerable = EmberObject.extend(MutableEnumerable, { }, removeObject(obj) { - var idx = this._content.indexOf(obj); + let idx = this._content.indexOf(obj); if (idx < 0) { return this; } @@ -53,7 +52,6 @@ var TestMutableEnumerable = EmberObject.extend(MutableEnumerable, { MutableEnumerableTests.extend({ - name: 'Basic Mutable Array', newObject(ary) { @@ -69,5 +67,4 @@ MutableEnumerableTests.extend({ toArray(obj) { return obj.slice(); } - }).run(); diff --git a/packages/ember-runtime/tests/mixins/observable_test.js b/packages/ember-runtime/tests/mixins/observable_test.js index 6e98780fdf1..dc3910b6440 100644 --- a/packages/ember-runtime/tests/mixins/observable_test.js +++ b/packages/ember-runtime/tests/mixins/observable_test.js @@ -6,31 +6,31 @@ import { testBoth } from 'ember-metal/tests/props_helper'; QUnit.module('mixins/observable'); QUnit.test('should be able to use getProperties to get a POJO of provided keys', function() { - var obj = EmberObject.create({ + let obj = EmberObject.create({ firstName: 'Steve', lastName: 'Jobs', companyName: 'Apple, Inc.' }); - var pojo = obj.getProperties('firstName', 'lastName'); + let pojo = obj.getProperties('firstName', 'lastName'); equal('Steve', pojo.firstName); equal('Jobs', pojo.lastName); }); QUnit.test('should be able to use getProperties with array parameter to get a POJO of provided keys', function() { - var obj = EmberObject.create({ + let obj = EmberObject.create({ firstName: 'Steve', lastName: 'Jobs', companyName: 'Apple, Inc.' }); - var pojo = obj.getProperties(['firstName', 'lastName']); + let pojo = obj.getProperties(['firstName', 'lastName']); equal('Steve', pojo.firstName); equal('Jobs', pojo.lastName); }); QUnit.test('should be able to use setProperties to set multiple properties at once', function() { - var obj = EmberObject.create({ + let obj = EmberObject.create({ firstName: 'Steve', lastName: 'Jobs', companyName: 'Apple, Inc.' @@ -42,8 +42,8 @@ QUnit.test('should be able to use setProperties to set multiple properties at on }); testBoth('calling setProperties completes safely despite exceptions', function(get, set) { - var exc = new Error('Something unexpected happened!'); - var obj = EmberObject.extend({ + let exc = new Error('Something unexpected happened!'); + let obj = EmberObject.extend({ companyName: computed({ get() { return 'Apple, Inc.'; }, set(key, value) { throw exc; } @@ -53,9 +53,9 @@ testBoth('calling setProperties completes safely despite exceptions', function(g lastName: 'Jobs' }); - var firstNameChangedCount = 0; + let firstNameChangedCount = 0; - addObserver(obj, 'firstName', function() { firstNameChangedCount++; }); + addObserver(obj, 'firstName', () => firstNameChangedCount++); try { obj.setProperties({ @@ -73,7 +73,7 @@ testBoth('calling setProperties completes safely despite exceptions', function(g }); testBoth('should be able to retrieve cached values of computed properties without invoking the computed property', function(get) { - var obj = EmberObject.extend({ + let obj = EmberObject.extend({ foo: computed(function() { return 'foo'; }) @@ -91,7 +91,7 @@ testBoth('should be able to retrieve cached values of computed properties withou }); QUnit.test('incrementProperty should work even if value is number in string', function() { - var obj = EmberObject.create({ + let obj = EmberObject.create({ age: '24' }); obj.incrementProperty('age'); diff --git a/packages/ember-runtime/tests/mixins/promise_proxy_test.js b/packages/ember-runtime/tests/mixins/promise_proxy_test.js index 13cf8edc4a6..050edf784b8 100644 --- a/packages/ember-runtime/tests/mixins/promise_proxy_test.js +++ b/packages/ember-runtime/tests/mixins/promise_proxy_test.js @@ -8,7 +8,7 @@ import { } from 'ember-runtime/ext/rsvp'; import * as RSVP from 'rsvp'; -var ObjectPromiseProxy; +let ObjectPromiseProxy; QUnit.test('present on ember namespace', function() { ok(PromiseProxyMixin, 'expected PromiseProxyMixin to exist'); @@ -21,7 +21,7 @@ QUnit.module('Ember.PromiseProxy - ObjectProxy', { }); QUnit.test('no promise, invoking then should raise', function() { - var proxy = ObjectPromiseProxy.create(); + let proxy = ObjectPromiseProxy.create(); throws(function() { proxy.then(function() { return this; }, function() { return this; }); @@ -29,25 +29,22 @@ QUnit.test('no promise, invoking then should raise', function() { }); QUnit.test('fulfillment', function() { - var value = { + let value = { firstName: 'stef', lastName: 'penner' }; - var deferred = RSVP.defer(); + let deferred = RSVP.defer(); - var proxy = ObjectPromiseProxy.create({ + let proxy = ObjectPromiseProxy.create({ promise: deferred.promise }); - var didFulfillCount = 0; - var didRejectCount = 0; + let didFulfillCount = 0; + let didRejectCount = 0; - proxy.then(function() { - didFulfillCount++; - }, function() { - didRejectCount++; - }); + proxy.then(() => didFulfillCount++, + () => didRejectCount++); equal(get(proxy, 'content'), undefined, 'expects the proxy to have no content'); equal(get(proxy, 'reason'), undefined, 'expects the proxy to have no reason'); @@ -92,20 +89,17 @@ QUnit.test('fulfillment', function() { }); QUnit.test('rejection', function() { - var reason = new Error('failure'); - var deferred = RSVP.defer(); - var proxy = ObjectPromiseProxy.create({ + let reason = new Error('failure'); + let deferred = RSVP.defer(); + let proxy = ObjectPromiseProxy.create({ promise: deferred.promise }); - var didFulfillCount = 0; - var didRejectCount = 0; + let didFulfillCount = 0; + let didRejectCount = 0; - proxy.then(function() { - didFulfillCount++; - }, function() { - didRejectCount++; - }); + proxy.then(() => didFulfillCount++, + () => didRejectCount++); equal(get(proxy, 'content'), undefined, 'expects the proxy to have no content'); equal(get(proxy, 'reason'), undefined, 'expects the proxy to have no reason'); @@ -153,10 +147,10 @@ QUnit.test('unhandled rejects still propagate to RSVP.on(\'error\', ...) ', func RSVP.on('error', onerror); RSVP.off('error', onerrorDefault); - var expectedReason = new Error('failure'); - var deferred = RSVP.defer(); + let expectedReason = new Error('failure'); + let deferred = RSVP.defer(); - var proxy = ObjectPromiseProxy.create({ + let proxy = ObjectPromiseProxy.create({ promise: deferred.promise }); @@ -189,17 +183,17 @@ QUnit.test('should work with promise inheritance', function() { PromiseSubclass.prototype.constructor = PromiseSubclass; PromiseSubclass.cast = RSVP.Promise.cast; - var proxy = ObjectPromiseProxy.create({ - promise: new PromiseSubclass(function() { }) + let proxy = ObjectPromiseProxy.create({ + promise: new PromiseSubclass(() => { }) }); ok(proxy.then() instanceof PromiseSubclass, 'promise proxy respected inheritance'); }); QUnit.test('should reset isFulfilled and isRejected when promise is reset', function() { - var deferred = EmberRSVP.defer(); + let deferred = EmberRSVP.defer(); - var proxy = ObjectPromiseProxy.create({ + let proxy = ObjectPromiseProxy.create({ promise: deferred.promise }); @@ -215,7 +209,7 @@ QUnit.test('should reset isFulfilled and isRejected when promise is reset', func equal(get(proxy, 'isRejected'), false, 'expects the proxy to indicate that it is not rejected'); equal(get(proxy, 'isFulfilled'), true, 'expects the proxy to indicate that it is fulfilled'); - var anotherDeferred = EmberRSVP.defer(); + let anotherDeferred = EmberRSVP.defer(); proxy.set('promise', anotherDeferred.promise); equal(get(proxy, 'isPending'), true, 'expects the proxy to indicate that it is loading'); @@ -232,30 +226,26 @@ QUnit.test('should reset isFulfilled and isRejected when promise is reset', func }); QUnit.test('should have content when isFulfilled is set', function() { - var deferred = EmberRSVP.defer(); + let deferred = EmberRSVP.defer(); - var proxy = ObjectPromiseProxy.create({ + let proxy = ObjectPromiseProxy.create({ promise: deferred.promise }); - proxy.addObserver('isFulfilled', function() { - equal(get(proxy, 'content'), true); - }); + proxy.addObserver('isFulfilled', () => equal(get(proxy, 'content'), true)); run(deferred, 'resolve', true); }); QUnit.test('should have reason when isRejected is set', function() { - var error = new Error('Y U REJECT?!?'); - var deferred = EmberRSVP.defer(); + let error = new Error('Y U REJECT?!?'); + let deferred = EmberRSVP.defer(); - var proxy = ObjectPromiseProxy.create({ + let proxy = ObjectPromiseProxy.create({ promise: deferred.promise }); - proxy.addObserver('isRejected', function() { - equal(get(proxy, 'reason'), error); - }); + proxy.addObserver('isRejected', () => equal(get(proxy, 'reason'), error)); try { run(deferred, 'reject', error); diff --git a/packages/ember-runtime/tests/mixins/target_action_support_test.js b/packages/ember-runtime/tests/mixins/target_action_support_test.js index 03e426c3b47..f4ca3d10f73 100644 --- a/packages/ember-runtime/tests/mixins/target_action_support_test.js +++ b/packages/ember-runtime/tests/mixins/target_action_support_test.js @@ -17,7 +17,7 @@ QUnit.module('TargetActionSupport', { QUnit.test('it should return false if no target or action are specified', function() { expect(1); - var obj = EmberObject.extend(TargetActionSupport).create(); + let obj = EmberObject.extend(TargetActionSupport).create(); ok(false === obj.triggerAction(), 'no target or action was specified'); }); @@ -25,7 +25,7 @@ QUnit.test('it should return false if no target or action are specified', functi QUnit.test('it should support actions specified as strings', function() { expect(2); - var obj = EmberObject.extend(TargetActionSupport).create({ + let obj = EmberObject.extend(TargetActionSupport).create({ target: EmberObject.create({ anEvent() { ok(true, 'anEvent method was called'); @@ -41,7 +41,7 @@ QUnit.test('it should support actions specified as strings', function() { QUnit.test('it should invoke the send() method on objects that implement it', function() { expect(3); - var obj = EmberObject.extend(TargetActionSupport).create({ + let obj = EmberObject.extend(TargetActionSupport).create({ target: EmberObject.create({ send(evt, context) { equal(evt, 'anEvent', 'send() method was invoked with correct event name'); @@ -58,7 +58,7 @@ QUnit.test('it should invoke the send() method on objects that implement it', fu QUnit.test('it should find targets specified using a property path', function() { expect(2); - var Test = {}; + let Test = {}; lookup.Test = Test; Test.targetObj = EmberObject.create({ @@ -67,7 +67,7 @@ QUnit.test('it should find targets specified using a property path', function() } }); - var myObj = EmberObject.extend(TargetActionSupport).create({ + let myObj = EmberObject.extend(TargetActionSupport).create({ target: 'Test.targetObj', action: 'anEvent' }); @@ -77,7 +77,7 @@ QUnit.test('it should find targets specified using a property path', function() QUnit.test('it should use an actionContext object specified as a property on the object', function() { expect(2); - var obj = EmberObject.extend(TargetActionSupport).create({ + let obj = EmberObject.extend(TargetActionSupport).create({ action: 'anEvent', actionContext: {}, target: EmberObject.create({ @@ -92,11 +92,11 @@ QUnit.test('it should use an actionContext object specified as a property on the QUnit.test('it should find an actionContext specified as a property path', function() { expect(2); - var Test = {}; + let Test = {}; lookup.Test = Test; Test.aContext = {}; - var obj = EmberObject.extend(TargetActionSupport).create({ + let obj = EmberObject.extend(TargetActionSupport).create({ action: 'anEvent', actionContext: 'Test.aContext', target: EmberObject.create({ @@ -111,12 +111,12 @@ QUnit.test('it should find an actionContext specified as a property path', funct QUnit.test('it should use the target specified in the argument', function() { expect(2); - var targetObj = EmberObject.create({ + let targetObj = EmberObject.create({ anEvent() { ok(true, 'anEvent method was called'); } }); - var obj = EmberObject.extend(TargetActionSupport).create({ + let obj = EmberObject.extend(TargetActionSupport).create({ action: 'anEvent' }); @@ -126,7 +126,7 @@ QUnit.test('it should use the target specified in the argument', function() { QUnit.test('it should use the action specified in the argument', function() { expect(2); - var obj = EmberObject.extend(TargetActionSupport).create({ + let obj = EmberObject.extend(TargetActionSupport).create({ target: EmberObject.create({ anEvent() { ok(true, 'anEvent method was called'); @@ -138,8 +138,8 @@ QUnit.test('it should use the action specified in the argument', function() { QUnit.test('it should use the actionContext specified in the argument', function() { expect(2); - var context = {}; - var obj = EmberObject.extend(TargetActionSupport).create({ + let context = {}; + let obj = EmberObject.extend(TargetActionSupport).create({ target: EmberObject.create({ anEvent(ctx) { ok(context === ctx, 'anEvent method was called with the expected context'); @@ -153,9 +153,9 @@ QUnit.test('it should use the actionContext specified in the argument', function QUnit.test('it should allow multiple arguments from actionContext', function() { expect(3); - var param1 = 'someParam'; - var param2 = 'someOtherParam'; - var obj = EmberObject.extend(TargetActionSupport).create({ + let param1 = 'someParam'; + let param2 = 'someOtherParam'; + let obj = EmberObject.extend(TargetActionSupport).create({ target: EmberObject.create({ anEvent(first, second) { ok(first === param1, 'anEvent method was called with the expected first argument'); @@ -170,7 +170,7 @@ QUnit.test('it should allow multiple arguments from actionContext', function() { QUnit.test('it should use a null value specified in the actionContext argument', function() { expect(2); - var obj = EmberObject.extend(TargetActionSupport).create({ + let obj = EmberObject.extend(TargetActionSupport).create({ target: EmberObject.create({ anEvent(ctx) { ok(null === ctx, 'anEvent method was called with the expected context (null)'); diff --git a/packages/ember-runtime/tests/suites/array.js b/packages/ember-runtime/tests/suites/array.js index 55478eaaaf6..b28458253fb 100644 --- a/packages/ember-runtime/tests/suites/array.js +++ b/packages/ember-runtime/tests/suites/array.js @@ -12,8 +12,7 @@ import { } from 'ember-runtime/mixins/array'; import isEnabled from 'ember-metal/features'; -var ObserverClass = EnumerableTestsObserverClass.extend({ - +const ObserverClass = EnumerableTestsObserverClass.extend({ observeArray(obj) { addArrayObserver(obj, this); return this; @@ -33,13 +32,10 @@ var ObserverClass = EnumerableTestsObserverClass.extend({ equal(this._after, null, 'should only call once'); this._after = Array.prototype.slice.call(arguments); } - }); -var ArrayTests = EnumerableTests.extend({ - +const ArrayTests = EnumerableTests.extend({ observerClass: ObserverClass - }); ArrayTests.ObserverClass = ObserverClass; diff --git a/packages/ember-runtime/tests/suites/array/includes.js b/packages/ember-runtime/tests/suites/array/includes.js index f47eb1c4fad..fa984962e00 100644 --- a/packages/ember-runtime/tests/suites/array/includes.js +++ b/packages/ember-runtime/tests/suites/array/includes.js @@ -1,36 +1,36 @@ import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('includes'); suite.test('includes returns correct value if startAt is positive', function() { - var data = this.newFixture(3); - var obj = this.newObject(data); + let data = this.newFixture(3); + let obj = this.newObject(data); equal(obj.includes(data[1], 1), true, 'should return true if included'); equal(obj.includes(data[0], 1), false, 'should return false if not included'); }); suite.test('includes returns correct value if startAt is negative', function() { - var data = this.newFixture(3); - var obj = this.newObject(data); + let data = this.newFixture(3); + let obj = this.newObject(data); equal(obj.includes(data[1], -2), true, 'should return true if included'); equal(obj.includes(data[0], -2), false, 'should return false if not included'); }); suite.test('includes returns true if startAt + length is still negative', function() { - var data = this.newFixture(1); - var obj = this.newObject(data); + let data = this.newFixture(1); + let obj = this.newObject(data); equal(obj.includes(data[0], -2), true, 'should return true if included'); equal(obj.includes(this.newFixture(1), -2), false, 'should return false if not included'); }); suite.test('includes returns false if startAt out of bounds', function() { - var data = this.newFixture(1); - var obj = this.newObject(data); + let data = this.newFixture(1); + let obj = this.newObject(data); equal(obj.includes(data[0], 2), false, 'should return false if startAt >= length'); equal(obj.includes(this.newFixture(1), 2), false, 'should return false if startAt >= length'); diff --git a/packages/ember-runtime/tests/suites/array/indexOf.js b/packages/ember-runtime/tests/suites/array/indexOf.js index 5a0be94a420..8540841cdd2 100644 --- a/packages/ember-runtime/tests/suites/array/indexOf.js +++ b/packages/ember-runtime/tests/suites/array/indexOf.js @@ -1,23 +1,22 @@ import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('indexOf'); suite.test('should return index of object', function() { - var expected = this.newFixture(3); - var obj = this.newObject(expected); - var len = 3; - var idx; + let expected = this.newFixture(3); + let obj = this.newObject(expected); + let len = 3; - for (idx = 0;idx < len;idx++) { + for (let idx = 0; idx < len; idx++) { equal(obj.indexOf(expected[idx]), idx, `obj.indexOf(${expected[idx]}) should match idx`); } }); suite.test('should return -1 when requesting object not in index', function() { - var obj = this.newObject(this.newFixture(3)); - var foo = {}; + let obj = this.newObject(this.newFixture(3)); + let foo = {}; equal(obj.indexOf(foo), -1, 'obj.indexOf(foo) should be < 0'); }); diff --git a/packages/ember-runtime/tests/suites/array/lastIndexOf.js b/packages/ember-runtime/tests/suites/array/lastIndexOf.js index 1f80434c2ad..74eb3a79ac7 100644 --- a/packages/ember-runtime/tests/suites/array/lastIndexOf.js +++ b/packages/ember-runtime/tests/suites/array/lastIndexOf.js @@ -1,59 +1,56 @@ import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('lastIndexOf'); suite.test('should return index of object\'s last occurrence', function() { - var expected = this.newFixture(3); - var obj = this.newObject(expected); - var len = 3; - var idx; + let expected = this.newFixture(3); + let obj = this.newObject(expected); + let len = 3; - for (idx = 0;idx < len;idx++) { + for (let idx = 0; idx < len; idx++) { equal(obj.lastIndexOf(expected[idx]), idx, `obj.lastIndexOf(${expected[idx]}) should match idx`); } }); suite.test('should return index of object\'s last occurrence even startAt search location is equal to length', function() { - var expected = this.newFixture(3); - var obj = this.newObject(expected); - var len = 3; - var idx; + let expected = this.newFixture(3); + let obj = this.newObject(expected); + let len = 3; - for (idx = 0;idx < len;idx++) { + for (let idx = 0; idx < len; idx++) { equal(obj.lastIndexOf(expected[idx], len), idx, `obj.lastIndexOfs(${expected[idx]}) should match idx`); } }); suite.test('should return index of object\'s last occurrence even startAt search location is greater than length', function() { - var expected = this.newFixture(3); - var obj = this.newObject(expected); - var len = 3; - var idx; + let expected = this.newFixture(3); + let obj = this.newObject(expected); + let len = 3; - for (idx = 0;idx < len;idx++) { + for (let idx = 0; idx < len; idx++) { equal(obj.lastIndexOf(expected[idx], len + 1), idx, `obj.lastIndexOf(${expected[idx]}) should match idx`); } }); suite.test('should return -1 when no match is found', function() { - var obj = this.newObject(this.newFixture(3)); - var foo = {}; + let obj = this.newObject(this.newFixture(3)); + let foo = {}; equal(obj.lastIndexOf(foo), -1, 'obj.lastIndexOf(foo) should be -1'); }); suite.test('should return -1 when no match is found even startAt search location is equal to length', function() { - var obj = this.newObject(this.newFixture(3)); - var foo = {}; + let obj = this.newObject(this.newFixture(3)); + let foo = {}; equal(obj.lastIndexOf(foo, obj.length), -1, 'obj.lastIndexOf(foo) should be -1'); }); suite.test('should return -1 when no match is found even startAt search location is greater than length', function() { - var obj = this.newObject(this.newFixture(3)); - var foo = {}; + let obj = this.newObject(this.newFixture(3)); + let foo = {}; equal(obj.lastIndexOf(foo, obj.length + 1), -1, 'obj.lastIndexOf(foo) should be -1'); }); diff --git a/packages/ember-runtime/tests/suites/array/objectAt.js b/packages/ember-runtime/tests/suites/array/objectAt.js index e9cea5bcbae..ede66472da6 100644 --- a/packages/ember-runtime/tests/suites/array/objectAt.js +++ b/packages/ember-runtime/tests/suites/array/objectAt.js @@ -1,23 +1,22 @@ import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; import { objectAt } from 'ember-runtime/mixins/array'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('objectAt'); suite.test('should return object at specified index', function() { - var expected = this.newFixture(3); - var obj = this.newObject(expected); - var len = expected.length; - var idx; + let expected = this.newFixture(3); + let obj = this.newObject(expected); + let len = expected.length; - for (idx = 0;idx < len;idx++) { + for (let idx = 0; idx < len; idx++) { equal(objectAt(obj, idx), expected[idx], `obj.objectAt(${idx}) should match`); } }); suite.test('should return undefined when requesting objects beyond index', function() { - var obj; + let obj; obj = this.newObject(this.newFixture(3)); equal(objectAt(obj, 5), undefined, 'should return undefined for obj.objectAt(5) when len = 3'); diff --git a/packages/ember-runtime/tests/suites/copyable.js b/packages/ember-runtime/tests/suites/copyable.js index 6bad177124f..f34c3850983 100644 --- a/packages/ember-runtime/tests/suites/copyable.js +++ b/packages/ember-runtime/tests/suites/copyable.js @@ -1,6 +1,6 @@ import { Suite } from 'ember-runtime/tests/suites/suite'; -var CopyableTests = Suite.extend({ +const CopyableTests = Suite.extend({ /* __Required.__ You must implement this method to apply this mixin. diff --git a/packages/ember-runtime/tests/suites/copyable/copy.js b/packages/ember-runtime/tests/suites/copyable/copy.js index b1b29c88e80..87f5b191495 100644 --- a/packages/ember-runtime/tests/suites/copyable/copy.js +++ b/packages/ember-runtime/tests/suites/copyable/copy.js @@ -1,12 +1,12 @@ import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('copy'); suite.test('should return an equivalent copy', function() { - var obj = this.newObject(); - var copy = obj.copy(); + let obj = this.newObject(); + let copy = obj.copy(); ok(this.isEqual(obj, copy), 'old object and new object should be equivalent'); }); diff --git a/packages/ember-runtime/tests/suites/copyable/frozenCopy.js b/packages/ember-runtime/tests/suites/copyable/frozenCopy.js index 5c911d89db0..16b81521677 100644 --- a/packages/ember-runtime/tests/suites/copyable/frozenCopy.js +++ b/packages/ember-runtime/tests/suites/copyable/frozenCopy.js @@ -2,12 +2,12 @@ import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; import {Freezable} from 'ember-runtime/mixins/freezable'; import {get} from 'ember-metal/property_get'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('frozenCopy'); suite.test('frozen objects should return same instance', function() { - var obj, copy; + let obj, copy; obj = this.newObject(); if (get(this, 'shouldBeFreezable')) { diff --git a/packages/ember-runtime/tests/suites/enumerable.js b/packages/ember-runtime/tests/suites/enumerable.js index c44b1fafc8b..09fa15ab4d1 100644 --- a/packages/ember-runtime/tests/suites/enumerable.js +++ b/packages/ember-runtime/tests/suites/enumerable.js @@ -6,8 +6,7 @@ import {get} from 'ember-metal/property_get'; import { _addBeforeObserver } from 'ember-metal/observer'; import isEnabled from 'ember-metal/features'; -var ObserverClass = EmberObject.extend({ - +const ObserverClass = EmberObject.extend({ _keysBefore: null, _keys: null, _values: null, @@ -21,7 +20,6 @@ var ObserverClass = EmberObject.extend({ this.reset(); }, - propertyWillChange(target, key) { if (this._keysBefore[key] === undefined) { this._keysBefore[key] = 0; } this._keysBefore[key]++; @@ -53,8 +51,8 @@ var ObserverClass = EmberObject.extend({ observeBefore(obj) { - var keys = Array.prototype.slice.call(arguments, 1); - var loc = keys.length; + let keys = Array.prototype.slice.call(arguments, 1); + let loc = keys.length; while (--loc>=0) { _addBeforeObserver(obj, keys[loc], this, 'propertyWillChange'); } @@ -73,8 +71,8 @@ var ObserverClass = EmberObject.extend({ */ observe(obj) { if (obj.addObserver) { - var keys = Array.prototype.slice.call(arguments, 1); - var loc = keys.length; + let keys = Array.prototype.slice.call(arguments, 1); + let loc = keys.length; while (--loc >= 0) { obj.addObserver(keys[loc], this, 'propertyDidChange'); @@ -155,11 +153,9 @@ var ObserverClass = EmberObject.extend({ equal(this._after, null, 'should only call once'); this._after = Array.prototype.slice.call(arguments); } - }); - -var EnumerableTests = Suite.extend({ +const EnumerableTests = Suite.extend({ /* __Required.__ You must implement this method to apply this mixin. @@ -184,7 +180,7 @@ var EnumerableTests = Suite.extend({ @returns {Array} array of strings */ newFixture(cnt) { - var ret = []; + let ret = []; while (--cnt >= 0) { ret.push(generateGuid()); } @@ -202,8 +198,8 @@ var EnumerableTests = Suite.extend({ @returns {Array} array of objects */ newObjectsFixture(cnt) { - var ret = []; - var item; + let ret = []; + let item; while (--cnt >= 0) { item = {}; guidFor(item); @@ -258,7 +254,6 @@ var EnumerableTests = Suite.extend({ */ run() {}, - /* Creates a new observer object for testing. You can add this object as an observer on an array and it will record results anytime it is invoked. @@ -266,7 +261,7 @@ var EnumerableTests = Suite.extend({ validate the results. */ newObserver(obj) { - var ret = get(this, 'observerClass').create(); + let ret = get(this, 'observerClass').create(); if (arguments.length > 0) { ret.observeBefore.apply(ret, arguments); } diff --git a/packages/ember-runtime/tests/suites/enumerable/any.js b/packages/ember-runtime/tests/suites/enumerable/any.js index f7d377e7c9b..d56a37af843 100644 --- a/packages/ember-runtime/tests/suites/enumerable/any.js +++ b/packages/ember-runtime/tests/suites/enumerable/any.js @@ -1,7 +1,7 @@ import { SuiteModuleBuilder } from 'ember-runtime/tests/suites/suite'; import { A as emberA } from 'ember-runtime/system/native_array'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); // .......................................................... // any() @@ -10,10 +10,10 @@ var suite = SuiteModuleBuilder.create(); suite.module('any'); suite.test('any should should invoke callback on each item as long as you return false', function() { - var obj = this.newObject(); - var ary = this.toArray(obj); - var found = []; - var result; + let obj = this.newObject(); + let ary = this.toArray(obj); + let found = []; + let result; result = obj.any(function(i) { found.push(i); @@ -24,12 +24,12 @@ suite.test('any should should invoke callback on each item as long as you return }); suite.test('any should stop invoking when you return true', function() { - var obj = this.newObject(); - var ary = this.toArray(obj); - var cnt = ary.length - 2; - var exp = cnt; - var found = []; - var result; + let obj = this.newObject(); + let ary = this.toArray(obj); + let cnt = ary.length - 2; + let exp = cnt; + let found = []; + let result; result = obj.any(function(i) { found.push(i); @@ -40,32 +40,28 @@ suite.test('any should stop invoking when you return true', function() { deepEqual(found, ary.slice(0, -2), 'items passed during any() should match'); }); - suite.test('any should return true if any object matches the callback', function() { - var obj = emberA([0, 1, 2]); - var result; + let obj = emberA([0, 1, 2]); + let result; - result = obj.any(function(i) { return !!i; }); + result = obj.any(i => !!i); equal(result, true, 'return value of obj.any'); }); - suite.test('any should return false if no object matches the callback', function() { - var obj = emberA([0, null, false]); - var result; + let obj = emberA([0, null, false]); + let result; - result = obj.any(function(i) { return !!i; }); + result = obj.any(i => !!i); equal(result, false, 'return value of obj.any'); }); - suite.test('any should produce correct results even if the matching element is undefined', function() { - var obj = emberA([undefined]); - var result; + let obj = emberA([undefined]); + let result; - result = obj.any(function(i) { return true; }); + result = obj.any(i => true); equal(result, true, 'return value of obj.any'); }); - export default suite; diff --git a/packages/ember-runtime/tests/suites/enumerable/compact.js b/packages/ember-runtime/tests/suites/enumerable/compact.js index 52344e0793b..5c49d496fe3 100644 --- a/packages/ember-runtime/tests/suites/enumerable/compact.js +++ b/packages/ember-runtime/tests/suites/enumerable/compact.js @@ -1,12 +1,12 @@ import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('compact'); suite.test('removes null and undefined values from enumerable', function() { - var obj = this.newObject([null, 1, false, '', undefined, 0, null]); - var ary = obj.compact(); + let obj = this.newObject([null, 1, false, '', undefined, 0, null]); + let ary = obj.compact(); deepEqual(ary, [1, false, '', 0]); }); diff --git a/packages/ember-runtime/tests/suites/enumerable/contains.js b/packages/ember-runtime/tests/suites/enumerable/contains.js index 295c4cfd1b0..e243db613fe 100644 --- a/packages/ember-runtime/tests/suites/enumerable/contains.js +++ b/packages/ember-runtime/tests/suites/enumerable/contains.js @@ -1,13 +1,13 @@ import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; import isEnabled from 'ember-metal/features'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('contains'); suite.test('contains returns true if item is in enumerable', function() { - var data = this.newFixture(3); - var obj = this.newObject(data); + let data = this.newFixture(3); + let obj = this.newObject(data); if (isEnabled('ember-runtime-enumerable-includes')) { expectDeprecation('`Enumerable#contains` is deprecated, use `Enumerable#includes` instead.'); @@ -16,8 +16,8 @@ suite.test('contains returns true if item is in enumerable', function() { }); suite.test('contains returns false if item is not in enumerable', function() { - var data = this.newFixture(1); - var obj = this.newObject(this.newFixture(3)); + let data = this.newFixture(1); + let obj = this.newObject(this.newFixture(3)); if (isEnabled('ember-runtime-enumerable-includes')) { expectDeprecation('`Enumerable#contains` is deprecated, use `Enumerable#includes` instead.'); diff --git a/packages/ember-runtime/tests/suites/enumerable/every.js b/packages/ember-runtime/tests/suites/enumerable/every.js index cf3e2e4396a..2c0494be789 100644 --- a/packages/ember-runtime/tests/suites/enumerable/every.js +++ b/packages/ember-runtime/tests/suites/enumerable/every.js @@ -1,7 +1,7 @@ import EmberObject from 'ember-runtime/system/object'; import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); // .......................................................... // every() @@ -10,10 +10,10 @@ var suite = SuiteModuleBuilder.create(); suite.module('every'); suite.test('every should should invoke callback on each item as long as you return true', function() { - var obj = this.newObject(); - var ary = this.toArray(obj); - var found = []; - var result; + let obj = this.newObject(); + let ary = this.toArray(obj); + let found = []; + let result; result = obj.every(function(i) { found.push(i); @@ -24,12 +24,12 @@ suite.test('every should should invoke callback on each item as long as you retu }); suite.test('every should stop invoking when you return false', function() { - var obj = this.newObject(); - var ary = this.toArray(obj); - var cnt = ary.length - 2; - var exp = cnt; - var found = []; - var result; + let obj = this.newObject(); + let ary = this.toArray(obj); + let cnt = ary.length - 2; + let exp = cnt; + let found = []; + let result; result = obj.every(function(i) { found.push(i); @@ -47,7 +47,7 @@ suite.test('every should stop invoking when you return false', function() { suite.module('isEvery'); suite.test('should return true of every property matches', function() { - var obj = this.newObject([ + let obj = this.newObject([ { foo: 'foo', bar: 'BAZ' }, EmberObject.create({ foo: 'foo', bar: 'bar' }) ]); @@ -57,7 +57,7 @@ suite.test('should return true of every property matches', function() { }); suite.test('should return true of every property is true', function() { - var obj = this.newObject([ + let obj = this.newObject([ { foo: 'foo', bar: true }, EmberObject.create({ foo: 'bar', bar: false }) ]); @@ -68,7 +68,7 @@ suite.test('should return true of every property is true', function() { }); suite.test('should return true if every property matches null', function() { - var obj = this.newObject([ + let obj = this.newObject([ { foo: null, bar: 'BAZ' }, EmberObject.create({ foo: null, bar: null }) ]); @@ -78,7 +78,7 @@ suite.test('should return true if every property matches null', function() { }); suite.test('should return true if every property is undefined', function() { - var obj = this.newObject([ + let obj = this.newObject([ { foo: undefined, bar: 'BAZ' }, EmberObject.create({ bar: undefined }) ]); diff --git a/packages/ember-runtime/tests/suites/enumerable/filter.js b/packages/ember-runtime/tests/suites/enumerable/filter.js index bf266b2eef2..0744580b342 100644 --- a/packages/ember-runtime/tests/suites/enumerable/filter.js +++ b/packages/ember-runtime/tests/suites/enumerable/filter.js @@ -1,7 +1,7 @@ import EmberObject from 'ember-runtime/system/object'; import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); // .......................................................... // filter() @@ -10,11 +10,11 @@ var suite = SuiteModuleBuilder.create(); suite.module('filter'); suite.test('filter should invoke on each item', function() { - var obj = this.newObject(); - var ary = this.toArray(obj); - var cnt = ary.length - 2; - var found = []; - var result; + let obj = this.newObject(); + let ary = this.toArray(obj); + let cnt = ary.length - 2; + let found = []; + let result; // return true on all but the last two result = obj.filter(function(i) { @@ -32,7 +32,7 @@ suite.test('filter should invoke on each item', function() { suite.module('filterBy'); suite.test('should filter based on object', function() { - var obj, ary; + let obj, ary; ary = [ { foo: 'foo', bar: 'BAZ' }, @@ -46,7 +46,7 @@ suite.test('should filter based on object', function() { }); suite.test('should include in result if property is true', function() { - var obj, ary; + let obj, ary; ary = [ { foo: 'foo', bar: true }, @@ -61,7 +61,7 @@ suite.test('should include in result if property is true', function() { }); suite.test('should filter on second argument if provided', function() { - var obj, ary; + let obj, ary; ary = [ { name: 'obj1', foo: 3 }, @@ -76,7 +76,7 @@ suite.test('should filter on second argument if provided', function() { }); suite.test('should correctly filter null second argument', function() { - var obj, ary; + let obj, ary; ary = [ { name: 'obj1', foo: 3 }, @@ -91,7 +91,7 @@ suite.test('should correctly filter null second argument', function() { }); suite.test('should not return all objects on undefined second argument', function() { - var obj, ary; + let obj, ary; ary = [ { name: 'obj1', foo: 3 }, @@ -104,7 +104,7 @@ suite.test('should not return all objects on undefined second argument', functio }); suite.test('should correctly filter explicit undefined second argument', function() { - var obj, ary; + let obj, ary; ary = [ { name: 'obj1', foo: 3 }, @@ -121,7 +121,7 @@ suite.test('should correctly filter explicit undefined second argument', functio }); suite.test('should not match undefined properties without second argument', function() { - var obj, ary; + let obj, ary; ary = [ { name: 'obj1', foo: 3 }, diff --git a/packages/ember-runtime/tests/suites/enumerable/find.js b/packages/ember-runtime/tests/suites/enumerable/find.js index 0033a4a2622..639cdbd2a5a 100644 --- a/packages/ember-runtime/tests/suites/enumerable/find.js +++ b/packages/ember-runtime/tests/suites/enumerable/find.js @@ -1,7 +1,7 @@ import EmberObject from 'ember-runtime/system/object'; import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); // .......................................................... // find() // @@ -9,10 +9,10 @@ var suite = SuiteModuleBuilder.create(); suite.module('find'); suite.test('find should invoke callback on each item as long as you return false', function() { - var obj = this.newObject(); - var ary = this.toArray(obj); - var found = []; - var result; + let obj = this.newObject(); + let ary = this.toArray(obj); + let found = []; + let result; result = obj.find(function(i) { found.push(i); @@ -23,12 +23,12 @@ suite.test('find should invoke callback on each item as long as you return false }); suite.test('every should stop invoking when you return true', function() { - var obj = this.newObject(); - var ary = this.toArray(obj); - var cnt = ary.length - 2; - var exp = cnt; - var found = []; - var result; + let obj = this.newObject(); + let ary = this.toArray(obj); + let cnt = ary.length - 2; + let exp = cnt; + let found = []; + let result; result = obj.find(function(i) { found.push(i); @@ -46,7 +46,7 @@ suite.test('every should stop invoking when you return true', function() { suite.module('findBy'); suite.test('should return first object of property matches', function() { - var ary, obj; + let ary, obj; ary = [ { foo: 'foo', bar: 'BAZ' }, @@ -60,7 +60,7 @@ suite.test('should return first object of property matches', function() { }); suite.test('should return first object with truthy prop', function() { - var ary, obj; + let ary, obj; ary = [ { foo: 'foo', bar: false }, @@ -75,7 +75,7 @@ suite.test('should return first object with truthy prop', function() { }); suite.test('should return first null property match', function() { - var ary, obj; + let ary, obj; ary = [ { foo: null, bar: 'BAZ' }, @@ -89,7 +89,7 @@ suite.test('should return first null property match', function() { }); suite.test('should return first undefined property match', function() { - var ary, obj; + let ary, obj; ary = [ { foo: undefined, bar: 'BAZ' }, diff --git a/packages/ember-runtime/tests/suites/enumerable/firstObject.js b/packages/ember-runtime/tests/suites/enumerable/firstObject.js index 822d4be1aed..b3034f83324 100644 --- a/packages/ember-runtime/tests/suites/enumerable/firstObject.js +++ b/packages/ember-runtime/tests/suites/enumerable/firstObject.js @@ -2,26 +2,26 @@ import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; import {get} from 'ember-metal/property_get'; import {set} from 'ember-metal/property_set'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('firstObject'); suite.test('returns first item in enumerable', function() { - var obj = this.newObject(); + let obj = this.newObject(); equal(get(obj, 'firstObject'), this.toArray(obj)[0]); }); suite.test('returns undefined if enumerable is empty', function() { - var obj = this.newObject([]); + let obj = this.newObject([]); equal(get(obj, 'firstObject'), undefined); }); suite.test('can not be set', function() { - var obj = this.newObject([]); + let obj = this.newObject([]); equal(get(obj, 'firstObject'), this.toArray(obj)[0]); - throws(function() { + throws(() => { set(obj, 'firstObject', 'foo!'); }, /Cannot set read-only property "firstObject" on object/); }); diff --git a/packages/ember-runtime/tests/suites/enumerable/forEach.js b/packages/ember-runtime/tests/suites/enumerable/forEach.js index 0f8b026313a..90666257577 100644 --- a/packages/ember-runtime/tests/suites/enumerable/forEach.js +++ b/packages/ember-runtime/tests/suites/enumerable/forEach.js @@ -2,16 +2,16 @@ import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; import {get} from 'ember-metal/property_get'; import {guidFor} from 'ember-metal/utils'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('forEach'); suite.test('forEach should iterate over list', function() { - var obj = this.newObject(); - var ary = this.toArray(obj); - var found = []; + let obj = this.newObject(); + let ary = this.toArray(obj); + let found = []; - obj.forEach(function(i) { found.push(i); }); + obj.forEach(i => found.push(i)); deepEqual(found, ary, 'items passed during forEach should match'); }); @@ -22,26 +22,26 @@ suite.test('forEach should iterate over list after mutation', function() { return; } - var obj = this.newObject(); - var ary = this.toArray(obj); - var found = []; + let obj = this.newObject(); + let ary = this.toArray(obj); + let found = []; - obj.forEach(function(i) { found.push(i); }); + obj.forEach(i => found.push(i)); deepEqual(found, ary, 'items passed during forEach should match'); this.mutate(obj); ary = this.toArray(obj); found = []; - obj.forEach(function(i) { found.push(i); }); + obj.forEach(i => found.push(i)); deepEqual(found, ary, 'items passed during forEach should match'); }); suite.test('2nd target parameter', function() { - var obj = this.newObject(); - var target = this; + let obj = this.newObject(); + let target = this; - obj.forEach(function() { + obj.forEach(() => { // ES6TODO: When transpiled we will end up with "use strict" which disables automatically binding to the global context. // Therefore, the following test can never pass in strict mode unless we modify the `map` function implementation to // use `Ember.lookup` if target is not specified. @@ -49,19 +49,18 @@ suite.test('2nd target parameter', function() { // equal(guidFor(this), guidFor(global), 'should pass the global object as this if no context'); }); - obj.forEach(function() { + obj.forEach(() => { equal(guidFor(this), guidFor(target), 'should pass target as this if context'); }, target); }); suite.test('callback params', function() { - var obj = this.newObject(); - var ary = this.toArray(obj); - var loc = 0; + let obj = this.newObject(); + let ary = this.toArray(obj); + let loc = 0; - - obj.forEach(function(item, idx, enumerable) { + obj.forEach((item, idx, enumerable) => { equal(item, ary[loc], 'item param'); equal(idx, loc, 'idx param'); equal(guidFor(enumerable), guidFor(obj), 'enumerable param'); diff --git a/packages/ember-runtime/tests/suites/enumerable/includes.js b/packages/ember-runtime/tests/suites/enumerable/includes.js index ef0e4ac0dc7..a2551ff651f 100644 --- a/packages/ember-runtime/tests/suites/enumerable/includes.js +++ b/packages/ember-runtime/tests/suites/enumerable/includes.js @@ -1,12 +1,12 @@ import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('includes'); suite.test('includes returns true if item is in enumerable', function() { - var data = this.newFixture(1); - var obj = this.newObject([...data, NaN, undefined, null]); + let data = this.newFixture(1); + let obj = this.newObject([...data, NaN, undefined, null]); equal(obj.includes(data[0]), true, 'should return true if included'); equal(obj.includes(NaN), true, 'should return true if NaN included'); @@ -15,8 +15,8 @@ suite.test('includes returns true if item is in enumerable', function() { }); suite.test('includes returns false if item is not in enumerable', function() { - var data = this.newFixture(1); - var obj = this.newObject([...this.newFixture(3), null]); + let data = this.newFixture(1); + let obj = this.newObject([...this.newFixture(3), null]); equal(obj.includes(data[0]), false, 'should return false if not included'); equal(obj.includes(undefined), false, 'should return false if undefined not included but null is included'); diff --git a/packages/ember-runtime/tests/suites/enumerable/invoke.js b/packages/ember-runtime/tests/suites/enumerable/invoke.js index d7d71237e4b..56728d890fc 100644 --- a/packages/ember-runtime/tests/suites/enumerable/invoke.js +++ b/packages/ember-runtime/tests/suites/enumerable/invoke.js @@ -1,12 +1,12 @@ import EmberObject from 'ember-runtime/system/object'; import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('invoke'); suite.test('invoke should call on each object that implements', function() { - var cnt, ary, obj; + let cnt, ary, obj; function F(amt) { cnt += amt === undefined ? 1 : amt; diff --git a/packages/ember-runtime/tests/suites/enumerable/is_any.js b/packages/ember-runtime/tests/suites/enumerable/is_any.js index d7f80f32930..646085bb105 100644 --- a/packages/ember-runtime/tests/suites/enumerable/is_any.js +++ b/packages/ember-runtime/tests/suites/enumerable/is_any.js @@ -1,7 +1,7 @@ import EmberObject from 'ember-runtime/system/object'; import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); // .......................................................... // isAny() @@ -10,7 +10,7 @@ var suite = SuiteModuleBuilder.create(); suite.module('isAny'); suite.test('should return true of any property matches', function() { - var obj = this.newObject([ + let obj = this.newObject([ { foo: 'foo', bar: 'BAZ' }, EmberObject.create({ foo: 'foo', bar: 'bar' }) ]); @@ -21,7 +21,7 @@ suite.test('should return true of any property matches', function() { }); suite.test('should return true of any property is true', function() { - var obj = this.newObject([ + let obj = this.newObject([ { foo: 'foo', bar: true }, EmberObject.create({ foo: 'bar', bar: false }) ]); @@ -33,7 +33,7 @@ suite.test('should return true of any property is true', function() { }); suite.test('should return true if any property matches null', function() { - var obj = this.newObject([ + let obj = this.newObject([ { foo: null, bar: 'bar' }, EmberObject.create({ foo: 'foo', bar: null }) ]); @@ -43,7 +43,7 @@ suite.test('should return true if any property matches null', function() { }); suite.test('should return true if any property is undefined', function() { - var obj = this.newObject([ + let obj = this.newObject([ { foo: undefined, bar: 'bar' }, EmberObject.create({ foo: 'foo' }) ]); @@ -53,7 +53,7 @@ suite.test('should return true if any property is undefined', function() { }); suite.test('should not match undefined properties without second argument', function() { - var obj = this.newObject([ + let obj = this.newObject([ { foo: undefined }, EmberObject.create({ }) ]); diff --git a/packages/ember-runtime/tests/suites/enumerable/lastObject.js b/packages/ember-runtime/tests/suites/enumerable/lastObject.js index db1efa98620..b230a2bb85d 100644 --- a/packages/ember-runtime/tests/suites/enumerable/lastObject.js +++ b/packages/ember-runtime/tests/suites/enumerable/lastObject.js @@ -2,26 +2,26 @@ import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; import {get} from 'ember-metal/property_get'; import {set} from 'ember-metal/property_set'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('lastObject'); suite.test('returns last item in enumerable', function() { - var obj = this.newObject(); - var ary = this.toArray(obj); + let obj = this.newObject(); + let ary = this.toArray(obj); equal(get(obj, 'lastObject'), ary[ary.length - 1]); }); suite.test('returns undefined if enumerable is empty', function() { - var obj = this.newObject([]); + let obj = this.newObject([]); equal(get(obj, 'lastObject'), undefined); }); suite.test('can not be set', function() { - var obj = this.newObject(); - var ary = this.toArray(obj); + let obj = this.newObject(); + let ary = this.toArray(obj); equal(get(obj, 'lastObject'), ary[ary.length - 1]); diff --git a/packages/ember-runtime/tests/suites/enumerable/map.js b/packages/ember-runtime/tests/suites/enumerable/map.js index f35960c9610..a90e7dd8008 100644 --- a/packages/ember-runtime/tests/suites/enumerable/map.js +++ b/packages/ember-runtime/tests/suites/enumerable/map.js @@ -2,16 +2,16 @@ import { SuiteModuleBuilder } from 'ember-runtime/tests/suites/suite'; import { get } from 'ember-metal/property_get'; import { guidFor } from 'ember-metal/utils'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('map'); -function mapFunc(item) { return item ? item.toString() : null; } +const mapFunc = item => item ? item.toString() : null; suite.test('map should iterate over list', function() { - var obj = this.newObject(); - var ary = this.toArray(obj).map(mapFunc); - var found = []; + let obj = this.newObject(); + let ary = this.toArray(obj).map(mapFunc); + let found = []; found = obj.map(mapFunc); deepEqual(found, ary, 'mapped arrays should match'); @@ -24,9 +24,9 @@ suite.test('map should iterate over list after mutation', function() { return; } - var obj = this.newObject(); - var ary = this.toArray(obj).map(mapFunc); - var found; + let obj = this.newObject(); + let ary = this.toArray(obj).map(mapFunc); + let found; found = obj.map(mapFunc); deepEqual(found, ary, 'items passed during forEach should match'); @@ -38,11 +38,11 @@ suite.test('map should iterate over list after mutation', function() { }); suite.test('2nd target parameter', function() { - var obj = this.newObject(); - var target = this; + let obj = this.newObject(); + let target = this; - obj.map(function() { + obj.map(() => { // ES6TODO: When transpiled we will end up with "use strict" which disables automatically binding to the global context. // Therefore, the following test can never pass in strict mode unless we modify the `map` function implementation to // use `Ember.lookup` if target is not specified. @@ -50,19 +50,18 @@ suite.test('2nd target parameter', function() { // equal(guidFor(this), guidFor(global), 'should pass the global object as this if no context'); }); - obj.map(function() { + obj.map(() => { equal(guidFor(this), guidFor(target), 'should pass target as this if context'); }, target); }); suite.test('callback params', function() { - var obj = this.newObject(); - var ary = this.toArray(obj); - var loc = 0; + let obj = this.newObject(); + let ary = this.toArray(obj); + let loc = 0; - - obj.map(function(item, idx, enumerable) { + obj.map((item, idx, enumerable) => { equal(item, ary[loc], 'item param'); equal(idx, loc, 'idx param'); equal(guidFor(enumerable), guidFor(obj), 'enumerable param'); diff --git a/packages/ember-runtime/tests/suites/enumerable/mapBy.js b/packages/ember-runtime/tests/suites/enumerable/mapBy.js index 46e51052d91..ee54796ba78 100644 --- a/packages/ember-runtime/tests/suites/enumerable/mapBy.js +++ b/packages/ember-runtime/tests/suites/enumerable/mapBy.js @@ -1,16 +1,16 @@ import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('mapBy'); suite.test('get value of each property', function() { - var obj = this.newObject([{ a: 1 }, { a: 2 }]); + let obj = this.newObject([{ a: 1 }, { a: 2 }]); equal(obj.mapBy('a').join(''), '12'); }); suite.test('should work also through getEach alias', function() { - var obj = this.newObject([{ a: 1 }, { a: 2 }]); + let obj = this.newObject([{ a: 1 }, { a: 2 }]); equal(obj.getEach('a').join(''), '12'); }); diff --git a/packages/ember-runtime/tests/suites/enumerable/reduce.js b/packages/ember-runtime/tests/suites/enumerable/reduce.js index e9e91034939..e52170fc489 100644 --- a/packages/ember-runtime/tests/suites/enumerable/reduce.js +++ b/packages/ember-runtime/tests/suites/enumerable/reduce.js @@ -1,24 +1,24 @@ import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('reduce'); suite.test('collects a summary value from an enumeration', function() { - var obj = this.newObject([1, 2, 3]); - var res = obj.reduce(function(previousValue, item, index, enumerable) { return previousValue + item; }, 0); + let obj = this.newObject([1, 2, 3]); + let res = obj.reduce((previousValue, item, index, enumerable) => previousValue + item, 0); equal(res, 6); }); suite.test('passes index of item to callback', function() { - var obj = this.newObject([1, 2, 3]); - var res = obj.reduce(function(previousValue, item, index, enumerable) { return previousValue + index; }, 0); + let obj = this.newObject([1, 2, 3]); + let res = obj.reduce((previousValue, item, index, enumerable) => previousValue + index, 0); equal(res, 3); }); suite.test('passes enumerable object to callback', function() { - var obj = this.newObject([1, 2, 3]); - var res = obj.reduce(function(previousValue, item, index, enumerable) { return enumerable; }, 0); + let obj = this.newObject([1, 2, 3]); + let res = obj.reduce((previousValue, item, index, enumerable) => enumerable, 0); equal(res, obj); }); diff --git a/packages/ember-runtime/tests/suites/enumerable/reject.js b/packages/ember-runtime/tests/suites/enumerable/reject.js index ce876a5b337..4b6daa9292c 100644 --- a/packages/ember-runtime/tests/suites/enumerable/reject.js +++ b/packages/ember-runtime/tests/suites/enumerable/reject.js @@ -1,7 +1,7 @@ import EmberObject from 'ember-runtime/system/object'; import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); // .......................................................... // reject() @@ -10,17 +10,17 @@ var suite = SuiteModuleBuilder.create(); suite.module('reject'); suite.test('should reject any item that does not meet the condition', function() { - var obj = this.newObject([1, 2, 3, 4]); - var result; + let obj = this.newObject([1, 2, 3, 4]); + let result; - result = obj.reject(function(i) { return i < 3; }); + result = obj.reject(i => i < 3); deepEqual(result, [3, 4], 'reject the correct items'); }); suite.test('should be the inverse of filter', function() { - var obj = this.newObject([1, 2, 3, 4]); - var isEven = function(i) { return i % 2 === 0; }; - var filtered, rejected; + let obj = this.newObject([1, 2, 3, 4]); + let isEven = i => i % 2 === 0; + let filtered, rejected; filtered = obj.filter(isEven); rejected = obj.reject(isEven); @@ -36,7 +36,7 @@ suite.test('should be the inverse of filter', function() { suite.module('rejectBy'); suite.test('should reject based on object', function() { - var obj, ary; + let obj, ary; ary = [ { foo: 'foo', bar: 'BAZ' }, @@ -50,7 +50,7 @@ suite.test('should reject based on object', function() { }); suite.test('should include in result if property is false', function() { - var obj, ary; + let obj, ary; ary = [ { foo: false, bar: true }, @@ -64,7 +64,7 @@ suite.test('should include in result if property is false', function() { }); suite.test('should reject on second argument if provided', function() { - var obj, ary; + let obj, ary; ary = [ { name: 'obj1', foo: 3 }, @@ -79,7 +79,7 @@ suite.test('should reject on second argument if provided', function() { }); suite.test('should correctly reject null second argument', function() { - var obj, ary; + let obj, ary; ary = [ { name: 'obj1', foo: 3 }, @@ -94,7 +94,7 @@ suite.test('should correctly reject null second argument', function() { }); suite.test('should correctly reject undefined second argument', function() { - var obj, ary; + let obj, ary; ary = [ { name: 'obj1', foo: 3 }, @@ -107,7 +107,7 @@ suite.test('should correctly reject undefined second argument', function() { }); suite.test('should correctly reject explicit undefined second argument', function() { - var obj, ary; + let obj, ary; ary = [ { name: 'obj1', foo: 3 }, @@ -124,7 +124,7 @@ suite.test('should correctly reject explicit undefined second argument', functio }); suite.test('should match undefined, null, or false properties without second argument', function() { - var obj, ary; + let obj, ary; ary = [ { name: 'obj1', foo: 3 }, diff --git a/packages/ember-runtime/tests/suites/enumerable/sortBy.js b/packages/ember-runtime/tests/suites/enumerable/sortBy.js index 668871998ab..35af9657398 100644 --- a/packages/ember-runtime/tests/suites/enumerable/sortBy.js +++ b/packages/ember-runtime/tests/suites/enumerable/sortBy.js @@ -1,21 +1,21 @@ import { SuiteModuleBuilder } from 'ember-runtime/tests/suites/suite'; import { get } from 'ember-metal/property_get'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('sortBy'); suite.test('sort by value of property', function() { - var obj = this.newObject([{ a: 2 }, { a: 1 }]); - var sorted = obj.sortBy('a'); + let obj = this.newObject([{ a: 2 }, { a: 1 }]); + let sorted = obj.sortBy('a'); equal(get(sorted[0], 'a'), 1); equal(get(sorted[1], 'a'), 2); }); suite.test('supports multiple propertyNames', function() { - var obj = this.newObject([{ a: 1, b: 2 }, { a: 1, b: 1 }]); - var sorted = obj.sortBy('a', 'b'); + let obj = this.newObject([{ a: 1, b: 2 }, { a: 1, b: 1 }]); + let sorted = obj.sortBy('a', 'b'); equal(get(sorted[0], 'b'), 1); equal(get(sorted[1], 'b'), 2); diff --git a/packages/ember-runtime/tests/suites/enumerable/toArray.js b/packages/ember-runtime/tests/suites/enumerable/toArray.js index 59674a881aa..3389dd6935d 100644 --- a/packages/ember-runtime/tests/suites/enumerable/toArray.js +++ b/packages/ember-runtime/tests/suites/enumerable/toArray.js @@ -1,11 +1,11 @@ import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('toArray'); suite.test('toArray should convert to an array', function() { - var obj = this.newObject(); + let obj = this.newObject(); deepEqual(obj.toArray(), this.toArray(obj)); }); diff --git a/packages/ember-runtime/tests/suites/enumerable/uniq.js b/packages/ember-runtime/tests/suites/enumerable/uniq.js index 09affb6845c..3284a61fc0e 100644 --- a/packages/ember-runtime/tests/suites/enumerable/uniq.js +++ b/packages/ember-runtime/tests/suites/enumerable/uniq.js @@ -1,11 +1,11 @@ import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('uniq'); suite.test('should return new instance with duplicates removed', function() { - var before, after, obj, ret; + let before, after, obj, ret; after = this.newFixture(3); before = [after[0], after[1], after[2], after[1], after[0]]; @@ -18,7 +18,7 @@ suite.test('should return new instance with duplicates removed', function() { }); suite.test('should return duplicate of same content if no duplicates found', function() { - var item, obj, ret; + let item, obj, ret; obj = this.newObject(this.newFixture(3)); ret = obj.uniq(item); ok(ret !== obj, 'should not be same object'); diff --git a/packages/ember-runtime/tests/suites/enumerable/uniqBy.js b/packages/ember-runtime/tests/suites/enumerable/uniqBy.js index 730460e7419..c089f72b333 100644 --- a/packages/ember-runtime/tests/suites/enumerable/uniqBy.js +++ b/packages/ember-runtime/tests/suites/enumerable/uniqBy.js @@ -1,13 +1,13 @@ import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; import isEnabled from 'ember-metal/features'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('uniqBy'); if (isEnabled('ember-runtime-computed-uniq-by')) { suite.test('should return new instance with duplicates removed', function() { - var numbers = this.newObject([ + let numbers = this.newObject([ { id: 1, value: 'one' }, { id: 2, value: 'two' }, { id: 1, value: 'one' } diff --git a/packages/ember-runtime/tests/suites/enumerable/without.js b/packages/ember-runtime/tests/suites/enumerable/without.js index 2277c0f1efc..532645e2bb8 100644 --- a/packages/ember-runtime/tests/suites/enumerable/without.js +++ b/packages/ember-runtime/tests/suites/enumerable/without.js @@ -1,12 +1,12 @@ import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; import isEnabled from 'ember-metal/features'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('without'); suite.test('should return new instance with item removed', function() { - var before, after, obj, ret; + let before, after, obj, ret; before = this.newFixture(3); after = [before[0], before[2]]; @@ -19,7 +19,7 @@ suite.test('should return new instance with item removed', function() { if (isEnabled('ember-runtime-enumerable-includes')) { suite.test('should remove NaN value', function() { - var before, after, obj, ret; + let before, after, obj, ret; before = [...this.newFixture(2), NaN]; after = [before[0], before[1]]; @@ -31,7 +31,7 @@ if (isEnabled('ember-runtime-enumerable-includes')) { } suite.test('should return same instance if object not found', function() { - var item, obj, ret; + let item, obj, ret; item = this.newFixture(1)[0]; obj = this.newObject(this.newFixture(3)); diff --git a/packages/ember-runtime/tests/suites/mutable_array.js b/packages/ember-runtime/tests/suites/mutable_array.js index 01a20fd478b..2a8db8f70ee 100644 --- a/packages/ember-runtime/tests/suites/mutable_array.js +++ b/packages/ember-runtime/tests/suites/mutable_array.js @@ -10,7 +10,7 @@ import shiftObjectTests from 'ember-runtime/tests/suites/mutable_array/shiftObje import unshiftObjectTests from 'ember-runtime/tests/suites/mutable_array/unshiftObject'; import reverseObjectsTests from 'ember-runtime/tests/suites/mutable_array/reverseObjects'; -var MutableArrayTests = ArrayTests.extend(); +const MutableArrayTests = ArrayTests.extend(); MutableArrayTests.importModuleTests(insertAtTests); MutableArrayTests.importModuleTests(popObjectTests); MutableArrayTests.importModuleTests(pushObjectTests); diff --git a/packages/ember-runtime/tests/suites/mutable_array/addObject.js b/packages/ember-runtime/tests/suites/mutable_array/addObject.js index 39e488a1d27..d1f558fb774 100644 --- a/packages/ember-runtime/tests/suites/mutable_array/addObject.js +++ b/packages/ember-runtime/tests/suites/mutable_array/addObject.js @@ -1,25 +1,23 @@ import get from 'ember-metal/property_get'; import { SuiteModuleBuilder } from 'ember-runtime/tests/suites/suite'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('addObject'); suite.test('should return receiver', function() { - var before, obj; - before = this.newFixture(3); - obj = this.newObject(before); + let before = this.newFixture(3); + let obj = this.newObject(before); equal(obj.addObject(before[1]), obj, 'should return receiver'); }); suite.test('[A,B].addObject(C) => [A,B,C] + notify', function() { - var obj, before, after, observer, item; + let before = this.newFixture(2); + let item = this.newFixture(1)[0]; + let after = [before[0], before[1], item]; + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - before = this.newFixture(2); - item = this.newFixture(1)[0]; - after = [before[0], before[1], item]; - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.addObject(item); @@ -38,13 +36,12 @@ suite.test('[A,B].addObject(C) => [A,B,C] + notify', function() { }); suite.test('[A,B,C].addObject(A) => [A,B,C] + NO notify', function() { - var obj, before, after, observer, item; + let before = this.newFixture(3); + let after = before; + let item = before[0]; + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - before = this.newFixture(3); - after = before; - item = before[0]; - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.addObject(item); // note: item in set diff --git a/packages/ember-runtime/tests/suites/mutable_array/clear.js b/packages/ember-runtime/tests/suites/mutable_array/clear.js index 9e846438829..f27a3a8f300 100644 --- a/packages/ember-runtime/tests/suites/mutable_array/clear.js +++ b/packages/ember-runtime/tests/suites/mutable_array/clear.js @@ -1,17 +1,16 @@ import get from 'ember-metal/property_get'; import { SuiteModuleBuilder } from 'ember-runtime/tests/suites/suite'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('clear'); suite.test('[].clear() => [] + notify', function () { - var obj, before, after, observer; + let before = []; + let after = []; + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - before = []; - after = []; - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ equal(obj.clear(), obj, 'return self'); diff --git a/packages/ember-runtime/tests/suites/mutable_array/insertAt.js b/packages/ember-runtime/tests/suites/mutable_array/insertAt.js index 274b3f7c4ba..45c0f652128 100644 --- a/packages/ember-runtime/tests/suites/mutable_array/insertAt.js +++ b/packages/ember-runtime/tests/suites/mutable_array/insertAt.js @@ -1,16 +1,14 @@ import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; import {get} from 'ember-metal/property_get'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('insertAt'); suite.test('[].insertAt(0, X) => [X] + notify', function() { - var obj, after, observer; - - after = this.newFixture(1); - obj = this.newObject([]); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); + let after = this.newFixture(1); + let obj = this.newObject([]); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ @@ -34,22 +32,18 @@ suite.test('[].insertAt(0, X) => [X] + notify', function() { }); suite.test('[].insertAt(200,X) => OUT_OF_RANGE_EXCEPTION exception', function() { - var obj = this.newObject([]); - var that = this; + let obj = this.newObject([]); + let that = this; - throws(function() { - obj.insertAt(200, that.newFixture(1)[0]); - }, Error); + throws(() => obj.insertAt(200, that.newFixture(1)[0]), Error); }); suite.test('[A].insertAt(0, X) => [X,A] + notify', function() { - var obj, item, after, before, observer; - - item = this.newFixture(1)[0]; - before = this.newFixture(1); - after = [item, before[0]]; - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); + let item = this.newFixture(1)[0]; + let before = this.newFixture(1); + let after = [item, before[0]]; + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ @@ -73,13 +67,11 @@ suite.test('[A].insertAt(0, X) => [X,A] + notify', function() { }); suite.test('[A].insertAt(1, X) => [A,X] + notify', function() { - var obj, item, after, before, observer; - - item = this.newFixture(1)[0]; - before = this.newFixture(1); - after = [before[0], item]; - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); + let item = this.newFixture(1)[0]; + let before = this.newFixture(1); + let after = [before[0], item]; + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ @@ -103,22 +95,18 @@ suite.test('[A].insertAt(1, X) => [A,X] + notify', function() { }); suite.test('[A].insertAt(200,X) => OUT_OF_RANGE exception', function() { - var obj = this.newObject(this.newFixture(1)); - var that = this; + let obj = this.newObject(this.newFixture(1)); + let that = this; - throws(function() { - obj.insertAt(200, that.newFixture(1)[0]); - }, Error); + throws(() => obj.insertAt(200, that.newFixture(1)[0]), Error); }); suite.test('[A,B,C].insertAt(0,X) => [X,A,B,C] + notify', function() { - var obj, item, after, before, observer; - - item = this.newFixture(1)[0]; - before = this.newFixture(3); - after = [item, before[0], before[1], before[2]]; - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); + let item = this.newFixture(1)[0]; + let before = this.newFixture(3); + let after = [item, before[0], before[1], before[2]]; + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ @@ -142,13 +130,11 @@ suite.test('[A,B,C].insertAt(0,X) => [X,A,B,C] + notify', function() { }); suite.test('[A,B,C].insertAt(1,X) => [A,X,B,C] + notify', function() { - var obj, item, after, before, observer; - - item = this.newFixture(1)[0]; - before = this.newFixture(3); - after = [before[0], item, before[1], before[2]]; - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); + let item = this.newFixture(1)[0]; + let before = this.newFixture(3); + let after = [before[0], item, before[1], before[2]]; + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ @@ -172,13 +158,11 @@ suite.test('[A,B,C].insertAt(1,X) => [A,X,B,C] + notify', function() { }); suite.test('[A,B,C].insertAt(3,X) => [A,B,C,X] + notify', function() { - var obj, item, after, before, observer; - - item = this.newFixture(1)[0]; - before = this.newFixture(3); - after = [before[0], before[1], before[2], item]; - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); + let item = this.newFixture(1)[0]; + let before = this.newFixture(3); + let after = [before[0], before[1], before[2], item]; + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ diff --git a/packages/ember-runtime/tests/suites/mutable_array/popObject.js b/packages/ember-runtime/tests/suites/mutable_array/popObject.js index 2cdc5918984..954aad79f6e 100644 --- a/packages/ember-runtime/tests/suites/mutable_array/popObject.js +++ b/packages/ember-runtime/tests/suites/mutable_array/popObject.js @@ -1,15 +1,14 @@ import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; import {get} from 'ember-metal/property_get'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('popObject'); suite.test('[].popObject() => [] + returns undefined + NO notify', function() { - var obj, observer; + let obj = this.newObject([]); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj = this.newObject([]); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ equal(obj.popObject(), undefined, 'popObject results'); @@ -24,15 +23,14 @@ suite.test('[].popObject() => [] + returns undefined + NO notify', function() { }); suite.test('[X].popObject() => [] + notify', function() { - var obj, before, after, observer, ret; + let before = this.newFixture(1); + let after = []; + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - before = this.newFixture(1); - after = []; - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ - ret = obj.popObject(); + let ret = obj.popObject(); equal(ret, before[0], 'return object'); deepEqual(this.toArray(obj), after, 'post item results'); @@ -46,15 +44,14 @@ suite.test('[X].popObject() => [] + notify', function() { }); suite.test('[A,B,C].popObject() => [A,B] + notify', function() { - var obj, before, after, observer, ret; + let before = this.newFixture(3); + let after = [before[0], before[1]]; + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - before = this.newFixture(3); - after = [before[0], before[1]]; - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ - ret = obj.popObject(); + let ret = obj.popObject(); equal(ret, before[2], 'return object'); deepEqual(this.toArray(obj), after, 'post item results'); diff --git a/packages/ember-runtime/tests/suites/mutable_array/pushObject.js b/packages/ember-runtime/tests/suites/mutable_array/pushObject.js index 5123772151c..8c1c064aa5a 100644 --- a/packages/ember-runtime/tests/suites/mutable_array/pushObject.js +++ b/packages/ember-runtime/tests/suites/mutable_array/pushObject.js @@ -1,23 +1,23 @@ import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; import {get} from 'ember-metal/property_get'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('pushObject'); suite.test('returns pushed object', function() { - var exp = this.newFixture(1)[0]; - var obj = this.newObject([]); + let exp = this.newFixture(1)[0]; + let obj = this.newObject([]); + equal(obj.pushObject(exp), exp, 'should return pushed object'); }); suite.test('[].pushObject(X) => [X] + notify', function() { - var obj, before, after, observer; + let before = []; + let after = this.newFixture(1); + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - before = []; - after = this.newFixture(1); - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.pushObject(after[0]); @@ -33,13 +33,12 @@ suite.test('[].pushObject(X) => [X] + notify', function() { }); suite.test('[A,B,C].pushObject(X) => [A,B,C,X] + notify', function() { - var obj, before, after, item, observer; + let before = this.newFixture(3); + let item = this.newFixture(1)[0]; + let after = [before[0], before[1], before[2], item]; + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - before = this.newFixture(3); - item = this.newFixture(1)[0]; - after = [before[0], before[1], before[2], item]; - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.pushObject(item); diff --git a/packages/ember-runtime/tests/suites/mutable_array/pushObjects.js b/packages/ember-runtime/tests/suites/mutable_array/pushObjects.js index b2a6547df67..df5994bd109 100644 --- a/packages/ember-runtime/tests/suites/mutable_array/pushObjects.js +++ b/packages/ember-runtime/tests/suites/mutable_array/pushObjects.js @@ -1,15 +1,13 @@ import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('pushObjects'); suite.test('should raise exception if not Ember.Enumerable is passed to pushObjects', function() { - var obj = this.newObject([]); + let obj = this.newObject([]); - throws(function() { - obj.pushObjects('string'); - }); + throws(() => obj.pushObjects('string')); }); export default suite; diff --git a/packages/ember-runtime/tests/suites/mutable_array/removeAt.js b/packages/ember-runtime/tests/suites/mutable_array/removeAt.js index b89795e78ee..2bf30b82783 100644 --- a/packages/ember-runtime/tests/suites/mutable_array/removeAt.js +++ b/packages/ember-runtime/tests/suites/mutable_array/removeAt.js @@ -1,17 +1,16 @@ import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; import {get} from 'ember-metal/property_get'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('removeAt'); suite.test('[X].removeAt(0) => [] + notify', function() { - var obj, before, after, observer; + let before = this.newFixture(1); + let after = []; + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - before = this.newFixture(1); - after = []; - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ equal(obj.removeAt(0), obj, 'return self'); @@ -27,19 +26,16 @@ suite.test('[X].removeAt(0) => [] + notify', function() { }); suite.test('[].removeAt(200) => OUT_OF_RANGE_EXCEPTION exception', function() { - var obj = this.newObject([]); - throws(function() { - obj.removeAt(200); - }, Error); + let obj = this.newObject([]); + throws(() => obj.removeAt(200), Error); }); suite.test('[A,B].removeAt(0) => [B] + notify', function() { - var obj, before, after, observer; + let before = this.newFixture(2); + let after = [before[1]]; + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - before = this.newFixture(2); - after = [before[1]]; - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ equal(obj.removeAt(0), obj, 'return self'); @@ -56,12 +52,11 @@ suite.test('[A,B].removeAt(0) => [B] + notify', function() { }); suite.test('[A,B].removeAt(1) => [A] + notify', function() { - var obj, before, after, observer; + let before = this.newFixture(2); + let after = [before[0]]; + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - before = this.newFixture(2); - after = [before[0]]; - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ equal(obj.removeAt(1), obj, 'return self'); @@ -78,12 +73,11 @@ suite.test('[A,B].removeAt(1) => [A] + notify', function() { }); suite.test('[A,B,C].removeAt(1) => [A,C] + notify', function() { - var obj, before, after, observer; + let before = this.newFixture(3); + let after = [before[0], before[2]]; + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - before = this.newFixture(3); - after = [before[0], before[2]]; - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ equal(obj.removeAt(1), obj, 'return self'); @@ -100,12 +94,11 @@ suite.test('[A,B,C].removeAt(1) => [A,C] + notify', function() { }); suite.test('[A,B,C,D].removeAt(1,2) => [A,D] + notify', function() { - var obj, before, after, observer; + let before = this.newFixture(4); + let after = [before[0], before[3]]; + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - before = this.newFixture(4); - after = [before[0], before[3]]; - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ equal(obj.removeAt(1, 2), obj, 'return self'); diff --git a/packages/ember-runtime/tests/suites/mutable_array/removeObject.js b/packages/ember-runtime/tests/suites/mutable_array/removeObject.js index 923c0e87b58..1c51acc2747 100644 --- a/packages/ember-runtime/tests/suites/mutable_array/removeObject.js +++ b/packages/ember-runtime/tests/suites/mutable_array/removeObject.js @@ -1,24 +1,23 @@ import get from 'ember-metal/property_get'; import { SuiteModuleBuilder } from 'ember-runtime/tests/suites/suite'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('removeObject'); suite.test('should return receiver', function() { - var before, obj; - before = this.newFixture(3); - obj = this.newObject(before); + let before = this.newFixture(3); + let obj = this.newObject(before); + equal(obj.removeObject(before[1]), obj, 'should return receiver'); }); suite.test('[A,B,C].removeObject(B) => [A,C] + notify', function() { - var obj, before, after, observer; + let before = this.newFixture(3); + let after = [before[0], before[2]]; + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - before = this.newFixture(3); - after = [before[0], before[2]]; - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.removeObject(before[1]); @@ -37,13 +36,12 @@ suite.test('[A,B,C].removeObject(B) => [A,C] + notify', function() { }); suite.test('[A,B,C].removeObject(D) => [A,B,C]', function() { - var obj, before, after, observer, item; + let before = this.newFixture(3); + let after = before; + let item = this.newFixture(1)[0]; + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - before = this.newFixture(3); - after = before; - item = this.newFixture(1)[0]; - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.removeObject(item); // note: item not in set diff --git a/packages/ember-runtime/tests/suites/mutable_array/replace.js b/packages/ember-runtime/tests/suites/mutable_array/replace.js index 7b8793c7232..9eb6e85a95f 100644 --- a/packages/ember-runtime/tests/suites/mutable_array/replace.js +++ b/packages/ember-runtime/tests/suites/mutable_array/replace.js @@ -1,14 +1,14 @@ import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('replace'); suite.test('[].replace(0,0,\'X\') => [\'X\'] + notify', function() { - var obj, exp, observer; - exp = this.newFixture(1); - obj = this.newObject([]); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); + let exp = this.newFixture(1); + let obj = this.newObject([]); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.replace(0, 0, exp); @@ -23,14 +23,13 @@ suite.test('[].replace(0,0,\'X\') => [\'X\'] + notify', function() { }); suite.test('[A,B,C,D].replace(1,2,X) => [A,X,D] + notify', function() { - var obj, observer, before, replace, after; + let before = this.newFixture(4); + let replace = this.newFixture(1); + let after = [before[0], replace[0], before[3]]; - before = this.newFixture(4); - replace = this.newFixture(1); - after = [before[0], replace[0], before[3]]; + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.replace(1, 2, replace); @@ -46,14 +45,13 @@ suite.test('[A,B,C,D].replace(1,2,X) => [A,X,D] + notify', function() { }); suite.test('[A,B,C,D].replace(1,2,[X,Y]) => [A,X,Y,D] + notify', function() { - var obj, observer, before, replace, after; + let before = this.newFixture(4); + let replace = this.newFixture(2); + let after = [before[0], replace[0], replace[1], before[3]]; - before = this.newFixture(4); - replace = this.newFixture(2); - after = [before[0], replace[0], replace[1], before[3]]; + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.replace(1, 2, replace); @@ -69,14 +67,13 @@ suite.test('[A,B,C,D].replace(1,2,[X,Y]) => [A,X,Y,D] + notify', function() { }); suite.test('[A,B].replace(1,0,[X,Y]) => [A,X,Y,B] + notify', function() { - var obj, observer, before, replace, after; + let before = this.newFixture(2); + let replace = this.newFixture(2); + let after = [before[0], replace[0], replace[1], before[1]]; - before = this.newFixture(2); - replace = this.newFixture(2); - after = [before[0], replace[0], replace[1], before[1]]; + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.replace(1, 0, replace); @@ -92,13 +89,12 @@ suite.test('[A,B].replace(1,0,[X,Y]) => [A,X,Y,B] + notify', function() { }); suite.test('[A,B,C,D].replace(2,2) => [A,B] + notify', function() { - var obj, observer, before, after; + let before = this.newFixture(4); + let after = [before[0], before[1]]; - before = this.newFixture(4); - after = [before[0], before[1]]; + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.replace(2, 2); @@ -114,10 +110,10 @@ suite.test('[A,B,C,D].replace(2,2) => [A,B] + notify', function() { }); suite.test('Adding object should notify enumerable observer', function() { - var fixtures = this.newFixture(4); - var obj = this.newObject(fixtures); - var observer = this.newObserver(obj).observeEnumerable(obj); - var item = this.newFixture(1)[0]; + let fixtures = this.newFixture(4); + let obj = this.newObject(fixtures); + let observer = this.newObserver(obj).observeEnumerable(obj); + let item = this.newFixture(1)[0]; obj.replace(2, 2, [item]); @@ -126,10 +122,10 @@ suite.test('Adding object should notify enumerable observer', function() { }); suite.test('Adding object should notify array observer', function() { - var fixtures = this.newFixture(4); - var obj = this.newObject(fixtures); - var observer = this.newObserver(obj).observeArray(obj); - var item = this.newFixture(1)[0]; + let fixtures = this.newFixture(4); + let obj = this.newObject(fixtures); + let observer = this.newObserver(obj).observeArray(obj); + let item = this.newFixture(1)[0]; obj.replace(2, 2, [item]); diff --git a/packages/ember-runtime/tests/suites/mutable_array/reverseObjects.js b/packages/ember-runtime/tests/suites/mutable_array/reverseObjects.js index c153afc1423..78d6d418059 100644 --- a/packages/ember-runtime/tests/suites/mutable_array/reverseObjects.js +++ b/packages/ember-runtime/tests/suites/mutable_array/reverseObjects.js @@ -1,17 +1,16 @@ import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; import {get} from 'ember-metal/property_get'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('reverseObjects'); suite.test('[A,B,C].reverseObjects() => [] + notify', function () { - var obj, before, after, observer; + let before = this.newFixture(3); + let after = [before[2], before[1], before[0]]; + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - before = this.newFixture(3); - after = [before[2], before[1], before[0]]; - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ equal(obj.reverseObjects(), obj, 'return self'); diff --git a/packages/ember-runtime/tests/suites/mutable_array/setObjects.js b/packages/ember-runtime/tests/suites/mutable_array/setObjects.js index bd8f264448e..3cdd9138015 100644 --- a/packages/ember-runtime/tests/suites/mutable_array/setObjects.js +++ b/packages/ember-runtime/tests/suites/mutable_array/setObjects.js @@ -1,17 +1,16 @@ import get from 'ember-metal/property_get'; import { SuiteModuleBuilder } from 'ember-runtime/tests/suites/suite'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('setObjects'); suite.test('[A,B,C].setObjects([]) = > [] + notify', function() { - var obj, before, after, observer; + let before = this.newFixture(3); + let after = []; + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - before = this.newFixture(3); - after = []; - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ equal(obj.setObjects(after), obj, 'return self'); @@ -27,12 +26,11 @@ suite.test('[A,B,C].setObjects([]) = > [] + notify', function() { }); suite.test('[A,B,C].setObjects([D, E, F, G]) = > [D, E, F, G] + notify', function() { - var obj, before, after, observer; + let before = this.newFixture(3); + let after = this.newFixture(4); + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - before = this.newFixture(3); - after = this.newFixture(4); - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ equal(obj.setObjects(after), obj, 'return self'); diff --git a/packages/ember-runtime/tests/suites/mutable_array/shiftObject.js b/packages/ember-runtime/tests/suites/mutable_array/shiftObject.js index 3d575255e22..0b625e699d1 100644 --- a/packages/ember-runtime/tests/suites/mutable_array/shiftObject.js +++ b/packages/ember-runtime/tests/suites/mutable_array/shiftObject.js @@ -1,17 +1,16 @@ import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; import {get} from 'ember-metal/property_get'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('shiftObject'); suite.test('[].shiftObject() => [] + returns undefined + NO notify', function() { - var obj, before, after, observer; + let before = []; + let after = []; + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - before = []; - after = []; - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ equal(obj.shiftObject(), undefined); @@ -28,12 +27,11 @@ suite.test('[].shiftObject() => [] + returns undefined + NO notify', function() }); suite.test('[X].shiftObject() => [] + notify', function() { - var obj, before, after, observer; + let before = this.newFixture(1); + let after = []; + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - before = this.newFixture(1); - after = []; - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ equal(obj.shiftObject(), before[0], 'should return object'); @@ -49,12 +47,11 @@ suite.test('[X].shiftObject() => [] + notify', function() { }); suite.test('[A,B,C].shiftObject() => [B,C] + notify', function() { - var obj, before, after, observer; + let before = this.newFixture(3); + let after = [before[1], before[2]]; + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - before = this.newFixture(3); - after = [before[1], before[2]]; - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ equal(obj.shiftObject(), before[0], 'should return object'); diff --git a/packages/ember-runtime/tests/suites/mutable_array/unshiftObject.js b/packages/ember-runtime/tests/suites/mutable_array/unshiftObject.js index 02cfaa50086..2d9579cbf2e 100644 --- a/packages/ember-runtime/tests/suites/mutable_array/unshiftObject.js +++ b/packages/ember-runtime/tests/suites/mutable_array/unshiftObject.js @@ -1,25 +1,24 @@ import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; import {get} from 'ember-metal/property_get'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('unshiftObject'); suite.test('returns unshifted object', function() { - var obj = this.newObject([]); - var item = this.newFixture(1)[0]; + let obj = this.newObject([]); + let item = this.newFixture(1)[0]; + equal(obj.unshiftObject(item), item, 'should return unshifted object'); }); - suite.test('[].unshiftObject(X) => [X] + notify', function() { - var obj, before, after, item, observer; + let before = []; + let item = this.newFixture(1)[0]; + let after = [item]; + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - before = []; - item = this.newFixture(1)[0]; - after = [item]; - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.unshiftObject(item); @@ -35,13 +34,12 @@ suite.test('[].unshiftObject(X) => [X] + notify', function() { }); suite.test('[A,B,C].unshiftObject(X) => [X,A,B,C] + notify', function() { - var obj, before, after, item, observer; + let before = this.newFixture(3); + let item = this.newFixture(1)[0]; + let after = [item, before[0], before[1], before[2]]; + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - before = this.newFixture(3); - item = this.newFixture(1)[0]; - after = [item, before[0], before[1], before[2]]; - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.unshiftObject(item); @@ -58,13 +56,12 @@ suite.test('[A,B,C].unshiftObject(X) => [X,A,B,C] + notify', function() { }); suite.test('[A,B,C].unshiftObject(A) => [A,A,B,C] + notify', function() { - var obj, before, after, item, observer; + let before = this.newFixture(3); + let item = before[0]; // note same object as current head. should end up twice + let after = [item, before[0], before[1], before[2]]; + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - before = this.newFixture(3); - item = before[0]; // note same object as current head. should end up twice - after = [item, before[0], before[1], before[2]]; - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.unshiftObject(item); diff --git a/packages/ember-runtime/tests/suites/mutable_array/unshiftObjects.js b/packages/ember-runtime/tests/suites/mutable_array/unshiftObjects.js index b47d29ef86b..bcf3c80c172 100644 --- a/packages/ember-runtime/tests/suites/mutable_array/unshiftObjects.js +++ b/packages/ember-runtime/tests/suites/mutable_array/unshiftObjects.js @@ -1,23 +1,23 @@ import get from 'ember-metal/property_get'; import { SuiteModuleBuilder } from 'ember-runtime/tests/suites/suite'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('unshiftObjects'); suite.test('returns receiver', function() { - var obj = this.newObject([]); - var items = this.newFixture(3); + let obj = this.newObject([]); + let items = this.newFixture(3); + equal(obj.unshiftObjects(items), obj, 'should return receiver'); }); suite.test('[].unshiftObjects([A,B,C]) => [A,B,C] + notify', function() { - var obj, before, items, observer; + let before = []; + let items = this.newFixture(3); + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - before = []; - items = this.newFixture(3); - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.unshiftObjects(items); @@ -33,13 +33,12 @@ suite.test('[].unshiftObjects([A,B,C]) => [A,B,C] + notify', function() { }); suite.test('[A,B,C].unshiftObjects([X,Y]) => [X,Y,A,B,C] + notify', function() { - var obj, before, items, after, observer; + let before = this.newFixture(3); + let items = this.newFixture(2); + let after = items.concat(before); + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - before = this.newFixture(3); - items = this.newFixture(2); - after = items.concat(before); - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.unshiftObjects(items); @@ -56,13 +55,12 @@ suite.test('[A,B,C].unshiftObjects([X,Y]) => [X,Y,A,B,C] + notify', function() { }); suite.test('[A,B,C].unshiftObjects([A,B]) => [A,B,A,B,C] + notify', function() { - var obj, before, after, items, observer; + let before = this.newFixture(3); + let items = [before[0], before[1]]; // note same object as current head. should end up twice + let after = items.concat(before); + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - before = this.newFixture(3); - items = [before[0], before[1]]; // note same object as current head. should end up twice - after = items.concat(before); - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.unshiftObjects(items); diff --git a/packages/ember-runtime/tests/suites/mutable_enumerable.js b/packages/ember-runtime/tests/suites/mutable_enumerable.js index bcb8a6c19fc..3a02d18369a 100644 --- a/packages/ember-runtime/tests/suites/mutable_enumerable.js +++ b/packages/ember-runtime/tests/suites/mutable_enumerable.js @@ -4,7 +4,7 @@ import addObjectTests from 'ember-runtime/tests/suites/mutable_enumerable/addObj import removeObjectTests from 'ember-runtime/tests/suites/mutable_enumerable/removeObject'; import removeObjectsTests from 'ember-runtime/tests/suites/mutable_enumerable/removeObjects'; -var MutableEnumerableTests = EnumerableTests.extend(); +const MutableEnumerableTests = EnumerableTests.extend(); MutableEnumerableTests.importModuleTests(addObjectTests); MutableEnumerableTests.importModuleTests(removeObjectTests); MutableEnumerableTests.importModuleTests(removeObjectsTests); diff --git a/packages/ember-runtime/tests/suites/mutable_enumerable/addObject.js b/packages/ember-runtime/tests/suites/mutable_enumerable/addObject.js index eea731d32fa..8bcabd06f02 100644 --- a/packages/ember-runtime/tests/suites/mutable_enumerable/addObject.js +++ b/packages/ember-runtime/tests/suites/mutable_enumerable/addObject.js @@ -1,25 +1,24 @@ import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; import {get} from 'ember-metal/property_get'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('addObject'); suite.test('should return receiver', function() { - var before, obj; - before = this.newFixture(3); - obj = this.newObject(before); + let before = this.newFixture(3); + let obj = this.newObject(before); + equal(obj.addObject(before[1]), obj, 'should return receiver'); }); suite.test('[A,B].addObject(C) => [A,B,C] + notify', function() { - var obj, before, after, observer, item; + let before = this.newFixture(2); + let item = this.newFixture(1)[0]; + let after = [before[0], before[1], item]; + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); - before = this.newFixture(2); - item = this.newFixture(1)[0]; - after = [before[0], before[1], item]; - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); get(obj, 'firstObject'); get(obj, 'lastObject'); @@ -38,13 +37,11 @@ suite.test('[A,B].addObject(C) => [A,B,C] + notify', function() { }); suite.test('[A,B,C].addObject(A) => [A,B,C] + NO notify', function() { - var obj, before, after, observer, item; - - before = this.newFixture(3); - after = before; - item = before[0]; - obj = this.newObject(before); - observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); + let before = this.newFixture(3); + let after = before; + let item = before[0]; + let obj = this.newObject(before); + let observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); obj.addObject(item); // note: item in set @@ -60,9 +57,9 @@ suite.test('[A,B,C].addObject(A) => [A,B,C] + NO notify', function() { }); suite.test('Adding object should notify enumerable observer', function() { - var obj = this.newObject(this.newFixture(3)); - var observer = this.newObserver(obj).observeEnumerable(obj); - var item = this.newFixture(1)[0]; + let obj = this.newObject(this.newFixture(3)); + let observer = this.newObserver(obj).observeEnumerable(obj); + let item = this.newFixture(1)[0]; obj.addObject(item); diff --git a/packages/ember-runtime/tests/suites/mutable_enumerable/removeObject.js b/packages/ember-runtime/tests/suites/mutable_enumerable/removeObject.js index efc8db74aab..23762b52830 100644 --- a/packages/ember-runtime/tests/suites/mutable_enumerable/removeObject.js +++ b/packages/ember-runtime/tests/suites/mutable_enumerable/removeObject.js @@ -2,24 +2,23 @@ import { get } from 'ember-metal/property_get'; import { SuiteModuleBuilder } from 'ember-runtime/tests/suites/suite'; import { A as emberA } from 'ember-runtime/system/native_array'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('removeObject'); suite.test('should return receiver', function() { - var before, obj; - before = this.newFixture(3); - obj = this.newObject(before); + let before = this.newFixture(3); + let obj = this.newObject(before); + equal(obj.removeObject(before[1]), obj, 'should return receiver'); }); suite.test('[A,B,C].removeObject(B) => [A,C] + notify', function() { - var obj, before, after, observer; + let before = emberA(this.newFixture(3)); + let after = [before[0], before[2]]; + let obj = before; + let observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); - before = emberA(this.newFixture(3)); - after = [before[0], before[2]]; - obj = before; - observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); // Prime the cache obj.removeObject(before[1]); @@ -37,13 +36,12 @@ suite.test('[A,B,C].removeObject(B) => [A,C] + notify', function() { }); suite.test('[A,B,C].removeObject(D) => [A,B,C]', function() { - var obj, before, after, observer, item; + let before = emberA(this.newFixture(3)); + let after = before; + let item = this.newFixture(1)[0]; + let obj = before; + let observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); - before = emberA(this.newFixture(3)); - after = before; - item = this.newFixture(1)[0]; - obj = before; - observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); // Prime the cache obj.removeObject(item); // Note: item not in set @@ -61,10 +59,10 @@ suite.test('[A,B,C].removeObject(D) => [A,B,C]', function() { }); suite.test('Removing object should notify enumerable observer', function() { - var fixtures = this.newFixture(3); - var obj = this.newObject(fixtures); - var observer = this.newObserver(obj).observeEnumerable(obj); - var item = fixtures[1]; + let fixtures = this.newFixture(3); + let obj = this.newObject(fixtures); + let observer = this.newObserver(obj).observeEnumerable(obj); + let item = fixtures[1]; obj.removeObject(item); diff --git a/packages/ember-runtime/tests/suites/mutable_enumerable/removeObjects.js b/packages/ember-runtime/tests/suites/mutable_enumerable/removeObjects.js index bde38d7138b..c1b7739e52e 100644 --- a/packages/ember-runtime/tests/suites/mutable_enumerable/removeObjects.js +++ b/packages/ember-runtime/tests/suites/mutable_enumerable/removeObjects.js @@ -2,24 +2,23 @@ import { SuiteModuleBuilder } from 'ember-runtime/tests/suites/suite'; import { get } from 'ember-metal/property_get'; import { A as emberA } from 'ember-runtime/system/native_array'; -var suite = SuiteModuleBuilder.create(); +const suite = SuiteModuleBuilder.create(); suite.module('removeObjects'); suite.test('should return receiver', function() { - var before, obj; - before = emberA(this.newFixture(3)); - obj = before; + let before = emberA(this.newFixture(3)); + let obj = before; + equal(obj.removeObjects(before[1]), obj, 'should return receiver'); }); suite.test('[A,B,C].removeObjects([B]) => [A,C] + notify', function() { - var obj, before, after, observer; + let before = emberA(this.newFixture(3)); + let after = [before[0], before[2]]; + let obj = before; + let observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); - before = emberA(this.newFixture(3)); - after = [before[0], before[2]]; - obj = before; - observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); // Prime the cache obj.removeObjects([before[1]]); @@ -37,12 +36,11 @@ suite.test('[A,B,C].removeObjects([B]) => [A,C] + notify', function() { }); suite.test('[{A},{B},{C}].removeObjects([{B}]) => [{A},{C}] + notify', function() { - var obj, before, after, observer; + let before = emberA(this.newObjectsFixture(3)); + let after = [before[0], before[2]]; + let obj = before; + let observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); - before = emberA(this.newObjectsFixture(3)); - after = [before[0], before[2]]; - obj = before; - observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); // Prime the cache obj.removeObjects([before[1]]); @@ -60,12 +58,11 @@ suite.test('[{A},{B},{C}].removeObjects([{B}]) => [{A},{C}] + notify', function( }); suite.test('[A,B,C].removeObjects([A,B]) => [C] + notify', function() { - var obj, before, after, observer; + let before = emberA(this.newFixture(3)); + let after = [before[2]]; + let obj = before; + let observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); - before = emberA(this.newFixture(3)); - after = [before[2]]; - obj = before; - observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); // Prime the cache obj.removeObjects([before[0], before[1]]); @@ -83,12 +80,11 @@ suite.test('[A,B,C].removeObjects([A,B]) => [C] + notify', function() { }); suite.test('[{A},{B},{C}].removeObjects([{A},{B}]) => [{C}] + notify', function() { - var obj, before, after, observer; + let before = emberA(this.newObjectsFixture(3)); + let after = [before[2]]; + let obj = before; + let observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); - before = emberA(this.newObjectsFixture(3)); - after = [before[2]]; - obj = before; - observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); // Prime the cache obj.removeObjects([before[0], before[1]]); @@ -106,12 +102,11 @@ suite.test('[{A},{B},{C}].removeObjects([{A},{B}]) => [{C}] + notify', function( }); suite.test('[A,B,C].removeObjects([A,B,C]) => [] + notify', function() { - var obj, before, after, observer; + let before = emberA(this.newFixture(3)); + let after = []; + let obj = before; + let observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); - before = emberA(this.newFixture(3)); - after = []; - obj = before; - observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); // Prime the cache obj.removeObjects([before[0], before[1], before[2]]); @@ -129,12 +124,11 @@ suite.test('[A,B,C].removeObjects([A,B,C]) => [] + notify', function() { }); suite.test('[{A},{B},{C}].removeObjects([{A},{B},{C}]) => [] + notify', function() { - var obj, before, after, observer; + let before = emberA(this.newObjectsFixture(3)); + let after = []; + let obj = before; + let observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); - before = emberA(this.newObjectsFixture(3)); - after = []; - obj = before; - observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); // Prime the cache obj.removeObjects(before); @@ -152,13 +146,12 @@ suite.test('[{A},{B},{C}].removeObjects([{A},{B},{C}]) => [] + notify', function }); suite.test('[A,B,C].removeObjects([D]) => [A,B,C]', function() { - var obj, before, after, observer, item; + let before = emberA(this.newFixture(3)); + let after = before; + let item = this.newFixture(1)[0]; + let obj = before; + let observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); - before = emberA(this.newFixture(3)); - after = before; - item = this.newFixture(1)[0]; - obj = before; - observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); // Prime the cache obj.removeObjects([item]); // Note: item not in set @@ -176,10 +169,10 @@ suite.test('[A,B,C].removeObjects([D]) => [A,B,C]', function() { }); suite.test('Removing objects should notify enumerable observer', function() { - var fixtures = this.newFixture(3); - var obj = this.newObject(fixtures); - var observer = this.newObserver(obj).observeEnumerable(obj); - var item = fixtures[1]; + let fixtures = this.newFixture(3); + let obj = this.newObject(fixtures); + let observer = this.newObserver(obj).observeEnumerable(obj); + let item = fixtures[1]; obj.removeObjects([item]); diff --git a/packages/ember-runtime/tests/suites/suite.js b/packages/ember-runtime/tests/suites/suite.js index a314a28fc5d..a53a01aa09b 100644 --- a/packages/ember-runtime/tests/suites/suite.js +++ b/packages/ember-runtime/tests/suites/suite.js @@ -35,7 +35,7 @@ import { get } from 'ember-metal/property_get'; @extends Ember.Object @private */ -var Suite = EmberObject.extend({ +const Suite = EmberObject.extend({ /* __Required.__ You must implement this method to apply this mixin. @@ -58,7 +58,7 @@ Suite.reopenClass({ plan: null, run() { - var C = this; + let C = this; return new C().run(); }, @@ -67,13 +67,13 @@ Suite.reopenClass({ opts = {}; } - var setup = opts.setup; - var teardown = opts.teardown; + let setup = opts.setup; + let teardown = opts.teardown; this.reopen({ run() { this._super(...arguments); - var title = get(this, 'name') + ': ' + desc; - var ctx = this; + let title = get(this, 'name') + ': ' + desc; + let ctx = this; QUnit.module(title, { setup() { if (setup) { @@ -95,12 +95,12 @@ Suite.reopenClass({ this.reopen({ run() { this._super(...arguments); - var ctx = this; + let ctx = this; if (!func) { QUnit.test(name); // output warning } else { - QUnit.test(name, function() { func.call(ctx); }); + QUnit.test(name, () => func.call(ctx)); } } }); @@ -108,8 +108,8 @@ Suite.reopenClass({ // convert to guids to minimize logging. same(actual, exp, message) { - actual = (actual && actual.map) ? actual.map(function(x) { return guidFor(x); }) : actual; - exp = (exp && exp.map) ? exp.map(function(x) { return guidFor(x); }) : exp; + actual = (actual && actual.map) ? actual.map(x => guidFor(x)) : actual; + exp = (exp && exp.map) ? exp.map(x => guidFor(x)) : exp; return deepEqual(actual, exp, message); }, @@ -125,7 +125,7 @@ Suite.reopenClass({ } }); -var SuiteModuleBuilder = EmberObject.extend({ +const SuiteModuleBuilder = EmberObject.extend({ _module: null, _tests: null, diff --git a/packages/ember-runtime/tests/system/array_proxy/arranged_content_test.js b/packages/ember-runtime/tests/system/array_proxy/arranged_content_test.js index 9971270d06c..29d0698f152 100644 --- a/packages/ember-runtime/tests/system/array_proxy/arranged_content_test.js +++ b/packages/ember-runtime/tests/system/array_proxy/arranged_content_test.js @@ -4,15 +4,15 @@ import ArrayProxy from 'ember-runtime/system/array_proxy'; import { A as emberA } from 'ember-runtime/system/native_array'; import { objectAt } from 'ember-runtime/mixins/array'; -var array; +let array; QUnit.module('ArrayProxy - arrangedContent', { setup() { - run(function() { + run(() => { array = ArrayProxy.extend({ arrangedContent: computed('content.[]', function() { - var content = this.get('content'); - return content && emberA(content.slice().sort(function(a, b) { + let content = this.get('content'); + return content && emberA(content.slice().sort((a, b) => { if (a == null) { a = -1; } if (b == null) { b = -1; } return b - a; @@ -24,29 +24,31 @@ QUnit.module('ArrayProxy - arrangedContent', { }); }, teardown() { - run(function() { - array.destroy(); - }); + run(() => array.destroy()); } }); QUnit.test('addObject - adds to end of \'content\' if not present', function() { - run(function() { array.addObject(3); }); + run(() => array.addObject(3)); + deepEqual(array.get('content'), [1, 2, 4, 5, 3], 'adds to end of content'); deepEqual(array.get('arrangedContent'), [5, 4, 3, 2, 1], 'arrangedContent stays sorted'); - run(function() { array.addObject(1); }); + run(() => array.addObject(1)); + deepEqual(array.get('content'), [1, 2, 4, 5, 3], 'does not add existing number to content'); }); QUnit.test('addObjects - adds to end of \'content\' if not present', function() { - run(function() { array.addObjects([1, 3, 6]); }); + run(() => array.addObjects([1, 3, 6])); + deepEqual(array.get('content'), [1, 2, 4, 5, 3, 6], 'adds to end of content'); deepEqual(array.get('arrangedContent'), [6, 5, 4, 3, 2, 1], 'arrangedContent stays sorted'); }); QUnit.test('compact - returns arrangedContent without nulls and undefined', function() { - run(function() { array.set('content', emberA([1, 3, null, 2, undefined])); }); + run(() => array.set('content', emberA([1, 3, null, 2, undefined]))); + deepEqual(array.compact(), [3, 2, 1]); }); @@ -55,13 +57,12 @@ QUnit.test('indexOf - returns index of object in arrangedContent', function() { }); QUnit.test('insertAt - raises, indeterminate behavior', function() { - throws(function() { - run(function() { array.insertAt(2, 3); }); - }); + throws(() => run(() => array.insertAt(2, 3))); }); QUnit.test('lastIndexOf - returns last index of object in arrangedContent', function() { - run(function() { array.pushObject(4); }); + run(() => array.pushObject(4)); + equal(array.lastIndexOf(4), 2, 'returns last arranged index'); }); @@ -83,62 +84,58 @@ QUnit.test('objectsAt - returns objects at indices in arrangedContent', function }); QUnit.test('popObject - removes last object in arrangedContent', function() { - var popped; - run(function() { popped = array.popObject(); }); + let popped; + run(() => popped = array.popObject()); equal(popped, 1, 'returns last object'); deepEqual(array.get('content'), [2, 4, 5], 'removes from content'); }); QUnit.test('pushObject - adds to end of content even if it already exists', function() { - run(function() { array.pushObject(1); }); + run(() => array.pushObject(1)); deepEqual(array.get('content'), [1, 2, 4, 5, 1], 'adds to end of content'); }); QUnit.test('pushObjects - adds multiple to end of content even if it already exists', function() { - run(function() { array.pushObjects([1, 2, 4]); }); + run(() => array.pushObjects([1, 2, 4])); deepEqual(array.get('content'), [1, 2, 4, 5, 1, 2, 4], 'adds to end of content'); }); QUnit.test('removeAt - removes from index in arrangedContent', function() { - run(function() { array.removeAt(1, 2); }); + run(() => array.removeAt(1, 2)); deepEqual(array.get('content'), [1, 5]); }); QUnit.test('removeObject - removes object from content', function() { - run(function() { array.removeObject(2); }); + run(() => array.removeObject(2)); deepEqual(array.get('content'), [1, 4, 5]); }); QUnit.test('removeObjects - removes objects from content', function() { - run(function() { array.removeObjects([2, 4, 6]); }); + run(() => array.removeObjects([2, 4, 6])); deepEqual(array.get('content'), [1, 5]); }); QUnit.test('replace - raises, indeterminate behavior', function() { - throws(function() { - run(function() { array.replace(1, 2, [3]); }); - }); + throws(() => run(() => array.replace(1, 2, [3]))); }); QUnit.test('replaceContent - does a standard array replace on content', function() { - run(function() { array.replaceContent(1, 2, [3]); }); + run(() => array.replaceContent(1, 2, [3])); deepEqual(array.get('content'), [1, 3, 5]); }); QUnit.test('reverseObjects - raises, use Sortable#sortAscending', function() { - throws(function() { - run(function() { array.reverseObjects(); }); - }); + throws(() => run(() => array.reverseObjects())); }); QUnit.test('setObjects - replaces entire content', function() { - run(function() { array.setObjects([6, 7, 8]); }); + run(() => array.setObjects([6, 7, 8])); deepEqual(array.get('content'), [6, 7, 8], 'replaces content'); }); QUnit.test('shiftObject - removes from start of arrangedContent', function() { - var shifted; - run(function() { shifted = array.shiftObject(); }); + let shifted = run(() => array.shiftObject()); + equal(shifted, 5, 'returns first object'); deepEqual(array.get('content'), [1, 2, 4], 'removes object from content'); }); @@ -152,7 +149,7 @@ QUnit.test('toArray - returns copy of arrangedContent', function() { }); QUnit.test('unshiftObject - adds to start of content', function() { - run(function() { array.unshiftObject(6); }); + run(() => array.unshiftObject(6)); deepEqual(array.get('content'), [6, 1, 2, 4, 5], 'adds to start of content'); }); @@ -209,7 +206,7 @@ QUnit.module('ArrayProxy - arrangedContent with transforms', { run(function() { array = ArrayProxy.extend({ arrangedContent: computed(function() { - var content = this.get('content'); + let content = this.get('content'); return content && emberA(content.slice().sort(function(a, b) { if (a == null) { a = -1; } if (b == null) { b = -1; } @@ -218,7 +215,7 @@ QUnit.module('ArrayProxy - arrangedContent with transforms', { }).property('content.[]'), objectAtContent(idx) { - var obj = objectAt(this.get('arrangedContent'), idx); + let obj = objectAt(this.get('arrangedContent'), idx); return obj && obj.toString(); } }).create({ @@ -260,7 +257,7 @@ QUnit.test('objectsAt - returns objects at indices in arrangedContent', function }); QUnit.test('popObject - removes last object in arrangedContent', function() { - var popped; + let popped; run(function() { popped = array.popObject(); }); equal(popped, '1', 'returns last object'); deepEqual(array.get('content'), [2, 4, 5], 'removes from content'); @@ -277,7 +274,7 @@ QUnit.test('removeObjects - removes objects from content', function() { }); QUnit.test('shiftObject - removes from start of arrangedContent', function() { - var shifted; + let shifted; run(function() { shifted = array.shiftObject(); }); equal(shifted, '5', 'returns first object'); deepEqual(array.get('content'), [1, 2, 4], 'removes object from content'); diff --git a/packages/ember-runtime/tests/system/array_proxy/content_change_test.js b/packages/ember-runtime/tests/system/array_proxy/content_change_test.js index 43a7bf78468..9dba0ed21a1 100644 --- a/packages/ember-runtime/tests/system/array_proxy/content_change_test.js +++ b/packages/ember-runtime/tests/system/array_proxy/content_change_test.js @@ -7,9 +7,9 @@ import { A as emberA } from 'ember-runtime/system/native_array'; QUnit.module('ArrayProxy - content change'); QUnit.test('should update length for null content', function() { - var proxy = ArrayProxy.create({ - content: emberA([1, 2, 3]) - }); + let proxy = ArrayProxy.create({ + content: emberA([1, 2, 3]) + }); equal(proxy.get('length'), 3, 'precond - length is 3'); @@ -19,7 +19,7 @@ QUnit.test('should update length for null content', function() { }); QUnit.test('should update length for null content when there is a computed property watching length', function() { - var proxy = ArrayProxy.extend({ + let proxy = ArrayProxy.extend({ isEmpty: not('length') }).create({ content: emberA([1, 2, 3]) @@ -37,10 +37,10 @@ QUnit.test('should update length for null content when there is a computed prope }); QUnit.test('The `arrangedContentWillChange` method is invoked before `content` is changed.', function() { - var callCount = 0; - var expectedLength; + let callCount = 0; + let expectedLength; - var proxy = ArrayProxy.extend({ + let proxy = ArrayProxy.extend({ arrangedContentWillChange() { equal(this.get('arrangedContent.length'), expectedLength, 'hook should be invoked before array has changed'); callCount++; @@ -59,10 +59,10 @@ QUnit.test('The `arrangedContentWillChange` method is invoked before `content` i }); QUnit.test('The `arrangedContentDidChange` method is invoked after `content` is changed.', function() { - var callCount = 0; - var expectedLength; + let callCount = 0; + let expectedLength; - var proxy = ArrayProxy.extend({ + let proxy = ArrayProxy.extend({ arrangedContentDidChange() { equal(this.get('arrangedContent.length'), expectedLength, 'hook should be invoked after array has changed'); callCount++; @@ -85,12 +85,10 @@ QUnit.test('The `arrangedContentDidChange` method is invoked after `content` is }); QUnit.test('The ArrayProxy doesn\'t explode when assigned a destroyed object', function() { - var proxy1 = ArrayProxy.create(); - var proxy2 = ArrayProxy.create(); + let proxy1 = ArrayProxy.create(); + let proxy2 = ArrayProxy.create(); - run(function() { - proxy1.destroy(); - }); + run(() => proxy1.destroy()); set(proxy2, 'content', proxy1); diff --git a/packages/ember-runtime/tests/system/array_proxy/content_update_test.js b/packages/ember-runtime/tests/system/array_proxy/content_update_test.js index c8a269bbde6..7b908b6af1d 100644 --- a/packages/ember-runtime/tests/system/array_proxy/content_update_test.js +++ b/packages/ember-runtime/tests/system/array_proxy/content_update_test.js @@ -5,10 +5,8 @@ import { A as emberA } from 'ember-runtime/system/native_array'; QUnit.module('Ember.ArrayProxy - content update'); QUnit.test('The `contentArrayDidChange` method is invoked after `content` is updated.', function() { - var proxy; - var observerCalled = false; - - proxy = ArrayProxy.extend({ + let observerCalled = false; + let proxy = ArrayProxy.extend({ arrangedContent: computed('content', function(key) { return emberA(this.get('content').slice()); }), diff --git a/packages/ember-runtime/tests/system/array_proxy/length_test.js b/packages/ember-runtime/tests/system/array_proxy/length_test.js index 669769cbb1e..1afb5c01518 100644 --- a/packages/ember-runtime/tests/system/array_proxy/length_test.js +++ b/packages/ember-runtime/tests/system/array_proxy/length_test.js @@ -7,33 +7,19 @@ import { A as a } from 'ember-runtime/system/native_array'; QUnit.module('Ember.ArrayProxy - content change (length)'); QUnit.test('array proxy + aliasedProperty complex test', function() { - var aCalled, bCalled, cCalled, dCalled, eCalled; + let aCalled, bCalled, cCalled, dCalled, eCalled; aCalled = bCalled = cCalled = dCalled = eCalled = 0; - var obj = Object.extend({ + let obj = Object.extend({ colors: computed.reads('model'), length: computed.reads('colors.length'), - a: observer('length', function() { - aCalled++; - }), - - b: observer('colors.length', function() { - bCalled++; - }), - - c: observer('colors.content.length', function() { - cCalled++; - }), - - d: observer('colors.[]', function() { - dCalled++; - }), - - e: observer('colors.content.[]', function() { - eCalled++; - }) + a: observer('length', () => aCalled++), + b: observer('colors.length', () => bCalled++), + c: observer('colors.content.length', () => cCalled++), + d: observer('colors.[]', () => dCalled++), + e: observer('colors.content.[]', () => eCalled++) }).create(); obj.set('model', ArrayProxy.create({ diff --git a/packages/ember-runtime/tests/system/array_proxy/suite_test.js b/packages/ember-runtime/tests/system/array_proxy/suite_test.js index 7186acbdb26..029a1be62d4 100644 --- a/packages/ember-runtime/tests/system/array_proxy/suite_test.js +++ b/packages/ember-runtime/tests/system/array_proxy/suite_test.js @@ -4,11 +4,10 @@ import { get } from 'ember-metal/property_get'; import { A as emberA } from 'ember-runtime/system/native_array'; MutableArrayTests.extend({ - name: 'Ember.ArrayProxy', newObject(ary) { - var ret = ary ? ary.slice() : this.newFixture(3); + let ret = ary ? ary.slice() : this.newFixture(3); return ArrayProxy.create({ content: emberA(ret) }); }, @@ -19,5 +18,4 @@ MutableArrayTests.extend({ toArray(obj) { return obj.toArray ? obj.toArray() : obj.slice(); } - }).run(); diff --git a/packages/ember-runtime/tests/system/core_object_test.js b/packages/ember-runtime/tests/system/core_object_test.js index 703bcc5302a..be24a28d289 100644 --- a/packages/ember-runtime/tests/system/core_object_test.js +++ b/packages/ember-runtime/tests/system/core_object_test.js @@ -4,7 +4,7 @@ import CoreObject from 'ember-runtime/system/core_object'; QUnit.module('Ember.CoreObject'); QUnit.test('works with new (one arg)', function() { - var obj = new CoreObject({ + let obj = new CoreObject({ firstName: 'Stef', lastName: 'Penner' }); @@ -14,7 +14,7 @@ QUnit.test('works with new (one arg)', function() { }); QUnit.test('works with new (> 1 arg)', function() { - var obj = new CoreObject({ + let obj = new CoreObject({ firstName: 'Stef', lastName: 'Penner' }, { @@ -28,7 +28,7 @@ QUnit.test('works with new (> 1 arg)', function() { }); QUnit.test('toString should be not be added as a property when calling toString()', function() { - var obj = new CoreObject({ + let obj = new CoreObject({ firstName: 'Foo', lastName: 'Bar' }); diff --git a/packages/ember-runtime/tests/system/lazy_load_test.js b/packages/ember-runtime/tests/system/lazy_load_test.js index 31f6fd4d4e2..25085df7709 100644 --- a/packages/ember-runtime/tests/system/lazy_load_test.js +++ b/packages/ember-runtime/tests/system/lazy_load_test.js @@ -4,7 +4,7 @@ import {onLoad, runLoadHooks} from 'ember-runtime/system/lazy_load'; QUnit.module('Lazy Loading'); QUnit.test('if a load hook is registered, it is executed when runLoadHooks are exected', function() { - var count = 0; + let count = 0; run(function() { onLoad('__test_hook__', function(object) { @@ -20,22 +20,16 @@ QUnit.test('if a load hook is registered, it is executed when runLoadHooks are e }); QUnit.test('if runLoadHooks was already run, it executes newly added hooks immediately', function() { - var count = 0; - run(function() { - onLoad('__test_hook__', function(object) { - count += object; - }); + let count = 0; + run(() => { + onLoad('__test_hook__', object => count += object); }); - run(function() { - runLoadHooks('__test_hook__', 1); - }); + run(() => runLoadHooks('__test_hook__', 1)); count = 0; - run(function() { - onLoad('__test_hook__', function(object) { - count += object; - }); + run(() => { + onLoad('__test_hook__', object => count += object); }); equal(count, 1, 'the original object was passed into the load hook'); @@ -45,7 +39,7 @@ QUnit.test('hooks in ENV.EMBER_LOAD_HOOKS[\'hookName\'] get executed', function( // Note that the necessary code to perform this test is run before // the Ember lib is loaded in tests/index.html - run(function() { + run(() => { runLoadHooks('__before_ember_test_hook__', 1); }); @@ -54,14 +48,14 @@ QUnit.test('hooks in ENV.EMBER_LOAD_HOOKS[\'hookName\'] get executed', function( if (typeof window === 'object' && typeof window.dispatchEvent === 'function' && typeof CustomEvent === 'function') { QUnit.test('load hooks trigger a custom event', function() { - var eventObject = 'super duper awesome events'; + let eventObject = 'super duper awesome events'; window.addEventListener('__test_hook_for_events__', function(e) { ok(true, 'custom event was fired'); equal(e.detail, eventObject, 'event details are provided properly'); }); - run(function() { + run(() => { runLoadHooks('__test_hook_for_events__', eventObject); }); }); diff --git a/packages/ember-runtime/tests/system/namespace/base_test.js b/packages/ember-runtime/tests/system/namespace/base_test.js index ec31b448bd7..b9b140e6a83 100644 --- a/packages/ember-runtime/tests/system/namespace/base_test.js +++ b/packages/ember-runtime/tests/system/namespace/base_test.js @@ -18,7 +18,7 @@ QUnit.module('Namespace', { teardown() { setNamespaceSearchDisabled(false); - for (var prop in lookup) { + for (let prop in lookup) { if (lookup[prop]) { run(lookup[prop], 'destroy'); } } @@ -35,22 +35,22 @@ QUnit.test('Namespace should be duck typed', function() { }); QUnit.test('Namespace is found and named', function() { - var nsA = lookup.NamespaceA = Namespace.create(); + let nsA = lookup.NamespaceA = Namespace.create(); equal(nsA.toString(), 'NamespaceA', 'namespaces should have a name if they are on lookup'); - var nsB = lookup.NamespaceB = Namespace.create(); + let nsB = lookup.NamespaceB = Namespace.create(); equal(nsB.toString(), 'NamespaceB', 'namespaces work if created after the first namespace processing pass'); }); QUnit.test('Classes under an Namespace are properly named', function() { - var nsA = lookup.NamespaceA = Namespace.create(); + let nsA = lookup.NamespaceA = Namespace.create(); nsA.Foo = EmberObject.extend(); equal(nsA.Foo.toString(), 'NamespaceA.Foo', 'Classes pick up their parent namespace'); nsA.Bar = EmberObject.extend(); equal(nsA.Bar.toString(), 'NamespaceA.Bar', 'New Classes get the naming treatment too'); - var nsB = lookup.NamespaceB = Namespace.create(); + let nsB = lookup.NamespaceB = Namespace.create(); nsB.Foo = EmberObject.extend(); equal(nsB.Foo.toString(), 'NamespaceB.Foo', 'Classes in new namespaces get the naming treatment'); }); @@ -62,16 +62,16 @@ QUnit.test('Classes under an Namespace are properly named', function() { //}); QUnit.test('Lowercase namespaces are no longer supported', function() { - var nsC = lookup.namespaceC = Namespace.create(); + let nsC = lookup.namespaceC = Namespace.create(); equal(nsC.toString(), undefined); }); QUnit.test('A namespace can be assigned a custom name', function() { - var nsA = Namespace.create({ + let nsA = Namespace.create({ name: 'NamespaceA' }); - var nsB = lookup.NamespaceB = Namespace.create({ + let nsB = lookup.NamespaceB = Namespace.create({ name: 'CustomNamespaceB' }); @@ -85,7 +85,7 @@ QUnit.test('A namespace can be assigned a custom name', function() { QUnit.test('Calling namespace.nameClasses() eagerly names all classes', function() { setNamespaceSearchDisabled(true); - var namespace = lookup.NS = Namespace.create(); + let namespace = lookup.NS = Namespace.create(); namespace.ClassA = EmberObject.extend(); namespace.ClassB = EmberObject.extend(); @@ -97,9 +97,9 @@ QUnit.test('Calling namespace.nameClasses() eagerly names all classes', function }); QUnit.test('A namespace can be looked up by its name', function() { - var NS = lookup.NS = Namespace.create(); - var UI = lookup.UI = Namespace.create(); - var CF = lookup.CF = Namespace.create(); + let NS = lookup.NS = Namespace.create(); + let UI = lookup.UI = Namespace.create(); + let CF = lookup.CF = Namespace.create(); equal(Namespace.byName('NS'), NS); equal(Namespace.byName('UI'), UI); @@ -107,21 +107,21 @@ QUnit.test('A namespace can be looked up by its name', function() { }); QUnit.test('A nested namespace can be looked up by its name', function() { - var UI = lookup.UI = Namespace.create(); + let UI = lookup.UI = Namespace.create(); UI.Nav = Namespace.create(); equal(Namespace.byName('UI.Nav'), UI.Nav); }); QUnit.test('Destroying a namespace before caching lookup removes it from the list of namespaces', function() { - var CF = lookup.CF = Namespace.create(); + let CF = lookup.CF = Namespace.create(); run(CF, 'destroy'); equal(Namespace.byName('CF'), undefined, 'namespace can not be found after destroyed'); }); QUnit.test('Destroying a namespace after looking up removes it from the list of namespaces', function() { - var CF = lookup.CF = Namespace.create(); + let CF = lookup.CF = Namespace.create(); equal(Namespace.byName('CF'), CF, 'precondition - namespace can be looked up by name'); diff --git a/packages/ember-runtime/tests/system/native_array/copyable_suite_test.js b/packages/ember-runtime/tests/system/native_array/copyable_suite_test.js index ae8f6977aa4..791cdf7d778 100644 --- a/packages/ember-runtime/tests/system/native_array/copyable_suite_test.js +++ b/packages/ember-runtime/tests/system/native_array/copyable_suite_test.js @@ -31,9 +31,9 @@ CopyableTests.extend({ QUnit.module('NativeArray Copyable'); QUnit.test('deep copy is respected', function() { - var array = emberA([{ id: 1 }, { id: 2 }, { id: 3 }]); + let array = emberA([{ id: 1 }, { id: 2 }, { id: 3 }]); - var copiedArray = array.copy(true); + let copiedArray = array.copy(true); deepEqual(copiedArray, array, 'copied array is equivalent'); ok(copiedArray[0] !== array[0], 'objects inside should be unique'); diff --git a/packages/ember-runtime/tests/system/native_array/suite_test.js b/packages/ember-runtime/tests/system/native_array/suite_test.js index 617c046b813..931d6df197b 100644 --- a/packages/ember-runtime/tests/system/native_array/suite_test.js +++ b/packages/ember-runtime/tests/system/native_array/suite_test.js @@ -2,7 +2,6 @@ import { A as emberA } from 'ember-runtime/system/native_array'; import MutableArrayTests from 'ember-runtime/tests/suites/mutable_array'; MutableArrayTests.extend({ - name: 'Native Array', newObject(ary) { @@ -16,5 +15,4 @@ MutableArrayTests.extend({ toArray(obj) { return obj.slice(); // make a copy. } - }).run(); diff --git a/packages/ember-runtime/tests/system/object/computed_test.js b/packages/ember-runtime/tests/system/object/computed_test.js index 91ae1e59787..66e5a62c16a 100644 --- a/packages/ember-runtime/tests/system/object/computed_test.js +++ b/packages/ember-runtime/tests/system/object/computed_test.js @@ -10,7 +10,7 @@ function K() { return this; } QUnit.module('EmberObject computed property'); testWithDefault('computed property on instance', function(get, set) { - var MyClass = EmberObject.extend({ + let MyClass = EmberObject.extend({ foo: computed(function() { return 'FOO'; }) }); @@ -19,11 +19,11 @@ testWithDefault('computed property on instance', function(get, set) { testWithDefault('computed property on subclass', function(get, set) { - var MyClass = EmberObject.extend({ + let MyClass = EmberObject.extend({ foo: computed(function() { return 'FOO'; }) }); - var Subclass = MyClass.extend({ + let Subclass = MyClass.extend({ foo: computed(function() { return 'BAR'; }) }); @@ -32,11 +32,11 @@ testWithDefault('computed property on subclass', function(get, set) { testWithDefault('replacing computed property with regular val', function(get, set) { - var MyClass = EmberObject.extend({ + let MyClass = EmberObject.extend({ foo: computed(function() { return 'FOO'; }) }); - var Subclass = MyClass.extend({ + let Subclass = MyClass.extend({ foo: 'BAR' }); @@ -44,7 +44,7 @@ testWithDefault('replacing computed property with regular val', function(get, se }); testWithDefault('complex depndent keys', function(get, set) { - var MyClass = EmberObject.extend({ + let MyClass = EmberObject.extend({ init() { this._super(...arguments); @@ -60,12 +60,12 @@ testWithDefault('complex depndent keys', function(get, set) { }); - var Subclass = MyClass.extend({ + let Subclass = MyClass.extend({ count: 20 }); - var obj1 = new MyClass(); - var obj2 = new Subclass(); + let obj1 = new MyClass(); + let obj2 = new Subclass(); equal(get(obj1, 'foo'), 'BIFF 1'); equal(get(obj2, 'foo'), 'BIFF 21'); @@ -82,7 +82,7 @@ testWithDefault('complex depndent keys', function(get, set) { }); testWithDefault('complex dependent keys changing complex dependent keys', function(get, set) { - var MyClass = EmberObject.extend({ + let MyClass = EmberObject.extend({ init() { this._super(...arguments); set(this, 'bar', { baz: 'BIFF' }); @@ -96,7 +96,7 @@ testWithDefault('complex dependent keys changing complex dependent keys', functi }).property('bar.baz') }); - var Subclass = MyClass.extend({ + let Subclass = MyClass.extend({ init() { this._super(...arguments); set(this, 'bar2', { baz: 'BIFF2' }); @@ -110,7 +110,7 @@ testWithDefault('complex dependent keys changing complex dependent keys', functi }).property('bar2.baz') }); - var obj2 = new Subclass(); + let obj2 = new Subclass(); equal(get(obj2, 'foo'), 'BIFF2 1'); @@ -122,14 +122,14 @@ testWithDefault('complex dependent keys changing complex dependent keys', functi }); QUnit.test('can retrieve metadata for a computed property', function() { - var MyClass = EmberObject.extend({ + let MyClass = EmberObject.extend({ computedProperty: computed(function() { }).meta({ key: 'keyValue' }) }); equal(emberGet(MyClass.metaForProperty('computedProperty'), 'key'), 'keyValue', 'metadata saved on the computed property can be retrieved'); - var ClassWithNoMetadata = EmberObject.extend({ + let ClassWithNoMetadata = EmberObject.extend({ computedProperty: computed(function() { }).volatile(), @@ -148,7 +148,7 @@ QUnit.test('can retrieve metadata for a computed property', function() { }); QUnit.test('can iterate over a list of computed properties for a class', function() { - var MyClass = EmberObject.extend({ + let MyClass = EmberObject.extend({ foo: computed(function() {}), fooDidChange: observer('foo', function() {}), @@ -158,7 +158,7 @@ QUnit.test('can iterate over a list of computed properties for a class', functio qux: alias('foo') }); - var SubClass = MyClass.extend({ + let SubClass = MyClass.extend({ baz: computed(function() {}) }); @@ -166,7 +166,7 @@ QUnit.test('can iterate over a list of computed properties for a class', functio bat: computed(function() {}).meta({ iAmBat: true }) }); - var list = []; + let list = []; MyClass.eachComputedProperty(function(name) { list.push(name); @@ -190,7 +190,7 @@ QUnit.test('can iterate over a list of computed properties for a class', functio }); QUnit.test('list of properties updates when an additional property is added (such cache busting)', function() { - var MyClass = EmberObject.extend({ + let MyClass = EmberObject.extend({ foo: computed(K), fooDidChange: observer('foo', function() {}), @@ -198,7 +198,7 @@ QUnit.test('list of properties updates when an additional property is added (suc bar: computed(K) }); - var list = []; + let list = []; MyClass.eachComputedProperty(function(name) { list.push(name); @@ -228,13 +228,13 @@ QUnit.test('Calling _super in call outside the immediate function of a CP getter }); } - var MyClass = EmberObject.extend({ + let MyClass = EmberObject.extend({ foo: computed(function() { return 'FOO'; }) }); - var SubClass = MyClass.extend({ + let SubClass = MyClass.extend({ foo: macro(function() { return this._super(); }) @@ -250,13 +250,13 @@ QUnit.test('Calling _super in apply outside the immediate function of a CP gette }); } - var MyClass = EmberObject.extend({ + let MyClass = EmberObject.extend({ foo: computed(function() { return 'FOO'; }) }); - var SubClass = MyClass.extend({ + let SubClass = MyClass.extend({ foo: macro(function() { return this._super(); }) diff --git a/packages/ember-runtime/tests/system/object/create_test.js b/packages/ember-runtime/tests/system/object/create_test.js index beee399bfc9..79dc48dc4c9 100644 --- a/packages/ember-runtime/tests/system/object/create_test.js +++ b/packages/ember-runtime/tests/system/object/create_test.js @@ -7,38 +7,38 @@ import EmberObject from 'ember-runtime/system/object'; QUnit.module('EmberObject.create', {}); QUnit.test('simple properties are set', function() { - var o = EmberObject.create({ ohai: 'there' }); + let o = EmberObject.create({ ohai: 'there' }); equal(o.get('ohai'), 'there'); }); QUnit.test('calls computed property setters', function() { - var MyClass = EmberObject.extend({ + let MyClass = EmberObject.extend({ foo: computed({ - get: function() { + get() { return 'this is not the value you\'re looking for'; }, - set: function(key, value) { + set(key, value) { return value; } }) }); - var o = MyClass.create({ foo: 'bar' }); + let o = MyClass.create({ foo: 'bar' }); equal(o.get('foo'), 'bar'); }); if (isEnabled('mandatory-setter')) { QUnit.test('sets up mandatory setters for watched simple properties', function() { - var MyClass = EmberObject.extend({ + let MyClass = EmberObject.extend({ foo: null, bar: null, fooDidChange: observer('foo', function() {}) }); - var o = MyClass.create({ foo: 'bar', bar: 'baz' }); + let o = MyClass.create({ foo: 'bar', bar: 'baz' }); equal(o.get('foo'), 'bar'); - var descriptor = Object.getOwnPropertyDescriptor(o, 'foo'); + let descriptor = Object.getOwnPropertyDescriptor(o, 'foo'); ok(descriptor.set, 'Mandatory setter was setup'); descriptor = Object.getOwnPropertyDescriptor(o, 'bar'); @@ -63,9 +63,9 @@ QUnit.test('allows bindings to be defined', function() { }); QUnit.test('calls setUnknownProperty if defined', function() { - var setUnknownPropertyCalled = false; + let setUnknownPropertyCalled = false; - var MyClass = EmberObject.extend({ + let MyClass = EmberObject.extend({ setUnknownProperty(key, value) { setUnknownPropertyCalled = true; } @@ -94,7 +94,7 @@ QUnit.test('throws if you try to call _super in a method', function() { }); QUnit.test('throws if you try to \'mixin\' a definition', function() { - var myMixin = Mixin.create({ + let myMixin = Mixin.create({ adder(arg1, arg2) { return arg1 + arg2; } @@ -107,7 +107,7 @@ QUnit.test('throws if you try to \'mixin\' a definition', function() { // This test is for IE8. QUnit.test('property name is the same as own prototype property', function() { - var MyClass = EmberObject.extend({ + let MyClass = EmberObject.extend({ toString() { return 'MyClass'; } }); @@ -115,27 +115,25 @@ QUnit.test('property name is the same as own prototype property', function() { }); QUnit.test('inherits properties from passed in EmberObject', function() { - var baseObj = EmberObject.create({ foo: 'bar' }); - var secondaryObj = EmberObject.create(baseObj); + let baseObj = EmberObject.create({ foo: 'bar' }); + let secondaryObj = EmberObject.create(baseObj); equal(secondaryObj.foo, baseObj.foo, 'Em.O.create inherits properties from EmberObject parameter'); }); QUnit.test('throws if you try to pass anything a string as a parameter', function() { - var expected = 'EmberObject.create only accepts an objects.'; + let expected = 'EmberObject.create only accepts an objects.'; - throws(function() { - EmberObject.create('some-string'); - }, expected); + throws(() => EmberObject.create('some-string'), expected); }); QUnit.test('EmberObject.create can take undefined as a parameter', function() { - var o = EmberObject.create(undefined); + let o = EmberObject.create(undefined); deepEqual(EmberObject.create(), o); }); QUnit.test('EmberObject.create can take null as a parameter', function() { - var o = EmberObject.create(null); + let o = EmberObject.create(null); deepEqual(EmberObject.create(), o); }); diff --git a/packages/ember-runtime/tests/system/object/destroy_test.js b/packages/ember-runtime/tests/system/object/destroy_test.js index 08c86167b15..21d7f68e91e 100644 --- a/packages/ember-runtime/tests/system/object/destroy_test.js +++ b/packages/ember-runtime/tests/system/object/destroy_test.js @@ -13,10 +13,10 @@ import { peekMeta } from 'ember-metal/meta'; QUnit.module('ember-runtime/system/object/destroy_test'); testBoth('should schedule objects to be destroyed at the end of the run loop', function(get, set) { - var obj = EmberObject.create(); - var meta; + let obj = EmberObject.create(); + let meta; - run(function() { + run(() => { obj.destroy(); meta = peekMeta(obj); ok(meta, 'meta is not destroyed immediately'); @@ -34,25 +34,21 @@ if (isEnabled('mandatory-setter')) { // a destroyed object removes meta but leaves the accessor // that looks it up QUnit.test('should raise an exception when modifying watched properties on a destroyed object', function() { - var obj = EmberObject.extend({ + let obj = EmberObject.extend({ fooDidChange: observer('foo', function() { }) }).create({ foo: 'bar' }); - run(function() { - obj.destroy(); - }); + run(() => obj.destroy()); - throws(function() { - set(obj, 'foo', 'baz'); - }, Error, 'raises an exception'); + throws(() => set(obj, 'foo', 'baz'), Error, 'raises an exception'); }); } QUnit.test('observers should not fire after an object has been destroyed', function() { - var count = 0; - var obj = EmberObject.extend({ + let count = 0; + let obj = EmberObject.extend({ fooDidChange: observer('foo', function() { count++; }) @@ -62,7 +58,7 @@ QUnit.test('observers should not fire after an object has been destroyed', funct equal(count, 1, 'observer was fired once'); - run(function() { + run(() => { beginPropertyChanges(); obj.set('foo', 'quux'); obj.destroy(); @@ -73,12 +69,12 @@ QUnit.test('observers should not fire after an object has been destroyed', funct }); QUnit.test('destroyed objects should not see each others changes during teardown but a long lived object should', function () { - var shouldChange = 0; - var shouldNotChange = 0; + let shouldChange = 0; + let shouldNotChange = 0; - var objs = {}; + let objs = {}; - var A = EmberObject.extend({ + let A = EmberObject.extend({ objs: objs, isAlive: true, willDestroy() { @@ -92,7 +88,7 @@ QUnit.test('destroyed objects should not see each others changes during teardown }) }); - var B = EmberObject.extend({ + let B = EmberObject.extend({ objs: objs, isAlive: true, willDestroy() { @@ -106,7 +102,7 @@ QUnit.test('destroyed objects should not see each others changes during teardown }) }); - var C = EmberObject.extend({ + let C = EmberObject.extend({ objs: objs, isAlive: true, willDestroy() { @@ -120,7 +116,7 @@ QUnit.test('destroyed objects should not see each others changes during teardown }) }); - var LongLivedObject = EmberObject.extend({ + let LongLivedObject = EmberObject.extend({ objs: objs, isAliveDidChange: observer('objs.a.isAlive', function () { shouldChange++; @@ -135,9 +131,9 @@ QUnit.test('destroyed objects should not see each others changes during teardown new LongLivedObject(); - run(function () { - var keys = Object.keys(objs); - for (var i = 0; i < keys.length; i++) { + run(() => { + let keys = Object.keys(objs); + for (let i = 0; i < keys.length; i++) { objs[keys[i]].destroy(); } }); @@ -147,19 +143,19 @@ QUnit.test('destroyed objects should not see each others changes during teardown }); QUnit.test('bindings should be synced when are updated in the willDestroy hook', function() { - var bar = EmberObject.create({ + let bar = EmberObject.create({ value: false, willDestroy() { this.set('value', true); } }); - var foo = EmberObject.create({ + let foo = EmberObject.create({ value: null, bar: bar }); - run(function() { + run(() => { let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + ' using an `alias` computed property instead.'; @@ -170,9 +166,7 @@ QUnit.test('bindings should be synced when are updated in the willDestroy hook', ok(bar.get('value') === false, 'the initial value has been bound'); - run(function() { - bar.destroy(); - }); + run(() => bar.destroy()); ok(foo.get('value'), 'foo is synced when the binding is updated in the willDestroy hook'); }); diff --git a/packages/ember-runtime/tests/system/object/detectInstance_test.js b/packages/ember-runtime/tests/system/object/detectInstance_test.js index d6e43e7b079..0ab64e83cfd 100644 --- a/packages/ember-runtime/tests/system/object/detectInstance_test.js +++ b/packages/ember-runtime/tests/system/object/detectInstance_test.js @@ -3,14 +3,14 @@ import EmberObject from 'ember-runtime/system/object'; QUnit.module('system/object/detectInstance'); QUnit.test('detectInstance detects instances correctly', function() { - var A = EmberObject.extend(); - var B = A.extend(); - var C = A.extend(); + let A = EmberObject.extend(); + let B = A.extend(); + let C = A.extend(); - var o = EmberObject.create(); - var a = A.create(); - var b = B.create(); - var c = C.create(); + let o = EmberObject.create(); + let a = A.create(); + let b = B.create(); + let c = C.create(); ok(EmberObject.detectInstance(o), 'o is an instance of EmberObject'); ok(EmberObject.detectInstance(a), 'a is an instance of EmberObject'); diff --git a/packages/ember-runtime/tests/system/object/detect_test.js b/packages/ember-runtime/tests/system/object/detect_test.js index 51df823f38e..05c69d6ded0 100644 --- a/packages/ember-runtime/tests/system/object/detect_test.js +++ b/packages/ember-runtime/tests/system/object/detect_test.js @@ -3,9 +3,9 @@ import EmberObject from 'ember-runtime/system/object'; QUnit.module('system/object/detect'); QUnit.test('detect detects classes correctly', function() { - var A = EmberObject.extend(); - var B = A.extend(); - var C = A.extend(); + let A = EmberObject.extend(); + let B = A.extend(); + let C = A.extend(); ok(EmberObject.detect(EmberObject), 'EmberObject is an EmberObject class'); ok(EmberObject.detect(A), 'A is an EmberObject class'); diff --git a/packages/ember-runtime/tests/system/object/events_test.js b/packages/ember-runtime/tests/system/object/events_test.js index ff9884c7ca9..31e697c8f53 100644 --- a/packages/ember-runtime/tests/system/object/events_test.js +++ b/packages/ember-runtime/tests/system/object/events_test.js @@ -4,10 +4,10 @@ import Evented from 'ember-runtime/mixins/evented'; QUnit.module('Object events'); QUnit.test('a listener can be added to an object', function() { - var count = 0; - var F = function() { count++; }; + let count = 0; + let F = function() { count++; }; - var obj = EmberObject.extend(Evented).create(); + let obj = EmberObject.extend(Evented).create(); obj.on('event!', F); obj.trigger('event!'); @@ -20,10 +20,10 @@ QUnit.test('a listener can be added to an object', function() { }); QUnit.test('a listener can be added and removed automatically the first time it is triggered', function() { - var count = 0; - var F = function() { count++; }; + let count = 0; + let F = function() { count++; }; - var obj = EmberObject.extend(Evented).create(); + let obj = EmberObject.extend(Evented).create(); obj.one('event!', F); obj.trigger('event!'); @@ -36,9 +36,9 @@ QUnit.test('a listener can be added and removed automatically the first time it }); QUnit.test('triggering an event can have arguments', function() { - var self, args; + let self, args; - var obj = EmberObject.extend(Evented).create(); + let obj = EmberObject.extend(Evented).create(); obj.on('event!', function() { args = [].slice.call(arguments); @@ -52,10 +52,10 @@ QUnit.test('triggering an event can have arguments', function() { }); QUnit.test('a listener can be added and removed automatically and have arguments', function() { - var self, args; - var count = 0; + let self, args; + let count = 0; - var obj = EmberObject.extend(Evented).create(); + let obj = EmberObject.extend(Evented).create(); obj.one('event!', function() { args = [].slice.call(arguments); @@ -77,10 +77,10 @@ QUnit.test('a listener can be added and removed automatically and have arguments }); QUnit.test('binding an event can specify a different target', function() { - var self, args; + let self, args; - var obj = EmberObject.extend(Evented).create(); - var target = {}; + let obj = EmberObject.extend(Evented).create(); + let target = {}; obj.on('event!', target, function() { args = [].slice.call(arguments); @@ -94,11 +94,11 @@ QUnit.test('binding an event can specify a different target', function() { }); QUnit.test('a listener registered with one can take method as string and can be added with different target', function() { - var count = 0; - var target = {}; + let count = 0; + let target = {}; target.fn = function() { count++; }; - var obj = EmberObject.extend(Evented).create(); + let obj = EmberObject.extend(Evented).create(); obj.one('event!', target, 'fn'); obj.trigger('event!'); @@ -111,10 +111,10 @@ QUnit.test('a listener registered with one can take method as string and can be }); QUnit.test('a listener registered with one can be removed with off', function() { - var obj = EmberObject.extend(Evented, { + let obj = EmberObject.extend(Evented, { F() {} }).create(); - var F = function() {}; + let F = function() {}; obj.one('event!', F); obj.one('event!', obj, 'F'); @@ -128,10 +128,10 @@ QUnit.test('a listener registered with one can be removed with off', function() }); QUnit.test('adding and removing listeners should be chainable', function() { - var obj = EmberObject.extend(Evented).create(); - var F = function() {}; + let obj = EmberObject.extend(Evented).create(); + let F = function() {}; - var ret = obj.on('event!', F); + let ret = obj.on('event!', F); equal(ret, obj, '#on returns self'); ret = obj.off('event!', F); diff --git a/packages/ember-runtime/tests/system/object/extend_test.js b/packages/ember-runtime/tests/system/object/extend_test.js index 209ec29aad5..054baa211aa 100644 --- a/packages/ember-runtime/tests/system/object/extend_test.js +++ b/packages/ember-runtime/tests/system/object/extend_test.js @@ -4,22 +4,22 @@ import EmberObject from 'ember-runtime/system/object'; QUnit.module('EmberObject.extend'); QUnit.test('Basic extend', function() { - var SomeClass = EmberObject.extend({ foo: 'BAR' }); + let SomeClass = EmberObject.extend({ foo: 'BAR' }); ok(SomeClass.isClass, 'A class has isClass of true'); - var obj = new SomeClass(); + let obj = new SomeClass(); equal(obj.foo, 'BAR'); }); QUnit.test('Sub-subclass', function() { - var SomeClass = EmberObject.extend({ foo: 'BAR' }); - var AnotherClass = SomeClass.extend({ bar: 'FOO' }); - var obj = new AnotherClass(); + let SomeClass = EmberObject.extend({ foo: 'BAR' }); + let AnotherClass = SomeClass.extend({ bar: 'FOO' }); + let obj = new AnotherClass(); equal(obj.foo, 'BAR'); equal(obj.bar, 'FOO'); }); QUnit.test('Overriding a method several layers deep', function() { - var SomeClass = EmberObject.extend({ + let SomeClass = EmberObject.extend({ fooCnt: 0, foo() { this.fooCnt++; }, @@ -27,7 +27,7 @@ QUnit.test('Overriding a method several layers deep', function() { bar() { this.barCnt++; } }); - var AnotherClass = SomeClass.extend({ + let AnotherClass = SomeClass.extend({ barCnt: 0, bar() { this.barCnt++; @@ -35,7 +35,7 @@ QUnit.test('Overriding a method several layers deep', function() { } }); - var FinalClass = AnotherClass.extend({ + let FinalClass = AnotherClass.extend({ fooCnt: 0, foo() { this.fooCnt++; @@ -43,7 +43,7 @@ QUnit.test('Overriding a method several layers deep', function() { } }); - var obj = new FinalClass(); + let obj = new FinalClass(); obj.foo(); obj.bar(); equal(obj.fooCnt, 2, 'should invoke both'); @@ -64,30 +64,30 @@ QUnit.test('Overriding a method several layers deep', function() { }); QUnit.test('With concatenatedProperties', function() { - var SomeClass = EmberObject.extend({ things: 'foo', concatenatedProperties: ['things'] }); - var AnotherClass = SomeClass.extend({ things: 'bar' }); - var YetAnotherClass = SomeClass.extend({ things: 'baz' }); - var some = new SomeClass(); - var another = new AnotherClass(); - var yetAnother = new YetAnotherClass(); + let SomeClass = EmberObject.extend({ things: 'foo', concatenatedProperties: ['things'] }); + let AnotherClass = SomeClass.extend({ things: 'bar' }); + let YetAnotherClass = SomeClass.extend({ things: 'baz' }); + let some = new SomeClass(); + let another = new AnotherClass(); + let yetAnother = new YetAnotherClass(); deepEqual(some.get('things'), ['foo'], 'base class should have just its value'); deepEqual(another.get('things'), ['foo', 'bar'], 'subclass should have base class\' and its own'); deepEqual(yetAnother.get('things'), ['foo', 'baz'], 'subclass should have base class\' and its own'); }); QUnit.test('With concatenatedProperties class properties', function() { - var SomeClass = EmberObject.extend(); + let SomeClass = EmberObject.extend(); SomeClass.reopenClass({ concatenatedProperties: ['things'], things: 'foo' }); - var AnotherClass = SomeClass.extend(); + let AnotherClass = SomeClass.extend(); AnotherClass.reopenClass({ things: 'bar' }); - var YetAnotherClass = SomeClass.extend(); + let YetAnotherClass = SomeClass.extend(); YetAnotherClass.reopenClass({ things: 'baz' }); - var some = new SomeClass(); - var another = new AnotherClass(); - var yetAnother = new YetAnotherClass(); + let some = new SomeClass(); + let another = new AnotherClass(); + let yetAnother = new YetAnotherClass(); deepEqual(get(some.constructor, 'things'), ['foo'], 'base class should have just its value'); deepEqual(get(another.constructor, 'things'), ['foo', 'bar'], 'subclass should have base class\' and its own'); deepEqual(get(yetAnother.constructor, 'things'), ['foo', 'baz'], 'subclass should have base class\' and its own'); diff --git a/packages/ember-runtime/tests/system/object/observer_test.js b/packages/ember-runtime/tests/system/object/observer_test.js index 90cdb6ab7a2..10103f7c80b 100644 --- a/packages/ember-runtime/tests/system/object/observer_test.js +++ b/packages/ember-runtime/tests/system/object/observer_test.js @@ -6,17 +6,15 @@ import EmberObject from 'ember-runtime/system/object'; QUnit.module('EmberObject observer'); testBoth('observer on class', function(get, set) { - var MyClass = EmberObject.extend({ - + let MyClass = EmberObject.extend({ count: 0, foo: observer('bar', function() { set(this, 'count', get(this, 'count') + 1); }) - }); - var obj = new MyClass(); + let obj = new MyClass(); equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); set(obj, 'bar', 'BAZ'); @@ -24,23 +22,21 @@ testBoth('observer on class', function(get, set) { }); testBoth('observer on subclass', function(get, set) { - var MyClass = EmberObject.extend({ - + let MyClass = EmberObject.extend({ count: 0, foo: observer('bar', function() { set(this, 'count', get(this, 'count') + 1); }) - }); - var Subclass = MyClass.extend({ + let Subclass = MyClass.extend({ foo: observer('baz', function() { set(this, 'count', get(this, 'count') + 1); }) }); - var obj = new Subclass(); + let obj = new Subclass(); equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); set(obj, 'bar', 'BAZ'); @@ -51,7 +47,7 @@ testBoth('observer on subclass', function(get, set) { }); testBoth('observer on instance', function(get, set) { - var obj = EmberObject.extend({ + let obj = EmberObject.extend({ foo: observer('bar', function() { set(this, 'count', get(this, 'count') + 1); }) @@ -66,7 +62,7 @@ testBoth('observer on instance', function(get, set) { }); testBoth('observer on instance overriding class', function(get, set) { - var MyClass = EmberObject.extend({ + let MyClass = EmberObject.extend({ count: 0, foo: observer('bar', function() { @@ -74,7 +70,7 @@ testBoth('observer on instance overriding class', function(get, set) { }) }); - var obj = MyClass.extend({ + let obj = MyClass.extend({ foo: observer('baz', function() { // <-- change property we observe set(this, 'count', get(this, 'count') + 1); }) @@ -90,7 +86,7 @@ testBoth('observer on instance overriding class', function(get, set) { }); testBoth('observer should not fire after being destroyed', function(get, set) { - var obj = EmberObject.extend({ + let obj = EmberObject.extend({ count: 0, foo: observer('bar', function() { set(this, 'count', get(this, 'count') + 1); @@ -99,7 +95,7 @@ testBoth('observer should not fire after being destroyed', function(get, set) { equal(get(obj, 'count'), 0, 'precond - should not invoke observer immediately'); - run(function() { obj.destroy(); }); + run(() => obj.destroy()); expectAssertion(function() { set(obj, 'bar', 'BAZ'); @@ -113,7 +109,7 @@ testBoth('observer should not fire after being destroyed', function(get, set) { testBoth('chain observer on class', function(get, set) { - var MyClass = EmberObject.extend({ + let MyClass = EmberObject.extend({ count: 0, foo: observer('bar.baz', function() { @@ -121,11 +117,11 @@ testBoth('chain observer on class', function(get, set) { }) }); - var obj1 = MyClass.create({ + let obj1 = MyClass.create({ bar: { baz: 'biff' } }); - var obj2 = MyClass.create({ + let obj2 = MyClass.create({ bar: { baz: 'biff2' } }); @@ -143,7 +139,7 @@ testBoth('chain observer on class', function(get, set) { testBoth('chain observer on class', function(get, set) { - var MyClass = EmberObject.extend({ + let MyClass = EmberObject.extend({ count: 0, foo: observer('bar.baz', function() { @@ -151,11 +147,11 @@ testBoth('chain observer on class', function(get, set) { }) }); - var obj1 = MyClass.extend().create({ + let obj1 = MyClass.extend().create({ bar: { baz: 'biff' } }); - var obj2 = MyClass.extend({ + let obj2 = MyClass.extend({ foo: observer('bar2.baz', function() { set(this, 'count', get(this, 'count') + 1); }) @@ -181,16 +177,16 @@ testBoth('chain observer on class', function(get, set) { }); testBoth('chain observer on class that has a reference to an uninitialized object will finish chains that reference it', function(get, set) { - var changed = false; + let changed = false; - var ChildClass = EmberObject.extend({ + let ChildClass = EmberObject.extend({ parent: null, parentOneTwoDidChange: observer('parent.one.two', function() { changed = true; }) }); - var ParentClass = EmberObject.extend({ + let ParentClass = EmberObject.extend({ one: { two: 'old' }, @@ -201,7 +197,7 @@ testBoth('chain observer on class that has a reference to an uninitialized objec } }); - var parent = new ParentClass(); + let parent = new ParentClass(); equal(changed, false, 'precond'); diff --git a/packages/ember-runtime/tests/system/object/reopenClass_test.js b/packages/ember-runtime/tests/system/object/reopenClass_test.js index 5d309fa9cd9..8e24e33ac11 100644 --- a/packages/ember-runtime/tests/system/object/reopenClass_test.js +++ b/packages/ember-runtime/tests/system/object/reopenClass_test.js @@ -4,7 +4,7 @@ import EmberObject from 'ember-runtime/system/object'; QUnit.module('system/object/reopenClass'); QUnit.test('adds new properties to subclass', function() { - var Subclass = EmberObject.extend(); + let Subclass = EmberObject.extend(); Subclass.reopenClass({ foo() { return 'FOO'; }, bar: 'BAR' @@ -15,13 +15,13 @@ QUnit.test('adds new properties to subclass', function() { }); QUnit.test('class properties inherited by subclasses', function() { - var Subclass = EmberObject.extend(); + let Subclass = EmberObject.extend(); Subclass.reopenClass({ foo() { return 'FOO'; }, bar: 'BAR' }); - var SubSub = Subclass.extend(); + let SubSub = Subclass.extend(); equal(SubSub.foo(), 'FOO', 'Adds method'); equal(get(SubSub, 'bar'), 'BAR', 'Adds property'); diff --git a/packages/ember-runtime/tests/system/object/reopen_test.js b/packages/ember-runtime/tests/system/object/reopen_test.js index 498c7f9c35b..92784c5b7fc 100644 --- a/packages/ember-runtime/tests/system/object/reopen_test.js +++ b/packages/ember-runtime/tests/system/object/reopen_test.js @@ -4,7 +4,7 @@ import EmberObject from 'ember-runtime/system/object'; QUnit.module('system/core_object/reopen'); QUnit.test('adds new properties to subclass instance', function() { - var Subclass = EmberObject.extend(); + let Subclass = EmberObject.extend(); Subclass.reopen({ foo() { return 'FOO'; }, bar: 'BAR' @@ -15,21 +15,20 @@ QUnit.test('adds new properties to subclass instance', function() { }); QUnit.test('reopened properties inherited by subclasses', function() { - var Subclass = EmberObject.extend(); - var SubSub = Subclass.extend(); + let Subclass = EmberObject.extend(); + let SubSub = Subclass.extend(); Subclass.reopen({ foo() { return 'FOO'; }, bar: 'BAR' }); - equal(new SubSub().foo(), 'FOO', 'Adds method'); equal(get(new SubSub(), 'bar'), 'BAR', 'Adds property'); }); QUnit.test('allows reopening already instantiated classes', function() { - var Subclass = EmberObject.extend(); + let Subclass = EmberObject.extend(); Subclass.create(); diff --git a/packages/ember-runtime/tests/system/object/strict-mode-test.js b/packages/ember-runtime/tests/system/object/strict-mode-test.js index 2eb55e90b6f..6378192ae7c 100644 --- a/packages/ember-runtime/tests/system/object/strict-mode-test.js +++ b/packages/ember-runtime/tests/system/object/strict-mode-test.js @@ -3,25 +3,25 @@ import EmberObject from 'ember-runtime/system/object'; QUnit.module('strict mode tests'); QUnit.test('__superWrapper does not throw errors in strict mode', function() { - var Foo = EmberObject.extend({ + let Foo = EmberObject.extend({ blah() { return 'foo'; } }); - var Bar = Foo.extend({ + let Bar = Foo.extend({ blah() { return 'bar'; }, callBlah() { - var blah = this.blah; + let blah = this.blah; return blah(); } }); - var bar = Bar.create(); + let bar = Bar.create(); equal(bar.callBlah(), 'bar', 'can call local function without call/apply'); }); diff --git a/packages/ember-runtime/tests/system/object/subclasses_test.js b/packages/ember-runtime/tests/system/object/subclasses_test.js index 68a86019eaa..233098862d7 100644 --- a/packages/ember-runtime/tests/system/object/subclasses_test.js +++ b/packages/ember-runtime/tests/system/object/subclasses_test.js @@ -5,8 +5,8 @@ import EmberObject from 'ember-runtime/system/object'; QUnit.module('system/object/subclasses'); QUnit.test('chains should copy forward to subclasses when prototype created', function () { - var ObjectWithChains, objWithChains, SubWithChains, SubSub, subSub; - run(function () { + let ObjectWithChains, objWithChains, SubWithChains, SubSub, subSub; + run(() => { ObjectWithChains = EmberObject.extend({ obj: { a: 'a', @@ -40,8 +40,6 @@ QUnit.test('chains should copy forward to subclasses when prototype created', fu }, deprecationMessage); }); equal(subSub.get('greeting'), 'hi world'); - run(function () { - objWithChains.set('obj.hi', 'hello'); - }); + run(() => objWithChains.set('obj.hi', 'hello')); equal(subSub.get('greeting'), 'hello world'); }); diff --git a/packages/ember-runtime/tests/system/object/toString_test.js b/packages/ember-runtime/tests/system/object/toString_test.js index 00b47ee4d52..4da6c224023 100644 --- a/packages/ember-runtime/tests/system/object/toString_test.js +++ b/packages/ember-runtime/tests/system/object/toString_test.js @@ -16,7 +16,7 @@ QUnit.module('system/object/toString', { }); QUnit.test('toString() returns the same value if called twice', function() { - var Foo = Namespace.create(); + let Foo = Namespace.create(); Foo.toString = function() { return 'Foo'; }; Foo.Bar = EmberObject.extend(); @@ -24,7 +24,7 @@ QUnit.test('toString() returns the same value if called twice', function() { equal(Foo.Bar.toString(), 'Foo.Bar'); equal(Foo.Bar.toString(), 'Foo.Bar'); - var obj = Foo.Bar.create(); + let obj = Foo.Bar.create(); equal(obj.toString(), 'hello {{yield}}
')); @@ -33,7 +33,7 @@ function prepare() { } function cleanup() { - run(function() { + run(() => { try { if (App) { App.destroy(); @@ -47,10 +47,10 @@ function cleanup() { } function cleanupHelpers() { - var included; + let included; keys(helpers). - forEach((name) => { + forEach(name => { if (isEnabled('ember-runtime-enumerable-includes')) { included = originalHelpers.includes(name); } else { @@ -69,7 +69,7 @@ QUnit.module('Application Lifecycle - Component Registration', { }); function boot(callback, startURL='/') { - run(function() { + run(() => { App = Application.create({ name: 'App', rootElement: '#qunit-fixture' @@ -86,12 +86,10 @@ function boot(callback, startURL='/') { if (callback) { callback(); } }); - var router = appInstance.lookup('router:main'); + let router = appInstance.lookup('router:main'); run(App, 'advanceReadiness'); - run(function() { - router.handleURL(startURL); - }); + run(() => router.handleURL(startURL)); } QUnit.test('The helper becomes the body of the component', function() { @@ -100,7 +98,7 @@ QUnit.test('The helper becomes the body of the component', function() { }); QUnit.test('If a component is registered, it is used', function() { - boot(function() { + boot(() => { appInstance.register('component:expand-it', Component.extend({ classNames: 'testing123' })); @@ -112,7 +110,7 @@ QUnit.test('If a component is registered, it is used', function() { QUnit.test('Late-registered components can be rendered with custom `layout` property', function() { setTemplate('application', compile('LOADING!
' )); - var rootSetup = 0; - var rootRender = 0; - var rootModel = 0; - var rootSerialize = 0; + let rootSetup = 0; + let rootRender = 0; + let rootModel = 0; + let rootSerialize = 0; bootApplication(); @@ -1016,11 +1002,9 @@ QUnit.asyncTest('Nested callbacks are not exited when moving to siblings', funct router = container.lookup('router:main'); - run(function() { - var menuItem = App.MenuItem.create({ id: 1 }); - run.later(function() { - RSVP.resolve(menuItem); - }, 1); + run(() => { + let menuItem = App.MenuItem.create({ id: 1 }); + run.later(() => RSVP.resolve(menuItem), 1); router.transitionTo('special', menuItem).then(function(result) { equal(rootSetup, 1, 'The root setup was not triggered again'); @@ -1043,8 +1027,8 @@ asyncTest('Events are triggered on the controller if a matching action name is i this.route('home', { path: '/' }); }); - var model = { name: 'Tom Dale' }; - var stateIsNotCalled = true; + let model = { name: 'Tom Dale' }; + let stateIsNotCalled = true; App.HomeRoute = Route.extend({ model() { @@ -1062,7 +1046,7 @@ asyncTest('Events are triggered on the controller if a matching action name is i '{{name}}' )); - var controller = Controller.extend({ + let controller = Controller.extend({ actions: { showStuff(context) { ok(stateIsNotCalled, 'an event on the state is not triggered'); @@ -1076,9 +1060,9 @@ asyncTest('Events are triggered on the controller if a matching action name is i bootApplication(); - var actionId = jQuery('#qunit-fixture a').data('ember-action'); - var [ action ] = ActionManager.registeredActions[actionId]; - var event = new jQuery.Event('click'); + let actionId = jQuery('#qunit-fixture a').data('ember-action'); + let [ action ] = ActionManager.registeredActions[actionId]; + let event = new jQuery.Event('click'); action.handler(event); }); @@ -1087,7 +1071,7 @@ asyncTest('Events are triggered on the current state when defined in `actions` o this.route('home', { path: '/' }); }); - var model = { name: 'Tom Dale' }; + let model = { name: 'Tom Dale' }; App.HomeRoute = Route.extend({ model() { @@ -1110,9 +1094,9 @@ asyncTest('Events are triggered on the current state when defined in `actions` o bootApplication(); - var actionId = jQuery('#qunit-fixture a').data('ember-action'); - var [ action ] = ActionManager.registeredActions[actionId]; - var event = new jQuery.Event('click'); + let actionId = jQuery('#qunit-fixture a').data('ember-action'); + let [ action ] = ActionManager.registeredActions[actionId]; + let event = new jQuery.Event('click'); action.handler(event); }); @@ -1123,7 +1107,7 @@ asyncTest('Events defined in `actions` object are triggered on the current state }); }); - var model = { name: 'Tom Dale' }; + let model = { name: 'Tom Dale' }; App.RootRoute = Route.extend({ actions: { @@ -1148,9 +1132,9 @@ asyncTest('Events defined in `actions` object are triggered on the current state bootApplication(); - var actionId = jQuery('#qunit-fixture a').data('ember-action'); - var [ action ] = ActionManager.registeredActions[actionId]; - var event = new jQuery.Event('click'); + let actionId = jQuery('#qunit-fixture a').data('ember-action'); + let [ action ] = ActionManager.registeredActions[actionId]; + let event = new jQuery.Event('click'); action.handler(event); }); @@ -1197,8 +1181,8 @@ asyncTest('Actions are not triggered on the controller if a matching action name this.route('home', { path: '/' }); }); - var model = { name: 'Tom Dale' }; - var stateIsNotCalled = true; + let model = { name: 'Tom Dale' }; + let stateIsNotCalled = true; App.HomeRoute = Route.extend({ model() { @@ -1218,7 +1202,7 @@ asyncTest('Actions are not triggered on the controller if a matching action name '{{name}}' )); - var controller = Controller.extend({ + let controller = Controller.extend({ showStuff(context) { stateIsNotCalled = false; ok(stateIsNotCalled, 'an event on the state is not triggered'); @@ -1229,9 +1213,9 @@ asyncTest('Actions are not triggered on the controller if a matching action name bootApplication(); - var actionId = jQuery('#qunit-fixture a').data('ember-action'); - var [ action ] = ActionManager.registeredActions[actionId]; - var event = new jQuery.Event('click'); + let actionId = jQuery('#qunit-fixture a').data('ember-action'); + let [ action ] = ActionManager.registeredActions[actionId]; + let event = new jQuery.Event('click'); action.handler(event); }); @@ -1242,8 +1226,8 @@ asyncTest('actions can be triggered with multiple arguments', function() { }); }); - var model1 = { name: 'Tilde' }; - var model2 = { name: 'Tom Dale' }; + let model1 = { name: 'Tilde' }; + let model2 = { name: 'Tom Dale' }; App.RootRoute = Route.extend({ actions: { @@ -1268,9 +1252,9 @@ asyncTest('actions can be triggered with multiple arguments', function() { bootApplication(); - var actionId = jQuery('#qunit-fixture a').data('ember-action'); - var [ action ] = ActionManager.registeredActions[actionId]; - var event = new jQuery.Event('click'); + let actionId = jQuery('#qunit-fixture a').data('ember-action'); + let [ action ] = ActionManager.registeredActions[actionId]; + let event = new jQuery.Event('click'); action.handler(event); }); @@ -1283,7 +1267,7 @@ QUnit.test('transitioning multiple times in a single run loop only sets the URL bootApplication(); - var urlSetCount = 0; + let urlSetCount = 0; router.get('location').setURL = function(path) { urlSetCount++; @@ -1312,20 +1296,18 @@ QUnit.test('navigating away triggers a url property change', function() { bootApplication(); - run(function() { + run(() => { addObserver(router, 'url', function() { ok(true, 'url change event was fired'); }); }); - ['foo', 'bar', '/foo'].forEach(function(destination) { - run(router, 'transitionTo', destination); - }); + ['foo', 'bar', '/foo'].forEach(destination => run(router, 'transitionTo', destination)); }); QUnit.test('using replaceWith calls location.replaceURL if available', function() { - var setCount = 0; - var replaceCount = 0; + let setCount = 0; + let replaceCount = 0; Router.reopen({ location: NoneLocation.create({ @@ -1351,9 +1333,7 @@ QUnit.test('using replaceWith calls location.replaceURL if available', function( equal(setCount, 0); equal(replaceCount, 0); - run(function() { - router.replaceWith('foo'); - }); + run(() => router.replaceWith('foo')); equal(setCount, 0, 'should not call setURL'); equal(replaceCount, 1, 'should call replaceURL once'); @@ -1361,7 +1341,7 @@ QUnit.test('using replaceWith calls location.replaceURL if available', function( }); QUnit.test('using replaceWith calls setURL if location.replaceURL is not defined', function() { - var setCount = 0; + let setCount = 0; Router.reopen({ location: NoneLocation.create({ @@ -1381,9 +1361,7 @@ QUnit.test('using replaceWith calls setURL if location.replaceURL is not defined equal(setCount, 0); - run(function() { - router.replaceWith('foo'); - }); + run(() => router.replaceWith('foo')); equal(setCount, 1, 'should call setURL once'); equal(router.get('location').getURL(), '/foo'); @@ -1402,20 +1380,20 @@ QUnit.test('Route inherits model from parent route', function() { }); }); - var post1 = {}; - var post2 = {}; - var post3 = {}; - var currentPost; - var share1 = {}; - var share2 = {}; - var share3 = {}; + let post1 = {}; + let post2 = {}; + let post3 = {}; + let currentPost; + let share1 = {}; + let share2 = {}; + let share3 = {}; - var posts = { + let posts = { 1: post1, 2: post2, 3: post3 }; - var shares = { + let shares = { 1: share1, 2: share2, 3: share3 @@ -1429,7 +1407,7 @@ QUnit.test('Route inherits model from parent route', function() { App.ThePostCommentsRoute = Route.extend({ afterModel(post, transition) { - var parent_model = this.modelFor('thePost'); + let parent_model = this.modelFor('thePost'); equal(post, parent_model); } @@ -1443,7 +1421,7 @@ QUnit.test('Route inherits model from parent route', function() { App.SharesShareRoute = Route.extend({ afterModel(share, transition) { - var parent_model = this.modelFor('shares'); + let parent_model = this.modelFor('shares'); equal(share, parent_model); } @@ -1474,12 +1452,12 @@ QUnit.test('Routes with { resetNamespace: true } inherits model from parent rout }); }); - var post1 = {}; - var post2 = {}; - var post3 = {}; - var currentPost; + let post1 = {}; + let post2 = {}; + let post3 = {}; + let currentPost; - var posts = { + let posts = { 1: post1, 2: post2, 3: post3 @@ -1493,7 +1471,7 @@ QUnit.test('Routes with { resetNamespace: true } inherits model from parent rout App.CommentsRoute = Route.extend({ afterModel(post, transition) { - var parent_model = this.modelFor('thePost'); + let parent_model = this.modelFor('thePost'); equal(post, parent_model); } @@ -1520,12 +1498,12 @@ QUnit.test('It is possible to get the model from a parent route', function() { }); }); - var post1 = {}; - var post2 = {}; - var post3 = {}; - var currentPost; + let post1 = {}; + let post2 = {}; + let post3 = {}; + let currentPost; - var posts = { + let posts = { 1: post1, 2: post2, 3: post3 @@ -1563,8 +1541,8 @@ QUnit.test('A redirection hook is provided', function() { this.route('home'); }); - var chooseFollowed = 0; - var destination; + let chooseFollowed = 0; + let destination; App.ChooseRoute = Route.extend({ redirect() { @@ -1634,7 +1612,7 @@ QUnit.test('Redirecting to the current target in the middle of a route does not }); }); - var successCount = 0; + let successCount = 0; App.BarRoute = Route.extend({ redirect() { this.transitionTo('bar.baz').then(function() { @@ -1673,9 +1651,9 @@ QUnit.test('Redirecting to the current target with a different context aborts th }); }); - var model = { id: 2 }; + let model = { id: 2 }; - var count = 0; + let count = 0; App.BarRoute = Route.extend({ afterModel(context) { @@ -1721,15 +1699,13 @@ QUnit.test('Transitioning from a parent event does not prevent currentPath from bootApplication(); - var applicationController = getOwner(router).lookup('controller:application'); + let applicationController = getOwner(router).lookup('controller:application'); handleURL('/foo/bar/baz'); equal(applicationController.get('currentPath'), 'foo.bar.baz'); - run(function() { - router.send('goToQux'); - }); + run(() => router.send('goToQux')); equal(applicationController.get('currentPath'), 'foo.qux'); equal(router.get('location').getURL(), '/foo/qux'); @@ -1853,8 +1829,8 @@ QUnit.test('Rendering into specified template with slash notation', function() { }); QUnit.test('Parent route context change', function() { - var editCount = 0; - var editedPostIds = emberA(); + let editCount = 0; + let editedPostIds = emberA(); setTemplate('application', compile('{{outlet}}')); setTemplate('posts', compile('{{outlet}}')); @@ -1892,7 +1868,7 @@ QUnit.test('Parent route context change', function() { App.PostEditRoute = Route.extend({ model(params) { - var postId = this.modelFor('post').id; + let postId = this.modelFor('post').id; editedPostIds.push(postId); return null; }, @@ -1906,26 +1882,18 @@ QUnit.test('Parent route context change', function() { handleURL('/posts/1'); - run(function() { - router.send('editPost'); - }); - - run(function() { - router.send('showPost', { id: '2' }); - }); - - run(function() { - router.send('editPost'); - }); + run(() => router.send('editPost')); + run(() => router.send('showPost', { id: '2' })); + run(() => router.send('editPost')); equal(editCount, 2, 'set up the edit route twice without failure'); deepEqual(editedPostIds, ['1', '2'], 'modelFor posts.post returns the right context'); }); test('Router accounts for rootURL on page load when using history location', function() { - var rootURL = window.location.pathname + '/app'; - var postsTemplateRendered = false; - var setHistory, HistoryTestLocation; + let rootURL = window.location.pathname + '/app'; + let postsTemplateRendered = false; + let setHistory, HistoryTestLocation; setHistory = function(obj, path) { obj.set('history', { state: { path: path } }); @@ -1935,7 +1903,7 @@ test('Router accounts for rootURL on page load when using history location', fun // and set current location to rootURL + '/posts' HistoryTestLocation = HistoryLocation.extend({ initState() { - var path = rootURL + '/posts'; + let path = rootURL + '/posts'; setHistory(this, path); this.set('location', { @@ -1979,8 +1947,8 @@ test('Router accounts for rootURL on page load when using history location', fun QUnit.test('The rootURL is passed properly to the location implementation', function() { expect(1); - var rootURL = '/blahzorz'; - var HistoryTestLocation; + let rootURL = '/blahzorz'; + let HistoryTestLocation; HistoryTestLocation = HistoryLocation.extend({ rootURL: 'this is not the URL you are looking for', @@ -2036,7 +2004,7 @@ QUnit.test('Generating a URL should not affect currentModel', function() { this.route('post', { path: '/posts/:post_id' }); }); - var posts = { + let posts = { 1: { id: 1 }, 2: { id: 2 } }; @@ -2051,10 +2019,10 @@ QUnit.test('Generating a URL should not affect currentModel', function() { handleURL('/posts/1'); - var route = container.lookup('route:post'); + let route = container.lookup('route:post'); equal(route.modelFor('post'), posts[1]); - var url = router.generate('post', posts[2]); + let url = router.generate('post', posts[2]); equal(url, '/posts/2'); equal(route.modelFor('post'), posts[1]); @@ -2062,7 +2030,7 @@ QUnit.test('Generating a URL should not affect currentModel', function() { QUnit.test('Generated route should be an instance of App.Route if provided', function() { - var generatedRoute; + let generatedRoute; Router.map(function() { this.route('posts'); @@ -2088,9 +2056,7 @@ QUnit.test('Nested index route is not overriden by parent\'s implicit index rout bootApplication(); - run(function() { - router.transitionTo('posts', { category: 'emberjs' }); - }); + run(() => router.transitionTo('posts', { category: 'emberjs' })); deepEqual(router.location.path, '/posts/emberjs'); }); @@ -2113,10 +2079,9 @@ if (isEnabled('ember-route-serializers')) { bootApplication(); - run(function() { - expectDeprecation(function() { - router.transitionTo('posts', { category: 'emberjs' }); - }, 'Defining a serialize function on route \'posts.index\' is deprecated. Instead, define it in the router\'s map as an option.'); + run(() => { + expectDeprecation(() => router.transitionTo('posts', { category: 'emberjs' }), + 'Defining a serialize function on route \'posts.index\' is deprecated. Instead, define it in the router\'s map as an option.'); }); deepEqual(router.location.path, '/posts/emberjs'); @@ -2175,7 +2140,7 @@ test('The template is not re-rendered when the route\'s context changes', functi } }); - var insertionCount = 0; + let insertionCount = 0; App.FooBarComponent = Component.extend({ didInsertElement() { insertionCount += 1; @@ -2198,9 +2163,7 @@ test('The template is not re-rendered when the route\'s context changes', functi equal(jQuery('p', '#qunit-fixture').text(), 'second'); equal(insertionCount, 1, 'view should have inserted only once'); - run(function() { - router.transitionTo('page', EmberObject.create({ name: 'third' })); - }); + run(() => router.transitionTo('page', EmberObject.create({ name: 'third' }))); equal(jQuery('p', '#qunit-fixture').text(), 'third'); equal(insertionCount, 1, 'view should still have inserted only once'); @@ -2258,7 +2221,7 @@ test('The template is not re-rendered when two routes present the exact same tem equal(insertionCount, 1, 'expected one assertion'); // Then transition directly by route name - run(function() { + run(() => { router.transitionTo('third').then(function(value) { ok(true, 'expected transition'); }, function(reason) { @@ -2277,8 +2240,8 @@ test('The template is not re-rendered when two routes present the exact same tem }); QUnit.test('ApplicationRoute with model does not proxy the currentPath', function() { - var model = {}; - var currentPath; + let model = {}; + let currentPath; App.ApplicationRoute = Route.extend({ model() { return model; } @@ -2299,7 +2262,7 @@ QUnit.test('ApplicationRoute with model does not proxy the currentPath', functio QUnit.test('Promises encountered on app load put app into loading state until resolved', function() { expect(2); - var deferred = RSVP.defer(); + let deferred = RSVP.defer(); App.IndexRoute = Route.extend({ model() { @@ -2373,9 +2336,7 @@ QUnit.test('Route will assert if you try to explicitly render {into: ...} a miss } }); - expectAssertion(function() { - bootApplication(); - }, 'You attempted to render into \'nonexistent\' but it was not found'); + expectAssertion(() => bootApplication(), 'You attempted to render into \'nonexistent\' but it was not found'); }); test('Route supports clearing outlet explicitly', function() { @@ -2423,21 +2384,21 @@ test('Route supports clearing outlet explicitly', function() { handleURL('/posts'); equal(jQuery('div.posts-index:contains(postsIndex)', '#qunit-fixture').length, 1, 'The posts/index template was rendered'); - run(function() { - router.send('showModal'); - }); + + run(() => router.send('showModal')); + equal(jQuery('div.posts-modal:contains(postsModal)', '#qunit-fixture').length, 1, 'The posts/modal template was rendered'); - run(function() { - router.send('showExtra'); - }); + + run(() => router.send('showExtra')); + equal(jQuery('div.posts-extra:contains(postsExtra)', '#qunit-fixture').length, 1, 'The posts/extra template was rendered'); - run(function() { - router.send('hideModal'); - }); + + run(() => router.send('hideModal')); + equal(jQuery('div.posts-modal:contains(postsModal)', '#qunit-fixture').length, 0, 'The posts/modal template was removed'); - run(function() { - router.send('hideExtra'); - }); + + run(() => router.send('hideExtra')); + equal(jQuery('div.posts-extra:contains(postsExtra)', '#qunit-fixture').length, 0, 'The posts/extra template was removed'); run(function() { router.send('showModal'); @@ -2486,13 +2447,13 @@ test('Route supports clearing outlet using string parameter', function() { handleURL('/posts'); equal(jQuery('div.posts-index:contains(postsIndex)', '#qunit-fixture').length, 1, 'The posts/index template was rendered'); - run(function() { - router.send('showModal'); - }); + + run(() => router.send('showModal')); + equal(jQuery('div.posts-modal:contains(postsModal)', '#qunit-fixture').length, 1, 'The posts/modal template was rendered'); - run(function() { - router.send('hideModal'); - }); + + run(() => router.send('hideModal')); + equal(jQuery('div.posts-modal:contains(postsModal)', '#qunit-fixture').length, 0, 'The posts/modal template was removed'); handleURL('/users'); @@ -2530,9 +2491,9 @@ test('Route silently fails when cleaning an outlet from an inactive view', funct handleURL('/posts'); - run(function() { router.send('showModal'); }); - run(function() { router.send('hideSelf'); }); - run(function() { router.send('hideModal'); }); + run(() => router.send('showModal')); + run(() => router.send('hideSelf')); + run(() => router.send('hideModal')); }); QUnit.test('Router `willTransition` hook passes in cancellable transition', function() { @@ -2589,7 +2550,7 @@ QUnit.test('Aborting/redirecting the transition in `willTransition` prevents Loa this.route('about'); }); - var redirect = false; + let redirect = false; App.IndexRoute = Route.extend({ actions: { @@ -2605,7 +2566,7 @@ QUnit.test('Aborting/redirecting the transition in `willTransition` prevents Loa } }); - var deferred = null; + let deferred = null; App.LoadingRoute = Route.extend({ activate() { @@ -2692,7 +2653,7 @@ QUnit.test('`didTransition` can be reopened', function() { QUnit.test('`activate` event fires on the route', function() { expect(2); - var eventFired = 0; + let eventFired = 0; Router.map(function() { this.route('nork'); @@ -2720,7 +2681,7 @@ QUnit.test('`activate` event fires on the route', function() { QUnit.test('`deactivate` event fires on the route', function() { expect(2); - var eventFired = 0; + let eventFired = 0; Router.map(function() { this.route('nork'); @@ -2792,13 +2753,9 @@ QUnit.test('transitionTo returns Transition when passed a route name', function( this.route('bar'); }); - var transition = null; - bootApplication(); - run(function() { - transition = router.transitionTo('bar'); - }); + let transition = run(() => router.transitionTo('bar')); equal(transition instanceof Transition, true); }); @@ -2812,13 +2769,9 @@ QUnit.test('transitionTo returns Transition when passed a url', function() { }); }); - var transition = null; - bootApplication(); - run(function() { - transition = router.transitionTo('/bar/baz'); - }); + let transition = run(() => router.transitionTo('/bar/baz')); equal(transition instanceof Transition, true); }); @@ -2840,7 +2793,7 @@ QUnit.test('currentRouteName is a property installed on ApplicationController th bootApplication(); - var appController = getOwner(router).lookup('controller:application'); + let appController = getOwner(router).lookup('controller:application'); function transitionAndCheck(path, expectedPath, expectedRouteName) { if (path) { run(router, 'transitionTo', path); } @@ -2864,7 +2817,7 @@ QUnit.test('currentRouteName is a property installed on ApplicationController th }); QUnit.test('Route model hook finds the same model as a manual find', function() { - var Post; + let Post; App.Post = EmberObject.extend(); App.Post.reopenClass({ find() { @@ -2891,14 +2844,14 @@ QUnit.test('Routes can refresh themselves causing their model hooks to be re-run }); }); - var appcount = 0; + let appcount = 0; App.ApplicationRoute = Route.extend({ model() { ++appcount; } }); - var parentcount = 0; + let parentcount = 0; App.ParentRoute = Route.extend({ model(params) { equal(params.parent_id, '123'); @@ -2911,7 +2864,7 @@ QUnit.test('Routes can refresh themselves causing their model hooks to be re-run } }); - var childcount = 0; + let childcount = 0; App.ParentChildRoute = Route.extend({ model() { ++childcount; @@ -2994,8 +2947,8 @@ QUnit.test('Redirecting with null model doesn\'t error out', function() { QUnit.test('rejecting the model hooks promise with a non-error prints the `message` property', function() { expect(5); - var rejectedMessage = 'OMG!! SOOOOOO BAD!!!!'; - var rejectedStack = 'Yeah, buddy: stack gets printed too.'; + let rejectedMessage = 'OMG!! SOOOOOO BAD!!!!'; + let rejectedStack = 'Yeah, buddy: stack gets printed too.'; Router.map(function() { this.route('yippie', { path: '/' }); @@ -3023,8 +2976,8 @@ QUnit.test('rejecting the model hooks promise with a non-error prints the `messa QUnit.test('rejecting the model hooks promise with an error with `errorThrown` property prints `errorThrown.message` property', function() { expect(5); - var rejectedMessage = 'OMG!! SOOOOOO BAD!!!!'; - var rejectedStack = 'Yeah, buddy: stack gets printed too.'; + let rejectedMessage = 'OMG!! SOOOOOO BAD!!!!'; + let rejectedStack = 'Yeah, buddy: stack gets printed too.'; Router.map(function() { this.route('yippie', { path: '/' }); @@ -3044,9 +2997,7 @@ QUnit.test('rejecting the model hooks promise with an error with `errorThrown` p } }); - throws(function() { - bootApplication(); - }, function(err) { + throws(() => bootApplication(), function(err) { equal(err.message, rejectedMessage); return true; }, 'expected an exception'); @@ -3072,8 +3023,8 @@ QUnit.test('rejecting the model hooks promise with no reason still logs error', QUnit.test('rejecting the model hooks promise with a string shows a good error', function() { expect(3); - var originalLoggerError = Logger.error; - var rejectedMessage = 'Supercalifragilisticexpialidocious'; + let originalLoggerError = Logger.error; + let rejectedMessage = 'Supercalifragilisticexpialidocious'; Router.map(function() { this.route('yondo', { path: '/' }); @@ -3090,9 +3041,7 @@ QUnit.test('rejecting the model hooks promise with a string shows a good error', } }); - throws(function() { - bootApplication(); - }, rejectedMessage, 'expected an exception'); + throws(() => bootApplication(), rejectedMessage, 'expected an exception'); Logger.error = originalLoggerError; }); @@ -3128,7 +3077,7 @@ QUnit.test('willLeave, willChangeContext, willChangeModel actions don\'t fire un QUnit.test('Errors in transitionTo within redirect hook are logged', function() { expect(4); - var actual = []; + let actual = []; Router.map(function() { this.route('yondo', { path: '/' }); @@ -3146,9 +3095,7 @@ QUnit.test('Errors in transitionTo within redirect hook are logged', function() actual.push(arguments); }; - throws(function() { - bootApplication(); - }, /More context objects were passed/); + throws(() => bootApplication(), /More context objects were passed/); equal(actual.length, 1, 'the error is only logged once'); equal(actual[0][0], 'Error while processing route: yondo', 'source route is printed'); @@ -3169,9 +3116,7 @@ QUnit.test('Errors in transition show error template if available', function() { } }); - throws(function() { - bootApplication(); - }, /More context objects were passed/); + throws(() => bootApplication(), /More context objects were passed/); equal(jQuery('#error').length, 1, 'Error template was rendered.'); }); @@ -3187,9 +3132,9 @@ QUnit.test('Route#resetController gets fired when changing models and exiting ro this.route('out'); }); - var calls = []; + let calls = []; - var SpyRoute = Route.extend({ + let SpyRoute = Route.extend({ setupController(controller, model, transition) { calls.push(['setup', this.routeName]); }, @@ -3229,9 +3174,7 @@ QUnit.test('Exception during initialization of non-initial route is not swallowe } }); bootApplication(); - throws(function() { - run(router, 'transitionTo', 'boom'); - }, /\bboom\b/); + throws(() => run(router, 'transitionTo', 'boom'), /\bboom\b/); }); @@ -3239,7 +3182,7 @@ QUnit.test('Exception during load of non-initial route is not swallowed', functi Router.map(function() { this.route('boom'); }); - var lookup = container.lookup; + let lookup = container.lookup; container.lookup = function() { if (arguments[0] === 'route:boom') { throw new Error('boom!'); @@ -3252,9 +3195,7 @@ QUnit.test('Exception during load of non-initial route is not swallowed', functi } }); bootApplication(); - throws(function() { - run(router, 'transitionTo', 'boom'); - }); + throws(() => run(router, 'transitionTo', 'boom')); }); QUnit.test('Exception during initialization of initial route is not swallowed', function() { @@ -3266,16 +3207,14 @@ QUnit.test('Exception during initialization of initial route is not swallowed', throw new Error('boom!'); } }); - throws(function() { - bootApplication(); - }, /\bboom\b/); + throws(() => bootApplication(), /\bboom\b/); }); QUnit.test('Exception during load of initial route is not swallowed', function() { Router.map(function() { this.route('boom', { path: '/' }); }); - var lookup = container.lookup; + let lookup = container.lookup; container.lookup = function() { if (arguments[0] === 'route:boom') { throw new Error('boom!'); @@ -3287,9 +3226,7 @@ QUnit.test('Exception during load of initial route is not swallowed', function() throw new Error('boom!'); } }); - throws(function() { - bootApplication(); - }, /\bboom\b/); + throws(() => bootApplication(), /\bboom\b/); }); QUnit.test('{{outlet}} works when created after initial render', function() { @@ -3307,9 +3244,7 @@ QUnit.test('{{outlet}} works when created after initial render', function() { equal(jQuery('#qunit-fixture').text(), 'HiBye', 'initial render'); - run(function() { - container.lookup('controller:sample').set('showTheThing', true); - }); + run(() => container.lookup('controller:sample').set('showTheThing', true)); equal(jQuery('#qunit-fixture').text(), 'HiYayBye', 'second render'); @@ -3432,7 +3367,7 @@ QUnit.test('Can render routes with no \'main\' outlet and their children', funct }); App.AppRoute = Route.extend({ - renderTemplate : function() { + renderTemplate() { this.render('app', { outlet: 'app', into: 'application' @@ -3445,7 +3380,7 @@ QUnit.test('Can render routes with no \'main\' outlet and their children', funct }); App.SubRoute = Route.extend({ - renderTemplate : function() { + renderTemplate() { this.render('sub', { outlet: 'sub', into: 'app' @@ -3467,13 +3402,13 @@ test('Tolerates stacked renders', function() { setTemplate('layer', compile('layer')); App.ApplicationRoute = Route.extend({ actions: { - openLayer: function() { + openLayer() { this.render('layer', { into: 'application', outlet: 'modal' }); }, - close: function() { + close() { this.disconnectOutlet({ outlet: 'modal', parentView: 'application' @@ -3524,7 +3459,7 @@ test('Allows any route to disconnectOutlet another route\'s templates', function setTemplate('layer', compile('layer')); App.ApplicationRoute = Route.extend({ actions: { - openLayer: function() { + openLayer() { this.render('layer', { into: 'application', outlet: 'modal' @@ -3534,7 +3469,7 @@ test('Allows any route to disconnectOutlet another route\'s templates', function }); App.IndexRoute = Route.extend({ actions: { - close: function() { + close() { this.disconnectOutlet({ parentView: 'application', outlet: 'modal' @@ -3561,7 +3496,7 @@ test('Can this.render({into:...}) the render helper', function() { this.render({ into: 'foo' }); }, actions: { - changeToBar: function() { + changeToBar() { this.disconnectOutlet({ parentView: 'foo', outlet: 'main' @@ -3615,7 +3550,7 @@ test('Can this.render({into:...}) the render helper\'s children', function() { this.render('other', { into: 'index' }); }, actions: { - changeToBar: function() { + changeToBar() { this.disconnectOutlet({ parentView: 'index', outlet: 'main' @@ -3643,7 +3578,7 @@ test('Can disconnect from the render helper\'s children', function() { this.render('other', { into: 'index' }); }, actions: { - disconnect: function() { + disconnect() { this.disconnectOutlet({ parentView: 'index', outlet: 'main' @@ -3666,11 +3601,11 @@ test('Can this.render({into:...}) nested render helpers', function() { setTemplate('baz', compile('baz')); App.IndexRoute = Route.extend({ - renderTemplate: function() { + renderTemplate() { this.render({ into: 'bar' }); }, actions: { - changeToBaz: function() { + changeToBaz() { this.disconnectOutlet({ parentView: 'bar', outlet: 'main' @@ -3693,11 +3628,11 @@ test('Can disconnect from nested render helpers', function() { setTemplate('index', compile('other')); App.IndexRoute = Route.extend({ - renderTemplate: function() { + renderTemplate() { this.render({ into: 'bar' }); }, actions: { - disconnect: function() { + disconnect() { this.disconnectOutlet({ parentView: 'bar', outlet: 'main' @@ -3715,9 +3650,9 @@ test('Can disconnect from nested render helpers', function() { QUnit.test('Components inside an outlet have their didInsertElement hook invoked when the route is displayed', function(assert) { setTemplate('index', compile('{{#if showFirst}}{{my-component}}{{else}}{{other-component}}{{/if}}')); - var myComponentCounter = 0; - var otherComponentCounter = 0; - var indexController; + let myComponentCounter = 0; + let otherComponentCounter = 0; + let indexController; App.IndexController = Controller.extend({ showFirst: true @@ -3746,9 +3681,7 @@ QUnit.test('Components inside an outlet have their didInsertElement hook invoked assert.strictEqual(myComponentCounter, 1, 'didInsertElement invoked on displayed component'); assert.strictEqual(otherComponentCounter, 0, 'didInsertElement not invoked on displayed component'); - run(function() { - indexController.set('showFirst', false); - }); + run(() => indexController.set('showFirst', false)); assert.strictEqual(myComponentCounter, 1, 'didInsertElement not invoked on displayed component'); assert.strictEqual(otherComponentCounter, 1, 'didInsertElement invoked on displayed component'); @@ -3775,23 +3708,21 @@ QUnit.test('Doesnt swallow exception thrown from willTransition', function() { bootApplication(); - throws(function() { - run(function() { - router.handleURL('/other'); - }); + throws(() => { + run(() => router.handleURL('/other')); }, /boom/, 'expected an exception that didnt happen'); }); QUnit.test('Exception if outlet name is undefined in render and disconnectOutlet', function(assert) { App.ApplicationRoute = Route.extend({ actions: { - showModal: function() { + showModal() { this.render({ outlet: undefined, parentView: 'application' }); }, - hideModal: function() { + hideModal() { this.disconnectOutlet({ outlet: undefined, parentView: 'application' @@ -3802,11 +3733,11 @@ QUnit.test('Exception if outlet name is undefined in render and disconnectOutlet bootApplication(); - throws(function() { - run(function() { router.send('showModal'); }); + throws(() => { + run(() => router.send('showModal')); }, /You passed undefined as the outlet name/); - throws(function() { - run(function() { router.send('hideModal'); }); + throws(() => { + run(() => router.send('hideModal')); }, /You passed undefined as the outlet name/); }); diff --git a/packages/ember/tests/routing/query_params_test.js b/packages/ember/tests/routing/query_params_test.js index 6993575e14f..1c8c9460e51 100644 --- a/packages/ember/tests/routing/query_params_test.js +++ b/packages/ember/tests/routing/query_params_test.js @@ -15,7 +15,7 @@ import { dasherize } from 'ember-runtime/system/string'; import Mixin from 'ember-metal/mixin'; import { meta } from 'ember-metal/meta'; -var App, router, container; +let App, router, container; function bootApplication() { router = container.lookup('router:main'); @@ -23,7 +23,7 @@ function bootApplication() { } function handleURL(path) { - return run(function() { + return run(() => { return router.handleURL(path).then(function(value) { ok(true, 'url: `' + path + '` was handled'); return value; @@ -34,14 +34,14 @@ function handleURL(path) { }); } -var startingURL = ''; -var expectedReplaceURL, expectedPushURL; +let startingURL = ''; +let expectedReplaceURL, expectedPushURL; function setAndFlush(obj, prop, value) { run(obj, 'set', prop, value); } -var TestLocation = NoneLocation.extend({ +const TestLocation = NoneLocation.extend({ initState() { this.set('path', startingURL); }, @@ -70,7 +70,7 @@ var TestLocation = NoneLocation.extend({ }); function sharedSetup() { - run(function() { + run(() => { App = Application.create({ name: 'App', rootElement: '#qunit-fixture' @@ -98,7 +98,7 @@ function sharedSetup() { function sharedTeardown() { try { - run(function() { + run(() => { App.destroy(); App = null; }); @@ -135,7 +135,7 @@ if (isEnabled('ember-routing-route-configured-query-params')) { bootApplication(); - var controller = container.lookup('controller:home'); + let controller = container.lookup('controller:home'); setAndFlush(controller, 'foo', '456'); @@ -161,7 +161,7 @@ if (isEnabled('ember-routing-route-configured-query-params')) { bootApplication(); - var controller = container.lookup('controller:home'); + let controller = container.lookup('controller:home'); run(router, 'transitionTo', 'home', { queryParams: { page: '4' } }); equal(controller.get('page'), 4); @@ -178,7 +178,7 @@ if (isEnabled('ember-routing-route-configured-query-params')) { bootApplication(); equal(router.get('location.path'), ''); - var controller = container.lookup('controller:index'); + let controller = container.lookup('controller:index'); setAndFlush(controller, 'foo', 'LEX'); @@ -206,7 +206,7 @@ if (isEnabled('ember-routing-route-configured-query-params')) { bootApplication(); equal(router.get('location.path'), ''); - var controller = container.lookup('controller:index'); + let controller = container.lookup('controller:index'); setAndFlush(controller, 'funTimes', 'woot'); equal(router.get('location.path'), '/?fun-times=woot'); @@ -335,7 +335,7 @@ if (isEnabled('ember-routing-route-configured-query-params')) { QUnit.test('can opt into full transition by setting refreshModel in route queryParams when all configuration is in route', function() { expect(6); - var appModelCount = 0; + let appModelCount = 0; App.ApplicationRoute = Route.extend({ queryParams: { 'appomg': { @@ -347,7 +347,7 @@ if (isEnabled('ember-routing-route-configured-query-params')) { } }); - var indexModelCount = 0; + let indexModelCount = 0; App.IndexRoute = Route.extend({ queryParams: { omg: { @@ -371,7 +371,7 @@ if (isEnabled('ember-routing-route-configured-query-params')) { equal(appModelCount, 1); equal(indexModelCount, 1); - var indexController = container.lookup('controller:index'); + let indexController = container.lookup('controller:index'); setAndFlush(indexController, 'omg', 'lex'); equal(appModelCount, 1); @@ -396,7 +396,7 @@ if (isEnabled('ember-routing-route-configured-query-params')) { refreshModel: true } }, - refresh: function() { + refresh() { ok(false); } }); @@ -408,7 +408,7 @@ if (isEnabled('ember-routing-route-configured-query-params')) { QUnit.test('can use refreshModel even w URL changes that remove QPs from address bar when QP configured on route', function() { expect(4); - var indexModelCount = 0; + let indexModelCount = 0; App.IndexRoute = Route.extend({ queryParams: { omg: { @@ -419,7 +419,7 @@ if (isEnabled('ember-routing-route-configured-query-params')) { model(params) { indexModelCount++; - var data; + let data; if (indexModelCount === 1) { data = 'foo'; } else if (indexModelCount === 2) { @@ -434,7 +434,7 @@ if (isEnabled('ember-routing-route-configured-query-params')) { bootApplication(); handleURL('/'); - var indexController = container.lookup('controller:index'); + let indexController = container.lookup('controller:index'); equal(indexController.get('omg'), 'lol'); }); @@ -454,7 +454,7 @@ if (isEnabled('ember-routing-route-configured-query-params')) { equal(router.get('location.path'), ''); - var appController = container.lookup('controller:application'); + let appController = container.lookup('controller:application'); expectedReplaceURL = '/?alex=wallace'; setAndFlush(appController, 'alex', 'wallace'); }); @@ -475,7 +475,7 @@ if (isEnabled('ember-routing-route-configured-query-params')) { equal(router.get('location.path'), ''); - var appController = container.lookup('controller:application'); + let appController = container.lookup('controller:application'); expectedReplaceURL = '/?commit_by=igor_seb'; setAndFlush(appController, 'commitBy', 'igor_seb'); }); @@ -498,7 +498,7 @@ if (isEnabled('ember-routing-route-configured-query-params')) { bootApplication(); - var appController = container.lookup('controller:application'); + let appController = container.lookup('controller:application'); expectedPushURL = '/?alex=wallace&steely=jan'; run(appController, 'setProperties', { alex: 'wallace', steely: 'jan' }); @@ -519,7 +519,7 @@ if (isEnabled('ember-routing-route-configured-query-params')) { }); }); - var parentModelCount = 0; + let parentModelCount = 0; App.ParentRoute = Route.extend({ model() { parentModelCount++; @@ -558,7 +558,7 @@ if (isEnabled('ember-routing-route-configured-query-params')) { startingURL = '/?omg=borf'; bootApplication(); - var indexController = container.lookup('controller:index'); + let indexController = container.lookup('controller:index'); equal(indexController.get('omg'), 'borf'); run(router, 'transitionTo', '/'); equal(indexController.get('omg'), 'lol'); @@ -662,7 +662,7 @@ if (isEnabled('ember-routing-route-configured-query-params')) { startingURL = '/?foo=true'; bootApplication(); - var controller = container.lookup('controller:index'); + let controller = container.lookup('controller:index'); equal(controller.get('foo'), true); handleURL('/?foo=false'); @@ -681,7 +681,7 @@ if (isEnabled('ember-routing-route-configured-query-params')) { startingURL = '/?foo='; bootApplication(); - var controller = container.lookup('controller:index'); + let controller = container.lookup('controller:index'); equal(controller.get('foo'), ''); }); @@ -700,7 +700,7 @@ if (isEnabled('ember-routing-route-configured-query-params')) { bootApplication(); - var controller = container.lookup('controller:home'); + let controller = container.lookup('controller:home'); setAndFlush(controller, 'foo', [1, 2]); @@ -743,7 +743,7 @@ if (isEnabled('ember-routing-route-configured-query-params')) { startingURL = '/?foo[]=1&foo[]=2&foo[]=3'; bootApplication(); - var controller = container.lookup('controller:index'); + let controller = container.lookup('controller:index'); deepEqual(controller.get('foo'), ['1', '2', '3']); }); @@ -761,7 +761,7 @@ if (isEnabled('ember-routing-route-configured-query-params')) { startingURL = '/?foo[]=1&foo[]=2&foo[]=3'; bootApplication(); - var controller = container.lookup('controller:index'); + let controller = container.lookup('controller:index'); deepEqual(controller.get('foo'), ['1', '2', '3']); }); @@ -784,7 +784,7 @@ if (isEnabled('ember-routing-route-configured-query-params')) { equal(router.get('location.path'), ''); - var controller = container.lookup('controller:home'); + let controller = container.lookup('controller:home'); run(controller.foo, 'pushObject', 1); equal(router.get('location.path'), '/?foo=%5B1%5D'); @@ -814,7 +814,7 @@ if (isEnabled('ember-routing-route-configured-query-params')) { QUnit.test('Overwriting with array with same content shouldn\'t refire update when configuration occurs on router but there is still a controller', function() { expect(3); - var modelCount = 0; + let modelCount = 0; App.Router.map(function() { this.route('home', { path: '/' }); @@ -836,7 +836,7 @@ if (isEnabled('ember-routing-route-configured-query-params')) { bootApplication(); equal(modelCount, 1); - var controller = container.lookup('controller:home'); + let controller = container.lookup('controller:home'); setAndFlush(controller, 'model', emberA([1])); equal(modelCount, 1); equal(router.get('location.path'), ''); @@ -889,7 +889,7 @@ if (isEnabled('ember-routing-route-configured-query-params')) { }); bootApplication(); - var controller = container.lookup('controller:bar'); + let controller = container.lookup('controller:bar'); expectedPushURL = '/foo'; run(jQuery('#foo-link'), 'click'); @@ -929,11 +929,11 @@ if (isEnabled('ember-routing-route-configured-query-params')) { bootApplication(); - var $link = jQuery('#the-link'); + let $link = jQuery('#the-link'); equal($link.attr('href'), '/example'); run($link, 'click'); - var controller = container.lookup('controller:example'); + let controller = container.lookup('controller:example'); equal(get(controller, 'foo'), undefined); }); @@ -1005,7 +1005,7 @@ if (isEnabled('ember-routing-route-configured-query-params')) { bootApplication(); equal(router.get('location.path'), ''); - var controller = container.lookup('controller:index'); + let controller = container.lookup('controller:index'); setAndFlush(controller, 'funTimes', 'woot'); equal(router.get('location.path'), '/?fun-times=woot'); @@ -1041,9 +1041,9 @@ if (isEnabled('ember-routing-route-configured-query-params')) { App.register('template:about', compile("TOPLEVEL ERROR: {{model.msg}}
'; - var reject = true; + let reject = true; App.ApplicationRoute = Route.extend({ model() { if (reject) { @@ -1010,9 +1009,8 @@ test('Rejected promises returned from ApplicationRoute transition into top-level } }); - throws(function() { - bootApplication(); - }, function(err) { return err.msg === 'BAD NEWS BEARS'; }); + throws(() => bootApplication(), + err => err.msg === 'BAD NEWS BEARS'); equal(jQuery('#toplevel-error', '#qunit-fixture').text(), 'TOPLEVEL ERROR: BAD NEWS BEARS'); diff --git a/packages/ember/tests/routing/toplevel_dom_test.js b/packages/ember/tests/routing/toplevel_dom_test.js index fb61dbe7f17..daa28e05f47 100644 --- a/packages/ember/tests/routing/toplevel_dom_test.js +++ b/packages/ember/tests/routing/toplevel_dom_test.js @@ -5,10 +5,10 @@ import jQuery from 'ember-views/system/jquery'; import NoneLocation from 'ember-routing/location/none_location'; import { setTemplates, set as setTemplate } from 'ember-templates/template_registry'; -var App, templates, router, container; +let App, templates, router, container; function bootApplication() { - for (var name in templates) { + for (let name in templates) { setTemplate(name, compile(templates[name])); } router = container.lookup('router:main'); @@ -17,7 +17,7 @@ function bootApplication() { QUnit.module('Top Level DOM Structure', { setup() { - run(function() { + run(() => { App = Application.create({ name: 'App', rootElement: '#qunit-fixture' @@ -38,7 +38,7 @@ QUnit.module('Top Level DOM Structure', { }, teardown() { - run(function() { + run(() => { App.destroy(); App = null; setTemplates({}); diff --git a/packages/ember/tests/view_instrumentation_test.js b/packages/ember/tests/view_instrumentation_test.js index 594c7a01af8..3aeea79b3ab 100644 --- a/packages/ember/tests/view_instrumentation_test.js +++ b/packages/ember/tests/view_instrumentation_test.js @@ -6,7 +6,7 @@ import { compile } from 'ember-template-compiler/tests/utils/helpers'; import { setTemplates, set as setTemplate } from 'ember-templates/template_registry'; import { test, testModule } from 'internal-test-helpers/tests/skip-if-glimmer'; -var App, $fixture; +let App, $fixture; function setupExample() { // setup templates @@ -20,13 +20,13 @@ function setupExample() { } function handleURL(path) { - var router = App.__container__.lookup('router:main'); + let router = App.__container__.lookup('router:main'); return run(router, 'handleURL', path); } testModule('View Instrumentation', { setup() { - run(function() { + run(() => { App = Application.create({ rootElement: '#qunit-fixture' }); @@ -50,7 +50,7 @@ testModule('View Instrumentation', { }); test('Nodes without view instances are instrumented', function(assert) { - var called = false; + let called = false; subscribe('render', { before() { called = true;