Skip to content

Commit

Permalink
updated: dev dependencies and small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
GianlucaGuarini committed Sep 19, 2017
1 parent c83db80 commit 5c1d1e8
Show file tree
Hide file tree
Showing 11 changed files with 2,339 additions and 223 deletions.
165 changes: 1 addition & 164 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,164 +1 @@
###########################################################################
# #
# Revised by aMarCruz - 2016-01-06 #
# Follow most of rules from http://standardjs.com/ #
# 2016-01-19: use 1tbs style for blocks, like in the riot core #
# 2016-03-05: revised for eslint v2.2, disallow conditional assign #
# 2016-03-10: allows conditional assigns, shadowing vars in the upper #
# scope, and the creation of functions within loops. #
# 2016-03-11: Don't require empty line after variable declarations #
# #
###########################################################################

root: true

###########################################################################
# ENVIRONMENT #
###########################################################################

env:
node: true
es6: true

parserOptions:
sourceType: "module"
ecmaVersion: 6
ecmaFeatures:
impliedStrict: true

###########################################################################
# GLOBALS #
###########################################################################

globals:
riot: false

###########################################################################
# RECOMMENDED PRESET - mainly for possible errors #
###########################################################################

extends:
"eslint:recommended" # See https://github.com/eslint/eslint/blob/master/conf/eslint.json

###########################################################################
# RULES - omitted defaults and rules in eslint:recommended #
###########################################################################

