Merge pull request #8250 from wdimac/fix/loop-protect-when-label-offset
Stop inject from mangling label when offset from loop
This commit is contained in:
@ -130,6 +130,7 @@ if (typeof DEBUG === 'undefined') { DEBUG = true; }
|
||||
var ignore = {};
|
||||
var pushonly = {};
|
||||
var labelPostion = null;
|
||||
var labelIndex = -1;
|
||||
|
||||
function insertReset(lineNum, line, matchPosition) {
|
||||
// recompile the line with the reset **just** before the actual loop
|
||||
@ -179,6 +180,7 @@ if (typeof DEBUG === 'undefined') { DEBUG = true; }
|
||||
if (directlyBeforeLoop(index, lineNum, lines)) {
|
||||
DEBUG && debug('- found a label: "' + labelMatch[0] + '"'); // jshint ignore:line
|
||||
labelPostion = lineNum;
|
||||
labelIndex = index;
|
||||
} else {
|
||||
DEBUG && debug('- ignored "label", false positive'); // jshint ignore:line
|
||||
}
|
||||
@ -309,10 +311,11 @@ if (typeof DEBUG === 'undefined') { DEBUG = true; }
|
||||
DEBUG && debug('- reset inserted above matched label on line ' + labelPostion); // jshint ignore:line
|
||||
if (recompiled[labelPostion] === undefined) {
|
||||
labelPostion--;
|
||||
matchPosition = 0;
|
||||
labelIndex = 0;
|
||||
}
|
||||
recompiled[labelPostion] = insertReset(printLineNumber, recompiled[labelPostion], matchPosition);
|
||||
recompiled[labelPostion] = insertReset(printLineNumber, recompiled[labelPostion], labelIndex);
|
||||
labelPostion = null;
|
||||
labelIndex = -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
15
test/public/js/loop-protect-test.js
Normal file
15
test/public/js/loop-protect-test.js
Normal file
@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
let loopProtect = require('../../../public/js/lib/loop-protect/loop-protect');
|
||||
|
||||
let test = require('tape');
|
||||
|
||||
test('LoopProtect injection', function(t) {
|
||||
t.plan(1);
|
||||
|
||||
// Label indented 2 spaces - loop indented three spaces
|
||||
t.true(
|
||||
loopProtect(' loop1:\n while(true) {\n\n}').indexOf('loop1') > 0,
|
||||
'Should keep loop label intact if not lined up with loop.'
|
||||
);
|
||||
});
|
Reference in New Issue
Block a user