Skip to content
This repository was archived by the owner on Sep 10, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

var doctrine = require('doctrine');
var File = require('./file'),
infer = require('./core').infer,
Reason = File.Reason,
Visibility = File.Visibility;

Expand Down Expand Up @@ -144,7 +145,7 @@ Comment.prototype.getExpressionAval =
types.push(t);
}
}, this);
return typeManager.getUnionType(types);
return new infer.UnionType(types);
case doctrine.Syntax.RestType:
// TODO: Expose varargs #20.
return this.getExpressionAval(
Expand Down
15 changes: 0 additions & 15 deletions lib/typemanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,21 +204,6 @@ TypeManager.prototype.getInstanceType = function(
};


/**
* Gets an AVal representing the union of the given AVals.
* @param {!Array.<!infer.AVal>} types The types to unionize.
* @return {!infer.AVal}
*/
TypeManager.prototype.getUnionType = function(types) {
// TODO: Decide if this behaves better with a synthetic 'Union' type #18.
var aval = new infer.AVal();
for (var i = 0; i < types.length; i++) {
types[i].propagate(aval);
}
return aval;
};


/** @return {string} The name of the file currently being processed. */
TypeManager.prototype.getCurrentOrigin = function() {
return infer.cx().curOrigin;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"closure"
],
"scripts": {
"test": "node_modules/mocha/bin/mocha"
"test": "mocha"
},
"author": "Josh Giles <joshgiles@google.com>"
}
4 changes: 2 additions & 2 deletions test/cases/unimplemented.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ nonNullable;//: MyClass
// Unions #18
/** @type {(MyClass|YourClass)} */
var union;
union;//: YourClass
union;//: (MyClass|YourClass)

/** @type {(!MyClass|!YourClass|{prop:(Blah|Blam)})} */
var nested;
nested; //: YourClass
nested; //: (MyClass|YourClass)

// Optional parameters #19.
/** @param {ParamType=} opt_param */
Expand Down
13 changes: 13 additions & 0 deletions test/cases/union-types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Union Types
// plugin=closure
// plugin=doc_comment null

/** @type {(number|string)} */
var union;
union; //: (number|string)


// Observe that some completions are coming from the number type such as
// Number.prototype.toExponential and others, such as charAt are coming
// from String.prototype.
union. //+ toString, toFixed, toExponential, charAt, charCodeAt, indexOf, ...
20 changes: 20 additions & 0 deletions test/condense.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var filter = process.argv[2];
var c = require("tern/test/condense-utils");
var util = require("tern/test/util");
var path = require("path");

var closure = require('../closure');
//Locate the Tern distribution installed with this repo and initialize the
//tern-closure plugin.
var ternDir = path.resolve(require.resolve('tern/lib/tern'), '../..');
closure.initialize(ternDir);

var closureCondenseConf = Object.create(c.condenseConf);
closureCondenseConf.projectDir = path.resolve(__dirname, "..");

exports.runTests = function(filter) {
function test(options) { c.testConf(closureCondenseConf, filter, options) };

test({load: ["union-types"], plugins: {closure: true}});

}
8 changes: 8 additions & 0 deletions test/condense/union-types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Union Types

/** @type {(number|string)} */
var varWithUnionAnnotation;
union;

var varPropagate = varWithUnionAnnotation;
varPropagate;
8 changes: 8 additions & 0 deletions test/condense/union-types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"!name": "union-types.js",
"varPropagate": "varWithUnionAnnotation",
"varWithUnionAnnotation": {
"!span": "51[3:4]-73[3:26]",
"!type": "(number|string)"
}
}
2 changes: 1 addition & 1 deletion test/file_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var chai = require('chai'),
sinonChai = require('sinon-chai');
chai.use(sinonChai);

var File = require('lib/file'),
var File = require('../lib/file'),
Visibility = File.Visibility,
Reason = File.Reason;

Expand Down
3 changes: 3 additions & 0 deletions test/runcases.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ var path = require('path');
var runcases = require('tern/test/runcases');
var util = require('tern/test/util');
var closure = require('../closure');
var condense = require('./condense');

// Locate the Tern distribution installed with this repo and initialize the
// tern-closure plugin.
var ternDir = path.resolve(require.resolve('tern/lib/tern'), '../..');
closure.initialize(ternDir);

var filter = process.argv[2];
var caseDir = path.resolve(__dirname, 'cases');
condense.runTests(filter);
runcases.runTests(filter, caseDir);
// Set non-zero exit code on failure.
process.exit(util.hasFailed());
6 changes: 3 additions & 3 deletions test/typemanager_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ var chai = require('chai'),
sinonChai = require('sinon-chai');
chai.use(sinonChai);

require('lib/core').initializeForTesting();
require('../lib/core').initializeForTesting();

var infer = require('tern/lib/infer'),
TypeManager = require('lib/typemanager'),
File = require('lib/file'),
TypeManager = require('../lib/typemanager'),
File = require('../lib/file'),
Visibility = File.Visibility,
Reason = File.Reason,
Server = require('tern/lib/tern').Server;
Expand Down