Skip to content

Commit

Permalink
Fix a whole bunch of types and type annotations.
Browse files Browse the repository at this point in the history
  • Loading branch information
eventualbuddha committed Aug 28, 2014
1 parent 38b206b commit b3020d4
Show file tree
Hide file tree
Showing 12 changed files with 227 additions and 133 deletions.
18 changes: 11 additions & 7 deletions lib/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function Container(options) {
* as a previous call, the same object will be returned.
*
* @param {string} importedPath
* @param {?Module} fromModule
* @param {Module=} fromModule
* @return {Module}
*/
Container.prototype.getModule = function(importedPath, fromModule) {
Expand Down Expand Up @@ -102,7 +102,7 @@ Container.prototype.addModule = function(mod) {
var name = mod.name;
var baseName = name;
var counter = 0;
var nameExists = false;
var nameExists;

while (true) {
nameExists = modules.some(function(existingModule) {
Expand Down Expand Up @@ -146,7 +146,7 @@ Container.prototype.write = function(target) {
/**
* Converts the contents of this container using the current formatter.
*
* @returns {File[]}
* @return {File[]}
*/
Container.prototype.convert = function() {
if (this.formatter.beforeConvert) {
Expand All @@ -173,17 +173,15 @@ Container.prototype.findImportedModules = function() {
lastModuleCount = knownModules.length;
for (var i = 0; i < lastModuleCount; i++) {
// Force loading of imported modules.
/* jshint expr:true */
knownModules[i].imports.modules;
/* jshint expr:false */
noop(knownModules[i].imports.modules);
}
}
};

/**
* Gets the modules in this container in no particular order.
*
* @returns {Module[]}
* @return {Module[]}
*/
Container.prototype.getModules = function() {
var modules = this.modules;
Expand All @@ -192,4 +190,10 @@ Container.prototype.getModules = function() {
});
};

/**
* Does nothing. This is only here to make JSHint/other static analysis
* tools happy about using getters for side effects.
*/
function noop() {}

module.exports = Container;
4 changes: 2 additions & 2 deletions lib/declaration_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ var n = types.namedTypes;
function DeclarationInfo(declaration, identifier) {
/**
* @type {Node}
* @property declaration
* @name DeclarationInfo#declaration
*/
this.declaration = declaration;
/**
* @type {Identifier}
* @property identifier
* @name DeclarationInfo#identifier
*/
this.identifier = identifier;
}
Expand Down
70 changes: 45 additions & 25 deletions lib/exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var sourcePosition = utils.sourcePosition;
* Represents a list of the exports for the given module.
*
* @constructor
* @extends ModuleBindingList
* @param {Module} mod
*/
function ExportDeclarationList(mod) {
Expand All @@ -29,7 +30,7 @@ extend(ExportDeclarationList, ModuleBindingList);

/**
* @private
* @param {Node} node
* @param {AST.Declaration} node
* @return {boolean}
*/
ExportDeclarationList.prototype.isMatchingBinding = function(node) {
Expand All @@ -40,8 +41,8 @@ ExportDeclarationList.prototype.isMatchingBinding = function(node) {
* Gets an export declaration for the given `node`.
*
* @private
* @param {ExportDeclaration} node
* @return {Import}
* @param {AST.ExportDeclaration} node
* @return {ExportDeclaration}
*/
ExportDeclarationList.prototype.declarationForNode = function(node) {
if (node.default) {
Expand All @@ -67,7 +68,7 @@ ExportDeclarationList.prototype.declarationForNode = function(node) {
ExportDeclarationList.prototype.findSpecifierForReference = function(referencePath) {
if (n.ExportSpecifier.check(referencePath.parent.node) && referencePath.parent.parent.node.source) {
// This is a direct export from another module, e.g. `export { foo } from 'foo'`.
return this.findSpecifierByIdentifier(referencePath.node);
return /** @type {ExportSpecifier} */this.findSpecifierByIdentifier(referencePath.node);
}

var declaration = this.findDeclarationForReference(referencePath);
Expand All @@ -76,7 +77,7 @@ ExportDeclarationList.prototype.findSpecifierForReference = function(referencePa
return null;
}

var specifier = this.findSpecifierByName(declaration.node.name);
var specifier = /** @type {ExportSpecifier} */this.findSpecifierByName(declaration.node.name);
assert.ok(
specifier,
'no specifier found for `' + referencePath.node.name + '`! this should not happen!'
Expand Down Expand Up @@ -113,7 +114,7 @@ ExportDeclaration.prototype.inspect = function() {
};

/**
* @alias inspect
* @see ExportDeclaration#inspect
*/
ExportDeclaration.prototype.toString = ExportDeclaration.prototype.inspect;

Expand All @@ -125,7 +126,7 @@ ExportDeclaration.prototype.toString = ExportDeclaration.prototype.inspect;
* @constructor
* @extends ExportDeclaration
* @param {Module} mod
* @param {ExportDeclaration} node
* @param {AST.ExportDeclaration} node
*/
function DefaultExportDeclaration(mod, node) {
ExportDeclaration.call(this, mod, node);
Expand All @@ -136,9 +137,9 @@ extend(DefaultExportDeclaration, ExportDeclaration);
* Contains a list of specifier name information for this export.
*
* @type {ExportSpecifier[]}
* @property specifiers
* @name DefaultExportSpecifier#specifiers
*/
memo(DefaultExportDeclaration.prototype, 'specifiers', function() {
memo(DefaultExportDeclaration.prototype, 'specifiers', /** @this DefaultExportDeclaration */function() {
var specifier = new DefaultExportSpecifier(this, this.node.declaration);
return [specifier];
});
Expand All @@ -151,7 +152,7 @@ memo(DefaultExportDeclaration.prototype, 'specifiers', function() {
* @constructor
* @extends ExportDeclaration
* @param {Module} mod
* @param {ExportDeclaration} node
* @param {AST.ExportDeclaration} node
*/
function NamedExportDeclaration(mod, node) {
ExportDeclaration.call(this, mod, node);
Expand All @@ -162,9 +163,9 @@ extend(NamedExportDeclaration, ExportDeclaration);
* Contains a list of specifier name information for this export.
*
* @type {ExportSpecifier[]}
* @property specifiers
* @name NamedExportDeclaration#specifiers
*/
memo(NamedExportDeclaration.prototype, 'specifiers', function() {
memo(NamedExportDeclaration.prototype, 'specifiers', /** @this NamedExportDeclaration */function() {
var self = this;
return this.node.specifiers.map(function(specifier) {
return new ExportSpecifier(self, specifier);
Expand All @@ -179,16 +180,20 @@ memo(NamedExportDeclaration.prototype, 'specifiers', function() {
* @constructor
* @extends ExportDeclaration
* @param {Module} mod
* @param {ExportDeclaration} node
* @param {AST.ExportDeclaration} node
*/
function VariableExportDeclaration(mod, node) {
ExportDeclaration.call(this, mod, node);
}
extend(VariableExportDeclaration, ExportDeclaration);

/**
* Gets the list of export specifiers for this declaration.
*
* @type {ExportSpecifier[]}
* @name VariableExportDeclaration#specifiers
*/
memo(VariableExportDeclaration.prototype, 'specifiers', function() {
memo(VariableExportDeclaration.prototype, 'specifiers', /** @this VariableExportDeclaration */function() {
var self = this;
return this.node.declaration.declarations.map(function(declarator) {
return new ExportSpecifier(self, declarator);
Expand All @@ -203,16 +208,20 @@ memo(VariableExportDeclaration.prototype, 'specifiers', function() {
* @constructor
* @extends ExportDeclaration
* @param {Module} mod
* @param {ExportDeclaration} node
* @param {AST.ExportDeclaration} node
*/
function FunctionExportDeclaration(mod, node) {
ExportDeclaration.call(this, mod, node);
}
extend(FunctionExportDeclaration, ExportDeclaration);

/**
* Gets the list of export specifiers for this declaration.
*
* @type {ExportSpecifier[]}
* @name FunctionExportDeclaration#specifiers
*/
memo(FunctionExportDeclaration.prototype, 'specifiers', function() {
memo(FunctionExportDeclaration.prototype, 'specifiers', /** @this FunctionExportDeclaration */function() {
return [new ExportSpecifier(this, this.node.declaration)];
});

Expand All @@ -222,7 +231,7 @@ memo(FunctionExportDeclaration.prototype, 'specifiers', function() {
* @constructor
* @extends ModuleBindingSpecifier
* @param {ExportDeclaration} declaration
* @param {ExportSpecifier} node
* @param {AST.Node} node
*/
function ExportSpecifier(declaration, node) {
ModuleBindingSpecifier.call(this, declaration, node);
Expand All @@ -239,10 +248,10 @@ extend(ExportSpecifier, ModuleBindingSpecifier);
* The module declaration info for the `a` export specifier is the variable
* declaration plus the `a` identifier in its first declarator.
*
* @type {DeclarationInfo}
* @property moduleDeclaration
* @type {?DeclarationInfo}
* @name ExportSpecifier#moduleDeclaration
*/
memo(ExportSpecifier.prototype, 'moduleDeclaration', function() {
memo(ExportSpecifier.prototype, 'moduleDeclaration', /** @this ExportSpecifier */function() {
if (this.declaration.source) {
// This is part of a direct export, e.g. `export { ... } from '...'`, so
// there is no declaration as part of this module.
Expand Down Expand Up @@ -277,42 +286,53 @@ memo(ExportSpecifier.prototype, 'moduleDeclaration', function() {
* @constructor
* @extends ExportSpecifier
* @param {ExportDeclaration} declaration
* @param {ExportSpecifier} node
* @param {AST.Expression} node
*/
function DefaultExportSpecifier(declaration, node) {
ExportSpecifier.call(this, declaration, node);
}
extend(DefaultExportSpecifier, ExportSpecifier);

/**
* The node of a default export specifier is an expression, not a specifier.
*
* @type {AST.Expression}
*/
DefaultExportSpecifier.prototype.node = null;

/**
* Default export specifier names are always "default".
*
* @type {string}
* @property name
* @name DefaultExportSpecifier#name
* @default "default"
*/
DefaultExportSpecifier.prototype.name = 'default';

/**
* Default export specifiers do not bind to a local identifier.
*
* @type {?Identifier}
* @property identifier
* @name DefaultExportSpecifier#identifier
* @default null
*/
DefaultExportSpecifier.prototype.identifier = null;

/**
* Default export specifiers do not have a local bound name.
*
* @type {?string}
* @property from
* @name DefaultExportSpecifier#from
* @default null
*/
DefaultExportSpecifier.prototype.from = null;

/**
* Default export specifiers do not have a local declaration.
*
* @type {?DeclarationInfo}
* @property moduleDeclaration
* @name DefaultExportSpecifier#moduleDeclaration
* @default null
*/
DefaultExportSpecifier.prototype.moduleDeclaration = null;

Expand Down
4 changes: 2 additions & 2 deletions lib/formatters/formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Formatter.prototype.importedReference = function(mod, referencePath) {
*
* @param {Module} mod
* @param {NodePath} referencePath
* @returns {?Node}
* @return {?Node}
*/
Formatter.prototype.localReference = function(mod, referencePath) {
return null;
Expand All @@ -117,7 +117,7 @@ Formatter.prototype.localReference = function(mod, referencePath) {
*
* @param {Module} mod
* @param {NodePath} nodePath
* @returns {?Node[]}
* @return {?Node[]}
*/
Formatter.prototype.processFunctionDeclaration = function(mod, nodePath) {
throw new Error('#processFunctionDeclaration must be implemented in subclasses');
Expand Down
Loading

0 comments on commit b3020d4

Please sign in to comment.