mirror of
https://github.com/swc-project/swc.git
synced 2024-11-24 02:06:08 +03:00
fix(es): Fix simple bugs (#2077)
swc_ecma_visit: - Ensure that #1967 is wrong. (#1967) swc: - Add a test for #1107. (#1107) node: - Make optional fields optional. (#1947)
This commit is contained in:
parent
b0067adb9c
commit
949a4d9716
40
ecmascript/parser/tests/visitor.rs
Normal file
40
ecmascript/parser/tests/visitor.rs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
use swc_common::{input::StringInput, FileName, DUMMY_SP};
|
||||||
|
use swc_ecma_ast::*;
|
||||||
|
use swc_ecma_parser::{lexer::Lexer, Parser};
|
||||||
|
use swc_ecma_visit::{All, Node, VisitAll, VisitWith};
|
||||||
|
|
||||||
|
struct Issue1967;
|
||||||
|
|
||||||
|
impl VisitAll for Issue1967 {
|
||||||
|
fn visit_expr(&mut self, _: &Expr, _: &dyn Node) {
|
||||||
|
panic!("intended")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[should_panic = "intended"]
|
||||||
|
fn issue_1967() {
|
||||||
|
testing::run_test2(false, |cm, _handler| {
|
||||||
|
let fm = cm.new_source_file(FileName::Anon, "function foo(){ return 'I'; }".to_string());
|
||||||
|
let lexer = Lexer::new(
|
||||||
|
Default::default(),
|
||||||
|
EsVersion::latest(),
|
||||||
|
StringInput::from(&*fm),
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut parser = Parser::new_from(lexer);
|
||||||
|
|
||||||
|
let m = parser.parse_module().unwrap();
|
||||||
|
|
||||||
|
m.visit_with(
|
||||||
|
&Invalid { span: DUMMY_SP },
|
||||||
|
&mut All {
|
||||||
|
visitor: Issue1967 {},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
}
|
@ -620,13 +620,13 @@ export interface ReactConfig {
|
|||||||
*
|
*
|
||||||
* Defaults to `React.createElement`.
|
* Defaults to `React.createElement`.
|
||||||
*/
|
*/
|
||||||
pragma: string;
|
pragma?: string;
|
||||||
/**
|
/**
|
||||||
* Replace the component used when compiling JSX fragments.
|
* Replace the component used when compiling JSX fragments.
|
||||||
*
|
*
|
||||||
* Defaults to `React.Fragment`
|
* Defaults to `React.Fragment`
|
||||||
*/
|
*/
|
||||||
pragmaFrag: string;
|
pragmaFrag?: string;
|
||||||
/**
|
/**
|
||||||
* Toggles whether or not to throw an error if a XML namespaced tag name is used. For example:
|
* Toggles whether or not to throw an error if a XML namespaced tag name is used. For example:
|
||||||
* `<f:image />`
|
* `<f:image />`
|
||||||
@ -635,7 +635,7 @@ export interface ReactConfig {
|
|||||||
* JSX does not currently have support for it.
|
* JSX does not currently have support for it.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
throwIfNamespace: boolean;
|
throwIfNamespace?: boolean;
|
||||||
/**
|
/**
|
||||||
* Toggles plugins that aid in development, such as @swc/plugin-transform-react-jsx-self
|
* Toggles plugins that aid in development, such as @swc/plugin-transform-react-jsx-self
|
||||||
* and @swc/plugin-transform-react-jsx-source.
|
* and @swc/plugin-transform-react-jsx-source.
|
||||||
@ -643,26 +643,26 @@ export interface ReactConfig {
|
|||||||
* Defaults to `false`,
|
* Defaults to `false`,
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
development: boolean;
|
development?: boolean;
|
||||||
/**
|
/**
|
||||||
* Use `Object.assign()` instead of `_extends`. Defaults to false.
|
* Use `Object.assign()` instead of `_extends`. Defaults to false.
|
||||||
*/
|
*/
|
||||||
useBuiltins: boolean;
|
useBuiltins?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable fast refresh feature for React app
|
* Enable fast refresh feature for React app
|
||||||
*/
|
*/
|
||||||
refresh: boolean;
|
refresh?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* jsx runtime
|
* jsx runtime
|
||||||
*/
|
*/
|
||||||
runtime: 'automatic' | 'classic'
|
runtime?: 'automatic' | 'classic'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Declares the module specifier to be used for importing the `jsx` and `jsxs` factory functions when using `runtime` 'automatic'
|
* Declares the module specifier to be used for importing the `jsx` and `jsxs` factory functions when using `runtime` 'automatic'
|
||||||
*/
|
*/
|
||||||
importSource: string
|
importSource?: string
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* - `import { DEBUG } from '@ember/env-flags';`
|
* - `import { DEBUG } from '@ember/env-flags';`
|
||||||
@ -786,7 +786,7 @@ export interface UmdConfig extends BaseModuleConfig {
|
|||||||
|
|
||||||
export interface AmdConfig extends BaseModuleConfig {
|
export interface AmdConfig extends BaseModuleConfig {
|
||||||
type: "amd";
|
type: "amd";
|
||||||
moduleId: string;
|
moduleId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Output {
|
export interface Output {
|
||||||
|
11
tests/fixture/issue-1107/1/input/index.js
Normal file
11
tests/fixture/issue-1107/1/input/index.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
export class Class1 {
|
||||||
|
constructor({ name = '' }) {
|
||||||
|
console.log(name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Class2 {
|
||||||
|
constructor({ name = '' }) {
|
||||||
|
console.log(name)
|
||||||
|
}
|
||||||
|
}
|
17
tests/fixture/issue-1107/1/output/index.js
Normal file
17
tests/fixture/issue-1107/1/output/index.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
function _classCallCheck(instance, Constructor) {
|
||||||
|
if (!(instance instanceof Constructor)) {
|
||||||
|
throw new TypeError("Cannot call a class as a function");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export var Class1 = function Class1(param) {
|
||||||
|
"use strict";
|
||||||
|
var _name = param.name, name = _name === void 0 ? '' : _name;
|
||||||
|
_classCallCheck(this, Class1);
|
||||||
|
console.log(name);
|
||||||
|
};
|
||||||
|
export var Class2 = function Class2(param) {
|
||||||
|
"use strict";
|
||||||
|
var _name = param.name, name = _name === void 0 ? '' : _name;
|
||||||
|
_classCallCheck(this, Class2);
|
||||||
|
console.log(name);
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user