From 4aba7ec1920e2eb8db9ac633f19207921b72eae0 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Thu, 8 Jan 2015 01:00:32 +1100 Subject: [PATCH] fix generation tests and add variable kind length --- lib/6to5/generation/buffer.js | 4 ++-- lib/6to5/generation/generators/statements.js | 5 +++-- .../comments/computed-property-comments-2/expected.js | 3 ++- .../variable-declarator-line-comment/expected.js | 1 + .../variable-declarator-multi-comment/expected.js | 1 + .../harmony-edgecase/yield-precedence/expected.js | 3 ++- .../VariableDeclaration-VariableDeclarator/expected.js | 9 ++++++--- 7 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/6to5/generation/buffer.js b/lib/6to5/generation/buffer.js index fdd53b0659..afd9c4dd23 100644 --- a/lib/6to5/generation/buffer.js +++ b/lib/6to5/generation/buffer.js @@ -14,11 +14,11 @@ Buffer.prototype.get = function () { return util.trimRight(this.buf); }; -Buffer.prototype.getIndent = function (i) { +Buffer.prototype.getIndent = function () { if (this.format.compact) { return ""; } else { - return util.repeat(i || this._indent, this.format.indent.style); + return util.repeat(this._indent, this.format.indent.style); } }; diff --git a/lib/6to5/generation/generators/statements.js b/lib/6to5/generation/generators/statements.js index 959e673ad5..613fdcf630 100644 --- a/lib/6to5/generation/generators/statements.js +++ b/lib/6to5/generation/generators/statements.js @@ -1,4 +1,5 @@ -var t = require("../../types"); +var util = require("../../util"); +var t = require("../../types"); exports.WithStatement = function (node, print) { this.keyword("with"); @@ -169,7 +170,7 @@ exports.VariableDeclaration = function (node, print, parent) { var sep = ","; if (inits > noInits) { // more inits than noinits - sep += "\n" + this.getIndent(2); + sep += "\n" + util.repeat(node.kind.length + 1); } else { sep += " "; } diff --git a/test/fixtures/generation/comments/computed-property-comments-2/expected.js b/test/fixtures/generation/comments/computed-property-comments-2/expected.js index 285ad050f3..1ad3a0f35f 100644 --- a/test/fixtures/generation/comments/computed-property-comments-2/expected.js +++ b/test/fixtures/generation/comments/computed-property-comments-2/expected.js @@ -7,4 +7,5 @@ var test = { * Inside bracket init */ "b"]: "2" -}, ok = 42; +}, + ok = 42; diff --git a/test/fixtures/generation/comments/variable-declarator-line-comment/expected.js b/test/fixtures/generation/comments/variable-declarator-line-comment/expected.js index 39d4b0648a..a7c1703428 100644 --- a/test/fixtures/generation/comments/variable-declarator-line-comment/expected.js +++ b/test/fixtures/generation/comments/variable-declarator-line-comment/expected.js @@ -3,6 +3,7 @@ function test() { // Leading to VariableDeclarator // Leading to VariableDeclarator i = 20, + // Leading to VariableDeclarator // Leading to VariableDeclarator j = 20; diff --git a/test/fixtures/generation/comments/variable-declarator-multi-comment/expected.js b/test/fixtures/generation/comments/variable-declarator-multi-comment/expected.js index 5ef974297b..84354421c2 100644 --- a/test/fixtures/generation/comments/variable-declarator-multi-comment/expected.js +++ b/test/fixtures/generation/comments/variable-declarator-multi-comment/expected.js @@ -5,6 +5,7 @@ function test() { * Leading to VariableDeclarator */ i = 20, + /* * Leading to VariableDeclarator * Leading to VariableDeclarator diff --git a/test/fixtures/generation/harmony-edgecase/yield-precedence/expected.js b/test/fixtures/generation/harmony-edgecase/yield-precedence/expected.js index a693c7a669..302ffe6c55 100644 --- a/test/fixtures/generation/harmony-edgecase/yield-precedence/expected.js +++ b/test/fixtures/generation/harmony-edgecase/yield-precedence/expected.js @@ -1,5 +1,6 @@ function* foo() { - var a = yield wat(), b = 2; + var a = yield wat(), + b = 2; var c = yield a = b; yield a, yield b; yield a = b; diff --git a/test/fixtures/generation/types/VariableDeclaration-VariableDeclarator/expected.js b/test/fixtures/generation/types/VariableDeclaration-VariableDeclarator/expected.js index ede42c53ec..86c14e5b1f 100644 --- a/test/fixtures/generation/types/VariableDeclaration-VariableDeclarator/expected.js +++ b/test/fixtures/generation/types/VariableDeclaration-VariableDeclarator/expected.js @@ -8,6 +8,9 @@ const foo = "foo"; let foo, bar = "bar"; var foo, bar = "bar"; -let foo = "foo", bar = "bar"; -var foo = "foo", bar = "bar"; -const foo = "foo", bar = "bar"; +let foo = "foo", + bar = "bar"; +var foo = "foo", + bar = "bar"; +const foo = "foo", + bar = "bar";