Permalink
Browse files

Merge pull request #310 from WolfgangKluge/281-lastsemic-white

White option and single line blocks
  • Loading branch information...
2 parents 178a3ff + e45de26 commit 4278a6c0b537f879ecbfa25486041a5cbbdd5d4f @valueof valueof committed Oct 25, 2011
Showing with 20 additions and 8 deletions.
  1. +11 −7 jshint.js
  2. +9 −1 tests/fixtures/white.js
View
@@ -2405,15 +2405,15 @@ loop: for (;;) {
}
- function statements(begin) {
+ function statements(startLine) {
var a = [], f, p;
while (!nexttoken.reach && nexttoken.id !== '(end)') {
if (nexttoken.id === ';') {
warning("Unnecessary semicolon.");
advance(';');
} else {
- a.push(statement());
+ a.push(statement(startLine === nexttoken.line));
}
}
return a;
@@ -2433,7 +2433,8 @@ loop: for (;;) {
old_indent = indent,
m = strict_mode,
s = scope,
- t;
+ t,
+ line;
inblock = ordinary;
if (!ordinary || !option.funcscope) scope = Object.create(scope);
@@ -2442,7 +2443,8 @@ loop: for (;;) {
if (nexttoken.id === '{') {
advance('{');
- if (nexttoken.id !== '}' || token.line !== nexttoken.line) {
+ line = token.line;
+ if (nexttoken.id !== '}' || line !== nexttoken.line) {
indent += option.indent;
while (!ordinary && nexttoken.from > indent) {
indent += option.indent;
@@ -2451,10 +2453,12 @@ loop: for (;;) {
funct['(context)']['(global)']) {
warning("Missing \"use strict\" statement.");
}
- a = statements();
+ a = statements(line);
strict_mode = m;
indent -= option.indent;
- indentation();
+ if (line !== nexttoken.line) {
+ indentation();
+ }
}
advance('}', t);
indent = old_indent;
@@ -3869,7 +3873,7 @@ loop: for (;;) {
use_strict();
}
- statements('lib');
+ statements();
}
advance('(end)');
} catch (e) {
View
@@ -36,4 +36,12 @@ function test2(a, b, c, d) {
while (a) return;
while (a)
return;
-}
+}
+
+/*fix for indentation on single-line blocks*/
+var name1 = (function () { var x = 2; return 'Anton'; }());
+
+/*unfortunately (as a side effect), this is also allowed*/
+var name2 = (function () { var x = 2;
+ return 'Anton';
+ }());

0 comments on commit 4278a6c

Please sign in to comment.