1 | FS Node
|
2 | -------
|
3 |
|
4 | Going not to be implemented
|
5 | ---------------------------
|
6 | WithStatement
|
7 | EmptyStatement
|
8 |
|
9 | Unimplemented
|
10 | -------------
|
11 |
|
12 | ?? LabeledStatement
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | 1) Class and Unittest
|
18 | ---------------------
|
19 |
|
20 | ? SequenceExpression
|
21 | ? LogicalExpression
|
22 | ? UnaryExpression
|
23 |
|
24 | 1.5) Document it first ;)
|
25 | -------------------------
|
26 |
|
27 |
|
28 | 2) FSParser can create item from fs source
|
29 | ------------------------------------------
|
30 |
|
31 |
|
32 | 3) FSTranspiler can transpile it into JS
|
33 | ----------------------------------------
|
34 |
|
35 | ArrayPattern
|
36 | ObjectPattern
|
37 | AssignmentPattern
|
38 | RestElement
|
39 | TryStatement
|
40 | CatchClause
|
41 | ThrowStatement
|
42 | SpreadElement
|
43 | TaggedTemplateExpression
|
44 | TemplateElement
|
45 | TemplateLiteral
|
46 | MetaProperty
|
47 | SwitchStatement
|
48 | SwitchCase
|
49 |
|
50 | 3 b) Unit tested
|
51 | ----------------------------------------
|
52 |
|
53 | DoWhileStatement
|
54 | ImportNamespaceSpecifier
|
55 | ImportDeclaration
|
56 | ImportSpecifier
|
57 | ImportDefaultSpecifier
|
58 | ForStatement
|
59 | ForInStatement
|
60 | ForOfStatement
|
61 | UpdateExpression
|
62 | ExportNamedDeclaration
|
63 | ExportAllDeclaration
|
64 | ExportSpecifier
|
65 | ExportDefaultDeclaration
|
66 | ConditionalExpression
|
67 | ClassDeclaration
|
68 | ClassExpression
|
69 | ClassBody
|
70 | Super
|
71 | MethodDefinition
|
72 | IfStatement
|
73 | WhileStatement
|
74 | NewExpression
|
75 | MemberExpression
|
76 | AssignmentExpression
|
77 | BinaryExpression
|
78 | ExpressionStatement
|
79 | AwaitExpression
|
80 | YieldExpression
|
81 | ArrowFunctionExpression
|
82 | FunctionDeclaration
|
83 | BreakStatement
|
84 | ContinueStatement
|
85 | DebuggerStatement
|
86 | ThisExpression
|
87 | ReturnStatement
|
88 | FunctionExpression
|
89 | ObjectExpression
|
90 | Property
|
91 | ArrayExpression
|
92 | BlockStatement
|
93 | CallExpression
|
94 | VariableDeclaration
|
95 | VariableDeclarator
|
96 | Program
|
97 | Literal
|
98 | Identifier
|
99 |
|
100 | 4) JSParser can create item from js source
|
101 | ------------------------------------------
|
102 |
|
103 | 5) JSTranspiler can transpile it into FS
|
104 | ----------------------------------------
|
105 |
|
106 | 6) Syntax highlighter
|
107 | ---------------------
|
108 |
|
109 | 7) Syntax highlighter
|
110 | ---------------------
|
111 |
|
112 | 8) Docs page
|
113 | ------------
|
114 |
|
115 | --
|
116 |
|
117 | ## Expressions and Patterns
|
118 |
|
119 | A binding pattern can be one of the following:
|
120 |
|
121 | ```ts
|
122 | type BindingPattern = ArrayPattern | ObjectPattern;
|
123 | ```
|
124 |
|
125 | An expression can be one of the following:
|
126 |
|
127 | ```ts
|
128 | type Expression = ThisExpression | Identifier | Literal |
|
129 | ArrayExpression | ObjectExpression | FunctionExpression | ArrowFunctionExpression | ClassExpression |
|
130 | TaggedTemplateExpression | MemberExpression | Super | MetaProperty |
|
131 | NewExpression | CallExpression | UpdateExpression | AwaitExpression | UnaryExpression |
|
132 | BinaryExpression | LogicalExpression | ConditionalExpression |
|
133 | YieldExpression | AssignmentExpression | SequenceExpression;
|
134 | ```
|
135 |
|
136 | Array Pattern
|
137 |
|
138 | ```ts
|
139 | interface ArrayPattern {
|
140 | type: 'ArrayPattern';
|
141 | elements: ArrayPatternElement[];
|
142 | }
|
143 | ```
|
144 |
|
145 | with
|
146 |
|
147 | ```ts
|
148 | type ArrayPatternElement = AssignmentPattern | Identifier | BindingPattern | RestElement | null;
|
149 |
|
150 | interface RestElement {
|
151 | type: 'RestElement';
|
152 | argument: Identifier | BindingPattern;
|
153 | }
|
154 | ```
|
155 |
|
156 | Assignment Pattern
|
157 |
|
158 | interface AssignmentPattern {
|
159 | type: 'AssignmentPattern';
|
160 | left: Identifier | BindingPattern;
|
161 | right: Expression;
|
162 | }
|
163 |
|
164 | Object Pattern
|
165 |
|
166 | interface ObjectPattern {
|
167 | type: 'ObjectPattern';
|
168 | properties: Property[];
|
169 | }
|
170 |
|
171 | This Expression
|
172 |
|
173 | interface ThisExpression {
|
174 | type: 'ThisExpression';
|
175 | }
|
176 |
|
177 | Identifier
|
178 |
|
179 | interface Identifier {
|
180 | type: 'Identifier';
|
181 | name: string;
|
182 | }
|
183 |
|
184 | Literal
|
185 |
|
186 | interface Literal {
|
187 | type: 'Literal';
|
188 | value: boolean | number | string | RegExp | null;
|
189 | raw: string;
|
190 | regex?: { pattern: string, flags: string };
|
191 | }
|
192 |
|
193 | The regex property only applies to regular expression literals.
|
194 | Array Expression
|
195 |
|
196 | interface ArrayExpression {
|
197 | type: 'ArrayExpression';
|
198 | elements: ArrayExpressionElement[];
|
199 | }
|
200 |
|
201 | where
|
202 |
|
203 | type ArrayExpressionElement = Expression | SpreadElement;
|
204 |
|
205 | Object Expression
|
206 |
|
207 | interface ObjectExpression {
|
208 | type: 'ObjectExpression';
|
209 | properties: Property[];
|
210 | }
|
211 |
|
212 | where
|
213 |
|
214 | interface Property {
|
215 | type: 'Property';
|
216 | key: Identifier | Literal;
|
217 | computed: boolean;
|
218 | value: AssignmentPattern | Identifier | BindingPattern | FunctionExpression | null;
|
219 | kind: 'get' | 'set' | 'init';
|
220 | method: false;
|
221 | shorthand: boolean;
|
222 | }
|
223 |
|
224 | Function Expression
|
225 |
|
226 | interface FunctionExpression {
|
227 | type: 'FunctionExpression';
|
228 | id: Identifier | null;
|
229 | params: FunctionParameter[];
|
230 | body: BlockStatement;
|
231 | generator: boolean;
|
232 | async: boolean;
|
233 | expression: boolean;
|
234 | }
|
235 |
|
236 | with
|
237 |
|
238 | type FunctionParameter = AssignmentPattern | Identifier | BindingPattern;
|
239 |
|
240 | The value of generator is true for a generator expression.
|
241 | Arrow Function Expression
|
242 |
|
243 | interface FunctionExpression {
|
244 | type: 'ArrowFunctionExpression';
|
245 | id: Identifier | null;
|
246 | params: FunctionParameter[];
|
247 | body: BlockStatement | Expression;
|
248 | generator: boolean;
|
249 | async: boolean;
|
250 | expression: false;
|
251 | }
|
252 |
|
253 | Class Expression
|
254 |
|
255 | interface ClassExpression {
|
256 | type: 'ClassExpression';
|
257 | id: Identifier | null;
|
258 | superClass: Identifier | null;
|
259 | body: ClassBody;
|
260 |
|
261 | with
|
262 |
|
263 | interface ClassBody {
|
264 | type: 'ClassBody';
|
265 | body: MethodDefinition[];
|
266 | }
|
267 |
|
268 | interface MethodDefinition {
|
269 | type: 'MethodDefinition';
|
270 | key: Expression | null;
|
271 | computed: boolean;
|
272 | value: FunctionExpression | null;
|
273 | kind: 'method' | 'constructor';
|
274 | static: boolean;
|
275 | }
|
276 |
|
277 | Tagged Template Expression
|
278 |
|
279 | ```ts
|
280 | interface TaggedTemplateExpression {
|
281 | type: 'TaggedTemplateExpression';
|
282 | readonly tag: Expression;
|
283 | readonly quasi: TemplateLiteral;
|
284 | }
|
285 | ```
|
286 |
|
287 | with
|
288 |
|
289 | interface TemplateElement {
|
290 | type: 'TemplateElement';
|
291 | value: { cooked: string; raw: string };
|
292 | tail: boolean;
|
293 | }
|
294 |
|
295 | interface TemplateLiteral {
|
296 | type: 'TemplateLiteral';
|
297 | quasis: TemplateElement[];
|
298 | expressions: Expression[];
|
299 | }
|
300 |
|
301 | Member Expression
|
302 |
|
303 | ```ts
|
304 | interface MemberExpression {
|
305 | type: 'MemberExpression';
|
306 | computed: boolean;
|
307 | object: Expression;
|
308 | property: Expression;
|
309 | }
|
310 | ```
|
311 |
|
312 | Super
|
313 |
|
314 | interface Super {
|
315 | type: 'Super';
|
316 | }
|
317 |
|
318 | MetaProperty
|
319 |
|
320 | interface MetaProperty {
|
321 | type: 'MetaProperty';
|
322 | meta: Identifier;
|
323 | property: Identifier;
|
324 | }
|
325 |
|
326 | Call and New Expressions
|
327 |
|
328 | interface CallExpression {
|
329 | type: 'CallExpression';
|
330 | callee: Expression;
|
331 | arguments: ArgumentListElement[];
|
332 | }
|
333 |
|
334 | interface NewExpression {
|
335 | type: 'NewExpression';
|
336 | callee: Expression;
|
337 | arguments: ArgumentListElement[];
|
338 | }
|
339 |
|
340 | with
|
341 |
|
342 | type ArgumentListElement = Expression | SpreadElement;
|
343 |
|
344 | interface SpreadElement {
|
345 | type: 'SpreadElement';
|
346 | argument: Expression;
|
347 | }
|
348 |
|
349 | Update Expression
|
350 |
|
351 | interface UpdateExpression {
|
352 | type: 'UpdateExpression';
|
353 | operator: '++' | '--';
|
354 | argument: Expression;
|
355 | prefix: boolean;
|
356 | }
|
357 |
|
358 | Await Expression
|
359 |
|
360 | interface AwaitExpression {
|
361 | type: 'AwaitExpression';
|
362 | argument: Expression;
|
363 | }
|
364 |
|
365 | Unary Expression
|
366 |
|
367 | interface UnaryExpression {
|
368 | type: 'UnaryExpression';
|
369 | operator: '+' | '-' | '~' | '!' | 'delete' | 'void' | 'typeof';
|
370 | argument: Expression;
|
371 | prefix: true;
|
372 | }
|
373 |
|
374 | Binary Expression
|
375 |
|
376 | interface BinaryExpression {
|
377 | type: 'BinaryExpression';
|
378 | operator: 'instanceof' | 'in' | '+' | '-' | '*' | '/' | '%' | '**' |
|
379 | '|' | '^' | '&' | '==' | '!=' | '===' | '!==' |
|
380 | '<' | '>' | '<=' | '<<' | '>>' | '>>>';
|
381 | left: Expression;
|
382 | right: Expression;
|
383 | }
|
384 |
|
385 | Logical Expression
|
386 |
|
387 | interface LogicalExpression {
|
388 | type: 'LogicalExpression';
|
389 | operator: '||' | '&&';
|
390 | left: Expression;
|
391 | right: Expression;
|
392 | }
|
393 |
|
394 | Conditional Expression
|
395 |
|
396 | interface ConditionalExpression {
|
397 | type: 'ConditionalExpression';
|
398 | test: Expression;
|
399 | consequent: Statement;
|
400 | alternate?: Statement;
|
401 | }
|
402 |
|
403 | Yield Expression
|
404 |
|
405 | interface YieldExpression {
|
406 | type: 'YieldExpression';
|
407 | argument: Expression | null;
|
408 | delegate: boolean;
|
409 | }
|
410 |
|
411 | Assignment Expression
|
412 |
|
413 | interface AssignmentExpression {
|
414 | type: 'AssignmentExpression';
|
415 | operator: '=' | '*=' | '**=' | '/=' | '%=' | '+=' | '-=' |
|
416 | '<<=' | '>>=' | '>>>=' | '&=' | '^=' | '|=';
|
417 | left: Expression;
|
418 | right: Expression;
|
419 | }
|
420 |
|
421 | Sequence Expression
|
422 |
|
423 | interface SequenceExpression {
|
424 | type: 'SequenceExpression';
|
425 | expressions: Expression[];
|
426 | }
|
427 |
|
428 | Statements and Declarations
|
429 |
|
430 | A statement can be one of the following:
|
431 |
|
432 | ```ts
|
433 | type Statement = BlockStatement | BreakStatement | ContinueStatement |
|
434 | DebuggerStatement | DoWhileStatement | EmptyStatement |
|
435 | ExpressionStatement | ForStatement | ForInStatement |
|
436 | ForOfStatement | FunctionDeclaration | IfStatement |
|
437 | LabeledStatement | ReturnStatement | SwitchStatement |
|
438 | ThrowStatement | TryStatement | VariableDeclaration |
|
439 | WhileStatement | WithStatement;
|
440 | ```
|
441 |
|
442 | A declaration can be one of the following:
|
443 |
|
444 | ```ts
|
445 | type Declaration = ClassDeclaration | FunctionDeclaration | VariableDeclaration;
|
446 | ```
|
447 |
|
448 | A statement list item is either a statement or a declaration:
|
449 |
|
450 | type StatementListItem = Declaration | Statement;
|
451 |
|
452 | ## Block Statement
|
453 |
|
454 | A series of statements enclosed by a pair of curly braces form a block statement:
|
455 |
|
456 | ```ts
|
457 | interface BlockStatement {
|
458 | type: 'BlockStatement';
|
459 | body: StatementListItem[];
|
460 | }
|
461 | ```
|
462 |
|
463 | Break Statement
|
464 |
|
465 | interface BreakStatement {
|
466 | type: 'BreakStatement';
|
467 | label: Identifier | null;
|
468 | }
|
469 |
|
470 | Class Declaration
|
471 |
|
472 | interface ClassDeclaration {
|
473 | type: 'ClassDeclaration';
|
474 | id: Identifier | null;
|
475 | superClass: Identifier | null;
|
476 | body: ClassBody;
|
477 | }
|
478 |
|
479 | Continue Statement
|
480 |
|
481 | interface ContinueStatement {
|
482 | type: 'ContinueStatement';
|
483 | label: Identifier | null;
|
484 | }
|
485 |
|
486 | Debugger Statement
|
487 |
|
488 | interface DebuggerStatement {
|
489 | type: 'DebuggerStatement';
|
490 | }
|
491 |
|
492 | Do-While Statement
|
493 |
|
494 | interface DoWhileStatement {
|
495 | type: 'DoWhileStatement';
|
496 | body: Statement;
|
497 | test: Expression;
|
498 | }
|
499 |
|
500 | Empty Statement
|
501 |
|
502 | interface EmptyStatement {
|
503 | type: 'EmptyStatement';
|
504 | }
|
505 |
|
506 | Expression Statement
|
507 |
|
508 | interface ExpressionStatement {
|
509 | type: 'ExpressionStatement';
|
510 | expression: Expression;
|
511 | directive?: string;
|
512 | }
|
513 |
|
514 | When the expression statement represents a directive (such as "use strict"), then the directive property will contain the directive string.
|
515 | For Statement
|
516 |
|
517 | interface ForStatement {
|
518 | type: 'ForStatement';
|
519 | init: Expression | VariableDeclaration | null;
|
520 | test: Expression | null;
|
521 | update: Expression | null;
|
522 | body: Statement;
|
523 | }
|
524 |
|
525 | For-In Statement
|
526 |
|
527 | interface ForInStatement {
|
528 | type: 'ForInStatement';
|
529 | left: Expression;
|
530 | right: Expression;
|
531 | body: Statement;
|
532 | each: false;
|
533 | }
|
534 |
|
535 | For-Of Statement
|
536 |
|
537 | interface ForOfStatement {
|
538 | type: 'ForOfStatement';
|
539 | left: Expression;
|
540 | right: Expression;
|
541 | body: Statement;
|
542 | }
|
543 |
|
544 | Function Declaration
|
545 |
|
546 | interface FunctionDeclaration {
|
547 | type: 'FunctionDeclaration';
|
548 | id: Identifier | null;
|
549 | params: FunctionParameter[];
|
550 | body: BlockStatement;
|
551 | generator: boolean;
|
552 | async: boolean;
|
553 | expression: false;
|
554 | }
|
555 |
|
556 | with
|
557 |
|
558 | type FunctionParameter = AssignmentPattern | Identifier | BindingPattern;
|
559 |
|
560 | If Statement
|
561 |
|
562 | interface IfStatement {
|
563 | type: 'IfStatement';
|
564 | test: Expression;
|
565 | consequent: Statement;
|
566 | alternate?: Statement;
|
567 | }
|
568 |
|
569 | Labelled Statement
|
570 |
|
571 | A statement prefixed by a label becomes a labelled statement:
|
572 |
|
573 | interface LabeledStatement {
|
574 | type: 'LabeledStatement';
|
575 | label: Identifier;
|
576 | body: Statement;
|
577 | }
|
578 |
|
579 | Return Statement
|
580 |
|
581 | interface ReturnStatement {
|
582 | type: 'ReturnStatement';
|
583 | argument: Expression | null;
|
584 | }
|
585 |
|
586 | Switch Statement
|
587 |
|
588 | interface SwitchStatement {
|
589 | type: 'SwitchStatement';
|
590 | discriminant: Expression;
|
591 | cases: SwitchCase[];
|
592 | }
|
593 |
|
594 | with
|
595 |
|
596 | interface SwitchCase {
|
597 | type: 'SwitchCase';
|
598 | test: Expression;
|
599 | consequent: Statement[];
|
600 | }
|
601 |
|
602 | Throw Statement
|
603 |
|
604 | interface ThrowStatement {
|
605 | type: 'ThrowStatement';
|
606 | argument: Expression;
|
607 | }
|
608 |
|
609 | Try Statement
|
610 |
|
611 | interface TryStatement {
|
612 | type: 'TryStatement';
|
613 | block: BlockStatement;
|
614 | handler: CatchClause | null;
|
615 | finalizer: BlockStatement | null;
|
616 | }
|
617 |
|
618 | with
|
619 |
|
620 | interface CatchClause {
|
621 | type: 'CatchClause';
|
622 | param: Identifier | BindingPattern;
|
623 | body: BlockStatement;
|
624 | }
|
625 |
|
626 | Variable Declaration
|
627 |
|
628 | interface VariableDeclaration {
|
629 | type: 'VariableDeclaration';
|
630 | declarations: VariableDeclarator[];
|
631 | kind: 'var' | 'const' | 'let';
|
632 | }
|
633 |
|
634 | with
|
635 |
|
636 | interface VariableDeclarator {
|
637 | type: 'VariableDeclarator';
|
638 | id: Identifier | BindingPattern;
|
639 | init: Expression | null;
|
640 | }
|
641 |
|
642 | While Statement
|
643 |
|
644 | interface WhileStatement {
|
645 | type: 'WhileStatement';
|
646 | test: Expression;
|
647 | body: Statement;
|
648 | }
|
649 |
|
650 | With Statement
|
651 |
|
652 | interface WithStatement {
|
653 | type: 'WithStatement';
|
654 | object: Expression;
|
655 | body: Statement;
|
656 | }
|
657 |
|
658 | Scripts and Modules
|
659 |
|
660 | A program can be either a script or a module.
|
661 |
|
662 | interface Program {
|
663 | type: 'Program';
|
664 | sourceType: 'script';
|
665 | body: StatementListItem[];
|
666 | }
|
667 |
|
668 | interface Program {
|
669 | type: 'Program';
|
670 | sourceType: 'module';
|
671 | body: ModuleItem[];
|
672 | }
|
673 |
|
674 | with
|
675 |
|
676 | type StatementListItem = Declaration | Statement;
|
677 | type ModuleItem = ImportDeclaration | ExportDeclaration | StatementListItem;
|
678 |
|
679 | Import Declaration
|
680 |
|
681 | type ImportDeclaration {
|
682 | type: 'ImportDeclaration';
|
683 | specifiers: ImportSpecifier[];
|
684 | source: Literal;
|
685 | }
|
686 |
|
687 | with
|
688 |
|
689 | interface ImportSpecifier {
|
690 | type: 'ImportSpecifier' | 'ImportDefaultSpecifier' | 'ImportNamespaceSpecifier';
|
691 | local: Identifier;
|
692 | imported?: Identifier;
|
693 | }
|
694 |
|
695 | Export Declaration
|
696 |
|
697 | An export declaration can be in the form of a batch, a default, or a named declaration.
|
698 |
|
699 | type ExportDeclaration = ExportAllDeclaration | ExportDefaultDeclaration | ExportNamedDeclaration;
|
700 |
|
701 | Each possible export declaration is described as follows:
|
702 |
|
703 | interface ExportAllDeclaration {
|
704 | type: 'ExportAllDeclaration';
|
705 | source: Literal;
|
706 | }
|
707 |
|
708 | interface ExportDefaultDeclaration {
|
709 | type: 'ExportDefaultDeclaration';
|
710 | declaration: Identifier | BindingPattern | ClassDeclaration | Expression | FunctionDeclaration;
|
711 | }
|
712 |
|
713 | interface ExportNamedDeclaration {
|
714 | type: 'ExportNamedDeclaration';
|
715 | declaration: ClassDeclaration | FunctionDeclaration | VariableDeclaration;
|
716 | specifiers: ExportSpecifier[];
|
717 | source: Literal;
|
718 | }
|
719 |
|
720 | with
|
721 |
|
722 | interface ExportSpecifier {
|
723 | type: 'ExportSpecifier';
|
724 | exported: Identifier;
|
725 | local: Identifier;
|
726 | };
|