@@ -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. */
@@ -181,51 +198,118 @@ class TopLevel extends @toplevel, StmtContainer {
181198
182199/**
183200 * A stand-alone file or script originating from an HTML `<script>` element.
201+ *
202+ * Example:
203+ *
204+ * ```
205+ * <script>
206+ * window.done = true;
207+ * </script>
208+ * ```
184209 */
185210class Script extends TopLevel {
186211 Script ( ) { this instanceof @script or this instanceof @inline_script }
187212}
188213
189214/**
190215 * A stand-alone file or an external script originating from an HTML `<script>` element.
216+ *
217+ * Example:
218+ *
219+ * ```
220+ * #! /usr/bin/node
221+ * console.log("Hello, world!");
222+ * ```
191223 */
192224class ExternalScript extends @script, Script { }
193225
194226/**
195227 * A script embedded inline in an HTML `<script>` element.
228+ *
229+ * Example:
230+ *
231+ * ```
232+ * <script>
233+ * window.done = true;
234+ * </script>
235+ * ```
196236 */
197237class InlineScript extends @inline_script, Script { }
198238
199239/**
200240 * A code snippet originating from an HTML attribute value.
241+ *
242+ * Examples:
243+ *
244+ * ```
245+ * <div onclick="alert('hi')">Click me</div>
246+ * <a href="javascript:alert('hi')">Click me</a>
247+ * ```
201248 */
202249class CodeInAttribute extends TopLevel {
203250 CodeInAttribute ( ) { this instanceof @event_handler or this instanceof @javascript_url }
204251}
205252
206253/**
207254 * A code snippet originating from an event handler attribute.
255+ *
256+ * Example:
257+ *
258+ * ```
259+ * <div onclick="alert('hi')">Click me</div>
260+ * ```
208261 */
209262class EventHandlerCode extends @event_handler, CodeInAttribute { }
210263
211264/**
212265 * A code snippet originating from a URL with the `javascript:` URL scheme.
266+ *
267+ * Example:
268+ *
269+ * ```
270+ * <a href="javascript:alert('hi')">Click me</a>
271+ * ```
213272 */
214273class JavaScriptURL extends @javascript_url, CodeInAttribute { }
215274
216275/**
217276 * A toplevel syntactic entity containing Closure-style externs definitions.
277+ *
278+ * Example:
279+ *
280+ * <pre>
281+ * /** @externs */
282+ * /** @typedef {String} */
283+ * var MyString;
284+ * </pre>
218285 */
219286class Externs extends TopLevel {
220287 Externs ( ) { isExterns ( ) }
221288}
222289
223- /** A program element that is either an expression or a statement. */
290+ /**
291+ * A program element that is either an expression or a statement.
292+ *
293+ * Examples:
294+ *
295+ * ```
296+ * var i = 0;
297+ * i = 9
298+ * ```
299+ */
224300class ExprOrStmt extends @exprorstmt, ControlFlowNode , ASTNode { }
225301
226302/**
227303 * A program element that contains statements, but isn't itself
228304 * a statement, in other words a toplevel or a function.
305+ *
306+ * Example:
307+ *
308+ * ```
309+ * function f() {
310+ * g();
311+ * }
312+ * ```
229313 */
230314class StmtContainer extends @stmt_container, ASTNode {
231315 /** Gets the innermost enclosing container in which this container is nested. */
@@ -312,6 +396,14 @@ module AST {
312396 * A program element that evaluates to a value at runtime. This includes expressions,
313397 * but also function and class declaration statements, as well as TypeScript
314398 * namespace and enum declarations.
399+ *
400+ * Examples:
401+ *
402+ * ```
403+ * 0 // expression
404+ * (function id(x) { return x; }) // parenthesized function expression
405+ * function id(x) { return x; } // function declaration
406+ * ```
315407 */
316408 class ValueNode extends ASTNode , @dataflownode {
317409 /** Gets type inference results for this element. */
0 commit comments