rules:
#
# POSSIBLE ERRORS
#
no-cond-assign: 0 # core riot style
no-extra-parens: [2, "all", {"conditionalAssign": false}] # disallow extra parens, except for conditional assign
valid-jsdoc: [2, { "prefer": { "return": "returns" }, "requireReturn": false, "requireReturnDescription": false }]
#
# BEST PRACTICES
#
block-scoped-var: 2 # treat var statements as if they were block scoped (Default: 0)
complexity: [1, 16] # specify the maximum cyclomatic complexity allowed in a program (Default [0, 11])
curly: [2, "multi-line"] # require curly braces for multiline control statements only
dot-location: [2, "property"] # dot in a member expression should be on the same line as the property
dot-notation: 1 # encourages use of dot notation whenever possible (Default: [0, { "allowKeywords": true }])
eqeqeq: [2, "smart"] # require the use of === and !== (Default: 0)
guard-for-in: 1 # make sure for-in loops have an if statement (Default: 0)
no-alert: 2 # disallow the use of alert, confirm, and prompt (Default: 0)
no-caller: 2 # disallow use of arguments.caller or arguments.callee (Default: 0)
no-div-regex: 2 # disallow division operators explicitly at beginning of regular expression (Default: 0)
no-else-return: 1 # disallow else after a return in an if
no-eval: 2 # disallow use of eval() (Default: 0)
no-extend-native: 2 # disallow adding to native types (Default: 0)
no-extra-bind: 2 # disallow unnecessary function binding (Default: 0)
no-floating-decimal: 2 # disallow the use of leading or trailing decimal points in numeric literals (Default: 0)
no-implied-eval: 2 # disallow use of eval()-like methods (Default: 0)
no-invalid-this: 2 # disallow this keywords outside of classes or class-like objects
no-iterator: 2 # disallow usage of __iterator__ property (Default: 0)
no-labels: 2 # disallow use of labeled statements (Default: 0)
no-lone-blocks: 2 # disallow unnecessary nested blocks (Default: 0)
no-multi-str: 2 # disallow use of multiline strings (Default: 0)
no-native-reassign: 2 # disallow reassignments of native objects (Default: 0)
no-new: 2 # disallow use of new operator when not part of the assignment or comparison (Default: 0)
no-new-func: 2 # disallow use of new operator for Function object
no-new-wrappers: 2 # disallow creating new instances of String, Number, and Boolean (Default: 0)
no-octal-escape: 2 # disallow use of octal escape sequences in string literals, such as `"Copyright \251"` (Default: 0)
no-proto: 2 # disallow usage of __proto__ property (Default: 0)
no-return-assign: 1 # disallow use of assignment in return statement (Default: 0)
no-script-url: 2 # disallow use of javascript urls (Default: 0)
no-self-compare: 2 # disallow comparisons where both sides are exactly the same (Default: 0)
no-sequences: 2 # disallow use of comma operator (Default: 0)
no-throw-literal: 2 # restrict what can be thrown as an exception
no-unused-expressions: 1 # disallow usage of expressions in statement position (Default: 0)
no-useless-call: 1 # disallow unnecessary .call() and .apply()
no-void: 2 # disallow use of void operator (Default: 0)
no-with: 2 # disallow use of the with statement (Default: 0)
radix: 2 # require use of the second argument for parseInt() (Default: 0)
wrap-iife: [2, "inside"] # require immediate function invocation to be wrapped in parentheses (Default: 0)
yoda: [2, "never"] # require or disallow Yoda conditions (Default: 0)
#
# STRICT MODE
#
#strict: 2 # require strict mode
#
# VARIABLES
#
no-catch-shadow: 2 # disallow the catch clause parameter name being the same as a variable in the outer scope
no-label-var: 2 # disallow labels that share a name with a variable (Default: 0)
no-shadow-restricted-names: 2 # disallow shadowing of names such as arguments (Default: 0)
# no-undef: 1 # disallow use of undeclared variables unless mentioned in a /*global */ block (Default: 2)
no-undef-init: 2 # disallow use of undefined when initializing variables (Default: 0)
# no-unused-vars: 1 # disallow declaration of variables that are not used in the code (Default: [2, {"vars": "all", "args": "after-used"}])
no-use-before-define: [2, "nofunc"] # disallow use of variables before they are defined (Default: 0)
#
# NODE.JS AND COMMONJS
#
handle-callback-err: 2 # enforces error handling in callbacks
no-mixed-requires: 2 # disallow mixing regular variable and require declarations
no-new-require: 2 # disallow use of new operator with the require function (Default: 0)
no-path-concat: 2 # disallow string concatenation with __dirname and __filename (Default: 0)
#
# STYLISTIC ISSUES
#
array-bracket-spacing: 2 # disallow spaces inside of brackets (Default: [0, "never"])
brace-style: [1, "1tbs", { "allowSingleLine": true }]
# require Stroustrup style: `else` must be on its own line (Default: [0, '1tbs'])
camelcase: [2, { "properties": "always" }]
# require camel case names (Default: 0)
comma-spacing: 2 # enforce spacing before and after comma (Default: 0)
comma-style: 2 # enforce one true comma style (Default: [0, "last"])
computed-property-spacing: [2, "never"]
# disallow spaces inside of computed properties
consistent-this: [2, "self"] # enforces consistent naming when capturing the current execution context
eol-last: 2 # enforce newline at the end of file, with no multiple empty lines
indent: [2, 2, { "SwitchCase": 1 }] # set a specific tab width and case indentation (Default: 0)
key-spacing: 2 # enforces spacing between keys and values in object literal properties
# (Default: [0, { "beforeColon": false, "afterColon": true }])
keyword-spacing: 2 # enforce spacing before and after keywords
linebreak-style: [2, "unix"]
max-depth: [1, 5] # specify the maximum depth blocks can be nested
max-len: [1, 96, 4, { "ignoreTrailingComments": true, "ignoreUrls": true, "ignorePattern": "=\\s+/|_regEx\\(|RegExp\\(" }]
no-control-regex: 1
# maximum line length, except for regexes
max-nested-callbacks: [2, 4] # specify the maximum depth callbacks can be nested (Default: [0, 2])
new-cap: 2 # require a capital letter for constructors (Default: 0)
new-parens: 2 # disallow the omission of parentheses when invoking a constructor with no arguments (Default: 0)
no-array-constructor: 2 # disallow use of the Array constructor (Default: 0)
no-lonely-if: 2 # disallow if as the only statement in an else block
no-multiple-empty-lines: [2, {"max": 2}]
# disallow multiple empty lines
no-new-object: 2 # disallow use of the Object constructor (Default: 0)
no-restricted-syntax: [2, "WithStatement"] # disallow use of `with` statements in code
no-spaced-func: 2 # disallow space between function identifier and application (Default: 0)
no-trailing-spaces: 2 # disallow trailing whitespace at the end of lines (Default: 0)
no-unneeded-ternary: 2 # disallow the use of ternary operators when a simpler alternative exists
operator-linebreak: 2 # [2, "after", { "overrides": { "?": "before" } }]
quote-props: [2, "as-needed"] # require quotes around object literal property names only if needed
quotes: [2, "single", "avoid-escape"]
# specify whether double or single quotes should be used (Default: [0, "double"])
semi-spacing: 2 # prevents the use of spaces before a semicolon in expressions
semi: [2, "never"] # require or disallow use of semicolons instead of ASI (Default: 0)
space-before-blocks: 2 # require a space before blocks (Default: [0, "always"])
space-before-function-paren: 2 # require a space before function parenthesis (Default: [0, "always"])
space-in-parens: 2 # require spaces inside parentheses (Default: [0, "never"])
space-infix-ops: [2, {"int32Hint": false}]
# require spaces around infix operators, expect for `var|0` (Default: 0)
space-unary-ops: 2 # require spaces after new, delete, typeof, void, yield, disallow spaces for ++, --, etc
object-curly-spacing: [2, "always", { "objectsInObjects": false }] # require spaces inside brackets
extends: eslint-config-riot
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Compiler Changes

