From efc9748a88233531867828d39afd0751e177a2dd Mon Sep 17 00:00:00 2001 From: baakqiu Date: Mon, 4 May 2020 16:59:15 +0800 Subject: [PATCH] [Release] Version 0.4.7 --- README.md | 2 +- dist/sval.es6.js | 85 +++++++++++++++++++++++++++---------------- dist/sval.js | 92 ++++++++++++++++++++++++++++------------------- dist/sval.min.js | 2 +- package-lock.json | 2 +- package.json | 2 +- src/index.ts | 2 +- types/index.d.ts | 4 ++- 8 files changed, 118 insertions(+), 73 deletions(-) diff --git a/README.md b/README.md index 2071b41..d12c11d 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ Sval instance has two methods, **import** and **run**. - **import** is to import modules into your Sval instance scope, expecting a name and a module as arguments like `import(name: string, mod: any)`, or an object which contains the modules as argument like `import({ [name: string]: any })`. The modules will be automatically declared as global variables. This method is more likely to be used in sandbox mode. -- **parse** is to parse the code with internal [Acorn](https://github.com/acornjs/acorn) or custom parser, to get the corresponding AST, like `parse(code: string)` or `parse(code: string, parser: (code: string, options: svalOptions) => estree.Node` +- **parse** is to parse the code with internal [Acorn](https://github.com/acornjs/acorn) or custom parser, to get the corresponding AST, like `parse(code: string)` or `parse(code: string, parser: (code: string, options: SvalOptions) => estree.Node` - **run** is to evaluate the code inputed, expecting a string as argument like `run(code: string)`, or an AST followed ESTree Spec as argument like `run(ast: estree.Node)`. If you want to export something, there is a internal global `exports` object for mounting what you want to export. diff --git a/dist/sval.es6.js b/dist/sval.es6.js index 33354dc..5a8aa4b 100644 --- a/dist/sval.es6.js +++ b/dist/sval.es6.js @@ -2,9 +2,10 @@ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('acorn')) : typeof define === 'function' && define.amd ? define(['acorn'], factory) : (global = global || self, global.Sval = factory(global.acorn)); -}(this, function (acorn) { 'use strict'; +}(this, (function (acorn) { 'use strict'; var declaration = /*#__PURE__*/Object.freeze({ + __proto__: null, get FunctionDeclaration () { return FunctionDeclaration; }, get VariableDeclaration () { return VariableDeclaration; }, get VariableDeclarator () { return VariableDeclarator; }, @@ -13,6 +14,7 @@ get MethodDefinition () { return MethodDefinition; } }); var declaration$1 = /*#__PURE__*/Object.freeze({ + __proto__: null, get FunctionDeclaration () { return FunctionDeclaration$1; }, get VariableDeclaration () { return VariableDeclaration$1; }, get VariableDeclarator () { return VariableDeclarator$1; }, @@ -380,7 +382,7 @@ } } - var version = "0.4.6"; + var version = "0.4.7"; const AWAIT = { RES: undefined }; const RETURN = { RES: undefined }; @@ -550,6 +552,7 @@ } var identifier = /*#__PURE__*/Object.freeze({ + __proto__: null, Identifier: Identifier }); @@ -558,6 +561,7 @@ } var literal = /*#__PURE__*/Object.freeze({ + __proto__: null, Literal: Literal }); @@ -1015,6 +1019,7 @@ } var expression = /*#__PURE__*/Object.freeze({ + __proto__: null, ThisExpression: ThisExpression, ArrayExpression: ArrayExpression, ObjectExpression: ObjectExpression, @@ -1090,7 +1095,10 @@ } if (matched) { const result = SwitchCase(eachCase, scope); - if (result === BREAK || result === CONTINUE || result === RETURN) { + if (result === BREAK) { + break; + } + if (result === CONTINUE || result === RETURN) { return result; } } @@ -1118,7 +1126,7 @@ if (param) { if (param.type === 'Identifier') { const name = param.name; - subScope.let(name, err); + subScope.var(name, err); } else { pattern$3(param, scope, { feed: err }); @@ -1223,6 +1231,7 @@ } var statement = /*#__PURE__*/Object.freeze({ + __proto__: null, ExpressionStatement: ExpressionStatement, BlockStatement: BlockStatement, EmptyStatement: EmptyStatement, @@ -1244,7 +1253,7 @@ }); function ObjectPattern(node, scope, options = {}) { - const { kind = 'let', hoist = false, onlyBlock = false, feed = {} } = options; + const { kind = 'var', hoist = false, onlyBlock = false, feed = {} } = options; const fedKeys = []; for (let i = 0; i < node.properties.length; i++) { const property = node.properties[i]; @@ -1253,7 +1262,7 @@ if (property.type === 'Property') { const value = property.value; if (value.type === 'Identifier') { - scope[onlyBlock ? kind : 'var'](value.name, onlyBlock ? DEADZONE : undefined); + scope[kind](value.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined); } else { pattern$3(value, scope, { kind, hoist, onlyBlock }); @@ -1299,7 +1308,7 @@ if (hoist) { if (onlyBlock || kind === 'var') { if (element.type === 'Identifier') { - scope[onlyBlock ? kind : 'var'](element.name, onlyBlock ? DEADZONE : undefined); + scope[kind](element.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined); } else { pattern$3(element, scope, { kind, hoist, onlyBlock }); @@ -1333,7 +1342,7 @@ if (hoist) { if (onlyBlock || kind === 'var') { if (arg.type === 'Identifier') { - scope[onlyBlock ? kind : 'var'](arg.name, onlyBlock ? DEADZONE : undefined); + scope[kind](arg.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined); } else { pattern$3(arg, scope, { kind, hoist, onlyBlock }); @@ -1354,12 +1363,12 @@ } } function AssignmentPattern(node, scope, options = {}) { - const { kind = 'let', hoist = false, onlyBlock = false, feed = evaluate(node.right, scope) } = options; + const { kind = 'var', hoist = false, onlyBlock = false, feed = evaluate(node.right, scope) } = options; const left = node.left; if (hoist) { if (onlyBlock || kind === 'var') { if (left.type === 'Identifier') { - scope[onlyBlock ? kind : 'var'](left.name, onlyBlock ? DEADZONE : undefined); + scope[kind](left.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined); } else { pattern$3(left, scope, { kind, hoist, onlyBlock }); @@ -1375,6 +1384,7 @@ } var pattern = /*#__PURE__*/Object.freeze({ + __proto__: null, ObjectPattern: ObjectPattern, ArrayPattern: ArrayPattern, RestElement: RestElement, @@ -1388,6 +1398,7 @@ } var program = /*#__PURE__*/Object.freeze({ + __proto__: null, Program: Program }); @@ -1416,11 +1427,11 @@ } } function VariableDeclarator(node, scope, options = {}) { - const { kind = 'let', hoist = false, onlyBlock = false, feed } = options; + const { kind = 'var', hoist = false, onlyBlock = false, feed } = options; if (hoist) { if (onlyBlock || kind === 'var') { if (node.id.type === 'Identifier') { - scope[onlyBlock ? kind : 'var'](node.id.name, onlyBlock ? DEADZONE : undefined); + scope[kind](node.id.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined); } else { pattern$3(node.id, scope, { kind, hoist, onlyBlock }); @@ -1538,6 +1549,7 @@ } var identifier$1 = /*#__PURE__*/Object.freeze({ + __proto__: null, Identifier: Identifier$1 }); @@ -1546,6 +1558,7 @@ } var literal$1 = /*#__PURE__*/Object.freeze({ + __proto__: null, Literal: Literal$1 }); @@ -2011,6 +2024,7 @@ } var expression$1 = /*#__PURE__*/Object.freeze({ + __proto__: null, ThisExpression: ThisExpression$1, ArrayExpression: ArrayExpression$1, ObjectExpression: ObjectExpression$1, @@ -2088,7 +2102,10 @@ } if (matched) { const result = yield* SwitchCase$1(eachCase, scope); - if (result === BREAK || result === CONTINUE || result === RETURN) { + if (result === BREAK) { + break; + } + if (result === CONTINUE || result === RETURN) { return result; } } @@ -2116,7 +2133,7 @@ if (param) { if (param.type === 'Identifier') { const name = param.name; - subScope.let(name, err); + subScope.var(name, err); } else { yield* pattern$2(param, scope, { feed: err }); @@ -2239,6 +2256,7 @@ } var statement$1 = /*#__PURE__*/Object.freeze({ + __proto__: null, ExpressionStatement: ExpressionStatement$1, BlockStatement: BlockStatement$1, EmptyStatement: EmptyStatement$1, @@ -2260,7 +2278,7 @@ }); function* ObjectPattern$1(node, scope, options = {}) { - const { kind = 'let', hoist = false, onlyBlock = false, feed = {} } = options; + const { kind = 'var', hoist = false, onlyBlock = false, feed = {} } = options; const fedKeys = []; for (let i = 0; i < node.properties.length; i++) { const property = node.properties[i]; @@ -2269,7 +2287,7 @@ if (property.type === 'Property') { const value = property.value; if (value.type === 'Identifier') { - scope[onlyBlock ? kind : 'var'](value.name, onlyBlock ? DEADZONE : undefined); + scope[kind](value.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined); } else { yield* pattern$2(value, scope, { kind, hoist, onlyBlock }); @@ -2315,7 +2333,7 @@ if (hoist) { if (onlyBlock || kind === 'var') { if (element.type === 'Identifier') { - scope[onlyBlock ? kind : 'var'](element.name, onlyBlock ? DEADZONE : undefined); + scope[kind](element.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined); } else { yield* pattern$2(element, scope, { kind, hoist, onlyBlock }); @@ -2349,7 +2367,7 @@ if (hoist) { if (onlyBlock || kind === 'var') { if (arg.type === 'Identifier') { - scope[onlyBlock ? kind : 'var'](arg.name, onlyBlock ? DEADZONE : undefined); + scope[kind](arg.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined); } else { yield* pattern$2(arg, scope, { kind, hoist, onlyBlock }); @@ -2370,12 +2388,12 @@ } } function* AssignmentPattern$1(node, scope, options = {}) { - const { kind = 'let', hoist = false, onlyBlock = false, feed = yield* evaluate$1(node.right, scope) } = options; + const { kind = 'var', hoist = false, onlyBlock = false, feed = yield* evaluate$1(node.right, scope) } = options; const left = node.left; if (hoist) { if (onlyBlock || kind === 'var') { if (left.type === 'Identifier') { - scope[onlyBlock ? kind : 'var'](left.name, onlyBlock ? DEADZONE : undefined); + scope[kind](left.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined); } else { yield* pattern$2(left, scope, { kind, hoist, onlyBlock }); @@ -2391,6 +2409,7 @@ } var pattern$1 = /*#__PURE__*/Object.freeze({ + __proto__: null, ObjectPattern: ObjectPattern$1, ArrayPattern: ArrayPattern$1, RestElement: RestElement$1, @@ -2422,11 +2441,11 @@ } } function* VariableDeclarator$1(node, scope, options = {}) { - const { kind = 'let', hoist = false, onlyBlock = false, feed } = options; + const { kind = 'var', hoist = false, onlyBlock = false, feed } = options; if (hoist) { if (onlyBlock || kind === 'var') { if (node.id.type === 'Identifier') { - scope[onlyBlock ? kind : 'var'](node.id.name, onlyBlock ? DEADZONE : undefined); + scope[kind](node.id.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined); } else { yield* pattern$2(node.id, scope, { kind, hoist, onlyBlock }); @@ -2666,10 +2685,10 @@ for (let i = 0; i < params.length; i++) { const param = params[i]; if (param.type === 'Identifier') { - subScope.let(param.name, args[i]); + subScope.var(param.name, args[i]); } else if (param.type === 'RestElement') { - yield* RestElement$1(param, subScope, { kind: 'let', feed: args.slice(i) }); + yield* RestElement$1(param, subScope, { kind: 'var', feed: args.slice(i) }); } else { yield* pattern$2(param, subScope, { feed: args[i] }); @@ -2697,7 +2716,7 @@ let func; if (node.async && node.generator) { func = function () { - const iterator = tmpFunc.apply(void 0, arguments); + const iterator = tmpFunc.apply(this, arguments); let last = Promise.resolve(); let hasCatch = false; const run = (opts) => last = last @@ -2720,7 +2739,7 @@ }; } else if (node.async) { - func = function () { return runAsync(tmpFunc.apply(void 0, arguments)); }; + func = function () { return runAsync(tmpFunc.apply(this, arguments)); }; } else { func = tmpFunc; @@ -2893,10 +2912,10 @@ for (let i = 0; i < params.length; i++) { const param = params[i]; if (param.type === 'Identifier') { - subScope.let(param.name, args[i]); + subScope.var(param.name, args[i]); } else if (param.type === 'RestElement') { - RestElement(param, subScope, { kind: 'let', feed: args.slice(i) }); + RestElement(param, subScope, { kind: 'var', feed: args.slice(i) }); } else { pattern$3(param, subScope, { feed: args[i] }); @@ -3021,8 +3040,14 @@ this.scope.var(name, nameOrModules[name]); } } + parse(code, parser) { + if (typeof parser === 'function') { + return parser(code, assign({}, this.options)); + } + return acorn.parse(code, this.options); + } run(code) { - const ast = acorn.parse(code, this.options); + const ast = typeof code === 'string' ? acorn.parse(code, this.options) : code; hoist$1(ast, this.scope); evaluate(ast, this.scope); } @@ -3031,4 +3056,4 @@ return Sval; -})); +}))); diff --git a/dist/sval.js b/dist/sval.js index 597d5af..d86d167 100644 --- a/dist/sval.js +++ b/dist/sval.js @@ -2,9 +2,10 @@ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('acorn')) : typeof define === 'function' && define.amd ? define(['acorn'], factory) : (global = global || self, global.Sval = factory(global.acorn)); -}(this, function (acorn) { 'use strict'; +}(this, (function (acorn) { 'use strict'; var declaration = /*#__PURE__*/Object.freeze({ + __proto__: null, get FunctionDeclaration () { return FunctionDeclaration; }, get VariableDeclaration () { return VariableDeclaration; }, get VariableDeclarator () { return VariableDeclarator; }, @@ -13,6 +14,7 @@ get MethodDefinition () { return MethodDefinition; } }); var declaration$1 = /*#__PURE__*/Object.freeze({ + __proto__: null, get FunctionDeclaration () { return FunctionDeclaration$1; }, get VariableDeclaration () { return VariableDeclaration$1; }, get VariableDeclarator () { return VariableDeclarator$1; }, @@ -380,7 +382,7 @@ } } - var version = "0.4.6"; + var version = "0.4.7"; var AWAIT = { RES: undefined }; var RETURN = { RES: undefined }; @@ -633,6 +635,7 @@ } var identifier = /*#__PURE__*/Object.freeze({ + __proto__: null, Identifier: Identifier }); @@ -641,6 +644,7 @@ } var literal = /*#__PURE__*/Object.freeze({ + __proto__: null, Literal: Literal }); @@ -1100,6 +1104,7 @@ } var expression = /*#__PURE__*/Object.freeze({ + __proto__: null, ThisExpression: ThisExpression, ArrayExpression: ArrayExpression, ObjectExpression: ObjectExpression, @@ -1176,7 +1181,10 @@ } if (matched) { var result = SwitchCase(eachCase, scope); - if (result === BREAK || result === CONTINUE || result === RETURN) { + if (result === BREAK) { + break; + } + if (result === CONTINUE || result === RETURN) { return result; } } @@ -1204,7 +1212,7 @@ if (param) { if (param.type === 'Identifier') { var name_1 = param.name; - subScope.let(name_1, err); + subScope.var(name_1, err); } else { pattern$3(param, scope, { feed: err }); @@ -1320,6 +1328,7 @@ } var statement = /*#__PURE__*/Object.freeze({ + __proto__: null, ExpressionStatement: ExpressionStatement, BlockStatement: BlockStatement, EmptyStatement: EmptyStatement, @@ -1342,7 +1351,7 @@ function ObjectPattern(node, scope, options) { if (options === void 0) { options = {}; } - var _a = options.kind, kind = _a === void 0 ? 'let' : _a, _b = options.hoist, hoist = _b === void 0 ? false : _b, _c = options.onlyBlock, onlyBlock = _c === void 0 ? false : _c, _d = options.feed, feed = _d === void 0 ? {} : _d; + var _a = options.kind, kind = _a === void 0 ? 'var' : _a, _b = options.hoist, hoist = _b === void 0 ? false : _b, _c = options.onlyBlock, onlyBlock = _c === void 0 ? false : _c, _d = options.feed, feed = _d === void 0 ? {} : _d; var fedKeys = []; for (var i = 0; i < node.properties.length; i++) { var property = node.properties[i]; @@ -1351,7 +1360,7 @@ if (property.type === 'Property') { var value = property.value; if (value.type === 'Identifier') { - scope[onlyBlock ? kind : 'var'](value.name, onlyBlock ? DEADZONE : undefined); + scope[kind](value.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined); } else { pattern$3(value, scope, { kind: kind, hoist: hoist, onlyBlock: onlyBlock }); @@ -1398,7 +1407,7 @@ if (hoist) { if (onlyBlock || kind === 'var') { if (element.type === 'Identifier') { - scope[onlyBlock ? kind : 'var'](element.name, onlyBlock ? DEADZONE : undefined); + scope[kind](element.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined); } else { pattern$3(element, scope, { kind: kind, hoist: hoist, onlyBlock: onlyBlock }); @@ -1433,7 +1442,7 @@ if (hoist) { if (onlyBlock || kind === 'var') { if (arg.type === 'Identifier') { - scope[onlyBlock ? kind : 'var'](arg.name, onlyBlock ? DEADZONE : undefined); + scope[kind](arg.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined); } else { pattern$3(arg, scope, { kind: kind, hoist: hoist, onlyBlock: onlyBlock }); @@ -1455,12 +1464,12 @@ } function AssignmentPattern(node, scope, options) { if (options === void 0) { options = {}; } - var _a = options.kind, kind = _a === void 0 ? 'let' : _a, _b = options.hoist, hoist = _b === void 0 ? false : _b, _c = options.onlyBlock, onlyBlock = _c === void 0 ? false : _c, _d = options.feed, feed = _d === void 0 ? evaluate(node.right, scope) : _d; + var _a = options.kind, kind = _a === void 0 ? 'var' : _a, _b = options.hoist, hoist = _b === void 0 ? false : _b, _c = options.onlyBlock, onlyBlock = _c === void 0 ? false : _c, _d = options.feed, feed = _d === void 0 ? evaluate(node.right, scope) : _d; var left = node.left; if (hoist) { if (onlyBlock || kind === 'var') { if (left.type === 'Identifier') { - scope[onlyBlock ? kind : 'var'](left.name, onlyBlock ? DEADZONE : undefined); + scope[kind](left.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined); } else { pattern$3(left, scope, { kind: kind, hoist: hoist, onlyBlock: onlyBlock }); @@ -1476,6 +1485,7 @@ } var pattern = /*#__PURE__*/Object.freeze({ + __proto__: null, ObjectPattern: ObjectPattern, ArrayPattern: ArrayPattern, RestElement: RestElement, @@ -1489,6 +1499,7 @@ } var program = /*#__PURE__*/Object.freeze({ + __proto__: null, Program: Program }); @@ -1519,11 +1530,11 @@ } function VariableDeclarator(node, scope, options) { if (options === void 0) { options = {}; } - var _a = options.kind, kind = _a === void 0 ? 'let' : _a, _b = options.hoist, hoist = _b === void 0 ? false : _b, _c = options.onlyBlock, onlyBlock = _c === void 0 ? false : _c, feed = options.feed; + var _a = options.kind, kind = _a === void 0 ? 'var' : _a, _b = options.hoist, hoist = _b === void 0 ? false : _b, _c = options.onlyBlock, onlyBlock = _c === void 0 ? false : _c, feed = options.feed; if (hoist) { if (onlyBlock || kind === 'var') { if (node.id.type === 'Identifier') { - scope[onlyBlock ? kind : 'var'](node.id.name, onlyBlock ? DEADZONE : undefined); + scope[kind](node.id.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined); } else { pattern$3(node.id, scope, { kind: kind, hoist: hoist, onlyBlock: onlyBlock }); @@ -1643,11 +1654,11 @@ else { return [2, undefined]; } - return [2]; }); } var identifier$1 = /*#__PURE__*/Object.freeze({ + __proto__: null, Identifier: Identifier$1 }); @@ -1658,6 +1669,7 @@ } var literal$1 = /*#__PURE__*/Object.freeze({ + __proto__: null, Literal: Literal$1 }); @@ -1672,7 +1684,6 @@ else { return [2, scope.find('this').get()]; } - return [2]; }); } function ArrayExpression$1(node, scope) { @@ -1786,7 +1797,6 @@ else { return [2, createFunc(node, scope)]; } - return [2]; }); } function UnaryExpression$1(node, scope) { @@ -1870,7 +1880,6 @@ else { throw new SyntaxError("Unexpected token " + node.operator); } - return [2]; } }); } @@ -1909,7 +1918,6 @@ case 'instanceof': return [2, left instanceof right]; default: throw new SyntaxError("Unexpected token " + node.operator); } - return [2]; } }); } @@ -1981,7 +1989,6 @@ return [2, variable.get()]; default: throw new SyntaxError("Unexpected token " + node.operator); } - return [2]; } }); } @@ -2068,7 +2075,6 @@ return [2, object[key]]; } } - return [2]; } }); } @@ -2398,6 +2404,7 @@ } var expression$1 = /*#__PURE__*/Object.freeze({ + __proto__: null, ThisExpression: ThisExpression$1, ArrayExpression: ArrayExpression$1, ObjectExpression: ObjectExpression$1, @@ -2552,7 +2559,10 @@ return [5, __values(SwitchCase$1(eachCase, scope))]; case 6: result = _c.sent(); - if (result === BREAK || result === CONTINUE || result === RETURN) { + if (result === BREAK) { + return [3, 8]; + } + if (result === CONTINUE || result === RETURN) { return [2, result]; } _c.label = 7; @@ -2610,7 +2620,7 @@ if (!param) return [3, 5]; if (!(param.type === 'Identifier')) return [3, 3]; name_1 = param.name; - subScope.let(name_1, err_1); + subScope.var(name_1, err_1); return [3, 5]; case 3: return [5, __values(pattern$2(param, scope, { feed: err_1 }))]; case 4: @@ -2855,6 +2865,7 @@ } var statement$1 = /*#__PURE__*/Object.freeze({ + __proto__: null, ExpressionStatement: ExpressionStatement$1, BlockStatement: BlockStatement$1, EmptyStatement: EmptyStatement$1, @@ -2881,7 +2892,7 @@ return __generator(this, function (_e) { switch (_e.label) { case 0: - _a = options.kind, kind = _a === void 0 ? 'let' : _a, _b = options.hoist, hoist = _b === void 0 ? false : _b, _c = options.onlyBlock, onlyBlock = _c === void 0 ? false : _c, _d = options.feed, feed = _d === void 0 ? {} : _d; + _a = options.kind, kind = _a === void 0 ? 'var' : _a, _b = options.hoist, hoist = _b === void 0 ? false : _b, _c = options.onlyBlock, onlyBlock = _c === void 0 ? false : _c, _d = options.feed, feed = _d === void 0 ? {} : _d; fedKeys = []; i = 0; _e.label = 1; @@ -2893,7 +2904,7 @@ if (!(property.type === 'Property')) return [3, 5]; value = property.value; if (!(value.type === 'Identifier')) return [3, 2]; - scope[onlyBlock ? kind : 'var'](value.name, onlyBlock ? DEADZONE : undefined); + scope[kind](value.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined); return [3, 4]; case 2: return [5, __values(pattern$2(value, scope, { kind: kind, hoist: hoist, onlyBlock: onlyBlock }))]; case 3: @@ -2960,7 +2971,7 @@ if (!hoist) return [3, 5]; if (!(onlyBlock || kind === 'var')) return [3, 4]; if (!(element.type === 'Identifier')) return [3, 2]; - scope[onlyBlock ? kind : 'var'](element.name, onlyBlock ? DEADZONE : undefined); + scope[kind](element.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined); return [3, 4]; case 2: return [5, __values(pattern$2(element, scope, { kind: kind, hoist: hoist, onlyBlock: onlyBlock }))]; case 3: @@ -3011,7 +3022,7 @@ if (!hoist) return [3, 4]; if (!(onlyBlock || kind === 'var')) return [3, 3]; if (!(arg.type === 'Identifier')) return [3, 1]; - scope[onlyBlock ? kind : 'var'](arg.name, onlyBlock ? DEADZONE : undefined); + scope[kind](arg.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined); return [3, 3]; case 1: return [5, __values(pattern$2(arg, scope, { kind: kind, hoist: hoist, onlyBlock: onlyBlock }))]; case 2: @@ -3043,7 +3054,7 @@ return __generator(this, function (_f) { switch (_f.label) { case 0: - _a = options.kind, kind = _a === void 0 ? 'let' : _a, _b = options.hoist, hoist = _b === void 0 ? false : _b, _c = options.onlyBlock, onlyBlock = _c === void 0 ? false : _c, _d = options.feed; + _a = options.kind, kind = _a === void 0 ? 'var' : _a, _b = options.hoist, hoist = _b === void 0 ? false : _b, _c = options.onlyBlock, onlyBlock = _c === void 0 ? false : _c, _d = options.feed; if (!(_d === void 0)) return [3, 2]; return [5, __values(evaluate$1(node.right, scope))]; case 1: @@ -3058,7 +3069,7 @@ if (!hoist) return [3, 7]; if (!(onlyBlock || kind === 'var')) return [3, 6]; if (!(left.type === 'Identifier')) return [3, 4]; - scope[onlyBlock ? kind : 'var'](left.name, onlyBlock ? DEADZONE : undefined); + scope[kind](left.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined); return [3, 6]; case 4: return [5, __values(pattern$2(left, scope, { kind: kind, hoist: hoist, onlyBlock: onlyBlock }))]; case 5: @@ -3079,6 +3090,7 @@ } var pattern$1 = /*#__PURE__*/Object.freeze({ + __proto__: null, ObjectPattern: ObjectPattern$1, ArrayPattern: ArrayPattern$1, RestElement: RestElement$1, @@ -3138,11 +3150,11 @@ return __generator(this, function (_e) { switch (_e.label) { case 0: - _a = options.kind, kind = _a === void 0 ? 'let' : _a, _b = options.hoist, hoist = _b === void 0 ? false : _b, _c = options.onlyBlock, onlyBlock = _c === void 0 ? false : _c, feed = options.feed; + _a = options.kind, kind = _a === void 0 ? 'var' : _a, _b = options.hoist, hoist = _b === void 0 ? false : _b, _c = options.onlyBlock, onlyBlock = _c === void 0 ? false : _c, feed = options.feed; if (!hoist) return [3, 4]; if (!(onlyBlock || kind === 'var')) return [3, 3]; if (!(node.id.type === 'Identifier')) return [3, 1]; - scope[onlyBlock ? kind : 'var'](node.id.name, onlyBlock ? DEADZONE : undefined); + scope[kind](node.id.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined); return [3, 3]; case 1: return [5, __values(pattern$2(node.id, scope, { kind: kind, hoist: hoist, onlyBlock: onlyBlock }))]; case 2: @@ -3538,11 +3550,11 @@ if (!(i < params.length)) return [3, 7]; param = params[i]; if (!(param.type === 'Identifier')) return [3, 2]; - subScope.let(param.name, args[i]); + subScope.var(param.name, args[i]); return [3, 6]; case 2: if (!(param.type === 'RestElement')) return [3, 4]; - return [5, __values(RestElement$1(param, subScope, { kind: 'let', feed: args.slice(i) }))]; + return [5, __values(RestElement$1(param, subScope, { kind: 'var', feed: args.slice(i) }))]; case 3: _a.sent(); return [3, 6]; @@ -3584,7 +3596,7 @@ var func; if (node.async && node.generator) { func = function () { - var iterator = tmpFunc.apply(void 0, arguments); + var iterator = tmpFunc.apply(this, arguments); var last = Promise.resolve(); var hasCatch = false; var run = function (opts) { @@ -3609,7 +3621,7 @@ }; } else if (node.async) { - func = function () { return runAsync(tmpFunc.apply(void 0, arguments)); }; + func = function () { return runAsync(tmpFunc.apply(this, arguments)); }; } else { func = tmpFunc; @@ -3814,10 +3826,10 @@ for (var i = 0; i < params.length; i++) { var param = params[i]; if (param.type === 'Identifier') { - subScope.let(param.name, args[i]); + subScope.var(param.name, args[i]); } else if (param.type === 'RestElement') { - RestElement(param, subScope, { kind: 'let', feed: args.slice(i) }); + RestElement(param, subScope, { kind: 'var', feed: args.slice(i) }); } else { pattern$3(param, subScope, { feed: args[i] }); @@ -3944,8 +3956,14 @@ this.scope.var(name_1, nameOrModules[name_1]); } }; + Sval.prototype.parse = function (code, parser) { + if (typeof parser === 'function') { + return parser(code, assign({}, this.options)); + } + return acorn.parse(code, this.options); + }; Sval.prototype.run = function (code) { - var ast = acorn.parse(code, this.options); + var ast = typeof code === 'string' ? acorn.parse(code, this.options) : code; hoist$1(ast, this.scope); evaluate(ast, this.scope); }; @@ -3955,4 +3973,4 @@ return Sval; -})); +}))); diff --git a/dist/sval.min.js b/dist/sval.min.js index fef4f20..a95ea20 100644 --- a/dist/sval.min.js +++ b/dist/sval.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).Sval=t()}(this,function(){"use strict";var n=Object.freeze({get FunctionDeclaration(){return Lt},get VariableDeclaration(){return Rt},get VariableDeclarator(){return Ot},get ClassDeclaration(){return Bt},get ClassBody(){return Dt},get MethodDefinition(){return Mt}}),i=Object.freeze({get FunctionDeclaration(){return sr},get VariableDeclaration(){return ar},get VariableDeclarator(){return or},get ClassDeclaration(){return cr},get ClassBody(){return ur},get MethodDefinition(){return hr}}),l=Object.freeze,m=Object.defineProperty,f=Object.getOwnPropertyDescriptor,a=Object.prototype.hasOwnProperty;var o=Object.getOwnPropertyNames,r=Object.setPrototypeOf;var c=Object.getPrototypeOf;var u=Object.getOwnPropertyDescriptor;function s(e,t,r){for(;t;){var n=u(t,r),i=void 0!==n&&void 0===n.writable&&"function"==typeof n[e]&&n[e];if(i)return i;s=t,t=c?c(s):s.__proto__}var s}function y(e,t){return s("get",e,t)}function g(e,t){return s("set",e,t)}var h=Object.create;function p(e,t){!function(e,t){r?r(e,t):e.__proto__=t}(e,t),e.prototype=h(t.prototype,{constructor:{value:e,writable:!0}})}var x=Object.assign||function(e){for(var t=1;t",D),template:new O("template"),invalidTemplate:new O("invalidTemplate"),ellipsis:new O("...",D),backQuote:new O("`",M),dollarBraceL:new O("${",{beforeExpr:!0,startsExpr:!0}),eq:new O("=",{beforeExpr:!0,isAssign:!0}),assign:new O("_=",{beforeExpr:!0,isAssign:!0}),incDec:new O("++/--",{prefix:!0,postfix:!0,startsExpr:!0}),prefix:new O("!/~",{beforeExpr:!0,prefix:!0,startsExpr:!0}),logicalOR:B("||",1),logicalAND:B("&&",2),bitwiseOR:B("|",3),bitwiseXOR:B("^",4),bitwiseAND:B("&",5),equality:B("==/!=/===/!==",6),relational:B("/<=/>=",7),bitShift:B("<>/>>>",8),plusMin:new O("+/-",{beforeExpr:!0,binop:9,prefix:!0,startsExpr:!0}),modulo:B("%",10),star:B("*",10),slash:B("/",10),starstar:new O("**",{beforeExpr:!0}),_break:U("break"),_case:U("case",D),_catch:U("catch"),_continue:U("continue"),_debugger:U("debugger"),_default:U("default",D),_do:U("do",{isLoop:!0,beforeExpr:!0}),_else:U("else",D),_finally:U("finally"),_for:U("for",{isLoop:!0}),_function:U("function",M),_if:U("if"),_return:U("return",D),_switch:U("switch"),_throw:U("throw",D),_try:U("try"),_var:U("var"),_const:U("const"),_while:U("while",{isLoop:!0}),_with:U("with"),_new:U("new",{beforeExpr:!0,startsExpr:!0}),_this:U("this",M),_super:U("super",M),_class:U("class",M),_extends:U("extends",D),_export:U("export"),_import:U("import"),_null:U("null",M),_true:U("true",M),_false:U("false",M),_in:U("in",{beforeExpr:!0,binop:7}),_instanceof:U("instanceof",{beforeExpr:!0,binop:7}),_typeof:U("typeof",{beforeExpr:!0,prefix:!0,startsExpr:!0}),_void:U("void",{beforeExpr:!0,prefix:!0,startsExpr:!0}),_delete:U("delete",{beforeExpr:!0,prefix:!0,startsExpr:!0})},q=/\r\n?|\n|\u2028|\u2029/,z=new RegExp(q.source,"g");function W(e,t){return 10===e||13===e||!t&&(8232===e||8233===e)}var G=/[\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]/,H=/(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g,Q=Object.prototype,K=Q.hasOwnProperty,X=Q.toString;function Y(e,t){return K.call(e,t)}var J=Array.isArray||function(e){return"[object Array]"===X.call(e)};function Z(e){return new RegExp("^(?:"+e.replace(/ /g,"|")+")$")}function $(e,t){this.line=e,this.column=t}var ee=function(e,t,r){this.start=t,this.end=r,null!==e.sourceFile&&(this.source=e.sourceFile)};var te={ecmaVersion:9,sourceType:"script",onInsertedSemicolon:null,onTrailingComma:null,allowReserved:null,allowReturnOutsideFunction:!($.prototype.offset=function(e){return new $(this.line,this.column+e)}),allowImportExportEverywhere:!1,allowAwaitOutsideFunction:!1,allowHashBang:!1,locations:!1,onToken:null,onComment:null,ranges:!1,program:null,sourceFile:null,directSourceFile:null,preserveParens:!1};function re(e){var t={};for(var r in te)t[r]=e&&Y(e,r)?e[r]:te[r];if(2015<=t.ecmaVersion&&(t.ecmaVersion-=2009),null==t.allowReserved&&(t.allowReserved=t.ecmaVersion<5),J(t.onToken)){var n=t.onToken;t.onToken=function(e){return n.push(e)}}return J(t.onComment)&&(t.onComment=function(o,c){return function(e,t,r,n,i,s){var a={type:e?"Block":"Line",value:t,start:r,end:n};o.locations&&(a.loc=new ee(this,i,s)),o.ranges&&(a.range=[r,n]),c.push(a)}}(t,t.onComment)),t}function ne(e,t){return 2|(e?4:0)|(t?8:0)}function ie(e,t,r){this.options=e=re(e),this.sourceFile=e.sourceFile,this.keywords=Z(E[6<=e.ecmaVersion?6:5]);var n="";if(!e.allowReserved){for(var i=e.ecmaVersion;!(n=k[i]);i--);"module"===e.sourceType&&(n+=" await")}this.reservedWords=Z(n);var s=(n?n+" ":"")+k.strict;this.reservedWordsStrict=Z(s),this.reservedWordsStrictBind=Z(s+" "+k.strictBind),this.input=String(t),this.containsEsc=!1,r?(this.pos=r,this.lineStart=this.input.lastIndexOf("\n",r-1)+1,this.curLine=this.input.slice(0,this.lineStart).split(q).length):(this.pos=this.lineStart=0,this.curLine=1),this.type=j.eof,this.value=null,this.start=this.end=this.pos,this.startLoc=this.endLoc=this.curPosition(),this.lastTokEndLoc=this.lastTokStartLoc=null,this.lastTokStart=this.lastTokEnd=this.pos,this.context=this.initialContext(),this.exprAllowed=!0,this.inModule="module"===e.sourceType,this.strict=this.inModule||this.strictDirective(this.pos),this.potentialArrowAt=-1,this.yieldPos=this.awaitPos=this.awaitIdentPos=0,this.labels=[],this.undefinedExports={},0===this.pos&&e.allowHashBang&&"#!"===this.input.slice(0,2)&&this.skipLineComment(2),this.scopeStack=[],this.enterScope(1),this.regexpState=null}var se={inFunction:{configurable:!0},inGenerator:{configurable:!0},inAsync:{configurable:!0},allowSuper:{configurable:!0},allowDirectSuper:{configurable:!0},treatFunctionsAsVar:{configurable:!0}};ie.prototype.parse=function(){var e=this.options.program||this.startNode();return this.nextToken(),this.parseTopLevel(e)},se.inFunction.get=function(){return 0<(2&this.currentVarScope().flags)},se.inGenerator.get=function(){return 0<(8&this.currentVarScope().flags)},se.inAsync.get=function(){return 0<(4&this.currentVarScope().flags)},se.allowSuper.get=function(){return 0<(64&this.currentThisScope().flags)},se.allowDirectSuper.get=function(){return 0<(128&this.currentThisScope().flags)},se.treatFunctionsAsVar.get=function(){return this.treatFunctionsAsVarInScope(this.currentScope())},ie.prototype.inNonArrowFunction=function(){return 0<(2&this.currentThisScope().flags)},ie.extend=function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];for(var r=this,n=0;n>10),56320+(1023&e)))}function De(e){return 36===e||40<=e&&e<=43||46===e||63===e||91<=e&&e<=94||123<=e&&e<=125}function Me(e){return 65<=e&&e<=90||97<=e&&e<=122}function Fe(e){return Me(e)||95===e}function Ue(e){return 48<=e&&e<=57}function je(e){return 48<=e&&e<=57||65<=e&&e<=70||97<=e&&e<=102}function qe(e){return 65<=e&&e<=70?e-65+10:97<=e&&e<=102?e-97+10:e-48}function ze(e){return 48<=e&&e<=55}Re.prototype.reset=function(e,t,r){var n=-1!==r.indexOf("u");this.start=0|e,this.source=t+"",this.flags=r,this.switchU=n&&6<=this.parser.options.ecmaVersion,this.switchN=n&&9<=this.parser.options.ecmaVersion},Re.prototype.raise=function(e){this.parser.raiseRecoverable(this.start,"Invalid regular expression: /"+this.source+"/: "+e)},Re.prototype.at=function(e){var t=this.source,r=t.length;if(r<=e)return-1;var n=t.charCodeAt(e);return!this.switchU||n<=55295||57344<=n||r<=e+1?n:(n<<10)+t.charCodeAt(e+1)-56613888},Re.prototype.nextIndex=function(e){var t=this.source,r=t.length;if(r<=e)return r;var n=t.charCodeAt(e);return!this.switchU||n<=55295||57344<=n||r<=e+1?e+1:e+2},Re.prototype.current=function(){return this.at(this.pos)},Re.prototype.lookahead=function(){return this.at(this.nextIndex(this.pos))},Re.prototype.advance=function(){this.pos=this.nextIndex(this.pos)},Re.prototype.eat=function(e){return this.current()===e&&(this.advance(),!0)},Oe.validateRegExpFlags=function(e){for(var t=e.validFlags,r=e.flags,n=0;ne.numCapturingParens&&e.raise("Invalid escape");for(var t=0,r=e.backReferenceNames;te.maxBackReference&&(e.maxBackReference=r),!0;if(r<=e.numCapturingParens)return!0;e.pos=t}return!1},Oe.regexp_eatKGroupName=function(e){if(e.eat(107)){if(this.regexp_eatGroupName(e))return e.backReferenceNames.push(e.lastStringValue),!0;e.raise("Invalid named reference")}return!1},Oe.regexp_eatCharacterEscape=function(e){return this.regexp_eatControlEscape(e)||this.regexp_eatCControlLetter(e)||this.regexp_eatZero(e)||this.regexp_eatHexEscapeSequence(e)||this.regexp_eatRegExpUnicodeEscapeSequence(e)||!e.switchU&&this.regexp_eatLegacyOctalEscapeSequence(e)||this.regexp_eatIdentityEscape(e)},Oe.regexp_eatCControlLetter=function(e){var t=e.pos;if(e.eat(99)){if(this.regexp_eatControlLetter(e))return!0;e.pos=t}return!1},Oe.regexp_eatZero=function(e){return 48===e.current()&&!Ue(e.lookahead())&&(e.lastIntValue=0,e.advance(),!0)},Oe.regexp_eatControlEscape=function(e){var t=e.current();return 116===t?(e.lastIntValue=9,e.advance(),!0):110===t?(e.lastIntValue=10,e.advance(),!0):118===t?(e.lastIntValue=11,e.advance(),!0):102===t?(e.lastIntValue=12,e.advance(),!0):114===t&&(e.lastIntValue=13,e.advance(),!0)},Oe.regexp_eatControlLetter=function(e){var t=e.current();return!!Me(t)&&(e.lastIntValue=t%32,e.advance(),!0)},Oe.regexp_eatRegExpUnicodeEscapeSequence=function(e){var t=e.pos;if(e.eat(117)){if(this.regexp_eatFixedHexDigits(e,4)){var r=e.lastIntValue;if(e.switchU&&55296<=r&&r<=56319){var n=e.pos;if(e.eat(92)&&e.eat(117)&&this.regexp_eatFixedHexDigits(e,4)){var i=e.lastIntValue;if(56320<=i&&i<=57343)return e.lastIntValue=1024*(r-55296)+(i-56320)+65536,!0}e.pos=n,e.lastIntValue=r}return!0}if(e.switchU&&e.eat(123)&&this.regexp_eatHexDigits(e)&&e.eat(125)&&function(e){return 0<=e&&e<=1114111}(e.lastIntValue))return!0;e.switchU&&e.raise("Invalid unicode escape"),e.pos=t}return!1},Oe.regexp_eatIdentityEscape=function(e){if(e.switchU)return!!this.regexp_eatSyntaxCharacter(e)||!!e.eat(47)&&(e.lastIntValue=47,!0);var t=e.current();return!(99===t||e.switchN&&107===t)&&(e.lastIntValue=t,e.advance(),!0)},Oe.regexp_eatDecimalEscape=function(e){e.lastIntValue=0;var t=e.current();if(49<=t&&t<=57){for(;e.lastIntValue=10*e.lastIntValue+(t-48),e.advance(),48<=(t=e.current())&&t<=57;);return!0}return!1},Oe.regexp_eatCharacterClassEscape=function(e){var t=e.current();if(function(e){return 100===e||68===e||115===e||83===e||119===e||87===e}(t))return e.lastIntValue=-1,e.advance(),!0;if(e.switchU&&9<=this.options.ecmaVersion&&(80===t||112===t)){if(e.lastIntValue=-1,e.advance(),e.eat(123)&&this.regexp_eatUnicodePropertyValueExpression(e)&&e.eat(125))return!0;e.raise("Invalid property name")}return!1},Oe.regexp_eatUnicodePropertyValueExpression=function(e){var t=e.pos;if(this.regexp_eatUnicodePropertyName(e)&&e.eat(61)){var r=e.lastStringValue;if(this.regexp_eatUnicodePropertyValue(e)){var n=e.lastStringValue;return this.regexp_validateUnicodePropertyNameAndValue(e,r,n),!0}}if(e.pos=t,this.regexp_eatLoneUnicodePropertyNameOrValue(e)){var i=e.lastStringValue;return this.regexp_validateUnicodePropertyNameOrValue(e,i),!0}return!1},Oe.regexp_validateUnicodePropertyNameAndValue=function(e,t,r){Y(e.unicodeProperties.nonBinary,t)||e.raise("Invalid property name"),e.unicodeProperties.nonBinary[t].test(r)||e.raise("Invalid property value")},Oe.regexp_validateUnicodePropertyNameOrValue=function(e,t){e.unicodeProperties.binary.test(t)||e.raise("Invalid property name")},Oe.regexp_eatUnicodePropertyName=function(e){var t=0;for(e.lastStringValue="";Fe(t=e.current());)e.lastStringValue+=Be(t),e.advance();return""!==e.lastStringValue},Oe.regexp_eatUnicodePropertyValue=function(e){var t,r=0;for(e.lastStringValue="";Fe(t=r=e.current())||Ue(t);)e.lastStringValue+=Be(r),e.advance();return""!==e.lastStringValue},Oe.regexp_eatLoneUnicodePropertyNameOrValue=function(e){return this.regexp_eatUnicodePropertyValue(e)},Oe.regexp_eatCharacterClass=function(e){if(e.eat(91)){if(e.eat(94),this.regexp_classRanges(e),e.eat(93))return!0;e.raise("Unterminated character class")}return!1},Oe.regexp_classRanges=function(e){for(;this.regexp_eatClassAtom(e);){var t=e.lastIntValue;if(e.eat(45)&&this.regexp_eatClassAtom(e)){var r=e.lastIntValue;!e.switchU||-1!==t&&-1!==r||e.raise("Invalid character class"),-1!==t&&-1!==r&&r>10),56320+(1023&e)))}Ge.next=function(){this.options.onToken&&this.options.onToken(new We(this)),this.lastTokEnd=this.end,this.lastTokStart=this.start,this.lastTokEndLoc=this.endLoc,this.lastTokStartLoc=this.startLoc,this.nextToken()},Ge.getToken=function(){return this.next(),new We(this)},"undefined"!=typeof Symbol&&(Ge[Symbol.iterator]=function(){var t=this;return{next:function(){var e=t.getToken();return{done:e.type===j.eof,value:e}}}}),Ge.curContext=function(){return this.context[this.context.length-1]},Ge.nextToken=function(){var e=this.curContext();return e&&e.preserveSpace||this.skipSpace(),this.start=this.pos,this.options.locations&&(this.startLoc=this.curPosition()),this.pos>=this.input.length?this.finishToken(j.eof):e.override?e.override(this):void this.readToken(this.fullCharCodeAtPos())},Ge.readToken=function(e){return L(e,6<=this.options.ecmaVersion)||92===e?this.readWord():this.getTokenFromCode(e)},Ge.fullCharCodeAtPos=function(){var e=this.input.charCodeAt(this.pos);return e<=55295||57344<=e?e:(e<<10)+this.input.charCodeAt(this.pos+1)-56613888},Ge.skipBlockComment=function(){var e,t=this.options.onComment&&this.curPosition(),r=this.pos,n=this.input.indexOf("*/",this.pos+=2);if(-1===n&&this.raise(this.pos-2,"Unterminated comment"),this.pos=n+2,this.options.locations)for(z.lastIndex=r;(e=z.exec(this.input))&&e.index=r.input.length&&r.raise(n,"Unterminated regular expression");var i=r.input.charAt(r.pos);if(q.test(i)&&r.raise(n,"Unterminated regular expression"),e)e=!1;else{if("["===i)t=!0;else if("]"===i&&t)t=!1;else if("/"===i&&!t)break;e="\\"===i}++r.pos}var s=this.input.slice(n,this.pos);++this.pos;var a=this.pos,o=this.readWord1();this.containsEsc&&this.unexpected(a);var c=this.regexpState||(this.regexpState=new Re(this));c.reset(n,s,o),this.validateRegExpFlags(c),this.validateRegExpPattern(c);var u=null;try{u=new RegExp(s,o)}catch(e){}return this.finishToken(j.regexp,{pattern:s,flags:o,value:u})},Ge.readInt=function(e,t){for(var r=this.pos,n=0,i=0,s=null==t?1/0:t;i=t.input.length&&t.raise(t.start,"Unterminated string constant");var i=t.input.charCodeAt(t.pos);if(i===e)break;92===i?(r+=t.input.slice(n,t.pos),r+=t.readEscapedChar(!1),n=t.pos):(W(i,10<=t.options.ecmaVersion)&&t.raise(t.start,"Unterminated string constant"),++t.pos)}return r+=this.input.slice(n,this.pos++),this.finishToken(j.string,r)};var Qe={};Ge.tryReadTemplateToken=function(){this.inTemplateElement=!0;try{this.readTmplToken()}catch(e){if(e!==Qe)throw e;this.readInvalidTemplateToken()}this.inTemplateElement=!1},Ge.invalidStringToken=function(e,t){if(this.inTemplateElement&&9<=this.options.ecmaVersion)throw Qe;this.raise(e,t)},Ge.readTmplToken=function(){for(var e=this,t="",r=this.pos;;){e.pos>=e.input.length&&e.raise(e.start,"Unterminated template");var n=e.input.charCodeAt(e.pos);if(96===n||36===n&&123===e.input.charCodeAt(e.pos+1))return e.pos!==e.start||e.type!==j.template&&e.type!==j.invalidTemplate?(t+=e.input.slice(r,e.pos),e.finishToken(j.template,t)):36===n?(e.pos+=2,e.finishToken(j.dollarBraceL)):(++e.pos,e.finishToken(j.backQuote));if(92===n)t+=e.input.slice(r,e.pos),t+=e.readEscapedChar(!0),r=e.pos;else if(W(n)){switch(t+=e.input.slice(r,e.pos),++e.pos,n){case 13:10===e.input.charCodeAt(e.pos)&&++e.pos;case 10:t+="\n";break;default:t+=String.fromCharCode(n)}e.options.locations&&(++e.curLine,e.lineStart=e.pos),r=e.pos}else++e.pos}},Ge.readInvalidTemplateToken=function(){for(var e=this;this.posa[0]&&t[1]=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}}}function ht(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,i,s=r.call(e),a=[];try{for(;(void 0===t||0":return n=":return n<=r;case"<<":return r<>":return r>>n;case">>>":return r>>>n;case"+":return r+n;case"-":return r-n;case"*":return r*n;case"**":return Math.pow(r,n);case"/":return r/n;case"%":return r%n;case"|":return r|n;case"^":return r^n;case"&":return r&n;case"in":return r in n;case"instanceof":return r instanceof n;default:throw new SyntaxError("Unexpected token "+e.operator)}},AssignmentExpression:function(e,t){var r,n=Nt(e.right,t),i=e.left;if("Identifier"===i.type){if(!(r=lt(i,t,{getVar:!0,throwErr:!1}))){var s=t.global().find("window").get();r=new at(s,i.name)}}else{if("MemberExpression"!==i.type)return xr(i,t,{feed:n});r=yt(i,t,{getVar:!0})}switch(e.operator){case"=":return r.set(n),r.get();case"+=":return r.set(r.get()+n),r.get();case"-=":return r.set(r.get()-n),r.get();case"*=":return r.set(r.get()*n),r.get();case"/=":return r.set(r.get()/n),r.get();case"%=":return r.set(r.get()%n),r.get();case"**=":return r.set(Math.pow(r.get(),n)),r.get();case"<<=":return r.set(r.get()<>=":return r.set(r.get()>>n),r.get();case">>>=":return r.set(r.get()>>>n),r.get();case"|=":return r.set(r.get()|n),r.get();case"^=":return r.set(r.get()^n),r.get();case"&=":return r.set(r.get()&n),r.get();default:throw new SyntaxError("Unexpected token "+e.operator)}},LogicalExpression:function(e,t){switch(e.operator){case"||":return Nt(e.left,t)||Nt(e.right,t);case"&&":return Nt(e.left,t)&&Nt(e.right,t);default:throw new SyntaxError("Unexpected token "+e.operator)}},MemberExpression:yt,ConditionalExpression:function(e,t){return Nt(e.test,t)?Nt(e.consequent,t):Nt(e.alternate,t)},CallExpression:function(e,t){var r,n;if("MemberExpression"===e.callee.type){n=yt(e.callee,t,{getObj:!0});var i=void 0;if(i=e.callee.computed?Nt(e.callee.property,t):e.callee.property.name,"Super"===e.callee.object.type){var s=t.find("this").get();r=n[i].bind(s)}else r=n[i];if("function"!=typeof r)throw new TypeError(i+" is not a function");if(r[tt])throw new TypeError("Class constructor "+i+" cannot be invoked without 'new'")}else if(n=t.find("this").get(),"function"!=typeof(r=Nt(e.callee,t))||"Super"!==e.callee.type&&r[tt]){var a;if("Identifier"===e.callee.type)a=e.callee.name;else try{a=JSON.stringify(r)}catch(e){a=""+r}throw"function"!=typeof r?new TypeError(a+" is not a function"):new TypeError("Class constructor "+a+" cannot be invoked without 'new'")}for(var o=[],c=0;c":return[2,i=":return[2,i<=n];case"<<":return[2,n<>":return[2,n>>i];case">>>":return[2,n>>>i];case"+":return[2,n+i];case"-":return[2,n-i];case"*":return[2,n*i];case"**":return[2,Math.pow(n,i)];case"/":return[2,n/i];case"%":return[2,n%i];case"|":return[2,n|i];case"^":return[2,n^i];case"&":return[2,n&i];case"in":return[2,n in i];case"instanceof":return[2,n instanceof i];default:throw new SyntaxError("Unexpected token "+t.operator)}return[2]}})},AssignmentExpression:function(t,r){var n,i,s,a;return ct(this,function(e){switch(e.label){case 0:return[5,ut(ir(t.right,r))];case 1:return n=e.sent(),"Identifier"!==(i=t.left).type?[3,3]:[5,ut(Ft(i,r,{getVar:!0,throwErr:!1}))];case 2:return(s=e.sent())||(a=r.global().find("window").get(),s=new at(a,i.name)),[3,7];case 3:return"MemberExpression"!==i.type?[3,5]:[5,ut(zt(i,r,{getVar:!0}))];case 4:return s=e.sent(),[3,7];case 5:return[5,ut(dr(i,r,{feed:n}))];case 6:return[2,e.sent()];case 7:switch(t.operator){case"=":return s.set(n),[2,s.get()];case"+=":return s.set(s.get()+n),[2,s.get()];case"-=":return s.set(s.get()-n),[2,s.get()];case"*=":return s.set(s.get()*n),[2,s.get()];case"/=":return s.set(s.get()/n),[2,s.get()];case"%=":return s.set(s.get()%n),[2,s.get()];case"**=":return s.set(Math.pow(s.get(),n)),[2,s.get()];case"<<=":return s.set(s.get()<>=":return s.set(s.get()>>n),[2,s.get()];case">>>=":return s.set(s.get()>>>n),[2,s.get()];case"|=":return s.set(s.get()|n),[2,s.get()];case"^=":return s.set(s.get()^n),[2,s.get()];case"&=":return s.set(s.get()&n),[2,s.get()];default:throw new SyntaxError("Unexpected token "+t.operator)}return[2]}})},LogicalExpression:function(t,r){var n,i;return ct(this,function(e){switch(e.label){case 0:switch(t.operator){case"||":return[3,1];case"&&":return[3,5]}return[3,9];case 1:return[5,ut(ir(t.left,r))];case 2:return(n=e.sent())?[3,4]:[5,ut(ir(t.right,r))];case 3:n=e.sent(),e.label=4;case 4:return[2,n];case 5:return[5,ut(ir(t.left,r))];case 6:return(i=e.sent())?[5,ut(ir(t.right,r))]:[3,8];case 7:i=e.sent(),e.label=8;case 8:return[2,i];case 9:throw new SyntaxError("Unexpected token "+t.operator)}})},MemberExpression:zt,ConditionalExpression:function(t,r){var n;return ct(this,function(e){switch(e.label){case 0:return[5,ut(ir(t.test,r))];case 1:return e.sent()?[5,ut(ir(t.consequent,r))]:[3,3];case 2:return n=e.sent(),[3,5];case 3:return[5,ut(ir(t.alternate,r))];case 4:n=e.sent(),e.label=5;case 5:return[2,n]}})},CallExpression:function(t,r){var n,i,s,a,o,c,u,h,p,l,d,f;return ct(this,function(e){switch(e.label){case 0:return"MemberExpression"!==t.callee.type?[3,5]:[5,ut(zt(t.callee,r,{getObj:!0}))];case 1:return i=e.sent(),s=void 0,t.callee.computed?[5,ut(ir(t.callee.property,r))]:[3,3];case 2:return s=e.sent(),[3,4];case 3:s=t.callee.property.name,e.label=4;case 4:if("function"!=typeof(n="Super"===t.callee.object.type?(a=r.find("this").get(),i[s].bind(a)):i[s]))throw new TypeError(s+" is not a function");if(n[tt])throw new TypeError("Class constructor "+s+" cannot be invoked without 'new'");return[3,7];case 5:return i=r.find("this").get(),[5,ut(ir(t.callee,r))];case 6:if("function"!=typeof(n=e.sent())||"Super"!==t.callee.type&&n[tt]){if("Identifier"===t.callee.type)o=t.callee.name;else try{o=JSON.stringify(n)}catch(e){o=""+n}throw"function"!=typeof n?new TypeError(o+" is not a function"):new TypeError("Class constructor "+o+" cannot be invoked without 'new'")}e.label=7;case 7:c=[],u=0,e.label=8;case 8:return u=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}}}(n),s=void 0,Ke.RES=i.next(),[4,Ke]):[3,8];case 2:s=e.sent(),e.label=3;case 3:return s.done?[3,7]:[5,ut(yr(t,r,{value:s.value}))];case 4:if((u=e.sent())===Je)return[3,7];if(u===Ye)return[3,5];if(u===Xe)return[2,u];e.label=5;case 5:return Ke.RES=i.next(),[4,Ke];case 6:return s=e.sent(),[3,3];case 7:return[3,15];case 8:e.trys.push([8,13,14,15]),a=ut(n),o=a.next(),e.label=9;case 9:return o.done?[3,12]:(c=o.value,[5,ut(yr(t,r,{value:c}))]);case 10:if((u=e.sent())===Je)return[3,12];if(u===Ye)return[3,11];if(u===Xe)return[2,u];e.label=11;case 11:return o=a.next(),[3,9];case 12:return[3,15];case 13:return h=e.sent(),p={error:h},[3,15];case 14:try{o&&!o.done&&(l=a.return)&&l.call(a)}finally{if(p)throw p.error}return[7];case 15:return[2]}})}});function Zt(t,r,n){var i,s,a,o,c,u,h,p,l,d,f,m,y,g,v;return void 0===n&&(n={}),ct(this,function(e){switch(e.label){case 0:i=n.kind,s=void 0===i?"let":i,a=n.hoist,o=void 0!==a&&a,c=n.onlyBlock,u=void 0!==c&&c,h=n.feed,p=void 0===h?{}:h,l=[],d=0,e.label=1;case 1:return d",M),template:new B("template"),invalidTemplate:new B("invalidTemplate"),ellipsis:new B("...",M),backQuote:new B("`",D),dollarBraceL:new B("${",{beforeExpr:!0,startsExpr:!0}),eq:new B("=",{beforeExpr:!0,isAssign:!0}),assign:new B("_=",{beforeExpr:!0,isAssign:!0}),incDec:new B("++/--",{prefix:!0,postfix:!0,startsExpr:!0}),prefix:new B("!/~",{beforeExpr:!0,prefix:!0,startsExpr:!0}),logicalOR:O("||",1),logicalAND:O("&&",2),bitwiseOR:O("|",3),bitwiseXOR:O("^",4),bitwiseAND:O("&",5),equality:O("==/!=/===/!==",6),relational:O("/<=/>=",7),bitShift:O("<>/>>>",8),plusMin:new B("+/-",{beforeExpr:!0,binop:9,prefix:!0,startsExpr:!0}),modulo:O("%",10),star:O("*",10),slash:O("/",10),starstar:new B("**",{beforeExpr:!0}),_break:F("break"),_case:F("case",M),_catch:F("catch"),_continue:F("continue"),_debugger:F("debugger"),_default:F("default",M),_do:F("do",{isLoop:!0,beforeExpr:!0}),_else:F("else",M),_finally:F("finally"),_for:F("for",{isLoop:!0}),_function:F("function",D),_if:F("if"),_return:F("return",M),_switch:F("switch"),_throw:F("throw",M),_try:F("try"),_var:F("var"),_const:F("const"),_while:F("while",{isLoop:!0}),_with:F("with"),_new:F("new",{beforeExpr:!0,startsExpr:!0}),_this:F("this",D),_super:F("super",D),_class:F("class",D),_extends:F("extends",M),_export:F("export"),_import:F("import",D),_null:F("null",D),_true:F("true",D),_false:F("false",D),_in:F("in",{beforeExpr:!0,binop:7}),_instanceof:F("instanceof",{beforeExpr:!0,binop:7}),_typeof:F("typeof",{beforeExpr:!0,prefix:!0,startsExpr:!0}),_void:F("void",{beforeExpr:!0,prefix:!0,startsExpr:!0}),_delete:F("delete",{beforeExpr:!0,prefix:!0,startsExpr:!0})},q=/\r\n?|\n|\u2028|\u2029/,W=new RegExp(q.source,"g");function G(e,t){return 10===e||13===e||!t&&(8232===e||8233===e)}var H=/[\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]/,z=/(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g,K=Object.prototype,Q=K.hasOwnProperty,X=K.toString;function J(e,t){return Q.call(e,t)}var Y=Array.isArray||function(e){return"[object Array]"===X.call(e)};function Z(e){return new RegExp("^(?:"+e.replace(/ /g,"|")+")$")}function $(e,t){this.line=e,this.column=t}var ee=function(e,t,r){this.start=t,this.end=r,null!==e.sourceFile&&(this.source=e.sourceFile)};function te(e,t){for(var r=1,i=0;;){W.lastIndex=i;var n=W.exec(e);if(!(n&&n.index>10),56320+(1023&e)))}function Fe(e){return 36===e||40<=e&&e<=43||46===e||63===e||91<=e&&e<=94||123<=e&&e<=125}function je(e){return 65<=e&&e<=90||97<=e&&e<=122}function qe(e){return je(e)||95===e}function We(e){return 48<=e&&e<=57}function Ge(e){return 48<=e&&e<=57||65<=e&&e<=70||97<=e&&e<=102}function He(e){return 65<=e&&e<=70?e-65+10:97<=e&&e<=102?e-97+10:e-48}function ze(e){return 48<=e&&e<=55}Me.prototype.reset=function(e,t,r){var i=-1!==r.indexOf("u");this.start=0|e,this.source=t+"",this.flags=r,this.switchU=i&&6<=this.parser.options.ecmaVersion,this.switchN=i&&9<=this.parser.options.ecmaVersion},Me.prototype.raise=function(e){this.parser.raiseRecoverable(this.start,"Invalid regular expression: /"+this.source+"/: "+e)},Me.prototype.at=function(e){var t=this.source,r=t.length;if(r<=e)return-1;var i=t.charCodeAt(e);if(!this.switchU||i<=55295||57344<=i||r<=e+1)return i;var n=t.charCodeAt(e+1);return 56320<=n&&n<=57343?(i<<10)+n-56613888:i},Me.prototype.nextIndex=function(e){var t=this.source,r=t.length;if(r<=e)return r;var i,n=t.charCodeAt(e);return!this.switchU||n<=55295||57344<=n||r<=e+1||(i=t.charCodeAt(e+1))<56320||57343e.numCapturingParens&&e.raise("Invalid escape");for(var t=0,r=e.backReferenceNames;te.maxBackReference&&(e.maxBackReference=r),!0;if(r<=e.numCapturingParens)return!0;e.pos=t}return!1},De.regexp_eatKGroupName=function(e){if(e.eat(107)){if(this.regexp_eatGroupName(e))return e.backReferenceNames.push(e.lastStringValue),!0;e.raise("Invalid named reference")}return!1},De.regexp_eatCharacterEscape=function(e){return this.regexp_eatControlEscape(e)||this.regexp_eatCControlLetter(e)||this.regexp_eatZero(e)||this.regexp_eatHexEscapeSequence(e)||this.regexp_eatRegExpUnicodeEscapeSequence(e)||!e.switchU&&this.regexp_eatLegacyOctalEscapeSequence(e)||this.regexp_eatIdentityEscape(e)},De.regexp_eatCControlLetter=function(e){var t=e.pos;if(e.eat(99)){if(this.regexp_eatControlLetter(e))return!0;e.pos=t}return!1},De.regexp_eatZero=function(e){return 48===e.current()&&!We(e.lookahead())&&(e.lastIntValue=0,e.advance(),!0)},De.regexp_eatControlEscape=function(e){var t=e.current();return 116===t?(e.lastIntValue=9,e.advance(),!0):110===t?(e.lastIntValue=10,e.advance(),!0):118===t?(e.lastIntValue=11,e.advance(),!0):102===t?(e.lastIntValue=12,e.advance(),!0):114===t&&(e.lastIntValue=13,e.advance(),!0)},De.regexp_eatControlLetter=function(e){var t=e.current();return!!je(t)&&(e.lastIntValue=t%32,e.advance(),!0)},De.regexp_eatRegExpUnicodeEscapeSequence=function(e){var t,r=e.pos;if(e.eat(117)){if(this.regexp_eatFixedHexDigits(e,4)){var i=e.lastIntValue;if(e.switchU&&55296<=i&&i<=56319){var n=e.pos;if(e.eat(92)&&e.eat(117)&&this.regexp_eatFixedHexDigits(e,4)){var s=e.lastIntValue;if(56320<=s&&s<=57343)return e.lastIntValue=1024*(i-55296)+(s-56320)+65536,!0}e.pos=n,e.lastIntValue=i}return!0}if(e.switchU&&e.eat(123)&&this.regexp_eatHexDigits(e)&&e.eat(125)&&(0<=(t=e.lastIntValue)&&t<=1114111))return!0;e.switchU&&e.raise("Invalid unicode escape"),e.pos=r}return!1},De.regexp_eatIdentityEscape=function(e){if(e.switchU)return!!this.regexp_eatSyntaxCharacter(e)||!!e.eat(47)&&(e.lastIntValue=47,!0);var t=e.current();return!(99===t||e.switchN&&107===t)&&(e.lastIntValue=t,e.advance(),!0)},De.regexp_eatDecimalEscape=function(e){e.lastIntValue=0;var t=e.current();if(49<=t&&t<=57){for(;e.lastIntValue=10*e.lastIntValue+(t-48),e.advance(),48<=(t=e.current())&&t<=57;);return!0}return!1},De.regexp_eatCharacterClassEscape=function(e){var t,r=e.current();if(100===(t=r)||68===t||115===t||83===t||119===t||87===t)return e.lastIntValue=-1,e.advance(),!0;if(e.switchU&&9<=this.options.ecmaVersion&&(80===r||112===r)){if(e.lastIntValue=-1,e.advance(),e.eat(123)&&this.regexp_eatUnicodePropertyValueExpression(e)&&e.eat(125))return!0;e.raise("Invalid property name")}return!1},De.regexp_eatUnicodePropertyValueExpression=function(e){var t=e.pos;if(this.regexp_eatUnicodePropertyName(e)&&e.eat(61)){var r=e.lastStringValue;if(this.regexp_eatUnicodePropertyValue(e)){var i=e.lastStringValue;return this.regexp_validateUnicodePropertyNameAndValue(e,r,i),!0}}if(e.pos=t,this.regexp_eatLoneUnicodePropertyNameOrValue(e)){var n=e.lastStringValue;return this.regexp_validateUnicodePropertyNameOrValue(e,n),!0}return!1},De.regexp_validateUnicodePropertyNameAndValue=function(e,t,r){J(e.unicodeProperties.nonBinary,t)||e.raise("Invalid property name"),e.unicodeProperties.nonBinary[t].test(r)||e.raise("Invalid property value")},De.regexp_validateUnicodePropertyNameOrValue=function(e,t){e.unicodeProperties.binary.test(t)||e.raise("Invalid property name")},De.regexp_eatUnicodePropertyName=function(e){var t=0;for(e.lastStringValue="";qe(t=e.current());)e.lastStringValue+=Ue(t),e.advance();return""!==e.lastStringValue},De.regexp_eatUnicodePropertyValue=function(e){var t,r=0;for(e.lastStringValue="";qe(t=r=e.current())||We(t);)e.lastStringValue+=Ue(r),e.advance();return""!==e.lastStringValue},De.regexp_eatLoneUnicodePropertyNameOrValue=function(e){return this.regexp_eatUnicodePropertyValue(e)},De.regexp_eatCharacterClass=function(e){if(e.eat(91)){if(e.eat(94),this.regexp_classRanges(e),e.eat(93))return!0;e.raise("Unterminated character class")}return!1},De.regexp_classRanges=function(e){for(;this.regexp_eatClassAtom(e);){var t,r=e.lastIntValue;e.eat(45)&&this.regexp_eatClassAtom(e)&&(t=e.lastIntValue,!e.switchU||-1!==r&&-1!==t||e.raise("Invalid character class"),-1!==r&&-1!==t&&t>10),56320+(1023&e)))}Qe.next=function(){this.options.onToken&&this.options.onToken(new Ke(this)),this.lastTokEnd=this.end,this.lastTokStart=this.start,this.lastTokEndLoc=this.endLoc,this.lastTokStartLoc=this.startLoc,this.nextToken()},Qe.getToken=function(){return this.next(),new Ke(this)},"undefined"!=typeof Symbol&&(Qe[Symbol.iterator]=function(){var t=this;return{next:function(){var e=t.getToken();return{done:e.type===j.eof,value:e}}}}),Qe.curContext=function(){return this.context[this.context.length-1]},Qe.nextToken=function(){var e=this.curContext();return e&&e.preserveSpace||this.skipSpace(),this.start=this.pos,this.options.locations&&(this.startLoc=this.curPosition()),this.pos>=this.input.length?this.finishToken(j.eof):e.override?e.override(this):void this.readToken(this.fullCharCodeAtPos())},Qe.readToken=function(e){return N(e,6<=this.options.ecmaVersion)||92===e?this.readWord():this.getTokenFromCode(e)},Qe.fullCharCodeAtPos=function(){var e=this.input.charCodeAt(this.pos);return e<=55295||57344<=e?e:(e<<10)+this.input.charCodeAt(this.pos+1)-56613888},Qe.skipBlockComment=function(){var e,t=this.options.onComment&&this.curPosition(),r=this.pos,i=this.input.indexOf("*/",this.pos+=2);if(-1===i&&this.raise(this.pos-2,"Unterminated comment"),this.pos=i+2,this.options.locations)for(W.lastIndex=r;(e=W.exec(this.input))&&e.index=this.input.length&&this.raise(r,"Unterminated regular expression");var i=this.input.charAt(this.pos);if(q.test(i)&&this.raise(r,"Unterminated regular expression"),e)e=!1;else{if("["===i)t=!0;else if("]"===i&&t)t=!1;else if("/"===i&&!t)break;e="\\"===i}++this.pos}var n=this.input.slice(r,this.pos);++this.pos;var s=this.pos,a=this.readWord1();this.containsEsc&&this.unexpected(s);var o=this.regexpState||(this.regexpState=new Me(this));o.reset(r,n,a),this.validateRegExpFlags(o),this.validateRegExpPattern(o);var c=null;try{c=new RegExp(n,a)}catch(e){}return this.finishToken(j.regexp,{pattern:n,flags:a,value:c})},Qe.readInt=function(e,t){for(var r=this.pos,i=0,n=0,s=null==t?1/0:t;n=this.input.length&&this.raise(this.start,"Unterminated string constant");var i=this.input.charCodeAt(this.pos);if(i===e)break;92===i?(t+=this.input.slice(r,this.pos),t+=this.readEscapedChar(!1),r=this.pos):(G(i,10<=this.options.ecmaVersion)&&this.raise(this.start,"Unterminated string constant"),++this.pos)}return t+=this.input.slice(r,this.pos++),this.finishToken(j.string,t)};var Je={};Qe.tryReadTemplateToken=function(){this.inTemplateElement=!0;try{this.readTmplToken()}catch(e){if(e!==Je)throw e;this.readInvalidTemplateToken()}this.inTemplateElement=!1},Qe.invalidStringToken=function(e,t){if(this.inTemplateElement&&9<=this.options.ecmaVersion)throw Je;this.raise(e,t)},Qe.readTmplToken=function(){for(var e="",t=this.pos;;){this.pos>=this.input.length&&this.raise(this.start,"Unterminated template");var r=this.input.charCodeAt(this.pos);if(96===r||36===r&&123===this.input.charCodeAt(this.pos+1))return this.pos!==this.start||this.type!==j.template&&this.type!==j.invalidTemplate?(e+=this.input.slice(t,this.pos),this.finishToken(j.template,e)):36===r?(this.pos+=2,this.finishToken(j.dollarBraceL)):(++this.pos,this.finishToken(j.backQuote));if(92===r)e+=this.input.slice(t,this.pos),e+=this.readEscapedChar(!0),t=this.pos;else if(G(r)){switch(e+=this.input.slice(t,this.pos),++this.pos,r){case 13:10===this.input.charCodeAt(this.pos)&&++this.pos;case 10:e+="\n";break;default:e+=String.fromCharCode(r)}this.options.locations&&(++this.curLine,this.lineStart=this.pos),t=this.pos}else++this.pos}},Qe.readInvalidTemplateToken=function(){for(;this.posa[0]&&t[1]=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}}}function yt(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var i,n,s=r.call(e),a=[];try{for(;(void 0===t||0":return i=":return i<=r;case"<<":return r<>":return r>>i;case">>>":return r>>>i;case"+":return r+i;case"-":return r-i;case"*":return r*i;case"**":return Math.pow(r,i);case"/":return r/i;case"%":return r%i;case"|":return r|i;case"^":return r^i;case"&":return r&i;case"in":return r in i;case"instanceof":return r instanceof i;default:throw new SyntaxError("Unexpected token "+e.operator)}},AssignmentExpression:function(e,t){var r,i,n=Ut(e.right,t),s=e.left;if("Identifier"===s.type){(i=xt(s,t,{getVar:!0,throwErr:!1}))||(r=t.global().find("window").get(),i=new pt(r,s.name))}else{if("MemberExpression"!==s.type)return Cr(s,t,{feed:n});i=_t(s,t,{getVar:!0})}switch(e.operator){case"=":return i.set(n),i.get();case"+=":return i.set(i.get()+n),i.get();case"-=":return i.set(i.get()-n),i.get();case"*=":return i.set(i.get()*n),i.get();case"/=":return i.set(i.get()/n),i.get();case"%=":return i.set(i.get()%n),i.get();case"**=":return i.set(Math.pow(i.get(),n)),i.get();case"<<=":return i.set(i.get()<>=":return i.set(i.get()>>n),i.get();case">>>=":return i.set(i.get()>>>n),i.get();case"|=":return i.set(i.get()|n),i.get();case"^=":return i.set(i.get()^n),i.get();case"&=":return i.set(i.get()&n),i.get();default:throw new SyntaxError("Unexpected token "+e.operator)}},LogicalExpression:function(e,t){switch(e.operator){case"||":return Ut(e.left,t)||Ut(e.right,t);case"&&":return Ut(e.left,t)&&Ut(e.right,t);default:throw new SyntaxError("Unexpected token "+e.operator)}},MemberExpression:_t,ConditionalExpression:function(e,t){return Ut(e.test,t)?Ut(e.consequent,t):Ut(e.alternate,t)},CallExpression:function(e,t){var r,i;if("MemberExpression"===e.callee.type){r=_t(e.callee,t,{getObj:!0});var n,s,a=void 0,a=e.callee.computed?Ut(e.callee.property,t):e.callee.property.name;if("function"!=typeof(s="Super"===e.callee.object.type?(n=t.find("this").get(),r[a].bind(n)):r[a]))throw new TypeError(a+" is not a function");if(s[st])throw new TypeError("Class constructor "+a+" cannot be invoked without 'new'")}else if(r=t.find("this").get(),"function"!=typeof(s=Ut(e.callee,t))||"Super"!==e.callee.type&&s[st]){if("Identifier"===e.callee.type)i=e.callee.name;else try{i=JSON.stringify(s)}catch(e){i=""+s}throw"function"!=typeof s?new TypeError(i+" is not a function"):new TypeError("Class constructor "+i+" cannot be invoked without 'new'")}for(var o=[],c=0;c":return[2,n=":return[2,n<=i];case"<<":return[2,i<>":return[2,i>>n];case">>>":return[2,i>>>n];case"+":return[2,i+n];case"-":return[2,i-n];case"*":return[2,i*n];case"**":return[2,Math.pow(i,n)];case"/":return[2,i/n];case"%":return[2,i%n];case"|":return[2,i|n];case"^":return[2,i^n];case"&":return[2,i&n];case"in":return[2,i in n];case"instanceof":return[2,i instanceof n];default:throw new SyntaxError("Unexpected token "+t.operator)}}})},AssignmentExpression:function(t,r){var i,n,s,a;return mt(this,function(e){switch(e.label){case 0:return[5,gt(pr(t.right,r))];case 1:return i=e.sent(),"Identifier"!==(n=t.left).type?[3,3]:[5,gt(zt(n,r,{getVar:!0,throwErr:!1}))];case 2:return(s=e.sent())||(a=r.global().find("window").get(),s=new pt(a,n.name)),[3,7];case 3:return"MemberExpression"!==n.type?[3,5]:[5,gt(Jt(n,r,{getVar:!0}))];case 4:return s=e.sent(),[3,7];case 5:return[5,gt(br(n,r,{feed:i}))];case 6:return[2,e.sent()];case 7:switch(t.operator){case"=":return s.set(i),[2,s.get()];case"+=":return s.set(s.get()+i),[2,s.get()];case"-=":return s.set(s.get()-i),[2,s.get()];case"*=":return s.set(s.get()*i),[2,s.get()];case"/=":return s.set(s.get()/i),[2,s.get()];case"%=":return s.set(s.get()%i),[2,s.get()];case"**=":return s.set(Math.pow(s.get(),i)),[2,s.get()];case"<<=":return s.set(s.get()<>=":return s.set(s.get()>>i),[2,s.get()];case">>>=":return s.set(s.get()>>>i),[2,s.get()];case"|=":return s.set(s.get()|i),[2,s.get()];case"^=":return s.set(s.get()^i),[2,s.get()];case"&=":return s.set(s.get()&i),[2,s.get()];default:throw new SyntaxError("Unexpected token "+t.operator)}}})},LogicalExpression:function(t,r){var i,n;return mt(this,function(e){switch(e.label){case 0:switch(t.operator){case"||":return[3,1];case"&&":return[3,5]}return[3,9];case 1:return[5,gt(pr(t.left,r))];case 2:return(i=e.sent())?[3,4]:[5,gt(pr(t.right,r))];case 3:i=e.sent(),e.label=4;case 4:return[2,i];case 5:return[5,gt(pr(t.left,r))];case 6:return(n=e.sent())?[5,gt(pr(t.right,r))]:[3,8];case 7:n=e.sent(),e.label=8;case 8:return[2,n];case 9:throw new SyntaxError("Unexpected token "+t.operator)}})},MemberExpression:Jt,ConditionalExpression:function(t,r){var i;return mt(this,function(e){switch(e.label){case 0:return[5,gt(pr(t.test,r))];case 1:return e.sent()?[5,gt(pr(t.consequent,r))]:[3,3];case 2:return i=e.sent(),[3,5];case 3:return[5,gt(pr(t.alternate,r))];case 4:i=e.sent(),e.label=5;case 5:return[2,i]}})},CallExpression:function(t,r){var i,n,s,a,o,c,h,u,p,l,d,f;return mt(this,function(e){switch(e.label){case 0:return"MemberExpression"!==t.callee.type?[3,5]:[5,gt(Jt(t.callee,r,{getObj:!0}))];case 1:return n=e.sent(),s=void 0,t.callee.computed?[5,gt(pr(t.callee.property,r))]:[3,3];case 2:return s=e.sent(),[3,4];case 3:s=t.callee.property.name,e.label=4;case 4:if("function"!=typeof(i="Super"===t.callee.object.type?(a=r.find("this").get(),n[s].bind(a)):n[s]))throw new TypeError(s+" is not a function");if(i[st])throw new TypeError("Class constructor "+s+" cannot be invoked without 'new'");return[3,7];case 5:return n=r.find("this").get(),[5,gt(pr(t.callee,r))];case 6:if("function"!=typeof(i=e.sent())||"Super"!==t.callee.type&&i[st]){if("Identifier"===t.callee.type)o=t.callee.name;else try{o=JSON.stringify(i)}catch(e){o=""+i}throw"function"!=typeof i?new TypeError(o+" is not a function"):new TypeError("Class constructor "+o+" cannot be invoked without 'new'")}e.label=7;case 7:c=[],h=0,e.label=8;case 8:return h=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}}}(i),s=void 0,Ze.RES=n.next(),[4,Ze]):[3,8];case 2:s=e.sent(),e.label=3;case 3:return s.done?[3,7]:[5,gt(_r(t,r,{value:s.value}))];case 4:if((h=e.sent())===tt)return[3,7];if(h===et)return[3,5];if(h===$e)return[2,h];e.label=5;case 5:return Ze.RES=n.next(),[4,Ze];case 6:return s=e.sent(),[3,3];case 7:return[3,15];case 8:e.trys.push([8,13,14,15]),a=gt(i),o=a.next(),e.label=9;case 9:return o.done?[3,12]:(c=o.value,[5,gt(_r(t,r,{value:c}))]);case 10:if((h=e.sent())===tt)return[3,12];if(h===et)return[3,11];if(h===$e)return[2,h];e.label=11;case 11:return o=a.next(),[3,9];case 12:return[3,15];case 13:return u=e.sent(),p={error:u},[3,15];case 14:try{o&&!o.done&&(l=a.return)&&l.call(a)}finally{if(p)throw p.error}return[7];case 15:return[2]}})}});function sr(t,r,i){var n,s,a,o,c,h,u,p,l,d,f,m,g,y,v;return void 0===i&&(i={}),mt(this,function(e){switch(e.label){case 0:n=i.kind,s=void 0===n?"var":n,a=i.hoist,o=void 0!==a&&a,c=i.onlyBlock,h=void 0!==c&&c,u=i.feed,p=void 0===u?{}:u,l=[],d=0,e.label=1;case 1:return d Node) { + parse(code: string, parser?: (code: string, options: SvalOptions) => Node) { if (typeof parser === 'function') { return parser(code, assign({}, this.options)) } diff --git a/types/index.d.ts b/types/index.d.ts index fcb8864..3ac9794 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,3 +1,4 @@ +import { Node, Program } from 'estree'; export interface SvalOptions { ecmaVer?: 3 | 5 | 6 | 7 | 8 | 9 | 10 | 2015 | 2016 | 2017 | 2018 | 2019; sandBox?: boolean; @@ -13,6 +14,7 @@ declare class Sval { import(nameOrModules: string | { [name: string]: any; }, mod?: any): void; - run(code: string): void; + parse(code: string, parser?: (code: string, options: SvalOptions) => Node): import("estree").Identifier | import("estree").SimpleLiteral | import("estree").RegExpLiteral | Program | import("estree").FunctionDeclaration | import("estree").FunctionExpression | import("estree").ArrowFunctionExpression | import("estree").SwitchCase | import("estree").CatchClause | import("estree").VariableDeclarator | import("estree").ExpressionStatement | import("estree").BlockStatement | import("estree").EmptyStatement | import("estree").DebuggerStatement | import("estree").WithStatement | import("estree").ReturnStatement | import("estree").LabeledStatement | import("estree").BreakStatement | import("estree").ContinueStatement | import("estree").IfStatement | import("estree").SwitchStatement | import("estree").ThrowStatement | import("estree").TryStatement | import("estree").WhileStatement | import("estree").DoWhileStatement | import("estree").ForStatement | import("estree").ForInStatement | import("estree").ForOfStatement | import("estree").VariableDeclaration | import("estree").ClassDeclaration | import("estree").ThisExpression | import("estree").ArrayExpression | import("estree").ObjectExpression | import("estree").YieldExpression | import("estree").UnaryExpression | import("estree").UpdateExpression | import("estree").BinaryExpression | import("estree").AssignmentExpression | import("estree").LogicalExpression | import("estree").MemberExpression | import("estree").ConditionalExpression | import("estree").SimpleCallExpression | import("estree").NewExpression | import("estree").SequenceExpression | import("estree").TemplateLiteral | import("estree").TaggedTemplateExpression | import("estree").ClassExpression | import("estree").MetaProperty | import("estree").AwaitExpression | import("estree").Property | import("estree").Super | import("estree").TemplateElement | import("estree").SpreadElement | import("estree").ObjectPattern | import("estree").ArrayPattern | import("estree").RestElement | import("estree").AssignmentPattern | import("estree").ClassBody | import("estree").MethodDefinition | import("estree").ImportDeclaration | import("estree").ExportNamedDeclaration | import("estree").ExportDefaultDeclaration | import("estree").ExportAllDeclaration | import("estree").ImportSpecifier | import("estree").ImportDefaultSpecifier | import("estree").ImportNamespaceSpecifier | import("estree").ExportSpecifier | import("acorn").Node; + run(code: string | Node): void; } export default Sval;