Skip to content

Commit

Permalink
refactor(es): Remove settings related to privateInObject (#6468)
Browse files Browse the repository at this point in the history
  • Loading branch information
Austaras authored Nov 20, 2022
1 parent 40ad709 commit c57307d
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 34 deletions.
2 changes: 0 additions & 2 deletions crates/swc/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use swc_ecma_minifier::option::{terser::TerserTopLevelOptions, MinifyOptions};
use swc_ecma_parser::Syntax;
use swc_ecma_transforms::{
compat,
compat::es2022::private_in_object,
feature::{enable_available_feature_from_es_version, FeatureFlag},
fixer::{fixer, paren_remover},
helpers, hygiene,
Expand Down Expand Up @@ -330,7 +329,6 @@ impl<'a, 'b, P: swc_ecma_visit::Fold> PassBuilder<'a, 'b, P> {
paren_remover(comments.map(|v| v as &dyn Comments)),
self.fixer
),
Optional::new(private_in_object(), syntax.private_in_object()),
compat_pass,
// module / helper
Optional::new(
Expand Down
1 change: 0 additions & 1 deletion crates/swc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,6 @@ impl Compiler {
decorators: true,
decorators_before_export: true,
import_assertions: true,
private_in_object: true,
..Default::default()
}),
IsModule::Bool(true),
Expand Down
12 changes: 12 additions & 0 deletions crates/swc/tests/fixture/issues-6xxx/6373/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"jsc": {
"parser": {
"syntax": "ecmascript"
},
"target": "es5"
},
"module": {
"type": "es6"
},
"isModule": true
}
1 change: 1 addition & 0 deletions crates/swc/tests/fixture/issues-6xxx/6373/input/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class x { static #y = #y in x ; }
9 changes: 9 additions & 0 deletions crates/swc/tests/fixture/issues-6xxx/6373/output/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
var x = function x() {
"use strict";
_class_call_check(this, x);
};
var _y = {
writable: true,
value: x === x
};
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
//// [privateNameInInExpressionUnused.ts]
var _brand_check_brand = new WeakSet();
class Foo {
#unused;
#brand = void _brand_check_brand.add(this);
#brand;
isFoo(v) {
// This should count as using/reading '#brand'
return _brand_check_brand.has(v);
return #brand in v;
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
//// [privateNameInInExpressionUnused.ts]
new WeakSet();
12 changes: 0 additions & 12 deletions crates/swc_ecma_parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,6 @@ impl Syntax {
}
}

pub fn private_in_object(self) -> bool {
match self {
Syntax::Es(EsConfig {
private_in_object, ..
}) => private_in_object,
Syntax::Typescript(_) => true,
}
}

pub(crate) fn allow_super_outside_method(self) -> bool {
match self {
Syntax::Es(EsConfig {
Expand Down Expand Up @@ -321,9 +312,6 @@ pub struct EsConfig {
#[serde(default)]
pub import_assertions: bool,

#[serde(default, rename = "privateInObject")]
pub private_in_object: bool,

#[serde(default, rename = "allowSuperOutsideMethod")]
pub allow_super_outside_method: bool,

Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_parser/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ impl<I: Tokens> Parser<I> {
}
}

if self.input.syntax().private_in_object() && eat!(self, '#') {
if eat!(self, '#') {
let id = self.parse_ident_name()?;
return Ok(Box::new(Expr::PrivateName(PrivateName {
span: span!(self, start),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

x Unexpected token `#`. Expected this, import, async, function, [ for array literal, { for object literal, @ for decorator, function, class, null, true, false, number, bigint, string, regexp, `
| for template literal, (, or an identifier
x Expected ident
,-[$DIR/tests/test262-parser/fail/c3731145e0e65d1d.js:1:1]
1 | #=
: ^
: ^
`----
6 changes: 1 addition & 5 deletions crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::{fs::read_to_string, path::PathBuf};

use serde::Deserialize;
use swc_common::{chain, Mark};
use swc_ecma_parser::{EsConfig, Syntax};
use swc_ecma_transforms_base::pass::noop;
use swc_ecma_transforms_compat::{
es2015::{arrow, classes, new_target::new_target},
Expand Down Expand Up @@ -96,10 +95,7 @@ fn fixture(input: PathBuf) {

let output = input.parent().unwrap().join("output.js");
test_fixture(
Syntax::Es(EsConfig {
private_in_object: true,
..Default::default()
}),
Default::default(),
&|t| get_passes(t, &options.plugins),
&input,
&output,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::path::PathBuf;

use serde::Deserialize;
use swc_common::chain;
use swc_ecma_parser::{EsConfig, Syntax};
use swc_ecma_transforms_base::pass::noop;
use swc_ecma_transforms_compat::{
es2015::classes,
Expand Down Expand Up @@ -32,10 +31,7 @@ fn fixture(input: PathBuf) {

let output = parent.join("output.js");
test_fixture(
Syntax::Es(EsConfig {
private_in_object: true,
..Default::default()
}),
Default::default(),
&|t| {
let mut pass: Box<dyn Fold> = Box::new(noop());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ fn identity(entry: PathBuf) {
decorators: true,
decorators_before_export: true,
export_default_from: true,
private_in_object: true,
import_assertions: true,
allow_super_outside_method: true,
..Default::default()
Expand Down

1 comment on commit c57307d

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: c57307d Previous: 08a9e21 Ratio
es/full/bugs-1 374285 ns/iter (± 24614) 343924 ns/iter (± 22485) 1.09
es/full/minify/libraries/antd 2009259990 ns/iter (± 40646178) 1843749333 ns/iter (± 35421072) 1.09
es/full/minify/libraries/d3 430972970 ns/iter (± 12555504) 387498447 ns/iter (± 5737899) 1.11
es/full/minify/libraries/echarts 1662554773 ns/iter (± 23161288) 1572904733 ns/iter (± 20004804) 1.06
es/full/minify/libraries/jquery 106754203 ns/iter (± 4099451) 98456298 ns/iter (± 1250161) 1.08
es/full/minify/libraries/lodash 137363179 ns/iter (± 8907230) 118166720 ns/iter (± 2299627) 1.16
es/full/minify/libraries/moment 67505846 ns/iter (± 2041159) 59148603 ns/iter (± 1227695) 1.14
es/full/minify/libraries/react 22600132 ns/iter (± 1324463) 19805763 ns/iter (± 491219) 1.14
es/full/minify/libraries/terser 353253471 ns/iter (± 7715785) 294796142 ns/iter (± 8290835) 1.20
es/full/minify/libraries/three 616425752 ns/iter (± 10261402) 565727456 ns/iter (± 7292018) 1.09
es/full/minify/libraries/typescript 3714122264 ns/iter (± 86495381) 3371443301 ns/iter (± 25883126) 1.10
es/full/minify/libraries/victory 875264815 ns/iter (± 25279076) 813563327 ns/iter (± 9071427) 1.08
es/full/minify/libraries/vue 168591942 ns/iter (± 4272102) 149708038 ns/iter (± 2072901) 1.13
es/full/codegen/es3 35041 ns/iter (± 2859) 32100 ns/iter (± 588) 1.09
es/full/codegen/es5 34826 ns/iter (± 1843) 32174 ns/iter (± 943) 1.08
es/full/codegen/es2015 34510 ns/iter (± 1941) 32209 ns/iter (± 599) 1.07
es/full/codegen/es2016 34866 ns/iter (± 3230) 32185 ns/iter (± 691) 1.08
es/full/codegen/es2017 35244 ns/iter (± 3399) 32113 ns/iter (± 1559) 1.10
es/full/codegen/es2018 34830 ns/iter (± 3021) 32131 ns/iter (± 932) 1.08
es/full/codegen/es2019 34946 ns/iter (± 6448) 32293 ns/iter (± 1393) 1.08
es/full/codegen/es2020 35269 ns/iter (± 1905) 32442 ns/iter (± 1290) 1.09
es/full/all/es3 206383691 ns/iter (± 12014761) 186157363 ns/iter (± 4084748) 1.11
es/full/all/es5 192097152 ns/iter (± 7633575) 176933693 ns/iter (± 3280462) 1.09
es/full/all/es2015 156620071 ns/iter (± 10149761) 141729882 ns/iter (± 9827151) 1.11
es/full/all/es2016 155846925 ns/iter (± 10365733) 140943158 ns/iter (± 2932572) 1.11
es/full/all/es2017 156069905 ns/iter (± 10071350) 140890007 ns/iter (± 7364971) 1.11
es/full/all/es2018 152076254 ns/iter (± 10577652) 140345275 ns/iter (± 8031443) 1.08
es/full/all/es2019 150651751 ns/iter (± 12613714) 138207241 ns/iter (± 4187062) 1.09
es/full/all/es2020 147469465 ns/iter (± 11532949) 132581196 ns/iter (± 2728081) 1.11
es/full/parser 754708 ns/iter (± 50669) 693874 ns/iter (± 30441) 1.09
es/full/base/fixer 28089 ns/iter (± 3589) 25086 ns/iter (± 896) 1.12
es/full/base/resolver_and_hygiene 95214 ns/iter (± 9003) 88295 ns/iter (± 6324) 1.08
serialization of ast node 232 ns/iter (± 37) 212 ns/iter (± 9) 1.09
serialization of serde 228 ns/iter (± 24) 217 ns/iter (± 7) 1.05

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.