@@ -4,6 +4,14 @@ import javascript
4
4
5
5
/**
6
6
* An ECMAScript 2015 module.
7
+ *
8
+ * Example:
9
+ *
10
+ * ```
11
+ * import console from 'console';
12
+ *
13
+ * console.log("Hello, world!");
14
+ * ```
7
15
*/
8
16
class ES2015Module extends Module {
9
17
ES2015Module ( ) { isES2015Module ( this ) }
@@ -32,7 +40,16 @@ class ES2015Module extends Module {
32
40
}
33
41
}
34
42
35
- /** An import declaration. */
43
+ /**
44
+ * An import declaration.
45
+ *
46
+ * Examples:
47
+ *
48
+ * ```
49
+ * import console, { log, error as fatal } from 'console';
50
+ * import * as console from 'console';
51
+ * ```
52
+ */
36
53
class ImportDeclaration extends Stmt , Import , @importdeclaration {
37
54
override ES2015Module getEnclosingModule ( ) { result = getTopLevel ( ) }
38
55
@@ -71,19 +88,20 @@ private class LiteralImportPath extends PathExprInModule, ConstantString {
71
88
/**
72
89
* An import specifier in an import declaration.
73
90
*
74
- * There are four kinds of import specifiers:
75
- *
76
- * - default import specifiers, which import the default export of a module
77
- * and make it available under a local name, as in `import` <u>`f`</u> `from 'a'`;
78
- * - namespace import specifiers, which import all exports of a module and
79
- * make them available through a local namespace object, as in
80
- * `import` <u>`* as ns`</u> `from 'a'`;
81
- * - named import specifiers, which import a named export of a module and
82
- * make it available in the importing module under the same name, as in
83
- * `import {` <u>`x`</u> `} from 'a'`;
84
- * - renaming import specifiers, which import a named export of a module and
85
- * make it available in the importing module under a different name, as in
86
- * `import {` <u>`x as y`</u> `} from 'a'`.
91
+ * Examples:
92
+ *
93
+ * ```
94
+ * import
95
+ * console, // default import specifier
96
+ * {
97
+ * log, // named import specifier
98
+ * error as fatal // renaming import specifier
99
+ * } from 'console';
100
+ *
101
+ * import
102
+ * * as console // namespace import specifier
103
+ * from 'console';
104
+ * ```
87
105
*/
88
106
class ImportSpecifier extends Expr , @importspecifier {
89
107
/** Gets the imported symbol; undefined for default and namespace import specifiers. */
@@ -110,26 +128,74 @@ class ImportSpecifier extends Expr, @importspecifier {
110
128
VarDecl getLocal ( ) { result = getChildExpr ( 1 ) }
111
129
}
112
130
113
- /** A named import specifier. */
131
+ /**
132
+ * A named import specifier.
133
+ *
134
+ * Examples:
135
+ *
136
+ * ```
137
+ * import
138
+ * {
139
+ * log, // named import specifier
140
+ * error as fatal // renaming import specifier
141
+ * } from 'console';
142
+ * ```
143
+ */
114
144
class NamedImportSpecifier extends ImportSpecifier , @namedimportspecifier { }
115
145
116
- /** A default import specifier. */
146
+ /**
147
+ * A default import specifier.
148
+ *
149
+ * Example:
150
+ *
151
+ * ```
152
+ * import
153
+ * console // default import specifier
154
+ * from 'console';
155
+ * ```
156
+ */
117
157
class ImportDefaultSpecifier extends ImportSpecifier , @importdefaultspecifier {
118
158
override string getImportedName ( ) { result = "default" }
119
159
}
120
160
121
- /** A namespace import specifier. */
161
+ /**
162
+ * A namespace import specifier.
163
+ *
164
+ * Example:
165
+ *
166
+ * ```
167
+ * import
168
+ * * as console // namespace import specifier
169
+ * from 'console';
170
+ * ```
171
+ */
122
172
class ImportNamespaceSpecifier extends ImportSpecifier , @importnamespacespecifier { }
123
173
124
- /** A bulk import that imports an entire module as a namespace. */
174
+ /**
175
+ * A bulk import that imports an entire module as a namespace.
176
+ *
177
+ * Example:
178
+ *
179
+ * ```
180
+ * import * as console from 'console';
181
+ * ```
182
+ */
125
183
class BulkImportDeclaration extends ImportDeclaration {
126
184
BulkImportDeclaration ( ) { getASpecifier ( ) instanceof ImportNamespaceSpecifier }
127
185
128
186
/** Gets the local namespace variable under which the module is imported. */
129
187
VarDecl getLocal ( ) { result = getASpecifier ( ) .getLocal ( ) }
130
188
}
131
189
132
- /** A selective import that imports zero or more declarations. */
190
+ /**
191
+ * A selective import that imports zero or more declarations.
192
+ *
193
+ * Example:
194
+ *
195
+ * ```
196
+ * import console, { log } from 'console';
197
+ * ```
198
+ */
133
199
class SelectiveImportDeclaration extends ImportDeclaration {
134
200
SelectiveImportDeclaration ( ) { not this instanceof BulkImportDeclaration }
135
201
@@ -147,16 +213,20 @@ class SelectiveImportDeclaration extends ImportDeclaration {
147
213
/**
148
214
* An export declaration.
149
215
*
150
- * There are three kinds of export declarations :
216
+ * Examples :
151
217
*
152
- * - a bulk re-export declaration of the form `export * from 'a'`, which re-exports
153
- * all exports of another module;
154
- * - a default export declaration of the form `export default var x = 42`, which exports
155
- * a local value or declaration as the default export;
156
- * - a named export declaration such as `export { x, y as z }`, which exports local
157
- * values or declarations under specific names; a named export declaration
158
- * may also export symbols itself imported from another module, as in
159
- * `export { x } from 'a'`.
218
+ * ```
219
+ * export * from 'a'; // bulk re-export declaration
220
+ *
221
+ * export default var x = 42; // default export declaration
222
+ * export default function f() {}; // default export declaration
223
+ * export default 42; // default export declaration
224
+ *
225
+ * export { x, y as z }; // named export declaration
226
+ * export var x = 42; // named export declaration
227
+ * export { x } from 'a'; // named re-export declaration
228
+ * export x from 'a'; // default re-export declaration
229
+ * ```
160
230
*/
161
231
abstract class ExportDeclaration extends Stmt , @exportdeclaration {
162
232
/** Gets the module to which this export declaration belongs. */
@@ -192,6 +262,12 @@ abstract class ExportDeclaration extends Stmt, @exportdeclaration {
192
262
/**
193
263
* A bulk re-export declaration of the form `export * from 'a'`, which re-exports
194
264
* all exports of another module.
265
+ *
266
+ * Examples:
267
+ *
268
+ * ```
269
+ * export * from 'a'; // bulk re-export declaration
270
+ * ```
195
271
*/
196
272
class BulkReExportDeclaration extends ReExportDeclaration , @exportalldeclaration {
197
273
/** Gets the name of the module from which this declaration re-exports. */
@@ -229,8 +305,15 @@ private predicate isShadowedFromBulkExport(BulkReExportDeclaration reExport, str
229
305
}
230
306
231
307
/**
232
- * A default export declaration such as `export default function f{}`
233
- * or `export default { x: 42 }`.
308
+ * A default export declaration.
309
+ *
310
+ * Examples:
311
+ *
312
+ * ```
313
+ * export default var x = 42;
314
+ * export default function f() {};
315
+ * export default 42;
316
+ * ```
234
317
*/
235
318
class ExportDefaultDeclaration extends ExportDeclaration , @exportdefaultdeclaration {
236
319
/** Gets the operand statement or expression that is exported by this declaration. */
@@ -253,7 +336,16 @@ class ExportDefaultDeclaration extends ExportDeclaration, @exportdefaultdeclarat
253
336
}
254
337
}
255
338
256
- /** A named export declaration such as `export { x, y }` or `export var x = 42`. */
339
+ /** A named export declaration.
340
+ * *
341
+ * Examples:
342
+ *
343
+ * ```
344
+ * export { x, y as z };
345
+ * export var x = 42;
346
+ * export { x } from 'a';
347
+ * ```
348
+ * */
257
349
class ExportNamedDeclaration extends ExportDeclaration , @exportnameddeclaration {
258
350
/** Gets the operand statement or expression that is exported by this declaration. */
259
351
ExprOrStmt getOperand ( ) { result = getChild ( - 1 ) }
@@ -322,7 +414,30 @@ class ExportNamedDeclaration extends ExportDeclaration, @exportnameddeclaration
322
414
}
323
415
}
324
416
325
- /** An export specifier in a named export declaration. */
417
+ /**
418
+ * An export specifier in an export declaration.
419
+ *
420
+ * Examples:
421
+ *
422
+ * ```
423
+ * export
424
+ * * // namespace export specifier
425
+ * from 'a';
426
+ *
427
+ * export
428
+ * default // default export specifier
429
+ * var x = 42;
430
+ *
431
+ * export {
432
+ * x, // named export specifier
433
+ * y as z // named export specifier
434
+ * };
435
+ *
436
+ * export
437
+ * x // default re-export specifier
438
+ * from 'a';
439
+ * ```
440
+ */
326
441
class ExportSpecifier extends Expr , @exportspecifier {
327
442
/** Gets the declaration to which this specifier belongs. */
328
443
ExportDeclaration getExportDeclaration ( ) { result = getParent ( ) }
@@ -380,21 +495,47 @@ class ExportSpecifier extends Expr, @exportspecifier {
380
495
}
381
496
382
497
/**
383
- * A named export specifier, for example `v` in `export { v }`.
498
+ * A named export specifier.
499
+ *
500
+ * Examples:
501
+ *
502
+ * ```
503
+ * export {
504
+ * x, // named export specifier
505
+ * y as z // named export specifier
506
+ * };
507
+ * ```
384
508
*/
385
509
class NamedExportSpecifier extends ExportSpecifier , @namedexportspecifier { }
386
510
387
511
/**
388
- * A default export specifier, for example `default` in `export default 42`,
389
- * or `v` in `export v from "mod"`.
512
+ * A default export specifier.
513
+ *
514
+ * Examples:
515
+ *
516
+ * ```
517
+ * export
518
+ * default // default export specifier
519
+ * 42;
520
+ * export
521
+ * x // default re-export specifier
522
+ * from 'a';
523
+ * ```
390
524
*/
391
525
class ExportDefaultSpecifier extends ExportSpecifier , @exportdefaultspecifier {
392
526
override string getExportedName ( ) { result = "default" }
393
527
}
394
528
395
529
/**
396
- * A default export specifier in a re-export declaration, for example `v` in
397
- * `export v from "mod"`.
530
+ * A default export specifier in a re-export declaration.
531
+ *
532
+ * Example:
533
+ *
534
+ * ```
535
+ * export
536
+ * x // default re-export specifier
537
+ * from 'a';
538
+ * ```
398
539
*/
399
540
class ReExportDefaultSpecifier extends ExportDefaultSpecifier {
400
541
ReExportDefaultSpecifier ( ) { getExportDeclaration ( ) instanceof ReExportDeclaration }
@@ -405,11 +546,29 @@ class ReExportDefaultSpecifier extends ExportDefaultSpecifier {
405
546
}
406
547
407
548
/**
408
- * A namespace export specifier, for example `*` in `export * from "mod"`.
549
+ * A namespace export specifier.
550
+ *
551
+ * Example:
552
+ *
553
+ * ```
554
+ * export
555
+ * * // namespace export specifier
556
+ * from 'a';
557
+ * ```
409
558
*/
410
559
class ExportNamespaceSpecifier extends ExportSpecifier , @exportnamespacespecifier { }
411
560
412
- /** An export declaration that re-exports declarations from another module. */
561
+ /**
562
+ * An export declaration that re-exports declarations from another module.
563
+ *
564
+ * Examples:
565
+ *
566
+ * ```
567
+ * export * from 'a'; // bulk re-export declaration
568
+ * export { x } from 'a'; // named re-export declaration
569
+ * export x from 'a'; // default re-export declaration
570
+ * ```
571
+ */
413
572
abstract class ReExportDeclaration extends ExportDeclaration {
414
573
/** Gets the path of the module from which this declaration re-exports. */
415
574
abstract ConstantString getImportedPath ( ) ;
@@ -441,7 +600,15 @@ private class LiteralReExportPath extends PathExprInModule, ConstantString {
441
600
override string getValue ( ) { result = this .( ConstantString ) .getStringValue ( ) }
442
601
}
443
602
444
- /** A named export declaration that re-exports symbols imported from another module. */
603
+ /**
604
+ * A named export declaration that re-exports symbols imported from another module.
605
+ *
606
+ * Example:
607
+ *
608
+ * ```
609
+ * export { x } from 'a';
610
+ * ```
611
+ */
445
612
class SelectiveReExportDeclaration extends ReExportDeclaration , ExportNamedDeclaration {
446
613
SelectiveReExportDeclaration ( ) { exists ( ExportNamedDeclaration .super .getImportedPath ( ) ) }
447
614
@@ -451,7 +618,19 @@ class SelectiveReExportDeclaration extends ReExportDeclaration, ExportNamedDecla
451
618
}
452
619
}
453
620
454
- /** An export declaration that exports zero or more declarations from the module it appears in. */
621
+ /**
622
+ * An export declaration that exports zero or more declarations from the module it appears in.
623
+ *
624
+ * Examples:
625
+ *
626
+ * ```
627
+ * export default var x = 42;
628
+ * export default function f() {};
629
+ * export default 42;
630
+ * export { x, y as z };
631
+ * export var x = 42;
632
+ * ```
633
+ */
455
634
class OriginalExportDeclaration extends ExportDeclaration {
456
635
OriginalExportDeclaration ( ) { not this instanceof ReExportDeclaration }
457
636
0 commit comments