Add support for extending builtins (#7020)

This commit is contained in:
Nicolò Ribaudo
2017-12-20 20:46:00 +01:00
committed by Henry Zhu
parent 148fe7d3ff
commit 0c885b3200
22 changed files with 244 additions and 7 deletions

View File

@@ -3,6 +3,15 @@ import VanillaTransformer from "./vanilla";
import annotateAsPure from "@babel/helper-annotate-as-pure";
import nameFunction from "@babel/helper-function-name";
import { types as t } from "@babel/core";
import globals from "globals";
const getBuiltinClasses = category =>
Object.keys(globals[category]).filter(name => /^[A-Z]/.test(name));
const builtinClasses = new Set([
...getBuiltinClasses("builtin"),
...getBuiltinClasses("browser"),
]);
export default function(api, options) {
const { loose } = options;
@@ -54,7 +63,9 @@ export default function(api, options) {
node[VISITED] = true;
path.replaceWith(new Constructor(path, state.file).run());
path.replaceWith(
new Constructor(path, state.file, builtinClasses).run(),
);
if (path.isCallExpression()) {
annotateAsPure(path);