From c57307d0029e9e52dc41411c4c727da221cdfadb Mon Sep 17 00:00:00 2001 From: Austaras Date: Mon, 21 Nov 2022 07:34:20 +0800 Subject: [PATCH] refactor(es): Remove settings related to `privateInObject` (#6468) --- crates/swc/src/builder.rs | 2 -- crates/swc/src/lib.rs | 1 - .../swc/tests/fixture/issues-6xxx/6373/input/.swcrc | 12 ++++++++++++ .../tests/fixture/issues-6xxx/6373/input/input.js | 1 + .../tests/fixture/issues-6xxx/6373/output/input.js | 9 +++++++++ .../privateNameInInExpressionUnused.1.normal.js | 5 ++--- .../privateNameInInExpressionUnused.2.minified.js | 1 - crates/swc_ecma_parser/src/lib.rs | 12 ------------ crates/swc_ecma_parser/src/parser/expr.rs | 2 +- .../fail/c3731145e0e65d1d.js.stderr | 5 ++--- .../tests/es2015_new_target.rs | 6 +----- .../tests/es2022_private_in_object.rs | 6 +----- .../tests/strip_correctness.rs | 1 - 13 files changed, 29 insertions(+), 34 deletions(-) create mode 100644 crates/swc/tests/fixture/issues-6xxx/6373/input/.swcrc create mode 100644 crates/swc/tests/fixture/issues-6xxx/6373/input/input.js create mode 100644 crates/swc/tests/fixture/issues-6xxx/6373/output/input.js diff --git a/crates/swc/src/builder.rs b/crates/swc/src/builder.rs index d90e954ebb0f..2c0780bf6715 100644 --- a/crates/swc/src/builder.rs +++ b/crates/swc/src/builder.rs @@ -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, @@ -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( diff --git a/crates/swc/src/lib.rs b/crates/swc/src/lib.rs index 91f72096a3e0..d932c2957439 100644 --- a/crates/swc/src/lib.rs +++ b/crates/swc/src/lib.rs @@ -1009,7 +1009,6 @@ impl Compiler { decorators: true, decorators_before_export: true, import_assertions: true, - private_in_object: true, ..Default::default() }), IsModule::Bool(true), diff --git a/crates/swc/tests/fixture/issues-6xxx/6373/input/.swcrc b/crates/swc/tests/fixture/issues-6xxx/6373/input/.swcrc new file mode 100644 index 000000000000..129a48e782db --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6373/input/.swcrc @@ -0,0 +1,12 @@ +{ + "jsc": { + "parser": { + "syntax": "ecmascript" + }, + "target": "es5" + }, + "module": { + "type": "es6" + }, + "isModule": true +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-6xxx/6373/input/input.js b/crates/swc/tests/fixture/issues-6xxx/6373/input/input.js new file mode 100644 index 000000000000..949565dcd49b --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6373/input/input.js @@ -0,0 +1 @@ +class x { static #y = #y in x ; } \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-6xxx/6373/output/input.js b/crates/swc/tests/fixture/issues-6xxx/6373/output/input.js new file mode 100644 index 000000000000..e59f2a3523e7 --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6373/output/input.js @@ -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 +}; diff --git a/crates/swc/tests/tsc-references/privateNameInInExpressionUnused.1.normal.js b/crates/swc/tests/tsc-references/privateNameInInExpressionUnused.1.normal.js index b070e32e71cf..54cebaf32e76 100644 --- a/crates/swc/tests/tsc-references/privateNameInInExpressionUnused.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameInInExpressionUnused.1.normal.js @@ -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; } } diff --git a/crates/swc/tests/tsc-references/privateNameInInExpressionUnused.2.minified.js b/crates/swc/tests/tsc-references/privateNameInInExpressionUnused.2.minified.js index 2cbd89df2d27..62c9d362c257 100644 --- a/crates/swc/tests/tsc-references/privateNameInInExpressionUnused.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameInInExpressionUnused.2.minified.js @@ -1,2 +1 @@ //// [privateNameInInExpressionUnused.ts] -new WeakSet(); diff --git a/crates/swc_ecma_parser/src/lib.rs b/crates/swc_ecma_parser/src/lib.rs index adf1428d929f..9fd15e210fe8 100644 --- a/crates/swc_ecma_parser/src/lib.rs +++ b/crates/swc_ecma_parser/src/lib.rs @@ -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 { @@ -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, diff --git a/crates/swc_ecma_parser/src/parser/expr.rs b/crates/swc_ecma_parser/src/parser/expr.rs index 3f73a9a70a66..6ab37876681d 100644 --- a/crates/swc_ecma_parser/src/parser/expr.rs +++ b/crates/swc_ecma_parser/src/parser/expr.rs @@ -487,7 +487,7 @@ impl Parser { } } - 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), diff --git a/crates/swc_ecma_parser/tests/test262-error-references/fail/c3731145e0e65d1d.js.stderr b/crates/swc_ecma_parser/tests/test262-error-references/fail/c3731145e0e65d1d.js.stderr index 834ca3cda87b..03085de60270 100644 --- a/crates/swc_ecma_parser/tests/test262-error-references/fail/c3731145e0e65d1d.js.stderr +++ b/crates/swc_ecma_parser/tests/test262-error-references/fail/c3731145e0e65d1d.js.stderr @@ -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 | #= - : ^ + : ^ `---- diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs b/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs index 5a165b66d889..01b30f8e08b0 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs @@ -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}, @@ -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, diff --git a/crates/swc_ecma_transforms_compat/tests/es2022_private_in_object.rs b/crates/swc_ecma_transforms_compat/tests/es2022_private_in_object.rs index 22acd2c7ca1c..cb19d148a47d 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2022_private_in_object.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2022_private_in_object.rs @@ -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, @@ -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 = Box::new(noop()); diff --git a/crates/swc_ecma_transforms_typescript/tests/strip_correctness.rs b/crates/swc_ecma_transforms_typescript/tests/strip_correctness.rs index d58fb74ef4d3..19122dc9dc2e 100644 --- a/crates/swc_ecma_transforms_typescript/tests/strip_correctness.rs +++ b/crates/swc_ecma_transforms_typescript/tests/strip_correctness.rs @@ -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()