UNPKG

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