Skip to content

Commit

Permalink
fix: treat increment and decrement ops as non-repeatable
Browse files Browse the repository at this point in the history
  • Loading branch information
alangpierce committed Feb 27, 2017
1 parent 57fda31 commit e0151b0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/stages/main/index.js
Expand Up @@ -27,6 +27,7 @@ import FunctionApplicationPatcher from './patchers/FunctionApplicationPatcher';
import FunctionPatcher from './patchers/FunctionPatcher';
import HeregexPatcher from './patchers/HeregexPatcher';
import IdentifierPatcher from './patchers/IdentifierPatcher';
import IncrementDecrementPatcher from './patchers/IncrementDecrementPatcher';
import InOpPatcher from './patchers/InOpPatcher';
import InstanceofOpPatcher from './patchers/InstanceofOpPatcher';
import JavaScriptPatcher from './patchers/JavaScriptPatcher';
Expand Down Expand Up @@ -87,10 +88,6 @@ export default class MainStage extends TransformCoffeeScriptStage {
case 'Float':
case 'Null':
case 'Undefined':
case 'PostIncrementOp':
case 'PostDecrementOp':
case 'PreIncrementOp':
case 'PreDecrementOp':
case 'Quasi':
return PassthroughPatcher;

Expand Down Expand Up @@ -120,6 +117,12 @@ export default class MainStage extends TransformCoffeeScriptStage {
case 'GTEOp':
return EqualityPatcher;

case 'PostIncrementOp':
case 'PostDecrementOp':
case 'PreIncrementOp':
case 'PreDecrementOp':
return IncrementDecrementPatcher;

case 'ObjectInitialiserMember':
return ObjectInitialiserMemberPatcher;

Expand Down
23 changes: 23 additions & 0 deletions src/stages/main/patchers/IncrementDecrementPatcher.js
@@ -0,0 +1,23 @@
import NodePatcher from '../../../patchers/NodePatcher';
import type { PatcherContext } from '../../../patchers/types';

export default class IncrementDecrementPatcher extends NodePatcher {
expression: NodePatcher;

constructor(patcherContext: PatcherContext, expression: NodePatcher) {
super(patcherContext);
this.expression = expression;
}

initialize() {
this.expression.setRequiresExpression();
}

patchAsExpression() {
this.expression.patch();
}

isRepeatable() {
return false;
}
}
9 changes: 9 additions & 0 deletions test/unary_operator_test.js
@@ -1,4 +1,5 @@
import check from './support/check';
import validate from './support/validate';

describe('unary operators', () => {
it('passes unary minus through', () => {
Expand Down Expand Up @@ -113,4 +114,12 @@ describe('unary operators', () => {
}
`);
});

it('treats the increment operator as non-repeatable', () => {
validate(`
n = 1
(n++)?.toString()
o = n
`, 2);
});
});

0 comments on commit e0151b0

Please sign in to comment.