2018-01-12 10:53:06 +03:00
|
|
|
#![feature(box_syntax)]
|
|
|
|
#![feature(box_patterns)]
|
|
|
|
#![feature(const_fn)]
|
|
|
|
#![feature(specialization)]
|
|
|
|
#![feature(never_type)]
|
2018-01-22 04:45:08 +03:00
|
|
|
// #![feature(nll)]
|
2018-01-12 10:53:06 +03:00
|
|
|
#![feature(try_from)]
|
|
|
|
#![feature(try_trait)]
|
|
|
|
#![deny(unreachable_patterns)]
|
|
|
|
#![deny(unsafe_code)]
|
|
|
|
|
|
|
|
extern crate either;
|
|
|
|
extern crate parser_macros;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate slog;
|
|
|
|
#[macro_use(js_word)]
|
2018-01-22 04:45:08 +03:00
|
|
|
pub extern crate swc_atoms;
|
|
|
|
pub extern crate swc_common;
|
2018-01-16 14:03:16 +03:00
|
|
|
pub extern crate swc_ecma_ast as ast;
|
2018-01-12 10:53:06 +03:00
|
|
|
#[macro_use]
|
2018-01-22 04:45:08 +03:00
|
|
|
pub extern crate swc_macros;
|
2018-01-12 10:53:06 +03:00
|
|
|
#[cfg(test)]
|
|
|
|
#[macro_use]
|
|
|
|
extern crate testing;
|
|
|
|
extern crate unicode_xid;
|
2018-09-16 14:25:41 +03:00
|
|
|
pub use self::{
|
|
|
|
lexer::input::{Input, SourceFileInput},
|
|
|
|
parser::*,
|
|
|
|
};
|
2018-01-21 11:47:37 +03:00
|
|
|
use slog::Logger;
|
2018-01-22 04:45:08 +03:00
|
|
|
use swc_common::errors::Handler;
|
2018-01-12 10:53:06 +03:00
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
mod macros;
|
2018-01-22 04:45:08 +03:00
|
|
|
mod error;
|
2018-01-21 11:47:37 +03:00
|
|
|
mod lexer;
|
|
|
|
mod parser;
|
2018-06-02 12:01:00 +03:00
|
|
|
mod token;
|
2018-01-21 11:47:37 +03:00
|
|
|
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
|
|
|
pub struct Config {
|
|
|
|
/// Support numeric separator.
|
|
|
|
pub num_sep: bool,
|
|
|
|
|
|
|
|
/// Support function bind expression.
|
|
|
|
pub fn_bind: bool,
|
2018-01-26 15:53:30 +03:00
|
|
|
}
|
2018-01-21 11:47:37 +03:00
|
|
|
|
2018-01-26 15:53:30 +03:00
|
|
|
/// Syntatic context.
|
|
|
|
#[derive(Debug, Clone, Copy, Default)]
|
|
|
|
struct Context {
|
2018-01-21 11:47:37 +03:00
|
|
|
/// Is in module code?
|
2018-01-26 15:53:30 +03:00
|
|
|
module: bool,
|
|
|
|
strict: bool,
|
|
|
|
include_in_expr: bool,
|
|
|
|
/// If true, await expression is parsed, and "await" is treated as a
|
|
|
|
/// keyword.
|
|
|
|
in_async: bool,
|
|
|
|
/// If true, yield expression is parsed, and "yield" is treated as a
|
|
|
|
/// keyword.
|
|
|
|
in_generator: bool,
|
|
|
|
|
|
|
|
in_function: bool,
|
|
|
|
|
|
|
|
in_parameters: bool,
|
2018-01-21 11:47:37 +03:00
|
|
|
}
|
|
|
|
|
2018-01-22 04:45:08 +03:00
|
|
|
#[derive(Clone, Copy)]
|
2018-01-21 11:47:37 +03:00
|
|
|
pub struct Session<'a> {
|
|
|
|
pub cfg: Config,
|
|
|
|
pub logger: &'a Logger,
|
2018-01-22 04:45:08 +03:00
|
|
|
pub handler: &'a Handler,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
fn with_test_sess<F, Ret>(src: &'static str, f: F) -> Ret
|
|
|
|
where
|
2018-10-25 07:17:05 +03:00
|
|
|
F: FnOnce(Session, SourceFileInput) -> Ret,
|
2018-01-22 04:45:08 +03:00
|
|
|
{
|
2018-01-23 15:38:48 +03:00
|
|
|
use std::rc::Rc;
|
2018-10-25 07:17:05 +03:00
|
|
|
use swc_common::{FileName, FilePathMapping, SourceMap};
|
2018-01-23 15:38:48 +03:00
|
|
|
|
2018-10-25 07:17:05 +03:00
|
|
|
let cm = Rc::new(SourceMap::new(FilePathMapping::empty()));
|
|
|
|
let fm = cm.new_source_file(FileName::Real("testing".into()), src.into());
|
2018-01-23 15:38:48 +03:00
|
|
|
|
2018-01-22 04:45:08 +03:00
|
|
|
let handler = ::swc_common::errors::Handler::with_tty_emitter(
|
2018-01-23 15:38:48 +03:00
|
|
|
::swc_common::errors::ColorConfig::Auto,
|
2018-01-22 04:45:08 +03:00
|
|
|
true,
|
|
|
|
false,
|
2018-01-23 15:38:48 +03:00
|
|
|
Some(cm),
|
2018-01-22 04:45:08 +03:00
|
|
|
);
|
2018-01-23 15:38:48 +03:00
|
|
|
|
2018-01-22 04:45:08 +03:00
|
|
|
let logger = ::testing::logger().new(o!("src" => src));
|
|
|
|
|
2018-01-23 15:38:48 +03:00
|
|
|
f(
|
|
|
|
Session {
|
|
|
|
handler: &handler,
|
|
|
|
logger: &logger,
|
|
|
|
cfg: Default::default(),
|
|
|
|
},
|
|
|
|
(&*fm).into(),
|
|
|
|
)
|
2018-01-21 11:47:37 +03:00
|
|
|
}
|