| OLD | NEW |
| 1 import ts = require('typescript'); | 1 import ts = require('typescript'); |
| 2 import base = require('./base'); | 2 import base = require('./base'); |
| 3 import {FacadeConverter} from './facade_converter'; | 3 import {FacadeConverter} from './facade_converter'; |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * To support arbitrary d.ts files in Dart we often have to merge two TypeScript | 6 * To support arbitrary d.ts files in Dart we often have to merge two TypeScript |
| 7 * types into a single Dart type because Dart lacks features such as method | 7 * types into a single Dart type because Dart lacks features such as method |
| 8 * overloads, type aliases, and union types. | 8 * overloads, type aliases, and union types. |
| 9 */ | 9 */ |
| 10 export class MergedType { | 10 export class MergedType { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 return ret; | 129 return ret; |
| 130 } | 130 } |
| 131 | 131 |
| 132 setOptional() { | 132 setOptional() { |
| 133 this.optional = true; | 133 this.optional = true; |
| 134 } | 134 } |
| 135 | 135 |
| 136 private name: Set<string> = new Set(); | 136 private name: Set<string> = new Set(); |
| 137 private type: MergedType; | 137 private type: MergedType; |
| 138 private optional: boolean = false; | 138 private optional: boolean = false; |
| 139 private textRange: ts.TextRange; | 139 private textRange: ts.Node; |
| 140 } | 140 } |
| 141 | 141 |
| 142 /** | 142 /** |
| 143 * Handle a parameter that is the result of merging parameter declarations from | 143 * Handle a parameter that is the result of merging parameter declarations from |
| 144 * multiple method overloads. | 144 * multiple method overloads. |
| 145 */ | 145 */ |
| 146 export class MergedTypeParameter { | 146 export class MergedTypeParameter { |
| 147 constructor(param: ts.TypeParameterDeclaration, fc: FacadeConverter) { | 147 constructor(param: ts.TypeParameterDeclaration, fc: FacadeConverter) { |
| 148 this.constraint = new MergedType(fc); | 148 this.constraint = new MergedType(fc); |
| 149 this.textRange = param; | 149 this.textRange = param; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 167 // We can't currently handle union types in merged type parameters as the co
mments for type | 167 // We can't currently handle union types in merged type parameters as the co
mments for type |
| 168 // parameters in function types are not there for documentation and impact s
trong mode. | 168 // parameters in function types are not there for documentation and impact s
trong mode. |
| 169 if (constraint && constraint.kind !== ts.SyntaxKind.UnionType) { | 169 if (constraint && constraint.kind !== ts.SyntaxKind.UnionType) { |
| 170 ret.constraint = constraint; | 170 ret.constraint = constraint; |
| 171 } | 171 } |
| 172 return ret; | 172 return ret; |
| 173 } | 173 } |
| 174 | 174 |
| 175 private name: string; | 175 private name: string; |
| 176 private constraint: MergedType; | 176 private constraint: MergedType; |
| 177 private textRange: ts.TextRange; | 177 private textRange: ts.Node; |
| 178 } | 178 } |
| 179 | 179 |
| 180 /** | 180 /** |
| 181 * Handle a parameter that is the result of merging parameter declarations from | 181 * Handle a parameter that is the result of merging parameter declarations from |
| 182 * multiple method overloads. | 182 * multiple method overloads. |
| 183 */ | 183 */ |
| 184 export class MergedTypeParameters { | 184 export class MergedTypeParameters { |
| 185 private mergedParameters: Map<string, MergedTypeParameter> = new Map(); | 185 private mergedParameters: Map<string, MergedTypeParameter> = new Map(); |
| 186 private textRange: ts.TextRange; | 186 private textRange: ts.TextRange; |
| 187 | 187 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 } | 207 } |
| 208 | 208 |
| 209 toTypeParameters(): ts.NodeArray<ts.TypeParameterDeclaration> { | 209 toTypeParameters(): ts.NodeArray<ts.TypeParameterDeclaration> { |
| 210 if (this.mergedParameters.size === 0) { | 210 if (this.mergedParameters.size === 0) { |
| 211 return undefined; | 211 return undefined; |
| 212 } | 212 } |
| 213 | 213 |
| 214 let ret = [] as ts.NodeArray<ts.TypeParameterDeclaration>; | 214 let ret = [] as ts.NodeArray<ts.TypeParameterDeclaration>; |
| 215 base.copyLocation(this.textRange, ret); | 215 base.copyNodeArrayLocation(this.textRange, ret); |
| 216 |
| 216 this.mergedParameters.forEach((mergedParameter) => { | 217 this.mergedParameters.forEach((mergedParameter) => { |
| 217 ret.push(mergedParameter.toTypeParameterDeclaration()); | 218 ret.push(mergedParameter.toTypeParameterDeclaration()); |
| 218 }); | 219 }); |
| 219 | 220 |
| 220 return ret; | 221 return ret; |
| 221 } | 222 } |
| 222 } | 223 } |
| 223 | 224 |
| 224 /** | 225 /** |
| 225 * Normalize a SourceFile | 226 * Normalize a SourceFile |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 } | 323 } |
| 323 | 324 |
| 324 if (existingClass || hasConstructor) { | 325 if (existingClass || hasConstructor) { |
| 325 if (!existingClass) { | 326 if (!existingClass) { |
| 326 // Create a stub existing class to upgrade the object literal to
if there is not an | 327 // Create a stub existing class to upgrade the object literal to
if there is not an |
| 327 // existing class with the same name. | 328 // existing class with the same name. |
| 328 let clazz = <ts.ClassDeclaration>ts.createNode(ts.SyntaxKind.Cla
ssDeclaration); | 329 let clazz = <ts.ClassDeclaration>ts.createNode(ts.SyntaxKind.Cla
ssDeclaration); |
| 329 base.copyLocation(declaration, clazz); | 330 base.copyLocation(declaration, clazz); |
| 330 clazz.name = declaration.name as ts.Identifier; | 331 clazz.name = declaration.name as ts.Identifier; |
| 331 clazz.members = <ts.NodeArray<ts.ClassElement>>[]; | 332 clazz.members = <ts.NodeArray<ts.ClassElement>>[]; |
| 332 base.copyLocation(declaration, clazz.members); | 333 base.copyNodeArrayLocation(declaration, clazz.members); |
| 333 replaceNode(n, clazz); | 334 replaceNode(n, clazz); |
| 334 classes.set(name, clazz); | 335 classes.set(name, clazz); |
| 335 } | 336 } |
| 336 | 337 |
| 337 let existing = classes.get(name); | 338 let existing = classes.get(name); |
| 338 if (existing.kind === ts.SyntaxKind.InterfaceDeclaration) { | 339 if (existing.kind === ts.SyntaxKind.InterfaceDeclaration) { |
| 339 let interfaceDecl = existing as base.ExtendedInterfaceDeclaratio
n; | 340 let interfaceDecl = existing as base.ExtendedInterfaceDeclaratio
n; |
| 340 // It is completely safe to assume that we know the precise clas
s like variable | 341 // It is completely safe to assume that we know the precise clas
s like variable |
| 341 // declaration for the interface in this case as they have the s
ame exact name. | 342 // declaration for the interface in this case as they have the s
ame exact name. |
| 342 interfaceDecl.classLikeVariableDeclaration = declaration; | 343 interfaceDecl.classLikeVariableDeclaration = declaration; |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 break; | 484 break; |
| 484 case ts.SyntaxKind.ModuleBlock: | 485 case ts.SyntaxKind.ModuleBlock: |
| 485 ts.forEachChild(n, (child) => gatherClasses(child, classes)); | 486 ts.forEachChild(n, (child) => gatherClasses(child, classes)); |
| 486 break; | 487 break; |
| 487 default: | 488 default: |
| 488 break; | 489 break; |
| 489 } | 490 } |
| 490 } | 491 } |
| 491 gatherClasses(f, new Map()); | 492 gatherClasses(f, new Map()); |
| 492 } | 493 } |
| OLD | NEW |