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 261619 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 regression tests
493276.patch (text/plain), 12.44 KB, created by
Olivier Thomann
on 2016-05-10 20:34:43 EDT
(
hide
)
Description:
Proposed patch including regression tests
Filename:
MIME Type:
Creator:
Olivier Thomann
Created:
2016-05-10 20:34:43 EDT
Size:
12.44 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 83fb7d6..a6d0fa5 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; >@@ -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); >@@ -297,7 +302,8 @@ define([ > return { > "Property": checkDoc, > "FunctionDeclaration": checkDoc, >- "ExpressionStatement": checkDoc >+ "ExpressionStatement": checkDoc, >+ "ExportNamedDeclaration": checkDoc > }; > }, > /** @callback */ >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/javascript/plugins/ternWorkerCore.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/ternWorkerCore.js >index 02c25b3..c95c291 100644 >--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/ternWorkerCore.js >+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/ternWorkerCore.js >@@ -428,6 +428,10 @@ function(Tern, defaultOptions, Deferred, Objects, Serialize, Messages, i18nUtil) > if (args.env) { > query.config.env = args.env; > } >+ if (!ternserver.options) { >+ ternserver.options = Object.create(null); >+ } >+ ternserver.options.sourceType = args.sourceType ? args.sourceType : "script"; > ternserver.request( > { > query: query, >diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/validator.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/validator.js >index 684aa66..5b022e8 100644 >--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/validator.js >+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/validator.js >@@ -248,13 +248,18 @@ define([ > _validate: function(meta, text, env, deferred, configuration) { > // When validating snippets in an html file ignore undefined rule because other scripts may add to the window object > var rules = config.rules; >- if (configuration) { >+ if (configuration && configuration.rules) { > rules = configuration.rules; > } > var files = [{type: 'full', name: meta.location, text: text}]; //$NON-NLS-1$ > var args = {meta: {location: meta.location}, env: env, files: files, rules: rules}; >- if (configuration && configuration.ecmaFeatures) { >- args.ecmaFeatures = configuration.ecmaFeatures; >+ if (configuration) { >+ if (configuration.ecmaFeatures) { >+ args.ecmaFeatures = configuration.ecmaFeatures; >+ } >+ if (configuration.sourceType) { >+ args.sourceType = configuration.sourceType; >+ } > } > var request = {request: 'lint', args: args}; //$NON-NLS-1$ > var start = Date.now(); >diff --git a/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/quickfixTests.js b/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/quickfixTests.js >index f879e05..741be0b 100644 >--- a/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/quickfixTests.js >+++ b/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/quickfixTests.js >@@ -158,7 +158,7 @@ define([ > */ > function getFixes(options) { > var obj = setup(options); >- return obj.validator.computeProblems(obj.editorContext, {contentType: obj.contentType, rule: options.rule}).then( >+ return obj.validator.computeProblems(obj.editorContext, {contentType: obj.contentType, rule: options.rule}, options.config).then( > function(problems) { > try { > var pbs = problems.problems; >@@ -488,6 +488,27 @@ define([ > contentType: 'text/html' > }); > }); >+ 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, >+ config: { >+ sourceType: "module" >+ } >+ }); >+ }); > }); > //CURLY > describe("curly", function() { >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 42b0880..36f44a4 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 >@@ -1136,6 +1136,7 @@ define([ > // MISSING-DOC DECL------------------------------------------------ > describe("missing-doc - function declaration", function(){ > var RULE_ID = "missing-doc"; >+ this.timeout(10000000); > it("should not flag for root function declaration", function(callback) { > var config = { rules: {} }; > config.rules[RULE_ID] = [1, {decl: 1}]; >@@ -1346,6 +1347,26 @@ define([ > worker.getTestState().callback(error); > }); > }); >+ it("should flag missing doc for export named declaration", function(callback) { >+ var config = { rules: {} }; >+ config.rules[RULE_ID] = [1, {decl: 1}]; >+ var features = Object.create(null); >+ features.modules = true; >+ config.ecmaFeatures = features; >+ config.sourceType = "module"; >+ validate({buffer: "var i = 0; export function myFunc() { return i; };", callback: callback, config: config}).then( >+ function (problems) { >+ assertProblems(problems, [{ >+ id: RULE_ID, >+ severity: 'warning', >+ description: "Missing documentation for function \'myFunc\'.", >+ nodeType: "Identifier" >+ }]); >+ }, >+ function (error) { >+ worker.getTestState().callback(error); >+ }); >+ }); > }); > > // MISSING-DOC EXPR >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..a832865 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 >@@ -94,7 +94,7 @@ > for (var i = 0; i < node.body.body.length; i++) { > var method = node.body.body[i], name > if (!method.commentsBefore) continue >- if (method.kind == "constructor") >+ if (method.kind === "constructor") > interpretComments(method, method.commentsBefore, scope, node.objType) > else if ((name = infer.propName(method)) != "<i>") > interpretComments(method, method.commentsBefore, scope, proto.getProp(name)) >@@ -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