mirror of
https://github.com/swc-project/swc.git
synced 2024-11-27 04:47:03 +03:00
fix(es/module): Fix exported vars with bigint values (#3909)
This commit is contained in:
parent
79a9cb4c72
commit
8559fc9623
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -1084,9 +1084,9 @@ checksum = "cb56e1aa765b4b4f3aadfab769793b7087bb03a4ea4920644a6d238e2df5b9ed"
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.7.0"
|
||||
version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5"
|
||||
checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"hashbrown",
|
||||
|
@ -13,7 +13,7 @@ version = "0.89.4"
|
||||
Inflector = "0.11.4"
|
||||
ahash = "0.7.4"
|
||||
anyhow = "1.0.41"
|
||||
indexmap = "1.6.1"
|
||||
indexmap = "1.8.0"
|
||||
pathdiff = "0.2.0"
|
||||
serde = {version = "1.0.118", features = ["derive"]}
|
||||
swc_atoms = {version = "0.2", path = "../swc_atoms"}
|
||||
|
@ -1,7 +1,8 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use indexmap::IndexMap;
|
||||
use swc_atoms::JsWord;
|
||||
use swc_common::{collections::AHashMap, pass::CompilerPass, util::take::Take, DUMMY_SP};
|
||||
use swc_common::{pass::CompilerPass, util::take::Take, DUMMY_SP};
|
||||
use swc_ecma_ast::*;
|
||||
use swc_ecma_utils::{find_ids, IsDirective};
|
||||
use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut};
|
||||
@ -129,7 +130,7 @@ impl VisitMut for ModuleHoister {
|
||||
let body = stmts;
|
||||
|
||||
let mut stmts = Vec::with_capacity(body.len());
|
||||
let mut named_exports = AHashMap::<JsWord, Vec<ExportSpecifier>>::default();
|
||||
let mut named_exports = IndexMap::<JsWord, Vec<ExportSpecifier>>::default();
|
||||
|
||||
// collect all named export stmts which bind local idents
|
||||
for item in body.into_iter() {
|
||||
|
@ -616,13 +616,8 @@ impl Scope {
|
||||
..e
|
||||
}),
|
||||
|
||||
Expr::Update(UpdateExpr {
|
||||
span,
|
||||
arg,
|
||||
op,
|
||||
prefix,
|
||||
}) if arg.is_ident() => {
|
||||
let arg = arg.ident().unwrap();
|
||||
Expr::Update(update) if update.arg.is_ident() => {
|
||||
let arg = update.arg.clone().expect_ident();
|
||||
let mut scope = folder.scope_mut();
|
||||
let entry = scope
|
||||
.exported_bindings
|
||||
@ -630,39 +625,20 @@ impl Scope {
|
||||
|
||||
match entry {
|
||||
Entry::Occupied(entry) => {
|
||||
let e = chain_assign!(
|
||||
entry,
|
||||
Box::new(Expr::Assign(AssignExpr {
|
||||
if update.prefix {
|
||||
*chain_assign!(entry, Box::new(update.into()))
|
||||
} else {
|
||||
// TODO: This assumes `pureGetters=true`
|
||||
Expr::Seq(SeqExpr {
|
||||
span: DUMMY_SP,
|
||||
left: PatOrExpr::Pat(arg.clone().into()),
|
||||
op: op!("="),
|
||||
right: Box::new(Expr::Bin(BinExpr {
|
||||
span: DUMMY_SP,
|
||||
left: Box::new(Expr::Unary(UnaryExpr {
|
||||
span: DUMMY_SP,
|
||||
op: op!(unary, "+"),
|
||||
arg: Box::new(Expr::Ident(arg)),
|
||||
})),
|
||||
op: match op {
|
||||
op!("++") => op!(bin, "+"),
|
||||
op!("--") => op!(bin, "-"),
|
||||
},
|
||||
right: Box::new(Expr::Lit(Lit::Num(Number {
|
||||
span: DUMMY_SP,
|
||||
value: 1.0,
|
||||
}))),
|
||||
})),
|
||||
}))
|
||||
);
|
||||
|
||||
*e
|
||||
exprs: vec![
|
||||
Box::new(update.into()),
|
||||
chain_assign!(entry, Box::new(arg.into())),
|
||||
],
|
||||
})
|
||||
}
|
||||
}
|
||||
_ => Expr::Update(UpdateExpr {
|
||||
span,
|
||||
arg: Box::new(Expr::Ident(arg)),
|
||||
op,
|
||||
prefix,
|
||||
}),
|
||||
_ => update.into(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -566,7 +566,7 @@ define(["exports"], function (_exports) {
|
||||
var test1 = 2;
|
||||
_exports.test = test1;
|
||||
_exports.test = test1 = 5;
|
||||
_exports.test = test1 = +test1 + 1;
|
||||
test1++, _exports.test = test1;
|
||||
|
||||
(function () {
|
||||
var test = 2;
|
||||
|
@ -478,7 +478,7 @@ let diffLevel = 0;
|
||||
exports.diffLevel = diffLevel;
|
||||
|
||||
function diff() {
|
||||
if (!(exports.diffLevel = diffLevel = +diffLevel + 1)) {
|
||||
if (!(exports.diffLevel = ++diffLevel)) {
|
||||
console.log("hey");
|
||||
}
|
||||
}
|
||||
@ -811,7 +811,7 @@ exports.f = exports.e = exports.c = exports.a = exports.test = void 0;
|
||||
var test = 2;
|
||||
exports.test = test;
|
||||
exports.test = test = 5;
|
||||
exports.test = test = +test + 1;
|
||||
test++, exports.test = test;
|
||||
|
||||
(function () {
|
||||
var test1 = 2;
|
||||
@ -2470,7 +2470,7 @@ let diffLevel = 0;
|
||||
exports.diffLevel = diffLevel;
|
||||
|
||||
function diff() {
|
||||
if (!(exports.diffLevel = diffLevel = +diffLevel - 1)) {
|
||||
if (!(exports.diffLevel = --diffLevel)) {
|
||||
console.log("hey");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,10 @@
|
||||
export let foo = 1n;
|
||||
|
||||
foo++;
|
||||
export let bar = ++foo;
|
||||
|
||||
export let baz = bar--;
|
||||
|
||||
export { foo as foobar, baz as bazbar };
|
||||
|
||||
--bar;
|
@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.bazbar = exports.foobar = exports.baz = exports.bar = exports.foo = void 0;
|
||||
let foo = 1n;
|
||||
exports.foo = foo;
|
||||
foo++, exports.foo = foo;
|
||||
let bar = exports.foo = ++foo;
|
||||
exports.bar = bar;
|
||||
let baz = (bar--, exports.bar = bar);
|
||||
exports.baz = baz;
|
||||
exports.bar = --bar;
|
||||
exports.foobar = foo;
|
||||
exports.bazbar = baz;
|
@ -1278,7 +1278,7 @@ d = 4;
|
||||
var test1 = 2;
|
||||
_exports.test = test1;
|
||||
_exports.test = test1 = 5;
|
||||
_exports.test = test1 = +test1 + 1;
|
||||
test1++, _exports.test = test1;
|
||||
|
||||
(function () {
|
||||
var test = 2;
|
||||
|
Loading…
Reference in New Issue
Block a user