Mark wrapNativeSuper and wrapRegExp as pure (#11134)
This commit is contained in:
parent
a583eab41f
commit
4b045819b8
@ -18,6 +18,7 @@
|
|||||||
"babel-plugin"
|
"babel-plugin"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@babel/helper-annotate-as-pure": "^7.8.3",
|
||||||
"@babel/helper-regex": "^7.8.3",
|
"@babel/helper-regex": "^7.8.3",
|
||||||
"regexpu-core": "^4.6.0"
|
"regexpu-core": "^4.6.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import { generateRegexpuOptions } from "./util";
|
|||||||
import pkg from "../package.json";
|
import pkg from "../package.json";
|
||||||
import { types as t } from "@babel/core";
|
import { types as t } from "@babel/core";
|
||||||
import { pullFlag } from "@babel/helper-regex";
|
import { pullFlag } from "@babel/helper-regex";
|
||||||
|
import annotateAsPure from "@babel/helper-annotate-as-pure";
|
||||||
|
|
||||||
// Note: Versions are represented as an integer. e.g. 7.1.5 is represented
|
// Note: Versions are represented as an integer. e.g. 7.1.5 is represented
|
||||||
// as 70000100005. This method is easier than using a semver-parsing
|
// as 70000100005. This method is easier than using a semver-parsing
|
||||||
@ -68,12 +69,13 @@ export function createRegExpFeaturePlugin({ name, feature, options = {} }) {
|
|||||||
runtime &&
|
runtime &&
|
||||||
!isRegExpTest(path)
|
!isRegExpTest(path)
|
||||||
) {
|
) {
|
||||||
path.replaceWith(
|
const call = t.callExpression(this.addHelper("wrapRegExp"), [
|
||||||
t.callExpression(this.addHelper("wrapRegExp"), [
|
|
||||||
node,
|
node,
|
||||||
t.valueToNode(namedCaptureGroups),
|
t.valueToNode(namedCaptureGroups),
|
||||||
]),
|
]);
|
||||||
);
|
annotateAsPure(call);
|
||||||
|
|
||||||
|
path.replaceWith(call);
|
||||||
}
|
}
|
||||||
if (hasFeature(features, FEATURES.unicodeFlag)) {
|
if (hasFeature(features, FEATURES.unicodeFlag)) {
|
||||||
pullFlag(node, "u");
|
pullFlag(node, "u");
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import ReplaceSupers, {
|
|||||||
import optimiseCall from "@babel/helper-optimise-call-expression";
|
import optimiseCall from "@babel/helper-optimise-call-expression";
|
||||||
import * as defineMap from "@babel/helper-define-map";
|
import * as defineMap from "@babel/helper-define-map";
|
||||||
import { traverse, template, types as t } from "@babel/core";
|
import { traverse, template, types as t } from "@babel/core";
|
||||||
|
import annotateAsPure from "@babel/helper-annotate-as-pure";
|
||||||
|
|
||||||
type ReadonlySet<T> = Set<T> | { has(val: T): boolean };
|
type ReadonlySet<T> = Set<T> | { has(val: T): boolean };
|
||||||
|
|
||||||
@ -565,11 +566,14 @@ export default function transformClass(
|
|||||||
const closureArgs = [];
|
const closureArgs = [];
|
||||||
|
|
||||||
if (classState.isDerived) {
|
if (classState.isDerived) {
|
||||||
const arg = classState.extendsNative
|
let arg = t.cloneNode(superName);
|
||||||
? t.callExpression(classState.file.addHelper("wrapNativeSuper"), [
|
if (classState.extendsNative) {
|
||||||
t.cloneNode(superName),
|
arg = t.callExpression(classState.file.addHelper("wrapNativeSuper"), [
|
||||||
])
|
arg,
|
||||||
: t.cloneNode(superName);
|
]);
|
||||||
|
annotateAsPure(arg);
|
||||||
|
}
|
||||||
|
|
||||||
const param = classState.scope.generateUidIdentifierBasedOnNode(
|
const param = classState.scope.generateUidIdentifierBasedOnNode(
|
||||||
superName,
|
superName,
|
||||||
);
|
);
|
||||||
|
|||||||
@ -22,4 +22,4 @@ var List = /*#__PURE__*/function (_Array) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return List;
|
return List;
|
||||||
}(_wrapNativeSuper(Array));
|
}( /*#__PURE__*/_wrapNativeSuper(Array));
|
||||||
|
|||||||
@ -30,4 +30,4 @@ var List = /*#__PURE__*/function (_Array) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return List;
|
return List;
|
||||||
}(_wrapNativeSuper(Array));
|
}( /*#__PURE__*/_wrapNativeSuper(Array));
|
||||||
|
|||||||
@ -20,7 +20,7 @@ var CustomElement = /*#__PURE__*/function (_HTMLElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return CustomElement;
|
return CustomElement;
|
||||||
}(babelHelpers.wrapNativeSuper(HTMLElement));
|
}( /*#__PURE__*/babelHelpers.wrapNativeSuper(HTMLElement));
|
||||||
|
|
||||||
;
|
;
|
||||||
new CustomElement();
|
new CustomElement();
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
"foo".match(babelHelpers.wrapRegExp(/(.)\1/, {
|
"foo".match( /*#__PURE__*/babelHelpers.wrapRegExp(/(.)\1/, {
|
||||||
double: 1
|
double: 1
|
||||||
}));
|
}));
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
"abba".match(babelHelpers.wrapRegExp(/(.)(.)\2\1/, {
|
"abba".match( /*#__PURE__*/babelHelpers.wrapRegExp(/(.)(.)\2\1/, {
|
||||||
n: 2
|
n: 2
|
||||||
}));
|
}));
|
||||||
|
|||||||
@ -32,6 +32,6 @@ var MyDate = /*#__PURE__*/function (_Date) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return MyDate;
|
return MyDate;
|
||||||
}(_wrapNativeSuper(Date));
|
}( /*#__PURE__*/_wrapNativeSuper(Date));
|
||||||
|
|
||||||
var myDate = new MyDate();
|
var myDate = new MyDate();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user