Skip to content

Commit 1d3b15d

Browse files
committed
Update package name, update and lock clang-format and tslint versions, and format all source files to match.
BUG= R=kevmoo@google.com Review URL: https://codereview.chromium.org//2416003003 .
1 parent 8d2218d commit 1d3b15d

19 files changed

+207
-173
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ Dart interop facade file is written to stdout.
2525
## Gulp tasks
2626

2727
- `gulp watch` executes the unit tests in watch mode (use `gulp test.unit` for a single run),
28-
- `gulp test.e2e` executes the e2e tests,
2928
- `gulp test.check-format` checks the source code formatting using `clang-format`,
3029
- `gulp test` runs unit tests, e2e tests and checks the source code formatting.
3130

gulpfile.js

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -85,42 +85,7 @@ gulp.task('test.unit', ['test.compile'], function(done) {
8585
}));
8686
});
8787

88-
// This test transpiles some unittests to dart and runs them in the Dart VM.
89-
gulp.task('test.e2e', ['test.compile'], function(done) {
90-
var testfile = 'helloworld';
91-
92-
// Removes backslashes from __dirname in Windows
93-
var dir = (__dirname.replace(/\\/g, '/') + '/build/e2e');
94-
if (fs.existsSync(dir)) fsx.removeSync(dir);
95-
fs.mkdirSync(dir);
96-
fsx.copySync(__dirname + '/test/e2e', dir);
97-
fsx.copySync(__dirname + '/typings', dir + '/typings');
98-
99-
// run node with a shell so we can wildcard all the .ts files
100-
var cmd = 'node ../lib/main.js --translateBuiltins --basePath=. --destination=. ' +
101-
'--typingsRoot=typings/';
102-
// Paths must be relative to our source root, so run with cwd == dir.
103-
spawn('sh', ['-c', cmd], {stdio: 'inherit', cwd: dir}).on('close', function(code, signal) {
104-
if (code > 0) {
105-
onError(new Error('Failed to transpile ' + testfile + '.ts'));
106-
} else {
107-
try {
108-
var opts = {stdio: 'inherit', cwd: dir};
109-
// Install the unittest packages on every run, using the content of pubspec.yaml
110-
// TODO: maybe this could be memoized or served locally?
111-
spawn(which.sync('pub'), ['install'], opts).on('close', function() {
112-
// Run the tests using built-in test runner.
113-
spawn(which.sync('dart'), [testfile + '.dart'], opts).on('close', done);
114-
});
115-
} catch (e) {
116-
console.log('Dart SDK is not found on the PATH:', e.message);
117-
throw e;
118-
}
119-
}
120-
});
121-
});
122-
123-
gulp.task('test', ['test.check-format', 'test.check-lint', 'test.unit', 'test.e2e']);
88+
gulp.task('test', ['test.check-format', 'test.check-lint', 'test.unit']);
12489

