Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: lib/statement.ts

Issue 2225953002: Strip more unused features. (Closed) Base URL: git@github.com:dart-lang/js_facade_gen.git@master
Patch Set: Fix types Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/module.ts ('k') | lib/type.ts » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 import * as ts from 'typescript';
2 import * as base from './base';
3 import {Transpiler} from './main';
4
5 type ClassLike = ts.ClassDeclaration | ts.InterfaceDeclaration;
6
7 export default class StatementTranspiler extends base.TranspilerBase {
8 constructor(tr: Transpiler) { super(tr); }
9
10 visitNode(node: ts.Node): boolean {
11 switch (node.kind) {
12 case ts.SyntaxKind.EmptyStatement:
13 this.emit(';');
14 break;
15 case ts.SyntaxKind.ReturnStatement:
16 let retStmt = <ts.ReturnStatement>node;
17 this.emit('return');
18 if (retStmt.expression) this.visit(retStmt.expression);
19 this.emit(';');
20 break;
21 case ts.SyntaxKind.BreakStatement:
22 case ts.SyntaxKind.ContinueStatement:
23 let breakContinue = <ts.BreakOrContinueStatement>node;
24 this.emit(breakContinue.kind === ts.SyntaxKind.BreakStatement ? 'break' : 'continue');
25 if (breakContinue.label) this.visit(breakContinue.label);
26 this.emit(';');
27 break;
28 case ts.SyntaxKind.VariableStatement:
29 let variableStmt = <ts.VariableStatement>node;
30 this.visit(variableStmt.declarationList);
31 this.emit(';');
32 break;
33 case ts.SyntaxKind.ExpressionStatement:
34 let expr = <ts.ExpressionStatement>node;
35 this.visit(expr.expression);
36 this.emit(';');
37 break;
38 case ts.SyntaxKind.SwitchStatement:
39 let switchStmt = <ts.SwitchStatement>node;
40 this.emit('switch (');
41 this.visit(switchStmt.expression);
42 this.emit(')');
43 this.visit(switchStmt.caseBlock);
44 break;
45 case ts.SyntaxKind.CaseBlock:
46 this.emit('{');
47 this.visitEach((<ts.CaseBlock>node).clauses);
48 this.emit('}');
49 break;
50 case ts.SyntaxKind.CaseClause:
51 let caseClause = <ts.CaseClause>node;
52 this.emit('case');
53 this.visit(caseClause.expression);
54 this.emit(':');
55 this.visitEach(caseClause.statements);
56 break;
57 case ts.SyntaxKind.DefaultClause:
58 this.emit('default :');
59 this.visitEach((<ts.DefaultClause>node).statements);
60 break;
61 case ts.SyntaxKind.IfStatement:
62 let ifStmt = <ts.IfStatement>node;
63 this.emit('if (');
64 this.visit(ifStmt.expression);
65 this.emit(')');
66 this.visit(ifStmt.thenStatement);
67 if (ifStmt.elseStatement) {
68 this.emit('else');
69 this.visit(ifStmt.elseStatement);
70 }
71 break;
72 case ts.SyntaxKind.ForStatement:
73 let forStmt = <ts.ForStatement>node;
74 this.emit('for (');
75 if (forStmt.initializer) this.visit(forStmt.initializer);
76 this.emit(';');
77 if (forStmt.condition) this.visit(forStmt.condition);
78 this.emit(';');
79 if (forStmt.incrementor) this.visit(forStmt.incrementor);
80 this.emit(')');
81 this.visit(forStmt.statement);
82 break;
83 case ts.SyntaxKind.ForInStatement:
84 // TODO(martinprobst): Dart's for-in loops actually have different seman tics, they are more
85 // like for-of loops, iterating over collections.
86 let forInStmt = <ts.ForInStatement>node;
87 this.emit('for (');
88 if (forInStmt.initializer) this.visit(forInStmt.initializer);
89 this.emit('in');
90 this.visit(forInStmt.expression);
91 this.emit(')');
92 this.visit(forInStmt.statement);
93 break;
94 case ts.SyntaxKind.ForOfStatement:
95 let forOfStmt = <ts.ForOfStatement>node;
96 this.emit('for (');
97 if (forOfStmt.initializer) this.visit(forOfStmt.initializer);
98 this.emit('in');
99 this.visit(forOfStmt.expression);
100 this.emit(')');
101 this.visit(forOfStmt.statement);
102 break;
103 case ts.SyntaxKind.WhileStatement:
104 let whileStmt = <ts.WhileStatement>node;
105 this.emit('while (');
106 this.visit(whileStmt.expression);
107 this.emit(')');
108 this.visit(whileStmt.statement);
109 break;
110 case ts.SyntaxKind.DoStatement:
111 let doStmt = <ts.DoStatement>node;
112 this.emit('do');
113 this.visit(doStmt.statement);
114 this.emit('while (');
115 this.visit(doStmt.expression);
116 this.emit(') ;');
117 break;
118
119 case ts.SyntaxKind.ThrowStatement:
120 let throwStmt = <ts.ThrowStatement>node;
121 let surroundingCatchClause = this.getAncestor(throwStmt, ts.SyntaxKind.C atchClause);
122 if (surroundingCatchClause) {
123 let ref = (<ts.CatchClause>surroundingCatchClause).variableDeclaration ;
124 if (ref.getText() === throwStmt.expression.getText()) {
125 this.emit('rethrow');
126 this.emit(';');
127 break;
128 }
129 }
130
131 this.emit('throw');
132 this.visit(throwStmt.expression);
133 this.emit(';');
134 break;
135 case ts.SyntaxKind.TryStatement:
136 let tryStmt = <ts.TryStatement>node;
137 this.emit('try');
138 this.visit(tryStmt.tryBlock);
139 if (tryStmt.catchClause) {
140 this.visit(tryStmt.catchClause);
141 }
142 if (tryStmt.finallyBlock) {
143 this.emit('finally');
144 this.visit(tryStmt.finallyBlock);
145 }
146 break;
147 case ts.SyntaxKind.CatchClause:
148 let ctch = <ts.CatchClause>node;
149 if (ctch.variableDeclaration.type) {
150 this.emit('on');
151 this.visit(ctch.variableDeclaration.type);
152 }
153 this.emit('catch');
154 this.emit('(');
155 this.visit(ctch.variableDeclaration.name);
156 this.emit(',');
157 this.visit(ctch.variableDeclaration.name);
158 this.emitNoSpace('_stack');
159 this.emit(')');
160 this.visit(ctch.block);
161 break;
162
163 case ts.SyntaxKind.Block:
164 this.emit('{');
165 this.visitEach((<ts.Block>node).statements);
166 this.emit('}');
167 break;
168 default:
169 return false;
170 }
171 return true;
172 }
173 }
OLDNEW
« no previous file with comments | « lib/module.ts ('k') | lib/type.ts » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698