fix(es/compat): Preserve spans in object_rest_spread (#5082)

This commit is contained in:
magic-akari 2022-07-02 11:50:30 +08:00 committed by GitHub
parent 586228106b
commit de66b64aed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 19 additions and 22 deletions

View File

@ -9,14 +9,14 @@ function _export(target, all) {
});
}
_export(exports, {
badIstanbul: ()=>badIstanbul,
noop: ()=>noop,
badIstanbul: ()=>badIstanbul,
downloadDocument: ()=>downloadDocument
});
const _objectWithoutProperties = require("@swc/helpers/lib/_object_without_properties.js").default;
//top comment
const noop = ()=>{};
var /* istanbul ignore next */ badIstanbul = (test)=>{
/* istanbul ignore next */ const badIstanbul = (test)=>{
const { value } = test, pixelParams = _objectWithoutProperties(test, [
"value"
]);

View File

@ -9,9 +9,9 @@ function _export(target, all) {
});
}
_export(exports, {
foo: ()=>foo,
a: ()=>a,
b: ()=>b
b: ()=>b,
foo: ()=>foo
});
const _extends = require("@swc/helpers/lib/_extends.js").default;
const a = 1;

View File

@ -581,7 +581,7 @@ impl BlockScoping {
fn find_vars<T>(node: &T) -> Vec<Id>
where
T: for<'any> VisitWith<VarCollector<'any>>,
T: for<'any> VisitWith<VarCollector<'any, Id>>,
{
let mut vars = vec![];
let mut v = VarCollector { to: &mut vars };

View File

@ -288,19 +288,16 @@ impl VisitMut for ObjectRest {
span,
decl: Decl::Var(var_decl),
..
}) => {
}) if var_decl.decls.iter().any(|v| v.name.is_object()) => {
let specifiers = {
let mut found = vec![];
let mut found: Vec<Ident> = vec![];
let mut finder = VarCollector { to: &mut found };
var_decl.visit_with(&mut finder);
found
.into_iter()
.map(|(sym, ctxt)| ExportNamedSpecifier {
.map(|ident| ExportNamedSpecifier {
span: DUMMY_SP,
orig: ModuleExportName::Ident(Ident::new(
sym,
DUMMY_SP.with_ctxt(ctxt),
)),
orig: ident.into(),
exported: None,
is_type_only: false,
})

View File

@ -128,7 +128,7 @@ impl SystemJs {
_ => Expr::Assign(assign_expr),
},
PatOrExpr::Pat(pat) => {
let mut to = vec![];
let mut to: Vec<Id> = vec![];
pat.visit_with(&mut VarCollector { to: &mut to });
match &**pat {
@ -392,7 +392,7 @@ impl SystemJs {
fn hoist_var_decl(&mut self, var_decl: VarDecl) -> Option<Expr> {
let mut exprs = vec![];
for var_declarator in var_decl.decls {
let mut tos = vec![];
let mut tos: Vec<Id> = vec![];
var_declarator.visit_with(&mut VarCollector { to: &mut tos });
for (sym, ctxt) in tos {
@ -433,7 +433,7 @@ impl SystemJs {
if let VarDeclOrPat::VarDecl(mut var_decl) = var_decl_or_pat {
if var_decl.kind == VarDeclKind::Var {
let var_declarator = var_decl.decls.remove(0);
let mut tos = vec![];
let mut tos: Vec<Id> = vec![];
var_declarator.visit_with(&mut VarCollector { to: &mut tos });
for to in tos {
@ -834,7 +834,7 @@ impl Fold for SystemJs {
..var_decl
};
for var_declarator in var_decl.decls {
let mut tos = vec![];
let mut tos: Vec<Id> = vec![];
var_declarator.visit_with(&mut VarCollector { to: &mut tos });
for to in tos {
let ident =

View File

@ -386,7 +386,7 @@ where
}
Decl::Var(ref var) => {
let mut names = vec![];
let mut names: Vec<Id> = vec![];
var.decls.visit_with(&mut VarCollector { to: &mut names });
for name in names {

View File

@ -1,15 +1,15 @@
use swc_ecma_ast::*;
use swc_ecma_visit::{noop_visit_type, Visit, VisitWith};
use crate::Id;
use crate::ident::IdentLike;
/// This collects variables bindings while ignoring if it's nested in
/// expression.
pub struct VarCollector<'a> {
pub to: &'a mut Vec<Id>,
pub struct VarCollector<'a, I: IdentLike> {
pub to: &'a mut Vec<I>,
}
impl Visit for VarCollector<'_> {
impl<'a, I: IdentLike> Visit for VarCollector<'a, I> {
noop_visit_type!();
fn visit_arrow_expr(&mut self, _: &ArrowExpr) {}
@ -25,7 +25,7 @@ impl Visit for VarCollector<'_> {
}
fn visit_ident(&mut self, i: &Ident) {
self.to.push((i.sym.clone(), i.span.ctxt()))
self.to.push(I::from_ident(i))
}
fn visit_var_declarator(&mut self, node: &VarDeclarator) {