Skip to content

Commit

Permalink
feat(Symbol): remove Symbol for Windows/IE10
Browse files Browse the repository at this point in the history
- remove spec "properties should provide getter only"

BREAKING CHANGE: remove spec "properties should provide getter only"
  • Loading branch information
59naga committed Apr 19, 2016
1 parent 3ff25d4 commit 594bd4f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 46 deletions.
45 changes: 9 additions & 36 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
// no dependencies
const TYPE = Symbol('type');
const VALUE = Symbol('value');
const OPTS = Symbol('options');
const META = Symbol('meta');

// @class Token
export default class Token {
/**
Expand All @@ -14,31 +8,10 @@ export default class Token {
* @param {object} [meta={}] - a token meta information
*/
constructor(type = 'text', value = null, options = {}, meta = {}) {
this[TYPE] = type;
this[VALUE] = value;
this[OPTS] = { ...options };
this[META] = { ...meta };
}

get type() {
return this[TYPE];
}
get value() {
return this[VALUE];
}
get options() {
return this[OPTS];
}
get meta() {
return this[META];
}
toJSON() {
return {
type: this.type,
value: this.value,
options: this.options,
meta: this.meta,
};
this.type = type;
this.value = value;
this.options = { ...options };
this.meta = { ...meta };
}

/**
Expand All @@ -56,7 +29,7 @@ export default class Token {
* @returns {this} this
*/
setType(type) {
this[TYPE] = type;
this.type = type;
return this;
}

Expand All @@ -66,7 +39,7 @@ export default class Token {
* @returns {this} this
*/
setValue(value) {
this[VALUE] = value;
this.value = value;
return this;
}

Expand All @@ -77,7 +50,7 @@ export default class Token {
* @returns {this} this
*/
setOption(key, value) {
this[OPTS][key] = value;
this.options[key] = value;
return this;
}

Expand All @@ -87,7 +60,7 @@ export default class Token {
* @returns {this} this
*/
setOptions(options) {
this[OPTS] = { ...this[OPTS], ...options };
this.options = { ...this.options, ...options };
return this;
}

Expand All @@ -98,7 +71,7 @@ export default class Token {
* @returns {this} this
*/
setMeta(key, value) {
this[META][key] = value;
this.meta[key] = value;
return this;
}
}
10 changes: 0 additions & 10 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// dependencies
import test from 'ava';
import { throws } from 'assert-exception';

// target
import Token from '../src';
Expand All @@ -12,15 +11,6 @@ test('token should be initialized with the text type', (t) => {
t.true(token.value === null);
});

test('properties should provide getter only', (t) => {
const token = new Token('text', 'foo');

t.true(
throws(() => {token.type = 'illegal';})
.message === 'Cannot set property type of #<Token> which has only a getter'
);
});

test('should be change the properties via the `set*` method', (t) => {
const token = new Token('text', 'foo');
t.true(token.type === 'text');
Expand Down

0 comments on commit 594bd4f

Please sign in to comment.