aboutsummaryrefslogtreecommitdiff
path: root/node_modules/espurify/lib
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/espurify/lib')
-rw-r--r--node_modules/espurify/lib/ast-properties.js132
-rw-r--r--node_modules/espurify/lib/clone-ast.js113
-rw-r--r--node_modules/espurify/lib/create-whitelist.js18
3 files changed, 139 insertions, 124 deletions
diff --git a/node_modules/espurify/lib/ast-properties.js b/node_modules/espurify/lib/ast-properties.js
index 37267b973..db22925d1 100644
--- a/node_modules/espurify/lib/ast-properties.js
+++ b/node_modules/espurify/lib/ast-properties.js
@@ -1,68 +1,68 @@
module.exports = {
- ArrayExpression: ['type', 'elements'],
- ArrayPattern: ['type', 'elements'],
- ArrowFunctionExpression: ['type', 'id', 'params', 'body', 'generator', 'expression', 'async'],
- AssignmentExpression: ['type', 'operator', 'left', 'right'],
- AssignmentPattern: ['type', 'left', 'right'],
- AwaitExpression: ['type', 'argument'],
- BinaryExpression: ['type', 'operator', 'left', 'right'],
- BlockStatement: ['type', 'body'],
- BreakStatement: ['type', 'label'],
- CallExpression: ['type', 'callee', 'arguments'],
- CatchClause: ['type', 'param', 'guard', 'body'],
- ClassBody: ['type', 'body'],
- ClassDeclaration: ['type', 'id', 'superClass', 'body'],
- ClassExpression: ['type', 'id', 'superClass', 'body'],
- ConditionalExpression: ['type', 'test', 'consequent', 'alternate'],
- ContinueStatement: ['type', 'label'],
- DebuggerStatement: ['type'],
- DoWhileStatement: ['type', 'body', 'test'],
- EmptyStatement: ['type'],
- ExportAllDeclaration: ['type', 'source'],
- ExportDefaultDeclaration: ['type', 'declaration'],
- ExportNamedDeclaration: ['type', 'declaration', 'specifiers', 'source'],
- ExportSpecifier: ['type', 'exported', 'local'],
- ExpressionStatement: ['type', 'expression'],
- ForInStatement: ['type', 'left', 'right', 'body'],
- ForOfStatement: ['type', 'left', 'right', 'body'],
- ForStatement: ['type', 'init', 'test', 'update', 'body'],
- FunctionDeclaration: ['type', 'id', 'params', 'body', 'generator', 'async'],
- FunctionExpression: ['type', 'id', 'params', 'body', 'generator', 'async'],
- Identifier: ['type', 'name'],
- IfStatement: ['type', 'test', 'consequent', 'alternate'],
- ImportDeclaration: ['type', 'specifiers', 'source'],
- ImportDefaultSpecifier: ['type', 'local'],
- ImportNamespaceSpecifier: ['type', 'local'],
- ImportSpecifier: ['type', 'imported', 'local'],
- LabeledStatement: ['type', 'label', 'body'],
- Literal: ['type', 'value', 'regex'],
- LogicalExpression: ['type', 'operator', 'left', 'right'],
- MemberExpression: ['type', 'object', 'property', 'computed'],
- MetaProperty: ['type', 'meta', 'property'],
- MethodDefinition: ['type', 'key', 'value', 'kind', 'computed', 'static'],
- NewExpression: ['type', 'callee', 'arguments'],
- ObjectExpression: ['type', 'properties'],
- ObjectPattern: ['type', 'properties'],
- Program: ['type', 'body', 'sourceType'],
- Property: ['type', 'key', 'value', 'kind', 'method', 'shorthand', 'computed'],
- RestElement: ['type', 'argument'],
- ReturnStatement: ['type', 'argument'],
- SequenceExpression: ['type', 'expressions'],
- SpreadElement: ['type', 'argument'],
- Super: ['type'],
- SwitchCase: ['type', 'test', 'consequent'],
- SwitchStatement: ['type', 'discriminant', 'cases', 'lexical'],
- TaggedTemplateExpression: ['type', 'tag', 'quasi'],
- TemplateElement: ['type', 'tail', 'value'],
- TemplateLiteral: ['type', 'quasis', 'expressions'],
- ThisExpression: ['type'],
- ThrowStatement: ['type', 'argument'],
- TryStatement: ['type', 'block', 'handler', 'finalizer'],
- UnaryExpression: ['type', 'operator', 'prefix', 'argument'],
- UpdateExpression: ['type', 'operator', 'argument', 'prefix'],
- VariableDeclaration: ['type', 'declarations', 'kind'],
- VariableDeclarator: ['type', 'id', 'init'],
- WhileStatement: ['type', 'test', 'body'],
- WithStatement: ['type', 'object', 'body'],
- YieldExpression: ['type', 'argument', 'delegate']
+ ArrayExpression: ['type', 'elements'],
+ ArrayPattern: ['type', 'elements'],
+ ArrowFunctionExpression: ['type', 'id', 'params', 'body', 'generator', 'expression', 'async'],
+ AssignmentExpression: ['type', 'operator', 'left', 'right'],
+ AssignmentPattern: ['type', 'left', 'right'],
+ AwaitExpression: ['type', 'argument'],
+ BinaryExpression: ['type', 'operator', 'left', 'right'],
+ BlockStatement: ['type', 'body'],
+ BreakStatement: ['type', 'label'],
+ CallExpression: ['type', 'callee', 'arguments'],
+ CatchClause: ['type', 'param', 'guard', 'body'],
+ ClassBody: ['type', 'body'],
+ ClassDeclaration: ['type', 'id', 'superClass', 'body'],
+ ClassExpression: ['type', 'id', 'superClass', 'body'],
+ ConditionalExpression: ['type', 'test', 'consequent', 'alternate'],
+ ContinueStatement: ['type', 'label'],
+ DebuggerStatement: ['type'],
+ DoWhileStatement: ['type', 'body', 'test'],
+ EmptyStatement: ['type'],
+ ExportAllDeclaration: ['type', 'source'],
+ ExportDefaultDeclaration: ['type', 'declaration'],
+ ExportNamedDeclaration: ['type', 'declaration', 'specifiers', 'source'],
+ ExportSpecifier: ['type', 'exported', 'local'],
+ ExpressionStatement: ['type', 'expression'],
+ ForInStatement: ['type', 'left', 'right', 'body'],
+ ForOfStatement: ['type', 'left', 'right', 'body', 'await'],
+ ForStatement: ['type', 'init', 'test', 'update', 'body'],
+ FunctionDeclaration: ['type', 'id', 'params', 'body', 'generator', 'async'],
+ FunctionExpression: ['type', 'id', 'params', 'body', 'generator', 'async'],
+ Identifier: ['type', 'name'],
+ IfStatement: ['type', 'test', 'consequent', 'alternate'],
+ ImportDeclaration: ['type', 'specifiers', 'source'],
+ ImportDefaultSpecifier: ['type', 'local'],
+ ImportNamespaceSpecifier: ['type', 'local'],
+ ImportSpecifier: ['type', 'imported', 'local'],
+ LabeledStatement: ['type', 'label', 'body'],
+ Literal: ['type', 'value', 'regex'],
+ LogicalExpression: ['type', 'operator', 'left', 'right'],
+ MemberExpression: ['type', 'object', 'property', 'computed'],
+ MetaProperty: ['type', 'meta', 'property'],
+ MethodDefinition: ['type', 'key', 'value', 'kind', 'computed', 'static'],
+ NewExpression: ['type', 'callee', 'arguments'],
+ ObjectExpression: ['type', 'properties'],
+ ObjectPattern: ['type', 'properties'],
+ Program: ['type', 'body', 'sourceType'],
+ Property: ['type', 'key', 'value', 'kind', 'method', 'shorthand', 'computed'],
+ RestElement: ['type', 'argument'],
+ ReturnStatement: ['type', 'argument'],
+ SequenceExpression: ['type', 'expressions'],
+ SpreadElement: ['type', 'argument'],
+ Super: ['type'],
+ SwitchCase: ['type', 'test', 'consequent'],
+ SwitchStatement: ['type', 'discriminant', 'cases', 'lexical'],
+ TaggedTemplateExpression: ['type', 'tag', 'quasi'],
+ TemplateElement: ['type', 'tail', 'value'],
+ TemplateLiteral: ['type', 'quasis', 'expressions'],
+ ThisExpression: ['type'],
+ ThrowStatement: ['type', 'argument'],
+ TryStatement: ['type', 'block', 'handler', 'finalizer'],
+ UnaryExpression: ['type', 'operator', 'prefix', 'argument'],
+ UpdateExpression: ['type', 'operator', 'argument', 'prefix'],
+ VariableDeclaration: ['type', 'declarations', 'kind'],
+ VariableDeclarator: ['type', 'id', 'init'],
+ WhileStatement: ['type', 'test', 'body'],
+ WithStatement: ['type', 'object', 'body'],
+ YieldExpression: ['type', 'argument', 'delegate']
};
diff --git a/node_modules/espurify/lib/clone-ast.js b/node_modules/espurify/lib/clone-ast.js
index f748b885d..f6804e716 100644
--- a/node_modules/espurify/lib/clone-ast.js
+++ b/node_modules/espurify/lib/clone-ast.js
@@ -3,67 +3,82 @@
var isArray = require('core-js/library/fn/array/is-array');
var objectKeys = require('core-js/library/fn/object/keys');
var indexOf = require('core-js/library/fn/array/index-of');
+var Map = require('core-js/library/fn/map');
var reduce = require('core-js/library/fn/array/reduce');
module.exports = function cloneWithWhitelist (astWhiteList) {
- var whitelist = reduce(objectKeys(astWhiteList), function (props, key) {
- var propNames = astWhiteList[key];
- var prepend = (indexOf(propNames, 'type') === -1) ? ['type'] : [];
- props[key] = prepend.concat(propNames);
- return props;
- }, {});
+ var whitelist = reduce(objectKeys(astWhiteList), function (props, key) {
+ var propNames = astWhiteList[key];
+ var prepend = (indexOf(propNames, 'type') === -1) ? ['type'] : [];
+ props[key] = prepend.concat(propNames || []);
+ return props;
+ }, {});
- function cloneNodeOrObject (obj) {
- var props = obj.type ? whitelist[obj.type] : null;
- if (props) {
- return cloneNode(obj, props);
- } else {
- return cloneObject(obj);
- }
+ function cloneNodeOrObject (obj, seen) {
+ var props = obj.type ? whitelist[obj.type] : null;
+ if (props) {
+ return cloneNode(obj, props, seen);
+ } else {
+ return cloneObject(obj, seen);
}
+ }
- function cloneArray (ary) {
- var i = ary.length, clone = [];
- while (i--) {
- clone[i] = cloneOf(ary[i]);
- }
- return clone;
+ function cloneArray (ary, seen) {
+ var i = ary.length;
+ var clone = [];
+ while (i--) {
+ clone[i] = cloneOf(ary[i], seen);
}
+ return clone;
+ }
- function cloneNode (node, props) {
- var i, len, key, clone = {};
- for (i = 0, len = props.length; i < len; i += 1) {
- key = props[i];
- if (node.hasOwnProperty(key)) {
- clone[key] = cloneOf(node[key]);
- }
- }
- return clone;
+ function cloneNode (node, props, seen) {
+ var i, len, key;
+ var clone = {};
+ for (i = 0, len = props.length; i < len; i += 1) {
+ key = props[i];
+ if (node.hasOwnProperty(key)) {
+ clone[key] = cloneOf(node[key], seen);
+ }
}
+ return clone;
+ }
- function cloneObject (obj) {
- var props = objectKeys(obj);
- var i, len, key, clone = {};
- for (i = 0, len = props.length; i < len; i += 1) {
- key = props[i];
- clone[key] = cloneOf(obj[key]);
- }
- return clone;
+ function cloneObject (obj, seen) {
+ var props = objectKeys(obj);
+ var i, len, key, value;
+ var clone = {};
+ for (i = 0, len = props.length; i < len; i += 1) {
+ key = props[i];
+ value = obj[key];
+ if (seen.has(value)) {
+ continue;
+ }
+ clone[key] = cloneOf(value, seen);
}
+ return clone;
+ }
- function cloneOf (val) {
- if (typeof val === 'object' && val !== null) {
- if (val instanceof RegExp) {
- return new RegExp(val);
- } else if (isArray(val)) {
- return cloneArray(val);
- } else {
- return cloneNodeOrObject(val);
- }
- } else {
- return val;
- }
+ function cloneOf (val, seen) {
+ if (typeof val === 'object' && val !== null) {
+ seen.set(val, true);
+ if (val instanceof RegExp) {
+ return new RegExp(val);
+ } else if (isArray(val)) {
+ return cloneArray(val, seen);
+ } else {
+ return cloneNodeOrObject(val, seen);
+ }
+ } else {
+ return val;
}
+ }
- return cloneNodeOrObject;
+ function cloneRoot (obj) {
+ var seen = new Map();
+ seen.set(obj, true);
+ return cloneNodeOrObject(obj, seen);
+ }
+
+ return cloneRoot;
};
diff --git a/node_modules/espurify/lib/create-whitelist.js b/node_modules/espurify/lib/create-whitelist.js
index b1dbc16a0..84e25997a 100644
--- a/node_modules/espurify/lib/create-whitelist.js
+++ b/node_modules/espurify/lib/create-whitelist.js
@@ -5,13 +5,13 @@ var objectKeys = require('core-js/library/fn/object/keys');
var assign = require('core-js/library/fn/object/assign');
module.exports = function createWhitelist (options) {
- var opts = assign({}, options);
- var typeName, i, len;
- var keys = objectKeys(defaultProps);
- var result = {};
- for (i = 0, len = keys.length; i < len; i += 1) {
- typeName = keys[i];
- result[typeName] = defaultProps[typeName].concat(opts.extra);
- }
- return result;
+ var opts = assign({}, options);
+ var typeName, i, len;
+ var keys = objectKeys(defaultProps);
+ var result = {};
+ for (i = 0, len = keys.length; i < len; i += 1) {
+ typeName = keys[i];
+ result[typeName] = defaultProps[typeName].concat(opts.extra || []);
+ }
+ return result;
};