12590
gulp.task('watch', ['test.unit'], function() {
12691
failOnError = false;

lib/base.ts

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@ export function isTypeNode(node: ts.Node): boolean {
250250

251251
export function isCallable(decl: ClassLike): boolean {
252252
let members = decl.members as Array<ts.ClassElement>;
253-
return members.some((member) => { return member.kind === ts.SyntaxKind.CallSignature; });
253+
return members.some((member) => {
254+
return member.kind === ts.SyntaxKind.CallSignature;
255+
});
254256
}
255257

256258
export function copyLocation(src: ts.TextRange, dest: ts.TextRange) {
@@ -328,21 +330,47 @@ export class TranspilerBase {
328330
private idCounter: number = 0;
329331
constructor(protected transpiler: Transpiler) {}
330332

331-
visit(n: ts.Node) { this.transpiler.visit(n); }
332-
pushContext(context: OutputContext) { this.transpiler.pushContext(context); }
333-
popContext() { this.transpiler.popContext(); }
334-
emit(s: string) { this.transpiler.emit(s); }
335-
emitNoSpace(s: string) { this.transpiler.emitNoSpace(s); }
336-
emitType(s: string, comment: string) { this.transpiler.emitType(s, comment); }
337-
maybeLineBreak() { return this.transpiler.maybeLineBreak(); }
338-
enterCodeComment() { return this.transpiler.enterCodeComment(); }
339-
exitCodeComment() { return this.transpiler.exitCodeComment(); }
333+
visit(n: ts.Node) {
334+
this.transpiler.visit(n);
335+
}
336+
pushContext(context: OutputContext) {
337+
this.transpiler.pushContext(context);
338+
}
339+
popContext() {
340+
this.transpiler.popContext();
341+
}
342+
emit(s: string) {
343+
this.transpiler.emit(s);
344+
}
345+
emitNoSpace(s: string) {
346+
this.transpiler.emitNoSpace(s);
347+
}
348+
emitType(s: string, comment: string) {
349+
this.transpiler.emitType(s, comment);
350+
}
351+
maybeLineBreak() {
352+
return this.transpiler.maybeLineBreak();
353+
}
354+
enterCodeComment() {
355+
return this.transpiler.enterCodeComment();
356+
}
357+
exitCodeComment() {
358+
return this.transpiler.exitCodeComment();
359+
}
340360

341-
enterTypeArguments() { this.transpiler.enterTypeArgument(); }
342-
exitTypeArguments() { this.transpiler.exitTypeArgument(); }
343-
get insideTypeArgument() { return this.transpiler.insideTypeArgument; }
361+
enterTypeArguments() {
362+
this.transpiler.enterTypeArgument();
363+
}
364+
exitTypeArguments() {
365+
this.transpiler.exitTypeArgument();
366+
}
367+
get insideTypeArgument() {
368+
return this.transpiler.insideTypeArgument;
369+
}
344370

345-
get insideCodeComment() { return this.transpiler.insideCodeComment; }
371+
get insideCodeComment() {
372+
return this.transpiler.insideCodeComment;
373+
}
346374

347375
getImportSummary(libraryUri: string): ImportSummary {
348376
if (!Object.hasOwnProperty.call(this.transpiler.imports, libraryUri)) {
@@ -390,11 +418,17 @@ export class TranspilerBase {
390418
}
391419

392420

393-
reportError(n: ts.Node, message: string) { this.transpiler.reportError(n, message); }
421+
reportError(n: ts.Node, message: string) {
422+
this.transpiler.reportError(n, message);
423+
}
394424

395-
visitNode(n: ts.Node): boolean { throw new Error('not implemented'); }
425+
visitNode(n: ts.Node): boolean {
426+
throw new Error('not implemented');
427+
}
396428

397-
visitEach(nodes: ts.Node[]) { nodes.forEach((n) => this.visit(n)); }
429+
visitEach(nodes: ts.Node[]) {
430+
nodes.forEach((n) => this.visit(n));
431+
}
398432

399433
visitEachIfPresent(nodes?: ts.Node[]) {
400434
if (nodes) this.visitEach(nodes);
@@ -451,7 +485,9 @@ export class TranspilerBase {
451485
return null;
452486
}
453487

454-
hasAncestor(n: ts.Node, kind: ts.SyntaxKind): boolean { return !!getAncestor(n, kind); }
488+
hasAncestor(n: ts.Node, kind: ts.SyntaxKind): boolean {
489+
return !!getAncestor(n, kind);
490+
}
455491

456492
hasAnnotation(decorators: ts.NodeArray<ts.Decorator>, name: string): boolean {
457493
if (!decorators) return false;
@@ -473,7 +509,9 @@ export class TranspilerBase {
473509
return this.transpiler.getRelativeFileName(fileName);
474510
}
475511

476-
getDartFileName(fileName?: string): string { return this.transpiler.getDartFileName(fileName); }
512+
getDartFileName(fileName?: string): string {
513+
return this.transpiler.getDartFileName(fileName);
514+
}
477515

478516
maybeVisitTypeArguments(n: {typeArguments?: ts.NodeArray<ts.TypeNode>}) {
479517
if (n.typeArguments) {

lib/declaration.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ export default class DeclarationTranspiler extends base.TranspilerBase {
2222

2323
static NUM_FAKE_REST_PARAMETERS = 5;
2424

25-
setTypeChecker(tc: ts.TypeChecker) { this.tc = tc; }
26-
setFacadeConverter(fc: FacadeConverter) { this.fc = fc; }
25+
setTypeChecker(tc: ts.TypeChecker) {
26+
this.tc = tc;
27+
}
28+
setFacadeConverter(fc: FacadeConverter) {
29+
this.fc = fc;
30+
}
2731

2832
getJsPath(node: ts.Node, suppressUnneededPaths = true): string {
2933
let path: Array<String> = [];

lib/facade_converter.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ class DartNameRecord {
8282
}
8383

8484
export class DartLibrary {
85-
constructor(private fileName: string) { this.usedNames = {}; }
85+
constructor(private fileName: string) {
86+
this.usedNames = {};
87+
}
8688

8789
/**
8890
* @returns {boolean} whether the name was added.
@@ -265,7 +267,9 @@ export class FacadeConverter extends base.TranspilerBase {
265267
}
266268
}
267269

268-
setTypeChecker(tc: ts.TypeChecker) { this.tc = tc; }
270+
setTypeChecker(tc: ts.TypeChecker) {
271+
this.tc = tc;
272+
}
269273

270274
pushTypeParameterNames(n: ts.FunctionLikeDeclaration) {
271275
if (!n.typeParameters) return;
@@ -322,7 +326,9 @@ export class FacadeConverter extends base.TranspilerBase {
322326
generateTypeList(types: ts.TypeNode[], options: TypeDisplayOptions, seperator = ','): string {
323327
let that = this;
324328
return types
325-
.map((type) => { return that.generateDartTypeName(type, addInsideTypeArgument(options)); })
329+
.map((type) => {
330+
return that.generateDartTypeName(type, addInsideTypeArgument(options));
331+
})
326332
.join(seperator);
327333
}
328334

@@ -714,7 +720,9 @@ export class FacadeConverter extends base.TranspilerBase {
714720
// MergedType will also follow typed aliases, etc which allows us to avoid
715721
// including that logic here as well.
716722
let mergedType = new MergedType(this);
717-
types.forEach((type) => { mergedType.merge(type); });
723+
types.forEach((type) => {
724+
mergedType.merge(type);
725+
});
718726
return mergedType.toSimpleTypeNode();
719727
}
720728

lib/main.ts

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ export class Transpiler {
120120
this.errors = [];
121121

122122
let sourceFileMap: {[s: string]: ts.SourceFile} = {};
123-
sourceFiles.forEach((f: ts.SourceFile) => { sourceFileMap[f.fileName] = f; });
123+
sourceFiles.forEach((f: ts.SourceFile) => {
124+
sourceFileMap[f.fileName] = f;
125+
});
124126

125127
// Check for global module export declarations and propogate them to all modules they export.
126128
sourceFiles.forEach((f: ts.SourceFile) => {
@@ -199,7 +201,9 @@ export class Transpiler {
199201
let contents = fs.readFileSync(sourcePath, 'UTF-8');
200202
return ts.createSourceFile(sourceName, contents, COMPILER_OPTIONS.target, true);
201203
},
202-
writeFile(name, text, writeByteOrderMark) { fs.writeFile(name, text); },
204+
writeFile(name, text, writeByteOrderMark) {
205+
fs.writeFile(name, text);
206+
},
203207
fileExists: (filename) => fs.existsSync(filename),
204208
readFile: (filename) => fs.readFileSync(filename, 'utf-8'),
205209
getDefaultLibFileName: () => defaultLibFileName,
@@ -218,7 +222,9 @@ export class Transpiler {
218222
return this.normalizeSlashes(path.join(destinationRoot, relative));
219223
}
220224

221-
public pushContext(context: OutputContext) { this.outputStack.push(this.outputs[context]); }
225+
public pushContext(context: OutputContext) {
226+
this.outputStack.push(this.outputs[context]);
227+
}
222228

223229
public popContext() {
224230
if (this.outputStack.length === 0) {
@@ -346,20 +352,42 @@ export class Transpiler {
346352
return !('/' + this.currentFile.fileName).match(/\/index\.(js|es6|d\.ts|ts)$/);
347353
}
348354

349-
private get currentOutput(): Output { return this.outputStack[this.outputStack.length - 1]; }
355+
private get currentOutput(): Output {
356+
return this.outputStack[this.outputStack.length - 1];
357+
}
350358

351-
emit(s: string) { this.currentOutput.emit(s); }
352-
emitNoSpace(s: string) { this.currentOutput.emitNoSpace(s); }
353-
maybeLineBreak() { return this.currentOutput.maybeLineBreak(); }
354-
enterCodeComment() { return this.currentOutput.enterCodeComment(); }
355-
exitCodeComment() { return this.currentOutput.exitCodeComment(); }
359+
emit(s: string) {
360+
this.currentOutput.emit(s);
361+
}
362+
emitNoSpace(s: string) {
363+
this.currentOutput.emitNoSpace(s);
364+
}
365+
maybeLineBreak() {
366+
return this.currentOutput.maybeLineBreak();
367+
}
368+
enterCodeComment() {
369+
return this.currentOutput.enterCodeComment();
370+
}
371+
exitCodeComment() {
372+
return this.currentOutput.exitCodeComment();
373+
}
356374

357-
enterTypeArgument() { this.typeArgumentDepth++; }
358-
exitTypeArgument() { this.typeArgumentDepth--; }
359-
get insideTypeArgument(): boolean { return this.typeArgumentDepth > 0; }
375+
enterTypeArgument() {
376+
this.typeArgumentDepth++;
377+
}
378+
exitTypeArgument() {
379+
this.typeArgumentDepth--;
380+
}
381+
get insideTypeArgument(): boolean {
382+
return this.typeArgumentDepth > 0;
383+
}
360384

361-
emitType(s: string, comment: string) { return this.currentOutput.emitType(s, comment); }
362-
get insideCodeComment() { return this.currentOutput.insideCodeComment; }
385+
emitType(s: string, comment: string) {
386+
return this.currentOutput.emitType(s, comment);
387+
}
388+
get insideCodeComment() {
389+
return this.currentOutput.insideCodeComment;
390+
}
363391

364392
reportError(n: ts.Node, message: string) {
365393
let file = n.getSourceFile() || this.currentFile;
@@ -405,7 +433,9 @@ export class Transpiler {
405433
'Unsupported node type ' + (<any>ts).SyntaxKind[node.kind] + ': ' + node.getFullText());
406434
}
407435

408-
private normalizeSlashes(path: string) { return path.replace(/\\/g, '/'); }
436+
private normalizeSlashes(path: string) {
437+
return path.replace(/\\/g, '/');
438+
}
409439

410440
private translateComment(comment: string): string {
411441
let rawComment = comment;

lib/merge.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ export class MergedParameter {
132132
return ret;
133133
}
134134

135-
setOptional() { this.optional = true; }
135+
setOptional() {
136+
this.optional = true;
137+
}
136138

137139
private name: {[s: string]: boolean} = {};
138140
private type: MergedType;
@@ -308,8 +310,9 @@ export function normalizeSourceFile(f: ts.SourceFile, fc: FacadeConverter) {
308310
if (decl == null) return;
309311
if (decl.kind !== ts.SyntaxKind.InterfaceDeclaration) return;
310312
let interfaceDecl = decl as base.ExtendedInterfaceDeclaration;
311-
if (!interfaceDecl.members.some(
312-
(member) => { return member.kind === ts.SyntaxKind.ConstructSignature; }))
313+
if (!interfaceDecl.members.some((member) => {
314+
return member.kind === ts.SyntaxKind.ConstructSignature;
315+
}))
313316
return;
314317

315318
if (interfaceDecl.classLikeVariableDeclaration == null) {

lib/type.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import {FacadeConverter, fixupIdentifierName} from './facade_converter';
55
import {Transpiler} from './main';
66

77
export default class TypeTranspiler extends base.TranspilerBase {
8-
constructor(tr: Transpiler, private fc: FacadeConverter) { super(tr); }
8+
constructor(tr: Transpiler, private fc: FacadeConverter) {
9+
super(tr);
10+
}
911

1012
visitNode(node: ts.Node): boolean {
1113
if (base.isTypeNode(node)) {

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "js_facade_gen",
2+
"name": "dart_js_facade_gen",
33
"version": "0.0.1",
44
"description": "Generate Dart package:js JS Interop faces for arbitrary TypeScript libraries.",
55
"main": "build/lib/main.js",
@@ -16,13 +16,13 @@
1616
},
1717
"devDependencies": {
1818
"chai": "^2.1.1",
19-
"clang-format": "^1.0.37",
19+
"clang-format": "1.0.45",
2020
"fs-extra": "^0.18.0",
2121
"gulp": "^3.8.11",
22-
"gulp-clang-format": "^1.0.21",
22+
"gulp-clang-format": "1.0.23",
2323
"gulp-mocha": "^2.0.0",
2424
"gulp-sourcemaps": "^1.5.0",
25-
"gulp-tslint": "^4.3.4",
25+
"gulp-tslint": "4.3.5",
2626
"gulp-typescript": "^2.7.6",
2727
"gulp-util": "^3.0.4",
2828
"merge2": "^0.3.1",
@@ -46,7 +46,7 @@
4646
"dart"
4747
],
4848
"contributors": [
49-
"Jacob Richman <jacobr@google.com> (https://www.dartlang.org/)"
49+
"Dart Team <mailto:misc@dartlang.org> (https://www.dartlang.org/)"
5050
],
5151
"license": "Apache-2.0",
5252
"bugs": {

test/call_test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,7 @@ class X {
6060
external y();
6161
}`);
6262
});
63-
it('suppress new calls without arguments', () => { expectTranslate('new Foo;').to.equal(''); });
63+
it('suppress new calls without arguments', () => {
64+
expectTranslate('new Foo;').to.equal('');
65+
});
6466
});

0 commit comments

Comments
 (0)