From 478330d805ad84fe7a9c7aea16d7675bb2072b45 Mon Sep 17 00:00:00 2001 From: HalidOdat Date: Fri, 10 Apr 2020 16:45:17 +0200 Subject: [PATCH] Added documentation to Const --- boa/src/syntax/ast/constant.rs | 80 +++++++++++++++++++++++++++++++--- boa/src/syntax/ast/node.rs | 8 ++-- 2 files changed, 77 insertions(+), 11 deletions(-) diff --git a/boa/src/syntax/ast/constant.rs b/boa/src/syntax/ast/constant.rs index 6d7fbc160f..932a2276d2 100644 --- a/boa/src/syntax/ast/constant.rs +++ b/boa/src/syntax/ast/constant.rs @@ -1,23 +1,89 @@ +//! This module implements the `Const` structure, which represents the primitive values in JavaScript. + use gc_derive::{Finalize, Trace}; use std::fmt::{Display, Formatter, Result}; #[cfg(feature = "serde-ast")] use serde::{Deserialize, Serialize}; -/// A Javascript Constant. + +/// Literals represent values in JavaScript. +/// +/// 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) +/// - [MDN documentation][mdn] +/// +/// [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)] pub enum Const { - /// A UTF-8 string, such as `"Hello, world"` + /// A string literal is zero or more characters enclosed in double (`"`) or single (`'`) quotation marks. + /// + /// A string must be delimited by quotation marks of the same type (that is, either both single quotation marks, or both double quotation marks). + /// You can call any of the String object's methods on a string literal value. + /// JavaScript automatically converts the string literal to a temporary String object, + /// calls the method, then discards the temporary String object. + /// + /// More information: + /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-terms-and-definitions-string-value) + /// - [MDN documentation][mdn] + /// + /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#String_literals String(String), - // A 64-bit floating-point number, such as `3.1415` + + /// A floating-point number literal. + /// + /// The exponent part is an "`e`" or "`E`" followed by an integer, which can be signed (preceded by "`+`" or "`-`"). + /// 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) + /// - [MDN documentation][mdn] + /// + /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#Floating-point_literals Num(f64), - // A 32-bit integer, such as `42` + + /// 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) + /// - [MDN documentation][mdn] + /// + /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#Numeric_literals Int(i32), - // A boolean, which is either `true` or `false` and is used to check if criteria are met + + /// The Boolean type has two literal values: `true` and `false`. + /// + /// 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) + /// - [MDN documentation][mdn] + /// + /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#Boolean_literals Bool(bool), - // The `null` value, which represents a non-existant value + + /// In JavaScript, `null` is marked as one of the primitive values, cause it's behaviour is seemingly primitive. + /// + /// In computer science, a null value represents a reference that points, + /// generally intentionally, to a nonexistent or invalid object or address. + /// The meaning of a null reference varies among language implementations. + /// + /// More information: + /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-null-value) + /// - [MDN documentation][mdn] + /// + /// [mdn]: https://developer.mozilla.org/en-US/docs/Glossary/null Null, - // The `undefined` value, which represents a field or index that doesn't exist + + /// 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) + /// - [MDN documentation][mdn] + /// + /// [mdn]: https://developer.mozilla.org/en-US/docs/Glossary/undefined Undefined, } diff --git a/boa/src/syntax/ast/node.rs b/boa/src/syntax/ast/node.rs index af549e91cf..05395124ad 100644 --- a/boa/src/syntax/ast/node.rs +++ b/boa/src/syntax/ast/node.rs @@ -121,7 +121,7 @@ pub enum Node { /// - [ECMAScript reference](https://tc39.es/ecma262/#sec-primary-expression-literals) /// - [MDN documentation][mdn] /// - /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#Data_types + /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#Literals Const(Const), /// The **`const` statements** are block-scoped, much like variables defined using the `let` keyword. @@ -749,11 +749,11 @@ pub enum PropertyDefinition { /// - [ECMAScript reference](https://tc39.es/ecma262/#prod-PropertyDefinition) /// - [MDN documentation][mdn] /// - /// [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), - + /// 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) /// - [MDN documentation][mdn]