Skip to content

Commit

Permalink
consistent variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed Apr 4, 2019
1 parent 1900dfa commit 6bddb8e
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 42 deletions.
38 changes: 19 additions & 19 deletions packages/moon/dist/moon.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @returns Value or default value
*/

function defaultValue(value, fallback) {
function valueDefault(value, fallback) {
return value === undefined ? fallback : value;
}
/**
Expand Down Expand Up @@ -126,22 +126,22 @@
var _char = input[i];

if (_char === "<") {
var nextChar = input[i + 1];
var charNext = input[i + 1];

if (nextChar === "/") {
if (charNext === "/") {
// Append a closing tag token if a sequence of characters begins
// with "</".
var closeIndex = input.indexOf(">", i + 2);
var indexClose = input.indexOf(">", i + 2);

var _type = input.slice(i + 2, closeIndex);
var _type = input.slice(i + 2, indexClose);

tokens.push({
type: "tagClose",
value: _type
});
i = closeIndex + 1;
i = indexClose + 1;
continue;
} else if (nextChar === "!" && input[i + 2] === "-" && input[i + 3] === "-") {
} else if (charNext === "!" && input[i + 2] === "-" && input[i + 3] === "-") {
// Ignore input if a sequence of characters begins with "<!--".
i = input.indexOf("-->", i + 4) + 3;
continue;
Expand Down Expand Up @@ -324,21 +324,21 @@


function parseElement(start, end, tokens) {
var firstToken = tokens[start];
var lastToken = tokens[end - 1];
var tokenFirst = tokens[start];
var tokenLast = tokens[end - 1];
var length = end - start;

if (length === 0) {
// Return an error because this parser does not accept empty inputs.
return new ParseError("development" === "development" ? "Parser expected an element but received nothing." : "", start, end);
} else if (length === 1) {
// The next alternate only matches on inputs with one token.
if (firstToken.type === "tagOpen" && firstToken.closed === true) {
if (tokenFirst.type === "tagOpen" && tokenFirst.closed === true) {
// Verify that the single token is a self-closing tag, and return a
// new element without children.
return {
type: firstToken.value,
attributes: firstToken.attributes,
type: tokenFirst.value,
attributes: tokenFirst.attributes,
children: []
};
} else {
Expand All @@ -347,7 +347,7 @@
} else {
// If the input size is greater than one, it must be a full element with
// both opening and closing tags that match.
if (firstToken.type === "tagOpen" && lastToken.type === "tagClose" && firstToken.value === lastToken.value) {
if (tokenFirst.type === "tagOpen" && tokenLast.type === "tagClose" && tokenFirst.value === tokenLast.value) {
// Attempt to parse the inner contents as children. They must be valid
// for the element parse to succeed.
var children = parseElements(start + 1, end - 1, tokens);
Expand All @@ -356,8 +356,8 @@
return new ParseError("development" === "development" ? "Parser expected valid child elements but encountered an error." : "", start, end, children);
} else {
return {
type: firstToken.value,
attributes: firstToken.attributes,
type: tokenFirst.value,
attributes: tokenFirst.attributes,
children: children
};
}
Expand Down Expand Up @@ -729,7 +729,7 @@

MoonComponent.prototype = data; // Handle the optional `name` parameter.

data.name = defaultValue(data.name, "Root"); // Ensure the view is defined, and compile it if needed.
data.name = valueDefault(data.name, "Root"); // Ensure the view is defined, and compile it if needed.

var view = data.view;

Expand All @@ -744,9 +744,9 @@
data.view = view; // Create default events at the beginning so that checks before calling them
// aren't required.

data.onCreate = defaultValue(data.onCreate, noop);
data.onUpdate = defaultValue(data.onUpdate, noop);
data.onDestroy = defaultValue(data.onDestroy, noop); // If a `root` option is given, create a new instance and mount it, or else
data.onCreate = valueDefault(data.onCreate, noop);
data.onUpdate = valueDefault(data.onUpdate, noop);
data.onDestroy = valueDefault(data.onDestroy, noop); // If a `root` option is given, create a new instance and mount it, or else
// just return the constructor.

var root = data.root;
Expand Down
12 changes: 6 additions & 6 deletions packages/moon/src/compiler/lexer/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,24 @@ export function lex(input) {
const char = input[i];

if (char === "<") {
const nextChar = input[i + 1];
const charNext = input[i + 1];

if (nextChar === "/") {
if (charNext === "/") {
// Append a closing tag token if a sequence of characters begins
// with "</".

const closeIndex = input.indexOf(">", i + 2);
const type = input.slice(i + 2, closeIndex);
const indexClose = input.indexOf(">", i + 2);
const type = input.slice(i + 2, indexClose);

tokens.push({
type: "tagClose",
value: type
});

i = closeIndex + 1;
i = indexClose + 1;
continue;
} else if (
nextChar === "!" &&
charNext === "!" &&
input[i + 2] === "-" &&
input[i + 3] === "-"
) {
Expand Down
22 changes: 11 additions & 11 deletions packages/moon/src/compiler/parser/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ function parseElements(start, end, tokens) {
* @returns {Object} Abstract syntax tree or ParseError
*/
function parseElement(start, end, tokens) {
const firstToken = tokens[start];
const lastToken = tokens[end - 1];
const tokenFirst = tokens[start];
const tokenLast = tokens[end - 1];
const length = end - start;

if (length === 0) {
Expand All @@ -101,14 +101,14 @@ function parseElement(start, end, tokens) {
} else if (length === 1) {
// The next alternate only matches on inputs with one token.
if (
firstToken.type === "tagOpen" &&
firstToken.closed === true
tokenFirst.type === "tagOpen" &&
tokenFirst.closed === true
) {
// Verify that the single token is a self-closing tag, and return a
// new element without children.
return {
type: firstToken.value,
attributes: firstToken.attributes,
type: tokenFirst.value,
attributes: tokenFirst.attributes,
children: []
};
} else {
Expand All @@ -124,9 +124,9 @@ function parseElement(start, end, tokens) {
// If the input size is greater than one, it must be a full element with
// both opening and closing tags that match.
if (
firstToken.type === "tagOpen" &&
lastToken.type === "tagClose" &&
firstToken.value === lastToken.value
tokenFirst.type === "tagOpen" &&
tokenLast.type === "tagClose" &&
tokenFirst.value === tokenLast.value
) {
// Attempt to parse the inner contents as children. They must be valid
// for the element parse to succeed.
Expand All @@ -143,8 +143,8 @@ function parseElement(start, end, tokens) {
);
} else {
return {
type: firstToken.value,
attributes: firstToken.attributes,
type: tokenFirst.value,
attributes: tokenFirst.attributes,
children
};
}
Expand Down
10 changes: 5 additions & 5 deletions packages/moon/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { parse } from "./compiler/parser/parser";
import { generate } from "./compiler/generator/generator";
import { compile } from "./compiler/compiler";
import { components } from "./component/components";
import { defaultValue, error, noop } from "./util/util";
import { error, noop, valueDefault } from "./util/util";

/**
* Moon
Expand Down Expand Up @@ -49,7 +49,7 @@ export default function Moon(data) {
MoonComponent.prototype = data;

// Handle the optional `name` parameter.
data.name = defaultValue(data.name, "Root");
data.name = valueDefault(data.name, "Root");

// Ensure the view is defined, and compile it if needed.
let view = data.view;
Expand All @@ -66,9 +66,9 @@ export default function Moon(data) {

// Create default events at the beginning so that checks before calling them
// aren't required.
data.onCreate = defaultValue(data.onCreate, noop);
data.onUpdate = defaultValue(data.onUpdate, noop);
data.onDestroy = defaultValue(data.onDestroy, noop);
data.onCreate = valueDefault(data.onCreate, noop);
data.onUpdate = valueDefault(data.onUpdate, noop);
data.onDestroy = valueDefault(data.onDestroy, noop);

// If a `root` option is given, create a new instance and mount it, or else
// just return the constructor.
Expand Down
2 changes: 1 addition & 1 deletion packages/moon/src/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function noop() {}
* @param fallback
* @returns Value or default value
*/
export function defaultValue(value, fallback) {
export function valueDefault(value, fallback) {
return value === undefined ? fallback : value;
}

Expand Down

0 comments on commit 6bddb8e

Please sign in to comment.