Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lc2

Package Overview
Dependencies
Maintainers
2
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lc2 - npm Package Compare versions

Comparing version 1.4.8 to 1.5.0

dist/executionUnit.js

23

package.json
{
"name": "lc2",
"version": "1.4.8",
"version": "1.5.0",
"description": "browser automation library",
"main": "src/index.js",
"scripts": {
"test": "ava",
"test": "ava --timeout 5000",
"dev": "webpack-dev-server --host 0.0.0.0 --port 3001",
"build": "webpack && webpack -p --output-filename lemoncase.min.js"
"build": "webpack && webpack --config webpack.prod.js -p --progress",
"lint": "eslint src/*.js src/**/*.js"
},

@@ -30,8 +31,12 @@ "engines": {

],
"author": "李超",
"author": "Chaos Lee",
"license": "GPL-3.0",
"devDependencies": {
"angular": "^1.5.7",
"angular": "^1.5.8",
"ava": "^0.15.2",
"codemirror": "^5.14.2",
"babel-core": "^6.13.2",
"babel-loader": "^6.2.4",
"babel-preset-es2015": "^6.13.2",
"codemirror": "^5.17.0",
"eslint": "^3.1.1",
"webpack": "^1.13.0",

@@ -43,10 +48,4 @@ "webpack-dev-server": "^1.14.1"

},
"xo": {
"rules": {
"linebreak-style": 0
}
},
"dependencies": {
"lc2-selector": "^1.0.3",
"oc-trigger": "^1.1.1",
"randexp": "^0.4.2",

@@ -53,0 +52,0 @@ "sizzle": "^2.3.0"

@@ -1,25 +0,16 @@

var parser = require('./parser/index');
var Case = require('./class/case').Case;
var setup = require('./global').setup;
var IF = require('./class/instruction');
var global = require('./global');
const parser = require('./parser/index');
require('./class/case_I');
require('./class/case_P');
require('./instructions');
var exports = {
Case: Case,
setup: setup,
Instruction: IF,
const LC = {
Case: require('./engine/case'),
Instruction: require('./engine/instruction'),
type: require('./engine/lc2').type,
parse: parser.parse,
parseAt: parser.parseFragment,
init: global.init,
getLemoncaseFrame: global.getLemoncaseFrame
parseAt: parser.parseFragment
};
module.exports = exports;
if (typeof module === 'undefined') {
window.LC = exports;
}
//make it available in node.js as well
if (typeof module !== 'undefined' && module.exports) {
module.exports = LC;
} else {
window.LC = LC;
}

@@ -1,2 +0,2 @@

var tt = require('./tokentype').types;
const tt = require('./tokentype').types;

@@ -119,3 +119,3 @@ module.exports = function (Parser) {

pp.parseMaybeUnary = function (sawUnary) {
pp.parseMaybeUnary = function () {
var expr;

@@ -131,8 +131,2 @@ if (this.type.prefix) {

if (update) {
} else {
sawUnary = true;
}
node.type = update ? 'UpdateExpr' : 'UnaryExpr';

@@ -161,9 +155,8 @@

pp.parseExprSubscripts = function () {
var startPos = this.start;
var expr = this.parseExprAtom();
return this.parseSubscripts(expr, startPos);
return this.parseSubscripts(expr);
};
pp.parseSubscripts = function (base, startPos) {
pp.parseSubscripts = function (base) {
for (;;) {

@@ -194,37 +187,37 @@ if (this.eat(tt.parenL)) {

switch (this.type) {
case tt.name:
return this.parseIndent(this.type !== tt.name);
case tt.name:
return this.parseIndent(this.type !== tt.name);
case tt.regexp:
var value = this.value;
node = this.parseLiteral('regexp');
node.regexp = value;
case tt.regexp:
var value = this.value;
node = this.parseLiteral('regexp');
node.regexp = value;
return node;
return node;
case tt.num: case tt.string:
return this.parseLiteral('literal', this.value);
case tt.num: case tt.string:
return this.parseLiteral('literal', this.value);
case tt._true: case tt._false:
return this.parseLiteral('literal', this.value);
case tt._true: case tt._false:
return this.parseLiteral('literal', this.value);
case tt.objectAt: case tt.dict:
return this.parseExtLiteral(this.type);
case tt.objectAt: case tt.dict:
return this.parseExtLiteral(this.type);
case tt.parenL:
return this.parseParenExpression();
case tt.parenL:
return this.parseParenExpression();
case tt.tagAtL: case tt.tagNumL: case tt.tagFacL:
return this.parseTagExpression();
// [attribute:selector]
case tt.bracketL:
return this.parseElmAttr();
// {style:selector}
case tt.braceL:
return this.parseElmStyle();
case tt.tagAtL: case tt.tagNumL: case tt.tagFacL:
return this.parseTagExpression();
// [attribute:selector]
case tt.bracketL:
return this.parseElmAttr();
// {style:selector}
case tt.braceL:
return this.parseElmStyle();
default:
this.inTag
? this.raise(this.lastTokStart, '(missing `/` before `>` ?) Unexpected token')
: this.unexpected();
default:
this.inTag
? this.raise(this.lastTokStart, '(missing `/` before `>` ?) Unexpected token')
: this.unexpected();
}

@@ -231,0 +224,0 @@ };

@@ -1,12 +0,12 @@

// the keywords
var reserve = ['in', 'by', 'to'];
var actions = ['click', 'input', 'rclick', 'dblclick',
const reserve = ['in', 'by', 'to'];
const actions = ['click', 'input', 'rclick', 'dblclick',
'movein', 'moveout', 'scroll', 'select', 'jumpto', 'refresh'];
var macros = ['CLOCK', 'TIMES', 'INTERVAL', 'SCREEN', 'AUTOSCROLL'];
const macros = ['TIMES', 'INTERVAL', 'SCREEN',
'AUTOSCROLL', 'AUTOCAPTURE'];
var keywords = ['wait', 'assert', 'log', 'console', 'var', 'process',
const keywords = ['wait', 'assert', 'log', 'console', 'var', 'process',
'return', 'true', 'false'].concat(reserve).concat(actions);
var keywordRegexp = new RegExp('^(' + keywords.join('|') + ')$');
var macroRegexp = new RegExp('^(' + macros.join('|') + ')$');
const keywordRegexp = new RegExp('^(' + keywords.join('|') + ')$');
const macroRegexp = new RegExp('^(' + macros.join('|') + ')$');

@@ -30,6 +30,6 @@ function isIdentifierStart(code) {

module.exports = {
keywordRegexp: keywordRegexp,
macroRegexp: macroRegexp,
isIdentifierStart: isIdentifierStart,
isIdentifierChar: isIdentifierChar
keywordRegexp,
macroRegexp,
isIdentifierStart,
isIdentifierChar
};

@@ -1,2 +0,2 @@

var Parser = require('./state');
const Parser = require('./state');

@@ -11,5 +11,5 @@ module.exports = {

parseFragment: function (input, options) {
var p = new Parser(options, input);
const p = new Parser(options, input);
p.nextToken();
return p.parseStatement();

@@ -16,0 +16,0 @@ },

@@ -1,4 +0,4 @@

var locutil = require('./locutil');
var getLineInfo = locutil.getLineInfo;
var empowerErrMsg = locutil.empowerErrMsg;
const locutil = require('./locutil');
const getLineInfo = locutil.getLineInfo;
const empowerErrMsg = locutil.empowerErrMsg;

@@ -12,8 +12,8 @@ // This function is used to raise exceptions on parse errors. It

module.exports = function (Parser) {
var pp = Parser.prototype;
let pp = Parser.prototype;
pp.raise = function (pos, msg) {
var loc = getLineInfo(this.input, pos);
const loc = getLineInfo(this.input, pos);
msg += ' (' + loc.line + ':' + loc.column + ')';
var left = this.options.left, right = this.options.right;
const left = this.options.left, right = this.options.right;
if (left || right) {

@@ -24,6 +24,7 @@ msg = left + msg + right;

}
var err = new SyntaxError(msg);
let err = new SyntaxError(msg);
err.pos = pos; err.loc = loc; err.raisedAt = this.pos;
throw err;
};
};

@@ -1,11 +0,13 @@

var lineBreakG = require('./whitespace').lineBreakG;
const lineBreakG = require('./whitespace').lineBreakG;
var Position = function (line, col) {
this.line = line;
this.column = col;
};
class Position {
constructor(line, col) {
this.line = line;
this.column = col;
}
Position.prototype.offset = function (n) {
return new Position(this.line, this.column + n);
};
offset(n) {
return new Position(this.line, this.column + n);
}
}

@@ -18,5 +20,5 @@ // these function 'power up' the error message

function getLineInfo(input, offset) {
for (var line = 1, cur = 0;;) {
for (let line = 1, cur = 0;;) {
lineBreakG.lastIndex = cur;
var match = lineBreakG.exec(input);
let match = lineBreakG.exec(input);
if (match && match.index < offset) {

@@ -34,9 +36,9 @@ ++line;

function empowerErrMsg(input, loc, msg) {
var errLine = input.split(lineBreakG)[loc.line - 1];
var strBeforeErr = errLine.substr(0, loc.column);
var width = widthOf(strBeforeErr);
var arrow = genArrow(width);
var positionedMsg = positionMsg(msg, width);
const errLine = input.split(lineBreakG)[loc.line - 1];
const strBeforeErr = errLine.substr(0, loc.column);
const width = widthOf(strBeforeErr);
const arrow = genArrow(width);
const positionedMsg = positionMsg(msg, width);
return '\n' + errLine + '\n' + arrow + '\n' + positionedMsg;

@@ -46,17 +48,5 @@ }

function genArrow(width) {
var i = -1, j = -1, out = '';
const arr = ' '.repeat(width) + '↑';
while (++i < width) {
out += ' ';
}
out += '↑\n';
while (++j < width) {
out += ' ';
}
out += '↑';
return out;
return arr + '\n' + arr;
}

@@ -70,3 +60,3 @@

var i = -1, emptyWidth = width - Math.floor(msg.length / 2), newMsg = '';
let i = -1, emptyWidth = width - Math.floor(msg.length / 2), newMsg = '';

@@ -84,16 +74,17 @@ while (++i < emptyWidth) {

function widthOf(str) {
var code,
width = 0,
i = -1, len = str.length;
const len = str.length;
let width = 0;
while (++i < len) {
for(let i = 0, code = ''; i < len; i++) {
code = str.charCodeAt(i);
switch (code) {
case 9: // '\t'
width += 4;
break;
default:
width += 1;
break;
case 9: // '\t'
width += 4;
break;
// other scienario are possible due to unicode
// we will ignore it for now
default:
width += 1;
break;
}

@@ -106,4 +97,5 @@ }

module.exports = {
getLineInfo: getLineInfo,
empowerErrMsg: empowerErrMsg
getLineInfo,
empowerErrMsg,
Position
};

@@ -1,4 +0,6 @@

var has = require('../util').has;
const has = function has(obj, propName) {
return Object.prototype.hasOwnProperty.call(obj, propName);
};
var defaultOptions = {
const defaultOptions = {
insertReturn: true,

@@ -12,3 +14,3 @@ onComment: function () {},

function getOptions(options) {
var result = {};
let result = {};
for (var op in defaultOptions) {

@@ -15,0 +17,0 @@ result[op] = options && has(options, op) ? options[op] : defaultOptions[op];

@@ -1,5 +0,5 @@

var tt = require('./tokentype').types;
const tt = require('./tokentype').types;
module.exports = function (Parser) {
var pp = Parser.prototype;
let pp = Parser.prototype;

@@ -9,2 +9,3 @@ pp.eat = function (type) {

this.next();
return true;

@@ -17,3 +18,5 @@ }

pp.semicolon = function () {
if (!this.eat(tt.semi)) this.expected(tt.semi);
if (!this.eat(tt.semi)) {
this.expected(tt.semi);
}
};

@@ -25,4 +28,4 @@

pp.unexpected = function (pos) {
this.raise(pos != null ? pos : this.start, 'Unexpected token');
pp.unexpected = function (pos = this.start) {
this.raise(pos, 'Unexpected token');
};

@@ -29,0 +32,0 @@

@@ -1,62 +0,60 @@

var getOptions = require('./options').getOptions;
var identifier = require('./identifier');
var keywordRegexp = identifier.keywordRegexp;
var macroRegexp = identifier.macroRegexp;
var tt = require('./tokentype').types;
const getOptions = require('./options').getOptions;
const identifier = require('./identifier');
const keywordRegexp = identifier.keywordRegexp;
const macroRegexp = identifier.macroRegexp;
const tt = require('./tokentype').types;
var Parser = function (options, input) {
this.options = getOptions(options);
this.keywords = keywordRegexp;
this.macros = macroRegexp;
this.input = String(input);
class Parser {
constructor(options, input) {
this.options = getOptions(options);
this.keywords = keywordRegexp;
this.macros = macroRegexp;
this.input = String(input);
this.pos = 0;
this.pos = 0;
this.type = tt.eof;
this.value = null;
this.type = tt.eof;
this.value = null;
this.start = this.end = this.pos;
this.start = this.end = this.pos;
this.lastTokStart = this.lastTokEnd = this.pos;
// generate word based on regex or use regex to match against string ?
this.exprAllowed = false;
this.genAllowed = false;
this.lastTokStart = this.lastTokEnd = this.pos;
// generate word based on regex or use regex to match against string ?
this.exprAllowed = false;
this.genAllowed = false;
this.labels = [];
this.labels = [];
// conf - #set
this.conf = {};
this.keys = {};
this.nextID = 0;
// keep track of process body(statements)
this.pcs = {};
// keep track of all the unused process/ declared process
this.pcsTable = {};
// keep track of potential errors <!missing slash>
this.inTag = false;
};
// conf - #set
this.conf = {};
this.keys = {};
this.nextID = 0;
// keep track of process body(statements)
this.pcs = {};
// keep track of all the unused process/ declared process
this.pcsTable = {};
// keep track of potential errors <!missing slash>
this.inTag = false;
}
Parser.prototype.parse = function () {
this.nextToken();
parse() {
this.nextToken();
var program = {
CONFIG: this.conf,
DATA_KEYS: this.keys,
PROCESSES: this.pcs
};
let program = {
CONFIG: this.conf,
DATA_KEYS: this.keys,
PROCESSES: this.pcs
};
return this.parseTopLevel(program);
};
return this.parseTopLevel(program);
}
}
var extend = function (fn) {
fn(Parser);
};
require('./location')(Parser);
require('./tokenize')(Parser);
require('./statement')(Parser);
require('./parseutil')(Parser);
require('./expression')(Parser);
require('./lval')(Parser);
extend(require('./location'));
extend(require('./tokenize'));
extend(require('./statement'));
extend(require('./parseutil'));
extend(require('./expression'));
extend(require('./lval'));
module.exports = Parser;

@@ -1,10 +0,11 @@

var tt = require('./tokentype').types;
const tt = require('./tokentype').types;
var getLineInfo = require('./locutil').getLineInfo;
var genExpr = require('./walk');
const getLineInfo = require('./locutil').getLineInfo;
const genExpr = require('./walk');
var insDefinition = require('../instructionType');
var type = require('../engine/lc2').type;
module.exports = function (Parser) {
var pp = Parser.prototype;
let pp = Parser.prototype;

@@ -19,3 +20,3 @@ // ### Statement parsing

//mark main as used but uninitialized at the beginning
var pcsTable = this.pcsTable;
let pcsTable = this.pcsTable;
pcsTable.main = {

@@ -30,3 +31,5 @@ pos: 0

for (var process in pcsTable) {
if (pcsTable[process]) this.raise(pcsTable[process].pos, 'Invalid process call at');
if (pcsTable[process]) {
this.raise(pcsTable[process].pos, 'Invalid process call at');
}
}

@@ -40,3 +43,3 @@

pp.parseStructure = function () {
var globaltype = this.type;
const globaltype = this.type;

@@ -50,8 +53,8 @@ if (globaltype.macro) return this.parseSet();

pp.parseSet = function () {
// #set ...
var setType = this.type;
// #macro ...
const setType = this.type;
if (!setType.macro) this.unexpected();
var key = setType.label.toLowerCase(); // CLOCK -> clock
const key = setType.label.toLowerCase(); // TIMES -> times

@@ -64,27 +67,29 @@ this.writeConfig(key);

pp.writeConfig = function (key) {
var val;
let val;
var confTable = this.conf;
if (confTable[key]) this.raise(this.start, this.type.keyword + ' was defined already');
const confTable = this.conf;
if (confTable[key]) {
this.raise(this.start, this.type.keyword + ' was defined already');
}
let x, y, splitVal = this.value.split(',');
switch (key) {
case "screen":
var x, y, splitVal = this.value.split(',');
if (splitVal.length !== 2) this.raise('Invalid arguments');
x = ~~parseInt(splitVal[0], 10);
y = ~~parseInt(splitVal[1], 10);
val = {
width: x,
height: y
}
break;
case 'screen':
if (splitVal.length !== 2) this.raise('Invalid arguments');
x = ~~parseInt(splitVal[0], 10);
y = ~~parseInt(splitVal[1], 10);
val = {
width: x,
height: y
};
break;
case 'autoscroll':
val = true;
break;
case 'autoscroll': case 'autocapture':
val = true;
break;
default:
val = parseInt(this.value, 10);
break;
};
default:
val = parseInt(this.value, 10);
break;
}

@@ -95,5 +100,5 @@ confTable[key] = val;

pp.parseProcess = function () {
var node = {
let node = {
LINE: getLineInfo(this.input, this.start),
TYPE: insDefinition.PROCESS,
TYPE: type.PROCESS,
BODY: {}

@@ -106,3 +111,3 @@ },

var name = this.parseIndent().name;
const name = this.parseIndent().name;
// check for process name

@@ -128,7 +133,7 @@ if (pcs[name]) this.raise(this.start, name + ' process was defined already');

pp.parsePcBlock = function (node) {
var statements = this.parseBlock();
const statements = this.parseBlock();
statements.push({
LINE: -1,
TYPE: insDefinition.RETURN,
TYPE: type.RETURN
});

@@ -142,6 +147,6 @@

var args = [];
const args = [];
while (!this.eat(tt.braceR)) {
var stmt = this.parseStatement(true);
const stmt = this.parseStatement(true);
args.push(stmt);

@@ -154,32 +159,32 @@ }

pp.parseStatement = function () {
var starttype = this.type, node = this.startNode();
let starttype = this.type, node = this.startNode();
switch (starttype) {
case tt._click: case tt._rclick: case tt._dblclick:
case tt._movein: case tt._moveout:
return this.parseMouseAction(node, starttype.keyword);
case tt._select:
return this.parseSelectAction(node);
case tt._scroll:
return this.parseScrollAction(node, starttype.keyword);
case tt._input:
return this.parseInputAction(node, starttype.keyword);
case tt._return:
return this.parseReturnStatement(node);
case tt._wait:
return this.parseWaitStatement(node);
case tt._assert:
return this.parseAssertStatement(node);
case tt._log: case tt._console:
return this.parseLogStatement(node, insDefinition.LOG);
case tt._jumpto:
return this.parseGotoStatement(node);
case tt._refresh:
return this.parseRefreshStatement(node);
case tt._var:
return this.parseVarStatement(node);
case tt.name:
return this.parseExprStatement(node);
default:
this.unexpected();
case tt._click: case tt._rclick: case tt._dblclick:
case tt._movein: case tt._moveout:
return this.parseMouseAction(node, starttype.keyword);
case tt._select:
return this.parseSelectAction(node);
case tt._scroll:
return this.parseScrollAction(node, starttype.keyword);
case tt._input:
return this.parseInputAction(node, starttype.keyword);
case tt._return:
return this.parseReturnStatement(node);
case tt._wait:
return this.parseWaitStatement(node);
case tt._assert:
return this.parseAssertStatement(node);
case tt._log: case tt._console:
return this.parseLogStatement(node, type.LOG);
case tt._jumpto:
return this.parseGotoStatement(node);
case tt._refresh:
return this.parseRefreshStatement(node);
case tt._var:
return this.parseVarStatement(node);
case tt.name:
return this.parseExprStatement(node);
default:
return this.parseEvaluation(node);
}

@@ -193,3 +198,3 @@ };

return this.finishNode(node, insDefinition.RETURN);
return this.finishNode(node, type.RETURN);
};

@@ -205,3 +210,3 @@

return this.finishNode(node, insDefinition.EXPRESSION);
return this.finishNode(node, type.EXPRESSION);
};

@@ -211,6 +216,6 @@

pp.parseVar = function (node) {
var declarations = [];
const declarations = [];
for (;;) {
var decl = {};
for (; ;) {
let decl = {};

@@ -237,3 +242,3 @@ //todo check var

pp.parseExprStatement = function (node) {
var expr = this.parseExpression();
const expr = this.parseExpression();

@@ -252,7 +257,7 @@ this.semicolon();

return this.finishNode(node, insDefinition.CALL);
return this.finishNode(node, type.CALL);
}
// a = 1
var fn = genExpr(expr);
const fn = genExpr(expr);

@@ -262,5 +267,17 @@ node.BODY.raw = expr;

return this.finishNode(node, insDefinition.EXPRESSION);
return this.finishNode(node, type.EXPRESSION);
};
pp.parseEvaluation = function (node) {
const expr = this.parseExpression();
this.semicolon();
const fn = genExpr(expr);
node.BODY.raw = expr;
node.BODY.exp = fn;
return this.finishNode(node, type.EXPRESSION);
};
pp.parseWaitStatement = function (node) {

@@ -274,3 +291,3 @@ this.next();

return this.finishNode(node, insDefinition.WAIT);
return this.finishNode(node, type.WAIT);
};

@@ -288,6 +305,8 @@

if (this.eat(tt._to)) {
var posX, posY;
let posX, posY;
posX = this.parseMaybeAssign();
this.expect(tt.comma);
posY = this.parseMaybeAssign();
node.BODY.posX = posX;
node.BODY.posY = posY;
}

@@ -297,3 +316,3 @@

return this.finishNode(node, insDefinition.TRIGGER);
return this.finishNode(node, type.TRIGGER);
};

@@ -314,3 +333,3 @@

return this.finishNode(node, insDefinition.TRIGGER);
return this.finishNode(node, type.TRIGGER);
};

@@ -329,6 +348,6 @@

node.BODY.action = 'select';
this.semicolon();
return this.finishNode(node, insDefinition.TRIGGER);
return this.finishNode(node, type.TRIGGER);
};

@@ -350,3 +369,3 @@

return this.finishNode(node, insDefinition.TRIGGER);
return this.finishNode(node, type.TRIGGER);
};

@@ -375,3 +394,3 @@

return this.finishNode(node, insDefinition.ASSERT);
return this.finishNode(node, type.ASSERT);
};

@@ -387,3 +406,3 @@

return this.finishNode(node, insDefinition.JUMPTO);
return this.finishNode(node, type.JUMPTO);
};

@@ -396,3 +415,3 @@

return this.finishNode(node, insDefinition.REFRESH);
return this.finishNode(node, type.REFRESH);
};

@@ -399,0 +418,0 @@

@@ -1,14 +0,14 @@

var identifier = require('./identifier');
var isIdentifierStart = identifier.isIdentifierStart;
var isIdentifierChar = identifier.isIdentifierChar;
const identifier = require('./identifier');
const isIdentifierStart = identifier.isIdentifierStart;
const isIdentifierChar = identifier.isIdentifierChar;
var tt = require('./tokentype').types;
var keywordTypes = require('./tokentype').keywordTypes;
const tt = require('./tokentype').types;
const keywordTypes = require('./tokentype').keywordTypes;
var whitespace = require('./whitespace');
var isNewLine = whitespace.isNewLine;
var lineBreak = whitespace.lineBreak;
const whitespace = require('./whitespace');
const isNewLine = whitespace.isNewLine;
const lineBreak = whitespace.lineBreak;
module.exports = function (Parser) {
var pp = Parser.prototype;
let pp = Parser.prototype;

@@ -41,5 +41,5 @@ pp.next = function () {

pp.fullCharCodeAtPos = function () {
var code = this.input.charCodeAt(this.pos);
const code = this.input.charCodeAt(this.pos);
if (code <= 0xd7ff || code >= 0xe000) return code;
var next = this.input.charCodeAt(this.pos + 1);
const next = this.input.charCodeAt(this.pos + 1);

@@ -50,3 +50,3 @@ return (code << 10) + next - 0x35fdc00;

pp.skipBlockComment = function () {
var start = this.pos, end = this.input.indexOf('*/', this.pos += 2);
let start = this.pos, end = this.input.indexOf('*/', this.pos += 2);
if (end === -1) this.raise(this.pos - 2, 'unterminated comment');

@@ -62,4 +62,4 @@ this.pos = end + 2;

pp.skipLineComment = function (startSkip) {
var start = this.pos;
var ch = this.input.charCodeAt(this.pos+=startSkip);
let start = this.pos;
let ch = this.input.charCodeAt(this.pos+=startSkip);
while (this.pos < this.input.length &&

@@ -82,32 +82,32 @@ ch !== 10 && ch !== 13 &&

loop: while (this.pos < this.input.length) {
var ch = this.input.charCodeAt(this.pos);
let ch = this.input.charCodeAt(this.pos);
switch (ch) {
case 32: case 160: // ' '
case 32: case 160: // ' '
++this.pos;
break;
case 13:
if (this.input.charCodeAt(this.pos + 1) === 10) {
++this.pos;
}
case 10: case 8232: case 8233: // eslint-disable-line no-fallthrough
++this.pos;
break;
case 47: // '/'
switch (this.input.charCodeAt(this.pos + 1)) {
case 42: // '*'
this.skipBlockComment();
break;
case 13:
if (this.input.charCodeAt(this.pos + 1) === 10) {
++this.pos;
}
case 10: case 8232: case 8233: //new line
++this.pos;
case 47:
this.skipLineComment(2);
break;
case 47: // '/'
switch (this.input.charCodeAt(this.pos + 1)) {
case 42: // '*'
this.skipBlockComment();
break;
case 47:
this.skipLineComment(2);
break;
default:
break loop;
}
break;
default:
if (ch > 8 && ch < 14) {
++this.pos;
} else {
break loop;
}
break loop;
}
break;
default:
if (ch > 8 && ch < 14) {
++this.pos;
} else {
break loop;
}
}

@@ -118,3 +118,3 @@ }

pp.readToken_slash = function () {
var next = this.input.charCodeAt(this.pos+1);
const next = this.input.charCodeAt(this.pos+1);
if (this.exprAllowed || this.genAllowed) {

@@ -134,5 +134,5 @@ ++this.pos;

pp.readToken_mult_modulo_exp = function (code) {
var next = this.input.charCodeAt(this.pos+1);
var size = 1;
var type = code === 42 ? tt.star : tt.modulo;
const next = this.input.charCodeAt(this.pos+1);
const size = 1;
const type = code === 42 ? tt.star : tt.modulo;

@@ -144,3 +144,3 @@ if (next === 61) return this.finishOp(tt.assign, size + 1);

pp.readToken_pipe_amp = function (code) {
var next = this.input.charCodeAt(this.pos+1);
const next = this.input.charCodeAt(this.pos+1);
// '&&' '||'

@@ -153,3 +153,3 @@ if (next === code) return this.finishOp(code === 124 ? tt.logicalOR : tt.logicalAND, 2);

pp.readToken_plus_min = function (code) {
var next = this.input.charCodeAt(this.pos+1);
const next = this.input.charCodeAt(this.pos+1);
if (next === code) return this.finishOp(tt.incDec, 2);

@@ -162,4 +162,4 @@ if (next === 61) return this.finishOp(tt.assign, 2);

pp.readToken_lt_gt = function (code) {
var next = this.input.charCodeAt(this.pos+1);
var size = 1;
const next = this.input.charCodeAt(this.pos+1);
let size = 1;
if (next === code) {

@@ -179,3 +179,3 @@ this.raise(this.pos, 'bitwise operator is not allowed');

pp.readToken_eq_excl = function (code) {
var next = this.input.charCodeAt(this.pos+1);
const next = this.input.charCodeAt(this.pos+1);
if (next === 126 && code === 33) return this.finishOp(tt.match, 2);

@@ -189,44 +189,44 @@ if (next === 61) return this.finishOp(tt.equality, this.input.charCodeAt(this.pos+2) === 61 ? 3 : 2);

switch (code) {
case 35: ++this.pos; return this.readMacro();
case 40: ++this.pos; return this.finishToken(tt.parenL);
case 41: ++this.pos; return this.finishToken(tt.parenR);
case 59: ++this.pos; return this.finishToken(tt.semi);
case 44: ++this.pos; return this.finishToken(tt.comma);
case 91: ++this.pos; return this.finishToken(tt.bracketL);
case 93: ++this.pos; return this.finishToken(tt.bracketR);
case 123: ++this.pos; return this.finishToken(tt.braceL);
case 125: ++this.pos; return this.finishToken(tt.braceR);
case 58: ++this.pos; return this.finishToken(tt.colon);
case 35: ++this.pos; return this.readMacro();
case 40: ++this.pos; return this.finishToken(tt.parenL);
case 41: ++this.pos; return this.finishToken(tt.parenR);
case 59: ++this.pos; return this.finishToken(tt.semi);
case 44: ++this.pos; return this.finishToken(tt.comma);
case 91: ++this.pos; return this.finishToken(tt.bracketL);
case 93: ++this.pos; return this.finishToken(tt.bracketR);
case 123: ++this.pos; return this.finishToken(tt.braceL);
case 125: ++this.pos; return this.finishToken(tt.braceR);
case 58: ++this.pos; return this.finishToken(tt.colon);
//number
case 48: case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: //0-9
return this.readNumber(false);
//number
case 48: case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: //0-9
return this.readNumber(false);
//string
case 34:case 39:
return this.readString(code);
//string
case 34:case 39:
return this.readString(code);
case 47: // '/'
return this.readToken_slash();
case 47: // '/'
return this.readToken_slash();
case 37: case 42: // '%*'
return this.readToken_mult_modulo_exp(code);
case 37: case 42: // '%*'
return this.readToken_mult_modulo_exp(code);
case 124: case 38: // '|&'
return this.readToken_pipe_amp(code);
case 124: case 38: // '|&'
return this.readToken_pipe_amp(code);
case 43: case 45: // '+-'
return this.readToken_plus_min(code);
case 43: case 45: // '+-'
return this.readToken_plus_min(code);
case 60: case 62: // '<>'
return this.readToken_lt_gt(code);
case 60: case 62: // '<>'
return this.readToken_lt_gt(code);
case 61: case 33: // '=!'
return this.readToken_eq_excl(code);
case 126: // '~~'
var next = this.input.charCodeAt(this.pos+1);
if (next !== 126) this.raise(this.pos, 'bitwise operator is not allowed');
return this.finishOp(tt.match, 2);
default:
this.raise(this.pos, 'Unexpected character "' + this.input[this.pos] + '"');
case 61: case 33: // '=!'
return this.readToken_eq_excl(code);
case 126: // '~~'
var next = this.input.charCodeAt(this.pos+1);
if (next !== 126) this.raise(this.pos, 'bitwise operator is not allowed');
return this.finishOp(tt.match, 2);
default:
this.raise(this.pos, 'Unexpected character "' + this.input[this.pos] + '"');
}

@@ -236,3 +236,3 @@ };

pp.finishOp = function (type, size) {
var str = this.input.slice(this.pos, this.pos += size);
const str = this.input.slice(this.pos, this.pos += size);

@@ -258,6 +258,6 @@ return this.finishToken(type, str);

pp.readRegexp = function (isGen) {
var escaped, inClass, start = this.pos;
let escaped, inClass, start = this.pos;
for (;;) {
if (this.pos >= this.input.length) this.raise(start, 'Unterminated regular expression');
var ch = this.input.charAt(this.pos);
let ch = this.input.charAt(this.pos);
if (lineBreak.test(ch)) this.raise(start, 'Unterminated regular expression');

@@ -278,12 +278,12 @@ if (!escaped) {

}
var content = this.input.slice(start, this.pos);
const content = this.input.slice(start, this.pos);
++this.pos;// skip '/' or '|'
var mods = this.readWord1();
const mods = this.readWord1();
if (mods) {
var validFlags = /^[gim]*$/;
let validFlags = /^[gim]*$/;
if (!validFlags.test(mods)) this.raise(start, 'Invalid regular expression flag');
}
var value = {
const value = {
pattern: content,

@@ -298,5 +298,5 @@ flags: mods,

pp.readInt = function (radix, len) {
var start = this.pos, total = 0;
for (var i = 0, e = len == null ? Infinity : len; i < e; ++i) {
var code = this.fullCharCodeAtPos(), val;
let start = this.pos, total = 0;
for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) {
let code = this.fullCharCodeAtPos(), val;
if (code >= 97) val = code - 97 + 10; // a

@@ -316,5 +316,5 @@ else if (code >= 65) val = code - 65 + 10; // A

pp.readNumber = function (startsWithDot) {
var start = this.pos, isFloat = false;
let start = this.pos, isFloat = false;
if (!startsWithDot && this.readInt(10) === null) this.raise(start, 'Invalid Number');
var next = this.fullCharCodeAtPos();
let next = this.fullCharCodeAtPos();
if (next === 46) {// '.'

@@ -334,3 +334,3 @@ ++this.pos;

var str = this.input.slice(start, this.pos), val;
let str = this.input.slice(start, this.pos), val;
if (isFloat) val = parseFloat(str);

@@ -343,6 +343,6 @@ else val = parseInt(str, 10);

pp.readString = function (quote) {
var out = '', start = this.start, chunkStart = ++this.pos;
let out = '', start = this.start, chunkStart = ++this.pos;
for (;;) {
if (this.pos >= this.input.length) this.raise(start, 'Unterminated string');
var ch = this.fullCharCodeAtPos();
let ch = this.fullCharCodeAtPos();
if (ch === quote) break;

@@ -364,15 +364,15 @@ if (ch === 92) { // '\' escape

pp.readEscapedChar = function () {
var ch = this.input.charCodeAt(++this.pos);
const ch = this.input.charCodeAt(++this.pos);
++this.pos;
switch (ch) {
case 110: return '\n';
case 114: return '\r';
case 116: return '\t';
case 98: return '\b';
case 118: return '\u000b';
case 102: return '\f';
case 13: if (this.fullCharCodeAtPos() === 10) ++this.pos; // '\r\n'
case 10: return '';
default:
return String.fromCharCode(ch);
case 110: return '\n';
case 114: return '\r';
case 116: return '\t';
case 98: return '\b';
case 118: return '\u000b';
case 102: return '\f';
case 13: if (this.fullCharCodeAtPos() === 10) ++this.pos; // '\r\n'
case 10: return ''; // eslint-disable-line no-fallthrough
default:
return String.fromCharCode(ch);
}

@@ -382,5 +382,6 @@ };

pp.readWord1 = function () {
var word = "", first = true, chunkStart = this.pos;
let word = '';
let chunkStart = this.pos;
while (this.pos < this.input.length) {
var ch = this.fullCharCodeAtPos();
let ch = this.fullCharCodeAtPos();
if (isIdentifierChar(ch)) {

@@ -391,4 +392,2 @@ ++this.pos;

}
first = false;
}

@@ -402,4 +401,4 @@ word += this.input.slice(chunkStart, this.pos);

pp.readWord = function () {
var word = this.readWord1();
var type = this.keywords.test(word) ? keywordTypes[word] : tt.name;
const word = this.readWord1();
const type = this.keywords.test(word) ? keywordTypes[word] : tt.name;

@@ -406,0 +405,0 @@ return this.finishToken(type, word);

@@ -13,16 +13,16 @@ // The assignment of fine-grained, information-carrying type objects

var TokenType = function (label, conf) {
if (conf === undefined) conf = {};
class TokenType {
constructor(label, conf = {}) {
this.label = label;
this.keyword = conf.keyword;
this.beforeGen = Boolean(conf.beforeGen);
this.beforeExpr = Boolean(conf.beforeExpr);
this.isAssign = Boolean(conf.isAssign);
this.prefix = Boolean(conf.prefix);
this.postfix = Boolean(conf.postfix);
this.binop = conf.binop || null;
this.macro = Boolean(conf.macro);
}
}
this.label = label;
this.keyword = conf.keyword;
this.beforeGen = Boolean(conf.beforeGen);
this.beforeExpr = Boolean(conf.beforeExpr);
this.isAssign = Boolean(conf.isAssign);
this.prefix = Boolean(conf.prefix);
this.postfix = Boolean(conf.postfix);
this.binop = conf.binop || null;
this.macro = Boolean(conf.macro);
};
function binop(name, prec) {

@@ -32,6 +32,6 @@ return new TokenType(name, {beforeGen: true, binop: prec});

var beforeGen = {beforeGen: true};
var macro = {macro: true};
const beforeGen = {beforeGen: true};
const macro = {macro: true};
var types = {
const types = {
num: new TokenType('num'),

@@ -87,3 +87,3 @@ regexp: new TokenType('regexp'),

var keywords = {};
let keywords = {};

@@ -93,3 +93,3 @@ function kw(name, options) {

options.keyword = name;
keywords[name] = types["_" + name] = new TokenType(name, options);
keywords[name] = types['_' + name] = new TokenType(name, options);
}

@@ -108,3 +108,2 @@

kw('select', beforeGen);
kw('CLOCK', macro);
kw('TIMES', macro);

@@ -114,2 +113,3 @@ kw('INTERVAL', macro);

kw('AUTOSCROLL', macro);
kw('AUTOCAPTURE', macro);
kw('wait', beforeGen);

@@ -116,0 +116,0 @@ kw('assert', beforeGen);

// walk a javascript style tree and transform it into a function
var visitors = {
const visitors = {
varDecl: function (node, c) {
var out = '';
var first = true;
let out = '';
let first = true;

@@ -21,4 +21,4 @@ node.declarations.forEach(function (decl) {

SequenceExpr: function (node, c) {
var out = '';
var first = true;
let out = '';
let first = true;

@@ -43,3 +43,3 @@ node.expressions.forEach(function (expr) {

if (node.regexp.isGenerate) {
var val = node.regexp;
const val = node.regexp;

@@ -63,3 +63,3 @@ return 'gen(/' + val.pattern + '/' + val.flags + ')';

MatchExpr: function (node, c) {
var out = '';
let out = '';

@@ -74,3 +74,3 @@ if (node.operator === '~~') out += '!';

UpdateExpr: function (node) {
var inside = '$.' + node.argument;
const inside = '$.' + node.argument;

@@ -94,3 +94,3 @@ return node.prefix ? node.operator + inside : inside + node.operator;

Attribute: function (node, c) {
var attr = c(node.val);
const attr = c(node.val);

@@ -101,3 +101,3 @@ return 'd(' + c(node.key) + ',' + attr + ')';

Style: function (node, c) {
var style = c(node.val);
const style = c(node.val);

@@ -109,3 +109,3 @@ return 'o(' + c(node.key) + ',' + style + ')';

TextExpr: function (node, c) {
var inside = 'String(' + c(node.val) + ')';
const inside = 'String(' + c(node.val) + ')';

@@ -116,3 +116,3 @@ return 't(' + inside + ')';

CountExpr: function (node, c) {
var inside = 'String(' + c(node.val) + ')';
const inside = 'String(' + c(node.val) + ')';

@@ -123,3 +123,3 @@ return 'c(' + inside + ')';

VisibilityExpr: function (node, c) {
var inside = 'String(' + c(node.val) + ')';
const inside = 'String(' + c(node.val) + ')';

@@ -131,4 +131,4 @@ return 'v(' + inside + ')';

module.exports = function genExpr(node) {
var string = (function c(node) {
var type = node.type;
const string = (function c(node) {
const type = node.type;

@@ -138,3 +138,3 @@ return visitors[type](node, c);

return new Function('$,o,d,c,t,v,m,gen', 'return ' + string + ';');
return 'return ' + string + ';';
};
// Matches a whole line break (where CRLF is considered a single
// line break). Used to count lines.
var lineBreak = /\r\n?|\n|\u2028|\u2029/;
const lineBreak = /\r\n?|\n|\u2028|\u2029/;

@@ -6,0 +6,0 @@ module.exports = {

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc