Skip to content

Commit

Permalink
fix SyntaxError: "Unexpected token (" on "https://staging-edit.merid…
Browse files Browse the repository at this point in the history
…ianapps.com/login"` (close #1101) (#1102)

* fix `SyntaxError: "Unexpected token (" on "https://staging-edit.meridianapps.com/login"` (close #1101)

* fix second issue
  • Loading branch information
LavrovArtem authored and churkin committed Apr 26, 2017
1 parent cf0b199 commit 4e2b758
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/processing/script/transformers/location-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export default {
node.left.type === Syntax.Identifier &&
node.left.name === 'location',

run: (node, parent, key) => createLocationSetWrapper(node.right, key !== 'arguments' &&
parent.type !== Syntax.SequenceExpression)
run: (node, parent, key) => {
var wrapWithSequence = key !== 'arguments' && key !== 'consequent' && key !== 'alternate' &&
(parent.type !== Syntax.SequenceExpression || parent.expressions[0] === node);

return createLocationSetWrapper(node.right, wrapWithSequence);
}
};
28 changes: 26 additions & 2 deletions test/server/script-processor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,38 @@ describe('Script processor', function () {
{
src: 'new function(a){location=str,a.click();}();',

expected: 'new function(a) {(function(){return__set$Loc(location,str)||' +
'(location=str);}.call(this), a.click());}();'
expected: 'new function(a) {(0,function(){return__set$Loc(location,str)||' +
'(location=str);}.call(this)), a.click();}();'
},
{
src: 'b.onerror = b.onload = function (a) { location = a; };',

expected: '__set$(b,"onerror",__set$(b,"onload",function(a){' +
'0,function(){return__set$Loc(location,a)||(location=a);}.call(this);}));'
},
{
src: 'location = newLocation, x = 5;',

expected: '0,function(){return __set$Loc(location,newLocation)||(location=newLocation);}.call(this), x = 5;'
},
{
src: 'x = 5, location = newLocation;',

expected: 'x = 5, function(){return __set$Loc(location,newLocation)||(location=newLocation);}.call(this);'
},
{
src: 'location ? location = newLocation : location = "#123";',

expected: '__get$Loc(location)' +
'? function(){return __set$Loc(location,newLocation)||(location=newLocation);}.call(this)' +
': function(){return __set$Loc(location,"#123")||(location="#123");}.call(this);'
},
{
src: 'if (location) { location = newLocation; } else location = "#123";',

expected: 'if (__get$Loc(location)) {' +
'0,function(){return __set$Loc(location,newLocation)||(location=newLocation);}.call(this);}' +
'else 0,function(){return __set$Loc(location,"#123")||(location="#123");}.call(this);'
}
]);
});
Expand Down

0 comments on commit 4e2b758

Please sign in to comment.