mirror of
https://github.com/swc-project/swc.git
synced 2024-11-23 09:38:16 +03:00
fix(es/compat): Apply static_blocks
before class_properties
(#3292)
This commit is contained in:
parent
be33d20baf
commit
89235b8294
@ -87,12 +87,14 @@ where
|
||||
// Proposals
|
||||
|
||||
// ES2022
|
||||
// static block needs to be placed before class property
|
||||
// because it transforms into private static property
|
||||
let pass = add!(pass, ClassStaticBlock, es2022::static_blocks());
|
||||
let pass = add!(
|
||||
pass,
|
||||
ClassProperties,
|
||||
es2022::class_properties(es2022::class_properties::Config { loose })
|
||||
);
|
||||
let pass = add!(pass, ClassStaticBlock, es2022::static_blocks());
|
||||
let pass = add!(pass, PrivatePropertyInObject, es2022::private_in_object());
|
||||
|
||||
// ES2021
|
||||
|
5
crates/swc_ecma_preset_env/tests/fixtures/transform/static-block/input.mjs
vendored
Normal file
5
crates/swc_ecma_preset_env/tests/fixtures/transform/static-block/input.mjs
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
class A {
|
||||
static {
|
||||
this.abc = 123
|
||||
}
|
||||
}
|
10
crates/swc_ecma_preset_env/tests/fixtures/transform/static-block/options.json
vendored
Normal file
10
crates/swc_ecma_preset_env/tests/fixtures/transform/static-block/options.json
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"presets": [
|
||||
[
|
||||
"../../../../lib",
|
||||
{
|
||||
"targets": "chrome 70"
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
8
crates/swc_ecma_preset_env/tests/fixtures/transform/static-block/output.mjs
vendored
Normal file
8
crates/swc_ecma_preset_env/tests/fixtures/transform/static-block/output.mjs
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
class A {
|
||||
}
|
||||
var __ = {
|
||||
writable: true,
|
||||
value: (()=>{
|
||||
A.abc = 123;
|
||||
})()
|
||||
};
|
@ -12,12 +12,14 @@ use std::{
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
use swc_common::{
|
||||
collections::AHashMap, comments::SingleThreadedComments, input::StringInput, FromVariant, Mark,
|
||||
chain, collections::AHashMap, comments::SingleThreadedComments, input::StringInput,
|
||||
FromVariant, Mark,
|
||||
};
|
||||
use swc_ecma_ast::*;
|
||||
use swc_ecma_codegen::Emitter;
|
||||
use swc_ecma_parser::{EsConfig, Parser, Syntax};
|
||||
use swc_ecma_preset_env::{preset_env, Config, FeatureOrModule, Mode, Targets, Version};
|
||||
use swc_ecma_transforms::fixer;
|
||||
use swc_ecma_utils::drop_span;
|
||||
use swc_ecma_visit::{as_folder, FoldWith, VisitMut};
|
||||
use testing::{NormalizedOutput, Tester};
|
||||
@ -119,34 +121,37 @@ fn exec(c: PresetConfig, dir: PathBuf) -> Result<(), Error> {
|
||||
|
||||
Tester::new()
|
||||
.print_errors(|cm, handler| {
|
||||
let mut pass = preset_env(
|
||||
Mark::fresh(Mark::root()),
|
||||
Some(SingleThreadedComments::default()),
|
||||
Config {
|
||||
debug: c.debug,
|
||||
mode: match c.use_built_ins {
|
||||
UseBuiltIns::Bool(false) => None,
|
||||
UseBuiltIns::Str(ref s) if s == "usage" => Some(Mode::Usage),
|
||||
UseBuiltIns::Str(ref s) if s == "entry" => Some(Mode::Entry),
|
||||
v => unreachable!("invalid: {:?}", v),
|
||||
let mut pass = chain!(
|
||||
preset_env(
|
||||
Mark::fresh(Mark::root()),
|
||||
Some(SingleThreadedComments::default()),
|
||||
Config {
|
||||
debug: c.debug,
|
||||
mode: match c.use_built_ins {
|
||||
UseBuiltIns::Bool(false) => None,
|
||||
UseBuiltIns::Str(ref s) if s == "usage" => Some(Mode::Usage),
|
||||
UseBuiltIns::Str(ref s) if s == "entry" => Some(Mode::Entry),
|
||||
v => unreachable!("invalid: {:?}", v),
|
||||
},
|
||||
skip: vec![],
|
||||
// TODO
|
||||
loose: true,
|
||||
// TODO
|
||||
dynamic_import: true,
|
||||
bugfixes: false,
|
||||
include: c.include,
|
||||
exclude: c.exclude,
|
||||
core_js: match c.corejs {
|
||||
CoreJs::Ver(v) => Some(v),
|
||||
ref s => unimplemented!("Unknown core js version: {:?}", s),
|
||||
},
|
||||
force_all_transforms: c.force_all_transforms,
|
||||
shipped_proposals: c.shipped_proposals,
|
||||
targets: c.targets,
|
||||
path: std::env::current_dir().unwrap(),
|
||||
},
|
||||
skip: vec![],
|
||||
// TODO
|
||||
loose: true,
|
||||
// TODO
|
||||
dynamic_import: true,
|
||||
bugfixes: false,
|
||||
include: c.include,
|
||||
exclude: c.exclude,
|
||||
core_js: match c.corejs {
|
||||
CoreJs::Ver(v) => Some(v),
|
||||
ref s => unimplemented!("Unknown core js version: {:?}", s),
|
||||
},
|
||||
force_all_transforms: c.force_all_transforms,
|
||||
shipped_proposals: c.shipped_proposals,
|
||||
targets: c.targets,
|
||||
path: std::env::current_dir().unwrap(),
|
||||
},
|
||||
),
|
||||
fixer(None)
|
||||
);
|
||||
|
||||
let print = |m: &Module| {
|
||||
@ -174,6 +179,7 @@ fn exec(c: PresetConfig, dir: PathBuf) -> Result<(), Error> {
|
||||
.expect("failed to load file");
|
||||
let mut p = Parser::new(
|
||||
Syntax::Es(EsConfig {
|
||||
static_blocks: true,
|
||||
..Default::default()
|
||||
}),
|
||||
StringInput::from(&*fm),
|
||||
|
@ -11,10 +11,10 @@ pub mod static_blocks;
|
||||
|
||||
pub fn es2022(config: Config) -> impl Fold {
|
||||
chain!(
|
||||
static_blocks(),
|
||||
class_properties(class_properties::Config {
|
||||
loose: config.loose,
|
||||
}),
|
||||
static_blocks(),
|
||||
private_in_object(),
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user