Browse Source

Documented console methods

pull/293/head
HalidOdat 4 years ago
parent
commit
269b063cf2
  1. 69
      boa/src/builtins/console.rs
  2. 130
      boa/src/builtins/console/mod.rs
  3. 28
      boa/src/syntax/ast/constant.rs
  4. 118
      boa/src/syntax/ast/keyword.rs
  5. 2
      boa/src/syntax/ast/mod.rs
  6. 148
      boa/src/syntax/ast/node.rs
  7. 144
      boa/src/syntax/ast/op.rs
  8. 10
      boa/src/syntax/ast/punc.rs
  9. 10
      boa/src/syntax/ast/token.rs
  10. 3
      boa/src/syntax/mod.rs

69
boa/src/builtins/console.rs

@ -1,69 +0,0 @@
//! This module implements the global `console` object.
//!
//! The `console` object can be accessed from any global object.
//!
//! The specifics of how it works varies from browser to browser, but there is a de facto set of features that are typically provided.
//!
//! More information:
//! - [MDN documentation][mdn]
//! - [WHATWG `console` specification][spec]
//!
//! [spec]: https://console.spec.whatwg.org/
//! [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/Console
#![allow(clippy::print_stdout)]
use crate::{
builtins::{
function::NativeFunctionData,
value::{from_value, log_string_from, to_value, ResultValue, Value, ValueData},
},
exec::Interpreter,
};
use gc::Gc;
use std::{iter::FromIterator, ops::Deref};
/// This `console` method prints the javascript values to stdout.
///
/// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `log` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#log
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/Console/log
pub fn log(_: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
// Welcome to console.log! The output here is what the developer sees, so its best matching through value types and stringifying to the correct output
// The input is a vector of Values, we generate a vector of strings then
// pass them to println!
let args: Vec<String> =
FromIterator::from_iter(args.iter().map(|x| log_string_from(x.deref(), false)));
println!("{}", args.join(" "));
Ok(Gc::new(ValueData::Undefined))
}
/// This `console` method prints the javascript values to stderr.
///
/// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `error` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#error
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/Console/error
pub fn error(_: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
let args: Vec<String> = FromIterator::from_iter(
args.iter()
.map(|x| from_value::<String>(x.clone()).expect("Could not convert value to String")),
);
eprintln!("{}", args.join(" "));
Ok(Gc::new(ValueData::Undefined))
}
/// Create a new `console` object.
pub fn create_constructor(global: &Value) -> Value {
let console = ValueData::new_obj(Some(global));
console.set_field_slice("log", to_value(log as NativeFunctionData));
console.set_field_slice("error", to_value(error as NativeFunctionData));
console.set_field_slice("exception", to_value(error as NativeFunctionData));
console
}

130
boa/src/builtins/console/mod.rs

