Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(es): Remove privateInObject related setting #6468

Merged
merged 2 commits into from Nov 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions crates/swc/src/builder.rs
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
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
@@ -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
@@ -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
@@ -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
};
@@ -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;
}
}
@@ -1,2 +1 @@
//// [privateNameInInExpressionUnused.ts]
new WeakSet();
12 changes: 0 additions & 12 deletions crates/swc_ecma_parser/src/lib.rs
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
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
@@ -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 | #=
: ^
: ^
`----
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
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
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