Skip to content

Commit

Permalink
fix(es/parser): Drop outdated options (#2974)
Browse files Browse the repository at this point in the history
swc_ecma_parser:
 - Drop flags in `EsConfig`.
 - Drop flags in `TsConfig`.
 - Drop unused variants from `SyntaxError`.
  • Loading branch information
kdy1 committed Dec 5, 2021
1 parent 16540fb commit 1ea965c
Show file tree
Hide file tree
Showing 40 changed files with 22 additions and 213 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions crates/swc/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1479,19 +1479,10 @@ impl Merge for Syntax {
impl Merge for swc_ecma_parser::EsConfig {
fn merge(&mut self, from: &Self) {
self.jsx |= from.jsx;
self.class_private_props |= from.class_private_props;
self.class_private_methods |= from.class_private_methods;
self.class_props |= from.class_props;
self.fn_bind |= from.fn_bind;
self.decorators |= from.decorators;
self.decorators_before_export |= from.decorators_before_export;
self.export_default_from |= from.export_default_from;
self.export_namespace_from |= from.export_namespace_from;
self.dynamic_import |= from.dynamic_import;
self.nullish_coalescing |= from.nullish_coalescing;
self.optional_chaining |= from.optional_chaining;
self.import_meta |= from.import_meta;
self.top_level_await |= from.top_level_await;
self.import_assertions |= from.import_assertions;
self.static_blocks |= from.static_blocks;
self.private_in_object |= from.private_in_object;
Expand All @@ -1502,7 +1493,6 @@ impl Merge for swc_ecma_parser::TsConfig {
fn merge(&mut self, from: &Self) {
self.tsx |= from.tsx;
self.decorators |= from.decorators;
self.dynamic_import |= from.dynamic_import;
}
}

Expand Down
2 changes: 0 additions & 2 deletions crates/swc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -966,10 +966,8 @@ impl Compiler {
jsx: true,
decorators: true,
decorators_before_export: true,
top_level_await: true,
import_assertions: true,
private_in_object: true,
dynamic_import: true,

..Default::default()
}),
Expand Down
2 changes: 0 additions & 2 deletions crates/swc/tests/rust_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ fn shopify_2_same_opt() {
syntax: Some(Syntax::Typescript(TsConfig {
tsx: true,
decorators: false,
dynamic_import: true,
dts: false,
no_early_errors: false,
})),
Expand Down Expand Up @@ -207,7 +206,6 @@ fn shopify_3_reduce_defaults() {
jsc: JscConfig {
syntax: Some(Syntax::Typescript(TsConfig {
tsx: true,
dynamic_import: true,
..Default::default()
})),
..Default::default()
Expand Down
3 changes: 0 additions & 3 deletions crates/swc/tests/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ const someValue = 'test' ?? 'default value';",
config: Config {
jsc: JscConfig {
syntax: Some(Syntax::Es(EsConfig {
nullish_coalescing: true,
optional_chaining: true,
..Default::default()
})),
..Default::default()
Expand All @@ -83,7 +81,6 @@ fn issue_834_3() {
config: Config {
jsc: JscConfig {
syntax: Some(Syntax::Es(EsConfig {
nullish_coalescing: true,
..Default::default()
})),
..Default::default()
Expand Down
1 change: 0 additions & 1 deletion crates/swc/tests/tsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ fn compile(input: &Path, output: &Path, opts: Options) {
syntax: Some(Syntax::Typescript(TsConfig {
tsx: input.to_string_lossy().ends_with(".tsx"),
decorators: true,
dynamic_import: true,
dts: false,
no_early_errors: true,
})),
Expand Down
1 change: 0 additions & 1 deletion crates/swc_bundler/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ impl Load for Loader {
Syntax::Typescript(TsConfig {
decorators: true,
tsx,
dynamic_import: true,
..Default::default()
}),
EsVersion::Es2020,
Expand Down
6 changes: 1 addition & 5 deletions crates/swc_ecma_codegen/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ fn export_namespace_from() {
"export * as Foo from 'foo';",
Default::default(),
Syntax::Es(EsConfig {
export_namespace_from: true,
..EsConfig::default()
}),
);
Expand All @@ -292,7 +291,6 @@ fn export_namespace_from_min() {
"export*as Foo from'foo'",
Config { minify: true },
Syntax::Es(EsConfig {
export_namespace_from: true,
..EsConfig::default()
}),
);
Expand All @@ -305,7 +303,6 @@ fn named_and_namespace_export_from() {
"export * as Foo, { bar } from 'foo';",
Default::default(),
Syntax::Es(EsConfig {
export_namespace_from: true,
..EsConfig::default()
}),
);
Expand All @@ -318,7 +315,6 @@ fn named_and_namespace_export_from_min() {
"export*as Foo,{bar}from'foo'",
Config { minify: true },
Syntax::Es(EsConfig {
export_namespace_from: true,
..EsConfig::default()
}),
);
Expand Down Expand Up @@ -525,7 +521,7 @@ fn integration_01_reduced_01() {
}

#[test]
fn dneo_8541_1() {
fn deno_8541_1() {
test_from_to(
"React.createElement('span', null, '\\u{b7}');",
"React.createElement('span', null, '\\u{b7}');",
Expand Down
1 change: 0 additions & 1 deletion crates/swc_ecma_dep_graph/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ mod tests {
Syntax::Typescript(TsConfig {
dts: file_name.ends_with(".d.ts"),
tsx: file_name.contains("tsx"),
dynamic_import: true,
decorators: true,
no_early_errors: true,
..Default::default()
Expand Down
24 changes: 5 additions & 19 deletions crates/swc_ecma_parser/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ pub enum SyntaxError {
ReservedWordInObjShorthandOrPat,

NullishCoalescingWithLogicalOp,
NullishCoalescingNotEnabled,

MultipleDefault {
/// Span of the previous default case
Expand All @@ -124,7 +123,7 @@ pub enum SyntaxError {
InvalidExpr,
NotSimpleAssign,
ExpectedIdent,
ExpctedSemi,
ExpectedSemi,
DuplicateLabel(JsWord),
AsyncGenerator,
NonTopLevelImportExport,
Expand Down Expand Up @@ -160,16 +159,13 @@ pub enum SyntaxError {
AsyncConstructor,
PropertyNamedConstructor,
DeclarePrivateIdentifier,
ClassProperty,
ReadOnlyMethod,
GeneratorConstructor,
TsBindingPatCannotBeOptional,

TrailingCommaInsideImport,
DynamicImport,

ExportDefaultWithOutFrom,
ExportNamespaceFrom,

DotsWithoutIdentifier,

Expand Down Expand Up @@ -338,7 +334,7 @@ impl SyntaxError {
// TODO
SyntaxError::NotSimpleAssign => "Cannot assign to this".into(),
SyntaxError::ExpectedIdent => "Expected ident".into(),
SyntaxError::ExpctedSemi => "Expected ';' or line break".into(),
SyntaxError::ExpectedSemi => "Expected ';' or line break".into(),
SyntaxError::DuplicateLabel(ref label) => {
format!("Label {} is already declared", label).into()
}
Expand Down Expand Up @@ -394,7 +390,7 @@ impl SyntaxError {
"A required element cannot follow an optional element.".into()
}
SyntaxError::TsInvalidParamPropPat => {
"Typescript parameter property must be identifer or assignment pattern".into()
"Typescript parameter property must be an identifier or assignment pattern".into()
}
SyntaxError::SpaceBetweenHashAndIdent => {
"Unexpected space between # and identifier".into()
Expand All @@ -406,9 +402,7 @@ impl SyntaxError {
SyntaxError::DeclarePrivateIdentifier => {
"'declare' modifier cannot be used with a private identifier".into()
}
SyntaxError::ClassProperty => {
"Class property requires `jsc.parser.classProperty` to be true".into()
}

SyntaxError::ReadOnlyMethod => "A method cannot be readonly".into(),
SyntaxError::TsBindingPatCannotBeOptional => "A binding pattern parameter cannot be \
optional in an implementation signature."
Expand All @@ -417,15 +411,10 @@ impl SyntaxError {
SyntaxError::TrailingCommaInsideImport => {
"Trailing comma is disallowed inside import(...) arguments".into()
}
SyntaxError::DynamicImport => {
"import(...) expressions requires `jsc.parser.dynamicImport` to be true".into()
}

SyntaxError::ExportDefaultWithOutFrom => {
"export default statements required from '...';".into()
}
SyntaxError::ExportNamespaceFrom => "export * as Foo from 'foo'; requires \
`jsc.parser.exportNamespaceFrom` to be true"
.into(),

SyntaxError::DotsWithoutIdentifier => {
"`...` must be followed by an identifier in declaration contexts".into()
Expand All @@ -439,9 +428,6 @@ impl SyntaxError {
"Nullish coalescing operator(??) requires parens when mixing with logical operators"
.into()
}
SyntaxError::NullishCoalescingNotEnabled => {
"Nullish coalescing operator(??) requires jsc.parser.nullishCoalescing".into()
}

SyntaxError::TS1056 => {
"jsc.target should be es5 or upper to use getter / setter".into()
Expand Down
10 changes: 2 additions & 8 deletions crates/swc_ecma_parser/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,18 +442,12 @@ impl<'a, I: Input> Lexer<'a, I> {
fn read_token_number_sign(&mut self) -> LexResult<Option<Token>> {
debug_assert!(self.cur().is_some());

let start = self.input.cur_pos();

if self.input.is_at_start() && self.read_token_interpreter()? {
return Ok(None);
}

if self.syntax.class_private_props() || self.syntax.class_private_methods() {
self.input.bump(); // '#'
return Ok(Some(Token::Hash));
}

self.error(start, SyntaxError::Hash)?
self.input.bump(); // '#'
return Ok(Some(Token::Hash));
}

fn read_token_interpreter(&mut self) -> LexResult<bool> {
Expand Down
3 changes: 1 addition & 2 deletions crates/swc_ecma_parser/src/lexer/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ impl<'a, I: Input> Lexer<'a, I> {

let mut prev = None;
while let Some(c) = self.cur() {
if allow_num_separator && self.syntax.num_sep() && c == '_' {
if allow_num_separator && c == '_' {
let is_allowed = |c: Option<char>| {
if c.is_none() {
return false;
Expand Down Expand Up @@ -438,7 +438,6 @@ mod tests {
crate::with_test_sess(s, |_, fm| {
let mut l = Lexer::new(
Syntax::Es(EsConfig {
num_sep: true,
..Default::default()
}),
Default::default(),
Expand Down
Loading

1 comment on commit 1ea965c

@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: 1ea965c Previous: 16540fb Ratio
full_es2015 198706311 ns/iter (± 16767570) 171644421 ns/iter (± 4000116) 1.16
full_es2016 158220057 ns/iter (± 14467234) 132040365 ns/iter (± 4894163) 1.20
full_es2017 163894870 ns/iter (± 14446080) 136942109 ns/iter (± 4803033) 1.20
full_es2018 167470487 ns/iter (± 20441509) 135909911 ns/iter (± 5488743) 1.23
full_es2019 166914572 ns/iter (± 20263588) 134841658 ns/iter (± 5814666) 1.24
full_es2020 164194134 ns/iter (± 14308023) 134738860 ns/iter (± 6747935) 1.22
full_es3 232827209 ns/iter (± 24005163) 205374002 ns/iter (± 16042061) 1.13
full_es5 215497998 ns/iter (± 25324409) 185420835 ns/iter (± 8766940) 1.16
parser 807893 ns/iter (± 99518) 655872 ns/iter (± 13988) 1.23

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

Please sign in to comment.