Skip to content

Commit

Permalink
Fixup transpilation issues with @ember/ordered-set. (#5557)
Browse files Browse the repository at this point in the history
* Ensure tests run minimally transpiled.

* Add specific test run for full transpilation.

* [BUGFIX beta] Prevent transpilation issues with @ember/ordered-set.

* Fix ES compatibility issues.

These cases were all previously working due to transpilation from `let`
to `var`. You *cannot* reference a block scoped variable (`let` /
`const`) during the variables own initializer.
  • Loading branch information
rwjblue authored and runspired committed Aug 8, 2018
1 parent 05bd20e commit 99d3635
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 40 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ jobs:
install: yarn install --no-lockfile --non-interactive
script: yarn test

- name: "Max Transpilation"
install: yarn install
env: TARGET_IE11=true
script: yarn test

- env: NAME=production # used only to make Travis UI show description
install: yarn install
script: yarn test:production
Expand Down
2 changes: 1 addition & 1 deletion addon/-legacy-private/system/model/internal-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export default class InternalModel {

get _recordArrays() {
if (this.__recordArrays === null) {
this.__recordArrays = OrderedSet.create();
this.__recordArrays = new OrderedSet();
}
return this.__recordArrays;
}
Expand Down
47 changes: 20 additions & 27 deletions addon/-private/system/ordered-set.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,30 @@
import EmberOrderedSet from '@ember/ordered-set';
import { guidFor } from '@ember/object/internals';

export default function OrderedSet() {
this._super$constructor();
}
export default class EmberDataOrderedSet extends EmberOrderedSet {
static create() {
return new this();
}

OrderedSet.create = function() {
let Constructor = this;
return new Constructor();
};
addWithIndex(obj, idx) {
let guid = guidFor(obj);
let presenceSet = this.presenceSet;
let list = this.list;

OrderedSet.prototype = Object.create(EmberOrderedSet.prototype);
OrderedSet.prototype.constructor = OrderedSet;
OrderedSet.prototype._super$constructor = EmberOrderedSet;
if (presenceSet[guid] === true) {
return;
}

OrderedSet.prototype.addWithIndex = function(obj, idx) {
let guid = guidFor(obj);
let presenceSet = this.presenceSet;
let list = this.list;
presenceSet[guid] = true;

if (presenceSet[guid] === true) {
return;
}
if (idx === undefined || idx === null) {
list.push(obj);
} else {
list.splice(idx, 0, obj);
}

presenceSet[guid] = true;
this.size += 1;

if (idx === undefined || idx === null) {
list.push(obj);
} else {
list.splice(idx, 0, obj);
return this;
}

this.size += 1;

return this;
};
}
2 changes: 1 addition & 1 deletion addon/-record-data-private/system/model/internal-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export default class InternalModel {

get _recordArrays() {
if (this.__recordArrays === null) {
this.__recordArrays = OrderedSet.create();
this.__recordArrays = new OrderedSet();
}
return this.__recordArrays;
}
Expand Down
13 changes: 13 additions & 0 deletions tests/dummy/config/targets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

const browsers = ['last 1 Chrome versions', 'last 1 Firefox versions', 'last 1 Safari versions'];

const needsIE11 = !!process.env.TARGET_IE11;

if (needsIE11) {
browsers.push('ie 11');
}

module.exports = {
browsers,
};
4 changes: 2 additions & 2 deletions tests/integration/store-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ test('destroying the store correctly cleans everything up', function(assert) {
};

let adapterPopulatedPeople = run(() => {
return (adapterPopulatedPeople = store.query('person', {
return store.query('person', {
someCrazy: 'query',
}));
});
});

let adapterPopulatedPeopleWillDestroy = tap(adapterPopulatedPeople.get('content'), 'willDestroy');
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/model-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -889,10 +889,10 @@ test(`a DS.model can define 'setUnknownProperty'`, function(assert) {
});

let tag = run(() => {
tag = store.createRecord('tag', { name: 'old' });
set(tag, 'title', 'new');
let record = store.createRecord('tag', { name: 'old' });
set(record, 'title', 'new');

return tag;
return record;
});

assert.equal(get(tag, 'name'), 'new', 'setUnknownProperty not triggered');
Expand Down Expand Up @@ -963,12 +963,12 @@ test('setting a property to undefined on a newly created record should not impac
});

let tag = run(() => {
tag = store.createRecord('tag');
let record = store.createRecord('tag');

set(tag, 'name', 'testing');
set(tag, 'name', undefined);
set(record, 'name', 'testing');
set(record, 'name', undefined);

return tag;
return record;
});

assert.equal(get(tag, 'currentState.stateName'), 'root.loaded.created.uncommitted');
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/model/rollback-attributes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', {
});

test('changes to attributes can be rolled back', function(assert) {
let person = run(() => {
let person;

run(() => {
store.push({
data: {
type: 'person',
Expand All @@ -59,7 +61,9 @@ test('changes to attributes can be rolled back', function(assert) {
});

test('changes to unassigned attributes can be rolled back', function(assert) {
let person = run(() => {
let person;

run(() => {
store.push({
data: {
type: 'person',
Expand Down

0 comments on commit 99d3635

Please sign in to comment.