shift-reducer
Advanced tools
Comparing version 3.0.3 to 4.0.0
@@ -1,2 +0,2 @@ | ||
"use strict"; | ||
'use strict'; | ||
@@ -7,37 +7,727 @@ Object.defineProperty(exports, "__esModule", { | ||
var _shiftSpec = require("shift-spec"); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /** | ||
* Copyright 2016 Shape Security, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
var _shiftSpec2 = _interopRequireDefault(_shiftSpec); | ||
var _shiftAst = require('shift-ast'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var Shift = _interopRequireWildcard(_shiftAst); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** | ||
* Copyright 2014 Shape Security, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
var CloneReducer = function CloneReducer() { | ||
_classCallCheck(this, CloneReducer); | ||
}; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
exports.default = CloneReducer; | ||
var CloneReducer = function () { | ||
function CloneReducer() { | ||
_classCallCheck(this, CloneReducer); | ||
} | ||
for (var typeName in _shiftSpec2.default) { | ||
var type = _shiftSpec2.default[typeName]; | ||
Object.defineProperty(CloneReducer.prototype, "reduce" + typeName, { | ||
value: function value(node, state) { | ||
return state; | ||
_createClass(CloneReducer, [{ | ||
key: 'reduceArrayAssignmentTarget', | ||
value: function reduceArrayAssignmentTarget(node, _ref) { | ||
var elements = _ref.elements; | ||
var rest = _ref.rest; | ||
return new Shift.ArrayAssignmentTarget(node, { elements: elements, rest: rest }); | ||
} | ||
}); | ||
} | ||
}, { | ||
key: 'reduceArrayBinding', | ||
value: function reduceArrayBinding(node, _ref2) { | ||
var elements = _ref2.elements; | ||
var rest = _ref2.rest; | ||
return new Shift.ArrayBinding(node, { elements: elements, rest: rest }); | ||
} | ||
}, { | ||
key: 'reduceArrayExpression', | ||
value: function reduceArrayExpression(node, _ref3) { | ||
var elements = _ref3.elements; | ||
return new Shift.ArrayExpression(node, { elements: elements }); | ||
} | ||
}, { | ||
key: 'reduceArrowExpression', | ||
value: function reduceArrowExpression(node, _ref4) { | ||
var params = _ref4.params; | ||
var body = _ref4.body; | ||
return new Shift.ArrowExpression(node, { params: params, body: body }); | ||
} | ||
}, { | ||
key: 'reduceAssignmentExpression', | ||
value: function reduceAssignmentExpression(node, _ref5) { | ||
var binding = _ref5.binding; | ||
var expression = _ref5.expression; | ||
return new Shift.AssignmentExpression(node, { binding: binding, expression: expression }); | ||
} | ||
}, { | ||
key: 'reduceAssignmentTargetIdentifier', | ||
value: function reduceAssignmentTargetIdentifier(node) { | ||
return new Shift.AssignmentTargetIdentifier(node, { name: node.name }); | ||
} | ||
}, { | ||
key: 'reduceAssignmentTargetPropertyIdentifier', | ||
value: function reduceAssignmentTargetPropertyIdentifier(node, _ref6) { | ||
var binding = _ref6.binding; | ||
var init = _ref6.init; | ||
return new Shift.AssignmentTargetPropertyIdentifier(node, { binding: binding, init: init }); | ||
} | ||
}, { | ||
key: 'reduceAssignmentTargetPropertyProperty', | ||
value: function reduceAssignmentTargetPropertyProperty(node, _ref7) { | ||
var name = _ref7.name; | ||
var binding = _ref7.binding; | ||
return new Shift.AssignmentTargetPropertyProperty(node, { name: name, binding: binding }); | ||
} | ||
}, { | ||
key: 'reduceAssignmentTargetWithDefault', | ||
value: function reduceAssignmentTargetWithDefault(node, _ref8) { | ||
var binding = _ref8.binding; | ||
var init = _ref8.init; | ||
return new Shift.AssignmentTargetWithDefault(node, { binding: binding, init: init }); | ||
} | ||
}, { | ||
key: 'reduceBinaryExpression', | ||
value: function reduceBinaryExpression(node, _ref9) { | ||
var left = _ref9.left; | ||
var right = _ref9.right; | ||
return new Shift.BinaryExpression(node, { left: left, operator: node.operator, right: right }); | ||
} | ||
}, { | ||
key: 'reduceBindingIdentifier', | ||
value: function reduceBindingIdentifier(node) { | ||
return new Shift.BindingIdentifier(node, { name: node.name }); | ||
} | ||
}, { | ||
key: 'reduceBindingPropertyIdentifier', | ||
value: function reduceBindingPropertyIdentifier(node, _ref10) { | ||
var binding = _ref10.binding; | ||
var init = _ref10.init; | ||
return new Shift.BindingPropertyIdentifier(node, { binding: binding, init: init }); | ||
} | ||
}, { | ||
key: 'reduceBindingPropertyProperty', | ||
value: function reduceBindingPropertyProperty(node, _ref11) { | ||
var name = _ref11.name; | ||
var binding = _ref11.binding; | ||
return new Shift.BindingPropertyProperty(node, { name: name, binding: binding }); | ||
} | ||
}, { | ||
key: 'reduceBindingWithDefault', | ||
value: function reduceBindingWithDefault(node, _ref12) { | ||
var binding = _ref12.binding; | ||
var init = _ref12.init; | ||
return new Shift.BindingWithDefault(node, { binding: binding, init: init }); | ||
} | ||
}, { | ||
key: 'reduceBlock', | ||
value: function reduceBlock(node, _ref13) { | ||
var statements = _ref13.statements; | ||
return new Shift.Block(node, { statements: statements }); | ||
} | ||
}, { | ||
key: 'reduceBlockStatement', | ||
value: function reduceBlockStatement(node, _ref14) { | ||
var block = _ref14.block; | ||
return new Shift.BlockStatement(node, { block: block }); | ||
} | ||
}, { | ||
key: 'reduceBreakStatement', | ||
value: function reduceBreakStatement(node) { | ||
return new Shift.BreakStatement(node, { label: node.label }); | ||
} | ||
}, { | ||
key: 'reduceCallExpression', | ||
value: function reduceCallExpression(node, _ref15) { | ||
var callee = _ref15.callee; | ||
var _arguments = _ref15.arguments; | ||
return new Shift.CallExpression(node, { callee: callee, arguments: _arguments }); | ||
} | ||
}, { | ||
key: 'reduceCatchClause', | ||
value: function reduceCatchClause(node, _ref16) { | ||
var binding = _ref16.binding; | ||
var body = _ref16.body; | ||
return new Shift.CatchClause(node, { binding: binding, body: body }); | ||
} | ||
}, { | ||
key: 'reduceClassDeclaration', | ||
value: function reduceClassDeclaration(node, _ref17) { | ||
var name = _ref17.name; | ||
var _super = _ref17.super; | ||
var elements = _ref17.elements; | ||
return new Shift.ClassDeclaration(node, { name: name, super: _super, elements: elements }); | ||
} | ||
}, { | ||
key: 'reduceClassElement', | ||
value: function reduceClassElement(node, _ref18) { | ||
var method = _ref18.method; | ||
return new Shift.ClassElement(node, { isStatic: node.isStatic, method: method }); | ||
} | ||
}, { | ||
key: 'reduceClassExpression', | ||
value: function reduceClassExpression(node, _ref19) { | ||
var name = _ref19.name; | ||
var _super = _ref19.super; | ||
var elements = _ref19.elements; | ||
return new Shift.ClassExpression(node, { name: name, super: _super, elements: elements }); | ||
} | ||
}, { | ||
key: 'reduceCompoundAssignmentExpression', | ||
value: function reduceCompoundAssignmentExpression(node, _ref20) { | ||
var binding = _ref20.binding; | ||
var expression = _ref20.expression; | ||
return new Shift.CompoundAssignmentExpression(node, { binding: binding, operator: node.operator, expression: expression }); | ||
} | ||
}, { | ||
key: 'reduceComputedMemberAssignmentTarget', | ||
value: function reduceComputedMemberAssignmentTarget(node, _ref21) { | ||
var object = _ref21.object; | ||
var expression = _ref21.expression; | ||
return new Shift.ComputedMemberAssignmentTarget(node, { object: object, expression: expression }); | ||
} | ||
}, { | ||
key: 'reduceComputedMemberExpression', | ||
value: function reduceComputedMemberExpression(node, _ref22) { | ||
var object = _ref22.object; | ||
var expression = _ref22.expression; | ||
return new Shift.ComputedMemberExpression(node, { object: object, expression: expression }); | ||
} | ||
}, { | ||
key: 'reduceComputedPropertyName', | ||
value: function reduceComputedPropertyName(node, _ref23) { | ||
var expression = _ref23.expression; | ||
return new Shift.ComputedPropertyName(node, { expression: expression }); | ||
} | ||
}, { | ||
key: 'reduceConditionalExpression', | ||
value: function reduceConditionalExpression(node, _ref24) { | ||
var test = _ref24.test; | ||
var consequent = _ref24.consequent; | ||
var alternate = _ref24.alternate; | ||
return new Shift.ConditionalExpression(node, { test: test, consequent: consequent, alternate: alternate }); | ||
} | ||
}, { | ||
key: 'reduceContinueStatement', | ||
value: function reduceContinueStatement(node) { | ||
return new Shift.ContinueStatement(node, { label: node.label }); | ||
} | ||
}, { | ||
key: 'reduceDataProperty', | ||
value: function reduceDataProperty(node, _ref25) { | ||
var name = _ref25.name; | ||
var expression = _ref25.expression; | ||
return new Shift.DataProperty(node, { name: name, expression: expression }); | ||
} | ||
}, { | ||
key: 'reduceDebuggerStatement', | ||
value: function reduceDebuggerStatement(node) { | ||
return new Shift.DebuggerStatement(); | ||
} | ||
}, { | ||
key: 'reduceDirective', | ||
value: function reduceDirective(node) { | ||
return new Shift.Directive(node, { rawValue: node.rawValue }); | ||
} | ||
}, { | ||
key: 'reduceDoWhileStatement', | ||
value: function reduceDoWhileStatement(node, _ref26) { | ||
var body = _ref26.body; | ||
var test = _ref26.test; | ||
return new Shift.DoWhileStatement(node, { body: body, test: test }); | ||
} | ||
}, { | ||
key: 'reduceEmptyStatement', | ||
value: function reduceEmptyStatement(node) { | ||
return new Shift.EmptyStatement(); | ||
} | ||
}, { | ||
key: 'reduceExport', | ||
value: function reduceExport(node, _ref27) { | ||
var declaration = _ref27.declaration; | ||
return new Shift.Export(node, { declaration: declaration }); | ||
} | ||
}, { | ||
key: 'reduceExportAllFrom', | ||
value: function reduceExportAllFrom(node) { | ||
return new Shift.ExportAllFrom(node, { moduleSpecifier: node.moduleSpecifier }); | ||
} | ||
}, { | ||
key: 'reduceExportDefault', | ||
value: function reduceExportDefault(node, _ref28) { | ||
var body = _ref28.body; | ||
return new Shift.ExportDefault(node, { body: body }); | ||
} | ||
}, { | ||
key: 'reduceExportFrom', | ||
value: function reduceExportFrom(node, _ref29) { | ||
var namedExports = _ref29.namedExports; | ||
return new Shift.ExportFrom(node, { namedExports: namedExports, moduleSpecifier: node.moduleSpecifier }); | ||
} | ||
}, { | ||
key: 'reduceExportFromSpecifier', | ||
value: function reduceExportFromSpecifier(node) { | ||
return new Shift.ExportFromSpecifier(node, { name: node.name, exportedName: node.exportedName }); | ||
} | ||
}, { | ||
key: 'reduceExportLocalSpecifier', | ||
value: function reduceExportLocalSpecifier(node, _ref30) { | ||
var name = _ref30.name; | ||
return new Shift.ExportLocalSpecifier(node, { name: name, exportedName: node.exportedName }); | ||
} | ||
}, { | ||
key: 'reduceExportLocals', | ||
value: function reduceExportLocals(node, _ref31) { | ||
var namedExports = _ref31.namedExports; | ||
return new Shift.ExportLocals(node, { namedExports: namedExports }); | ||
} | ||
}, { | ||
key: 'reduceExpressionStatement', | ||
value: function reduceExpressionStatement(node, _ref32) { | ||
var expression = _ref32.expression; | ||
return new Shift.ExpressionStatement(node, { expression: expression }); | ||
} | ||
}, { | ||
key: 'reduceForInStatement', | ||
value: function reduceForInStatement(node, _ref33) { | ||
var left = _ref33.left; | ||
var right = _ref33.right; | ||
var body = _ref33.body; | ||
return new Shift.ForInStatement(node, { left: left, right: right, body: body }); | ||
} | ||
}, { | ||
key: 'reduceForOfStatement', | ||
value: function reduceForOfStatement(node, _ref34) { | ||
var left = _ref34.left; | ||
var right = _ref34.right; | ||
var body = _ref34.body; | ||
return new Shift.ForOfStatement(node, { left: left, right: right, body: body }); | ||
} | ||
}, { | ||
key: 'reduceForStatement', | ||
value: function reduceForStatement(node, _ref35) { | ||
var init = _ref35.init; | ||
var test = _ref35.test; | ||
var update = _ref35.update; | ||
var body = _ref35.body; | ||
return new Shift.ForStatement(node, { init: init, test: test, update: update, body: body }); | ||
} | ||
}, { | ||
key: 'reduceFormalParameters', | ||
value: function reduceFormalParameters(node, _ref36) { | ||
var items = _ref36.items; | ||
var rest = _ref36.rest; | ||
return new Shift.FormalParameters(node, { items: items, rest: rest }); | ||
} | ||
}, { | ||
key: 'reduceFunctionBody', | ||
value: function reduceFunctionBody(node, _ref37) { | ||
var directives = _ref37.directives; | ||
var statements = _ref37.statements; | ||
return new Shift.FunctionBody(node, { directives: directives, statements: statements }); | ||
} | ||
}, { | ||
key: 'reduceFunctionDeclaration', | ||
value: function reduceFunctionDeclaration(node, _ref38) { | ||
var name = _ref38.name; | ||
var params = _ref38.params; | ||
var body = _ref38.body; | ||
return new Shift.FunctionDeclaration(node, { isGenerator: node.isGenerator, name: name, params: params, body: body }); | ||
} | ||
}, { | ||
key: 'reduceFunctionExpression', | ||
value: function reduceFunctionExpression(node, _ref39) { | ||
var name = _ref39.name; | ||
var params = _ref39.params; | ||
var body = _ref39.body; | ||
return new Shift.FunctionExpression(node, { isGenerator: node.isGenerator, name: name, params: params, body: body }); | ||
} | ||
}, { | ||
key: 'reduceGetter', | ||
value: function reduceGetter(node, _ref40) { | ||
var name = _ref40.name; | ||
var body = _ref40.body; | ||
return new Shift.Getter(node, { name: name, body: body }); | ||
} | ||
}, { | ||
key: 'reduceIdentifierExpression', | ||
value: function reduceIdentifierExpression(node) { | ||
return new Shift.IdentifierExpression(node, { name: node.name }); | ||
} | ||
}, { | ||
key: 'reduceIfStatement', | ||
value: function reduceIfStatement(node, _ref41) { | ||
var test = _ref41.test; | ||
var consequent = _ref41.consequent; | ||
var alternate = _ref41.alternate; | ||
return new Shift.IfStatement(node, { test: test, consequent: consequent, alternate: alternate }); | ||
} | ||
}, { | ||
key: 'reduceImport', | ||
value: function reduceImport(node, _ref42) { | ||
var defaultBinding = _ref42.defaultBinding; | ||
var namedImports = _ref42.namedImports; | ||
return new Shift.Import(node, { defaultBinding: defaultBinding, namedImports: namedImports, moduleSpecifier: node.moduleSpecifier }); | ||
} | ||
}, { | ||
key: 'reduceImportNamespace', | ||
value: function reduceImportNamespace(node, _ref43) { | ||
var defaultBinding = _ref43.defaultBinding; | ||
var namespaceBinding = _ref43.namespaceBinding; | ||
return new Shift.ImportNamespace(node, { defaultBinding: defaultBinding, namespaceBinding: namespaceBinding, moduleSpecifier: node.moduleSpecifier }); | ||
} | ||
}, { | ||
key: 'reduceImportSpecifier', | ||
value: function reduceImportSpecifier(node, _ref44) { | ||
var binding = _ref44.binding; | ||
return new Shift.ImportSpecifier(node, { name: node.name, binding: binding }); | ||
} | ||
}, { | ||
key: 'reduceLabeledStatement', | ||
value: function reduceLabeledStatement(node, _ref45) { | ||
var body = _ref45.body; | ||
return new Shift.LabeledStatement(node, { label: node.label, body: body }); | ||
} | ||
}, { | ||
key: 'reduceLiteralBooleanExpression', | ||
value: function reduceLiteralBooleanExpression(node) { | ||
return new Shift.LiteralBooleanExpression(node, { value: node.value }); | ||
} | ||
}, { | ||
key: 'reduceLiteralInfinityExpression', | ||
value: function reduceLiteralInfinityExpression(node) { | ||
return new Shift.LiteralInfinityExpression(); | ||
} | ||
}, { | ||
key: 'reduceLiteralNullExpression', | ||
value: function reduceLiteralNullExpression(node) { | ||
return new Shift.LiteralNullExpression(); | ||
} | ||
}, { | ||
key: 'reduceLiteralNumericExpression', | ||
value: function reduceLiteralNumericExpression(node) { | ||
return new Shift.LiteralNumericExpression(node, { value: node.value }); | ||
} | ||
}, { | ||
key: 'reduceLiteralRegExpExpression', | ||
value: function reduceLiteralRegExpExpression(node) { | ||
return new Shift.LiteralRegExpExpression(node, { pattern: node.pattern, global: node.global, ignoreCase: node.ignoreCase, multiLine: node.multiLine, sticky: node.sticky, unicode: node.unicode }); | ||
} | ||
}, { | ||
key: 'reduceLiteralStringExpression', | ||
value: function reduceLiteralStringExpression(node) { | ||
return new Shift.LiteralStringExpression(node, { value: node.value }); | ||
} | ||
}, { | ||
key: 'reduceMethod', | ||
value: function reduceMethod(node, _ref46) { | ||
var name = _ref46.name; | ||
var params = _ref46.params; | ||
var body = _ref46.body; | ||
return new Shift.Method(node, { isGenerator: node.isGenerator, name: name, params: params, body: body }); | ||
} | ||
}, { | ||
key: 'reduceModule', | ||
value: function reduceModule(node, _ref47) { | ||
var directives = _ref47.directives; | ||
var items = _ref47.items; | ||
return new Shift.Module(node, { directives: directives, items: items }); | ||
} | ||
}, { | ||
key: 'reduceNewExpression', | ||
value: function reduceNewExpression(node, _ref48) { | ||
var callee = _ref48.callee; | ||
var _arguments = _ref48.arguments; | ||
return new Shift.NewExpression(node, { callee: callee, arguments: _arguments }); | ||
} | ||
}, { | ||
key: 'reduceNewTargetExpression', | ||
value: function reduceNewTargetExpression(node) { | ||
return new Shift.NewTargetExpression(); | ||
} | ||
}, { | ||
key: 'reduceObjectAssignmentTarget', | ||
value: function reduceObjectAssignmentTarget(node, _ref49) { | ||
var properties = _ref49.properties; | ||
return new Shift.ObjectAssignmentTarget(node, { properties: properties }); | ||
} | ||
}, { | ||
key: 'reduceObjectBinding', | ||
value: function reduceObjectBinding(node, _ref50) { | ||
var properties = _ref50.properties; | ||
return new Shift.ObjectBinding(node, { properties: properties }); | ||
} | ||
}, { | ||
key: 'reduceObjectExpression', | ||
value: function reduceObjectExpression(node, _ref51) { | ||
var properties = _ref51.properties; | ||
return new Shift.ObjectExpression(node, { properties: properties }); | ||
} | ||
}, { | ||
key: 'reduceReturnStatement', | ||
value: function reduceReturnStatement(node, _ref52) { | ||
var expression = _ref52.expression; | ||
return new Shift.ReturnStatement(node, { expression: expression }); | ||
} | ||
}, { | ||
key: 'reduceScript', | ||
value: function reduceScript(node, _ref53) { | ||
var directives = _ref53.directives; | ||
var statements = _ref53.statements; | ||
return new Shift.Script(node, { directives: directives, statements: statements }); | ||
} | ||
}, { | ||
key: 'reduceSetter', | ||
value: function reduceSetter(node, _ref54) { | ||
var name = _ref54.name; | ||
var param = _ref54.param; | ||
var body = _ref54.body; | ||
return new Shift.Setter(node, { name: name, param: param, body: body }); | ||
} | ||
}, { | ||
key: 'reduceShorthandProperty', | ||
value: function reduceShorthandProperty(node, _ref55) { | ||
var name = _ref55.name; | ||
return new Shift.ShorthandProperty(node, { name: name }); | ||
} | ||
}, { | ||
key: 'reduceSpreadElement', | ||
value: function reduceSpreadElement(node, _ref56) { | ||
var expression = _ref56.expression; | ||
return new Shift.SpreadElement(node, { expression: expression }); | ||
} | ||
}, { | ||
key: 'reduceStaticMemberAssignmentTarget', | ||
value: function reduceStaticMemberAssignmentTarget(node, _ref57) { | ||
var object = _ref57.object; | ||
return new Shift.StaticMemberAssignmentTarget(node, { object: object, property: node.property }); | ||
} | ||
}, { | ||
key: 'reduceStaticMemberExpression', | ||
value: function reduceStaticMemberExpression(node, _ref58) { | ||
var object = _ref58.object; | ||
return new Shift.StaticMemberExpression(node, { object: object, property: node.property }); | ||
} | ||
}, { | ||
key: 'reduceStaticPropertyName', | ||
value: function reduceStaticPropertyName(node) { | ||
return new Shift.StaticPropertyName(node, { value: node.value }); | ||
} | ||
}, { | ||
key: 'reduceSuper', | ||
value: function reduceSuper(node) { | ||
return new Shift.Super(); | ||
} | ||
}, { | ||
key: 'reduceSwitchCase', | ||
value: function reduceSwitchCase(node, _ref59) { | ||
var test = _ref59.test; | ||
var consequent = _ref59.consequent; | ||
return new Shift.SwitchCase(node, { test: test, consequent: consequent }); | ||
} | ||
}, { | ||
key: 'reduceSwitchDefault', | ||
value: function reduceSwitchDefault(node, _ref60) { | ||
var consequent = _ref60.consequent; | ||
return new Shift.SwitchDefault(node, { consequent: consequent }); | ||
} | ||
}, { | ||
key: 'reduceSwitchStatement', | ||
value: function reduceSwitchStatement(node, _ref61) { | ||
var discriminant = _ref61.discriminant; | ||
var cases = _ref61.cases; | ||
return new Shift.SwitchStatement(node, { discriminant: discriminant, cases: cases }); | ||
} | ||
}, { | ||
key: 'reduceSwitchStatementWithDefault', | ||
value: function reduceSwitchStatementWithDefault(node, _ref62) { | ||
var discriminant = _ref62.discriminant; | ||
var preDefaultCases = _ref62.preDefaultCases; | ||
var defaultCase = _ref62.defaultCase; | ||
var postDefaultCases = _ref62.postDefaultCases; | ||
return new Shift.SwitchStatementWithDefault(node, { discriminant: discriminant, preDefaultCases: preDefaultCases, defaultCase: defaultCase, postDefaultCases: postDefaultCases }); | ||
} | ||
}, { | ||
key: 'reduceTemplateElement', | ||
value: function reduceTemplateElement(node) { | ||
return new Shift.TemplateElement(node, { rawValue: node.rawValue }); | ||
} | ||
}, { | ||
key: 'reduceTemplateExpression', | ||
value: function reduceTemplateExpression(node, _ref63) { | ||
var tag = _ref63.tag; | ||
var elements = _ref63.elements; | ||
return new Shift.TemplateExpression(node, { tag: tag, elements: elements }); | ||
} | ||
}, { | ||
key: 'reduceThisExpression', | ||
value: function reduceThisExpression(node) { | ||
return new Shift.ThisExpression(); | ||
} | ||
}, { | ||
key: 'reduceThrowStatement', | ||
value: function reduceThrowStatement(node, _ref64) { | ||
var expression = _ref64.expression; | ||
return new Shift.ThrowStatement(node, { expression: expression }); | ||
} | ||
}, { | ||
key: 'reduceTryCatchStatement', | ||
value: function reduceTryCatchStatement(node, _ref65) { | ||
var body = _ref65.body; | ||
var catchClause = _ref65.catchClause; | ||
return new Shift.TryCatchStatement(node, { body: body, catchClause: catchClause }); | ||
} | ||
}, { | ||
key: 'reduceTryFinallyStatement', | ||
value: function reduceTryFinallyStatement(node, _ref66) { | ||
var body = _ref66.body; | ||
var catchClause = _ref66.catchClause; | ||
var finalizer = _ref66.finalizer; | ||
return new Shift.TryFinallyStatement(node, { body: body, catchClause: catchClause, finalizer: finalizer }); | ||
} | ||
}, { | ||
key: 'reduceUnaryExpression', | ||
value: function reduceUnaryExpression(node, _ref67) { | ||
var operand = _ref67.operand; | ||
return new Shift.UnaryExpression(node, { operator: node.operator, operand: operand }); | ||
} | ||
}, { | ||
key: 'reduceUpdateExpression', | ||
value: function reduceUpdateExpression(node, _ref68) { | ||
var operand = _ref68.operand; | ||
return new Shift.UpdateExpression(node, { isPrefix: node.isPrefix, operator: node.operator, operand: operand }); | ||
} | ||
}, { | ||
key: 'reduceVariableDeclaration', | ||
value: function reduceVariableDeclaration(node, _ref69) { | ||
var declarators = _ref69.declarators; | ||
return new Shift.VariableDeclaration(node, { kind: node.kind, declarators: declarators }); | ||
} | ||
}, { | ||
key: 'reduceVariableDeclarationStatement', | ||
value: function reduceVariableDeclarationStatement(node, _ref70) { | ||
var declaration = _ref70.declaration; | ||
return new Shift.VariableDeclarationStatement(node, { declaration: declaration }); | ||
} | ||
}, { | ||
key: 'reduceVariableDeclarator', | ||
value: function reduceVariableDeclarator(node, _ref71) { | ||
var binding = _ref71.binding; | ||
var init = _ref71.init; | ||
return new Shift.VariableDeclarator(node, { binding: binding, init: init }); | ||
} | ||
}, { | ||
key: 'reduceWhileStatement', | ||
value: function reduceWhileStatement(node, _ref72) { | ||
var test = _ref72.test; | ||
var body = _ref72.body; | ||
return new Shift.WhileStatement(node, { test: test, body: body }); | ||
} | ||
}, { | ||
key: 'reduceWithStatement', | ||
value: function reduceWithStatement(node, _ref73) { | ||
var object = _ref73.object; | ||
var body = _ref73.body; | ||
return new Shift.WithStatement(node, { object: object, body: body }); | ||
} | ||
}, { | ||
key: 'reduceYieldExpression', | ||
value: function reduceYieldExpression(node, _ref74) { | ||
var expression = _ref74.expression; | ||
return new Shift.YieldExpression(node, { expression: expression }); | ||
} | ||
}, { | ||
key: 'reduceYieldGeneratorExpression', | ||
value: function reduceYieldGeneratorExpression(node, _ref75) { | ||
var expression = _ref75.expression; | ||
return new Shift.YieldGeneratorExpression(node, { expression: expression }); | ||
} | ||
}]); | ||
return CloneReducer; | ||
}(); | ||
exports.default = CloneReducer; |
@@ -6,3 +6,2 @@ "use strict"; | ||
}); | ||
exports.MonoidalReducer = exports.CloneReducer = undefined; | ||
exports.default = reduce; | ||
@@ -15,3 +14,3 @@ | ||
get: function get() { | ||
return _cloneReducer.default; | ||
return _interopRequireDefault(_cloneReducer).default; | ||
} | ||
@@ -25,61 +24,421 @@ }); | ||
get: function get() { | ||
return _monoidalReducer.default; | ||
return _interopRequireDefault(_monoidalReducer).default; | ||
} | ||
}); | ||
var _shiftSpec = require("shift-spec"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _shiftSpec2 = _interopRequireDefault(_shiftSpec); | ||
/** | ||
* Copyright 2016 Shape Security, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var director = { | ||
ArrayAssignmentTarget: function ArrayAssignmentTarget(reducer, node) { | ||
var _this = this; | ||
function transformWithSpec(transformer, node, spec) { | ||
switch (spec.typeName) { | ||
case "Enum": | ||
case "String": | ||
case "Number": | ||
case "Boolean": | ||
case "SourceSpan": | ||
return node; | ||
case "Const": | ||
// TODO: checked version | ||
return transformWithSpec(transformer, node, spec.argument); | ||
case "Maybe": | ||
return node && transformWithSpec(transformer, node, spec.argument); | ||
case "List": | ||
return node.map(function (e) { | ||
return transformWithSpec(transformer, e, spec.argument); | ||
}); | ||
case "Union": | ||
// TODO: checked version | ||
return transformWithSpec(transformer, node, _shiftSpec2.default[node.type]); | ||
default: | ||
var state = {}; | ||
spec.fields.forEach(function (field) { | ||
var v = transformWithSpec(transformer, node[field.name], field.type); | ||
state[field.name] = v == null ? null : v; | ||
}); | ||
if (typeof transformer["reduce" + node.type] !== "function") { | ||
throw new Error("Encountered " + node.type + ", which the provided reducer does not handle."); | ||
} | ||
return transformer["reduce" + node.type](node, state); | ||
return reducer.reduceArrayAssignmentTarget(node, { elements: node.elements.map(function (v) { | ||
return v && _this[v.type](reducer, v); | ||
}), rest: node.rest && this[node.rest.type](reducer, node.rest) }); | ||
}, | ||
ArrayBinding: function ArrayBinding(reducer, node) { | ||
var _this2 = this; | ||
return reducer.reduceArrayBinding(node, { elements: node.elements.map(function (v) { | ||
return v && _this2[v.type](reducer, v); | ||
}), rest: node.rest && this[node.rest.type](reducer, node.rest) }); | ||
}, | ||
ArrayExpression: function ArrayExpression(reducer, node) { | ||
var _this3 = this; | ||
return reducer.reduceArrayExpression(node, { elements: node.elements.map(function (v) { | ||
return v && _this3[v.type](reducer, v); | ||
}) }); | ||
}, | ||
ArrowExpression: function ArrowExpression(reducer, node) { | ||
return reducer.reduceArrowExpression(node, { params: this.FormalParameters(reducer, node.params), body: this[node.body.type](reducer, node.body) }); | ||
}, | ||
AssignmentExpression: function AssignmentExpression(reducer, node) { | ||
return reducer.reduceAssignmentExpression(node, { binding: this[node.binding.type](reducer, node.binding), expression: this[node.expression.type](reducer, node.expression) }); | ||
}, | ||
AssignmentTargetIdentifier: function AssignmentTargetIdentifier(reducer, node) { | ||
return reducer.reduceAssignmentTargetIdentifier(node); | ||
}, | ||
AssignmentTargetPropertyIdentifier: function AssignmentTargetPropertyIdentifier(reducer, node) { | ||
return reducer.reduceAssignmentTargetPropertyIdentifier(node, { binding: this.AssignmentTargetIdentifier(reducer, node.binding), init: node.init && this[node.init.type](reducer, node.init) }); | ||
}, | ||
AssignmentTargetPropertyProperty: function AssignmentTargetPropertyProperty(reducer, node) { | ||
return reducer.reduceAssignmentTargetPropertyProperty(node, { name: this[node.name.type](reducer, node.name), binding: this[node.binding.type](reducer, node.binding) }); | ||
}, | ||
AssignmentTargetWithDefault: function AssignmentTargetWithDefault(reducer, node) { | ||
return reducer.reduceAssignmentTargetWithDefault(node, { binding: this[node.binding.type](reducer, node.binding), init: this[node.init.type](reducer, node.init) }); | ||
}, | ||
BinaryExpression: function BinaryExpression(reducer, node) { | ||
return reducer.reduceBinaryExpression(node, { left: this[node.left.type](reducer, node.left), right: this[node.right.type](reducer, node.right) }); | ||
}, | ||
BindingIdentifier: function BindingIdentifier(reducer, node) { | ||
return reducer.reduceBindingIdentifier(node); | ||
}, | ||
BindingPropertyIdentifier: function BindingPropertyIdentifier(reducer, node) { | ||
return reducer.reduceBindingPropertyIdentifier(node, { binding: this.BindingIdentifier(reducer, node.binding), init: node.init && this[node.init.type](reducer, node.init) }); | ||
}, | ||
BindingPropertyProperty: function BindingPropertyProperty(reducer, node) { | ||
return reducer.reduceBindingPropertyProperty(node, { name: this[node.name.type](reducer, node.name), binding: this[node.binding.type](reducer, node.binding) }); | ||
}, | ||
BindingWithDefault: function BindingWithDefault(reducer, node) { | ||
return reducer.reduceBindingWithDefault(node, { binding: this[node.binding.type](reducer, node.binding), init: this[node.init.type](reducer, node.init) }); | ||
}, | ||
Block: function Block(reducer, node) { | ||
var _this4 = this; | ||
return reducer.reduceBlock(node, { statements: node.statements.map(function (v) { | ||
return _this4[v.type](reducer, v); | ||
}) }); | ||
}, | ||
BlockStatement: function BlockStatement(reducer, node) { | ||
return reducer.reduceBlockStatement(node, { block: this.Block(reducer, node.block) }); | ||
}, | ||
BreakStatement: function BreakStatement(reducer, node) { | ||
return reducer.reduceBreakStatement(node); | ||
}, | ||
CallExpression: function CallExpression(reducer, node) { | ||
var _this5 = this; | ||
return reducer.reduceCallExpression(node, { callee: this[node.callee.type](reducer, node.callee), arguments: node.arguments.map(function (v) { | ||
return _this5[v.type](reducer, v); | ||
}) }); | ||
}, | ||
CatchClause: function CatchClause(reducer, node) { | ||
return reducer.reduceCatchClause(node, { binding: this[node.binding.type](reducer, node.binding), body: this.Block(reducer, node.body) }); | ||
}, | ||
ClassDeclaration: function ClassDeclaration(reducer, node) { | ||
var _this6 = this; | ||
return reducer.reduceClassDeclaration(node, { name: this.BindingIdentifier(reducer, node.name), super: node.super && this[node.super.type](reducer, node.super), elements: node.elements.map(function (v) { | ||
return _this6.ClassElement(reducer, v); | ||
}) }); | ||
}, | ||
ClassElement: function ClassElement(reducer, node) { | ||
return reducer.reduceClassElement(node, { method: this[node.method.type](reducer, node.method) }); | ||
}, | ||
ClassExpression: function ClassExpression(reducer, node) { | ||
var _this7 = this; | ||
return reducer.reduceClassExpression(node, { name: node.name && this.BindingIdentifier(reducer, node.name), super: node.super && this[node.super.type](reducer, node.super), elements: node.elements.map(function (v) { | ||
return _this7.ClassElement(reducer, v); | ||
}) }); | ||
}, | ||
CompoundAssignmentExpression: function CompoundAssignmentExpression(reducer, node) { | ||
return reducer.reduceCompoundAssignmentExpression(node, { binding: this[node.binding.type](reducer, node.binding), expression: this[node.expression.type](reducer, node.expression) }); | ||
}, | ||
ComputedMemberAssignmentTarget: function ComputedMemberAssignmentTarget(reducer, node) { | ||
return reducer.reduceComputedMemberAssignmentTarget(node, { object: this[node.object.type](reducer, node.object), expression: this[node.expression.type](reducer, node.expression) }); | ||
}, | ||
ComputedMemberExpression: function ComputedMemberExpression(reducer, node) { | ||
return reducer.reduceComputedMemberExpression(node, { object: this[node.object.type](reducer, node.object), expression: this[node.expression.type](reducer, node.expression) }); | ||
}, | ||
ComputedPropertyName: function ComputedPropertyName(reducer, node) { | ||
return reducer.reduceComputedPropertyName(node, { expression: this[node.expression.type](reducer, node.expression) }); | ||
}, | ||
ConditionalExpression: function ConditionalExpression(reducer, node) { | ||
return reducer.reduceConditionalExpression(node, { test: this[node.test.type](reducer, node.test), consequent: this[node.consequent.type](reducer, node.consequent), alternate: this[node.alternate.type](reducer, node.alternate) }); | ||
}, | ||
ContinueStatement: function ContinueStatement(reducer, node) { | ||
return reducer.reduceContinueStatement(node); | ||
}, | ||
DataProperty: function DataProperty(reducer, node) { | ||
return reducer.reduceDataProperty(node, { name: this[node.name.type](reducer, node.name), expression: this[node.expression.type](reducer, node.expression) }); | ||
}, | ||
DebuggerStatement: function DebuggerStatement(reducer, node) { | ||
return reducer.reduceDebuggerStatement(node); | ||
}, | ||
Directive: function Directive(reducer, node) { | ||
return reducer.reduceDirective(node); | ||
}, | ||
DoWhileStatement: function DoWhileStatement(reducer, node) { | ||
return reducer.reduceDoWhileStatement(node, { body: this[node.body.type](reducer, node.body), test: this[node.test.type](reducer, node.test) }); | ||
}, | ||
EmptyStatement: function EmptyStatement(reducer, node) { | ||
return reducer.reduceEmptyStatement(node); | ||
}, | ||
Export: function Export(reducer, node) { | ||
return reducer.reduceExport(node, { declaration: this[node.declaration.type](reducer, node.declaration) }); | ||
}, | ||
ExportAllFrom: function ExportAllFrom(reducer, node) { | ||
return reducer.reduceExportAllFrom(node); | ||
}, | ||
ExportDefault: function ExportDefault(reducer, node) { | ||
return reducer.reduceExportDefault(node, { body: this[node.body.type](reducer, node.body) }); | ||
}, | ||
ExportFrom: function ExportFrom(reducer, node) { | ||
var _this8 = this; | ||
return reducer.reduceExportFrom(node, { namedExports: node.namedExports.map(function (v) { | ||
return _this8.ExportFromSpecifier(reducer, v); | ||
}) }); | ||
}, | ||
ExportFromSpecifier: function ExportFromSpecifier(reducer, node) { | ||
return reducer.reduceExportFromSpecifier(node); | ||
}, | ||
ExportLocalSpecifier: function ExportLocalSpecifier(reducer, node) { | ||
return reducer.reduceExportLocalSpecifier(node, { name: this.IdentifierExpression(reducer, node.name) }); | ||
}, | ||
ExportLocals: function ExportLocals(reducer, node) { | ||
var _this9 = this; | ||
return reducer.reduceExportLocals(node, { namedExports: node.namedExports.map(function (v) { | ||
return _this9.ExportLocalSpecifier(reducer, v); | ||
}) }); | ||
}, | ||
ExpressionStatement: function ExpressionStatement(reducer, node) { | ||
return reducer.reduceExpressionStatement(node, { expression: this[node.expression.type](reducer, node.expression) }); | ||
}, | ||
ForInStatement: function ForInStatement(reducer, node) { | ||
return reducer.reduceForInStatement(node, { left: this[node.left.type](reducer, node.left), right: this[node.right.type](reducer, node.right), body: this[node.body.type](reducer, node.body) }); | ||
}, | ||
ForOfStatement: function ForOfStatement(reducer, node) { | ||
return reducer.reduceForOfStatement(node, { left: this[node.left.type](reducer, node.left), right: this[node.right.type](reducer, node.right), body: this[node.body.type](reducer, node.body) }); | ||
}, | ||
ForStatement: function ForStatement(reducer, node) { | ||
return reducer.reduceForStatement(node, { init: node.init && this[node.init.type](reducer, node.init), test: node.test && this[node.test.type](reducer, node.test), update: node.update && this[node.update.type](reducer, node.update), body: this[node.body.type](reducer, node.body) }); | ||
}, | ||
FormalParameters: function FormalParameters(reducer, node) { | ||
var _this10 = this; | ||
return reducer.reduceFormalParameters(node, { items: node.items.map(function (v) { | ||
return _this10[v.type](reducer, v); | ||
}), rest: node.rest && this[node.rest.type](reducer, node.rest) }); | ||
}, | ||
FunctionBody: function FunctionBody(reducer, node) { | ||
var _this11 = this; | ||
return reducer.reduceFunctionBody(node, { directives: node.directives.map(function (v) { | ||
return _this11.Directive(reducer, v); | ||
}), statements: node.statements.map(function (v) { | ||
return _this11[v.type](reducer, v); | ||
}) }); | ||
}, | ||
FunctionDeclaration: function FunctionDeclaration(reducer, node) { | ||
return reducer.reduceFunctionDeclaration(node, { name: this.BindingIdentifier(reducer, node.name), params: this.FormalParameters(reducer, node.params), body: this.FunctionBody(reducer, node.body) }); | ||
}, | ||
FunctionExpression: function FunctionExpression(reducer, node) { | ||
return reducer.reduceFunctionExpression(node, { name: node.name && this.BindingIdentifier(reducer, node.name), params: this.FormalParameters(reducer, node.params), body: this.FunctionBody(reducer, node.body) }); | ||
}, | ||
Getter: function Getter(reducer, node) { | ||
return reducer.reduceGetter(node, { name: this[node.name.type](reducer, node.name), body: this.FunctionBody(reducer, node.body) }); | ||
}, | ||
IdentifierExpression: function IdentifierExpression(reducer, node) { | ||
return reducer.reduceIdentifierExpression(node); | ||
}, | ||
IfStatement: function IfStatement(reducer, node) { | ||
return reducer.reduceIfStatement(node, { test: this[node.test.type](reducer, node.test), consequent: this[node.consequent.type](reducer, node.consequent), alternate: node.alternate && this[node.alternate.type](reducer, node.alternate) }); | ||
}, | ||
Import: function Import(reducer, node) { | ||
var _this12 = this; | ||
return reducer.reduceImport(node, { defaultBinding: node.defaultBinding && this.BindingIdentifier(reducer, node.defaultBinding), namedImports: node.namedImports.map(function (v) { | ||
return _this12.ImportSpecifier(reducer, v); | ||
}) }); | ||
}, | ||
ImportNamespace: function ImportNamespace(reducer, node) { | ||
return reducer.reduceImportNamespace(node, { defaultBinding: node.defaultBinding && this.BindingIdentifier(reducer, node.defaultBinding), namespaceBinding: this.BindingIdentifier(reducer, node.namespaceBinding) }); | ||
}, | ||
ImportSpecifier: function ImportSpecifier(reducer, node) { | ||
return reducer.reduceImportSpecifier(node, { binding: this.BindingIdentifier(reducer, node.binding) }); | ||
}, | ||
LabeledStatement: function LabeledStatement(reducer, node) { | ||
return reducer.reduceLabeledStatement(node, { body: this[node.body.type](reducer, node.body) }); | ||
}, | ||
LiteralBooleanExpression: function LiteralBooleanExpression(reducer, node) { | ||
return reducer.reduceLiteralBooleanExpression(node); | ||
}, | ||
LiteralInfinityExpression: function LiteralInfinityExpression(reducer, node) { | ||
return reducer.reduceLiteralInfinityExpression(node); | ||
}, | ||
LiteralNullExpression: function LiteralNullExpression(reducer, node) { | ||
return reducer.reduceLiteralNullExpression(node); | ||
}, | ||
LiteralNumericExpression: function LiteralNumericExpression(reducer, node) { | ||
return reducer.reduceLiteralNumericExpression(node); | ||
}, | ||
LiteralRegExpExpression: function LiteralRegExpExpression(reducer, node) { | ||
return reducer.reduceLiteralRegExpExpression(node); | ||
}, | ||
LiteralStringExpression: function LiteralStringExpression(reducer, node) { | ||
return reducer.reduceLiteralStringExpression(node); | ||
}, | ||
Method: function Method(reducer, node) { | ||
return reducer.reduceMethod(node, { name: this[node.name.type](reducer, node.name), params: this.FormalParameters(reducer, node.params), body: this.FunctionBody(reducer, node.body) }); | ||
}, | ||
Module: function Module(reducer, node) { | ||
var _this13 = this; | ||
return reducer.reduceModule(node, { directives: node.directives.map(function (v) { | ||
return _this13.Directive(reducer, v); | ||
}), items: node.items.map(function (v) { | ||
return _this13[v.type](reducer, v); | ||
}) }); | ||
}, | ||
NewExpression: function NewExpression(reducer, node) { | ||
var _this14 = this; | ||
return reducer.reduceNewExpression(node, { callee: this[node.callee.type](reducer, node.callee), arguments: node.arguments.map(function (v) { | ||
return _this14[v.type](reducer, v); | ||
}) }); | ||
}, | ||
NewTargetExpression: function NewTargetExpression(reducer, node) { | ||
return reducer.reduceNewTargetExpression(node); | ||
}, | ||
ObjectAssignmentTarget: function ObjectAssignmentTarget(reducer, node) { | ||
var _this15 = this; | ||
return reducer.reduceObjectAssignmentTarget(node, { properties: node.properties.map(function (v) { | ||
return _this15[v.type](reducer, v); | ||
}) }); | ||
}, | ||
ObjectBinding: function ObjectBinding(reducer, node) { | ||
var _this16 = this; | ||
return reducer.reduceObjectBinding(node, { properties: node.properties.map(function (v) { | ||
return _this16[v.type](reducer, v); | ||
}) }); | ||
}, | ||
ObjectExpression: function ObjectExpression(reducer, node) { | ||
var _this17 = this; | ||
return reducer.reduceObjectExpression(node, { properties: node.properties.map(function (v) { | ||
return _this17[v.type](reducer, v); | ||
}) }); | ||
}, | ||
ReturnStatement: function ReturnStatement(reducer, node) { | ||
return reducer.reduceReturnStatement(node, { expression: node.expression && this[node.expression.type](reducer, node.expression) }); | ||
}, | ||
Script: function Script(reducer, node) { | ||
var _this18 = this; | ||
return reducer.reduceScript(node, { directives: node.directives.map(function (v) { | ||
return _this18.Directive(reducer, v); | ||
}), statements: node.statements.map(function (v) { | ||
return _this18[v.type](reducer, v); | ||
}) }); | ||
}, | ||
Setter: function Setter(reducer, node) { | ||
return reducer.reduceSetter(node, { name: this[node.name.type](reducer, node.name), param: this[node.param.type](reducer, node.param), body: this.FunctionBody(reducer, node.body) }); | ||
}, | ||
ShorthandProperty: function ShorthandProperty(reducer, node) { | ||
return reducer.reduceShorthandProperty(node, { name: this.IdentifierExpression(reducer, node.name) }); | ||
}, | ||
SpreadElement: function SpreadElement(reducer, node) { | ||
return reducer.reduceSpreadElement(node, { expression: this[node.expression.type](reducer, node.expression) }); | ||
}, | ||
StaticMemberAssignmentTarget: function StaticMemberAssignmentTarget(reducer, node) { | ||
return reducer.reduceStaticMemberAssignmentTarget(node, { object: this[node.object.type](reducer, node.object) }); | ||
}, | ||
StaticMemberExpression: function StaticMemberExpression(reducer, node) { | ||
return reducer.reduceStaticMemberExpression(node, { object: this[node.object.type](reducer, node.object) }); | ||
}, | ||
StaticPropertyName: function StaticPropertyName(reducer, node) { | ||
return reducer.reduceStaticPropertyName(node); | ||
}, | ||
Super: function Super(reducer, node) { | ||
return reducer.reduceSuper(node); | ||
}, | ||
SwitchCase: function SwitchCase(reducer, node) { | ||
var _this19 = this; | ||
return reducer.reduceSwitchCase(node, { test: this[node.test.type](reducer, node.test), consequent: node.consequent.map(function (v) { | ||
return _this19[v.type](reducer, v); | ||
}) }); | ||
}, | ||
SwitchDefault: function SwitchDefault(reducer, node) { | ||
var _this20 = this; | ||
return reducer.reduceSwitchDefault(node, { consequent: node.consequent.map(function (v) { | ||
return _this20[v.type](reducer, v); | ||
}) }); | ||
}, | ||
SwitchStatement: function SwitchStatement(reducer, node) { | ||
var _this21 = this; | ||
return reducer.reduceSwitchStatement(node, { discriminant: this[node.discriminant.type](reducer, node.discriminant), cases: node.cases.map(function (v) { | ||
return _this21.SwitchCase(reducer, v); | ||
}) }); | ||
}, | ||
SwitchStatementWithDefault: function SwitchStatementWithDefault(reducer, node) { | ||
var _this22 = this; | ||
return reducer.reduceSwitchStatementWithDefault(node, { discriminant: this[node.discriminant.type](reducer, node.discriminant), preDefaultCases: node.preDefaultCases.map(function (v) { | ||
return _this22.SwitchCase(reducer, v); | ||
}), defaultCase: this.SwitchDefault(reducer, node.defaultCase), postDefaultCases: node.postDefaultCases.map(function (v) { | ||
return _this22.SwitchCase(reducer, v); | ||
}) }); | ||
}, | ||
TemplateElement: function TemplateElement(reducer, node) { | ||
return reducer.reduceTemplateElement(node); | ||
}, | ||
TemplateExpression: function TemplateExpression(reducer, node) { | ||
var _this23 = this; | ||
return reducer.reduceTemplateExpression(node, { tag: node.tag && this[node.tag.type](reducer, node.tag), elements: node.elements.map(function (v) { | ||
return _this23[v.type](reducer, v); | ||
}) }); | ||
}, | ||
ThisExpression: function ThisExpression(reducer, node) { | ||
return reducer.reduceThisExpression(node); | ||
}, | ||
ThrowStatement: function ThrowStatement(reducer, node) { | ||
return reducer.reduceThrowStatement(node, { expression: this[node.expression.type](reducer, node.expression) }); | ||
}, | ||
TryCatchStatement: function TryCatchStatement(reducer, node) { | ||
return reducer.reduceTryCatchStatement(node, { body: this.Block(reducer, node.body), catchClause: this.CatchClause(reducer, node.catchClause) }); | ||
}, | ||
TryFinallyStatement: function TryFinallyStatement(reducer, node) { | ||
return reducer.reduceTryFinallyStatement(node, { body: this.Block(reducer, node.body), catchClause: node.catchClause && this.CatchClause(reducer, node.catchClause), finalizer: this.Block(reducer, node.finalizer) }); | ||
}, | ||
UnaryExpression: function UnaryExpression(reducer, node) { | ||
return reducer.reduceUnaryExpression(node, { operand: this[node.operand.type](reducer, node.operand) }); | ||
}, | ||
UpdateExpression: function UpdateExpression(reducer, node) { | ||
return reducer.reduceUpdateExpression(node, { operand: this[node.operand.type](reducer, node.operand) }); | ||
}, | ||
VariableDeclaration: function VariableDeclaration(reducer, node) { | ||
var _this24 = this; | ||
return reducer.reduceVariableDeclaration(node, { declarators: node.declarators.map(function (v) { | ||
return _this24.VariableDeclarator(reducer, v); | ||
}) }); | ||
}, | ||
VariableDeclarationStatement: function VariableDeclarationStatement(reducer, node) { | ||
return reducer.reduceVariableDeclarationStatement(node, { declaration: this.VariableDeclaration(reducer, node.declaration) }); | ||
}, | ||
VariableDeclarator: function VariableDeclarator(reducer, node) { | ||
return reducer.reduceVariableDeclarator(node, { binding: this[node.binding.type](reducer, node.binding), init: node.init && this[node.init.type](reducer, node.init) }); | ||
}, | ||
WhileStatement: function WhileStatement(reducer, node) { | ||
return reducer.reduceWhileStatement(node, { test: this[node.test.type](reducer, node.test), body: this[node.body.type](reducer, node.body) }); | ||
}, | ||
WithStatement: function WithStatement(reducer, node) { | ||
return reducer.reduceWithStatement(node, { object: this[node.object.type](reducer, node.object), body: this[node.body.type](reducer, node.body) }); | ||
}, | ||
YieldExpression: function YieldExpression(reducer, node) { | ||
return reducer.reduceYieldExpression(node, { expression: node.expression && this[node.expression.type](reducer, node.expression) }); | ||
}, | ||
YieldGeneratorExpression: function YieldGeneratorExpression(reducer, node) { | ||
return reducer.reduceYieldGeneratorExpression(node, { expression: this[node.expression.type](reducer, node.expression) }); | ||
} | ||
} /** | ||
* Copyright 2014 Shape Security, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
}; | ||
function reduce(reducer, reducible) { | ||
return transformWithSpec(reducer, reducible, _shiftSpec2.default[reducible.type]); | ||
function reduce(reducer, node) { | ||
return director[node.type](reducer, node); | ||
} |
@@ -1,21 +0,3 @@ | ||
"use strict"; | ||
'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; /** | ||
* Copyright 2014 Shape Security, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -25,6 +7,22 @@ value: true | ||
var _shiftSpec = require("shift-spec"); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /** | ||
* Copyright 2016 Shape Security, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
var _shiftSpec2 = _interopRequireDefault(_shiftSpec); | ||
var _shiftAst = require('shift-ast'); | ||
var _shiftAst2 = _interopRequireDefault(_shiftAst); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -34,84 +32,2 @@ | ||
var methods = {}; | ||
function id(x) { | ||
return x; | ||
} | ||
function handlerForFieldOfType(type) { | ||
switch (type.typeName) { | ||
case "Enum": | ||
case "String": | ||
case "Boolean": | ||
case "Number": | ||
case "SourceSpan": | ||
return null; | ||
case "Const": | ||
return handlerForFieldOfType(type.argument); | ||
case "Maybe": | ||
{ | ||
var _ret = function () { | ||
var subHandler = handlerForFieldOfType(type.argument); | ||
if (subHandler == null) return { | ||
v: null | ||
}; | ||
return { | ||
v: function v(t) { | ||
return t == null ? this.identity : subHandler.call(this, t); | ||
} | ||
}; | ||
}(); | ||
if ((typeof _ret === "undefined" ? "undefined" : _typeof(_ret)) === "object") return _ret.v; | ||
} | ||
case "List": | ||
{ | ||
var _ret2 = function () { | ||
var subHandler = handlerForFieldOfType(type.argument); | ||
if (subHandler == null) return { | ||
v: null | ||
}; | ||
return { | ||
v: function v(t) { | ||
var _this = this; | ||
return this.fold(t.map(function (x) { | ||
return subHandler.call(_this, x); | ||
})); | ||
} | ||
}; | ||
}(); | ||
if ((typeof _ret2 === "undefined" ? "undefined" : _typeof(_ret2)) === "object") return _ret2.v; | ||
} | ||
default: | ||
return id; | ||
} | ||
} | ||
var _loop = function _loop(typeName) { | ||
var type = _shiftSpec2.default[typeName]; | ||
var handlers = {}; | ||
type.fields.forEach(function (field) { | ||
var handler = handlerForFieldOfType(field.type); | ||
if (handler != null) handlers[field.name] = handler; | ||
}); | ||
var fieldNames = Object.keys(handlers); | ||
methods["reduce" + typeName] = { | ||
value: function value(node, state) { | ||
var _this3 = this; | ||
return this.fold(fieldNames.map(function (fieldName) { | ||
return handlers[fieldName].call(_this3, state[fieldName]); | ||
})); | ||
} | ||
}; | ||
}; | ||
for (var typeName in _shiftSpec2.default) { | ||
_loop(typeName); | ||
} | ||
var MonoidalReducer = function () { | ||
@@ -129,10 +45,707 @@ function MonoidalReducer(monoid) { | ||
_createClass(MonoidalReducer, [{ | ||
key: "fold", | ||
key: 'fold', | ||
value: function fold(list, a) { | ||
var _this2 = this; | ||
var _this = this; | ||
return list.reduce(function (memo, x) { | ||
return _this2.append(memo, x); | ||
return _this.append(memo, x); | ||
}, a == null ? this.identity : a); | ||
} | ||
}, { | ||
key: 'reduceArrayAssignmentTarget', | ||
value: function reduceArrayAssignmentTarget(node, _ref) { | ||
var elements = _ref.elements; | ||
var rest = _ref.rest; | ||
return this.append(this.fold(elements.filter(function (n) { | ||
return n !== null; | ||
})), rest === null ? this.identity : rest); | ||
} | ||
}, { | ||
key: 'reduceArrayBinding', | ||
value: function reduceArrayBinding(node, _ref2) { | ||
var elements = _ref2.elements; | ||
var rest = _ref2.rest; | ||
return this.append(this.fold(elements.filter(function (n) { | ||
return n !== null; | ||
})), rest === null ? this.identity : rest); | ||
} | ||
}, { | ||
key: 'reduceArrayExpression', | ||
value: function reduceArrayExpression(node, _ref3) { | ||
var elements = _ref3.elements; | ||
return this.fold(elements.filter(function (n) { | ||
return n !== null; | ||
})); | ||
} | ||
}, { | ||
key: 'reduceArrowExpression', | ||
value: function reduceArrowExpression(node, _ref4) { | ||
var params = _ref4.params; | ||
var body = _ref4.body; | ||
return this.append(params, body); | ||
} | ||
}, { | ||
key: 'reduceAssignmentExpression', | ||
value: function reduceAssignmentExpression(node, _ref5) { | ||
var binding = _ref5.binding; | ||
var expression = _ref5.expression; | ||
return this.append(binding, expression); | ||
} | ||
}, { | ||
key: 'reduceAssignmentTargetIdentifier', | ||
value: function reduceAssignmentTargetIdentifier(node) { | ||
return this.identity; | ||
} | ||
}, { | ||
key: 'reduceAssignmentTargetPropertyIdentifier', | ||
value: function reduceAssignmentTargetPropertyIdentifier(node, _ref6) { | ||
var binding = _ref6.binding; | ||
var init = _ref6.init; | ||
return this.append(binding, init === null ? this.identity : init); | ||
} | ||
}, { | ||
key: 'reduceAssignmentTargetPropertyProperty', | ||
value: function reduceAssignmentTargetPropertyProperty(node, _ref7) { | ||
var name = _ref7.name; | ||
var binding = _ref7.binding; | ||
return this.append(name, binding); | ||
} | ||
}, { | ||
key: 'reduceAssignmentTargetWithDefault', | ||
value: function reduceAssignmentTargetWithDefault(node, _ref8) { | ||
var binding = _ref8.binding; | ||
var init = _ref8.init; | ||
return this.append(binding, init); | ||
} | ||
}, { | ||
key: 'reduceBinaryExpression', | ||
value: function reduceBinaryExpression(node, _ref9) { | ||
var left = _ref9.left; | ||
var right = _ref9.right; | ||
return this.append(left, right); | ||
} | ||
}, { | ||
key: 'reduceBindingIdentifier', | ||
value: function reduceBindingIdentifier(node) { | ||
return this.identity; | ||
} | ||
}, { | ||
key: 'reduceBindingPropertyIdentifier', | ||
value: function reduceBindingPropertyIdentifier(node, _ref10) { | ||
var binding = _ref10.binding; | ||
var init = _ref10.init; | ||
return this.append(binding, init === null ? this.identity : init); | ||
} | ||
}, { | ||
key: 'reduceBindingPropertyProperty', | ||
value: function reduceBindingPropertyProperty(node, _ref11) { | ||
var name = _ref11.name; | ||
var binding = _ref11.binding; | ||
return this.append(name, binding); | ||
} | ||
}, { | ||
key: 'reduceBindingWithDefault', | ||
value: function reduceBindingWithDefault(node, _ref12) { | ||
var binding = _ref12.binding; | ||
var init = _ref12.init; | ||
return this.append(binding, init); | ||
} | ||
}, { | ||
key: 'reduceBlock', | ||
value: function reduceBlock(node, _ref13) { | ||
var statements = _ref13.statements; | ||
return this.fold(statements); | ||
} | ||
}, { | ||
key: 'reduceBlockStatement', | ||
value: function reduceBlockStatement(node, _ref14) { | ||
var block = _ref14.block; | ||
return block; | ||
} | ||
}, { | ||
key: 'reduceBreakStatement', | ||
value: function reduceBreakStatement(node) { | ||
return this.identity; | ||
} | ||
}, { | ||
key: 'reduceCallExpression', | ||
value: function reduceCallExpression(node, _ref15) { | ||
var callee = _ref15.callee; | ||
var _arguments = _ref15.arguments; | ||
return this.append(callee, this.fold(_arguments)); | ||
} | ||
}, { | ||
key: 'reduceCatchClause', | ||
value: function reduceCatchClause(node, _ref16) { | ||
var binding = _ref16.binding; | ||
var body = _ref16.body; | ||
return this.append(binding, body); | ||
} | ||
}, { | ||
key: 'reduceClassDeclaration', | ||
value: function reduceClassDeclaration(node, _ref17) { | ||
var name = _ref17.name; | ||
var _super = _ref17.super; | ||
var elements = _ref17.elements; | ||
return this.fold([name, _super === null ? this.identity : _super, this.fold(elements)]); | ||
} | ||
}, { | ||
key: 'reduceClassElement', | ||
value: function reduceClassElement(node, _ref18) { | ||
var method = _ref18.method; | ||
return method; | ||
} | ||
}, { | ||
key: 'reduceClassExpression', | ||
value: function reduceClassExpression(node, _ref19) { | ||
var name = _ref19.name; | ||
var _super = _ref19.super; | ||
var elements = _ref19.elements; | ||
return this.fold([name === null ? this.identity : name, _super === null ? this.identity : _super, this.fold(elements)]); | ||
} | ||
}, { | ||
key: 'reduceCompoundAssignmentExpression', | ||
value: function reduceCompoundAssignmentExpression(node, _ref20) { | ||
var binding = _ref20.binding; | ||
var expression = _ref20.expression; | ||
return this.append(binding, expression); | ||
} | ||
}, { | ||
key: 'reduceComputedMemberAssignmentTarget', | ||
value: function reduceComputedMemberAssignmentTarget(node, _ref21) { | ||
var object = _ref21.object; | ||
var expression = _ref21.expression; | ||
return this.append(object, expression); | ||
} | ||
}, { | ||
key: 'reduceComputedMemberExpression', | ||
value: function reduceComputedMemberExpression(node, _ref22) { | ||
var object = _ref22.object; | ||
var expression = _ref22.expression; | ||
return this.append(object, expression); | ||
} | ||
}, { | ||
key: 'reduceComputedPropertyName', | ||
value: function reduceComputedPropertyName(node, _ref23) { | ||
var expression = _ref23.expression; | ||
return expression; | ||
} | ||
}, { | ||
key: 'reduceConditionalExpression', | ||
value: function reduceConditionalExpression(node, _ref24) { | ||
var test = _ref24.test; | ||
var consequent = _ref24.consequent; | ||
var alternate = _ref24.alternate; | ||
return this.fold([test, consequent, alternate]); | ||
} | ||
}, { | ||
key: 'reduceContinueStatement', | ||
value: function reduceContinueStatement(node) { | ||
return this.identity; | ||
} | ||
}, { | ||
key: 'reduceDataProperty', | ||
value: function reduceDataProperty(node, _ref25) { | ||
var name = _ref25.name; | ||
var expression = _ref25.expression; | ||
return this.append(name, expression); | ||
} | ||
}, { | ||
key: 'reduceDebuggerStatement', | ||
value: function reduceDebuggerStatement(node) { | ||
return this.identity; | ||
} | ||
}, { | ||
key: 'reduceDirective', | ||
value: function reduceDirective(node) { | ||
return this.identity; | ||
} | ||
}, { | ||
key: 'reduceDoWhileStatement', | ||
value: function reduceDoWhileStatement(node, _ref26) { | ||
var body = _ref26.body; | ||
var test = _ref26.test; | ||
return this.append(body, test); | ||
} | ||
}, { | ||
key: 'reduceEmptyStatement', | ||
value: function reduceEmptyStatement(node) { | ||
return this.identity; | ||
} | ||
}, { | ||
key: 'reduceExport', | ||
value: function reduceExport(node, _ref27) { | ||
var declaration = _ref27.declaration; | ||
return declaration; | ||
} | ||
}, { | ||
key: 'reduceExportAllFrom', | ||
value: function reduceExportAllFrom(node) { | ||
return this.identity; | ||
} | ||
}, { | ||
key: 'reduceExportDefault', | ||
value: function reduceExportDefault(node, _ref28) { | ||
var body = _ref28.body; | ||
return body; | ||
} | ||
}, { | ||
key: 'reduceExportFrom', | ||
value: function reduceExportFrom(node, _ref29) { | ||
var namedExports = _ref29.namedExports; | ||
return this.fold(namedExports); | ||
} | ||
}, { | ||
key: 'reduceExportFromSpecifier', | ||
value: function reduceExportFromSpecifier(node) { | ||
return this.identity; | ||
} | ||
}, { | ||
key: 'reduceExportLocalSpecifier', | ||
value: function reduceExportLocalSpecifier(node, _ref30) { | ||
var name = _ref30.name; | ||
return name; | ||
} | ||
}, { | ||
key: 'reduceExportLocals', | ||
value: function reduceExportLocals(node, _ref31) { | ||
var namedExports = _ref31.namedExports; | ||
return this.fold(namedExports); | ||
} | ||
}, { | ||
key: 'reduceExpressionStatement', | ||
value: function reduceExpressionStatement(node, _ref32) { | ||
var expression = _ref32.expression; | ||
return expression; | ||
} | ||
}, { | ||
key: 'reduceForInStatement', | ||
value: function reduceForInStatement(node, _ref33) { | ||
var left = _ref33.left; | ||
var right = _ref33.right; | ||
var body = _ref33.body; | ||
return this.fold([left, right, body]); | ||
} | ||
}, { | ||
key: 'reduceForOfStatement', | ||
value: function reduceForOfStatement(node, _ref34) { | ||
var left = _ref34.left; | ||
var right = _ref34.right; | ||
var body = _ref34.body; | ||
return this.fold([left, right, body]); | ||
} | ||
}, { | ||
key: 'reduceForStatement', | ||
value: function reduceForStatement(node, _ref35) { | ||
var init = _ref35.init; | ||
var test = _ref35.test; | ||
var update = _ref35.update; | ||
var body = _ref35.body; | ||
return this.fold([init === null ? this.identity : init, test === null ? this.identity : test, update === null ? this.identity : update, body]); | ||
} | ||
}, { | ||
key: 'reduceFormalParameters', | ||
value: function reduceFormalParameters(node, _ref36) { | ||
var items = _ref36.items; | ||
var rest = _ref36.rest; | ||
return this.append(this.fold(items), rest === null ? this.identity : rest); | ||
} | ||
}, { | ||
key: 'reduceFunctionBody', | ||
value: function reduceFunctionBody(node, _ref37) { | ||
var directives = _ref37.directives; | ||
var statements = _ref37.statements; | ||
return this.append(this.fold(directives), this.fold(statements)); | ||
} | ||
}, { | ||
key: 'reduceFunctionDeclaration', | ||
value: function reduceFunctionDeclaration(node, _ref38) { | ||
var name = _ref38.name; | ||
var params = _ref38.params; | ||
var body = _ref38.body; | ||
return this.fold([name, params, body]); | ||
} | ||
}, { | ||
key: 'reduceFunctionExpression', | ||
value: function reduceFunctionExpression(node, _ref39) { | ||
var name = _ref39.name; | ||
var params = _ref39.params; | ||
var body = _ref39.body; | ||
return this.fold([name === null ? this.identity : name, params, body]); | ||
} | ||
}, { | ||
key: 'reduceGetter', | ||
value: function reduceGetter(node, _ref40) { | ||
var name = _ref40.name; | ||
var body = _ref40.body; | ||
return this.append(name, body); | ||
} | ||
}, { | ||
key: 'reduceIdentifierExpression', | ||
value: function reduceIdentifierExpression(node) { | ||
return this.identity; | ||
} | ||
}, { | ||
key: 'reduceIfStatement', | ||
value: function reduceIfStatement(node, _ref41) { | ||
var test = _ref41.test; | ||
var consequent = _ref41.consequent; | ||
var alternate = _ref41.alternate; | ||
return this.fold([test, consequent, alternate === null ? this.identity : alternate]); | ||
} | ||
}, { | ||
key: 'reduceImport', | ||
value: function reduceImport(node, _ref42) { | ||
var defaultBinding = _ref42.defaultBinding; | ||
var namedImports = _ref42.namedImports; | ||
return this.append(defaultBinding === null ? this.identity : defaultBinding, this.fold(namedImports)); | ||
} | ||
}, { | ||
key: 'reduceImportNamespace', | ||
value: function reduceImportNamespace(node, _ref43) { | ||
var defaultBinding = _ref43.defaultBinding; | ||
var namespaceBinding = _ref43.namespaceBinding; | ||
return this.append(defaultBinding === null ? this.identity : defaultBinding, namespaceBinding); | ||
} | ||
}, { | ||
key: 'reduceImportSpecifier', | ||
value: function reduceImportSpecifier(node, _ref44) { | ||
var binding = _ref44.binding; | ||
return binding; | ||
} | ||
}, { | ||
key: 'reduceLabeledStatement', | ||
value: function reduceLabeledStatement(node, _ref45) { | ||
var body = _ref45.body; | ||
return body; | ||
} | ||
}, { | ||
key: 'reduceLiteralBooleanExpression', | ||
value: function reduceLiteralBooleanExpression(node) { | ||
return this.identity; | ||
} | ||
}, { | ||
key: 'reduceLiteralInfinityExpression', | ||
value: function reduceLiteralInfinityExpression(node) { | ||
return this.identity; | ||
} | ||
}, { | ||
key: 'reduceLiteralNullExpression', | ||
value: function reduceLiteralNullExpression(node) { | ||
return this.identity; | ||
} | ||
}, { | ||
key: 'reduceLiteralNumericExpression', | ||
value: function reduceLiteralNumericExpression(node) { | ||
return this.identity; | ||
} | ||
}, { | ||
key: 'reduceLiteralRegExpExpression', | ||
value: function reduceLiteralRegExpExpression(node) { | ||
return this.identity; | ||
} | ||
}, { | ||
key: 'reduceLiteralStringExpression', | ||
value: function reduceLiteralStringExpression(node) { | ||
return this.identity; | ||
} | ||
}, { | ||
key: 'reduceMethod', | ||
value: function reduceMethod(node, _ref46) { | ||
var name = _ref46.name; | ||
var params = _ref46.params; | ||
var body = _ref46.body; | ||
return this.fold([name, params, body]); | ||
} | ||
}, { | ||
key: 'reduceModule', | ||
value: function reduceModule(node, _ref47) { | ||
var directives = _ref47.directives; | ||
var items = _ref47.items; | ||
return this.append(this.fold(directives), this.fold(items)); | ||
} | ||
}, { | ||
key: 'reduceNewExpression', | ||
value: function reduceNewExpression(node, _ref48) { | ||
var callee = _ref48.callee; | ||
var _arguments = _ref48.arguments; | ||
return this.append(callee, this.fold(_arguments)); | ||
} | ||
}, { | ||
key: 'reduceNewTargetExpression', | ||
value: function reduceNewTargetExpression(node) { | ||
return this.identity; | ||
} | ||
}, { | ||
key: 'reduceObjectAssignmentTarget', | ||
value: function reduceObjectAssignmentTarget(node, _ref49) { | ||
var properties = _ref49.properties; | ||
return this.fold(properties); | ||
} | ||
}, { | ||
key: 'reduceObjectBinding', | ||
value: function reduceObjectBinding(node, _ref50) { | ||
var properties = _ref50.properties; | ||
return this.fold(properties); | ||
} | ||
}, { | ||
key: 'reduceObjectExpression', | ||
value: function reduceObjectExpression(node, _ref51) { | ||
var properties = _ref51.properties; | ||
return this.fold(properties); | ||
} | ||
}, { | ||
key: 'reduceReturnStatement', | ||
value: function reduceReturnStatement(node, _ref52) { | ||
var expression = _ref52.expression; | ||
return expression === null ? this.identity : expression; | ||
} | ||
}, { | ||
key: 'reduceScript', | ||
value: function reduceScript(node, _ref53) { | ||
var directives = _ref53.directives; | ||
var statements = _ref53.statements; | ||
return this.append(this.fold(directives), this.fold(statements)); | ||
} | ||
}, { | ||
key: 'reduceSetter', | ||
value: function reduceSetter(node, _ref54) { | ||
var name = _ref54.name; | ||
var param = _ref54.param; | ||
var body = _ref54.body; | ||
return this.fold([name, param, body]); | ||
} | ||
}, { | ||
key: 'reduceShorthandProperty', | ||
value: function reduceShorthandProperty(node, _ref55) { | ||
var name = _ref55.name; | ||
return name; | ||
} | ||
}, { | ||
key: 'reduceSpreadElement', | ||
value: function reduceSpreadElement(node, _ref56) { | ||
var expression = _ref56.expression; | ||
return expression; | ||
} | ||
}, { | ||
key: 'reduceStaticMemberAssignmentTarget', | ||
value: function reduceStaticMemberAssignmentTarget(node, _ref57) { | ||
var object = _ref57.object; | ||
return object; | ||
} | ||
}, { | ||
key: 'reduceStaticMemberExpression', | ||
value: function reduceStaticMemberExpression(node, _ref58) { | ||
var object = _ref58.object; | ||
return object; | ||
} | ||
}, { | ||
key: 'reduceStaticPropertyName', | ||
value: function reduceStaticPropertyName(node) { | ||
return this.identity; | ||
} | ||
}, { | ||
key: 'reduceSuper', | ||
value: function reduceSuper(node) { | ||
return this.identity; | ||
} | ||
}, { | ||
key: 'reduceSwitchCase', | ||
value: function reduceSwitchCase(node, _ref59) { | ||
var test = _ref59.test; | ||
var consequent = _ref59.consequent; | ||
return this.append(test, this.fold(consequent)); | ||
} | ||
}, { | ||
key: 'reduceSwitchDefault', | ||
value: function reduceSwitchDefault(node, _ref60) { | ||
var consequent = _ref60.consequent; | ||
return this.fold(consequent); | ||
} | ||
}, { | ||
key: 'reduceSwitchStatement', | ||
value: function reduceSwitchStatement(node, _ref61) { | ||
var discriminant = _ref61.discriminant; | ||
var cases = _ref61.cases; | ||
return this.append(discriminant, this.fold(cases)); | ||
} | ||
}, { | ||
key: 'reduceSwitchStatementWithDefault', | ||
value: function reduceSwitchStatementWithDefault(node, _ref62) { | ||
var discriminant = _ref62.discriminant; | ||
var preDefaultCases = _ref62.preDefaultCases; | ||
var defaultCase = _ref62.defaultCase; | ||
var postDefaultCases = _ref62.postDefaultCases; | ||
return this.fold([discriminant, this.fold(preDefaultCases), defaultCase, this.fold(postDefaultCases)]); | ||
} | ||
}, { | ||
key: 'reduceTemplateElement', | ||
value: function reduceTemplateElement(node) { | ||
return this.identity; | ||
} | ||
}, { | ||
key: 'reduceTemplateExpression', | ||
value: function reduceTemplateExpression(node, _ref63) { | ||
var tag = _ref63.tag; | ||
var elements = _ref63.elements; | ||
return this.append(tag === null ? this.identity : tag, this.fold(elements)); | ||
} | ||
}, { | ||
key: 'reduceThisExpression', | ||
value: function reduceThisExpression(node) { | ||
return this.identity; | ||
} | ||
}, { | ||
key: 'reduceThrowStatement', | ||
value: function reduceThrowStatement(node, _ref64) { | ||
var expression = _ref64.expression; | ||
return expression; | ||
} | ||
}, { | ||
key: 'reduceTryCatchStatement', | ||
value: function reduceTryCatchStatement(node, _ref65) { | ||
var body = _ref65.body; | ||
var catchClause = _ref65.catchClause; | ||
return this.append(body, catchClause); | ||
} | ||
}, { | ||
key: 'reduceTryFinallyStatement', | ||
value: function reduceTryFinallyStatement(node, _ref66) { | ||
var body = _ref66.body; | ||
var catchClause = _ref66.catchClause; | ||
var finalizer = _ref66.finalizer; | ||
return this.fold([body, catchClause === null ? this.identity : catchClause, finalizer]); | ||
} | ||
}, { | ||
key: 'reduceUnaryExpression', | ||
value: function reduceUnaryExpression(node, _ref67) { | ||
var operand = _ref67.operand; | ||
return operand; | ||
} | ||
}, { | ||
key: 'reduceUpdateExpression', | ||
value: function reduceUpdateExpression(node, _ref68) { | ||
var operand = _ref68.operand; | ||
return operand; | ||
} | ||
}, { | ||
key: 'reduceVariableDeclaration', | ||
value: function reduceVariableDeclaration(node, _ref69) { | ||
var declarators = _ref69.declarators; | ||
return this.fold(declarators); | ||
} | ||
}, { | ||
key: 'reduceVariableDeclarationStatement', | ||
value: function reduceVariableDeclarationStatement(node, _ref70) { | ||
var declaration = _ref70.declaration; | ||
return declaration; | ||
} | ||
}, { | ||
key: 'reduceVariableDeclarator', | ||
value: function reduceVariableDeclarator(node, _ref71) { | ||
var binding = _ref71.binding; | ||
var init = _ref71.init; | ||
return this.append(binding, init === null ? this.identity : init); | ||
} | ||
}, { | ||
key: 'reduceWhileStatement', | ||
value: function reduceWhileStatement(node, _ref72) { | ||
var test = _ref72.test; | ||
var body = _ref72.body; | ||
return this.append(test, body); | ||
} | ||
}, { | ||
key: 'reduceWithStatement', | ||
value: function reduceWithStatement(node, _ref73) { | ||
var object = _ref73.object; | ||
var body = _ref73.body; | ||
return this.append(object, body); | ||
} | ||
}, { | ||
key: 'reduceYieldExpression', | ||
value: function reduceYieldExpression(node, _ref74) { | ||
var expression = _ref74.expression; | ||
return expression === null ? this.identity : expression; | ||
} | ||
}, { | ||
key: 'reduceYieldGeneratorExpression', | ||
value: function reduceYieldGeneratorExpression(node, _ref75) { | ||
var expression = _ref75.expression; | ||
return expression; | ||
} | ||
}]); | ||
@@ -143,4 +756,2 @@ | ||
exports.default = MonoidalReducer; | ||
Object.defineProperties(MonoidalReducer.prototype, methods); | ||
exports.default = MonoidalReducer; |
{ | ||
"name": "shift-reducer", | ||
"version": "3.0.3", | ||
"version": "4.0.0", | ||
"description": "reducer for the Shift AST format", | ||
@@ -16,8 +16,8 @@ "author": "Shape Security Labs", | ||
"scripts": { | ||
"test": "mocha --compilers js:babel-register --inline-diffs --check-leaks --ui tdd --reporter dot test", | ||
"build": "babel --source-maps-inline --out-dir dist src", | ||
"test": "mocha --inline-diffs --check-leaks --ui tdd --reporter dot test", | ||
"build": "mkdir -p gen dist && node src/generate-clone-reducer.js && node src/generate-monoidal-reducer.js && node src/generate-index.js && babel --out-dir dist gen", | ||
"prepublish": "rm -rf dist && npm update && npm run build" | ||
}, | ||
"dependencies": { | ||
"shift-spec": "^2015.2.0" | ||
"shift-ast": "^4.0.0" | ||
}, | ||
@@ -28,4 +28,6 @@ "devDependencies": { | ||
"babel-preset-es2015": "6.3.13", | ||
"everything.js": "^1.0.3", | ||
"mocha": "^2.3.4", | ||
"shift-parser": "^3.0.0" | ||
"shift-parser": "^3.0.0", | ||
"shift-spec": "^2016.0.0" | ||
}, | ||
@@ -32,0 +34,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
98616
1721
7
5
1
0
1
+ Addedshift-ast@^4.0.0
+ Addedshift-ast@4.0.0(transitive)
- Removedshift-spec@^2015.2.0
- Removedshift-spec@2015.2.1(transitive)