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

Side by Side Diff: lib/main.ts

Issue 2416003003: Update package name, update and lock clang-format and tslint versions, and format all source files … (Closed)
Patch Set: Use ES6 Map and Set instead of Object literals to avoid ordering instability across different Node … Created 4 years, 2 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/facade_converter.ts ('k') | lib/merge.ts » ('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 dartStyle from 'dart-style'; 1 import * as dartStyle from 'dart-style';
2 import * as fs from 'fs'; 2 import * as fs from 'fs';
3 import * as path from 'path'; 3 import * as path from 'path';
4 import * as ts from 'typescript'; 4 import * as ts from 'typescript';
5
6 import * as base from './base'; 5 import * as base from './base';
7 import {ImportSummary, TranspilerBase} from './base'; 6 import {ImportSummary, TranspilerBase} from './base';
8 import DeclarationTranspiler from './declaration'; 7 import DeclarationTranspiler from './declaration';
9 import {FacadeConverter} from './facade_converter'; 8 import {FacadeConverter} from './facade_converter';
10 import * as merge from './merge'; 9 import * as merge from './merge';
11 import mkdirP from './mkdirp'; 10 import mkdirP from './mkdirp';
12 import ModuleTranspiler from './module'; 11 import ModuleTranspiler from './module';
13 import TypeTranspiler from './type'; 12 import TypeTranspiler from './type';
14 13
15 export interface TranspilerOptions { 14 export interface TranspilerOptions {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 66
68 const NUM_OUTPUT_CONTEXTS = 3; 67 const NUM_OUTPUT_CONTEXTS = 3;
69 68
70 export class Transpiler { 69 export class Transpiler {
71 private outputs: Output[]; 70 private outputs: Output[];
72 private outputStack: Output[]; 71 private outputStack: Output[];
73 private currentFile: ts.SourceFile; 72 private currentFile: ts.SourceFile;
74 /** 73 /**
75 * Map of import library path to a Set of identifier names being imported. 74 * Map of import library path to a Set of identifier names being imported.
76 */ 75 */
77 imports: ts.Map<ImportSummary>; 76 imports: Map<String, ImportSummary>;
78 // Comments attach to all following AST nodes before the next 'physical' token . Track the earliest 77 // Comments attach to all following AST nodes before the next 'physical' token . Track the earliest
79 // offset to avoid printing comments multiple times. 78 // offset to avoid printing comments multiple times.
80 private lastCommentIdx: number = -1; 79 private lastCommentIdx: number = -1;
81 private errors: string[] = []; 80 private errors: string[] = [];
82 81
83 private transpilers: TranspilerBase[]; 82 private transpilers: TranspilerBase[];
84 private declarationTranspiler: DeclarationTranspiler; 83 private declarationTranspiler: DeclarationTranspiler;
85 private fc: FacadeConverter; 84 private fc: FacadeConverter;
86 /* Number of nested levels of type arguments the current expression is within. */ 85 /* Number of nested levels of type arguments the current expression is within. */
87 private typeArgumentDepth = 0; 86 private typeArgumentDepth = 0;
88 87
89 constructor(private options: TranspilerOptions = {}) { 88 constructor(private options: TranspilerOptions) {
89 this.options = this.options || {};
90 this.fc = new FacadeConverter(this, options.typingsRoot); 90 this.fc = new FacadeConverter(this, options.typingsRoot);
91 this.declarationTranspiler = new DeclarationTranspiler( 91 this.declarationTranspiler = new DeclarationTranspiler(
92 this, this.fc, options.enforceUnderscoreConventions, options.promoteFunc tionLikeMembers); 92 this, this.fc, options.enforceUnderscoreConventions, options.promoteFunc tionLikeMembers);
93 this.transpilers = [ 93 this.transpilers = [
94 new ModuleTranspiler(this, this.fc, options.moduleName), 94 new ModuleTranspiler(this, this.fc, options.moduleName),
95 this.declarationTranspiler, 95 this.declarationTranspiler,
96 new TypeTranspiler(this, this.fc), 96 new TypeTranspiler(this, this.fc),
97 ]; 97 ];
98 } 98 }
99 99
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 if (this.outputStack.length === 0) { 230 if (this.outputStack.length === 0) {
231 this.reportError(null, 'Attempting to pop output stack when already empty' ); 231 this.reportError(null, 'Attempting to pop output stack when already empty' );
232 } 232 }
233 this.outputStack.pop(); 233 this.outputStack.pop();
234 } 234 }
235 235
236 private translate(sourceFile: ts.SourceFile): string { 236 private translate(sourceFile: ts.SourceFile): string {
237 this.currentFile = sourceFile; 237 this.currentFile = sourceFile;
238 this.outputs = []; 238 this.outputs = [];
239 this.outputStack = []; 239 this.outputStack = [];
240 this.imports = {}; 240 this.imports = new Map();
241 for (let i = 0; i < NUM_OUTPUT_CONTEXTS; ++i) { 241 for (let i = 0; i < NUM_OUTPUT_CONTEXTS; ++i) {
242 this.outputs.push(new Output()); 242 this.outputs.push(new Output());
243 } 243 }
244 244
245 this.lastCommentIdx = -1; 245 this.lastCommentIdx = -1;
246 merge.normalizeSourceFile(sourceFile, this.fc); 246 merge.normalizeSourceFile(sourceFile, this.fc);
247 this.pushContext(OutputContext.Default); 247 this.pushContext(OutputContext.Default);
248 this.visit(sourceFile); 248 this.visit(sourceFile);
249 this.popContext(); 249 this.popContext();
250 if (this.outputStack.length > 0) { 250 if (this.outputStack.length > 0) {
251 this.reportError( 251 this.reportError(
252 sourceFile, 'Internal error managing output contexts. ' + 252 sourceFile, 'Internal error managing output contexts. ' +
253 'Inconsistent push and pop context calls.'); 253 'Inconsistent push and pop context calls.');
254 } 254 }
255 this.pushContext(OutputContext.Import); 255 this.pushContext(OutputContext.Import);
256 256
257 for (let name of Object.getOwnPropertyNames(this.imports)) { 257 this.imports.forEach((summary, name) => {
258 let summary = this.imports[name];
259 this.emit(`import ${JSON.stringify(name)}`); 258 this.emit(`import ${JSON.stringify(name)}`);
260 259
261 if (!summary.showAll) { 260 if (!summary.showAll) {
262 let shownNames = Object.getOwnPropertyNames(summary.shown); 261 let shownNames = Array.from(summary.shown);
263 if (shownNames.length > 0) { 262 if (shownNames.length > 0) {
264 this.emit(`show ${shownNames.join(', ')}`); 263 this.emit(`show ${shownNames.join(', ')}`);
265 } 264 }
266 } 265 }
267 if (summary.asPrefix) { 266 if (summary.asPrefix) {
268 this.emit(`as ${summary.asPrefix}`); 267 this.emit(`as ${summary.asPrefix}`);
269 } 268 }
270 this.emit(';\n'); 269 this.emit(';\n');
271 } 270 });
272 this.popContext(); 271 this.popContext();
273 272
274 let result = ''; 273 let result = '';
275 for (let output of this.outputs) { 274 for (let output of this.outputs) {
276 result += output.getResult(); 275 result += output.getResult();
277 } 276 }
278 return this.formatCode(result, sourceFile); 277 return this.formatCode(result, sourceFile);
279 } 278 }
280 279
281 private formatCode(code: string, context: ts.Node) { 280 private formatCode(code: string, context: ts.Node) {
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 try { 594 try {
596 let transpiler = new Transpiler(args); 595 let transpiler = new Transpiler(args);
597 if (args.destination) console.error('Transpiling', args._, 'to', args.destin ation); 596 if (args.destination) console.error('Transpiling', args._, 'to', args.destin ation);
598 transpiler.transpile(args._, args.destination); 597 transpiler.transpile(args._, args.destination);
599 } catch (e) { 598 } catch (e) {
600 if (e.name !== 'DartFacadeError') throw e; 599 if (e.name !== 'DartFacadeError') throw e;
601 console.error(e.message); 600 console.error(e.message);
602 process.exit(1); 601 process.exit(1);
603 } 602 }
604 } 603 }
OLDNEW
« no previous file with comments | « lib/facade_converter.ts ('k') | lib/merge.ts » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698