Skip to content

Commit f23372c

Browse files
committed
add a test that uses a namespace-qualified interface
Summary: Extend the namespace-qualifying-types test to also test an imported interface. Fix one minor bug it revealed (the Closure-side "function Foo()" generated from a "interface Foo" must also be exported if the interface is exported.) More work on #112. Reviewers: rkirov Reviewed By: rkirov Differential Revision: https://reviews.angular.io/D126
1 parent 15e87f0 commit f23372c

9 files changed

+25
-2
lines changed

src/tsickle.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -461,18 +461,23 @@ class Annotator extends Rewriter {
461461
private emitInterface(iface: ts.InterfaceDeclaration) {
462462
if (this.options.untyped) return;
463463
this.emit(`\n/** @record */\n`);
464-
this.emit(`function ${getIdentifierText(iface.name)}() {}\n`);
464+
let name = getIdentifierText(iface.name);
465+
this.emit(`function ${name}() {}\n`);
465466
if (iface.typeParameters) {
466467
this.emit(`// TODO: type parameters.\n`);
467468
}
468469
if (iface.heritageClauses) {
469470
this.emit(`// TODO: derived interfaces.\n`);
470471
}
471472

472-
const memberNamespace = [getIdentifierText(iface.name), 'prototype'];
473+
const memberNamespace = [name, 'prototype'];
473474
for (let elem of iface.members) {
474475
this.visitProperty(memberNamespace, elem);
475476
}
477+
478+
if (iface.flags & ts.NodeFlags.Export) {
479+
this.emit(`export {${name}};\n`);
480+
}
476481
}
477482

478483
// emitTypeAnnotationsHelper produces a

test_files/export/export_helper.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ exports.export1 = 3;
77
exports.export2 = 3;
88
/** @record */
99
function Bar() { }
10+
exports.Bar = Bar;
1011
/** @type {number} */
1112
Bar.prototype.barField;
1213
exports.export3 = null;

test_files/export/export_helper.tsickle.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export let /** @type {number} */ export2 = 3;
77
function Bar() {}
88
/** @type {number} */
99
Bar.prototype.barField;
10+
export {Bar};
1011

1112

1213
export interface Bar { barField: number; }

test_files/jsdoc_types/jsdoc_types.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ goog.module('tsickle_test.jsdoc_types.jsdoc_types');/**
66
var module1 = goog.require('tsickle_test.jsdoc_types.module1');
77
// Check that imported types get the proper names in JSDoc.
88
let /** @type {module1.Class} */ x1 = new module1.Class();
9+
let /** @type {module1.Interface} */ x2 = null;

test_files/jsdoc_types/jsdoc_types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ import * as module1 from './module1';
77

88
// Check that imported types get the proper names in JSDoc.
99
let x1 = new module1.Class();
10+
let x2: module1.Interface = null;

test_files/jsdoc_types/jsdoc_types.tsickle.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ import * as module1 from './module1';
77

88
// Check that imported types get the proper names in JSDoc.
99
let /** @type {module1.Class} */ x1 = new module1.Class();
10+
let /** @type {module1.Interface} */ x2: module1.Interface = null;

test_files/jsdoc_types/module1.js

+5
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@ goog.module('tsickle_test.jsdoc_types.module1');
22
class Class {
33
}
44
exports.Class = Class;
5+
/** @record */
6+
function Interface() { }
7+
exports.Interface = Interface;
8+
/** @type {number} */
9+
Interface.prototype.x;

test_files/jsdoc_types/module1.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export class Class {}
2+
export interface Interface { x: number }
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
11
export class Class {}
2+
/** @record */
3+
function Interface() {}
4+
/** @type {number} */
5+
Interface.prototype.x;
6+
export {Interface};
7+
8+
export interface Interface { x: number }

0 commit comments

Comments
 (0)