Add support for extending builtins (#7020)
This commit is contained in:
committed by
Henry Zhu
parent
148fe7d3ff
commit
0c885b3200
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user