-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
196 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,4 @@ | ||
**/coverage/ | ||
**/dist/ | ||
**/test/specs/expect/ | ||
**/test/specs/fixtures/ | ||
**/test/specs/parsers/js/ | ||
**/test/v223/ | ||
**/test/perf.js | ||
**/test/ | ||
!/test/runner.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
Regex detection. | ||
From: https://github.com/riot/parser/blob/master/src/skip-regex.js | ||
*/ | ||
//#if NODE | ||
'use strict' | ||
//#endif | ||
//#if 0 | ||
/* eslint no-unused-vars: [2, {args: "after-used", varsIgnorePattern: "^skipRegex"}] */ | ||
//#endif | ||
|
||
var skipRegex = (function () { | ||
|
||
// safe characters to precced a regex (including `=>`, `**`, and `...`) | ||
var beforeReChars = '[{(,;:?=|&!^~>%*/' | ||
|
||
// keyword that can preceed a regex (`in` is handled as special case) | ||
var beforeReWords = [ | ||
'case', | ||
'default', | ||
'do', | ||
'else', | ||
'in', | ||
'instanceof', | ||
'prefix', | ||
'return', | ||
'typeof', | ||
'void', | ||
'yield' | ||
] | ||
|
||
var wordsLastChar = beforeReWords.reduce(function (s, w) { | ||
return s + w.slice(-1) | ||
}, '') | ||
|
||
// The string to test can't include line-endings | ||
var RE_REGEX = /^\/(?=[^*>/])[^[/\\]*(?:(?:\\.|\[(?:\\.|[^\]\\]*)*\])[^[\\/]*)*?\/[gimuy]*/ | ||
var RE_VN_CHAR = /[$\w]/ | ||
|
||
// Searches the position of the previous non-blank character inside `code`, | ||
// starting with `pos - 1`. | ||
function prev (code, pos) { | ||
while (--pos >= 0 && /\s/.test(code[pos])); | ||
return pos | ||
} | ||
|
||
/** | ||
* Check if the code in the `start` position can be a regex. | ||
* | ||
* @param {string} code - Buffer to test in | ||
* @param {number} start - Position the first slash inside `code` | ||
* @returns {number} position of the char following the regex. | ||
*/ | ||
function _skipRegex (code, start) { | ||
|
||
// `exec()` will extract from the slash to the end of line and the | ||
// chained `match()` will match the possible regex. | ||
var re = /.*/g | ||
var pos = re.lastIndex = start++ | ||
var match = re.exec(code)[0].match(RE_REGEX) | ||
|
||
if (match) { | ||
var next = pos + match[0].length // result is not from `re.exec` | ||
|
||
pos = prev(code, pos) | ||
var c = code[pos] | ||
|
||
// start of buffer or safe prefix? | ||
if (pos < 0 || ~beforeReChars.indexOf(c)) { | ||
return next | ||
} | ||
|
||
// from here, `pos` is >= 0 and `c` is code[pos] | ||
// is-tanbul ignore next: This is for ES6 | ||
if (c === '.') { | ||
// can be `...` or something silly like 5./2 | ||
if (code[pos - 1] === '.') { | ||
start = next | ||
} | ||
|
||
} else if (c === '+' || c === '-') { | ||
// tricky case | ||
if (code[--pos] !== c || // if have a single operator or | ||
(pos = prev(code, pos)) < 0 || // ...have `++` and no previous token or | ||
!RE_VN_CHAR.test(code[pos])) { // ...the token is not a JS var/number | ||
start = next // ...this is a regex | ||
} | ||
|
||
} else if (~wordsLastChar.indexOf(c)) { | ||
// keyword? | ||
var end = pos + 1 | ||
|
||
while (--pos >= 0 && RE_VN_CHAR.test(code[pos])); | ||
if (~beforeReWords.indexOf(code.slice(pos + 1, end))) { | ||
start = next | ||
} | ||
} | ||
} | ||
|
||
return start | ||
} | ||
|
||
return _skipRegex | ||
|
||
})() | ||
|
||
//#if NODE | ||
module.exports = skipRegex | ||
//#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
riot.tag2('my-tag', '<div>{(2+3)/2}</div> <hr>', '', '', function(opts){ | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// riot/riot#2369 | ||
riot.tag2('my-tag', '<h1>{getSpaceName(message)}</h1>', '', '', function(opts) { | ||
this.message = 'display/example/stuff' | ||
this.getSpaceNameForLink = function(link) { | ||
|
||
return link.match(/display\/(\w+)\//)[1] | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<my-tag> | ||
<div>{ (2+3)/2 }</div> | ||
<hr/> | ||
</my-tag> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// riot/riot#2369 | ||
<my-tag> | ||
<h1>{ getSpaceName(message) }</h1> | ||
|
||
<script> | ||
this.message = 'display/example/stuff' | ||
this.getSpaceNameForLink = function(link) { | ||
|
||
return link.match(/display\/(\w+)\//)[1] | ||
} | ||
</script> | ||
</my-tag> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters