Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Update Tern & Acorn (#11569)
Browse files Browse the repository at this point in the history
* Update Tern -> post-0.13
Replace Acorn submodule with local copy
Update Acorn -> post-2.2

* Change function call for renamed function

* Load ecma6.json into Tern

* Workaround non-emittable options in acorn_loose

* Fix unit test
Since we only get 500 hints back and there have been many new additions,
Date's "getSecond" was no longer part of those 500. Thus, I decided to
check for the existence of hints from Function, String and Array instead
of Function, Array and Date.

* Make use of the correct, renamed Tern definition

* remove old acorn & tern

* add acorn & tern as npm dependencies

add lodash as dependency

* grunt install installs dependencies for extensions from npm

* fix acorn & tern paths

* load libraries from node_modules, not working yet

fix acorn to load it with requirejs

* forgot to add glob dev dependency

travis builds on node 0.10 which doesn't have promise

* add eslint-env node

* fix missing use strict
  • Loading branch information
Marcel Gerber committed Aug 26, 2016
1 parent 63962ce commit 1ed6c04
Show file tree
Hide file tree
Showing 18 changed files with 238 additions and 39 deletions.
6 changes: 0 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
[submodule "src/thirdparty/mustache"]
path = src/thirdparty/mustache
url = https://github.com/janl/mustache.js.git
[submodule "src/extensions/default/JavaScriptCodeHints/thirdparty/tern"]
path = src/extensions/default/JavaScriptCodeHints/thirdparty/tern
url = https://github.com/ternjs/tern.git
[submodule "src/extensions/default/JavaScriptCodeHints/thirdparty/acorn"]
path = src/extensions/default/JavaScriptCodeHints/thirdparty/acorn
url = https://github.com/marijnh/acorn.git
[submodule "src/thirdparty/requirejs"]
path = src/thirdparty/requirejs
url = https://github.com/jrburke/requirejs.git
Expand Down
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ module.exports = function (grunt) {
});

// task: install
grunt.registerTask('install', ['write-config', 'less']);
grunt.registerTask('install', ['write-config', 'less', 'npm-install-extensions']);

