mirror of
https://github.com/swc-project/swc.git
synced 2024-12-23 21:54:36 +03:00
Fix bugs (#482)
swc_ecma_parser: - fix lexing of numbers like 9.09 swc_ecma_transforms: - jsx_text_to_str - use fxhash instead of ahash for exports
This commit is contained in:
parent
bc19ee274b
commit
b3a2ee8e9b
2
.github/workflows/lint.yml
vendored
2
.github/workflows/lint.yml
vendored
@ -1,6 +1,6 @@
|
||||
name: Lint
|
||||
|
||||
on: [push]
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
|
@ -1 +1 @@
|
||||
622141790000000000000000;
|
||||
602214179000000000000000;
|
||||
|
@ -87,13 +87,14 @@ impl<'a, I: Input> Lexer<'a, I> {
|
||||
debug_assert!(self.cur().unwrap().is_digit(10));
|
||||
}
|
||||
|
||||
let mut raw = Raw(Some(String::new()));
|
||||
// Read numbers after dot
|
||||
let dec_val = self.read_int(10, 0, &mut Raw(None))?;
|
||||
let dec_val = self.read_int(10, 0, &mut raw)?;
|
||||
let mut s = String::new();
|
||||
write!(s, "{}.", val).unwrap();
|
||||
|
||||
if let Some(ref n) = dec_val {
|
||||
write!(s, "{}", n).unwrap();
|
||||
if let Some(..) = dec_val {
|
||||
s.push_str(&raw.0.as_ref().unwrap());
|
||||
}
|
||||
|
||||
val = s.parse().expect("failed to parse float using rust's impl");
|
||||
@ -402,6 +403,11 @@ mod tests {
|
||||
debug_assert_eq!(77777777777777777.1f64, num("77777777777777777.1"))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn issue_480() {
|
||||
debug_assert_eq!(9.09, num("9.09"))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn num_legacy_octal() {
|
||||
debug_assert_eq!(0o12 as f64, num("0012"));
|
||||
|
@ -1088,6 +1088,36 @@ fn issue_401() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn issue_481() {
|
||||
assert_eq!(
|
||||
lex_tokens(
|
||||
crate::Syntax::Es(crate::EsConfig {
|
||||
jsx: true,
|
||||
..Default::default()
|
||||
}),
|
||||
"<span> {foo}</span>"
|
||||
),
|
||||
vec![
|
||||
Token::JSXTagStart,
|
||||
Token::JSXName {
|
||||
name: "span".into()
|
||||
},
|
||||
Token::JSXTagEnd,
|
||||
JSXText { raw: " ".into() },
|
||||
LBrace,
|
||||
Word(Word::Ident("foo".into())),
|
||||
RBrace,
|
||||
JSXTagStart,
|
||||
BinOp(Div),
|
||||
JSXName {
|
||||
name: "span".into()
|
||||
},
|
||||
JSXTagEnd,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn lex_colors_js(b: &mut Bencher) {
|
||||
b.bytes = include_str!("../../colors.js").len() as _;
|
||||
|
@ -7,7 +7,7 @@ use crate::{
|
||||
util::{prepend_stmts, var::VarCollector, DestructuringFinder, ExprFactory},
|
||||
};
|
||||
use ast::*;
|
||||
use hashbrown::HashSet;
|
||||
use fxhash::FxHashSet;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::iter;
|
||||
use swc_atoms::js_word;
|
||||
@ -55,7 +55,7 @@ impl Fold<Module> for Amd {
|
||||
}
|
||||
|
||||
let mut exports = vec![];
|
||||
let mut initialized = HashSet::default();
|
||||
let mut initialized = FxHashSet::default();
|
||||
let mut export_alls = vec![];
|
||||
let mut emitted_esmodule = false;
|
||||
let mut has_export = false;
|
||||
|
@ -8,7 +8,7 @@ use crate::{
|
||||
util::{var::VarCollector, DestructuringFinder, ExprFactory},
|
||||
};
|
||||
use ast::*;
|
||||
use hashbrown::HashSet;
|
||||
use fxhash::FxHashSet;
|
||||
use swc_atoms::js_word;
|
||||
use swc_common::{Fold, FoldWith, VisitWith, DUMMY_SP};
|
||||
|
||||
@ -40,7 +40,7 @@ impl Fold<Vec<ModuleItem>> for CommonJs {
|
||||
}
|
||||
|
||||
let mut exports = vec![];
|
||||
let mut initialized = HashSet::default();
|
||||
let mut initialized = FxHashSet::default();
|
||||
let mut export_alls = vec![];
|
||||
|
||||
for item in items {
|
||||
|
@ -9,7 +9,7 @@ use crate::{
|
||||
util::{prepend_stmts, var::VarCollector, DestructuringFinder, ExprFactory},
|
||||
};
|
||||
use ast::*;
|
||||
use hashbrown::HashSet;
|
||||
use fxhash::FxHashSet;
|
||||
use std::sync::Arc;
|
||||
use swc_atoms::js_word;
|
||||
use swc_common::{Fold, FoldWith, Mark, SourceMap, VisitWith, DUMMY_SP};
|
||||
@ -53,7 +53,7 @@ impl Fold<Module> for Umd {
|
||||
}
|
||||
|
||||
let mut exports = vec![];
|
||||
let mut initialized = HashSet::default();
|
||||
let mut initialized = FxHashSet::default();
|
||||
let mut export_alls = vec![];
|
||||
let mut emitted_esmodule = false;
|
||||
let mut has_export = false;
|
||||
|
@ -1,5 +1,6 @@
|
||||
use crate::util::{undefined, DestructuringFinder, ExprFactory};
|
||||
use ast::*;
|
||||
use fxhash::FxHashSet;
|
||||
use hashbrown::{hash_map::Entry, HashMap, HashSet};
|
||||
use indexmap::IndexMap;
|
||||
use inflector::Inflector;
|
||||
@ -718,7 +719,7 @@ pub(super) fn use_strict() -> Stmt {
|
||||
/// ```js
|
||||
/// exports.default = exports.foo = void 0;
|
||||
/// ```
|
||||
pub(super) fn initialize_to_undefined(exports: Ident, initialized: HashSet<JsWord>) -> Box<Expr> {
|
||||
pub(super) fn initialize_to_undefined(exports: Ident, initialized: FxHashSet<JsWord>) -> Box<Expr> {
|
||||
let mut rhs = undefined(DUMMY_SP);
|
||||
|
||||
for name in initialized.into_iter() {
|
||||
|
@ -172,6 +172,7 @@ impl Jsx {
|
||||
if s.value.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
Lit::Str(s).as_arg()
|
||||
}
|
||||
JSXElementChild::JSXExprContainer(JSXExprContainer {
|
||||
@ -392,11 +393,14 @@ fn to_prop_name(n: JSXAttrName) -> PropName {
|
||||
}
|
||||
|
||||
fn jsx_text_to_str(t: JsWord) -> JsWord {
|
||||
if t == *" " {
|
||||
return t;
|
||||
}
|
||||
if !t.contains(' ') && !t.contains('\n') {
|
||||
return t;
|
||||
}
|
||||
|
||||
let mut buf = String::new();
|
||||
let mut buf = String::from("");
|
||||
for s in t.replace("\n", " ").split_ascii_whitespace() {
|
||||
buf.push_str(s);
|
||||
buf.push(' ');
|
||||
|
@ -1066,3 +1066,17 @@ test!(
|
||||
var _react = _interopRequireDefault(require('react'));
|
||||
_react.default.createElement('div', null);"
|
||||
);
|
||||
|
||||
test!(
|
||||
::swc_ecma_parser::Syntax::Es(::swc_ecma_parser::EsConfig {
|
||||
jsx: true,
|
||||
..Default::default()
|
||||
}),
|
||||
|_| tr(Options {
|
||||
use_builtins: true,
|
||||
..Default::default()
|
||||
}),
|
||||
issue_481,
|
||||
"<span> {foo}</span>;",
|
||||
"React.createElement('span', null, ' ', foo);"
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user