From 269b063cf223106069f459915aa3df50aa56fe22 Mon Sep 17 00:00:00 2001 From: HalidOdat Date: Sun, 26 Apr 2020 02:40:39 +0200 Subject: [PATCH] Documented console methods --- boa/src/builtins/console.rs | 69 --------------- boa/src/builtins/console/mod.rs | 130 ++++++++++++++++++++++++---- boa/src/syntax/ast/constant.rs | 28 ++++-- boa/src/syntax/ast/keyword.rs | 118 +++++++++++++++++-------- boa/src/syntax/ast/mod.rs | 2 + boa/src/syntax/ast/node.rs | 148 ++++++++++++++++++++++---------- boa/src/syntax/ast/op.rs | 144 ++++++++++++++++++++----------- boa/src/syntax/ast/punc.rs | 10 ++- boa/src/syntax/ast/token.rs | 10 +++ boa/src/syntax/mod.rs | 3 - 10 files changed, 438 insertions(+), 224 deletions(-) delete mode 100644 boa/src/builtins/console.rs diff --git a/boa/src/builtins/console.rs b/boa/src/builtins/console.rs deleted file mode 100644 index 8081ee22f1..0000000000 --- a/boa/src/builtins/console.rs +++ /dev/null @@ -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 = - 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 = FromIterator::from_iter( - args.iter() - .map(|x| from_value::(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 -} diff --git a/boa/src/builtins/console/mod.rs b/boa/src/builtins/console/mod.rs index 835a1755a3..92d10d538c 100644 --- a/boa/src/builtins/console/mod.rs +++ b/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)] #[cfg(test)] @@ -14,6 +27,7 @@ use crate::{ use gc::Gc; use std::{collections::HashMap, time::SystemTime}; +/// This is the internal console object state. #[derive(Debug, Default)] pub struct ConsoleState { count_map: HashMap, @@ -33,6 +47,7 @@ impl ConsoleState { impl InternalState for ConsoleState {} +/// This represents the different types of log messages. #[derive(Debug)] pub enum LogMessage { Log(String), @@ -41,12 +56,14 @@ pub enum LogMessage { Error(String), } +/// Helper function that returns the argument at a specified index. fn get_arg_at_index(args: &[Value], index: usize) -> Option { args.get(index) .cloned() .map(|s| from_value::(s).expect("Convert error")) } +/// Helper function for logging messages. pub fn logger(msg: LogMessage, console_state: &ConsoleState) { 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 { let target = get_arg_at_index::(data, 0).unwrap_or_default(); 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 /// were no arguments. /// -/// More information: +/// 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 { let assertion = get_arg_at_index::(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. /// -/// More information: +/// 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 { this.with_internal_state_mut(|state: &mut ConsoleState| { state.groups.clear(); @@ -166,7 +194,12 @@ pub fn clear(this: &Value, _: &[Value], _: &mut Interpreter) -> ResultValue { /// /// Prints a JavaScript values with "debug" logLevel. /// -/// More information: +/// 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 { this.with_internal_state_ref(|state| logger(LogMessage::Log(formatter(&args[..])), state)); 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. /// -/// More information: +/// 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 { this.with_internal_state_ref(|state| logger(LogMessage::Error(formatter(&args[..])), state)); 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. /// -/// More information: +/// 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 { this.with_internal_state_ref(|state| logger(LogMessage::Info(formatter(&args[..])), state)); 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. /// -/// More information: +/// 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 { this.with_internal_state_ref(|state| logger(LogMessage::Log(formatter(&args[..])), state)); 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. /// -/// More information: +/// 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 { if !args.is_empty() { 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. /// -/// More information: +/// 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 { this.with_internal_state_ref(|state| logger(LogMessage::Warn(formatter(&args[..])), state)); 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. /// -/// More information: +/// 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 { let label = get_arg_at_index::(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. /// -/// More information: +/// 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 { let label = get_arg_at_index::(args, 0).unwrap_or_else(|| "default".to_string()); @@ -281,7 +349,12 @@ fn system_time_in_ms() -> u128 { /// /// Starts the timer for given label. /// -/// More information: +/// 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 { let label = get_arg_at_index::(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. /// -/// More information: +/// 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 { let label = get_arg_at_index::(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. /// -/// More information: +/// 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 { let label = get_arg_at_index::(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. /// -/// More information: +/// 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 { 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. /// -/// More information: +/// 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 { this.with_internal_state_mut(|state: &mut ConsoleState| { state.groups.pop(); @@ -386,7 +479,12 @@ pub fn group_end(this: &Value, _: &[Value], _: &mut Interpreter) -> ResultValue /// /// Prints info about item /// -/// More information: +/// 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 { this.with_internal_state_mut(|state: &mut ConsoleState| { logger( diff --git a/boa/src/syntax/ast/constant.rs b/boa/src/syntax/ast/constant.rs index 932a2276d2..f253c63ab5 100644 --- a/boa/src/syntax/ast/constant.rs +++ b/boa/src/syntax/ast/constant.rs @@ -1,4 +1,11 @@ //! 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 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. /// /// More information: -/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-primary-expression-literals) +/// - [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 #[cfg_attr(feature = "serde-ast", derive(Serialize, Deserialize))] #[derive(Clone, Debug, Trace, Finalize, PartialEq)] @@ -26,9 +34,10 @@ pub enum Const { /// calls the method, then discards the temporary String object. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-terms-and-definitions-string-value) + /// - [ECMAScript reference][spec] /// - [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 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`"). /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-terms-and-definitions-number-value) + /// - [ECMAScript reference][spec] /// - [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 Num(f64), /// Integer types can be expressed in decimal (base 10), hexadecimal (base 16), octal (base 8) and binary (base 2). /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-terms-and-definitions-number-value) + /// - [ECMAScript reference][spec] /// - [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 Int(i32), @@ -58,9 +69,10 @@ pub enum Const { /// The Boolean object is a wrapper around the primitive Boolean data type. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-terms-and-definitions-boolean-value) + /// - [ECMAScript reference][spec] /// - [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 Bool(bool), @@ -71,18 +83,20 @@ pub enum Const { /// The meaning of a null reference varies among language implementations. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-null-value) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#sec-null-value /// [mdn]: https://developer.mozilla.org/en-US/docs/Glossary/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. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-undefined) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#sec-undefined /// [mdn]: https://developer.mozilla.org/en-US/docs/Glossary/undefined Undefined, } diff --git a/boa/src/syntax/ast/keyword.rs b/boa/src/syntax/ast/keyword.rs index ea3c494a46..20181a5ad8 100644 --- a/boa/src/syntax/ast/keyword.rs +++ b/boa/src/syntax/ast/keyword.rs @@ -1,4 +1,11 @@ //! 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::{ error, @@ -14,9 +21,10 @@ use serde::{Deserialize, Serialize}; /// In JavaScript you cannot use these reserved words as variables, labels, or function names. /// /// More information: -/// - [ECMAScript reference](https://www.ecma-international.org/ecma-262/#sec-keywords) +/// - [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 #[cfg_attr(feature = "serde-ast", derive(Serialize, Deserialize))] #[derive(Clone, Copy, PartialEq, Debug)] @@ -24,9 +32,10 @@ pub enum Keyword { /// The `await` keyword. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-AwaitExpression) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#prod-AwaitExpression /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await Await, @@ -34,9 +43,10 @@ pub enum Keyword { /// /// More information: /// - [break `Node` documentation][node] - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-BreakStatement) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#prod-BreakStatement /// [node]: ../node/enum.Node.html#variant.Break /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/break Break, @@ -45,9 +55,10 @@ pub enum Keyword { /// /// More information: /// - [switch `Node` documentation][node] - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-CaseClause) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#prod-CaseClause /// [node]: ../node/enum.Node.html#variant.Switch /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch Case, @@ -56,9 +67,10 @@ pub enum Keyword { /// /// More information: /// - [try `Node` documentation][node] - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-Catch) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#prod-Catch /// [node]: ../node/enum.Node.html#variant.Try /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch Catch, @@ -66,9 +78,10 @@ pub enum Keyword { /// The `class` keyword. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-ClassDeclaration) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#prod-ClassDeclaration /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/class Class, @@ -76,9 +89,10 @@ pub enum Keyword { /// /// More information: /// - [continue `Node` documentation][node] - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-ContinueStatement) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#prod-ContinueStatement /// [node]: ../node/enum.Node.html#variant.Continue /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/continue Continue, @@ -87,9 +101,10 @@ pub enum Keyword { /// /// More information: /// - [const `Node` documentation][node] - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-let-and-const-declarations) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#sec-let-and-const-declarations /// [node]: ../node/enum.Node.html#variant.ConstDecl /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const Const, @@ -97,9 +112,10 @@ pub enum Keyword { /// The `debugger` keyword. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-debugger-statement) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#sec-debugger-statement /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/debugger Debugger, @@ -107,11 +123,13 @@ pub enum Keyword { /// /// More information: /// - [switch `Node` documentation][node] - /// - [ECMAScript reference default clause](https://tc39.es/ecma262/#prod-DefaultClause) - /// - [ECMAScript reference default export](https://tc39.es/ecma262/#prod-ImportedDefaultBinding) + /// - [ECMAScript reference default clause][spec-clause] + /// - [ECMAScript reference default export][spec-export] /// - [MDN documentation][mdn] /// /// [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 Default, @@ -119,9 +137,10 @@ pub enum Keyword { /// /// More information: /// - [delete `UnaryOp` documentation][unary] - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-delete-operator) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#sec-delete-operator /// [unary]: ../op/enum.UnaryOp.html#variant.Delete /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete Delete, @@ -129,9 +148,10 @@ pub enum Keyword { /// The `do` keyword. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-do-while-statement) + /// - [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 Do, @@ -139,10 +159,11 @@ pub enum Keyword { /// /// More information: /// - [if `Node` documentation][node] - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-IfStatement) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// /// [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 Else, @@ -154,18 +175,20 @@ pub enum Keyword { /// The `export` keyword. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-exports) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#sec-exports /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export Export, /// The `extends` keyword. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-ClassHeritage) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#prod-ClassHeritage /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/extends Extends, @@ -173,10 +196,11 @@ pub enum Keyword { /// /// More information: /// - [try `Node` documentation][node] - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-Finally) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// /// [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 Finally, @@ -184,10 +208,11 @@ pub enum Keyword { /// /// More information: /// - [for loop `Node` documentation][node] - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-ForDeclaration) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// /// [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 For, @@ -195,10 +220,11 @@ pub enum Keyword { /// /// More information: /// - [function `Node` documentation][node] - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-terms-and-definitions-function) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// /// [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 Function, @@ -206,37 +232,41 @@ pub enum Keyword { /// /// More information: /// - [if `Node` documentation][node] - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-IfStatement) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// /// [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 If, /// The `in` keyword. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-RelationalExpression) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#prod-RelationalExpression /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/in In, /// The `instanceof` keyword. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-instanceofoperator) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#sec-instanceofoperator /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof InstanceOf, /// The `import` keyword. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-imports) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#sec-imports /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import Import, @@ -244,10 +274,11 @@ pub enum Keyword { /// /// More information: /// - [let `Node` documentation][node] - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-let-and-const-declarations) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// /// [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 Let, @@ -255,10 +286,11 @@ pub enum Keyword { /// /// More information: /// - [new `Node` documentation][node] - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-NewExpression) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// /// [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 New, @@ -266,19 +298,21 @@ pub enum Keyword { /// /// More information: /// - [return `Node` documentation][node] - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-ReturnStatement) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// /// [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 Return, /// The `super` keyword /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-super-keyword) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#sec-super-keyword /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/super Super, @@ -286,10 +320,11 @@ pub enum Keyword { /// /// More information: /// - [switch `Node` documentation][node] - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-SwitchStatement) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// /// [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 Switch, @@ -297,10 +332,11 @@ pub enum Keyword { /// /// More information: /// - [this `Node` documentation][node] - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-this-keyword) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// /// [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 This, @@ -308,10 +344,11 @@ pub enum Keyword { /// /// More information: /// - [throw `Node` documentation][node] - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-ArrowFunction) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// /// [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 Throw, @@ -319,10 +356,11 @@ pub enum Keyword { /// /// More information: /// - [try `Node` documentation][node] - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-TryStatement) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// /// [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 Try, @@ -330,10 +368,11 @@ pub enum Keyword { /// /// More information: /// - [typeof `UnaryOp` documentation][unary] - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-typeof-operator) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// /// [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 TypeOf, @@ -341,10 +380,11 @@ pub enum Keyword { /// /// More information: /// - [var `Node` documentation][node] - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-VariableStatement) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// /// [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 Var, @@ -352,10 +392,11 @@ pub enum Keyword { /// /// More information: /// - [void `UnaryOp` documentation][unary] - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-void-operator) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// /// [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 Void, @@ -363,28 +404,31 @@ pub enum Keyword { /// /// More information: /// - [while `Node` documentation][node] - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-grammar-notation-WhileStatement) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// /// [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 While, /// The `with` keyword. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-WithStatement) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#prod-WithStatement /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/with With, /// The 'yield' keyword. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-YieldExpression) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#prod-YieldExpression /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/yield Yield, } diff --git a/boa/src/syntax/ast/mod.rs b/boa/src/syntax/ast/mod.rs index 12374f427d..7d1d1c7fd1 100644 --- a/boa/src/syntax/ast/mod.rs +++ b/boa/src/syntax/ast/mod.rs @@ -1,3 +1,5 @@ +//! The Javascript Abstract Syntax Tree. + pub mod constant; pub mod keyword; pub mod node; diff --git a/boa/src/syntax/ast/node.rs b/boa/src/syntax/ast/node.rs index e9b8586835..4893840108 100644 --- a/boa/src/syntax/ast/node.rs +++ b/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. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-ArrayLiteral) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#prod-ArrayLiteral /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array ArrayDecl(Vec), @@ -35,9 +36,10 @@ pub enum Node { /// Arrow functions cannot be used as constructors and will throw an error when used with new. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-ArrowFunction) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#prod-ArrowFunction /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions ArrowFunctionDecl(Vec, Box), @@ -46,9 +48,10 @@ pub enum Node { /// Assignment operator (`=`), assigns the value of its right operand to its left operand. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-AssignmentExpression) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#prod-AssignmentExpression /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators Assign(Box, Box), @@ -68,9 +71,10 @@ pub enum Node { /// where you provide no statement, although one is required. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-BlockStatement) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#prod-BlockStatement /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/block Block(Vec), @@ -81,9 +85,10 @@ pub enum Node { /// it does not have to be preceded by a loop statement. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-BreakStatement) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#prod-BreakStatement /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/break Break(Option), @@ -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). /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-CallExpression) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#prod-CallExpression /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions#Calling_functions Call(Box, Vec), @@ -107,9 +113,10 @@ pub enum Node { /// This operator is frequently used as a shortcut for the `if` statement. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-ConditionalExpression) + /// - [ECMAScript reference][spec] /// - [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 ConditionalOp(Box, Box, Box), @@ -118,9 +125,10 @@ pub enum Node { /// These are fixed values **not variables** that you literally provide in your script. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-primary-expression-literals) + /// - [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 Const(Const), @@ -133,9 +141,10 @@ pub enum Node { /// (This makes sense, given that it can't be changed later.) /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-let-and-const-declarations) + /// - [ECMAScript reference][spec] /// - [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 /// [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 @@ -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. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-ContinueStatement) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#prod-ContinueStatement /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/continue Continue(Option), - /// 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, Box), /// 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. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-terms-and-definitions-function) + /// - [ECMAScript reference][spec] /// - [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 FunctionDecl(Option, Vec, Box), @@ -186,9 +206,10 @@ pub enum Node { /// if it has a reference to a Function instance as its value). /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-property-accessors) + /// - [ECMAScript reference][spec] /// - [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 GetConstField(Box, String), @@ -204,9 +225,10 @@ pub enum Node { /// if it has a reference to a Function instance as its value). /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-property-accessors) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#sec-property-accessors /// [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 GetField(Box, Box), @@ -217,9 +239,10 @@ pub enum Node { /// The JavaScript for loop is similar to the Java and C for loop. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-ForDeclaration) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#prod-ForDeclaration /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for ForLoop( Option>, @@ -235,9 +258,10 @@ pub enum Node { /// **Note** that there is no elseif (in one word) keyword in JavaScript. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-IfStatement) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#prod-IfStatement /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else /// [truthy]: https://developer.mozilla.org/en-US/docs/Glossary/truthy /// [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). /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-let-and-const-declarations) + /// - [ECMAScript reference][spec] /// - [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 LetDecl(Vec<(String, Option)>), @@ -267,9 +292,10 @@ pub enum Node { /// to convert identifiers to strings, but sometimes it is possible to parse strings into identifiers. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-Identifier) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#prod-Identifier /// [mdn]: https://developer.mozilla.org/en-US/docs/Glossary/Identifier Local(String), @@ -282,9 +308,10 @@ pub enum Node { /// - Returns this if the function doesn't return its own object. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-NewExpression) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#prod-NewExpression /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new New(Box), @@ -297,9 +324,10 @@ pub enum Node { /// contain [`primitive`][primitive] data types or other objects. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-ObjectLiteral) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#prod-ObjectLiteral /// [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 /// [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. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-ReturnStatement) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#prod-ReturnStatement /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return Return(Option>), @@ -331,9 +360,10 @@ pub enum Node { /// the cases are not equal to each other.) /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-SwitchStatement) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#prod-SwitchStatement /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch Switch(Box, Vec<(Node, Vec)>, Option>), @@ -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. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-SpreadElement) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#prod-SpreadElement /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax Spread(Box), /// Similar to `Node::Block` but without the braces /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-StatementList) + /// - [ECMAScript reference][spec] + /// + /// [spec]: https://tc39.es/ecma262/#prod-StatementList StatementList(Vec), /// The **`throw` statement** throws a user-defined exception. @@ -366,9 +399,10 @@ pub enum Node { /// caller functions, the program will terminate. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-ThrowStatement) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#prod-ThrowStatement /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/throw Throw(Box), @@ -379,9 +413,10 @@ pub enum Node { /// Returns a string indicating the type of the unevaluated operand. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-typeof-operator) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#sec-typeof-operator /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof TypeOf(Box), @@ -391,9 +426,10 @@ pub enum Node { /// even for single statements. At least one `catch`-block, or a `finally`-block, must be present. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-TryStatement) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#prod-TryStatement /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch Try( Box, @@ -409,18 +445,20 @@ pub enum Node { /// mode can be any value. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-this-keyword) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#sec-this-keyword /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this This, /// A unary operation is an operation with only one operand. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-UnaryExpression) + /// - [ECMAScript reference][spec] /// - [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 UnaryOp(UnaryOp, Box), @@ -435,9 +473,10 @@ pub enum Node { /// (it becomes a property of the global object) when the assignment is executed. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-VariableStatement) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#prod-VariableStatement /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var VarDecl(Vec<(String, Option)>), @@ -446,9 +485,10 @@ pub enum Node { /// The condition is evaluated before executing the statement. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-grammar-notation-WhileStatement) + /// - [ECMAScript reference][spec] /// - [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 WhileLoop(Box, Box), } @@ -460,6 +500,7 @@ impl Operator for Node { _ => true, } } + fn get_precedence(&self) -> u64 { match self { 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, /// not any value like numbers, strings, or objects. -///```javascript +///```text ///function foo(formalParametar1, formalParametar2) { ///} ///``` -/// For more information, please check +/// +/// 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))] #[derive(Clone, Debug, PartialEq, Trace, Finalize)] pub struct FormalParameter { @@ -707,7 +754,13 @@ pub struct FormalParameter { pub is_rest_param: bool, } -/// +/// A sequence of `FormalParameter`. +/// +/// More information: +/// - [ECMAScript reference][spec] +/// - [MDN documentation][mdn] +/// +/// [spec]: https://tc39.es/ecma262/#prod-FormalParameters pub type FormalParameters = Vec; 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. /// /// More information: -/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-PropertyDefinition) +/// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// +/// [spec]: https://tc39.es/ecma262/#prod-PropertyDefinition /// [mdn]: https://developer.mozilla.org/en-US/docs/Glossary/property/JavaScript // TODO: Support all features: https://tc39.es/ecma262/#prod-PropertyDefinition #[cfg_attr(feature = "serde-ast", derive(Serialize, Deserialize))] @@ -738,27 +792,30 @@ pub enum PropertyDefinition { /// Puts a variable into an object. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-IdentifierReference) + /// - [ECMAScript reference][spec] /// - [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 IdentifierReference(String), /// Binds a property name to a JavaScript value. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-PropertyDefinition) + /// - [ECMAScript reference][spec] /// - [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 Property(String, Node), /// A property of an object can also refer to a function or a getter or setter method. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-MethodDefinition) + /// - [ECMAScript reference][spec] /// - [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 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()`. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-PropertyDefinition) + /// - [ECMAScript reference][spec] /// - [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 SpreadObject(Node), } @@ -781,9 +839,10 @@ pub enum PropertyDefinition { /// It is a shorthand for a function assigned to the method's name. /// /// More information: -/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-MethodDefinition) +/// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// +/// [spec]: https://tc39.es/ecma262/#prod-MethodDefinition /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Method_definitions #[cfg_attr(feature = "serde-ast", derive(Serialize, Deserialize))] #[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. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-MethodDefinition) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#prod-MethodDefinition /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/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. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-MethodDefinition) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#prod-MethodDefinition /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/set Set, /// Starting with ECMAScript 2015, you are able to define own methods in a shorter syntax, similar to the getters and setters. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-MethodDefinition) + /// - [ECMAScript reference][spec] /// - [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 Ordinary, // TODO: support other method definition kinds, like `Generator`. diff --git a/boa/src/syntax/ast/op.rs b/boa/src/syntax/ast/op.rs index 8639de975b..0881cdbd92 100644 --- a/boa/src/syntax/ast/op.rs +++ b/boa/src/syntax/ast/op.rs @@ -33,9 +33,10 @@ pub enum NumOp { /// Syntax: `x + y` /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-addition-operator-plus). + /// - [ECMAScript reference][spec]. /// - [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 Add, @@ -44,9 +45,10 @@ pub enum NumOp { /// Syntax: `x - y` /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-subtraction-operator-minus). + /// - [ECMAScript reference][spec]. /// - [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 Sub, @@ -56,9 +58,10 @@ pub enum NumOp { /// Syntax: `x / y` /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-MultiplicativeOperator) + /// - [ECMAScript reference][spec] /// - [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 Div, @@ -67,9 +70,10 @@ pub enum NumOp { /// Syntax: `x * y` /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-MultiplicativeExpression) + /// - [ECMAScript reference][spec] /// - [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 Mul, @@ -81,9 +85,10 @@ pub enum NumOp { /// The exponentiation operator is right-associative. a ** b ** c is equal to a ** (b ** c). /// /// More information: - /// - [ECMAScript reference]: . + /// - [ECMAScript reference][spec] /// - [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 Exp, @@ -94,9 +99,10 @@ pub enum NumOp { /// The remainder operator always takes the sign of the dividend. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-MultiplicativeOperator) + /// - [ECMAScript reference][spec] /// - [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 Mod, } @@ -125,9 +131,10 @@ impl Display for NumOp { /// function calls. /// /// More information: -/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-UnaryExpression) +/// - [ECMAScript reference][spec] /// - [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 #[cfg_attr(feature = "serde-ast", derive(Serialize, Deserialize))] #[derive(Clone, Debug, Trace, Finalize, PartialEq)] @@ -139,9 +146,10 @@ pub enum UnaryOp { /// This operator increments and returns the value after incrementing. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-postfix-increment-operator) + /// - [ECMAScript reference][spec] /// - [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 IncrementPost, @@ -152,9 +160,10 @@ pub enum UnaryOp { /// This operator increments and returns the value before incrementing. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-prefix-increment-operator) + /// - [ECMAScript reference][spec] /// - [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 IncrementPre, @@ -165,9 +174,10 @@ pub enum UnaryOp { /// This operator decrements and returns the value before decrementing. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-postfix-decrement-operator) + /// - [ECMAScript reference][spec] /// - [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 DecrementPost, @@ -178,9 +188,10 @@ pub enum UnaryOp { /// This operator decrements the operand and returns the value after decrementing. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-prefix-decrement-operator) + /// - [ECMAScript reference][spec] /// - [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 DecrementPre, @@ -192,9 +203,10 @@ pub enum UnaryOp { /// however, it performs an additional operation, negation. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-unary-minus-operator) + /// - [ECMAScript reference][spec] /// - [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 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`. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-unary-plus-operator) + /// - [ECMAScript reference][spec] /// - [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 Plus, @@ -223,9 +236,10 @@ pub enum UnaryOp { /// force the conversion of any value to the corresponding boolean primitive. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-logical-not-operator) + /// - [ECMAScript reference][spec] /// - [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 Not, @@ -237,9 +251,10 @@ pub enum UnaryOp { /// Bitwise NOTing any number x yields -(x + 1). For example, ~-5 yields 4. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-bitwise-not-operator) + /// - [ECMAScript reference][spec] /// - [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 Tilde, @@ -252,9 +267,10 @@ pub enum UnaryOp { /// There are other uses as well. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-typeof-operator) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#sec-typeof-operator /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof TypeOf, @@ -272,9 +288,10 @@ pub enum UnaryOp { /// property, in which case, `false` is returned in non-strict mode. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-delete-operator) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#sec-delete-operator /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/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. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-void-operator) + /// - [ECMAScript reference][spec] /// - [MDN documentation][mdn] /// + /// [spec]: https://tc39.es/ecma262/#sec-void-operator /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void Void, } @@ -333,9 +351,10 @@ pub enum BitOp { /// Syntax: `x & y` /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-BitwiseANDExpression) + /// - [ECMAScript reference][spec] /// - [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 And, @@ -344,9 +363,10 @@ pub enum BitOp { /// Syntax: `x | y` /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-BitwiseORExpression) + /// - [ECMAScript reference][spec] /// - [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 Or, @@ -355,9 +375,10 @@ pub enum BitOp { /// Syntax: `x ^ y` /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-BitwiseXORExpression) + /// - [ECMAScript reference][spec] /// - [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 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. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-left-shift-operator) + /// - [ECMAScript reference][spec] /// - [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 Shl, @@ -384,9 +406,10 @@ pub enum BitOp { /// Hence the name "sign-propagating". /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-signed-right-shift-operator) + /// - [ECMAScript reference][spec] /// - [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 Shr, @@ -399,9 +422,10 @@ pub enum BitOp { /// Unlike the other bitwise operators, zero-fill right shift returns an unsigned 32-bit integer. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-unsigned-right-shift-operator) + /// - [ECMAScript reference][spec] /// - [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 UShr, } @@ -433,9 +457,10 @@ impl Display for BitOp { /// to compatible types before checking equality. /// /// More information: -/// - [ECMAScript reference](tc39.es/ecma262/#sec-testing-and-comparison-operations) +/// - [ECMAScript reference][spec] /// - [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 #[cfg_attr(feature = "serde-ast", derive(Serialize, Deserialize))] #[derive(Clone, Debug, Trace, Finalize, PartialEq)] @@ -448,9 +473,10 @@ pub enum CompOp { /// refer to the same object in memory. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-abstract-equality-comparison) + /// - [ECMAScript reference][spec] /// - [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 Equal, @@ -463,9 +489,10 @@ pub enum CompOp { /// internal references which are not equal when operands refer to different objects in memory. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-EqualityExpression) + /// - [ECMAScript reference][spec] /// - [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 NotEqual, @@ -476,9 +503,10 @@ pub enum CompOp { /// Returns `true` if the operands are equal and of the same type. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-strict-equality-comparison) + /// - [ECMAScript reference][spec] /// - [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 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. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-EqualityExpression) + /// - [ECMAScript reference][spec] /// - [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> StrictNotEqual, @@ -502,9 +531,10 @@ pub enum CompOp { /// Returns `true` if the left operand is greater than the right operand. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-RelationalExpression) + /// - [ECMAScript reference][spec] /// - [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 GreaterThan, @@ -515,9 +545,10 @@ pub enum CompOp { /// Returns `true` if the left operand is greater than the right operand. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-RelationalExpression) + /// - [ECMAScript reference][spec] /// - [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 GreaterThanOrEqual, @@ -528,9 +559,10 @@ pub enum CompOp { /// Returns `true` if the left operand is less than the right operand. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-RelationalExpression) + /// - [ECMAScript reference][spec] /// - [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 LessThan, @@ -541,9 +573,10 @@ pub enum CompOp { /// Returns `true` if the left operand is less than or equal to the right operand. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-RelationalExpression) + /// - [ECMAScript reference][spec] /// - [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 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. /// /// More information: -/// - [ECMAScript reference](https://tc39.es/ecma262/#sec-binary-logical-operators) +/// - [ECMAScript reference][spec] /// - [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 #[cfg_attr(feature = "serde-ast", derive(Serialize, Deserialize))] #[derive(Clone, Debug, Trace, Finalize, PartialEq)] @@ -586,9 +620,10 @@ pub enum LogOp { /// Syntax: `x && y` /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-LogicalANDExpression) + /// - [ECMAScript reference][spec] /// - [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 And, @@ -598,9 +633,10 @@ pub enum LogOp { /// Syntax: `x || y` /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-LogicalORExpression) + /// - [ECMAScript reference]( /// - [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 Or, } @@ -700,9 +736,10 @@ impl Display for BinOp { /// There are also compound assignment operators that are shorthand for the operations /// /// More information: -/// - [ECMAScript reference](https://tc39.es/ecma262/#prod-AssignmentOperator) +/// - [ECMAScript reference][spec] /// - [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 #[cfg_attr(feature = "serde-ast", derive(Serialize, Deserialize))] #[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. /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-AssignmentOperator) + /// - [ECMAScript reference][spec] /// - [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 Add, @@ -725,9 +763,10 @@ pub enum AssignOp { /// Syntax: `x -= y` /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-AssignmentOperator) + /// - [ECMAScript reference][spec] /// - [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 Sub, @@ -736,9 +775,10 @@ pub enum AssignOp { /// Syntax: `x *= y` /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-AssignmentOperator) + /// - [ECMAScript reference][spec] /// - [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 Mul, @@ -747,9 +787,10 @@ pub enum AssignOp { /// Syntax: `x /= y` /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-AssignmentOperator) + /// - [ECMAScript reference][spec] /// - [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 Div, @@ -758,9 +799,10 @@ pub enum AssignOp { /// Syntax: `x %= y` /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-AssignmentOperator) + /// - [ECMAScript reference][spec] /// - [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 Mod, @@ -769,9 +811,10 @@ pub enum AssignOp { /// Syntax: `x ** y` /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-AssignmentOperator) + /// - [ECMAScript reference][spec] /// - [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 Exp, @@ -781,9 +824,10 @@ pub enum AssignOp { /// Syntax: `x &= y` /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-AssignmentOperator) + /// - [ECMAScript reference][spec] /// - [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 And, @@ -793,9 +837,10 @@ pub enum AssignOp { /// Syntax: `x |= y` /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-AssignmentOperator) + /// - [ECMAScript reference][spec] /// - [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 Or, @@ -805,9 +850,10 @@ pub enum AssignOp { /// Syntax: `x ^= y` /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-AssignmentOperator) + /// - [ECMAScript reference][spec] /// - [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 Xor, @@ -816,9 +862,10 @@ pub enum AssignOp { /// Syntax: `x <<= y` /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-AssignmentOperator) + /// - [ECMAScript reference][spec] /// - [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 Shl, @@ -827,9 +874,10 @@ pub enum AssignOp { /// Syntax: `x >>= y` /// /// More information: - /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-AssignmentOperator) + /// - [ECMAScript reference][spec] /// - [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 Shr, // TODO: Add UShl (unsigned shift left). diff --git a/boa/src/syntax/ast/punc.rs b/boa/src/syntax/ast/punc.rs index 8afa9e671d..6cb23a7c9a 100644 --- a/boa/src/syntax/ast/punc.rs +++ b/boa/src/syntax/ast/punc.rs @@ -1,4 +1,9 @@ //! 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 std::fmt::{Display, Error, Formatter}; @@ -8,7 +13,10 @@ use serde::{Deserialize, Serialize}; /// 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))] #[derive(PartialEq, Clone, Copy, Debug)] pub enum Punctuator { diff --git a/boa/src/syntax/ast/token.rs b/boa/src/syntax/ast/token.rs index 71c1815feb..6584ccfeea 100644 --- a/boa/src/syntax/ast/token.rs +++ b/boa/src/syntax/ast/token.rs @@ -1,4 +1,9 @@ //! 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 std::fmt::{Debug, Display, Formatter, Result}; @@ -7,6 +12,11 @@ use std::fmt::{Debug, Display, Formatter, Result}; use serde::{Deserialize, Serialize}; /// 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))] #[derive(Debug, Clone, PartialEq)] pub struct Token { diff --git a/boa/src/syntax/mod.rs b/boa/src/syntax/mod.rs index ab4b4a62d8..739c4a069b 100644 --- a/boa/src/syntax/mod.rs +++ b/boa/src/syntax/mod.rs @@ -1,8 +1,5 @@ //! Syntactical analysis, such as AST, Parsing and Lexing -/// The Javascript Abstract Syntax Tree pub mod ast; -/// Lexical analysis (tokenizing/lexing). pub mod lexer; -// Parses a sequence of tokens into expressions pub mod parser;