@@ -10,6 +10,15 @@ import javascript
1010 *
1111 * This class provides generic traversal methods applicable to all AST nodes,
1212 * such as obtaining the children of an AST node.
13+ *
14+ * Examples:
15+ *
16+ * ```
17+ * function abs(x) {
18+ * return x < 0 ? -x : x;
19+ * }
20+ * abs(-42);
21+ * ```
1322 */
1423class ASTNode extends @ast_node, Locatable {
1524 override Location getLocation ( ) { hasLocation ( this , result ) }
@@ -128,6 +137,14 @@ class ASTNode extends @ast_node, Locatable {
128137 * A toplevel syntactic unit; that is, a stand-alone script, an inline script
129138 * embedded in an HTML `<script>` tag, a code snippet assigned to an HTML event
130139 * handler attribute, or a `javascript:` URL.
140+ *
141+ * Example:
142+ *
143+ * ```
144+ * <script>
145+ * window.done = true;
146+ * </script>
147+ * ```
131148 */
132149class TopLevel extends @toplevel, StmtContainer {
133150 /** Holds if this toplevel is minified. */
@@ -185,51 +202,118 @@ class TopLevel extends @toplevel, StmtContainer {
185202
186203/**
187204 * A stand-alone file or script originating from an HTML `<script>` element.
205+ *
206+ * Example:
207+ *
208+ * ```
209+ * <script>
210+ * window.done = true;
211+ * </script>
212+ * ```
188213 */
189214class Script extends TopLevel {
190215 Script ( ) { this instanceof @script or this instanceof @inline_script }
191216}
192217
193218/**
194219 * A stand-alone file or an external script originating from an HTML `<script>` element.
220+ *
221+ * Example:
222+ *
223+ * ```
224+ * #! /usr/bin/node
225+ * console.log("Hello, world!");
226+ * ```
195227 */
196228class ExternalScript extends @script, Script { }
197229
198230/**
199231 * A script embedded inline in an HTML `<script>` element.
232+ *
233+ * Example:
234+ *
235+ * ```
236+ * <script>
237+ * window.done = true;
238+ * </script>
239+ * ```
200240 */
201241class InlineScript extends @inline_script, Script { }
202242
203243/**
204244 * A code snippet originating from an HTML attribute value.
245+ *
246+ * Examples:
247+ *
248+ * ```
249+ * <div onclick="alert('hi')">Click me</div>
250+ * <a href="javascript:alert('hi')">Click me</a>
251+ * ```
205252 */
206253class CodeInAttribute extends TopLevel {
207254 CodeInAttribute ( ) { this instanceof @event_handler or this instanceof @javascript_url }
208255}
209256
210257/**
211258 * A code snippet originating from an event handler attribute.
259+ *
260+ * Example:
261+ *
262+ * ```
263+ * <div onclick="alert('hi')">Click me</div>
264+ * ```
212265 */
213266class EventHandlerCode extends @event_handler, CodeInAttribute { }
214267
215268/**
216269 * A code snippet originating from a URL with the `javascript:` URL scheme.
270+ *
271+ * Example:
272+ *
273+ * ```
274+ * <a href="javascript:alert('hi')">Click me</a>
275+ * ```
217276 */
218277class JavaScriptURL extends @javascript_url, CodeInAttribute { }
219278
220279/**
221280 * A toplevel syntactic entity containing Closure-style externs definitions.
281+ *
282+ * Example:
283+ *
284+ * <pre>
285+ * /** @externs */
286+ * /** @typedef {String} */
287+ * var MyString;
288+ * </pre>
222289 */
223290class Externs extends TopLevel {
224291 Externs ( ) { isExterns ( ) }
225292}
226293
227- /** A program element that is either an expression or a statement. */
294+ /**
295+ * A program element that is either an expression or a statement.
296+ *
297+ * Examples:
298+ *
299+ * ```
300+ * var i = 0;
301+ * i = 9
302+ * ```
303+ */
228304class ExprOrStmt extends @exprorstmt, ControlFlowNode , ASTNode { }
229305
230306/**
231307 * A program element that contains statements, but isn't itself
232308 * a statement, in other words a toplevel or a function.
309+ *
310+ * Example:
311+ *
312+ * ```
313+ * function f() {
314+ * g();
315+ * }
316+ * ```
233317 */
234318class StmtContainer extends @stmt_container, ASTNode {
235319 /** Gets the innermost enclosing container in which this container is nested. */
@@ -316,6 +400,14 @@ module AST {
316400 * A program element that evaluates to a value at runtime. This includes expressions,
317401 * but also function and class declaration statements, as well as TypeScript
318402 * namespace and enum declarations.
403+ *
404+ * Examples:
405+ *
406+ * ```
407+ * 0 // expression
408+ * (function id(x) { return x; }) // parenthesized function expression
409+ * function id(x) { return x; } // function declaration
410+ * ```
319411 */
320412 class ValueNode extends ASTNode , @dataflownode {
321413 /** Gets type inference results for this element. */
0 commit comments