From d24ec032c2c65681b4e37bcb8f184f0c85e70a60 Mon Sep 17 00:00:00 2001 From: Sean Usick Date: Tue, 7 Oct 2014 15:29:56 -0500 Subject: [PATCH 1/8] :circus_tent: Added .gitattributes --- .gitattributes | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..412eeda --- /dev/null +++ b/.gitattributes @@ -0,0 +1,22 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp +*.sln merge=union +*.csproj merge=union +*.vbproj merge=union +*.fsproj merge=union +*.dbproj merge=union + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain From 2cd2de2ffc3209b1ef659d4b5b74174d676f40a1 Mon Sep 17 00:00:00 2001 From: Sean Usick Date: Tue, 7 Oct 2014 15:30:02 -0500 Subject: [PATCH 2/8] Revert ":circus_tent: Added .gitattributes" This reverts commit d24ec032c2c65681b4e37bcb8f184f0c85e70a60. --- .gitattributes | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 412eeda..0000000 --- a/.gitattributes +++ /dev/null @@ -1,22 +0,0 @@ -# Auto detect text files and perform LF normalization -* text=auto - -# Custom for Visual Studio -*.cs diff=csharp -*.sln merge=union -*.csproj merge=union -*.vbproj merge=union -*.fsproj merge=union -*.dbproj merge=union - -# Standard to msysgit -*.doc diff=astextplain -*.DOC diff=astextplain -*.docx diff=astextplain -*.DOCX diff=astextplain -*.dot diff=astextplain -*.DOT diff=astextplain -*.pdf diff=astextplain -*.PDF diff=astextplain -*.rtf diff=astextplain -*.RTF diff=astextplain From c22a337023a418bd2c4422672b001828c8ad9538 Mon Sep 17 00:00:00 2001 From: Sean Usick Date: Tue, 7 Oct 2014 15:40:52 -0500 Subject: [PATCH 3/8] Add support for union types Imports and exports union type information from condense json files. --- test/cases/union-types.js | 7 +++++++ test/condense.js | 20 ++++++++++++++++++++ test/condense/union-types.js | 8 ++++++++ test/condense/union-types.json | 11 +++++++++++ test/runcases.js | 3 +++ 5 files changed, 49 insertions(+) create mode 100644 test/cases/union-types.js create mode 100644 test/condense.js create mode 100644 test/condense/union-types.js create mode 100644 test/condense/union-types.json diff --git a/test/cases/union-types.js b/test/cases/union-types.js new file mode 100644 index 0000000..1ee37fd --- /dev/null +++ b/test/cases/union-types.js @@ -0,0 +1,7 @@ +// Type unions +// plugin=closure +// plugin=doc_comment null + +/** @type {(number|string)} */ +var union; +union; //: (number|string) \ No newline at end of file diff --git a/test/condense.js b/test/condense.js new file mode 100644 index 0000000..74a39e9 --- /dev/null +++ b/test/condense.js @@ -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}}); + +} \ No newline at end of file diff --git a/test/condense/union-types.js b/test/condense/union-types.js new file mode 100644 index 0000000..7fcb7f9 --- /dev/null +++ b/test/condense/union-types.js @@ -0,0 +1,8 @@ +// Union Types + +/** @type {(number|string)} */ +var varWithUnionAnnotation; +union; + +var varPropagate = varWithUnionAnnotation; +varPropagate; \ No newline at end of file diff --git a/test/condense/union-types.json b/test/condense/union-types.json new file mode 100644 index 0000000..e303522 --- /dev/null +++ b/test/condense/union-types.json @@ -0,0 +1,11 @@ +{ + "!name": "union-types.js", + "varPropagate": { + "!span": "87[6:4]-99[6:16]", + "!type": "(number|string)" + }, + "varWithUnionAnnotation": { + "!span": "51[3:4]-73[3:26]", + "!type": "(number|string)" + } +} \ No newline at end of file diff --git a/test/runcases.js b/test/runcases.js index 2a315e5..232b363 100755 --- a/test/runcases.js +++ b/test/runcases.js @@ -16,6 +16,8 @@ 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'), '../..'); @@ -23,6 +25,7 @@ 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()); From 43fdac22c488d4326fa4b909e2e833b0066263a6 Mon Sep 17 00:00:00 2001 From: Sean Usick Date: Tue, 7 Oct 2014 15:42:35 -0500 Subject: [PATCH 4/8] make naming orthagonal --- test/cases/union-types.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cases/union-types.js b/test/cases/union-types.js index 1ee37fd..015efe6 100644 --- a/test/cases/union-types.js +++ b/test/cases/union-types.js @@ -1,4 +1,4 @@ -// Type unions +// Union Types // plugin=closure // plugin=doc_comment null From 5e977aa81f00a6c82ee08f25ec388890bbea6b00 Mon Sep 17 00:00:00 2001 From: Sean Usick Date: Thu, 9 Oct 2014 10:24:59 -0500 Subject: [PATCH 5/8] Got union type completion working and all tests passing --- lib/comment.js | 3 ++- lib/typemanager.js | 15 --------------- test/cases/unimplemented.js | 4 ++-- test/cases/union-types.js | 8 +++++++- test/condense/union-types.json | 5 +---- 5 files changed, 12 insertions(+), 23 deletions(-) diff --git a/lib/comment.js b/lib/comment.js index 97818f8..13b86a4 100644 --- a/lib/comment.js +++ b/lib/comment.js @@ -16,6 +16,7 @@ var doctrine = require('doctrine'); var File = require('./file'), + infer = require('./core').infer, Reason = File.Reason, Visibility = File.Visibility; @@ -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( diff --git a/lib/typemanager.js b/lib/typemanager.js index 219c864..8e5bc04 100644 --- a/lib/typemanager.js +++ b/lib/typemanager.js @@ -204,21 +204,6 @@ TypeManager.prototype.getInstanceType = function( }; -/** - * Gets an AVal representing the union of the given AVals. - * @param {!Array.} 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; diff --git a/test/cases/unimplemented.js b/test/cases/unimplemented.js index 28830ca..7bd5110 100644 --- a/test/cases/unimplemented.js +++ b/test/cases/unimplemented.js @@ -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 */ diff --git a/test/cases/union-types.js b/test/cases/union-types.js index 015efe6..b46d192 100644 --- a/test/cases/union-types.js +++ b/test/cases/union-types.js @@ -4,4 +4,10 @@ /** @type {(number|string)} */ var union; -union; //: (number|string) \ No newline at end of file +union; //: (number|string) + + +// observe that some completions are coming from the type number such as +// Number.prototype.toExponential and others, such as charAt are coming +// from String.prototype +union. //+ toString, toFixed, toExponential, charAt, charCodeAt, indexOf, ... \ No newline at end of file diff --git a/test/condense/union-types.json b/test/condense/union-types.json index e303522..304ec4c 100644 --- a/test/condense/union-types.json +++ b/test/condense/union-types.json @@ -1,9 +1,6 @@ { "!name": "union-types.js", - "varPropagate": { - "!span": "87[6:4]-99[6:16]", - "!type": "(number|string)" - }, + "varPropagate": "varWithUnionAnnotation", "varWithUnionAnnotation": { "!span": "51[3:4]-73[3:26]", "!type": "(number|string)" From 29eae929cd2da50846d27adf162e0e0b7e91c70f Mon Sep 17 00:00:00 2001 From: Sean Usick Date: Thu, 9 Oct 2014 15:42:55 -0500 Subject: [PATCH 6/8] grammer and spelling --- test/cases/union-types.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/cases/union-types.js b/test/cases/union-types.js index b46d192..8e6fef3 100644 --- a/test/cases/union-types.js +++ b/test/cases/union-types.js @@ -7,7 +7,7 @@ var union; union; //: (number|string) -// observe that some completions are coming from the type number such as +// 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 +// from String.prototype. union. //+ toString, toFixed, toExponential, charAt, charCodeAt, indexOf, ... \ No newline at end of file From 1a9e4428798686003d94fb8d22ab6da6d65cc9e6 Mon Sep 17 00:00:00 2001 From: Sean Usick Date: Wed, 29 Oct 2014 16:17:46 -0500 Subject: [PATCH 7/8] Fix test command mocha no longer needs node_modules path, also this makes npm test work on a windows msys enviroment --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 364e897..aa1b306 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "closure" ], "scripts": { - "test": "node_modules/mocha/bin/mocha" + "test": "mocha" }, "author": "Josh Giles " } From 3a37dc258f9ffaa602f83c256a61d98a546b2de5 Mon Sep 17 00:00:00 2001 From: Sean Usick Date: Wed, 29 Oct 2014 16:30:27 -0500 Subject: [PATCH 8/8] get mocha tests passing --- test/file_test.js | 2 +- test/typemanager_test.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/file_test.js b/test/file_test.js index a532583..6ee7659 100644 --- a/test/file_test.js +++ b/test/file_test.js @@ -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; diff --git a/test/typemanager_test.js b/test/typemanager_test.js index 5b3fc9d..9bc319d 100644 --- a/test/typemanager_test.js +++ b/test/typemanager_test.js @@ -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;