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 239360 Details for
Bug 426399
The ILLEGAL token sounds bad
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 fix
error-types.patch (text/plain), 10.64 KB, created by
Michael Rennie
on 2014-01-27 15:13:12 EST
(
hide
)
Description:
proposed fix
Filename:
MIME Type:
Creator:
Michael Rennie
Created:
2014-01-27 15:13:12 EST
Size:
10.64 KB
patch
obsolete
>diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/astManager.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/astManager.js >index 6b5b8a0..46ca13e 100644 >--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/astManager.js >+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/astManager.js >@@ -1,6 +1,6 @@ > /******************************************************************************* > * @license >- * Copyright (c) 2013 IBM Corporation and others. >+ * Copyright (c) 2013, 2014 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 >@@ -15,7 +15,21 @@ > 'orion/Deferred', > 'orion/objects', > 'orion/serialize' >-], function(_, Deferred, objects, Serialize) { >+], function(Esprima, Deferred, Objects, Serialize) { >+ /** >+ * @description Object of error types >+ * @since 5.0 >+ */ >+ var ErrorTypes = { >+ /** >+ * @description Something unexpected has been found while parsing, most commonly a syntax error >+ */ >+ Unexpected: 1, >+ /** >+ * @description A Syntax problem that reports the last entered token as the problem >+ */ >+ EndOfInput: 2 >+ }; > > /** > * Provides a shared AST. >@@ -25,26 +39,8 @@ > function ASTManager() { > this.cache = null; > } >- function emptyAST(text) { >- var charCount = (text && typeof text.length === "number") ? text.length : 0; >- return { >- type: "Program", //$NON-NLS-0$ >- body: [], >- comments: [], >- tokens: [], >- range: [0, charCount] >- }; >- } >- objects.mixin(ASTManager.prototype, /** @lends javascript.ASTManager.prototype */ { >- /** >- * @description Object of error types >- */ >- ErrorTypes: { >- /** >- * @description Something unexpected has been found while parsing, most commonly a syntax error >- */ >- Unexpected: "unexp" >- }, >+ >+ Objects.mixin(ASTManager.prototype, /** @lends javascript.ASTManager.prototype */ { > /** > * @param {Object} editorContext > * @returns {orion.Promise} A promise resolving to the AST. >@@ -74,9 +70,9 @@ > tokens: true > }); > } catch (e) { >- // The "tolerant" esprima sometimes blows up from parse errors in initial statements of code. >+ // The "tolerant" Esprima sometimes blows up from parse errors in initial statements of code. > // Just return an empty AST with the parse error. >- ast = emptyAST(text); >+ ast = this._emptyAST(text); > ast.errors = [e]; > } > if (ast.errors) { >@@ -84,6 +80,23 @@ > ast.errors = ast.errors.map(Serialize.serializeError); > } > return ast; >+ }, >+ /** >+ * @description Returns an empty AST in the event a parse failed with a thrown exception >+ * @function >+ * @private >+ * @param {String} text The text that failed to parse >+ * @returns {Object} A new, empty AST object >+ */ >+ _emptyAST: function(text) { >+ var charCount = (text && typeof text.length === "number") ? text.length : 0; >+ return { >+ type: "Program", //$NON-NLS-0$ >+ body: [], >+ comments: [], >+ tokens: [], >+ range: [0, charCount] >+ }; > }, > /** > * @description Computes the problem type from the error and sets a 'type' property >@@ -96,11 +109,12 @@ > if(errors && Array.isArray(errors)) { > errors.forEach(function(error) { > var msg = error.message; >- if(msg) { >- if(msg.indexOf('token') > -1 || msg.indexOf('identifier') > -1 || >- msg.indexOf('string') > -1 || msg.indexOf('number') > -1) { >- error.type = 'unexp'; >- return; >+ //first sanitize it >+ error.message = msg = msg.replace(/^Line \d+: /, ''); >+ if(/^Unexpected/.test(msg)) { >+ error.type = ErrorTypes.Unexpected; >+ if(/end of input$/.test(msg)) { >+ error.type = ErrorTypes.EndOfInput; > } > } > }); >@@ -114,5 +128,7 @@ > this.cache = null; > } > }); >- return ASTManager; >+ return { >+ ASTManager : ASTManager, >+ ErrorTypes : ErrorTypes}; > }); >\ No newline at end of file >diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/eslint/validator.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/eslint/validator.js >index 1eb0966..c63f4c0 100644 >--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/eslint/validator.js >+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/eslint/validator.js >@@ -12,8 +12,10 @@ > /*global define*/ > define([ > "eslint", >- "orion/objects" >-], function(eslint, objects) { >+ "orion/objects", >+ "orion/Deferred", >+ "javascript/astManager" >+], function(eslint, Objects, Deferred, ASTManager) { > // Should have a better way of keeping this up-to-date with ./load-rules-async.js > var config = { > // 0:off, 1:warning, 2:error >@@ -27,6 +29,13 @@ > "missing-func-decl-doc": [0, 'decl'], //$NON-NLS-0$ //$NON-NLS-1$ > "missing-func-expr-doc": [0, 'expr'] //$NON-NLS-0$ //$NON-NLS-1$ > }, >+ /** >+ * @description Sets the given rule to the given enabled value >+ * @function >+ * @private >+ * @param {String} ruleId The id of the rule to change >+ * @param {Number} value The vlaue to set the rule to >+ */ > setOption: function(ruleId, value) { > if (typeof value === "number") { > if(Array.isArray(this.rules[ruleId])) { >@@ -43,6 +52,7 @@ > * @description Creates a new ESLintValidator > * @constructor > * @public >+ * @param {javascript.ASTManager} astManager The AST manager backing this validator > * @returns {ESLintValidator} Returns a new validator > */ > function ESLintValidator(astManager) { >@@ -91,6 +101,7 @@ > } else if (typeof e.index === "number") { //$NON-NLS-0$ > // Esprima parse error > start = e.index; >+ end = e.end ? e.end : start; > } > var prob = { > description: e.message, >@@ -101,30 +112,65 @@ > return prob; > } > >- objects.mixin(ESLintValidator.prototype, { >+ Objects.mixin(ESLintValidator.prototype, { > /** > * @descritpion Extracts any errors captured by the tolerant esprima parser and returns them > * @function > * @private >- * @param {esprima.ASTNode} ast The AST >+ * @param {esprima.AST} ast The AST >+ * @param {String} buffer the text form the editor >+ * @param {Array} asterrors The parse problems in the AST > * @returns {esprima.Error[]} The array of AST errors (if any) > */ >- _extractParseErrors: function(ast) { >+ _extractParseErrors: function(ast, buffer, offsets) { > var errors = [], errorMap = Object.create(null); >- (ast.errors || []).forEach(function(error) { >- var msg = error.message, match; >- // Errors come as 'Line nn: Unexpected foo'. Strip off the first part >- if ((match = /^Line \d+: /.exec(msg))) { >- error.message = msg = "Parse error: " + msg.substring(match.index + match[0].length) + "."; >+ var asterrors = ast.errors; >+ if(asterrors) { >+ var len = asterrors.length; >+ for(var i = 0; i < len; i++) { >+ var error = asterrors[i]; >+ var msg = error.message; >+ if(errorMap[error.index] === msg) { >+ continue; >+ } >+ errorMap[error.index] = msg; >+ if(error.type) { >+ switch(error.type) { >+ case ASTManager.ErrorTypes.Unexpected: >+ var token = buffer.substring(error.index, offsets[i] + error.column); >+ error.message = msg = "Syntax error on token '"+token+"', delete this token."; >+ error.end = offsets[i] + error.column; >+ break; >+ case ASTManager.ErrorTypes.EndOfInput: >+ error.message = "Syntax error, incomplete statement."; >+ var text = buffer.substring(offsets[i], error.index).replace(/\s\s*$/, ''); >+ //tag the last char, maybe end of word, maybe bad punctuation >+ error.index = offsets[i] + text.length-1; >+ error.end = offsets[i] + text.length; >+ break; >+ } >+ } >+ errors.push(error); > } >- // Hack to filter out duplicate error produced by our esprima, having same index and message as previous error. >- if (errorMap[error.index] === msg) { >- return; >- } >- errorMap[error.index] = msg; >- errors.push(error); >- }); >+ } > return errors; >+ }, >+ /** >+ * @description Computes the array of line start promises for parser errors >+ * @function >+ * @private >+ * @param {orin.editor.EditorContext} editorContext The backing editor context >+ * @param {Array} errors The array of parser errors >+ * @returns {Array|orion.Promise} Returns the array of line start promises >+ */ >+ _getLineStartPromises: function(editorContext, errors) { >+ var promises = []; >+ (errors || []).forEach(function(error) { >+ if(error.lineNumber) { >+ promises.push(editorContext.getLineStart(error.lineNumber-1)); >+ } >+ }); >+ return promises; > }, > /** > * @descripion Callback to create problems from orion.edit.validator >@@ -137,13 +183,18 @@ > computeProblems: function(editorContext, context) { > var _self = this; > return this.astManager.getAST(editorContext).then(function(ast) { >+ var deferred = new Deferred(); >+ var promises = [deferred.resolve(ast), editorContext.getText()] >+ .concat(_self._getLineStartPromises(editorContext, ast.errors)); >+ return new Deferred.all(promises); >+ }).then(function(results) { > var eslintErrors = [], error; > try { >- eslintErrors = eslint.verify(ast, config); >+ eslintErrors = eslint.verify(results[0], config); > } catch (e) { > error = e; > } >- var parseErrors = _self._extractParseErrors(ast); >+ var parseErrors = _self._extractParseErrors(results[0], results[1], results.splice(2, results.length)); > var problems = [] > .concat(eslintErrors) > .concat(parseErrors) >diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js >index 9640737..062e291 100644 >--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js >+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js >@@ -60,7 +60,7 @@ > /** > * Create the AST manager > */ >- var astManager = new ASTManager(); >+ var astManager = new ASTManager.ASTManager(); > > /** > * Register AST manager as Model Change listener >diff --git a/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/astManagerTests.js b/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/astManagerTests.js >index 2c12882..8111f6b 100644 >--- a/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/astManagerTests.js >+++ b/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/astManagerTests.js >@@ -39,7 +39,7 @@ > return this.ast; > } > }; >- var astManager = new ASTManager(); >+ var astManager = new ASTManager.ASTManager(); > return { > astManager: astManager, > editorContext: mockEditorContext,
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 426399
:
239242
| 239360