Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 261741 Details for
Bug 493276
[es6] Comments attached to incorrect node in 'export' statement
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Proposed patch including updated regression tests
493276.patch (text/plain), 34.92 KB, created by
Olivier Thomann
on 2016-05-13 19:10:19 EDT
(
hide
)
Description:
Proposed patch including updated regression tests
Filename:
MIME Type:
Creator:
Olivier Thomann
Created:
2016-05-13 19:10:19 EDT
Size:
34.92 KB
patch
obsolete
>diff --git a/bundles/org.eclipse.orion.client.javascript/web/eslint/lib/load-rules-async.js b/bundles/org.eclipse.orion.client.javascript/web/eslint/lib/load-rules-async.js >index ceaf93c..face9eb 100644 >--- a/bundles/org.eclipse.orion.client.javascript/web/eslint/lib/load-rules-async.js >+++ b/bundles/org.eclipse.orion.client.javascript/web/eslint/lib/load-rules-async.js >@@ -265,8 +265,8 @@ define([ > if(!comments || comments.leading.length < 1) { > //TODO see https://github.com/jquery/esprima/issues/1071 > comments = context.getComments(node.id); >- } >- if(!validComment(comments)) { >+ } >+ if(!validComment(comments) && node.parent && node.parent.type !== "ExportNamedDeclaration") { > context.report(node.id, ProblemMessages['missing-doc'], {0:node.id.name}, { type: 'decl' }); //$NON-NLS-1$ > } > break; >@@ -297,7 +302,8 @@ define([ > return { > "Property": checkDoc, > "FunctionDeclaration": checkDoc, >- "ExpressionStatement": checkDoc >+ "ExpressionStatement": checkDoc, >+ "ExportNamedDeclaration": checkDoc > }; > }, > /** @callback */ >@@ -287,7 +287,12 @@ define([ > } > } > break; >- } >+ case 'ExportNamedDeclaration' : >+ comments = context.getComments(node); >+ if(!validComment(comments) && node.declaration && node.declaration.type === "FunctionDeclaration") { >+ context.report(node.declaration.id, ProblemMessages['missing-doc'], {0:node.declaration.id.name}, { type: 'decl' }); //$NON-NLS-1$ >+ } >+ } > } > catch(ex) { > Logger.log(ex); >diff --git a/bundles/org.eclipse.orion.client.javascript/web/eslint/lib/source-code.js b/bundles/org.eclipse.orion.client.javascript/web/eslint/lib/source-code.js >index 181eb50..36e5d5e 100644 >--- a/bundles/org.eclipse.orion.client.javascript/web/eslint/lib/source-code.js >+++ b/bundles/org.eclipse.orion.client.javascript/web/eslint/lib/source-code.js >@@ -141,9 +141,8 @@ SourceCode.prototype = { > if (node) { > return (this.text !== null) ? this.text.slice(Math.max(node.range[0] - (beforeCount || 0), 0), > node.range[1] + (afterCount || 0)) : null; >- } else { >- return this.text; > } >+ return this.text; > > }, > >@@ -179,10 +178,18 @@ SourceCode.prototype = { > * leadingComments/trailingComments. Comments are only left in the > * Program node comments array if there is no executable code. > */ >- if (node.type === "Program") { >- if (node.body.length === 0) { >- leadingComments = node.comments; >- } >+ switch(node.type) { >+ case "Program" : >+ if (node.body.length === 0) { >+ leadingComments = node.comments; >+ } >+ break; >+ case "FunctionDeclaration" : >+ var parent = node.parent; >+ if (looksLikeExport(parent)) { >+ leadingComments = parent.leadingComments || []; >+ trailingComments = parent.trailingComments || []; >+ } > } > > return { >@@ -207,10 +214,8 @@ SourceCode.prototype = { > case "FunctionDeclaration": > if (looksLikeExport(parent)) { > return findJSDocComment(parent.leadingComments, line); >- } else { >- return findJSDocComment(node.leadingComments, line); > } >- break; >+ return findJSDocComment(node.leadingComments, line); > > case "ClassDeclaration": > return findJSDocComment(node.leadingComments, line); >diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/commands/generateDocCommand.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/commands/generateDocCommand.js >index 8600cbc..81eaccc 100644 >--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/commands/generateDocCommand.js >+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/commands/generateDocCommand.js >@@ -28,7 +28,18 @@ define([ > this.astManager = ASTManager; > this.cuprovider = CUProvider; > } >- >+ >+ /** >+ * Check to see if its a ES6 export declaration >+ * @param {ASTNode} astNode - any node >+ * @returns {boolean} whether the given node represents a export declaration >+ * @private >+ */ >+ function looksLikeExport(astNode) { >+ return astNode.type === "ExportDefaultDeclaration" || astNode.type === "ExportNamedDeclaration" || >+ astNode.type === "ExportAllDeclaration" || astNode.type === "ExportSpecifier"; >+ } >+ > Objects.mixin(GenerateDocCommand.prototype, { > /** > * @callback >@@ -72,7 +83,14 @@ define([ > var template; > var start = parent.range[0]; > if(parent.type === 'FunctionDeclaration') { >- template = this._genTemplate(parent.id.name, parent.params, false, parent.range[0], text); >+ var len = parent.parents.length-1; >+ var funcParent = parent.parents[len]; >+ if (funcParent && looksLikeExport(funcParent)) { >+ template = this._genTemplate(parent.id.name, parent.params, false, funcParent.range[0], text); >+ start = funcParent.range[0]; >+ } else { >+ template = this._genTemplate(parent.id.name, parent.params, false, parent.range[0], text); >+ } > } else if(parent.type === 'Property') { > template = this._genTemplate(parent.key.name ? parent.key.name : parent.key.value, parent.value.params, true, parent.range[0], text); > } else if(parent.type === 'VariableDeclarator') { >diff --git a/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/JsMochaSuite.html b/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/JsMochaSuite.html >index 9a8d879..3caea32 100644 >--- a/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/JsMochaSuite.html >+++ b/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/JsMochaSuite.html >@@ -23,7 +23,7 @@ > "js-tests/javascript/testingWorker", > 'js-tests/javascript/crossFileTests', > 'js-tests/javascript/ternAssistIndexTests', >- 'js-tests/javascript/ternAssistModuleTests', >+ 'js-tests/javascript/ternAssistModuleTests', > 'js-tests/javascript/ternAssistTests', > 'js-tests/javascript/ternCommandsTests', > 'js-tests/javascript/esprimaTolerantTests', >@@ -34,14 +34,16 @@ > 'js-tests/javascript/validatorTests', > 'js-tests/javascript/lruTests', > 'js-tests/javascript/quickfixTests', >+ 'js-tests/javascript/es6QuickfixTests', > 'js-tests/javascript/eslintCoreTests', > 'js-tests/javascript/scriptResolverTests', > 'js-tests/javascript/sigparserTests', >+ 'js-tests/javascript/es6ValidatorTests', > 'js-tests/javascript/ternProjectFileTests', > 'js-tests/javascript/ternProjectManagerTests', >- 'js-tests/javascript/ternProjectValidatorTests' >+ 'js-tests/javascript/ternProjectValidatorTests', > ], function(worker, crossFileTests, ternAssistIndexTests, ternAssistModuleTests, ternAssistTests, ternCommandTests, esprimaTolerantTests, dependencyTests, finderTests, occurrencesTests, outlinerTests, validatorTests, lruTests, quickfixTests, >- eslintCoreTests, scriptResolverTests, sigparserTests, ternProjectTests, ternProjectValidatorTests) { >+ es6QuickfixTests, eslintCoreTests, scriptResolverTests, sigparserTests, es6ValidatorTests, ternProjectTests, ternProjectValidatorTests) { > var testworker; > before("reset timeout", function(done) { > this.timeout(30000); >@@ -62,13 +64,15 @@ > occurrencesTests(testworker); > outlinerTests(testworker); > quickfixTests(testworker); >+ es6QuickfixTests(testworker); > scriptResolverTests(testworker); > sigparserTests(testworker); > ternAssistIndexTests(testworker); >- ternAssistModuleTests(testworker); >+ ternAssistModuleTests(testworker); > ternAssistTests(testworker); > ternCommandTests(testworker); > validatorTests(testworker); >+ es6ValidatorTests(testworker); > ternProjectTests(testworker); > ternProjectValidatorTests(testworker); > testSuite.run(); >diff --git a/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/es6QuickfixTests.js b/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/es6QuickfixTests.js >new file mode 100644 >index 0000000..776016f >--- /dev/null >+++ b/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/es6QuickfixTests.js >@@ -0,0 +1,292 @@ >+/******************************************************************************* >+ * @license >+ * Copyright (c) 2016 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials are made >+ * available under the terms of the Eclipse Public License v1.0 >+ * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution >+ * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+/*eslint-env amd, mocha*/ >+/* eslint-disable missing-nls */ >+define([ >+ 'javascript/quickFixes', >+ 'javascript/validator', >+ 'chai/chai', >+ 'orion/Deferred', >+ 'javascript/astManager', >+ 'javascript/cuProvider', >+ 'javascript/commands/renameCommand', >+ 'javascript/commands/generateDocCommand', >+ 'orion/serviceregistry', >+ 'javascript/javascriptProject', >+ 'mocha/mocha', //must stay at the end, not a module >+], function(QuickFixes, Validator, chai, Deferred, ASTManager, CUProvider, RenameCommand, GenerateDocCommand, mServiceRegistry, JSProject) { >+ var assert = chai.assert; >+ >+ return function(worker) { >+ describe('ES6 Quick Fix Tests',function() { >+ this.timeout(10000); >+ before('Reset Tern Server', function(done) { >+ worker.start(done, {options:{ecmaVersion:6, sourceType:"module"}}); >+ }); >+ >+ /** >+ * @description Sets up the test >+ * >+ * Supported options include: >+ * - `buffer` - the source to process >+ * - `contentType` - the content type to load, defaults to application/javascript if not specified >+ * - `callback` - the 'done' param from the tests, its required for all worker-based tests >+ * - `rule` - the rule object. {@link #createTestRule(...)} >+ * - `expected` - the array of expected fixes >+ * - `fixid` - the id of the rule to use if not the same as the one created by default - allows testing multifixes >+ * @param {Object} options {buffer, contentType} >+ * @returns {Object} The object with the initialized values >+ */ >+ function setup(options) { >+ var buffer = options.buffer; >+ var contentType = options.contentType ? options.contentType : 'application/javascript'; >+ var astManager = new ASTManager.ASTManager(); >+ var serviceRegistry = new mServiceRegistry.ServiceRegistry(); >+ var validator = new Validator(worker); >+ var state = Object.create(null); >+ var loc = contentType === 'text/html' ? 'es6quickfix_test_script.html' : 'es6quickfix_test_script.js'; >+ assert(options.callback, "You must provide a callback for a worker-based test"); >+ state.callback = options.callback; >+ worker.setTestState(state); >+ var rule = options.rule; >+ validator._enableOnly(rule.id, rule.severity, rule.opts); >+ var renameCommand = new RenameCommand.RenameCommand(worker, {setSearchLocation: function(){}}); >+ var generateDocCommand = new GenerateDocCommand.GenerateDocCommand(astManager, CUProvider); >+ var fixComputer = new QuickFixes.JavaScriptQuickfixes(astManager, renameCommand, generateDocCommand, new JSProject(serviceRegistry), worker); >+ var editorContext = { >+ /*override*/ >+ getText: function(start, end) { >+ if(typeof start === 'undefined' && typeof end === 'undefined') { >+ return new Deferred().resolve(buffer); >+ } >+ return new Deferred().resolve(buffer.slice(start, end)); >+ }, >+ >+ setText: function(text, start, end) { >+ return new Deferred().resolve(assertFixes(text, start, end, options.expected)); >+ }, >+ >+ getSelections: function(){ >+ return new Deferred().resolve([]); >+ }, >+ >+ getFileMetadata:function() { >+ var o = Object.create(null); >+ o.contentType = Object.create(null); >+ o.contentType.id = contentType; >+ o.location = loc; >+ return new Deferred().resolve(o); >+ }, >+ exitLinkedMode: function() { >+ return new Deferred().resolve(); >+ }, >+ enterLinkedMode: function(linkModel) { >+ return new Deferred().resolve(assertLinkedModel(linkModel, options.expected)); >+ }, >+ setCaretOffset: function(caretOffset) { >+ return new Deferred().resolve(caretOffset); >+ }, >+ openEditor: function(file, opts){ >+ return new Deferred().resolve(assertFixes({file: file, start: opts.start, end: opts.end}, null, null, options.expected)); >+ } >+ }; >+ return { >+ validator: validator, >+ fixComputer: fixComputer, >+ editorContext: editorContext, >+ contentType: contentType, >+ loc: loc >+ }; >+ } >+ >+ /** >+ * @callback from Mocha after each test run >+ */ >+ afterEach(function() { >+ CUProvider.onModelChanging({file: {location: 'es6quickfix_test_script.js'}}); >+ CUProvider.onModelChanging({file: {location: 'es6quickfix_test_script.html'}}); >+ }); >+ >+ /** >+ * @description Checks the state of the linked models >+ * @param {Object} linkedModel The linked model from the platform >+ * @param {Object} expected The expected linked model from the test >+ * @since 11.0 >+ */ >+ function assertLinkedModel(linkedModel, expected) { >+ try { >+ assert(expected, "There must be an expected linkedModel"); >+ assert(expected.groups, "There must be a groups node in the expected linked model"); >+ assert(Array.isArray(expected.groups), "Groups must be an array in the expected linked model"); >+ assert(linkedModel, "There must be a linkedModel"); >+ assert(linkedModel.groups, "There must be a groups node in the linked model"); >+ assert(Array.isArray(linkedModel.groups), "Groups must be an array in the linked model"); >+ assert.equal(linkedModel.groups.length, expected.groups.length, "The linked mode groups should be the same length"); >+ expected.groups.forEach(function(group, index) { >+ //groups have data and positions: [{offset, length}] >+ var g = linkedModel.groups[index]; >+ assert.equal(typeof g.data, typeof group.data, "The type of the data of the groups is not the same"); >+ assert(Array.isArray(g.positions), "There should be a positions array"); >+ assert(Array.isArray(group.positions), "There must be an expected positions array"); >+ assert.equal(g.positions.length, group.positions.length, "The position arrays should be the same size"); >+ group.positions.forEach(function(pos, index2) { >+ var p = g.positions[index2]; >+ assert(p, "There should be a position"); >+ assert.equal(p.offset, pos.offset, "The position offsets do not match"); >+ assert.equal(p.length, pos.length, "The position lengths do not match"); >+ }); >+ }); >+ } >+ catch(err) { >+ worker.getTestState().callback(err); >+ } >+ } >+ >+ /** >+ * @description Runs the validator on the given options and computes fixes for those problems >+ * @param {Object} options {buffer, contentType, rule} >+ * @returns {orion.Promise} The validation promise >+ */ >+ function getFixes(options) { >+ var obj = setup(options); >+ return obj.validator.computeProblems(obj.editorContext, {contentType: obj.contentType, rule: options.rule}).then( >+ function(problems) { >+ try { >+ var pbs = problems.problems; >+ var annot = pbs[0]; >+ if(options.pid) { >+ for(var i = 0; i < pbs.length; i++) { >+ if(pbs[i].id === options.pid) { >+ annot = pbs[i]; >+ break; >+ } >+ } >+ assert(i !== pbs.length, "Did not find any problems for the expected id: "+ options.pid); >+ } else { >+ assert(pbs, "There should always be problems"); >+ // Some quick fixes may provide multiple expected text edits per problem >+ if (!Array.isArray(options.expected)){ >+ assert.equal(pbs.length, 1, 'Expected only one problem per test'); >+ } >+ assert(annot.id, "No problem id is reported"); >+ assert(annot.id.indexOf(options.rule.id) === 0, "The problem id should start with the enabled rule id"); >+ } >+ annot.title = annot.description; >+ if(options.fixid) { >+ annot.fixid = options.fixid; >+ } >+ var annotations; >+ if (Array.isArray(options.expected)){ >+ annotations = pbs; >+ for (i=0; i<annotations.length; i++) { >+ annotations[i].title = annotations[i].description; >+ } >+ } >+ return obj.fixComputer.execute(obj.editorContext, {annotation: annot, annotations: annotations, input: obj.loc}).then(function() { >+ worker.getTestState().callback(); >+ }, >+ function(err) { >+ if(err instanceof Error) { >+ worker.getTestState().callback(err); >+ } else if(typeof err.Message === 'string') { >+ worker.getTestState().callback(err.Message); >+ } else { >+ worker.getTestState().callback("Test rejected with unknown error"); >+ } >+ }); >+ } >+ catch(err) { >+ worker.getTestState().callback(err); >+ } >+ }, >+ function (error) { >+ worker.getTestState().callback(error); >+ }); >+ } >+ >+ /** >+ * @description Compares the computed fixes set against the expected ones >+ * @param {Array.<orion.Fix>} computed The computed set of fixes >+ * @param {Array.<Object>} expected The expected set of fixes >+ */ >+ function assertFixes(computed, start, end, expected) { >+ try { >+ assert(computed !== null && typeof computed !== 'undefined', 'There should be fixes'); >+ if (Array.isArray(expected)){ >+ assert(Array.isArray(computed.text), "Expected multiple quick fix text edits"); >+ assert(Array.isArray(computed.selection), "Expected multiple quick fix selections"); >+ assert.equal(computed.text.length, expected.length, "Wrong number of quick fix text edits"); >+ assert.equal(computed.selection.length, expected.length, "Wrong number of quick fix selections"); >+ for (var i=0; i<expected.length; i++) { >+ assert(computed.text[i] === expected[i].value, 'The fix: \"'+computed.text[i]+'\" does not match the expected fix of: \"'+expected[i].value + '\"'); >+ assert.equal(computed.selection[i].start, expected[i].start, 'The fix starts do not match'); >+ assert.equal(computed.selection[i].end, expected[i].end, 'The fix ends do not match'); >+ } >+ } else if (typeof computed === 'object' && computed.file && expected.file){ >+ assert.equal(computed.file, expected.file, 'Navigation fix found but to wrong file.\nExpected: ' + expected.file + ' (' + expected.start + ',' + expected.end + ')\nActual: ' + computed.file + ' (' + computed.start + ',' + computed.end + ')'); >+ assert.equal(computed.start, expected.start, 'Navigation fix found but to wrong start.\nExpected: ' + expected.file + ' (' + expected.start + ',' + expected.end + ')\nActual: ' + computed.file + ' (' + computed.start + ',' + computed.end + ')'); >+ assert.equal(computed.end, expected.end, 'Navigation fix found but to wrong end.\nExpected: ' + expected.file + ' (' + expected.start + ',' + expected.end + ')\nActual: ' + computed.file + ' (' + computed.start + ',' + computed.end + ')'); >+ } else if (typeof computed === 'object' && Array.isArray(computed.text)){ >+ assert.equal(computed.text.length, 1, 'Was expecting one quick fix text edit'); >+ assert.equal(computed.selection.length, 1, 'Was expected one quick fix selection range'); >+ assert(computed.text[0].indexOf(expected.value) > -1, 'The fix: \"'+computed.text[0]+'\"" does not match the expected fix of: '+expected.value); >+ assert.equal(computed.selection[0].start, expected.start, 'The fix starts do not match'); >+ assert.equal(computed.selection[0].end, expected.end, 'The fix ends do not match'); >+ } else { >+ assert(computed.indexOf(expected.value) > -1, 'The fix: '+computed+' does not match the expected fix of: '+expected.value); >+ assert.equal(start, expected.start, 'The fix starts do not match'); >+ assert.equal(end, expected.end, 'The fix ends do not match'); >+ } >+ } >+ catch(err) { >+ worker.getTestState().callback(err); >+ } >+ } >+ >+ /** >+ * @description Creates a test rule object for the test set up >+ * @param {String} id The id of the rule used to update the preferences in javascript/validator#updated >+ * @param {Number} severity The severity of the problem or null (which defaults to '2') >+ * @param {String} opts The optional args for a rule. For example no-missing-doc has 'decl' and 'expr' as optional args >+ * @returns {Object} Returns a new rule object for testing with >+ */ >+ function createTestRule(id, severity, opts) { >+ var rule = Object.create(null); >+ rule.id = id; >+ rule.severity = severity ? severity : 2; >+ rule.opts = opts; >+ return rule; >+ } >+ //MISSING-DOC >+ describe("missing-doc", function() { >+ it("export named declaration", function(done) { >+ var rule = createTestRule("missing-doc"); >+ var expected = { >+ value: "/**\n"+ >+ " * @name myFunc\n"+ >+ " * @description description\n"+ >+ " * @returns returns\n"+ >+ " */\n", >+ start: 21, >+ end: 21 >+ }; >+ return getFixes({ >+ buffer: "var MYCONSTANT = \"\";\nexport function myFunc() { return MYCONSTANT; }", >+ rule: rule, >+ expected: expected, >+ callback: done >+ }); >+ }); >+ }); >+ }); >+ }; >+}); >diff --git a/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/es6ValidatorTests.js b/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/es6ValidatorTests.js >new file mode 100644 >index 0000000..1a5ab9a >--- /dev/null >+++ b/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/es6ValidatorTests.js >@@ -0,0 +1,196 @@ >+/******************************************************************************* >+ * @license >+ * Copyright (c) 2016 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials are made >+ * available under the terms of the Eclipse Public License v1.0 >+ * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution >+ * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+/*eslint-env amd, mocha, node*/ >+/* eslint-disable missing-nls */ >+define([ >+ 'javascript/validator', >+ 'chai/chai', >+ 'orion/Deferred', >+ 'mocha/mocha', //must stay at the end, not a module >+], function(Validator, chai, Deferred) { >+ var assert = chai.assert; >+ return function(worker) { >+ describe('ES6 Validator Tests', function() { >+ >+ before('Reset Tern Server', function(done) { >+ worker.start(done, {options:{ecmaVersion:6, sourceType:"module"}}); >+ }); >+ >+ /** >+ * @description Sets up the test >+ * @param {Object} options {buffer, contentType}i >+ * @returns {Object} The object with the initialized values >+ */ >+ function setup(options) { >+ var buffer = options.buffer; >+ var contentType = options.contentType ? options.contentType : 'application/javascript'; >+ var validator = new Validator(worker); >+ var state = Object.create(null); >+ assert(options.callback, "You must provide a callback for a worker-based test"); >+ state.callback = options.callback; >+ worker.setTestState(state); >+ >+ if (options.createFiles){ >+ for (var i=0; i<options.createFiles.length; i++) { >+ worker.createTestFile(options.createFiles[i].name, options.createFiles[i].text); >+ } >+ } >+ >+ var editorContext = { >+ /*override*/ >+ getText: function() { >+ return new Deferred().resolve(buffer); >+ }, >+ /*override*/ >+ getFileMetadata: function() { >+ var o = Object.create(null); >+ o.contentType = Object.create(null); >+ o.contentType.id = contentType; >+ o.location = 'es6validator_test_script.js'; >+ if (contentType === 'text/html'){ >+ o.location = 'es6validator_test_script.html'; >+ } >+ return new Deferred().resolve(o); >+ } >+ }; >+ return { >+ validator: validator, >+ editorContext: editorContext, >+ contentType: contentType >+ }; >+ } >+ >+ /** >+ * @name validate >+ * @description Runs the validator on the given options >+ * @param {Object} options {buffer, contentType} >+ * @returns {orion.Promise} The validation promise >+ */ >+ function validate(options) { >+ var obj = setup(options); >+ return obj.validator.computeProblems(obj.editorContext, {contentType: obj.contentType}, options.config); >+ } >+ >+ /** >+ * @name assertProblems >+ * @description Compares the computed problem set against the expected ones >+ * @param {Array.<orion.Problem>} computed The computed est of problems >+ * @param {Array.<Object>} expected The expected set of problems >+ */ >+ function assertProblems(computed, expected) { >+ try { >+ var problems = computed.problems; >+ assert.equal(problems.length, expected.length, "The wrong number of problems was computed"); >+ for(var i = 0; i < problems.length; i++) { >+ var pb = problems[i]; >+ var expb = expected[i]; >+ if (expb.start) { >+ assert.equal(pb.start, expb.start, "Wrong problem start"); >+ } >+ if (expb.end) { >+ assert.equal(pb.end, expb.end, "Wrong problem end"); >+ } >+ if (expb.line) { >+ assert.equal(pb.line, expb.line, "Wrong problem line number"); >+ } >+ if (expb.description) { >+ assert.equal(pb.description, expb.description, "Wrong problem message"); >+ } >+ if (expb.severity) { >+ assert.equal(pb.severity, expb.severity, "Wrong problem severity"); >+ } >+ if(pb.descriptionArgs) { >+ assert(expb.descriptionArgs, "Missing expected description arguments"); >+ assert.equal(pb.descriptionArgs.nls, expb.descriptionArgs.nls, "Missing NLS descriptipon argument key"); >+ } >+ if (expb.nodeType) { >+ assert.equal(pb.nodeType, expb.nodeType); >+ } >+ if (expb.nlsComment) { >+ assert(pb.data, "Missing data"); >+ assert(pb.data.nlsComment, "Missing data nlsComment"); >+ assert.equal(pb.data.nlsComment, expb.nlsComment, "Wrong data nlsComment"); >+ } >+ } >+ worker.getTestState().callback(); >+ } >+ catch(err) { >+ worker.getTestState().callback(err); >+ } >+ } >+ >+ describe("missing-doc - function declaration - ecma6", function() { >+ it("should flag missing doc for export named declaration", function(callback) { >+ var config = { rules: {} }; >+ config.rules['missing-doc'] = [1, {decl: 1}]; >+ var features = Object.create(null); >+ features.modules = true; >+ config.ecmaFeatures = features; >+ validate({buffer: "var i = 0; export function myFunc() { return i; };", callback: callback, config: config}).then( >+ function (problems) { >+ assertProblems(problems, [{ >+ id: 'missing-doc', >+ severity: 'warning', >+ description: "Missing documentation for function \'myFunc\'.", >+ nodeType: "Identifier" >+ }]); >+ }, >+ function (error) { >+ worker.getTestState().callback(error); >+ }); >+ }); >+ }); >+ describe("missing-nls", function() { >+ var RULE_ID = "missing-nls"; >+ it("Ignore es6 import 1", function(callback) { >+ var topic = 'import { MYCONSTANT , arr } from "./exports";'; >+ var config = { rules: {} }; >+ var createFiles = [{name: './exports', text: ''}]; >+ config.rules[RULE_ID] = 1; >+ validate({buffer: topic, callback: callback, config: config, createFiles: createFiles}).then( >+ function (problems) { >+ assertProblems(problems, []); >+ }, >+ function (error) { >+ worker.getTestState().callback(error); >+ }); >+ }); >+ it("Ignore es6 import 2", function(callback) { >+ var topic = 'import * as myImport from "./exports";'; >+ var config = { rules: {} }; >+ var createFiles = [{name: './exports', text: ''}]; >+ config.rules[RULE_ID] = 1; >+ validate({buffer: topic, callback: callback, config: config, createFiles: createFiles}).then( >+ function (problems) { >+ assertProblems(problems, []); >+ }, >+ function (error) { >+ worker.getTestState().callback(error); >+ }); >+ }); >+ it("Ignore es6 import 3", function(callback) { >+ var topic = 'import "./exports";'; >+ var config = { rules: {} }; >+ var createFiles = [{name: './exports', text: ''}]; >+ config.rules[RULE_ID] = 1; >+ validate({buffer: topic, callback: callback, config: config, createFiles: createFiles}).then( >+ function (problems) { >+ assertProblems(problems, []); >+ }, >+ function (error) { >+ worker.getTestState().callback(error); >+ }); >+ }); >+ }); >+ }); >+ }; >+}); >diff --git a/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/testingWorker.js b/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/testingWorker.js >index edf76ff..600a64b 100644 >--- a/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/testingWorker.js >+++ b/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/testingWorker.js >@@ -83,13 +83,21 @@ define([ > * @param {Function} callback The callback to call when done starting worker and server > * @since 11.0 > */ >- WrappedWorker.prototype.start = function(callback) { >- _state.callback = callback; >- message({request: 'start_server', args: {}}, function() { >- callback(); >+ WrappedWorker.prototype.start = function(callback, json, fn) { >+ if(callback) { >+ //tests can pass in null here to avoid having the test "complete" once the server starts >+ _state.callback = callback; >+ } >+ var j = json ? json : {}; >+ message({request: 'start_server', args: j}, function() { >+ if(typeof fn === "function") { >+ fn(); >+ } >+ if(callback) { >+ callback(); >+ } > }); > }; >- > /** > * @name WrappedWorker.prototype.setTestState > * @description Sets the test state, must be called per test to ensure the correct state is being tested >diff --git a/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/validatorTests.js b/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/validatorTests.js >index 1402974..9e2b320 100644 >--- a/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/validatorTests.js >+++ b/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/validatorTests.js >@@ -5617,66 +5617,6 @@ define([ > worker.getTestState().callback(error); > }); > }); >- it("Ignore es6 import 1", function(callback) { >- var topic = 'import { MYCONSTANT , arr } from "./exports";'; >- var config = { rules: {} }; >- var createFiles = [{name: './exports', text: ''}]; >- config.rules[RULE_ID] = 1; >- validate({buffer: topic, callback: callback, config: config, createFiles: createFiles}).then( >- function (problems) { >- // TODO Tern does not default to 'sourceType: module' so we have a parse error, accepting the parse error is faster than restarting the server >- assertProblems(problems, [ >- { >- id: "forbiddenExportImport", >- severity: 'error', >- description: "'import' and 'export' may appear only with 'sourceType: module'", >- } >- ]); >- }, >- function (error) { >- worker.getTestState().callback(error); >- }); >- }); >- it("Ignore es6 import 2", function(callback) { >- var topic = 'import * from "./exports";'; >- var config = { rules: {} }; >- var createFiles = [{name: './exports', text: ''}]; >- config.rules[RULE_ID] = 1; >- validate({buffer: topic, callback: callback, config: config, createFiles: createFiles}).then( >- function (problems) { >- // TODO Tern does not default to 'sourceType: module' so we have a parse error, accepting the parse error is faster than restarting the server >- assertProblems(problems, [ >- { >- id: "forbiddenExportImport", >- severity: 'error', >- description: "'import' and 'export' may appear only with 'sourceType: module'", >- } >- ]); >- }, >- function (error) { >- worker.getTestState().callback(error); >- }); >- }); >- it("Ignore es6 import 3", function(callback) { >- var topic = 'import "./exports";'; >- var config = { rules: {} }; >- var createFiles = [{name: './exports', text: ''}]; >- config.rules[RULE_ID] = 1; >- validate({buffer: topic, callback: callback, config: config, createFiles: createFiles}).then( >- function (problems) { >- // TODO Tern does not default to 'sourceType: module' so we have a parse error, accepting the parse error is faster than restarting the server >- assertProblems(problems, [ >- { >- id: "forbiddenExportImport", >- severity: 'error', >- description: "'import' and 'export' may appear only with 'sourceType: module'", >- } >- ]); >- }, >- function (error) { >- worker.getTestState().callback(error); >- }); >- }); > it("HTML Mark missing", function(callback) { > var topic = "<script>var a = \"a\"; var b = \"bb\";</script>"; > var config = { rules: {} }; >diff --git a/bundles/org.eclipse.orion.client.javascript/web/tern/plugin/doc_comment.js b/bundles/org.eclipse.orion.client.javascript/web/tern/plugin/doc_comment.js >index bd44020..728c40e 100644 >--- a/bundles/org.eclipse.orion.client.javascript/web/tern/plugin/doc_comment.js >+++ b/bundles/org.eclipse.orion.client.javascript/web/tern/plugin/doc_comment.js >@@ -108,6 +108,18 @@ > if (prop) interpretComments(node, node.commentsBefore, scope, prop); > } > } >+ }, >+ // ORION >+ ExportNamedDeclaration: function(node, scope) { >+ if (node.leadingComments && node.declaration && node.declaration.type === 'FunctionDeclaration') { >+ var commentsBefore = []; >+ node.leadingComments.forEach(function(comment) { >+ commentsBefore.push(comment.value); >+ }); >+ interpretComments(node, commentsBefore, scope, >+ scope.getProp(node.declaration.id.name), >+ node.declaration.scope.fnType); >+ } > } > }, infer.searchVisitor, scope); > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 493276
:
261619
| 261741