From 594bd4f13d37f09d2b4a51fc8af80de4ef8b7fd9 Mon Sep 17 00:00:00 2001 From: 59naga Date: Wed, 20 Apr 2016 03:29:44 +0900 Subject: [PATCH] feat(Symbol): remove Symbol for Windows/IE10 - remove spec "properties should provide getter only" BREAKING CHANGE: remove spec "properties should provide getter only" --- src/index.js | 45 +++++++++------------------------------------ test/index.js | 10 ---------- 2 files changed, 9 insertions(+), 46 deletions(-) diff --git a/src/index.js b/src/index.js index f5ed059..2915ae3 100644 --- a/src/index.js +++ b/src/index.js @@ -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 { /** @@ -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 }; } /** @@ -56,7 +29,7 @@ export default class Token { * @returns {this} this */ setType(type) { - this[TYPE] = type; + this.type = type; return this; } @@ -66,7 +39,7 @@ export default class Token { * @returns {this} this */ setValue(value) { - this[VALUE] = value; + this.value = value; return this; } @@ -77,7 +50,7 @@ export default class Token { * @returns {this} this */ setOption(key, value) { - this[OPTS][key] = value; + this.options[key] = value; return this; } @@ -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; } @@ -98,7 +71,7 @@ export default class Token { * @returns {this} this */ setMeta(key, value) { - this[META][key] = value; + this.meta[key] = value; return this; } } diff --git a/test/index.js b/test/index.js index f43eb12..12ece14 100644 --- a/test/index.js +++ b/test/index.js @@ -1,6 +1,5 @@ // dependencies import test from 'ava'; -import { throws } from 'assert-exception'; // target import Token from '../src'; @@ -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 # 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');