Replace generic __clone call by specific methods (#13611)

* update benchmark babel parser version

* perf: replace generic __clone by specific methods

baseline 256 length-1 named export: 4_704 ops/sec ±1.59% (0.213ms)
baseline 512 length-1 named export: 2_426 ops/sec ±0.52% (0.412ms)
baseline 1024 length-1 named export: 1_118 ops/sec ±1.23% (0.895ms)
baseline 2048 length-1 named export: 556 ops/sec ±0.77% (1.799ms)
current 256 length-1 named export: 7_073 ops/sec ±33.67% (0.141ms)
current 512 length-1 named export: 4_441 ops/sec ±0.79% (0.225ms)
current 1024 length-1 named export: 2_142 ops/sec ±1.09% (0.467ms)
current 2048 length-1 named export: 943 ops/sec ±2.12% (1.06ms)

* breaking: remove Node#__clone in Babel 8

* test: use t.cloneNode
This commit is contained in:
Huáng Jùnliàng
2021-07-30 16:19:35 -04:00
committed by GitHub
parent 2340b87094
commit d3a7cd5e8d
8 changed files with 72 additions and 20 deletions

View File

@@ -25,6 +25,7 @@ import {
} from "../../util/scopeflags";
import type { ExpressionErrors } from "../../parser/util";
import { Errors, makeErrorTemplates, ErrorCodes } from "../../parser/error";
import { cloneIdentifier } from "../../parser/node";
const reservedTypes = new Set([
"_",
@@ -2655,7 +2656,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
// `import {type as ,` or `import {type as }`
specifier.imported = as_ident;
specifier.importKind = specifierTypeKind;
specifier.local = as_ident.__clone();
specifier.local = cloneIdentifier(as_ident);
} else {
// `import {type as foo`
specifier.imported = firstIdent;
@@ -2673,7 +2674,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
specifier.local = this.parseIdentifier();
} else {
isBinding = true;
specifier.local = specifier.imported.__clone();
specifier.local = cloneIdentifier(specifier.imported);
}
} else {
if (firstIdentIsString) {
@@ -2688,7 +2689,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
isBinding = true;
specifier.imported = firstIdent;
specifier.importKind = null;
specifier.local = specifier.imported.__clone();
specifier.local = cloneIdentifier(specifier.imported);
}
const nodeIsTypeImport = hasTypeImportKind(node);