Adding documentation to escape.js

This commit is contained in:
Jeff Avallone 2015-04-19 20:49:57 -04:00
parent d8a635fa8f
commit 51c2f87765

View File

@ -1,3 +1,7 @@
// Escape nodes are used for escape sequences. It is rendered as a label with
// the description of the escape and the numeric code it matches when
// appropriate.
import _ from 'lodash'; import _ from 'lodash';
function hex(value) { function hex(value) {
@ -13,6 +17,7 @@ function hex(value) {
export default { export default {
type: 'escape', type: 'escape',
// Renders the escape into the currently set container.
_render() { _render() {
return this.renderLabel(this.label) return this.renderLabel(this.label)
.then(label => { .then(label => {
@ -27,10 +32,15 @@ export default {
setup() { setup() {
var addHex; var addHex;
// The escape code. For an escape such as `\b` it would be "b".
this.code = this.properties.esc.properties.code.textValue; this.code = this.properties.esc.properties.code.textValue;
// The argument. For an escape such as `\xab` it would be "ab".
this.arg = this.properties.esc.properties.arg.textValue; this.arg = this.properties.esc.properties.arg.textValue;
// Retrieves the label, ordinal value, an flag to control adding hex value
// from the escape code mappings
[this.label, this.ordinal, addHex] = _.result(this, this.code); [this.label, this.ordinal, addHex] = _.result(this, this.code);
// When requested, add hex code to the label.
if (addHex) { if (addHex) {
this.label = `${this.label} ${hex(this.ordinal)}`; this.label = `${this.label} ${hex(this.ordinal)}`;
} }