@babel/helper-transform-fixture-test-runner
Advanced tools
Comparing version 7.0.0-beta.38 to 7.0.0-beta.39
112
lib/index.js
@@ -130,2 +130,112 @@ "use strict"; | ||
function checkDuplicatedNodes(ast) { | ||
var nodes = new WeakSet(); | ||
var parents = new WeakMap(); | ||
var setParent = function setParent(child, parent) { | ||
if (typeof child === "object" && child !== null) { | ||
var p = parents.get(child); | ||
if (!p) { | ||
p = []; | ||
parents.set(child, p); | ||
} | ||
p.unshift(parent); | ||
} | ||
}; | ||
var registerChildren = function registerChildren(node) { | ||
for (var key in node) { | ||
if (Array.isArray(node[key])) { | ||
node[key].forEach(function (child) { | ||
return setParent(child, node); | ||
}); | ||
} else { | ||
setParent(node[key], node); | ||
} | ||
} | ||
}; | ||
var parentIs = function parentIs(node, test) { | ||
return (parents.get(node) || []).some(function (parent) { | ||
return test(parent); | ||
}); | ||
}; | ||
var isByRegenerator = function isByRegenerator(node) { | ||
if (!node) { | ||
return false; | ||
} else if (node.type === "Identifier") { | ||
if (/^_(?:context|value|callee|marked)\d*$/.test(node.name)) { | ||
return true; | ||
} else if (/^t\d+$/.test(node.name) && parentIs(node, function (parent) { | ||
return parent.type === "MemberExpression" && isByRegenerator(parent.object); | ||
})) { | ||
return true; | ||
} else if (parentIs(node, function (parent) { | ||
return parent.type === "VariableDeclarator" && parentIs(parent, function (parent) { | ||
return parent.type === "VariableDeclaration" && parentIs(parent, function (parent) { | ||
return parent.type === "BlockStatement" && parentIs(parent, function (parent) { | ||
return parent.type === "FunctionExpression" && isByRegenerator(parent.id); | ||
}); | ||
}); | ||
}); | ||
})) { | ||
return true; | ||
} else if (parentIs(node, function (parent) { | ||
return parent.type === "VariableDeclarator" && parentIs(parent, function (parent) { | ||
return parent.type === "VariableDeclaration" && parentIs(parent, function (parent) { | ||
return parent.type === "BlockStatement" && parent.body.length === 2 && parent.body[1].type === "ReturnStatement" && parent.body[1].argument.type === "CallExpression" && parent.body[1].argument.callee.type === "MemberExpression" && parent.body[1].argument.callee.property.type === "Identifier" && parent.body[1].argument.callee.property.name === "wrap"; | ||
}); | ||
}); | ||
})) { | ||
return true; | ||
} else if (parentIs(node, function (parent) { | ||
return parent.type === "CallExpression" && parent.arguments.length === 3 && parent.arguments[1] === node && parent.callee.type === "MemberExpression" && parent.callee.property.type === "Identifier" && parent.callee.property.name === "wrap"; | ||
})) { | ||
return true; | ||
} else if (parentIs(node, function (parent) { | ||
return parent.type === "CallExpression" && parent.callee.type === "MemberExpression" && parent.callee.property.type === "Identifier" && parent.callee.property.name === "mark"; | ||
})) { | ||
return true; | ||
} | ||
} else if (node.type === "MemberExpression") { | ||
return isByRegenerator(node.object); | ||
} else if (node.type === "CallExpression") { | ||
return isByRegenerator(node.callee); | ||
} else if (node.type === "AssignmentExpression") { | ||
return isByRegenerator(node.left); | ||
} else if (node.type === "NumericLiteral") { | ||
if (parentIs(node, function (parent) { | ||
return parent.type === "AssignmentExpression" && isByRegenerator(parent.left); | ||
})) { | ||
return true; | ||
} else if (parentIs(node, function (parent) { | ||
return parent.type === "CallExpression" && parent.callee.type === "MemberExpression" && isByRegenerator(parent.callee.object); | ||
})) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
var hidePrivateProperties = function hidePrivateProperties(key, val) { | ||
if (key[0] === "_") return "[Private]"; | ||
return val; | ||
}; | ||
babel.types.traverseFast(ast, function (node) { | ||
registerChildren(node); | ||
if (isByRegenerator(node)) return; | ||
if (nodes.has(node)) { | ||
throw new Error("Do not reuse nodes. Use `t.cloneNode` to copy them.\n" + JSON.stringify(node, hidePrivateProperties, 2) + "\nParent:\n" + JSON.stringify(parents.get(node), hidePrivateProperties, 2)); | ||
} | ||
nodes.add(node); | ||
}); | ||
} | ||
function run(task) { | ||
@@ -160,2 +270,3 @@ var actual = task.actual; | ||
result = babel.transform(execCode, execOpts); | ||
checkDuplicatedNodes(result.ast); | ||
execCode = result.code; | ||
@@ -176,2 +287,3 @@ | ||
result = babel.transform(actualCode, getOpts(actual)); | ||
checkDuplicatedNodes(result.ast); | ||
@@ -178,0 +290,0 @@ if (!expect.code && result.code && !opts.throws && _fs.default.statSync(_path.default.dirname(expect.loc)).isDirectory() && !process.env.CI) { |
{ | ||
"name": "@babel/helper-transform-fixture-test-runner", | ||
"version": "7.0.0-beta.38", | ||
"version": "7.0.0-beta.39", | ||
"description": "Transform test runner for @babel/helper-fixtures module", | ||
@@ -11,6 +11,6 @@ "author": "Sebastian McKenzie <sebmck@gmail.com>", | ||
"dependencies": { | ||
"@babel/code-frame": "7.0.0-beta.38", | ||
"@babel/core": "7.0.0-beta.38", | ||
"@babel/helper-fixtures": "7.0.0-beta.38", | ||
"@babel/polyfill": "7.0.0-beta.38", | ||
"@babel/code-frame": "7.0.0-beta.39", | ||
"@babel/core": "7.0.0-beta.39", | ||
"@babel/helper-fixtures": "7.0.0-beta.39", | ||
"@babel/polyfill": "7.0.0-beta.39", | ||
"chai": "^4.1.0", | ||
@@ -17,0 +17,0 @@ "lodash": "^4.2.0", |
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
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
15228
350
+ Added@babel/code-frame@7.0.0-beta.39(transitive)
+ Added@babel/core@7.0.0-beta.39(transitive)
+ Added@babel/generator@7.0.0-beta.39(transitive)
+ Added@babel/helper-fixtures@7.0.0-beta.39(transitive)
+ Added@babel/helper-function-name@7.0.0-beta.39(transitive)
+ Added@babel/helper-get-function-arity@7.0.0-beta.39(transitive)
+ Added@babel/helpers@7.0.0-beta.39(transitive)
+ Added@babel/polyfill@7.0.0-beta.39(transitive)
+ Added@babel/template@7.0.0-beta.39(transitive)
+ Added@babel/traverse@7.0.0-beta.39(transitive)
+ Added@babel/types@7.0.0-beta.39(transitive)
+ Addedbabylon@7.0.0-beta.39(transitive)
- Removed@babel/code-frame@7.0.0-beta.38(transitive)
- Removed@babel/core@7.0.0-beta.38(transitive)
- Removed@babel/generator@7.0.0-beta.38(transitive)
- Removed@babel/helper-fixtures@7.0.0-beta.38(transitive)
- Removed@babel/helper-function-name@7.0.0-beta.38(transitive)
- Removed@babel/helper-get-function-arity@7.0.0-beta.38(transitive)
- Removed@babel/helpers@7.0.0-beta.38(transitive)
- Removed@babel/polyfill@7.0.0-beta.38(transitive)
- Removed@babel/template@7.0.0-beta.38(transitive)
- Removed@babel/traverse@7.0.0-beta.38(transitive)
- Removed@babel/types@7.0.0-beta.38(transitive)
- Removedbabylon@7.0.0-beta.38(transitive)
Updated@babel/core@7.0.0-beta.39