Fix PaperScript#compile() with prefix operators

Closes #1611
This commit is contained in:
sasensi 2018-11-23 11:54:42 +01:00 committed by Jürg Lehni
parent aca3059814
commit 80131f0398
3 changed files with 27 additions and 0 deletions

View file

@ -268,6 +268,11 @@ Base.exports.PaperScript = function() {
str = exp;
str = arg + '; ' + str;
}
// If this is a prefixed update expression (++a / --a),
// wrap expression in IIFE to avoid several bugs (#1450)
if (node.prefix) {
str = '(function(){return '+str+';})()';
}
replaceCode(node, str);
} else { // AssignmentExpression
if (/^.=$/.test(node.operator)

20
test/tests/PaperScript.js Normal file
View file

@ -0,0 +1,20 @@
/*
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/
QUnit.module('PaperScript');
test('PaperScript#compile() with prefix increment/decrement operators', function() {
var code = 'var x = 1; var y = 1 * --x;';
var compiled = PaperScript.compile(code, paper);
PaperScript.execute(compiled, paper);
expect(0);
});

View file

@ -63,6 +63,8 @@
/*#*/ include('Numerical.js');
/*#*/ include('PaperScript.js');
// There is no need to test interactions in node context.
if (!isNodeContext) {
/*#*/ include('Interactions.js');