Skip to content

Commit

Permalink
Fix #40
Browse files Browse the repository at this point in the history
  • Loading branch information
felix9 committed Aug 31, 2017
1 parent 5f0158e commit 815e4a8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/compiler.js
Expand Up @@ -11,7 +11,7 @@ function compile(nodes) {

function reduce(nodes) {
var node;
for (var i in nodes) {
for (var i = 0; i < nodes.length; i++) {
node = nodes[i];
switch (node.type) {
case "Assign":
Expand Down Expand Up @@ -133,24 +133,22 @@ function compile(nodes) {
// If `a` or `b` are arrays and have items in them, the last item in the
// array is used as the context for the next sub-path.
function deepRef(start, keys, value, line, column) {
var key;
var traversed = [];
var traversedPath = "";
var path = keys.join(".");
var ctx = start;
var keysLen = keys.length;

for (var i in keys) {
key = keys[i];
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
traversed.push(key);
traversedPath = traversed.join(".");
if (typeof ctx[key] === "undefined") {
if (i === String(keysLen - 1)) {
if (i === keys.length - 1) {
ctx[key] = value;
} else {
ctx[key] = {};
}
} else if (i !== keysLen - 1 && valueAssignments.indexOf(traversedPath) > -1) {
} else if (i !== keys.length - 1 && valueAssignments.indexOf(traversedPath) > -1) {
// already a non-object value at key, can't be used as part of a new path
genError("Cannot redefine existing key '" + traversedPath + "'.", line, column);
}
Expand All @@ -167,7 +165,7 @@ function compile(nodes) {
function reduceArrayWithTypeChecking(array) {
// Ensure that all items in the array are of the same type
var firstType = null;
for(var i in array) {
for (var i = 0; i < array.length; i++) {
var node = array[i];
if (firstType === null) {
firstType = node.type;
Expand Down
4 changes: 4 additions & 0 deletions test/table_arrays_hard.toml
@@ -1,3 +1,7 @@
[[fruit]]
name = "durian"
variety = []

[[fruit]]
name = "apple"

Expand Down
4 changes: 4 additions & 0 deletions test/test_toml.js
Expand Up @@ -71,6 +71,10 @@ var easyTableArrayExpected = {

var hardTableArrayExpected = {
"fruit": [
{
"name": "durian",
"variety": []
},
{
"name": "apple",
"physical": {
Expand Down

0 comments on commit 815e4a8

Please sign in to comment.