Permalink
Browse files

More compact '/' concatnation

  • Loading branch information...
1 parent 3773c72 commit d37058a55b8ead6040696dcfce708739d592fd89 @Constellation Constellation committed Jul 21, 2012
Showing with 14 additions and 10 deletions.
  1. +13 −9 escodegen.js
  2. +1 −1 test/options.js
View
@@ -434,7 +434,7 @@
var leftChar = left.charAt(left.length - 1),
rightChar = right.charAt(0);
- if (((leftChar === '+' || leftChar === '-') && leftChar === rightChar) || (isIdentifierPart(leftChar) && isIdentifierPart(rightChar)) || (leftChar === '/' || rightChar === '/')) {
+ if (((leftChar === '+' || leftChar === '-') && leftChar === rightChar) || (isIdentifierPart(leftChar) && isIdentifierPart(rightChar))) {
return left + ' ' + right;
} else if (isWhiteSpace(leftChar) || isLineTerminator(leftChar) || isWhiteSpace(rightChar) || isLineTerminator(rightChar)) {
return left + right;
@@ -706,14 +706,18 @@
expr.operator
);
- result = join(
- result,
- generateExpression(expr.right, {
- precedence: currentPrecedence + 1,
- allowIn: allowIn,
- allowCall: true
- })
- );
+ fragment = generateExpression(expr.right, {
+ precedence: currentPrecedence + 1,
+ allowIn: allowIn,
+ allowCall: true
+ });
+
+ if (expr.operator === '/' && result.charAt(result.length - 1) === '/') {
+ // If '/' concats with '/', it is interpreted as comment start
+ result += ' ' + fragment;
+ } else {
+ result = join(result, fragment);
+ }
if (expr.operator === 'in' && !allowIn) {
result = '(' + result + ')';
View
@@ -656,7 +656,7 @@ var data = [{
'({})': '({});',
'(function(){})': '(function(){});',
- '/ / / / /': '/ / / / /;'
+ '/ / / / /': '/ // / /;'
}
}, {
options: {

1 comment on commit d37058a

Owner

related #29

Please sign in to comment.