### v3.2.5
- Update dependencies and refactor some internal code avoiding bitwise operators
- Fix coffeescript parser require https://github.com/riot/compiler/pull/102

### v3.2.4
- Fix [riot#2369](https://github.com/riot/riot/issues/2369) : Possible bug involving compilation of tags containing regex.
- Using the `skip-regex` function from npm for sharing bwteen modules (at future).
Expand Down
8 changes: 4 additions & 4 deletions lib/brackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var skipRegex = require('skip-regex')
* @const {RegExp}
* @static
*/
var R_MLCOMMS = /\/\*[^*]*\*+(?:[^*\/][^*]*\*+)*\//g
var R_MLCOMMS = /\/\*[^*]*\*+(?:[^*/][^*]*\*+)*\//g

/**
* Matches single and double quoted strings. Don't care about inner EOLs, so it
Expand All @@ -33,8 +33,8 @@ var R_STRINGS = /"[^"\\]*(?:\\[\S\s][^"\\]*)*"|'[^'\\]*(?:\\[\S\s][^'\\]*)*'|`[^
* @static
*/
var S_QBLOCKS = R_STRINGS.source + '|' +
/(?:\breturn\s+|(?:[$\w\)\]]|\+\+|--)\s*(\/)(?![*\/]))/.source + '|' +
/\/(?=[^*\/])[^[\/\\]*(?:(?:\[(?:\\.|[^\]\\]*)*\]|\\.)[^[\/\\]*)*?([^<]\/)[gim]*/.source
/(?:\breturn\s+|(?:[$\w)\]]|\+\+|--)\s*(\/)(?![*/]))/.source + '|' +
/\/(?=[^*/])[^[/\\]*(?:(?:\[(?:\\.|[^\]\\]*)*\]|\\.)[^[/\\]*)*?([^<]\/)[gim]*/.source

/*
JS/ES6 quoted strings and start of regex (basic ES6 does not supports nested backquotes).
Expand Down Expand Up @@ -172,7 +172,7 @@ module.exports.split = function split (str, _, _bp) {
if (!match[1]) { // ignore it if have an escape char
unescapeStr(str.slice(start, pos)) // push part, even if empty
start = re.lastIndex // next position is the new start
re = _bp[6 + (isexpr ^= 1)] // switch mode and swap regexp
re = _bp[6 + (isexpr = !isexpr)] // switch mode and swap regexp
re.lastIndex = start // update the regex pointer
}
}
Expand Down
46 changes: 23 additions & 23 deletions lib/compiler.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* The riot-compiler v3.2.4
* The riot-compiler WIP
*
* @module compiler
* @version v3.2.4
* @version WIP
* @license MIT
* @copyright Muut Inc. + contributors
*/
Expand Down Expand Up @@ -59,7 +59,7 @@ var HTML_COMMS = RegExp(/<!--(?!>)[\S\s]*?-->/.source + '|' + S_LINESTR, 'g')
* {@link module:compiler~parseAttribs|parseAttribs}
* @const {RegExp}
*/
var HTML_TAGS = /<(-?[A-Za-z][-\w\xA0-\xFF]*)(?:\s+([^"'\/>]*(?:(?:"[^"]*"|'[^']*'|\/[^>])[^'"\/>]*)*)|\s*)(\/?)>/g
var HTML_TAGS = /<(-?[A-Za-z][-\w\xA0-\xFF]*)(?:\s+([^"'/>]*(?:(?:"[^"]*"|'[^']*'|\/[^>])[^'"/>]*)*)|\s*)(\/?)>/g

/**
* Matches spaces and tabs between HTML tags
Expand Down Expand Up @@ -136,7 +136,7 @@ function cleanSource (src) {
mm,
re = HTML_COMMS

if (~src.indexOf('\r')) {
if (src.indexOf('\r') !== 1) {
src = src.replace(/\r\n?/g, '\n')
}

Expand Down Expand Up @@ -188,7 +188,7 @@ function parseAttribs (str, pcex) {
if (RE_HASEXPR.test(v)) {

if (k === 'value') vexp = 1
if (~RIOT_ATTRS.indexOf(k)) k = 'riot-' + k
if (RIOT_ATTRS.indexOf(k) !== -1) k = 'riot-' + k
}

list.push(k + '=' + v)
Expand Down Expand Up @@ -625,7 +625,7 @@ var END_TAGS = /\/>\n|^<(?:\/?-?[A-Za-z][-\w\xA0-\xFF]*\s*|-?[A-Za-z][-\w\xA0-\x
function _q (s, r) {
if (!s) return "''"
s = SQ + s.replace(/\\/g, '\\\\').replace(/'/g, "\\'") + SQ
return r && ~s.indexOf('\n') ? s.replace(/\n/g, '\\n') : s
return r && s.indexOf('\n') !== -1 ? s.replace(/\n/g, '\\n') : s
}

/**
Expand Down Expand Up @@ -668,7 +668,7 @@ function splitBlocks (str) {
k = str.lastIndexOf('<'),
n = str.length

while (~k) {
while (k !== -1) {
m = str.slice(k, n).match(END_TAGS)
if (m) {
k += m.index + m[0].length
Expand Down Expand Up @@ -727,11 +727,11 @@ function getAttrib (attribs, name) {
*/
function unescapeHTML (str) {
return str
.replace(/&amp;/g, '&')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&quot;/g, '"')
.replace(/&#039;/g, '\'')
.replace(/&amp;/g, '&')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&quot;/g, '"')
.replace(/&#039;/g, '\'')
}

/**
Expand Down Expand Up @@ -773,12 +773,12 @@ function getCode (code, opts, attribs, base) {
}

return _compileJS(
code,
opts,
type,
extend(jsParserOptions, getParserOptions(attribs)),
base
)
code,
opts,
type,
extend(jsParserOptions, getParserOptions(attribs)),
base
)
}

/**
Expand Down Expand Up @@ -828,7 +828,7 @@ var
* unquoted expressions, but disallows the character '>' within unquoted attribute values.
* @const {RegExp}
*/
CUST_TAG = RegExp(/^([ \t]*)<(-?[A-Za-z][-\w\xA0-\xFF]*)(?:\s+([^'"\/>]+(?:(?:@|\/[^>])[^'"\/>]*)*)|\s*)?(?:\/>|>[ \t]*\n?([\S\s]*)^\1<\/\2\s*>|>(.*)<\/\2\s*>)/
CUST_TAG = RegExp(/^([ \t]*)<(-?[A-Za-z][-\w\xA0-\xFF]*)(?:\s+([^'"/>]+(?:(?:@|\/[^>])[^'"/>]*)*)|\s*)?(?:\/>|>[ \t]*\n?([\S\s]*)^\1<\/\2\s*>|>(.*)<\/\2\s*>)/
.source.replace('@', S_STRINGS), 'gim'),
/**
* Matches `script` elements, capturing its attributes in $1 and its content in $2.
Expand All @@ -843,7 +843,7 @@ var
*/
STYLES = /<style(\s+[^>]*)?>\n?([\S\s]*?)<\/style\s*>/gi

/**
/**
* The main compiler processes all custom tags, one by one.
*
* - Sends the received source to the html parser, if any is specified
Expand Down Expand Up @@ -911,8 +911,8 @@ function compile (src, opts, url) {

attribs = attribs && included('attribs')
? restoreExpr(
parseAttribs(
splitHtml(attribs, opts, pcex),
parseAttribs(
splitHtml(attribs, opts, pcex),
pcex),
pcex) : ''

Expand Down Expand Up @@ -992,5 +992,5 @@ module.exports = {
css: compileCSS,
js: compileJS,
parsers: parsers,
version: 'v3.2.4'
version: 'WIP'
}
4 changes: 2 additions & 2 deletions lib/js-splitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var skipRegex = require('skip-regex')
var S_SQ_STR = /'[^'\n\r\\]*(?:\\(?:\r\n?|[\S\s])[^'\n\r\\]*)*'/.source

var S_R_SRC1 = [
/\/\*[^*]*\*+(?:[^*\/][^*]*\*+)*\//.source,
/\/\*[^*]*\*+(?:[^*/][^*]*\*+)*\//.source,
'//.*',
S_SQ_STR,
S_SQ_STR.replace(/'/g, '"'),
Expand Down Expand Up @@ -57,7 +57,7 @@ function jsSplitter (code, start) {
var re1 = new RegExp(S_R_SRC1, 'g')
var re2

var offset = start |= 0
var offset = start | 0
var result = [[]]
var stack = []
var re = re1
Expand Down
4 changes: 2 additions & 2 deletions lib/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ function _load (branch, parser) {
function _find (branch, name) {
return branch ? _parsers[branch][name] && branch
: _parsers.js[name] ? 'js'
: _parsers.css[name] ? 'css'
: _parsers.html[name] ? 'html' : NULL
: _parsers.css[name] ? 'css'
: _parsers.html[name] ? 'html' : NULL
}

/**
Expand Down
Loading

0 comments on commit 5c1d1e8

Please sign in to comment.