@babel/helper-define-polyfill-provider
Advanced tools
Comparing version
@@ -26,4 +26,16 @@ "use strict"; | ||
} | ||
function getType(target) { | ||
return Object.prototype.toString.call(target).slice(8, -1); | ||
function resolve(path, resolved = new Set()) { | ||
if (resolved.has(path)) return; | ||
resolved.add(path); | ||
if (path.isVariableDeclarator()) { | ||
if (path.get("id").isIdentifier()) { | ||
return resolve(path.get("init"), resolved); | ||
} | ||
} else if (path.isReferencedIdentifier()) { | ||
const binding = path.scope.getBinding(path.node.name); | ||
if (!binding) return path; | ||
if (!binding.constant) return; | ||
return resolve(binding.path, resolved); | ||
} | ||
return path; | ||
} | ||
@@ -34,9 +46,5 @@ function resolveId(path) { | ||
} | ||
if (path.isPure()) { | ||
const { | ||
deopt | ||
} = path.evaluate(); | ||
if (deopt && deopt.isIdentifier()) { | ||
return deopt.node.name; | ||
} | ||
const resolved = resolve(path); | ||
if (resolved != null && resolved.isIdentifier()) { | ||
return resolved.node.name; | ||
} | ||
@@ -89,22 +97,39 @@ } | ||
} | ||
if (obj.isRegExpLiteral()) { | ||
return { | ||
id: "RegExp", | ||
placement: "prototype" | ||
}; | ||
} else if (obj.isFunction()) { | ||
return { | ||
id: "Function", | ||
placement: "prototype" | ||
}; | ||
} else if (obj.isPure()) { | ||
const { | ||
value | ||
} = obj.evaluate(); | ||
if (value !== undefined) { | ||
const path = resolve(obj); | ||
switch (path == null ? void 0 : path.type) { | ||
case "RegExpLiteral": | ||
return { | ||
id: getType(value), | ||
id: "RegExp", | ||
placement: "prototype" | ||
}; | ||
} | ||
case "FunctionExpression": | ||
return { | ||
id: "Function", | ||
placement: "prototype" | ||
}; | ||
case "StringLiteral": | ||
return { | ||
id: "String", | ||
placement: "prototype" | ||
}; | ||
case "NumberLiteral": | ||
return { | ||
id: "Number", | ||
placement: "prototype" | ||
}; | ||
case "BooleanLiteral": | ||
return { | ||
id: "Boolean", | ||
placement: "prototype" | ||
}; | ||
case "ObjectExpression": | ||
return { | ||
id: "Object", | ||
placement: "prototype" | ||
}; | ||
case "ArrayExpression": | ||
return { | ||
id: "Array", | ||
placement: "prototype" | ||
}; | ||
} | ||
@@ -111,0 +136,0 @@ return { |
{ | ||
"name": "@babel/helper-define-polyfill-provider", | ||
"version": "0.6.3", | ||
"version": "0.6.4", | ||
"description": "Babel helper to create your own polyfill provider", | ||
@@ -58,3 +58,3 @@ "repository": { | ||
}, | ||
"gitHead": "66340fb145086a826c496f008f67488367846c09" | ||
"gitHead": "d87c29c909148920ad18690b63d450c561842298" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
226587
2.27%2645
2.92%