@ -1,3 +1,16 @@
//! This module implements the global `console` object.
//!
//! The `console` object can be accessed from any global object.
//!
//! The specifics of how it works varies from browser to browser, but there is a de facto set of features that are typically provided.
//!
//! More information:
//! - [MDN documentation][mdn]
//! - [WHATWG `console` specification][spec]
//!
//! [spec]: https://console.spec.whatwg.org/
//! [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/Console
#![allow(clippy::print_stdout)] #![allow(clippy::print_stdout)]
#[cfg(test)] #[cfg(test)]
@ -14,6 +27,7 @@ use crate::{
use gc::Gc; use gc::Gc;
use std::{collections::HashMap, time::SystemTime}; use std::{collections::HashMap, time::SystemTime};
/// This is the internal console object state.
#[derive(Debug, Default)] #[derive(Debug, Default)]
pub struct ConsoleState { pub struct ConsoleState {
count_map: HashMap<String, u32>, count_map: HashMap<String, u32>,
@ -33,6 +47,7 @@ impl ConsoleState {
impl InternalState for ConsoleState {} impl InternalState for ConsoleState {}
/// This represents the different types of log messages.
#[derive(Debug)] #[derive(Debug)]
pub enum LogMessage { pub enum LogMessage {
Log(String), Log(String),
@ -41,12 +56,14 @@ pub enum LogMessage {
Error(String), Error(String),
} }
/// Helper function that returns the argument at a specified index.
fn get_arg_at_index<T: FromValue + Default>(args: &[Value], index: usize) -> Option<T> { fn get_arg_at_index<T: FromValue + Default>(args: &[Value], index: usize) -> Option<T> {
args.get(index) args.get(index)
.cloned() .cloned()
.map(|s| from_value::<T>(s).expect("Convert error")) .map(|s| from_value::<T>(s).expect("Convert error"))
} }
/// Helper function for logging messages.
pub fn logger(msg: LogMessage, console_state: &ConsoleState) { pub fn logger(msg: LogMessage, console_state: &ConsoleState) {
let indent = 2 * console_state.groups.len(); let indent = 2 * console_state.groups.len();
@ -60,6 +77,7 @@ pub fn logger(msg: LogMessage, console_state: &ConsoleState) {
} }
} }
/// This represents the `console` formatter.
pub fn formatter(data: &[Value]) -> String { pub fn formatter(data: &[Value]) -> String {
let target = get_arg_at_index::<String>(data, 0).unwrap_or_default(); let target = get_arg_at_index::<String>(data, 0).unwrap_or_default();
match data.len() { match data.len() {
@ -125,7 +143,12 @@ pub fn formatter(data: &[Value]) -> String {
/// Prints a JavaScript value to the standard error if first argument evaluates to `false` or there /// Prints a JavaScript value to the standard error if first argument evaluates to `false` or there
/// were no arguments. /// were no arguments.
/// ///
/// More information: <https://console.spec.whatwg.org/#assert> /// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `console` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#assert
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/assert
pub fn assert(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue { pub fn assert(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
let assertion = get_arg_at_index::<bool>(args, 0).unwrap_or_default(); let assertion = get_arg_at_index::<bool>(args, 0).unwrap_or_default();
@ -153,7 +176,12 @@ pub fn assert(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue
/// ///
/// Removes all groups and clears console if possible. /// Removes all groups and clears console if possible.
/// ///
/// More information: <https://console.spec.whatwg.org/#clear> /// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `console` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#clear
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/clear
pub fn clear(this: &Value, _: &[Value], _: &mut Interpreter) -> ResultValue { pub fn clear(this: &Value, _: &[Value], _: &mut Interpreter) -> ResultValue {
this.with_internal_state_mut(|state: &mut ConsoleState| { this.with_internal_state_mut(|state: &mut ConsoleState| {
state.groups.clear(); state.groups.clear();
@ -166,7 +194,12 @@ pub fn clear(this: &Value, _: &[Value], _: &mut Interpreter) -> ResultValue {
/// ///
/// Prints a JavaScript values with "debug" logLevel. /// Prints a JavaScript values with "debug" logLevel.
/// ///
/// More information: <https://console.spec.whatwg.org/#debug> /// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `console` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#debug
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/debug
pub fn debug(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue { pub fn debug(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
this.with_internal_state_ref(|state| logger(LogMessage::Log(formatter(&args[..])), state)); this.with_internal_state_ref(|state| logger(LogMessage::Log(formatter(&args[..])), state));
Ok(Gc::new(ValueData::Undefined)) Ok(Gc::new(ValueData::Undefined))
@ -176,7 +209,12 @@ pub fn debug(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
/// ///
/// Prints a JavaScript values with "error" logLevel. /// Prints a JavaScript values with "error" logLevel.
/// ///
/// More information: <https://console.spec.whatwg.org/#error> /// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `console` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#error
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/error
pub fn error(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue { pub fn error(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
this.with_internal_state_ref(|state| logger(LogMessage::Error(formatter(&args[..])), state)); this.with_internal_state_ref(|state| logger(LogMessage::Error(formatter(&args[..])), state));
Ok(Gc::new(ValueData::Undefined)) Ok(Gc::new(ValueData::Undefined))
@ -186,7 +224,12 @@ pub fn error(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
/// ///
/// Prints a JavaScript values with "info" logLevel. /// Prints a JavaScript values with "info" logLevel.
/// ///
/// More information: <https://console.spec.whatwg.org/#info> /// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `console` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#info
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/info
pub fn info(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue { pub fn info(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
this.with_internal_state_ref(|state| logger(LogMessage::Info(formatter(&args[..])), state)); this.with_internal_state_ref(|state| logger(LogMessage::Info(formatter(&args[..])), state));
Ok(Gc::new(ValueData::Undefined)) Ok(Gc::new(ValueData::Undefined))
@ -196,7 +239,12 @@ pub fn info(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
/// ///
/// Prints a JavaScript values with "log" logLevel. /// Prints a JavaScript values with "log" logLevel.
/// ///
/// More information: <https://console.spec.whatwg.org/#log> /// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `console` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#log
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/log
pub fn log(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue { pub fn log(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
this.with_internal_state_ref(|state| logger(LogMessage::Log(formatter(&args[..])), state)); this.with_internal_state_ref(|state| logger(LogMessage::Log(formatter(&args[..])), state));
Ok(Gc::new(ValueData::Undefined)) Ok(Gc::new(ValueData::Undefined))
@ -206,7 +254,12 @@ pub fn log(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
/// ///
/// Prints a stack trace with "trace" logLevel, optionally labelled by data. /// Prints a stack trace with "trace" logLevel, optionally labelled by data.
/// ///
/// More information: <https://console.spec.whatwg.org/#trace> /// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `console` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#trace
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/trace
pub fn trace(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue { pub fn trace(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
if !args.is_empty() { if !args.is_empty() {
this.with_internal_state_ref(|state| logger(LogMessage::Log(formatter(&args[..])), state)); this.with_internal_state_ref(|state| logger(LogMessage::Log(formatter(&args[..])), state));
@ -227,7 +280,12 @@ pub fn trace(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
/// ///
/// Prints a JavaScript values with "warn" logLevel. /// Prints a JavaScript values with "warn" logLevel.
/// ///
/// More information: <https://console.spec.whatwg.org/#warn> /// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `console` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#warn
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/warn
pub fn warn(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue { pub fn warn(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
this.with_internal_state_ref(|state| logger(LogMessage::Warn(formatter(&args[..])), state)); this.with_internal_state_ref(|state| logger(LogMessage::Warn(formatter(&args[..])), state));
Ok(Gc::new(ValueData::Undefined)) Ok(Gc::new(ValueData::Undefined))
@ -237,7 +295,12 @@ pub fn warn(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
/// ///
/// Prints number of times the function was called with that particular label. /// Prints number of times the function was called with that particular label.
/// ///
/// More information: <https://console.spec.whatwg.org/#count> /// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `console` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#count
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/count
pub fn count(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue { pub fn count(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
let label = get_arg_at_index::<String>(args, 0).unwrap_or_else(|| "default".to_string()); let label = get_arg_at_index::<String>(args, 0).unwrap_or_else(|| "default".to_string());
@ -256,7 +319,12 @@ pub fn count(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
/// ///
/// Resets the counter for label. /// Resets the counter for label.
/// ///
/// More information: <https://console.spec.whatwg.org/#countreset> /// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `console` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#countreset
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/countReset
pub fn count_reset(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue { pub fn count_reset(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
let label = get_arg_at_index::<String>(args, 0).unwrap_or_else(|| "default".to_string()); let label = get_arg_at_index::<String>(args, 0).unwrap_or_else(|| "default".to_string());
@ -281,7 +349,12 @@ fn system_time_in_ms() -> u128 {
/// ///
/// Starts the timer for given label. /// Starts the timer for given label.
/// ///
/// More information: <https://console.spec.whatwg.org/#time> /// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `console` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#time
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/time
pub fn time(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue { pub fn time(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
let label = get_arg_at_index::<String>(args, 0).unwrap_or_else(|| "default".to_string()); let label = get_arg_at_index::<String>(args, 0).unwrap_or_else(|| "default".to_string());
@ -304,7 +377,12 @@ pub fn time(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
/// ///
/// Prints elapsed time for timer with given label. /// Prints elapsed time for timer with given label.
/// ///
/// More information: <https://console.spec.whatwg.org/#timelog> /// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `console` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#timelog
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/timeLog
pub fn time_log(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue { pub fn time_log(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
let label = get_arg_at_index::<String>(args, 0).unwrap_or_else(|| "default".to_string()); let label = get_arg_at_index::<String>(args, 0).unwrap_or_else(|| "default".to_string());
@ -331,7 +409,12 @@ pub fn time_log(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValu
/// ///
/// Removes the timer with given label. /// Removes the timer with given label.
/// ///
/// More information: <https://console.spec.whatwg.org/#timeend> /// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `console` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#timeend
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/timeEnd
pub fn time_end(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue { pub fn time_end(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
let label = get_arg_at_index::<String>(args, 0).unwrap_or_else(|| "default".to_string()); let label = get_arg_at_index::<String>(args, 0).unwrap_or_else(|| "default".to_string());
@ -357,7 +440,12 @@ pub fn time_end(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValu
/// ///
/// Adds new group with name from formatted data to stack. /// Adds new group with name from formatted data to stack.
/// ///
/// More information: <https://console.spec.whatwg.org/#group> /// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `console` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#group
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/group
pub fn group(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue { pub fn group(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
let group_label = formatter(args); let group_label = formatter(args);
@ -373,7 +461,12 @@ pub fn group(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
/// ///
/// Removes the last group from the stack. /// Removes the last group from the stack.
/// ///
/// More information: <https://console.spec.whatwg.org/#groupend> /// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `console` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#groupend
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/groupEnd
pub fn group_end(this: &Value, _: &[Value], _: &mut Interpreter) -> ResultValue { pub fn group_end(this: &Value, _: &[Value], _: &mut Interpreter) -> ResultValue {
this.with_internal_state_mut(|state: &mut ConsoleState| { this.with_internal_state_mut(|state: &mut ConsoleState| {
state.groups.pop(); state.groups.pop();
@ -386,7 +479,12 @@ pub fn group_end(this: &Value, _: &[Value], _: &mut Interpreter) -> ResultValue
/// ///
/// Prints info about item /// Prints info about item
/// ///
/// More information: <https://console.spec.whatwg.org/#dir> /// More information:
/// - [MDN documentation][mdn]
/// - [WHATWG `console` specification][spec]
///
/// [spec]: https://console.spec.whatwg.org/#dir
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/dir
pub fn dir(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue { pub fn dir(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
this.with_internal_state_mut(|state: &mut ConsoleState| { this.with_internal_state_mut(|state: &mut ConsoleState| {
logger( logger(

28
boa/src/syntax/ast/constant.rs

@ -1,4 +1,11 @@
//! This module implements the `Const` structure, which represents the primitive values in JavaScript. //! This module implements the `Const` structure, which represents the primitive values in JavaScript.
//!
//! More information:
//! - [ECMAScript reference][spec]
//! - [MDN documentation][mdn]
//!
//! [spec]: https://tc39.es/ecma262/#sec-primary-expression-literals
//! [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#Literals
use gc_derive::{Finalize, Trace}; use gc_derive::{Finalize, Trace};
use std::fmt::{Display, Formatter, Result}; use std::fmt::{Display, Formatter, Result};
@ -11,9 +18,10 @@ use serde::{Deserialize, Serialize};
/// These are fixed values **not variables** that you literally provide in your script. /// These are fixed values **not variables** that you literally provide in your script.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-primary-expression-literals) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-primary-expression-literals
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#Literals /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#Literals
#[cfg_attr(feature = "serde-ast", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde-ast", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, Trace, Finalize, PartialEq)] #[derive(Clone, Debug, Trace, Finalize, PartialEq)]
@ -26,9 +34,10 @@ pub enum Const {
/// calls the method, then discards the temporary String object. /// calls the method, then discards the temporary String object.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-terms-and-definitions-string-value) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-terms-and-definitions-string-value
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#String_literals /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#String_literals
String(String), String(String),
@ -38,18 +47,20 @@ pub enum Const {
/// A floating-point literal must have at least one digit, and either a decimal point or "`e`" (or "`E`"). /// A floating-point literal must have at least one digit, and either a decimal point or "`e`" (or "`E`").
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-terms-and-definitions-number-value) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-terms-and-definitions-number-value
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#Floating-point_literals /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#Floating-point_literals
Num(f64), Num(f64),
/// Integer types can be expressed in decimal (base 10), hexadecimal (base 16), octal (base 8) and binary (base 2). /// Integer types can be expressed in decimal (base 10), hexadecimal (base 16), octal (base 8) and binary (base 2).
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-terms-and-definitions-number-value) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-terms-and-definitions-number-value
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#Numeric_literals /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#Numeric_literals
Int(i32), Int(i32),
@ -58,9 +69,10 @@ pub enum Const {
/// The Boolean object is a wrapper around the primitive Boolean data type. /// The Boolean object is a wrapper around the primitive Boolean data type.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-terms-and-definitions-boolean-value) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-terms-and-definitions-boolean-value
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#Boolean_literals /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#Boolean_literals
Bool(bool), Bool(bool),
@ -71,18 +83,20 @@ pub enum Const {
/// The meaning of a null reference varies among language implementations. /// The meaning of a null reference varies among language implementations.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-null-value) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-null-value
/// [mdn]: https://developer.mozilla.org/en-US/docs/Glossary/null /// [mdn]: https://developer.mozilla.org/en-US/docs/Glossary/null
Null, Null,
/// The `undefined` is a primitive value automatically assigned to variables that have just been declared, or to formal arguments for which there are no actual arguments. /// The `undefined` is a primitive value automatically assigned to variables that have just been declared, or to formal arguments for which there are no actual arguments.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-undefined) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-undefined
/// [mdn]: https://developer.mozilla.org/en-US/docs/Glossary/undefined /// [mdn]: https://developer.mozilla.org/en-US/docs/Glossary/undefined
Undefined, Undefined,
} }

118
boa/src/syntax/ast/keyword.rs

@ -1,4 +1,11 @@
//! This module implements the `Keyword` structure, which represents reserved words of the JavaScript language. //! This module implements the `Keyword` structure, which represents reserved words of the JavaScript language.
//!
//! More information:
//! - [ECMAScript reference][spec]
//! - [MDN documentation][mdn]
//!
//! [spec]: https://www.ecma-international.org/ecma-262/#sec-keywords
//! [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Keywords
use std::{ use std::{
error, error,
@ -14,9 +21,10 @@ use serde::{Deserialize, Serialize};
/// In JavaScript you cannot use these reserved words as variables, labels, or function names. /// In JavaScript you cannot use these reserved words as variables, labels, or function names.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://www.ecma-international.org/ecma-262/#sec-keywords) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://www.ecma-international.org/ecma-262/#sec-keywords
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Keywords /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Keywords
#[cfg_attr(feature = "serde-ast", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde-ast", derive(Serialize, Deserialize))]
#[derive(Clone, Copy, PartialEq, Debug)] #[derive(Clone, Copy, PartialEq, Debug)]
@ -24,9 +32,10 @@ pub enum Keyword {
/// The `await` keyword. /// The `await` keyword.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-AwaitExpression) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-AwaitExpression
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await
Await, Await,
@ -34,9 +43,10 @@ pub enum Keyword {
/// ///
/// More information: /// More information:
/// - [break `Node` documentation][node] /// - [break `Node` documentation][node]
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-BreakStatement) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-BreakStatement
/// [node]: ../node/enum.Node.html#variant.Break /// [node]: ../node/enum.Node.html#variant.Break
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/break /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/break
Break, Break,
@ -45,9 +55,10 @@ pub enum Keyword {
/// ///
/// More information: /// More information:
/// - [switch `Node` documentation][node] /// - [switch `Node` documentation][node]
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-CaseClause) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-CaseClause
/// [node]: ../node/enum.Node.html#variant.Switch /// [node]: ../node/enum.Node.html#variant.Switch
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch
Case, Case,
@ -56,9 +67,10 @@ pub enum Keyword {
/// ///
/// More information: /// More information:
/// - [try `Node` documentation][node] /// - [try `Node` documentation][node]
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-Catch) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-Catch
/// [node]: ../node/enum.Node.html#variant.Try /// [node]: ../node/enum.Node.html#variant.Try
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch
Catch, Catch,
@ -66,9 +78,10 @@ pub enum Keyword {
/// The `class` keyword. /// The `class` keyword.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-ClassDeclaration) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-ClassDeclaration
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/class /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/class
Class, Class,
@ -76,9 +89,10 @@ pub enum Keyword {
/// ///
/// More information: /// More information:
/// - [continue `Node` documentation][node] /// - [continue `Node` documentation][node]
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-ContinueStatement) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-ContinueStatement
/// [node]: ../node/enum.Node.html#variant.Continue /// [node]: ../node/enum.Node.html#variant.Continue
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/continue /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/continue
Continue, Continue,
@ -87,9 +101,10 @@ pub enum Keyword {
/// ///
/// More information: /// More information:
/// - [const `Node` documentation][node] /// - [const `Node` documentation][node]
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-let-and-const-declarations) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-let-and-const-declarations
/// [node]: ../node/enum.Node.html#variant.ConstDecl /// [node]: ../node/enum.Node.html#variant.ConstDecl
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const
Const, Const,
@ -97,9 +112,10 @@ pub enum Keyword {
/// The `debugger` keyword. /// The `debugger` keyword.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-debugger-statement) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-debugger-statement
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/debugger /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/debugger
Debugger, Debugger,
@ -107,11 +123,13 @@ pub enum Keyword {
/// ///
/// More information: /// More information:
/// - [switch `Node` documentation][node] /// - [switch `Node` documentation][node]
/// - [ECMAScript reference default clause](https://tc39.es/ecma262/#prod-DefaultClause) /// - [ECMAScript reference default clause][spec-clause]
/// - [ECMAScript reference default export](https://tc39.es/ecma262/#prod-ImportedDefaultBinding) /// - [ECMAScript reference default export][spec-export]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [node]: ../node/enum.Node.html#variant.Switch /// [node]: ../node/enum.Node.html#variant.Switch
/// [spec-clause]: https://tc39.es/ecma262/#prod-DefaultClause
/// [spec-export]: https://tc39.es/ecma262/#prod-ImportedDefaultBinding
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/default /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/default
Default, Default,
@ -119,9 +137,10 @@ pub enum Keyword {
/// ///
/// More information: /// More information:
/// - [delete `UnaryOp` documentation][unary] /// - [delete `UnaryOp` documentation][unary]
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-delete-operator) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-delete-operator
/// [unary]: ../op/enum.UnaryOp.html#variant.Delete /// [unary]: ../op/enum.UnaryOp.html#variant.Delete
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete
Delete, Delete,
@ -129,9 +148,10 @@ pub enum Keyword {
/// The `do` keyword. /// The `do` keyword.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-do-while-statement) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-do-while-statement
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/do...while /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/do...while
Do, Do,
@ -139,10 +159,11 @@ pub enum Keyword {
/// ///
/// More information: /// More information:
/// - [if `Node` documentation][node] /// - [if `Node` documentation][node]
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-IfStatement) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [node]: ../node/enum.Node.html#variant.If /// [node]: ../node/enum.Node.html#variant.If
/// [spec]: https://tc39.es/ecma262/#prod-IfStatement
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else
Else, Else,
@ -154,18 +175,20 @@ pub enum Keyword {
/// The `export` keyword. /// The `export` keyword.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-exports) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-exports
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export
Export, Export,
/// The `extends` keyword. /// The `extends` keyword.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-ClassHeritage) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-ClassHeritage
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/extends /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/extends
Extends, Extends,
@ -173,10 +196,11 @@ pub enum Keyword {
/// ///
/// More information: /// More information:
/// - [try `Node` documentation][node] /// - [try `Node` documentation][node]
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-Finally) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [node]: ../node/enum.Node.html#variant.Try /// [node]: ../node/enum.Node.html#variant.Try
/// [spec]: https://tc39.es/ecma262/#prod-Finally
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch
Finally, Finally,
@ -184,10 +208,11 @@ pub enum Keyword {
/// ///
/// More information: /// More information:
/// - [for loop `Node` documentation][node] /// - [for loop `Node` documentation][node]
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-ForDeclaration) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [node]: ../node/enum.Node.html#variant.ForLoop /// [node]: ../node/enum.Node.html#variant.ForLoop
/// [spec]: https://tc39.es/ecma262/#prod-ForDeclaration
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for
For, For,
@ -195,10 +220,11 @@ pub enum Keyword {
/// ///
/// More information: /// More information:
/// - [function `Node` documentation][node] /// - [function `Node` documentation][node]
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-terms-and-definitions-function) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [node]: ../node/enum.Node.html#variant.FunctionDecl /// [node]: ../node/enum.Node.html#variant.FunctionDecl
/// [spec]: https://tc39.es/ecma262/#sec-terms-and-definitions-function
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function
Function, Function,
@ -206,37 +232,41 @@ pub enum Keyword {
/// ///
/// More information: /// More information:
/// - [if `Node` documentation][node] /// - [if `Node` documentation][node]
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-IfStatement) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [node]: ../node/enum.Node.html#variant.If /// [node]: ../node/enum.Node.html#variant.If
/// [spec]: https://tc39.es/ecma262/#prod-IfStatement
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else
If, If,
/// The `in` keyword. /// The `in` keyword.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-RelationalExpression) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-RelationalExpression
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/in /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/in
In, In,
/// The `instanceof` keyword. /// The `instanceof` keyword.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-instanceofoperator) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-instanceofoperator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof
InstanceOf, InstanceOf,
/// The `import` keyword. /// The `import` keyword.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-imports) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-imports
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
Import, Import,
@ -244,10 +274,11 @@ pub enum Keyword {
/// ///
/// More information: /// More information:
/// - [let `Node` documentation][node] /// - [let `Node` documentation][node]
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-let-and-const-declarations) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [node]: ../node/enum.Node.html#variant.LetDecl /// [node]: ../node/enum.Node.html#variant.LetDecl
/// [spec]: https://tc39.es/ecma262/#sec-let-and-const-declarations
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let
Let, Let,
@ -255,10 +286,11 @@ pub enum Keyword {
/// ///
/// More information: /// More information:
/// - [new `Node` documentation][node] /// - [new `Node` documentation][node]
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-NewExpression) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [node]: ../node/enum.Node.html#variant.New /// [node]: ../node/enum.Node.html#variant.New
/// [spec]: https://tc39.es/ecma262/#prod-NewExpression
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new
New, New,
@ -266,19 +298,21 @@ pub enum Keyword {
/// ///
/// More information: /// More information:
/// - [return `Node` documentation][node] /// - [return `Node` documentation][node]
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-ReturnStatement) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [node]: ../node/enum.Node.html#variant.Return /// [node]: ../node/enum.Node.html#variant.Return
/// [spec]: https://tc39.es/ecma262/#prod-ReturnStatement
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return
Return, Return,
/// The `super` keyword /// The `super` keyword
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-super-keyword) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-super-keyword
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/super /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/super
Super, Super,
@ -286,10 +320,11 @@ pub enum Keyword {
/// ///
/// More information: /// More information:
/// - [switch `Node` documentation][node] /// - [switch `Node` documentation][node]
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-SwitchStatement) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [node]: ../node/enum.Node.html#variant.Switch /// [node]: ../node/enum.Node.html#variant.Switch
/// [spec]: https://tc39.es/ecma262/#prod-SwitchStatement
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch
Switch, Switch,
@ -297,10 +332,11 @@ pub enum Keyword {
/// ///
/// More information: /// More information:
/// - [this `Node` documentation][node] /// - [this `Node` documentation][node]
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-this-keyword) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [node]: ../node/enum.Node.html#variant.This /// [node]: ../node/enum.Node.html#variant.This
/// [spec]: https://tc39.es/ecma262/#sec-this-keyword
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this
This, This,
@ -308,10 +344,11 @@ pub enum Keyword {
/// ///
/// More information: /// More information:
/// - [throw `Node` documentation][node] /// - [throw `Node` documentation][node]
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-ArrowFunction) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [node]: ../node/enum.Node.html#variant.Throw /// [node]: ../node/enum.Node.html#variant.Throw
/// [spec]: https://tc39.es/ecma262/#prod-ArrowFunction
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions
Throw, Throw,
@ -319,10 +356,11 @@ pub enum Keyword {
/// ///
/// More information: /// More information:
/// - [try `Node` documentation][node] /// - [try `Node` documentation][node]
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-TryStatement) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [node]: ../node/enum.Node.html#variant.Try /// [node]: ../node/enum.Node.html#variant.Try
/// [spec]: https://tc39.es/ecma262/#prod-TryStatement
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch
Try, Try,
@ -330,10 +368,11 @@ pub enum Keyword {
/// ///
/// More information: /// More information:
/// - [typeof `UnaryOp` documentation][unary] /// - [typeof `UnaryOp` documentation][unary]
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-typeof-operator) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [unary]: ../op/enum.UnaryOp.html#variant.TypeOf /// [unary]: ../op/enum.UnaryOp.html#variant.TypeOf
/// [spec]: https://tc39.es/ecma262/#sec-typeof-operator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof
TypeOf, TypeOf,
@ -341,10 +380,11 @@ pub enum Keyword {
/// ///
/// More information: /// More information:
/// - [var `Node` documentation][node] /// - [var `Node` documentation][node]
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-VariableStatement) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [node]: ../node/enum.Node.html#variant.VarDecl /// [node]: ../node/enum.Node.html#variant.VarDecl
/// [spec]: https://tc39.es/ecma262/#prod-VariableStatement
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var
Var, Var,
@ -352,10 +392,11 @@ pub enum Keyword {
/// ///
/// More information: /// More information:
/// - [void `UnaryOp` documentation][unary] /// - [void `UnaryOp` documentation][unary]
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-void-operator) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [unary]: ../op/enum.UnaryOp.html#variant.Void /// [unary]: ../op/enum.UnaryOp.html#variant.Void
/// [spec]: https://tc39.es/ecma262/#sec-void-operator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void
Void, Void,
@ -363,28 +404,31 @@ pub enum Keyword {
/// ///
/// More information: /// More information:
/// - [while `Node` documentation][node] /// - [while `Node` documentation][node]
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-grammar-notation-WhileStatement) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [node]: ../node/enum.Node.html#variant.While /// [node]: ../node/enum.Node.html#variant.While
/// [spec]: https://tc39.es/ecma262/#prod-grammar-notation-WhileStatement
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/while /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/while
While, While,
/// The `with` keyword. /// The `with` keyword.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-WithStatement) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-WithStatement
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/with /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/with
With, With,
/// The 'yield' keyword. /// The 'yield' keyword.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-YieldExpression) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-YieldExpression
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/yield /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/yield
Yield, Yield,
} }

2
boa/src/syntax/ast/mod.rs

@ -1,3 +1,5 @@
//! The Javascript Abstract Syntax Tree.
pub mod constant; pub mod constant;
pub mod keyword; pub mod keyword;
pub mod node; pub mod node;

148
boa/src/syntax/ast/node.rs

@ -23,9 +23,10 @@ pub enum Node {
/// In JavaScript, arrays start at index zero and can be manipulated with various methods. /// In JavaScript, arrays start at index zero and can be manipulated with various methods.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-ArrayLiteral) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-ArrayLiteral
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
ArrayDecl(Vec<Node>), ArrayDecl(Vec<Node>),
@ -35,9 +36,10 @@ pub enum Node {
/// Arrow functions cannot be used as constructors and will throw an error when used with new. /// Arrow functions cannot be used as constructors and will throw an error when used with new.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-ArrowFunction) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-ArrowFunction
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions
ArrowFunctionDecl(Vec<FormalParameter>, Box<Node>), ArrowFunctionDecl(Vec<FormalParameter>, Box<Node>),
@ -46,9 +48,10 @@ pub enum Node {
/// Assignment operator (`=`), assigns the value of its right operand to its left operand. /// Assignment operator (`=`), assigns the value of its right operand to its left operand.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-AssignmentExpression) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-AssignmentExpression
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators
Assign(Box<Node>, Box<Node>), Assign(Box<Node>, Box<Node>),
@ -68,9 +71,10 @@ pub enum Node {
/// where you provide no statement, although one is required. /// where you provide no statement, although one is required.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-BlockStatement) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-BlockStatement
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/block /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/block
Block(Vec<Node>), Block(Vec<Node>),
@ -81,9 +85,10 @@ pub enum Node {
/// it does not have to be preceded by a loop statement. /// it does not have to be preceded by a loop statement.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-BreakStatement) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-BreakStatement
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/break /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/break
Break(Option<String>), Break(Option<String>),
@ -94,9 +99,10 @@ pub enum Node {
/// The scope of a function is the function in which it is declared (or the entire program, if it is declared at the top level). /// The scope of a function is the function in which it is declared (or the entire program, if it is declared at the top level).
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-CallExpression) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-CallExpression
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions#Calling_functions /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions#Calling_functions
Call(Box<Node>, Vec<Node>), Call(Box<Node>, Vec<Node>),
@ -107,9 +113,10 @@ pub enum Node {
/// This operator is frequently used as a shortcut for the `if` statement. /// This operator is frequently used as a shortcut for the `if` statement.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-ConditionalExpression) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-ConditionalExpression
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#Literals /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#Literals
ConditionalOp(Box<Node>, Box<Node>, Box<Node>), ConditionalOp(Box<Node>, Box<Node>, Box<Node>),
@ -118,9 +125,10 @@ pub enum Node {
/// These are fixed values **not variables** that you literally provide in your script. /// These are fixed values **not variables** that you literally provide in your script.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-primary-expression-literals) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-primary-expression-literals
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#Literals /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#Literals
Const(Const), Const(Const),
@ -133,9 +141,10 @@ pub enum Node {
/// (This makes sense, given that it can't be changed later.) /// (This makes sense, given that it can't be changed later.)
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-let-and-const-declarations) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-let-and-const-declarations
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const
/// [identifier]: https://developer.mozilla.org/en-US/docs/Glossary/identifier /// [identifier]: https://developer.mozilla.org/en-US/docs/Glossary/identifier
/// [expression]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Expressions /// [expression]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Expressions
@ -148,13 +157,23 @@ pub enum Node {
/// loop statement instead of the current loop. In this case, the continue statement needs to be nested within this labeled statement. /// loop statement instead of the current loop. In this case, the continue statement needs to be nested within this labeled statement.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-ContinueStatement) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-ContinueStatement
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/continue /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/continue
Continue(Option<String>), Continue(Option<String>),
/// do [body] while [cond] /// The **`do...while` statement** creates a loop that executes a specified statement until the test condition evaluates to false.
///
/// The condition is evaluated after executing the statement, resulting in the specified statement executing at least once.
///
/// More information:
/// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn]
///
/// [spec]: https://tc39.es/ecma262/#sec-do-while-statement
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/do...while
DoWhileLoop(Box<Node>, Box<Node>), DoWhileLoop(Box<Node>, Box<Node>),
/// The **`function` declaration** (function statement) defines a function with the specified parameters. /// The **`function` declaration** (function statement) defines a function with the specified parameters.
@ -166,9 +185,10 @@ pub enum Node {
/// By default, functions return undefined. To return any other value, the function must have a return statement that specifies the value to return. /// By default, functions return undefined. To return any other value, the function must have a return statement that specifies the value to return.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-terms-and-definitions-function) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-terms-and-definitions-function
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function
FunctionDecl(Option<String>, Vec<FormalParameter>, Box<Node>), FunctionDecl(Option<String>, Vec<FormalParameter>, Box<Node>),
@ -186,9 +206,10 @@ pub enum Node {
/// if it has a reference to a Function instance as its value). /// if it has a reference to a Function instance as its value).
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-property-accessors) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-property-accessors
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors#Dot_notation /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors#Dot_notation
GetConstField(Box<Node>, String), GetConstField(Box<Node>, String),
@ -204,9 +225,10 @@ pub enum Node {
/// if it has a reference to a Function instance as its value). /// if it has a reference to a Function instance as its value).
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-property-accessors) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-property-accessors
/// [symbol]: https://developer.mozilla.org/en-US/docs/Glossary/Symbol /// [symbol]: https://developer.mozilla.org/en-US/docs/Glossary/Symbol
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors#Bracket_notation /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors#Bracket_notation
GetField(Box<Node>, Box<Node>), GetField(Box<Node>, Box<Node>),
@ -217,9 +239,10 @@ pub enum Node {
/// The JavaScript for loop is similar to the Java and C for loop. /// The JavaScript for loop is similar to the Java and C for loop.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-ForDeclaration) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-ForDeclaration
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for
ForLoop( ForLoop(
Option<Box<Node>>, Option<Box<Node>>,
@ -235,9 +258,10 @@ pub enum Node {
/// **Note** that there is no elseif (in one word) keyword in JavaScript. /// **Note** that there is no elseif (in one word) keyword in JavaScript.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-IfStatement) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-IfStatement
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else
/// [truthy]: https://developer.mozilla.org/en-US/docs/Glossary/truthy /// [truthy]: https://developer.mozilla.org/en-US/docs/Glossary/truthy
/// [falsy]: https://developer.mozilla.org/en-US/docs/Glossary/falsy /// [falsy]: https://developer.mozilla.org/en-US/docs/Glossary/falsy
@ -253,9 +277,10 @@ pub enum Node {
/// Just like const the `let` does not create properties of the window object when declared globally (in the top-most scope). /// Just like const the `let` does not create properties of the window object when declared globally (in the top-most scope).
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-let-and-const-declarations) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-let-and-const-declarations
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let
LetDecl(Vec<(String, Option<Node>)>), LetDecl(Vec<(String, Option<Node>)>),
@ -267,9 +292,10 @@ pub enum Node {
/// to convert identifiers to strings, but sometimes it is possible to parse strings into identifiers. /// to convert identifiers to strings, but sometimes it is possible to parse strings into identifiers.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-Identifier) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-Identifier
/// [mdn]: https://developer.mozilla.org/en-US/docs/Glossary/Identifier /// [mdn]: https://developer.mozilla.org/en-US/docs/Glossary/Identifier
Local(String), Local(String),
@ -282,9 +308,10 @@ pub enum Node {
/// - Returns this if the function doesn't return its own object. /// - Returns this if the function doesn't return its own object.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-NewExpression) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-NewExpression
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new
New(Box<Node>), New(Box<Node>),
@ -297,9 +324,10 @@ pub enum Node {
/// contain [`primitive`][primitive] data types or other objects. /// contain [`primitive`][primitive] data types or other objects.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-ObjectLiteral) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-ObjectLiteral
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer
/// [object]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object /// [object]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object
/// [primitive]: https://developer.mozilla.org/en-US/docs/Glossary/primitive /// [primitive]: https://developer.mozilla.org/en-US/docs/Glossary/primitive
@ -316,9 +344,10 @@ pub enum Node {
/// If specified, a given value is returned to the function caller. /// If specified, a given value is returned to the function caller.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-ReturnStatement) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-ReturnStatement
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return
Return(Option<Box<Node>>), Return(Option<Box<Node>>),
@ -331,9 +360,10 @@ pub enum Node {
/// the cases are not equal to each other.) /// the cases are not equal to each other.)
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-SwitchStatement) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-SwitchStatement
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch
Switch(Box<Node>, Vec<(Node, Vec<Node>)>, Option<Box<Node>>), Switch(Box<Node>, Vec<(Node, Vec<Node>)>, Option<Box<Node>>),
@ -345,16 +375,19 @@ pub enum Node {
/// are expected, or an object expression to be expanded in places where zero or more key-value pairs (for object literals) are expected. /// are expected, or an object expression to be expanded in places where zero or more key-value pairs (for object literals) are expected.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-SpreadElement) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-SpreadElement
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax
Spread(Box<Node>), Spread(Box<Node>),
/// Similar to `Node::Block` but without the braces /// Similar to `Node::Block` but without the braces
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-StatementList) /// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#prod-StatementList
StatementList(Vec<Node>), StatementList(Vec<Node>),
/// The **`throw` statement** throws a user-defined exception. /// The **`throw` statement** throws a user-defined exception.
@ -366,9 +399,10 @@ pub enum Node {
/// caller functions, the program will terminate. /// caller functions, the program will terminate.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-ThrowStatement) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-ThrowStatement
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/throw /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/throw
Throw(Box<Node>), Throw(Box<Node>),
@ -379,9 +413,10 @@ pub enum Node {
/// Returns a string indicating the type of the unevaluated operand. /// Returns a string indicating the type of the unevaluated operand.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-typeof-operator) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-typeof-operator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof
TypeOf(Box<Node>), TypeOf(Box<Node>),
@ -391,9 +426,10 @@ pub enum Node {
/// even for single statements. At least one `catch`-block, or a `finally`-block, must be present. /// even for single statements. At least one `catch`-block, or a `finally`-block, must be present.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-TryStatement) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-TryStatement
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch
Try( Try(
Box<Node>, Box<Node>,
@ -409,18 +445,20 @@ pub enum Node {
/// mode can be any value. /// mode can be any value.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-this-keyword) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-this-keyword
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this
This, This,
/// A unary operation is an operation with only one operand. /// A unary operation is an operation with only one operand.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-UnaryExpression) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-UnaryExpression
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Unary_operators /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Unary_operators
UnaryOp(UnaryOp, Box<Node>), UnaryOp(UnaryOp, Box<Node>),
@ -435,9 +473,10 @@ pub enum Node {
/// (it becomes a property of the global object) when the assignment is executed. /// (it becomes a property of the global object) when the assignment is executed.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-VariableStatement) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-VariableStatement
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var
VarDecl(Vec<(String, Option<Node>)>), VarDecl(Vec<(String, Option<Node>)>),
@ -446,9 +485,10 @@ pub enum Node {
/// The condition is evaluated before executing the statement. /// The condition is evaluated before executing the statement.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-grammar-notation-WhileStatement) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-grammar-notation-WhileStatement
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/while /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/while
WhileLoop(Box<Node>, Box<Node>), WhileLoop(Box<Node>, Box<Node>),
} }
@ -460,6 +500,7 @@ impl Operator for Node {
_ => true, _ => true,
} }
} }
fn get_precedence(&self) -> u64 { fn get_precedence(&self) -> u64 {
match self { match self {
Node::GetField(_, _) | Node::GetConstField(_, _) => 1, Node::GetField(_, _) | Node::GetConstField(_, _) => 1,
@ -694,11 +735,17 @@ fn join_nodes(f: &mut fmt::Formatter<'_>, nodes: &[Node]) -> fmt::Result {
/// ///
/// In the declaration of a function, the parameters must be identifiers, /// In the declaration of a function, the parameters must be identifiers,
/// not any value like numbers, strings, or objects. /// not any value like numbers, strings, or objects.
///```javascript ///```text
///function foo(formalParametar1, formalParametar2) { ///function foo(formalParametar1, formalParametar2) {
///} ///}
///``` ///```
/// For more information, please check <https://tc39.es/ecma262/#prod-FormalParameter> ///
/// More information:
/// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn]
///
/// [spec]: https://tc39.es/ecma262/#prod-FormalParameter
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Missing_formal_parameter
#[cfg_attr(feature = "serde-ast", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde-ast", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, PartialEq, Trace, Finalize)] #[derive(Clone, Debug, PartialEq, Trace, Finalize)]
pub struct FormalParameter { pub struct FormalParameter {
@ -707,7 +754,13 @@ pub struct FormalParameter {
pub is_rest_param: bool, pub is_rest_param: bool,
} }
/// <https://tc39.es/ecma262/#prod-FormalParameters> /// A sequence of `FormalParameter`.
///
/// More information:
/// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn]
///
/// [spec]: https://tc39.es/ecma262/#prod-FormalParameters
pub type FormalParameters = Vec<FormalParameter>; pub type FormalParameters = Vec<FormalParameter>;
impl FormalParameter { impl FormalParameter {
@ -727,9 +780,10 @@ impl FormalParameter {
/// This distinction matters because the original referenced object remains unchanged when you change the property's value. /// This distinction matters because the original referenced object remains unchanged when you change the property's value.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-PropertyDefinition) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-PropertyDefinition
/// [mdn]: https://developer.mozilla.org/en-US/docs/Glossary/property/JavaScript /// [mdn]: https://developer.mozilla.org/en-US/docs/Glossary/property/JavaScript
// TODO: Support all features: https://tc39.es/ecma262/#prod-PropertyDefinition // TODO: Support all features: https://tc39.es/ecma262/#prod-PropertyDefinition
#[cfg_attr(feature = "serde-ast", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde-ast", derive(Serialize, Deserialize))]
@ -738,27 +792,30 @@ pub enum PropertyDefinition {
/// Puts a variable into an object. /// Puts a variable into an object.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-IdentifierReference) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-IdentifierReference
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#Property_definitions /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#Property_definitions
IdentifierReference(String), IdentifierReference(String),
/// Binds a property name to a JavaScript value. /// Binds a property name to a JavaScript value.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-PropertyDefinition) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-PropertyDefinition
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#Property_definitions /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#Property_definitions
Property(String, Node), Property(String, Node),
/// A property of an object can also refer to a function or a getter or setter method. /// A property of an object can also refer to a function or a getter or setter method.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-MethodDefinition) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-MethodDefinition
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#Method_definitions /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#Method_definitions
MethodDefinition(MethodDefinitionKind, String, Node), MethodDefinition(MethodDefinitionKind, String, Node),
@ -768,9 +825,10 @@ pub enum PropertyDefinition {
/// Shallow-cloning (excluding `prototype`) or merging objects is now possible using a shorter syntax than `Object.assign()`. /// Shallow-cloning (excluding `prototype`) or merging objects is now possible using a shorter syntax than `Object.assign()`.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-PropertyDefinition) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-PropertyDefinition
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#Spread_properties /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#Spread_properties
SpreadObject(Node), SpreadObject(Node),
} }
@ -781,9 +839,10 @@ pub enum PropertyDefinition {
/// It is a shorthand for a function assigned to the method's name. /// It is a shorthand for a function assigned to the method's name.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-MethodDefinition) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-MethodDefinition
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Method_definitions /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Method_definitions
#[cfg_attr(feature = "serde-ast", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde-ast", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, PartialEq, Trace, Finalize)] #[derive(Clone, Debug, PartialEq, Trace, Finalize)]
@ -798,9 +857,10 @@ pub enum MethodDefinitionKind {
/// although it is possible to use a getter and a setter in conjunction to create a type of pseudo-property. /// although it is possible to use a getter and a setter in conjunction to create a type of pseudo-property.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-MethodDefinition) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-MethodDefinition
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get
Get, Get,
@ -811,18 +871,20 @@ pub enum MethodDefinitionKind {
/// It is not possible to simultaneously have a setter on a property that holds an actual value. /// It is not possible to simultaneously have a setter on a property that holds an actual value.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-MethodDefinition) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-MethodDefinition
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/set /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/set
Set, Set,
/// Starting with ECMAScript 2015, you are able to define own methods in a shorter syntax, similar to the getters and setters. /// Starting with ECMAScript 2015, you are able to define own methods in a shorter syntax, similar to the getters and setters.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-MethodDefinition) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-MethodDefinition
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions#Method_definition_syntax /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions#Method_definition_syntax
Ordinary, Ordinary,
// TODO: support other method definition kinds, like `Generator`. // TODO: support other method definition kinds, like `Generator`.

144
boa/src/syntax/ast/op.rs

@ -33,9 +33,10 @@ pub enum NumOp {
/// Syntax: `x + y` /// Syntax: `x + y`
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-addition-operator-plus). /// - [ECMAScript reference][spec].
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-addition-operator-plus
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Addition /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Addition
Add, Add,
@ -44,9 +45,10 @@ pub enum NumOp {
/// Syntax: `x - y` /// Syntax: `x - y`
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-subtraction-operator-minus). /// - [ECMAScript reference][spec].
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-subtraction-operator-minus
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Subtraction /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Subtraction
Sub, Sub,
@ -56,9 +58,10 @@ pub enum NumOp {
/// Syntax: `x / y` /// Syntax: `x / y`
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-MultiplicativeOperator) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-MultiplicativeOperator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Division /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Division
Div, Div,
@ -67,9 +70,10 @@ pub enum NumOp {
/// Syntax: `x * y` /// Syntax: `x * y`
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-MultiplicativeExpression) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-MultiplicativeExpression
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Multiplication /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Multiplication
Mul, Mul,
@ -81,9 +85,10 @@ pub enum NumOp {
/// The exponentiation operator is right-associative. a ** b ** c is equal to a ** (b ** c). /// The exponentiation operator is right-associative. a ** b ** c is equal to a ** (b ** c).
/// ///
/// More information: /// More information:
/// - [ECMAScript reference]: <https://tc39.es/ecma262/#sec-exp-operator>. /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-exp-operator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Exponentiation /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Exponentiation
Exp, Exp,
@ -94,9 +99,10 @@ pub enum NumOp {
/// The remainder operator always takes the sign of the dividend. /// The remainder operator always takes the sign of the dividend.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-MultiplicativeOperator) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-MultiplicativeOperator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Remainder /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Remainder
Mod, Mod,
} }
@ -125,9 +131,10 @@ impl Display for NumOp {
/// function calls. /// function calls.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-UnaryExpression) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-UnaryExpression
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Unary /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Unary
#[cfg_attr(feature = "serde-ast", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde-ast", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, Trace, Finalize, PartialEq)] #[derive(Clone, Debug, Trace, Finalize, PartialEq)]
@ -139,9 +146,10 @@ pub enum UnaryOp {
/// This operator increments and returns the value after incrementing. /// This operator increments and returns the value after incrementing.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-postfix-increment-operator) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-postfix-increment-operator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Increment /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Increment
IncrementPost, IncrementPost,
@ -152,9 +160,10 @@ pub enum UnaryOp {
/// This operator increments and returns the value before incrementing. /// This operator increments and returns the value before incrementing.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-prefix-increment-operator) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-prefix-increment-operator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Increment /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Increment
IncrementPre, IncrementPre,
@ -165,9 +174,10 @@ pub enum UnaryOp {
/// This operator decrements and returns the value before decrementing. /// This operator decrements and returns the value before decrementing.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-postfix-decrement-operator) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-postfix-decrement-operator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Decrement /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Decrement
DecrementPost, DecrementPost,
@ -178,9 +188,10 @@ pub enum UnaryOp {
/// This operator decrements the operand and returns the value after decrementing. /// This operator decrements the operand and returns the value after decrementing.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-prefix-decrement-operator) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-prefix-decrement-operator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Decrement /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Decrement
DecrementPre, DecrementPre,
@ -192,9 +203,10 @@ pub enum UnaryOp {
/// however, it performs an additional operation, negation. /// however, it performs an additional operation, negation.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-unary-minus-operator) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-unary-minus-operator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Unary_negation /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Unary_negation
Minus, Minus,
@ -207,9 +219,10 @@ pub enum UnaryOp {
/// It can convert `string` representations of integers and floats, as well as the non-string values `true`, `false`, and `null`. /// It can convert `string` representations of integers and floats, as well as the non-string values `true`, `false`, and `null`.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-unary-plus-operator) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-unary-plus-operator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Unary_plus /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Unary_plus
Plus, Plus,
@ -223,9 +236,10 @@ pub enum UnaryOp {
/// force the conversion of any value to the corresponding boolean primitive. /// force the conversion of any value to the corresponding boolean primitive.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-logical-not-operator) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-logical-not-operator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators#Logical_NOT /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators#Logical_NOT
Not, Not,
@ -237,9 +251,10 @@ pub enum UnaryOp {
/// Bitwise NOTing any number x yields -(x + 1). For example, ~-5 yields 4. /// Bitwise NOTing any number x yields -(x + 1). For example, ~-5 yields 4.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-bitwise-not-operator) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-bitwise-not-operator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Bitwise_NOT /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Bitwise_NOT
Tilde, Tilde,
@ -252,9 +267,10 @@ pub enum UnaryOp {
/// There are other uses as well. /// There are other uses as well.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-typeof-operator) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-typeof-operator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof
TypeOf, TypeOf,
@ -272,9 +288,10 @@ pub enum UnaryOp {
/// property, in which case, `false` is returned in non-strict mode. /// property, in which case, `false` is returned in non-strict mode.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-delete-operator) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-delete-operator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete
Delete, Delete,
@ -291,9 +308,10 @@ pub enum UnaryOp {
/// `void` can be used to force the function keyword to be treated as an expression instead of a declaration. /// `void` can be used to force the function keyword to be treated as an expression instead of a declaration.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-void-operator) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-void-operator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void
Void, Void,
} }
@ -333,9 +351,10 @@ pub enum BitOp {
/// Syntax: `x & y` /// Syntax: `x & y`
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-BitwiseANDExpression) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-BitwiseANDExpression
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Bitwise_AND /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Bitwise_AND
And, And,
@ -344,9 +363,10 @@ pub enum BitOp {
/// Syntax: `x | y` /// Syntax: `x | y`
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-BitwiseORExpression) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-BitwiseORExpression
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Bitwise_OR /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Bitwise_OR
Or, Or,
@ -355,9 +375,10 @@ pub enum BitOp {
/// Syntax: `x ^ y` /// Syntax: `x ^ y`
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-BitwiseXORExpression) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-BitwiseXORExpression
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Bitwise_XOR /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Bitwise_XOR
Xor, Xor,
@ -368,9 +389,10 @@ pub enum BitOp {
/// Excess bits shifted off to the left are discarded. Zero bits are shifted in from the right. /// Excess bits shifted off to the left are discarded. Zero bits are shifted in from the right.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-left-shift-operator) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-left-shift-operator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Left_shift /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Left_shift
Shl, Shl,
@ -384,9 +406,10 @@ pub enum BitOp {
/// Hence the name "sign-propagating". /// Hence the name "sign-propagating".
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-signed-right-shift-operator) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-signed-right-shift-operator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Right_shift /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Right_shift
Shr, Shr,
@ -399,9 +422,10 @@ pub enum BitOp {
/// Unlike the other bitwise operators, zero-fill right shift returns an unsigned 32-bit integer. /// Unlike the other bitwise operators, zero-fill right shift returns an unsigned 32-bit integer.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-unsigned-right-shift-operator) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-unsigned-right-shift-operator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Unsigned_right_shift /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Unsigned_right_shift
UShr, UShr,
} }
@ -433,9 +457,10 @@ impl Display for BitOp {
/// to compatible types before checking equality. /// to compatible types before checking equality.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](tc39.es/ecma262/#sec-testing-and-comparison-operations) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: tc39.es/ecma262/#sec-testing-and-comparison-operations
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Comparison /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Comparison
#[cfg_attr(feature = "serde-ast", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde-ast", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, Trace, Finalize, PartialEq)] #[derive(Clone, Debug, Trace, Finalize, PartialEq)]
@ -448,9 +473,10 @@ pub enum CompOp {
/// refer to the same object in memory. /// refer to the same object in memory.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-abstract-equality-comparison) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-abstract-equality-comparison
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Equality /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Equality
Equal, Equal,
@ -463,9 +489,10 @@ pub enum CompOp {
/// internal references which are not equal when operands refer to different objects in memory. /// internal references which are not equal when operands refer to different objects in memory.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-EqualityExpression) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-EqualityExpression
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Inequality /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Inequality
NotEqual, NotEqual,
@ -476,9 +503,10 @@ pub enum CompOp {
/// Returns `true` if the operands are equal and of the same type. /// Returns `true` if the operands are equal and of the same type.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-strict-equality-comparison) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-strict-equality-comparison
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Identity /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Identity
StrictEqual, StrictEqual,
@ -489,9 +517,10 @@ pub enum CompOp {
/// Returns `true` if the operands are of the same type but not equal, or are of different type. /// Returns `true` if the operands are of the same type but not equal, or are of different type.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-EqualityExpression) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-EqualityExpression
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Nonidentity> /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Nonidentity>
StrictNotEqual, StrictNotEqual,
@ -502,9 +531,10 @@ pub enum CompOp {
/// Returns `true` if the left operand is greater than the right operand. /// Returns `true` if the left operand is greater than the right operand.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-RelationalExpression) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-RelationalExpression
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Greater_than_operator /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Greater_than_operator
GreaterThan, GreaterThan,
@ -515,9 +545,10 @@ pub enum CompOp {
/// Returns `true` if the left operand is greater than the right operand. /// Returns `true` if the left operand is greater than the right operand.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-RelationalExpression) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-RelationalExpression
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Greater_than_operator /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Greater_than_operator
GreaterThanOrEqual, GreaterThanOrEqual,
@ -528,9 +559,10 @@ pub enum CompOp {
/// Returns `true` if the left operand is less than the right operand. /// Returns `true` if the left operand is less than the right operand.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-RelationalExpression) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-RelationalExpression
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Less_than_operator /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Less_than_operator
LessThan, LessThan,
@ -541,9 +573,10 @@ pub enum CompOp {
/// Returns `true` if the left operand is less than or equal to the right operand. /// Returns `true` if the left operand is less than or equal to the right operand.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-RelationalExpression) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-RelationalExpression
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Less_than_or_equal_operator /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Less_than_or_equal_operator
LessThanOrEqual, LessThanOrEqual,
} }
@ -573,9 +606,10 @@ impl Display for CompOp {
/// so if these operators are used with non-Boolean values, they may return a non-Boolean value. /// so if these operators are used with non-Boolean values, they may return a non-Boolean value.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-binary-logical-operators) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-binary-logical-operators
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Logical /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Logical
#[cfg_attr(feature = "serde-ast", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde-ast", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, Trace, Finalize, PartialEq)] #[derive(Clone, Debug, Trace, Finalize, PartialEq)]
@ -586,9 +620,10 @@ pub enum LogOp {
/// Syntax: `x && y` /// Syntax: `x && y`
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-LogicalANDExpression) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-LogicalANDExpression
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators#Logical_AND /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators#Logical_AND
And, And,
@ -598,9 +633,10 @@ pub enum LogOp {
/// Syntax: `x || y` /// Syntax: `x || y`
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-LogicalORExpression) /// - [ECMAScript reference](
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-LogicalORExpression)
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators#Logical_OR /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators#Logical_OR
Or, Or,
} }
@ -700,9 +736,10 @@ impl Display for BinOp {
/// There are also compound assignment operators that are shorthand for the operations /// There are also compound assignment operators that are shorthand for the operations
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-AssignmentOperator) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-AssignmentOperator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Assignment /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Assignment
#[cfg_attr(feature = "serde-ast", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde-ast", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, Trace, Finalize, PartialEq)] #[derive(Clone, Debug, Trace, Finalize, PartialEq)]
@ -714,9 +751,10 @@ pub enum AssignOp {
/// The types of the two operands determine the behavior of the addition assignment operator. Addition or concatenation is possible. /// The types of the two operands determine the behavior of the addition assignment operator. Addition or concatenation is possible.
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-AssignmentOperator) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-AssignmentOperator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators#Addition_assignment /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators#Addition_assignment
Add, Add,
@ -725,9 +763,10 @@ pub enum AssignOp {
/// Syntax: `x -= y` /// Syntax: `x -= y`
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-AssignmentOperator) /// - [ECMAScript reference][spec]
/// - [MDN documentation](mdn) /// - [MDN documentation](mdn)
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-AssignmentOperator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators#Subtraction_assignment /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators#Subtraction_assignment
Sub, Sub,
@ -736,9 +775,10 @@ pub enum AssignOp {
/// Syntax: `x *= y` /// Syntax: `x *= y`
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-AssignmentOperator) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-AssignmentOperator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators#Multiplication_assignment /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators#Multiplication_assignment
Mul, Mul,
@ -747,9 +787,10 @@ pub enum AssignOp {
/// Syntax: `x /= y` /// Syntax: `x /= y`
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-AssignmentOperator) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-AssignmentOperator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators#Division_assignment /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators#Division_assignment
Div, Div,
@ -758,9 +799,10 @@ pub enum AssignOp {
/// Syntax: `x %= y` /// Syntax: `x %= y`
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-AssignmentOperator) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-AssignmentOperator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators#Remainder_assignment /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators#Remainder_assignment
Mod, Mod,
@ -769,9 +811,10 @@ pub enum AssignOp {
/// Syntax: `x ** y` /// Syntax: `x ** y`
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-AssignmentOperator) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-AssignmentOperator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators#Exponentiation_assignment /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators#Exponentiation_assignment
Exp, Exp,
@ -781,9 +824,10 @@ pub enum AssignOp {
/// Syntax: `x &= y` /// Syntax: `x &= y`
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-AssignmentOperator) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-AssignmentOperator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators#Bitwise_AND_assignment /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators#Bitwise_AND_assignment
And, And,
@ -793,9 +837,10 @@ pub enum AssignOp {
/// Syntax: `x |= y` /// Syntax: `x |= y`
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-AssignmentOperator) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-AssignmentOperator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators#Bitwise_OR_assignment /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators#Bitwise_OR_assignment
Or, Or,
@ -805,9 +850,10 @@ pub enum AssignOp {
/// Syntax: `x ^= y` /// Syntax: `x ^= y`
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-AssignmentOperator) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-AssignmentOperator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators#Bitwise_XOR_assignment /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators#Bitwise_XOR_assignment
Xor, Xor,
@ -816,9 +862,10 @@ pub enum AssignOp {
/// Syntax: `x <<= y` /// Syntax: `x <<= y`
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-AssignmentOperator) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-AssignmentOperator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators#Left_shift_assignment /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators#Left_shift_assignment
Shl, Shl,
@ -827,9 +874,10 @@ pub enum AssignOp {
/// Syntax: `x >>= y` /// Syntax: `x >>= y`
/// ///
/// More information: /// More information:
/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-AssignmentOperator) /// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn] /// - [MDN documentation][mdn]
/// ///
/// [spec]: https://tc39.es/ecma262/#prod-AssignmentOperator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators#Right_shift_assignment /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators#Right_shift_assignment
Shr, Shr,
// TODO: Add UShl (unsigned shift left). // TODO: Add UShl (unsigned shift left).

10
boa/src/syntax/ast/punc.rs

@ -1,4 +1,9 @@
//! This module implements the `Punctuator`, which represents all punctuators used in JavaScript //! This module implements the `Punctuator`, which represents all punctuators used in JavaScript
//!
//! More information:
//! - [ECMAScript Reference][spec]
//!
//! [spec]: https://tc39.es/ecma262/#prod-Punctuator
use crate::syntax::ast::op::{BinOp, BitOp, CompOp, LogOp, NumOp}; use crate::syntax::ast::op::{BinOp, BitOp, CompOp, LogOp, NumOp};
use std::fmt::{Display, Error, Formatter}; use std::fmt::{Display, Error, Formatter};
@ -8,7 +13,10 @@ use serde::{Deserialize, Serialize};
/// The Punctuator enum describes all of the punctuators used in JavaScript. /// The Punctuator enum describes all of the punctuators used in JavaScript.
/// ///
/// For more information: [ECMAScript Reference](https://tc39.es/ecma262/#prod-Punctuator) /// More information:
/// - [ECMAScript Reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#prod-Punctuator
#[cfg_attr(feature = "serde-ast", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde-ast", derive(Serialize, Deserialize))]
#[derive(PartialEq, Clone, Copy, Debug)] #[derive(PartialEq, Clone, Copy, Debug)]
pub enum Punctuator { pub enum Punctuator {

10
boa/src/syntax/ast/token.rs

@ -1,4 +1,9 @@
//! This module implements all of the [Token]s used in the JavaScript programing language. //! This module implements all of the [Token]s used in the JavaScript programing language.
//!
//! More information:
//! - [ECMAScript reference][spec]
//!
//! [spec]: https://tc39.es/ecma262/#sec-tokens
use crate::syntax::ast::{keyword::Keyword, pos::Position, punc::Punctuator}; use crate::syntax::ast::{keyword::Keyword, pos::Position, punc::Punctuator};
use std::fmt::{Debug, Display, Formatter, Result}; use std::fmt::{Debug, Display, Formatter, Result};
@ -7,6 +12,11 @@ use std::fmt::{Debug, Display, Formatter, Result};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
/// This represents the smallest individual words, phrases, or characters that JavaScript can understand. /// This represents the smallest individual words, phrases, or characters that JavaScript can understand.
///
/// More information:
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-tokens
#[cfg_attr(feature = "serde-ast", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde-ast", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
pub struct Token { pub struct Token {

3
boa/src/syntax/mod.rs

@ -1,8 +1,5 @@
//! Syntactical analysis, such as AST, Parsing and Lexing //! Syntactical analysis, such as AST, Parsing and Lexing
/// The Javascript Abstract Syntax Tree
pub mod ast; pub mod ast;
/// Lexical analysis (tokenizing/lexing).
pub mod lexer; pub mod lexer;
// Parses a sequence of tokens into expressions
pub mod parser; pub mod parser;

Loading…
Cancel
Save