Comparing version 0.0.9 to 0.0.10
@@ -13,3 +13,3 @@ 'use strict'; | ||
var instructions = ['You should create SourceCodeFile instance with code or filename:', ' code: `new SourceCodeFile( { code: \'var a = 1;\' } )`', ' file: `new SourceCodeFile( { file: \'./full/path/to/file.js\' } )`', ' ast: `new SourceCodeFile( { ast: ast_object } )`'].join('\n'); | ||
var instructions = ['SourceCode creation Error. You should create SourceCode instance with a code or a filename:', ' code: `new SourceCode( { code: \'var a = 1;\' } )`', ' file: `new SourceCode( { file: \'./full/path/to/file.js\' } )`', ' ast: `new SourceCode( { ast: ast_object } )`'].join('\n'); | ||
@@ -53,3 +53,8 @@ /** | ||
this.__code = code; | ||
this.__ast = recast.parse(code); | ||
try { | ||
this.__ast = recast.parse(code); | ||
} catch (err) { | ||
this.__print_parse_error(code, err); | ||
throw err; | ||
} | ||
} else if (ast) { | ||
@@ -62,2 +67,26 @@ this.__file_path = file_path; | ||
}, { | ||
key: '__print_parse_error', | ||
value: function __print_parse_error(code, err) { | ||
// get the source code line of the error | ||
var errorLine = ''; | ||
if (err.lineNumber) { | ||
errorLine = code.split('\n')[err.lineNumber - 1]; | ||
} | ||
// show column indicator | ||
var errorColumnIndicator = ''; | ||
if (err.column) { | ||
for (var i = 0; i < err.column - 1; i++) { | ||
errorColumnIndicator += '-'; | ||
} | ||
errorColumnIndicator += '^'; | ||
} | ||
// error complement | ||
var error_message_complement = ['', ' ' + errorLine, ' ' + errorColumnIndicator, ' ' + err.message].join('\n'); | ||
// throw esprima error | ||
err.message = error_message_complement; | ||
} | ||
}, { | ||
key: '__loadFromFile', | ||
@@ -110,2 +139,2 @@ | ||
module.exports = SourceCode; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNvdXJjZS1jb2RlLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7O0FBQUEsSUFBSSxNQUFNLEdBQUcsT0FBTyxDQUFDLFFBQVEsQ0FBQ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gICB2YXIgZmlsZV9jb250ZW50ID0geWllbGQgZmlsZVV0aWxzLnJlYWQoZnVsbF9wYXRoKTtcbiAgICAgIHRoaXMuX19pbml0aWFsaXplKGZpbGVfY29udGVudCwgbnVsbCk7XG4gICAgICByZXR1cm4gdGhpcztcbiAgICB9LmJpbmQodGhpcykpKGZ1bGxfcGF0aCk7XG4gIH1cblxuICBnZXQgY29kZSgpIHtcbiAgICByZXR1cm4gdGhpcy5fX2NvZGU7XG4gIH1cblxuICBnZXQgYXN0KCkge1xuICAgIHJldHVybiB0aGlzLl9fYXN0O1xuICB9XG5cbiAgZ2V0IGZpbGVwYXRoKCkge1xuICAgIHJldHVybiB0aGlzLl9fZmlsZV9wYXRoO1xuICB9XG5cbn1cblxubW9kdWxlLmV4cG9ydHMgPSBTb3VyY2VDb2RlO1xuIl0sInNvdXJjZVJvb3QiOiIvc291cmNlLyJ9 |
{ | ||
"name": "castborg", | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"description": "AST searcher and modifier", | ||
@@ -15,3 +15,3 @@ "main": "index.js", | ||
"devDependencies": { | ||
"azk-dev": "^0.0.5" | ||
"azk-dev": "0.0.5" | ||
}, | ||
@@ -18,0 +18,0 @@ "scripts": { |
@@ -6,6 +6,6 @@ var recast = require('recast'); | ||
var instructions = [ | ||
'You should create SourceCodeFile instance with code or filename:', | ||
' code: `new SourceCodeFile( { code: \'var a = 1;\' } )`', | ||
' file: `new SourceCodeFile( { file: \'./full/path/to/file.js\' } )`', | ||
' ast: `new SourceCodeFile( { ast: ast_object } )`', | ||
'SourceCode creation Error. You should create SourceCode instance with a code or a filename:', | ||
' code: `new SourceCode( { code: \'var a = 1;\' } )`', | ||
' file: `new SourceCode( { file: \'./full/path/to/file.js\' } )`', | ||
' ast: `new SourceCode( { ast: ast_object } )`', | ||
].join('\n'); | ||
@@ -47,3 +47,8 @@ | ||
this.__code = code; | ||
this.__ast = recast.parse(code); | ||
try { | ||
this.__ast = recast.parse(code); | ||
} catch (err) { | ||
this.__print_parse_error(code, err); | ||
throw err; | ||
} | ||
} else if (ast) { | ||
@@ -56,2 +61,30 @@ this.__file_path = file_path; | ||
__print_parse_error(code, err) { | ||
// get the source code line of the error | ||
var errorLine = ''; | ||
if (err.lineNumber) { | ||
errorLine = code.split('\n')[err.lineNumber - 1]; | ||
} | ||
// show column indicator | ||
var errorColumnIndicator = ''; | ||
if (err.column) { | ||
for (var i = 0; i < err.column - 1; i++) { | ||
errorColumnIndicator += '-'; | ||
} | ||
errorColumnIndicator += '^'; | ||
} | ||
// error complement | ||
var error_message_complement = [ | ||
'', | ||
' ' + errorLine, | ||
' ' + errorColumnIndicator, | ||
' ' + err.message | ||
].join('\n'); | ||
// throw esprima error | ||
err.message = error_message_complement; | ||
} | ||
// async call. | ||
@@ -58,0 +91,0 @@ // bb.coroutine(function* -> returns a promise and can use 'yield' |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
62795
763