// task: test
grunt.registerTask('test', ['eslint', 'jasmine', 'nls-check']);
Expand Down
15 changes: 10 additions & 5 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
},
"dependencies": {
"anymatch": "1.3.0",
"chokidar": "1.6.0"
"chokidar": "1.6.0",
"lodash": "4.15.0"
},
"devDependencies": {
"glob": "7.0.6",
"grunt": "0.4.5",
"jasmine-node": "1.11.0",
"grunt-jasmine-node": "0.1.0",
Expand Down
4 changes: 3 additions & 1 deletion src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@
},
"dependencies": {
"anymatch": "1.3.0",
"chokidar": "1.6.0"
"chokidar": "1.6.0",
"lodash": "4.15.0"
},
"devDependencies": {
"glob": "7.0.6",
"grunt": "0.4.5",
"jasmine-node": "1.11.0",
"grunt-jasmine-node": "0.1.0",
Expand Down
1 change: 1 addition & 0 deletions src/extensions/default/JavaScriptCodeHints/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules/
2 changes: 1 addition & 1 deletion src/extensions/default/JavaScriptCodeHints/HintUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
define(function (require, exports, module) {
"use strict";

var Acorn = require("thirdparty/acorn/acorn");
var Acorn = require("node_modules/acorn/dist/acorn");

var LANGUAGE_ID = "javascript",
HTML_LANGUAGE_ID = "html",
Expand Down
4 changes: 2 additions & 2 deletions src/extensions/default/JavaScriptCodeHints/ScopeManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ define(function (require, exports, module) {

var ternEnvironment = [],
pendingTernRequests = {},
builtinFiles = ["ecma5.json", "browser.json", "jquery.json"],
builtinFiles = ["ecmascript.json", "browser.json", "jquery.json"],
builtinLibraryNames = [],
isDocumentDirty = false,
_hintCount = 0,
Expand Down Expand Up @@ -84,7 +84,7 @@ define(function (require, exports, module) {
* Read in the json files that have type information for the builtins, dom,etc
*/
function initTernEnv() {
var path = ExtensionUtils.getModulePath(module, "thirdparty/tern/defs/"),
var path = ExtensionUtils.getModulePath(module, "node_modules/tern/defs/"),
files = builtinFiles,
library;

Expand Down
8 changes: 5 additions & 3 deletions src/extensions/default/JavaScriptCodeHints/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ define(function (require, exports, module) {
HTMLUtils = brackets.getModule("language/HTMLUtils"),
HintUtils = require("HintUtils"),
ScopeManager = require("ScopeManager"),
Acorn = require("thirdparty/acorn/acorn"),
Acorn_Loose = require("thirdparty/acorn/acorn_loose");
Acorn = require("node_modules/acorn/dist/acorn"),
Acorn_Loose = require("node_modules/acorn/dist/acorn_loose");

/**
* Session objects encapsulate state associated with a hinting session
Expand Down Expand Up @@ -669,7 +669,9 @@ define(function (require, exports, module) {
var ast;
try {
ast = Acorn.parse(fragment);
} catch (e) { ast = Acorn_Loose.parse_dammit(fragment); }
} catch (e) {
ast = Acorn_Loose.parse_dammit(fragment, {});
}

// find argument as cursor location and bold it.
var startOffset = this.getOffsetFromCursor(start),
Expand Down
34 changes: 34 additions & 0 deletions src/extensions/default/JavaScriptCodeHints/fix-acorn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2013 - present Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/

/*eslint-env node */
/*jslint node: true */

"use strict";

var fs = require("fs");
var path = require("path");
var fpath = path.resolve(__dirname, "node_modules", "acorn", "dist", "acorn_loose.js");
var content = fs.readFileSync(fpath, "utf8");
content = content.replace(/'\.\/acorn\.js'/g, "'./acorn'");
fs.writeFileSync(fpath, content, "utf8");
8 changes: 4 additions & 4 deletions src/extensions/default/JavaScriptCodeHints/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ define(function (require, exports, module) {
HintUtils = require("HintUtils"),
ScopeManager = require("ScopeManager"),
Session = require("Session"),
Acorn = require("thirdparty/acorn/acorn");
Acorn = require("node_modules/acorn/dist/acorn");

var session = null, // object that encapsulates the current session state
cachedCursor = null, // last cursor of the current hinting session
Expand Down Expand Up @@ -590,16 +590,16 @@ define(function (require, exports, module) {
// to check this, run the hint through Acorns tokenizer
// it should result in one token, and that token should either be
// a 'name' or a 'keyword', as javascript allows keywords as property names
var tokenizer = Acorn.tokenize(completion);
var currentToken = tokenizer();
var tokenizer = Acorn.tokenizer(completion);
var currentToken = tokenizer.getToken();

// the name is invalid if the hint is not a 'name' or 'keyword' token
if (currentToken.type !== Acorn.tokTypes.name && !currentToken.type.keyword) {
invalidPropertyName = true;
} else {
// check for a second token - if there is one (other than 'eof')
// then the hint isn't a valid property name either
currentToken = tokenizer();
currentToken = tokenizer.getToken();
if (currentToken.type !== Acorn.tokTypes.eof) {
invalidPropertyName = true;
}
Expand Down
122 changes: 122 additions & 0 deletions src/extensions/default/JavaScriptCodeHints/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/extensions/default/JavaScriptCodeHints/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "brackets-javascript-code-hints",
"dependencies": {
"acorn": "3.3.0",
"tern": "0.20.0"
},
"scripts": {
"postinstall": "node ./fix-acorn"
}
}
4 changes: 2 additions & 2 deletions src/extensions/default/JavaScriptCodeHints/tern-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var config = {};
require(["./MessageIds", "./HintUtils2"], function (messageIds, hintUtils2) {
MessageIds = messageIds;
HintUtils2 = hintUtils2;
var ternRequire = require.config({baseUrl: "./thirdparty"});
var ternRequire = require.config({baseUrl: "./node_modules"});
ternRequire(["tern/lib/tern", "tern/lib/infer", "tern/plugin/requirejs", "tern/plugin/doc_comment", "tern/plugin/angular"], function (tern, infer, requirejs, docComment) {
Tern = tern;
Infer = infer;
Expand Down Expand Up @@ -110,7 +110,7 @@ var config = {};
* Create a new tern server.
*
* @param {Object} env - an Object with the environment, as read in from
* the json files in thirdparty/tern/defs
* the json files in node_modules/tern/defs
* @param {Array.<string>} files - a list of filenames tern should be aware of
*/
function initTernServer(env, files) {
Expand Down
Submodule acorn deleted from 78e1d7
1 change: 0 additions & 1 deletion src/extensions/default/JavaScriptCodeHints/thirdparty/tern
Submodule tern deleted from 7606a6
4 changes: 2 additions & 2 deletions src/extensions/default/JavaScriptCodeHints/unittests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1152,8 +1152,8 @@ define(function (require, exports, module) {
testDoc.replaceRange("help.", start, start);
testEditor.setCursorPos(end);
var hintObj = expectHints(JSCodeHints.jsHintProvider);
// check we have a properties from "Function", "Array", and "Date"
hintsPresentOrdered(hintObj, ["apply", "concat", "getSeconds"]);
// check we have a properties from "Function", "String", and "Array"
hintsPresentOrdered(hintObj, ["apply", "charCodeAt", "concat"]);
});

it("should switch to guesses after typing a query that does not match any hints", function () {
Expand Down
Loading

0 comments on commit 1ed6c04

Please sign in to comment.