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

Side by Side Diff: lib/type.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/statement.ts ('k') | package.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import * as ts from 'typescript'; 1 import * as ts from 'typescript';
2
2 import * as base from './base'; 3 import * as base from './base';
4 import {FacadeConverter, fixupIdentifierName} from './facade_converter';
3 import {Transpiler} from './main'; 5 import {Transpiler} from './main';
4 import {FacadeConverter} from './facade_converter';
5 6
6 export default class TypeTranspiler extends base.TranspilerBase { 7 export default class TypeTranspiler extends base.TranspilerBase {
7 constructor(tr: Transpiler, private fc: FacadeConverter) { super(tr); } 8 constructor(tr: Transpiler, private fc: FacadeConverter) { super(tr); }
8 9
9 visitNode(node: ts.Node): boolean { 10 visitNode(node: ts.Node): boolean {
11 if (base.isTypeNode(node)) {
12 this.emit(this.fc.generateDartTypeName(<ts.TypeNode>node, this.insideCodeC omment));
13 return true;
14 }
10 switch (node.kind) { 15 switch (node.kind) {
11 case ts.SyntaxKind.TypeLiteral:
12 let indexType = this.maybeDestructureIndexType(<ts.TypeLiteralNode>node) ;
13 if (indexType) {
14 // This is effectively a Map.
15 this.emit('Map <');
16 this.visit(indexType[0]);
17 this.emit(',');
18 this.visit(indexType[1]);
19 this.emit('>');
20 } else {
21 // Dart doesn't support other type literals.
22 this.emit('dynamic');
23 }
24 break;
25 case ts.SyntaxKind.UnionType:
26 this.emit('dynamic /*');
27 this.visitList((<ts.UnionTypeNode>node).types, '|');
28 this.emit('*/');
29 break;
30 case ts.SyntaxKind.TypeReference:
31 let typeRef = <ts.TypeReferenceNode>node;
32 this.fc.visitTypeName(typeRef.typeName);
33 this.maybeVisitTypeArguments(typeRef);
34 break;
35 case ts.SyntaxKind.TypeAssertionExpression: 16 case ts.SyntaxKind.TypeAssertionExpression:
36 let typeAssertExpr = <ts.TypeAssertion>node; 17 let typeAssertExpr = <ts.TypeAssertion>node;
37 if (this.isReifiedTypeLiteral(typeAssertExpr)) { 18 if (this.isReifiedTypeLiteral(typeAssertExpr)) {
38 this.visit(typeAssertExpr.expression); 19 this.visit(typeAssertExpr.expression);
39 break; // type is handled by the container literal itself. 20 break; // type is handled by the container literal itself.
40 } 21 }
41 this.emit('('); 22 this.emit('(');
42 this.visit(typeAssertExpr.expression); 23 this.visit(typeAssertExpr.expression);
43 this.emit('as'); 24 this.emit('as');
44 this.visit(typeAssertExpr.type); 25 this.visit(typeAssertExpr.type);
45 this.emit(')'); 26 this.emit(')');
46 break; 27 break;
47 case ts.SyntaxKind.TypeParameter: 28 case ts.SyntaxKind.TypeParameter:
48 let typeParam = <ts.TypeParameterDeclaration>node; 29 let typeParam = <ts.TypeParameterDeclaration>node;
49 this.visit(typeParam.name); 30 this.visit(typeParam.name);
50 if (typeParam.constraint) { 31 if (typeParam.constraint) {
51 this.emit('extends'); 32 this.emit('extends');
52 this.visit(typeParam.constraint); 33 this.visit(typeParam.constraint);
53 } 34 }
54 break; 35 break;
55 case ts.SyntaxKind.ArrayType:
56 this.emit('List');
57 this.emit('<');
58 this.visit((<ts.ArrayTypeNode>node).elementType);
59 this.emit('>');
60 break;
61 case ts.SyntaxKind.FunctionType:
62 this.emit('dynamic /*');
63 this.emit(node.getText());
64 this.emit('*/');
65 break;
66 case ts.SyntaxKind.QualifiedName: 36 case ts.SyntaxKind.QualifiedName:
37 // TODO(jacobr): there is overlap between this case and
38 // generateDartTypeName in facade_converter.
67 let first = <ts.QualifiedName>node; 39 let first = <ts.QualifiedName>node;
40 let match = this.fc.lookupCustomDartTypeName(first, this.insideCodeComme nt);
41 if (match) {
42 this.emitType(match.name, match.comment);
43 break;
44 }
68 this.visit(first.left); 45 this.visit(first.left);
69 this.emit('.'); 46 this.emit('.');
70 this.visit(first.right); 47 this.visit(first.right);
71 break; 48 break;
72 case ts.SyntaxKind.Identifier: 49 case ts.SyntaxKind.Identifier:
73 let ident = <ts.Identifier>node; 50 let ident = <ts.Identifier>node;
74 this.fc.visitTypeName(ident); 51 let text = fixupIdentifierName(ident.text);
52 this.emit(text);
75 break; 53 break;
54 // TODO(jacobr): all these cases might be obsolete.
76 case ts.SyntaxKind.NumberKeyword: 55 case ts.SyntaxKind.NumberKeyword:
77 this.emit('num'); 56 this.emit('num');
78 break; 57 break;
79 case ts.SyntaxKind.StringKeyword: 58 case ts.SyntaxKind.StringKeyword:
80 this.emit('String'); 59 this.emit('String');
81 break; 60 break;
82 case ts.SyntaxKind.VoidKeyword: 61 case ts.SyntaxKind.VoidKeyword:
83 this.emit('void'); 62 this.emit('void');
84 break; 63 break;
85 case ts.SyntaxKind.BooleanKeyword: 64 case ts.SyntaxKind.BooleanKeyword:
(...skipping 13 matching lines...) Expand all
99 node.type.kind === ts.SyntaxKind.ArrayType) { 78 node.type.kind === ts.SyntaxKind.ArrayType) {
100 return true; 79 return true;
101 } else if ( 80 } else if (
102 node.expression.kind === ts.SyntaxKind.ObjectLiteralExpression && 81 node.expression.kind === ts.SyntaxKind.ObjectLiteralExpression &&
103 node.type.kind === ts.SyntaxKind.TypeLiteral) { 82 node.type.kind === ts.SyntaxKind.TypeLiteral) {
104 return true; 83 return true;
105 } 84 }
106 return false; 85 return false;
107 } 86 }
108 } 87 }
OLDNEW
« no previous file with comments | « lib/statement.ts ('k') | package.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698