coffee-lex
Advanced tools
Comparing version 8.1.1 to 8.1.2
@@ -24,3 +24,3 @@ "use strict"; | ||
pending.unshift.apply(pending, calculateHeregexpPadding_1.default(source, pending)); | ||
pending.unshift.apply(pending, combinedLocationsForMultiwordOperators(pending, source)); | ||
pending.unshift.apply(pending, combinedLocationsForNegatedOperators(pending, source)); | ||
location = pending.shift(); | ||
@@ -35,23 +35,51 @@ if (previousLocation && previousLocation.type !== SourceType_1.default.SPACE) { | ||
exports.default = lex; | ||
function combinedLocationsForMultiwordOperators(stream, source) { | ||
if (!stream.hasNext(SourceType_1.default.OPERATOR, SourceType_1.default.SPACE, SourceType_1.default.OPERATOR) && | ||
!stream.hasNext(SourceType_1.default.OPERATOR, SourceType_1.default.SPACE, SourceType_1.default.RELATION)) { | ||
function combinedLocationsForNegatedOperators(stream, source) { | ||
if (!stream.hasNext(SourceType_1.default.OPERATOR)) { | ||
return []; | ||
} | ||
var not = stream.shift(); | ||
var space = stream.shift(); | ||
var operator = stream.shift(); | ||
var next = stream.peek(); | ||
if (source.slice(not.index, space.index) === 'not') { | ||
var op = source.slice(operator.index, next.index); | ||
switch (op) { | ||
case 'in': | ||
case 'of': | ||
return [new SourceLocation_1.default(SourceType_1.default.RELATION, not.index)]; | ||
case 'instanceof': | ||
return [new SourceLocation_1.default(SourceType_1.default.OPERATOR, not.index)]; | ||
var locationsToRestore = []; | ||
function shift() { | ||
var location = stream.shift(); | ||
locationsToRestore.push(location); | ||
return location; | ||
} | ||
var not = shift(); | ||
var space = shift(); | ||
var text = source.slice(not.index, space.index); | ||
var operator; | ||
if (text === 'not') { | ||
if (space.type === SourceType_1.default.SPACE) { | ||
// It is a space, so the operator is at the next location. | ||
operator = shift(); | ||
} | ||
else { | ||
// `not` must be followed by a space, so this isn't a match. | ||
return locationsToRestore; | ||
} | ||
} | ||
else if (text === '!') { | ||
if (space.type === SourceType_1.default.SPACE) { | ||
// It is a space, so the operator is at the next location. | ||
operator = shift(); | ||
} | ||
else { | ||
// The optional space is missing, so the next thing must be the operator. | ||
operator = space; | ||
} | ||
} | ||
else { | ||
// Not a negation token, so put them back. | ||
return locationsToRestore; | ||
} | ||
var next = stream.peek(); | ||
var op = source.slice(operator.index, next.index); | ||
switch (op) { | ||
case 'in': | ||
case 'of': | ||
return [new SourceLocation_1.default(SourceType_1.default.RELATION, not.index)]; | ||
case 'instanceof': | ||
return [new SourceLocation_1.default(SourceType_1.default.OPERATOR, not.index)]; | ||
} | ||
// Doesn't match, so put them back. | ||
return [not, space, operator]; | ||
return locationsToRestore; | ||
} | ||
@@ -58,0 +86,0 @@ var REGEXP_FLAGS = ['i', 'g', 'm', 'u', 'y']; |
@@ -39,8 +39,8 @@ { | ||
"@types/node": "^9.3.0", | ||
"decaffeinate-coffeescript": "1.12.7-patch.1", | ||
"decaffeinate-coffeescript": "1.12.7-patch.2", | ||
"mocha": "^5.0.0", | ||
"prettier": "1.10.2", | ||
"prettier": "1.11.0", | ||
"prettier-check": "2.0.0", | ||
"semantic-release": "^6.3.5", | ||
"ts-node": "^4.1.0", | ||
"ts-node": "^5.0.0", | ||
"tslint": "^5.8.0", | ||
@@ -52,3 +52,3 @@ "typescript": "^2.6.2" | ||
}, | ||
"version": "8.1.1" | ||
"version": "8.1.2" | ||
} |
Sorry, the diff of this file is not supported yet
162458
3943